Do not check for non NULL pointer before HeapFree'ing it. It's
[wine] / dlls / user / static.c
1 /*
2  * Static control
3  *
4  * Copyright  David W. Metcalfe, 1993
5  *
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.
10  *
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.
15  *
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
19  *
20  * NOTES
21  *
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.
24  * 
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.
28  * 
29  * TODO:
30  *
31  *   Styles
32  *   - SS_CENTERIMAGE
33  *   - SS_EDITCONTROL
34  *   - SS_ENDELLIPSIS
35  *   - SS_ENHMETAFILE
36  *   - SS_PATHELLIPSIS
37  *   - SS_REALSIZECONTROL
38  *   - SS_REALSIZEIMAGE
39  *   - SS_RIGHTJUST
40  *   - SS_WORDELLIPSIS
41  *
42  *   Notifications
43  *   - STN_DISABLE
44  *   - STN_ENABLE
45  *
46  *   Messages
47  *   - STM_SETIMAGE: IMAGE_CURSOR, IMAGE_ENHMETAFILE
48  */
49
50 #include <stdarg.h>
51
52 #include "windef.h"
53 #include "winbase.h"
54 #include "wingdi.h"
55 #include "wine/winuser16.h"
56 #include "controls.h"
57 #include "user_private.h"
58 #include "wine/debug.h"
59
60 WINE_DEFAULT_DEBUG_CHANNEL(static);
61
62 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style );
63 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style );
64 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style );
65 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style );
66 static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc, DWORD style );
67 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style );
68 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
69 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
70
71 static COLORREF color_windowframe, color_background, color_window;
72
73 /* offsets for GetWindowLong for static private information */
74 #define HFONT_GWL_OFFSET    0
75 #define HICON_GWL_OFFSET    (sizeof(HFONT))
76 #define STATIC_EXTRA_BYTES  (HICON_GWL_OFFSET + sizeof(HICON))
77
78 typedef void (*pfPaint)( HWND hwnd, HDC hdc, DWORD style );
79
80 static pfPaint staticPaintFunc[SS_TYPEMASK+1] =
81 {
82     STATIC_PaintTextfn,      /* SS_LEFT */
83     STATIC_PaintTextfn,      /* SS_CENTER */
84     STATIC_PaintTextfn,      /* SS_RIGHT */
85     STATIC_PaintIconfn,      /* SS_ICON */
86     STATIC_PaintRectfn,      /* SS_BLACKRECT */
87     STATIC_PaintRectfn,      /* SS_GRAYRECT */
88     STATIC_PaintRectfn,      /* SS_WHITERECT */
89     STATIC_PaintRectfn,      /* SS_BLACKFRAME */
90     STATIC_PaintRectfn,      /* SS_GRAYFRAME */
91     STATIC_PaintRectfn,      /* SS_WHITEFRAME */
92     NULL,                    /* SS_USERITEM */
93     STATIC_PaintTextfn,      /* SS_SIMPLE */
94     STATIC_PaintTextfn,      /* SS_LEFTNOWORDWRAP */
95     STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
96     STATIC_PaintBitmapfn,    /* SS_BITMAP */
97     NULL,                    /* SS_ENHMETAFILE */
98     STATIC_PaintEtchedfn,    /* SS_ETCHEDHORZ */
99     STATIC_PaintEtchedfn,    /* SS_ETCHEDVERT */
100     STATIC_PaintEtchedfn,    /* SS_ETCHEDFRAME */
101 };
102
103
104 /*********************************************************************
105  * static class descriptor
106  */
107 const struct builtin_class_descr STATIC_builtin_class =
108 {
109     "Static",            /* name */
110     CS_DBLCLKS | CS_PARENTDC, /* style  */
111     StaticWndProcA,      /* procA */
112     StaticWndProcW,      /* procW */
113     STATIC_EXTRA_BYTES,  /* extra */
114     IDC_ARROW,           /* cursor */
115     0                    /* brush */
116 };
117
118
119 /***********************************************************************
120  *           STATIC_SetIcon
121  *
122  * Set the icon for an SS_ICON control.
123  */
124 static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
125 {
126     HICON prevIcon;
127     CURSORICONINFO *info = hicon?(CURSORICONINFO *) GlobalLock16(HICON_16(hicon)):NULL;
128
129     if ((style & SS_TYPEMASK) != SS_ICON) return 0;
130     if (hicon && !info) {
131         ERR("huh? hicon!=0, but info=0???\n");
132         return 0;
133     }
134     prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
135     if (hicon && !(style & SS_CENTERIMAGE))
136     {
137         SetWindowPos( hwnd, 0, 0, 0, info->nWidth, info->nHeight,
138                         SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
139         GlobalUnlock16(HICON_16(hicon));
140     }
141     return prevIcon;
142 }
143
144 /***********************************************************************
145  *           STATIC_SetBitmap
146  *
147  * Set the bitmap for an SS_BITMAP control.
148  */
149 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
150 {
151     HBITMAP hOldBitmap;
152
153     if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
154     if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
155         ERR("huh? hBitmap!=0, but not bitmap\n");
156         return 0;
157     }
158     hOldBitmap = (HBITMAP)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hBitmap );
159     if (hBitmap && !(style & SS_CENTERIMAGE))
160     {
161         BITMAP bm;
162         GetObjectW(hBitmap, sizeof(bm), &bm);
163         SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
164                       SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
165     }
166     return hOldBitmap;
167 }
168
169 /***********************************************************************
170  *           STATIC_LoadIconA
171  *
172  * Load the icon for an SS_ICON control.
173  */
174 static HICON STATIC_LoadIconA( HWND hwnd, LPCSTR name )
175 {
176     HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
177     HICON hicon = LoadIconA( hInstance, name );
178     if (!hicon) hicon = LoadIconA( 0, name );
179     return hicon;
180 }
181
182 /***********************************************************************
183  *           STATIC_LoadIconW
184  *
185  * Load the icon for an SS_ICON control.
186  */
187 static HICON STATIC_LoadIconW( HWND hwnd, LPCWSTR name )
188 {
189     HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
190     HICON hicon = LoadIconW( hInstance, name );
191     if (!hicon) hicon = LoadIconW( 0, name );
192     return hicon;
193 }
194
195 /***********************************************************************
196  *           STATIC_LoadBitmapA
197  *
198  * Load the bitmap for an SS_BITMAP control.
199  */
200 static HBITMAP STATIC_LoadBitmapA( HWND hwnd, LPCSTR name )
201 {
202     HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
203     HBITMAP hbitmap = LoadBitmapA( hInstance, name );
204     if (!hbitmap)  /* Try OEM icon (FIXME: is this right?) */
205         hbitmap = LoadBitmapA( 0, name );
206     return hbitmap;
207 }
208
209 /***********************************************************************
210  *           STATIC_LoadBitmapW
211  *
212  * Load the bitmap for an SS_BITMAP control.
213  */
214 static HBITMAP STATIC_LoadBitmapW( HWND hwnd, LPCWSTR name )
215 {
216     HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
217     HBITMAP hbitmap = LoadBitmapW( hInstance, name );
218     if (!hbitmap)  /* Try OEM icon (FIXME: is this right?) */
219         hbitmap = LoadBitmapW( 0, name );
220     return hbitmap;
221 }
222
223 /***********************************************************************
224  *           STATIC_TryPaintFcn
225  *
226  * Try to immediately paint the control.
227  */
228 static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
229 {
230     LONG style = full_style & SS_TYPEMASK;
231     RECT rc;
232
233     GetClientRect( hwnd, &rc );
234     if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
235     {
236         HDC hdc;
237         hdc = GetDC( hwnd );
238         (staticPaintFunc[style])( hwnd, hdc, full_style );
239         ReleaseDC( hwnd, hdc );
240     }
241 }
242
243 /***********************************************************************
244  *           StaticWndProc_common
245  */
246 static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam,
247                                      LPARAM lParam, BOOL unicode )
248 {
249     LRESULT lResult = 0;
250     LONG full_style = GetWindowLongW( hwnd, GWL_STYLE );
251     LONG style = full_style & SS_TYPEMASK;
252
253     switch (uMsg)
254     {
255     case WM_CREATE:
256         if (style < 0L || style > SS_TYPEMASK)
257         {
258             ERR("Unknown style 0x%02lx\n", style );
259             return -1;
260         }
261         /* initialise colours */
262         color_windowframe  = GetSysColor(COLOR_WINDOWFRAME);
263         color_background   = GetSysColor(COLOR_BACKGROUND);
264         color_window       = GetSysColor(COLOR_WINDOW);
265         break;
266
267     case WM_NCDESTROY:
268         if (style == SS_ICON) {
269 /*
270  * FIXME
271  *           DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
272  *
273  * We don't want to do this yet because DestroyIcon32 is broken. If the icon
274  * had already been loaded by the application the last thing we want to do is
275  * GlobalFree16 the handle.
276  */
277             break;
278         }
279         else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
280                               DefWindowProcA(hwnd, uMsg, wParam, lParam);
281
282     case WM_PAINT:
283         {
284             PAINTSTRUCT ps;
285             HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
286             if (staticPaintFunc[style])
287                 (staticPaintFunc[style])( hwnd, hdc, full_style );
288             if (!wParam) EndPaint(hwnd, &ps);
289         }
290         break;
291
292     case WM_ENABLE:
293         InvalidateRect(hwnd, NULL, TRUE);
294         break;
295
296     case WM_SYSCOLORCHANGE:
297         color_windowframe  = GetSysColor(COLOR_WINDOWFRAME);
298         color_background   = GetSysColor(COLOR_BACKGROUND);
299         color_window       = GetSysColor(COLOR_WINDOW);
300         InvalidateRect(hwnd, NULL, TRUE);
301         break;
302
303     case WM_NCCREATE:
304         if (full_style & SS_SUNKEN)
305             SetWindowLongW( hwnd, GWL_EXSTYLE,
306                             GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
307
308         if(unicode)
309             lParam = (LPARAM)(((LPCREATESTRUCTW)lParam)->lpszName);
310         else
311             lParam = (LPARAM)(((LPCREATESTRUCTA)lParam)->lpszName);
312         /* fall through */
313     case WM_SETTEXT:
314         switch (style) {
315         case SS_ICON:
316         {
317             HICON hIcon;
318             if(unicode)
319                 hIcon = STATIC_LoadIconW(hwnd, (LPCWSTR)lParam);
320             else
321                 hIcon = STATIC_LoadIconA(hwnd, (LPCSTR)lParam);
322             /* FIXME : should we also return the previous hIcon here ??? */
323             STATIC_SetIcon(hwnd, hIcon, full_style);
324             break;
325         }
326         case SS_BITMAP:
327         {
328             HBITMAP hBitmap;
329             if(unicode)
330                 hBitmap = STATIC_LoadBitmapW(hwnd, (LPCWSTR)lParam);
331             else
332                 hBitmap = STATIC_LoadBitmapA(hwnd, (LPCSTR)lParam);
333             STATIC_SetBitmap(hwnd, hBitmap, full_style);
334             break;
335         }
336         case SS_LEFT:
337         case SS_CENTER:
338         case SS_RIGHT:
339         case SS_SIMPLE:
340         case SS_LEFTNOWORDWRAP:
341         {
342             if (HIWORD(lParam))
343             {
344                 if(unicode)
345                     lResult = DefWindowProcW( hwnd, WM_SETTEXT, wParam, lParam );
346                 else
347                     lResult = DefWindowProcA( hwnd, WM_SETTEXT, wParam, lParam );
348             }
349             if (uMsg == WM_SETTEXT)
350                 STATIC_TryPaintFcn( hwnd, full_style );
351             break;
352         }
353         default:
354             if (HIWORD(lParam))
355             {
356                 if(unicode)
357                     lResult = DefWindowProcW( hwnd, WM_SETTEXT, wParam, lParam );
358                 else
359                     lResult = DefWindowProcA( hwnd, WM_SETTEXT, wParam, lParam );
360             }
361             if(uMsg == WM_SETTEXT)
362                 InvalidateRect(hwnd, NULL, TRUE);
363         }
364         return 1; /* success. FIXME: check text length */
365
366     case WM_SETFONT:
367         if ((style == SS_ICON) || (style == SS_BITMAP)) return 0;
368         SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, wParam );
369         if (LOWORD(lParam))
370             InvalidateRect( hwnd, NULL, TRUE );
371         break;
372
373     case WM_GETFONT:
374         return GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
375
376     case WM_NCHITTEST:
377         if (full_style & SS_NOTIFY)
378            return HTCLIENT;
379         else
380            return HTTRANSPARENT;
381
382     case WM_GETDLGCODE:
383         return DLGC_STATIC;
384
385     case WM_LBUTTONDOWN:
386     case WM_NCLBUTTONDOWN:
387         if (full_style & SS_NOTIFY)
388             SendMessageW( GetParent(hwnd), WM_COMMAND,
389                           MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_CLICKED ), (LPARAM)hwnd);
390         return 0;
391
392     case WM_LBUTTONDBLCLK:
393     case WM_NCLBUTTONDBLCLK:
394         if (full_style & SS_NOTIFY)
395             SendMessageW( GetParent(hwnd), WM_COMMAND,
396                           MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DBLCLK ), (LPARAM)hwnd);
397         return 0;
398
399     case STM_GETIMAGE:
400     case STM_GETICON16:
401     case STM_GETICON:
402         return GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
403
404     case STM_SETIMAGE:
405         switch(wParam) {
406         case IMAGE_BITMAP:
407             lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
408             break;
409         case IMAGE_CURSOR:
410             FIXME("STM_SETIMAGE: Unhandled type IMAGE_CURSOR\n");
411             break;
412         case IMAGE_ENHMETAFILE:
413             FIXME("STM_SETIMAGE: Unhandled type IMAGE_ENHMETAFILE\n");
414             break;
415         case IMAGE_ICON:
416             lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
417             break;
418         default:
419             FIXME("STM_SETIMAGE: Unhandled type %x\n", wParam);
420             break;
421         }
422         InvalidateRect( hwnd, NULL, TRUE );
423         break;
424
425     case STM_SETICON16:
426     case STM_SETICON:
427         lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
428         InvalidateRect( hwnd, NULL, TRUE );
429         break;
430
431     default:
432         return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
433                          DefWindowProcA(hwnd, uMsg, wParam, lParam);
434     }
435     return lResult;
436 }
437
438 /***********************************************************************
439  *           StaticWndProcA
440  */
441 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
442 {
443     if (!IsWindow( hWnd )) return 0;
444     return StaticWndProc_common(hWnd, uMsg, wParam, lParam, FALSE);
445 }
446
447 /***********************************************************************
448  *           StaticWndProcW
449  */
450 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
451 {
452     if (!IsWindow( hWnd )) return 0;
453     return StaticWndProc_common(hWnd, uMsg, wParam, lParam, TRUE);
454 }
455
456 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
457 {
458   DRAWITEMSTRUCT dis;
459   UINT id = (UINT)GetWindowLongPtrW( hwnd, GWLP_ID );
460
461   dis.CtlType    = ODT_STATIC;
462   dis.CtlID      = id;
463   dis.itemID     = 0;
464   dis.itemAction = ODA_DRAWENTIRE;
465   dis.itemState  = 0;
466   dis.hwndItem   = hwnd;
467   dis.hDC        = hdc;
468   dis.itemData   = 0;
469   GetClientRect( hwnd, &dis.rcItem );
470
471   SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
472   SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
473 }
474
475 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
476 {
477     RECT rc;
478     HBRUSH hBrush;
479     HFONT hFont;
480     WORD wFormat;
481     INT len;
482     WCHAR *text;
483
484     GetClientRect( hwnd, &rc);
485
486     switch (style & SS_TYPEMASK)
487     {
488     case SS_LEFT:
489         wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
490         break;
491
492     case SS_CENTER:
493         wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
494         break;
495
496     case SS_RIGHT:
497         wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
498         break;
499
500     case SS_SIMPLE:
501         wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER;
502         break;
503
504     case SS_LEFTNOWORDWRAP:
505         wFormat = DT_LEFT | DT_EXPANDTABS | DT_VCENTER;
506         break;
507
508     default:
509         return;
510     }
511
512     if (style & SS_NOPREFIX)
513         wFormat |= DT_NOPREFIX;
514     if (style & SS_CENTERIMAGE)
515         wFormat |= DT_VCENTER;
516
517     if ((hFont = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET ))) SelectObject( hdc, hFont );
518
519     if ((style & SS_NOPREFIX) || ((style & SS_TYPEMASK) != SS_SIMPLE))
520     {
521         hBrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC,
522                                        (WPARAM)hdc, (LPARAM)hwnd );
523         if (!hBrush) /* did the app forget to call defwindowproc ? */
524             hBrush = (HBRUSH)DefWindowProcW(GetParent(hwnd), WM_CTLCOLORSTATIC,
525                                             (WPARAM)hdc, (LPARAM)hwnd);
526         FillRect( hdc, &rc, hBrush );
527     }
528     if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
529
530     if (!(len = SendMessageW( hwnd, WM_GETTEXTLENGTH, 0, 0 ))) return;
531     if (!(text = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return;
532     SendMessageW( hwnd, WM_GETTEXT, len + 1, (LPARAM)text );
533     DrawTextW( hdc, text, -1, &rc, wFormat );
534     HeapFree( GetProcessHeap(), 0, text );
535 }
536
537 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
538 {
539     RECT rc;
540     HBRUSH hBrush;
541
542     GetClientRect( hwnd, &rc);
543
544     switch (style & SS_TYPEMASK)
545     {
546     case SS_BLACKRECT:
547         hBrush = CreateSolidBrush(color_windowframe);
548         FillRect( hdc, &rc, hBrush );
549         break;
550     case SS_GRAYRECT:
551         hBrush = CreateSolidBrush(color_background);
552         FillRect( hdc, &rc, hBrush );
553         break;
554     case SS_WHITERECT:
555         hBrush = CreateSolidBrush(color_window);
556         FillRect( hdc, &rc, hBrush );
557         break;
558     case SS_BLACKFRAME:
559         hBrush = CreateSolidBrush(color_windowframe);
560         FrameRect( hdc, &rc, hBrush );
561         break;
562     case SS_GRAYFRAME:
563         hBrush = CreateSolidBrush(color_background);
564         FrameRect( hdc, &rc, hBrush );
565         break;
566     case SS_WHITEFRAME:
567         hBrush = CreateSolidBrush(color_window);
568         FrameRect( hdc, &rc, hBrush );
569         break;
570     default:
571         return;
572     }
573     DeleteObject( hBrush );
574 }
575
576
577 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
578 {
579     RECT rc;
580     HBRUSH hbrush;
581     HICON hIcon;
582     INT x, y;
583
584     GetClientRect( hwnd, &rc );
585     hbrush = (HBRUSH)SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC,
586                                    (WPARAM)hdc, (LPARAM)hwnd );
587     FillRect( hdc, &rc, hbrush );
588     hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
589     if (style & SS_CENTERIMAGE)
590     {
591         CURSORICONINFO *info = hIcon ? (CURSORICONINFO *)GlobalLock16(HICON_16(hIcon)) : NULL;
592         x = (rc.right - rc.left)/2 - (info ? info->nWidth/2 : 0);
593         y = (rc.bottom - rc.top)/2 - (info ? info->nHeight/2 : 0);
594     }
595     else
596     {
597         x = rc.left;
598         y = rc.top;
599     }
600     if (hIcon)
601         DrawIcon( hdc, x, y, hIcon );
602 }
603
604 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
605 {
606     HDC hMemDC;
607     HBITMAP hBitmap, oldbitmap;
608
609     /* message is still sent, even if the returned brush is not used */
610     SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC,
611                                    (WPARAM)hdc, (LPARAM)hwnd );
612
613     if ((hBitmap = (HBITMAP)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
614     {
615         INT x, y;
616         BITMAP bm;
617
618         if(GetObjectType(hBitmap) != OBJ_BITMAP) return;
619         if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
620         GetObjectW(hBitmap, sizeof(bm), &bm);
621         oldbitmap = SelectObject(hMemDC, hBitmap);
622         if (style & SS_CENTERIMAGE)
623         {
624             RECT rcClient;
625             GetClientRect(hwnd, &rcClient);
626             x = (rcClient.right - rcClient.left)/2 - bm.bmWidth/2;
627             y = (rcClient.bottom - rcClient.top)/2 - bm.bmHeight/2;
628         }
629         else
630         {
631             x = 0;
632             y = 0;
633         }
634         BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
635                SRCCOPY);
636         SelectObject(hMemDC, oldbitmap);
637         DeleteDC(hMemDC);
638     }
639 }
640
641
642 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
643 {
644     RECT rc;
645
646     GetClientRect( hwnd, &rc );
647     switch (style & SS_TYPEMASK)
648     {
649         case SS_ETCHEDHORZ:
650             DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
651             break;
652         case SS_ETCHEDVERT:
653             DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
654             break;
655         case SS_ETCHEDFRAME:
656             DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
657             break;
658     }
659 }