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 HICON
STATIC_SetIcon( HWND hwnd
, HICON hicon
)
55 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
56 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
58 if ((wndPtr
->dwStyle
& 0x0f) != SS_ICON
) return 0;
59 prevIcon
= infoPtr
->hIcon
;
60 infoPtr
->hIcon
= hicon
;
63 CURSORICONINFO
*info
= (CURSORICONINFO
*) GlobalLock( hicon
);
64 SetWindowPos( hwnd
, 0, 0, 0, info
->nWidth
, info
->nHeight
,
65 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
66 GlobalUnlock( hicon
);
72 /***********************************************************************
75 LONG
StaticWndProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
78 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
79 LONG style
= wndPtr
->dwStyle
& 0x0000000F;
80 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
84 InvalidateRect(hWnd
, NULL
, FALSE
);
90 CREATESTRUCT
* createStruct
= (CREATESTRUCT
*)PTR_SEG_TO_LIN(lParam
);
91 if (createStruct
->lpszName
)
93 HICON hicon
= LoadIcon( createStruct
->hInstance
,
94 (SEGPTR
)createStruct
->lpszName
);
95 if (!hicon
) /* Try OEM icon (FIXME: is this right?) */
96 hicon
= LoadIcon( 0, (SEGPTR
)createStruct
->lpszName
);
97 STATIC_SetIcon( hWnd
, hicon
);
101 return DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
104 if (style
< 0L || style
> LAST_STATIC_TYPE
)
106 fprintf( stderr
, "STATIC: Unknown style 0x%02lx\n", style
);
110 /* initialise colours */
111 color_windowframe
= GetSysColor(COLOR_WINDOWFRAME
);
112 color_background
= GetSysColor(COLOR_BACKGROUND
);
113 color_window
= GetSysColor(COLOR_WINDOW
);
117 if (style
== SS_ICON
)
118 DestroyIcon( STATIC_SetIcon( hWnd
, 0 ) );
120 lResult
= DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
126 BeginPaint( hWnd
, &ps
);
127 if (staticPaintFunc
[style
])
128 (staticPaintFunc
[style
])( hWnd
, ps
.hdc
);
129 EndPaint( hWnd
, &ps
);
133 case WM_SYSCOLORCHANGE
:
134 color_windowframe
= GetSysColor(COLOR_WINDOWFRAME
);
135 color_background
= GetSysColor(COLOR_BACKGROUND
);
136 color_window
= GetSysColor(COLOR_WINDOW
);
137 InvalidateRect(hWnd
, NULL
, TRUE
);
141 if (style
== SS_ICON
)
142 /* FIXME : should we also return the previous hIcon here ??? */
143 STATIC_SetIcon( hWnd
, LoadIcon( wndPtr
->hInstance
,
146 DEFWND_SetText( hWnd
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
147 InvalidateRect( hWnd
, NULL
, FALSE
);
148 UpdateWindow( hWnd
);
152 if (style
== SS_ICON
) return 0;
153 infoPtr
->hFont
= (HFONT
)wParam
;
156 InvalidateRect( hWnd
, NULL
, FALSE
);
157 UpdateWindow( hWnd
);
162 return (LONG
)infoPtr
->hFont
;
165 return HTTRANSPARENT
;
171 return (LONG
)infoPtr
->hIcon
;
174 lResult
= (LONG
)STATIC_SetIcon( hWnd
, (HICON
)wParam
);
175 InvalidateRect( hWnd
, NULL
, FALSE
);
176 UpdateWindow( hWnd
);
180 lResult
= DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
188 static void PaintTextfn( HWND hwnd
, HDC hdc
)
195 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
196 LONG style
= wndPtr
->dwStyle
;
197 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
199 GetClientRect(hwnd
, &rc
);
200 text
= USER_HEAP_LIN_ADDR( wndPtr
->hText
);
202 switch (style
& 0x0000000F)
205 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
209 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
213 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
217 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_NOCLIP
;
220 case SS_LEFTNOWORDWRAP
:
221 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_EXPANDTABS
| DT_VCENTER
| DT_NOCLIP
;
228 if (style
& SS_NOPREFIX
)
229 wFormat
|= DT_NOPREFIX
;
231 if (infoPtr
->hFont
) SelectObject( hdc
, infoPtr
->hFont
);
233 hBrush
= (HBRUSH
)SendMessage( wndPtr
->hwndParent
, WM_CTLCOLORSTATIC
,
234 (WPARAM
)hdc
, (LPARAM
)hwnd
);
236 hBrush
= SendMessage( wndPtr
->hwndParent
, WM_CTLCOLOR
, (WORD
)hdc
,
237 MAKELONG(hwnd
, CTLCOLOR_STATIC
));
239 if (hBrush
== (HBRUSH
)NULL
) hBrush
= GetStockObject(WHITE_BRUSH
);
240 FillRect(hdc
, &rc
, hBrush
);
242 DrawText(hdc
, text
, -1, &rc
, wFormat
);
245 static void PaintRectfn( HWND hwnd
, HDC hdc
)
250 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
252 GetClientRect(hwnd
, &rc
);
254 switch (wndPtr
->dwStyle
& 0x0f)
257 hBrush
= CreateSolidBrush(color_windowframe
);
258 FillRect( hdc
, &rc
, hBrush
);
261 hBrush
= CreateSolidBrush(color_background
);
262 FillRect( hdc
, &rc
, hBrush
);
265 hBrush
= CreateSolidBrush(color_window
);
266 FillRect( hdc
, &rc
, hBrush
);
269 hBrush
= CreateSolidBrush(color_windowframe
);
270 FrameRect( hdc
, &rc
, hBrush
);
273 hBrush
= CreateSolidBrush(color_background
);
274 FrameRect( hdc
, &rc
, hBrush
);
277 hBrush
= CreateSolidBrush(color_window
);
278 FrameRect( hdc
, &rc
, hBrush
);
283 DeleteObject( hBrush
);
287 static void PaintIconfn( HWND hwnd
, HDC hdc
)
291 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
292 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
294 GetClientRect(hwnd
, &rc
);
296 hbrush
= (HBRUSH
)SendMessage( wndPtr
->hwndParent
, WM_CTLCOLORSTATIC
,
297 (WPARAM
)hdc
, (LPARAM
)hwnd
);
299 hbrush
= SendMessage( wndPtr
->hwndParent
, WM_CTLCOLOR
, hdc
,
300 MAKELONG(hwnd
, CTLCOLOR_STATIC
));
302 FillRect( hdc
, &rc
, hbrush
);
303 if (infoPtr
->hIcon
) DrawIcon( hdc
, rc
.left
, rc
.top
, infoPtr
->hIcon
);