user32: Don't wait for other threads to process WM_NCDESTROY.
[wine.git] / dlls / user32 / static.c
blob1f7c03121c3114a46d4d0a11a13462464e5a7b29
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 * - 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).
27 * TODO:
28 * - Animated cursors
31 #include <stdarg.h>
33 #include "windef.h"
34 #include "winbase.h"
35 #include "wingdi.h"
36 #include "controls.h"
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 =
89 staticW, /* name */
90 CS_DBLCLKS | CS_PARENTDC, /* style */
91 WINPROC_STATIC, /* proc */
92 STATIC_EXTRA_BYTES, /* extra */
93 IDC_ARROW, /* cursor */
94 0 /* brush */
97 /***********************************************************************
98 * STATIC_SetIcon
100 * Set the icon for an SS_ICON control.
102 static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
104 HICON prevIcon;
105 SIZE size;
107 if ((style & SS_TYPEMASK) != SS_ICON) return 0;
108 if (hicon && !get_icon_size( hicon, &size ))
110 WARN("hicon != 0, but invalid\n");
111 return 0;
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)
120 RECT wr;
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 );
125 else */
127 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
130 return prevIcon;
133 /***********************************************************************
134 * STATIC_SetBitmap
136 * Set the bitmap for an SS_BITMAP control.
138 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
140 HBITMAP hOldBitmap;
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");
145 return 0;
147 hOldBitmap = (HBITMAP)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hBitmap );
148 if (hBitmap && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
150 BITMAP bm;
151 GetObjectW(hBitmap, sizeof(bm), &bm);
152 /* Windows currently doesn't implement SS_RIGHTJUST */
154 if ((style & SS_RIGHTJUST) != 0)
156 RECT wr;
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 );
161 else */
163 SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
164 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
168 return hOldBitmap;
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");
181 return 0;
183 return (HENHMETAFILE)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hEnhMetaFile );
186 /***********************************************************************
187 * STATIC_GetImage
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)
196 case SS_ICON:
197 if ((wParam != IMAGE_ICON) &&
198 (wParam != IMAGE_CURSOR)) return NULL;
199 break;
200 case SS_BITMAP:
201 if (wParam != IMAGE_BITMAP) return NULL;
202 break;
203 case SS_ENHMETAFILE:
204 if (wParam != IMAGE_ENHMETAFILE) return NULL;
205 break;
206 default:
207 return NULL;
209 return (HANDLE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
212 /***********************************************************************
213 * STATIC_LoadIconA
215 * Load the icon for an SS_ICON control.
217 static HICON STATIC_LoadIconA( HINSTANCE hInstance, LPCSTR name, DWORD style )
219 HICON hicon = 0;
221 if (hInstance && ((ULONG_PTR)hInstance >> 16))
223 if ((style & SS_REALSIZEIMAGE) != 0)
224 hicon = LoadImageA(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
225 else
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 */
235 return hicon;
238 /***********************************************************************
239 * STATIC_LoadIconW
241 * Load the icon for an SS_ICON control.
243 static HICON STATIC_LoadIconW( HINSTANCE hInstance, LPCWSTR name, DWORD style )
245 HICON hicon = 0;
247 if (hInstance && ((ULONG_PTR)hInstance >> 16))
249 if ((style & SS_REALSIZEIMAGE) != 0)
250 hicon = LoadImageW(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
251 else
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 */
261 return hicon;
264 /***********************************************************************
265 * STATIC_TryPaintFcn
267 * Try to immediately paint the control.
269 static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
271 LONG style = full_style & SS_TYPEMASK;
272 RECT rc;
274 GetClientRect( hwnd, &rc );
275 if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
277 HDC hdc;
278 HRGN hrgn;
280 hdc = GetDC( hwnd );
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)
291 HBRUSH hBrush;
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);
304 return hBrush;
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 /***********************************************************************
315 * hasTextStyle
317 * Tests if the control displays text.
319 static BOOL hasTextStyle( DWORD style )
321 switch(style & SS_TYPEMASK)
323 case SS_SIMPLE:
324 case SS_LEFT:
325 case SS_LEFTNOWORDWRAP:
326 case SS_CENTER:
327 case SS_RIGHT:
328 case SS_OWNERDRAW:
329 return TRUE;
332 return FALSE;
335 /***********************************************************************
336 * StaticWndProc_common
338 LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL unicode )
340 LRESULT lResult = 0;
341 LONG full_style = GetWindowLongW( hwnd, GWL_STYLE );
342 LONG style = full_style & SS_TYPEMASK;
344 if (!IsWindow( hwnd )) return 0;
346 switch (uMsg)
348 case WM_CREATE:
349 if (style < 0L || style > SS_TYPEMASK)
351 ERR("Unknown style 0x%02x\n", style );
352 return -1;
354 STATIC_InitColours();
355 break;
357 case WM_NCDESTROY:
358 if (style == SS_ICON) {
360 * FIXME
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.
367 break;
369 else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
370 DefWindowProcA(hwnd, uMsg, wParam, lParam);
372 case WM_ERASEBKGND:
373 /* do all painting in WM_PAINT like Windows does */
374 return 1;
376 case WM_PRINTCLIENT:
377 case WM_PAINT:
379 PAINTSTRUCT ps;
380 RECT rect;
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);
392 break;
394 case WM_ENABLE:
395 STATIC_TryPaintFcn( hwnd, full_style );
396 if (full_style & SS_NOTIFY) {
397 if (wParam) {
398 SendMessageW( GetParent(hwnd), WM_COMMAND,
399 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_ENABLE ), (LPARAM)hwnd);
401 else {
402 SendMessageW( GetParent(hwnd), WM_COMMAND,
403 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DISABLE ), (LPARAM)hwnd);
406 break;
408 case WM_SYSCOLORCHANGE:
409 STATIC_InitColours();
410 STATIC_TryPaintFcn( hwnd, full_style );
411 break;
413 case WM_NCCREATE:
415 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
417 if (full_style & SS_SUNKEN)
418 SetWindowLongW( hwnd, GWL_EXSTYLE,
419 GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
421 switch (style) {
422 case SS_ICON:
424 HICON hIcon;
425 if (unicode || IS_INTRESOURCE(cs->lpszName))
426 hIcon = STATIC_LoadIconW(cs->hInstance, cs->lpszName, full_style);
427 else
428 hIcon = STATIC_LoadIconA(cs->hInstance, (LPCSTR)cs->lpszName, full_style);
429 STATIC_SetIcon(hwnd, hIcon, full_style);
431 break;
432 case SS_BITMAP:
433 if ((ULONG_PTR)cs->hInstance >> 16)
435 HBITMAP hBitmap;
436 if (unicode || IS_INTRESOURCE(cs->lpszName))
437 hBitmap = LoadBitmapW(cs->hInstance, cs->lpszName);
438 else
439 hBitmap = LoadBitmapA(cs->hInstance, (LPCSTR)cs->lpszName);
440 STATIC_SetBitmap(hwnd, hBitmap, full_style);
442 break;
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);
450 case WM_SETTEXT:
451 if (hasTextStyle( full_style ))
453 if (unicode)
454 lResult = DefWindowProcW( hwnd, uMsg, wParam, lParam );
455 else
456 lResult = DefWindowProcA( hwnd, uMsg, wParam, lParam );
457 STATIC_TryPaintFcn( hwnd, full_style );
459 break;
461 case WM_SETFONT:
462 if (hasTextStyle( full_style ))
464 SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, wParam );
465 if (LOWORD(lParam))
466 RedrawWindow( hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
468 break;
470 case WM_GETFONT:
471 return GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
473 case WM_NCHITTEST:
474 if (full_style & SS_NOTIFY)
475 return HTCLIENT;
476 else
477 return HTTRANSPARENT;
479 case WM_GETDLGCODE:
480 return DLGC_STATIC;
482 case WM_LBUTTONDOWN:
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);
487 return 0;
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);
494 return 0;
496 case STM_GETIMAGE:
497 return (LRESULT)STATIC_GetImage( hwnd, wParam, full_style );
499 case STM_GETICON:
500 return (LRESULT)STATIC_GetImage( hwnd, IMAGE_ICON, full_style );
502 case STM_SETIMAGE:
503 switch(wParam) {
504 case IMAGE_BITMAP:
505 lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
506 break;
507 case IMAGE_ENHMETAFILE:
508 lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
509 break;
510 case IMAGE_ICON:
511 case IMAGE_CURSOR:
512 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
513 break;
514 default:
515 FIXME("STM_SETIMAGE: Unhandled type %lx\n", wParam);
516 break;
518 STATIC_TryPaintFcn( hwnd, full_style );
519 break;
521 case STM_SETICON:
522 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
523 STATIC_TryPaintFcn( hwnd, full_style );
524 break;
526 default:
527 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
528 DefWindowProcA(hwnd, uMsg, wParam, lParam);
530 return lResult;
533 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
535 DRAWITEMSTRUCT dis;
536 HFONT font, oldFont = NULL;
537 UINT id = (UINT)GetWindowLongPtrW( hwnd, GWLP_ID );
539 dis.CtlType = ODT_STATIC;
540 dis.CtlID = id;
541 dis.itemID = 0;
542 dis.itemAction = ODA_DRAWENTIRE;
543 dis.itemState = IsWindowEnabled(hwnd) ? 0 : ODS_DISABLED;
544 dis.hwndItem = hwnd;
545 dis.hDC = hdc;
546 dis.itemData = 0;
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 )
558 RECT rc;
559 HBRUSH hBrush;
560 HFONT hFont, hOldFont = NULL;
561 UINT format;
562 INT len, buf_size;
563 WCHAR *text;
565 GetClientRect( hwnd, &rc);
567 switch (style & SS_TYPEMASK)
569 case SS_LEFT:
570 format = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
571 break;
573 case SS_CENTER:
574 format = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
575 break;
577 case SS_RIGHT:
578 format = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
579 break;
581 case SS_SIMPLE:
582 format = DT_LEFT | DT_SINGLELINE;
583 break;
585 case SS_LEFTNOWORDWRAP:
586 format = DT_LEFT | DT_EXPANDTABS;
587 break;
589 default:
590 return;
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
617 brush is not used */
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));
626 buf_size = 256;
627 if (!(text = HeapAlloc( GetProcessHeap(), 0, buf_size * sizeof(WCHAR) )))
628 goto no_TextOut;
630 while ((len = InternalGetWindowText( hwnd, text, buf_size )) == buf_size - 1)
632 buf_size *= 2;
633 if (!(text = HeapReAlloc( GetProcessHeap(), 0, text, buf_size * sizeof(WCHAR) )))
634 goto no_TextOut;
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 );
647 else
649 DrawTextW( hdc, text, -1, &rc, format );
652 no_TextOut:
653 HeapFree( GetProcessHeap(), 0, text );
655 if (hFont)
656 SelectObject( hdc, hOldFont );
659 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
661 RECT rc;
662 HBRUSH hBrush;
664 GetClientRect( hwnd, &rc);
666 /* FIXME: send WM_CTLCOLORSTATIC */
667 switch (style & SS_TYPEMASK)
669 case SS_BLACKRECT:
670 hBrush = CreateSolidBrush(color_3ddkshadow);
671 FillRect( hdc, &rc, hBrush );
672 break;
673 case SS_GRAYRECT:
674 hBrush = CreateSolidBrush(color_3dshadow);
675 FillRect( hdc, &rc, hBrush );
676 break;
677 case SS_WHITERECT:
678 hBrush = CreateSolidBrush(color_3dhighlight);
679 FillRect( hdc, &rc, hBrush );
680 break;
681 case SS_BLACKFRAME:
682 hBrush = CreateSolidBrush(color_3ddkshadow);
683 FrameRect( hdc, &rc, hBrush );
684 break;
685 case SS_GRAYFRAME:
686 hBrush = CreateSolidBrush(color_3dshadow);
687 FrameRect( hdc, &rc, hBrush );
688 break;
689 case SS_WHITEFRAME:
690 hBrush = CreateSolidBrush(color_3dhighlight);
691 FrameRect( hdc, &rc, hBrush );
692 break;
693 default:
694 return;
696 DeleteObject( hBrush );
700 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
702 RECT rc, iconRect;
703 HBRUSH hbrush;
704 HICON hIcon;
705 SIZE size;
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);
714 else
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;
723 else
724 iconRect = rc;
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 )
733 HDC hMemDC;
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 )))
743 BITMAP bm;
744 RECT rcClient;
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);
767 DeleteDC(hMemDC);
772 static void STATIC_PaintEnhMetafn(HWND hwnd, HDC hdc, DWORD style )
774 HENHMETAFILE hEnhMetaFile;
775 RECT rc;
776 HBRUSH hbrush;
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
784 device context! */
785 if (GetObjectType(hEnhMetaFile) == OBJ_ENHMETAFILE)
786 PlayEnhMetaFile(hdc, hEnhMetaFile, &rc);
791 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
793 RECT rc;
795 /* FIXME: sometimes (not always) sends WM_CTLCOLORSTATIC */
796 GetClientRect( hwnd, &rc );
797 switch (style & SS_TYPEMASK)
799 case SS_ETCHEDHORZ:
800 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
801 break;
802 case SS_ETCHEDVERT:
803 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
804 break;
805 case SS_ETCHEDFRAME:
806 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
807 break;