4 * Copyright David W. Metcalfe, 1993
11 #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
);
21 static void STATIC_PaintEtchedfn( 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 STATIC_PaintEtchedfn
, /* SS_ETCHEDHORIZ */
47 STATIC_PaintEtchedfn
, /* SS_ETCHEDVERT */
48 STATIC_PaintEtchedfn
, /* 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 if (!HIWORD(wndPtr
->hInstance
)) {
119 LPSTR segname
= SEGPTR_STRDUP(name
);
120 hicon
= LoadIcon16( wndPtr
->hInstance
, SEGPTR_GET(segname
) );
121 SEGPTR_FREE(segname
);
123 hicon
= LoadIcon32A( wndPtr
->hInstance
, name
);
125 LPSTR segname
= SEGPTR_STRDUP(name
);
127 if (HIWORD(wndPtr
->hInstance
))
128 FIXME(static,"win16 window class, but win32 hinstance??\n");
129 hicon
= LoadIcon16( wndPtr
->hInstance
, SEGPTR_GET(segname
) );
130 SEGPTR_FREE(segname
);
133 hicon
= LoadIcon32A( 0, name
);
137 /***********************************************************************
140 * Load the bitmap for an SS_BITMAP control.
142 static HBITMAP16
STATIC_LoadBitmap( WND
*wndPtr
, LPCSTR name
)
146 if (wndPtr
->flags
& WIN_ISWIN32
)
148 hbitmap
= LoadBitmap32A( wndPtr
->hInstance
, name
);
149 if (!hbitmap
) /* Try OEM icon (FIXME: is this right?) */
150 hbitmap
= LoadBitmap32A( 0, name
);
154 LPSTR segname
= SEGPTR_STRDUP(name
);
155 hbitmap
= LoadBitmap16( wndPtr
->hInstance
, SEGPTR_GET(segname
) );
156 if (!hbitmap
) /* Try OEM icon (FIXME: is this right?) */
157 hbitmap
= LoadBitmap32A( 0, segname
);
158 SEGPTR_FREE(segname
);
164 /***********************************************************************
167 LRESULT WINAPI
StaticWndProc( HWND32 hWnd
, UINT32 uMsg
, WPARAM32 wParam
,
171 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
172 LONG style
= wndPtr
->dwStyle
& SS_TYPEMASK
;
173 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
178 CREATESTRUCT32A
*cs
= (CREATESTRUCT32A
*)lParam
;
180 if ((TWEAK_WineLook
> WIN31_LOOK
) && (wndPtr
->dwStyle
& SS_SUNKEN
))
181 wndPtr
->dwExStyle
|= WS_EX_STATICEDGE
;
183 if (style
== SS_ICON
)
186 STATIC_SetIcon( wndPtr
,
187 STATIC_LoadIcon( wndPtr
, cs
->lpszName
));
190 if (style
== SS_BITMAP
)
193 STATIC_SetBitmap( wndPtr
,
194 STATIC_LoadBitmap( wndPtr
, cs
->lpszName
));
195 WARN(static, "style SS_BITMAP, dwStyle is 0x%08lx\n",
199 if (!HIWORD(cs
->lpszName
) && (cs
->lpszName
)) {
200 FIXME(static,"windowName is 0x%04x, not doing DefWindowProc\n",
205 return DefWindowProc32A( hWnd
, uMsg
, wParam
, lParam
);
208 if (style
< 0L || style
> SS_TYPEMASK
)
210 ERR(static, "Unknown style 0x%02lx\n", style
);
214 /* initialise colours */
215 color_windowframe
= GetSysColor32(COLOR_WINDOWFRAME
);
216 color_background
= GetSysColor32(COLOR_BACKGROUND
);
217 color_window
= GetSysColor32(COLOR_WINDOW
);
221 if (style
== SS_ICON
)
222 DestroyIcon32( STATIC_SetIcon( wndPtr
, 0 ) );
224 lResult
= DefWindowProc32A( hWnd
, uMsg
, wParam
, lParam
);
230 BeginPaint32( hWnd
, &ps
);
231 if (staticPaintFunc
[style
])
232 (staticPaintFunc
[style
])( wndPtr
, ps
.hdc
);
233 EndPaint32( hWnd
, &ps
);
238 InvalidateRect32( hWnd
, NULL
, FALSE
);
241 case WM_SYSCOLORCHANGE
:
242 color_windowframe
= GetSysColor32(COLOR_WINDOWFRAME
);
243 color_background
= GetSysColor32(COLOR_BACKGROUND
);
244 color_window
= GetSysColor32(COLOR_WINDOW
);
245 InvalidateRect32( hWnd
, NULL
, TRUE
);
249 if (style
== SS_ICON
)
250 /* FIXME : should we also return the previous hIcon here ??? */
251 STATIC_SetIcon( wndPtr
, STATIC_LoadIcon( wndPtr
, (LPCSTR
)lParam
));
252 else if (style
== SS_BITMAP
)
253 STATIC_SetBitmap(wndPtr
,STATIC_LoadBitmap(wndPtr
,(LPCSTR
)lParam
));
255 DEFWND_SetText( wndPtr
, (LPCSTR
)lParam
);
256 InvalidateRect32( hWnd
, NULL
, FALSE
);
257 UpdateWindow32( hWnd
);
261 if (style
== SS_ICON
) return 0;
262 if (style
== SS_BITMAP
) return 0;
263 infoPtr
->hFont
= (HFONT16
)wParam
;
266 InvalidateRect32( hWnd
, NULL
, FALSE
);
267 UpdateWindow32( hWnd
);
272 return infoPtr
->hFont
;
275 return HTTRANSPARENT
;
283 return infoPtr
->hIcon
;
286 /* FIXME: handle wParam */
287 lResult
= STATIC_SetBitmap( wndPtr
, (HBITMAP32
)lParam
);
288 InvalidateRect32( hWnd
, NULL
, FALSE
);
289 UpdateWindow32( hWnd
);
294 lResult
= STATIC_SetIcon( wndPtr
, (HICON16
)wParam
);
295 InvalidateRect32( hWnd
, NULL
, FALSE
);
296 UpdateWindow32( hWnd
);
300 lResult
= DefWindowProc32A(hWnd
, uMsg
, wParam
, lParam
);
308 static void STATIC_PaintTextfn( WND
*wndPtr
, HDC32 hdc
)
314 LONG style
= wndPtr
->dwStyle
;
315 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
317 GetClientRect32( wndPtr
->hwndSelf
, &rc
);
319 switch (style
& SS_TYPEMASK
)
322 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
326 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
330 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
334 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_NOCLIP
;
337 case SS_LEFTNOWORDWRAP
:
338 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_EXPANDTABS
| DT_VCENTER
| DT_NOCLIP
;
345 if (style
& SS_NOPREFIX
)
346 wFormat
|= DT_NOPREFIX
;
348 if (infoPtr
->hFont
) SelectObject32( hdc
, infoPtr
->hFont
);
349 hBrush
= SendMessage32A( GetParent32(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
350 hdc
, wndPtr
->hwndSelf
);
351 if (!hBrush
) hBrush
= GetStockObject32(WHITE_BRUSH
);
352 FillRect32( hdc
, &rc
, hBrush
);
353 if (wndPtr
->text
) DrawText32A( hdc
, wndPtr
->text
, -1, &rc
, wFormat
);
356 static void STATIC_PaintRectfn( WND
*wndPtr
, HDC32 hdc
)
361 GetClientRect32( wndPtr
->hwndSelf
, &rc
);
363 switch (wndPtr
->dwStyle
& SS_TYPEMASK
)
366 hBrush
= CreateSolidBrush32(color_windowframe
);
367 FillRect32( hdc
, &rc
, hBrush
);
370 hBrush
= CreateSolidBrush32(color_background
);
371 FillRect32( hdc
, &rc
, hBrush
);
374 hBrush
= CreateSolidBrush32(color_window
);
375 FillRect32( hdc
, &rc
, hBrush
);
378 hBrush
= CreateSolidBrush32(color_windowframe
);
379 FrameRect32( hdc
, &rc
, hBrush
);
382 hBrush
= CreateSolidBrush32(color_background
);
383 FrameRect32( hdc
, &rc
, hBrush
);
386 hBrush
= CreateSolidBrush32(color_window
);
387 FrameRect32( hdc
, &rc
, hBrush
);
392 DeleteObject32( hBrush
);
396 static void STATIC_PaintIconfn( WND
*wndPtr
, HDC32 hdc
)
400 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
402 GetClientRect32( wndPtr
->hwndSelf
, &rc
);
403 hbrush
= SendMessage32A( GetParent32(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
404 hdc
, wndPtr
->hwndSelf
);
405 FillRect32( hdc
, &rc
, hbrush
);
406 if (infoPtr
->hIcon
) DrawIcon32( hdc
, rc
.left
, rc
.top
, infoPtr
->hIcon
);
409 static void STATIC_PaintBitmapfn(WND
*wndPtr
, HDC32 hdc
)
413 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
417 GetClientRect32( wndPtr
->hwndSelf
, &rc
);
418 hbrush
= SendMessage32A( GetParent32(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
419 hdc
, wndPtr
->hwndSelf
);
420 FillRect32( hdc
, &rc
, hbrush
);
421 if (infoPtr
->hIcon
) {
422 BITMAPOBJ
*bmp
= (BITMAPOBJ
*) GDI_HEAP_LOCK( infoPtr
->hIcon
);
425 if (!(hMemDC
= CreateCompatibleDC32( hdc
))) return;
427 oldbitmap
= SelectObject32(hMemDC
,infoPtr
->hIcon
);
428 BitBlt32(hdc
,bmp
->size
.cx
,bmp
->size
.cy
,bmp
->bitmap
.bmWidth
,bmp
->bitmap
.bmHeight
,hMemDC
,0,0,SRCCOPY
);
430 GDI_HEAP_UNLOCK(infoPtr
->hIcon
);
435 static void STATIC_PaintEtchedfn( WND
*wndPtr
, HDC32 hdc
)
441 if (TWEAK_WineLook
== WIN31_LOOK
)
444 GetClientRect32( wndPtr
->hwndSelf
, &rc
);
445 hbrush
= SendMessage32A( GetParent32(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
446 hdc
, wndPtr
->hwndSelf
);
447 FillRect32( hdc
, &rc
, hbrush
);
449 switch (wndPtr
->dwStyle
& SS_TYPEMASK
)
452 hpen
= SelectObject32 (hdc
, GetSysColorPen32 (COLOR_3DSHADOW
));
453 MoveToEx32 (hdc
, rc
.left
, rc
.bottom
/ 2 - 1, NULL
);
454 LineTo32 (hdc
, rc
.right
- 1, rc
.bottom
/ 2 - 1);
455 SelectObject32 (hdc
, GetSysColorPen32 (COLOR_3DHIGHLIGHT
));
456 MoveToEx32 (hdc
, rc
.left
, rc
.bottom
/ 2, NULL
);
457 LineTo32 (hdc
, rc
.right
, rc
.bottom
/ 2);
458 LineTo32 (hdc
, rc
.right
, rc
.bottom
/ 2 - 1);
459 SelectObject32 (hdc
, hpen
);
463 hpen
= SelectObject32 (hdc
, GetSysColorPen32 (COLOR_3DSHADOW
));
464 MoveToEx32 (hdc
, rc
.right
/ 2 - 1, rc
.top
, NULL
);
465 LineTo32 (hdc
, rc
.right
/ 2 - 1, rc
.bottom
- 1);
466 SelectObject32 (hdc
, GetSysColorPen32 (COLOR_3DHIGHLIGHT
));
467 MoveToEx32 (hdc
, rc
.right
/ 2, rc
.top
, NULL
);
468 LineTo32 (hdc
, rc
.right
/ 2, rc
.bottom
);
469 LineTo32 (hdc
, rc
.right
/ 2 -1 , rc
.bottom
);
470 SelectObject32 (hdc
, hpen
);
474 DrawEdge32 (hdc
, &rc
, EDGE_ETCHED
, BF_RECT
);