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
=
100 L
"Static", /* name */
101 CS_DBLCLKS
| CS_PARENTDC
, /* style */
102 StaticWndProcA
, /* procA */
103 StaticWndProcW
, /* procW */
104 STATIC_EXTRA_BYTES
, /* extra */
105 IDC_ARROW
, /* cursor */
109 static __inline
void set_ui_state( HWND hwnd
, LONG flags
)
111 SetWindowLongW( hwnd
, UISTATE_GWL_OFFSET
, flags
);
114 static __inline LONG
get_ui_state( HWND hwnd
)
116 return GetWindowLongPtrW( hwnd
, UISTATE_GWL_OFFSET
);
119 static void setup_clipping(HWND hwnd
, HDC hdc
, HRGN
*orig
)
124 /* Native control has always a clipping region set (this may be because
125 * builtin controls uses CS_PARENTDC) and an application depends on it
127 hrgn
= CreateRectRgn(0, 0, 1, 1);
128 if (GetClipRgn(hdc
, hrgn
) != 1)
135 GetClientRect(hwnd
, &rc
);
136 DPtoLP(hdc
, (POINT
*)&rc
, 2);
137 IntersectClipRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
140 static void restore_clipping(HDC hdc
, HRGN hrgn
)
142 SelectClipRgn(hdc
, hrgn
);
147 /* Retrieve the UI state for the control */
148 static BOOL
STATIC_update_uistate(HWND hwnd
, BOOL unicode
)
150 LONG flags
, prevflags
;
153 flags
= DefWindowProcW(hwnd
, WM_QUERYUISTATE
, 0, 0);
155 flags
= DefWindowProcA(hwnd
, WM_QUERYUISTATE
, 0, 0);
157 prevflags
= get_ui_state(hwnd
);
159 if (prevflags
!= flags
)
161 set_ui_state(hwnd
, flags
);
168 /***********************************************************************
171 * Set the icon for an SS_ICON control. Modified for ReactOS
173 static HICON
STATIC_SetIcon( HWND hwnd
, HICON hicon
, DWORD style
)
178 if ((style
& SS_TYPEMASK
) != SS_ICON
) return 0;
179 if (hicon
&& (!GetIconInfo(hicon
, &info
))) {
180 WARN("hicon != 0, but info == 0\n");
183 prevIcon
= (HICON
)SetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
, (LONG_PTR
)hicon
);
184 if (hicon
&& !(style
& SS_CENTERIMAGE
) && !(style
& SS_REALSIZECONTROL
))
188 if (!GetObjectW(info
.hbmColor
, sizeof(BITMAP
), &bm
))
193 /* Windows currently doesn't implement SS_RIGHTJUST */
195 if ((style & SS_RIGHTJUST) != 0)
198 GetWindowRect(hwnd, &wr);
199 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
200 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
204 SetWindowPos( hwnd
, 0, 0, 0, bm
.bmWidth
, bm
.bmHeight
,
205 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
211 /***********************************************************************
214 * Set the bitmap for an SS_BITMAP control. Modified for ReactOS
216 static HBITMAP
STATIC_SetBitmap( HWND hwnd
, HBITMAP hBitmap
, DWORD style
)
220 if ((style
& SS_TYPEMASK
) != SS_BITMAP
) return 0;
221 if (hBitmap
&& GetObjectType(hBitmap
) != OBJ_BITMAP
) {
222 WARN("hBitmap != 0, but it's not a bitmap\n");
225 hOldBitmap
= (HBITMAP
)SetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
, (LONG_PTR
)hBitmap
);
226 if (hBitmap
&& !(style
& SS_CENTERIMAGE
) && !(style
& SS_REALSIZECONTROL
))
229 GetObjectW(hBitmap
, sizeof(bm
), &bm
);
230 /* Windows currently doesn't implement SS_RIGHTJUST */
232 if ((style & SS_RIGHTJUST) != 0)
235 GetWindowRect(hwnd, &wr);
236 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
237 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
241 SetWindowPos( hwnd
, 0, 0, 0, bm
.bmWidth
, bm
.bmHeight
,
242 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
248 /***********************************************************************
249 * STATIC_SetEnhMetaFile
251 * Set the enhanced metafile for an SS_ENHMETAFILE control.
253 //static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
255 // if ((style & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
256 // if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE) {
257 // WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
260 // return (HENHMETAFILE)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hEnhMetaFile );
263 /***********************************************************************
266 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
267 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
269 static HANDLE
STATIC_GetImage( HWND hwnd
, WPARAM wParam
, DWORD style
)
271 switch(style
& SS_TYPEMASK
)
274 if ((wParam
!= IMAGE_ICON
) &&
275 (wParam
!= IMAGE_CURSOR
)) return NULL
;
278 if (wParam
!= IMAGE_BITMAP
) return NULL
;
281 if (wParam
!= IMAGE_ENHMETAFILE
) return NULL
;
286 return (HANDLE
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
);
289 /***********************************************************************
292 * Load the icon for an SS_ICON control.
294 static HICON
STATIC_LoadIconA( HWND hwnd
, LPCSTR name
, DWORD style
)
296 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
297 if ((style
& SS_REALSIZEIMAGE
) != 0)
299 return LoadImageA(hInstance
, name
, IMAGE_ICON
, 0, 0, LR_SHARED
);
303 HICON hicon
= LoadIconA( hInstance
, name
);
304 if (!hicon
) hicon
= LoadCursorA( hInstance
, name
);
305 if (!hicon
) hicon
= LoadIconA( 0, name
);
306 /* Windows doesn't try to load a standard cursor,
307 probably because most IDs for standard cursors conflict
308 with the IDs for standard icons anyway */
313 /***********************************************************************
316 * Load the icon for an SS_ICON control.
318 static HICON
STATIC_LoadIconW( HWND hwnd
, LPCWSTR name
, DWORD style
)
320 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
321 if ((style
& SS_REALSIZEIMAGE
) != 0)
323 return LoadImageW(hInstance
, name
, IMAGE_ICON
, 0, 0, LR_SHARED
);
327 HICON hicon
= LoadIconW( hInstance
, name
);
328 if (!hicon
) hicon
= LoadCursorW( hInstance
, name
);
329 if (!hicon
) hicon
= LoadIconW( 0, name
);
330 /* Windows doesn't try to load a standard cursor,
331 probably because most IDs for standard cursors conflict
332 with the IDs for standard icons anyway */
337 /***********************************************************************
340 * Load the bitmap for an SS_BITMAP control.
342 static HBITMAP
STATIC_LoadBitmapA( HWND hwnd
, LPCSTR name
)
344 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
345 /* Windows doesn't try to load OEM Bitmaps (hInstance == NULL) */
346 return LoadBitmapA( hInstance
, name
);
349 /***********************************************************************
352 * Load the bitmap for an SS_BITMAP control.
354 static HBITMAP
STATIC_LoadBitmapW( HWND hwnd
, LPCWSTR name
)
356 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
357 /* Windows doesn't try to load OEM Bitmaps (hInstance == NULL) */
358 return LoadBitmapW( hInstance
, name
);
361 /***********************************************************************
364 * Try to immediately paint the control.
366 static VOID
STATIC_TryPaintFcn(HWND hwnd
, LONG full_style
)
368 LONG style
= full_style
& SS_TYPEMASK
;
371 GetClientRect( hwnd
, &rc
);
372 if (!IsRectEmpty(&rc
) && IsWindowVisible(hwnd
) && staticPaintFunc
[style
])
378 setup_clipping(hwnd
, hdc
, &hOrigClipping
);
379 (staticPaintFunc
[style
])( hwnd
, hdc
, full_style
);
380 restore_clipping(hdc
, hOrigClipping
);
381 ReleaseDC( hwnd
, hdc
);
385 static HBRUSH
STATIC_SendWmCtlColorStatic(HWND hwnd
, HDC hdc
)
388 HWND parent
= GetParent(hwnd
);
390 if(!parent
) parent
= hwnd
;
391 hBrush
= (HBRUSH
) SendMessageW( GetParent(hwnd
),
392 WM_CTLCOLORSTATIC
, (WPARAM
)hdc
, (LPARAM
)hwnd
);
393 if (!hBrush
) /* did the app forget to call DefWindowProc ? */
395 /* FIXME: DefWindowProc should return different colors if a
396 manifest is present */
397 hBrush
= (HBRUSH
)DefWindowProcW(GetParent(hwnd
), WM_CTLCOLORSTATIC
,
398 (WPARAM
)hdc
, (LPARAM
)hwnd
);
403 static VOID
STATIC_InitColours(void)
405 color_3ddkshadow
= GetSysColor(COLOR_3DDKSHADOW
);
406 color_3dshadow
= GetSysColor(COLOR_3DSHADOW
);
407 color_3dhighlight
= GetSysColor(COLOR_3DHIGHLIGHT
);
410 /***********************************************************************
413 * Tests if the control displays text.
415 static BOOL
hasTextStyle( DWORD style
)
417 switch(style
& SS_TYPEMASK
)
421 case SS_LEFTNOWORDWRAP
:
431 /***********************************************************************
432 * StaticWndProc_common
434 static LRESULT
StaticWndProc_common( HWND hwnd
, UINT uMsg
, WPARAM wParam
,
435 LPARAM lParam
, BOOL unicode
)
438 LONG full_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
439 LONG style
= full_style
& SS_TYPEMASK
;
444 if (style
< 0L || style
> SS_TYPEMASK
)
446 ERR("Unknown style 0x%02lx\n", style
);
449 STATIC_update_uistate(hwnd
, unicode
);
450 STATIC_InitColours();
454 if (style
== SS_ICON
) {
457 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
459 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
460 * had already been loaded by the application the last thing we want to do is
461 * GlobalFree16 the handle.
465 else return unicode
? DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
) :
466 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
469 /* do all painting in WM_PAINT like Windows does */
476 HDC hdc
= wParam
? (HDC
)wParam
: BeginPaint(hwnd
, &ps
);
477 if (staticPaintFunc
[style
])
480 setup_clipping(hwnd
, hdc
, &hOrigClipping
);
481 (staticPaintFunc
[style
])( hwnd
, hdc
, full_style
);
482 restore_clipping(hdc
, hOrigClipping
);
484 if (!wParam
) EndPaint(hwnd
, &ps
);
489 STATIC_TryPaintFcn( hwnd
, full_style
);
490 if (full_style
& SS_NOTIFY
) {
492 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
493 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_ENABLE
), (LPARAM
)hwnd
);
496 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
497 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_DISABLE
), (LPARAM
)hwnd
);
502 case WM_SYSCOLORCHANGE
:
503 STATIC_InitColours();
504 STATIC_TryPaintFcn( hwnd
, full_style
);
512 if (full_style
& SS_SUNKEN
)
513 SetWindowLongW( hwnd
, GWL_EXSTYLE
,
514 GetWindowLongW( hwnd
, GWL_EXSTYLE
) | WS_EX_STATICEDGE
);
519 textW
= ((LPCREATESTRUCTW
)lParam
)->lpszName
;
523 textA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
532 hIcon
= STATIC_LoadIconW(hwnd
, textW
, full_style
);
534 hIcon
= STATIC_LoadIconA(hwnd
, textA
, full_style
);
535 STATIC_SetIcon(hwnd
, hIcon
, full_style
);
542 hBitmap
= STATIC_LoadBitmapW(hwnd
, textW
);
544 hBitmap
= STATIC_LoadBitmapA(hwnd
, textA
);
545 STATIC_SetBitmap(hwnd
, hBitmap
, full_style
);
549 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
550 the enhanced metafile that was specified as the window text. */
552 return unicode
? DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
) :
553 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
556 if (hasTextStyle( full_style
))
561 lResult
= DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
563 lResult
= DefWindowProcA( hwnd
, uMsg
, wParam
, lParam
);
564 STATIC_TryPaintFcn( hwnd
, full_style
);
570 if (hasTextStyle( full_style
))
572 SetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
, wParam
);
574 RedrawWindow( hwnd
, NULL
, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_ALLCHILDREN
);
579 return GetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
);
582 if (full_style
& SS_NOTIFY
)
585 return HTTRANSPARENT
;
591 case WM_NCLBUTTONDOWN
:
592 if (full_style
& SS_NOTIFY
)
593 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
594 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_CLICKED
), (LPARAM
)hwnd
);
597 case WM_LBUTTONDBLCLK
:
598 case WM_NCLBUTTONDBLCLK
:
599 if (full_style
& SS_NOTIFY
)
600 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
601 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_DBLCLK
), (LPARAM
)hwnd
);
605 return (LRESULT
)STATIC_GetImage( hwnd
, wParam
, full_style
);
610 return (LRESULT
)STATIC_GetImage( hwnd
, IMAGE_ICON
, full_style
);
615 lResult
= (LRESULT
)STATIC_SetBitmap( hwnd
, (HBITMAP
)lParam
, full_style
);
617 // case IMAGE_ENHMETAFILE:
618 // lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
622 lResult
= (LRESULT
)STATIC_SetIcon( hwnd
, (HICON
)lParam
, full_style
);
625 FIXME("STM_SETIMAGE: Unhandled type %x\n", wParam
);
628 STATIC_TryPaintFcn( hwnd
, full_style
);
635 lResult
= (LRESULT
)STATIC_SetIcon( hwnd
, (HICON
)wParam
, full_style
);
636 STATIC_TryPaintFcn( hwnd
, full_style
);
639 case WM_UPDATEUISTATE
:
641 DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
643 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
645 if (STATIC_update_uistate(hwnd
, unicode
) && hasTextStyle( full_style
))
647 RedrawWindow( hwnd
, NULL
, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_ALLCHILDREN
);
652 return unicode
? DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
) :
653 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
658 /***********************************************************************
661 static LRESULT WINAPI
StaticWndProcA( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
663 if (!IsWindow( hWnd
)) return 0;
664 return StaticWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
667 /***********************************************************************
670 static LRESULT WINAPI
StaticWndProcW( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
672 if (!IsWindow( hWnd
)) return 0;
673 return StaticWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
676 static void STATIC_PaintOwnerDrawfn( HWND hwnd
, HDC hdc
, DWORD style
)
679 HFONT font
, oldFont
= NULL
;
680 UINT id
= (UINT
)GetWindowLongPtrW( hwnd
, GWLP_ID
);
682 dis
.CtlType
= ODT_STATIC
;
685 dis
.itemAction
= ODA_DRAWENTIRE
;
686 dis
.itemState
= IsWindowEnabled(hwnd
) ? 0 : ODS_DISABLED
;
690 GetClientRect( hwnd
, &dis
.rcItem
);
692 font
= (HFONT
)GetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
);
693 if (font
) oldFont
= SelectObject( hdc
, font
);
694 SendMessageW( GetParent(hwnd
), WM_CTLCOLORSTATIC
, (WPARAM
)hdc
, (LPARAM
)hwnd
);
695 SendMessageW( GetParent(hwnd
), WM_DRAWITEM
, id
, (LPARAM
)&dis
);
696 if (font
) SelectObject( hdc
, oldFont
);
699 static void STATIC_PaintTextfn( HWND hwnd
, HDC hdc
, DWORD style
)
703 HFONT hFont
, hOldFont
= NULL
;
708 GetClientRect( hwnd
, &rc
);
710 switch (style
& SS_TYPEMASK
)
713 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
;
717 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
;
721 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
;
725 wFormat
= DT_LEFT
| DT_SINGLELINE
;
728 case SS_LEFTNOWORDWRAP
:
729 wFormat
= DT_LEFT
| DT_EXPANDTABS
;
736 if (style
& SS_NOPREFIX
)
737 wFormat
|= DT_NOPREFIX
;
738 else if (get_ui_state(hwnd
) & UISF_HIDEACCEL
)
739 wFormat
|= DT_HIDEPREFIX
;
741 if ((style
& SS_TYPEMASK
) != SS_SIMPLE
)
743 if (style
& SS_CENTERIMAGE
)
744 wFormat
|= DT_SINGLELINE
| DT_VCENTER
;
745 if (style
& SS_EDITCONTROL
)
746 wFormat
|= DT_EDITCONTROL
;
747 if (style
& SS_ENDELLIPSIS
)
748 wFormat
|= DT_SINGLELINE
| DT_END_ELLIPSIS
;
749 if (style
& SS_PATHELLIPSIS
)
750 wFormat
|= DT_SINGLELINE
| DT_PATH_ELLIPSIS
;
751 if (style
& SS_WORDELLIPSIS
)
752 wFormat
|= DT_SINGLELINE
| DT_WORD_ELLIPSIS
;
755 if ((hFont
= (HFONT
)GetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
)))
756 hOldFont
= (HFONT
)SelectObject( hdc
, hFont
);
758 /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
760 hBrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
762 if ((style
& SS_TYPEMASK
) != SS_SIMPLE
)
764 FillRect( hdc
, &rc
, hBrush
);
765 if (!IsWindowEnabled(hwnd
)) SetTextColor(hdc
, GetSysColor(COLOR_GRAYTEXT
));
769 if (!(text
= HeapAlloc( GetProcessHeap(), 0, buf_size
* sizeof(WCHAR
) )))
772 while ((len
= InternalGetWindowText( hwnd
, text
, buf_size
)) == buf_size
- 1)
775 if (!(text
= HeapReAlloc( GetProcessHeap(), 0, text
, buf_size
* sizeof(WCHAR
) )))
779 if (!len
) goto no_TextOut
;
781 if (((style
& SS_TYPEMASK
) == SS_SIMPLE
) && (style
& SS_NOPREFIX
))
783 /* Windows uses the faster ExtTextOut() to draw the text and
784 to paint the whole client rectangle with the text background
785 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
786 ExtTextOutW( hdc
, rc
.left
, rc
.top
, ETO_CLIPPED
| ETO_OPAQUE
,
787 &rc
, text
, len
, NULL
);
791 DrawTextW( hdc
, text
, -1, &rc
, wFormat
);
795 HeapFree( GetProcessHeap(), 0, text
);
798 SelectObject( hdc
, hOldFont
);
801 static void STATIC_PaintRectfn( HWND hwnd
, HDC hdc
, DWORD style
)
806 GetClientRect( hwnd
, &rc
);
808 /* FIXME: send WM_CTLCOLORSTATIC */
809 switch (style
& SS_TYPEMASK
)
812 hBrush
= CreateSolidBrush(color_3ddkshadow
);
813 FillRect( hdc
, &rc
, hBrush
);
816 hBrush
= CreateSolidBrush(color_3dshadow
);
817 FillRect( hdc
, &rc
, hBrush
);
820 hBrush
= CreateSolidBrush(color_3dhighlight
);
821 FillRect( hdc
, &rc
, hBrush
);
824 hBrush
= CreateSolidBrush(color_3ddkshadow
);
825 FrameRect( hdc
, &rc
, hBrush
);
828 hBrush
= CreateSolidBrush(color_3dshadow
);
829 FrameRect( hdc
, &rc
, hBrush
);
832 hBrush
= CreateSolidBrush(color_3dhighlight
);
833 FrameRect( hdc
, &rc
, hBrush
);
838 DeleteObject( hBrush
);
841 /* Modified for ReactOS */
842 static void STATIC_PaintIconfn( HWND hwnd
, HDC hdc
, DWORD style
)
849 GetClientRect( hwnd
, &rc
);
850 hbrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
851 hIcon
= (HICON
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
);
852 if (!hIcon
|| (!GetIconInfo(hIcon
, &info
)))
854 FillRect(hdc
, &rc
, hbrush
);
859 if (!GetObjectW(info
.hbmColor
, sizeof(BITMAP
), &bm
)) return;
860 if (style
& SS_CENTERIMAGE
)
862 iconRect
.left
= (rc
.right
- rc
.left
) / 2 - bm
.bmWidth
/ 2;
863 iconRect
.top
= (rc
.bottom
- rc
.top
) / 2 - bm
.bmHeight
/ 2;
864 iconRect
.right
= iconRect
.left
+ bm
.bmWidth
;
865 iconRect
.bottom
= iconRect
.top
+ bm
.bmHeight
;
869 FillRect( hdc
, &rc
, hbrush
);
870 DrawIconEx( hdc
, iconRect
.left
, iconRect
.top
, hIcon
, iconRect
.right
- iconRect
.left
,
871 iconRect
.bottom
- iconRect
.top
, 0, NULL
, DI_NORMAL
);
875 static void STATIC_PaintBitmapfn(HWND hwnd
, HDC hdc
, DWORD style
)
878 HBITMAP hBitmap
, oldbitmap
;
881 /* message is still sent, even if the returned brush is not used */
882 hbrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
884 if ((hBitmap
= (HBITMAP
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
))
885 && (GetObjectType(hBitmap
) == OBJ_BITMAP
)
886 && (hMemDC
= CreateCompatibleDC( hdc
)))
892 GetObjectW(hBitmap
, sizeof(bm
), &bm
);
893 oldbitmap
= SelectObject(hMemDC
, hBitmap
);
895 /* Set the background color for monochrome bitmaps
896 to the color of the background brush */
897 if (GetObjectW( hbrush
, sizeof(brush
), &brush
))
899 if (brush
.lbStyle
== BS_SOLID
)
900 SetBkColor(hdc
, brush
.lbColor
);
902 GetClientRect(hwnd
, &rcClient
);
903 if (style
& SS_CENTERIMAGE
)
906 x
= (rcClient
.right
- rcClient
.left
)/2 - bm
.bmWidth
/2;
907 y
= (rcClient
.bottom
- rcClient
.top
)/2 - bm
.bmHeight
/2;
908 FillRect( hdc
, &rcClient
, hbrush
);
909 BitBlt(hdc
, x
, y
, bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0,
914 StretchBlt(hdc
, 0, 0, rcClient
.right
- rcClient
.left
,
915 rcClient
.bottom
- rcClient
.top
, hMemDC
,
916 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
918 SelectObject(hMemDC
, oldbitmap
);
924 GetClientRect( hwnd
, &rcClient
);
925 FillRect( hdc
, &rcClient
, hbrush
);
930 //static void STATIC_PaintEnhMetafn(HWND hwnd, HDC hdc, DWORD style )
932 // HENHMETAFILE hEnhMetaFile;
936 // GetClientRect(hwnd, &rc);
937 // hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
938 // FillRect(hdc, &rc, hbrush);
939 // if ((hEnhMetaFile = (HENHMETAFILE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
941 // /* The control's current font is not selected into the
942 // device context! */
943 // if (GetObjectType(hEnhMetaFile) == OBJ_ENHMETAFILE)
944 // PlayEnhMetaFile(hdc, hEnhMetaFile, &rc);
949 static void STATIC_PaintEtchedfn( HWND hwnd
, HDC hdc
, DWORD style
)
953 /* FIXME: sometimes (not always) sends WM_CTLCOLORSTATIC */
954 GetClientRect( hwnd
, &rc
);
955 switch (style
& SS_TYPEMASK
)
958 DrawEdge(hdc
,&rc
,EDGE_ETCHED
,BF_TOP
|BF_BOTTOM
);
961 DrawEdge(hdc
,&rc
,EDGE_ETCHED
,BF_LEFT
|BF_RIGHT
);
964 DrawEdge (hdc
, &rc
, EDGE_ETCHED
, BF_RECT
);