static control: Support SS_REALSIZECONTROL.
[wine.git] / dlls / user / static.c
blob0b8cb29cfa18de44af37c3fa44cec6138ed562f3
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_REALSIZEIMAGE
33 * - SS_RIGHTJUST
35 * Notifications
36 * - STN_DISABLE
37 * - STN_ENABLE
39 * Messages
40 * - STM_SETIMAGE: IMAGE_CURSOR
43 #include <stdarg.h>
45 #include "windef.h"
46 #include "winbase.h"
47 #include "wingdi.h"
48 #include "wine/winuser16.h"
49 #include "controls.h"
50 #include "user_private.h"
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(static);
55 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style );
56 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style );
57 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style );
58 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style );
59 static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc, DWORD style );
60 static void STATIC_PaintEnhMetafn( HWND hwnd, HDC hdc, DWORD style );
61 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style );
62 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
63 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
65 static COLORREF color_3dshadow, color_3ddkshadow, color_3dhighlight;
67 /* offsets for GetWindowLong for static private information */
68 #define HFONT_GWL_OFFSET 0
69 #define HICON_GWL_OFFSET (sizeof(HFONT))
70 #define STATIC_EXTRA_BYTES (HICON_GWL_OFFSET + sizeof(HICON))
72 typedef void (*pfPaint)( HWND hwnd, HDC hdc, DWORD style );
74 static pfPaint staticPaintFunc[SS_TYPEMASK+1] =
76 STATIC_PaintTextfn, /* SS_LEFT */
77 STATIC_PaintTextfn, /* SS_CENTER */
78 STATIC_PaintTextfn, /* SS_RIGHT */
79 STATIC_PaintIconfn, /* SS_ICON */
80 STATIC_PaintRectfn, /* SS_BLACKRECT */
81 STATIC_PaintRectfn, /* SS_GRAYRECT */
82 STATIC_PaintRectfn, /* SS_WHITERECT */
83 STATIC_PaintRectfn, /* SS_BLACKFRAME */
84 STATIC_PaintRectfn, /* SS_GRAYFRAME */
85 STATIC_PaintRectfn, /* SS_WHITEFRAME */
86 NULL, /* SS_USERITEM */
87 STATIC_PaintTextfn, /* SS_SIMPLE */
88 STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
89 STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
90 STATIC_PaintBitmapfn, /* SS_BITMAP */
91 STATIC_PaintEnhMetafn, /* SS_ENHMETAFILE */
92 STATIC_PaintEtchedfn, /* SS_ETCHEDHORZ */
93 STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
94 STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
98 /*********************************************************************
99 * static class descriptor
101 const struct builtin_class_descr STATIC_builtin_class =
103 "Static", /* name */
104 CS_DBLCLKS | CS_PARENTDC, /* style */
105 StaticWndProcA, /* procA */
106 StaticWndProcW, /* procW */
107 STATIC_EXTRA_BYTES, /* extra */
108 IDC_ARROW, /* cursor */
109 0 /* brush */
113 /***********************************************************************
114 * STATIC_SetIcon
116 * Set the icon for an SS_ICON control.
118 static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
120 HICON prevIcon;
121 CURSORICONINFO * info;
123 if ((style & SS_TYPEMASK) != SS_ICON) return 0;
124 info = hicon?(CURSORICONINFO *) GlobalLock16(HICON_16(hicon)):NULL;
125 if (hicon && !info) {
126 WARN("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) && !(style & SS_REALSIZECONTROL))
132 /* Windows currently doesn't implement SS_RIGHTJUST */
134 if ((style & SS_RIGHTJUST) != 0)
136 RECT wr;
137 GetWindowRect(hwnd, &wr);
138 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
139 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
141 else */
143 SetWindowPos( hwnd, 0, 0, 0, info->nWidth, info->nHeight,
144 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
147 if (info) GlobalUnlock16(HICON_16(hicon));
148 return prevIcon;
151 /***********************************************************************
152 * STATIC_SetBitmap
154 * Set the bitmap for an SS_BITMAP control.
156 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
158 HBITMAP hOldBitmap;
160 if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
161 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
162 WARN("hBitmap != 0, but it's not a bitmap\n");
163 return 0;
165 hOldBitmap = (HBITMAP)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hBitmap );
166 if (hBitmap && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
168 BITMAP bm;
169 GetObjectW(hBitmap, sizeof(bm), &bm);
170 /* Windows currently doesn't implement SS_RIGHTJUST */
172 if ((style & SS_RIGHTJUST) != 0)
174 RECT wr;
175 GetWindowRect(hwnd, &wr);
176 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
177 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
179 else */
181 SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
182 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
186 return hOldBitmap;
189 /***********************************************************************
190 * STATIC_SetEnhMetaFile
192 * Set the enhanced metafile for an SS_ENHMETAFILE control.
194 static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
196 if ((style & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
197 if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE) {
198 WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
199 return 0;
201 return (HENHMETAFILE)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hEnhMetaFile );
204 /***********************************************************************
205 * STATIC_LoadIconA
207 * Load the icon for an SS_ICON control.
209 static HICON STATIC_LoadIconA( HWND hwnd, LPCSTR name )
211 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
212 HICON hicon = LoadIconA( hInstance, name );
213 if (!hicon) hicon = LoadIconA( 0, name );
214 return hicon;
217 /***********************************************************************
218 * STATIC_LoadIconW
220 * Load the icon for an SS_ICON control.
222 static HICON STATIC_LoadIconW( HWND hwnd, LPCWSTR name )
224 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
225 HICON hicon = LoadIconW( hInstance, name );
226 if (!hicon) hicon = LoadIconW( 0, name );
227 return hicon;
230 /***********************************************************************
231 * STATIC_LoadBitmapA
233 * Load the bitmap for an SS_BITMAP control.
235 static HBITMAP STATIC_LoadBitmapA( HWND hwnd, LPCSTR name )
237 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
238 HBITMAP hbitmap = LoadBitmapA( hInstance, name );
239 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
240 hbitmap = LoadBitmapA( 0, name );
241 return hbitmap;
244 /***********************************************************************
245 * STATIC_LoadBitmapW
247 * Load the bitmap for an SS_BITMAP control.
249 static HBITMAP STATIC_LoadBitmapW( HWND hwnd, LPCWSTR name )
251 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
252 HBITMAP hbitmap = LoadBitmapW( hInstance, name );
253 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
254 hbitmap = LoadBitmapW( 0, name );
255 return hbitmap;
258 /***********************************************************************
259 * STATIC_TryPaintFcn
261 * Try to immediately paint the control.
263 static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
265 LONG style = full_style & SS_TYPEMASK;
266 RECT rc;
268 GetClientRect( hwnd, &rc );
269 if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
271 HDC hdc;
272 hdc = GetDC( hwnd );
273 (staticPaintFunc[style])( hwnd, hdc, full_style );
274 ReleaseDC( hwnd, hdc );
278 static HBRUSH STATIC_SendWmCtlColorStatic(HWND hwnd, HDC hdc)
280 HBRUSH hBrush = (HBRUSH) SendMessageW( GetParent(hwnd),
281 WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
282 if (!hBrush) /* did the app forget to call DefWindowProc ? */
284 /* FIXME: DefWindowProc should return different colors if a
285 manifest is present */
286 hBrush = (HBRUSH)DefWindowProcW(GetParent(hwnd), WM_CTLCOLORSTATIC,
287 (WPARAM)hdc, (LPARAM)hwnd);
289 return hBrush;
292 static VOID STATIC_InitColours(void)
294 color_3ddkshadow = GetSysColor(COLOR_3DDKSHADOW);
295 color_3dshadow = GetSysColor(COLOR_3DSHADOW);
296 color_3dhighlight = GetSysColor(COLOR_3DHIGHLIGHT);
299 /***********************************************************************
300 * StaticWndProc_common
302 static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam,
303 LPARAM lParam, BOOL unicode )
305 LRESULT lResult = 0;
306 LONG full_style = GetWindowLongW( hwnd, GWL_STYLE );
307 LONG style = full_style & SS_TYPEMASK;
309 switch (uMsg)
311 case WM_CREATE:
312 if (style < 0L || style > SS_TYPEMASK)
314 ERR("Unknown style 0x%02lx\n", style );
315 return -1;
317 STATIC_InitColours();
318 break;
320 case WM_NCDESTROY:
321 if (style == SS_ICON) {
323 * FIXME
324 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
326 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
327 * had already been loaded by the application the last thing we want to do is
328 * GlobalFree16 the handle.
330 break;
332 else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
333 DefWindowProcA(hwnd, uMsg, wParam, lParam);
335 case WM_PRINTCLIENT:
336 case WM_PAINT:
338 PAINTSTRUCT ps;
339 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
340 if (staticPaintFunc[style])
341 (staticPaintFunc[style])( hwnd, hdc, full_style );
342 if (!wParam) EndPaint(hwnd, &ps);
344 break;
346 case WM_ENABLE:
347 InvalidateRect(hwnd, NULL, TRUE);
348 break;
350 case WM_SYSCOLORCHANGE:
351 STATIC_InitColours();
352 InvalidateRect(hwnd, NULL, TRUE);
353 break;
355 case WM_NCCREATE:
356 if (full_style & SS_SUNKEN)
357 SetWindowLongW( hwnd, GWL_EXSTYLE,
358 GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
360 if(unicode)
361 lParam = (LPARAM)(((LPCREATESTRUCTW)lParam)->lpszName);
362 else
363 lParam = (LPARAM)(((LPCREATESTRUCTA)lParam)->lpszName);
364 /* fall through */
365 case WM_SETTEXT:
366 switch (style) {
367 case SS_ICON:
369 HICON hIcon;
370 if(unicode)
371 hIcon = STATIC_LoadIconW(hwnd, (LPCWSTR)lParam);
372 else
373 hIcon = STATIC_LoadIconA(hwnd, (LPCSTR)lParam);
374 /* FIXME : should we also return the previous hIcon here ??? */
375 STATIC_SetIcon(hwnd, hIcon, full_style);
376 break;
378 case SS_BITMAP:
380 HBITMAP hBitmap;
381 if(unicode)
382 hBitmap = STATIC_LoadBitmapW(hwnd, (LPCWSTR)lParam);
383 else
384 hBitmap = STATIC_LoadBitmapA(hwnd, (LPCSTR)lParam);
385 STATIC_SetBitmap(hwnd, hBitmap, full_style);
386 break;
388 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
389 the enhanced metafile that was specified as the window text. */
391 case SS_LEFT:
392 case SS_CENTER:
393 case SS_RIGHT:
394 case SS_SIMPLE:
395 case SS_LEFTNOWORDWRAP:
397 if (HIWORD(lParam))
399 if(unicode)
400 lResult = DefWindowProcW( hwnd, WM_SETTEXT, wParam, lParam );
401 else
402 lResult = DefWindowProcA( hwnd, WM_SETTEXT, wParam, lParam );
404 if (uMsg == WM_SETTEXT)
405 STATIC_TryPaintFcn( hwnd, full_style );
406 break;
408 default:
409 if (HIWORD(lParam))
411 if(unicode)
412 lResult = DefWindowProcW( hwnd, WM_SETTEXT, wParam, lParam );
413 else
414 lResult = DefWindowProcA( hwnd, WM_SETTEXT, wParam, lParam );
416 if(uMsg == WM_SETTEXT)
417 InvalidateRect(hwnd, NULL, TRUE);
419 return 1; /* success. FIXME: check text length */
421 case WM_SETFONT:
422 if ((style == SS_ICON) || (style == SS_BITMAP)) return 0;
423 SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, wParam );
424 if (LOWORD(lParam))
425 InvalidateRect( hwnd, NULL, TRUE );
426 break;
428 case WM_GETFONT:
429 return GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
431 case WM_NCHITTEST:
432 if (full_style & SS_NOTIFY)
433 return HTCLIENT;
434 else
435 return HTTRANSPARENT;
437 case WM_GETDLGCODE:
438 return DLGC_STATIC;
440 case WM_LBUTTONDOWN:
441 case WM_NCLBUTTONDOWN:
442 if (full_style & SS_NOTIFY)
443 SendMessageW( GetParent(hwnd), WM_COMMAND,
444 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_CLICKED ), (LPARAM)hwnd);
445 return 0;
447 case WM_LBUTTONDBLCLK:
448 case WM_NCLBUTTONDBLCLK:
449 if (full_style & SS_NOTIFY)
450 SendMessageW( GetParent(hwnd), WM_COMMAND,
451 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DBLCLK ), (LPARAM)hwnd);
452 return 0;
454 case STM_GETIMAGE:
455 /* FIXME: Return NULL if wParam doesn't match the control's style.
456 wParam is IMAGE_BITMAP, IMAGE_CURSOR, IMAGE_ENHMETAFILE
457 or IMAGE_ICON */
458 case STM_GETICON16:
459 case STM_GETICON:
460 /* FIXME: Return NULL if this control doesn't show an icon */
461 return GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
463 case STM_SETIMAGE:
464 switch(wParam) {
465 case IMAGE_BITMAP:
466 lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
467 break;
468 case IMAGE_CURSOR:
469 FIXME("STM_SETIMAGE: Unhandled type IMAGE_CURSOR\n");
470 break;
471 case IMAGE_ENHMETAFILE:
472 lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
473 break;
474 case IMAGE_ICON:
475 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
476 break;
477 default:
478 FIXME("STM_SETIMAGE: Unhandled type %x\n", wParam);
479 break;
481 InvalidateRect( hwnd, NULL, TRUE );
482 break;
484 case STM_SETICON16:
485 case STM_SETICON:
486 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
487 InvalidateRect( hwnd, NULL, TRUE );
488 break;
490 default:
491 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
492 DefWindowProcA(hwnd, uMsg, wParam, lParam);
494 return lResult;
497 /***********************************************************************
498 * StaticWndProcA
500 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
502 if (!IsWindow( hWnd )) return 0;
503 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, FALSE);
506 /***********************************************************************
507 * StaticWndProcW
509 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
511 if (!IsWindow( hWnd )) return 0;
512 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, TRUE);
515 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
517 DRAWITEMSTRUCT dis;
518 HFONT font, oldFont = NULL;
519 UINT id = (UINT)GetWindowLongPtrW( hwnd, GWLP_ID );
521 dis.CtlType = ODT_STATIC;
522 dis.CtlID = id;
523 dis.itemID = 0;
524 dis.itemAction = ODA_DRAWENTIRE;
525 dis.itemState = IsWindowEnabled(hwnd) ? 0 : ODS_DISABLED;
526 dis.hwndItem = hwnd;
527 dis.hDC = hdc;
528 dis.itemData = 0;
529 GetClientRect( hwnd, &dis.rcItem );
531 font = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
532 if (font) oldFont = SelectObject( hdc, font );
533 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
534 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
535 if (font) SelectObject( hdc, oldFont );
538 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
540 RECT rc;
541 HBRUSH hBrush;
542 HFONT hFont, hOldFont = NULL;
543 WORD wFormat;
544 INT len;
545 WCHAR *text;
547 GetClientRect( hwnd, &rc);
549 switch (style & SS_TYPEMASK)
551 case SS_LEFT:
552 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
553 break;
555 case SS_CENTER:
556 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
557 break;
559 case SS_RIGHT:
560 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
561 break;
563 case SS_SIMPLE:
564 wFormat = DT_LEFT | DT_SINGLELINE;
565 break;
567 case SS_LEFTNOWORDWRAP:
568 wFormat = DT_LEFT | DT_EXPANDTABS;
569 break;
571 default:
572 return;
575 if (style & SS_NOPREFIX)
576 wFormat |= DT_NOPREFIX;
578 if ((style & SS_TYPEMASK) != SS_SIMPLE)
580 if (style & SS_CENTERIMAGE)
581 wFormat |= DT_SINGLELINE | DT_VCENTER;
582 if (style & SS_EDITCONTROL)
583 wFormat |= DT_EDITCONTROL;
584 if (style & SS_ENDELLIPSIS)
585 wFormat |= DT_SINGLELINE | DT_END_ELLIPSIS;
586 if (style & SS_PATHELLIPSIS)
587 wFormat |= DT_SINGLELINE | DT_PATH_ELLIPSIS;
588 if (style & SS_WORDELLIPSIS)
589 wFormat |= DT_SINGLELINE | DT_WORD_ELLIPSIS;
592 if ((hFont = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET )))
593 hOldFont = (HFONT)SelectObject( hdc, hFont );
595 /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
596 brush is not used */
597 hBrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
599 if ((style & SS_TYPEMASK) != SS_SIMPLE)
601 FillRect( hdc, &rc, hBrush );
602 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
605 if (!(len = SendMessageW( hwnd, WM_GETTEXTLENGTH, 0, 0 ))) return;
606 if (!(text = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return;
607 SendMessageW( hwnd, WM_GETTEXT, len + 1, (LPARAM)text );
609 if (((style & SS_TYPEMASK) == SS_SIMPLE) && (style & SS_NOPREFIX))
611 /* Windows uses the faster ExtTextOut() to draw the text and
612 to paint the whole client rectangle with the text background
613 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
614 ExtTextOutW( hdc, rc.left, rc.top, ETO_CLIPPED | ETO_OPAQUE,
615 &rc, text, len, NULL );
617 else
619 DrawTextW( hdc, text, -1, &rc, wFormat );
622 HeapFree( GetProcessHeap(), 0, text );
624 if (hFont)
625 SelectObject( hdc, hOldFont );
628 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
630 RECT rc;
631 HBRUSH hBrush;
633 GetClientRect( hwnd, &rc);
635 switch (style & SS_TYPEMASK)
637 case SS_BLACKRECT:
638 hBrush = CreateSolidBrush(color_3ddkshadow);
639 FillRect( hdc, &rc, hBrush );
640 break;
641 case SS_GRAYRECT:
642 hBrush = CreateSolidBrush(color_3dshadow);
643 FillRect( hdc, &rc, hBrush );
644 break;
645 case SS_WHITERECT:
646 hBrush = CreateSolidBrush(color_3dhighlight);
647 FillRect( hdc, &rc, hBrush );
648 break;
649 case SS_BLACKFRAME:
650 hBrush = CreateSolidBrush(color_3ddkshadow);
651 FrameRect( hdc, &rc, hBrush );
652 break;
653 case SS_GRAYFRAME:
654 hBrush = CreateSolidBrush(color_3dshadow);
655 FrameRect( hdc, &rc, hBrush );
656 break;
657 case SS_WHITEFRAME:
658 hBrush = CreateSolidBrush(color_3dhighlight);
659 FrameRect( hdc, &rc, hBrush );
660 break;
661 default:
662 return;
664 DeleteObject( hBrush );
668 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
670 RECT rc;
671 HBRUSH hbrush;
672 HICON hIcon;
673 INT x, y;
675 GetClientRect( hwnd, &rc );
676 hbrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC,
677 (WPARAM)hdc, (LPARAM)hwnd );
678 FillRect( hdc, &rc, hbrush );
679 hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
680 if (style & SS_CENTERIMAGE)
682 CURSORICONINFO *info = hIcon ? (CURSORICONINFO *)GlobalLock16(HICON_16(hIcon)) : NULL;
683 x = (rc.right - rc.left)/2 - (info ? info->nWidth/2 : 0);
684 y = (rc.bottom - rc.top)/2 - (info ? info->nHeight/2 : 0);
686 else
688 x = rc.left;
689 y = rc.top;
691 if (hIcon)
692 DrawIcon( hdc, x, y, hIcon );
695 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
697 HDC hMemDC;
698 HBITMAP hBitmap, oldbitmap;
700 /* message is still sent, even if the returned brush is not used */
701 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC,
702 (WPARAM)hdc, (LPARAM)hwnd );
704 if ((hBitmap = (HBITMAP)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
706 INT x, y;
707 BITMAP bm;
709 if(GetObjectType(hBitmap) != OBJ_BITMAP) return;
710 if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
711 GetObjectW(hBitmap, sizeof(bm), &bm);
712 oldbitmap = SelectObject(hMemDC, hBitmap);
713 if (style & SS_CENTERIMAGE)
715 RECT rcClient;
716 GetClientRect(hwnd, &rcClient);
717 x = (rcClient.right - rcClient.left)/2 - bm.bmWidth/2;
718 y = (rcClient.bottom - rcClient.top)/2 - bm.bmHeight/2;
720 else
722 x = 0;
723 y = 0;
725 BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
726 SRCCOPY);
727 SelectObject(hMemDC, oldbitmap);
728 DeleteDC(hMemDC);
733 static void STATIC_PaintEnhMetafn(HWND hwnd, HDC hdc, DWORD style )
735 HENHMETAFILE hEnhMetaFile;
736 RECT rc;
737 HBRUSH hbrush;
739 GetClientRect(hwnd, &rc);
740 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
741 FillRect(hdc, &rc, hbrush);
742 if ((hEnhMetaFile = (HENHMETAFILE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
744 /* The control's current font is not selected into the
745 device context! */
746 if (GetObjectType(hEnhMetaFile) == OBJ_ENHMETAFILE)
747 PlayEnhMetaFile(hdc, hEnhMetaFile, &rc);
752 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
754 RECT rc;
756 GetClientRect( hwnd, &rc );
757 switch (style & SS_TYPEMASK)
759 case SS_ETCHEDHORZ:
760 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
761 break;
762 case SS_ETCHEDVERT:
763 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
764 break;
765 case SS_ETCHEDFRAME:
766 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
767 break;