push 83f6eeab4f78cf34cba36fe6c2150f9c23ec0aba
[wine/hacks.git] / dlls / user32 / static.c
blobbb6abfb0524b29d436626212d7546e82c90e229d
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 "wine/winuser16.h"
51 #include "controls.h"
52 #include "user_private.h"
53 #include "wine/debug.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(static);
57 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style );
58 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style );
59 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style );
60 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style );
61 static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc, DWORD style );
62 static void STATIC_PaintEnhMetafn( HWND hwnd, HDC hdc, DWORD style );
63 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style );
64 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
65 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
67 static COLORREF color_3dshadow, color_3ddkshadow, color_3dhighlight;
69 /* offsets for GetWindowLong for static private information */
70 #define HFONT_GWL_OFFSET 0
71 #define HICON_GWL_OFFSET (sizeof(HFONT))
72 #define STATIC_EXTRA_BYTES (HICON_GWL_OFFSET + sizeof(HICON))
74 typedef void (*pfPaint)( HWND hwnd, HDC hdc, DWORD style );
76 static const pfPaint staticPaintFunc[SS_TYPEMASK+1] =
78 STATIC_PaintTextfn, /* SS_LEFT */
79 STATIC_PaintTextfn, /* SS_CENTER */
80 STATIC_PaintTextfn, /* SS_RIGHT */
81 STATIC_PaintIconfn, /* SS_ICON */
82 STATIC_PaintRectfn, /* SS_BLACKRECT */
83 STATIC_PaintRectfn, /* SS_GRAYRECT */
84 STATIC_PaintRectfn, /* SS_WHITERECT */
85 STATIC_PaintRectfn, /* SS_BLACKFRAME */
86 STATIC_PaintRectfn, /* SS_GRAYFRAME */
87 STATIC_PaintRectfn, /* SS_WHITEFRAME */
88 NULL, /* SS_USERITEM */
89 STATIC_PaintTextfn, /* SS_SIMPLE */
90 STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
91 STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
92 STATIC_PaintBitmapfn, /* SS_BITMAP */
93 STATIC_PaintEnhMetafn, /* SS_ENHMETAFILE */
94 STATIC_PaintEtchedfn, /* SS_ETCHEDHORZ */
95 STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
96 STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
100 /*********************************************************************
101 * static class descriptor
103 const struct builtin_class_descr STATIC_builtin_class =
105 "Static", /* name */
106 CS_DBLCLKS | CS_PARENTDC, /* style */
107 StaticWndProcA, /* procA */
108 StaticWndProcW, /* procW */
109 STATIC_EXTRA_BYTES, /* extra */
110 IDC_ARROW, /* cursor */
111 0 /* brush */
114 static void setup_clipping(HWND hwnd, HDC hdc, HRGN *orig)
116 RECT rc;
117 HRGN hrgn;
119 /* Native control has always a clipping region set (this may be because
120 * builtin controls uses CS_PARENTDC) and an application depends on it
122 hrgn = CreateRectRgn(0, 0, 1, 1);
123 if (GetClipRgn(hdc, hrgn) != 1)
125 DeleteObject(hrgn);
126 *orig = NULL;
127 } else
128 *orig = hrgn;
130 GetClientRect(hwnd, &rc);
131 DPtoLP(hdc, (POINT *)&rc, 2);
132 IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom);
135 static void restore_clipping(HDC hdc, HRGN hrgn)
137 SelectClipRgn(hdc, hrgn);
138 if (hrgn != NULL)
139 DeleteObject(hrgn);
142 /***********************************************************************
143 * STATIC_SetIcon
145 * Set the icon for an SS_ICON control.
147 static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
149 HICON prevIcon;
150 CURSORICONINFO * info;
152 if ((style & SS_TYPEMASK) != SS_ICON) return 0;
153 info = hicon?(CURSORICONINFO *) GlobalLock16(HICON_16(hicon)):NULL;
154 if (hicon && !info) {
155 WARN("hicon != 0, but info == 0\n");
156 return 0;
158 prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
159 if (hicon && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
161 /* Windows currently doesn't implement SS_RIGHTJUST */
163 if ((style & SS_RIGHTJUST) != 0)
165 RECT wr;
166 GetWindowRect(hwnd, &wr);
167 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
168 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
170 else */
172 SetWindowPos( hwnd, 0, 0, 0, info->nWidth, info->nHeight,
173 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
176 if (info) GlobalUnlock16(HICON_16(hicon));
177 return prevIcon;
180 /***********************************************************************
181 * STATIC_SetBitmap
183 * Set the bitmap for an SS_BITMAP control.
185 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
187 HBITMAP hOldBitmap;
189 if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
190 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
191 WARN("hBitmap != 0, but it's not a bitmap\n");
192 return 0;
194 hOldBitmap = (HBITMAP)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hBitmap );
195 if (hBitmap && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
197 BITMAP bm;
198 GetObjectW(hBitmap, sizeof(bm), &bm);
199 /* Windows currently doesn't implement SS_RIGHTJUST */
201 if ((style & SS_RIGHTJUST) != 0)
203 RECT wr;
204 GetWindowRect(hwnd, &wr);
205 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
206 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
208 else */
210 SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
211 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
215 return hOldBitmap;
218 /***********************************************************************
219 * STATIC_SetEnhMetaFile
221 * Set the enhanced metafile for an SS_ENHMETAFILE control.
223 static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
225 if ((style & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
226 if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE) {
227 WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
228 return 0;
230 return (HENHMETAFILE)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hEnhMetaFile );
233 /***********************************************************************
234 * STATIC_GetImage
236 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
237 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
239 static HANDLE STATIC_GetImage( HWND hwnd, WPARAM wParam, DWORD style )
241 switch(style & SS_TYPEMASK)
243 case SS_ICON:
244 if ((wParam != IMAGE_ICON) &&
245 (wParam != IMAGE_CURSOR)) return NULL;
246 break;
247 case SS_BITMAP:
248 if (wParam != IMAGE_BITMAP) return NULL;
249 break;
250 case SS_ENHMETAFILE:
251 if (wParam != IMAGE_ENHMETAFILE) return NULL;
252 break;
253 default:
254 return NULL;
256 return (HANDLE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
259 /***********************************************************************
260 * STATIC_LoadIconA
262 * Load the icon for an SS_ICON control.
264 static HICON STATIC_LoadIconA( HWND hwnd, LPCSTR name, DWORD style )
266 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
267 if ((style & SS_REALSIZEIMAGE) != 0)
269 return LoadImageA(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
271 else
273 HICON hicon = LoadIconA( hInstance, name );
274 if (!hicon) hicon = LoadCursorA( hInstance, name );
275 if (!hicon) hicon = LoadIconA( 0, name );
276 /* Windows doesn't try to load a standard cursor,
277 probably because most IDs for standard cursors conflict
278 with the IDs for standard icons anyway */
279 return hicon;
283 /***********************************************************************
284 * STATIC_LoadIconW
286 * Load the icon for an SS_ICON control.
288 static HICON STATIC_LoadIconW( HWND hwnd, LPCWSTR name, DWORD style )
290 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
291 if ((style & SS_REALSIZEIMAGE) != 0)
293 return LoadImageW(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
295 else
297 HICON hicon = LoadIconW( hInstance, name );
298 if (!hicon) hicon = LoadCursorW( hInstance, name );
299 if (!hicon) hicon = LoadIconW( 0, name );
300 /* Windows doesn't try to load a standard cursor,
301 probably because most IDs for standard cursors conflict
302 with the IDs for standard icons anyway */
303 return hicon;
307 /***********************************************************************
308 * STATIC_LoadBitmapA
310 * Load the bitmap for an SS_BITMAP control.
312 static HBITMAP STATIC_LoadBitmapA( HWND hwnd, LPCSTR name )
314 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
315 /* Windows doesn't try to load OEM Bitmaps (hInstance == NULL) */
316 return LoadBitmapA( hInstance, name );
319 /***********************************************************************
320 * STATIC_LoadBitmapW
322 * Load the bitmap for an SS_BITMAP control.
324 static HBITMAP STATIC_LoadBitmapW( HWND hwnd, LPCWSTR name )
326 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
327 /* Windows doesn't try to load OEM Bitmaps (hInstance == NULL) */
328 return LoadBitmapW( hInstance, name );
331 /***********************************************************************
332 * STATIC_TryPaintFcn
334 * Try to immediately paint the control.
336 static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
338 LONG style = full_style & SS_TYPEMASK;
339 RECT rc;
341 GetClientRect( hwnd, &rc );
342 if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
344 HDC hdc;
345 HRGN hOrigClipping;
347 hdc = GetDC( hwnd );
348 setup_clipping(hwnd, hdc, &hOrigClipping);
349 (staticPaintFunc[style])( hwnd, hdc, full_style );
350 restore_clipping(hdc, hOrigClipping);
351 ReleaseDC( hwnd, hdc );
355 static HBRUSH STATIC_SendWmCtlColorStatic(HWND hwnd, HDC hdc)
357 HBRUSH hBrush;
358 HWND parent = GetParent(hwnd);
360 if (!parent) parent = hwnd;
361 hBrush = (HBRUSH) SendMessageW( parent,
362 WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
363 if (!hBrush) /* did the app forget to call DefWindowProc ? */
365 /* FIXME: DefWindowProc should return different colors if a
366 manifest is present */
367 hBrush = (HBRUSH)DefWindowProcW( parent, WM_CTLCOLORSTATIC,
368 (WPARAM)hdc, (LPARAM)hwnd);
370 return hBrush;
373 static VOID STATIC_InitColours(void)
375 color_3ddkshadow = GetSysColor(COLOR_3DDKSHADOW);
376 color_3dshadow = GetSysColor(COLOR_3DSHADOW);
377 color_3dhighlight = GetSysColor(COLOR_3DHIGHLIGHT);
380 /***********************************************************************
381 * hasTextStyle
383 * Tests if the control displays text.
385 static BOOL hasTextStyle( DWORD style )
387 switch(style & SS_TYPEMASK)
389 case SS_SIMPLE:
390 case SS_LEFT:
391 case SS_LEFTNOWORDWRAP:
392 case SS_CENTER:
393 case SS_RIGHT:
394 case SS_OWNERDRAW:
395 return TRUE;
398 return FALSE;
401 /***********************************************************************
402 * StaticWndProc_common
404 static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam,
405 LPARAM lParam, BOOL unicode )
407 LRESULT lResult = 0;
408 LONG full_style = GetWindowLongW( hwnd, GWL_STYLE );
409 LONG style = full_style & SS_TYPEMASK;
411 switch (uMsg)
413 case WM_CREATE:
414 if (style < 0L || style > SS_TYPEMASK)
416 ERR("Unknown style 0x%02x\n", style );
417 return -1;
419 STATIC_InitColours();
420 break;
422 case WM_NCDESTROY:
423 if (style == SS_ICON) {
425 * FIXME
426 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
428 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
429 * had already been loaded by the application the last thing we want to do is
430 * GlobalFree16 the handle.
432 break;
434 else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
435 DefWindowProcA(hwnd, uMsg, wParam, lParam);
437 case WM_ERASEBKGND:
438 /* do all painting in WM_PAINT like Windows does */
439 return 1;
441 case WM_PRINTCLIENT:
442 case WM_PAINT:
444 PAINTSTRUCT ps;
445 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
446 if (staticPaintFunc[style])
448 HRGN hOrigClipping;
449 setup_clipping(hwnd, hdc, &hOrigClipping);
450 (staticPaintFunc[style])( hwnd, hdc, full_style );
451 restore_clipping(hdc, hOrigClipping);
453 if (!wParam) EndPaint(hwnd, &ps);
455 break;
457 case WM_ENABLE:
458 STATIC_TryPaintFcn( hwnd, full_style );
459 if (full_style & SS_NOTIFY) {
460 if (wParam) {
461 SendMessageW( GetParent(hwnd), WM_COMMAND,
462 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_ENABLE ), (LPARAM)hwnd);
464 else {
465 SendMessageW( GetParent(hwnd), WM_COMMAND,
466 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DISABLE ), (LPARAM)hwnd);
469 break;
471 case WM_SYSCOLORCHANGE:
472 STATIC_InitColours();
473 STATIC_TryPaintFcn( hwnd, full_style );
474 break;
476 case WM_NCCREATE:
478 LPCSTR textA;
479 LPCWSTR textW;
481 if (full_style & SS_SUNKEN)
482 SetWindowLongW( hwnd, GWL_EXSTYLE,
483 GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
485 if(unicode)
487 textA = NULL;
488 textW = ((LPCREATESTRUCTW)lParam)->lpszName;
490 else
492 textA = ((LPCREATESTRUCTA)lParam)->lpszName;
493 textW = NULL;
496 switch (style) {
497 case SS_ICON:
499 HICON hIcon;
500 if(unicode)
501 hIcon = STATIC_LoadIconW(hwnd, textW, full_style);
502 else
503 hIcon = STATIC_LoadIconA(hwnd, textA, full_style);
504 STATIC_SetIcon(hwnd, hIcon, full_style);
506 break;
507 case SS_BITMAP:
509 HBITMAP hBitmap;
510 if(unicode)
511 hBitmap = STATIC_LoadBitmapW(hwnd, textW);
512 else
513 hBitmap = STATIC_LoadBitmapA(hwnd, textA);
514 STATIC_SetBitmap(hwnd, hBitmap, full_style);
516 break;
518 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
519 the enhanced metafile that was specified as the window text. */
521 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
522 DefWindowProcA(hwnd, uMsg, wParam, lParam);
524 case WM_SETTEXT:
525 if (hasTextStyle( full_style ))
527 if (HIWORD(lParam))
529 if(unicode)
530 lResult = DefWindowProcW( hwnd, uMsg, wParam, lParam );
531 else
532 lResult = DefWindowProcA( hwnd, uMsg, wParam, lParam );
533 STATIC_TryPaintFcn( hwnd, full_style );
536 break;
538 case WM_SETFONT:
539 if (hasTextStyle( full_style ))
541 SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, wParam );
542 if (LOWORD(lParam))
543 RedrawWindow( hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
545 break;
547 case WM_GETFONT:
548 return GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
550 case WM_NCHITTEST:
551 if (full_style & SS_NOTIFY)
552 return HTCLIENT;
553 else
554 return HTTRANSPARENT;
556 case WM_GETDLGCODE:
557 return DLGC_STATIC;
559 case WM_LBUTTONDOWN:
560 case WM_NCLBUTTONDOWN:
561 if (full_style & SS_NOTIFY)
562 SendMessageW( GetParent(hwnd), WM_COMMAND,
563 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_CLICKED ), (LPARAM)hwnd);
564 return 0;
566 case WM_LBUTTONDBLCLK:
567 case WM_NCLBUTTONDBLCLK:
568 if (full_style & SS_NOTIFY)
569 SendMessageW( GetParent(hwnd), WM_COMMAND,
570 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DBLCLK ), (LPARAM)hwnd);
571 return 0;
573 case STM_GETIMAGE:
574 return (LRESULT)STATIC_GetImage( hwnd, wParam, full_style );
576 case STM_GETICON16:
577 case STM_GETICON:
578 return (LRESULT)STATIC_GetImage( hwnd, IMAGE_ICON, full_style );
580 case STM_SETIMAGE:
581 switch(wParam) {
582 case IMAGE_BITMAP:
583 lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
584 break;
585 case IMAGE_ENHMETAFILE:
586 lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
587 break;
588 case IMAGE_ICON:
589 case IMAGE_CURSOR:
590 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
591 break;
592 default:
593 FIXME("STM_SETIMAGE: Unhandled type %lx\n", wParam);
594 break;
596 STATIC_TryPaintFcn( hwnd, full_style );
597 break;
599 case STM_SETICON16:
600 case STM_SETICON:
601 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
602 STATIC_TryPaintFcn( hwnd, full_style );
603 break;
605 default:
606 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
607 DefWindowProcA(hwnd, uMsg, wParam, lParam);
609 return lResult;
612 /***********************************************************************
613 * StaticWndProcA
615 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
617 if (!IsWindow( hWnd )) return 0;
618 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, FALSE);
621 /***********************************************************************
622 * StaticWndProcW
624 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
626 if (!IsWindow( hWnd )) return 0;
627 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, TRUE);
630 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
632 DRAWITEMSTRUCT dis;
633 HFONT font, oldFont = NULL;
634 UINT id = (UINT)GetWindowLongPtrW( hwnd, GWLP_ID );
636 dis.CtlType = ODT_STATIC;
637 dis.CtlID = id;
638 dis.itemID = 0;
639 dis.itemAction = ODA_DRAWENTIRE;
640 dis.itemState = IsWindowEnabled(hwnd) ? 0 : ODS_DISABLED;
641 dis.hwndItem = hwnd;
642 dis.hDC = hdc;
643 dis.itemData = 0;
644 GetClientRect( hwnd, &dis.rcItem );
646 font = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
647 if (font) oldFont = SelectObject( hdc, font );
648 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
649 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
650 if (font) SelectObject( hdc, oldFont );
653 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
655 RECT rc;
656 HBRUSH hBrush;
657 HFONT hFont, hOldFont = NULL;
658 WORD wFormat;
659 INT len, buf_size;
660 WCHAR *text;
662 GetClientRect( hwnd, &rc);
664 switch (style & SS_TYPEMASK)
666 case SS_LEFT:
667 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
668 break;
670 case SS_CENTER:
671 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
672 break;
674 case SS_RIGHT:
675 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
676 break;
678 case SS_SIMPLE:
679 wFormat = DT_LEFT | DT_SINGLELINE;
680 break;
682 case SS_LEFTNOWORDWRAP:
683 wFormat = DT_LEFT | DT_EXPANDTABS;
684 break;
686 default:
687 return;
690 if (style & SS_NOPREFIX)
691 wFormat |= DT_NOPREFIX;
693 if ((style & SS_TYPEMASK) != SS_SIMPLE)
695 if (style & SS_CENTERIMAGE)
696 wFormat |= DT_SINGLELINE | DT_VCENTER;
697 if (style & SS_EDITCONTROL)
698 wFormat |= DT_EDITCONTROL;
699 if (style & SS_ENDELLIPSIS)
700 wFormat |= DT_SINGLELINE | DT_END_ELLIPSIS;
701 if (style & SS_PATHELLIPSIS)
702 wFormat |= DT_SINGLELINE | DT_PATH_ELLIPSIS;
703 if (style & SS_WORDELLIPSIS)
704 wFormat |= DT_SINGLELINE | DT_WORD_ELLIPSIS;
707 if ((hFont = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET )))
708 hOldFont = (HFONT)SelectObject( hdc, hFont );
710 /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
711 brush is not used */
712 hBrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
714 if ((style & SS_TYPEMASK) != SS_SIMPLE)
716 FillRect( hdc, &rc, hBrush );
717 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
720 buf_size = 256;
721 if (!(text = HeapAlloc( GetProcessHeap(), 0, buf_size * sizeof(WCHAR) )))
722 goto no_TextOut;
724 while ((len = InternalGetWindowText( hwnd, text, buf_size )) == buf_size - 1)
726 buf_size *= 2;
727 if (!(text = HeapReAlloc( GetProcessHeap(), 0, text, buf_size * sizeof(WCHAR) )))
728 goto no_TextOut;
731 if (!len) goto no_TextOut;
733 if (((style & SS_TYPEMASK) == SS_SIMPLE) && (style & SS_NOPREFIX))
735 /* Windows uses the faster ExtTextOut() to draw the text and
736 to paint the whole client rectangle with the text background
737 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
738 ExtTextOutW( hdc, rc.left, rc.top, ETO_CLIPPED | ETO_OPAQUE,
739 &rc, text, len, NULL );
741 else
743 DrawTextW( hdc, text, -1, &rc, wFormat );
746 no_TextOut:
747 HeapFree( GetProcessHeap(), 0, text );
749 if (hFont)
750 SelectObject( hdc, hOldFont );
753 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
755 RECT rc;
756 HBRUSH hBrush;
758 GetClientRect( hwnd, &rc);
760 /* FIXME: send WM_CTLCOLORSTATIC */
761 switch (style & SS_TYPEMASK)
763 case SS_BLACKRECT:
764 hBrush = CreateSolidBrush(color_3ddkshadow);
765 FillRect( hdc, &rc, hBrush );
766 break;
767 case SS_GRAYRECT:
768 hBrush = CreateSolidBrush(color_3dshadow);
769 FillRect( hdc, &rc, hBrush );
770 break;
771 case SS_WHITERECT:
772 hBrush = CreateSolidBrush(color_3dhighlight);
773 FillRect( hdc, &rc, hBrush );
774 break;
775 case SS_BLACKFRAME:
776 hBrush = CreateSolidBrush(color_3ddkshadow);
777 FrameRect( hdc, &rc, hBrush );
778 break;
779 case SS_GRAYFRAME:
780 hBrush = CreateSolidBrush(color_3dshadow);
781 FrameRect( hdc, &rc, hBrush );
782 break;
783 case SS_WHITEFRAME:
784 hBrush = CreateSolidBrush(color_3dhighlight);
785 FrameRect( hdc, &rc, hBrush );
786 break;
787 default:
788 return;
790 DeleteObject( hBrush );
794 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
796 RECT rc, iconRect;
797 HBRUSH hbrush;
798 HICON hIcon;
799 CURSORICONINFO * info;
801 GetClientRect( hwnd, &rc );
802 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
803 hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
804 info = hIcon ? (CURSORICONINFO *)GlobalLock16(HICON_16(hIcon)) : NULL;
805 if (!hIcon || !info)
807 FillRect(hdc, &rc, hbrush);
809 else
811 if (style & SS_CENTERIMAGE)
813 iconRect.left = (rc.right - rc.left) / 2 - info->nWidth / 2;
814 iconRect.top = (rc.bottom - rc.top) / 2 - info->nHeight / 2;
815 iconRect.right = iconRect.left + info->nWidth;
816 iconRect.bottom = iconRect.top + info->nHeight;
818 else
819 iconRect = rc;
820 FillRect( hdc, &rc, hbrush );
821 DrawIconEx( hdc, iconRect.left, iconRect.top, hIcon, iconRect.right - iconRect.left,
822 iconRect.bottom - iconRect.top, 0, NULL, DI_NORMAL );
824 if (info) GlobalUnlock16(HICON_16(hIcon));
827 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
829 HDC hMemDC;
830 HBITMAP hBitmap, oldbitmap;
831 HBRUSH hbrush;
833 /* message is still sent, even if the returned brush is not used */
834 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
836 if ((hBitmap = (HBITMAP)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET ))
837 && (GetObjectType(hBitmap) == OBJ_BITMAP)
838 && (hMemDC = CreateCompatibleDC( hdc )))
840 BITMAP bm;
841 RECT rcClient;
842 LOGBRUSH brush;
844 GetObjectW(hBitmap, sizeof(bm), &bm);
845 oldbitmap = SelectObject(hMemDC, hBitmap);
847 /* Set the background color for monochrome bitmaps
848 to the color of the background brush */
849 if (GetObjectW( hbrush, sizeof(brush), &brush ))
851 if (brush.lbStyle == BS_SOLID)
852 SetBkColor(hdc, brush.lbColor);
854 GetClientRect(hwnd, &rcClient);
855 if (style & SS_CENTERIMAGE)
857 INT x, y;
858 x = (rcClient.right - rcClient.left)/2 - bm.bmWidth/2;
859 y = (rcClient.bottom - rcClient.top)/2 - bm.bmHeight/2;
860 FillRect( hdc, &rcClient, hbrush );
861 BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
862 SRCCOPY);
864 else
866 StretchBlt(hdc, 0, 0, rcClient.right - rcClient.left,
867 rcClient.bottom - rcClient.top, hMemDC,
868 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
870 SelectObject(hMemDC, oldbitmap);
871 DeleteDC(hMemDC);
873 else
875 RECT rcClient;
876 GetClientRect( hwnd, &rcClient );
877 FillRect( hdc, &rcClient, hbrush );
882 static void STATIC_PaintEnhMetafn(HWND hwnd, HDC hdc, DWORD style )
884 HENHMETAFILE hEnhMetaFile;
885 RECT rc;
886 HBRUSH hbrush;
888 GetClientRect(hwnd, &rc);
889 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
890 FillRect(hdc, &rc, hbrush);
891 if ((hEnhMetaFile = (HENHMETAFILE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
893 /* The control's current font is not selected into the
894 device context! */
895 if (GetObjectType(hEnhMetaFile) == OBJ_ENHMETAFILE)
896 PlayEnhMetaFile(hdc, hEnhMetaFile, &rc);
901 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
903 RECT rc;
905 /* FIXME: sometimes (not always) sends WM_CTLCOLORSTATIC */
906 GetClientRect( hwnd, &rc );
907 switch (style & SS_TYPEMASK)
909 case SS_ETCHEDHORZ:
910 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
911 break;
912 case SS_ETCHEDVERT:
913 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
914 break;
915 case SS_ETCHEDFRAME:
916 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
917 break;