#ifndef  WIN31
#define WIN31
#endif
#include <string.h>
#include <static.h>
#include "status.h"
#define TEXTLEN    20 //Really should set this dynamically
#define ixBorder  3
#define iyBorder  3
#define iTextOffset  ixBorder+1

//Paint the control in the current font, adding a 3D textured border
//Note that OWL does not call Paint routine for a predefined control, so we have to catch WM_PAINT
void TStatus::WMPaint(RTMessage /*msg*/)
{
   PAINTSTRUCT ps;
   RECT rect;
   TEXTMETRIC tmCurFont;
   char text[TEXTLEN];
   HFONT hCurFont;
   HBRUSH hGrayBrush;
   HPEN hPen, hOldPen;
   LOGBRUSH lbrushGray;

   hCurFont=(HFONT)SendMessage(HWindow, WM_GETFONT, 0, 0); //Get the current font for control

   BeginPaint(HWindow, &ps); 
   SetBkMode(ps.hdc, TRANSPARENT); //Set Background to not erase our gray rectangle with text frame
   GetClientRect(HWindow, &rect);
   hGrayBrush=(HBRUSH)GetStockObject(LTGRAY_BRUSH);
   SelectObject(ps.hdc, hGrayBrush);
   Rectangle(ps.hdc,rect.left, rect.top, rect.right+1, rect.bottom+1);

   hPen=(HPEN)GetStockObject(WHITE_PEN);
   hOldPen=(HPEN)SelectObject(ps.hdc, hPen);
   MoveTo(ps.hdc, rect.left+ixBorder, rect.bottom-iyBorder);
   LineTo(ps.hdc, rect.right-ixBorder, rect.bottom-iyBorder);
   LineTo(ps.hdc, rect.right-ixBorder, rect.top+iyBorder);

   hGrayBrush=(HBRUSH)GetStockObject(GRAY_BRUSH);
   GetObject(hGrayBrush, sizeof(lbrushGray), &lbrushGray);

   hPen=CreatePen(PS_SOLID, 0, lbrushGray.lbColor); //use color of stock gray_brush(there is no gray_pen)
   SelectObject(ps.hdc, hPen);
   MoveTo(ps.hdc, rect.right-ixBorder, rect.top+iyBorder);
   LineTo(ps.hdc, rect.left+ixBorder, rect.top+iyBorder);
   LineTo(ps.hdc, rect.left+ixBorder, rect.bottom-iyBorder);
   SelectObject(ps.hdc, hOldPen);
   DeleteObject(hPen);

   SelectObject(ps.hdc, hCurFont); //Use current font
   GetTextMetrics(ps.hdc, &tmCurFont);
   GetText(text, TEXTLEN);
   TextOut(ps.hdc, rect.left+iTextOffset,
      ((rect.bottom-rect.top)-tmCurFont.tmHeight)/2+rect.top,text,
       strlen(text)); //Prints Text In Middle y, and iTextOffset away from left border
   EndPaint(HWindow, &ps); 
};

void TStatus::WMSetText(RTMessage msg)  {
   //toggle WS_VISIBLE before calling Default WNDPROC so static text is not redrawn
   //before we get a chance to redraw it.
   SetWindowLong(HWindow, GWL_STYLE, GetWindowLong(HWindow, GWL_STYLE)^WS_VISIBLE);
   DefWndProc(msg); //Allow Default WNDPROC a chance to set text
   SetWindowLong(HWindow, GWL_STYLE, GetWindowLong(HWindow, GWL_STYLE)^WS_VISIBLE);//Make VISIBLE again
   InvalidateRect(HWindow, NULL, TRUE); //Invalidate whole window
   UpdateWindow(HWindow); //Force a redraw (So we only draw after a WM_PAINT
}

