4 * Copyright David W. Metcalfe, 1993
14 static void STATIC_PaintTextfn( WND
*wndPtr
, HDC32 hdc
);
15 static void STATIC_PaintRectfn( WND
*wndPtr
, HDC32 hdc
);
16 static void STATIC_PaintIconfn( WND
*wndPtr
, HDC32 hdc
);
19 static COLORREF color_windowframe
, color_background
, color_window
;
22 typedef void (*pfPaint
)( WND
*, HDC32
);
24 #define LAST_STATIC_TYPE SS_LEFTNOWORDWRAP
26 static pfPaint staticPaintFunc
[LAST_STATIC_TYPE
+1] =
28 STATIC_PaintTextfn
, /* SS_LEFT */
29 STATIC_PaintTextfn
, /* SS_CENTER */
30 STATIC_PaintTextfn
, /* SS_RIGHT */
31 STATIC_PaintIconfn
, /* SS_ICON */
32 STATIC_PaintRectfn
, /* SS_BLACKRECT */
33 STATIC_PaintRectfn
, /* SS_GRAYRECT */
34 STATIC_PaintRectfn
, /* SS_WHITERECT */
35 STATIC_PaintRectfn
, /* SS_BLACKFRAME */
36 STATIC_PaintRectfn
, /* SS_GRAYFRAME */
37 STATIC_PaintRectfn
, /* SS_WHITEFRAME */
38 NULL
, /* Not defined */
39 STATIC_PaintTextfn
, /* SS_SIMPLE */
40 STATIC_PaintTextfn
/* SS_LEFTNOWORDWRAP */
44 /***********************************************************************
47 * Set the icon for an SS_ICON control.
49 static HICON16
STATIC_SetIcon( WND
*wndPtr
, HICON16 hicon
)
52 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
54 if ((wndPtr
->dwStyle
& 0x0f) != SS_ICON
) return 0;
55 prevIcon
= infoPtr
->hIcon
;
56 infoPtr
->hIcon
= hicon
;
59 CURSORICONINFO
*info
= (CURSORICONINFO
*) GlobalLock16( hicon
);
60 SetWindowPos32( wndPtr
->hwndSelf
, 0, 0, 0, info
->nWidth
, info
->nHeight
,
61 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
62 GlobalUnlock16( hicon
);
68 /***********************************************************************
71 * Load the icon for an SS_ICON control.
73 static HICON16
STATIC_LoadIcon( WND
*wndPtr
, LPCSTR name
)
77 if (wndPtr
->flags
& WIN_ISWIN32
)
79 hicon
= LoadIcon32A( wndPtr
->hInstance
, name
);
80 if (!hicon
) /* Try OEM icon (FIXME: is this right?) */
81 hicon
= LoadIcon32A( 0, name
);
85 LPSTR segname
= SEGPTR_STRDUP(name
);
86 hicon
= LoadIcon16( wndPtr
->hInstance
, SEGPTR_GET(segname
) );
87 if (!hicon
) /* Try OEM icon (FIXME: is this right?) */
88 hicon
= LoadIcon32A( 0, segname
);
95 /***********************************************************************
98 LRESULT
StaticWndProc( HWND32 hWnd
, UINT32 uMsg
, WPARAM32 wParam
,
102 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
103 LONG style
= wndPtr
->dwStyle
& 0x0000000F;
104 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
109 if (style
== SS_ICON
)
111 CREATESTRUCT32A
*cs
= (CREATESTRUCT32A
*)lParam
;
113 STATIC_SetIcon( wndPtr
,
114 STATIC_LoadIcon( wndPtr
, cs
->lpszName
));
117 return DefWindowProc32A( hWnd
, uMsg
, wParam
, lParam
);
120 if (style
< 0L || style
> LAST_STATIC_TYPE
)
122 fprintf( stderr
, "STATIC: Unknown style 0x%02lx\n", style
);
126 /* initialise colours */
127 color_windowframe
= GetSysColor32(COLOR_WINDOWFRAME
);
128 color_background
= GetSysColor32(COLOR_BACKGROUND
);
129 color_window
= GetSysColor32(COLOR_WINDOW
);
133 if (style
== SS_ICON
)
134 DestroyIcon32( STATIC_SetIcon( wndPtr
, 0 ) );
136 lResult
= DefWindowProc32A( hWnd
, uMsg
, wParam
, lParam
);
142 BeginPaint32( hWnd
, &ps
);
143 if (staticPaintFunc
[style
])
144 (staticPaintFunc
[style
])( wndPtr
, ps
.hdc
);
145 EndPaint32( hWnd
, &ps
);
150 InvalidateRect32( hWnd
, NULL
, FALSE
);
153 case WM_SYSCOLORCHANGE
:
154 color_windowframe
= GetSysColor32(COLOR_WINDOWFRAME
);
155 color_background
= GetSysColor32(COLOR_BACKGROUND
);
156 color_window
= GetSysColor32(COLOR_WINDOW
);
157 InvalidateRect32( hWnd
, NULL
, TRUE
);
161 if (style
== SS_ICON
)
162 /* FIXME : should we also return the previous hIcon here ??? */
163 STATIC_SetIcon( wndPtr
, STATIC_LoadIcon( wndPtr
, (LPCSTR
)lParam
));
165 DEFWND_SetText( wndPtr
, (LPCSTR
)lParam
);
166 InvalidateRect32( hWnd
, NULL
, FALSE
);
167 UpdateWindow32( hWnd
);
171 if (style
== SS_ICON
) return 0;
172 infoPtr
->hFont
= (HFONT16
)wParam
;
175 InvalidateRect32( hWnd
, NULL
, FALSE
);
176 UpdateWindow32( hWnd
);
181 return infoPtr
->hFont
;
184 return HTTRANSPARENT
;
190 return infoPtr
->hIcon
;
193 lResult
= STATIC_SetIcon( wndPtr
, (HICON16
)wParam
);
194 InvalidateRect32( hWnd
, NULL
, FALSE
);
195 UpdateWindow32( hWnd
);
199 lResult
= DefWindowProc32A(hWnd
, uMsg
, wParam
, lParam
);
207 static void STATIC_PaintTextfn( WND
*wndPtr
, HDC32 hdc
)
213 LONG style
= wndPtr
->dwStyle
;
214 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
216 GetClientRect32( wndPtr
->hwndSelf
, &rc
);
218 switch (style
& 0x0000000F)
221 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
225 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
229 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
233 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_NOCLIP
;
236 case SS_LEFTNOWORDWRAP
:
237 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_EXPANDTABS
| DT_VCENTER
| DT_NOCLIP
;
244 if (style
& SS_NOPREFIX
)
245 wFormat
|= DT_NOPREFIX
;
247 if (infoPtr
->hFont
) SelectObject32( hdc
, infoPtr
->hFont
);
248 hBrush
= SendMessage32A( GetParent32(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
249 hdc
, wndPtr
->hwndSelf
);
250 if (!hBrush
) hBrush
= GetStockObject32(WHITE_BRUSH
);
251 FillRect32( hdc
, &rc
, hBrush
);
252 if (wndPtr
->text
) DrawText32A( hdc
, wndPtr
->text
, -1, &rc
, wFormat
);
255 static void STATIC_PaintRectfn( WND
*wndPtr
, HDC32 hdc
)
260 GetClientRect32( wndPtr
->hwndSelf
, &rc
);
262 switch (wndPtr
->dwStyle
& 0x0f)
265 hBrush
= CreateSolidBrush32(color_windowframe
);
266 FillRect32( hdc
, &rc
, hBrush
);
269 hBrush
= CreateSolidBrush32(color_background
);
270 FillRect32( hdc
, &rc
, hBrush
);
273 hBrush
= CreateSolidBrush32(color_window
);
274 FillRect32( hdc
, &rc
, hBrush
);
277 hBrush
= CreateSolidBrush32(color_windowframe
);
278 FrameRect32( hdc
, &rc
, hBrush
);
281 hBrush
= CreateSolidBrush32(color_background
);
282 FrameRect32( hdc
, &rc
, hBrush
);
285 hBrush
= CreateSolidBrush32(color_window
);
286 FrameRect32( hdc
, &rc
, hBrush
);
291 DeleteObject32( hBrush
);
295 static void STATIC_PaintIconfn( WND
*wndPtr
, HDC32 hdc
)
299 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
301 GetClientRect32( wndPtr
->hwndSelf
, &rc
);
302 hbrush
= SendMessage32A( GetParent32(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
303 hdc
, wndPtr
->hwndSelf
);
304 FillRect32( hdc
, &rc
, hbrush
);
305 if (infoPtr
->hIcon
) DrawIcon32( hdc
, rc
.left
, rc
.top
, infoPtr
->hIcon
);