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).
39 #include "wine/heap.h"
40 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(static);
46 static void STATIC_PaintOwnerDrawfn( HWND hwnd
, HDC hdc
, DWORD style
);
47 static void STATIC_PaintTextfn( HWND hwnd
, HDC hdc
, DWORD style
);
48 static void STATIC_PaintRectfn( HWND hwnd
, HDC hdc
, DWORD style
);
49 static void STATIC_PaintIconfn( HWND hwnd
, HDC hdc
, DWORD style
);
50 static void STATIC_PaintBitmapfn( HWND hwnd
, HDC hdc
, DWORD style
);
51 static void STATIC_PaintEnhMetafn( HWND hwnd
, HDC hdc
, DWORD style
);
52 static void STATIC_PaintEtchedfn( HWND hwnd
, HDC hdc
, DWORD style
);
54 struct static_extra_info
66 typedef void (*pfPaint
)( HWND hwnd
, HDC hdc
, DWORD style
);
68 static const pfPaint staticPaintFunc
[SS_TYPEMASK
+1] =
70 STATIC_PaintTextfn
, /* SS_LEFT */
71 STATIC_PaintTextfn
, /* SS_CENTER */
72 STATIC_PaintTextfn
, /* SS_RIGHT */
73 STATIC_PaintIconfn
, /* SS_ICON */
74 STATIC_PaintRectfn
, /* SS_BLACKRECT */
75 STATIC_PaintRectfn
, /* SS_GRAYRECT */
76 STATIC_PaintRectfn
, /* SS_WHITERECT */
77 STATIC_PaintRectfn
, /* SS_BLACKFRAME */
78 STATIC_PaintRectfn
, /* SS_GRAYFRAME */
79 STATIC_PaintRectfn
, /* SS_WHITEFRAME */
80 NULL
, /* SS_USERITEM */
81 STATIC_PaintTextfn
, /* SS_SIMPLE */
82 STATIC_PaintTextfn
, /* SS_LEFTNOWORDWRAP */
83 STATIC_PaintOwnerDrawfn
, /* SS_OWNERDRAW */
84 STATIC_PaintBitmapfn
, /* SS_BITMAP */
85 STATIC_PaintEnhMetafn
, /* SS_ENHMETAFILE */
86 STATIC_PaintEtchedfn
, /* SS_ETCHEDHORZ */
87 STATIC_PaintEtchedfn
, /* SS_ETCHEDVERT */
88 STATIC_PaintEtchedfn
, /* SS_ETCHEDFRAME */
91 static struct static_extra_info
*get_extra_ptr( HWND hwnd
, BOOL force
)
93 struct static_extra_info
*extra
= (struct static_extra_info
*)GetWindowLongPtrW( hwnd
, 0 );
96 extra
= heap_alloc_zero( sizeof(*extra
) );
98 SetWindowLongPtrW( hwnd
, 0, (ULONG_PTR
)extra
);
103 static BOOL
get_icon_size( HICON handle
, SIZE
*size
)
109 if (!GetIconInfo(handle
, &info
))
112 ret
= GetObjectW(info
.hbmColor
, sizeof(bmp
), &bmp
);
115 size
->cx
= bmp
.bmWidth
;
116 size
->cy
= bmp
.bmHeight
;
119 DeleteObject(info
.hbmMask
);
120 DeleteObject(info
.hbmColor
);
125 /***********************************************************************
128 * Set the icon for an SS_ICON control.
130 static HICON
STATIC_SetIcon( HWND hwnd
, HICON hicon
, DWORD style
)
134 struct static_extra_info
*extra
;
136 if ((style
& SS_TYPEMASK
) != SS_ICON
) return 0;
137 if (hicon
&& !get_icon_size( hicon
, &size
))
139 WARN("hicon != 0, but invalid\n");
143 extra
= get_extra_ptr( hwnd
, TRUE
);
144 if (!extra
) return 0;
146 prevIcon
= extra
->image
.hicon
;
147 extra
->image
.hicon
= hicon
;
148 if (hicon
&& !(style
& SS_CENTERIMAGE
) && !(style
& SS_REALSIZECONTROL
))
150 /* Windows currently doesn't implement SS_RIGHTJUST */
152 if ((style & SS_RIGHTJUST) != 0)
155 GetWindowRect(hwnd, &wr);
156 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
157 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
161 SetWindowPos( hwnd
, 0, 0, 0, size
.cx
, size
.cy
, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
167 static HBITMAP
create_alpha_bitmap( HBITMAP hbitmap
)
176 BOOL has_alpha
= FALSE
;
178 GetObjectW( hbitmap
, sizeof(bm
), &bm
);
179 if (bm
.bmBitsPixel
!= 32) return 0;
181 if (!(hdc
= CreateCompatibleDC( 0 ))) return 0;
183 info
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
184 info
.bmiHeader
.biWidth
= bm
.bmWidth
;
185 info
.bmiHeader
.biHeight
= -bm
.bmHeight
;
186 info
.bmiHeader
.biPlanes
= 1;
187 info
.bmiHeader
.biBitCount
= 32;
188 info
.bmiHeader
.biCompression
= BI_RGB
;
189 info
.bmiHeader
.biSizeImage
= bm
.bmWidth
* bm
.bmHeight
* 4;
190 info
.bmiHeader
.biXPelsPerMeter
= 0;
191 info
.bmiHeader
.biYPelsPerMeter
= 0;
192 info
.bmiHeader
.biClrUsed
= 0;
193 info
.bmiHeader
.biClrImportant
= 0;
194 if ((alpha
= CreateDIBSection( hdc
, &info
, DIB_RGB_COLORS
, &bits
, NULL
, 0 )))
196 GetDIBits( hdc
, hbitmap
, 0, bm
.bmHeight
, bits
, &info
, DIB_RGB_COLORS
);
198 for (i
= 0, ptr
= bits
; i
< bm
.bmWidth
* bm
.bmHeight
; i
++, ptr
+= 4)
199 if ((has_alpha
= (ptr
[3] != 0))) break;
203 DeleteObject( alpha
);
213 /***********************************************************************
216 * Set the bitmap for an SS_BITMAP control.
218 static HBITMAP
STATIC_SetBitmap( HWND hwnd
, HBITMAP hBitmap
, DWORD style
)
220 HBITMAP hOldBitmap
, alpha
;
221 struct static_extra_info
*extra
;
223 if ((style
& SS_TYPEMASK
) != SS_BITMAP
) return 0;
224 if (hBitmap
&& GetObjectType(hBitmap
) != OBJ_BITMAP
)
226 WARN("hBitmap != 0, but it's not a bitmap\n");
230 extra
= get_extra_ptr( hwnd
, TRUE
);
231 if (!extra
) return 0;
233 hOldBitmap
= extra
->image
.hbitmap
;
234 extra
->image
.hbitmap
= hBitmap
;
235 extra
->image_has_alpha
= FALSE
;
239 alpha
= create_alpha_bitmap( hBitmap
);
242 extra
->image
.hbitmap
= alpha
;
243 extra
->image_has_alpha
= TRUE
;
247 if (hBitmap
&& !(style
& SS_CENTERIMAGE
) && !(style
& SS_REALSIZECONTROL
))
250 GetObjectW(hBitmap
, sizeof(bm
), &bm
);
252 /* Windows currently doesn't implement SS_RIGHTJUST */
254 if ((style & SS_RIGHTJUST) != 0)
257 GetWindowRect(hwnd, &wr);
258 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
259 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
263 SetWindowPos( hwnd
, 0, 0, 0, bm
.bmWidth
, bm
.bmHeight
,
264 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
270 /***********************************************************************
271 * STATIC_SetEnhMetaFile
273 * Set the enhanced metafile for an SS_ENHMETAFILE control.
275 static HENHMETAFILE
STATIC_SetEnhMetaFile( HWND hwnd
, HENHMETAFILE hEnhMetaFile
, DWORD style
)
277 HENHMETAFILE old_hemf
;
278 struct static_extra_info
*extra
;
280 if ((style
& SS_TYPEMASK
) != SS_ENHMETAFILE
) return 0;
281 if (hEnhMetaFile
&& GetObjectType(hEnhMetaFile
) != OBJ_ENHMETAFILE
)
283 WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
287 extra
= get_extra_ptr( hwnd
, TRUE
);
288 if (!extra
) return 0;
290 old_hemf
= extra
->image
.hemf
;
291 extra
->image
.hemf
= hEnhMetaFile
;
296 /***********************************************************************
299 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
300 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
302 static HANDLE
STATIC_GetImage( HWND hwnd
, WPARAM wParam
, DWORD style
)
304 struct static_extra_info
*extra
;
306 switch (style
& SS_TYPEMASK
)
309 if ((wParam
!= IMAGE_ICON
) &&
310 (wParam
!= IMAGE_CURSOR
)) return NULL
;
313 if (wParam
!= IMAGE_BITMAP
) return NULL
;
316 if (wParam
!= IMAGE_ENHMETAFILE
) return NULL
;
322 extra
= get_extra_ptr( hwnd
, FALSE
);
323 return extra
? extra
->image
.hbitmap
: 0;
326 static void STATIC_SetFont( HWND hwnd
, HFONT hfont
)
328 struct static_extra_info
*extra
= get_extra_ptr( hwnd
, TRUE
);
330 extra
->hfont
= hfont
;
333 static HFONT
STATIC_GetFont( HWND hwnd
)
335 struct static_extra_info
*extra
= get_extra_ptr( hwnd
, FALSE
);
336 return extra
? extra
->hfont
: 0;
339 /***********************************************************************
342 * Load the icon for an SS_ICON control.
344 static HICON
STATIC_LoadIconW( HINSTANCE hInstance
, LPCWSTR name
, DWORD style
)
348 if (hInstance
&& ((ULONG_PTR
)hInstance
>> 16))
350 if ((style
& SS_REALSIZEIMAGE
) != 0)
351 hicon
= LoadImageW(hInstance
, name
, IMAGE_ICON
, 0, 0, LR_SHARED
);
354 hicon
= LoadIconW( hInstance
, name
);
355 if (!hicon
) hicon
= LoadCursorW( hInstance
, name
);
358 if (!hicon
) hicon
= LoadIconW( 0, name
);
359 /* Windows doesn't try to load a standard cursor,
360 probably because most IDs for standard cursors conflict
361 with the IDs for standard icons anyway */
365 /***********************************************************************
368 * Try to immediately paint the control.
370 static VOID
STATIC_TryPaintFcn(HWND hwnd
, LONG full_style
)
372 LONG style
= full_style
& SS_TYPEMASK
;
375 GetClientRect( hwnd
, &rc
);
376 if (!IsRectEmpty(&rc
) && IsWindowVisible(hwnd
) && staticPaintFunc
[style
])
382 hrgn
= set_control_clipping( hdc
, &rc
);
383 (staticPaintFunc
[style
])( hwnd
, hdc
, full_style
);
384 SelectClipRgn( hdc
, hrgn
);
385 if (hrgn
) DeleteObject( hrgn
);
386 ReleaseDC( hwnd
, hdc
);
390 static HBRUSH
STATIC_SendWmCtlColorStatic(HWND hwnd
, HDC hdc
)
393 HWND parent
= GetParent(hwnd
);
395 if (!parent
) parent
= hwnd
;
396 hBrush
= (HBRUSH
) SendMessageW( parent
, WM_CTLCOLORSTATIC
, (WPARAM
)hdc
, (LPARAM
)hwnd
);
397 if (!hBrush
) /* did the app forget to call DefWindowProc ? */
399 /* FIXME: DefWindowProc should return different colors if a
400 manifest is present */
401 hBrush
= (HBRUSH
)DefWindowProcW( parent
, WM_CTLCOLORSTATIC
, (WPARAM
)hdc
, (LPARAM
)hwnd
);
406 /***********************************************************************
409 * Tests if the control displays text.
411 static BOOL
hasTextStyle( DWORD style
)
413 switch (style
& SS_TYPEMASK
)
417 case SS_LEFTNOWORDWRAP
:
427 static LRESULT CALLBACK
STATIC_WindowProc( HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
430 LONG full_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
431 LONG style
= full_style
& SS_TYPEMASK
;
433 if (!IsWindow( hwnd
)) return 0;
438 if (style
< 0L || style
> SS_TYPEMASK
)
440 ERR("Unknown style 0x%02x\n", style
);
446 if (style
== SS_ICON
)
448 struct static_extra_info
*extra
= get_extra_ptr( hwnd
, FALSE
);
451 if (extra
->image_has_alpha
)
452 DeleteObject( extra
->image
.hbitmap
);
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.
466 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
469 /* do all painting in WM_PAINT like Windows does */
477 HDC hdc
= wParam
? (HDC
)wParam
: BeginPaint(hwnd
, &ps
);
478 GetClientRect( hwnd
, &rect
);
479 if (staticPaintFunc
[style
])
481 HRGN hrgn
= set_control_clipping( hdc
, &rect
);
482 (staticPaintFunc
[style
])( hwnd
, hdc
, full_style
);
483 SelectClipRgn( hdc
, hrgn
);
484 if (hrgn
) DeleteObject( hrgn
);
486 if (!wParam
) EndPaint(hwnd
, &ps
);
491 STATIC_TryPaintFcn( hwnd
, full_style
);
492 if (full_style
& SS_NOTIFY
)
495 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
496 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_ENABLE
), (LPARAM
)hwnd
);
498 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
499 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_DISABLE
), (LPARAM
)hwnd
);
503 case WM_SYSCOLORCHANGE
:
504 COMCTL32_RefreshSysColors();
505 STATIC_TryPaintFcn( hwnd
, full_style
);
510 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
512 if (full_style
& SS_SUNKEN
)
513 SetWindowLongW( hwnd
, GWL_EXSTYLE
,
514 GetWindowLongW( hwnd
, GWL_EXSTYLE
) | WS_EX_STATICEDGE
);
522 hIcon
= STATIC_LoadIconW(cs
->hInstance
, cs
->lpszName
, full_style
);
523 STATIC_SetIcon(hwnd
, hIcon
, full_style
);
527 if ((ULONG_PTR
)cs
->hInstance
>> 16)
530 hBitmap
= LoadBitmapW(cs
->hInstance
, cs
->lpszName
);
531 STATIC_SetBitmap(hwnd
, hBitmap
, full_style
);
535 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
536 the enhanced metafile that was specified as the window text. */
538 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
541 if (hasTextStyle( full_style
))
543 lResult
= DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
544 STATIC_TryPaintFcn( hwnd
, full_style
);
549 if (hasTextStyle( full_style
))
551 STATIC_SetFont( hwnd
, (HFONT
)wParam
);
553 RedrawWindow( hwnd
, NULL
, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_ALLCHILDREN
);
558 return (LRESULT
)STATIC_GetFont( hwnd
);
561 if (full_style
& SS_NOTIFY
)
564 return HTTRANSPARENT
;
570 case WM_NCLBUTTONDOWN
:
571 if (full_style
& SS_NOTIFY
)
572 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
573 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_CLICKED
), (LPARAM
)hwnd
);
576 case WM_LBUTTONDBLCLK
:
577 case WM_NCLBUTTONDBLCLK
:
578 if (full_style
& SS_NOTIFY
)
579 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
580 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_DBLCLK
), (LPARAM
)hwnd
);
584 return (LRESULT
)STATIC_GetImage( hwnd
, wParam
, full_style
);
587 return (LRESULT
)STATIC_GetImage( hwnd
, IMAGE_ICON
, full_style
);
593 lResult
= (LRESULT
)STATIC_SetBitmap( hwnd
, (HBITMAP
)lParam
, full_style
);
595 case IMAGE_ENHMETAFILE
:
596 lResult
= (LRESULT
)STATIC_SetEnhMetaFile( hwnd
, (HENHMETAFILE
)lParam
, full_style
);
600 lResult
= (LRESULT
)STATIC_SetIcon( hwnd
, (HICON
)lParam
, full_style
);
603 FIXME("STM_SETIMAGE: Unhandled type %lx\n", wParam
);
606 STATIC_TryPaintFcn( hwnd
, full_style
);
610 lResult
= (LRESULT
)STATIC_SetIcon( hwnd
, (HICON
)wParam
, full_style
);
611 STATIC_TryPaintFcn( hwnd
, full_style
);
615 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
620 static void STATIC_PaintOwnerDrawfn( HWND hwnd
, HDC hdc
, DWORD style
)
623 HFONT font
, oldFont
= NULL
;
624 UINT id
= (UINT
)GetWindowLongPtrW( hwnd
, GWLP_ID
);
626 dis
.CtlType
= ODT_STATIC
;
629 dis
.itemAction
= ODA_DRAWENTIRE
;
630 dis
.itemState
= IsWindowEnabled(hwnd
) ? 0 : ODS_DISABLED
;
634 GetClientRect( hwnd
, &dis
.rcItem
);
636 font
= STATIC_GetFont( hwnd
);
637 if (font
) oldFont
= SelectObject( hdc
, font
);
638 SendMessageW( GetParent(hwnd
), WM_CTLCOLORSTATIC
, (WPARAM
)hdc
, (LPARAM
)hwnd
);
639 SendMessageW( GetParent(hwnd
), WM_DRAWITEM
, id
, (LPARAM
)&dis
);
640 if (font
) SelectObject( hdc
, oldFont
);
643 static void STATIC_PaintTextfn( HWND hwnd
, HDC hdc
, DWORD style
)
647 HFONT hFont
, hOldFont
= NULL
;
652 GetClientRect( hwnd
, &rc
);
654 switch (style
& SS_TYPEMASK
)
657 format
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
;
661 format
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
;
665 format
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
;
669 format
= DT_LEFT
| DT_SINGLELINE
;
672 case SS_LEFTNOWORDWRAP
:
673 format
= DT_LEFT
| DT_EXPANDTABS
;
680 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_RIGHT
)
681 format
= DT_RIGHT
| (format
& ~(DT_LEFT
| DT_CENTER
));
683 if (style
& SS_NOPREFIX
)
684 format
|= DT_NOPREFIX
;
686 if ((style
& SS_TYPEMASK
) != SS_SIMPLE
)
688 if (style
& SS_CENTERIMAGE
)
689 format
|= DT_SINGLELINE
| DT_VCENTER
;
690 if (style
& SS_EDITCONTROL
)
691 format
|= DT_EDITCONTROL
;
692 if (style
& SS_ENDELLIPSIS
)
693 format
|= DT_SINGLELINE
| DT_END_ELLIPSIS
;
694 if (style
& SS_PATHELLIPSIS
)
695 format
|= DT_SINGLELINE
| DT_PATH_ELLIPSIS
;
696 if (style
& SS_WORDELLIPSIS
)
697 format
|= DT_SINGLELINE
| DT_WORD_ELLIPSIS
;
700 if ((hFont
= STATIC_GetFont( hwnd
)))
701 hOldFont
= SelectObject( hdc
, hFont
);
703 /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
705 hBrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
707 if ((style
& SS_TYPEMASK
) != SS_SIMPLE
)
709 FillRect( hdc
, &rc
, hBrush
);
710 if (!IsWindowEnabled(hwnd
)) SetTextColor(hdc
, GetSysColor(COLOR_GRAYTEXT
));
714 if (!(text
= HeapAlloc( GetProcessHeap(), 0, buf_size
* sizeof(WCHAR
) )))
717 while ((len
= InternalGetWindowText( hwnd
, text
, buf_size
)) == buf_size
- 1)
720 if (!(text
= HeapReAlloc( GetProcessHeap(), 0, text
, buf_size
* sizeof(WCHAR
) )))
724 if (!len
) goto no_TextOut
;
726 if (((style
& SS_TYPEMASK
) == SS_SIMPLE
) && (style
& SS_NOPREFIX
))
728 /* Windows uses the faster ExtTextOut() to draw the text and
729 to paint the whole client rectangle with the text background
730 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
731 ExtTextOutW( hdc
, rc
.left
, rc
.top
, ETO_CLIPPED
| ETO_OPAQUE
,
732 &rc
, text
, len
, NULL
);
736 DrawTextW( hdc
, text
, -1, &rc
, format
);
740 HeapFree( GetProcessHeap(), 0, text
);
743 SelectObject( hdc
, hOldFont
);
746 static void STATIC_PaintRectfn( HWND hwnd
, HDC hdc
, DWORD style
)
751 GetClientRect( hwnd
, &rc
);
753 /* FIXME: send WM_CTLCOLORSTATIC */
754 switch (style
& SS_TYPEMASK
)
757 hBrush
= CreateSolidBrush(comctl32_color
.clr3dDkShadow
);
758 FillRect( hdc
, &rc
, hBrush
);
761 hBrush
= CreateSolidBrush(comctl32_color
.clr3dShadow
);
762 FillRect( hdc
, &rc
, hBrush
);
765 hBrush
= CreateSolidBrush(comctl32_color
.clr3dHilight
);
766 FillRect( hdc
, &rc
, hBrush
);
769 hBrush
= CreateSolidBrush(comctl32_color
.clr3dDkShadow
);
770 FrameRect( hdc
, &rc
, hBrush
);
773 hBrush
= CreateSolidBrush(comctl32_color
.clr3dShadow
);
774 FrameRect( hdc
, &rc
, hBrush
);
777 hBrush
= CreateSolidBrush(comctl32_color
.clr3dHilight
);
778 FrameRect( hdc
, &rc
, hBrush
);
783 DeleteObject( hBrush
);
787 static void STATIC_PaintIconfn( HWND hwnd
, HDC hdc
, DWORD style
)
794 GetClientRect( hwnd
, &rc
);
795 hbrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
796 hIcon
= STATIC_GetImage( hwnd
, IMAGE_ICON
, style
);
797 if (!hIcon
|| !get_icon_size( hIcon
, &size
))
799 FillRect(hdc
, &rc
, hbrush
);
803 if (style
& SS_CENTERIMAGE
)
805 iconRect
.left
= (rc
.right
- rc
.left
) / 2 - size
.cx
/ 2;
806 iconRect
.top
= (rc
.bottom
- rc
.top
) / 2 - size
.cy
/ 2;
807 iconRect
.right
= iconRect
.left
+ size
.cx
;
808 iconRect
.bottom
= iconRect
.top
+ size
.cy
;
812 FillRect( hdc
, &rc
, hbrush
);
813 DrawIconEx( hdc
, iconRect
.left
, iconRect
.top
, hIcon
, iconRect
.right
- iconRect
.left
,
814 iconRect
.bottom
- iconRect
.top
, 0, NULL
, DI_NORMAL
);
818 static void STATIC_PaintBitmapfn(HWND hwnd
, HDC hdc
, DWORD style
)
821 HBITMAP hBitmap
, oldbitmap
;
824 hbrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
826 if ((hBitmap
= STATIC_GetImage( hwnd
, IMAGE_BITMAP
, style
))
827 && (GetObjectType(hBitmap
) == OBJ_BITMAP
)
828 && (hMemDC
= CreateCompatibleDC( hdc
)))
833 BLENDFUNCTION blend
= { AC_SRC_OVER
, 0, 255, AC_SRC_ALPHA
};
834 struct static_extra_info
*extra
= get_extra_ptr( hwnd
, FALSE
);
836 GetObjectW(hBitmap
, sizeof(bm
), &bm
);
837 oldbitmap
= SelectObject(hMemDC
, hBitmap
);
839 /* Set the background color for monochrome bitmaps
840 to the color of the background brush */
841 if (GetObjectW( hbrush
, sizeof(brush
), &brush
))
843 if (brush
.lbStyle
== BS_SOLID
)
844 SetBkColor(hdc
, brush
.lbColor
);
846 GetClientRect(hwnd
, &rcClient
);
847 if (style
& SS_CENTERIMAGE
)
849 FillRect( hdc
, &rcClient
, hbrush
);
850 rcClient
.left
= (rcClient
.right
- rcClient
.left
)/2 - bm
.bmWidth
/2;
851 rcClient
.top
= (rcClient
.bottom
- rcClient
.top
)/2 - bm
.bmHeight
/2;
852 rcClient
.right
= rcClient
.left
+ bm
.bmWidth
;
853 rcClient
.bottom
= rcClient
.top
+ bm
.bmHeight
;
856 if (extra
->image_has_alpha
)
857 GdiAlphaBlend(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
- rcClient
.left
,
858 rcClient
.bottom
- rcClient
.top
, hMemDC
,
859 0, 0, bm
.bmWidth
, bm
.bmHeight
, blend
);
861 StretchBlt(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
- rcClient
.left
,
862 rcClient
.bottom
- rcClient
.top
, hMemDC
,
863 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
864 SelectObject(hMemDC
, oldbitmap
);
869 static void STATIC_PaintEnhMetafn(HWND hwnd
, HDC hdc
, DWORD style
)
871 HENHMETAFILE hEnhMetaFile
;
875 GetClientRect(hwnd
, &rc
);
876 hbrush
= STATIC_SendWmCtlColorStatic(hwnd
, hdc
);
877 FillRect(hdc
, &rc
, hbrush
);
878 if ((hEnhMetaFile
= STATIC_GetImage( hwnd
, IMAGE_ENHMETAFILE
, style
)))
880 /* The control's current font is not selected into the
882 if (GetObjectType(hEnhMetaFile
) == OBJ_ENHMETAFILE
)
883 PlayEnhMetaFile(hdc
, hEnhMetaFile
, &rc
);
887 static void STATIC_PaintEtchedfn( HWND hwnd
, HDC hdc
, DWORD style
)
891 /* FIXME: sometimes (not always) sends WM_CTLCOLORSTATIC */
892 GetClientRect( hwnd
, &rc
);
893 switch (style
& SS_TYPEMASK
)
896 DrawEdge(hdc
, &rc
, EDGE_ETCHED
, BF_TOP
| BF_BOTTOM
);
899 DrawEdge(hdc
, &rc
, EDGE_ETCHED
, BF_LEFT
| BF_RIGHT
);
902 DrawEdge(hdc
, &rc
, EDGE_ETCHED
, BF_RECT
);
907 void STATIC_Register(void)
911 memset(&wndClass
, 0, sizeof(wndClass
));
912 wndClass
.style
= CS_DBLCLKS
| CS_PARENTDC
| CS_GLOBALCLASS
;
913 wndClass
.lpfnWndProc
= STATIC_WindowProc
;
914 wndClass
.cbClsExtra
= 0;
915 wndClass
.cbWndExtra
= sizeof(struct static_extra_info
*);
916 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
917 wndClass
.hbrBackground
= NULL
;
918 wndClass
.lpszClassName
= WC_STATICW
;
919 RegisterClassW(&wndClass
);