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
;
53 CURSORICONINFO
*info
= hicon
?(CURSORICONINFO
*) GlobalLock16( hicon
):NULL
;
55 if ((wndPtr
->dwStyle
& 0x0f) != SS_ICON
) return 0;
57 fprintf(stderr
,"STATIC_SetIcon: huh? hicon!=0, but info=0???\n");
60 prevIcon
= infoPtr
->hIcon
;
61 infoPtr
->hIcon
= hicon
;
64 SetWindowPos32( wndPtr
->hwndSelf
, 0, 0, 0, info
->nWidth
, info
->nHeight
,
65 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
66 GlobalUnlock16( hicon
);
72 /***********************************************************************
75 * Load the icon for an SS_ICON control.
77 static HICON16
STATIC_LoadIcon( WND
*wndPtr
, LPCSTR name
)
81 if (wndPtr
->flags
& WIN_ISWIN32
)
83 hicon
= LoadIcon32A( wndPtr
->hInstance
, name
);
84 if (!hicon
) /* Try OEM icon (FIXME: is this right?) */
85 hicon
= LoadIcon32A( 0, name
);
89 LPSTR segname
= SEGPTR_STRDUP(name
);
90 hicon
= LoadIcon16( wndPtr
->hInstance
, SEGPTR_GET(segname
) );
91 if (!hicon
) /* Try OEM icon (FIXME: is this right?) */
92 hicon
= LoadIcon32A( 0, segname
);
99 /***********************************************************************
102 LRESULT WINAPI
StaticWndProc( HWND32 hWnd
, UINT32 uMsg
, WPARAM32 wParam
,
106 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
107 LONG style
= wndPtr
->dwStyle
& 0x0000000F;
108 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
113 if (style
== SS_ICON
)
115 CREATESTRUCT32A
*cs
= (CREATESTRUCT32A
*)lParam
;
117 STATIC_SetIcon( wndPtr
,
118 STATIC_LoadIcon( wndPtr
, cs
->lpszName
));
121 return DefWindowProc32A( hWnd
, uMsg
, wParam
, lParam
);
124 if (style
< 0L || style
> LAST_STATIC_TYPE
)
126 fprintf( stderr
, "STATIC: Unknown style 0x%02lx\n", style
);
130 /* initialise colours */
131 color_windowframe
= GetSysColor32(COLOR_WINDOWFRAME
);
132 color_background
= GetSysColor32(COLOR_BACKGROUND
);
133 color_window
= GetSysColor32(COLOR_WINDOW
);
137 if (style
== SS_ICON
)
138 DestroyIcon32( STATIC_SetIcon( wndPtr
, 0 ) );
140 lResult
= DefWindowProc32A( hWnd
, uMsg
, wParam
, lParam
);
146 BeginPaint32( hWnd
, &ps
);
147 if (staticPaintFunc
[style
])
148 (staticPaintFunc
[style
])( wndPtr
, ps
.hdc
);
149 EndPaint32( hWnd
, &ps
);
154 InvalidateRect32( hWnd
, NULL
, FALSE
);
157 case WM_SYSCOLORCHANGE
:
158 color_windowframe
= GetSysColor32(COLOR_WINDOWFRAME
);
159 color_background
= GetSysColor32(COLOR_BACKGROUND
);
160 color_window
= GetSysColor32(COLOR_WINDOW
);
161 InvalidateRect32( hWnd
, NULL
, TRUE
);
165 if (style
== SS_ICON
)
166 /* FIXME : should we also return the previous hIcon here ??? */
167 STATIC_SetIcon( wndPtr
, STATIC_LoadIcon( wndPtr
, (LPCSTR
)lParam
));
169 DEFWND_SetText( wndPtr
, (LPCSTR
)lParam
);
170 InvalidateRect32( hWnd
, NULL
, FALSE
);
171 UpdateWindow32( hWnd
);
175 if (style
== SS_ICON
) return 0;
176 infoPtr
->hFont
= (HFONT16
)wParam
;
179 InvalidateRect32( hWnd
, NULL
, FALSE
);
180 UpdateWindow32( hWnd
);
185 return infoPtr
->hFont
;
188 return HTTRANSPARENT
;
194 return infoPtr
->hIcon
;
197 lResult
= STATIC_SetIcon( wndPtr
, (HICON16
)wParam
);
198 InvalidateRect32( hWnd
, NULL
, FALSE
);
199 UpdateWindow32( hWnd
);
203 lResult
= DefWindowProc32A(hWnd
, uMsg
, wParam
, lParam
);
211 static void STATIC_PaintTextfn( WND
*wndPtr
, HDC32 hdc
)
217 LONG style
= wndPtr
->dwStyle
;
218 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
220 GetClientRect32( wndPtr
->hwndSelf
, &rc
);
222 switch (style
& 0x0000000F)
225 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
229 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
233 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
237 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_NOCLIP
;
240 case SS_LEFTNOWORDWRAP
:
241 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_EXPANDTABS
| DT_VCENTER
| DT_NOCLIP
;
248 if (style
& SS_NOPREFIX
)
249 wFormat
|= DT_NOPREFIX
;
251 if (infoPtr
->hFont
) SelectObject32( hdc
, infoPtr
->hFont
);
252 hBrush
= SendMessage32A( GetParent32(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
253 hdc
, wndPtr
->hwndSelf
);
254 if (!hBrush
) hBrush
= GetStockObject32(WHITE_BRUSH
);
255 FillRect32( hdc
, &rc
, hBrush
);
256 if (wndPtr
->text
) DrawText32A( hdc
, wndPtr
->text
, -1, &rc
, wFormat
);
259 static void STATIC_PaintRectfn( WND
*wndPtr
, HDC32 hdc
)
264 GetClientRect32( wndPtr
->hwndSelf
, &rc
);
266 switch (wndPtr
->dwStyle
& 0x0f)
269 hBrush
= CreateSolidBrush32(color_windowframe
);
270 FillRect32( hdc
, &rc
, hBrush
);
273 hBrush
= CreateSolidBrush32(color_background
);
274 FillRect32( hdc
, &rc
, hBrush
);
277 hBrush
= CreateSolidBrush32(color_window
);
278 FillRect32( hdc
, &rc
, hBrush
);
281 hBrush
= CreateSolidBrush32(color_windowframe
);
282 FrameRect32( hdc
, &rc
, hBrush
);
285 hBrush
= CreateSolidBrush32(color_background
);
286 FrameRect32( hdc
, &rc
, hBrush
);
289 hBrush
= CreateSolidBrush32(color_window
);
290 FrameRect32( hdc
, &rc
, hBrush
);
295 DeleteObject32( hBrush
);
299 static void STATIC_PaintIconfn( WND
*wndPtr
, HDC32 hdc
)
303 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
305 GetClientRect32( wndPtr
->hwndSelf
, &rc
);
306 hbrush
= SendMessage32A( GetParent32(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
307 hdc
, wndPtr
->hwndSelf
);
308 FillRect32( hdc
, &rc
, hbrush
);
309 if (infoPtr
->hIcon
) DrawIcon32( hdc
, rc
.left
, rc
.top
, infoPtr
->hIcon
);