4 * Copyright David W. Metcalfe, 1993
6 static char Copyright[] = "Copyright David W. Metcalfe, 1993";
15 extern void DEFWND_SetText( HWND hwnd
, LPSTR text
); /* windows/defwnd.c */
17 static void PaintTextfn( HWND hwnd
, HDC hdc
);
18 static void PaintRectfn( HWND hwnd
, HDC hdc
);
19 static void PaintIconfn( HWND hwnd
, HDC hdc
);
22 static COLORREF color_windowframe
, color_background
, color_window
;
25 typedef void (*pfPaint
)(HWND
, HDC
);
27 #define LAST_STATIC_TYPE SS_LEFTNOWORDWRAP
29 static pfPaint staticPaintFunc
[LAST_STATIC_TYPE
+1] =
31 PaintTextfn
, /* SS_LEFT */
32 PaintTextfn
, /* SS_CENTER */
33 PaintTextfn
, /* SS_RIGHT */
34 PaintIconfn
, /* SS_ICON */
35 PaintRectfn
, /* SS_BLACKRECT */
36 PaintRectfn
, /* SS_GRAYRECT */
37 PaintRectfn
, /* SS_WHITERECT */
38 PaintRectfn
, /* SS_BLACKFRAME */
39 PaintRectfn
, /* SS_GRAYFRAME */
40 PaintRectfn
, /* SS_WHITEFRAME */
41 NULL
, /* Not defined */
42 PaintTextfn
, /* SS_SIMPLE */
43 PaintTextfn
/* SS_LEFTNOWORDWRAP */
47 /***********************************************************************
50 * Set the icon for an SS_ICON control.
52 static void STATIC_SetIcon( HWND hwnd
, HICON hicon
)
54 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
55 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
57 if ((wndPtr
->dwStyle
& 0x0f) != SS_ICON
) return;
58 if (infoPtr
->hIcon
) DestroyIcon( infoPtr
->hIcon
);
59 infoPtr
->hIcon
= hicon
;
62 CURSORICONINFO
*info
= (CURSORICONINFO
*) GlobalLock( hicon
);
63 SetWindowPos( hwnd
, 0, 0, 0, info
->nWidth
, info
->nHeight
,
64 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
65 GlobalUnlock( hicon
);
70 /***********************************************************************
73 LONG
StaticWndProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
76 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
77 LONG style
= wndPtr
->dwStyle
& 0x0000000F;
78 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
82 InvalidateRect(hWnd
, NULL
, FALSE
);
88 CREATESTRUCT
* createStruct
= (CREATESTRUCT
*)PTR_SEG_TO_LIN(lParam
);
89 if (createStruct
->lpszName
)
90 STATIC_SetIcon( hWnd
, LoadIcon( createStruct
->hInstance
,
91 (SEGPTR
)createStruct
->lpszName
));
94 return DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
97 if (style
< 0L || style
> LAST_STATIC_TYPE
)
99 fprintf( stderr
, "STATIC: Unknown style 0x%02lx\n", style
);
103 /* initialise colours */
104 color_windowframe
= GetSysColor(COLOR_WINDOWFRAME
);
105 color_background
= GetSysColor(COLOR_BACKGROUND
);
106 color_window
= GetSysColor(COLOR_WINDOW
);
110 if (style
== SS_ICON
)
111 STATIC_SetIcon( hWnd
, 0 ); /* Destroy the current icon */
113 lResult
= DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
119 BeginPaint( hWnd
, &ps
);
120 if (staticPaintFunc
[style
])
121 (staticPaintFunc
[style
])( hWnd
, ps
.hdc
);
122 EndPaint( hWnd
, &ps
);
126 case WM_SYSCOLORCHANGE
:
127 color_windowframe
= GetSysColor(COLOR_WINDOWFRAME
);
128 color_background
= GetSysColor(COLOR_BACKGROUND
);
129 color_window
= GetSysColor(COLOR_WINDOW
);
130 InvalidateRect(hWnd
, NULL
, TRUE
);
134 if (style
== SS_ICON
)
135 STATIC_SetIcon( hWnd
, LoadIcon( wndPtr
->hInstance
,
138 DEFWND_SetText( hWnd
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
139 InvalidateRect( hWnd
, NULL
, FALSE
);
140 UpdateWindow( hWnd
);
144 if (style
== SS_ICON
) return 0;
145 infoPtr
->hFont
= (HFONT
)wParam
;
148 InvalidateRect( hWnd
, NULL
, FALSE
);
149 UpdateWindow( hWnd
);
154 return (LONG
)infoPtr
->hFont
;
157 return HTTRANSPARENT
;
163 return (LONG
)infoPtr
->hIcon
;
166 STATIC_SetIcon( hWnd
, (HICON
)wParam
);
167 InvalidateRect( hWnd
, NULL
, FALSE
);
168 UpdateWindow( hWnd
);
172 lResult
= DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
180 static void PaintTextfn( HWND hwnd
, HDC hdc
)
187 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
188 LONG style
= wndPtr
->dwStyle
;
189 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
191 GetClientRect(hwnd
, &rc
);
192 text
= USER_HEAP_LIN_ADDR( wndPtr
->hText
);
194 switch (style
& 0x0000000F)
197 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
;
201 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
;
205 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
;
209 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
;
212 case SS_LEFTNOWORDWRAP
:
213 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_EXPANDTABS
| DT_VCENTER
;
220 if (style
& SS_NOPREFIX
)
221 wFormat
|= DT_NOPREFIX
;
223 if (infoPtr
->hFont
) SelectObject( hdc
, infoPtr
->hFont
);
225 hBrush
= (HBRUSH
)SendMessage( wndPtr
->hwndParent
, WM_CTLCOLORSTATIC
,
226 (WPARAM
)hdc
, (LPARAM
)hwnd
);
228 hBrush
= SendMessage( wndPtr
->hwndParent
, WM_CTLCOLOR
, (WORD
)hdc
,
229 MAKELONG(hwnd
, CTLCOLOR_STATIC
));
231 if (hBrush
== (HBRUSH
)NULL
) hBrush
= GetStockObject(WHITE_BRUSH
);
232 FillRect(hdc
, &rc
, hBrush
);
234 DrawText(hdc
, text
, -1, &rc
, wFormat
);
237 static void PaintRectfn( HWND hwnd
, HDC hdc
)
242 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
244 GetClientRect(hwnd
, &rc
);
246 switch (wndPtr
->dwStyle
& 0x0f)
249 hBrush
= CreateSolidBrush(color_windowframe
);
250 FillRect( hdc
, &rc
, hBrush
);
253 hBrush
= CreateSolidBrush(color_background
);
254 FillRect( hdc
, &rc
, hBrush
);
257 hBrush
= CreateSolidBrush(color_window
);
258 FillRect( hdc
, &rc
, hBrush
);
261 hBrush
= CreateSolidBrush(color_windowframe
);
262 FrameRect( hdc
, &rc
, hBrush
);
265 hBrush
= CreateSolidBrush(color_background
);
266 FrameRect( hdc
, &rc
, hBrush
);
269 hBrush
= CreateSolidBrush(color_window
);
270 FrameRect( hdc
, &rc
, hBrush
);
275 DeleteObject( hBrush
);
279 static void PaintIconfn( HWND hwnd
, HDC hdc
)
283 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
284 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
286 GetClientRect(hwnd
, &rc
);
288 hbrush
= (HBRUSH
)SendMessage( wndPtr
->hwndParent
, WM_CTLCOLORSTATIC
,
289 (WPARAM
)hdc
, (LPARAM
)hwnd
);
291 hbrush
= SendMessage( wndPtr
->hwndParent
, WM_CTLCOLOR
, hdc
,
292 MAKELONG(hwnd
, CTLCOLOR_STATIC
));
294 FillRect( hdc
, &rc
, hbrush
);
295 if (infoPtr
->hIcon
) DrawIcon( hdc
, rc
.left
, rc
.top
, infoPtr
->hIcon
);