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 static const WCHAR staticW[] = {'S','t','a','t','i','c',0};
104 const struct builtin_class_descr STATIC_builtin_class =
107 CS_DBLCLKS | CS_PARENTDC, /* style */
108 StaticWndProcA, /* procA */
109 StaticWndProcW, /* procW */
110 STATIC_EXTRA_BYTES, /* extra */
111 IDC_ARROW, /* cursor */
115 static void setup_clipping(HWND hwnd, HDC hdc, HRGN *orig)
120 /* Native control has always a clipping region set (this may be because
121 * builtin controls uses CS_PARENTDC) and an application depends on it
123 hrgn = CreateRectRgn(0, 0, 1, 1);
124 if (GetClipRgn(hdc, hrgn) != 1)
131 GetClientRect(hwnd, &rc);
132 DPtoLP(hdc, (POINT *)&rc, 2);
133 IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom);
136 static void restore_clipping(HDC hdc, HRGN hrgn)
138 SelectClipRgn(hdc, hrgn);
143 /***********************************************************************
146 * Set the icon for an SS_ICON control.
148 static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
153 if ((style & SS_TYPEMASK) != SS_ICON) return 0;
154 if (hicon && !get_icon_size( hicon, &size ))
156 WARN("hicon != 0, but invalid\n");
159 prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
160 if (hicon && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
162 /* Windows currently doesn't implement SS_RIGHTJUST */
164 if ((style & SS_RIGHTJUST) != 0)
167 GetWindowRect(hwnd, &wr);
168 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
169 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
173 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
179 /***********************************************************************
182 * Set the bitmap for an SS_BITMAP control.
184 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
188 if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
189 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
190 WARN("hBitmap != 0, but it's not a bitmap\n");
193 hOldBitmap = (HBITMAP)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hBitmap );
194 if (hBitmap && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
197 GetObjectW(hBitmap, sizeof(bm), &bm);
198 /* Windows currently doesn't implement SS_RIGHTJUST */
200 if ((style & SS_RIGHTJUST) != 0)
203 GetWindowRect(hwnd, &wr);
204 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
205 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
209 SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
210 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
217 /***********************************************************************
218 * STATIC_SetEnhMetaFile
220 * Set the enhanced metafile for an SS_ENHMETAFILE control.
222 static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
224 if ((style & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
225 if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE) {
226 WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
229 return (HENHMETAFILE)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hEnhMetaFile );
232 /***********************************************************************
235 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
236 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
238 static HANDLE STATIC_GetImage( HWND hwnd, WPARAM wParam, DWORD style )
240 switch(style & SS_TYPEMASK)
243 if ((wParam != IMAGE_ICON) &&
244 (wParam != IMAGE_CURSOR)) return NULL;
247 if (wParam != IMAGE_BITMAP) return NULL;
250 if (wParam != IMAGE_ENHMETAFILE) return NULL;
255 return (HANDLE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
258 /***********************************************************************
261 * Load the icon for an SS_ICON control.
263 static HICON STATIC_LoadIconA( HWND hwnd, LPCSTR name, DWORD style )
265 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
266 if ((style & SS_REALSIZEIMAGE) != 0)
268 return LoadImageA(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
272 HICON hicon = LoadIconA( hInstance, name );
273 if (!hicon) hicon = LoadCursorA( hInstance, name );
274 if (!hicon) hicon = LoadIconA( 0, name );
275 /* Windows doesn't try to load a standard cursor,
276 probably because most IDs for standard cursors conflict
277 with the IDs for standard icons anyway */
282 /***********************************************************************
285 * Load the icon for an SS_ICON control.
287 static HICON STATIC_LoadIconW( HWND hwnd, LPCWSTR name, DWORD style )
289 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
290 if ((style & SS_REALSIZEIMAGE) != 0)
292 return LoadImageW(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
296 HICON hicon = LoadIconW( hInstance, name );
297 if (!hicon) hicon = LoadCursorW( hInstance, name );
298 if (!hicon) hicon = LoadIconW( 0, name );
299 /* Windows doesn't try to load a standard cursor,
300 probably because most IDs for standard cursors conflict
301 with the IDs for standard icons anyway */
306 /***********************************************************************
309 * Load the bitmap for an SS_BITMAP control.
311 static HBITMAP STATIC_LoadBitmapA( HWND hwnd, LPCSTR name )
313 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
314 /* Windows doesn't try to load OEM Bitmaps (hInstance == NULL) */
315 return LoadBitmapA( hInstance, name );
318 /***********************************************************************
321 * Load the bitmap for an SS_BITMAP control.
323 static HBITMAP STATIC_LoadBitmapW( HWND hwnd, LPCWSTR name )
325 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
326 /* Windows doesn't try to load OEM Bitmaps (hInstance == NULL) */
327 return LoadBitmapW( hInstance, name );
330 /***********************************************************************
333 * Try to immediately paint the control.
335 static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
337 LONG style = full_style & SS_TYPEMASK;
340 GetClientRect( hwnd, &rc );
341 if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
347 setup_clipping(hwnd, hdc, &hOrigClipping);
348 (staticPaintFunc[style])( hwnd, hdc, full_style );
349 restore_clipping(hdc, hOrigClipping);
350 ReleaseDC( hwnd, hdc );
354 static HBRUSH STATIC_SendWmCtlColorStatic(HWND hwnd, HDC hdc)
357 HWND parent = GetParent(hwnd);
359 if (!parent) parent = hwnd;
360 hBrush = (HBRUSH) SendMessageW( parent,
361 WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
362 if (!hBrush) /* did the app forget to call DefWindowProc ? */
364 /* FIXME: DefWindowProc should return different colors if a
365 manifest is present */
366 hBrush = (HBRUSH)DefWindowProcW( parent, WM_CTLCOLORSTATIC,
367 (WPARAM)hdc, (LPARAM)hwnd);
372 static VOID STATIC_InitColours(void)
374 color_3ddkshadow = GetSysColor(COLOR_3DDKSHADOW);
375 color_3dshadow = GetSysColor(COLOR_3DSHADOW);
376 color_3dhighlight = GetSysColor(COLOR_3DHIGHLIGHT);
379 /***********************************************************************
382 * Tests if the control displays text.
384 static BOOL hasTextStyle( DWORD style )
386 switch(style & SS_TYPEMASK)
390 case SS_LEFTNOWORDWRAP:
400 /***********************************************************************
401 * StaticWndProc_common
403 static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam,
404 LPARAM lParam, BOOL unicode )
407 LONG full_style = GetWindowLongW( hwnd, GWL_STYLE );
408 LONG style = full_style & SS_TYPEMASK;
413 if (style < 0L || style > SS_TYPEMASK)
415 ERR("Unknown style 0x%02x\n", style );
418 STATIC_InitColours();
422 if (style == SS_ICON) {
425 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
427 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
428 * had already been loaded by the application the last thing we want to do is
429 * GlobalFree16 the handle.
433 else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
434 DefWindowProcA(hwnd, uMsg, wParam, lParam);
437 /* do all painting in WM_PAINT like Windows does */
444 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
445 if (staticPaintFunc[style])
448 setup_clipping(hwnd, hdc, &hOrigClipping);
449 (staticPaintFunc[style])( hwnd, hdc, full_style );
450 restore_clipping(hdc, hOrigClipping);
452 if (!wParam) EndPaint(hwnd, &ps);
457 STATIC_TryPaintFcn( hwnd, full_style );
458 if (full_style & SS_NOTIFY) {
460 SendMessageW( GetParent(hwnd), WM_COMMAND,
461 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_ENABLE ), (LPARAM)hwnd);
464 SendMessageW( GetParent(hwnd), WM_COMMAND,
465 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DISABLE ), (LPARAM)hwnd);
470 case WM_SYSCOLORCHANGE:
471 STATIC_InitColours();
472 STATIC_TryPaintFcn( hwnd, full_style );
480 if (full_style & SS_SUNKEN)
481 SetWindowLongW( hwnd, GWL_EXSTYLE,
482 GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
487 textW = ((LPCREATESTRUCTW)lParam)->lpszName;
491 textA = ((LPCREATESTRUCTA)lParam)->lpszName;
500 hIcon = STATIC_LoadIconW(hwnd, textW, full_style);
502 hIcon = STATIC_LoadIconA(hwnd, textA, full_style);
503 STATIC_SetIcon(hwnd, hIcon, full_style);
510 hBitmap = STATIC_LoadBitmapW(hwnd, textW);
512 hBitmap = STATIC_LoadBitmapA(hwnd, textA);
513 STATIC_SetBitmap(hwnd, hBitmap, full_style);
517 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
518 the enhanced metafile that was specified as the window text. */
520 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
521 DefWindowProcA(hwnd, uMsg, wParam, lParam);
524 if (hasTextStyle( full_style ))
529 lResult = DefWindowProcW( hwnd, uMsg, wParam, lParam );
531 lResult = DefWindowProcA( hwnd, uMsg, wParam, lParam );
532 STATIC_TryPaintFcn( hwnd, full_style );
538 if (hasTextStyle( full_style ))
540 SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, wParam );
542 RedrawWindow( hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
547 return GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
550 if (full_style & SS_NOTIFY)
553 return HTTRANSPARENT;
559 case WM_NCLBUTTONDOWN:
560 if (full_style & SS_NOTIFY)
561 SendMessageW( GetParent(hwnd), WM_COMMAND,
562 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_CLICKED ), (LPARAM)hwnd);
565 case WM_LBUTTONDBLCLK:
566 case WM_NCLBUTTONDBLCLK:
567 if (full_style & SS_NOTIFY)
568 SendMessageW( GetParent(hwnd), WM_COMMAND,
569 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DBLCLK ), (LPARAM)hwnd);
573 return (LRESULT)STATIC_GetImage( hwnd, wParam, full_style );
576 return (LRESULT)STATIC_GetImage( hwnd, IMAGE_ICON, full_style );
581 lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
583 case IMAGE_ENHMETAFILE:
584 lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
588 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
591 FIXME("STM_SETIMAGE: Unhandled type %lx\n", wParam);
594 STATIC_TryPaintFcn( hwnd, full_style );
598 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
599 STATIC_TryPaintFcn( hwnd, full_style );
603 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
604 DefWindowProcA(hwnd, uMsg, wParam, lParam);
609 /***********************************************************************
610 * StaticWndProc_wrapper16
612 static LRESULT StaticWndProc_wrapper16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
617 wParam = (WPARAM)HICON_32( (HICON16)wParam );
618 return StaticWndProc_common( hwnd, STM_SETICON, wParam, lParam, FALSE );
620 return HICON_16( StaticWndProc_common( hwnd, STM_GETICON, wParam, lParam, FALSE ));
622 return StaticWndProc_common( hwnd, msg, wParam, lParam, unicode );
626 /***********************************************************************
629 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
631 if (!IsWindow( hWnd )) return 0;
632 return StaticWndProc_wrapper16(hWnd, uMsg, wParam, lParam, FALSE);
635 /***********************************************************************
638 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
640 if (!IsWindow( hWnd )) return 0;
641 return StaticWndProc_wrapper16(hWnd, uMsg, wParam, lParam, TRUE);
644 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
647 HFONT font, oldFont = NULL;
648 UINT id = (UINT)GetWindowLongPtrW( hwnd, GWLP_ID );
650 dis.CtlType = ODT_STATIC;
653 dis.itemAction = ODA_DRAWENTIRE;
654 dis.itemState = IsWindowEnabled(hwnd) ? 0 : ODS_DISABLED;
658 GetClientRect( hwnd, &dis.rcItem );
660 font = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
661 if (font) oldFont = SelectObject( hdc, font );
662 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
663 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
664 if (font) SelectObject( hdc, oldFont );
667 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
671 HFONT hFont, hOldFont = NULL;
676 GetClientRect( hwnd, &rc);
678 switch (style & SS_TYPEMASK)
681 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
685 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
689 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
693 wFormat = DT_LEFT | DT_SINGLELINE;
696 case SS_LEFTNOWORDWRAP:
697 wFormat = DT_LEFT | DT_EXPANDTABS;
704 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_RIGHT)
705 wFormat = DT_RIGHT | (wFormat & ~(DT_LEFT | DT_CENTER));
707 if (style & SS_NOPREFIX)
708 wFormat |= DT_NOPREFIX;
710 if ((style & SS_TYPEMASK) != SS_SIMPLE)
712 if (style & SS_CENTERIMAGE)
713 wFormat |= DT_SINGLELINE | DT_VCENTER;
714 if (style & SS_EDITCONTROL)
715 wFormat |= DT_EDITCONTROL;
716 if (style & SS_ENDELLIPSIS)
717 wFormat |= DT_SINGLELINE | DT_END_ELLIPSIS;
718 if (style & SS_PATHELLIPSIS)
719 wFormat |= DT_SINGLELINE | DT_PATH_ELLIPSIS;
720 if (style & SS_WORDELLIPSIS)
721 wFormat |= DT_SINGLELINE | DT_WORD_ELLIPSIS;
724 if ((hFont = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET )))
725 hOldFont = SelectObject( hdc, hFont );
727 /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
729 hBrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
731 if ((style & SS_TYPEMASK) != SS_SIMPLE)
733 FillRect( hdc, &rc, hBrush );
734 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
738 if (!(text = HeapAlloc( GetProcessHeap(), 0, buf_size * sizeof(WCHAR) )))
741 while ((len = InternalGetWindowText( hwnd, text, buf_size )) == buf_size - 1)
744 if (!(text = HeapReAlloc( GetProcessHeap(), 0, text, buf_size * sizeof(WCHAR) )))
748 if (!len) goto no_TextOut;
750 if (((style & SS_TYPEMASK) == SS_SIMPLE) && (style & SS_NOPREFIX))
752 /* Windows uses the faster ExtTextOut() to draw the text and
753 to paint the whole client rectangle with the text background
754 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
755 ExtTextOutW( hdc, rc.left, rc.top, ETO_CLIPPED | ETO_OPAQUE,
756 &rc, text, len, NULL );
760 DrawTextW( hdc, text, -1, &rc, wFormat );
764 HeapFree( GetProcessHeap(), 0, text );
767 SelectObject( hdc, hOldFont );
770 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
775 GetClientRect( hwnd, &rc);
777 /* FIXME: send WM_CTLCOLORSTATIC */
778 switch (style & SS_TYPEMASK)
781 hBrush = CreateSolidBrush(color_3ddkshadow);
782 FillRect( hdc, &rc, hBrush );
785 hBrush = CreateSolidBrush(color_3dshadow);
786 FillRect( hdc, &rc, hBrush );
789 hBrush = CreateSolidBrush(color_3dhighlight);
790 FillRect( hdc, &rc, hBrush );
793 hBrush = CreateSolidBrush(color_3ddkshadow);
794 FrameRect( hdc, &rc, hBrush );
797 hBrush = CreateSolidBrush(color_3dshadow);
798 FrameRect( hdc, &rc, hBrush );
801 hBrush = CreateSolidBrush(color_3dhighlight);
802 FrameRect( hdc, &rc, hBrush );
807 DeleteObject( hBrush );
811 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
818 GetClientRect( hwnd, &rc );
819 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
820 hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
821 if (!hIcon || !get_icon_size( hIcon, &size ))
823 FillRect(hdc, &rc, hbrush);
827 if (style & SS_CENTERIMAGE)
829 iconRect.left = (rc.right - rc.left) / 2 - size.cx / 2;
830 iconRect.top = (rc.bottom - rc.top) / 2 - size.cy / 2;
831 iconRect.right = iconRect.left + size.cx;
832 iconRect.bottom = iconRect.top + size.cy;
836 FillRect( hdc, &rc, hbrush );
837 DrawIconEx( hdc, iconRect.left, iconRect.top, hIcon, iconRect.right - iconRect.left,
838 iconRect.bottom - iconRect.top, 0, NULL, DI_NORMAL );
842 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
845 HBITMAP hBitmap, oldbitmap;
848 /* message is still sent, even if the returned brush is not used */
849 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
851 if ((hBitmap = (HBITMAP)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET ))
852 && (GetObjectType(hBitmap) == OBJ_BITMAP)
853 && (hMemDC = CreateCompatibleDC( hdc )))
859 GetObjectW(hBitmap, sizeof(bm), &bm);
860 oldbitmap = SelectObject(hMemDC, hBitmap);
862 /* Set the background color for monochrome bitmaps
863 to the color of the background brush */
864 if (GetObjectW( hbrush, sizeof(brush), &brush ))
866 if (brush.lbStyle == BS_SOLID)
867 SetBkColor(hdc, brush.lbColor);
869 GetClientRect(hwnd, &rcClient);
870 if (style & SS_CENTERIMAGE)
873 x = (rcClient.right - rcClient.left)/2 - bm.bmWidth/2;
874 y = (rcClient.bottom - rcClient.top)/2 - bm.bmHeight/2;
875 FillRect( hdc, &rcClient, hbrush );
876 BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
881 StretchBlt(hdc, 0, 0, rcClient.right - rcClient.left,
882 rcClient.bottom - rcClient.top, hMemDC,
883 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
885 SelectObject(hMemDC, oldbitmap);
891 static void STATIC_PaintEnhMetafn(HWND hwnd, HDC hdc, DWORD style )
893 HENHMETAFILE hEnhMetaFile;
897 GetClientRect(hwnd, &rc);
898 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
899 FillRect(hdc, &rc, hbrush);
900 if ((hEnhMetaFile = (HENHMETAFILE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
902 /* The control's current font is not selected into the
904 if (GetObjectType(hEnhMetaFile) == OBJ_ENHMETAFILE)
905 PlayEnhMetaFile(hdc, hEnhMetaFile, &rc);
910 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
914 /* FIXME: sometimes (not always) sends WM_CTLCOLORSTATIC */
915 GetClientRect( hwnd, &rc );
916 switch (style & SS_TYPEMASK)
919 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
922 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
925 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);