ntdll: Translate signal to trap when trap code is 0 on ARM.
[wine.git] / dlls / comctl32 / static.c
blob5cc02ced97dcec405662b4d62c1c4e79ae2189ab
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 "winuser.h"
37 #include "commctrl.h"
39 #include "wine/debug.h"
41 #include "comctl32.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(static);
45 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style );
46 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style );
47 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style );
48 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style );
49 static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc, DWORD style );
50 static void STATIC_PaintEnhMetafn( HWND hwnd, HDC hdc, DWORD style );
51 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style );
53 /* offsets for GetWindowLong for static private information */
54 #define HFONT_GWL_OFFSET 0
55 #define HICON_GWL_OFFSET (sizeof(HFONT))
56 #define STATIC_EXTRA_BYTES (HICON_GWL_OFFSET + sizeof(HICON))
58 typedef void (*pfPaint)( HWND hwnd, HDC hdc, DWORD style );
60 static const pfPaint staticPaintFunc[SS_TYPEMASK+1] =
62 STATIC_PaintTextfn, /* SS_LEFT */
63 STATIC_PaintTextfn, /* SS_CENTER */
64 STATIC_PaintTextfn, /* SS_RIGHT */
65 STATIC_PaintIconfn, /* SS_ICON */
66 STATIC_PaintRectfn, /* SS_BLACKRECT */
67 STATIC_PaintRectfn, /* SS_GRAYRECT */
68 STATIC_PaintRectfn, /* SS_WHITERECT */
69 STATIC_PaintRectfn, /* SS_BLACKFRAME */
70 STATIC_PaintRectfn, /* SS_GRAYFRAME */
71 STATIC_PaintRectfn, /* SS_WHITEFRAME */
72 NULL, /* SS_USERITEM */
73 STATIC_PaintTextfn, /* SS_SIMPLE */
74 STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
75 STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
76 STATIC_PaintBitmapfn, /* SS_BITMAP */
77 STATIC_PaintEnhMetafn, /* SS_ENHMETAFILE */
78 STATIC_PaintEtchedfn, /* SS_ETCHEDHORZ */
79 STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
80 STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
83 static BOOL get_icon_size( HICON handle, SIZE *size )
85 ICONINFO info;
86 BITMAP bmp;
87 int ret;
89 if (!GetIconInfo(handle, &info))
90 return FALSE;
92 ret = GetObjectW(info.hbmColor, sizeof(bmp), &bmp);
93 if (ret)
95 size->cx = bmp.bmWidth;
96 size->cy = bmp.bmHeight;
99 DeleteObject(info.hbmMask);
100 DeleteObject(info.hbmColor);
102 return !!ret;
105 /***********************************************************************
106 * STATIC_SetIcon
108 * Set the icon for an SS_ICON control.
110 static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
112 HICON prevIcon;
113 SIZE size;
115 if ((style & SS_TYPEMASK) != SS_ICON) return 0;
116 if (hicon && !get_icon_size( hicon, &size ))
118 WARN("hicon != 0, but invalid\n");
119 return 0;
121 prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
122 if (hicon && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
124 /* Windows currently doesn't implement SS_RIGHTJUST */
126 if ((style & SS_RIGHTJUST) != 0)
128 RECT wr;
129 GetWindowRect(hwnd, &wr);
130 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
131 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
133 else */
135 SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
138 return prevIcon;
141 /***********************************************************************
142 * STATIC_SetBitmap
144 * Set the bitmap for an SS_BITMAP control.
146 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
148 HBITMAP hOldBitmap;
150 if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
151 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP)
153 WARN("hBitmap != 0, but it's not a bitmap\n");
154 return 0;
156 hOldBitmap = (HBITMAP)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hBitmap );
157 if (hBitmap && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
159 BITMAP bm;
160 GetObjectW(hBitmap, sizeof(bm), &bm);
161 /* Windows currently doesn't implement SS_RIGHTJUST */
163 if ((style & SS_RIGHTJUST) != 0)
165 RECT wr;
166 GetWindowRect(hwnd, &wr);
167 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
168 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
170 else */
172 SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
173 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
176 return hOldBitmap;
179 /***********************************************************************
180 * STATIC_SetEnhMetaFile
182 * Set the enhanced metafile for an SS_ENHMETAFILE control.
184 static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
186 if ((style & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
187 if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE)
189 WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
190 return 0;
192 return (HENHMETAFILE)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hEnhMetaFile );
195 /***********************************************************************
196 * STATIC_GetImage
198 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
199 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
201 static HANDLE STATIC_GetImage( HWND hwnd, WPARAM wParam, DWORD style )
203 switch (style & SS_TYPEMASK)
205 case SS_ICON:
206 if ((wParam != IMAGE_ICON) &&
207 (wParam != IMAGE_CURSOR)) return NULL;
208 break;
209 case SS_BITMAP:
210 if (wParam != IMAGE_BITMAP) return NULL;
211 break;
212 case SS_ENHMETAFILE:
213 if (wParam != IMAGE_ENHMETAFILE) return NULL;
214 break;
215 default:
216 return NULL;
218 return (HANDLE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
221 /***********************************************************************
222 * STATIC_LoadIconW
224 * Load the icon for an SS_ICON control.
226 static HICON STATIC_LoadIconW( HINSTANCE hInstance, LPCWSTR name, DWORD style )
228 HICON hicon = 0;
230 if (hInstance && ((ULONG_PTR)hInstance >> 16))
232 if ((style & SS_REALSIZEIMAGE) != 0)
233 hicon = LoadImageW(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
234 else
236 hicon = LoadIconW( hInstance, name );
237 if (!hicon) hicon = LoadCursorW( hInstance, name );
240 if (!hicon) hicon = LoadIconW( 0, name );
241 /* Windows doesn't try to load a standard cursor,
242 probably because most IDs for standard cursors conflict
243 with the IDs for standard icons anyway */
244 return hicon;
247 /***********************************************************************
248 * STATIC_TryPaintFcn
250 * Try to immediately paint the control.
252 static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
254 LONG style = full_style & SS_TYPEMASK;
255 RECT rc;
257 GetClientRect( hwnd, &rc );
258 if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
260 HDC hdc;
261 HRGN hrgn;
263 hdc = GetDC( hwnd );
264 hrgn = set_control_clipping( hdc, &rc );
265 (staticPaintFunc[style])( hwnd, hdc, full_style );
266 SelectClipRgn( hdc, hrgn );
267 if (hrgn) DeleteObject( hrgn );
268 ReleaseDC( hwnd, hdc );
272 static HBRUSH STATIC_SendWmCtlColorStatic(HWND hwnd, HDC hdc)
274 HBRUSH hBrush;
275 HWND parent = GetParent(hwnd);
277 if (!parent) parent = hwnd;
278 hBrush = (HBRUSH) SendMessageW( parent, WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
279 if (!hBrush) /* did the app forget to call DefWindowProc ? */
281 /* FIXME: DefWindowProc should return different colors if a
282 manifest is present */
283 hBrush = (HBRUSH)DefWindowProcW( parent, WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd);
285 return hBrush;
288 /***********************************************************************
289 * hasTextStyle
291 * Tests if the control displays text.
293 static BOOL hasTextStyle( DWORD style )
295 switch (style & SS_TYPEMASK)
297 case SS_SIMPLE:
298 case SS_LEFT:
299 case SS_LEFTNOWORDWRAP:
300 case SS_CENTER:
301 case SS_RIGHT:
302 case SS_OWNERDRAW:
303 return TRUE;
306 return FALSE;
309 static LRESULT CALLBACK STATIC_WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
311 LRESULT lResult = 0;
312 LONG full_style = GetWindowLongW( hwnd, GWL_STYLE );
313 LONG style = full_style & SS_TYPEMASK;
315 if (!IsWindow( hwnd )) return 0;
317 switch (uMsg)
319 case WM_CREATE:
320 if (style < 0L || style > SS_TYPEMASK)
322 ERR("Unknown style 0x%02x\n", style );
323 return -1;
325 break;
327 case WM_NCDESTROY:
328 if (style == SS_ICON)
331 * FIXME
332 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
334 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
335 * had already been loaded by the application the last thing we want to do is
336 * GlobalFree16 the handle.
338 break;
340 else
341 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
343 case WM_ERASEBKGND:
344 /* do all painting in WM_PAINT like Windows does */
345 return 1;
347 case WM_PRINTCLIENT:
348 case WM_PAINT:
350 PAINTSTRUCT ps;
351 RECT rect;
352 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
353 GetClientRect( hwnd, &rect );
354 if (staticPaintFunc[style])
356 HRGN hrgn = set_control_clipping( hdc, &rect );
357 (staticPaintFunc[style])( hwnd, hdc, full_style );
358 SelectClipRgn( hdc, hrgn );
359 if (hrgn) DeleteObject( hrgn );
361 if (!wParam) EndPaint(hwnd, &ps);
363 break;
365 case WM_ENABLE:
366 STATIC_TryPaintFcn( hwnd, full_style );
367 if (full_style & SS_NOTIFY)
369 if (wParam)
370 SendMessageW( GetParent(hwnd), WM_COMMAND,
371 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_ENABLE ), (LPARAM)hwnd);
372 else
373 SendMessageW( GetParent(hwnd), WM_COMMAND,
374 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DISABLE ), (LPARAM)hwnd);
376 break;
378 case WM_SYSCOLORCHANGE:
379 COMCTL32_RefreshSysColors();
380 STATIC_TryPaintFcn( hwnd, full_style );
381 break;
383 case WM_NCCREATE:
385 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
387 if (full_style & SS_SUNKEN)
388 SetWindowLongW( hwnd, GWL_EXSTYLE,
389 GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
391 switch (style)
393 case SS_ICON:
395 HICON hIcon;
397 hIcon = STATIC_LoadIconW(cs->hInstance, cs->lpszName, full_style);
398 STATIC_SetIcon(hwnd, hIcon, full_style);
400 break;
401 case SS_BITMAP:
402 if ((ULONG_PTR)cs->hInstance >> 16)
404 HBITMAP hBitmap;
405 hBitmap = LoadBitmapW(cs->hInstance, cs->lpszName);
406 STATIC_SetBitmap(hwnd, hBitmap, full_style);
408 break;
410 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
411 the enhanced metafile that was specified as the window text. */
413 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
415 case WM_SETTEXT:
416 if (hasTextStyle( full_style ))
418 lResult = DefWindowProcW( hwnd, uMsg, wParam, lParam );
419 STATIC_TryPaintFcn( hwnd, full_style );
421 break;
423 case WM_SETFONT:
424 if (hasTextStyle( full_style ))
426 SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, wParam );
427 if (LOWORD(lParam))
428 RedrawWindow( hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
430 break;
432 case WM_GETFONT:
433 return GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
435 case WM_NCHITTEST:
436 if (full_style & SS_NOTIFY)
437 return HTCLIENT;
438 else
439 return HTTRANSPARENT;
441 case WM_GETDLGCODE:
442 return DLGC_STATIC;
444 case WM_LBUTTONDOWN:
445 case WM_NCLBUTTONDOWN:
446 if (full_style & SS_NOTIFY)
447 SendMessageW( GetParent(hwnd), WM_COMMAND,
448 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_CLICKED ), (LPARAM)hwnd);
449 return 0;
451 case WM_LBUTTONDBLCLK:
452 case WM_NCLBUTTONDBLCLK:
453 if (full_style & SS_NOTIFY)
454 SendMessageW( GetParent(hwnd), WM_COMMAND,
455 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DBLCLK ), (LPARAM)hwnd);
456 return 0;
458 case STM_GETIMAGE:
459 return (LRESULT)STATIC_GetImage( hwnd, wParam, full_style );
461 case STM_GETICON:
462 return (LRESULT)STATIC_GetImage( hwnd, IMAGE_ICON, full_style );
464 case STM_SETIMAGE:
465 switch (wParam)
467 case IMAGE_BITMAP:
468 lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
469 break;
470 case IMAGE_ENHMETAFILE:
471 lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
472 break;
473 case IMAGE_ICON:
474 case IMAGE_CURSOR:
475 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
476 break;
477 default:
478 FIXME("STM_SETIMAGE: Unhandled type %lx\n", wParam);
479 break;
481 STATIC_TryPaintFcn( hwnd, full_style );
482 break;
484 case STM_SETICON:
485 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
486 STATIC_TryPaintFcn( hwnd, full_style );
487 break;
489 default:
490 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
492 return lResult;
495 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
497 DRAWITEMSTRUCT dis;
498 HFONT font, oldFont = NULL;
499 UINT id = (UINT)GetWindowLongPtrW( hwnd, GWLP_ID );
501 dis.CtlType = ODT_STATIC;
502 dis.CtlID = id;
503 dis.itemID = 0;
504 dis.itemAction = ODA_DRAWENTIRE;
505 dis.itemState = IsWindowEnabled(hwnd) ? 0 : ODS_DISABLED;
506 dis.hwndItem = hwnd;
507 dis.hDC = hdc;
508 dis.itemData = 0;
509 GetClientRect( hwnd, &dis.rcItem );
511 font = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
512 if (font) oldFont = SelectObject( hdc, font );
513 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
514 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
515 if (font) SelectObject( hdc, oldFont );
518 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
520 RECT rc;
521 HBRUSH hBrush;
522 HFONT hFont, hOldFont = NULL;
523 UINT format;
524 INT len, buf_size;
525 WCHAR *text;
527 GetClientRect( hwnd, &rc);
529 switch (style & SS_TYPEMASK)
531 case SS_LEFT:
532 format = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
533 break;
535 case SS_CENTER:
536 format = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
537 break;
539 case SS_RIGHT:
540 format = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
541 break;
543 case SS_SIMPLE:
544 format = DT_LEFT | DT_SINGLELINE;
545 break;
547 case SS_LEFTNOWORDWRAP:
548 format = DT_LEFT | DT_EXPANDTABS;
549 break;
551 default:
552 return;
555 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_RIGHT)
556 format = DT_RIGHT | (format & ~(DT_LEFT | DT_CENTER));
558 if (style & SS_NOPREFIX)
559 format |= DT_NOPREFIX;
561 if ((style & SS_TYPEMASK) != SS_SIMPLE)
563 if (style & SS_CENTERIMAGE)
564 format |= DT_SINGLELINE | DT_VCENTER;
565 if (style & SS_EDITCONTROL)
566 format |= DT_EDITCONTROL;
567 if (style & SS_ENDELLIPSIS)
568 format |= DT_SINGLELINE | DT_END_ELLIPSIS;
569 if (style & SS_PATHELLIPSIS)
570 format |= DT_SINGLELINE | DT_PATH_ELLIPSIS;
571 if (style & SS_WORDELLIPSIS)
572 format |= DT_SINGLELINE | DT_WORD_ELLIPSIS;
575 if ((hFont = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET )))
576 hOldFont = SelectObject( hdc, hFont );
578 /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
579 brush is not used */
580 hBrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
582 if ((style & SS_TYPEMASK) != SS_SIMPLE)
584 FillRect( hdc, &rc, hBrush );
585 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
588 buf_size = 256;
589 if (!(text = HeapAlloc( GetProcessHeap(), 0, buf_size * sizeof(WCHAR) )))
590 goto no_TextOut;
592 while ((len = InternalGetWindowText( hwnd, text, buf_size )) == buf_size - 1)
594 buf_size *= 2;
595 if (!(text = HeapReAlloc( GetProcessHeap(), 0, text, buf_size * sizeof(WCHAR) )))
596 goto no_TextOut;
599 if (!len) goto no_TextOut;
601 if (((style & SS_TYPEMASK) == SS_SIMPLE) && (style & SS_NOPREFIX))
603 /* Windows uses the faster ExtTextOut() to draw the text and
604 to paint the whole client rectangle with the text background
605 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
606 ExtTextOutW( hdc, rc.left, rc.top, ETO_CLIPPED | ETO_OPAQUE,
607 &rc, text, len, NULL );
609 else
611 DrawTextW( hdc, text, -1, &rc, format );
614 no_TextOut:
615 HeapFree( GetProcessHeap(), 0, text );
617 if (hFont)
618 SelectObject( hdc, hOldFont );
621 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
623 RECT rc;
624 HBRUSH hBrush;
626 GetClientRect( hwnd, &rc);
628 /* FIXME: send WM_CTLCOLORSTATIC */
629 switch (style & SS_TYPEMASK)
631 case SS_BLACKRECT:
632 hBrush = CreateSolidBrush(comctl32_color.clr3dDkShadow);
633 FillRect( hdc, &rc, hBrush );
634 break;
635 case SS_GRAYRECT:
636 hBrush = CreateSolidBrush(comctl32_color.clr3dShadow);
637 FillRect( hdc, &rc, hBrush );
638 break;
639 case SS_WHITERECT:
640 hBrush = CreateSolidBrush(comctl32_color.clr3dHilight);
641 FillRect( hdc, &rc, hBrush );
642 break;
643 case SS_BLACKFRAME:
644 hBrush = CreateSolidBrush(comctl32_color.clr3dDkShadow);
645 FrameRect( hdc, &rc, hBrush );
646 break;
647 case SS_GRAYFRAME:
648 hBrush = CreateSolidBrush(comctl32_color.clr3dShadow);
649 FrameRect( hdc, &rc, hBrush );
650 break;
651 case SS_WHITEFRAME:
652 hBrush = CreateSolidBrush(comctl32_color.clr3dHilight);
653 FrameRect( hdc, &rc, hBrush );
654 break;
655 default:
656 return;
658 DeleteObject( hBrush );
662 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
664 RECT rc, iconRect;
665 HBRUSH hbrush;
666 HICON hIcon;
667 SIZE size;
669 GetClientRect( hwnd, &rc );
670 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
671 hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
672 if (!hIcon || !get_icon_size( hIcon, &size ))
674 FillRect(hdc, &rc, hbrush);
676 else
678 if (style & SS_CENTERIMAGE)
680 iconRect.left = (rc.right - rc.left) / 2 - size.cx / 2;
681 iconRect.top = (rc.bottom - rc.top) / 2 - size.cy / 2;
682 iconRect.right = iconRect.left + size.cx;
683 iconRect.bottom = iconRect.top + size.cy;
685 else
686 iconRect = rc;
687 FillRect( hdc, &rc, hbrush );
688 DrawIconEx( hdc, iconRect.left, iconRect.top, hIcon, iconRect.right - iconRect.left,
689 iconRect.bottom - iconRect.top, 0, NULL, DI_NORMAL );
693 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
695 HDC hMemDC;
696 HBITMAP hBitmap, oldbitmap;
697 HBRUSH hbrush;
699 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
701 if ((hBitmap = (HBITMAP)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET ))
702 && (GetObjectType(hBitmap) == OBJ_BITMAP)
703 && (hMemDC = CreateCompatibleDC( hdc )))
705 BITMAP bm;
706 RECT rcClient;
707 LOGBRUSH brush;
709 GetObjectW(hBitmap, sizeof(bm), &bm);
710 oldbitmap = SelectObject(hMemDC, hBitmap);
712 /* Set the background color for monochrome bitmaps
713 to the color of the background brush */
714 if (GetObjectW( hbrush, sizeof(brush), &brush ))
716 if (brush.lbStyle == BS_SOLID)
717 SetBkColor(hdc, brush.lbColor);
719 GetClientRect(hwnd, &rcClient);
720 if (style & SS_CENTERIMAGE)
722 FillRect( hdc, &rcClient, hbrush );
723 rcClient.left = (rcClient.right - rcClient.left)/2 - bm.bmWidth/2;
724 rcClient.top = (rcClient.bottom - rcClient.top)/2 - bm.bmHeight/2;
725 rcClient.right = rcClient.left + bm.bmWidth;
726 rcClient.bottom = rcClient.top + bm.bmHeight;
728 StretchBlt(hdc, rcClient.left, rcClient.top, rcClient.right - rcClient.left,
729 rcClient.bottom - rcClient.top, hMemDC,
730 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
731 SelectObject(hMemDC, oldbitmap);
732 DeleteDC(hMemDC);
736 static void STATIC_PaintEnhMetafn(HWND hwnd, HDC hdc, DWORD style )
738 HENHMETAFILE hEnhMetaFile;
739 RECT rc;
740 HBRUSH hbrush;
742 GetClientRect(hwnd, &rc);
743 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
744 FillRect(hdc, &rc, hbrush);
745 if ((hEnhMetaFile = (HENHMETAFILE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
747 /* The control's current font is not selected into the
748 device context! */
749 if (GetObjectType(hEnhMetaFile) == OBJ_ENHMETAFILE)
750 PlayEnhMetaFile(hdc, hEnhMetaFile, &rc);
754 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
756 RECT rc;
758 /* FIXME: sometimes (not always) sends WM_CTLCOLORSTATIC */
759 GetClientRect( hwnd, &rc );
760 switch (style & SS_TYPEMASK)
762 case SS_ETCHEDHORZ:
763 DrawEdge(hdc, &rc, EDGE_ETCHED, BF_TOP | BF_BOTTOM);
764 break;
765 case SS_ETCHEDVERT:
766 DrawEdge(hdc, &rc, EDGE_ETCHED, BF_LEFT | BF_RIGHT);
767 break;
768 case SS_ETCHEDFRAME:
769 DrawEdge(hdc, &rc, EDGE_ETCHED, BF_RECT);
770 break;
774 void STATIC_Register(void)
776 WNDCLASSW wndClass;
778 memset(&wndClass, 0, sizeof(wndClass));
779 wndClass.style = CS_DBLCLKS | CS_PARENTDC | CS_GLOBALCLASS;
780 wndClass.lpfnWndProc = STATIC_WindowProc;
781 wndClass.cbClsExtra = 0;
782 wndClass.cbWndExtra = STATIC_EXTRA_BYTES;
783 wndClass.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
784 wndClass.hbrBackground = NULL;
785 wndClass.lpszClassName = WC_STATICW;
786 RegisterClassW(&wndClass);