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).
41 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(static);
47 static void STATIC_PaintOwnerDrawfn( HWND hwnd
, HDC hdc
, HBRUSH hbrush
, DWORD style
);
48 static void STATIC_PaintTextfn( HWND hwnd
, HDC hdc
, HBRUSH hbrush
, DWORD style
);
49 static void STATIC_PaintRectfn( HWND hwnd
, HDC hdc
, HBRUSH hbrush
, DWORD style
);
50 static void STATIC_PaintIconfn( HWND hwnd
, HDC hdc
, HBRUSH hbrush
, DWORD style
);
51 static void STATIC_PaintBitmapfn( HWND hwnd
, HDC hdc
, HBRUSH hbrush
, DWORD style
);
52 static void STATIC_PaintEnhMetafn( HWND hwnd
, HDC hdc
, HBRUSH hbrush
, DWORD style
);
53 static void STATIC_PaintEtchedfn( HWND hwnd
, HDC hdc
, HBRUSH hbrush
, DWORD style
);
55 struct static_extra_info
67 typedef void (*pfPaint
)( HWND hwnd
, HDC hdc
, HBRUSH hbrush
, DWORD style
);
69 static const pfPaint staticPaintFunc
[SS_TYPEMASK
+1] =
71 STATIC_PaintTextfn
, /* SS_LEFT */
72 STATIC_PaintTextfn
, /* SS_CENTER */
73 STATIC_PaintTextfn
, /* SS_RIGHT */
74 STATIC_PaintIconfn
, /* SS_ICON */
75 STATIC_PaintRectfn
, /* SS_BLACKRECT */
76 STATIC_PaintRectfn
, /* SS_GRAYRECT */
77 STATIC_PaintRectfn
, /* SS_WHITERECT */
78 STATIC_PaintRectfn
, /* SS_BLACKFRAME */
79 STATIC_PaintRectfn
, /* SS_GRAYFRAME */
80 STATIC_PaintRectfn
, /* SS_WHITEFRAME */
81 NULL
, /* SS_USERITEM */
82 STATIC_PaintTextfn
, /* SS_SIMPLE */
83 STATIC_PaintTextfn
, /* SS_LEFTNOWORDWRAP */
84 STATIC_PaintOwnerDrawfn
, /* SS_OWNERDRAW */
85 STATIC_PaintBitmapfn
, /* SS_BITMAP */
86 STATIC_PaintEnhMetafn
, /* SS_ENHMETAFILE */
87 NULL
, /* SS_ETCHEDHORZ */
88 NULL
, /* SS_ETCHEDVERT */
89 STATIC_PaintEtchedfn
, /* SS_ETCHEDFRAME */
92 static struct static_extra_info
*get_extra_ptr( HWND hwnd
, BOOL force
)
94 struct static_extra_info
*extra
= (struct static_extra_info
*)GetWindowLongPtrW( hwnd
, 0 );
97 extra
= Alloc( sizeof(*extra
) );
99 SetWindowLongPtrW( hwnd
, 0, (ULONG_PTR
)extra
);
104 static BOOL
get_icon_size( HICON handle
, SIZE
*size
)
110 if (!GetIconInfo(handle
, &info
))
113 ret
= GetObjectW(info
.hbmColor
, sizeof(bmp
), &bmp
);
116 size
->cx
= bmp
.bmWidth
;
117 size
->cy
= bmp
.bmHeight
;
120 DeleteObject(info
.hbmMask
);
121 DeleteObject(info
.hbmColor
);
126 /***********************************************************************
129 * Set the icon for an SS_ICON control.
131 static HICON
STATIC_SetIcon( HWND hwnd
, HICON hicon
, DWORD style
)
135 struct static_extra_info
*extra
;
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
);
208 /* pre-multiply by alpha */
209 for (i
= 0, ptr
= bits
; i
< bm
.bmWidth
* bm
.bmHeight
; i
++, ptr
+= 4)
211 unsigned int alpha
= ptr
[3];
212 ptr
[0] = (ptr
[0] * alpha
+ 127) / 255;
213 ptr
[1] = (ptr
[1] * alpha
+ 127) / 255;
214 ptr
[2] = (ptr
[2] * alpha
+ 127) / 255;
224 /***********************************************************************
227 * Set the bitmap for an SS_BITMAP control.
229 static HBITMAP
STATIC_SetBitmap( HWND hwnd
, HBITMAP hBitmap
, DWORD style
)
231 HBITMAP hOldBitmap
, alpha
;
232 struct static_extra_info
*extra
;
234 if (hBitmap
&& GetObjectType(hBitmap
) != OBJ_BITMAP
)
236 WARN("hBitmap != 0, but it's not a bitmap\n");
240 extra
= get_extra_ptr( hwnd
, TRUE
);
241 if (!extra
) return 0;
243 hOldBitmap
= extra
->image
.hbitmap
;
244 extra
->image
.hbitmap
= hBitmap
;
245 extra
->image_has_alpha
= FALSE
;
249 alpha
= create_alpha_bitmap( hBitmap
);
252 extra
->image
.hbitmap
= alpha
;
253 extra
->image_has_alpha
= TRUE
;
257 if (hBitmap
&& !(style
& SS_CENTERIMAGE
) && !(style
& SS_REALSIZECONTROL
))
260 GetObjectW(hBitmap
, sizeof(bm
), &bm
);
262 /* Windows currently doesn't implement SS_RIGHTJUST */
264 if ((style & SS_RIGHTJUST) != 0)
267 GetWindowRect(hwnd, &wr);
268 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
269 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
273 SetWindowPos( hwnd
, 0, 0, 0, bm
.bmWidth
, bm
.bmHeight
,
274 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
280 /***********************************************************************
281 * STATIC_SetEnhMetaFile
283 * Set the enhanced metafile for an SS_ENHMETAFILE control.
285 static HENHMETAFILE
STATIC_SetEnhMetaFile( HWND hwnd
, HENHMETAFILE hEnhMetaFile
, DWORD style
)
287 HENHMETAFILE old_hemf
;
288 struct static_extra_info
*extra
;
290 if (hEnhMetaFile
&& GetObjectType(hEnhMetaFile
) != OBJ_ENHMETAFILE
)
292 WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
296 extra
= get_extra_ptr( hwnd
, TRUE
);
297 if (!extra
) return 0;
299 old_hemf
= extra
->image
.hemf
;
300 extra
->image
.hemf
= hEnhMetaFile
;
305 /***********************************************************************
308 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
309 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
311 static HANDLE
STATIC_GetImage( HWND hwnd
, WPARAM wParam
, DWORD style
)
313 struct static_extra_info
*extra
;
315 switch (style
& SS_TYPEMASK
)
318 if ((wParam
!= IMAGE_ICON
) &&
319 (wParam
!= IMAGE_CURSOR
)) return NULL
;
322 if (wParam
!= IMAGE_BITMAP
) return NULL
;
325 if (wParam
!= IMAGE_ENHMETAFILE
) return NULL
;
331 extra
= get_extra_ptr( hwnd
, FALSE
);
332 return extra
? extra
->image
.hbitmap
: 0;
335 static void STATIC_SetFont( HWND hwnd
, HFONT hfont
)
337 struct static_extra_info
*extra
= get_extra_ptr( hwnd
, TRUE
);
339 extra
->hfont
= hfont
;
342 static HFONT
STATIC_GetFont( HWND hwnd
)
344 struct static_extra_info
*extra
= get_extra_ptr( hwnd
, FALSE
);
345 return extra
? extra
->hfont
: 0;
348 /***********************************************************************
351 * Load the icon for an SS_ICON control.
353 static HICON
STATIC_LoadIconW( HINSTANCE hInstance
, LPCWSTR name
, DWORD style
)
357 if (hInstance
&& ((ULONG_PTR
)hInstance
>> 16))
359 if ((style
& SS_REALSIZEIMAGE
) != 0)
360 hicon
= LoadImageW(hInstance
, name
, IMAGE_ICON
, 0, 0, LR_SHARED
);
363 hicon
= LoadIconW( hInstance
, name
);
364 if (!hicon
) hicon
= LoadCursorW( hInstance
, name
);
367 if (!hicon
) hicon
= LoadIconW( 0, name
);
368 /* Windows doesn't try to load a standard cursor,
369 probably because most IDs for standard cursors conflict
370 with the IDs for standard icons anyway */
374 static HBRUSH
STATIC_SendWmCtlColorStatic(HWND hwnd
, HDC hdc
)
377 HWND parent
= GetParent(hwnd
);
379 if (!parent
) parent
= hwnd
;
380 hBrush
= (HBRUSH
) SendMessageW( parent
, WM_CTLCOLORSTATIC
, (WPARAM
)hdc
, (LPARAM
)hwnd
);
381 if (!hBrush
) /* did the app forget to call DefWindowProc ? */
383 /* FIXME: DefWindowProc should return different colors if a
384 manifest is present */
385 hBrush
= (HBRUSH
)DefWindowProcW( parent
, WM_CTLCOLORSTATIC
, (WPARAM
)hdc
, (LPARAM
)hwnd
);
390 /***********************************************************************
393 * Try to immediately paint the control.
395 static VOID
STATIC_TryPaintFcn(HWND hwnd
, LONG full_style
)
397 if (IsWindowVisible(hwnd
))
403 LONG style
= full_style
& SS_TYPEMASK
;
405 GetClientRect( hwnd
, &rc
);
407 hrgn
= set_control_clipping( hdc
, &rc
);
408 hbrush
= STATIC_SendWmCtlColorStatic( hwnd
, hdc
);
409 if (staticPaintFunc
[style
])
410 (staticPaintFunc
[style
])( hwnd
, hdc
, hbrush
, full_style
);
411 SelectClipRgn( hdc
, hrgn
);
412 if (hrgn
) DeleteObject( hrgn
);
413 ReleaseDC( hwnd
, hdc
);
417 /***********************************************************************
420 * Tests if the control displays text.
422 static BOOL
hasTextStyle( DWORD style
)
424 switch (style
& SS_TYPEMASK
)
428 case SS_LEFTNOWORDWRAP
:
438 static LRESULT CALLBACK
STATIC_WindowProc( HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
440 const WCHAR
*window_name
;
442 LONG full_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
443 LONG style
= full_style
& SS_TYPEMASK
;
445 if (!IsWindow( hwnd
)) return 0;
453 if (style
< 0L || style
> SS_TYPEMASK
)
455 ERR("Unknown style %#lx\n", style
);
459 parent
= GetParent( hwnd
);
461 EnableThemeDialogTexture( parent
, ETDT_ENABLE
);
466 if (style
== SS_ICON
)
468 struct static_extra_info
*extra
= get_extra_ptr( hwnd
, FALSE
);
471 if (extra
->image_has_alpha
)
472 DeleteObject( extra
->image
.hbitmap
);
477 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
479 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
480 * had already been loaded by the application the last thing we want to do is
481 * GlobalFree16 the handle.
486 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
489 /* do all painting in WM_PAINT like Windows does */
497 HDC hdc
= wParam
? (HDC
)wParam
: BeginPaint(hwnd
, &ps
);
501 GetClientRect( hwnd
, &rect
);
502 hrgn
= set_control_clipping( hdc
, &rect
);
503 hbrush
= STATIC_SendWmCtlColorStatic( hwnd
, hdc
);
504 if (staticPaintFunc
[style
])
505 (staticPaintFunc
[style
])( hwnd
, hdc
, hbrush
, full_style
);
506 SelectClipRgn( hdc
, hrgn
);
507 if (hrgn
) DeleteObject( hrgn
);
508 if (!wParam
) EndPaint(hwnd
, &ps
);
513 STATIC_TryPaintFcn( hwnd
, full_style
);
514 if (full_style
& SS_NOTIFY
)
517 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
518 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_ENABLE
), (LPARAM
)hwnd
);
520 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
521 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_DISABLE
), (LPARAM
)hwnd
);
525 case WM_SYSCOLORCHANGE
:
526 COMCTL32_RefreshSysColors();
527 STATIC_TryPaintFcn( hwnd
, full_style
);
530 case WM_THEMECHANGED
:
531 InvalidateRect( hwnd
, 0, TRUE
);
536 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
538 if (full_style
& SS_SUNKEN
|| style
== SS_ETCHEDHORZ
|| style
== SS_ETCHEDVERT
)
539 SetWindowLongW( hwnd
, GWL_EXSTYLE
,
540 GetWindowLongW( hwnd
, GWL_EXSTYLE
) | WS_EX_STATICEDGE
);
542 if (style
== SS_ETCHEDHORZ
|| style
== SS_ETCHEDVERT
) {
544 GetClientRect(hwnd
, &rc
);
545 if (style
== SS_ETCHEDHORZ
)
549 AdjustWindowRectEx(&rc
, full_style
, FALSE
, GetWindowLongW(hwnd
, GWL_EXSTYLE
));
550 SetWindowPos(hwnd
, NULL
, 0, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOZORDER
);
553 if (cs
->lpszName
&& cs
->lpszName
[0] == 0xffff)
554 window_name
= MAKEINTRESOURCEW(cs
->lpszName
[1]);
556 window_name
= cs
->lpszName
;
564 hIcon
= STATIC_LoadIconW(cs
->hInstance
, window_name
, full_style
);
565 STATIC_SetIcon(hwnd
, hIcon
, full_style
);
569 if ((ULONG_PTR
)cs
->hInstance
>> 16)
572 hBitmap
= LoadBitmapW(cs
->hInstance
, window_name
);
573 STATIC_SetBitmap(hwnd
, hBitmap
, full_style
);
577 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
578 the enhanced metafile that was specified as the window text. */
580 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
583 if (hasTextStyle( full_style
))
585 lResult
= DefWindowProcW( hwnd
, uMsg
, wParam
, lParam
);
586 STATIC_TryPaintFcn( hwnd
, full_style
);
591 if (hasTextStyle( full_style
))
593 STATIC_SetFont( hwnd
, (HFONT
)wParam
);
595 RedrawWindow( hwnd
, NULL
, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_ALLCHILDREN
);
600 return (LRESULT
)STATIC_GetFont( hwnd
);
603 if (full_style
& SS_NOTIFY
)
606 return HTTRANSPARENT
;
612 case WM_NCLBUTTONDOWN
:
613 if (full_style
& SS_NOTIFY
)
614 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
615 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_CLICKED
), (LPARAM
)hwnd
);
618 case WM_LBUTTONDBLCLK
:
619 case WM_NCLBUTTONDBLCLK
:
620 if (full_style
& SS_NOTIFY
)
621 SendMessageW( GetParent(hwnd
), WM_COMMAND
,
622 MAKEWPARAM( GetWindowLongPtrW(hwnd
,GWLP_ID
), STN_DBLCLK
), (LPARAM
)hwnd
);
626 return (LRESULT
)STATIC_GetImage( hwnd
, wParam
, full_style
);
629 return (LRESULT
)STATIC_GetImage( hwnd
, IMAGE_ICON
, full_style
);
635 if (style
!= SS_BITMAP
) return 0;
636 lResult
= (LRESULT
)STATIC_SetBitmap( hwnd
, (HBITMAP
)lParam
, full_style
);
638 case IMAGE_ENHMETAFILE
:
639 if (style
!= SS_ENHMETAFILE
) return 0;
640 lResult
= (LRESULT
)STATIC_SetEnhMetaFile( hwnd
, (HENHMETAFILE
)lParam
, full_style
);
644 if (style
!= SS_ICON
) return 0;
645 lResult
= (LRESULT
)STATIC_SetIcon( hwnd
, (HICON
)lParam
, full_style
);
648 FIXME("STM_SETIMAGE: Unhandled type %Ix\n", wParam
);
651 STATIC_TryPaintFcn( hwnd
, full_style
);
655 if (style
!= SS_ICON
) return 0;
656 lResult
= (LRESULT
)STATIC_SetIcon( hwnd
, (HICON
)wParam
, full_style
);
657 STATIC_TryPaintFcn( hwnd
, full_style
);
661 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
666 static void STATIC_PaintOwnerDrawfn( HWND hwnd
, HDC hdc
, HBRUSH hbrush
, DWORD style
)
669 HFONT font
, oldFont
= NULL
;
670 UINT id
= (UINT
)GetWindowLongPtrW( hwnd
, GWLP_ID
);
672 dis
.CtlType
= ODT_STATIC
;
675 dis
.itemAction
= ODA_DRAWENTIRE
;
676 dis
.itemState
= IsWindowEnabled(hwnd
) ? 0 : ODS_DISABLED
;
680 GetClientRect( hwnd
, &dis
.rcItem
);
682 font
= STATIC_GetFont( hwnd
);
683 if (font
) oldFont
= SelectObject( hdc
, font
);
684 SendMessageW( GetParent(hwnd
), WM_DRAWITEM
, id
, (LPARAM
)&dis
);
685 if (font
) SelectObject( hdc
, oldFont
);
688 static void STATIC_PaintTextfn( HWND hwnd
, HDC hdc
, HBRUSH hbrush
, DWORD style
)
691 HFONT hFont
, hOldFont
= NULL
;
696 GetClientRect( hwnd
, &rc
);
698 switch (style
& SS_TYPEMASK
)
701 format
= DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
;
705 format
= DT_CENTER
| DT_EXPANDTABS
| DT_WORDBREAK
;
709 format
= DT_RIGHT
| DT_EXPANDTABS
| DT_WORDBREAK
;
713 format
= DT_LEFT
| DT_SINGLELINE
;
716 case SS_LEFTNOWORDWRAP
:
717 format
= DT_LEFT
| DT_EXPANDTABS
;
724 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_RIGHT
)
725 format
= DT_RIGHT
| (format
& ~(DT_LEFT
| DT_CENTER
));
727 if (style
& SS_NOPREFIX
)
728 format
|= DT_NOPREFIX
;
730 if ((style
& SS_TYPEMASK
) != SS_SIMPLE
)
732 if (style
& SS_CENTERIMAGE
)
733 format
|= DT_SINGLELINE
| DT_VCENTER
;
734 if (style
& SS_EDITCONTROL
)
735 format
|= DT_EDITCONTROL
;
736 if (style
& SS_ENDELLIPSIS
)
737 format
|= DT_SINGLELINE
| DT_END_ELLIPSIS
;
738 if (style
& SS_PATHELLIPSIS
)
739 format
|= DT_SINGLELINE
| DT_PATH_ELLIPSIS
;
740 if (style
& SS_WORDELLIPSIS
)
741 format
|= DT_SINGLELINE
| DT_WORD_ELLIPSIS
;
744 if ((hFont
= STATIC_GetFont( hwnd
)))
745 hOldFont
= SelectObject( hdc
, hFont
);
747 if ((style
& SS_TYPEMASK
) != SS_SIMPLE
)
749 FillRect( hdc
, &rc
, hbrush
);
750 if (!IsWindowEnabled(hwnd
)) SetTextColor(hdc
, GetSysColor(COLOR_GRAYTEXT
));
754 if (!(text
= Alloc( buf_size
* sizeof(WCHAR
) )))
757 while ((len
= InternalGetWindowText( hwnd
, text
, buf_size
)) == buf_size
- 1)
760 if (!(text
= ReAlloc( text
, buf_size
* sizeof(WCHAR
) )))
764 if (!len
) goto no_TextOut
;
766 if (((style
& SS_TYPEMASK
) == SS_SIMPLE
) && (style
& SS_NOPREFIX
))
768 /* Windows uses the faster ExtTextOut() to draw the text and
769 to paint the whole client rectangle with the text background
770 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
771 ExtTextOutW( hdc
, rc
.left
, rc
.top
, ETO_CLIPPED
| ETO_OPAQUE
,
772 &rc
, text
, len
, NULL
);
776 DrawTextW( hdc
, text
, -1, &rc
, format
);
783 SelectObject( hdc
, hOldFont
);
786 static void STATIC_PaintRectfn( HWND hwnd
, HDC hdc
, HBRUSH hbrush
, DWORD style
)
790 GetClientRect( hwnd
, &rc
);
792 switch (style
& SS_TYPEMASK
)
795 hbrush
= CreateSolidBrush(comctl32_color
.clr3dDkShadow
);
796 FillRect( hdc
, &rc
, hbrush
);
799 hbrush
= CreateSolidBrush(comctl32_color
.clr3dShadow
);
800 FillRect( hdc
, &rc
, hbrush
);
803 hbrush
= CreateSolidBrush(comctl32_color
.clr3dHilight
);
804 FillRect( hdc
, &rc
, hbrush
);
807 hbrush
= CreateSolidBrush(comctl32_color
.clr3dDkShadow
);
808 FrameRect( hdc
, &rc
, hbrush
);
811 hbrush
= CreateSolidBrush(comctl32_color
.clr3dShadow
);
812 FrameRect( hdc
, &rc
, hbrush
);
815 hbrush
= CreateSolidBrush(comctl32_color
.clr3dHilight
);
816 FrameRect( hdc
, &rc
, hbrush
);
821 DeleteObject( hbrush
);
825 static void STATIC_PaintIconfn( HWND hwnd
, HDC hdc
, HBRUSH hbrush
, DWORD style
)
831 GetClientRect( hwnd
, &rc
);
832 hIcon
= STATIC_GetImage( hwnd
, IMAGE_ICON
, style
);
833 if (!hIcon
|| !get_icon_size( hIcon
, &size
))
835 FillRect(hdc
, &rc
, hbrush
);
839 if (style
& SS_CENTERIMAGE
)
841 iconRect
.left
= (rc
.right
- rc
.left
) / 2 - size
.cx
/ 2;
842 iconRect
.top
= (rc
.bottom
- rc
.top
) / 2 - size
.cy
/ 2;
843 iconRect
.right
= iconRect
.left
+ size
.cx
;
844 iconRect
.bottom
= iconRect
.top
+ size
.cy
;
848 FillRect( hdc
, &rc
, hbrush
);
849 DrawIconEx( hdc
, iconRect
.left
, iconRect
.top
, hIcon
, iconRect
.right
- iconRect
.left
,
850 iconRect
.bottom
- iconRect
.top
, 0, NULL
, DI_NORMAL
);
854 static void STATIC_PaintBitmapfn(HWND hwnd
, HDC hdc
, HBRUSH hbrush
, DWORD style
)
857 HBITMAP hBitmap
, oldbitmap
;
860 GetClientRect( hwnd
, &rcClient
);
861 FillRect( hdc
, &rcClient
, hbrush
);
863 if ((hBitmap
= STATIC_GetImage( hwnd
, IMAGE_BITMAP
, style
))
864 && (GetObjectType(hBitmap
) == OBJ_BITMAP
)
865 && (hMemDC
= CreateCompatibleDC( hdc
)))
869 BLENDFUNCTION blend
= { AC_SRC_OVER
, 0, 255, AC_SRC_ALPHA
};
870 struct static_extra_info
*extra
= get_extra_ptr( hwnd
, FALSE
);
872 GetObjectW(hBitmap
, sizeof(bm
), &bm
);
873 oldbitmap
= SelectObject(hMemDC
, hBitmap
);
875 /* Set the background color for monochrome bitmaps
876 to the color of the background brush */
877 if (GetObjectW( hbrush
, sizeof(brush
), &brush
))
879 if (brush
.lbStyle
== BS_SOLID
)
880 SetBkColor(hdc
, brush
.lbColor
);
882 if (style
& SS_CENTERIMAGE
)
884 rcClient
.left
= (rcClient
.right
- rcClient
.left
)/2 - bm
.bmWidth
/2;
885 rcClient
.top
= (rcClient
.bottom
- rcClient
.top
)/2 - bm
.bmHeight
/2;
886 rcClient
.right
= rcClient
.left
+ bm
.bmWidth
;
887 rcClient
.bottom
= rcClient
.top
+ bm
.bmHeight
;
890 if (extra
->image_has_alpha
)
891 GdiAlphaBlend(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
- rcClient
.left
,
892 rcClient
.bottom
- rcClient
.top
, hMemDC
,
893 0, 0, bm
.bmWidth
, bm
.bmHeight
, blend
);
895 StretchBlt(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
- rcClient
.left
,
896 rcClient
.bottom
- rcClient
.top
, hMemDC
,
897 0, 0, bm
.bmWidth
, bm
.bmHeight
, SRCCOPY
);
898 SelectObject(hMemDC
, oldbitmap
);
903 static void STATIC_PaintEnhMetafn(HWND hwnd
, HDC hdc
, HBRUSH hbrush
, DWORD style
)
905 HENHMETAFILE hEnhMetaFile
;
908 GetClientRect(hwnd
, &rc
);
909 FillRect(hdc
, &rc
, hbrush
);
910 if ((hEnhMetaFile
= STATIC_GetImage( hwnd
, IMAGE_ENHMETAFILE
, style
)))
912 /* The control's current font is not selected into the
914 if (GetObjectType(hEnhMetaFile
) == OBJ_ENHMETAFILE
)
915 PlayEnhMetaFile(hdc
, hEnhMetaFile
, &rc
);
919 static void STATIC_PaintEtchedfn( HWND hwnd
, HDC hdc
, HBRUSH hbrush
, DWORD style
)
923 GetClientRect( hwnd
, &rc
);
924 DrawEdge(hdc
, &rc
, EDGE_ETCHED
, BF_RECT
);
927 void STATIC_Register(void)
931 memset(&wndClass
, 0, sizeof(wndClass
));
932 wndClass
.style
= CS_DBLCLKS
| CS_PARENTDC
| CS_GLOBALCLASS
;
933 wndClass
.lpfnWndProc
= STATIC_WindowProc
;
934 wndClass
.cbClsExtra
= 0;
935 wndClass
.cbWndExtra
= sizeof(struct static_extra_info
*);
936 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
937 wndClass
.hbrBackground
= NULL
;
938 wndClass
.lpszClassName
= WC_STATICW
;
939 RegisterClassW(&wndClass
);