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).
50 #include "wine/winuser16.h"
52 #include "user_private.h"
53 #include "wine/debug.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(static);
57 static void STATIC_PaintOwnerDrawfn( HWND hwnd
, HDC hdc
, DWORD style
);
58 static void STATIC_PaintTextfn( HWND hwnd
, HDC hdc
, DWORD style
);
59 static void STATIC_PaintRectfn( HWND hwnd
, HDC hdc
, DWORD style
);
60 static void STATIC_PaintIconfn( HWND hwnd
, HDC hdc
, DWORD style
);
61 static void STATIC_PaintBitmapfn( HWND hwnd
, HDC hdc
, DWORD style
);
62 static void STATIC_PaintEnhMetafn( HWND hwnd
, HDC hdc
, DWORD style
);
63 static void STATIC_PaintEtchedfn( HWND hwnd
, HDC hdc
, DWORD style
);
64 static LRESULT WINAPI
StaticWndProcA( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
65 static LRESULT WINAPI
StaticWndProcW( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
67 static COLORREF color_3dshadow
, color_3ddkshadow
, color_3dhighlight
;
69 /* offsets for GetWindowLong for static private information */
70 #define HFONT_GWL_OFFSET 0
71 #define HICON_GWL_OFFSET (sizeof(HFONT))
72 #define STATIC_EXTRA_BYTES (HICON_GWL_OFFSET + sizeof(HICON))
74 typedef void (*pfPaint
)( HWND hwnd
, HDC hdc
, DWORD style
);
76 static const pfPaint staticPaintFunc
[SS_TYPEMASK
+1] =
78 STATIC_PaintTextfn
, /* SS_LEFT */
79 STATIC_PaintTextfn
, /* SS_CENTER */
80 STATIC_PaintTextfn
, /* SS_RIGHT */
81 STATIC_PaintIconfn
, /* SS_ICON */
82 STATIC_PaintRectfn
, /* SS_BLACKRECT */
83 STATIC_PaintRectfn
, /* SS_GRAYRECT */
84 STATIC_PaintRectfn
, /* SS_WHITERECT */
85 STATIC_PaintRectfn
, /* SS_BLACKFRAME */
86 STATIC_PaintRectfn
, /* SS_GRAYFRAME */
87 STATIC_PaintRectfn
, /* SS_WHITEFRAME */
88 NULL
, /* SS_USERITEM */
89 STATIC_PaintTextfn
, /* SS_SIMPLE */
90 STATIC_PaintTextfn
, /* SS_LEFTNOWORDWRAP */
91 STATIC_PaintOwnerDrawfn
, /* SS_OWNERDRAW */
92 STATIC_PaintBitmapfn
, /* SS_BITMAP */
93 STATIC_PaintEnhMetafn
, /* SS_ENHMETAFILE */
94 STATIC_PaintEtchedfn
, /* SS_ETCHEDHORZ */
95 STATIC_PaintEtchedfn
, /* SS_ETCHEDVERT */
96 STATIC_PaintEtchedfn
, /* SS_ETCHEDFRAME */
100 /*********************************************************************
101 * static class descriptor
103 const struct builtin_class_descr STATIC_builtin_class
=
106 CS_DBLCLKS
| CS_PARENTDC
, /* style */
107 StaticWndProcA
, /* procA */
108 StaticWndProcW
, /* procW */
109 STATIC_EXTRA_BYTES
, /* extra */
110 IDC_ARROW
, /* cursor */
114 static void setup_clipping(HWND hwnd
, HDC hdc
, HRGN
*orig
)
119 /* Native control has always a clipping region set (this may be because
120 * builtin controls uses CS_PARENTDC) and an application depends on it
122 hrgn
= CreateRectRgn(0, 0, 1, 1);
123 if (GetClipRgn(hdc
, hrgn
) != 1)
130 GetClientRect(hwnd
, &rc
);
131 DPtoLP(hdc
, (POINT
*)&rc
, 2);
132 IntersectClipRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
135 static void restore_clipping(HDC hdc
, HRGN hrgn
)
137 SelectClipRgn(hdc
, hrgn
);
142 /***********************************************************************
145 * Set the icon for an SS_ICON control.
147 static HICON
STATIC_SetIcon( HWND hwnd
, HICON hicon
, DWORD style
)
150 CURSORICONINFO
* info
;
152 if ((style
& SS_TYPEMASK
) != SS_ICON
) return 0;
153 info
= hicon
?(CURSORICONINFO
*) GlobalLock16(HICON_16(hicon
)):NULL
;
154 if (hicon
&& !info
) {
155 WARN("hicon != 0, but info == 0\n");
158 prevIcon
= (HICON
)SetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
, (LONG_PTR
)hicon
);
159 if (hicon
&& !(style
& SS_CENTERIMAGE
) && !(style
& SS_REALSIZECONTROL
))
161 /* Windows currently doesn't implement SS_RIGHTJUST */
163 if ((style & SS_RIGHTJUST) != 0)
166 GetWindowRect(hwnd, &wr);
167 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
168 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
172 SetWindowPos( hwnd
, 0, 0, 0, info
->nWidth
, info
->nHeight
,
173 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
176 if (info
) GlobalUnlock16(HICON_16(hicon
));
180 /***********************************************************************
183 * Set the bitmap for an SS_BITMAP control.
185 static HBITMAP
STATIC_SetBitmap( HWND hwnd
, HBITMAP hBitmap
, DWORD style
)
189 if ((style
& SS_TYPEMASK
) != SS_BITMAP
) return 0;
190 if (hBitmap
&& GetObjectType(hBitmap
) != OBJ_BITMAP
) {
191 WARN("hBitmap != 0, but it's not a bitmap\n");
194 hOldBitmap
= (HBITMAP
)SetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
, (LONG_PTR
)hBitmap
);
195 if (hBitmap
&& !(style
& SS_CENTERIMAGE
) && !(style
& SS_REALSIZECONTROL
))
198 GetObjectW(hBitmap
, sizeof(bm
), &bm
);
199 /* Windows currently doesn't implement SS_RIGHTJUST */
201 if ((style & SS_RIGHTJUST) != 0)
204 GetWindowRect(hwnd, &wr);
205 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
206 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
210 SetWindowPos( hwnd
, 0, 0, 0, bm
.bmWidth
, bm
.bmHeight
,
211 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
218 /***********************************************************************
219 * STATIC_SetEnhMetaFile
221 * Set the enhanced metafile for an SS_ENHMETAFILE control.
223 static HENHMETAFILE
STATIC_SetEnhMetaFile( HWND hwnd
, HENHMETAFILE hEnhMetaFile
, DWORD style
)
225 if ((style
& SS_TYPEMASK
) != SS_ENHMETAFILE
) return 0;
226 if (hEnhMetaFile
&& GetObjectType(hEnhMetaFile
) != OBJ_ENHMETAFILE
) {
227 WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
230 return (HENHMETAFILE
)SetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
, (LONG_PTR
)hEnhMetaFile
);
233 /***********************************************************************
236 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
237 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
239 static HANDLE
STATIC_GetImage( HWND hwnd
, WPARAM wParam
, DWORD style
)
241 switch(style
& SS_TYPEMASK
)
244 if ((wParam
!= IMAGE_ICON
) &&
245 (wParam
!= IMAGE_CURSOR
)) return NULL
;
248 if (wParam
!= IMAGE_BITMAP
) return NULL
;
251 if (wParam
!= IMAGE_ENHMETAFILE
) return NULL
;
256 return (HANDLE
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
);
259 /***********************************************************************
262 * Load the icon for an SS_ICON control.
264 static HICON
STATIC_LoadIconA( HWND hwnd
, LPCSTR name
, DWORD style
)
266 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
267 if ((style
& SS_REALSIZEIMAGE
) != 0)
269 return LoadImageA(hInstance
, name
, IMAGE_ICON
, 0, 0, LR_SHARED
);
273 HICON hicon
= LoadIconA( hInstance
, name
);
274 if (!hicon
) hicon
= LoadCursorA( hInstance
, name
);
275 if (!hicon
) hicon
= LoadIconA( 0, name
);
276 /* Windows doesn't try to load a standard cursor,
277 probably because most IDs for standard cursors conflict
278 with the IDs for standard icons anyway */
283 /***********************************************************************
286 * Load the icon for an SS_ICON control.
288 static HICON
STATIC_LoadIconW( HWND hwnd
, LPCWSTR name
, DWORD style
)
290 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
291 if ((style
& SS_REALSIZEIMAGE
) != 0)
293 return LoadImageW(hInstance
, name
, IMAGE_ICON
, 0, 0, LR_SHARED
);
297 HICON hicon
= LoadIconW( hInstance
, name
);
298 if (!hicon
) hicon
= LoadCursorW( hInstance
, name
);
299 if (!hicon
) hicon
= LoadIconW( 0, name
);
300 /* Windows doesn't try to load a standard cursor,
301 probably because most IDs for standard cursors conflict
302 with the IDs for standard icons anyway */
307 /***********************************************************************
310 * Load the bitmap for an SS_BITMAP control.
312 static HBITMAP
STATIC_LoadBitmapA( HWND hwnd
, LPCSTR name
)
314 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
315 /* Windows doesn't try to load OEM Bitmaps (hInstance == NULL) */
316 return LoadBitmapA( hInstance
, name
);
319 /***********************************************************************
322 * Load the bitmap for an SS_BITMAP control.
324 static HBITMAP
STATIC_LoadBitmapW( HWND hwnd
, LPCWSTR name
)
326 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
327 /* Windows doesn't try to load OEM Bitmaps (hInstance == NULL) */
328 return LoadBitmapW( hInstance
, name
);
331 /***********************************************************************
334 * Try to immediately paint the control.
336 static VOID
STATIC_TryPaintFcn(HWND hwnd
, LONG full_style
)
338 LONG style
= full_style
& SS_TYPEMASK
;
341 GetClientRect( hwnd
, &rc
);
342 if (!IsRectEmpty(&rc
) && IsWindowVisible(hwnd
) && staticPaintFunc
[style
])
348 setup_clipping(hwnd
, hdc
, &hOrigClipping
);
349 (staticPaintFunc
[style
])( hwnd
, hdc
, full_style
);
350 restore_clipping(hdc
, hOrigClipping
);
351 ReleaseDC( hwnd
, hdc
);
355 static HBRUSH
STATIC_SendWmCtlColorStatic(HWND hwnd
, HDC hdc
)
358 HWND parent
= GetParent(hwnd
);
360 if (!parent
) parent
= hwnd
;
361 hBrush
= (HBRUSH
) SendMessageW( parent
,
362 WM_CTLCOLORSTATIC
, (WPARAM
)hdc
, (LPARAM
)hwnd
);
363 if (!hBrush
) /* did the app forget to call DefWindowProc ? */
365 /* FIXME: DefWindowProc should return different colors if a
366 manifest is present */
367 hBrush
= (HBRUSH
)DefWindowProcW( parent
, WM_CTLCOLORSTATIC
,
368 (WPARAM
)hdc
, (LPARAM
)hwnd
);
373 static VOID
STATIC_InitColours(void)
375 color_3ddkshadow
= GetSysColor(COLOR_3DDKSHADOW
);
376 color_3dshadow
= GetSysColor(COLOR_3DSHADOW
);
377 color_3dhighlight
= GetSysColor(COLOR_3DHIGHLIGHT
);
380 /***********************************************************************
383 * Tests if the control displays text.
385 static BOOL
hasTextStyle( DWORD style
)
387 switch(style
& SS_TYPEMASK
)
391 case SS_LEFTNOWORDWRAP
:
401 /***********************************************************************
402 * StaticWndProc_common
404 static LRESULT
StaticWndProc_common( HWND hwnd
, UINT uMsg
, WPARAM wParam
,
405 LPARAM lParam
, BOOL unicode
)
408 LONG full_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
409 LONG style
= full_style
& SS_TYPEMASK
;
414 if (style
< 0L || style
> SS_TYPEMASK
)
416 ERR("Unknown style 0x%02x\n", style
);
419 STATIC_InitColours();
423 if (style
== SS_ICON
) {
426 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
428 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
429 * had already been loaded by the application the last thing we want to do is
430 * GlobalFree16 the handle.
434 else return unicode
? DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
) :
435 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
438 /* do all painting in WM_PAINT like Windows does */
445 HDC hdc
= wParam
? (HDC
)wParam
: BeginPaint(hwnd
, &ps
);
446 if (staticPaintFunc
[style
])
449 setup_clipping(hwnd
, hdc
, &hOrigClipping
);
450 (staticPaintFunc
[style
])( hwnd
, hdc
, full_style
);
451 restore_clipping(hdc
, hOrigClipping
);
453 if (!wParam
) EndPaint(hwnd
, &ps
);
458 STATIC_TryPaintFcn( hwnd
, full_style
);
459 if (full_style
& SS_NOTIFY
) {
461 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
462 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_ENABLE
), (LPARAM
)hwnd
);
465 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
466 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_DISABLE
), (LPARAM
)hwnd
);
471 case WM_SYSCOLORCHANGE
:
472 STATIC_InitColours();
473 STATIC_TryPaintFcn( hwnd
, full_style
);
481 if (full_style
& SS_SUNKEN
)
482 SetWindowLongW( hwnd
, GWL_EXSTYLE
,
483 GetWindowLongW( hwnd
, GWL_EXSTYLE
) | WS_EX_STATICEDGE
);
488 textW
= ((LPCREATESTRUCTW
)lParam
)->lpszName
;
492 textA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
501 hIcon
= STATIC_LoadIconW(hwnd
, textW
, full_style
);
503 hIcon
= STATIC_LoadIconA(hwnd
, textA
, full_style
);
504 STATIC_SetIcon(hwnd
, hIcon
, full_style
);
511 hBitmap
= STATIC_LoadBitmapW(hwnd
, textW
);
513 hBitmap
= STATIC_LoadBitmapA(hwnd
, textA
);
514 STATIC_SetBitmap(hwnd
, hBitmap
, full_style
);
518 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
519 the enhanced metafile that was specified as the window text. */
521 return unicode
? DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
) :
522 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
525 if (hasTextStyle( full_style
))
530 lResult
= DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
532 lResult
= DefWindowProcA( hwnd
, uMsg
, wParam
, lParam
);
533 STATIC_TryPaintFcn( hwnd
, full_style
);
539 if (hasTextStyle( full_style
))
541 SetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
, wParam
);
543 RedrawWindow( hwnd
, NULL
, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_ALLCHILDREN
);
548 return GetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
);
551 if (full_style
& SS_NOTIFY
)
554 return HTTRANSPARENT
;
560 case WM_NCLBUTTONDOWN
:
561 if (full_style
& SS_NOTIFY
)
562 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
563 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_CLICKED
), (LPARAM
)hwnd
);
566 case WM_LBUTTONDBLCLK
:
567 case WM_NCLBUTTONDBLCLK
:
568 if (full_style
& SS_NOTIFY
)
569 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
570 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_DBLCLK
), (LPARAM
)hwnd
);
574 return (LRESULT
)STATIC_GetImage( hwnd
, wParam
, full_style
);
578 return (LRESULT
)STATIC_GetImage( hwnd
, IMAGE_ICON
, full_style
);
583 lResult
= (LRESULT
)STATIC_SetBitmap( hwnd
, (HBITMAP
)lParam
, full_style
);
585 case IMAGE_ENHMETAFILE
:
586 lResult
= (LRESULT
)STATIC_SetEnhMetaFile( hwnd
, (HENHMETAFILE
)lParam
, full_style
);
590 lResult
= (LRESULT
)STATIC_SetIcon( hwnd
, (HICON
)lParam
, full_style
);
593 FIXME("STM_SETIMAGE: Unhandled type %lx\n", wParam
);
596 STATIC_TryPaintFcn( hwnd
, full_style
);
601 lResult
= (LRESULT
)STATIC_SetIcon( hwnd
, (HICON
)wParam
, full_style
);
602 STATIC_TryPaintFcn( hwnd
, full_style
);
606 return unicode
? DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
) :
607 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
612 /***********************************************************************
615 static LRESULT WINAPI
StaticWndProcA( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
617 if (!IsWindow( hWnd
)) return 0;
618 return StaticWndProc_common(hWnd
, uMsg
, wParam
, lParam
, FALSE
);
621 /***********************************************************************
624 static LRESULT WINAPI
StaticWndProcW( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
626 if (!IsWindow( hWnd
)) return 0;
627 return StaticWndProc_common(hWnd
, uMsg
, wParam
, lParam
, TRUE
);
630 static void STATIC_PaintOwnerDrawfn( HWND hwnd
, HDC hdc
, DWORD style
)
633 HFONT font
, oldFont
= NULL
;
634 UINT id
= (UINT
)GetWindowLongPtrW( hwnd
, GWLP_ID
);
636 dis
.CtlType
= ODT_STATIC
;
639 dis
.itemAction
= ODA_DRAWENTIRE
;
640 dis
.itemState
= IsWindowEnabled(hwnd
) ? 0 : ODS_DISABLED
;
644 GetClientRect( hwnd
, &dis
.rcItem
);
646 font
= (HFONT
)GetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
);
647 if (font
) oldFont
= SelectObject( hdc
, font
);
648 SendMessageW( GetParent(hwnd
), WM_CTLCOLORSTATIC
, (WPARAM
)hdc
, (LPARAM
)hwnd
);
649 SendMessageW( GetParent(hwnd
), WM_DRAWITEM
, id
, (LPARAM
)&dis
);
650 if (font
) SelectObject( hdc
, oldFont
);
653 static void STATIC_PaintTextfn( HWND hwnd
, HDC hdc
, DWORD style
)
657 HFONT hFont
, hOldFont
= NULL
;
662 GetClientRect( hwnd
, &rc
);
664 switch (style
& SS_TYPEMASK
)
667 wFormat
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
;
671 wFormat
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
;
675 wFormat
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
;
679 wFormat
= DT_LEFT
| DT_SINGLELINE
;
682 case SS_LEFTNOWORDWRAP
:
683 wFormat
= DT_LEFT
| DT_EXPANDTABS
;
690 if (style
& SS_NOPREFIX
)
691 wFormat
|= DT_NOPREFIX
;
693 if ((style
& SS_TYPEMASK
) != SS_SIMPLE
)
695 if (style
& SS_CENTERIMAGE
)
696 wFormat
|= DT_SINGLELINE
| DT_VCENTER
;
697 if (style
& SS_EDITCONTROL
)
698 wFormat
|= DT_EDITCONTROL
;
699 if (style
& SS_ENDELLIPSIS
)
700 wFormat
|= DT_SINGLELINE
| DT_END_ELLIPSIS
;
701 if (style
& SS_PATHELLIPSIS
)
702 wFormat
|= DT_SINGLELINE
| DT_PATH_ELLIPSIS
;
703 if (style
& SS_WORDELLIPSIS
)
704 wFormat
|= DT_SINGLELINE
| DT_WORD_ELLIPSIS
;
707 if ((hFont
= (HFONT
)GetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
)))
708 hOldFont
= (HFONT
)SelectObject( hdc
, hFont
);
710 /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
712 hBrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
714 if ((style
& SS_TYPEMASK
) != SS_SIMPLE
)
716 FillRect( hdc
, &rc
, hBrush
);
717 if (!IsWindowEnabled(hwnd
)) SetTextColor(hdc
, GetSysColor(COLOR_GRAYTEXT
));
721 if (!(text
= HeapAlloc( GetProcessHeap(), 0, buf_size
* sizeof(WCHAR
) )))
724 while ((len
= InternalGetWindowText( hwnd
, text
, buf_size
)) == buf_size
- 1)
727 if (!(text
= HeapReAlloc( GetProcessHeap(), 0, text
, buf_size
* sizeof(WCHAR
) )))
731 if (!len
) goto no_TextOut
;
733 if (((style
& SS_TYPEMASK
) == SS_SIMPLE
) && (style
& SS_NOPREFIX
))
735 /* Windows uses the faster ExtTextOut() to draw the text and
736 to paint the whole client rectangle with the text background
737 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
738 ExtTextOutW( hdc
, rc
.left
, rc
.top
, ETO_CLIPPED
| ETO_OPAQUE
,
739 &rc
, text
, len
, NULL
);
743 DrawTextW( hdc
, text
, -1, &rc
, wFormat
);
747 HeapFree( GetProcessHeap(), 0, text
);
750 SelectObject( hdc
, hOldFont
);
753 static void STATIC_PaintRectfn( HWND hwnd
, HDC hdc
, DWORD style
)
758 GetClientRect( hwnd
, &rc
);
760 /* FIXME: send WM_CTLCOLORSTATIC */
761 switch (style
& SS_TYPEMASK
)
764 hBrush
= CreateSolidBrush(color_3ddkshadow
);
765 FillRect( hdc
, &rc
, hBrush
);
768 hBrush
= CreateSolidBrush(color_3dshadow
);
769 FillRect( hdc
, &rc
, hBrush
);
772 hBrush
= CreateSolidBrush(color_3dhighlight
);
773 FillRect( hdc
, &rc
, hBrush
);
776 hBrush
= CreateSolidBrush(color_3ddkshadow
);
777 FrameRect( hdc
, &rc
, hBrush
);
780 hBrush
= CreateSolidBrush(color_3dshadow
);
781 FrameRect( hdc
, &rc
, hBrush
);
784 hBrush
= CreateSolidBrush(color_3dhighlight
);
785 FrameRect( hdc
, &rc
, hBrush
);
790 DeleteObject( hBrush
);
794 static void STATIC_PaintIconfn( HWND hwnd
, HDC hdc
, DWORD style
)
799 CURSORICONINFO
* info
;
801 GetClientRect( hwnd
, &rc
);
802 hbrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
803 hIcon
= (HICON
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
);
804 info
= hIcon
? (CURSORICONINFO
*)GlobalLock16(HICON_16(hIcon
)) : NULL
;
807 FillRect(hdc
, &rc
, hbrush
);
811 if (style
& SS_CENTERIMAGE
)
813 iconRect
.left
= (rc
.right
- rc
.left
) / 2 - info
->nWidth
/ 2;
814 iconRect
.top
= (rc
.bottom
- rc
.top
) / 2 - info
->nHeight
/ 2;
815 iconRect
.right
= iconRect
.left
+ info
->nWidth
;
816 iconRect
.bottom
= iconRect
.top
+ info
->nHeight
;
820 FillRect( hdc
, &rc
, hbrush
);
821 DrawIconEx( hdc
, iconRect
.left
, iconRect
.top
, hIcon
, iconRect
.right
- iconRect
.left
,
822 iconRect
.bottom
- iconRect
.top
, 0, NULL
, DI_NORMAL
);
824 if (info
) GlobalUnlock16(HICON_16(hIcon
));
827 static void STATIC_PaintBitmapfn(HWND hwnd
, HDC hdc
, DWORD style
)
830 HBITMAP hBitmap
, oldbitmap
;
833 /* message is still sent, even if the returned brush is not used */
834 hbrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
836 if ((hBitmap
= (HBITMAP
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
))
837 && (GetObjectType(hBitmap
) == OBJ_BITMAP
)
838 && (hMemDC
= CreateCompatibleDC( hdc
)))
844 GetObjectW(hBitmap
, sizeof(bm
), &bm
);
845 oldbitmap
= SelectObject(hMemDC
, hBitmap
);
847 /* Set the background color for monochrome bitmaps
848 to the color of the background brush */
849 if (GetObjectW( hbrush
, sizeof(brush
), &brush
))
851 if (brush
.lbStyle
== BS_SOLID
)
852 SetBkColor(hdc
, brush
.lbColor
);
854 GetClientRect(hwnd
, &rcClient
);
855 if (style
& SS_CENTERIMAGE
)
858 x
= (rcClient
.right
- rcClient
.left
)/2 - bm
.bmWidth
/2;
859 y
= (rcClient
.bottom
- rcClient
.top
)/2 - bm
.bmHeight
/2;
860 FillRect( hdc
, &rcClient
, hbrush
);
861 BitBlt(hdc
, x
, y
, bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0,
866 StretchBlt(hdc
, 0, 0, rcClient
.right
- rcClient
.left
,
867 rcClient
.bottom
- rcClient
.top
, hMemDC
,
868 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
870 SelectObject(hMemDC
, oldbitmap
);
876 GetClientRect( hwnd
, &rcClient
);
877 FillRect( hdc
, &rcClient
, hbrush
);
882 static void STATIC_PaintEnhMetafn(HWND hwnd
, HDC hdc
, DWORD style
)
884 HENHMETAFILE hEnhMetaFile
;
888 GetClientRect(hwnd
, &rc
);
889 hbrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
890 FillRect(hdc
, &rc
, hbrush
);
891 if ((hEnhMetaFile
= (HENHMETAFILE
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
)))
893 /* The control's current font is not selected into the
895 if (GetObjectType(hEnhMetaFile
) == OBJ_ENHMETAFILE
)
896 PlayEnhMetaFile(hdc
, hEnhMetaFile
, &rc
);
901 static void STATIC_PaintEtchedfn( HWND hwnd
, HDC hdc
, DWORD style
)
905 /* FIXME: sometimes (not always) sends WM_CTLCOLORSTATIC */
906 GetClientRect( hwnd
, &rc
);
907 switch (style
& SS_TYPEMASK
)
910 DrawEdge(hdc
,&rc
,EDGE_ETCHED
,BF_TOP
|BF_BOTTOM
);
913 DrawEdge(hdc
,&rc
,EDGE_ETCHED
,BF_LEFT
|BF_RIGHT
);
916 DrawEdge (hdc
, &rc
, EDGE_ETCHED
, BF_RECT
);