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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * This code was audited for completeness against the documented features
23 * of Comctl32.dll version 6.0 on Oct. 4, 2004, by Dimitrie O. Paun.
25 * Unless otherwise noted, we believe this code to be complete, as per
26 * the specification mentioned above.
27 * If you discover missing features, or bugs, please note them below.
30 * - Windows XP introduced new behavior: The background of centered
31 * icons and bitmaps is painted differently. This is only done if
32 * a manifest is present.
33 * Because it has not yet been decided how to implement the two
34 * different modes in Wine, only the Windows XP mode is implemented.
35 * - Controls with SS_SIMPLE but without SS_NOPREFIX:
36 * The text should not be changed. Windows doesn't clear the
37 * client rectangle, so the new text must be larger than the old one.
38 * - The SS_RIGHTJUST style is currently not implemented by Windows
39 * (or it does something different than documented).
47 #include <wine/debug.h>
49 WINE_DEFAULT_DEBUG_CHANNEL(static);
51 static void STATIC_PaintOwnerDrawfn( HWND hwnd
, HDC hdc
, DWORD style
);
52 static void STATIC_PaintTextfn( HWND hwnd
, HDC hdc
, DWORD style
);
53 static void STATIC_PaintRectfn( HWND hwnd
, HDC hdc
, DWORD style
);
54 static void STATIC_PaintIconfn( HWND hwnd
, HDC hdc
, DWORD style
);
55 static void STATIC_PaintBitmapfn( HWND hwnd
, HDC hdc
, DWORD style
);
56 static void STATIC_PaintEnhMetafn( HWND hwnd
, HDC hdc
, DWORD style
);
57 static void STATIC_PaintEtchedfn( HWND hwnd
, HDC hdc
, DWORD style
);
58 //static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
59 //static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
61 static COLORREF color_3dshadow
, color_3ddkshadow
, color_3dhighlight
;
63 /* offsets for GetWindowLong for static private information */
64 #define HFONT_GWL_OFFSET 0
65 #define HICON_GWL_OFFSET (sizeof(HFONT))
66 #define UISTATE_GWL_OFFSET (HICON_GWL_OFFSET+sizeof(HICON))
67 #define STATIC_EXTRA_BYTES (UISTATE_GWL_OFFSET + sizeof(LONG))
69 typedef void (*pfPaint
)( HWND hwnd
, HDC hdc
, DWORD style
);
71 static const pfPaint staticPaintFunc
[SS_TYPEMASK
+1] =
73 STATIC_PaintTextfn
, /* SS_LEFT */
74 STATIC_PaintTextfn
, /* SS_CENTER */
75 STATIC_PaintTextfn
, /* SS_RIGHT */
76 STATIC_PaintIconfn
, /* SS_ICON */
77 STATIC_PaintRectfn
, /* SS_BLACKRECT */
78 STATIC_PaintRectfn
, /* SS_GRAYRECT */
79 STATIC_PaintRectfn
, /* SS_WHITERECT */
80 STATIC_PaintRectfn
, /* SS_BLACKFRAME */
81 STATIC_PaintRectfn
, /* SS_GRAYFRAME */
82 STATIC_PaintRectfn
, /* SS_WHITEFRAME */
83 NULL
, /* SS_USERITEM */
84 STATIC_PaintTextfn
, /* SS_SIMPLE */
85 STATIC_PaintTextfn
, /* SS_LEFTNOWORDWRAP */
86 STATIC_PaintOwnerDrawfn
, /* SS_OWNERDRAW */
87 STATIC_PaintBitmapfn
, /* SS_BITMAP */
88 STATIC_PaintEnhMetafn
, /* SS_ENHMETAFILE */
89 STATIC_PaintEtchedfn
, /* SS_ETCHEDHORZ */
90 STATIC_PaintEtchedfn
, /* SS_ETCHEDVERT */
91 STATIC_PaintEtchedfn
, /* SS_ETCHEDFRAME */
95 /*********************************************************************
96 * static class descriptor
98 static const WCHAR staticW
[] = {'S','t','a','t','i','c',0};
99 const struct builtin_class_descr STATIC_builtin_class
=
102 CS_DBLCLKS
| CS_PARENTDC
, /* style */
103 StaticWndProcA
, /* procA */
104 StaticWndProcW
, /* procW */
105 STATIC_EXTRA_BYTES
, /* extra */
106 IDC_ARROW
, /* cursor */
111 static __inline
void set_ui_state( HWND hwnd
, LONG flags
)
113 SetWindowLongPtrW( hwnd
, UISTATE_GWL_OFFSET
, flags
);
116 static __inline LONG
get_ui_state( HWND hwnd
)
118 return GetWindowLongPtrW( hwnd
, UISTATE_GWL_OFFSET
);
121 /* Retrieve the UI state for the control */
122 static BOOL
STATIC_update_uistate(HWND hwnd
, BOOL unicode
)
124 LONG flags
, prevflags
;
127 flags
= DefWindowProcW(hwnd
, WM_QUERYUISTATE
, 0, 0);
129 flags
= DefWindowProcA(hwnd
, WM_QUERYUISTATE
, 0, 0);
131 prevflags
= get_ui_state(hwnd
);
133 if (prevflags
!= flags
)
135 set_ui_state(hwnd
, flags
);
142 /* END REACTOS ONLY */
144 static void setup_clipping(HWND hwnd
, HDC hdc
, HRGN
*orig
)
149 /* Native control has always a clipping region set (this may be because
150 * builtin controls uses CS_PARENTDC) and an application depends on it
152 hrgn
= CreateRectRgn(0, 0, 1, 1);
153 if (GetClipRgn(hdc
, hrgn
) != 1)
160 GetClientRect(hwnd
, &rc
);
161 DPtoLP(hdc
, (POINT
*)&rc
, 2);
162 IntersectClipRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
165 static void restore_clipping(HDC hdc
, HRGN hrgn
)
167 SelectClipRgn(hdc
, hrgn
);
172 /***********************************************************************
175 * Set the icon for an SS_ICON control. Modified for ReactOS
177 static HICON
STATIC_SetIcon( HWND hwnd
, HICON hicon
, DWORD style
)
182 if ((style
& SS_TYPEMASK
) != SS_ICON
) return 0;
183 if (hicon
&& (!GetIconInfo(hicon
, &info
))) {
184 WARN("hicon != 0, but info == 0\n");
187 prevIcon
= (HICON
)SetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
, (LONG_PTR
)hicon
);
188 if (hicon
&& !(style
& SS_CENTERIMAGE
) && !(style
& SS_REALSIZECONTROL
))
192 if (!GetObjectW(info
.hbmColor
, sizeof(BITMAP
), &bm
))
197 /* Windows currently doesn't implement SS_RIGHTJUST */
199 if ((style & SS_RIGHTJUST) != 0)
202 GetWindowRect(hwnd, &wr);
203 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
204 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
208 SetWindowPos( hwnd
, 0, 0, 0, bm
.bmWidth
, bm
.bmHeight
,
209 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
215 /***********************************************************************
218 * Set the bitmap for an SS_BITMAP control. Modified for ReactOS
220 static HBITMAP
STATIC_SetBitmap( HWND hwnd
, HBITMAP hBitmap
, DWORD style
)
224 if ((style
& SS_TYPEMASK
) != SS_BITMAP
) return 0;
225 if (hBitmap
&& GetObjectType(hBitmap
) != OBJ_BITMAP
) {
226 WARN("hBitmap != 0, but it's not a bitmap\n");
229 hOldBitmap
= (HBITMAP
)SetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
, (LONG_PTR
)hBitmap
);
230 if (hBitmap
&& !(style
& SS_CENTERIMAGE
) && !(style
& SS_REALSIZECONTROL
))
233 GetObjectW(hBitmap
, sizeof(bm
), &bm
);
234 /* Windows currently doesn't implement SS_RIGHTJUST */
236 if ((style & SS_RIGHTJUST) != 0)
239 GetWindowRect(hwnd, &wr);
240 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
241 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
245 SetWindowPos( hwnd
, 0, 0, 0, bm
.bmWidth
, bm
.bmHeight
,
246 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
253 /***********************************************************************
254 * STATIC_SetEnhMetaFile
256 * Set the enhanced metafile for an SS_ENHMETAFILE control.
258 static HENHMETAFILE
STATIC_SetEnhMetaFile( HWND hwnd
, HENHMETAFILE hEnhMetaFile
, DWORD style
)
260 if ((style
& SS_TYPEMASK
) != SS_ENHMETAFILE
) return 0;
261 if (hEnhMetaFile
&& GetObjectType(hEnhMetaFile
) != OBJ_ENHMETAFILE
) {
262 WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
265 return (HENHMETAFILE
)SetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
, (LONG_PTR
)hEnhMetaFile
);
268 /***********************************************************************
271 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
272 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
274 static HANDLE
STATIC_GetImage( HWND hwnd
, WPARAM wParam
, DWORD style
)
276 switch(style
& SS_TYPEMASK
)
279 if ((wParam
!= IMAGE_ICON
) &&
280 (wParam
!= IMAGE_CURSOR
)) return NULL
;
283 if (wParam
!= IMAGE_BITMAP
) return NULL
;
286 if (wParam
!= IMAGE_ENHMETAFILE
) return NULL
;
291 return (HANDLE
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
);
294 /***********************************************************************
297 * Load the icon for an SS_ICON control.
299 static HICON
STATIC_LoadIconA( HINSTANCE hInstance
, LPCSTR name
, DWORD style
)
303 if (hInstance
&& ((ULONG_PTR
)hInstance
>> 16))
305 if ((style
& SS_REALSIZEIMAGE
) != 0)
306 hicon
= LoadImageA(hInstance
, name
, IMAGE_ICON
, 0, 0, LR_SHARED
);
309 hicon
= LoadIconA( hInstance
, name
);
310 if (!hicon
) hicon
= LoadCursorA( hInstance
, name
);
313 if (!hicon
) hicon
= LoadIconA( 0, name
);
314 /* Windows doesn't try to load a standard cursor,
315 probably because most IDs for standard cursors conflict
316 with the IDs for standard icons anyway */
320 /***********************************************************************
323 * Load the icon for an SS_ICON control.
325 static HICON
STATIC_LoadIconW( HINSTANCE hInstance
, LPCWSTR name
, DWORD style
)
329 if (hInstance
&& ((ULONG_PTR
)hInstance
>> 16))
331 if ((style
& SS_REALSIZEIMAGE
) != 0)
332 hicon
= LoadImageW(hInstance
, name
, IMAGE_ICON
, 0, 0, LR_SHARED
);
335 hicon
= LoadIconW( hInstance
, name
);
336 if (!hicon
) hicon
= LoadCursorW( hInstance
, name
);
339 if (!hicon
) hicon
= LoadIconW( 0, name
);
340 /* Windows doesn't try to load a standard cursor,
341 probably because most IDs for standard cursors conflict
342 with the IDs for standard icons anyway */
347 /***********************************************************************
350 * Try to immediately paint the control.
352 static VOID
STATIC_TryPaintFcn(HWND hwnd
, LONG full_style
)
354 LONG style
= full_style
& SS_TYPEMASK
;
357 GetClientRect( hwnd
, &rc
);
358 if (!IsRectEmpty(&rc
) && IsWindowVisible(hwnd
) && staticPaintFunc
[style
])
364 setup_clipping(hwnd
, hdc
, &hOrigClipping
);
365 (staticPaintFunc
[style
])( hwnd
, hdc
, full_style
);
366 restore_clipping(hdc
, hOrigClipping
);
367 ReleaseDC( hwnd
, hdc
);
371 static HBRUSH
STATIC_SendWmCtlColorStatic(HWND hwnd
, HDC hdc
)
374 HWND parent
= GetParent(hwnd
);
376 if (!parent
) parent
= hwnd
;
377 hBrush
= (HBRUSH
) SendMessageW( parent
,
378 WM_CTLCOLORSTATIC
, (WPARAM
)hdc
, (LPARAM
)hwnd
);
379 if (!hBrush
) /* did the app forget to call DefWindowProc ? */
381 /* FIXME: DefWindowProc should return different colors if a
382 manifest is present */
383 hBrush
= (HBRUSH
)DefWindowProcW( parent
, WM_CTLCOLORSTATIC
,
384 (WPARAM
)hdc
, (LPARAM
)hwnd
);
389 static VOID
STATIC_InitColours(void)
391 color_3ddkshadow
= GetSysColor(COLOR_3DDKSHADOW
);
392 color_3dshadow
= GetSysColor(COLOR_3DSHADOW
);
393 color_3dhighlight
= GetSysColor(COLOR_3DHIGHLIGHT
);
396 /***********************************************************************
399 * Tests if the control displays text.
401 static BOOL
hasTextStyle( DWORD style
)
403 switch(style
& SS_TYPEMASK
)
407 case SS_LEFTNOWORDWRAP
:
417 /***********************************************************************
418 * StaticWndProc_common
420 LRESULT WINAPI
StaticWndProc_common( HWND hwnd
, UINT uMsg
, WPARAM wParam
,
421 LPARAM lParam
, BOOL unicode
)
424 LONG full_style
= GetWindowLongPtrW( hwnd
, GWL_STYLE
);
425 LONG style
= full_style
& SS_TYPEMASK
;
429 pWnd
= ValidateHwnd(hwnd
);
434 NtUserSetWindowFNID(hwnd
, FNID_STATIC
);
442 if (style
< 0L || style
> SS_TYPEMASK
)
444 ERR("Unknown style 0x%02lx\n", style
);
447 STATIC_update_uistate(hwnd
, unicode
);
448 STATIC_InitColours();
453 NtUserSetWindowFNID(hwnd
, FNID_DESTROY
);
455 if (style
== SS_ICON
) {
458 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
460 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
461 * had already been loaded by the application the last thing we want to do is
462 * GlobalFree16 the handle.
466 else return unicode
? DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
) :
467 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
470 /* do all painting in WM_PAINT like Windows does */
477 HDC hdc
= wParam
? (HDC
)wParam
: BeginPaint(hwnd
, &ps
);
478 if (staticPaintFunc
[style
])
481 setup_clipping(hwnd
, hdc
, &hOrigClipping
);
482 (staticPaintFunc
[style
])( hwnd
, hdc
, full_style
);
483 restore_clipping(hdc
, hOrigClipping
);
485 if (!wParam
) EndPaint(hwnd
, &ps
);
490 STATIC_TryPaintFcn( hwnd
, full_style
);
491 if (full_style
& SS_NOTIFY
) {
493 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
494 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_ENABLE
), (LPARAM
)hwnd
);
497 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
498 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_DISABLE
), (LPARAM
)hwnd
);
503 case WM_SYSCOLORCHANGE
:
504 STATIC_InitColours();
505 STATIC_TryPaintFcn( hwnd
, full_style
);
514 if (full_style
& SS_SUNKEN
)
515 SetWindowLongPtrW( hwnd
, GWL_EXSTYLE
,
516 GetWindowLongPtrW( hwnd
, GWL_EXSTYLE
) | WS_EX_STATICEDGE
);
521 textW
= ((LPCREATESTRUCTW
)lParam
)->lpszName
;
525 textA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
530 hInstance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
537 hIcon
= STATIC_LoadIconW(hInstance
, textW
, full_style
);
539 hIcon
= STATIC_LoadIconA(hInstance
, textA
, full_style
);
540 STATIC_SetIcon(hwnd
, hIcon
, full_style
);
544 if ((ULONG_PTR
)hInstance
>> 16)
548 hBitmap
= LoadBitmapW(hInstance
, textW
);
550 hBitmap
= LoadBitmapA(hInstance
, textA
);
551 STATIC_SetBitmap(hwnd
, hBitmap
, full_style
);
555 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
556 the enhanced metafile that was specified as the window text. */
558 return unicode
? DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
) :
559 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
562 if (hasTextStyle( full_style
))
567 lResult
= DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
569 lResult
= DefWindowProcA( hwnd
, uMsg
, wParam
, lParam
);
570 STATIC_TryPaintFcn( hwnd
, full_style
);
576 if (hasTextStyle( full_style
))
578 SetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
, wParam
);
580 RedrawWindow( hwnd
, NULL
, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_ALLCHILDREN
);
585 return GetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
);
588 if (full_style
& SS_NOTIFY
)
591 return HTTRANSPARENT
;
597 case WM_NCLBUTTONDOWN
:
598 if (full_style
& SS_NOTIFY
)
599 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
600 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_CLICKED
), (LPARAM
)hwnd
);
603 case WM_LBUTTONDBLCLK
:
604 case WM_NCLBUTTONDBLCLK
:
605 if (full_style
& SS_NOTIFY
)
606 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
607 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_DBLCLK
), (LPARAM
)hwnd
);
611 return (LRESULT
)STATIC_GetImage( hwnd
, wParam
, full_style
);
614 return (LRESULT
)STATIC_GetImage( hwnd
, IMAGE_ICON
, full_style
);
619 if (style
!= SS_BITMAP
) return 0;
620 lResult
= (LRESULT
)STATIC_SetBitmap( hwnd
, (HBITMAP
)lParam
, full_style
);
622 case IMAGE_ENHMETAFILE
:
623 if (style
!= SS_ENHMETAFILE
) return 0;
624 lResult
= (LRESULT
)STATIC_SetEnhMetaFile( hwnd
, (HENHMETAFILE
)lParam
, full_style
);
628 if (style
!= SS_ICON
) return 0;
629 lResult
= (LRESULT
)STATIC_SetIcon( hwnd
, (HICON
)lParam
, full_style
);
632 FIXME("STM_SETIMAGE: Unhandled type %lx\n", wParam
);
635 STATIC_TryPaintFcn( hwnd
, full_style
);
639 lResult
= (LRESULT
)STATIC_SetIcon( hwnd
, (HICON
)wParam
, full_style
);
640 STATIC_TryPaintFcn( hwnd
, full_style
);
643 case WM_UPDATEUISTATE
:
645 DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
647 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
649 if (STATIC_update_uistate(hwnd
, unicode
) && hasTextStyle( full_style
))
651 RedrawWindow( hwnd
, NULL
, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_ALLCHILDREN
);
656 return unicode
? DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
) :
657 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
662 /***********************************************************************
665 LRESULT WINAPI
StaticWndProcA( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
667 if (!IsWindow( hWnd
)) return 0;
668 return StaticWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
671 /***********************************************************************
674 LRESULT WINAPI
StaticWndProcW( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
676 if (!IsWindow( hWnd
)) return 0;
677 return StaticWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
680 static void STATIC_PaintOwnerDrawfn( HWND hwnd
, HDC hdc
, DWORD style
)
683 HFONT font
, oldFont
= NULL
;
684 UINT id
= (UINT
)GetWindowLongPtrW( hwnd
, GWLP_ID
);
686 dis
.CtlType
= ODT_STATIC
;
689 dis
.itemAction
= ODA_DRAWENTIRE
;
690 dis
.itemState
= IsWindowEnabled(hwnd
) ? 0 : ODS_DISABLED
;
694 GetClientRect( hwnd
, &dis
.rcItem
);
696 font
= (HFONT
)GetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
);
697 if (font
) oldFont
= SelectObject( hdc
, font
);
698 SendMessageW( GetParent(hwnd
), WM_CTLCOLORSTATIC
, (WPARAM
)hdc
, (LPARAM
)hwnd
);
699 SendMessageW( GetParent(hwnd
), WM_DRAWITEM
, id
, (LPARAM
)&dis
);
700 if (font
) SelectObject( hdc
, oldFont
);
703 static void STATIC_PaintTextfn( HWND hwnd
, HDC hdc
, DWORD style
)
707 HFONT hFont
, hOldFont
= NULL
;
712 GetClientRect( hwnd
, &rc
);
714 switch (style
& SS_TYPEMASK
)
717 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
;
721 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
;
725 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
;
729 wFormat
= DT_LEFT
| DT_SINGLELINE
;
732 case SS_LEFTNOWORDWRAP
:
733 wFormat
= DT_LEFT
| DT_EXPANDTABS
;
740 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_RIGHT
)
741 wFormat
= DT_RIGHT
| (wFormat
& ~(DT_LEFT
| DT_CENTER
));
743 if (style
& SS_NOPREFIX
)
744 wFormat
|= DT_NOPREFIX
;
745 else if (get_ui_state(hwnd
) & UISF_HIDEACCEL
)
746 wFormat
|= DT_HIDEPREFIX
;
748 if ((style
& SS_TYPEMASK
) != SS_SIMPLE
)
750 if (style
& SS_CENTERIMAGE
)
751 wFormat
|= DT_SINGLELINE
| DT_VCENTER
;
752 if (style
& SS_EDITCONTROL
)
753 wFormat
|= DT_EDITCONTROL
;
754 if (style
& SS_ENDELLIPSIS
)
755 wFormat
|= DT_SINGLELINE
| DT_END_ELLIPSIS
;
756 if (style
& SS_PATHELLIPSIS
)
757 wFormat
|= DT_SINGLELINE
| DT_PATH_ELLIPSIS
;
758 if (style
& SS_WORDELLIPSIS
)
759 wFormat
|= DT_SINGLELINE
| DT_WORD_ELLIPSIS
;
762 if ((hFont
= (HFONT
)GetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
)))
763 hOldFont
= SelectObject( hdc
, hFont
);
765 /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
767 hBrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
769 if ((style
& SS_TYPEMASK
) != SS_SIMPLE
)
771 FillRect( hdc
, &rc
, hBrush
);
772 if (!IsWindowEnabled(hwnd
)) SetTextColor(hdc
, GetSysColor(COLOR_GRAYTEXT
));
776 if (!(text
= HeapAlloc( GetProcessHeap(), 0, buf_size
* sizeof(WCHAR
) )))
779 while ((len
= InternalGetWindowText( hwnd
, text
, buf_size
)) == buf_size
- 1)
782 if (!(text
= HeapReAlloc( GetProcessHeap(), 0, text
, buf_size
* sizeof(WCHAR
) )))
786 if (!len
) goto no_TextOut
;
788 if (((style
& SS_TYPEMASK
) == SS_SIMPLE
) && (style
& SS_NOPREFIX
))
790 /* Windows uses the faster ExtTextOut() to draw the text and
791 to paint the whole client rectangle with the text background
792 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
793 ExtTextOutW( hdc
, rc
.left
, rc
.top
, ETO_CLIPPED
| ETO_OPAQUE
,
794 &rc
, text
, len
, NULL
);
798 DrawTextW( hdc
, text
, -1, &rc
, wFormat
);
802 HeapFree( GetProcessHeap(), 0, text
);
805 SelectObject( hdc
, hOldFont
);
808 static void STATIC_PaintRectfn( HWND hwnd
, HDC hdc
, DWORD style
)
813 GetClientRect( hwnd
, &rc
);
815 /* FIXME: send WM_CTLCOLORSTATIC */
816 switch (style
& SS_TYPEMASK
)
819 hBrush
= CreateSolidBrush(color_3ddkshadow
);
820 FillRect( hdc
, &rc
, hBrush
);
823 hBrush
= CreateSolidBrush(color_3dshadow
);
824 FillRect( hdc
, &rc
, hBrush
);
827 hBrush
= CreateSolidBrush(color_3dhighlight
);
828 FillRect( hdc
, &rc
, hBrush
);
831 hBrush
= CreateSolidBrush(color_3ddkshadow
);
832 FrameRect( hdc
, &rc
, hBrush
);
835 hBrush
= CreateSolidBrush(color_3dshadow
);
836 FrameRect( hdc
, &rc
, hBrush
);
839 hBrush
= CreateSolidBrush(color_3dhighlight
);
840 FrameRect( hdc
, &rc
, hBrush
);
845 DeleteObject( hBrush
);
848 static void STATIC_PaintIconfn( HWND hwnd
, HDC hdc
, DWORD style
)
855 GetClientRect( hwnd
, &rc
);
856 hbrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
857 hIcon
= (HICON
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
);
858 if (!hIcon
|| !get_icon_size( hIcon
, &size
))
860 FillRect(hdc
, &rc
, hbrush
);
864 if (style
& SS_CENTERIMAGE
)
866 iconRect
.left
= (rc
.right
- rc
.left
) / 2 - size
.cx
/ 2;
867 iconRect
.top
= (rc
.bottom
- rc
.top
) / 2 - size
.cy
/ 2;
868 iconRect
.right
= iconRect
.left
+ size
.cx
;
869 iconRect
.bottom
= iconRect
.top
+ size
.cy
;
873 FillRect( hdc
, &rc
, hbrush
);
874 DrawIconEx( hdc
, iconRect
.left
, iconRect
.top
, hIcon
, iconRect
.right
- iconRect
.left
,
875 iconRect
.bottom
- iconRect
.top
, 0, NULL
, DI_NORMAL
);
879 static void STATIC_PaintBitmapfn(HWND hwnd
, HDC hdc
, DWORD style
)
882 HBITMAP hBitmap
, oldbitmap
;
885 /* message is still sent, even if the returned brush is not used */
886 hbrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
888 if ((hBitmap
= (HBITMAP
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
))
889 && (GetObjectType(hBitmap
) == OBJ_BITMAP
)
890 && (hMemDC
= CreateCompatibleDC( hdc
)))
896 GetObjectW(hBitmap
, sizeof(bm
), &bm
);
897 oldbitmap
= SelectObject(hMemDC
, hBitmap
);
899 /* Set the background color for monochrome bitmaps
900 to the color of the background brush */
901 if (GetObjectW( hbrush
, sizeof(brush
), &brush
))
903 if (brush
.lbStyle
== BS_SOLID
)
904 SetBkColor(hdc
, brush
.lbColor
);
906 GetClientRect(hwnd
, &rcClient
);
907 if (style
& SS_CENTERIMAGE
)
910 x
= (rcClient
.right
- rcClient
.left
)/2 - bm
.bmWidth
/2;
911 y
= (rcClient
.bottom
- rcClient
.top
)/2 - bm
.bmHeight
/2;
912 FillRect( hdc
, &rcClient
, hbrush
);
913 BitBlt(hdc
, x
, y
, bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0,
918 StretchBlt(hdc
, 0, 0, rcClient
.right
- rcClient
.left
,
919 rcClient
.bottom
- rcClient
.top
, hMemDC
,
920 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
922 SelectObject(hMemDC
, oldbitmap
);
928 static void STATIC_PaintEnhMetafn(HWND hwnd
, HDC hdc
, DWORD style
)
930 HENHMETAFILE hEnhMetaFile
;
934 GetClientRect(hwnd
, &rc
);
935 hbrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
936 FillRect(hdc
, &rc
, hbrush
);
937 if ((hEnhMetaFile
= (HENHMETAFILE
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
)))
939 /* The control's current font is not selected into the
941 if (GetObjectType(hEnhMetaFile
) == OBJ_ENHMETAFILE
)
942 PlayEnhMetaFile(hdc
, hEnhMetaFile
, &rc
);
947 static void STATIC_PaintEtchedfn( HWND hwnd
, HDC hdc
, DWORD style
)
951 /* FIXME: sometimes (not always) sends WM_CTLCOLORSTATIC */
952 GetClientRect( hwnd
, &rc
);
953 switch (style
& SS_TYPEMASK
)
956 DrawEdge(hdc
,&rc
,EDGE_ETCHED
,BF_TOP
|BF_BOTTOM
);
959 DrawEdge(hdc
,&rc
,EDGE_ETCHED
,BF_LEFT
|BF_RIGHT
);
962 DrawEdge (hdc
, &rc
, EDGE_ETCHED
, BF_RECT
);