Merge freeldr from amd64 branch:
[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 * 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 * Notes:
30 * - Windows XP introduced new behavior: The background of centered
31 * icons and bitmaps is painted differently. This is only done if
32 * a manifest is present.
33 * Because it has not yet been decided how to implement the two
34 * different modes in Wine, only the Windows XP mode is implemented.
35 * - Controls with SS_SIMPLE but without SS_NOPREFIX:
36 * The text should not be changed. Windows doesn't clear the
37 * client rectangle, so the new text must be larger than the old one.
38 * - The SS_RIGHTJUST style is currently not implemented by Windows
39 * (or it does something different than documented).
40 *
41 * TODO:
42 * - Animated cursors
43 */
44
45 #include <user32.h>
46
47 #include <wine/debug.h>
48
49 WINE_DEFAULT_DEBUG_CHANNEL(static);
50
51 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style );
52 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style );
53 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style );
54 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style );
55 static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc, DWORD style );
56 //static void STATIC_PaintEnhMetafn( HWND hwnd, HDC hdc, DWORD style );
57 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style );
58 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
59 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
60
61 static COLORREF color_3dshadow, color_3ddkshadow, color_3dhighlight;
62
63 /* offsets for GetWindowLong for static private information */
64 #define HFONT_GWL_OFFSET 0
65 #define HICON_GWL_OFFSET (sizeof(HFONT))
66 #define UISTATE_GWL_OFFSET (HICON_GWL_OFFSET+sizeof(HICON))
67 #define STATIC_EXTRA_BYTES (UISTATE_GWL_OFFSET + sizeof(LONG))
68
69 typedef void (*pfPaint)( HWND hwnd, HDC hdc, DWORD style );
70
71 static pfPaint staticPaintFunc[SS_TYPEMASK+1] =
72 {
73 STATIC_PaintTextfn, /* SS_LEFT */
74 STATIC_PaintTextfn, /* SS_CENTER */
75 STATIC_PaintTextfn, /* SS_RIGHT */
76 STATIC_PaintIconfn, /* SS_ICON */
77 STATIC_PaintRectfn, /* SS_BLACKRECT */
78 STATIC_PaintRectfn, /* SS_GRAYRECT */
79 STATIC_PaintRectfn, /* SS_WHITERECT */
80 STATIC_PaintRectfn, /* SS_BLACKFRAME */
81 STATIC_PaintRectfn, /* SS_GRAYFRAME */
82 STATIC_PaintRectfn, /* SS_WHITEFRAME */
83 NULL, /* SS_USERITEM */
84 STATIC_PaintTextfn, /* SS_SIMPLE */
85 STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
86 STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
87 STATIC_PaintBitmapfn, /* SS_BITMAP */
88 NULL, /* STATIC_PaintEnhMetafn, SS_ENHMETAFILE */
89 STATIC_PaintEtchedfn, /* SS_ETCHEDHORZ */
90 STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
91 STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
92 };
93
94
95 /*********************************************************************
96 * static class descriptor
97 */
98 const struct builtin_class_descr STATIC_builtin_class =
99 {
100 L"Static", /* name */
101 CS_DBLCLKS | CS_PARENTDC, /* style */
102 StaticWndProcA, /* procA */
103 StaticWndProcW, /* procW */
104 STATIC_EXTRA_BYTES, /* extra */
105 IDC_ARROW, /* cursor */
106 0 /* brush */
107 };
108
109 static __inline void set_ui_state( HWND hwnd, LONG flags )
110 {
111 SetWindowLongW( hwnd, UISTATE_GWL_OFFSET, flags );
112 }
113
114 static __inline LONG get_ui_state( HWND hwnd )
115 {
116 return GetWindowLongPtrW( hwnd, UISTATE_GWL_OFFSET );
117 }
118
119 static void setup_clipping(HWND hwnd, HDC hdc, HRGN *orig)
120 {
121 RECT rc;
122 HRGN hrgn;
123
124 /* Native control has always a clipping region set (this may be because
125 * builtin controls uses CS_PARENTDC) and an application depends on it
126 */
127 hrgn = CreateRectRgn(0, 0, 1, 1);
128 if (GetClipRgn(hdc, hrgn) != 1)
129 {
130 DeleteObject(hrgn);
131 *orig = NULL;
132 } else
133 *orig = hrgn;
134
135 GetClientRect(hwnd, &rc);
136 DPtoLP(hdc, (POINT *)&rc, 2);
137 IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom);
138 }
139
140 static void restore_clipping(HDC hdc, HRGN hrgn)
141 {
142 SelectClipRgn(hdc, hrgn);
143 if (hrgn != NULL)
144 DeleteObject(hrgn);
145 }
146
147 /* Retrieve the UI state for the control */
148 static BOOL STATIC_update_uistate(HWND hwnd, BOOL unicode)
149 {
150 LONG flags, prevflags;
151
152 if (unicode)
153 flags = DefWindowProcW(hwnd, WM_QUERYUISTATE, 0, 0);
154 else
155 flags = DefWindowProcA(hwnd, WM_QUERYUISTATE, 0, 0);
156
157 prevflags = get_ui_state(hwnd);
158
159 if (prevflags != flags)
160 {
161 set_ui_state(hwnd, flags);
162 return TRUE;
163 }
164
165 return FALSE;
166 }
167
168 /***********************************************************************
169 * STATIC_SetIcon
170 *
171 * Set the icon for an SS_ICON control. Modified for ReactOS
172 */
173 static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
174 {
175 HICON prevIcon;
176 ICONINFO info;
177
178 if ((style & SS_TYPEMASK) != SS_ICON) return 0;
179 if (hicon && (!GetIconInfo(hicon, &info))) {
180 WARN("hicon != 0, but info == 0\n");
181 return 0;
182 }
183 prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
184 if (hicon && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
185 {
186 BITMAP bm;
187
188 if (!GetObjectW(info.hbmColor, sizeof(BITMAP), &bm))
189 {
190 return 0;
191 }
192
193 /* Windows currently doesn't implement SS_RIGHTJUST */
194 /*
195 if ((style & SS_RIGHTJUST) != 0)
196 {
197 RECT wr;
198 GetWindowRect(hwnd, &wr);
199 SetWindowPos( hwnd, 0, wr.right - info->nWidth, wr.bottom - info->nHeight,
200 info->nWidth, info->nHeight, SWP_NOACTIVATE | SWP_NOZORDER );
201 }
202 else */
203 {
204 SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
205 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
206 }
207 }
208 return prevIcon;
209 }
210
211 /***********************************************************************
212 * STATIC_SetBitmap
213 *
214 * Set the bitmap for an SS_BITMAP control. Modified for ReactOS
215 */
216 static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
217 {
218 HBITMAP hOldBitmap;
219
220 if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
221 if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
222 WARN("hBitmap != 0, but it's not a bitmap\n");
223 return 0;
224 }
225 hOldBitmap = (HBITMAP)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hBitmap );
226 if (hBitmap && !(style & SS_CENTERIMAGE) && !(style & SS_REALSIZECONTROL))
227 {
228 BITMAP bm;
229 GetObjectW(hBitmap, sizeof(bm), &bm);
230 /* Windows currently doesn't implement SS_RIGHTJUST */
231 /*
232 if ((style & SS_RIGHTJUST) != 0)
233 {
234 RECT wr;
235 GetWindowRect(hwnd, &wr);
236 SetWindowPos( hwnd, 0, wr.right - bm.bmWidth, wr.bottom - bm.bmHeight,
237 bm.bmWidth, bm.bmHeight, SWP_NOACTIVATE | SWP_NOZORDER );
238 }
239 else */
240 {
241 SetWindowPos( hwnd, 0, 0, 0, bm.bmWidth, bm.bmHeight,
242 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
243 }
244 }
245 return hOldBitmap;
246 }
247
248 /***********************************************************************
249 * STATIC_SetEnhMetaFile
250 *
251 * Set the enhanced metafile for an SS_ENHMETAFILE control.
252 */
253 //static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
254 //{
255 // if ((style & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
256 // if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE) {
257 // WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
258 // return 0;
259 // }
260 // return (HENHMETAFILE)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hEnhMetaFile );
261 //}
262
263 /***********************************************************************
264 * STATIC_GetImage
265 *
266 * Gets the bitmap for an SS_BITMAP control, the icon/cursor for an
267 * SS_ICON control or the enhanced metafile for an SS_ENHMETAFILE control.
268 */
269 static HANDLE STATIC_GetImage( HWND hwnd, WPARAM wParam, DWORD style )
270 {
271 switch(style & SS_TYPEMASK)
272 {
273 case SS_ICON:
274 if ((wParam != IMAGE_ICON) &&
275 (wParam != IMAGE_CURSOR)) return NULL;
276 break;
277 case SS_BITMAP:
278 if (wParam != IMAGE_BITMAP) return NULL;
279 break;
280 case SS_ENHMETAFILE:
281 if (wParam != IMAGE_ENHMETAFILE) return NULL;
282 break;
283 default:
284 return NULL;
285 }
286 return (HANDLE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
287 }
288
289 /***********************************************************************
290 * STATIC_LoadIconA
291 *
292 * Load the icon for an SS_ICON control.
293 */
294 static HICON STATIC_LoadIconA( HWND hwnd, LPCSTR name, DWORD style )
295 {
296 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
297 if ((style & SS_REALSIZEIMAGE) != 0)
298 {
299 return LoadImageA(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
300 }
301 else
302 {
303 HICON hicon = LoadIconA( hInstance, name );
304 if (!hicon) hicon = LoadCursorA( hInstance, name );
305 if (!hicon) hicon = LoadIconA( 0, name );
306 /* Windows doesn't try to load a standard cursor,
307 probably because most IDs for standard cursors conflict
308 with the IDs for standard icons anyway */
309 return hicon;
310 }
311 }
312
313 /***********************************************************************
314 * STATIC_LoadIconW
315 *
316 * Load the icon for an SS_ICON control.
317 */
318 static HICON STATIC_LoadIconW( HWND hwnd, LPCWSTR name, DWORD style )
319 {
320 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
321 if ((style & SS_REALSIZEIMAGE) != 0)
322 {
323 return LoadImageW(hInstance, name, IMAGE_ICON, 0, 0, LR_SHARED);
324 }
325 else
326 {
327 HICON hicon = LoadIconW( hInstance, name );
328 if (!hicon) hicon = LoadCursorW( hInstance, name );
329 if (!hicon) hicon = LoadIconW( 0, name );
330 /* Windows doesn't try to load a standard cursor,
331 probably because most IDs for standard cursors conflict
332 with the IDs for standard icons anyway */
333 return hicon;
334 }
335 }
336
337 /***********************************************************************
338 * STATIC_LoadBitmapA
339 *
340 * Load the bitmap for an SS_BITMAP control.
341 */
342 static HBITMAP STATIC_LoadBitmapA( HWND hwnd, LPCSTR name )
343 {
344 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
345 /* Windows doesn't try to load OEM Bitmaps (hInstance == NULL) */
346 return LoadBitmapA( hInstance, name );
347 }
348
349 /***********************************************************************
350 * STATIC_LoadBitmapW
351 *
352 * Load the bitmap for an SS_BITMAP control.
353 */
354 static HBITMAP STATIC_LoadBitmapW( HWND hwnd, LPCWSTR name )
355 {
356 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
357 /* Windows doesn't try to load OEM Bitmaps (hInstance == NULL) */
358 return LoadBitmapW( hInstance, name );
359 }
360
361 /***********************************************************************
362 * STATIC_TryPaintFcn
363 *
364 * Try to immediately paint the control.
365 */
366 static VOID STATIC_TryPaintFcn(HWND hwnd, LONG full_style)
367 {
368 LONG style = full_style & SS_TYPEMASK;
369 RECT rc;
370
371 GetClientRect( hwnd, &rc );
372 if (!IsRectEmpty(&rc) && IsWindowVisible(hwnd) && staticPaintFunc[style])
373 {
374 HDC hdc;
375 HRGN hOrigClipping;
376
377 hdc = GetDC( hwnd );
378 setup_clipping(hwnd, hdc, &hOrigClipping);
379 (staticPaintFunc[style])( hwnd, hdc, full_style );
380 restore_clipping(hdc, hOrigClipping);
381 ReleaseDC( hwnd, hdc );
382 }
383 }
384
385 static HBRUSH STATIC_SendWmCtlColorStatic(HWND hwnd, HDC hdc)
386 {
387 HBRUSH hBrush;
388 HWND parent = GetParent(hwnd);
389
390 if(!parent) parent = hwnd;
391 hBrush = (HBRUSH) SendMessageW( GetParent(hwnd),
392 WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
393 if (!hBrush) /* did the app forget to call DefWindowProc ? */
394 {
395 /* FIXME: DefWindowProc should return different colors if a
396 manifest is present */
397 hBrush = (HBRUSH)DefWindowProcW(GetParent(hwnd), WM_CTLCOLORSTATIC,
398 (WPARAM)hdc, (LPARAM)hwnd);
399 }
400 return hBrush;
401 }
402
403 static VOID STATIC_InitColours(void)
404 {
405 color_3ddkshadow = GetSysColor(COLOR_3DDKSHADOW);
406 color_3dshadow = GetSysColor(COLOR_3DSHADOW);
407 color_3dhighlight = GetSysColor(COLOR_3DHIGHLIGHT);
408 }
409
410 /***********************************************************************
411 * hasTextStyle
412 *
413 * Tests if the control displays text.
414 */
415 static BOOL hasTextStyle( DWORD style )
416 {
417 switch(style & SS_TYPEMASK)
418 {
419 case SS_SIMPLE:
420 case SS_LEFT:
421 case SS_LEFTNOWORDWRAP:
422 case SS_CENTER:
423 case SS_RIGHT:
424 case SS_OWNERDRAW:
425 return TRUE;
426 }
427
428 return FALSE;
429 }
430
431 /***********************************************************************
432 * StaticWndProc_common
433 */
434 static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam,
435 LPARAM lParam, BOOL unicode )
436 {
437 LRESULT lResult = 0;
438 LONG full_style = GetWindowLongW( hwnd, GWL_STYLE );
439 LONG style = full_style & SS_TYPEMASK;
440
441 switch (uMsg)
442 {
443 case WM_CREATE:
444 if (style < 0L || style > SS_TYPEMASK)
445 {
446 ERR("Unknown style 0x%02lx\n", style );
447 return -1;
448 }
449 STATIC_update_uistate(hwnd, unicode);
450 STATIC_InitColours();
451 break;
452
453 case WM_NCDESTROY:
454 if (style == SS_ICON) {
455 /*
456 * FIXME
457 * DestroyIcon32( STATIC_SetIcon( wndPtr, 0 ) );
458 *
459 * We don't want to do this yet because DestroyIcon32 is broken. If the icon
460 * had already been loaded by the application the last thing we want to do is
461 * GlobalFree16 the handle.
462 */
463 break;
464 }
465 else return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
466 DefWindowProcA(hwnd, uMsg, wParam, lParam);
467
468 case WM_ERASEBKGND:
469 /* do all painting in WM_PAINT like Windows does */
470 return 1;
471
472 case WM_PRINTCLIENT:
473 case WM_PAINT:
474 {
475 PAINTSTRUCT ps;
476 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd, &ps);
477 if (staticPaintFunc[style])
478 {
479 HRGN hOrigClipping;
480 setup_clipping(hwnd, hdc, &hOrigClipping);
481 (staticPaintFunc[style])( hwnd, hdc, full_style );
482 restore_clipping(hdc, hOrigClipping);
483 }
484 if (!wParam) EndPaint(hwnd, &ps);
485 }
486 break;
487
488 case WM_ENABLE:
489 STATIC_TryPaintFcn( hwnd, full_style );
490 if (full_style & SS_NOTIFY) {
491 if (wParam) {
492 SendMessageW( GetParent(hwnd), WM_COMMAND,
493 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_ENABLE ), (LPARAM)hwnd);
494 }
495 else {
496 SendMessageW( GetParent(hwnd), WM_COMMAND,
497 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DISABLE ), (LPARAM)hwnd);
498 }
499 }
500 break;
501
502 case WM_SYSCOLORCHANGE:
503 STATIC_InitColours();
504 STATIC_TryPaintFcn( hwnd, full_style );
505 break;
506
507 case WM_NCCREATE:
508 {
509 LPCSTR textA;
510 LPCWSTR textW;
511
512 if (full_style & SS_SUNKEN)
513 SetWindowLongW( hwnd, GWL_EXSTYLE,
514 GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_STATICEDGE );
515
516 if(unicode)
517 {
518 textA = NULL;
519 textW = ((LPCREATESTRUCTW)lParam)->lpszName;
520 }
521 else
522 {
523 textA = ((LPCREATESTRUCTA)lParam)->lpszName;
524 textW = NULL;
525 }
526
527 switch (style) {
528 case SS_ICON:
529 {
530 HICON hIcon;
531 if(unicode)
532 hIcon = STATIC_LoadIconW(hwnd, textW, full_style);
533 else
534 hIcon = STATIC_LoadIconA(hwnd, textA, full_style);
535 STATIC_SetIcon(hwnd, hIcon, full_style);
536 }
537 break;
538 case SS_BITMAP:
539 {
540 HBITMAP hBitmap;
541 if(unicode)
542 hBitmap = STATIC_LoadBitmapW(hwnd, textW);
543 else
544 hBitmap = STATIC_LoadBitmapA(hwnd, textA);
545 STATIC_SetBitmap(hwnd, hBitmap, full_style);
546 }
547 break;
548 }
549 /* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
550 the enhanced metafile that was specified as the window text. */
551 }
552 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
553 DefWindowProcA(hwnd, uMsg, wParam, lParam);
554
555 case WM_SETTEXT:
556 if (hasTextStyle( full_style ))
557 {
558 if (HIWORD(lParam))
559 {
560 if(unicode)
561 lResult = DefWindowProcW( hwnd, uMsg, wParam, lParam );
562 else
563 lResult = DefWindowProcA( hwnd, uMsg, wParam, lParam );
564 STATIC_TryPaintFcn( hwnd, full_style );
565 }
566 }
567 break;
568
569 case WM_SETFONT:
570 if (hasTextStyle( full_style ))
571 {
572 SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, wParam );
573 if (LOWORD(lParam))
574 RedrawWindow( hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
575 }
576 break;
577
578 case WM_GETFONT:
579 return GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
580
581 case WM_NCHITTEST:
582 if (full_style & SS_NOTIFY)
583 return HTCLIENT;
584 else
585 return HTTRANSPARENT;
586
587 case WM_GETDLGCODE:
588 return DLGC_STATIC;
589
590 case WM_LBUTTONDOWN:
591 case WM_NCLBUTTONDOWN:
592 if (full_style & SS_NOTIFY)
593 SendMessageW( GetParent(hwnd), WM_COMMAND,
594 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_CLICKED ), (LPARAM)hwnd);
595 return 0;
596
597 case WM_LBUTTONDBLCLK:
598 case WM_NCLBUTTONDBLCLK:
599 if (full_style & SS_NOTIFY)
600 SendMessageW( GetParent(hwnd), WM_COMMAND,
601 MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DBLCLK ), (LPARAM)hwnd);
602 return 0;
603
604 case STM_GETIMAGE:
605 return (LRESULT)STATIC_GetImage( hwnd, wParam, full_style );
606 #ifndef __REACTOS__
607 case STM_GETICON16:
608 #endif
609 case STM_GETICON:
610 return (LRESULT)STATIC_GetImage( hwnd, IMAGE_ICON, full_style );
611
612 case STM_SETIMAGE:
613 switch(wParam) {
614 case IMAGE_BITMAP:
615 lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
616 break;
617 // case IMAGE_ENHMETAFILE:
618 // lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
619 // break;
620 case IMAGE_ICON:
621 case IMAGE_CURSOR:
622 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
623 break;
624 default:
625 FIXME("STM_SETIMAGE: Unhandled type %x\n", wParam);
626 break;
627 }
628 STATIC_TryPaintFcn( hwnd, full_style );
629 break;
630
631 #ifndef __REACTOS__
632 case STM_SETICON16:
633 #endif
634 case STM_SETICON:
635 lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
636 STATIC_TryPaintFcn( hwnd, full_style );
637 break;
638
639 case WM_UPDATEUISTATE:
640 if (unicode)
641 DefWindowProcW(hwnd, uMsg, wParam, lParam);
642 else
643 DefWindowProcA(hwnd, uMsg, wParam, lParam);
644
645 if (STATIC_update_uistate(hwnd, unicode) && hasTextStyle( full_style ))
646 {
647 RedrawWindow( hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
648 }
649 break;
650
651 default:
652 return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
653 DefWindowProcA(hwnd, uMsg, wParam, lParam);
654 }
655 return lResult;
656 }
657
658 /***********************************************************************
659 * StaticWndProcA
660 */
661 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
662 {
663 if (!IsWindow( hWnd )) return 0;
664 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, FALSE);
665 }
666
667 /***********************************************************************
668 * StaticWndProcW
669 */
670 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
671 {
672 if (!IsWindow( hWnd )) return 0;
673 return StaticWndProc_common(hWnd, uMsg, wParam, lParam, TRUE);
674 }
675
676 static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
677 {
678 DRAWITEMSTRUCT dis;
679 HFONT font, oldFont = NULL;
680 UINT id = (UINT)GetWindowLongPtrW( hwnd, GWLP_ID );
681
682 dis.CtlType = ODT_STATIC;
683 dis.CtlID = id;
684 dis.itemID = 0;
685 dis.itemAction = ODA_DRAWENTIRE;
686 dis.itemState = IsWindowEnabled(hwnd) ? 0 : ODS_DISABLED;
687 dis.hwndItem = hwnd;
688 dis.hDC = hdc;
689 dis.itemData = 0;
690 GetClientRect( hwnd, &dis.rcItem );
691
692 font = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
693 if (font) oldFont = SelectObject( hdc, font );
694 SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
695 SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
696 if (font) SelectObject( hdc, oldFont );
697 }
698
699 static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
700 {
701 RECT rc;
702 HBRUSH hBrush;
703 HFONT hFont, hOldFont = NULL;
704 DWORD wFormat;
705 INT len, buf_size;
706 WCHAR *text;
707
708 GetClientRect( hwnd, &rc);
709
710 switch (style & SS_TYPEMASK)
711 {
712 case SS_LEFT:
713 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
714 break;
715
716 case SS_CENTER:
717 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
718 break;
719
720 case SS_RIGHT:
721 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
722 break;
723
724 case SS_SIMPLE:
725 wFormat = DT_LEFT | DT_SINGLELINE;
726 break;
727
728 case SS_LEFTNOWORDWRAP:
729 wFormat = DT_LEFT | DT_EXPANDTABS;
730 break;
731
732 default:
733 return;
734 }
735
736 if (style & SS_NOPREFIX)
737 wFormat |= DT_NOPREFIX;
738 else if (get_ui_state(hwnd) & UISF_HIDEACCEL)
739 wFormat |= DT_HIDEPREFIX;
740
741 if ((style & SS_TYPEMASK) != SS_SIMPLE)
742 {
743 if (style & SS_CENTERIMAGE)
744 wFormat |= DT_SINGLELINE | DT_VCENTER;
745 if (style & SS_EDITCONTROL)
746 wFormat |= DT_EDITCONTROL;
747 if (style & SS_ENDELLIPSIS)
748 wFormat |= DT_SINGLELINE | DT_END_ELLIPSIS;
749 if (style & SS_PATHELLIPSIS)
750 wFormat |= DT_SINGLELINE | DT_PATH_ELLIPSIS;
751 if (style & SS_WORDELLIPSIS)
752 wFormat |= DT_SINGLELINE | DT_WORD_ELLIPSIS;
753 }
754
755 if ((hFont = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET )))
756 hOldFont = (HFONT)SelectObject( hdc, hFont );
757
758 /* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
759 brush is not used */
760 hBrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
761
762 if ((style & SS_TYPEMASK) != SS_SIMPLE)
763 {
764 FillRect( hdc, &rc, hBrush );
765 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
766 }
767
768 buf_size = 256;
769 if (!(text = HeapAlloc( GetProcessHeap(), 0, buf_size * sizeof(WCHAR) )))
770 goto no_TextOut;
771
772 while ((len = InternalGetWindowText( hwnd, text, buf_size )) == buf_size - 1)
773 {
774 buf_size *= 2;
775 if (!(text = HeapReAlloc( GetProcessHeap(), 0, text, buf_size * sizeof(WCHAR) )))
776 goto no_TextOut;
777 }
778
779 if (!len) goto no_TextOut;
780
781 if (((style & SS_TYPEMASK) == SS_SIMPLE) && (style & SS_NOPREFIX))
782 {
783 /* Windows uses the faster ExtTextOut() to draw the text and
784 to paint the whole client rectangle with the text background
785 color. Reference: "Static Controls" by Kyle Marsh, 1992 */
786 ExtTextOutW( hdc, rc.left, rc.top, ETO_CLIPPED | ETO_OPAQUE,
787 &rc, text, len, NULL );
788 }
789 else
790 {
791 DrawTextW( hdc, text, -1, &rc, wFormat );
792 }
793
794 no_TextOut:
795 HeapFree( GetProcessHeap(), 0, text );
796
797 if (hFont)
798 SelectObject( hdc, hOldFont );
799 }
800
801 static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
802 {
803 RECT rc;
804 HBRUSH hBrush;
805
806 GetClientRect( hwnd, &rc);
807
808 /* FIXME: send WM_CTLCOLORSTATIC */
809 switch (style & SS_TYPEMASK)
810 {
811 case SS_BLACKRECT:
812 hBrush = CreateSolidBrush(color_3ddkshadow);
813 FillRect( hdc, &rc, hBrush );
814 break;
815 case SS_GRAYRECT:
816 hBrush = CreateSolidBrush(color_3dshadow);
817 FillRect( hdc, &rc, hBrush );
818 break;
819 case SS_WHITERECT:
820 hBrush = CreateSolidBrush(color_3dhighlight);
821 FillRect( hdc, &rc, hBrush );
822 break;
823 case SS_BLACKFRAME:
824 hBrush = CreateSolidBrush(color_3ddkshadow);
825 FrameRect( hdc, &rc, hBrush );
826 break;
827 case SS_GRAYFRAME:
828 hBrush = CreateSolidBrush(color_3dshadow);
829 FrameRect( hdc, &rc, hBrush );
830 break;
831 case SS_WHITEFRAME:
832 hBrush = CreateSolidBrush(color_3dhighlight);
833 FrameRect( hdc, &rc, hBrush );
834 break;
835 default:
836 return;
837 }
838 DeleteObject( hBrush );
839 }
840
841 /* Modified for ReactOS */
842 static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
843 {
844 RECT rc, iconRect;
845 HBRUSH hbrush;
846 HICON hIcon;
847 ICONINFO info;
848
849 GetClientRect( hwnd, &rc );
850 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
851 hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
852 if (!hIcon || (!GetIconInfo(hIcon, &info)))
853 {
854 FillRect(hdc, &rc, hbrush);
855 }
856 else
857 {
858 BITMAP bm;
859 if (!GetObjectW(info.hbmColor, sizeof(BITMAP), &bm)) return;
860 if (style & SS_CENTERIMAGE)
861 {
862 iconRect.left = (rc.right - rc.left) / 2 - bm.bmWidth / 2;
863 iconRect.top = (rc.bottom - rc.top) / 2 - bm.bmHeight / 2;
864 iconRect.right = iconRect.left + bm.bmWidth;
865 iconRect.bottom = iconRect.top + bm.bmHeight;
866 }
867 else
868 iconRect = rc;
869 FillRect( hdc, &rc, hbrush );
870 DrawIconEx( hdc, iconRect.left, iconRect.top, hIcon, iconRect.right - iconRect.left,
871 iconRect.bottom - iconRect.top, 0, NULL, DI_NORMAL );
872 }
873 }
874
875 static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
876 {
877 HDC hMemDC;
878 HBITMAP hBitmap, oldbitmap;
879 HBRUSH hbrush;
880
881 /* message is still sent, even if the returned brush is not used */
882 hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
883
884 if ((hBitmap = (HBITMAP)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET ))
885 && (GetObjectType(hBitmap) == OBJ_BITMAP)
886 && (hMemDC = CreateCompatibleDC( hdc )))
887 {
888 BITMAP bm;
889 RECT rcClient;
890 LOGBRUSH brush;
891
892 GetObjectW(hBitmap, sizeof(bm), &bm);
893 oldbitmap = SelectObject(hMemDC, hBitmap);
894
895 /* Set the background color for monochrome bitmaps
896 to the color of the background brush */
897 if (GetObjectW( hbrush, sizeof(brush), &brush ))
898 {
899 if (brush.lbStyle == BS_SOLID)
900 SetBkColor(hdc, brush.lbColor);
901 }
902 GetClientRect(hwnd, &rcClient);
903 if (style & SS_CENTERIMAGE)
904 {
905 INT x, y;
906 x = (rcClient.right - rcClient.left)/2 - bm.bmWidth/2;
907 y = (rcClient.bottom - rcClient.top)/2 - bm.bmHeight/2;
908 FillRect( hdc, &rcClient, hbrush );
909 BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
910 SRCCOPY);
911 }
912 else
913 {
914 StretchBlt(hdc, 0, 0, rcClient.right - rcClient.left,
915 rcClient.bottom - rcClient.top, hMemDC,
916 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
917 }
918 SelectObject(hMemDC, oldbitmap);
919 DeleteDC(hMemDC);
920 }
921 else
922 {
923 RECT rcClient;
924 GetClientRect( hwnd, &rcClient );
925 FillRect( hdc, &rcClient, hbrush );
926 }
927 }
928
929
930 //static void STATIC_PaintEnhMetafn(HWND hwnd, HDC hdc, DWORD style )
931 //{
932 // HENHMETAFILE hEnhMetaFile;
933 // RECT rc;
934 // HBRUSH hbrush;
935 //
936 // GetClientRect(hwnd, &rc);
937 // hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
938 // FillRect(hdc, &rc, hbrush);
939 // if ((hEnhMetaFile = (HENHMETAFILE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
940 // {
941 // /* The control's current font is not selected into the
942 // device context! */
943 // if (GetObjectType(hEnhMetaFile) == OBJ_ENHMETAFILE)
944 // PlayEnhMetaFile(hdc, hEnhMetaFile, &rc);
945 // }
946 //}
947
948
949 static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
950 {
951 RECT rc;
952
953 /* FIXME: sometimes (not always) sends WM_CTLCOLORSTATIC */
954 GetClientRect( hwnd, &rc );
955 switch (style & SS_TYPEMASK)
956 {
957 case SS_ETCHEDHORZ:
958 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
959 break;
960 case SS_ETCHEDVERT:
961 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
962 break;
963 case SS_ETCHEDFRAME:
964 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
965 break;
966 }
967 }