4 * Copyright David W. Metcalfe, 1993
14 extern void DEFWND_SetText( WND
*wndPtr
, LPSTR text
); /* windows/defwnd.c */
16 static void STATIC_PaintTextfn( WND
*wndPtr
, HDC hdc
);
17 static void STATIC_PaintRectfn( WND
*wndPtr
, HDC hdc
);
18 static void STATIC_PaintIconfn( WND
*wndPtr
, HDC hdc
);
21 static COLORREF color_windowframe
, color_background
, color_window
;
24 typedef void (*pfPaint
)( WND
*, HDC
);
26 #define LAST_STATIC_TYPE SS_LEFTNOWORDWRAP
28 static pfPaint staticPaintFunc
[LAST_STATIC_TYPE
+1] =
30 STATIC_PaintTextfn
, /* SS_LEFT */
31 STATIC_PaintTextfn
, /* SS_CENTER */
32 STATIC_PaintTextfn
, /* SS_RIGHT */
33 STATIC_PaintIconfn
, /* SS_ICON */
34 STATIC_PaintRectfn
, /* SS_BLACKRECT */
35 STATIC_PaintRectfn
, /* SS_GRAYRECT */
36 STATIC_PaintRectfn
, /* SS_WHITERECT */
37 STATIC_PaintRectfn
, /* SS_BLACKFRAME */
38 STATIC_PaintRectfn
, /* SS_GRAYFRAME */
39 STATIC_PaintRectfn
, /* SS_WHITEFRAME */
40 NULL
, /* Not defined */
41 STATIC_PaintTextfn
, /* SS_SIMPLE */
42 STATIC_PaintTextfn
/* SS_LEFTNOWORDWRAP */
46 /***********************************************************************
49 * Set the icon for an SS_ICON control.
51 static HICON
STATIC_SetIcon( WND
*wndPtr
, HICON hicon
)
54 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
56 if ((wndPtr
->dwStyle
& 0x0f) != SS_ICON
) return 0;
57 prevIcon
= infoPtr
->hIcon
;
58 infoPtr
->hIcon
= hicon
;
61 CURSORICONINFO
*info
= (CURSORICONINFO
*) GlobalLock16( hicon
);
62 SetWindowPos( wndPtr
->hwndSelf
, 0, 0, 0, info
->nWidth
, info
->nHeight
,
63 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
64 GlobalUnlock16( hicon
);
70 /***********************************************************************
73 LONG
StaticWndProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
76 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
77 LONG style
= wndPtr
->dwStyle
& 0x0000000F;
78 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
82 InvalidateRect(hWnd
, NULL
, FALSE
);
88 CREATESTRUCT
* createStruct
= (CREATESTRUCT
*)PTR_SEG_TO_LIN(lParam
);
89 if (createStruct
->lpszName
)
91 HICON hicon
= LoadIcon( createStruct
->hInstance
,
92 createStruct
->lpszName
);
93 if (!hicon
) /* Try OEM icon (FIXME: is this right?) */
94 hicon
= LoadIcon( 0, createStruct
->lpszName
);
95 STATIC_SetIcon( wndPtr
, hicon
);
99 return DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
102 if (style
< 0L || style
> LAST_STATIC_TYPE
)
104 fprintf( stderr
, "STATIC: Unknown style 0x%02lx\n", style
);
108 /* initialise colours */
109 color_windowframe
= GetSysColor(COLOR_WINDOWFRAME
);
110 color_background
= GetSysColor(COLOR_BACKGROUND
);
111 color_window
= GetSysColor(COLOR_WINDOW
);
115 if (style
== SS_ICON
)
116 DestroyIcon( STATIC_SetIcon( wndPtr
, 0 ) );
118 lResult
= DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
124 BeginPaint( hWnd
, &ps
);
125 if (staticPaintFunc
[style
])
126 (staticPaintFunc
[style
])( wndPtr
, ps
.hdc
);
127 EndPaint( hWnd
, &ps
);
131 case WM_SYSCOLORCHANGE
:
132 color_windowframe
= GetSysColor(COLOR_WINDOWFRAME
);
133 color_background
= GetSysColor(COLOR_BACKGROUND
);
134 color_window
= GetSysColor(COLOR_WINDOW
);
135 InvalidateRect(hWnd
, NULL
, TRUE
);
139 if (style
== SS_ICON
)
140 /* FIXME : should we also return the previous hIcon here ??? */
141 STATIC_SetIcon( wndPtr
, LoadIcon( wndPtr
->hInstance
,
144 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
145 InvalidateRect( hWnd
, NULL
, FALSE
);
146 UpdateWindow( hWnd
);
150 if (style
== SS_ICON
) return 0;
151 infoPtr
->hFont
= (HFONT
)wParam
;
154 InvalidateRect( hWnd
, NULL
, FALSE
);
155 UpdateWindow( hWnd
);
160 return infoPtr
->hFont
;
163 return HTTRANSPARENT
;
169 return infoPtr
->hIcon
;
172 lResult
= STATIC_SetIcon( wndPtr
, (HICON
)wParam
);
173 InvalidateRect( hWnd
, NULL
, FALSE
);
174 UpdateWindow( hWnd
);
178 lResult
= DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
186 static void STATIC_PaintTextfn( WND
*wndPtr
, HDC hdc
)
193 LONG style
= wndPtr
->dwStyle
;
194 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
196 GetClientRect( wndPtr
->hwndSelf
, &rc
);
197 text
= USER_HEAP_LIN_ADDR( wndPtr
->hText
);
199 switch (style
& 0x0000000F)
202 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
206 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
210 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
214 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_NOCLIP
;
217 case SS_LEFTNOWORDWRAP
:
218 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_EXPANDTABS
| DT_VCENTER
| DT_NOCLIP
;
225 if (style
& SS_NOPREFIX
)
226 wFormat
|= DT_NOPREFIX
;
228 if (infoPtr
->hFont
) SelectObject( hdc
, infoPtr
->hFont
);
230 hBrush
= SendMessage( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
231 hdc
, wndPtr
->hwndSelf
);
233 hBrush
= SendMessage( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLOR
, (WORD
)hdc
,
234 MAKELONG(wndPtr
->hwndSelf
, CTLCOLOR_STATIC
));
236 if (!hBrush
) hBrush
= GetStockObject(WHITE_BRUSH
);
237 FillRect(hdc
, &rc
, hBrush
);
238 if (text
) DrawText( hdc
, text
, -1, &rc
, wFormat
);
241 static void STATIC_PaintRectfn( WND
*wndPtr
, HDC hdc
)
246 GetClientRect( wndPtr
->hwndSelf
, &rc
);
248 switch (wndPtr
->dwStyle
& 0x0f)
251 hBrush
= CreateSolidBrush(color_windowframe
);
252 FillRect( hdc
, &rc
, hBrush
);
255 hBrush
= CreateSolidBrush(color_background
);
256 FillRect( hdc
, &rc
, hBrush
);
259 hBrush
= CreateSolidBrush(color_window
);
260 FillRect( hdc
, &rc
, hBrush
);
263 hBrush
= CreateSolidBrush(color_windowframe
);
264 FrameRect( hdc
, &rc
, hBrush
);
267 hBrush
= CreateSolidBrush(color_background
);
268 FrameRect( hdc
, &rc
, hBrush
);
271 hBrush
= CreateSolidBrush(color_window
);
272 FrameRect( hdc
, &rc
, hBrush
);
277 DeleteObject( hBrush
);
281 static void STATIC_PaintIconfn( WND
*wndPtr
, HDC hdc
)
285 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
287 GetClientRect( wndPtr
->hwndSelf
, &rc
);
289 hbrush
= SendMessage( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
290 hdc
, wndPtr
->hwndSelf
);
292 hbrush
= SendMessage( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLOR
, hdc
,
293 MAKELONG(wndPtr
->hwndSelf
, CTLCOLOR_STATIC
));
295 FillRect( hdc
, &rc
, hbrush
);
296 if (infoPtr
->hIcon
) DrawIcon( hdc
, rc
.left
, rc
.top
, infoPtr
->hIcon
);