static control: Better STM_GETIMAGE.
[wine.git] / dlls / user / static.c
blobbd28668f0c49d8d6fa512de4545fd0aff2897ab6
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_RIGHTJUST
34 * Notifications
35 * - STN_DISABLE
36 * - STN_ENABLE
38 * Messages
39 * - STM_SETIMAGE: IMAGE_CURSOR
42 #include <stdarg.h>
44 #include "windef.h"
45 #include "winbase.h"
46 #include "wingdi.h"
47 #include "wine/winuser16.h"
48 #include "controls.h"
49 #include "user_private.h"
50 #include "wine/debug.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(static);
54 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style );
55 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style );
56 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style );
57 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style );
58 static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc, DWORD style );
59 static void STATIC_PaintEnhMetafn( HWND hwnd, HDC hdc, DWORD style );
60 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style );
61 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
62 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
64 static COLORREF color_3dshadow, color_3ddkshadow, color_3dhighlight;
66 /* offsets for GetWindowLong for static private information */
67 #define HFONT_GWL_OFFSET 0
68 #define HICON_GWL_OFFSET (sizeof(HFONT))
69 #define STATIC_EXTRA_BYTES (HICON_GWL_OFFSET + sizeof(HICON))
71 typedef void (*pfPaint)( HWND hwnd, HDC hdc, DWORD style );
73 static pfPaint staticPaintFunc[SS_TYPEMASK+1] =
75 STATIC_PaintTextfn, /* SS_LEFT */
76 STATIC_PaintTextfn, /* SS_CENTER */
77 STATIC_PaintTextfn, /* SS_RIGHT */
78 STATIC_PaintIconfn, /* SS_ICON */
79 STATIC_PaintRectfn, /* SS_BLACKRECT */
80 STATIC_PaintRectfn, /* SS_GRAYRECT */
81 STATIC_PaintRectfn, /* SS_WHITERECT */
82 STATIC_PaintRectfn, /* SS_BLACKFRAME */
83 STATIC_PaintRectfn, /* SS_GRAYFRAME */
84 STATIC_PaintRectfn, /* SS_WHITEFRAME */
85 NULL, /* SS_USERITEM */
86 STATIC_PaintTextfn, /* SS_SIMPLE */
87 STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
88 STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
89 STATIC_PaintBitmapfn, /* SS_BITMAP */
90 STATIC_PaintEnhMetafn, /* SS_ENHMETAFILE */
91 STATIC_PaintEtchedfn, /* SS_ETCHEDHORZ */
92 STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
93 STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
97 /*********************************************************************
98 * static class descriptor
100 const struct builtin_class_descr STATIC_builtin_class =
102 "Static", /* name */
103 CS_DBLCLKS | CS_PARENTDC, /* style */
104 StaticWndProcA, /* procA */
105 StaticWndProcW, /* procW */
106 STATIC_EXTRA_BYTES, /* extra */
107 IDC_ARROW, /* cursor */
108 0 /* brush */
112 /***********************************************************************
113 * STATIC_SetIcon
115 * Set the icon for an SS_ICON control.
117 static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
119 HICON prevIcon;
120 CURSORICONINFO * info;
122 if ((style & SS_TYPEMASK) != SS_ICON) return 0;
123 info = hicon?(CURSORICONINFO *) GlobalLock16(HICON_16(hicon)):NULL;
124 if (hicon && !info) {
125 WARN("hicon != 0, but info == 0\n");
126 return 0;
128 prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
129 if (hicon && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
131 /* Windows currently doesn't implement SS_RIGHTJUST */
133 if ((style & SS_RIGHTJUST) != 0)
135 RECT wr;
136 GetWindowRect(hwnd, &wr);
137 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
138 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
140 else */
142 SetWindowPos( hwnd, 0, 0, 0, info->nWidth, info->nHeight,
143 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
146 if (info) GlobalUnlock16(HICON_16(hicon));
147 return prevIcon;
150 /***********************************************************************
151 * STATIC_SetBitmap
153 * Set the bitmap for an SS_BITMAP control.
155 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
157 HBITMAP hOldBitmap;
159 if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
160 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
161 WARN("hBitmap != 0, but it's not a bitmap\n");
162 return 0;
164 hOldBitmap = (HBITMAP)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hBitmap );
165 if (hBitmap && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
167 BITMAP bm;
168 GetObjectW(hBitmap, sizeof(bm), &bm);
169 /* Windows currently doesn't implement SS_RIGHTJUST */
171 if ((style & SS_RIGHTJUST) != 0)
173 RECT wr;
174 GetWindowRect(hwnd, &wr);
175 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
176 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
178 else */
180 SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
181 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
185 return hOldBitmap;
188 /***********************************************************************
189 * STATIC_SetEnhMetaFile
191 * Set the enhanced metafile for an SS_ENHMETAFILE control.
193 static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
195 if ((style & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
196 if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE) {
197 WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
198 return 0;
200 return (HENHMETAFILE)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hEnhMetaFile );
203 /***********************************************************************
204 * STATIC_GetImage
206 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
207 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
209 static HANDLE STATIC_GetImage( HWND hwnd, WPARAM wParam, DWORD style )
211 switch(style & SS_TYPEMASK)
213 case SS_ICON:
214 if ((wParam != IMAGE_ICON) &&
215 (wParam != IMAGE_CURSOR)) return NULL;
216 break;
217 case SS_BITMAP:
218 if (wParam != IMAGE_BITMAP) return NULL;
219 break;
220 case SS_ENHMETAFILE:
221 if (wParam != IMAGE_ENHMETAFILE) return NULL;
222 break;
223 default:
224 return NULL;
226 return (HANDLE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
229 /***********************************************************************
230 * STATIC_LoadIconA
232 * Load the icon for an SS_ICON control.
234 static HICON STATIC_LoadIconA( HWND hwnd, LPCSTR name, DWORD style )
236 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
237 if ((style & SS_REALSIZEIMAGE) != 0)
239 return LoadImageA(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
241 else
243 HICON hicon = LoadIconA( hInstance, name );
244 if (!hicon) hicon = LoadCursorA( hInstance, name );
245 if (!hicon) hicon = LoadIconA( 0, name );
246 /* Windows doesn't try to load a standard cursor,
247 probably because most IDs for standard cursors conflict
248 with the IDs for standard icons anyway */
249 return hicon;
253 /***********************************************************************
254 * STATIC_LoadIconW
256 * Load the icon for an SS_ICON control.
258 static HICON STATIC_LoadIconW( HWND hwnd, LPCWSTR name, DWORD style )
260 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
261 if ((style & SS_REALSIZEIMAGE) != 0)
263 return LoadImageW(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
265 else
267 HICON hicon = LoadIconW( hInstance, name );
268 if (!hicon) hicon = LoadCursorW( hInstance, name );
269 if (!hicon) hicon = LoadIconW( 0, name );
270 /* Windows doesn't try to load a standard cursor,
271 probably because most IDs for standard cursors conflict
272 with the IDs for standard icons anyway */
273 return hicon;
277 /***********************************************************************
278 * STATIC_LoadBitmapA
280 * Load the bitmap for an SS_BITMAP control.
282 static HBITMAP STATIC_LoadBitmapA( HWND hwnd, LPCSTR name )
284 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
285 HBITMAP hbitmap = LoadBitmapA( hInstance, name );
286 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
287 hbitmap = LoadBitmapA( 0, name );
288 return hbitmap;
291 /***********************************************************************
292 * STATIC_LoadBitmapW
294 * Load the bitmap for an SS_BITMAP control.
296 static HBITMAP STATIC_LoadBitmapW( HWND hwnd, LPCWSTR name )
298 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
299 HBITMAP hbitmap = LoadBitmapW( hInstance, name );
300 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
301 hbitmap = LoadBitmapW( 0, name );
302 return hbitmap;
305 /***********************************************************************
306 * STATIC_TryPaintFcn
308 * Try to immediately paint the control.
310 static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
312 LONG style = full_style & SS_TYPEMASK;
313 RECT rc;
315 GetClientRect( hwnd, &rc );
316 if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
318 HDC hdc;
319 hdc = GetDC( hwnd );
320 (staticPaintFunc[style])( hwnd, hdc, full_style );
321 ReleaseDC( hwnd, hdc );
325 static HBRUSH STATIC_SendWmCtlColorStatic(HWND hwnd, HDC hdc)
327 HBRUSH hBrush = (HBRUSH) SendMessageW( GetParent(hwnd),
328 WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
329 if (!hBrush) /* did the app forget to call DefWindowProc ? */
331 /* FIXME: DefWindowProc should return different colors if a
332 manifest is present */
333 hBrush = (HBRUSH)DefWindowProcW(GetParent(hwnd), WM_CTLCOLORSTATIC,
334 (WPARAM)hdc, (LPARAM)hwnd);
336 return hBrush;
339 static VOID STATIC_InitColours(void)
341 color_3ddkshadow = GetSysColor(COLOR_3DDKSHADOW);
342 color_3dshadow = GetSysColor(COLOR_3DSHADOW);
343 color_3dhighlight = GetSysColor(COLOR_3DHIGHLIGHT);
346 /***********************************************************************
347 * StaticWndProc_common
349 static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam,
350 LPARAM lParam, BOOL unicode )
352 LRESULT lResult = 0;
353 LONG full_style = GetWindowLongW( hwnd, GWL_STYLE );
354 LONG style = full_style & SS_TYPEMASK;
356 switch (uMsg)
358 case WM_CREATE:
359 if (style < 0L || style > SS_TYPEMASK)
361 ERR("Unknown style 0x%02lx\n", style );
362 return -1;
364 STATIC_InitColours();
365 break;
367 case WM_NCDESTROY:
368 if (style == SS_ICON) {
370 * FIXME
371 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
373 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
374 * had already been loaded by the application the last thing we want to do is
375 * GlobalFree16 the handle.
377 break;
379 else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
380 DefWindowProcA(hwnd, uMsg, wParam, lParam);
382 case WM_PRINTCLIENT:
383 case WM_PAINT:
385 PAINTSTRUCT ps;
386 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
387 if (staticPaintFunc[style])
388 (staticPaintFunc[style])( hwnd, hdc, full_style );
389 if (!wParam) EndPaint(hwnd, &ps);
391 break;
393 case WM_ENABLE:
394 InvalidateRect(hwnd, NULL, TRUE);
395 break;
397 case WM_SYSCOLORCHANGE:
398 STATIC_InitColours();
399 InvalidateRect(hwnd, NULL, TRUE);
400 break;
402 case WM_NCCREATE:
403 if (full_style & SS_SUNKEN)
404 SetWindowLongW( hwnd, GWL_EXSTYLE,
405 GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
407 if(unicode)
408 lParam = (LPARAM)(((LPCREATESTRUCTW)lParam)->lpszName);
409 else
410 lParam = (LPARAM)(((LPCREATESTRUCTA)lParam)->lpszName);
411 /* fall through */
412 case WM_SETTEXT:
413 switch (style) {
414 case SS_ICON:
416 HICON hIcon;
417 if(unicode)
418 hIcon = STATIC_LoadIconW(hwnd, (LPCWSTR)lParam, full_style);
419 else
420 hIcon = STATIC_LoadIconA(hwnd, (LPCSTR)lParam, full_style);
421 /* FIXME : should we also return the previous hIcon here ??? */
422 STATIC_SetIcon(hwnd, hIcon, full_style);
423 break;
425 case SS_BITMAP:
427 HBITMAP hBitmap;
428 if(unicode)
429 hBitmap = STATIC_LoadBitmapW(hwnd, (LPCWSTR)lParam);
430 else
431 hBitmap = STATIC_LoadBitmapA(hwnd, (LPCSTR)lParam);
432 STATIC_SetBitmap(hwnd, hBitmap, full_style);
433 break;
435 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
436 the enhanced metafile that was specified as the window text. */
438 case SS_LEFT:
439 case SS_CENTER:
440 case SS_RIGHT:
441 case SS_SIMPLE:
442 case SS_LEFTNOWORDWRAP:
444 if (HIWORD(lParam))
446 if(unicode)
447 lResult = DefWindowProcW( hwnd, WM_SETTEXT, wParam, lParam );
448 else
449 lResult = DefWindowProcA( hwnd, WM_SETTEXT, wParam, lParam );
451 if (uMsg == WM_SETTEXT)
452 STATIC_TryPaintFcn( hwnd, full_style );
453 break;
455 default:
456 if (HIWORD(lParam))
458 if(unicode)
459 lResult = DefWindowProcW( hwnd, WM_SETTEXT, wParam, lParam );
460 else
461 lResult = DefWindowProcA( hwnd, WM_SETTEXT, wParam, lParam );
463 if(uMsg == WM_SETTEXT)
464 InvalidateRect(hwnd, NULL, TRUE);
466 return 1; /* success. FIXME: check text length */
468 case WM_SETFONT:
469 if ((style == SS_ICON) || (style == SS_BITMAP)) return 0;
470 SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, wParam );
471 if (LOWORD(lParam))
472 InvalidateRect( hwnd, NULL, TRUE );
473 break;
475 case WM_GETFONT:
476 return GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
478 case WM_NCHITTEST:
479 if (full_style & SS_NOTIFY)
480 return HTCLIENT;
481 else
482 return HTTRANSPARENT;
484 case WM_GETDLGCODE:
485 return DLGC_STATIC;
487 case WM_LBUTTONDOWN:
488 case WM_NCLBUTTONDOWN:
489 if (full_style & SS_NOTIFY)
490 SendMessageW( GetParent(hwnd), WM_COMMAND,
491 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_CLICKED ), (LPARAM)hwnd);
492 return 0;
494 case WM_LBUTTONDBLCLK:
495 case WM_NCLBUTTONDBLCLK:
496 if (full_style & SS_NOTIFY)
497 SendMessageW( GetParent(hwnd), WM_COMMAND,
498 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DBLCLK ), (LPARAM)hwnd);
499 return 0;
501 case STM_GETIMAGE:
502 return (LRESULT)STATIC_GetImage( hwnd, wParam, full_style );
504 case STM_GETICON16:
505 case STM_GETICON:
506 return (LRESULT)STATIC_GetImage( hwnd, IMAGE_ICON, full_style );
508 case STM_SETIMAGE:
509 switch(wParam) {
510 case IMAGE_BITMAP:
511 lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
512 break;
513 case IMAGE_CURSOR:
514 FIXME("STM_SETIMAGE: Unhandled type IMAGE_CURSOR\n");
515 break;
516 case IMAGE_ENHMETAFILE:
517 lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
518 break;
519 case IMAGE_ICON:
520 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
521 break;
522 default:
523 FIXME("STM_SETIMAGE: Unhandled type %x\n", wParam);
524 break;
526 InvalidateRect( hwnd, NULL, TRUE );
527 break;
529 case STM_SETICON16:
530 case STM_SETICON:
531 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
532 InvalidateRect( hwnd, NULL, TRUE );
533 break;
535 default:
536 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
537 DefWindowProcA(hwnd, uMsg, wParam, lParam);
539 return lResult;
542 /***********************************************************************
543 * StaticWndProcA
545 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
547 if (!IsWindow( hWnd )) return 0;
548 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, FALSE);
551 /***********************************************************************
552 * StaticWndProcW
554 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
556 if (!IsWindow( hWnd )) return 0;
557 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, TRUE);
560 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
562 DRAWITEMSTRUCT dis;
563 HFONT font, oldFont = NULL;
564 UINT id = (UINT)GetWindowLongPtrW( hwnd, GWLP_ID );
566 dis.CtlType = ODT_STATIC;
567 dis.CtlID = id;
568 dis.itemID = 0;
569 dis.itemAction = ODA_DRAWENTIRE;
570 dis.itemState = IsWindowEnabled(hwnd) ? 0 : ODS_DISABLED;
571 dis.hwndItem = hwnd;
572 dis.hDC = hdc;
573 dis.itemData = 0;
574 GetClientRect( hwnd, &dis.rcItem );
576 font = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
577 if (font) oldFont = SelectObject( hdc, font );
578 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
579 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
580 if (font) SelectObject( hdc, oldFont );
583 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
585 RECT rc;
586 HBRUSH hBrush;
587 HFONT hFont, hOldFont = NULL;
588 WORD wFormat;
589 INT len;
590 WCHAR *text;
592 GetClientRect( hwnd, &rc);
594 switch (style & SS_TYPEMASK)
596 case SS_LEFT:
597 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
598 break;
600 case SS_CENTER:
601 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
602 break;
604 case SS_RIGHT:
605 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
606 break;
608 case SS_SIMPLE:
609 wFormat = DT_LEFT | DT_SINGLELINE;
610 break;
612 case SS_LEFTNOWORDWRAP:
613 wFormat = DT_LEFT | DT_EXPANDTABS;
614 break;
616 default:
617 return;
620 if (style & SS_NOPREFIX)
621 wFormat |= DT_NOPREFIX;
623 if ((style & SS_TYPEMASK) != SS_SIMPLE)
625 if (style & SS_CENTERIMAGE)
626 wFormat |= DT_SINGLELINE | DT_VCENTER;
627 if (style & SS_EDITCONTROL)
628 wFormat |= DT_EDITCONTROL;
629 if (style & SS_ENDELLIPSIS)
630 wFormat |= DT_SINGLELINE | DT_END_ELLIPSIS;
631 if (style & SS_PATHELLIPSIS)
632 wFormat |= DT_SINGLELINE | DT_PATH_ELLIPSIS;
633 if (style & SS_WORDELLIPSIS)
634 wFormat |= DT_SINGLELINE | DT_WORD_ELLIPSIS;
637 if ((hFont = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET )))
638 hOldFont = (HFONT)SelectObject( hdc, hFont );
640 /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
641 brush is not used */
642 hBrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
644 if ((style & SS_TYPEMASK) != SS_SIMPLE)
646 FillRect( hdc, &rc, hBrush );
647 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
650 if (!(len = SendMessageW( hwnd, WM_GETTEXTLENGTH, 0, 0 ))) return;
651 if (!(text = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return;
652 SendMessageW( hwnd, WM_GETTEXT, len + 1, (LPARAM)text );
654 if (((style & SS_TYPEMASK) == SS_SIMPLE) && (style & SS_NOPREFIX))
656 /* Windows uses the faster ExtTextOut() to draw the text and
657 to paint the whole client rectangle with the text background
658 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
659 ExtTextOutW( hdc, rc.left, rc.top, ETO_CLIPPED | ETO_OPAQUE,
660 &rc, text, len, NULL );
662 else
664 DrawTextW( hdc, text, -1, &rc, wFormat );
667 HeapFree( GetProcessHeap(), 0, text );
669 if (hFont)
670 SelectObject( hdc, hOldFont );
673 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
675 RECT rc;
676 HBRUSH hBrush;
678 GetClientRect( hwnd, &rc);
680 switch (style & SS_TYPEMASK)
682 case SS_BLACKRECT:
683 hBrush = CreateSolidBrush(color_3ddkshadow);
684 FillRect( hdc, &rc, hBrush );
685 break;
686 case SS_GRAYRECT:
687 hBrush = CreateSolidBrush(color_3dshadow);
688 FillRect( hdc, &rc, hBrush );
689 break;
690 case SS_WHITERECT:
691 hBrush = CreateSolidBrush(color_3dhighlight);
692 FillRect( hdc, &rc, hBrush );
693 break;
694 case SS_BLACKFRAME:
695 hBrush = CreateSolidBrush(color_3ddkshadow);
696 FrameRect( hdc, &rc, hBrush );
697 break;
698 case SS_GRAYFRAME:
699 hBrush = CreateSolidBrush(color_3dshadow);
700 FrameRect( hdc, &rc, hBrush );
701 break;
702 case SS_WHITEFRAME:
703 hBrush = CreateSolidBrush(color_3dhighlight);
704 FrameRect( hdc, &rc, hBrush );
705 break;
706 default:
707 return;
709 DeleteObject( hBrush );
713 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
715 RECT rc;
716 HBRUSH hbrush;
717 HICON hIcon;
718 INT x, y;
720 GetClientRect( hwnd, &rc );
721 hbrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC,
722 (WPARAM)hdc, (LPARAM)hwnd );
723 FillRect( hdc, &rc, hbrush );
724 hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
725 if (style & SS_CENTERIMAGE)
727 CURSORICONINFO *info = hIcon ? (CURSORICONINFO *)GlobalLock16(HICON_16(hIcon)) : NULL;
728 x = (rc.right - rc.left)/2 - (info ? info->nWidth/2 : 0);
729 y = (rc.bottom - rc.top)/2 - (info ? info->nHeight/2 : 0);
731 else
733 x = rc.left;
734 y = rc.top;
736 if (hIcon)
737 DrawIcon( hdc, x, y, hIcon );
740 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
742 HDC hMemDC;
743 HBITMAP hBitmap, oldbitmap;
745 /* message is still sent, even if the returned brush is not used */
746 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC,
747 (WPARAM)hdc, (LPARAM)hwnd );
749 if ((hBitmap = (HBITMAP)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
751 INT x, y;
752 BITMAP bm;
754 if(GetObjectType(hBitmap) != OBJ_BITMAP) return;
755 if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
756 GetObjectW(hBitmap, sizeof(bm), &bm);
757 oldbitmap = SelectObject(hMemDC, hBitmap);
758 if (style & SS_CENTERIMAGE)
760 RECT rcClient;
761 GetClientRect(hwnd, &rcClient);
762 x = (rcClient.right - rcClient.left)/2 - bm.bmWidth/2;
763 y = (rcClient.bottom - rcClient.top)/2 - bm.bmHeight/2;
765 else
767 x = 0;
768 y = 0;
770 BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
771 SRCCOPY);
772 SelectObject(hMemDC, oldbitmap);
773 DeleteDC(hMemDC);
778 static void STATIC_PaintEnhMetafn(HWND hwnd, HDC hdc, DWORD style )
780 HENHMETAFILE hEnhMetaFile;
781 RECT rc;
782 HBRUSH hbrush;
784 GetClientRect(hwnd, &rc);
785 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
786 FillRect(hdc, &rc, hbrush);
787 if ((hEnhMetaFile = (HENHMETAFILE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
789 /* The control's current font is not selected into the
790 device context! */
791 if (GetObjectType(hEnhMetaFile) == OBJ_ENHMETAFILE)
792 PlayEnhMetaFile(hdc, hEnhMetaFile, &rc);
797 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
799 RECT rc;
801 GetClientRect( hwnd, &rc );
802 switch (style & SS_TYPEMASK)
804 case SS_ETCHEDHORZ:
805 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
806 break;
807 case SS_ETCHEDVERT:
808 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
809 break;
810 case SS_ETCHEDFRAME:
811 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
812 break;