4 * Copyright David W. Metcalfe, 1993
13 static void STATIC_PaintTextfn( WND
*wndPtr
, HDC32 hdc
);
14 static void STATIC_PaintRectfn( WND
*wndPtr
, HDC32 hdc
);
15 static void STATIC_PaintIconfn( WND
*wndPtr
, HDC32 hdc
);
18 static COLORREF color_windowframe
, color_background
, color_window
;
21 typedef void (*pfPaint
)( WND
*, HDC32
);
23 #define LAST_STATIC_TYPE SS_LEFTNOWORDWRAP
25 static pfPaint staticPaintFunc
[LAST_STATIC_TYPE
+1] =
27 STATIC_PaintTextfn
, /* SS_LEFT */
28 STATIC_PaintTextfn
, /* SS_CENTER */
29 STATIC_PaintTextfn
, /* SS_RIGHT */
30 STATIC_PaintIconfn
, /* SS_ICON */
31 STATIC_PaintRectfn
, /* SS_BLACKRECT */
32 STATIC_PaintRectfn
, /* SS_GRAYRECT */
33 STATIC_PaintRectfn
, /* SS_WHITERECT */
34 STATIC_PaintRectfn
, /* SS_BLACKFRAME */
35 STATIC_PaintRectfn
, /* SS_GRAYFRAME */
36 STATIC_PaintRectfn
, /* SS_WHITEFRAME */
37 NULL
, /* Not defined */
38 STATIC_PaintTextfn
, /* SS_SIMPLE */
39 STATIC_PaintTextfn
/* SS_LEFTNOWORDWRAP */
43 /***********************************************************************
46 * Set the icon for an SS_ICON control.
48 static HICON16
STATIC_SetIcon( WND
*wndPtr
, HICON16 hicon
)
51 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
53 if ((wndPtr
->dwStyle
& 0x0f) != SS_ICON
) return 0;
54 prevIcon
= infoPtr
->hIcon
;
55 infoPtr
->hIcon
= hicon
;
58 CURSORICONINFO
*info
= (CURSORICONINFO
*) GlobalLock16( hicon
);
59 SetWindowPos32( wndPtr
->hwndSelf
, 0, 0, 0, info
->nWidth
, info
->nHeight
,
60 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
61 GlobalUnlock16( hicon
);
67 /***********************************************************************
70 LRESULT
StaticWndProc( HWND16 hWnd
, UINT16 uMsg
, WPARAM16 wParam
,
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 HICON16 hicon
= LoadIcon16( cs
->hInstance
, cs
->lpszName
);
91 if (!hicon
) /* Try OEM icon (FIXME: is this right?) */
92 hicon
= LoadIcon16( 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
= GetSysColor32(COLOR_WINDOWFRAME
);
108 color_background
= GetSysColor32(COLOR_BACKGROUND
);
109 color_window
= GetSysColor32(COLOR_WINDOW
);
113 if (style
== SS_ICON
)
114 DestroyIcon32( 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
= GetSysColor32(COLOR_WINDOWFRAME
);
131 color_background
= GetSysColor32(COLOR_BACKGROUND
);
132 color_window
= GetSysColor32(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
, LoadIcon16( wndPtr
->hInstance
,
142 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
143 InvalidateRect32( hWnd
, NULL
, FALSE
);
144 UpdateWindow32( hWnd
);
148 if (style
== SS_ICON
) return 0;
149 infoPtr
->hFont
= (HFONT16
)wParam
;
152 InvalidateRect32( hWnd
, NULL
, FALSE
);
153 UpdateWindow32( hWnd
);
158 return infoPtr
->hFont
;
161 return HTTRANSPARENT
;
167 return infoPtr
->hIcon
;
170 lResult
= STATIC_SetIcon( wndPtr
, (HICON16
)wParam
);
171 InvalidateRect32( hWnd
, NULL
, FALSE
);
172 UpdateWindow32( hWnd
);
176 lResult
= DefWindowProc16(hWnd
, uMsg
, wParam
, lParam
);
184 static void STATIC_PaintTextfn( WND
*wndPtr
, HDC32 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
) SelectObject32( hdc
, infoPtr
->hFont
);
225 hBrush
= SendMessage32A( GetParent32(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
226 hdc
, wndPtr
->hwndSelf
);
227 if (!hBrush
) hBrush
= GetStockObject32(WHITE_BRUSH
);
228 FillRect16(hdc
, &rc
, hBrush
);
229 if (wndPtr
->text
) DrawText16( hdc
, wndPtr
->text
, -1, &rc
, wFormat
);
232 static void STATIC_PaintRectfn( WND
*wndPtr
, HDC32 hdc
)
237 GetClientRect16( wndPtr
->hwndSelf
, &rc
);
239 switch (wndPtr
->dwStyle
& 0x0f)
242 hBrush
= CreateSolidBrush32(color_windowframe
);
243 FillRect16( hdc
, &rc
, hBrush
);
246 hBrush
= CreateSolidBrush32(color_background
);
247 FillRect16( hdc
, &rc
, hBrush
);
250 hBrush
= CreateSolidBrush32(color_window
);
251 FillRect16( hdc
, &rc
, hBrush
);
254 hBrush
= CreateSolidBrush32(color_windowframe
);
255 FrameRect16( hdc
, &rc
, hBrush
);
258 hBrush
= CreateSolidBrush32(color_background
);
259 FrameRect16( hdc
, &rc
, hBrush
);
262 hBrush
= CreateSolidBrush32(color_window
);
263 FrameRect16( hdc
, &rc
, hBrush
);
268 DeleteObject32( hBrush
);
272 static void STATIC_PaintIconfn( WND
*wndPtr
, HDC32 hdc
)
276 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
278 GetClientRect32( wndPtr
->hwndSelf
, &rc
);
279 hbrush
= SendMessage32A( GetParent32(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
280 hdc
, wndPtr
->hwndSelf
);
281 FillRect32( hdc
, &rc
, hbrush
);
282 if (infoPtr
->hIcon
) DrawIcon32( hdc
, rc
.left
, rc
.top
, infoPtr
->hIcon
);