4 * Copyright David W. Metcalfe, 1993
8 #include "wine/winuser16.h"
10 #include "cursoricon.h"
13 #include "debugtools.h"
16 DEFAULT_DEBUG_CHANNEL(static)
18 static void STATIC_PaintTextfn( WND
*wndPtr
, HDC hdc
);
19 static void STATIC_PaintRectfn( WND
*wndPtr
, HDC hdc
);
20 static void STATIC_PaintIconfn( WND
*wndPtr
, HDC hdc
);
21 static void STATIC_PaintBitmapfn( WND
*wndPtr
, HDC hdc
);
22 static void STATIC_PaintEtchedfn( WND
*wndPtr
, HDC hdc
);
24 static COLORREF color_windowframe
, color_background
, color_window
;
27 typedef void (*pfPaint
)( WND
*, HDC
);
29 static pfPaint staticPaintFunc
[SS_TYPEMASK
+1] =
31 STATIC_PaintTextfn
, /* SS_LEFT */
32 STATIC_PaintTextfn
, /* SS_CENTER */
33 STATIC_PaintTextfn
, /* SS_RIGHT */
34 STATIC_PaintIconfn
, /* SS_ICON */
35 STATIC_PaintRectfn
, /* SS_BLACKRECT */
36 STATIC_PaintRectfn
, /* SS_GRAYRECT */
37 STATIC_PaintRectfn
, /* SS_WHITERECT */
38 STATIC_PaintRectfn
, /* SS_BLACKFRAME */
39 STATIC_PaintRectfn
, /* SS_GRAYFRAME */
40 STATIC_PaintRectfn
, /* SS_WHITEFRAME */
41 NULL
, /* Not defined */
42 STATIC_PaintTextfn
, /* SS_SIMPLE */
43 STATIC_PaintTextfn
, /* SS_LEFTNOWORDWRAP */
44 NULL
, /* SS_OWNERDRAW */
45 STATIC_PaintBitmapfn
, /* SS_BITMAP */
46 NULL
, /* SS_ENHMETAFILE */
47 STATIC_PaintEtchedfn
, /* SS_ETCHEDHORIZ */
48 STATIC_PaintEtchedfn
, /* SS_ETCHEDVERT */
49 STATIC_PaintEtchedfn
, /* SS_ETCHEDFRAME */
53 /***********************************************************************
56 * Set the icon for an SS_ICON control.
58 static HICON16
STATIC_SetIcon( WND
*wndPtr
, HICON16 hicon
)
61 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
62 CURSORICONINFO
*info
= hicon
?(CURSORICONINFO
*) GlobalLock16( hicon
):NULL
;
64 if ((wndPtr
->dwStyle
& SS_TYPEMASK
) != SS_ICON
) return 0;
66 ERR("huh? hicon!=0, but info=0???\n");
69 prevIcon
= infoPtr
->hIcon
;
70 infoPtr
->hIcon
= hicon
;
73 SetWindowPos( wndPtr
->hwndSelf
, 0, 0, 0, info
->nWidth
, info
->nHeight
,
74 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
75 GlobalUnlock16( hicon
);
80 /***********************************************************************
83 * Set the bitmap for an SS_BITMAP control.
85 static HBITMAP16
STATIC_SetBitmap( WND
*wndPtr
, HBITMAP16 hBitmap
)
88 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
90 if ((wndPtr
->dwStyle
& SS_TYPEMASK
) != SS_BITMAP
) return 0;
91 if (hBitmap
&& GetObjectType(hBitmap
) != OBJ_BITMAP
) {
92 ERR("huh? hBitmap!=0, but not bitmap\n");
95 hOldBitmap
= infoPtr
->hIcon
;
96 infoPtr
->hIcon
= hBitmap
;
100 GetObjectA(hBitmap
, sizeof(bm
), &bm
);
101 SetWindowPos( wndPtr
->hwndSelf
, 0, 0, 0, bm
.bmWidth
, bm
.bmHeight
,
102 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
108 /***********************************************************************
111 * Load the icon for an SS_ICON control.
113 static HICON16
STATIC_LoadIcon( WND
*wndPtr
, LPCSTR name
)
117 if (wndPtr
->flags
& WIN_ISWIN32
)
119 if (!HIWORD(wndPtr
->hInstance
)) {
120 LPSTR segname
= SEGPTR_STRDUP(name
);
121 hicon
= LoadIcon16( wndPtr
->hInstance
, SEGPTR_GET(segname
) );
122 SEGPTR_FREE(segname
);
124 hicon
= LoadIconA( wndPtr
->hInstance
, name
);
126 LPSTR segname
= SEGPTR_STRDUP(name
);
128 if (HIWORD(wndPtr
->hInstance
))
129 FIXME("win16 window class, but win32 hinstance??\n");
130 hicon
= LoadIcon16( wndPtr
->hInstance
, SEGPTR_GET(segname
) );
131 SEGPTR_FREE(segname
);
134 hicon
= LoadIconA( 0, name
);
138 /***********************************************************************
141 * Load the bitmap for an SS_BITMAP control.
143 static HBITMAP16
STATIC_LoadBitmap( WND
*wndPtr
, LPCSTR name
)
147 if (wndPtr
->flags
& WIN_ISWIN32
)
149 hbitmap
= LoadBitmapA( wndPtr
->hInstance
, name
);
150 if (!hbitmap
) /* Try OEM icon (FIXME: is this right?) */
151 hbitmap
= LoadBitmapA( 0, name
);
155 LPSTR segname
= SEGPTR_STRDUP(name
);
156 hbitmap
= LoadBitmap16( wndPtr
->hInstance
, SEGPTR_GET(segname
) );
157 if (!hbitmap
) /* Try OEM icon (FIXME: is this right?) */
158 hbitmap
= LoadBitmapA( 0, segname
);
159 SEGPTR_FREE(segname
);
165 /***********************************************************************
168 LRESULT WINAPI
StaticWndProc( HWND hWnd
, UINT uMsg
, WPARAM wParam
,
172 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
173 LONG style
= wndPtr
->dwStyle
& SS_TYPEMASK
;
174 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
179 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
181 if ((TWEAK_WineLook
> WIN31_LOOK
) && (wndPtr
->dwStyle
& SS_SUNKEN
))
182 wndPtr
->dwExStyle
|= WS_EX_STATICEDGE
;
184 if (style
== SS_ICON
)
188 if (!HIWORD(cs
->lpszName
) || cs
->lpszName
[0])
189 STATIC_SetIcon( wndPtr
,
190 STATIC_LoadIcon( wndPtr
, cs
->lpszName
));
195 if (style
== SS_BITMAP
)
198 STATIC_SetBitmap( wndPtr
,
199 STATIC_LoadBitmap( wndPtr
, cs
->lpszName
));
200 WARN("style SS_BITMAP, dwStyle is 0x%08lx\n",
205 if (!HIWORD(cs
->lpszName
) && (cs
->lpszName
))
207 FIXME("windowName is 0x%04x, not doing DefWindowProc\n",
208 LOWORD(cs
->lpszName
));
212 lResult
= DefWindowProcA( hWnd
, uMsg
, wParam
, lParam
);
216 if (style
< 0L || style
> SS_TYPEMASK
)
218 ERR("Unknown style 0x%02lx\n", style
);
222 /* initialise colours */
223 color_windowframe
= GetSysColor(COLOR_WINDOWFRAME
);
224 color_background
= GetSysColor(COLOR_BACKGROUND
);
225 color_window
= GetSysColor(COLOR_WINDOW
);
229 if (style
== SS_ICON
) {
232 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
234 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
235 * had already been loaded by the application the last thing we want to do is
236 * GlobalFree16 the handle.
239 lResult
= DefWindowProcA( hWnd
, uMsg
, wParam
, lParam
);
246 BeginPaint( hWnd
, &ps
);
247 if (staticPaintFunc
[style
])
248 (staticPaintFunc
[style
])( wndPtr
, ps
.hdc
);
249 EndPaint( hWnd
, &ps
);
254 InvalidateRect( hWnd
, NULL
, FALSE
);
257 case WM_SYSCOLORCHANGE
:
258 color_windowframe
= GetSysColor(COLOR_WINDOWFRAME
);
259 color_background
= GetSysColor(COLOR_BACKGROUND
);
260 color_window
= GetSysColor(COLOR_WINDOW
);
261 InvalidateRect( hWnd
, NULL
, TRUE
);
265 if (style
== SS_ICON
)
266 /* FIXME : should we also return the previous hIcon here ??? */
267 STATIC_SetIcon( wndPtr
, STATIC_LoadIcon( wndPtr
, (LPCSTR
)lParam
));
268 else if (style
== SS_BITMAP
)
269 STATIC_SetBitmap(wndPtr
,STATIC_LoadBitmap(wndPtr
,(LPCSTR
)lParam
));
271 DEFWND_SetText( wndPtr
, (LPCSTR
)lParam
);
272 InvalidateRect( hWnd
, NULL
, FALSE
);
273 UpdateWindow( hWnd
);
277 if (style
== SS_ICON
)
282 if (style
== SS_BITMAP
)
287 infoPtr
->hFont
= (HFONT16
)wParam
;
290 InvalidateRect( hWnd
, NULL
, FALSE
);
291 UpdateWindow( hWnd
);
296 lResult
= infoPtr
->hFont
;
300 lResult
= HTTRANSPARENT
;
304 lResult
= DLGC_STATIC
;
310 lResult
= infoPtr
->hIcon
;
314 /* FIXME: handle wParam */
315 lResult
= STATIC_SetBitmap( wndPtr
, (HBITMAP
)lParam
);
316 InvalidateRect( hWnd
, NULL
, FALSE
);
317 UpdateWindow( hWnd
);
322 lResult
= STATIC_SetIcon( wndPtr
, (HICON16
)wParam
);
323 InvalidateRect( hWnd
, NULL
, FALSE
);
324 UpdateWindow( hWnd
);
328 lResult
= DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
333 WIN_ReleaseWndPtr(wndPtr
);
338 static void STATIC_PaintTextfn( WND
*wndPtr
, HDC hdc
)
344 LONG style
= wndPtr
->dwStyle
;
345 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
347 GetClientRect( wndPtr
->hwndSelf
, &rc
);
349 switch (style
& SS_TYPEMASK
)
352 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
356 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
360 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_NOCLIP
;
364 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
| DT_NOCLIP
;
367 case SS_LEFTNOWORDWRAP
:
368 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_VCENTER
;
375 if (style
& SS_NOPREFIX
)
376 wFormat
|= DT_NOPREFIX
;
378 if (infoPtr
->hFont
) SelectObject( hdc
, infoPtr
->hFont
);
379 hBrush
= SendMessageA( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
380 hdc
, wndPtr
->hwndSelf
);
381 if (!hBrush
) hBrush
= GetStockObject(WHITE_BRUSH
);
382 FillRect( hdc
, &rc
, hBrush
);
384 if (!IsWindowEnabled(wndPtr
->hwndSelf
))
385 SetTextColor(hdc
, GetSysColor(COLOR_GRAYTEXT
));
387 if (wndPtr
->text
) DrawTextA( hdc
, wndPtr
->text
, -1, &rc
, wFormat
);
390 static void STATIC_PaintRectfn( WND
*wndPtr
, HDC hdc
)
395 GetClientRect( wndPtr
->hwndSelf
, &rc
);
397 switch (wndPtr
->dwStyle
& SS_TYPEMASK
)
400 hBrush
= CreateSolidBrush(color_windowframe
);
401 FillRect( hdc
, &rc
, hBrush
);
404 hBrush
= CreateSolidBrush(color_background
);
405 FillRect( hdc
, &rc
, hBrush
);
408 hBrush
= CreateSolidBrush(color_window
);
409 FillRect( hdc
, &rc
, hBrush
);
412 hBrush
= CreateSolidBrush(color_windowframe
);
413 FrameRect( hdc
, &rc
, hBrush
);
416 hBrush
= CreateSolidBrush(color_background
);
417 FrameRect( hdc
, &rc
, hBrush
);
420 hBrush
= CreateSolidBrush(color_window
);
421 FrameRect( hdc
, &rc
, hBrush
);
426 DeleteObject( hBrush
);
430 static void STATIC_PaintIconfn( WND
*wndPtr
, HDC hdc
)
434 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
436 GetClientRect( wndPtr
->hwndSelf
, &rc
);
437 hbrush
= SendMessageA( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
438 hdc
, wndPtr
->hwndSelf
);
439 FillRect( hdc
, &rc
, hbrush
);
440 if (infoPtr
->hIcon
) DrawIcon( hdc
, rc
.left
, rc
.top
, infoPtr
->hIcon
);
443 static void STATIC_PaintBitmapfn(WND
*wndPtr
, HDC hdc
)
447 STATICINFO
*infoPtr
= (STATICINFO
*)wndPtr
->wExtra
;
451 GetClientRect( wndPtr
->hwndSelf
, &rc
);
452 hbrush
= SendMessageA( GetParent(wndPtr
->hwndSelf
), WM_CTLCOLORSTATIC
,
453 hdc
, wndPtr
->hwndSelf
);
454 FillRect( hdc
, &rc
, hbrush
);
456 if (infoPtr
->hIcon
) {
460 if(GetObjectType(infoPtr
->hIcon
) != OBJ_BITMAP
)
462 if (!(hMemDC
= CreateCompatibleDC( hdc
))) return;
463 GetObjectA(infoPtr
->hIcon
, sizeof(bm
), &bm
);
464 GetBitmapDimensionEx(infoPtr
->hIcon
, &sz
);
465 oldbitmap
= SelectObject(hMemDC
, infoPtr
->hIcon
);
466 BitBlt(hdc
, sz
.cx
, sz
.cy
, bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0,
468 SelectObject(hMemDC
, oldbitmap
);
474 static void STATIC_PaintEtchedfn( WND
*wndPtr
, HDC hdc
)
478 if (TWEAK_WineLook
== WIN31_LOOK
)
481 GetClientRect( wndPtr
->hwndSelf
, &rc
);
482 switch (wndPtr
->dwStyle
& SS_TYPEMASK
)
485 DrawEdge(hdc
,&rc
,EDGE_ETCHED
,BF_TOP
|BF_BOTTOM
);
488 DrawEdge(hdc
,&rc
,EDGE_ETCHED
,BF_LEFT
|BF_RIGHT
);
491 DrawEdge (hdc
, &rc
, EDGE_ETCHED
, BF_RECT
);