usp10: Avoid leaking "open_stack" and "stack_index" in case of 0 "pair_count" in...
[wine.git] / dlls / user32 / static.c
blob11b04fc98f5b519fff89ef347c2233fb03ebb587
1 /*
2 * Static control
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
20 * Notes:
21 * - Windows XP introduced new behavior: The background of centered
22 * icons and bitmaps is painted differently. This is only done if
23 * a manifest is present.
24 * Because it has not yet been decided how to implement the two
25 * different modes in Wine, only the Windows XP mode is implemented.
26 * - Controls with SS_SIMPLE but without SS_NOPREFIX:
27 * The text should not be changed. Windows doesn't clear the
28 * client rectangle, so the new text must be larger than the old one.
29 * - The SS_RIGHTJUST style is currently not implemented by Windows
30 * (or it does something different than documented).
32 * TODO:
33 * - Animated cursors
36 #include <stdarg.h>
38 #include "windef.h"
39 #include "winbase.h"
40 #include "wingdi.h"
41 #include "controls.h"
42 #include "user_private.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(static);
47 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style );
48 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style );
49 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style );
50 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style );
51 static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc, DWORD style );
52 static void STATIC_PaintEnhMetafn( HWND hwnd, HDC hdc, DWORD style );
53 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style );
55 static COLORREF color_3dshadow, color_3ddkshadow, color_3dhighlight;
57 /* offsets for GetWindowLong for static private information */
58 #define HFONT_GWL_OFFSET 0
59 #define HICON_GWL_OFFSET (sizeof(HFONT))
60 #define STATIC_EXTRA_BYTES (HICON_GWL_OFFSET + sizeof(HICON))
62 typedef void (*pfPaint)( HWND hwnd, HDC hdc, DWORD style );
64 static const pfPaint staticPaintFunc[SS_TYPEMASK+1] =
66 STATIC_PaintTextfn, /* SS_LEFT */
67 STATIC_PaintTextfn, /* SS_CENTER */
68 STATIC_PaintTextfn, /* SS_RIGHT */
69 STATIC_PaintIconfn, /* SS_ICON */
70 STATIC_PaintRectfn, /* SS_BLACKRECT */
71 STATIC_PaintRectfn, /* SS_GRAYRECT */
72 STATIC_PaintRectfn, /* SS_WHITERECT */
73 STATIC_PaintRectfn, /* SS_BLACKFRAME */
74 STATIC_PaintRectfn, /* SS_GRAYFRAME */
75 STATIC_PaintRectfn, /* SS_WHITEFRAME */
76 NULL, /* SS_USERITEM */
77 STATIC_PaintTextfn, /* SS_SIMPLE */
78 STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
79 STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
80 STATIC_PaintBitmapfn, /* SS_BITMAP */
81 STATIC_PaintEnhMetafn, /* SS_ENHMETAFILE */
82 STATIC_PaintEtchedfn, /* SS_ETCHEDHORZ */
83 STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
84 STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
88 /*********************************************************************
89 * static class descriptor
91 static const WCHAR staticW[] = {'S','t','a','t','i','c',0};
92 const struct builtin_class_descr STATIC_builtin_class =
94 staticW, /* name */
95 CS_DBLCLKS | CS_PARENTDC, /* style */
96 WINPROC_STATIC, /* proc */
97 STATIC_EXTRA_BYTES, /* extra */
98 IDC_ARROW, /* cursor */
99 0 /* brush */
102 /***********************************************************************
103 * STATIC_SetIcon
105 * Set the icon for an SS_ICON control.
107 static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
109 HICON prevIcon;
110 SIZE size;
112 if ((style & SS_TYPEMASK) != SS_ICON) return 0;
113 if (hicon && !get_icon_size( hicon, &size ))
115 WARN("hicon != 0, but invalid\n");
116 return 0;
118 prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
119 if (hicon && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
121 /* Windows currently doesn't implement SS_RIGHTJUST */
123 if ((style & SS_RIGHTJUST) != 0)
125 RECT wr;
126 GetWindowRect(hwnd, &wr);
127 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
128 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
130 else */
132 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
135 return prevIcon;
138 /***********************************************************************
139 * STATIC_SetBitmap
141 * Set the bitmap for an SS_BITMAP control.
143 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
145 HBITMAP hOldBitmap;
147 if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
148 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
149 WARN("hBitmap != 0, but it's not a bitmap\n");
150 return 0;
152 hOldBitmap = (HBITMAP)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hBitmap );
153 if (hBitmap && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
155 BITMAP bm;
156 GetObjectW(hBitmap, sizeof(bm), &bm);
157 /* Windows currently doesn't implement SS_RIGHTJUST */
159 if ((style & SS_RIGHTJUST) != 0)
161 RECT wr;
162 GetWindowRect(hwnd, &wr);
163 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
164 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
166 else */
168 SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
169 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
173 return hOldBitmap;
176 /***********************************************************************
177 * STATIC_SetEnhMetaFile
179 * Set the enhanced metafile for an SS_ENHMETAFILE control.
181 static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
183 if ((style & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
184 if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE) {
185 WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
186 return 0;
188 return (HENHMETAFILE)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hEnhMetaFile );
191 /***********************************************************************
192 * STATIC_GetImage
194 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
195 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
197 static HANDLE STATIC_GetImage( HWND hwnd, WPARAM wParam, DWORD style )
199 switch(style & SS_TYPEMASK)
201 case SS_ICON:
202 if ((wParam != IMAGE_ICON) &&
203 (wParam != IMAGE_CURSOR)) return NULL;
204 break;
205 case SS_BITMAP:
206 if (wParam != IMAGE_BITMAP) return NULL;
207 break;
208 case SS_ENHMETAFILE:
209 if (wParam != IMAGE_ENHMETAFILE) return NULL;
210 break;
211 default:
212 return NULL;
214 return (HANDLE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
217 /***********************************************************************
218 * STATIC_LoadIconA
220 * Load the icon for an SS_ICON control.
222 static HICON STATIC_LoadIconA( HINSTANCE hInstance, LPCSTR name, DWORD style )
224 HICON hicon = 0;
226 if (hInstance && ((ULONG_PTR)hInstance >> 16))
228 if ((style & SS_REALSIZEIMAGE) != 0)
229 hicon = LoadImageA(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
230 else
232 hicon = LoadIconA( hInstance, name );
233 if (!hicon) hicon = LoadCursorA( hInstance, name );
236 if (!hicon) hicon = LoadIconA( 0, name );
237 /* Windows doesn't try to load a standard cursor,
238 probably because most IDs for standard cursors conflict
239 with the IDs for standard icons anyway */
240 return hicon;
243 /***********************************************************************
244 * STATIC_LoadIconW
246 * Load the icon for an SS_ICON control.
248 static HICON STATIC_LoadIconW( HINSTANCE hInstance, LPCWSTR name, DWORD style )
250 HICON hicon = 0;
252 if (hInstance && ((ULONG_PTR)hInstance >> 16))
254 if ((style & SS_REALSIZEIMAGE) != 0)
255 hicon = LoadImageW(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
256 else
258 hicon = LoadIconW( hInstance, name );
259 if (!hicon) hicon = LoadCursorW( hInstance, name );
262 if (!hicon) hicon = LoadIconW( 0, name );
263 /* Windows doesn't try to load a standard cursor,
264 probably because most IDs for standard cursors conflict
265 with the IDs for standard icons anyway */
266 return hicon;
269 /***********************************************************************
270 * STATIC_TryPaintFcn
272 * Try to immediately paint the control.
274 static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
276 LONG style = full_style & SS_TYPEMASK;
277 RECT rc;
279 GetClientRect( hwnd, &rc );
280 if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
282 HDC hdc;
283 HRGN hrgn;
285 hdc = GetDC( hwnd );
286 hrgn = set_control_clipping( hdc, &rc );
287 (staticPaintFunc[style])( hwnd, hdc, full_style );
288 SelectClipRgn( hdc, hrgn );
289 if (hrgn) DeleteObject( hrgn );
290 ReleaseDC( hwnd, hdc );
294 static HBRUSH STATIC_SendWmCtlColorStatic(HWND hwnd, HDC hdc)
296 HBRUSH hBrush;
297 HWND parent = GetParent(hwnd);
299 if (!parent) parent = hwnd;
300 hBrush = (HBRUSH) SendMessageW( parent,
301 WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
302 if (!hBrush) /* did the app forget to call DefWindowProc ? */
304 /* FIXME: DefWindowProc should return different colors if a
305 manifest is present */
306 hBrush = (HBRUSH)DefWindowProcW( parent, WM_CTLCOLORSTATIC,
307 (WPARAM)hdc, (LPARAM)hwnd);
309 return hBrush;
312 static VOID STATIC_InitColours(void)
314 color_3ddkshadow = GetSysColor(COLOR_3DDKSHADOW);
315 color_3dshadow = GetSysColor(COLOR_3DSHADOW);
316 color_3dhighlight = GetSysColor(COLOR_3DHIGHLIGHT);
319 /***********************************************************************
320 * hasTextStyle
322 * Tests if the control displays text.
324 static BOOL hasTextStyle( DWORD style )
326 switch(style & SS_TYPEMASK)
328 case SS_SIMPLE:
329 case SS_LEFT:
330 case SS_LEFTNOWORDWRAP:
331 case SS_CENTER:
332 case SS_RIGHT:
333 case SS_OWNERDRAW:
334 return TRUE;
337 return FALSE;
340 /***********************************************************************
341 * StaticWndProc_common
343 LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL unicode )
345 LRESULT lResult = 0;
346 LONG full_style = GetWindowLongW( hwnd, GWL_STYLE );
347 LONG style = full_style & SS_TYPEMASK;
349 if (!IsWindow( hwnd )) return 0;
351 switch (uMsg)
353 case WM_CREATE:
354 if (style < 0L || style > SS_TYPEMASK)
356 ERR("Unknown style 0x%02x\n", style );
357 return -1;
359 STATIC_InitColours();
360 break;
362 case WM_NCDESTROY:
363 if (style == SS_ICON) {
365 * FIXME
366 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
368 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
369 * had already been loaded by the application the last thing we want to do is
370 * GlobalFree16 the handle.
372 break;
374 else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
375 DefWindowProcA(hwnd, uMsg, wParam, lParam);
377 case WM_ERASEBKGND:
378 /* do all painting in WM_PAINT like Windows does */
379 return 1;
381 case WM_PRINTCLIENT:
382 case WM_PAINT:
384 PAINTSTRUCT ps;
385 RECT rect;
386 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
387 GetClientRect( hwnd, &rect );
388 if (staticPaintFunc[style])
390 HRGN hrgn = set_control_clipping( hdc, &rect );
391 (staticPaintFunc[style])( hwnd, hdc, full_style );
392 SelectClipRgn( hdc, hrgn );
393 if (hrgn) DeleteObject( hrgn );
395 if (!wParam) EndPaint(hwnd, &ps);
397 break;
399 case WM_ENABLE:
400 STATIC_TryPaintFcn( hwnd, full_style );
401 if (full_style & SS_NOTIFY) {
402 if (wParam) {
403 SendMessageW( GetParent(hwnd), WM_COMMAND,
404 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_ENABLE ), (LPARAM)hwnd);
406 else {
407 SendMessageW( GetParent(hwnd), WM_COMMAND,
408 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DISABLE ), (LPARAM)hwnd);
411 break;
413 case WM_SYSCOLORCHANGE:
414 STATIC_InitColours();
415 STATIC_TryPaintFcn( hwnd, full_style );
416 break;
418 case WM_NCCREATE:
420 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
422 if (full_style & SS_SUNKEN)
423 SetWindowLongW( hwnd, GWL_EXSTYLE,
424 GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
426 switch (style) {
427 case SS_ICON:
429 HICON hIcon;
430 if (unicode || IS_INTRESOURCE(cs->lpszName))
431 hIcon = STATIC_LoadIconW(cs->hInstance, cs->lpszName, full_style);
432 else
433 hIcon = STATIC_LoadIconA(cs->hInstance, (LPCSTR)cs->lpszName, full_style);
434 STATIC_SetIcon(hwnd, hIcon, full_style);
436 break;
437 case SS_BITMAP:
438 if ((ULONG_PTR)cs->hInstance >> 16)
440 HBITMAP hBitmap;
441 if (unicode || IS_INTRESOURCE(cs->lpszName))
442 hBitmap = LoadBitmapW(cs->hInstance, cs->lpszName);
443 else
444 hBitmap = LoadBitmapA(cs->hInstance, (LPCSTR)cs->lpszName);
445 STATIC_SetBitmap(hwnd, hBitmap, full_style);
447 break;
449 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
450 the enhanced metafile that was specified as the window text. */
452 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
453 DefWindowProcA(hwnd, uMsg, wParam, lParam);
455 case WM_SETTEXT:
456 if (hasTextStyle( full_style ))
458 if (unicode)
459 lResult = DefWindowProcW( hwnd, uMsg, wParam, lParam );
460 else
461 lResult = DefWindowProcA( hwnd, uMsg, wParam, lParam );
462 STATIC_TryPaintFcn( hwnd, full_style );
464 break;
466 case WM_SETFONT:
467 if (hasTextStyle( full_style ))
469 SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, wParam );
470 if (LOWORD(lParam))
471 RedrawWindow( hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
473 break;
475 case WM_GETFONT:
476 return GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
478 case WM_NCHITTEST:
479 if (full_style & SS_NOTIFY)
480 return HTCLIENT;
481 else
482 return HTTRANSPARENT;
484 case WM_GETDLGCODE:
485 return DLGC_STATIC;
487 case WM_LBUTTONDOWN:
488 case WM_NCLBUTTONDOWN:
489 if (full_style & SS_NOTIFY)
490 SendMessageW( GetParent(hwnd), WM_COMMAND,
491 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_CLICKED ), (LPARAM)hwnd);
492 return 0;
494 case WM_LBUTTONDBLCLK:
495 case WM_NCLBUTTONDBLCLK:
496 if (full_style & SS_NOTIFY)
497 SendMessageW( GetParent(hwnd), WM_COMMAND,
498 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DBLCLK ), (LPARAM)hwnd);
499 return 0;
501 case STM_GETIMAGE:
502 return (LRESULT)STATIC_GetImage( hwnd, wParam, full_style );
504 case STM_GETICON:
505 return (LRESULT)STATIC_GetImage( hwnd, IMAGE_ICON, full_style );
507 case STM_SETIMAGE:
508 switch(wParam) {
509 case IMAGE_BITMAP:
510 lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
511 break;
512 case IMAGE_ENHMETAFILE:
513 lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
514 break;
515 case IMAGE_ICON:
516 case IMAGE_CURSOR:
517 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
518 break;
519 default:
520 FIXME("STM_SETIMAGE: Unhandled type %lx\n", wParam);
521 break;
523 STATIC_TryPaintFcn( hwnd, full_style );
524 break;
526 case STM_SETICON:
527 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
528 STATIC_TryPaintFcn( hwnd, full_style );
529 break;
531 default:
532 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
533 DefWindowProcA(hwnd, uMsg, wParam, lParam);
535 return lResult;
538 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
540 DRAWITEMSTRUCT dis;
541 HFONT font, oldFont = NULL;
542 UINT id = (UINT)GetWindowLongPtrW( hwnd, GWLP_ID );
544 dis.CtlType = ODT_STATIC;
545 dis.CtlID = id;
546 dis.itemID = 0;
547 dis.itemAction = ODA_DRAWENTIRE;
548 dis.itemState = IsWindowEnabled(hwnd) ? 0 : ODS_DISABLED;
549 dis.hwndItem = hwnd;
550 dis.hDC = hdc;
551 dis.itemData = 0;
552 GetClientRect( hwnd, &dis.rcItem );
554 font = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
555 if (font) oldFont = SelectObject( hdc, font );
556 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
557 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
558 if (font) SelectObject( hdc, oldFont );
561 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
563 RECT rc;
564 HBRUSH hBrush;
565 HFONT hFont, hOldFont = NULL;
566 UINT format;
567 INT len, buf_size;
568 WCHAR *text;
570 GetClientRect( hwnd, &rc);
572 switch (style & SS_TYPEMASK)
574 case SS_LEFT:
575 format = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
576 break;
578 case SS_CENTER:
579 format = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
580 break;
582 case SS_RIGHT:
583 format = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
584 break;
586 case SS_SIMPLE:
587 format = DT_LEFT | DT_SINGLELINE;
588 break;
590 case SS_LEFTNOWORDWRAP:
591 format = DT_LEFT | DT_EXPANDTABS;
592 break;
594 default:
595 return;
598 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_RIGHT)
599 format = DT_RIGHT | (format & ~(DT_LEFT | DT_CENTER));
601 if (style & SS_NOPREFIX)
602 format |= DT_NOPREFIX;
604 if ((style & SS_TYPEMASK) != SS_SIMPLE)
606 if (style & SS_CENTERIMAGE)
607 format |= DT_SINGLELINE | DT_VCENTER;
608 if (style & SS_EDITCONTROL)
609 format |= DT_EDITCONTROL;
610 if (style & SS_ENDELLIPSIS)
611 format |= DT_SINGLELINE | DT_END_ELLIPSIS;
612 if (style & SS_PATHELLIPSIS)
613 format |= DT_SINGLELINE | DT_PATH_ELLIPSIS;
614 if (style & SS_WORDELLIPSIS)
615 format |= DT_SINGLELINE | DT_WORD_ELLIPSIS;
618 if ((hFont = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET )))
619 hOldFont = SelectObject( hdc, hFont );
621 /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
622 brush is not used */
623 hBrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
625 if ((style & SS_TYPEMASK) != SS_SIMPLE)
627 FillRect( hdc, &rc, hBrush );
628 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
631 buf_size = 256;
632 if (!(text = HeapAlloc( GetProcessHeap(), 0, buf_size * sizeof(WCHAR) )))
633 goto no_TextOut;
635 while ((len = InternalGetWindowText( hwnd, text, buf_size )) == buf_size - 1)
637 buf_size *= 2;
638 if (!(text = HeapReAlloc( GetProcessHeap(), 0, text, buf_size * sizeof(WCHAR) )))
639 goto no_TextOut;
642 if (!len) goto no_TextOut;
644 if (((style & SS_TYPEMASK) == SS_SIMPLE) && (style & SS_NOPREFIX))
646 /* Windows uses the faster ExtTextOut() to draw the text and
647 to paint the whole client rectangle with the text background
648 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
649 ExtTextOutW( hdc, rc.left, rc.top, ETO_CLIPPED | ETO_OPAQUE,
650 &rc, text, len, NULL );
652 else
654 DrawTextW( hdc, text, -1, &rc, format );
657 no_TextOut:
658 HeapFree( GetProcessHeap(), 0, text );
660 if (hFont)
661 SelectObject( hdc, hOldFont );
664 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
666 RECT rc;
667 HBRUSH hBrush;
669 GetClientRect( hwnd, &rc);
671 /* FIXME: send WM_CTLCOLORSTATIC */
672 switch (style & SS_TYPEMASK)
674 case SS_BLACKRECT:
675 hBrush = CreateSolidBrush(color_3ddkshadow);
676 FillRect( hdc, &rc, hBrush );
677 break;
678 case SS_GRAYRECT:
679 hBrush = CreateSolidBrush(color_3dshadow);
680 FillRect( hdc, &rc, hBrush );
681 break;
682 case SS_WHITERECT:
683 hBrush = CreateSolidBrush(color_3dhighlight);
684 FillRect( hdc, &rc, hBrush );
685 break;
686 case SS_BLACKFRAME:
687 hBrush = CreateSolidBrush(color_3ddkshadow);
688 FrameRect( hdc, &rc, hBrush );
689 break;
690 case SS_GRAYFRAME:
691 hBrush = CreateSolidBrush(color_3dshadow);
692 FrameRect( hdc, &rc, hBrush );
693 break;
694 case SS_WHITEFRAME:
695 hBrush = CreateSolidBrush(color_3dhighlight);
696 FrameRect( hdc, &rc, hBrush );
697 break;
698 default:
699 return;
701 DeleteObject( hBrush );
705 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
707 RECT rc, iconRect;
708 HBRUSH hbrush;
709 HICON hIcon;
710 SIZE size;
712 GetClientRect( hwnd, &rc );
713 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
714 hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
715 if (!hIcon || !get_icon_size( hIcon, &size ))
717 FillRect(hdc, &rc, hbrush);
719 else
721 if (style & SS_CENTERIMAGE)
723 iconRect.left = (rc.right - rc.left) / 2 - size.cx / 2;
724 iconRect.top = (rc.bottom - rc.top) / 2 - size.cy / 2;
725 iconRect.right = iconRect.left + size.cx;
726 iconRect.bottom = iconRect.top + size.cy;
728 else
729 iconRect = rc;
730 FillRect( hdc, &rc, hbrush );
731 DrawIconEx( hdc, iconRect.left, iconRect.top, hIcon, iconRect.right - iconRect.left,
732 iconRect.bottom - iconRect.top, 0, NULL, DI_NORMAL );
736 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
738 HDC hMemDC;
739 HBITMAP hBitmap, oldbitmap;
740 HBRUSH hbrush;
742 /* message is still sent, even if the returned brush is not used */
743 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
745 if ((hBitmap = (HBITMAP)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET ))
746 && (GetObjectType(hBitmap) == OBJ_BITMAP)
747 && (hMemDC = CreateCompatibleDC( hdc )))
749 BITMAP bm;
750 RECT rcClient;
751 LOGBRUSH brush;
753 GetObjectW(hBitmap, sizeof(bm), &bm);
754 oldbitmap = SelectObject(hMemDC, hBitmap);
756 /* Set the background color for monochrome bitmaps
757 to the color of the background brush */
758 if (GetObjectW( hbrush, sizeof(brush), &brush ))
760 if (brush.lbStyle == BS_SOLID)
761 SetBkColor(hdc, brush.lbColor);
763 GetClientRect(hwnd, &rcClient);
764 if (style & SS_CENTERIMAGE)
766 FillRect( hdc, &rcClient, hbrush );
767 rcClient.left = (rcClient.right - rcClient.left)/2 - bm.bmWidth/2;
768 rcClient.top = (rcClient.bottom - rcClient.top)/2 - bm.bmHeight/2;
769 rcClient.right = rcClient.left + bm.bmWidth;
770 rcClient.bottom = rcClient.top + bm.bmHeight;
772 StretchBlt(hdc, rcClient.left, rcClient.top, rcClient.right - rcClient.left,
773 rcClient.bottom - rcClient.top, hMemDC,
774 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
775 SelectObject(hMemDC, oldbitmap);
776 DeleteDC(hMemDC);
781 static void STATIC_PaintEnhMetafn(HWND hwnd, HDC hdc, DWORD style )
783 HENHMETAFILE hEnhMetaFile;
784 RECT rc;
785 HBRUSH hbrush;
787 GetClientRect(hwnd, &rc);
788 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
789 FillRect(hdc, &rc, hbrush);
790 if ((hEnhMetaFile = (HENHMETAFILE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
792 /* The control's current font is not selected into the
793 device context! */
794 if (GetObjectType(hEnhMetaFile) == OBJ_ENHMETAFILE)
795 PlayEnhMetaFile(hdc, hEnhMetaFile, &rc);
800 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
802 RECT rc;
804 /* FIXME: sometimes (not always) sends WM_CTLCOLORSTATIC */
805 GetClientRect( hwnd, &rc );
806 switch (style & SS_TYPEMASK)
808 case SS_ETCHEDHORZ:
809 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
810 break;
811 case SS_ETCHEDVERT:
812 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
813 break;
814 case SS_ETCHEDFRAME:
815 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
816 break;