4 * Copyright David W. Metcalfe, 1993
6 static char Copyright[] = "Copyright David W. Metcalfe, 1993";
16 extern void DEFWND_SetText( HWND hwnd
, LPSTR text
); /* windows/defwnd.c */
18 static void PaintTextfn( HWND hwnd
, HDC hdc
);
19 static void PaintRectfn( HWND hwnd
, HDC hdc
);
20 static void PaintFramefn( HWND hwnd
, HDC hdc
);
21 static void PaintIconfn( HWND hwnd
, HDC hdc
);
24 static COLORREF color_windowframe
, color_background
, color_window
;
27 typedef void (*pfPaint
)(HWND
, HDC
);
29 #define LAST_STATIC_TYPE SS_LEFTNOWORDWRAP
31 static pfPaint staticPaintFunc
[LAST_STATIC_TYPE
+1] =
33 PaintTextfn
, /* SS_LEFT */
34 PaintTextfn
, /* SS_CENTER */
35 PaintTextfn
, /* SS_RIGHT */
36 PaintIconfn
, /* SS_ICON */
37 PaintRectfn
, /* SS_BLACKRECT */
38 PaintRectfn
, /* SS_GRAYRECT */
39 PaintRectfn
, /* SS_WHITERECT */
40 PaintFramefn
, /* SS_BLACKFRAME */
41 PaintFramefn
, /* SS_GRAYFRAME */
42 PaintFramefn
, /* SS_WHITEFRAME */
43 NULL
, /* Not defined */
44 PaintTextfn
, /* SS_SIMPLE */
45 PaintTextfn
/* SS_LEFTNOWORDWRAP */
49 /***********************************************************************
52 * Set the icon for an SS_ICON control.
54 static void STATIC_SetIcon( HWND hwnd
, HICON hicon
)
56 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
57 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
59 if ((wndPtr
->dwStyle
& 0x0f) != SS_ICON
) return;
60 if (infoPtr
->hIcon
) DestroyIcon( infoPtr
->hIcon
);
61 infoPtr
->hIcon
= hicon
;
64 ICONALLOC
*icon
= (ICONALLOC
*) GlobalLock( hicon
);
65 SetWindowPos( hwnd
, 0, 0, 0,
66 icon
->descriptor
.Width
, icon
->descriptor
.Height
,
67 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
68 GlobalUnlock( hicon
);
73 /***********************************************************************
76 LONG
StaticWndProc(HWND hWnd
, WORD uMsg
, WORD wParam
, LONG lParam
)
79 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
80 LONG style
= wndPtr
->dwStyle
& 0x0000000F;
81 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
85 InvalidateRect(hWnd
, NULL
, FALSE
);
91 CREATESTRUCT
* createStruct
= (CREATESTRUCT
*)PTR_SEG_TO_LIN(lParam
);
92 if (createStruct
->lpszName
)
93 STATIC_SetIcon( hWnd
, LoadIcon( createStruct
->hInstance
,
94 (SEGPTR
)createStruct
->lpszName
));
97 return DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
100 if (style
< 0L || style
> LAST_STATIC_TYPE
)
102 fprintf( stderr
, "STATIC: Unknown style 0x%02lx\n", style
);
106 /* initialise colours */
107 color_windowframe
= GetSysColor(COLOR_WINDOWFRAME
);
108 color_background
= GetSysColor(COLOR_BACKGROUND
);
109 color_window
= GetSysColor(COLOR_WINDOW
);
113 if (style
== SS_ICON
)
114 STATIC_SetIcon( hWnd
, 0 ); /* Destroy the current icon */
116 lResult
= DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
122 BeginPaint( hWnd
, &ps
);
123 if (staticPaintFunc
[style
])
124 (staticPaintFunc
[style
])( hWnd
, ps
.hdc
);
125 EndPaint( hWnd
, &ps
);
129 case WM_SYSCOLORCHANGE
:
130 color_windowframe
= GetSysColor(COLOR_WINDOWFRAME
);
131 color_background
= GetSysColor(COLOR_BACKGROUND
);
132 color_window
= GetSysColor(COLOR_WINDOW
);
133 InvalidateRect(hWnd
, NULL
, TRUE
);
137 if (style
== SS_ICON
)
138 STATIC_SetIcon( hWnd
, LoadIcon( wndPtr
->hInstance
,
141 DEFWND_SetText( hWnd
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
142 InvalidateRect( hWnd
, NULL
, FALSE
);
143 UpdateWindow( hWnd
);
147 if (style
== SS_ICON
) return 0;
148 infoPtr
->hFont
= wParam
;
151 InvalidateRect( hWnd
, NULL
, FALSE
);
152 UpdateWindow( hWnd
);
157 return infoPtr
->hFont
;
160 return HTTRANSPARENT
;
166 return infoPtr
->hIcon
;
169 STATIC_SetIcon( hWnd
, wParam
);
170 InvalidateRect( hWnd
, NULL
, FALSE
);
171 UpdateWindow( hWnd
);
175 lResult
= DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
183 static void PaintTextfn( HWND hwnd
, HDC hdc
)
190 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
191 LONG style
= wndPtr
->dwStyle
;
192 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
194 GetClientRect(hwnd
, &rc
);
195 text
= USER_HEAP_LIN_ADDR( wndPtr
->hText
);
197 switch (style
& 0x0000000F)
200 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
;
204 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
;
208 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
;
212 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
;
215 case SS_LEFTNOWORDWRAP
:
216 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_EXPANDTABS
| DT_VCENTER
;
223 if (style
& SS_NOPREFIX
)
224 wFormat
|= DT_NOPREFIX
;
226 if (infoPtr
->hFont
) SelectObject( hdc
, infoPtr
->hFont
);
227 hBrush
= SendMessage( wndPtr
->hwndParent
, WM_CTLCOLOR
, (WORD
)hdc
,
228 MAKELONG(hwnd
, CTLCOLOR_STATIC
));
229 if (hBrush
== (HBRUSH
)NULL
) hBrush
= GetStockObject(WHITE_BRUSH
);
230 FillRect(hdc
, &rc
, hBrush
);
232 DrawText(hdc
, text
, -1, &rc
, wFormat
);
235 static void PaintRectfn( HWND hwnd
, HDC hdc
)
240 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
242 GetClientRect(hwnd
, &rc
);
244 switch (wndPtr
->dwStyle
& 0x0000000F)
247 hBrush
= CreateSolidBrush(color_windowframe
);
251 hBrush
= CreateSolidBrush(color_background
);
255 hBrush
= CreateSolidBrush(color_window
);
261 FillRect( hdc
, &rc
, hBrush
);
264 static void PaintFramefn( HWND hwnd
, HDC hdc
)
268 HBRUSH hOldBrush
, hBrush
;
270 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
272 GetClientRect(hwnd
, &rc
);
274 switch (wndPtr
->dwStyle
& 0x0000000F)
277 hPen
= CreatePen(PS_SOLID
, 1, color_windowframe
);
281 hPen
= CreatePen(PS_SOLID
, 1, color_background
);
285 hPen
= CreatePen(PS_SOLID
, 1, color_window
);
292 hBrush
= CreateSolidBrush(color_window
);
293 hOldPen
= (HPEN
)SelectObject(hdc
, (HANDLE
)hPen
);
294 hOldBrush
= (HBRUSH
)SelectObject(hdc
, (HANDLE
)hBrush
);
295 Rectangle(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
297 SelectObject(hdc
, (HANDLE
)hOldPen
);
298 SelectObject(hdc
, (HANDLE
)hOldBrush
);
299 DeleteObject((HANDLE
)hPen
);
300 DeleteObject((HANDLE
)hBrush
);
304 static void PaintIconfn( HWND hwnd
, HDC hdc
)
308 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
309 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
311 GetClientRect(hwnd
, &rc
);
312 hbrush
= SendMessage( wndPtr
->hwndParent
, WM_CTLCOLOR
, hdc
,
313 MAKELONG(hwnd
, CTLCOLOR_STATIC
));
314 FillRect( hdc
, &rc
, hbrush
);
315 if (infoPtr
->hIcon
) DrawIcon( hdc
, rc
.left
, rc
.top
, infoPtr
->hIcon
);