4 * Copyright David W. Metcalfe, 1993
8 #include "wine/winuser16.h"
11 #include "cursoricon.h"
14 #include "debugtools.h"
17 DEFAULT_DEBUG_CHANNEL(static)
19 static void STATIC_PaintTextfn( WND
*wndPtr
, HDC hdc
);
20 static void STATIC_PaintRectfn( WND
*wndPtr
, HDC hdc
);
21 static void STATIC_PaintIconfn( WND
*wndPtr
, HDC hdc
);
22 static void STATIC_PaintBitmapfn( WND
*wndPtr
, HDC hdc
);
23 static void STATIC_PaintEtchedfn( WND
*wndPtr
, HDC hdc
);
25 static COLORREF color_windowframe
, color_background
, color_window
;
28 typedef void (*pfPaint
)( WND
*, HDC
);
30 static pfPaint staticPaintFunc
[SS_TYPEMASK
+1] =
32 STATIC_PaintTextfn
, /* SS_LEFT */
33 STATIC_PaintTextfn
, /* SS_CENTER */
34 STATIC_PaintTextfn
, /* SS_RIGHT */
35 STATIC_PaintIconfn
, /* SS_ICON */
36 STATIC_PaintRectfn
, /* SS_BLACKRECT */
37 STATIC_PaintRectfn
, /* SS_GRAYRECT */
38 STATIC_PaintRectfn
, /* SS_WHITERECT */
39 STATIC_PaintRectfn
, /* SS_BLACKFRAME */
40 STATIC_PaintRectfn
, /* SS_GRAYFRAME */
41 STATIC_PaintRectfn
, /* SS_WHITEFRAME */
42 NULL
, /* Not defined */
43 STATIC_PaintTextfn
, /* SS_SIMPLE */
44 STATIC_PaintTextfn
, /* SS_LEFTNOWORDWRAP */
45 NULL
, /* SS_OWNERDRAW */
46 STATIC_PaintBitmapfn
, /* SS_BITMAP */
47 NULL
, /* SS_ENHMETAFILE */
48 STATIC_PaintEtchedfn
, /* SS_ETCHEDHORIZ */
49 STATIC_PaintEtchedfn
, /* SS_ETCHEDVERT */
50 STATIC_PaintEtchedfn
, /* SS_ETCHEDFRAME */
54 /***********************************************************************
57 * Set the icon for an SS_ICON control.
59 static HICON16
STATIC_SetIcon( WND
*wndPtr
, HICON16 hicon
)
62 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
63 CURSORICONINFO
*info
= hicon
?(CURSORICONINFO
*) GlobalLock16( hicon
):NULL
;
65 if ((wndPtr
->dwStyle
& SS_TYPEMASK
) != SS_ICON
) return 0;
67 ERR("huh? hicon!=0, but info=0???\n");
70 prevIcon
= infoPtr
->hIcon
;
71 infoPtr
->hIcon
= hicon
;
74 SetWindowPos( wndPtr
->hwndSelf
, 0, 0, 0, info
->nWidth
, info
->nHeight
,
75 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
76 GlobalUnlock16( hicon
);
81 /***********************************************************************
84 * Set the bitmap for an SS_BITMAP control.
86 static HICON16
STATIC_SetBitmap( WND
*wndPtr
, HICON16 hicon
)
89 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
90 BITMAPOBJ
*info
= (BITMAPOBJ
*)GDI_HEAP_LOCK(hicon
);
92 if ((wndPtr
->dwStyle
& SS_TYPEMASK
) != SS_BITMAP
) return 0;
94 ERR("huh? hicon!=0, but info=0???\n");
97 prevIcon
= infoPtr
->hIcon
;
98 infoPtr
->hIcon
= hicon
;
101 SetWindowPos( wndPtr
->hwndSelf
, 0, 0, 0, info
->bitmap
.bmWidth
, info
->bitmap
.bmHeight
,
102 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
104 GDI_HEAP_UNLOCK( hicon
);
109 /***********************************************************************
112 * Load the icon for an SS_ICON control.
114 static HICON16
STATIC_LoadIcon( WND
*wndPtr
, LPCSTR name
)
118 if (wndPtr
->flags
& WIN_ISWIN32
)
120 if (!HIWORD(wndPtr
->hInstance
)) {
121 LPSTR segname
= SEGPTR_STRDUP(name
);
122 hicon
= LoadIcon16( wndPtr
->hInstance
, SEGPTR_GET(segname
) );
123 SEGPTR_FREE(segname
);
125 hicon
= LoadIconA( wndPtr
->hInstance
, name
);
127 LPSTR segname
= SEGPTR_STRDUP(name
);
129 if (HIWORD(wndPtr
->hInstance
))
130 FIXME("win16 window class, but win32 hinstance??\n");
131 hicon
= LoadIcon16( wndPtr
->hInstance
, SEGPTR_GET(segname
) );
132 SEGPTR_FREE(segname
);
135 hicon
= LoadIconA( 0, name
);
139 /***********************************************************************
142 * Load the bitmap for an SS_BITMAP control.
144 static HBITMAP16
STATIC_LoadBitmap( WND
*wndPtr
, LPCSTR name
)
148 if (wndPtr
->flags
& WIN_ISWIN32
)
150 hbitmap
= LoadBitmapA( wndPtr
->hInstance
, name
);
151 if (!hbitmap
) /* Try OEM icon (FIXME: is this right?) */
152 hbitmap
= LoadBitmapA( 0, name
);
156 LPSTR segname
= SEGPTR_STRDUP(name
);
157 hbitmap
= LoadBitmap16( wndPtr
->hInstance
, SEGPTR_GET(segname
) );
158 if (!hbitmap
) /* Try OEM icon (FIXME: is this right?) */
159 hbitmap
= LoadBitmapA( 0, segname
);
160 SEGPTR_FREE(segname
);
166 /***********************************************************************
169 LRESULT WINAPI
StaticWndProc( HWND hWnd
, UINT uMsg
, WPARAM wParam
,
173 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
174 LONG style
= wndPtr
->dwStyle
& SS_TYPEMASK
;
175 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
180 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
182 if ((TWEAK_WineLook
> WIN31_LOOK
) && (wndPtr
->dwStyle
& SS_SUNKEN
))
183 wndPtr
->dwExStyle
|= WS_EX_STATICEDGE
;
185 if (style
== SS_ICON
)
189 if (!HIWORD(cs
->lpszName
) || cs
->lpszName
[0])
190 STATIC_SetIcon( wndPtr
,
191 STATIC_LoadIcon( wndPtr
, cs
->lpszName
));
196 if (style
== SS_BITMAP
)
199 STATIC_SetBitmap( wndPtr
,
200 STATIC_LoadBitmap( wndPtr
, cs
->lpszName
));
201 WARN("style SS_BITMAP, dwStyle is 0x%08lx\n",
206 if (!HIWORD(cs
->lpszName
) && (cs
->lpszName
))
208 FIXME("windowName is 0x%04x, not doing DefWindowProc\n",
209 LOWORD(cs
->lpszName
));
213 lResult
= DefWindowProcA( hWnd
, uMsg
, wParam
, lParam
);
217 if (style
< 0L || style
> SS_TYPEMASK
)
219 ERR("Unknown style 0x%02lx\n", style
);
223 /* initialise colours */
224 color_windowframe
= GetSysColor(COLOR_WINDOWFRAME
);
225 color_background
= GetSysColor(COLOR_BACKGROUND
);
226 color_window
= GetSysColor(COLOR_WINDOW
);
230 if (style
== SS_ICON
) {
233 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
235 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
236 * had already been loaded by the application the last thing we want to do is
237 * GlobalFree16 the handle.
240 lResult
= DefWindowProcA( hWnd
, uMsg
, wParam
, lParam
);
247 BeginPaint( hWnd
, &ps
);
248 if (staticPaintFunc
[style
])
249 (staticPaintFunc
[style
])( wndPtr
, ps
.hdc
);
250 EndPaint( hWnd
, &ps
);
255 InvalidateRect( hWnd
, NULL
, FALSE
);
258 case WM_SYSCOLORCHANGE
:
259 color_windowframe
= GetSysColor(COLOR_WINDOWFRAME
);
260 color_background
= GetSysColor(COLOR_BACKGROUND
);
261 color_window
= GetSysColor(COLOR_WINDOW
);
262 InvalidateRect( hWnd
, NULL
, TRUE
);
266 if (style
== SS_ICON
)
267 /* FIXME : should we also return the previous hIcon here ??? */
268 STATIC_SetIcon( wndPtr
, STATIC_LoadIcon( wndPtr
, (LPCSTR
)lParam
));
269 else if (style
== SS_BITMAP
)
270 STATIC_SetBitmap(wndPtr
,STATIC_LoadBitmap(wndPtr
,(LPCSTR
)lParam
));
272 DEFWND_SetText( wndPtr
, (LPCSTR
)lParam
);
273 InvalidateRect( hWnd
, NULL
, FALSE
);
274 UpdateWindow( hWnd
);
278 if (style
== SS_ICON
)
283 if (style
== SS_BITMAP
)
288 infoPtr
->hFont
= (HFONT16
)wParam
;
291 InvalidateRect( hWnd
, NULL
, FALSE
);
292 UpdateWindow( hWnd
);
297 lResult
= infoPtr
->hFont
;
301 lResult
= HTTRANSPARENT
;
305 lResult
= DLGC_STATIC
;
311 lResult
= infoPtr
->hIcon
;
315 /* FIXME: handle wParam */
316 lResult
= STATIC_SetBitmap( wndPtr
, (HBITMAP
)lParam
);
317 InvalidateRect( hWnd
, NULL
, FALSE
);
318 UpdateWindow( hWnd
);
323 lResult
= STATIC_SetIcon( wndPtr
, (HICON16
)wParam
);
324 InvalidateRect( hWnd
, NULL
, FALSE
);
325 UpdateWindow( hWnd
);
329 lResult
= DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
334 WIN_ReleaseWndPtr(wndPtr
);
339 static void STATIC_PaintTextfn( WND
*wndPtr
, HDC hdc
)
345 LONG style
= wndPtr
->dwStyle
;
346 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
348 GetClientRect( wndPtr
->hwndSelf
, &rc
);
350 switch (style
& SS_TYPEMASK
)
353 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
357 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
361 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
365 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_NOCLIP
;
368 case SS_LEFTNOWORDWRAP
:
369 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_VCENTER
;
376 if (style
& SS_NOPREFIX
)
377 wFormat
|= DT_NOPREFIX
;
379 if (infoPtr
->hFont
) SelectObject( hdc
, infoPtr
->hFont
);
380 hBrush
= SendMessageA( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
381 hdc
, wndPtr
->hwndSelf
);
382 if (!hBrush
) hBrush
= GetStockObject(WHITE_BRUSH
);
383 FillRect( hdc
, &rc
, hBrush
);
384 if (wndPtr
->text
) DrawTextA( hdc
, wndPtr
->text
, -1, &rc
, wFormat
);
387 static void STATIC_PaintRectfn( WND
*wndPtr
, HDC hdc
)
392 GetClientRect( wndPtr
->hwndSelf
, &rc
);
394 switch (wndPtr
->dwStyle
& SS_TYPEMASK
)
397 hBrush
= CreateSolidBrush(color_windowframe
);
398 FillRect( hdc
, &rc
, hBrush
);
401 hBrush
= CreateSolidBrush(color_background
);
402 FillRect( hdc
, &rc
, hBrush
);
405 hBrush
= CreateSolidBrush(color_window
);
406 FillRect( hdc
, &rc
, hBrush
);
409 hBrush
= CreateSolidBrush(color_windowframe
);
410 FrameRect( hdc
, &rc
, hBrush
);
413 hBrush
= CreateSolidBrush(color_background
);
414 FrameRect( hdc
, &rc
, hBrush
);
417 hBrush
= CreateSolidBrush(color_window
);
418 FrameRect( hdc
, &rc
, hBrush
);
423 DeleteObject( hBrush
);
427 static void STATIC_PaintIconfn( WND
*wndPtr
, HDC hdc
)
431 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
433 GetClientRect( wndPtr
->hwndSelf
, &rc
);
434 hbrush
= SendMessageA( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
435 hdc
, wndPtr
->hwndSelf
);
436 FillRect( hdc
, &rc
, hbrush
);
437 if (infoPtr
->hIcon
) DrawIcon( hdc
, rc
.left
, rc
.top
, infoPtr
->hIcon
);
440 static void STATIC_PaintBitmapfn(WND
*wndPtr
, HDC hdc
)
444 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
448 GetClientRect( wndPtr
->hwndSelf
, &rc
);
449 hbrush
= SendMessageA( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
450 hdc
, wndPtr
->hwndSelf
);
451 FillRect( hdc
, &rc
, hbrush
);
452 if (infoPtr
->hIcon
) {
453 BITMAPOBJ
*bmp
= (BITMAPOBJ
*) GDI_HEAP_LOCK( infoPtr
->hIcon
);
456 if (!(hMemDC
= CreateCompatibleDC( hdc
))) return;
458 oldbitmap
= SelectObject(hMemDC
,infoPtr
->hIcon
);
459 BitBlt(hdc
,bmp
->size
.cx
,bmp
->size
.cy
,bmp
->bitmap
.bmWidth
,bmp
->bitmap
.bmHeight
,hMemDC
,0,0,SRCCOPY
);
461 GDI_HEAP_UNLOCK(infoPtr
->hIcon
);
466 static void STATIC_PaintEtchedfn( WND
*wndPtr
, HDC hdc
)
472 if (TWEAK_WineLook
== WIN31_LOOK
)
475 GetClientRect( wndPtr
->hwndSelf
, &rc
);
476 hbrush
= SendMessageA( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
477 hdc
, wndPtr
->hwndSelf
);
478 FillRect( hdc
, &rc
, hbrush
);
480 switch (wndPtr
->dwStyle
& SS_TYPEMASK
)
483 hpen
= SelectObject (hdc
, GetSysColorPen (COLOR_3DSHADOW
));
484 MoveToEx (hdc
, rc
.left
, rc
.bottom
/ 2 - 1, NULL
);
485 LineTo (hdc
, rc
.right
- 1, rc
.bottom
/ 2 - 1);
486 SelectObject (hdc
, GetSysColorPen (COLOR_3DHIGHLIGHT
));
487 MoveToEx (hdc
, rc
.left
, rc
.bottom
/ 2, NULL
);
488 LineTo (hdc
, rc
.right
, rc
.bottom
/ 2);
489 LineTo (hdc
, rc
.right
, rc
.bottom
/ 2 - 1);
490 SelectObject (hdc
, hpen
);
494 hpen
= SelectObject (hdc
, GetSysColorPen (COLOR_3DSHADOW
));
495 MoveToEx (hdc
, rc
.right
/ 2 - 1, rc
.top
, NULL
);
496 LineTo (hdc
, rc
.right
/ 2 - 1, rc
.bottom
- 1);
497 SelectObject (hdc
, GetSysColorPen (COLOR_3DHIGHLIGHT
));
498 MoveToEx (hdc
, rc
.right
/ 2, rc
.top
, NULL
);
499 LineTo (hdc
, rc
.right
/ 2, rc
.bottom
);
500 LineTo (hdc
, rc
.right
/ 2 -1 , rc
.bottom
);
501 SelectObject (hdc
, hpen
);
505 DrawEdge (hdc
, &rc
, EDGE_ETCHED
, BF_RECT
);