dmime/tests: Test tempo track Play and DMUS_PMSGT_TEMPO messages.
[wine.git] / dlls / user32 / static.c
blobf3953f7610aabe33ca9cc15fdce61c69a8d4ac20
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:
21 * - Controls with SS_SIMPLE but without SS_NOPREFIX:
22 * The text should not be changed. Windows doesn't clear the
23 * client rectangle, so the new text must be larger than the old one.
24 * - The SS_RIGHTJUST style is currently not implemented by Windows
25 * (or it does something different than documented).
27 * TODO:
28 * - Animated cursors
31 #include <stdarg.h>
33 #include "windef.h"
34 #include "winbase.h"
35 #include "wingdi.h"
36 #include "controls.h"
37 #include "user_private.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(static);
42 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, HBRUSH hbrush, DWORD style );
43 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, HBRUSH hbrush, DWORD style );
44 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, HBRUSH hbrush, DWORD style );
45 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, HBRUSH hbrush, DWORD style );
46 static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc, HBRUSH hbrush, DWORD style );
47 static void STATIC_PaintEnhMetafn( HWND hwnd, HDC hdc, HBRUSH hbrush, DWORD style );
48 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, HBRUSH hbrush, DWORD style );
50 static COLORREF color_3dshadow, color_3ddkshadow, color_3dhighlight;
52 /* offsets for GetWindowLong for static private information */
53 #define HFONT_GWL_OFFSET 0
54 #define HICON_GWL_OFFSET (sizeof(HFONT))
56 typedef void (*pfPaint)( HWND hwnd, HDC hdc, HBRUSH hbrush, DWORD style );
58 static const pfPaint staticPaintFunc[SS_TYPEMASK+1] =
60 STATIC_PaintTextfn, /* SS_LEFT */
61 STATIC_PaintTextfn, /* SS_CENTER */
62 STATIC_PaintTextfn, /* SS_RIGHT */
63 STATIC_PaintIconfn, /* SS_ICON */
64 STATIC_PaintRectfn, /* SS_BLACKRECT */
65 STATIC_PaintRectfn, /* SS_GRAYRECT */
66 STATIC_PaintRectfn, /* SS_WHITERECT */
67 STATIC_PaintRectfn, /* SS_BLACKFRAME */
68 STATIC_PaintRectfn, /* SS_GRAYFRAME */
69 STATIC_PaintRectfn, /* SS_WHITEFRAME */
70 NULL, /* SS_USERITEM */
71 STATIC_PaintTextfn, /* SS_SIMPLE */
72 STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
73 STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
74 STATIC_PaintBitmapfn, /* SS_BITMAP */
75 STATIC_PaintEnhMetafn, /* SS_ENHMETAFILE */
76 NULL, /* SS_ETCHEDHORZ */
77 NULL, /* SS_ETCHEDVERT */
78 STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
82 /***********************************************************************
83 * STATIC_SetIcon
85 * Set the icon for an SS_ICON control.
87 static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
89 HICON prevIcon;
90 SIZE size;
92 if (hicon && !get_icon_size( hicon, &size ))
94 WARN("hicon != 0, but invalid\n");
95 return 0;
97 prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
98 if (hicon && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
100 /* Windows currently doesn't implement SS_RIGHTJUST */
102 if ((style & SS_RIGHTJUST) != 0)
104 RECT wr;
105 GetWindowRect(hwnd, &wr);
106 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
107 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
109 else */
111 NtUserSetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
114 return prevIcon;
117 /***********************************************************************
118 * STATIC_SetBitmap
120 * Set the bitmap for an SS_BITMAP control.
122 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
124 HBITMAP hOldBitmap;
126 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
127 WARN("hBitmap != 0, but it's not a bitmap\n");
128 return 0;
130 hOldBitmap = (HBITMAP)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hBitmap );
131 if (hBitmap && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
133 BITMAP bm;
134 GetObjectW(hBitmap, sizeof(bm), &bm);
135 /* Windows currently doesn't implement SS_RIGHTJUST */
137 if ((style & SS_RIGHTJUST) != 0)
139 RECT wr;
140 GetWindowRect(hwnd, &wr);
141 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
142 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
144 else */
146 NtUserSetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
147 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
151 return hOldBitmap;
154 /***********************************************************************
155 * STATIC_SetEnhMetaFile
157 * Set the enhanced metafile for an SS_ENHMETAFILE control.
159 static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
161 if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE) {
162 WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
163 return 0;
165 return (HENHMETAFILE)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hEnhMetaFile );
168 /***********************************************************************
169 * STATIC_GetImage
171 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
172 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
174 static HANDLE STATIC_GetImage( HWND hwnd, WPARAM wParam, DWORD style )
176 switch(style & SS_TYPEMASK)
178 case SS_ICON:
179 if ((wParam != IMAGE_ICON) &&
180 (wParam != IMAGE_CURSOR)) return NULL;
181 break;
182 case SS_BITMAP:
183 if (wParam != IMAGE_BITMAP) return NULL;
184 break;
185 case SS_ENHMETAFILE:
186 if (wParam != IMAGE_ENHMETAFILE) return NULL;
187 break;
188 default:
189 return NULL;
191 return (HANDLE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
194 /***********************************************************************
195 * STATIC_LoadIconA
197 * Load the icon for an SS_ICON control.
199 static HICON STATIC_LoadIconA( HINSTANCE hInstance, LPCSTR name, DWORD style )
201 HICON hicon = 0;
203 if (hInstance && ((ULONG_PTR)hInstance >> 16))
205 if ((style & SS_REALSIZEIMAGE) != 0)
206 hicon = LoadImageA(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
207 else
209 hicon = LoadIconA( hInstance, name );
210 if (!hicon) hicon = LoadCursorA( hInstance, name );
213 if (!hicon) hicon = LoadIconA( 0, name );
214 /* Windows doesn't try to load a standard cursor,
215 probably because most IDs for standard cursors conflict
216 with the IDs for standard icons anyway */
217 return hicon;
219 /***********************************************************************
220 * STATIC_SendWmCtlColorStatic
222 * Sends WM_CTLCOLORSTATIC message and returns brush to be used for painting.
224 static HBRUSH STATIC_SendWmCtlColorStatic(HWND hwnd, HDC hdc)
226 HBRUSH hBrush;
227 HWND parent = GetParent(hwnd);
229 if (!parent) parent = hwnd;
230 hBrush = (HBRUSH) SendMessageW( parent, WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
231 if (!hBrush) /* did the app forget to call DefWindowProc ? */
232 hBrush = (HBRUSH)DefWindowProcW( parent, WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd);
233 return hBrush;
236 /***********************************************************************
237 * STATIC_LoadIconW
239 * Load the icon for an SS_ICON control.
241 static HICON STATIC_LoadIconW( HINSTANCE hInstance, LPCWSTR name, DWORD style )
243 HICON hicon = 0;
245 if (hInstance && ((ULONG_PTR)hInstance >> 16))
247 if ((style & SS_REALSIZEIMAGE) != 0)
248 hicon = LoadImageW(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
249 else
251 hicon = LoadIconW( hInstance, name );
252 if (!hicon) hicon = LoadCursorW( hInstance, name );
255 if (!hicon) hicon = LoadIconW( 0, name );
256 /* Windows doesn't try to load a standard cursor,
257 probably because most IDs for standard cursors conflict
258 with the IDs for standard icons anyway */
259 return hicon;
262 /***********************************************************************
263 * STATIC_TryPaintFcn
265 * Try to immediately paint the control.
267 static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
269 if (IsWindowVisible(hwnd))
271 RECT rc;
272 HDC hdc;
273 HRGN hrgn;
274 HBRUSH hbrush;
275 LONG style = full_style & SS_TYPEMASK;
277 GetClientRect( hwnd, &rc );
278 hdc = NtUserGetDC( hwnd );
279 hrgn = set_control_clipping( hdc, &rc );
280 hbrush = STATIC_SendWmCtlColorStatic( hwnd, hdc );
281 if (staticPaintFunc[style])
282 (staticPaintFunc[style])( hwnd, hdc, hbrush, full_style );
283 SelectClipRgn( hdc, hrgn );
284 if (hrgn) DeleteObject( hrgn );
285 NtUserReleaseDC( hwnd, hdc );
289 static VOID STATIC_InitColours(void)
291 color_3ddkshadow = GetSysColor(COLOR_3DDKSHADOW);
292 color_3dshadow = GetSysColor(COLOR_3DSHADOW);
293 color_3dhighlight = GetSysColor(COLOR_3DHIGHLIGHT);
296 /***********************************************************************
297 * hasTextStyle
299 * Tests if the control displays text.
301 static BOOL hasTextStyle( DWORD style )
303 switch(style & SS_TYPEMASK)
305 case SS_SIMPLE:
306 case SS_LEFT:
307 case SS_LEFTNOWORDWRAP:
308 case SS_CENTER:
309 case SS_RIGHT:
310 case SS_OWNERDRAW:
311 return TRUE;
314 return FALSE;
317 /***********************************************************************
318 * StaticWndProc_common
320 LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL unicode )
322 LRESULT lResult = 0;
323 LONG full_style = GetWindowLongW( hwnd, GWL_STYLE );
324 LONG style = full_style & SS_TYPEMASK;
326 if (!IsWindow( hwnd )) return 0;
328 switch (uMsg)
330 case WM_CREATE:
331 if (style < 0L || style > SS_TYPEMASK)
333 ERR("Unknown style 0x%02lx\n", style );
334 return -1;
336 STATIC_InitColours();
337 break;
339 case WM_NCDESTROY:
340 if (style == SS_ICON) {
342 * FIXME
343 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
345 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
346 * had already been loaded by the application the last thing we want to do is
347 * GlobalFree16 the handle.
349 break;
351 else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
352 DefWindowProcA(hwnd, uMsg, wParam, lParam);
354 case WM_ERASEBKGND:
355 /* do all painting in WM_PAINT like Windows does */
356 return 1;
358 case WM_PRINTCLIENT:
359 case WM_PAINT:
361 PAINTSTRUCT ps;
362 RECT rect;
363 HDC hdc = wParam ? (HDC)wParam : NtUserBeginPaint( hwnd, &ps );
364 HRGN hrgn;
365 HBRUSH hbrush;
367 GetClientRect( hwnd, &rect );
368 hrgn = set_control_clipping( hdc, &rect );
369 hbrush = STATIC_SendWmCtlColorStatic( hwnd, hdc );
370 if (staticPaintFunc[style])
371 (staticPaintFunc[style])( hwnd, hdc, hbrush, full_style );
372 SelectClipRgn( hdc, hrgn );
373 if (hrgn) DeleteObject( hrgn );
374 if (!wParam) NtUserEndPaint( hwnd, &ps );
376 break;
378 case WM_ENABLE:
379 STATIC_TryPaintFcn( hwnd, full_style );
380 if (full_style & SS_NOTIFY) {
381 if (wParam) {
382 SendMessageW( GetParent(hwnd), WM_COMMAND,
383 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_ENABLE ), (LPARAM)hwnd);
385 else {
386 SendMessageW( GetParent(hwnd), WM_COMMAND,
387 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DISABLE ), (LPARAM)hwnd);
390 break;
392 case WM_SYSCOLORCHANGE:
393 STATIC_InitColours();
394 STATIC_TryPaintFcn( hwnd, full_style );
395 break;
397 case WM_NCCREATE:
399 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
401 if (full_style & SS_SUNKEN || style == SS_ETCHEDHORZ || style == SS_ETCHEDVERT)
402 SetWindowLongW( hwnd, GWL_EXSTYLE,
403 GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
405 if (style == SS_ETCHEDHORZ || style == SS_ETCHEDVERT)
407 RECT rc;
408 GetClientRect(hwnd, &rc);
409 if (style == SS_ETCHEDHORZ)
410 rc.bottom = rc.top;
411 else
412 rc.right = rc.left;
413 AdjustWindowRectEx(&rc, full_style, FALSE, GetWindowLongW(hwnd, GWL_EXSTYLE));
414 NtUserSetWindowPos( hwnd, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
415 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
418 switch (style) {
419 case SS_ICON:
421 const WCHAR *name = cs->lpszName;
422 HICON hIcon;
424 if (!unicode)
426 const char *nameA = (const char *)name;
427 if (nameA && nameA[0] == '\xff')
428 name = MAKEINTRESOURCEW(MAKEWORD(nameA[1], nameA[2]));
430 else if (name && name[0] == 0xffff)
432 name = MAKEINTRESOURCEW(name[1]);
435 if (unicode || IS_INTRESOURCE(name))
436 hIcon = STATIC_LoadIconW(cs->hInstance, name, full_style);
437 else
438 hIcon = STATIC_LoadIconA(cs->hInstance, (const char *)name, full_style);
439 STATIC_SetIcon(hwnd, hIcon, full_style);
441 break;
442 case SS_BITMAP:
443 if ((ULONG_PTR)cs->hInstance >> 16)
445 const WCHAR *name = cs->lpszName;
446 HBITMAP hBitmap;
448 if (!unicode)
450 const char *nameA = (const char *)name;
451 if (nameA && nameA[0] == '\xff')
452 name = MAKEINTRESOURCEW(MAKEWORD(nameA[1], nameA[2]));
454 else if (name && name[0] == 0xffff)
456 name = MAKEINTRESOURCEW(name[1]);
459 if (unicode || IS_INTRESOURCE(name))
460 hBitmap = LoadBitmapW(cs->hInstance, name);
461 else
462 hBitmap = LoadBitmapA(cs->hInstance, (const char *)name);
463 STATIC_SetBitmap(hwnd, hBitmap, full_style);
465 break;
467 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
468 the enhanced metafile that was specified as the window text. */
470 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
471 DefWindowProcA(hwnd, uMsg, wParam, lParam);
473 case WM_SETTEXT:
474 if (hasTextStyle( full_style ))
476 if (unicode)
477 lResult = DefWindowProcW( hwnd, uMsg, wParam, lParam );
478 else
479 lResult = DefWindowProcA( hwnd, uMsg, wParam, lParam );
480 STATIC_TryPaintFcn( hwnd, full_style );
482 break;
484 case WM_SETFONT:
485 if (hasTextStyle( full_style ))
487 SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, wParam );
488 if (LOWORD(lParam))
489 NtUserRedrawWindow( hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE |
490 RDW_UPDATENOW | RDW_ALLCHILDREN );
492 break;
494 case WM_GETFONT:
495 return GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
497 case WM_NCHITTEST:
498 if (full_style & SS_NOTIFY)
499 return HTCLIENT;
500 else
501 return HTTRANSPARENT;
503 case WM_GETDLGCODE:
504 return DLGC_STATIC;
506 case WM_LBUTTONDOWN:
507 case WM_NCLBUTTONDOWN:
508 if (full_style & SS_NOTIFY)
509 SendMessageW( GetParent(hwnd), WM_COMMAND,
510 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_CLICKED ), (LPARAM)hwnd);
511 return 0;
513 case WM_LBUTTONDBLCLK:
514 case WM_NCLBUTTONDBLCLK:
515 if (full_style & SS_NOTIFY)
516 SendMessageW( GetParent(hwnd), WM_COMMAND,
517 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DBLCLK ), (LPARAM)hwnd);
518 return 0;
520 case STM_GETIMAGE:
521 return (LRESULT)STATIC_GetImage( hwnd, wParam, full_style );
523 case STM_GETICON:
524 return (LRESULT)STATIC_GetImage( hwnd, IMAGE_ICON, full_style );
526 case STM_SETIMAGE:
527 switch(wParam) {
528 case IMAGE_BITMAP:
529 if (style != SS_BITMAP) return 0;
530 lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
531 break;
532 case IMAGE_ENHMETAFILE:
533 if (style != SS_ENHMETAFILE) return 0;
534 lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
535 break;
536 case IMAGE_ICON:
537 case IMAGE_CURSOR:
538 if (style != SS_ICON) return 0;
539 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
540 break;
541 default:
542 FIXME("STM_SETIMAGE: Unhandled type %Ix\n", wParam);
543 break;
545 STATIC_TryPaintFcn( hwnd, full_style );
546 break;
548 case STM_SETICON:
549 if (style != SS_ICON) return 0;
550 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
551 STATIC_TryPaintFcn( hwnd, full_style );
552 break;
554 default:
555 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
556 DefWindowProcA(hwnd, uMsg, wParam, lParam);
558 return lResult;
561 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, HBRUSH hbrush, DWORD style )
563 DRAWITEMSTRUCT dis;
564 HFONT font, oldFont = NULL;
565 UINT id = (UINT)GetWindowLongPtrW( hwnd, GWLP_ID );
567 dis.CtlType = ODT_STATIC;
568 dis.CtlID = id;
569 dis.itemID = 0;
570 dis.itemAction = ODA_DRAWENTIRE;
571 dis.itemState = IsWindowEnabled(hwnd) ? 0 : ODS_DISABLED;
572 dis.hwndItem = hwnd;
573 dis.hDC = hdc;
574 dis.itemData = 0;
575 GetClientRect( hwnd, &dis.rcItem );
577 font = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
578 if (font) oldFont = SelectObject( hdc, font );
579 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
580 if (font) SelectObject( hdc, oldFont );
583 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, HBRUSH hbrush, DWORD style )
585 RECT rc;
586 HFONT hFont, hOldFont = NULL;
587 UINT format;
588 INT len, buf_size;
589 WCHAR *text;
591 GetClientRect( hwnd, &rc);
593 switch (style & SS_TYPEMASK)
595 case SS_LEFT:
596 format = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
597 break;
599 case SS_CENTER:
600 format = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
601 break;
603 case SS_RIGHT:
604 format = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
605 break;
607 case SS_SIMPLE:
608 format = DT_LEFT | DT_SINGLELINE;
609 break;
611 case SS_LEFTNOWORDWRAP:
612 format = DT_LEFT | DT_EXPANDTABS;
613 break;
615 default:
616 return;
619 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_RIGHT)
620 format = DT_RIGHT | (format & ~(DT_LEFT | DT_CENTER));
622 if (style & SS_NOPREFIX)
623 format |= DT_NOPREFIX;
625 if ((style & SS_TYPEMASK) != SS_SIMPLE)
627 if (style & SS_CENTERIMAGE)
628 format |= DT_SINGLELINE | DT_VCENTER;
629 if (style & SS_EDITCONTROL)
630 format |= DT_EDITCONTROL;
631 if (style & SS_ENDELLIPSIS)
632 format |= DT_SINGLELINE | DT_END_ELLIPSIS;
633 if (style & SS_PATHELLIPSIS)
634 format |= DT_SINGLELINE | DT_PATH_ELLIPSIS;
635 if (style & SS_WORDELLIPSIS)
636 format |= DT_SINGLELINE | DT_WORD_ELLIPSIS;
639 if ((hFont = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET )))
640 hOldFont = SelectObject( hdc, hFont );
642 if ((style & SS_TYPEMASK) != SS_SIMPLE)
644 FillRect( hdc, &rc, hbrush );
645 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
648 buf_size = 256;
649 if (!(text = HeapAlloc( GetProcessHeap(), 0, buf_size * sizeof(WCHAR) )))
650 goto no_TextOut;
652 while ((len = NtUserInternalGetWindowText( hwnd, text, buf_size )) == buf_size - 1)
654 buf_size *= 2;
655 if (!(text = HeapReAlloc( GetProcessHeap(), 0, text, buf_size * sizeof(WCHAR) )))
656 goto no_TextOut;
659 if (!len) goto no_TextOut;
661 if (((style & SS_TYPEMASK) == SS_SIMPLE) && (style & SS_NOPREFIX))
663 /* Windows uses the faster ExtTextOut() to draw the text and
664 to paint the whole client rectangle with the text background
665 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
666 ExtTextOutW( hdc, rc.left, rc.top, ETO_CLIPPED | ETO_OPAQUE,
667 &rc, text, len, NULL );
669 else
671 DrawTextW( hdc, text, -1, &rc, format );
674 no_TextOut:
675 HeapFree( GetProcessHeap(), 0, text );
677 if (hFont)
678 SelectObject( hdc, hOldFont );
681 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, HBRUSH hbrush, DWORD style )
683 RECT rc;
685 GetClientRect( hwnd, &rc);
687 /* FIXME: send WM_CTLCOLORSTATIC */
688 switch (style & SS_TYPEMASK)
690 case SS_BLACKRECT:
691 hbrush = CreateSolidBrush(color_3ddkshadow);
692 FillRect( hdc, &rc, hbrush );
693 break;
694 case SS_GRAYRECT:
695 hbrush = CreateSolidBrush(color_3dshadow);
696 FillRect( hdc, &rc, hbrush );
697 break;
698 case SS_WHITERECT:
699 hbrush = CreateSolidBrush(color_3dhighlight);
700 FillRect( hdc, &rc, hbrush );
701 break;
702 case SS_BLACKFRAME:
703 hbrush = CreateSolidBrush(color_3ddkshadow);
704 FrameRect( hdc, &rc, hbrush );
705 break;
706 case SS_GRAYFRAME:
707 hbrush = CreateSolidBrush(color_3dshadow);
708 FrameRect( hdc, &rc, hbrush );
709 break;
710 case SS_WHITEFRAME:
711 hbrush = CreateSolidBrush(color_3dhighlight);
712 FrameRect( hdc, &rc, hbrush );
713 break;
714 default:
715 return;
717 DeleteObject( hbrush );
721 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, HBRUSH hbrush, DWORD style )
723 RECT rc, iconRect;
724 HICON hIcon;
725 SIZE size;
727 GetClientRect( hwnd, &rc );
728 hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
729 if (!hIcon || !get_icon_size( hIcon, &size ))
731 FillRect(hdc, &rc, hbrush);
733 else
735 if (style & SS_CENTERIMAGE)
737 iconRect.left = (rc.right - rc.left) / 2 - size.cx / 2;
738 iconRect.top = (rc.bottom - rc.top) / 2 - size.cy / 2;
739 iconRect.right = iconRect.left + size.cx;
740 iconRect.bottom = iconRect.top + size.cy;
742 else
743 iconRect = rc;
744 FillRect( hdc, &rc, hbrush );
745 NtUserDrawIconEx( hdc, iconRect.left, iconRect.top, hIcon, iconRect.right - iconRect.left,
746 iconRect.bottom - iconRect.top, 0, NULL, DI_NORMAL );
750 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, HBRUSH hbrush, DWORD style )
752 HDC hMemDC;
753 HBITMAP hBitmap, oldbitmap;
755 if ((hBitmap = (HBITMAP)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET ))
756 && (GetObjectType(hBitmap) == OBJ_BITMAP)
757 && (hMemDC = CreateCompatibleDC( hdc )))
759 BITMAP bm;
760 RECT rcClient;
762 GetObjectW(hBitmap, sizeof(bm), &bm);
763 oldbitmap = SelectObject(hMemDC, hBitmap);
765 GetClientRect(hwnd, &rcClient);
766 if (style & SS_CENTERIMAGE)
768 hbrush = CreateSolidBrush(GetPixel(hMemDC, 0, 0));
770 FillRect(hdc, &rcClient, hbrush);
772 rcClient.left = (rcClient.right - rcClient.left)/2 - bm.bmWidth/2;
773 rcClient.top = (rcClient.bottom - rcClient.top)/2 - bm.bmHeight/2;
774 rcClient.right = rcClient.left + bm.bmWidth;
775 rcClient.bottom = rcClient.top + bm.bmHeight;
777 DeleteObject(hbrush);
779 StretchBlt(hdc, rcClient.left, rcClient.top, rcClient.right - rcClient.left,
780 rcClient.bottom - rcClient.top, hMemDC,
781 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
782 SelectObject(hMemDC, oldbitmap);
783 DeleteDC(hMemDC);
788 static void STATIC_PaintEnhMetafn(HWND hwnd, HDC hdc, HBRUSH hbrush, DWORD style )
790 HENHMETAFILE hEnhMetaFile;
791 RECT rc;
793 GetClientRect(hwnd, &rc);
794 FillRect(hdc, &rc, hbrush);
795 if ((hEnhMetaFile = (HENHMETAFILE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
797 /* The control's current font is not selected into the
798 device context! */
799 if (GetObjectType(hEnhMetaFile) == OBJ_ENHMETAFILE)
800 PlayEnhMetaFile(hdc, hEnhMetaFile, &rc);
805 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, HBRUSH hbrush, DWORD style )
807 RECT rc;
809 GetClientRect( hwnd, &rc );
810 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);