4 * Copyright David W. Metcalfe, 1993
10 #include "wine/winuser16.h"
12 #include "cursoricon.h"
15 #include "debugtools.h"
18 DEFAULT_DEBUG_CHANNEL(static)
20 static void STATIC_PaintOwnerDrawfn( WND
*wndPtr
, HDC hdc
);
21 static void STATIC_PaintTextfn( WND
*wndPtr
, HDC hdc
);
22 static void STATIC_PaintRectfn( WND
*wndPtr
, HDC hdc
);
23 static void STATIC_PaintIconfn( WND
*wndPtr
, HDC hdc
);
24 static void STATIC_PaintBitmapfn( WND
*wndPtr
, HDC hdc
);
25 static void STATIC_PaintEtchedfn( WND
*wndPtr
, HDC hdc
);
27 static COLORREF color_windowframe
, color_background
, color_window
;
30 typedef void (*pfPaint
)( WND
*, HDC
);
32 static pfPaint staticPaintFunc
[SS_TYPEMASK
+1] =
34 STATIC_PaintTextfn
, /* SS_LEFT */
35 STATIC_PaintTextfn
, /* SS_CENTER */
36 STATIC_PaintTextfn
, /* SS_RIGHT */
37 STATIC_PaintIconfn
, /* SS_ICON */
38 STATIC_PaintRectfn
, /* SS_BLACKRECT */
39 STATIC_PaintRectfn
, /* SS_GRAYRECT */
40 STATIC_PaintRectfn
, /* SS_WHITERECT */
41 STATIC_PaintRectfn
, /* SS_BLACKFRAME */
42 STATIC_PaintRectfn
, /* SS_GRAYFRAME */
43 STATIC_PaintRectfn
, /* SS_WHITEFRAME */
44 NULL
, /* Not defined */
45 STATIC_PaintTextfn
, /* SS_SIMPLE */
46 STATIC_PaintTextfn
, /* SS_LEFTNOWORDWRAP */
47 STATIC_PaintOwnerDrawfn
, /* SS_OWNERDRAW */
48 STATIC_PaintBitmapfn
, /* SS_BITMAP */
49 NULL
, /* SS_ENHMETAFILE */
50 STATIC_PaintEtchedfn
, /* SS_ETCHEDHORIZ */
51 STATIC_PaintEtchedfn
, /* SS_ETCHEDVERT */
52 STATIC_PaintEtchedfn
, /* SS_ETCHEDFRAME */
56 /***********************************************************************
59 * Set the icon for an SS_ICON control.
61 static HICON16
STATIC_SetIcon( WND
*wndPtr
, HICON16 hicon
)
64 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
65 CURSORICONINFO
*info
= hicon
?(CURSORICONINFO
*) GlobalLock16( hicon
):NULL
;
67 if ((wndPtr
->dwStyle
& SS_TYPEMASK
) != SS_ICON
) return 0;
69 ERR("huh? hicon!=0, but info=0???\n");
72 prevIcon
= infoPtr
->hIcon
;
73 infoPtr
->hIcon
= hicon
;
76 SetWindowPos( wndPtr
->hwndSelf
, 0, 0, 0, info
->nWidth
, info
->nHeight
,
77 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
78 GlobalUnlock16( hicon
);
83 /***********************************************************************
86 * Set the bitmap for an SS_BITMAP control.
88 static HBITMAP16
STATIC_SetBitmap( WND
*wndPtr
, HBITMAP16 hBitmap
)
91 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
93 if ((wndPtr
->dwStyle
& SS_TYPEMASK
) != SS_BITMAP
) return 0;
94 if (hBitmap
&& GetObjectType(hBitmap
) != OBJ_BITMAP
) {
95 ERR("huh? hBitmap!=0, but not bitmap\n");
98 hOldBitmap
= infoPtr
->hIcon
;
99 infoPtr
->hIcon
= hBitmap
;
103 GetObjectA(hBitmap
, sizeof(bm
), &bm
);
104 SetWindowPos( wndPtr
->hwndSelf
, 0, 0, 0, bm
.bmWidth
, bm
.bmHeight
,
105 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
111 /***********************************************************************
114 * Load the icon for an SS_ICON control.
116 static HICON16
STATIC_LoadIcon( WND
*wndPtr
, LPCSTR name
)
120 if (wndPtr
->flags
& WIN_ISWIN32
)
122 if (!HIWORD(wndPtr
->hInstance
)) {
123 LPSTR segname
= SEGPTR_STRDUP(name
);
124 hicon
= LoadIcon16( wndPtr
->hInstance
, SEGPTR_GET(segname
) );
125 SEGPTR_FREE(segname
);
127 hicon
= LoadIconA( wndPtr
->hInstance
, name
);
129 LPSTR segname
= SEGPTR_STRDUP(name
);
131 if (HIWORD(wndPtr
->hInstance
))
132 FIXME("win16 window class, but win32 hinstance??\n");
133 hicon
= LoadIcon16( wndPtr
->hInstance
, SEGPTR_GET(segname
) );
134 SEGPTR_FREE(segname
);
137 hicon
= LoadIconA( 0, name
);
141 /***********************************************************************
144 * Load the bitmap for an SS_BITMAP control.
146 static HBITMAP16
STATIC_LoadBitmap( WND
*wndPtr
, LPCSTR name
)
150 if (wndPtr
->flags
& WIN_ISWIN32
)
152 hbitmap
= LoadBitmapA( wndPtr
->hInstance
, name
);
153 if (!hbitmap
) /* Try OEM icon (FIXME: is this right?) */
154 hbitmap
= LoadBitmapA( 0, name
);
158 LPSTR segname
= SEGPTR_STRDUP(name
);
159 hbitmap
= LoadBitmap16( wndPtr
->hInstance
, SEGPTR_GET(segname
) );
160 if (!hbitmap
) /* Try OEM icon (FIXME: is this right?) */
161 hbitmap
= LoadBitmapA( 0, segname
);
162 SEGPTR_FREE(segname
);
168 /***********************************************************************
171 LRESULT WINAPI
StaticWndProc( HWND hWnd
, UINT uMsg
, WPARAM wParam
,
175 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
176 LONG style
= wndPtr
->dwStyle
& SS_TYPEMASK
;
177 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
182 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
184 if ((TWEAK_WineLook
> WIN31_LOOK
) && (wndPtr
->dwStyle
& SS_SUNKEN
))
185 wndPtr
->dwExStyle
|= WS_EX_STATICEDGE
;
187 if (style
== SS_ICON
)
191 if (!HIWORD(cs
->lpszName
) || cs
->lpszName
[0])
192 STATIC_SetIcon( wndPtr
,
193 STATIC_LoadIcon( wndPtr
, cs
->lpszName
));
198 if (style
== SS_BITMAP
)
201 STATIC_SetBitmap( wndPtr
,
202 STATIC_LoadBitmap( wndPtr
, cs
->lpszName
));
203 WARN("style SS_BITMAP, dwStyle is 0x%08lx\n",
208 if (!HIWORD(cs
->lpszName
) && (cs
->lpszName
))
210 FIXME("windowName is 0x%04x, not doing DefWindowProc\n",
211 LOWORD(cs
->lpszName
));
215 lResult
= DefWindowProcA( hWnd
, uMsg
, wParam
, lParam
);
219 if (style
< 0L || style
> SS_TYPEMASK
)
221 ERR("Unknown style 0x%02lx\n", style
);
225 /* initialise colours */
226 color_windowframe
= GetSysColor(COLOR_WINDOWFRAME
);
227 color_background
= GetSysColor(COLOR_BACKGROUND
);
228 color_window
= GetSysColor(COLOR_WINDOW
);
232 if (style
== SS_ICON
) {
235 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
237 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
238 * had already been loaded by the application the last thing we want to do is
239 * GlobalFree16 the handle.
242 lResult
= DefWindowProcA( hWnd
, uMsg
, wParam
, lParam
);
249 BeginPaint( hWnd
, &ps
);
250 if (staticPaintFunc
[style
])
251 (staticPaintFunc
[style
])( wndPtr
, ps
.hdc
);
252 EndPaint( hWnd
, &ps
);
257 InvalidateRect( hWnd
, NULL
, FALSE
);
260 case WM_SYSCOLORCHANGE
:
261 color_windowframe
= GetSysColor(COLOR_WINDOWFRAME
);
262 color_background
= GetSysColor(COLOR_BACKGROUND
);
263 color_window
= GetSysColor(COLOR_WINDOW
);
264 InvalidateRect( hWnd
, NULL
, TRUE
);
268 if (style
== SS_ICON
)
269 /* FIXME : should we also return the previous hIcon here ??? */
270 STATIC_SetIcon( wndPtr
, STATIC_LoadIcon( wndPtr
, (LPCSTR
)lParam
));
271 else if (style
== SS_BITMAP
)
272 STATIC_SetBitmap(wndPtr
,STATIC_LoadBitmap(wndPtr
,(LPCSTR
)lParam
));
274 DEFWND_SetTextA( wndPtr
, (LPCSTR
)lParam
);
275 InvalidateRect( hWnd
, NULL
, FALSE
);
279 if (style
== SS_ICON
)
284 if (style
== SS_BITMAP
)
289 infoPtr
->hFont
= (HFONT16
)wParam
;
292 InvalidateRect( hWnd
, NULL
, FALSE
);
293 UpdateWindow( hWnd
);
298 lResult
= infoPtr
->hFont
;
302 if (wndPtr
->dwStyle
& SS_NOTIFY
)
305 lResult
= HTTRANSPARENT
;
309 lResult
= DLGC_STATIC
;
315 lResult
= infoPtr
->hIcon
;
321 lResult
= STATIC_SetBitmap( wndPtr
, (HBITMAP
)lParam
);
324 lResult
= STATIC_SetIcon( wndPtr
, (HICON16
)lParam
);
327 FIXME("STM_SETIMAGE: Unhandled type %x\n", wParam
);
330 InvalidateRect( hWnd
, NULL
, FALSE
);
331 UpdateWindow( hWnd
);
336 lResult
= STATIC_SetIcon( wndPtr
, (HICON16
)wParam
);
337 InvalidateRect( hWnd
, NULL
, FALSE
);
338 UpdateWindow( hWnd
);
342 lResult
= DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
347 WIN_ReleaseWndPtr(wndPtr
);
351 static void STATIC_PaintOwnerDrawfn( WND
*wndPtr
, HDC hdc
)
355 dis
.CtlType
= ODT_STATIC
;
356 dis
.CtlID
= wndPtr
->wIDmenu
;
358 dis
.itemAction
= ODA_DRAWENTIRE
;
360 dis
.hwndItem
= wndPtr
->hwndSelf
;
363 GetClientRect( wndPtr
->hwndSelf
, &dis
.rcItem
);
365 SendMessageA( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
366 hdc
, wndPtr
->hwndSelf
);
367 SendMessageA( GetParent(wndPtr
->hwndSelf
), WM_DRAWITEM
,
368 wndPtr
->wIDmenu
, (LPARAM
)&dis
);
371 static void STATIC_PaintTextfn( WND
*wndPtr
, HDC hdc
)
377 LONG style
= wndPtr
->dwStyle
;
378 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
380 GetClientRect( wndPtr
->hwndSelf
, &rc
);
382 switch (style
& SS_TYPEMASK
)
385 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
389 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
393 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
397 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_NOCLIP
;
400 case SS_LEFTNOWORDWRAP
:
401 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_VCENTER
;
408 if (style
& SS_NOPREFIX
)
409 wFormat
|= DT_NOPREFIX
;
411 if (infoPtr
->hFont
) SelectObject( hdc
, infoPtr
->hFont
);
413 if ((style
& SS_NOPREFIX
) || ((style
& SS_TYPEMASK
) != SS_SIMPLE
))
415 hBrush
= SendMessageA( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
416 hdc
, wndPtr
->hwndSelf
);
417 if (!hBrush
) hBrush
= GetStockObject(WHITE_BRUSH
);
418 FillRect( hdc
, &rc
, hBrush
);
420 if (!IsWindowEnabled(wndPtr
->hwndSelf
))
421 SetTextColor(hdc
, GetSysColor(COLOR_GRAYTEXT
));
423 if (wndPtr
->text
) DrawTextW( hdc
, wndPtr
->text
, -1, &rc
, wFormat
);
426 static void STATIC_PaintRectfn( WND
*wndPtr
, HDC hdc
)
431 GetClientRect( wndPtr
->hwndSelf
, &rc
);
433 switch (wndPtr
->dwStyle
& SS_TYPEMASK
)
436 hBrush
= CreateSolidBrush(color_windowframe
);
437 FillRect( hdc
, &rc
, hBrush
);
440 hBrush
= CreateSolidBrush(color_background
);
441 FillRect( hdc
, &rc
, hBrush
);
444 hBrush
= CreateSolidBrush(color_window
);
445 FillRect( hdc
, &rc
, hBrush
);
448 hBrush
= CreateSolidBrush(color_windowframe
);
449 FrameRect( hdc
, &rc
, hBrush
);
452 hBrush
= CreateSolidBrush(color_background
);
453 FrameRect( hdc
, &rc
, hBrush
);
456 hBrush
= CreateSolidBrush(color_window
);
457 FrameRect( hdc
, &rc
, hBrush
);
462 DeleteObject( hBrush
);
466 static void STATIC_PaintIconfn( WND
*wndPtr
, HDC hdc
)
470 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
472 GetClientRect( wndPtr
->hwndSelf
, &rc
);
473 hbrush
= SendMessageA( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
474 hdc
, wndPtr
->hwndSelf
);
475 FillRect( hdc
, &rc
, hbrush
);
476 if (infoPtr
->hIcon
) DrawIcon( hdc
, rc
.left
, rc
.top
, infoPtr
->hIcon
);
479 static void STATIC_PaintBitmapfn(WND
*wndPtr
, HDC hdc
)
483 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
487 GetClientRect( wndPtr
->hwndSelf
, &rc
);
488 hbrush
= SendMessageA( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
489 hdc
, wndPtr
->hwndSelf
);
490 FillRect( hdc
, &rc
, hbrush
);
492 if (infoPtr
->hIcon
) {
496 if(GetObjectType(infoPtr
->hIcon
) != OBJ_BITMAP
)
498 if (!(hMemDC
= CreateCompatibleDC( hdc
))) return;
499 GetObjectA(infoPtr
->hIcon
, sizeof(bm
), &bm
);
500 GetBitmapDimensionEx(infoPtr
->hIcon
, &sz
);
501 oldbitmap
= SelectObject(hMemDC
, infoPtr
->hIcon
);
502 BitBlt(hdc
, sz
.cx
, sz
.cy
, bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0,
504 SelectObject(hMemDC
, oldbitmap
);
510 static void STATIC_PaintEtchedfn( WND
*wndPtr
, HDC hdc
)
514 if (TWEAK_WineLook
== WIN31_LOOK
)
517 GetClientRect( wndPtr
->hwndSelf
, &rc
);
518 switch (wndPtr
->dwStyle
& SS_TYPEMASK
)
521 DrawEdge(hdc
,&rc
,EDGE_ETCHED
,BF_TOP
|BF_BOTTOM
);
524 DrawEdge(hdc
,&rc
,EDGE_ETCHED
,BF_LEFT
|BF_RIGHT
);
527 DrawEdge (hdc
, &rc
, EDGE_ETCHED
, BF_RECT
);