push c1305fa47cb9668bae64d371dcb799102c36f834
[wine/hacks.git] / dlls / user32 / static.c
blob69acbc52c8742d6413ba4faf4403c2fad0bff6fe
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 static const WCHAR staticW[] = {'S','t','a','t','i','c',0};
104 const struct builtin_class_descr STATIC_builtin_class =
106 staticW, /* name */
107 CS_DBLCLKS | CS_PARENTDC, /* style */
108 StaticWndProcA, /* procA */
109 StaticWndProcW, /* procW */
110 STATIC_EXTRA_BYTES, /* extra */
111 IDC_ARROW, /* cursor */
112 0 /* brush */
115 static void setup_clipping(HWND hwnd, HDC hdc, HRGN *orig)
117 RECT rc;
118 HRGN hrgn;
120 /* Native control has always a clipping region set (this may be because
121 * builtin controls uses CS_PARENTDC) and an application depends on it
123 hrgn = CreateRectRgn(0, 0, 1, 1);
124 if (GetClipRgn(hdc, hrgn) != 1)
126 DeleteObject(hrgn);
127 *orig = NULL;
128 } else
129 *orig = hrgn;
131 GetClientRect(hwnd, &rc);
132 DPtoLP(hdc, (POINT *)&rc, 2);
133 IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom);
136 static void restore_clipping(HDC hdc, HRGN hrgn)
138 SelectClipRgn(hdc, hrgn);
139 if (hrgn != NULL)
140 DeleteObject(hrgn);
143 /***********************************************************************
144 * STATIC_SetIcon
146 * Set the icon for an SS_ICON control.
148 static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
150 HICON prevIcon;
151 CURSORICONINFO * info;
153 if ((style & SS_TYPEMASK) != SS_ICON) return 0;
154 info = hicon ? GlobalLock16(HICON_16(hicon)) : NULL;
155 if (hicon && !info) {
156 WARN("hicon != 0, but info == 0\n");
157 return 0;
159 prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
160 if (hicon && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
162 /* Windows currently doesn't implement SS_RIGHTJUST */
164 if ((style & SS_RIGHTJUST) != 0)
166 RECT wr;
167 GetWindowRect(hwnd, &wr);
168 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
169 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
171 else */
173 SetWindowPos( hwnd, 0, 0, 0, info->nWidth, info->nHeight,
174 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
177 if (info) GlobalUnlock16(HICON_16(hicon));
178 return prevIcon;
181 /***********************************************************************
182 * STATIC_SetBitmap
184 * Set the bitmap for an SS_BITMAP control.
186 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
188 HBITMAP hOldBitmap;
190 if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
191 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
192 WARN("hBitmap != 0, but it's not a bitmap\n");
193 return 0;
195 hOldBitmap = (HBITMAP)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hBitmap );
196 if (hBitmap && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
198 BITMAP bm;
199 GetObjectW(hBitmap, sizeof(bm), &bm);
200 /* Windows currently doesn't implement SS_RIGHTJUST */
202 if ((style & SS_RIGHTJUST) != 0)
204 RECT wr;
205 GetWindowRect(hwnd, &wr);
206 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
207 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
209 else */
211 SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
212 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
216 return hOldBitmap;
219 /***********************************************************************
220 * STATIC_SetEnhMetaFile
222 * Set the enhanced metafile for an SS_ENHMETAFILE control.
224 static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
226 if ((style & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
227 if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE) {
228 WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
229 return 0;
231 return (HENHMETAFILE)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hEnhMetaFile );
234 /***********************************************************************
235 * STATIC_GetImage
237 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
238 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
240 static HANDLE STATIC_GetImage( HWND hwnd, WPARAM wParam, DWORD style )
242 switch(style & SS_TYPEMASK)
244 case SS_ICON:
245 if ((wParam != IMAGE_ICON) &&
246 (wParam != IMAGE_CURSOR)) return NULL;
247 break;
248 case SS_BITMAP:
249 if (wParam != IMAGE_BITMAP) return NULL;
250 break;
251 case SS_ENHMETAFILE:
252 if (wParam != IMAGE_ENHMETAFILE) return NULL;
253 break;
254 default:
255 return NULL;
257 return (HANDLE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
260 /***********************************************************************
261 * STATIC_LoadIconA
263 * Load the icon for an SS_ICON control.
265 static HICON STATIC_LoadIconA( HWND hwnd, LPCSTR name, DWORD style )
267 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
268 if ((style & SS_REALSIZEIMAGE) != 0)
270 return LoadImageA(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
272 else
274 HICON hicon = LoadIconA( hInstance, name );
275 if (!hicon) hicon = LoadCursorA( hInstance, name );
276 if (!hicon) hicon = LoadIconA( 0, name );
277 /* Windows doesn't try to load a standard cursor,
278 probably because most IDs for standard cursors conflict
279 with the IDs for standard icons anyway */
280 return hicon;
284 /***********************************************************************
285 * STATIC_LoadIconW
287 * Load the icon for an SS_ICON control.
289 static HICON STATIC_LoadIconW( HWND hwnd, LPCWSTR name, DWORD style )
291 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
292 if ((style & SS_REALSIZEIMAGE) != 0)
294 return LoadImageW(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
296 else
298 HICON hicon = LoadIconW( hInstance, name );
299 if (!hicon) hicon = LoadCursorW( hInstance, name );
300 if (!hicon) hicon = LoadIconW( 0, name );
301 /* Windows doesn't try to load a standard cursor,
302 probably because most IDs for standard cursors conflict
303 with the IDs for standard icons anyway */
304 return hicon;
308 /***********************************************************************
309 * STATIC_LoadBitmapA
311 * Load the bitmap for an SS_BITMAP control.
313 static HBITMAP STATIC_LoadBitmapA( HWND hwnd, LPCSTR name )
315 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
316 /* Windows doesn't try to load OEM Bitmaps (hInstance == NULL) */
317 return LoadBitmapA( hInstance, name );
320 /***********************************************************************
321 * STATIC_LoadBitmapW
323 * Load the bitmap for an SS_BITMAP control.
325 static HBITMAP STATIC_LoadBitmapW( HWND hwnd, LPCWSTR name )
327 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
328 /* Windows doesn't try to load OEM Bitmaps (hInstance == NULL) */
329 return LoadBitmapW( hInstance, name );
332 /***********************************************************************
333 * STATIC_TryPaintFcn
335 * Try to immediately paint the control.
337 static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
339 LONG style = full_style & SS_TYPEMASK;
340 RECT rc;
342 GetClientRect( hwnd, &rc );
343 if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
345 HDC hdc;
346 HRGN hOrigClipping;
348 hdc = GetDC( hwnd );
349 setup_clipping(hwnd, hdc, &hOrigClipping);
350 (staticPaintFunc[style])( hwnd, hdc, full_style );
351 restore_clipping(hdc, hOrigClipping);
352 ReleaseDC( hwnd, hdc );
356 static HBRUSH STATIC_SendWmCtlColorStatic(HWND hwnd, HDC hdc)
358 HBRUSH hBrush;
359 HWND parent = GetParent(hwnd);
361 if (!parent) parent = hwnd;
362 hBrush = (HBRUSH) SendMessageW( parent,
363 WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
364 if (!hBrush) /* did the app forget to call DefWindowProc ? */
366 /* FIXME: DefWindowProc should return different colors if a
367 manifest is present */
368 hBrush = (HBRUSH)DefWindowProcW( parent, WM_CTLCOLORSTATIC,
369 (WPARAM)hdc, (LPARAM)hwnd);
371 return hBrush;
374 static VOID STATIC_InitColours(void)
376 color_3ddkshadow = GetSysColor(COLOR_3DDKSHADOW);
377 color_3dshadow = GetSysColor(COLOR_3DSHADOW);
378 color_3dhighlight = GetSysColor(COLOR_3DHIGHLIGHT);
381 /***********************************************************************
382 * hasTextStyle
384 * Tests if the control displays text.
386 static BOOL hasTextStyle( DWORD style )
388 switch(style & SS_TYPEMASK)
390 case SS_SIMPLE:
391 case SS_LEFT:
392 case SS_LEFTNOWORDWRAP:
393 case SS_CENTER:
394 case SS_RIGHT:
395 case SS_OWNERDRAW:
396 return TRUE;
399 return FALSE;
402 /***********************************************************************
403 * StaticWndProc_common
405 static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam,
406 LPARAM lParam, BOOL unicode )
408 LRESULT lResult = 0;
409 LONG full_style = GetWindowLongW( hwnd, GWL_STYLE );
410 LONG style = full_style & SS_TYPEMASK;
412 switch (uMsg)
414 case WM_CREATE:
415 if (style < 0L || style > SS_TYPEMASK)
417 ERR("Unknown style 0x%02x\n", style );
418 return -1;
420 STATIC_InitColours();
421 break;
423 case WM_NCDESTROY:
424 if (style == SS_ICON) {
426 * FIXME
427 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
429 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
430 * had already been loaded by the application the last thing we want to do is
431 * GlobalFree16 the handle.
433 break;
435 else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
436 DefWindowProcA(hwnd, uMsg, wParam, lParam);
438 case WM_ERASEBKGND:
439 /* do all painting in WM_PAINT like Windows does */
440 return 1;
442 case WM_PRINTCLIENT:
443 case WM_PAINT:
445 PAINTSTRUCT ps;
446 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
447 if (staticPaintFunc[style])
449 HRGN hOrigClipping;
450 setup_clipping(hwnd, hdc, &hOrigClipping);
451 (staticPaintFunc[style])( hwnd, hdc, full_style );
452 restore_clipping(hdc, hOrigClipping);
454 if (!wParam) EndPaint(hwnd, &ps);
456 break;
458 case WM_ENABLE:
459 STATIC_TryPaintFcn( hwnd, full_style );
460 if (full_style & SS_NOTIFY) {
461 if (wParam) {
462 SendMessageW( GetParent(hwnd), WM_COMMAND,
463 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_ENABLE ), (LPARAM)hwnd);
465 else {
466 SendMessageW( GetParent(hwnd), WM_COMMAND,
467 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DISABLE ), (LPARAM)hwnd);
470 break;
472 case WM_SYSCOLORCHANGE:
473 STATIC_InitColours();
474 STATIC_TryPaintFcn( hwnd, full_style );
475 break;
477 case WM_NCCREATE:
479 LPCSTR textA;
480 LPCWSTR textW;
482 if (full_style & SS_SUNKEN)
483 SetWindowLongW( hwnd, GWL_EXSTYLE,
484 GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
486 if(unicode)
488 textA = NULL;
489 textW = ((LPCREATESTRUCTW)lParam)->lpszName;
491 else
493 textA = ((LPCREATESTRUCTA)lParam)->lpszName;
494 textW = NULL;
497 switch (style) {
498 case SS_ICON:
500 HICON hIcon;
501 if(unicode)
502 hIcon = STATIC_LoadIconW(hwnd, textW, full_style);
503 else
504 hIcon = STATIC_LoadIconA(hwnd, textA, full_style);
505 STATIC_SetIcon(hwnd, hIcon, full_style);
507 break;
508 case SS_BITMAP:
510 HBITMAP hBitmap;
511 if(unicode)
512 hBitmap = STATIC_LoadBitmapW(hwnd, textW);
513 else
514 hBitmap = STATIC_LoadBitmapA(hwnd, textA);
515 STATIC_SetBitmap(hwnd, hBitmap, full_style);
517 break;
519 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
520 the enhanced metafile that was specified as the window text. */
522 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
523 DefWindowProcA(hwnd, uMsg, wParam, lParam);
525 case WM_SETTEXT:
526 if (hasTextStyle( full_style ))
528 if (HIWORD(lParam))
530 if(unicode)
531 lResult = DefWindowProcW( hwnd, uMsg, wParam, lParam );
532 else
533 lResult = DefWindowProcA( hwnd, uMsg, wParam, lParam );
534 STATIC_TryPaintFcn( hwnd, full_style );
537 break;
539 case WM_SETFONT:
540 if (hasTextStyle( full_style ))
542 SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, wParam );
543 if (LOWORD(lParam))
544 RedrawWindow( hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
546 break;
548 case WM_GETFONT:
549 return GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
551 case WM_NCHITTEST:
552 if (full_style & SS_NOTIFY)
553 return HTCLIENT;
554 else
555 return HTTRANSPARENT;
557 case WM_GETDLGCODE:
558 return DLGC_STATIC;
560 case WM_LBUTTONDOWN:
561 case WM_NCLBUTTONDOWN:
562 if (full_style & SS_NOTIFY)
563 SendMessageW( GetParent(hwnd), WM_COMMAND,
564 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_CLICKED ), (LPARAM)hwnd);
565 return 0;
567 case WM_LBUTTONDBLCLK:
568 case WM_NCLBUTTONDBLCLK:
569 if (full_style & SS_NOTIFY)
570 SendMessageW( GetParent(hwnd), WM_COMMAND,
571 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DBLCLK ), (LPARAM)hwnd);
572 return 0;
574 case STM_GETIMAGE:
575 return (LRESULT)STATIC_GetImage( hwnd, wParam, full_style );
577 case STM_GETICON16:
578 case STM_GETICON:
579 return (LRESULT)STATIC_GetImage( hwnd, IMAGE_ICON, full_style );
581 case STM_SETIMAGE:
582 switch(wParam) {
583 case IMAGE_BITMAP:
584 lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
585 break;
586 case IMAGE_ENHMETAFILE:
587 lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
588 break;
589 case IMAGE_ICON:
590 case IMAGE_CURSOR:
591 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
592 break;
593 default:
594 FIXME("STM_SETIMAGE: Unhandled type %lx\n", wParam);
595 break;
597 STATIC_TryPaintFcn( hwnd, full_style );
598 break;
600 case STM_SETICON16:
601 case STM_SETICON:
602 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
603 STATIC_TryPaintFcn( hwnd, full_style );
604 break;
606 default:
607 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
608 DefWindowProcA(hwnd, uMsg, wParam, lParam);
610 return lResult;
613 /***********************************************************************
614 * StaticWndProcA
616 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
618 if (!IsWindow( hWnd )) return 0;
619 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, FALSE);
622 /***********************************************************************
623 * StaticWndProcW
625 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
627 if (!IsWindow( hWnd )) return 0;
628 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, TRUE);
631 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
633 DRAWITEMSTRUCT dis;
634 HFONT font, oldFont = NULL;
635 UINT id = (UINT)GetWindowLongPtrW( hwnd, GWLP_ID );
637 dis.CtlType = ODT_STATIC;
638 dis.CtlID = id;
639 dis.itemID = 0;
640 dis.itemAction = ODA_DRAWENTIRE;
641 dis.itemState = IsWindowEnabled(hwnd) ? 0 : ODS_DISABLED;
642 dis.hwndItem = hwnd;
643 dis.hDC = hdc;
644 dis.itemData = 0;
645 GetClientRect( hwnd, &dis.rcItem );
647 font = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
648 if (font) oldFont = SelectObject( hdc, font );
649 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
650 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
651 if (font) SelectObject( hdc, oldFont );
654 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
656 RECT rc;
657 HBRUSH hBrush;
658 HFONT hFont, hOldFont = NULL;
659 WORD wFormat;
660 INT len, buf_size;
661 WCHAR *text;
663 GetClientRect( hwnd, &rc);
665 switch (style & SS_TYPEMASK)
667 case SS_LEFT:
668 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
669 break;
671 case SS_CENTER:
672 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
673 break;
675 case SS_RIGHT:
676 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
677 break;
679 case SS_SIMPLE:
680 wFormat = DT_LEFT | DT_SINGLELINE;
681 break;
683 case SS_LEFTNOWORDWRAP:
684 wFormat = DT_LEFT | DT_EXPANDTABS;
685 break;
687 default:
688 return;
691 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_RIGHT)
692 wFormat = DT_RIGHT | (wFormat & ~(DT_LEFT | DT_CENTER));
694 if (style & SS_NOPREFIX)
695 wFormat |= DT_NOPREFIX;
697 if ((style & SS_TYPEMASK) != SS_SIMPLE)
699 if (style & SS_CENTERIMAGE)
700 wFormat |= DT_SINGLELINE | DT_VCENTER;
701 if (style & SS_EDITCONTROL)
702 wFormat |= DT_EDITCONTROL;
703 if (style & SS_ENDELLIPSIS)
704 wFormat |= DT_SINGLELINE | DT_END_ELLIPSIS;
705 if (style & SS_PATHELLIPSIS)
706 wFormat |= DT_SINGLELINE | DT_PATH_ELLIPSIS;
707 if (style & SS_WORDELLIPSIS)
708 wFormat |= DT_SINGLELINE | DT_WORD_ELLIPSIS;
711 if ((hFont = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET )))
712 hOldFont = SelectObject( hdc, hFont );
714 /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
715 brush is not used */
716 hBrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
718 if ((style & SS_TYPEMASK) != SS_SIMPLE)
720 FillRect( hdc, &rc, hBrush );
721 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
724 buf_size = 256;
725 if (!(text = HeapAlloc( GetProcessHeap(), 0, buf_size * sizeof(WCHAR) )))
726 goto no_TextOut;
728 while ((len = InternalGetWindowText( hwnd, text, buf_size )) == buf_size - 1)
730 buf_size *= 2;
731 if (!(text = HeapReAlloc( GetProcessHeap(), 0, text, buf_size * sizeof(WCHAR) )))
732 goto no_TextOut;
735 if (!len) goto no_TextOut;
737 if (((style & SS_TYPEMASK) == SS_SIMPLE) && (style & SS_NOPREFIX))
739 /* Windows uses the faster ExtTextOut() to draw the text and
740 to paint the whole client rectangle with the text background
741 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
742 ExtTextOutW( hdc, rc.left, rc.top, ETO_CLIPPED | ETO_OPAQUE,
743 &rc, text, len, NULL );
745 else
747 DrawTextW( hdc, text, -1, &rc, wFormat );
750 no_TextOut:
751 HeapFree( GetProcessHeap(), 0, text );
753 if (hFont)
754 SelectObject( hdc, hOldFont );
757 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
759 RECT rc;
760 HBRUSH hBrush;
762 GetClientRect( hwnd, &rc);
764 /* FIXME: send WM_CTLCOLORSTATIC */
765 switch (style & SS_TYPEMASK)
767 case SS_BLACKRECT:
768 hBrush = CreateSolidBrush(color_3ddkshadow);
769 FillRect( hdc, &rc, hBrush );
770 break;
771 case SS_GRAYRECT:
772 hBrush = CreateSolidBrush(color_3dshadow);
773 FillRect( hdc, &rc, hBrush );
774 break;
775 case SS_WHITERECT:
776 hBrush = CreateSolidBrush(color_3dhighlight);
777 FillRect( hdc, &rc, hBrush );
778 break;
779 case SS_BLACKFRAME:
780 hBrush = CreateSolidBrush(color_3ddkshadow);
781 FrameRect( hdc, &rc, hBrush );
782 break;
783 case SS_GRAYFRAME:
784 hBrush = CreateSolidBrush(color_3dshadow);
785 FrameRect( hdc, &rc, hBrush );
786 break;
787 case SS_WHITEFRAME:
788 hBrush = CreateSolidBrush(color_3dhighlight);
789 FrameRect( hdc, &rc, hBrush );
790 break;
791 default:
792 return;
794 DeleteObject( hBrush );
798 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
800 RECT rc, iconRect;
801 HBRUSH hbrush;
802 HICON hIcon;
803 CURSORICONINFO * info;
805 GetClientRect( hwnd, &rc );
806 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
807 hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
808 info = hIcon ? GlobalLock16(HICON_16(hIcon)) : NULL;
809 if (!hIcon || !info)
811 FillRect(hdc, &rc, hbrush);
813 else
815 if (style & SS_CENTERIMAGE)
817 iconRect.left = (rc.right - rc.left) / 2 - info->nWidth / 2;
818 iconRect.top = (rc.bottom - rc.top) / 2 - info->nHeight / 2;
819 iconRect.right = iconRect.left + info->nWidth;
820 iconRect.bottom = iconRect.top + info->nHeight;
822 else
823 iconRect = rc;
824 FillRect( hdc, &rc, hbrush );
825 DrawIconEx( hdc, iconRect.left, iconRect.top, hIcon, iconRect.right - iconRect.left,
826 iconRect.bottom - iconRect.top, 0, NULL, DI_NORMAL );
828 if (info) GlobalUnlock16(HICON_16(hIcon));
831 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
833 HDC hMemDC;
834 HBITMAP hBitmap, oldbitmap;
835 HBRUSH hbrush;
837 /* message is still sent, even if the returned brush is not used */
838 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
840 if ((hBitmap = (HBITMAP)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET ))
841 && (GetObjectType(hBitmap) == OBJ_BITMAP)
842 && (hMemDC = CreateCompatibleDC( hdc )))
844 BITMAP bm;
845 RECT rcClient;
846 LOGBRUSH brush;
848 GetObjectW(hBitmap, sizeof(bm), &bm);
849 oldbitmap = SelectObject(hMemDC, hBitmap);
851 /* Set the background color for monochrome bitmaps
852 to the color of the background brush */
853 if (GetObjectW( hbrush, sizeof(brush), &brush ))
855 if (brush.lbStyle == BS_SOLID)
856 SetBkColor(hdc, brush.lbColor);
858 GetClientRect(hwnd, &rcClient);
859 if (style & SS_CENTERIMAGE)
861 INT x, y;
862 x = (rcClient.right - rcClient.left)/2 - bm.bmWidth/2;
863 y = (rcClient.bottom - rcClient.top)/2 - bm.bmHeight/2;
864 FillRect( hdc, &rcClient, hbrush );
865 BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
866 SRCCOPY);
868 else
870 StretchBlt(hdc, 0, 0, rcClient.right - rcClient.left,
871 rcClient.bottom - rcClient.top, hMemDC,
872 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
874 SelectObject(hMemDC, oldbitmap);
875 DeleteDC(hMemDC);
880 static void STATIC_PaintEnhMetafn(HWND hwnd, HDC hdc, DWORD style )
882 HENHMETAFILE hEnhMetaFile;
883 RECT rc;
884 HBRUSH hbrush;
886 GetClientRect(hwnd, &rc);
887 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
888 FillRect(hdc, &rc, hbrush);
889 if ((hEnhMetaFile = (HENHMETAFILE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
891 /* The control's current font is not selected into the
892 device context! */
893 if (GetObjectType(hEnhMetaFile) == OBJ_ENHMETAFILE)
894 PlayEnhMetaFile(hdc, hEnhMetaFile, &rc);
899 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
901 RECT rc;
903 /* FIXME: sometimes (not always) sends WM_CTLCOLORSTATIC */
904 GetClientRect( hwnd, &rc );
905 switch (style & SS_TYPEMASK)
907 case SS_ETCHEDHORZ:
908 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
909 break;
910 case SS_ETCHEDVERT:
911 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
912 break;
913 case SS_ETCHEDFRAME:
914 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
915 break;