static control: Background of enhanced metafiles.
[wine/multimedia.git] / dlls / user / static.c
bloba3483c664866c7e94349679bf8695cbd0706c71a
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 * TODO:
31 * Styles
32 * - SS_REALSIZECONTROL
33 * - SS_REALSIZEIMAGE
34 * - SS_RIGHTJUST
36 * Notifications
37 * - STN_DISABLE
38 * - STN_ENABLE
40 * Messages
41 * - STM_SETIMAGE: IMAGE_CURSOR
44 #include <stdarg.h>
46 #include "windef.h"
47 #include "winbase.h"
48 #include "wingdi.h"
49 #include "wine/winuser16.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 );
63 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
64 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
66 static COLORREF color_3dshadow, color_3ddkshadow, color_3dhighlight;
68 /* offsets for GetWindowLong for static private information */
69 #define HFONT_GWL_OFFSET 0
70 #define HICON_GWL_OFFSET (sizeof(HFONT))
71 #define STATIC_EXTRA_BYTES (HICON_GWL_OFFSET + sizeof(HICON))
73 typedef void (*pfPaint)( HWND hwnd, HDC hdc, DWORD style );
75 static pfPaint staticPaintFunc[SS_TYPEMASK+1] =
77 STATIC_PaintTextfn, /* SS_LEFT */
78 STATIC_PaintTextfn, /* SS_CENTER */
79 STATIC_PaintTextfn, /* SS_RIGHT */
80 STATIC_PaintIconfn, /* SS_ICON */
81 STATIC_PaintRectfn, /* SS_BLACKRECT */
82 STATIC_PaintRectfn, /* SS_GRAYRECT */
83 STATIC_PaintRectfn, /* SS_WHITERECT */
84 STATIC_PaintRectfn, /* SS_BLACKFRAME */
85 STATIC_PaintRectfn, /* SS_GRAYFRAME */
86 STATIC_PaintRectfn, /* SS_WHITEFRAME */
87 NULL, /* SS_USERITEM */
88 STATIC_PaintTextfn, /* SS_SIMPLE */
89 STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
90 STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
91 STATIC_PaintBitmapfn, /* SS_BITMAP */
92 STATIC_PaintEnhMetafn, /* SS_ENHMETAFILE */
93 STATIC_PaintEtchedfn, /* SS_ETCHEDHORZ */
94 STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
95 STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
99 /*********************************************************************
100 * static class descriptor
102 const struct builtin_class_descr STATIC_builtin_class =
104 "Static", /* name */
105 CS_DBLCLKS | CS_PARENTDC, /* style */
106 StaticWndProcA, /* procA */
107 StaticWndProcW, /* procW */
108 STATIC_EXTRA_BYTES, /* extra */
109 IDC_ARROW, /* cursor */
110 0 /* brush */
114 /***********************************************************************
115 * STATIC_SetIcon
117 * Set the icon for an SS_ICON control.
119 static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
121 HICON prevIcon;
122 CURSORICONINFO *info = hicon?(CURSORICONINFO *) GlobalLock16(HICON_16(hicon)):NULL;
124 if ((style & SS_TYPEMASK) != SS_ICON) return 0;
125 if (hicon && !info) {
126 ERR("hicon != 0, but info == 0\n");
127 return 0;
129 prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
130 if (hicon && !(style & SS_CENTERIMAGE))
132 SetWindowPos( hwnd, 0, 0, 0, info->nWidth, info->nHeight,
133 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
134 GlobalUnlock16(HICON_16(hicon));
136 return prevIcon;
139 /***********************************************************************
140 * STATIC_SetBitmap
142 * Set the bitmap for an SS_BITMAP control.
144 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
146 HBITMAP hOldBitmap;
148 if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
149 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
150 ERR("hBitmap != 0, but it's not a bitmap\n");
151 return 0;
153 hOldBitmap = (HBITMAP)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hBitmap );
154 if (hBitmap && !(style & SS_CENTERIMAGE))
156 BITMAP bm;
157 GetObjectW(hBitmap, sizeof(bm), &bm);
158 SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
159 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
161 return hOldBitmap;
164 /***********************************************************************
165 * STATIC_SetEnhMetaFile
167 * Set the enhanced metafile for an SS_ENHMETAFILE control.
169 static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
171 if ((style & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
172 if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE) {
173 ERR("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
174 return 0;
176 return (HENHMETAFILE)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hEnhMetaFile );
179 /***********************************************************************
180 * STATIC_LoadIconA
182 * Load the icon for an SS_ICON control.
184 static HICON STATIC_LoadIconA( HWND hwnd, LPCSTR name )
186 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
187 HICON hicon = LoadIconA( hInstance, name );
188 if (!hicon) hicon = LoadIconA( 0, name );
189 return hicon;
192 /***********************************************************************
193 * STATIC_LoadIconW
195 * Load the icon for an SS_ICON control.
197 static HICON STATIC_LoadIconW( HWND hwnd, LPCWSTR name )
199 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
200 HICON hicon = LoadIconW( hInstance, name );
201 if (!hicon) hicon = LoadIconW( 0, name );
202 return hicon;
205 /***********************************************************************
206 * STATIC_LoadBitmapA
208 * Load the bitmap for an SS_BITMAP control.
210 static HBITMAP STATIC_LoadBitmapA( HWND hwnd, LPCSTR name )
212 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
213 HBITMAP hbitmap = LoadBitmapA( hInstance, name );
214 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
215 hbitmap = LoadBitmapA( 0, name );
216 return hbitmap;
219 /***********************************************************************
220 * STATIC_LoadBitmapW
222 * Load the bitmap for an SS_BITMAP control.
224 static HBITMAP STATIC_LoadBitmapW( HWND hwnd, LPCWSTR name )
226 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
227 HBITMAP hbitmap = LoadBitmapW( hInstance, name );
228 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
229 hbitmap = LoadBitmapW( 0, name );
230 return hbitmap;
233 /***********************************************************************
234 * STATIC_TryPaintFcn
236 * Try to immediately paint the control.
238 static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
240 LONG style = full_style & SS_TYPEMASK;
241 RECT rc;
243 GetClientRect( hwnd, &rc );
244 if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
246 HDC hdc;
247 hdc = GetDC( hwnd );
248 (staticPaintFunc[style])( hwnd, hdc, full_style );
249 ReleaseDC( hwnd, hdc );
253 static HBRUSH STATIC_SendWmCtlColorStatic(HWND hwnd, HDC hdc)
255 HBRUSH hBrush = (HBRUSH) SendMessageW( GetParent(hwnd),
256 WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
257 if (!hBrush) /* did the app forget to call DefWindowProc ? */
259 /* FIXME: DefWindowProc should return different colors if a
260 manifest is present */
261 hBrush = (HBRUSH)DefWindowProcW(GetParent(hwnd), WM_CTLCOLORSTATIC,
262 (WPARAM)hdc, (LPARAM)hwnd);
264 return hBrush;
267 static VOID STATIC_InitColours(void)
269 color_3ddkshadow = GetSysColor(COLOR_3DDKSHADOW);
270 color_3dshadow = GetSysColor(COLOR_3DSHADOW);
271 color_3dhighlight = GetSysColor(COLOR_3DHIGHLIGHT);
274 /***********************************************************************
275 * StaticWndProc_common
277 static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam,
278 LPARAM lParam, BOOL unicode )
280 LRESULT lResult = 0;
281 LONG full_style = GetWindowLongW( hwnd, GWL_STYLE );
282 LONG style = full_style & SS_TYPEMASK;
284 switch (uMsg)
286 case WM_CREATE:
287 if (style < 0L || style > SS_TYPEMASK)
289 ERR("Unknown style 0x%02lx\n", style );
290 return -1;
292 STATIC_InitColours();
293 break;
295 case WM_NCDESTROY:
296 if (style == SS_ICON) {
298 * FIXME
299 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
301 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
302 * had already been loaded by the application the last thing we want to do is
303 * GlobalFree16 the handle.
305 break;
307 else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
308 DefWindowProcA(hwnd, uMsg, wParam, lParam);
310 case WM_PRINTCLIENT:
311 case WM_PAINT:
313 PAINTSTRUCT ps;
314 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
315 if (staticPaintFunc[style])
316 (staticPaintFunc[style])( hwnd, hdc, full_style );
317 if (!wParam) EndPaint(hwnd, &ps);
319 break;
321 case WM_ENABLE:
322 InvalidateRect(hwnd, NULL, TRUE);
323 break;
325 case WM_SYSCOLORCHANGE:
326 STATIC_InitColours();
327 InvalidateRect(hwnd, NULL, TRUE);
328 break;
330 case WM_NCCREATE:
331 if (full_style & SS_SUNKEN)
332 SetWindowLongW( hwnd, GWL_EXSTYLE,
333 GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
335 if(unicode)
336 lParam = (LPARAM)(((LPCREATESTRUCTW)lParam)->lpszName);
337 else
338 lParam = (LPARAM)(((LPCREATESTRUCTA)lParam)->lpszName);
339 /* fall through */
340 case WM_SETTEXT:
341 switch (style) {
342 case SS_ICON:
344 HICON hIcon;
345 if(unicode)
346 hIcon = STATIC_LoadIconW(hwnd, (LPCWSTR)lParam);
347 else
348 hIcon = STATIC_LoadIconA(hwnd, (LPCSTR)lParam);
349 /* FIXME : should we also return the previous hIcon here ??? */
350 STATIC_SetIcon(hwnd, hIcon, full_style);
351 break;
353 case SS_BITMAP:
355 HBITMAP hBitmap;
356 if(unicode)
357 hBitmap = STATIC_LoadBitmapW(hwnd, (LPCWSTR)lParam);
358 else
359 hBitmap = STATIC_LoadBitmapA(hwnd, (LPCSTR)lParam);
360 STATIC_SetBitmap(hwnd, hBitmap, full_style);
361 break;
363 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
364 the enhanced metafile that was specified as the window text. */
366 case SS_LEFT:
367 case SS_CENTER:
368 case SS_RIGHT:
369 case SS_SIMPLE:
370 case SS_LEFTNOWORDWRAP:
372 if (HIWORD(lParam))
374 if(unicode)
375 lResult = DefWindowProcW( hwnd, WM_SETTEXT, wParam, lParam );
376 else
377 lResult = DefWindowProcA( hwnd, WM_SETTEXT, wParam, lParam );
379 if (uMsg == WM_SETTEXT)
380 STATIC_TryPaintFcn( hwnd, full_style );
381 break;
383 default:
384 if (HIWORD(lParam))
386 if(unicode)
387 lResult = DefWindowProcW( hwnd, WM_SETTEXT, wParam, lParam );
388 else
389 lResult = DefWindowProcA( hwnd, WM_SETTEXT, wParam, lParam );
391 if(uMsg == WM_SETTEXT)
392 InvalidateRect(hwnd, NULL, TRUE);
394 return 1; /* success. FIXME: check text length */
396 case WM_SETFONT:
397 if ((style == SS_ICON) || (style == SS_BITMAP)) return 0;
398 SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, wParam );
399 if (LOWORD(lParam))
400 InvalidateRect( hwnd, NULL, TRUE );
401 break;
403 case WM_GETFONT:
404 return GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
406 case WM_NCHITTEST:
407 if (full_style & SS_NOTIFY)
408 return HTCLIENT;
409 else
410 return HTTRANSPARENT;
412 case WM_GETDLGCODE:
413 return DLGC_STATIC;
415 case WM_LBUTTONDOWN:
416 case WM_NCLBUTTONDOWN:
417 if (full_style & SS_NOTIFY)
418 SendMessageW( GetParent(hwnd), WM_COMMAND,
419 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_CLICKED ), (LPARAM)hwnd);
420 return 0;
422 case WM_LBUTTONDBLCLK:
423 case WM_NCLBUTTONDBLCLK:
424 if (full_style & SS_NOTIFY)
425 SendMessageW( GetParent(hwnd), WM_COMMAND,
426 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DBLCLK ), (LPARAM)hwnd);
427 return 0;
429 case STM_GETIMAGE:
430 /* FIXME: Return NULL if wParam doesn't match the control's style.
431 wParam is IMAGE_BITMAP, IMAGE_CURSOR, IMAGE_ENHMETAFILE
432 or IMAGE_ICON */
433 case STM_GETICON16:
434 case STM_GETICON:
435 /* FIXME: Return NULL if this control doesn't show an icon */
436 return GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
438 case STM_SETIMAGE:
439 switch(wParam) {
440 case IMAGE_BITMAP:
441 lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
442 break;
443 case IMAGE_CURSOR:
444 FIXME("STM_SETIMAGE: Unhandled type IMAGE_CURSOR\n");
445 break;
446 case IMAGE_ENHMETAFILE:
447 lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
448 break;
449 case IMAGE_ICON:
450 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
451 break;
452 default:
453 FIXME("STM_SETIMAGE: Unhandled type %x\n", wParam);
454 break;
456 InvalidateRect( hwnd, NULL, TRUE );
457 break;
459 case STM_SETICON16:
460 case STM_SETICON:
461 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
462 InvalidateRect( hwnd, NULL, TRUE );
463 break;
465 default:
466 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
467 DefWindowProcA(hwnd, uMsg, wParam, lParam);
469 return lResult;
472 /***********************************************************************
473 * StaticWndProcA
475 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
477 if (!IsWindow( hWnd )) return 0;
478 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, FALSE);
481 /***********************************************************************
482 * StaticWndProcW
484 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
486 if (!IsWindow( hWnd )) return 0;
487 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, TRUE);
490 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
492 DRAWITEMSTRUCT dis;
493 HFONT font, oldFont = NULL;
494 UINT id = (UINT)GetWindowLongPtrW( hwnd, GWLP_ID );
496 dis.CtlType = ODT_STATIC;
497 dis.CtlID = id;
498 dis.itemID = 0;
499 dis.itemAction = ODA_DRAWENTIRE;
500 dis.itemState = IsWindowEnabled(hwnd) ? 0 : ODS_DISABLED;
501 dis.hwndItem = hwnd;
502 dis.hDC = hdc;
503 dis.itemData = 0;
504 GetClientRect( hwnd, &dis.rcItem );
506 font = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
507 if (font) oldFont = SelectObject( hdc, font );
508 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
509 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
510 if (font) SelectObject( hdc, oldFont );
513 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
515 RECT rc;
516 HBRUSH hBrush;
517 HFONT hFont, hOldFont = NULL;
518 WORD wFormat;
519 INT len;
520 WCHAR *text;
522 GetClientRect( hwnd, &rc);
524 switch (style & SS_TYPEMASK)
526 case SS_LEFT:
527 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
528 break;
530 case SS_CENTER:
531 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
532 break;
534 case SS_RIGHT:
535 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
536 break;
538 case SS_SIMPLE:
539 wFormat = DT_LEFT | DT_SINGLELINE;
540 break;
542 case SS_LEFTNOWORDWRAP:
543 wFormat = DT_LEFT | DT_EXPANDTABS;
544 break;
546 default:
547 return;
550 if (style & SS_NOPREFIX)
551 wFormat |= DT_NOPREFIX;
553 if ((style & SS_TYPEMASK) != SS_SIMPLE)
555 if (style & SS_CENTERIMAGE)
556 wFormat |= DT_SINGLELINE | DT_VCENTER;
557 if (style & SS_EDITCONTROL)
558 wFormat |= DT_EDITCONTROL;
559 if (style & SS_ENDELLIPSIS)
560 wFormat |= DT_SINGLELINE | DT_END_ELLIPSIS;
561 if (style & SS_PATHELLIPSIS)
562 wFormat |= DT_SINGLELINE | DT_PATH_ELLIPSIS;
563 if (style & SS_WORDELLIPSIS)
564 wFormat |= DT_SINGLELINE | DT_WORD_ELLIPSIS;
567 if ((hFont = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET )))
568 hOldFont = (HFONT)SelectObject( hdc, hFont );
570 /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
571 brush is not used */
572 hBrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
574 if ((style & SS_TYPEMASK) != SS_SIMPLE)
576 FillRect( hdc, &rc, hBrush );
577 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
580 if (!(len = SendMessageW( hwnd, WM_GETTEXTLENGTH, 0, 0 ))) return;
581 if (!(text = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return;
582 SendMessageW( hwnd, WM_GETTEXT, len + 1, (LPARAM)text );
584 if (((style & SS_TYPEMASK) == SS_SIMPLE) && (style & SS_NOPREFIX))
586 /* Windows uses the faster ExtTextOut() to draw the text and
587 to paint the whole client rectangle with the text background
588 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
589 ExtTextOutW( hdc, rc.left, rc.top, ETO_CLIPPED | ETO_OPAQUE,
590 &rc, text, len, NULL );
592 else
594 DrawTextW( hdc, text, -1, &rc, wFormat );
597 HeapFree( GetProcessHeap(), 0, text );
599 if (hFont)
600 SelectObject( hdc, hOldFont );
603 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
605 RECT rc;
606 HBRUSH hBrush;
608 GetClientRect( hwnd, &rc);
610 switch (style & SS_TYPEMASK)
612 case SS_BLACKRECT:
613 hBrush = CreateSolidBrush(color_3ddkshadow);
614 FillRect( hdc, &rc, hBrush );
615 break;
616 case SS_GRAYRECT:
617 hBrush = CreateSolidBrush(color_3dshadow);
618 FillRect( hdc, &rc, hBrush );
619 break;
620 case SS_WHITERECT:
621 hBrush = CreateSolidBrush(color_3dhighlight);
622 FillRect( hdc, &rc, hBrush );
623 break;
624 case SS_BLACKFRAME:
625 hBrush = CreateSolidBrush(color_3ddkshadow);
626 FrameRect( hdc, &rc, hBrush );
627 break;
628 case SS_GRAYFRAME:
629 hBrush = CreateSolidBrush(color_3dshadow);
630 FrameRect( hdc, &rc, hBrush );
631 break;
632 case SS_WHITEFRAME:
633 hBrush = CreateSolidBrush(color_3dhighlight);
634 FrameRect( hdc, &rc, hBrush );
635 break;
636 default:
637 return;
639 DeleteObject( hBrush );
643 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
645 RECT rc;
646 HBRUSH hbrush;
647 HICON hIcon;
648 INT x, y;
650 GetClientRect( hwnd, &rc );
651 hbrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC,
652 (WPARAM)hdc, (LPARAM)hwnd );
653 FillRect( hdc, &rc, hbrush );
654 hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
655 if (style & SS_CENTERIMAGE)
657 CURSORICONINFO *info = hIcon ? (CURSORICONINFO *)GlobalLock16(HICON_16(hIcon)) : NULL;
658 x = (rc.right - rc.left)/2 - (info ? info->nWidth/2 : 0);
659 y = (rc.bottom - rc.top)/2 - (info ? info->nHeight/2 : 0);
661 else
663 x = rc.left;
664 y = rc.top;
666 if (hIcon)
667 DrawIcon( hdc, x, y, hIcon );
670 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
672 HDC hMemDC;
673 HBITMAP hBitmap, oldbitmap;
675 /* message is still sent, even if the returned brush is not used */
676 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC,
677 (WPARAM)hdc, (LPARAM)hwnd );
679 if ((hBitmap = (HBITMAP)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
681 INT x, y;
682 BITMAP bm;
684 if(GetObjectType(hBitmap) != OBJ_BITMAP) return;
685 if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
686 GetObjectW(hBitmap, sizeof(bm), &bm);
687 oldbitmap = SelectObject(hMemDC, hBitmap);
688 if (style & SS_CENTERIMAGE)
690 RECT rcClient;
691 GetClientRect(hwnd, &rcClient);
692 x = (rcClient.right - rcClient.left)/2 - bm.bmWidth/2;
693 y = (rcClient.bottom - rcClient.top)/2 - bm.bmHeight/2;
695 else
697 x = 0;
698 y = 0;
700 BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
701 SRCCOPY);
702 SelectObject(hMemDC, oldbitmap);
703 DeleteDC(hMemDC);
708 static void STATIC_PaintEnhMetafn(HWND hwnd, HDC hdc, DWORD style )
710 HENHMETAFILE hEnhMetaFile;
711 RECT rc;
712 HBRUSH hbrush;
714 GetClientRect(hwnd, &rc);
715 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
716 FillRect(hdc, &rc, hbrush);
717 if ((hEnhMetaFile = (HENHMETAFILE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
719 /* The control's current font is not selected into the
720 device context! */
721 if (GetObjectType(hEnhMetaFile) == OBJ_ENHMETAFILE)
722 PlayEnhMetaFile(hdc, hEnhMetaFile, &rc);
727 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
729 RECT rc;
731 GetClientRect( hwnd, &rc );
732 switch (style & SS_TYPEMASK)
734 case SS_ETCHEDHORZ:
735 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
736 break;
737 case SS_ETCHEDVERT:
738 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
739 break;
740 case SS_ETCHEDFRAME:
741 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
742 break;