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