4 * Copyright David W. Metcalfe, 1993
12 #include "cursoricon.h"
17 static void STATIC_PaintTextfn( WND
*wndPtr
, HDC32 hdc
);
18 static void STATIC_PaintRectfn( WND
*wndPtr
, HDC32 hdc
);
19 static void STATIC_PaintIconfn( WND
*wndPtr
, HDC32 hdc
);
20 static void STATIC_PaintBitmapfn( WND
*wndPtr
, HDC32 hdc
);
23 static COLORREF color_windowframe
, color_background
, color_window
;
26 typedef void (*pfPaint
)( WND
*, HDC32
);
28 static pfPaint staticPaintFunc
[SS_TYPEMASK
+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 */
43 NULL
, /* SS_OWNERDRAW */
44 STATIC_PaintBitmapfn
, /* SS_BITMAP */
45 NULL
, /* SS_ENHMETAFILE */
46 NULL
, /* SS_ETCHEDHORIZ */
47 NULL
, /* SS_ETCHEDVERT */
48 NULL
, /* SS_ETCHEDFRAME */
52 /***********************************************************************
55 * Set the icon for an SS_ICON control.
57 static HICON16
STATIC_SetIcon( WND
*wndPtr
, HICON16 hicon
)
60 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
61 CURSORICONINFO
*info
= hicon
?(CURSORICONINFO
*) GlobalLock16( hicon
):NULL
;
63 if ((wndPtr
->dwStyle
& SS_TYPEMASK
) != SS_ICON
) return 0;
65 ERR(static, "huh? hicon!=0, but info=0???\n");
68 prevIcon
= infoPtr
->hIcon
;
69 infoPtr
->hIcon
= hicon
;
72 SetWindowPos32( wndPtr
->hwndSelf
, 0, 0, 0, info
->nWidth
, info
->nHeight
,
73 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
74 GlobalUnlock16( hicon
);
79 /***********************************************************************
82 * Set the bitmap for an SS_BITMAP control.
84 static HICON16
STATIC_SetBitmap( WND
*wndPtr
, HICON16 hicon
)
87 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
88 BITMAPOBJ
*info
= (BITMAPOBJ
*)GDI_HEAP_LOCK(hicon
);
90 if ((wndPtr
->dwStyle
& SS_TYPEMASK
) != SS_BITMAP
) return 0;
92 ERR(static, "huh? hicon!=0, but info=0???\n");
95 prevIcon
= infoPtr
->hIcon
;
96 infoPtr
->hIcon
= hicon
;
99 SetWindowPos32( wndPtr
->hwndSelf
, 0, 0, 0, info
->bitmap
.bmWidth
, info
->bitmap
.bmHeight
,
100 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
102 GDI_HEAP_UNLOCK( hicon
);
107 /***********************************************************************
110 * Load the icon for an SS_ICON control.
112 static HICON16
STATIC_LoadIcon( WND
*wndPtr
, LPCSTR name
)
116 if (wndPtr
->flags
& WIN_ISWIN32
)
118 hicon
= LoadIcon32A( wndPtr
->hInstance
, name
);
119 if (!hicon
) /* Try OEM icon (FIXME: is this right?) */
120 hicon
= LoadIcon32A( 0, name
);
124 LPSTR segname
= SEGPTR_STRDUP(name
);
125 hicon
= LoadIcon16( wndPtr
->hInstance
, SEGPTR_GET(segname
) );
126 if (!hicon
) /* Try OEM icon (FIXME: is this right?) */
127 hicon
= LoadIcon32A( 0, segname
);
128 SEGPTR_FREE(segname
);
133 /***********************************************************************
136 * Load the bitmap for an SS_BITMAP control.
138 static HBITMAP16
STATIC_LoadBitmap( WND
*wndPtr
, LPCSTR name
)
142 if (wndPtr
->flags
& WIN_ISWIN32
)
144 hbitmap
= LoadBitmap32A( wndPtr
->hInstance
, name
);
145 if (!hbitmap
) /* Try OEM icon (FIXME: is this right?) */
146 hbitmap
= LoadBitmap32A( 0, name
);
150 LPSTR segname
= SEGPTR_STRDUP(name
);
151 hbitmap
= LoadBitmap16( wndPtr
->hInstance
, SEGPTR_GET(segname
) );
152 if (!hbitmap
) /* Try OEM icon (FIXME: is this right?) */
153 hbitmap
= LoadBitmap32A( 0, segname
);
154 SEGPTR_FREE(segname
);
160 /***********************************************************************
163 LRESULT WINAPI
StaticWndProc( HWND32 hWnd
, UINT32 uMsg
, WPARAM32 wParam
,
167 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
168 LONG style
= wndPtr
->dwStyle
& SS_TYPEMASK
;
169 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
174 if (style
== SS_ICON
)
176 CREATESTRUCT32A
*cs
= (CREATESTRUCT32A
*)lParam
;
178 STATIC_SetIcon( wndPtr
,
179 STATIC_LoadIcon( wndPtr
, cs
->lpszName
));
182 if (style
== SS_BITMAP
)
184 CREATESTRUCT32A
*cs
= (CREATESTRUCT32A
*)lParam
;
186 STATIC_SetBitmap( wndPtr
,
187 STATIC_LoadBitmap( wndPtr
, cs
->lpszName
));
188 WARN(static, "style SS_BITMAP, dwStyle is 0x%08lx\n",
192 return DefWindowProc32A( hWnd
, uMsg
, wParam
, lParam
);
195 if (style
< 0L || style
> SS_TYPEMASK
)
197 ERR(static, "Unknown style 0x%02lx\n", style
);
201 /* initialise colours */
202 color_windowframe
= GetSysColor32(COLOR_WINDOWFRAME
);
203 color_background
= GetSysColor32(COLOR_BACKGROUND
);
204 color_window
= GetSysColor32(COLOR_WINDOW
);
208 if (style
== SS_ICON
)
209 DestroyIcon32( STATIC_SetIcon( wndPtr
, 0 ) );
211 lResult
= DefWindowProc32A( hWnd
, uMsg
, wParam
, lParam
);
217 BeginPaint32( hWnd
, &ps
);
218 if (staticPaintFunc
[style
])
219 (staticPaintFunc
[style
])( wndPtr
, ps
.hdc
);
220 EndPaint32( hWnd
, &ps
);
225 InvalidateRect32( hWnd
, NULL
, FALSE
);
228 case WM_SYSCOLORCHANGE
:
229 color_windowframe
= GetSysColor32(COLOR_WINDOWFRAME
);
230 color_background
= GetSysColor32(COLOR_BACKGROUND
);
231 color_window
= GetSysColor32(COLOR_WINDOW
);
232 InvalidateRect32( hWnd
, NULL
, TRUE
);
236 if (style
== SS_ICON
)
237 /* FIXME : should we also return the previous hIcon here ??? */
238 STATIC_SetIcon( wndPtr
, STATIC_LoadIcon( wndPtr
, (LPCSTR
)lParam
));
239 else if (style
== SS_BITMAP
)
240 STATIC_SetBitmap(wndPtr
,STATIC_LoadBitmap(wndPtr
,(LPCSTR
)lParam
));
242 DEFWND_SetText( wndPtr
, (LPCSTR
)lParam
);
243 InvalidateRect32( hWnd
, NULL
, FALSE
);
244 UpdateWindow32( hWnd
);
248 if (style
== SS_ICON
) return 0;
249 if (style
== SS_BITMAP
) return 0;
250 infoPtr
->hFont
= (HFONT16
)wParam
;
253 InvalidateRect32( hWnd
, NULL
, FALSE
);
254 UpdateWindow32( hWnd
);
259 return infoPtr
->hFont
;
262 return HTTRANSPARENT
;
267 return infoPtr
->hIcon
;
271 return infoPtr
->hIcon
;
274 /* FIXME: handle wParam */
275 lResult
= STATIC_SetBitmap( wndPtr
, (HBITMAP32
)lParam
);
276 InvalidateRect32( hWnd
, NULL
, FALSE
);
277 UpdateWindow32( hWnd
);
281 lResult
= STATIC_SetIcon( wndPtr
, (HICON16
)wParam
);
282 InvalidateRect32( hWnd
, NULL
, FALSE
);
283 UpdateWindow32( hWnd
);
287 lResult
= DefWindowProc32A(hWnd
, uMsg
, wParam
, lParam
);
295 static void STATIC_PaintTextfn( WND
*wndPtr
, HDC32 hdc
)
301 LONG style
= wndPtr
->dwStyle
;
302 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
304 GetClientRect32( wndPtr
->hwndSelf
, &rc
);
306 switch (style
& SS_TYPEMASK
)
309 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
313 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
317 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
321 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_NOCLIP
;
324 case SS_LEFTNOWORDWRAP
:
325 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_EXPANDTABS
| DT_VCENTER
| DT_NOCLIP
;
332 if (style
& SS_NOPREFIX
)
333 wFormat
|= DT_NOPREFIX
;
335 if (infoPtr
->hFont
) SelectObject32( hdc
, infoPtr
->hFont
);
336 hBrush
= SendMessage32A( GetParent32(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
337 hdc
, wndPtr
->hwndSelf
);
338 if (!hBrush
) hBrush
= GetStockObject32(WHITE_BRUSH
);
339 FillRect32( hdc
, &rc
, hBrush
);
340 if (wndPtr
->text
) DrawText32A( hdc
, wndPtr
->text
, -1, &rc
, wFormat
);
343 static void STATIC_PaintRectfn( WND
*wndPtr
, HDC32 hdc
)
348 GetClientRect32( wndPtr
->hwndSelf
, &rc
);
350 switch (wndPtr
->dwStyle
& SS_TYPEMASK
)
353 hBrush
= CreateSolidBrush32(color_windowframe
);
354 FillRect32( hdc
, &rc
, hBrush
);
357 hBrush
= CreateSolidBrush32(color_background
);
358 FillRect32( hdc
, &rc
, hBrush
);
361 hBrush
= CreateSolidBrush32(color_window
);
362 FillRect32( hdc
, &rc
, hBrush
);
365 hBrush
= CreateSolidBrush32(color_windowframe
);
366 FrameRect32( hdc
, &rc
, hBrush
);
369 hBrush
= CreateSolidBrush32(color_background
);
370 FrameRect32( hdc
, &rc
, hBrush
);
373 hBrush
= CreateSolidBrush32(color_window
);
374 FrameRect32( hdc
, &rc
, hBrush
);
379 DeleteObject32( hBrush
);
383 static void STATIC_PaintIconfn( WND
*wndPtr
, HDC32 hdc
)
387 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
389 GetClientRect32( wndPtr
->hwndSelf
, &rc
);
390 hbrush
= SendMessage32A( GetParent32(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
391 hdc
, wndPtr
->hwndSelf
);
392 FillRect32( hdc
, &rc
, hbrush
);
393 if (infoPtr
->hIcon
) DrawIcon32( hdc
, rc
.left
, rc
.top
, infoPtr
->hIcon
);
396 static void STATIC_PaintBitmapfn(WND
*wndPtr
, HDC32 hdc
)
400 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
404 GetClientRect32( wndPtr
->hwndSelf
, &rc
);
405 hbrush
= SendMessage32A( GetParent32(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
406 hdc
, wndPtr
->hwndSelf
);
407 FillRect32( hdc
, &rc
, hbrush
);
408 if (infoPtr
->hIcon
) {
409 BITMAPOBJ
*bmp
= (BITMAPOBJ
*) GDI_HEAP_LOCK( infoPtr
->hIcon
);
412 if (!(hMemDC
= CreateCompatibleDC32( hdc
))) return;
414 oldbitmap
= SelectObject32(hMemDC
,infoPtr
->hIcon
);
415 BitBlt32(hdc
,bmp
->size
.cx
,bmp
->size
.cy
,bmp
->bitmap
.bmWidth
,bmp
->bitmap
.bmHeight
,hMemDC
,0,0,SRCCOPY
);
417 GDI_HEAP_UNLOCK(infoPtr
->hIcon
);