user32: Pre-allocate the window procedure for the static class.
[wine/hacks.git] / dlls / user32 / static.c
blob0f778bb16389bfaa835b6402af9851fc22220d27
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
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.
29 * Notes:
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).
41 * TODO:
42 * - Animated cursors
45 #include <stdarg.h>
47 #include "windef.h"
48 #include "winbase.h"
49 #include "wingdi.h"
50 #include "controls.h"
51 #include "user_private.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(static);
56 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style );
57 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style );
58 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style );
59 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style );
60 static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc, DWORD style );
61 static void STATIC_PaintEnhMetafn( HWND hwnd, HDC hdc, DWORD style );
62 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style );
64 static COLORREF color_3dshadow, color_3ddkshadow, color_3dhighlight;
66 /* offsets for GetWindowLong for static private information */
67 #define HFONT_GWL_OFFSET 0
68 #define HICON_GWL_OFFSET (sizeof(HFONT))
69 #define STATIC_EXTRA_BYTES (HICON_GWL_OFFSET + sizeof(HICON))
71 typedef void (*pfPaint)( HWND hwnd, HDC hdc, DWORD style );
73 static const pfPaint staticPaintFunc[SS_TYPEMASK+1] =
75 STATIC_PaintTextfn, /* SS_LEFT */
76 STATIC_PaintTextfn, /* SS_CENTER */
77 STATIC_PaintTextfn, /* SS_RIGHT */
78 STATIC_PaintIconfn, /* SS_ICON */
79 STATIC_PaintRectfn, /* SS_BLACKRECT */
80 STATIC_PaintRectfn, /* SS_GRAYRECT */
81 STATIC_PaintRectfn, /* SS_WHITERECT */
82 STATIC_PaintRectfn, /* SS_BLACKFRAME */
83 STATIC_PaintRectfn, /* SS_GRAYFRAME */
84 STATIC_PaintRectfn, /* SS_WHITEFRAME */
85 NULL, /* SS_USERITEM */
86 STATIC_PaintTextfn, /* SS_SIMPLE */
87 STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
88 STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
89 STATIC_PaintBitmapfn, /* SS_BITMAP */
90 STATIC_PaintEnhMetafn, /* SS_ENHMETAFILE */
91 STATIC_PaintEtchedfn, /* SS_ETCHEDHORZ */
92 STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
93 STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
97 /*********************************************************************
98 * static class descriptor
100 static const WCHAR staticW[] = {'S','t','a','t','i','c',0};
101 const struct builtin_class_descr STATIC_builtin_class =
103 staticW, /* name */
104 CS_DBLCLKS | CS_PARENTDC, /* style */
105 NULL, /* procA */
106 BUILTIN_WINPROC(WINPROC_STATIC), /* procW */
107 STATIC_EXTRA_BYTES, /* extra */
108 IDC_ARROW, /* cursor */
109 0 /* brush */
112 static void setup_clipping(HWND hwnd, HDC hdc, HRGN *orig)
114 RECT rc;
115 HRGN hrgn;
117 /* Native control has always a clipping region set (this may be because
118 * builtin controls uses CS_PARENTDC) and an application depends on it
120 hrgn = CreateRectRgn(0, 0, 1, 1);
121 if (GetClipRgn(hdc, hrgn) != 1)
123 DeleteObject(hrgn);
124 *orig = NULL;
125 } else
126 *orig = hrgn;
128 GetClientRect(hwnd, &rc);
129 DPtoLP(hdc, (POINT *)&rc, 2);
130 IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom);
133 static void restore_clipping(HDC hdc, HRGN hrgn)
135 SelectClipRgn(hdc, hrgn);
136 if (hrgn != NULL)
137 DeleteObject(hrgn);
140 /***********************************************************************
141 * STATIC_SetIcon
143 * Set the icon for an SS_ICON control.
145 static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
147 HICON prevIcon;
148 SIZE size;
150 if ((style & SS_TYPEMASK) != SS_ICON) return 0;
151 if (hicon && !get_icon_size( hicon, &size ))
153 WARN("hicon != 0, but invalid\n");
154 return 0;
156 prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
157 if (hicon && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
159 /* Windows currently doesn't implement SS_RIGHTJUST */
161 if ((style & SS_RIGHTJUST) != 0)
163 RECT wr;
164 GetWindowRect(hwnd, &wr);
165 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
166 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
168 else */
170 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
173 return prevIcon;
176 /***********************************************************************
177 * STATIC_SetBitmap
179 * Set the bitmap for an SS_BITMAP control.
181 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
183 HBITMAP hOldBitmap;
185 if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
186 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
187 WARN("hBitmap != 0, but it's not a bitmap\n");
188 return 0;
190 hOldBitmap = (HBITMAP)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hBitmap );
191 if (hBitmap && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
193 BITMAP bm;
194 GetObjectW(hBitmap, sizeof(bm), &bm);
195 /* Windows currently doesn't implement SS_RIGHTJUST */
197 if ((style & SS_RIGHTJUST) != 0)
199 RECT wr;
200 GetWindowRect(hwnd, &wr);
201 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
202 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
204 else */
206 SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
207 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
211 return hOldBitmap;
214 /***********************************************************************
215 * STATIC_SetEnhMetaFile
217 * Set the enhanced metafile for an SS_ENHMETAFILE control.
219 static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
221 if ((style & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
222 if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE) {
223 WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
224 return 0;
226 return (HENHMETAFILE)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hEnhMetaFile );
229 /***********************************************************************
230 * STATIC_GetImage
232 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
233 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
235 static HANDLE STATIC_GetImage( HWND hwnd, WPARAM wParam, DWORD style )
237 switch(style & SS_TYPEMASK)
239 case SS_ICON:
240 if ((wParam != IMAGE_ICON) &&
241 (wParam != IMAGE_CURSOR)) return NULL;
242 break;
243 case SS_BITMAP:
244 if (wParam != IMAGE_BITMAP) return NULL;
245 break;
246 case SS_ENHMETAFILE:
247 if (wParam != IMAGE_ENHMETAFILE) return NULL;
248 break;
249 default:
250 return NULL;
252 return (HANDLE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
255 /***********************************************************************
256 * STATIC_LoadIconA
258 * Load the icon for an SS_ICON control.
260 static HICON STATIC_LoadIconA( HWND hwnd, LPCSTR name, DWORD style )
262 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
263 if ((style & SS_REALSIZEIMAGE) != 0)
265 return LoadImageA(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
267 else
269 HICON hicon = LoadIconA( hInstance, name );
270 if (!hicon) hicon = LoadCursorA( hInstance, name );
271 if (!hicon) hicon = LoadIconA( 0, name );
272 /* Windows doesn't try to load a standard cursor,
273 probably because most IDs for standard cursors conflict
274 with the IDs for standard icons anyway */
275 return hicon;
279 /***********************************************************************
280 * STATIC_LoadIconW
282 * Load the icon for an SS_ICON control.
284 static HICON STATIC_LoadIconW( HWND hwnd, LPCWSTR name, DWORD style )
286 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
287 if ((style & SS_REALSIZEIMAGE) != 0)
289 return LoadImageW(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
291 else
293 HICON hicon = LoadIconW( hInstance, name );
294 if (!hicon) hicon = LoadCursorW( hInstance, name );
295 if (!hicon) hicon = LoadIconW( 0, name );
296 /* Windows doesn't try to load a standard cursor,
297 probably because most IDs for standard cursors conflict
298 with the IDs for standard icons anyway */
299 return hicon;
303 /***********************************************************************
304 * STATIC_LoadBitmapA
306 * Load the bitmap for an SS_BITMAP control.
308 static HBITMAP STATIC_LoadBitmapA( HWND hwnd, LPCSTR name )
310 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
311 /* Windows doesn't try to load OEM Bitmaps (hInstance == NULL) */
312 return LoadBitmapA( hInstance, name );
315 /***********************************************************************
316 * STATIC_LoadBitmapW
318 * Load the bitmap for an SS_BITMAP control.
320 static HBITMAP STATIC_LoadBitmapW( HWND hwnd, LPCWSTR name )
322 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
323 /* Windows doesn't try to load OEM Bitmaps (hInstance == NULL) */
324 return LoadBitmapW( hInstance, name );
327 /***********************************************************************
328 * STATIC_TryPaintFcn
330 * Try to immediately paint the control.
332 static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
334 LONG style = full_style & SS_TYPEMASK;
335 RECT rc;
337 GetClientRect( hwnd, &rc );
338 if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
340 HDC hdc;
341 HRGN hOrigClipping;
343 hdc = GetDC( hwnd );
344 setup_clipping(hwnd, hdc, &hOrigClipping);
345 (staticPaintFunc[style])( hwnd, hdc, full_style );
346 restore_clipping(hdc, hOrigClipping);
347 ReleaseDC( hwnd, hdc );
351 static HBRUSH STATIC_SendWmCtlColorStatic(HWND hwnd, HDC hdc)
353 HBRUSH hBrush;
354 HWND parent = GetParent(hwnd);
356 if (!parent) parent = hwnd;
357 hBrush = (HBRUSH) SendMessageW( parent,
358 WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
359 if (!hBrush) /* did the app forget to call DefWindowProc ? */
361 /* FIXME: DefWindowProc should return different colors if a
362 manifest is present */
363 hBrush = (HBRUSH)DefWindowProcW( parent, WM_CTLCOLORSTATIC,
364 (WPARAM)hdc, (LPARAM)hwnd);
366 return hBrush;
369 static VOID STATIC_InitColours(void)
371 color_3ddkshadow = GetSysColor(COLOR_3DDKSHADOW);
372 color_3dshadow = GetSysColor(COLOR_3DSHADOW);
373 color_3dhighlight = GetSysColor(COLOR_3DHIGHLIGHT);
376 /***********************************************************************
377 * hasTextStyle
379 * Tests if the control displays text.
381 static BOOL hasTextStyle( DWORD style )
383 switch(style & SS_TYPEMASK)
385 case SS_SIMPLE:
386 case SS_LEFT:
387 case SS_LEFTNOWORDWRAP:
388 case SS_CENTER:
389 case SS_RIGHT:
390 case SS_OWNERDRAW:
391 return TRUE;
394 return FALSE;
397 /***********************************************************************
398 * StaticWndProc_common
400 LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL unicode )
402 LRESULT lResult = 0;
403 LONG full_style = GetWindowLongW( hwnd, GWL_STYLE );
404 LONG style = full_style & SS_TYPEMASK;
406 if (!IsWindow( hwnd )) return 0;
408 switch (uMsg)
410 case WM_CREATE:
411 if (style < 0L || style > SS_TYPEMASK)
413 ERR("Unknown style 0x%02x\n", style );
414 return -1;
416 STATIC_InitColours();
417 break;
419 case WM_NCDESTROY:
420 if (style == SS_ICON) {
422 * FIXME
423 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
425 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
426 * had already been loaded by the application the last thing we want to do is
427 * GlobalFree16 the handle.
429 break;
431 else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
432 DefWindowProcA(hwnd, uMsg, wParam, lParam);
434 case WM_ERASEBKGND:
435 /* do all painting in WM_PAINT like Windows does */
436 return 1;
438 case WM_PRINTCLIENT:
439 case WM_PAINT:
441 PAINTSTRUCT ps;
442 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
443 if (staticPaintFunc[style])
445 HRGN hOrigClipping;
446 setup_clipping(hwnd, hdc, &hOrigClipping);
447 (staticPaintFunc[style])( hwnd, hdc, full_style );
448 restore_clipping(hdc, hOrigClipping);
450 if (!wParam) EndPaint(hwnd, &ps);
452 break;
454 case WM_ENABLE:
455 STATIC_TryPaintFcn( hwnd, full_style );
456 if (full_style & SS_NOTIFY) {
457 if (wParam) {
458 SendMessageW( GetParent(hwnd), WM_COMMAND,
459 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_ENABLE ), (LPARAM)hwnd);
461 else {
462 SendMessageW( GetParent(hwnd), WM_COMMAND,
463 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DISABLE ), (LPARAM)hwnd);
466 break;
468 case WM_SYSCOLORCHANGE:
469 STATIC_InitColours();
470 STATIC_TryPaintFcn( hwnd, full_style );
471 break;
473 case WM_NCCREATE:
475 LPCSTR textA;
476 LPCWSTR textW;
478 if (full_style & SS_SUNKEN)
479 SetWindowLongW( hwnd, GWL_EXSTYLE,
480 GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
482 if(unicode)
484 textA = NULL;
485 textW = ((LPCREATESTRUCTW)lParam)->lpszName;
487 else
489 textA = ((LPCREATESTRUCTA)lParam)->lpszName;
490 textW = NULL;
493 switch (style) {
494 case SS_ICON:
496 HICON hIcon;
497 if(unicode)
498 hIcon = STATIC_LoadIconW(hwnd, textW, full_style);
499 else
500 hIcon = STATIC_LoadIconA(hwnd, textA, full_style);
501 STATIC_SetIcon(hwnd, hIcon, full_style);
503 break;
504 case SS_BITMAP:
506 HBITMAP hBitmap;
507 if(unicode)
508 hBitmap = STATIC_LoadBitmapW(hwnd, textW);
509 else
510 hBitmap = STATIC_LoadBitmapA(hwnd, textA);
511 STATIC_SetBitmap(hwnd, hBitmap, full_style);
513 break;
515 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
516 the enhanced metafile that was specified as the window text. */
518 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
519 DefWindowProcA(hwnd, uMsg, wParam, lParam);
521 case WM_SETTEXT:
522 if (hasTextStyle( full_style ))
524 if (HIWORD(lParam))
526 if(unicode)
527 lResult = DefWindowProcW( hwnd, uMsg, wParam, lParam );
528 else
529 lResult = DefWindowProcA( hwnd, uMsg, wParam, lParam );
530 STATIC_TryPaintFcn( hwnd, full_style );
533 break;
535 case WM_SETFONT:
536 if (hasTextStyle( full_style ))
538 SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, wParam );
539 if (LOWORD(lParam))
540 RedrawWindow( hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
542 break;
544 case WM_GETFONT:
545 return GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
547 case WM_NCHITTEST:
548 if (full_style & SS_NOTIFY)
549 return HTCLIENT;
550 else
551 return HTTRANSPARENT;
553 case WM_GETDLGCODE:
554 return DLGC_STATIC;
556 case WM_LBUTTONDOWN:
557 case WM_NCLBUTTONDOWN:
558 if (full_style & SS_NOTIFY)
559 SendMessageW( GetParent(hwnd), WM_COMMAND,
560 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_CLICKED ), (LPARAM)hwnd);
561 return 0;
563 case WM_LBUTTONDBLCLK:
564 case WM_NCLBUTTONDBLCLK:
565 if (full_style & SS_NOTIFY)
566 SendMessageW( GetParent(hwnd), WM_COMMAND,
567 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DBLCLK ), (LPARAM)hwnd);
568 return 0;
570 case STM_GETIMAGE:
571 return (LRESULT)STATIC_GetImage( hwnd, wParam, full_style );
573 case STM_GETICON:
574 return (LRESULT)STATIC_GetImage( hwnd, IMAGE_ICON, full_style );
576 case STM_SETIMAGE:
577 switch(wParam) {
578 case IMAGE_BITMAP:
579 lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
580 break;
581 case IMAGE_ENHMETAFILE:
582 lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
583 break;
584 case IMAGE_ICON:
585 case IMAGE_CURSOR:
586 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
587 break;
588 default:
589 FIXME("STM_SETIMAGE: Unhandled type %lx\n", wParam);
590 break;
592 STATIC_TryPaintFcn( hwnd, full_style );
593 break;
595 case STM_SETICON:
596 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
597 STATIC_TryPaintFcn( hwnd, full_style );
598 break;
600 default:
601 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
602 DefWindowProcA(hwnd, uMsg, wParam, lParam);
604 return lResult;
607 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
609 DRAWITEMSTRUCT dis;
610 HFONT font, oldFont = NULL;
611 UINT id = (UINT)GetWindowLongPtrW( hwnd, GWLP_ID );
613 dis.CtlType = ODT_STATIC;
614 dis.CtlID = id;
615 dis.itemID = 0;
616 dis.itemAction = ODA_DRAWENTIRE;
617 dis.itemState = IsWindowEnabled(hwnd) ? 0 : ODS_DISABLED;
618 dis.hwndItem = hwnd;
619 dis.hDC = hdc;
620 dis.itemData = 0;
621 GetClientRect( hwnd, &dis.rcItem );
623 font = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
624 if (font) oldFont = SelectObject( hdc, font );
625 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
626 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
627 if (font) SelectObject( hdc, oldFont );
630 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
632 RECT rc;
633 HBRUSH hBrush;
634 HFONT hFont, hOldFont = NULL;
635 WORD wFormat;
636 INT len, buf_size;
637 WCHAR *text;
639 GetClientRect( hwnd, &rc);
641 switch (style & SS_TYPEMASK)
643 case SS_LEFT:
644 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
645 break;
647 case SS_CENTER:
648 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
649 break;
651 case SS_RIGHT:
652 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
653 break;
655 case SS_SIMPLE:
656 wFormat = DT_LEFT | DT_SINGLELINE;
657 break;
659 case SS_LEFTNOWORDWRAP:
660 wFormat = DT_LEFT | DT_EXPANDTABS;
661 break;
663 default:
664 return;
667 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_RIGHT)
668 wFormat = DT_RIGHT | (wFormat & ~(DT_LEFT | DT_CENTER));
670 if (style & SS_NOPREFIX)
671 wFormat |= DT_NOPREFIX;
673 if ((style & SS_TYPEMASK) != SS_SIMPLE)
675 if (style & SS_CENTERIMAGE)
676 wFormat |= DT_SINGLELINE | DT_VCENTER;
677 if (style & SS_EDITCONTROL)
678 wFormat |= DT_EDITCONTROL;
679 if (style & SS_ENDELLIPSIS)
680 wFormat |= DT_SINGLELINE | DT_END_ELLIPSIS;
681 if (style & SS_PATHELLIPSIS)
682 wFormat |= DT_SINGLELINE | DT_PATH_ELLIPSIS;
683 if (style & SS_WORDELLIPSIS)
684 wFormat |= DT_SINGLELINE | DT_WORD_ELLIPSIS;
687 if ((hFont = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET )))
688 hOldFont = SelectObject( hdc, hFont );
690 /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
691 brush is not used */
692 hBrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
694 if ((style & SS_TYPEMASK) != SS_SIMPLE)
696 FillRect( hdc, &rc, hBrush );
697 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
700 buf_size = 256;
701 if (!(text = HeapAlloc( GetProcessHeap(), 0, buf_size * sizeof(WCHAR) )))
702 goto no_TextOut;
704 while ((len = InternalGetWindowText( hwnd, text, buf_size )) == buf_size - 1)
706 buf_size *= 2;
707 if (!(text = HeapReAlloc( GetProcessHeap(), 0, text, buf_size * sizeof(WCHAR) )))
708 goto no_TextOut;
711 if (!len) goto no_TextOut;
713 if (((style & SS_TYPEMASK) == SS_SIMPLE) && (style & SS_NOPREFIX))
715 /* Windows uses the faster ExtTextOut() to draw the text and
716 to paint the whole client rectangle with the text background
717 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
718 ExtTextOutW( hdc, rc.left, rc.top, ETO_CLIPPED | ETO_OPAQUE,
719 &rc, text, len, NULL );
721 else
723 DrawTextW( hdc, text, -1, &rc, wFormat );
726 no_TextOut:
727 HeapFree( GetProcessHeap(), 0, text );
729 if (hFont)
730 SelectObject( hdc, hOldFont );
733 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
735 RECT rc;
736 HBRUSH hBrush;
738 GetClientRect( hwnd, &rc);
740 /* FIXME: send WM_CTLCOLORSTATIC */
741 switch (style & SS_TYPEMASK)
743 case SS_BLACKRECT:
744 hBrush = CreateSolidBrush(color_3ddkshadow);
745 FillRect( hdc, &rc, hBrush );
746 break;
747 case SS_GRAYRECT:
748 hBrush = CreateSolidBrush(color_3dshadow);
749 FillRect( hdc, &rc, hBrush );
750 break;
751 case SS_WHITERECT:
752 hBrush = CreateSolidBrush(color_3dhighlight);
753 FillRect( hdc, &rc, hBrush );
754 break;
755 case SS_BLACKFRAME:
756 hBrush = CreateSolidBrush(color_3ddkshadow);
757 FrameRect( hdc, &rc, hBrush );
758 break;
759 case SS_GRAYFRAME:
760 hBrush = CreateSolidBrush(color_3dshadow);
761 FrameRect( hdc, &rc, hBrush );
762 break;
763 case SS_WHITEFRAME:
764 hBrush = CreateSolidBrush(color_3dhighlight);
765 FrameRect( hdc, &rc, hBrush );
766 break;
767 default:
768 return;
770 DeleteObject( hBrush );
774 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
776 RECT rc, iconRect;
777 HBRUSH hbrush;
778 HICON hIcon;
779 SIZE size;
781 GetClientRect( hwnd, &rc );
782 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
783 hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
784 if (!hIcon || !get_icon_size( hIcon, &size ))
786 FillRect(hdc, &rc, hbrush);
788 else
790 if (style & SS_CENTERIMAGE)
792 iconRect.left = (rc.right - rc.left) / 2 - size.cx / 2;
793 iconRect.top = (rc.bottom - rc.top) / 2 - size.cy / 2;
794 iconRect.right = iconRect.left + size.cx;
795 iconRect.bottom = iconRect.top + size.cy;
797 else
798 iconRect = rc;
799 FillRect( hdc, &rc, hbrush );
800 DrawIconEx( hdc, iconRect.left, iconRect.top, hIcon, iconRect.right - iconRect.left,
801 iconRect.bottom - iconRect.top, 0, NULL, DI_NORMAL );
805 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
807 HDC hMemDC;
808 HBITMAP hBitmap, oldbitmap;
809 HBRUSH hbrush;
811 /* message is still sent, even if the returned brush is not used */
812 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
814 if ((hBitmap = (HBITMAP)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET ))
815 && (GetObjectType(hBitmap) == OBJ_BITMAP)
816 && (hMemDC = CreateCompatibleDC( hdc )))
818 BITMAP bm;
819 RECT rcClient;
820 LOGBRUSH brush;
822 GetObjectW(hBitmap, sizeof(bm), &bm);
823 oldbitmap = SelectObject(hMemDC, hBitmap);
825 /* Set the background color for monochrome bitmaps
826 to the color of the background brush */
827 if (GetObjectW( hbrush, sizeof(brush), &brush ))
829 if (brush.lbStyle == BS_SOLID)
830 SetBkColor(hdc, brush.lbColor);
832 GetClientRect(hwnd, &rcClient);
833 if (style & SS_CENTERIMAGE)
835 INT x, y;
836 x = (rcClient.right - rcClient.left)/2 - bm.bmWidth/2;
837 y = (rcClient.bottom - rcClient.top)/2 - bm.bmHeight/2;
838 FillRect( hdc, &rcClient, hbrush );
839 BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
840 SRCCOPY);
842 else
844 StretchBlt(hdc, 0, 0, rcClient.right - rcClient.left,
845 rcClient.bottom - rcClient.top, hMemDC,
846 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
848 SelectObject(hMemDC, oldbitmap);
849 DeleteDC(hMemDC);
854 static void STATIC_PaintEnhMetafn(HWND hwnd, HDC hdc, DWORD style )
856 HENHMETAFILE hEnhMetaFile;
857 RECT rc;
858 HBRUSH hbrush;
860 GetClientRect(hwnd, &rc);
861 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
862 FillRect(hdc, &rc, hbrush);
863 if ((hEnhMetaFile = (HENHMETAFILE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
865 /* The control's current font is not selected into the
866 device context! */
867 if (GetObjectType(hEnhMetaFile) == OBJ_ENHMETAFILE)
868 PlayEnhMetaFile(hdc, hEnhMetaFile, &rc);
873 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
875 RECT rc;
877 /* FIXME: sometimes (not always) sends WM_CTLCOLORSTATIC */
878 GetClientRect( hwnd, &rc );
879 switch (style & SS_TYPEMASK)
881 case SS_ETCHEDHORZ:
882 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
883 break;
884 case SS_ETCHEDVERT:
885 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
886 break;
887 case SS_ETCHEDFRAME:
888 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
889 break;