4 * Copyright David W. Metcalfe, 1993
14 static void STATIC_PaintTextfn( WND
*wndPtr
, HDC hdc
);
15 static void STATIC_PaintRectfn( WND
*wndPtr
, HDC hdc
);
16 static void STATIC_PaintIconfn( WND
*wndPtr
, HDC hdc
);
19 static COLORREF color_windowframe
, color_background
, color_window
;
22 typedef void (*pfPaint
)( WND
*, HDC
);
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 HICON
STATIC_SetIcon( WND
*wndPtr
, HICON 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 SetWindowPos( wndPtr
->hwndSelf
, 0, 0, 0, info
->nWidth
, info
->nHeight
,
61 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
62 GlobalUnlock16( hicon
);
68 /***********************************************************************
71 LRESULT
StaticWndProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
74 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
75 LONG style
= wndPtr
->dwStyle
& 0x0000000F;
76 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
81 InvalidateRect32( hWnd
, NULL
, FALSE
);
87 CREATESTRUCT16
*cs
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
90 HICON hicon
= LoadIcon( cs
->hInstance
, cs
->lpszName
);
91 if (!hicon
) /* Try OEM icon (FIXME: is this right?) */
92 hicon
= LoadIcon( 0, cs
->lpszName
);
93 STATIC_SetIcon( wndPtr
, hicon
);
97 return DefWindowProc16(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 DestroyIcon( STATIC_SetIcon( wndPtr
, 0 ) );
116 lResult
= DefWindowProc16(hWnd
, uMsg
, wParam
, lParam
);
122 BeginPaint16( hWnd
, &ps
);
123 if (staticPaintFunc
[style
])
124 (staticPaintFunc
[style
])( wndPtr
, ps
.hdc
);
125 EndPaint16( 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 InvalidateRect32( hWnd
, NULL
, TRUE
);
137 if (style
== SS_ICON
)
138 /* FIXME : should we also return the previous hIcon here ??? */
139 STATIC_SetIcon( wndPtr
, LoadIcon( wndPtr
->hInstance
,
142 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
143 InvalidateRect32( hWnd
, NULL
, FALSE
);
144 UpdateWindow( hWnd
);
148 if (style
== SS_ICON
) return 0;
149 infoPtr
->hFont
= (HFONT
)wParam
;
152 InvalidateRect32( hWnd
, NULL
, FALSE
);
153 UpdateWindow( hWnd
);
158 return infoPtr
->hFont
;
161 return HTTRANSPARENT
;
167 return infoPtr
->hIcon
;
170 lResult
= STATIC_SetIcon( wndPtr
, (HICON
)wParam
);
171 InvalidateRect32( hWnd
, NULL
, FALSE
);
172 UpdateWindow( hWnd
);
176 lResult
= DefWindowProc16(hWnd
, uMsg
, wParam
, lParam
);
184 static void STATIC_PaintTextfn( WND
*wndPtr
, HDC hdc
)
190 LONG style
= wndPtr
->dwStyle
;
191 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
193 GetClientRect16( wndPtr
->hwndSelf
, &rc
);
195 switch (style
& 0x0000000F)
198 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
202 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
206 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
210 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_NOCLIP
;
213 case SS_LEFTNOWORDWRAP
:
214 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_EXPANDTABS
| DT_VCENTER
| DT_NOCLIP
;
221 if (style
& SS_NOPREFIX
)
222 wFormat
|= DT_NOPREFIX
;
224 if (infoPtr
->hFont
) SelectObject( hdc
, infoPtr
->hFont
);
226 hBrush
= SendMessage32A( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
227 hdc
, wndPtr
->hwndSelf
);
229 hBrush
= SendMessage16( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLOR
, (WORD
)hdc
,
230 MAKELONG(wndPtr
->hwndSelf
, CTLCOLOR_STATIC
));
232 if (!hBrush
) hBrush
= GetStockObject(WHITE_BRUSH
);
233 FillRect16(hdc
, &rc
, hBrush
);
234 if (wndPtr
->text
) DrawText16( hdc
, wndPtr
->text
, -1, &rc
, wFormat
);
237 static void STATIC_PaintRectfn( WND
*wndPtr
, HDC hdc
)
242 GetClientRect16( wndPtr
->hwndSelf
, &rc
);
244 switch (wndPtr
->dwStyle
& 0x0f)
247 hBrush
= CreateSolidBrush(color_windowframe
);
248 FillRect16( hdc
, &rc
, hBrush
);
251 hBrush
= CreateSolidBrush(color_background
);
252 FillRect16( hdc
, &rc
, hBrush
);
255 hBrush
= CreateSolidBrush(color_window
);
256 FillRect16( hdc
, &rc
, hBrush
);
259 hBrush
= CreateSolidBrush(color_windowframe
);
260 FrameRect16( hdc
, &rc
, hBrush
);
263 hBrush
= CreateSolidBrush(color_background
);
264 FrameRect16( hdc
, &rc
, hBrush
);
267 hBrush
= CreateSolidBrush(color_window
);
268 FrameRect16( hdc
, &rc
, hBrush
);
273 DeleteObject( hBrush
);
277 static void STATIC_PaintIconfn( WND
*wndPtr
, HDC hdc
)
281 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
283 GetClientRect16( wndPtr
->hwndSelf
, &rc
);
285 hbrush
= SendMessage32A( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
286 hdc
, wndPtr
->hwndSelf
);
288 hbrush
= SendMessage16( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLOR
, hdc
,
289 MAKELONG(wndPtr
->hwndSelf
, CTLCOLOR_STATIC
));
291 FillRect16( hdc
, &rc
, hbrush
);
292 if (infoPtr
->hIcon
) DrawIcon( hdc
, rc
.left
, rc
.top
, infoPtr
->hIcon
);