4 * Copyright David W. Metcalfe, 1993
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 WINE_DEFAULT_DEBUG_CHANNEL(static);
27 static void STATIC_PaintOwnerDrawfn( HWND hwnd
, HDC hdc
, DWORD style
);
28 static void STATIC_PaintTextfn( HWND hwnd
, HDC hdc
, DWORD style
);
29 static void STATIC_PaintRectfn( HWND hwnd
, HDC hdc
, DWORD style
);
30 static void STATIC_PaintIconfn( HWND hwnd
, HDC hdc
, DWORD style
);
31 static void STATIC_PaintBitmapfn( HWND hwnd
, HDC hdc
, DWORD style
);
32 static void STATIC_PaintEtchedfn( HWND hwnd
, HDC hdc
, DWORD style
);
33 static LRESULT WINAPI
StaticWndProcA( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
34 static LRESULT WINAPI
StaticWndProcW( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
36 static COLORREF color_3dshadow
, color_3ddkshadow
, color_3dhighlight
;
38 /* offsets for GetWindowLong for static private information */
39 #define HFONT_GWL_OFFSET 0
40 #define HICON_GWL_OFFSET (sizeof(HFONT))
41 #define STATIC_EXTRA_BYTES (HICON_GWL_OFFSET + sizeof(HICON))
43 typedef void (*pfPaint
)( HWND hwnd
, HDC hdc
, DWORD style
);
45 static pfPaint staticPaintFunc
[SS_TYPEMASK
+1] =
47 STATIC_PaintTextfn
, /* SS_LEFT */
48 STATIC_PaintTextfn
, /* SS_CENTER */
49 STATIC_PaintTextfn
, /* SS_RIGHT */
50 STATIC_PaintIconfn
, /* SS_ICON */
51 STATIC_PaintRectfn
, /* SS_BLACKRECT */
52 STATIC_PaintRectfn
, /* SS_GRAYRECT */
53 STATIC_PaintRectfn
, /* SS_WHITERECT */
54 STATIC_PaintRectfn
, /* SS_BLACKFRAME */
55 STATIC_PaintRectfn
, /* SS_GRAYFRAME */
56 STATIC_PaintRectfn
, /* SS_WHITEFRAME */
57 NULL
, /* SS_USERITEM */
58 STATIC_PaintTextfn
, /* SS_SIMPLE */
59 STATIC_PaintTextfn
, /* SS_LEFTNOWORDWRAP */
60 STATIC_PaintOwnerDrawfn
, /* SS_OWNERDRAW */
61 STATIC_PaintBitmapfn
, /* SS_BITMAP */
62 NULL
, /* SS_ENHMETAFILE */
63 STATIC_PaintEtchedfn
, /* SS_ETCHEDHORIZ */
64 STATIC_PaintEtchedfn
, /* SS_ETCHEDVERT */
65 STATIC_PaintEtchedfn
, /* SS_ETCHEDFRAME */
69 /*********************************************************************
70 * static class descriptor
72 const struct builtin_class_descr STATIC_builtin_class
=
76 CS_DBLCLKS
| CS_PARENTDC
, /* style */
77 (WNDPROC
) StaticWndProcW
, /* procW */
78 (WNDPROC
) StaticWndProcA
, /* procA */
79 STATIC_EXTRA_BYTES
, /* extra */
80 (LPCWSTR
) IDC_ARROW
, /* cursor */ /* FIXME Wine uses IDC_ARROWA */
84 CS_DBLCLKS
| CS_PARENTDC
, /* style */
85 StaticWndProcA
, /* procA */
86 StaticWndProcW
, /* procW */
87 STATIC_EXTRA_BYTES
, /* extra */
88 IDC_ARROW
, /* cursor */
94 /***********************************************************************
97 * Set the icon for an SS_ICON control.
99 static HICON
STATIC_SetIcon( HWND hwnd
, HICON hicon
, DWORD style
)
104 if ((style
& SS_TYPEMASK
) != SS_ICON
) return 0;
105 prevIcon
= (HICON
)SetWindowLongA( hwnd
, HICON_GWL_OFFSET
, (LONG
)hicon
);
106 if (hicon
&& !(style
& SS_CENTERIMAGE
))
111 if (!GetIconInfo(hicon
, &info
))
115 if (!GetObjectW(info
.hbmColor
, sizeof(BITMAP
), &bm
))
119 SetWindowPos( hwnd
, 0, 0, 0, bm
.bmWidth
, bm
.bmHeight
,
120 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
125 CURSORICONINFO
*info
= hicon
?(CURSORICONINFO
*) GlobalLock16(HICON_16(hicon
)):NULL
;
127 if ((style
& SS_TYPEMASK
) != SS_ICON
) return 0;
128 if (hicon
&& !info
) {
129 ERR("huh? hicon!=0, but info=0???\n");
132 prevIcon
= (HICON
)SetWindowLongA( hwnd
, HICON_GWL_OFFSET
, (LONG
)hicon
);
133 if (hicon
&& !(style
& SS_CENTERIMAGE
))
135 SetWindowPos( hwnd
, 0, 0, 0, info
->nWidth
, info
->nHeight
,
136 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
137 GlobalUnlock16(HICON_16(hicon
));
143 /***********************************************************************
146 * Set the bitmap for an SS_BITMAP control.
148 static HBITMAP
STATIC_SetBitmap( HWND hwnd
, HBITMAP hBitmap
, DWORD style
)
152 if ((style
& SS_TYPEMASK
) != SS_BITMAP
) return 0;
153 if (hBitmap
&& GetObjectType(hBitmap
) != OBJ_BITMAP
) {
155 OutputDebugStringA("huh? hBitmap!=0, but not bitmap\n");
157 ERR("huh? hBitmap!=0, but not bitmap\n");
161 hOldBitmap
= (HBITMAP
)SetWindowLongA( hwnd
, HICON_GWL_OFFSET
, (LONG
)hBitmap
);
162 if (hBitmap
&& !(style
& SS_CENTERIMAGE
))
165 GetObjectW(hBitmap
, sizeof(bm
), &bm
);
166 SetWindowPos( hwnd
, 0, 0, 0, bm
.bmWidth
, bm
.bmHeight
,
167 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
172 /***********************************************************************
175 * Load the icon for an SS_ICON control.
177 static HICON
STATIC_LoadIconA( HWND hwnd
, LPCSTR name
)
179 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongA( hwnd
, GWL_HINSTANCE
);
180 HICON hicon
= LoadIconA( hInstance
, name
);
181 if (!hicon
) hicon
= LoadIconA( 0, name
);
185 /***********************************************************************
188 * Load the icon for an SS_ICON control.
190 static HICON
STATIC_LoadIconW( HWND hwnd
, LPCWSTR name
)
192 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongA( hwnd
, GWL_HINSTANCE
);
193 HICON hicon
= LoadIconW( hInstance
, name
);
194 if (!hicon
) hicon
= LoadIconW( 0, name
);
198 /***********************************************************************
201 * Load the bitmap for an SS_BITMAP control.
203 static HBITMAP
STATIC_LoadBitmapA( HWND hwnd
, LPCSTR name
)
205 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongA( hwnd
, GWL_HINSTANCE
);
206 HBITMAP hbitmap
= LoadBitmapA( hInstance
, name
);
207 if (!hbitmap
) /* Try OEM icon (FIXME: is this right?) */
208 hbitmap
= LoadBitmapA( 0, name
);
212 /***********************************************************************
215 * Load the bitmap for an SS_BITMAP control.
217 static HBITMAP
STATIC_LoadBitmapW( HWND hwnd
, LPCWSTR name
)
219 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongA( hwnd
, GWL_HINSTANCE
);
220 HBITMAP hbitmap
= LoadBitmapW( hInstance
, name
);
221 if (!hbitmap
) /* Try OEM icon (FIXME: is this right?) */
222 hbitmap
= LoadBitmapW( 0, name
);
226 /***********************************************************************
229 * Try to immediately paint the control.
231 static VOID
STATIC_TryPaintFcn(HWND hwnd
, LONG full_style
)
233 LONG style
= full_style
& SS_TYPEMASK
;
236 GetClientRect( hwnd
, &rc
);
237 if (!IsRectEmpty(&rc
) && IsWindowVisible(hwnd
) && staticPaintFunc
[style
])
241 (staticPaintFunc
[style
])( hwnd
, hdc
, full_style
);
242 ReleaseDC( hwnd
, hdc
);
246 static VOID
STATIC_InitColours()
248 color_3ddkshadow
= GetSysColor(COLOR_3DDKSHADOW
);
249 color_3dshadow
= GetSysColor(COLOR_3DSHADOW
);
250 color_3dhighlight
= GetSysColor(COLOR_3DHIGHLIGHT
);
253 /***********************************************************************
254 * StaticWndProc_common
256 static LRESULT
StaticWndProc_common( HWND hwnd
, UINT uMsg
, WPARAM wParam
,
257 LPARAM lParam
, BOOL unicode
)
260 LONG full_style
= GetWindowLongA( hwnd
, GWL_STYLE
);
261 LONG style
= full_style
& SS_TYPEMASK
;
266 if (style
< 0L || style
> SS_TYPEMASK
)
269 OutputDebugStringA("Unknown style\n");
271 ERR("Unknown style 0x%02lx\n", style
);
275 STATIC_InitColours();
279 if (style
== SS_ICON
) {
282 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
284 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
285 * had already been loaded by the application the last thing we want to do is
286 * GlobalFree16 the handle.
290 else return unicode
? DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
) :
291 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
296 HDC hdc
= wParam
? (HDC
)wParam
: BeginPaint(hwnd
, &ps
);
297 if (staticPaintFunc
[style
])
298 (staticPaintFunc
[style
])( hwnd
, hdc
, full_style
);
299 if (!wParam
) EndPaint(hwnd
, &ps
);
304 InvalidateRect(hwnd
, NULL
, TRUE
);
307 case WM_SYSCOLORCHANGE
:
308 STATIC_InitColours();
309 InvalidateRect(hwnd
, NULL
, TRUE
);
313 if (full_style
& SS_SUNKEN
)
314 SetWindowLongA( hwnd
, GWL_EXSTYLE
,
315 GetWindowLongA( hwnd
, GWL_EXSTYLE
) | WS_EX_STATICEDGE
);
318 lParam
= (LPARAM
)(((LPCREATESTRUCTW
)lParam
)->lpszName
);
320 lParam
= (LPARAM
)(((LPCREATESTRUCTA
)lParam
)->lpszName
);
328 hIcon
= STATIC_LoadIconW(hwnd
, (LPCWSTR
)lParam
);
330 hIcon
= STATIC_LoadIconA(hwnd
, (LPCSTR
)lParam
);
331 /* FIXME : should we also return the previous hIcon here ??? */
332 STATIC_SetIcon(hwnd
, hIcon
, full_style
);
339 hBitmap
= STATIC_LoadBitmapW(hwnd
, (LPCWSTR
)lParam
);
341 hBitmap
= STATIC_LoadBitmapA(hwnd
, (LPCSTR
)lParam
);
342 STATIC_SetBitmap(hwnd
, hBitmap
, full_style
);
349 case SS_LEFTNOWORDWRAP
:
354 lResult
= DefWindowProcW( hwnd
, WM_SETTEXT
, wParam
, lParam
);
356 lResult
= DefWindowProcA( hwnd
, WM_SETTEXT
, wParam
, lParam
);
358 if (uMsg
== WM_SETTEXT
)
359 STATIC_TryPaintFcn( hwnd
, full_style
);
366 lResult
= DefWindowProcW( hwnd
, WM_SETTEXT
, wParam
, lParam
);
368 lResult
= DefWindowProcA( hwnd
, WM_SETTEXT
, wParam
, lParam
);
370 if(uMsg
== WM_SETTEXT
)
371 InvalidateRect(hwnd
, NULL
, TRUE
);
373 return 1; /* success. FIXME: check text length */
376 if ((style
== SS_ICON
) || (style
== SS_BITMAP
)) return 0;
377 SetWindowLongA( hwnd
, HFONT_GWL_OFFSET
, wParam
);
379 InvalidateRect( hwnd
, NULL
, TRUE
);
383 return GetWindowLongA( hwnd
, HFONT_GWL_OFFSET
);
386 if (full_style
& SS_NOTIFY
)
389 return HTTRANSPARENT
;
395 case WM_NCLBUTTONDOWN
:
396 if (full_style
& SS_NOTIFY
)
397 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
398 MAKEWPARAM( GetWindowLongW(hwnd
,GWL_ID
), STN_CLICKED
), (LPARAM
)hwnd
);
401 case WM_LBUTTONDBLCLK
:
402 case WM_NCLBUTTONDBLCLK
:
403 if (full_style
& SS_NOTIFY
)
404 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
405 MAKEWPARAM( GetWindowLongW(hwnd
,GWL_ID
), STN_DBLCLK
), (LPARAM
)hwnd
);
413 return GetWindowLongA( hwnd
, HICON_GWL_OFFSET
);
418 lResult
= (LRESULT
)STATIC_SetBitmap( hwnd
, (HBITMAP
)lParam
, full_style
);
421 lResult
= (LRESULT
)STATIC_SetIcon( hwnd
, (HICON
)lParam
, full_style
);
425 FIXME("STM_SETIMAGE: Unhandled type %x\n", wParam
);
429 InvalidateRect( hwnd
, NULL
, TRUE
);
436 lResult
= (LRESULT
)STATIC_SetIcon( hwnd
, (HICON
)wParam
, full_style
);
437 InvalidateRect( hwnd
, NULL
, TRUE
);
441 return unicode
? DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
) :
442 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
447 /***********************************************************************
450 static LRESULT WINAPI
StaticWndProcA( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
452 if (!IsWindow( hWnd
)) return 0;
453 return StaticWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
456 /***********************************************************************
459 static LRESULT WINAPI
StaticWndProcW( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
461 if (!IsWindow( hWnd
)) return 0;
462 return StaticWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
465 static void STATIC_PaintOwnerDrawfn( HWND hwnd
, HDC hdc
, DWORD style
)
468 LONG id
= GetWindowLongA( hwnd
, GWL_ID
);
470 dis
.CtlType
= ODT_STATIC
;
473 dis
.itemAction
= ODA_DRAWENTIRE
;
478 GetClientRect( hwnd
, &dis
.rcItem
);
480 SendMessageW( GetParent(hwnd
), WM_CTLCOLORSTATIC
, (WPARAM
)hdc
, (LPARAM
)hwnd
);
481 SendMessageW( GetParent(hwnd
), WM_DRAWITEM
, id
, (LPARAM
)&dis
);
484 static void STATIC_PaintTextfn( HWND hwnd
, HDC hdc
, DWORD style
)
493 GetClientRect( hwnd
, &rc
);
495 switch (style
& SS_TYPEMASK
)
498 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
;
502 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
;
506 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
;
510 wFormat
= DT_LEFT
| DT_SINGLELINE
| DT_VCENTER
;
513 case SS_LEFTNOWORDWRAP
:
514 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_VCENTER
;
521 if (style
& SS_NOPREFIX
)
522 wFormat
|= DT_NOPREFIX
;
523 if (style
& SS_CENTERIMAGE
)
524 wFormat
|= DT_VCENTER
;
526 if ((hFont
= (HFONT
)GetWindowLongA( hwnd
, HFONT_GWL_OFFSET
))) SelectObject( hdc
, hFont
);
528 if ((style
& SS_NOPREFIX
) || ((style
& SS_TYPEMASK
) != SS_SIMPLE
))
530 hBrush
= (HBRUSH
)SendMessageW( GetParent(hwnd
), WM_CTLCOLORSTATIC
,
531 (WPARAM
)hdc
, (LPARAM
)hwnd
);
532 if (!hBrush
) /* did the app forget to call defwindowproc ? */
533 hBrush
= (HBRUSH
)DefWindowProcW(GetParent(hwnd
), WM_CTLCOLORSTATIC
,
534 (WPARAM
)hdc
, (LPARAM
)hwnd
);
535 FillRect( hdc
, &rc
, hBrush
);
537 if (!IsWindowEnabled(hwnd
)) SetTextColor(hdc
, GetSysColor(COLOR_GRAYTEXT
));
539 if (!(len
= SendMessageW( hwnd
, WM_GETTEXTLENGTH
, 0, 0 ))) return;
540 if (!(text
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) ))) return;
541 SendMessageW( hwnd
, WM_GETTEXT
, len
+ 1, (LPARAM
)text
);
542 DrawTextW( hdc
, text
, -1, &rc
, wFormat
);
543 HeapFree( GetProcessHeap(), 0, text
);
546 static void STATIC_PaintRectfn( HWND hwnd
, HDC hdc
, DWORD style
)
551 GetClientRect( hwnd
, &rc
);
553 switch (style
& SS_TYPEMASK
)
556 hBrush
= CreateSolidBrush(color_3ddkshadow
);
557 FillRect( hdc
, &rc
, hBrush
);
560 hBrush
= CreateSolidBrush(color_3dshadow
);
561 FillRect( hdc
, &rc
, hBrush
);
564 hBrush
= CreateSolidBrush(color_3dhighlight
);
565 FillRect( hdc
, &rc
, hBrush
);
568 hBrush
= CreateSolidBrush(color_3ddkshadow
);
569 FrameRect( hdc
, &rc
, hBrush
);
572 hBrush
= CreateSolidBrush(color_3dshadow
);
573 FrameRect( hdc
, &rc
, hBrush
);
576 hBrush
= CreateSolidBrush(color_3dhighlight
);
577 FrameRect( hdc
, &rc
, hBrush
);
582 DeleteObject( hBrush
);
586 static void STATIC_PaintIconfn( HWND hwnd
, HDC hdc
, DWORD style
)
593 GetClientRect( hwnd
, &rc
);
594 hbrush
= (HBRUSH
)SendMessageW( GetParent(hwnd
), WM_CTLCOLORSTATIC
,
595 (WPARAM
)hdc
, (LPARAM
)hwnd
);
596 FillRect( hdc
, &rc
, hbrush
);
597 hIcon
= (HICON
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
);
598 if (style
& SS_CENTERIMAGE
)
601 CURSORICONINFO
*info
= hIcon
? (CURSORICONINFO
*)GlobalLock16(HICON_16(hIcon
)) : NULL
;
602 x
= (rc
.right
- rc
.left
)/2 - (info
? info
->nWidth
/2 : 0);
603 y
= (rc
.bottom
- rc
.top
)/2 - (info
? info
->nHeight
/2 : 0);
608 if (!GetIconInfo(hIcon
, &info
))
610 if (!GetObjectW(info
.hbmColor
, sizeof(BITMAP
), &bm
))
612 x
= (rc
.right
- rc
.left
)/2 - bm
.bmWidth
/2;
613 y
= (rc
.bottom
- rc
.top
)/2 - bm
.bmHeight
/2;
622 DrawIcon( hdc
, x
, y
, hIcon
);
625 static void STATIC_PaintBitmapfn(HWND hwnd
, HDC hdc
, DWORD style
)
628 HBITMAP hBitmap
, oldbitmap
;
630 /* message is still sent, even if the returned brush is not used */
631 SendMessageW( GetParent(hwnd
), WM_CTLCOLORSTATIC
,
632 (WPARAM
)hdc
, (LPARAM
)hwnd
);
634 if ((hBitmap
= (HBITMAP
)GetWindowLongA( hwnd
, HICON_GWL_OFFSET
)))
639 if(GetObjectType(hBitmap
) != OBJ_BITMAP
) return;
640 if (!(hMemDC
= CreateCompatibleDC( hdc
))) return;
641 GetObjectW(hBitmap
, sizeof(bm
), &bm
);
642 oldbitmap
= SelectObject(hMemDC
, hBitmap
);
643 if (style
& SS_CENTERIMAGE
)
646 GetClientRect(hwnd
, &rcClient
);
647 x
= (rcClient
.right
- rcClient
.left
)/2 - bm
.bmWidth
/2;
648 y
= (rcClient
.bottom
- rcClient
.top
)/2 - bm
.bmHeight
/2;
655 BitBlt(hdc
, x
, y
, bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0,
657 SelectObject(hMemDC
, oldbitmap
);
663 static void STATIC_PaintEtchedfn( HWND hwnd
, HDC hdc
, DWORD style
)
667 GetClientRect( hwnd
, &rc
);
668 switch (style
& SS_TYPEMASK
)
671 DrawEdge(hdc
,&rc
,EDGE_ETCHED
,BF_TOP
|BF_BOTTOM
);
674 DrawEdge(hdc
,&rc
,EDGE_ETCHED
,BF_LEFT
|BF_RIGHT
);
677 DrawEdge (hdc
, &rc
, EDGE_ETCHED
, BF_RECT
);