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
21 * - Controls with SS_SIMPLE but without SS_NOPREFIX:
22 * The text should not be changed. Windows doesn't clear the
23 * client rectangle, so the new text must be larger than the old one.
24 * - The SS_RIGHTJUST style is currently not implemented by Windows
25 * (or it does something different than documented).
37 #include "user_private.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(static);
42 static void STATIC_PaintOwnerDrawfn( HWND hwnd
, HDC hdc
, DWORD style
);
43 static void STATIC_PaintTextfn( HWND hwnd
, HDC hdc
, DWORD style
);
44 static void STATIC_PaintRectfn( HWND hwnd
, HDC hdc
, DWORD style
);
45 static void STATIC_PaintIconfn( HWND hwnd
, HDC hdc
, DWORD style
);
46 static void STATIC_PaintBitmapfn( HWND hwnd
, HDC hdc
, DWORD style
);
47 static void STATIC_PaintEnhMetafn( HWND hwnd
, HDC hdc
, DWORD style
);
48 static void STATIC_PaintEtchedfn( HWND hwnd
, HDC hdc
, DWORD style
);
50 static COLORREF color_3dshadow
, color_3ddkshadow
, color_3dhighlight
;
52 /* offsets for GetWindowLong for static private information */
53 #define HFONT_GWL_OFFSET 0
54 #define HICON_GWL_OFFSET (sizeof(HFONT))
55 #define STATIC_EXTRA_BYTES (HICON_GWL_OFFSET + sizeof(HICON))
57 typedef void (*pfPaint
)( HWND hwnd
, HDC hdc
, DWORD style
);
59 static const pfPaint staticPaintFunc
[SS_TYPEMASK
+1] =
61 STATIC_PaintTextfn
, /* SS_LEFT */
62 STATIC_PaintTextfn
, /* SS_CENTER */
63 STATIC_PaintTextfn
, /* SS_RIGHT */
64 STATIC_PaintIconfn
, /* SS_ICON */
65 STATIC_PaintRectfn
, /* SS_BLACKRECT */
66 STATIC_PaintRectfn
, /* SS_GRAYRECT */
67 STATIC_PaintRectfn
, /* SS_WHITERECT */
68 STATIC_PaintRectfn
, /* SS_BLACKFRAME */
69 STATIC_PaintRectfn
, /* SS_GRAYFRAME */
70 STATIC_PaintRectfn
, /* SS_WHITEFRAME */
71 NULL
, /* SS_USERITEM */
72 STATIC_PaintTextfn
, /* SS_SIMPLE */
73 STATIC_PaintTextfn
, /* SS_LEFTNOWORDWRAP */
74 STATIC_PaintOwnerDrawfn
, /* SS_OWNERDRAW */
75 STATIC_PaintBitmapfn
, /* SS_BITMAP */
76 STATIC_PaintEnhMetafn
, /* SS_ENHMETAFILE */
77 STATIC_PaintEtchedfn
, /* SS_ETCHEDHORZ */
78 STATIC_PaintEtchedfn
, /* SS_ETCHEDVERT */
79 STATIC_PaintEtchedfn
, /* SS_ETCHEDFRAME */
83 /*********************************************************************
84 * static class descriptor
86 static const WCHAR staticW
[] = {'S','t','a','t','i','c',0};
87 const struct builtin_class_descr STATIC_builtin_class
=
90 CS_DBLCLKS
| CS_PARENTDC
, /* style */
91 WINPROC_STATIC
, /* proc */
92 STATIC_EXTRA_BYTES
, /* extra */
93 IDC_ARROW
, /* cursor */
97 /***********************************************************************
100 * Set the icon for an SS_ICON control.
102 static HICON
STATIC_SetIcon( HWND hwnd
, HICON hicon
, DWORD style
)
107 if ((style
& SS_TYPEMASK
) != SS_ICON
) return 0;
108 if (hicon
&& !get_icon_size( hicon
, &size
))
110 WARN("hicon != 0, but invalid\n");
113 prevIcon
= (HICON
)SetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
, (LONG_PTR
)hicon
);
114 if (hicon
&& !(style
& SS_CENTERIMAGE
) && !(style
& SS_REALSIZECONTROL
))
116 /* Windows currently doesn't implement SS_RIGHTJUST */
118 if ((style & SS_RIGHTJUST) != 0)
121 GetWindowRect(hwnd, &wr);
122 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
123 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
127 SetWindowPos( hwnd
, 0, 0, 0, size
.cx
, size
.cy
, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
133 /***********************************************************************
136 * Set the bitmap for an SS_BITMAP control.
138 static HBITMAP
STATIC_SetBitmap( HWND hwnd
, HBITMAP hBitmap
, DWORD style
)
142 if ((style
& SS_TYPEMASK
) != SS_BITMAP
) return 0;
143 if (hBitmap
&& GetObjectType(hBitmap
) != OBJ_BITMAP
) {
144 WARN("hBitmap != 0, but it's not a bitmap\n");
147 hOldBitmap
= (HBITMAP
)SetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
, (LONG_PTR
)hBitmap
);
148 if (hBitmap
&& !(style
& SS_CENTERIMAGE
) && !(style
& SS_REALSIZECONTROL
))
151 GetObjectW(hBitmap
, sizeof(bm
), &bm
);
152 /* Windows currently doesn't implement SS_RIGHTJUST */
154 if ((style & SS_RIGHTJUST) != 0)
157 GetWindowRect(hwnd, &wr);
158 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
159 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
163 SetWindowPos( hwnd
, 0, 0, 0, bm
.bmWidth
, bm
.bmHeight
,
164 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
171 /***********************************************************************
172 * STATIC_SetEnhMetaFile
174 * Set the enhanced metafile for an SS_ENHMETAFILE control.
176 static HENHMETAFILE
STATIC_SetEnhMetaFile( HWND hwnd
, HENHMETAFILE hEnhMetaFile
, DWORD style
)
178 if ((style
& SS_TYPEMASK
) != SS_ENHMETAFILE
) return 0;
179 if (hEnhMetaFile
&& GetObjectType(hEnhMetaFile
) != OBJ_ENHMETAFILE
) {
180 WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
183 return (HENHMETAFILE
)SetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
, (LONG_PTR
)hEnhMetaFile
);
186 /***********************************************************************
189 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
190 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
192 static HANDLE
STATIC_GetImage( HWND hwnd
, WPARAM wParam
, DWORD style
)
194 switch(style
& SS_TYPEMASK
)
197 if ((wParam
!= IMAGE_ICON
) &&
198 (wParam
!= IMAGE_CURSOR
)) return NULL
;
201 if (wParam
!= IMAGE_BITMAP
) return NULL
;
204 if (wParam
!= IMAGE_ENHMETAFILE
) return NULL
;
209 return (HANDLE
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
);
212 /***********************************************************************
215 * Load the icon for an SS_ICON control.
217 static HICON
STATIC_LoadIconA( HINSTANCE hInstance
, LPCSTR name
, DWORD style
)
221 if (hInstance
&& ((ULONG_PTR
)hInstance
>> 16))
223 if ((style
& SS_REALSIZEIMAGE
) != 0)
224 hicon
= LoadImageA(hInstance
, name
, IMAGE_ICON
, 0, 0, LR_SHARED
);
227 hicon
= LoadIconA( hInstance
, name
);
228 if (!hicon
) hicon
= LoadCursorA( hInstance
, name
);
231 if (!hicon
) hicon
= LoadIconA( 0, name
);
232 /* Windows doesn't try to load a standard cursor,
233 probably because most IDs for standard cursors conflict
234 with the IDs for standard icons anyway */
238 /***********************************************************************
241 * Load the icon for an SS_ICON control.
243 static HICON
STATIC_LoadIconW( HINSTANCE hInstance
, LPCWSTR name
, DWORD style
)
247 if (hInstance
&& ((ULONG_PTR
)hInstance
>> 16))
249 if ((style
& SS_REALSIZEIMAGE
) != 0)
250 hicon
= LoadImageW(hInstance
, name
, IMAGE_ICON
, 0, 0, LR_SHARED
);
253 hicon
= LoadIconW( hInstance
, name
);
254 if (!hicon
) hicon
= LoadCursorW( hInstance
, name
);
257 if (!hicon
) hicon
= LoadIconW( 0, name
);
258 /* Windows doesn't try to load a standard cursor,
259 probably because most IDs for standard cursors conflict
260 with the IDs for standard icons anyway */
264 /***********************************************************************
267 * Try to immediately paint the control.
269 static VOID
STATIC_TryPaintFcn(HWND hwnd
, LONG full_style
)
271 LONG style
= full_style
& SS_TYPEMASK
;
274 GetClientRect( hwnd
, &rc
);
275 if (!IsRectEmpty(&rc
) && IsWindowVisible(hwnd
) && staticPaintFunc
[style
])
281 hrgn
= set_control_clipping( hdc
, &rc
);
282 (staticPaintFunc
[style
])( hwnd
, hdc
, full_style
);
283 SelectClipRgn( hdc
, hrgn
);
284 if (hrgn
) DeleteObject( hrgn
);
285 ReleaseDC( hwnd
, hdc
);
289 static HBRUSH
STATIC_SendWmCtlColorStatic(HWND hwnd
, HDC hdc
)
292 HWND parent
= GetParent(hwnd
);
294 if (!parent
) parent
= hwnd
;
295 hBrush
= (HBRUSH
) SendMessageW( parent
,
296 WM_CTLCOLORSTATIC
, (WPARAM
)hdc
, (LPARAM
)hwnd
);
297 if (!hBrush
) /* did the app forget to call DefWindowProc ? */
299 /* FIXME: DefWindowProc should return different colors if a
300 manifest is present */
301 hBrush
= (HBRUSH
)DefWindowProcW( parent
, WM_CTLCOLORSTATIC
,
302 (WPARAM
)hdc
, (LPARAM
)hwnd
);
307 static VOID
STATIC_InitColours(void)
309 color_3ddkshadow
= GetSysColor(COLOR_3DDKSHADOW
);
310 color_3dshadow
= GetSysColor(COLOR_3DSHADOW
);
311 color_3dhighlight
= GetSysColor(COLOR_3DHIGHLIGHT
);
314 /***********************************************************************
317 * Tests if the control displays text.
319 static BOOL
hasTextStyle( DWORD style
)
321 switch(style
& SS_TYPEMASK
)
325 case SS_LEFTNOWORDWRAP
:
335 /***********************************************************************
336 * StaticWndProc_common
338 LRESULT
StaticWndProc_common( HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
341 LONG full_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
342 LONG style
= full_style
& SS_TYPEMASK
;
344 if (!IsWindow( hwnd
)) return 0;
349 if (style
< 0L || style
> SS_TYPEMASK
)
351 ERR("Unknown style 0x%02x\n", style
);
354 STATIC_InitColours();
358 if (style
== SS_ICON
) {
361 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
363 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
364 * had already been loaded by the application the last thing we want to do is
365 * GlobalFree16 the handle.
369 else return unicode
? DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
) :
370 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
373 /* do all painting in WM_PAINT like Windows does */
381 HDC hdc
= wParam
? (HDC
)wParam
: BeginPaint(hwnd
, &ps
);
382 GetClientRect( hwnd
, &rect
);
383 if (staticPaintFunc
[style
])
385 HRGN hrgn
= set_control_clipping( hdc
, &rect
);
386 (staticPaintFunc
[style
])( hwnd
, hdc
, full_style
);
387 SelectClipRgn( hdc
, hrgn
);
388 if (hrgn
) DeleteObject( hrgn
);
390 if (!wParam
) EndPaint(hwnd
, &ps
);
395 STATIC_TryPaintFcn( hwnd
, full_style
);
396 if (full_style
& SS_NOTIFY
) {
398 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
399 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_ENABLE
), (LPARAM
)hwnd
);
402 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
403 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_DISABLE
), (LPARAM
)hwnd
);
408 case WM_SYSCOLORCHANGE
:
409 STATIC_InitColours();
410 STATIC_TryPaintFcn( hwnd
, full_style
);
415 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
417 if (full_style
& SS_SUNKEN
)
418 SetWindowLongW( hwnd
, GWL_EXSTYLE
,
419 GetWindowLongW( hwnd
, GWL_EXSTYLE
) | WS_EX_STATICEDGE
);
425 if (unicode
|| IS_INTRESOURCE(cs
->lpszName
))
426 hIcon
= STATIC_LoadIconW(cs
->hInstance
, cs
->lpszName
, full_style
);
428 hIcon
= STATIC_LoadIconA(cs
->hInstance
, (LPCSTR
)cs
->lpszName
, full_style
);
429 STATIC_SetIcon(hwnd
, hIcon
, full_style
);
433 if ((ULONG_PTR
)cs
->hInstance
>> 16)
436 if (unicode
|| IS_INTRESOURCE(cs
->lpszName
))
437 hBitmap
= LoadBitmapW(cs
->hInstance
, cs
->lpszName
);
439 hBitmap
= LoadBitmapA(cs
->hInstance
, (LPCSTR
)cs
->lpszName
);
440 STATIC_SetBitmap(hwnd
, hBitmap
, full_style
);
444 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
445 the enhanced metafile that was specified as the window text. */
447 return unicode
? DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
) :
448 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
451 if (hasTextStyle( full_style
))
454 lResult
= DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
456 lResult
= DefWindowProcA( hwnd
, uMsg
, wParam
, lParam
);
457 STATIC_TryPaintFcn( hwnd
, full_style
);
462 if (hasTextStyle( full_style
))
464 SetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
, wParam
);
466 RedrawWindow( hwnd
, NULL
, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_ALLCHILDREN
);
471 return GetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
);
474 if (full_style
& SS_NOTIFY
)
477 return HTTRANSPARENT
;
483 case WM_NCLBUTTONDOWN
:
484 if (full_style
& SS_NOTIFY
)
485 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
486 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_CLICKED
), (LPARAM
)hwnd
);
489 case WM_LBUTTONDBLCLK
:
490 case WM_NCLBUTTONDBLCLK
:
491 if (full_style
& SS_NOTIFY
)
492 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
493 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_DBLCLK
), (LPARAM
)hwnd
);
497 return (LRESULT
)STATIC_GetImage( hwnd
, wParam
, full_style
);
500 return (LRESULT
)STATIC_GetImage( hwnd
, IMAGE_ICON
, full_style
);
505 lResult
= (LRESULT
)STATIC_SetBitmap( hwnd
, (HBITMAP
)lParam
, full_style
);
507 case IMAGE_ENHMETAFILE
:
508 lResult
= (LRESULT
)STATIC_SetEnhMetaFile( hwnd
, (HENHMETAFILE
)lParam
, full_style
);
512 lResult
= (LRESULT
)STATIC_SetIcon( hwnd
, (HICON
)lParam
, full_style
);
515 FIXME("STM_SETIMAGE: Unhandled type %lx\n", wParam
);
518 STATIC_TryPaintFcn( hwnd
, full_style
);
522 lResult
= (LRESULT
)STATIC_SetIcon( hwnd
, (HICON
)wParam
, full_style
);
523 STATIC_TryPaintFcn( hwnd
, full_style
);
527 return unicode
? DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
) :
528 DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
533 static void STATIC_PaintOwnerDrawfn( HWND hwnd
, HDC hdc
, DWORD style
)
536 HFONT font
, oldFont
= NULL
;
537 UINT id
= (UINT
)GetWindowLongPtrW( hwnd
, GWLP_ID
);
539 dis
.CtlType
= ODT_STATIC
;
542 dis
.itemAction
= ODA_DRAWENTIRE
;
543 dis
.itemState
= IsWindowEnabled(hwnd
) ? 0 : ODS_DISABLED
;
547 GetClientRect( hwnd
, &dis
.rcItem
);
549 font
= (HFONT
)GetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
);
550 if (font
) oldFont
= SelectObject( hdc
, font
);
551 SendMessageW( GetParent(hwnd
), WM_CTLCOLORSTATIC
, (WPARAM
)hdc
, (LPARAM
)hwnd
);
552 SendMessageW( GetParent(hwnd
), WM_DRAWITEM
, id
, (LPARAM
)&dis
);
553 if (font
) SelectObject( hdc
, oldFont
);
556 static void STATIC_PaintTextfn( HWND hwnd
, HDC hdc
, DWORD style
)
560 HFONT hFont
, hOldFont
= NULL
;
565 GetClientRect( hwnd
, &rc
);
567 switch (style
& SS_TYPEMASK
)
570 format
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
;
574 format
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
;
578 format
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
;
582 format
= DT_LEFT
| DT_SINGLELINE
;
585 case SS_LEFTNOWORDWRAP
:
586 format
= DT_LEFT
| DT_EXPANDTABS
;
593 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_RIGHT
)
594 format
= DT_RIGHT
| (format
& ~(DT_LEFT
| DT_CENTER
));
596 if (style
& SS_NOPREFIX
)
597 format
|= DT_NOPREFIX
;
599 if ((style
& SS_TYPEMASK
) != SS_SIMPLE
)
601 if (style
& SS_CENTERIMAGE
)
602 format
|= DT_SINGLELINE
| DT_VCENTER
;
603 if (style
& SS_EDITCONTROL
)
604 format
|= DT_EDITCONTROL
;
605 if (style
& SS_ENDELLIPSIS
)
606 format
|= DT_SINGLELINE
| DT_END_ELLIPSIS
;
607 if (style
& SS_PATHELLIPSIS
)
608 format
|= DT_SINGLELINE
| DT_PATH_ELLIPSIS
;
609 if (style
& SS_WORDELLIPSIS
)
610 format
|= DT_SINGLELINE
| DT_WORD_ELLIPSIS
;
613 if ((hFont
= (HFONT
)GetWindowLongPtrW( hwnd
, HFONT_GWL_OFFSET
)))
614 hOldFont
= SelectObject( hdc
, hFont
);
616 /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
618 hBrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
620 if ((style
& SS_TYPEMASK
) != SS_SIMPLE
)
622 FillRect( hdc
, &rc
, hBrush
);
623 if (!IsWindowEnabled(hwnd
)) SetTextColor(hdc
, GetSysColor(COLOR_GRAYTEXT
));
627 if (!(text
= HeapAlloc( GetProcessHeap(), 0, buf_size
* sizeof(WCHAR
) )))
630 while ((len
= InternalGetWindowText( hwnd
, text
, buf_size
)) == buf_size
- 1)
633 if (!(text
= HeapReAlloc( GetProcessHeap(), 0, text
, buf_size
* sizeof(WCHAR
) )))
637 if (!len
) goto no_TextOut
;
639 if (((style
& SS_TYPEMASK
) == SS_SIMPLE
) && (style
& SS_NOPREFIX
))
641 /* Windows uses the faster ExtTextOut() to draw the text and
642 to paint the whole client rectangle with the text background
643 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
644 ExtTextOutW( hdc
, rc
.left
, rc
.top
, ETO_CLIPPED
| ETO_OPAQUE
,
645 &rc
, text
, len
, NULL
);
649 DrawTextW( hdc
, text
, -1, &rc
, format
);
653 HeapFree( GetProcessHeap(), 0, text
);
656 SelectObject( hdc
, hOldFont
);
659 static void STATIC_PaintRectfn( HWND hwnd
, HDC hdc
, DWORD style
)
664 GetClientRect( hwnd
, &rc
);
666 /* FIXME: send WM_CTLCOLORSTATIC */
667 switch (style
& SS_TYPEMASK
)
670 hBrush
= CreateSolidBrush(color_3ddkshadow
);
671 FillRect( hdc
, &rc
, hBrush
);
674 hBrush
= CreateSolidBrush(color_3dshadow
);
675 FillRect( hdc
, &rc
, hBrush
);
678 hBrush
= CreateSolidBrush(color_3dhighlight
);
679 FillRect( hdc
, &rc
, hBrush
);
682 hBrush
= CreateSolidBrush(color_3ddkshadow
);
683 FrameRect( hdc
, &rc
, hBrush
);
686 hBrush
= CreateSolidBrush(color_3dshadow
);
687 FrameRect( hdc
, &rc
, hBrush
);
690 hBrush
= CreateSolidBrush(color_3dhighlight
);
691 FrameRect( hdc
, &rc
, hBrush
);
696 DeleteObject( hBrush
);
700 static void STATIC_PaintIconfn( HWND hwnd
, HDC hdc
, DWORD style
)
707 GetClientRect( hwnd
, &rc
);
708 hbrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
709 hIcon
= (HICON
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
);
710 if (!hIcon
|| !get_icon_size( hIcon
, &size
))
712 FillRect(hdc
, &rc
, hbrush
);
716 if (style
& SS_CENTERIMAGE
)
718 iconRect
.left
= (rc
.right
- rc
.left
) / 2 - size
.cx
/ 2;
719 iconRect
.top
= (rc
.bottom
- rc
.top
) / 2 - size
.cy
/ 2;
720 iconRect
.right
= iconRect
.left
+ size
.cx
;
721 iconRect
.bottom
= iconRect
.top
+ size
.cy
;
725 FillRect( hdc
, &rc
, hbrush
);
726 DrawIconEx( hdc
, iconRect
.left
, iconRect
.top
, hIcon
, iconRect
.right
- iconRect
.left
,
727 iconRect
.bottom
- iconRect
.top
, 0, NULL
, DI_NORMAL
);
731 static void STATIC_PaintBitmapfn(HWND hwnd
, HDC hdc
, DWORD style
)
734 HBITMAP hBitmap
, oldbitmap
;
736 /* message is still sent, even if the returned brush is not used */
737 STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
739 if ((hBitmap
= (HBITMAP
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
))
740 && (GetObjectType(hBitmap
) == OBJ_BITMAP
)
741 && (hMemDC
= CreateCompatibleDC( hdc
)))
746 GetObjectW(hBitmap
, sizeof(bm
), &bm
);
747 oldbitmap
= SelectObject(hMemDC
, hBitmap
);
749 GetClientRect(hwnd
, &rcClient
);
750 if (style
& SS_CENTERIMAGE
)
752 HBRUSH hbrush
= CreateSolidBrush(GetPixel(hMemDC
, 0, 0));
754 FillRect(hdc
, &rcClient
, hbrush
);
756 rcClient
.left
= (rcClient
.right
- rcClient
.left
)/2 - bm
.bmWidth
/2;
757 rcClient
.top
= (rcClient
.bottom
- rcClient
.top
)/2 - bm
.bmHeight
/2;
758 rcClient
.right
= rcClient
.left
+ bm
.bmWidth
;
759 rcClient
.bottom
= rcClient
.top
+ bm
.bmHeight
;
761 DeleteObject(hbrush
);
763 StretchBlt(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
- rcClient
.left
,
764 rcClient
.bottom
- rcClient
.top
, hMemDC
,
765 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
766 SelectObject(hMemDC
, oldbitmap
);
772 static void STATIC_PaintEnhMetafn(HWND hwnd
, HDC hdc
, DWORD style
)
774 HENHMETAFILE hEnhMetaFile
;
778 GetClientRect(hwnd
, &rc
);
779 hbrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
780 FillRect(hdc
, &rc
, hbrush
);
781 if ((hEnhMetaFile
= (HENHMETAFILE
)GetWindowLongPtrW( hwnd
, HICON_GWL_OFFSET
)))
783 /* The control's current font is not selected into the
785 if (GetObjectType(hEnhMetaFile
) == OBJ_ENHMETAFILE
)
786 PlayEnhMetaFile(hdc
, hEnhMetaFile
, &rc
);
791 static void STATIC_PaintEtchedfn( HWND hwnd
, HDC hdc
, DWORD style
)
795 /* FIXME: sometimes (not always) sends WM_CTLCOLORSTATIC */
796 GetClientRect( hwnd
, &rc
);
797 switch (style
& SS_TYPEMASK
)
800 DrawEdge(hdc
,&rc
,EDGE_ETCHED
,BF_TOP
|BF_BOTTOM
);
803 DrawEdge(hdc
,&rc
,EDGE_ETCHED
,BF_LEFT
|BF_RIGHT
);
806 DrawEdge (hdc
, &rc
, EDGE_ETCHED
, BF_RECT
);