d2d1: Create feature level 10.0 device context state objects.
[wine.git] / dlls / user32 / static.c
blob35bdc2490c01dfdc3a141cb317aa41060ed356d3
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 const struct builtin_class_descr STATIC_builtin_class =
88 L"Static", /* name */
89 CS_DBLCLKS | CS_PARENTDC, /* style */
90 WINPROC_STATIC, /* proc */
91 STATIC_EXTRA_BYTES, /* extra */
92 IDC_ARROW, /* cursor */
93 0 /* brush */
96 /***********************************************************************
97 * STATIC_SetIcon
99 * Set the icon for an SS_ICON control.
101 static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
103 HICON prevIcon;
104 SIZE size;
106 if (hicon && !get_icon_size( hicon, &size ))
108 WARN("hicon != 0, but invalid\n");
109 return 0;
111 prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
112 if (hicon && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
114 /* Windows currently doesn't implement SS_RIGHTJUST */
116 if ((style & SS_RIGHTJUST) != 0)
118 RECT wr;
119 GetWindowRect(hwnd, &wr);
120 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
121 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
123 else */
125 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
128 return prevIcon;
131 /***********************************************************************
132 * STATIC_SetBitmap
134 * Set the bitmap for an SS_BITMAP control.
136 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
138 HBITMAP hOldBitmap;
140 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
141 WARN("hBitmap != 0, but it's not a bitmap\n");
142 return 0;
144 hOldBitmap = (HBITMAP)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hBitmap );
145 if (hBitmap && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
147 BITMAP bm;
148 GetObjectW(hBitmap, sizeof(bm), &bm);
149 /* Windows currently doesn't implement SS_RIGHTJUST */
151 if ((style & SS_RIGHTJUST) != 0)
153 RECT wr;
154 GetWindowRect(hwnd, &wr);
155 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
156 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
158 else */
160 SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
161 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
165 return hOldBitmap;
168 /***********************************************************************
169 * STATIC_SetEnhMetaFile
171 * Set the enhanced metafile for an SS_ENHMETAFILE control.
173 static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
175 if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE) {
176 WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
177 return 0;
179 return (HENHMETAFILE)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hEnhMetaFile );
182 /***********************************************************************
183 * STATIC_GetImage
185 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
186 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
188 static HANDLE STATIC_GetImage( HWND hwnd, WPARAM wParam, DWORD style )
190 switch(style & SS_TYPEMASK)
192 case SS_ICON:
193 if ((wParam != IMAGE_ICON) &&
194 (wParam != IMAGE_CURSOR)) return NULL;
195 break;
196 case SS_BITMAP:
197 if (wParam != IMAGE_BITMAP) return NULL;
198 break;
199 case SS_ENHMETAFILE:
200 if (wParam != IMAGE_ENHMETAFILE) return NULL;
201 break;
202 default:
203 return NULL;
205 return (HANDLE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
208 /***********************************************************************
209 * STATIC_LoadIconA
211 * Load the icon for an SS_ICON control.
213 static HICON STATIC_LoadIconA( HINSTANCE hInstance, LPCSTR name, DWORD style )
215 HICON hicon = 0;
217 if (hInstance && ((ULONG_PTR)hInstance >> 16))
219 if ((style & SS_REALSIZEIMAGE) != 0)
220 hicon = LoadImageA(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
221 else
223 hicon = LoadIconA( hInstance, name );
224 if (!hicon) hicon = LoadCursorA( hInstance, name );
227 if (!hicon) hicon = LoadIconA( 0, name );
228 /* Windows doesn't try to load a standard cursor,
229 probably because most IDs for standard cursors conflict
230 with the IDs for standard icons anyway */
231 return hicon;
234 /***********************************************************************
235 * STATIC_LoadIconW
237 * Load the icon for an SS_ICON control.
239 static HICON STATIC_LoadIconW( HINSTANCE hInstance, LPCWSTR name, DWORD style )
241 HICON hicon = 0;
243 if (hInstance && ((ULONG_PTR)hInstance >> 16))
245 if ((style & SS_REALSIZEIMAGE) != 0)
246 hicon = LoadImageW(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
247 else
249 hicon = LoadIconW( hInstance, name );
250 if (!hicon) hicon = LoadCursorW( hInstance, name );
253 if (!hicon) hicon = LoadIconW( 0, name );
254 /* Windows doesn't try to load a standard cursor,
255 probably because most IDs for standard cursors conflict
256 with the IDs for standard icons anyway */
257 return hicon;
260 /***********************************************************************
261 * STATIC_TryPaintFcn
263 * Try to immediately paint the control.
265 static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
267 LONG style = full_style & SS_TYPEMASK;
268 RECT rc;
270 GetClientRect( hwnd, &rc );
271 if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
273 HDC hdc;
274 HRGN hrgn;
276 hdc = GetDC( hwnd );
277 hrgn = set_control_clipping( hdc, &rc );
278 (staticPaintFunc[style])( hwnd, hdc, full_style );
279 SelectClipRgn( hdc, hrgn );
280 if (hrgn) DeleteObject( hrgn );
281 ReleaseDC( hwnd, hdc );
285 static HBRUSH STATIC_SendWmCtlColorStatic(HWND hwnd, HDC hdc)
287 HBRUSH hBrush;
288 HWND parent = GetParent(hwnd);
290 if (!parent) parent = hwnd;
291 hBrush = (HBRUSH) SendMessageW( parent,
292 WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
293 if (!hBrush) /* did the app forget to call DefWindowProc ? */
295 /* FIXME: DefWindowProc should return different colors if a
296 manifest is present */
297 hBrush = (HBRUSH)DefWindowProcW( parent, WM_CTLCOLORSTATIC,
298 (WPARAM)hdc, (LPARAM)hwnd);
300 return hBrush;
303 static VOID STATIC_InitColours(void)
305 color_3ddkshadow = GetSysColor(COLOR_3DDKSHADOW);
306 color_3dshadow = GetSysColor(COLOR_3DSHADOW);
307 color_3dhighlight = GetSysColor(COLOR_3DHIGHLIGHT);
310 /***********************************************************************
311 * hasTextStyle
313 * Tests if the control displays text.
315 static BOOL hasTextStyle( DWORD style )
317 switch(style & SS_TYPEMASK)
319 case SS_SIMPLE:
320 case SS_LEFT:
321 case SS_LEFTNOWORDWRAP:
322 case SS_CENTER:
323 case SS_RIGHT:
324 case SS_OWNERDRAW:
325 return TRUE;
328 return FALSE;
331 /***********************************************************************
332 * StaticWndProc_common
334 LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL unicode )
336 LRESULT lResult = 0;
337 LONG full_style = GetWindowLongW( hwnd, GWL_STYLE );
338 LONG style = full_style & SS_TYPEMASK;
340 if (!IsWindow( hwnd )) return 0;
342 switch (uMsg)
344 case WM_CREATE:
345 if (style < 0L || style > SS_TYPEMASK)
347 ERR("Unknown style 0x%02x\n", style );
348 return -1;
350 STATIC_InitColours();
351 break;
353 case WM_NCDESTROY:
354 if (style == SS_ICON) {
356 * FIXME
357 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
359 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
360 * had already been loaded by the application the last thing we want to do is
361 * GlobalFree16 the handle.
363 break;
365 else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
366 DefWindowProcA(hwnd, uMsg, wParam, lParam);
368 case WM_ERASEBKGND:
369 /* do all painting in WM_PAINT like Windows does */
370 return 1;
372 case WM_PRINTCLIENT:
373 case WM_PAINT:
375 PAINTSTRUCT ps;
376 RECT rect;
377 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
378 GetClientRect( hwnd, &rect );
379 if (staticPaintFunc[style])
381 HRGN hrgn = set_control_clipping( hdc, &rect );
382 (staticPaintFunc[style])( hwnd, hdc, full_style );
383 SelectClipRgn( hdc, hrgn );
384 if (hrgn) DeleteObject( hrgn );
386 if (!wParam) EndPaint(hwnd, &ps);
388 break;
390 case WM_ENABLE:
391 STATIC_TryPaintFcn( hwnd, full_style );
392 if (full_style & SS_NOTIFY) {
393 if (wParam) {
394 SendMessageW( GetParent(hwnd), WM_COMMAND,
395 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_ENABLE ), (LPARAM)hwnd);
397 else {
398 SendMessageW( GetParent(hwnd), WM_COMMAND,
399 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DISABLE ), (LPARAM)hwnd);
402 break;
404 case WM_SYSCOLORCHANGE:
405 STATIC_InitColours();
406 STATIC_TryPaintFcn( hwnd, full_style );
407 break;
409 case WM_NCCREATE:
411 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
413 if (full_style & SS_SUNKEN)
414 SetWindowLongW( hwnd, GWL_EXSTYLE,
415 GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
417 switch (style) {
418 case SS_ICON:
420 HICON hIcon;
421 if (unicode || IS_INTRESOURCE(cs->lpszName))
422 hIcon = STATIC_LoadIconW(cs->hInstance, cs->lpszName, full_style);
423 else
424 hIcon = STATIC_LoadIconA(cs->hInstance, (LPCSTR)cs->lpszName, full_style);
425 STATIC_SetIcon(hwnd, hIcon, full_style);
427 break;
428 case SS_BITMAP:
429 if ((ULONG_PTR)cs->hInstance >> 16)
431 HBITMAP hBitmap;
432 if (unicode || IS_INTRESOURCE(cs->lpszName))
433 hBitmap = LoadBitmapW(cs->hInstance, cs->lpszName);
434 else
435 hBitmap = LoadBitmapA(cs->hInstance, (LPCSTR)cs->lpszName);
436 STATIC_SetBitmap(hwnd, hBitmap, full_style);
438 break;
440 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
441 the enhanced metafile that was specified as the window text. */
443 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
444 DefWindowProcA(hwnd, uMsg, wParam, lParam);
446 case WM_SETTEXT:
447 if (hasTextStyle( full_style ))
449 if (unicode)
450 lResult = DefWindowProcW( hwnd, uMsg, wParam, lParam );
451 else
452 lResult = DefWindowProcA( hwnd, uMsg, wParam, lParam );
453 STATIC_TryPaintFcn( hwnd, full_style );
455 break;
457 case WM_SETFONT:
458 if (hasTextStyle( full_style ))
460 SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, wParam );
461 if (LOWORD(lParam))
462 RedrawWindow( hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
464 break;
466 case WM_GETFONT:
467 return GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
469 case WM_NCHITTEST:
470 if (full_style & SS_NOTIFY)
471 return HTCLIENT;
472 else
473 return HTTRANSPARENT;
475 case WM_GETDLGCODE:
476 return DLGC_STATIC;
478 case WM_LBUTTONDOWN:
479 case WM_NCLBUTTONDOWN:
480 if (full_style & SS_NOTIFY)
481 SendMessageW( GetParent(hwnd), WM_COMMAND,
482 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_CLICKED ), (LPARAM)hwnd);
483 return 0;
485 case WM_LBUTTONDBLCLK:
486 case WM_NCLBUTTONDBLCLK:
487 if (full_style & SS_NOTIFY)
488 SendMessageW( GetParent(hwnd), WM_COMMAND,
489 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DBLCLK ), (LPARAM)hwnd);
490 return 0;
492 case STM_GETIMAGE:
493 return (LRESULT)STATIC_GetImage( hwnd, wParam, full_style );
495 case STM_GETICON:
496 return (LRESULT)STATIC_GetImage( hwnd, IMAGE_ICON, full_style );
498 case STM_SETIMAGE:
499 switch(wParam) {
500 case IMAGE_BITMAP:
501 if (style != SS_BITMAP) return 0;
502 lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
503 break;
504 case IMAGE_ENHMETAFILE:
505 if (style != SS_ENHMETAFILE) return 0;
506 lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
507 break;
508 case IMAGE_ICON:
509 case IMAGE_CURSOR:
510 if (style != SS_ICON) return 0;
511 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
512 break;
513 default:
514 FIXME("STM_SETIMAGE: Unhandled type %lx\n", wParam);
515 break;
517 STATIC_TryPaintFcn( hwnd, full_style );
518 break;
520 case STM_SETICON:
521 if (style != SS_ICON) return 0;
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;