user32: Simplify window procedure allocation for the builtin classes.
[wine/hacks.git] / dlls / user32 / static.c
blob2ed3b75ae72db0fbd0523bb0969ab99239cbe935
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 WINPROC_STATIC, /* proc */
106 STATIC_EXTRA_BYTES, /* extra */
107 IDC_ARROW, /* cursor */
108 0 /* brush */
111 static void setup_clipping(HWND hwnd, HDC hdc, HRGN *orig)
113 RECT rc;
114 HRGN hrgn;
116 /* Native control has always a clipping region set (this may be because
117 * builtin controls uses CS_PARENTDC) and an application depends on it
119 hrgn = CreateRectRgn(0, 0, 1, 1);
120 if (GetClipRgn(hdc, hrgn) != 1)
122 DeleteObject(hrgn);
123 *orig = NULL;
124 } else
125 *orig = hrgn;
127 GetClientRect(hwnd, &rc);
128 DPtoLP(hdc, (POINT *)&rc, 2);
129 IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom);
132 static void restore_clipping(HDC hdc, HRGN hrgn)
134 SelectClipRgn(hdc, hrgn);
135 if (hrgn != NULL)
136 DeleteObject(hrgn);
139 /***********************************************************************
140 * STATIC_SetIcon
142 * Set the icon for an SS_ICON control.
144 static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
146 HICON prevIcon;
147 SIZE size;
149 if ((style & SS_TYPEMASK) != SS_ICON) return 0;
150 if (hicon && !get_icon_size( hicon, &size ))
152 WARN("hicon != 0, but invalid\n");
153 return 0;
155 prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
156 if (hicon && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
158 /* Windows currently doesn't implement SS_RIGHTJUST */
160 if ((style & SS_RIGHTJUST) != 0)
162 RECT wr;
163 GetWindowRect(hwnd, &wr);
164 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
165 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
167 else */
169 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
172 return prevIcon;
175 /***********************************************************************
176 * STATIC_SetBitmap
178 * Set the bitmap for an SS_BITMAP control.
180 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
182 HBITMAP hOldBitmap;
184 if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
185 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
186 WARN("hBitmap != 0, but it's not a bitmap\n");
187 return 0;
189 hOldBitmap = (HBITMAP)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hBitmap );
190 if (hBitmap && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
192 BITMAP bm;
193 GetObjectW(hBitmap, sizeof(bm), &bm);
194 /* Windows currently doesn't implement SS_RIGHTJUST */
196 if ((style & SS_RIGHTJUST) != 0)
198 RECT wr;
199 GetWindowRect(hwnd, &wr);
200 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
201 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
203 else */
205 SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
206 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
210 return hOldBitmap;
213 /***********************************************************************
214 * STATIC_SetEnhMetaFile
216 * Set the enhanced metafile for an SS_ENHMETAFILE control.
218 static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
220 if ((style & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
221 if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE) {
222 WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
223 return 0;
225 return (HENHMETAFILE)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hEnhMetaFile );
228 /***********************************************************************
229 * STATIC_GetImage
231 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
232 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
234 static HANDLE STATIC_GetImage( HWND hwnd, WPARAM wParam, DWORD style )
236 switch(style & SS_TYPEMASK)
238 case SS_ICON:
239 if ((wParam != IMAGE_ICON) &&
240 (wParam != IMAGE_CURSOR)) return NULL;
241 break;
242 case SS_BITMAP:
243 if (wParam != IMAGE_BITMAP) return NULL;
244 break;
245 case SS_ENHMETAFILE:
246 if (wParam != IMAGE_ENHMETAFILE) return NULL;
247 break;
248 default:
249 return NULL;
251 return (HANDLE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
254 /***********************************************************************
255 * STATIC_LoadIconA
257 * Load the icon for an SS_ICON control.
259 static HICON STATIC_LoadIconA( HWND hwnd, LPCSTR name, DWORD style )
261 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
262 if ((style & SS_REALSIZEIMAGE) != 0)
264 return LoadImageA(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
266 else
268 HICON hicon = LoadIconA( hInstance, name );
269 if (!hicon) hicon = LoadCursorA( hInstance, name );
270 if (!hicon) hicon = LoadIconA( 0, name );
271 /* Windows doesn't try to load a standard cursor,
272 probably because most IDs for standard cursors conflict
273 with the IDs for standard icons anyway */
274 return hicon;
278 /***********************************************************************
279 * STATIC_LoadIconW
281 * Load the icon for an SS_ICON control.
283 static HICON STATIC_LoadIconW( HWND hwnd, LPCWSTR name, DWORD style )
285 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
286 if ((style & SS_REALSIZEIMAGE) != 0)
288 return LoadImageW(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
290 else
292 HICON hicon = LoadIconW( hInstance, name );
293 if (!hicon) hicon = LoadCursorW( hInstance, name );
294 if (!hicon) hicon = LoadIconW( 0, name );
295 /* Windows doesn't try to load a standard cursor,
296 probably because most IDs for standard cursors conflict
297 with the IDs for standard icons anyway */
298 return hicon;
302 /***********************************************************************
303 * STATIC_LoadBitmapA
305 * Load the bitmap for an SS_BITMAP control.
307 static HBITMAP STATIC_LoadBitmapA( HWND hwnd, LPCSTR name )
309 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
310 /* Windows doesn't try to load OEM Bitmaps (hInstance == NULL) */
311 return LoadBitmapA( hInstance, name );
314 /***********************************************************************
315 * STATIC_LoadBitmapW
317 * Load the bitmap for an SS_BITMAP control.
319 static HBITMAP STATIC_LoadBitmapW( HWND hwnd, LPCWSTR name )
321 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
322 /* Windows doesn't try to load OEM Bitmaps (hInstance == NULL) */
323 return LoadBitmapW( hInstance, name );
326 /***********************************************************************
327 * STATIC_TryPaintFcn
329 * Try to immediately paint the control.
331 static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
333 LONG style = full_style & SS_TYPEMASK;
334 RECT rc;
336 GetClientRect( hwnd, &rc );
337 if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
339 HDC hdc;
340 HRGN hOrigClipping;
342 hdc = GetDC( hwnd );
343 setup_clipping(hwnd, hdc, &hOrigClipping);
344 (staticPaintFunc[style])( hwnd, hdc, full_style );
345 restore_clipping(hdc, hOrigClipping);
346 ReleaseDC( hwnd, hdc );
350 static HBRUSH STATIC_SendWmCtlColorStatic(HWND hwnd, HDC hdc)
352 HBRUSH hBrush;
353 HWND parent = GetParent(hwnd);
355 if (!parent) parent = hwnd;
356 hBrush = (HBRUSH) SendMessageW( parent,
357 WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
358 if (!hBrush) /* did the app forget to call DefWindowProc ? */
360 /* FIXME: DefWindowProc should return different colors if a
361 manifest is present */
362 hBrush = (HBRUSH)DefWindowProcW( parent, WM_CTLCOLORSTATIC,
363 (WPARAM)hdc, (LPARAM)hwnd);
365 return hBrush;
368 static VOID STATIC_InitColours(void)
370 color_3ddkshadow = GetSysColor(COLOR_3DDKSHADOW);
371 color_3dshadow = GetSysColor(COLOR_3DSHADOW);
372 color_3dhighlight = GetSysColor(COLOR_3DHIGHLIGHT);
375 /***********************************************************************
376 * hasTextStyle
378 * Tests if the control displays text.
380 static BOOL hasTextStyle( DWORD style )
382 switch(style & SS_TYPEMASK)
384 case SS_SIMPLE:
385 case SS_LEFT:
386 case SS_LEFTNOWORDWRAP:
387 case SS_CENTER:
388 case SS_RIGHT:
389 case SS_OWNERDRAW:
390 return TRUE;
393 return FALSE;
396 /***********************************************************************
397 * StaticWndProc_common
399 LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL unicode )
401 LRESULT lResult = 0;
402 LONG full_style = GetWindowLongW( hwnd, GWL_STYLE );
403 LONG style = full_style & SS_TYPEMASK;
405 if (!IsWindow( hwnd )) return 0;
407 switch (uMsg)
409 case WM_CREATE:
410 if (style < 0L || style > SS_TYPEMASK)
412 ERR("Unknown style 0x%02x\n", style );
413 return -1;
415 STATIC_InitColours();
416 break;
418 case WM_NCDESTROY:
419 if (style == SS_ICON) {
421 * FIXME
422 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
424 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
425 * had already been loaded by the application the last thing we want to do is
426 * GlobalFree16 the handle.
428 break;
430 else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
431 DefWindowProcA(hwnd, uMsg, wParam, lParam);
433 case WM_ERASEBKGND:
434 /* do all painting in WM_PAINT like Windows does */
435 return 1;
437 case WM_PRINTCLIENT:
438 case WM_PAINT:
440 PAINTSTRUCT ps;
441 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
442 if (staticPaintFunc[style])
444 HRGN hOrigClipping;
445 setup_clipping(hwnd, hdc, &hOrigClipping);
446 (staticPaintFunc[style])( hwnd, hdc, full_style );
447 restore_clipping(hdc, hOrigClipping);
449 if (!wParam) EndPaint(hwnd, &ps);
451 break;
453 case WM_ENABLE:
454 STATIC_TryPaintFcn( hwnd, full_style );
455 if (full_style & SS_NOTIFY) {
456 if (wParam) {
457 SendMessageW( GetParent(hwnd), WM_COMMAND,
458 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_ENABLE ), (LPARAM)hwnd);
460 else {
461 SendMessageW( GetParent(hwnd), WM_COMMAND,
462 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DISABLE ), (LPARAM)hwnd);
465 break;
467 case WM_SYSCOLORCHANGE:
468 STATIC_InitColours();
469 STATIC_TryPaintFcn( hwnd, full_style );
470 break;
472 case WM_NCCREATE:
474 LPCSTR textA;
475 LPCWSTR textW;
477 if (full_style & SS_SUNKEN)
478 SetWindowLongW( hwnd, GWL_EXSTYLE,
479 GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
481 if(unicode)
483 textA = NULL;
484 textW = ((LPCREATESTRUCTW)lParam)->lpszName;
486 else
488 textA = ((LPCREATESTRUCTA)lParam)->lpszName;
489 textW = NULL;
492 switch (style) {
493 case SS_ICON:
495 HICON hIcon;
496 if(unicode)
497 hIcon = STATIC_LoadIconW(hwnd, textW, full_style);
498 else
499 hIcon = STATIC_LoadIconA(hwnd, textA, full_style);
500 STATIC_SetIcon(hwnd, hIcon, full_style);
502 break;
503 case SS_BITMAP:
505 HBITMAP hBitmap;
506 if(unicode)
507 hBitmap = STATIC_LoadBitmapW(hwnd, textW);
508 else
509 hBitmap = STATIC_LoadBitmapA(hwnd, textA);
510 STATIC_SetBitmap(hwnd, hBitmap, full_style);
512 break;
514 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
515 the enhanced metafile that was specified as the window text. */
517 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
518 DefWindowProcA(hwnd, uMsg, wParam, lParam);
520 case WM_SETTEXT:
521 if (hasTextStyle( full_style ))
523 if (HIWORD(lParam))
525 if(unicode)
526 lResult = DefWindowProcW( hwnd, uMsg, wParam, lParam );
527 else
528 lResult = DefWindowProcA( hwnd, uMsg, wParam, lParam );
529 STATIC_TryPaintFcn( hwnd, full_style );
532 break;
534 case WM_SETFONT:
535 if (hasTextStyle( full_style ))
537 SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, wParam );
538 if (LOWORD(lParam))
539 RedrawWindow( hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
541 break;
543 case WM_GETFONT:
544 return GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
546 case WM_NCHITTEST:
547 if (full_style & SS_NOTIFY)
548 return HTCLIENT;
549 else
550 return HTTRANSPARENT;
552 case WM_GETDLGCODE:
553 return DLGC_STATIC;
555 case WM_LBUTTONDOWN:
556 case WM_NCLBUTTONDOWN:
557 if (full_style & SS_NOTIFY)
558 SendMessageW( GetParent(hwnd), WM_COMMAND,
559 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_CLICKED ), (LPARAM)hwnd);
560 return 0;
562 case WM_LBUTTONDBLCLK:
563 case WM_NCLBUTTONDBLCLK:
564 if (full_style & SS_NOTIFY)
565 SendMessageW( GetParent(hwnd), WM_COMMAND,
566 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DBLCLK ), (LPARAM)hwnd);
567 return 0;
569 case STM_GETIMAGE:
570 return (LRESULT)STATIC_GetImage( hwnd, wParam, full_style );
572 case STM_GETICON:
573 return (LRESULT)STATIC_GetImage( hwnd, IMAGE_ICON, full_style );
575 case STM_SETIMAGE:
576 switch(wParam) {
577 case IMAGE_BITMAP:
578 lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
579 break;
580 case IMAGE_ENHMETAFILE:
581 lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
582 break;
583 case IMAGE_ICON:
584 case IMAGE_CURSOR:
585 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
586 break;
587 default:
588 FIXME("STM_SETIMAGE: Unhandled type %lx\n", wParam);
589 break;
591 STATIC_TryPaintFcn( hwnd, full_style );
592 break;
594 case STM_SETICON:
595 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
596 STATIC_TryPaintFcn( hwnd, full_style );
597 break;
599 default:
600 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
601 DefWindowProcA(hwnd, uMsg, wParam, lParam);
603 return lResult;
606 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
608 DRAWITEMSTRUCT dis;
609 HFONT font, oldFont = NULL;
610 UINT id = (UINT)GetWindowLongPtrW( hwnd, GWLP_ID );
612 dis.CtlType = ODT_STATIC;
613 dis.CtlID = id;
614 dis.itemID = 0;
615 dis.itemAction = ODA_DRAWENTIRE;
616 dis.itemState = IsWindowEnabled(hwnd) ? 0 : ODS_DISABLED;
617 dis.hwndItem = hwnd;
618 dis.hDC = hdc;
619 dis.itemData = 0;
620 GetClientRect( hwnd, &dis.rcItem );
622 font = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
623 if (font) oldFont = SelectObject( hdc, font );
624 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
625 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
626 if (font) SelectObject( hdc, oldFont );
629 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
631 RECT rc;
632 HBRUSH hBrush;
633 HFONT hFont, hOldFont = NULL;
634 WORD wFormat;
635 INT len, buf_size;
636 WCHAR *text;
638 GetClientRect( hwnd, &rc);
640 switch (style & SS_TYPEMASK)
642 case SS_LEFT:
643 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
644 break;
646 case SS_CENTER:
647 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
648 break;
650 case SS_RIGHT:
651 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
652 break;
654 case SS_SIMPLE:
655 wFormat = DT_LEFT | DT_SINGLELINE;
656 break;
658 case SS_LEFTNOWORDWRAP:
659 wFormat = DT_LEFT | DT_EXPANDTABS;
660 break;
662 default:
663 return;
666 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_RIGHT)
667 wFormat = DT_RIGHT | (wFormat & ~(DT_LEFT | DT_CENTER));
669 if (style & SS_NOPREFIX)
670 wFormat |= DT_NOPREFIX;
672 if ((style & SS_TYPEMASK) != SS_SIMPLE)
674 if (style & SS_CENTERIMAGE)
675 wFormat |= DT_SINGLELINE | DT_VCENTER;
676 if (style & SS_EDITCONTROL)
677 wFormat |= DT_EDITCONTROL;
678 if (style & SS_ENDELLIPSIS)
679 wFormat |= DT_SINGLELINE | DT_END_ELLIPSIS;
680 if (style & SS_PATHELLIPSIS)
681 wFormat |= DT_SINGLELINE | DT_PATH_ELLIPSIS;
682 if (style & SS_WORDELLIPSIS)
683 wFormat |= DT_SINGLELINE | DT_WORD_ELLIPSIS;
686 if ((hFont = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET )))
687 hOldFont = SelectObject( hdc, hFont );
689 /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
690 brush is not used */
691 hBrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
693 if ((style & SS_TYPEMASK) != SS_SIMPLE)
695 FillRect( hdc, &rc, hBrush );
696 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
699 buf_size = 256;
700 if (!(text = HeapAlloc( GetProcessHeap(), 0, buf_size * sizeof(WCHAR) )))
701 goto no_TextOut;
703 while ((len = InternalGetWindowText( hwnd, text, buf_size )) == buf_size - 1)
705 buf_size *= 2;
706 if (!(text = HeapReAlloc( GetProcessHeap(), 0, text, buf_size * sizeof(WCHAR) )))
707 goto no_TextOut;
710 if (!len) goto no_TextOut;
712 if (((style & SS_TYPEMASK) == SS_SIMPLE) && (style & SS_NOPREFIX))
714 /* Windows uses the faster ExtTextOut() to draw the text and
715 to paint the whole client rectangle with the text background
716 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
717 ExtTextOutW( hdc, rc.left, rc.top, ETO_CLIPPED | ETO_OPAQUE,
718 &rc, text, len, NULL );
720 else
722 DrawTextW( hdc, text, -1, &rc, wFormat );
725 no_TextOut:
726 HeapFree( GetProcessHeap(), 0, text );
728 if (hFont)
729 SelectObject( hdc, hOldFont );
732 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
734 RECT rc;
735 HBRUSH hBrush;
737 GetClientRect( hwnd, &rc);
739 /* FIXME: send WM_CTLCOLORSTATIC */
740 switch (style & SS_TYPEMASK)
742 case SS_BLACKRECT:
743 hBrush = CreateSolidBrush(color_3ddkshadow);
744 FillRect( hdc, &rc, hBrush );
745 break;
746 case SS_GRAYRECT:
747 hBrush = CreateSolidBrush(color_3dshadow);
748 FillRect( hdc, &rc, hBrush );
749 break;
750 case SS_WHITERECT:
751 hBrush = CreateSolidBrush(color_3dhighlight);
752 FillRect( hdc, &rc, hBrush );
753 break;
754 case SS_BLACKFRAME:
755 hBrush = CreateSolidBrush(color_3ddkshadow);
756 FrameRect( hdc, &rc, hBrush );
757 break;
758 case SS_GRAYFRAME:
759 hBrush = CreateSolidBrush(color_3dshadow);
760 FrameRect( hdc, &rc, hBrush );
761 break;
762 case SS_WHITEFRAME:
763 hBrush = CreateSolidBrush(color_3dhighlight);
764 FrameRect( hdc, &rc, hBrush );
765 break;
766 default:
767 return;
769 DeleteObject( hBrush );
773 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
775 RECT rc, iconRect;
776 HBRUSH hbrush;
777 HICON hIcon;
778 SIZE size;
780 GetClientRect( hwnd, &rc );
781 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
782 hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
783 if (!hIcon || !get_icon_size( hIcon, &size ))
785 FillRect(hdc, &rc, hbrush);
787 else
789 if (style & SS_CENTERIMAGE)
791 iconRect.left = (rc.right - rc.left) / 2 - size.cx / 2;
792 iconRect.top = (rc.bottom - rc.top) / 2 - size.cy / 2;
793 iconRect.right = iconRect.left + size.cx;
794 iconRect.bottom = iconRect.top + size.cy;
796 else
797 iconRect = rc;
798 FillRect( hdc, &rc, hbrush );
799 DrawIconEx( hdc, iconRect.left, iconRect.top, hIcon, iconRect.right - iconRect.left,
800 iconRect.bottom - iconRect.top, 0, NULL, DI_NORMAL );
804 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
806 HDC hMemDC;
807 HBITMAP hBitmap, oldbitmap;
808 HBRUSH hbrush;
810 /* message is still sent, even if the returned brush is not used */
811 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
813 if ((hBitmap = (HBITMAP)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET ))
814 && (GetObjectType(hBitmap) == OBJ_BITMAP)
815 && (hMemDC = CreateCompatibleDC( hdc )))
817 BITMAP bm;
818 RECT rcClient;
819 LOGBRUSH brush;
821 GetObjectW(hBitmap, sizeof(bm), &bm);
822 oldbitmap = SelectObject(hMemDC, hBitmap);
824 /* Set the background color for monochrome bitmaps
825 to the color of the background brush */
826 if (GetObjectW( hbrush, sizeof(brush), &brush ))
828 if (brush.lbStyle == BS_SOLID)
829 SetBkColor(hdc, brush.lbColor);
831 GetClientRect(hwnd, &rcClient);
832 if (style & SS_CENTERIMAGE)
834 INT x, y;
835 x = (rcClient.right - rcClient.left)/2 - bm.bmWidth/2;
836 y = (rcClient.bottom - rcClient.top)/2 - bm.bmHeight/2;
837 FillRect( hdc, &rcClient, hbrush );
838 BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
839 SRCCOPY);
841 else
843 StretchBlt(hdc, 0, 0, rcClient.right - rcClient.left,
844 rcClient.bottom - rcClient.top, hMemDC,
845 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
847 SelectObject(hMemDC, oldbitmap);
848 DeleteDC(hMemDC);
853 static void STATIC_PaintEnhMetafn(HWND hwnd, HDC hdc, DWORD style )
855 HENHMETAFILE hEnhMetaFile;
856 RECT rc;
857 HBRUSH hbrush;
859 GetClientRect(hwnd, &rc);
860 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
861 FillRect(hdc, &rc, hbrush);
862 if ((hEnhMetaFile = (HENHMETAFILE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
864 /* The control's current font is not selected into the
865 device context! */
866 if (GetObjectType(hEnhMetaFile) == OBJ_ENHMETAFILE)
867 PlayEnhMetaFile(hdc, hEnhMetaFile, &rc);
872 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
874 RECT rc;
876 /* FIXME: sometimes (not always) sends WM_CTLCOLORSTATIC */
877 GetClientRect( hwnd, &rc );
878 switch (style & SS_TYPEMASK)
880 case SS_ETCHEDHORZ:
881 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
882 break;
883 case SS_ETCHEDVERT:
884 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
885 break;
886 case SS_ETCHEDFRAME:
887 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
888 break;