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