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