kernel32: Update version to Win 10.
[wine.git] / dlls / user32 / static.c
blob72e49e15e8f92d2a503a1aad9be86a83c3eacb41
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 ((style & SS_TYPEMASK) != SS_ICON) return 0;
107 if (hicon && !get_icon_size( hicon, &size ))
109 WARN("hicon != 0, but invalid\n");
110 return 0;
112 prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
113 if (hicon && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
115 /* Windows currently doesn't implement SS_RIGHTJUST */
117 if ((style & SS_RIGHTJUST) != 0)
119 RECT wr;
120 GetWindowRect(hwnd, &wr);
121 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
122 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
124 else */
126 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
129 return prevIcon;
132 /***********************************************************************
133 * STATIC_SetBitmap
135 * Set the bitmap for an SS_BITMAP control.
137 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
139 HBITMAP hOldBitmap;
141 if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
142 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
143 WARN("hBitmap != 0, but it's not a bitmap\n");
144 return 0;
146 hOldBitmap = (HBITMAP)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hBitmap );
147 if (hBitmap && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
149 BITMAP bm;
150 GetObjectW(hBitmap, sizeof(bm), &bm);
151 /* Windows currently doesn't implement SS_RIGHTJUST */
153 if ((style & SS_RIGHTJUST) != 0)
155 RECT wr;
156 GetWindowRect(hwnd, &wr);
157 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
158 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
160 else */
162 SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
163 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
167 return hOldBitmap;
170 /***********************************************************************
171 * STATIC_SetEnhMetaFile
173 * Set the enhanced metafile for an SS_ENHMETAFILE control.
175 static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
177 if ((style & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
178 if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE) {
179 WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
180 return 0;
182 return (HENHMETAFILE)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hEnhMetaFile );
185 /***********************************************************************
186 * STATIC_GetImage
188 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
189 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
191 static HANDLE STATIC_GetImage( HWND hwnd, WPARAM wParam, DWORD style )
193 switch(style & SS_TYPEMASK)
195 case SS_ICON:
196 if ((wParam != IMAGE_ICON) &&
197 (wParam != IMAGE_CURSOR)) return NULL;
198 break;
199 case SS_BITMAP:
200 if (wParam != IMAGE_BITMAP) return NULL;
201 break;
202 case SS_ENHMETAFILE:
203 if (wParam != IMAGE_ENHMETAFILE) return NULL;
204 break;
205 default:
206 return NULL;
208 return (HANDLE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
211 /***********************************************************************
212 * STATIC_LoadIconA
214 * Load the icon for an SS_ICON control.
216 static HICON STATIC_LoadIconA( HINSTANCE hInstance, LPCSTR name, DWORD style )
218 HICON hicon = 0;
220 if (hInstance && ((ULONG_PTR)hInstance >> 16))
222 if ((style & SS_REALSIZEIMAGE) != 0)
223 hicon = LoadImageA(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
224 else
226 hicon = LoadIconA( hInstance, name );
227 if (!hicon) hicon = LoadCursorA( hInstance, name );
230 if (!hicon) hicon = LoadIconA( 0, name );
231 /* Windows doesn't try to load a standard cursor,
232 probably because most IDs for standard cursors conflict
233 with the IDs for standard icons anyway */
234 return hicon;
237 /***********************************************************************
238 * STATIC_LoadIconW
240 * Load the icon for an SS_ICON control.
242 static HICON STATIC_LoadIconW( HINSTANCE hInstance, LPCWSTR name, DWORD style )
244 HICON hicon = 0;
246 if (hInstance && ((ULONG_PTR)hInstance >> 16))
248 if ((style & SS_REALSIZEIMAGE) != 0)
249 hicon = LoadImageW(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
250 else
252 hicon = LoadIconW( hInstance, name );
253 if (!hicon) hicon = LoadCursorW( hInstance, name );
256 if (!hicon) hicon = LoadIconW( 0, name );
257 /* Windows doesn't try to load a standard cursor,
258 probably because most IDs for standard cursors conflict
259 with the IDs for standard icons anyway */
260 return hicon;
263 /***********************************************************************
264 * STATIC_TryPaintFcn
266 * Try to immediately paint the control.
268 static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
270 LONG style = full_style & SS_TYPEMASK;
271 RECT rc;
273 GetClientRect( hwnd, &rc );
274 if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
276 HDC hdc;
277 HRGN hrgn;
279 hdc = GetDC( hwnd );
280 hrgn = set_control_clipping( hdc, &rc );
281 (staticPaintFunc[style])( hwnd, hdc, full_style );
282 SelectClipRgn( hdc, hrgn );
283 if (hrgn) DeleteObject( hrgn );
284 ReleaseDC( hwnd, hdc );
288 static HBRUSH STATIC_SendWmCtlColorStatic(HWND hwnd, HDC hdc)
290 HBRUSH hBrush;
291 HWND parent = GetParent(hwnd);
293 if (!parent) parent = hwnd;
294 hBrush = (HBRUSH) SendMessageW( parent,
295 WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
296 if (!hBrush) /* did the app forget to call DefWindowProc ? */
298 /* FIXME: DefWindowProc should return different colors if a
299 manifest is present */
300 hBrush = (HBRUSH)DefWindowProcW( parent, WM_CTLCOLORSTATIC,
301 (WPARAM)hdc, (LPARAM)hwnd);
303 return hBrush;
306 static VOID STATIC_InitColours(void)
308 color_3ddkshadow = GetSysColor(COLOR_3DDKSHADOW);
309 color_3dshadow = GetSysColor(COLOR_3DSHADOW);
310 color_3dhighlight = GetSysColor(COLOR_3DHIGHLIGHT);
313 /***********************************************************************
314 * hasTextStyle
316 * Tests if the control displays text.
318 static BOOL hasTextStyle( DWORD style )
320 switch(style & SS_TYPEMASK)
322 case SS_SIMPLE:
323 case SS_LEFT:
324 case SS_LEFTNOWORDWRAP:
325 case SS_CENTER:
326 case SS_RIGHT:
327 case SS_OWNERDRAW:
328 return TRUE;
331 return FALSE;
334 /***********************************************************************
335 * StaticWndProc_common
337 LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL unicode )
339 LRESULT lResult = 0;
340 LONG full_style = GetWindowLongW( hwnd, GWL_STYLE );
341 LONG style = full_style & SS_TYPEMASK;
343 if (!IsWindow( hwnd )) return 0;
345 switch (uMsg)
347 case WM_CREATE:
348 if (style < 0L || style > SS_TYPEMASK)
350 ERR("Unknown style 0x%02x\n", style );
351 return -1;
353 STATIC_InitColours();
354 break;
356 case WM_NCDESTROY:
357 if (style == SS_ICON) {
359 * FIXME
360 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
362 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
363 * had already been loaded by the application the last thing we want to do is
364 * GlobalFree16 the handle.
366 break;
368 else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
369 DefWindowProcA(hwnd, uMsg, wParam, lParam);
371 case WM_ERASEBKGND:
372 /* do all painting in WM_PAINT like Windows does */
373 return 1;
375 case WM_PRINTCLIENT:
376 case WM_PAINT:
378 PAINTSTRUCT ps;
379 RECT rect;
380 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
381 GetClientRect( hwnd, &rect );
382 if (staticPaintFunc[style])
384 HRGN hrgn = set_control_clipping( hdc, &rect );
385 (staticPaintFunc[style])( hwnd, hdc, full_style );
386 SelectClipRgn( hdc, hrgn );
387 if (hrgn) DeleteObject( hrgn );
389 if (!wParam) EndPaint(hwnd, &ps);
391 break;
393 case WM_ENABLE:
394 STATIC_TryPaintFcn( hwnd, full_style );
395 if (full_style & SS_NOTIFY) {
396 if (wParam) {
397 SendMessageW( GetParent(hwnd), WM_COMMAND,
398 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_ENABLE ), (LPARAM)hwnd);
400 else {
401 SendMessageW( GetParent(hwnd), WM_COMMAND,
402 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DISABLE ), (LPARAM)hwnd);
405 break;
407 case WM_SYSCOLORCHANGE:
408 STATIC_InitColours();
409 STATIC_TryPaintFcn( hwnd, full_style );
410 break;
412 case WM_NCCREATE:
414 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
416 if (full_style & SS_SUNKEN)
417 SetWindowLongW( hwnd, GWL_EXSTYLE,
418 GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
420 switch (style) {
421 case SS_ICON:
423 HICON hIcon;
424 if (unicode || IS_INTRESOURCE(cs->lpszName))
425 hIcon = STATIC_LoadIconW(cs->hInstance, cs->lpszName, full_style);
426 else
427 hIcon = STATIC_LoadIconA(cs->hInstance, (LPCSTR)cs->lpszName, full_style);
428 STATIC_SetIcon(hwnd, hIcon, full_style);
430 break;
431 case SS_BITMAP:
432 if ((ULONG_PTR)cs->hInstance >> 16)
434 HBITMAP hBitmap;
435 if (unicode || IS_INTRESOURCE(cs->lpszName))
436 hBitmap = LoadBitmapW(cs->hInstance, cs->lpszName);
437 else
438 hBitmap = LoadBitmapA(cs->hInstance, (LPCSTR)cs->lpszName);
439 STATIC_SetBitmap(hwnd, hBitmap, full_style);
441 break;
443 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
444 the enhanced metafile that was specified as the window text. */
446 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
447 DefWindowProcA(hwnd, uMsg, wParam, lParam);
449 case WM_SETTEXT:
450 if (hasTextStyle( full_style ))
452 if (unicode)
453 lResult = DefWindowProcW( hwnd, uMsg, wParam, lParam );
454 else
455 lResult = DefWindowProcA( hwnd, uMsg, wParam, lParam );
456 STATIC_TryPaintFcn( hwnd, full_style );
458 break;
460 case WM_SETFONT:
461 if (hasTextStyle( full_style ))
463 SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, wParam );
464 if (LOWORD(lParam))
465 RedrawWindow( hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
467 break;
469 case WM_GETFONT:
470 return GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
472 case WM_NCHITTEST:
473 if (full_style & SS_NOTIFY)
474 return HTCLIENT;
475 else
476 return HTTRANSPARENT;
478 case WM_GETDLGCODE:
479 return DLGC_STATIC;
481 case WM_LBUTTONDOWN:
482 case WM_NCLBUTTONDOWN:
483 if (full_style & SS_NOTIFY)
484 SendMessageW( GetParent(hwnd), WM_COMMAND,
485 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_CLICKED ), (LPARAM)hwnd);
486 return 0;
488 case WM_LBUTTONDBLCLK:
489 case WM_NCLBUTTONDBLCLK:
490 if (full_style & SS_NOTIFY)
491 SendMessageW( GetParent(hwnd), WM_COMMAND,
492 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DBLCLK ), (LPARAM)hwnd);
493 return 0;
495 case STM_GETIMAGE:
496 return (LRESULT)STATIC_GetImage( hwnd, wParam, full_style );
498 case STM_GETICON:
499 return (LRESULT)STATIC_GetImage( hwnd, IMAGE_ICON, full_style );
501 case STM_SETIMAGE:
502 switch(wParam) {
503 case IMAGE_BITMAP:
504 lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
505 break;
506 case IMAGE_ENHMETAFILE:
507 lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
508 break;
509 case IMAGE_ICON:
510 case IMAGE_CURSOR:
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 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
522 STATIC_TryPaintFcn( hwnd, full_style );
523 break;
525 default:
526 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
527 DefWindowProcA(hwnd, uMsg, wParam, lParam);
529 return lResult;
532 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
534 DRAWITEMSTRUCT dis;
535 HFONT font, oldFont = NULL;
536 UINT id = (UINT)GetWindowLongPtrW( hwnd, GWLP_ID );
538 dis.CtlType = ODT_STATIC;
539 dis.CtlID = id;
540 dis.itemID = 0;
541 dis.itemAction = ODA_DRAWENTIRE;
542 dis.itemState = IsWindowEnabled(hwnd) ? 0 : ODS_DISABLED;
543 dis.hwndItem = hwnd;
544 dis.hDC = hdc;
545 dis.itemData = 0;
546 GetClientRect( hwnd, &dis.rcItem );
548 font = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
549 if (font) oldFont = SelectObject( hdc, font );
550 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
551 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
552 if (font) SelectObject( hdc, oldFont );
555 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
557 RECT rc;
558 HBRUSH hBrush;
559 HFONT hFont, hOldFont = NULL;
560 UINT format;
561 INT len, buf_size;
562 WCHAR *text;
564 GetClientRect( hwnd, &rc);
566 switch (style & SS_TYPEMASK)
568 case SS_LEFT:
569 format = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
570 break;
572 case SS_CENTER:
573 format = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
574 break;
576 case SS_RIGHT:
577 format = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
578 break;
580 case SS_SIMPLE:
581 format = DT_LEFT | DT_SINGLELINE;
582 break;
584 case SS_LEFTNOWORDWRAP:
585 format = DT_LEFT | DT_EXPANDTABS;
586 break;
588 default:
589 return;
592 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_RIGHT)
593 format = DT_RIGHT | (format & ~(DT_LEFT | DT_CENTER));
595 if (style & SS_NOPREFIX)
596 format |= DT_NOPREFIX;
598 if ((style & SS_TYPEMASK) != SS_SIMPLE)
600 if (style & SS_CENTERIMAGE)
601 format |= DT_SINGLELINE | DT_VCENTER;
602 if (style & SS_EDITCONTROL)
603 format |= DT_EDITCONTROL;
604 if (style & SS_ENDELLIPSIS)
605 format |= DT_SINGLELINE | DT_END_ELLIPSIS;
606 if (style & SS_PATHELLIPSIS)
607 format |= DT_SINGLELINE | DT_PATH_ELLIPSIS;
608 if (style & SS_WORDELLIPSIS)
609 format |= DT_SINGLELINE | DT_WORD_ELLIPSIS;
612 if ((hFont = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET )))
613 hOldFont = SelectObject( hdc, hFont );
615 /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
616 brush is not used */
617 hBrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
619 if ((style & SS_TYPEMASK) != SS_SIMPLE)
621 FillRect( hdc, &rc, hBrush );
622 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
625 buf_size = 256;
626 if (!(text = HeapAlloc( GetProcessHeap(), 0, buf_size * sizeof(WCHAR) )))
627 goto no_TextOut;
629 while ((len = InternalGetWindowText( hwnd, text, buf_size )) == buf_size - 1)
631 buf_size *= 2;
632 if (!(text = HeapReAlloc( GetProcessHeap(), 0, text, buf_size * sizeof(WCHAR) )))
633 goto no_TextOut;
636 if (!len) goto no_TextOut;
638 if (((style & SS_TYPEMASK) == SS_SIMPLE) && (style & SS_NOPREFIX))
640 /* Windows uses the faster ExtTextOut() to draw the text and
641 to paint the whole client rectangle with the text background
642 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
643 ExtTextOutW( hdc, rc.left, rc.top, ETO_CLIPPED | ETO_OPAQUE,
644 &rc, text, len, NULL );
646 else
648 DrawTextW( hdc, text, -1, &rc, format );
651 no_TextOut:
652 HeapFree( GetProcessHeap(), 0, text );
654 if (hFont)
655 SelectObject( hdc, hOldFont );
658 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
660 RECT rc;
661 HBRUSH hBrush;
663 GetClientRect( hwnd, &rc);
665 /* FIXME: send WM_CTLCOLORSTATIC */
666 switch (style & SS_TYPEMASK)
668 case SS_BLACKRECT:
669 hBrush = CreateSolidBrush(color_3ddkshadow);
670 FillRect( hdc, &rc, hBrush );
671 break;
672 case SS_GRAYRECT:
673 hBrush = CreateSolidBrush(color_3dshadow);
674 FillRect( hdc, &rc, hBrush );
675 break;
676 case SS_WHITERECT:
677 hBrush = CreateSolidBrush(color_3dhighlight);
678 FillRect( hdc, &rc, hBrush );
679 break;
680 case SS_BLACKFRAME:
681 hBrush = CreateSolidBrush(color_3ddkshadow);
682 FrameRect( hdc, &rc, hBrush );
683 break;
684 case SS_GRAYFRAME:
685 hBrush = CreateSolidBrush(color_3dshadow);
686 FrameRect( hdc, &rc, hBrush );
687 break;
688 case SS_WHITEFRAME:
689 hBrush = CreateSolidBrush(color_3dhighlight);
690 FrameRect( hdc, &rc, hBrush );
691 break;
692 default:
693 return;
695 DeleteObject( hBrush );
699 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
701 RECT rc, iconRect;
702 HBRUSH hbrush;
703 HICON hIcon;
704 SIZE size;
706 GetClientRect( hwnd, &rc );
707 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
708 hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
709 if (!hIcon || !get_icon_size( hIcon, &size ))
711 FillRect(hdc, &rc, hbrush);
713 else
715 if (style & SS_CENTERIMAGE)
717 iconRect.left = (rc.right - rc.left) / 2 - size.cx / 2;
718 iconRect.top = (rc.bottom - rc.top) / 2 - size.cy / 2;
719 iconRect.right = iconRect.left + size.cx;
720 iconRect.bottom = iconRect.top + size.cy;
722 else
723 iconRect = rc;
724 FillRect( hdc, &rc, hbrush );
725 DrawIconEx( hdc, iconRect.left, iconRect.top, hIcon, iconRect.right - iconRect.left,
726 iconRect.bottom - iconRect.top, 0, NULL, DI_NORMAL );
730 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
732 HDC hMemDC;
733 HBITMAP hBitmap, oldbitmap;
735 /* message is still sent, even if the returned brush is not used */
736 STATIC_SendWmCtlColorStatic(hwnd, hdc);
738 if ((hBitmap = (HBITMAP)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET ))
739 && (GetObjectType(hBitmap) == OBJ_BITMAP)
740 && (hMemDC = CreateCompatibleDC( hdc )))
742 BITMAP bm;
743 RECT rcClient;
745 GetObjectW(hBitmap, sizeof(bm), &bm);
746 oldbitmap = SelectObject(hMemDC, hBitmap);
748 GetClientRect(hwnd, &rcClient);
749 if (style & SS_CENTERIMAGE)
751 HBRUSH hbrush = CreateSolidBrush(GetPixel(hMemDC, 0, 0));
753 FillRect(hdc, &rcClient, hbrush);
755 rcClient.left = (rcClient.right - rcClient.left)/2 - bm.bmWidth/2;
756 rcClient.top = (rcClient.bottom - rcClient.top)/2 - bm.bmHeight/2;
757 rcClient.right = rcClient.left + bm.bmWidth;
758 rcClient.bottom = rcClient.top + bm.bmHeight;
760 DeleteObject(hbrush);
762 StretchBlt(hdc, rcClient.left, rcClient.top, rcClient.right - rcClient.left,
763 rcClient.bottom - rcClient.top, hMemDC,
764 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
765 SelectObject(hMemDC, oldbitmap);
766 DeleteDC(hMemDC);
771 static void STATIC_PaintEnhMetafn(HWND hwnd, HDC hdc, DWORD style )
773 HENHMETAFILE hEnhMetaFile;
774 RECT rc;
775 HBRUSH hbrush;
777 GetClientRect(hwnd, &rc);
778 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
779 FillRect(hdc, &rc, hbrush);
780 if ((hEnhMetaFile = (HENHMETAFILE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
782 /* The control's current font is not selected into the
783 device context! */
784 if (GetObjectType(hEnhMetaFile) == OBJ_ENHMETAFILE)
785 PlayEnhMetaFile(hdc, hEnhMetaFile, &rc);
790 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
792 RECT rc;
794 /* FIXME: sometimes (not always) sends WM_CTLCOLORSTATIC */
795 GetClientRect( hwnd, &rc );
796 switch (style & SS_TYPEMASK)
798 case SS_ETCHEDHORZ:
799 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
800 break;
801 case SS_ETCHEDVERT:
802 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
803 break;
804 case SS_ETCHEDFRAME:
805 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
806 break;