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
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 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 NULL
, /* 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 const struct builtin_class_descr STATIC_builtin_class
=
101 L
"Static", /* name */
102 CS_DBLCLKS
| CS_PARENTDC
, /* style */
103 (WNDPROC
) StaticWndProcW
, /* procW */
104 (WNDPROC
) StaticWndProcA
, /* procA */
105 STATIC_EXTRA_BYTES
, /* extra */
106 (LPCWSTR
) IDC_ARROW
, /* cursor */ /* FIXME Wine uses IDC_ARROWA */
110 CS_DBLCLKS
| CS_PARENTDC
, /* style */
111 StaticWndProcA
, /* procA */
112 StaticWndProcW
, /* procW */
113 STATIC_EXTRA_BYTES
, /* extra */
114 IDC_ARROW
, /* cursor */
119 static __inline
void set_ui_state( HWND hwnd
, LONG flags
)
121 SetWindowLongW( hwnd
, UISTATE_GWL_OFFSET
, flags
);
124 static __inline LONG
get_ui_state( HWND hwnd
)
126 return GetWindowLongPtrW( hwnd
, UISTATE_GWL_OFFSET
);
129 static void setup_clipping(HWND hwnd
, HDC hdc
, HRGN
*orig
)
134 /* Native control has always a clipping region set (this may be because
135 * builtin controls uses CS_PARENTDC) and an application depends on it
137 hrgn
= CreateRectRgn(0, 0, 1, 1);
138 if (GetClipRgn(hdc
, hrgn
) != 1)
145 GetClientRect(hwnd
, &rc
);
146 DPtoLP(hdc
, (POINT
*)&rc
, 2);
147 IntersectClipRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
150 static void restore_clipping(HDC hdc
, HRGN hrgn
)
152 SelectClipRgn(hdc
, hrgn
);
157 /* Retrieve the UI state for the control */
158 static BOOL
STATIC_update_uistate(HWND hwnd
, BOOL unicode
)
160 LONG flags
, prevflags
;
163 flags
= DefWindowProcW(hwnd
, WM_QUERYUISTATE
, 0, 0);
165 flags
= DefWindowProcA(hwnd
, WM_QUERYUISTATE
, 0, 0);
167 prevflags
= get_ui_state(hwnd
);
169 if (prevflags
!= flags
)
171 set_ui_state(hwnd
, flags
);
178 /***********************************************************************
181 * Set the icon for an SS_ICON control. Modified for ReactOS
183 static HICON
STATIC_SetIcon( HWND hwnd
, HICON hicon
, DWORD style
)
188 if ((style
& SS_TYPEMASK
) != SS_ICON
) return 0;
189 if (hicon
&& (!GetIconInfo(hicon
, &info
))) {
190 WARN("hicon != 0, but info == 0\n");
193 prevIcon
= (HICON
)SetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
, (LONG_PTR
)hicon
);
194 if (hicon
&& !(style
& SS_CENTERIMAGE
) && !(style
& SS_REALSIZECONTROL
))
198 if (!GetObjectW(info
.hbmColor
, sizeof(BITMAP
), &bm
))
203 /* Windows currently doesn't implement SS_RIGHTJUST */
205 if ((style & SS_RIGHTJUST) != 0)
208 GetWindowRect(hwnd, &wr);
209 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
210 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
214 NtUserSetWindowPos( hwnd
, 0, 0, 0, bm
.bmWidth
, bm
.bmHeight
,
215 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
221 /***********************************************************************
224 * Set the bitmap for an SS_BITMAP control. Modified for ReactOS
226 static HBITMAP
STATIC_SetBitmap( HWND hwnd
, HBITMAP hBitmap
, DWORD style
)
230 if ((style
& SS_TYPEMASK
) != SS_BITMAP
) return 0;
231 if (hBitmap
&& GetObjectType(hBitmap
) != OBJ_BITMAP
) {
232 WARN("hBitmap != 0, but it's not a bitmap\n");
235 hOldBitmap
= (HBITMAP
)SetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
, (LONG_PTR
)hBitmap
);
236 if (hBitmap
&& !(style
& SS_CENTERIMAGE
) && !(style
& SS_REALSIZECONTROL
))
239 GetObjectW(hBitmap
, sizeof(bm
), &bm
);
240 /* Windows currently doesn't implement SS_RIGHTJUST */
242 if ((style & SS_RIGHTJUST) != 0)
245 GetWindowRect(hwnd, &wr);
246 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
247 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
251 NtUserSetWindowPos( hwnd
, 0, 0, 0, bm
.bmWidth
, bm
.bmHeight
,
252 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
258 /***********************************************************************
259 * STATIC_SetEnhMetaFile
261 * Set the enhanced metafile for an SS_ENHMETAFILE control.
263 //static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
265 // if ((style & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
266 // if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE) {
267 // WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
270 // return (HENHMETAFILE)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hEnhMetaFile );
273 /***********************************************************************
276 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
277 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
279 static HANDLE
STATIC_GetImage( HWND hwnd
, WPARAM wParam
, DWORD style
)
281 switch(style
& SS_TYPEMASK
)
284 if ((wParam
!= IMAGE_ICON
) &&
285 (wParam
!= IMAGE_CURSOR
)) return NULL
;
288 if (wParam
!= IMAGE_BITMAP
) return NULL
;
291 if (wParam
!= IMAGE_ENHMETAFILE
) return NULL
;
296 return (HANDLE
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
);
299 /***********************************************************************
302 * Load the icon for an SS_ICON control.
304 static HICON
STATIC_LoadIconA( HWND hwnd
, LPCSTR name
, DWORD style
)
306 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
307 if ((style
& SS_REALSIZEIMAGE
) != 0)
309 return LoadImageA(hInstance
, name
, IMAGE_ICON
, 0, 0, LR_SHARED
);
313 HICON hicon
= LoadIconA( hInstance
, name
);
314 if (!hicon
) hicon
= LoadCursorA( hInstance
, name
);
315 if (!hicon
) hicon
= LoadIconA( 0, name
);
316 /* Windows doesn't try to load a standard cursor,
317 probably because most IDs for standard cursors conflict
318 with the IDs for standard icons anyway */
323 /***********************************************************************
326 * Load the icon for an SS_ICON control.
328 static HICON
STATIC_LoadIconW( HWND hwnd
, LPCWSTR name
, DWORD style
)
330 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
331 if ((style
& SS_REALSIZEIMAGE
) != 0)
333 return LoadImageW(hInstance
, name
, IMAGE_ICON
, 0, 0, LR_SHARED
);
337 HICON hicon
= LoadIconW( hInstance
, name
);
338 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 * Load the bitmap for an SS_BITMAP control.
352 static HBITMAP
STATIC_LoadBitmapA( HWND hwnd
, LPCSTR name
)
354 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
355 /* Windows doesn't try to load OEM Bitmaps (hInstance == NULL) */
356 return LoadBitmapA( hInstance
, name
);
359 /***********************************************************************
362 * Load the bitmap for an SS_BITMAP control.
364 static HBITMAP
STATIC_LoadBitmapW( HWND hwnd
, LPCWSTR name
)
366 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
367 /* Windows doesn't try to load OEM Bitmaps (hInstance == NULL) */
368 return LoadBitmapW( hInstance
, name
);
371 /***********************************************************************
374 * Try to immediately paint the control.
376 static VOID
STATIC_TryPaintFcn(HWND hwnd
, LONG full_style
)
378 LONG style
= full_style
& SS_TYPEMASK
;
381 GetClientRect( hwnd
, &rc
);
382 if (!IsRectEmpty(&rc
) && IsWindowVisible(hwnd
) && staticPaintFunc
[style
])
387 hdc
= NtUserGetDC( hwnd
);
388 setup_clipping(hwnd
, hdc
, &hOrigClipping
);
389 (staticPaintFunc
[style
])( hwnd
, hdc
, full_style
);
390 restore_clipping(hdc
, hOrigClipping
);
391 ReleaseDC( hwnd
, hdc
);
395 static HBRUSH
STATIC_SendWmCtlColorStatic(HWND hwnd
, HDC hdc
)
398 HWND parent
= GetParent(hwnd
);
400 if(!parent
) parent
= hwnd
;
401 hBrush
= (HBRUSH
) SendMessageW( GetParent(hwnd
),
402 WM_CTLCOLORSTATIC
, (WPARAM
)hdc
, (LPARAM
)hwnd
);
403 if (!hBrush
) /* did the app forget to call DefWindowProc ? */
405 /* FIXME: DefWindowProc should return different colors if a
406 manifest is present */
407 hBrush
= (HBRUSH
)DefWindowProcW(GetParent(hwnd
), WM_CTLCOLORSTATIC
,
408 (WPARAM
)hdc
, (LPARAM
)hwnd
);
413 static VOID
STATIC_InitColours(void)
415 color_3ddkshadow
= GetSysColor(COLOR_3DDKSHADOW
);
416 color_3dshadow
= GetSysColor(COLOR_3DSHADOW
);
417 color_3dhighlight
= GetSysColor(COLOR_3DHIGHLIGHT
);
420 /***********************************************************************
423 * Tests if the control displays text.
425 static BOOL
hasTextStyle( DWORD style
)
427 switch(style
& SS_TYPEMASK
)
431 case SS_LEFTNOWORDWRAP
:
441 /***********************************************************************
442 * StaticWndProc_common
444 static LRESULT
StaticWndProc_common( HWND hwnd
, UINT uMsg
, WPARAM wParam
,
445 LPARAM lParam
, BOOL unicode
)
448 LONG full_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
449 LONG style
= full_style
& SS_TYPEMASK
;
454 if (style
< 0L || style
> SS_TYPEMASK
)
456 ERR("Unknown style 0x%02lx\n", style
);
459 STATIC_update_uistate(hwnd
, unicode
);
460 STATIC_InitColours();
464 if (style
== SS_ICON
) {
467 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
469 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
470 * had already been loaded by the application the last thing we want to do is
471 * GlobalFree16 the handle.
475 else return unicode
? DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
) :
476 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
479 /* do all painting in WM_PAINT like Windows does */
486 HDC hdc
= wParam
? (HDC
)wParam
: NtUserBeginPaint(hwnd
, &ps
);
487 if (staticPaintFunc
[style
])
490 setup_clipping(hwnd
, hdc
, &hOrigClipping
);
491 (staticPaintFunc
[style
])( hwnd
, hdc
, full_style
);
492 restore_clipping(hdc
, hOrigClipping
);
494 if (!wParam
) NtUserEndPaint(hwnd
, &ps
);
499 STATIC_TryPaintFcn( hwnd
, full_style
);
500 if (full_style
& SS_NOTIFY
) {
502 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
503 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_ENABLE
), (LPARAM
)hwnd
);
506 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
507 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_DISABLE
), (LPARAM
)hwnd
);
512 case WM_SYSCOLORCHANGE
:
513 STATIC_InitColours();
514 STATIC_TryPaintFcn( hwnd
, full_style
);
522 if (full_style
& SS_SUNKEN
)
523 SetWindowLongW( hwnd
, GWL_EXSTYLE
,
524 GetWindowLongW( hwnd
, GWL_EXSTYLE
) | WS_EX_STATICEDGE
);
529 textW
= ((LPCREATESTRUCTW
)lParam
)->lpszName
;
533 textA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
542 hIcon
= STATIC_LoadIconW(hwnd
, textW
, full_style
);
544 hIcon
= STATIC_LoadIconA(hwnd
, textA
, full_style
);
545 STATIC_SetIcon(hwnd
, hIcon
, full_style
);
552 hBitmap
= STATIC_LoadBitmapW(hwnd
, textW
);
554 hBitmap
= STATIC_LoadBitmapA(hwnd
, textA
);
555 STATIC_SetBitmap(hwnd
, hBitmap
, full_style
);
559 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
560 the enhanced metafile that was specified as the window text. */
562 return unicode
? DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
) :
563 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
566 if (hasTextStyle( full_style
))
571 lResult
= DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
573 lResult
= DefWindowProcA( hwnd
, uMsg
, wParam
, lParam
);
574 STATIC_TryPaintFcn( hwnd
, full_style
);
580 if (hasTextStyle( full_style
))
582 SetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
, wParam
);
584 NtUserRedrawWindow( hwnd
, NULL
, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_ALLCHILDREN
);
589 return GetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
);
592 if (full_style
& SS_NOTIFY
)
595 return HTTRANSPARENT
;
601 case WM_NCLBUTTONDOWN
:
602 if (full_style
& SS_NOTIFY
)
603 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
604 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_CLICKED
), (LPARAM
)hwnd
);
607 case WM_LBUTTONDBLCLK
:
608 case WM_NCLBUTTONDBLCLK
:
609 if (full_style
& SS_NOTIFY
)
610 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
611 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_DBLCLK
), (LPARAM
)hwnd
);
615 return (LRESULT
)STATIC_GetImage( hwnd
, wParam
, full_style
);
620 return (LRESULT
)STATIC_GetImage( hwnd
, IMAGE_ICON
, full_style
);
625 lResult
= (LRESULT
)STATIC_SetBitmap( hwnd
, (HBITMAP
)lParam
, full_style
);
627 // case IMAGE_ENHMETAFILE:
628 // lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
632 lResult
= (LRESULT
)STATIC_SetIcon( hwnd
, (HICON
)lParam
, full_style
);
635 FIXME("STM_SETIMAGE: Unhandled type %x\n", wParam
);
638 STATIC_TryPaintFcn( hwnd
, full_style
);
645 lResult
= (LRESULT
)STATIC_SetIcon( hwnd
, (HICON
)wParam
, full_style
);
646 STATIC_TryPaintFcn( hwnd
, full_style
);
649 case WM_UPDATEUISTATE
:
651 DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
653 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
655 if (STATIC_update_uistate(hwnd
, unicode
) && hasTextStyle( full_style
))
657 NtUserRedrawWindow( hwnd
, NULL
, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_ALLCHILDREN
);
662 return unicode
? DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
) :
663 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
668 /***********************************************************************
671 static LRESULT WINAPI
StaticWndProcA( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
673 if (!IsWindow( hWnd
)) return 0;
674 return StaticWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
677 /***********************************************************************
680 static LRESULT WINAPI
StaticWndProcW( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
682 if (!IsWindow( hWnd
)) return 0;
683 return StaticWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
686 static void STATIC_PaintOwnerDrawfn( HWND hwnd
, HDC hdc
, DWORD style
)
689 HFONT font
, oldFont
= NULL
;
690 UINT id
= (UINT
)GetWindowLongPtrW( hwnd
, GWLP_ID
);
692 dis
.CtlType
= ODT_STATIC
;
695 dis
.itemAction
= ODA_DRAWENTIRE
;
696 dis
.itemState
= IsWindowEnabled(hwnd
) ? 0 : ODS_DISABLED
;
700 GetClientRect( hwnd
, &dis
.rcItem
);
702 font
= (HFONT
)GetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
);
703 if (font
) oldFont
= SelectObject( hdc
, font
);
704 SendMessageW( GetParent(hwnd
), WM_CTLCOLORSTATIC
, (WPARAM
)hdc
, (LPARAM
)hwnd
);
705 SendMessageW( GetParent(hwnd
), WM_DRAWITEM
, id
, (LPARAM
)&dis
);
706 if (font
) SelectObject( hdc
, oldFont
);
709 static void STATIC_PaintTextfn( HWND hwnd
, HDC hdc
, DWORD style
)
713 HFONT hFont
, hOldFont
= NULL
;
718 GetClientRect( hwnd
, &rc
);
720 switch (style
& SS_TYPEMASK
)
723 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
;
727 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
;
731 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
;
735 wFormat
= DT_LEFT
| DT_SINGLELINE
;
738 case SS_LEFTNOWORDWRAP
:
739 wFormat
= DT_LEFT
| DT_EXPANDTABS
;
746 if (style
& SS_NOPREFIX
)
747 wFormat
|= DT_NOPREFIX
;
748 else if (get_ui_state(hwnd
) & UISF_HIDEACCEL
)
749 wFormat
|= DT_HIDEPREFIX
;
751 if ((style
& SS_TYPEMASK
) != SS_SIMPLE
)
753 if (style
& SS_CENTERIMAGE
)
754 wFormat
|= DT_SINGLELINE
| DT_VCENTER
;
755 if (style
& SS_EDITCONTROL
)
756 wFormat
|= DT_EDITCONTROL
;
757 if (style
& SS_ENDELLIPSIS
)
758 wFormat
|= DT_SINGLELINE
| DT_END_ELLIPSIS
;
759 if (style
& SS_PATHELLIPSIS
)
760 wFormat
|= DT_SINGLELINE
| DT_PATH_ELLIPSIS
;
761 if (style
& SS_WORDELLIPSIS
)
762 wFormat
|= DT_SINGLELINE
| DT_WORD_ELLIPSIS
;
765 if ((hFont
= (HFONT
)GetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
)))
766 hOldFont
= (HFONT
)SelectObject( hdc
, hFont
);
768 /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
770 hBrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
772 if ((style
& SS_TYPEMASK
) != SS_SIMPLE
)
774 FillRect( hdc
, &rc
, hBrush
);
775 if (!IsWindowEnabled(hwnd
)) SetTextColor(hdc
, GetSysColor(COLOR_GRAYTEXT
));
779 if (!(text
= HeapAlloc( GetProcessHeap(), 0, buf_size
* sizeof(WCHAR
) )))
782 while ((len
= InternalGetWindowText( hwnd
, text
, buf_size
)) == buf_size
- 1)
785 if (!(text
= HeapReAlloc( GetProcessHeap(), 0, text
, buf_size
* sizeof(WCHAR
) )))
789 if (!len
) goto no_TextOut
;
791 if (((style
& SS_TYPEMASK
) == SS_SIMPLE
) && (style
& SS_NOPREFIX
))
793 /* Windows uses the faster ExtTextOut() to draw the text and
794 to paint the whole client rectangle with the text background
795 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
796 ExtTextOutW( hdc
, rc
.left
, rc
.top
, ETO_CLIPPED
| ETO_OPAQUE
,
797 &rc
, text
, len
, NULL
);
801 DrawTextW( hdc
, text
, -1, &rc
, wFormat
);
805 HeapFree( GetProcessHeap(), 0, text
);
808 SelectObject( hdc
, hOldFont
);
811 static void STATIC_PaintRectfn( HWND hwnd
, HDC hdc
, DWORD style
)
816 GetClientRect( hwnd
, &rc
);
818 /* FIXME: send WM_CTLCOLORSTATIC */
819 switch (style
& SS_TYPEMASK
)
822 hBrush
= CreateSolidBrush(color_3ddkshadow
);
823 FillRect( hdc
, &rc
, hBrush
);
826 hBrush
= CreateSolidBrush(color_3dshadow
);
827 FillRect( hdc
, &rc
, hBrush
);
830 hBrush
= CreateSolidBrush(color_3dhighlight
);
831 FillRect( hdc
, &rc
, hBrush
);
834 hBrush
= CreateSolidBrush(color_3ddkshadow
);
835 FrameRect( hdc
, &rc
, hBrush
);
838 hBrush
= CreateSolidBrush(color_3dshadow
);
839 FrameRect( hdc
, &rc
, hBrush
);
842 hBrush
= CreateSolidBrush(color_3dhighlight
);
843 FrameRect( hdc
, &rc
, hBrush
);
848 DeleteObject( hBrush
);
851 /* Modified for ReactOS */
852 static void STATIC_PaintIconfn( HWND hwnd
, HDC hdc
, DWORD style
)
859 GetClientRect( hwnd
, &rc
);
860 hbrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
861 hIcon
= (HICON
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
);
862 if (!hIcon
|| (!GetIconInfo(hIcon
, &info
)))
864 FillRect(hdc
, &rc
, hbrush
);
869 if (!GetObjectW(info
.hbmColor
, sizeof(BITMAP
), &bm
)) return;
870 if (style
& SS_CENTERIMAGE
)
872 iconRect
.left
= (rc
.right
- rc
.left
) / 2 - bm
.bmWidth
/ 2;
873 iconRect
.top
= (rc
.bottom
- rc
.top
) / 2 - bm
.bmHeight
/ 2;
874 iconRect
.right
= iconRect
.left
+ bm
.bmWidth
;
875 iconRect
.bottom
= iconRect
.top
+ bm
.bmHeight
;
879 FillRect( hdc
, &rc
, hbrush
);
880 DrawIconEx( hdc
, iconRect
.left
, iconRect
.top
, hIcon
, iconRect
.right
- iconRect
.left
,
881 iconRect
.bottom
- iconRect
.top
, 0, NULL
, DI_NORMAL
);
885 static void STATIC_PaintBitmapfn(HWND hwnd
, HDC hdc
, DWORD style
)
888 HBITMAP hBitmap
, oldbitmap
;
891 /* message is still sent, even if the returned brush is not used */
892 hbrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
894 if ((hBitmap
= (HBITMAP
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
))
895 && (GetObjectType(hBitmap
) == OBJ_BITMAP
)
896 && (hMemDC
= CreateCompatibleDC( hdc
)))
902 GetObjectW(hBitmap
, sizeof(bm
), &bm
);
903 oldbitmap
= SelectObject(hMemDC
, hBitmap
);
905 /* Set the background color for monochrome bitmaps
906 to the color of the background brush */
907 if (GetObjectW( hbrush
, sizeof(brush
), &brush
))
909 if (brush
.lbStyle
== BS_SOLID
)
910 SetBkColor(hdc
, brush
.lbColor
);
912 GetClientRect(hwnd
, &rcClient
);
913 if (style
& SS_CENTERIMAGE
)
916 x
= (rcClient
.right
- rcClient
.left
)/2 - bm
.bmWidth
/2;
917 y
= (rcClient
.bottom
- rcClient
.top
)/2 - bm
.bmHeight
/2;
918 FillRect( hdc
, &rcClient
, hbrush
);
919 BitBlt(hdc
, x
, y
, bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0,
924 StretchBlt(hdc
, 0, 0, rcClient
.right
- rcClient
.left
,
925 rcClient
.bottom
- rcClient
.top
, hMemDC
,
926 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
928 SelectObject(hMemDC
, oldbitmap
);
934 GetClientRect( hwnd
, &rcClient
);
935 FillRect( hdc
, &rcClient
, hbrush
);
940 //static void STATIC_PaintEnhMetafn(HWND hwnd, HDC hdc, DWORD style )
942 // HENHMETAFILE hEnhMetaFile;
946 // GetClientRect(hwnd, &rc);
947 // hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
948 // FillRect(hdc, &rc, hbrush);
949 // if ((hEnhMetaFile = (HENHMETAFILE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
951 // /* The control's current font is not selected into the
952 // device context! */
953 // if (GetObjectType(hEnhMetaFile) == OBJ_ENHMETAFILE)
954 // PlayEnhMetaFile(hdc, hEnhMetaFile, &rc);
959 static void STATIC_PaintEtchedfn( HWND hwnd
, HDC hdc
, DWORD style
)
963 /* FIXME: sometimes (not always) sends WM_CTLCOLORSTATIC */
964 GetClientRect( hwnd
, &rc
);
965 switch (style
& SS_TYPEMASK
)
968 DrawEdge(hdc
,&rc
,EDGE_ETCHED
,BF_TOP
|BF_BOTTOM
);
971 DrawEdge(hdc
,&rc
,EDGE_ETCHED
,BF_LEFT
|BF_RIGHT
);
974 DrawEdge (hdc
, &rc
, EDGE_ETCHED
, BF_RECT
);