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