source: trunk/src/user32/static.cpp@ 5404

Last change on this file since 5404 was 5404, checked in by sandervl, 24 years ago

WM_NCHITTEST changes; no longer rely on PM

File size: 23.3 KB
Line 
1/* $Id: static.cpp,v 1.23 2001-03-30 11:14:36 sandervl Exp $ */
2/*
3 * Static control
4 *
5 * Copyright 1999 Christoph Bratschi
6 *
7 * Copyright David W. Metcalfe, 1993
8 *
9 * Corel version: 20000317
10 * (WINE version: 990923)
11 *
12 * SvL:
13 * SS_REALSIZEIMAGE is supposed to prevent control resizing, but that doesn't
14 * appear to happen in NT (although the SDK docs are very clear about this)
15 * Need to figure out why. (not resizing messes up the bitmap control in
16 * the Microsoft Visual C++ 4.2 install program)
17 * Same thing happens with a very simply test app, so the installer
18 * does nothing special.
19 *
20 *
21 * Status: complete
22 * Version: 5.00
23 */
24
25#include <stdlib.h>
26#include <string.h>
27#include <os2win.h>
28#include "controls.h"
29#include "static.h"
30
31#define DBG_LOCALLOG DBG_static
32#include "dbglocal.h"
33
34//Prototypes
35
36static void STATIC_PaintTextfn( HWND hwnd, HDC hdc );
37static void STATIC_PaintRectfn( HWND hwnd, HDC hdc );
38static void STATIC_PaintIconfn( HWND hwnd, HDC hdc );
39static void STATIC_PaintBitmapfn( HWND hwnd, HDC hdc );
40static void STATIC_PaintMetafilefn(HWND hwnd,HDC hdc);
41static void STATIC_PaintOwnerDrawfn(HWND hwnd,HDC hdc);
42static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc );
43
44static COLORREF color_windowframe, color_background, color_window;
45
46
47typedef void (*pfPaint)( HWND, HDC );
48
49static pfPaint staticPaintFunc[SS_TYPEMASK+1] =
50{
51 STATIC_PaintTextfn, /* SS_LEFT */
52 STATIC_PaintTextfn, /* SS_CENTER */
53 STATIC_PaintTextfn, /* SS_RIGHT */
54 STATIC_PaintIconfn, /* SS_ICON */
55 STATIC_PaintRectfn, /* SS_BLACKRECT */
56 STATIC_PaintRectfn, /* SS_GRAYRECT */
57 STATIC_PaintRectfn, /* SS_WHITERECT */
58 STATIC_PaintRectfn, /* SS_BLACKFRAME */
59 STATIC_PaintRectfn, /* SS_GRAYFRAME */
60 STATIC_PaintRectfn, /* SS_WHITEFRAME */
61 NULL, /* SS_USERITEM */
62 STATIC_PaintTextfn, /* SS_SIMPLE */
63 STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */
64 STATIC_PaintOwnerDrawfn, /* SS_OWNERDRAW */
65 STATIC_PaintBitmapfn, /* SS_BITMAP */
66 STATIC_PaintMetafilefn, /* SS_ENHMETAFILE */
67 STATIC_PaintEtchedfn, /* SS_ETCHEDHORIZ */
68 STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */
69 STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */
70};
71
72static void STATIC_ResizeWindow(HWND hwnd,DWORD dwStyle,INT w,INT h)
73{
74 if (dwStyle & SS_RIGHTJUST)
75 {
76 RECT rect;
77
78 GetWindowRect(hwnd,&rect);
79 SetWindowPos(hwnd,0,rect.right-w,rect.bottom-h,w,h,SWP_NOACTIVATE | SWP_NOZORDER);
80 } else SetWindowPos(hwnd,0,0,0,w,h,SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
81}
82
83/***********************************************************************
84 * STATIC_SetIcon
85 *
86 * Set the icon for an SS_ICON control.
87 */
88static HICON STATIC_SetIcon( HWND hwnd, HICON hicon )
89{
90 HICON prevIcon;
91 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
92 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
93 ICONINFO ii;
94 BITMAP bmp;
95
96 if (infoPtr == NULL)
97 return 0;
98
99 if ((dwStyle & SS_TYPEMASK) != SS_ICON) return 0;
100
101 if (infoPtr->hIcon) DestroyIcon(infoPtr->hIcon);
102 prevIcon = infoPtr->hIcon;
103 infoPtr->hIcon = hicon;
104
105 if (!GetIconInfo(hicon,&ii)) return prevIcon;
106 if (ii.hbmColor)
107 GetObjectA(ii.hbmColor,sizeof(BITMAP),(LPVOID)&bmp);
108 else
109 {
110 GetObjectA(ii.hbmMask,sizeof(BITMAP),(LPVOID)&bmp);
111 bmp.bmHeight /= 2;
112 }
113
114#if 1
115 //SvL: Breaks MS Visual C++ install dialogs with static controls (no resize)
116 if (!(dwStyle & (SS_CENTERIMAGE))) STATIC_ResizeWindow(hwnd,dwStyle,bmp.bmWidth,bmp.bmHeight);
117#else
118 if (!(dwStyle & (SS_CENTERIMAGE | SS_REALSIZEIMAGE))) STATIC_ResizeWindow(hwnd,dwStyle,bmp.bmWidth,bmp.bmHeight);
119#endif
120
121 if (ii.hbmColor) DeleteObject(ii.hbmColor);
122 if (ii.hbmMask) DeleteObject(ii.hbmMask);
123
124 return prevIcon;
125}
126
127/***********************************************************************
128 * STATIC_SetBitmap
129 *
130 * Set the bitmap for an SS_BITMAP control.
131 */
132static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap )
133{
134 HBITMAP hOldBitmap;
135 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
136 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
137
138 if (infoPtr == NULL)
139 return 0;
140
141 if ((dwStyle & SS_TYPEMASK) != SS_BITMAP) return 0;
142
143 if (hBitmap && (GetObjectType(hBitmap) != OBJ_BITMAP)) {
144 //ERR("huh? hBitmap!=0, but not bitmap\n");
145 return 0;
146 }
147 hOldBitmap = infoPtr->hIcon;
148 infoPtr->hIcon = hBitmap;
149#if 1
150 //SvL: Breaks MS Visual C++ install dialogs with static controls (no resize)
151 if (hBitmap && !(dwStyle & (SS_CENTERIMAGE)))
152#else
153 if (hBitmap && !(dwStyle & (SS_CENTERIMAGE | SS_REALSIZEIMAGE)))
154#endif
155 {
156 BITMAP bm;
157
158 GetObjectA(hBitmap,sizeof(bm),&bm);
159 STATIC_ResizeWindow(hwnd,dwStyle,bm.bmWidth,bm.bmHeight);
160 }
161
162 return hOldBitmap;
163}
164
165static HENHMETAFILE STATIC_SetMetafile(HWND hwnd,HENHMETAFILE hMetafile)
166{
167 HENHMETAFILE hOldMetafile;
168
169 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
170 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
171
172 if ((dwStyle & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
173
174 hOldMetafile = infoPtr->hIcon;
175 infoPtr->hIcon = hMetafile;
176
177 return hOldMetafile;
178}
179
180/***********************************************************************
181 * STATIC_LoadIcon
182 *
183 * Load the icon for an SS_ICON control.
184 */
185static HICON STATIC_LoadIcon( HWND hwnd, LPCSTR name )
186{
187 HICON hicon;
188
189 hicon = LoadIconA(GetWindowLongA(hwnd,GWL_HINSTANCE),name);
190
191 if (!hicon)
192 hicon = LoadIconA(0, name);
193
194 return hicon;
195}
196
197/***********************************************************************
198 * STATIC_LoadBitmap
199 *
200 * Load the bitmap for an SS_BITMAP control.
201 */
202static HBITMAP STATIC_LoadBitmap( HWND hwnd, LPCSTR name )
203{
204 HBITMAP hbitmap;
205
206 hbitmap = LoadBitmapA(GetWindowLongA(hwnd,GWL_HINSTANCE),name);
207
208 if (!hbitmap) /* Try OEM icon (FIXME: is this right?) */
209 hbitmap = LoadBitmapA(0,name);
210
211 return hbitmap;
212}
213
214static HBITMAP STATIC_LoadMetafile(HWND hwnd,LPCSTR name)
215{
216 HENHMETAFILE hMetafile;
217
218 hMetafile = GetEnhMetaFileA(name); //CB: right?
219
220 return hMetafile;
221}
222
223/* message handler */
224
225LRESULT STATIC_NCCreate(HWND hwnd,WPARAM wParam,LPARAM lParam)
226{
227 CREATESTRUCTA *cs = (CREATESTRUCTA*)lParam;
228 STATICINFO* infoPtr;
229 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
230 DWORD style = dwStyle & SS_TYPEMASK;
231 DWORD dwExStyle = GetWindowLongA(hwnd,GWL_EXSTYLE);
232
233 infoPtr = (STATICINFO*)malloc(sizeof(STATICINFO));
234 infoPtr->hFont = 0;
235 infoPtr->dummy = 0;
236 infoPtr->hIcon = 0;
237 SetInfoPtr(hwnd,(DWORD)infoPtr);
238
239 if (dwStyle & SS_SUNKEN)
240 {
241 dwExStyle |= WS_EX_STATICEDGE;
242 SetWindowLongA(hwnd,GWL_EXSTYLE,dwExStyle);
243 }
244
245 if (style == SS_ICON)
246 {
247 if (cs->lpszName) //CB: is 0 a valid icon id? winhlp32: lpszName = NULL
248 {
249 if (!HIWORD(cs->lpszName) || cs->lpszName[0])
250 STATIC_SetIcon(hwnd,STATIC_LoadIcon(hwnd,cs->lpszName));
251 }
252 return TRUE;
253 }
254 if (style == SS_BITMAP)
255 {
256 if (cs->lpszName)
257 STATIC_SetBitmap(hwnd,STATIC_LoadBitmap(hwnd,cs->lpszName));
258 return TRUE;
259 }
260 if (style == SS_ENHMETAFILE)
261 {
262 if (cs->lpszName) STATIC_SetMetafile(hwnd,STATIC_LoadMetafile(hwnd,cs->lpszName));
263 return TRUE;
264 }
265 if (!HIWORD(cs->lpszName) && (cs->lpszName)) return TRUE;
266
267 return DefWindowProcA(hwnd,WM_NCCREATE,wParam,lParam);
268}
269
270LRESULT STATIC_Create(HWND hwnd,WPARAM wParam,LPARAM lParam)
271{
272 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
273
274 if ((style < 0L) || (style > SS_TYPEMASK))
275 {
276 //Unknown style
277 return (LRESULT)-1;
278 }
279
280 /* initialise colours */
281 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
282 color_background = GetSysColor(COLOR_BACKGROUND);
283 color_window = GetSysColor(COLOR_WINDOW);
284
285 return 0;
286}
287
288LRESULT STATIC_NCDestroy(HWND hwnd,WPARAM wParam,LPARAM lParam)
289{
290 STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
291 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
292
293 if ((style == SS_ICON) && infoPtr->hIcon)
294 {
295 DestroyIcon(infoPtr->hIcon);
296 } else if ((style == SS_BITMAP) && infoPtr->hIcon)
297 {
298 DeleteObject(infoPtr->hIcon);
299 } else if ((style == SS_ENHMETAFILE) && infoPtr->hIcon)
300 {
301 DeleteEnhMetaFile((HENHMETAFILE)infoPtr->hIcon);
302 }
303
304 free(infoPtr);
305
306 return DefWindowProcA(hwnd,WM_NCDESTROY,wParam,lParam);
307}
308
309LRESULT STATIC_Paint(HWND hwnd,WPARAM wParam,LPARAM lParam)
310{
311 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
312 PAINTSTRUCT ps;
313
314 BeginPaint(hwnd,&ps);
315 if (staticPaintFunc[style]) (staticPaintFunc[style])(hwnd,ps.hdc);
316 EndPaint(hwnd,&ps);
317
318 return 0;
319}
320
321LRESULT STATIC_Enable(HWND hwnd,WPARAM wParam,LPARAM lParam)
322{
323 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
324
325 if (dwStyle & SS_NOTIFY) SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),wParam ? STN_ENABLE:STN_DISABLE),hwnd);
326
327 InvalidateRect(hwnd,NULL,FALSE);
328
329 return 0;
330}
331
332LRESULT STATIC_SysColorChange(HWND hwnd,WPARAM wParam,LPARAM lParam)
333{
334 color_windowframe = GetSysColor(COLOR_WINDOWFRAME);
335 color_background = GetSysColor(COLOR_BACKGROUND);
336 color_window = GetSysColor(COLOR_WINDOW);
337
338 InvalidateRect(hwnd,NULL,TRUE);
339
340 return 0;
341}
342
343LRESULT STATIC_SetText(HWND hwnd,WPARAM wParam,LPARAM lParam)
344{
345 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
346
347 if (style == SS_ICON)
348 STATIC_SetIcon(hwnd,STATIC_LoadIcon(hwnd,(LPCSTR)lParam));
349 else if (style == SS_BITMAP)
350 STATIC_SetBitmap(hwnd,STATIC_LoadBitmap(hwnd,(LPCSTR)lParam));
351 else if (style == SS_ENHMETAFILE)
352 STATIC_SetMetafile(hwnd,STATIC_LoadMetafile(hwnd,(LPCSTR)lParam));
353 else
354 DefWindowProcA(hwnd,WM_SETTEXT,wParam,lParam);
355
356 InvalidateRect(hwnd,NULL,FALSE);
357
358 return TRUE;
359}
360
361LRESULT STATIC_GetText(HWND hwnd,WPARAM wParam,LPARAM lParam)
362{
363 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
364
365 if (style == SS_ICON)
366 {
367 STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
368
369 if ((wParam < 4) || !lParam) return 0;
370 memcpy((VOID*)lParam,&infoPtr->hIcon,4);
371
372 return 4;
373 } else return DefWindowProcA(hwnd,WM_GETTEXT,wParam,lParam);
374}
375
376LRESULT STATIC_GetTextLength(HWND hwnd,WPARAM wParam,LPARAM lParam)
377{
378 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
379
380 if (style == SS_ICON) return 4;
381 else return DefWindowProcA(hwnd,WM_GETTEXTLENGTH,wParam,lParam);
382}
383
384LRESULT STATIC_SetFont(HWND hwnd,WPARAM wParam,LPARAM lParam)
385{
386 STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
387 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
388
389 if (style == SS_ICON) return 0;
390 if (style == SS_BITMAP) return 0;
391 if (style == SS_ENHMETAFILE) return 0;
392
393 infoPtr->hFont = (HFONT)wParam;
394
395 if (LOWORD(lParam))
396 {
397 InvalidateRect(hwnd,NULL,FALSE);
398 UpdateWindow(hwnd);
399 }
400
401 return 0;
402}
403
404LRESULT STATIC_GetFont(HWND hwnd,WPARAM wParam,LPARAM lParam)
405{
406 STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
407
408 return infoPtr->hFont;
409}
410
411LRESULT STATIC_NCHitTest(HWND hwnd,WPARAM wParam,LPARAM lParam)
412{
413 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
414 LRESULT lResult;
415
416#ifndef ODIN_HITTEST
417 //SvL: If a static window has children, then we can't return HTTRANSPARENT
418 // here. For some reason PM then sends all mouse messages to the parent
419 // of the static window; even if they are intended for the children of
420 // the static window.
421 // TODO: This could break some win32 apps (parent not receiving mouse
422 // message for static window (non-child) area)
423 if(GetWindow(hwnd, GW_HWNDFIRST) != 0) {
424 return HTCLIENT;
425 }
426#endif
427
428 if (dwStyle & SS_NOTIFY)
429 lResult = HTCLIENT;
430 else lResult = HTTRANSPARENT;
431
432 return lResult;
433}
434
435LRESULT STATIC_GetDlgCode(HWND hwnd,WPARAM wParam,LPARAM lParam)
436{
437 return DLGC_STATIC;
438}
439
440LRESULT STATIC_GetIcon(HWND hwnd,WPARAM wParam,LPARAM lParam)
441{
442 STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
443
444 return infoPtr->hIcon;
445}
446
447LRESULT STATIC_GetImage(HWND hwnd,WPARAM wParam,LPARAM lParam)
448{
449 STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
450 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
451
452 switch (wParam)
453 {
454 case IMAGE_BITMAP:
455 if (style & SS_BITMAP) return infoPtr->hIcon;
456 break;
457
458 case IMAGE_CURSOR:
459 case IMAGE_ICON:
460 if (style & SS_ICON) return infoPtr->hIcon;
461 break;
462
463 case IMAGE_ENHMETAFILE:
464 if (style & SS_ENHMETAFILE) return infoPtr->hIcon;
465 break;
466
467 default:
468 break;
469 }
470
471 return 0;
472}
473
474LRESULT STATIC_SetImage(HWND hwnd,WPARAM wParam,LPARAM lParam)
475{
476 LRESULT lResult = 0;
477
478 switch (wParam)
479 {
480 case IMAGE_CURSOR:
481 case IMAGE_ICON:
482 lResult = STATIC_SetIcon(hwnd,(HICON)lParam);
483 break;
484
485 case IMAGE_BITMAP:
486 lResult = STATIC_SetBitmap(hwnd,(HBITMAP)lParam);
487 break;
488
489 case IMAGE_ENHMETAFILE:
490 lResult = STATIC_SetMetafile(hwnd,(HENHMETAFILE)lParam);
491 break;
492
493 default:
494 return 0;
495 }
496
497 if (lResult) InvalidateRect(hwnd,NULL,FALSE);
498
499 return lResult;
500}
501
502LRESULT STATIC_SetIconMsg(HWND hwnd,WPARAM wParam,LPARAM lParam)
503{
504 LRESULT lResult;
505
506 lResult = STATIC_SetIcon(hwnd,(HICON)wParam);
507
508 InvalidateRect(hwnd,NULL,FALSE);
509
510 return lResult;
511}
512
513LRESULT STATIC_Click(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
514{
515 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
516
517 if (dwStyle & SS_NOTIFY) SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),STN_CLICKED),hwnd);
518
519 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
520}
521
522LRESULT STATIC_DoubleClick(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
523{
524 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
525
526 if (dwStyle & SS_NOTIFY) SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),STN_DBLCLK),hwnd);
527
528 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
529}
530
531/***********************************************************************
532 * StaticWndProc
533 */
534LRESULT WINAPI StaticWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
535{
536 switch (uMsg)
537 {
538 case WM_NCCREATE:
539 return STATIC_NCCreate(hwnd,wParam,lParam);
540
541 case WM_CREATE:
542 return STATIC_Create(hwnd,wParam,lParam);
543
544 case WM_NCDESTROY:
545 return STATIC_NCDestroy(hwnd,wParam,lParam);
546
547 case WM_PAINT:
548 return STATIC_Paint(hwnd,wParam,lParam);
549
550 case WM_ENABLE:
551 return STATIC_Enable(hwnd,wParam,lParam);
552
553 case WM_SYSCOLORCHANGE:
554 return STATIC_SysColorChange(hwnd,wParam,lParam);
555
556 case WM_SETTEXT:
557 return STATIC_SetText(hwnd,wParam,lParam);
558
559 case WM_GETTEXT:
560 return STATIC_GetText(hwnd,wParam,lParam);
561
562 case WM_GETTEXTLENGTH:
563 return STATIC_GetTextLength(hwnd,wParam,lParam);
564
565 case WM_SETFONT:
566 return STATIC_SetFont(hwnd,wParam,lParam);
567
568 case WM_GETFONT:
569 return STATIC_GetFont(hwnd,wParam,lParam);
570
571 case WM_NCHITTEST:
572 return STATIC_NCHitTest(hwnd,wParam,lParam);
573
574 case WM_GETDLGCODE:
575 return STATIC_GetDlgCode(hwnd,wParam,lParam);
576
577 case WM_LBUTTONDOWN:
578 case WM_NCLBUTTONDOWN:
579 return STATIC_Click(hwnd,uMsg,wParam,lParam);
580
581 case WM_LBUTTONDBLCLK:
582 case WM_NCLBUTTONDBLCLK:
583 return STATIC_DoubleClick(hwnd,uMsg,wParam,lParam);
584
585 case STM_GETIMAGE:
586 return STATIC_GetImage(hwnd,wParam,lParam);
587
588 case STM_GETICON:
589 return STATIC_GetIcon(hwnd,wParam,lParam);
590
591 case STM_SETIMAGE:
592 return STATIC_SetImage(hwnd,wParam,lParam);
593
594 case STM_SETICON:
595 return STATIC_SetIconMsg(hwnd,wParam,lParam);
596
597 case STM_MSGMAX:
598 return 0; //CB: undocumented!
599
600 default:
601 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
602 break;
603 }
604
605 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
606}
607
608
609static void STATIC_PaintTextfn(HWND hwnd, HDC hdc )
610{
611 RECT rc;
612 HBRUSH hBrush;
613 WORD wFormat;
614 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
615 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
616 INT textLen;
617
618 GetClientRect(hwnd,&rc);
619
620 switch (dwStyle & SS_TYPEMASK)
621 {
622 case SS_LEFT:
623 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
624 break;
625
626 case SS_CENTER:
627 case SS_CENTERIMAGE:
628 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
629 break;
630
631 case SS_RIGHT:
632 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
633 break;
634
635 case SS_SIMPLE:
636 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
637 break;
638
639 case SS_LEFTNOWORDWRAP:
640 wFormat = DT_LEFT | DT_EXPANDTABS | DT_VCENTER;
641 break;
642
643 default:
644 return;
645 }
646
647 if (dwStyle & SS_NOPREFIX) wFormat |= DT_NOPREFIX;
648 if (dwStyle & SS_ENDELLIPSIS) wFormat |= DT_END_ELLIPSIS;
649 if (dwStyle & SS_PATHELLIPSIS) wFormat |= DT_PATH_ELLIPSIS;
650 if (dwStyle & SS_WORDELLIPSIS) wFormat |= DT_WORD_ELLIPSIS;
651
652 if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont );
653//SvL: This is what the latest Wine code does. Fixes the common color dialog
654#if 1
655 if ((dwStyle & SS_NOPREFIX) || ((dwStyle & SS_TYPEMASK) != SS_SIMPLE))
656 {
657 hBrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
658 hdc, hwnd );
659 if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
660 FillRect( hdc, &rc, hBrush );
661 }
662#else
663 hBrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
664 hdc, hwnd );
665 if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
666 FillRect( hdc, &rc, hBrush );
667#endif
668
669 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc,GetSysColor(COLOR_GRAYTEXT));
670
671 textLen = GetWindowTextLengthA(hwnd);
672 if (textLen > 0)
673 {
674 char* text;
675
676 textLen++;
677 text = (char*)malloc(textLen);
678 GetWindowTextA(hwnd,text,textLen);
679 DrawTextExA(hdc,text,-1,&rc,wFormat,NULL);
680 free(text);
681 }
682}
683
684static void STATIC_PaintRectfn( HWND hwnd, HDC hdc )
685{
686 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
687 RECT rc;
688 HBRUSH hBrush;
689
690 GetClientRect( hwnd, &rc);
691
692 switch (dwStyle & SS_TYPEMASK)
693 {
694 case SS_BLACKRECT:
695 hBrush = CreateSolidBrush(color_windowframe);
696 FillRect( hdc, &rc, hBrush );
697 break;
698 case SS_GRAYRECT:
699 hBrush = CreateSolidBrush(color_background);
700 FillRect( hdc, &rc, hBrush );
701 break;
702 case SS_WHITERECT:
703 hBrush = CreateSolidBrush(color_window);
704 FillRect( hdc, &rc, hBrush );
705 break;
706 case SS_BLACKFRAME:
707 hBrush = CreateSolidBrush(color_windowframe);
708 FrameRect( hdc, &rc, hBrush );
709 break;
710 case SS_GRAYFRAME:
711 hBrush = CreateSolidBrush(color_background);
712 FrameRect( hdc, &rc, hBrush );
713 break;
714 case SS_WHITEFRAME:
715 hBrush = CreateSolidBrush(color_window);
716 FrameRect( hdc, &rc, hBrush );
717 break;
718 default:
719 return;
720 }
721 DeleteObject( hBrush );
722}
723
724
725static void STATIC_PaintIconfn( HWND hwnd, HDC hdc )
726{
727 RECT rc;
728 HBRUSH hbrush;
729 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
730 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
731
732 GetClientRect( hwnd, &rc );
733 hbrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
734 hdc, hwnd );
735 FillRect( hdc, &rc, hbrush );
736 if (dwStyle & SS_CENTERIMAGE)
737 {
738 ICONINFO ii;
739 BITMAP bmp;
740
741 if (!GetIconInfo(infoPtr->hIcon,&ii)) return;
742 if (ii.hbmColor)
743 GetObjectA(ii.hbmColor,sizeof(BITMAP),(LPVOID)&bmp);
744 else
745 {
746 GetObjectA(ii.hbmMask,sizeof(BITMAP),(LPVOID)&bmp);
747 bmp.bmHeight /= 2;
748 }
749 DrawIcon(hdc,(rc.right-bmp.bmWidth)/2,(rc.bottom-bmp.bmHeight)/2,infoPtr->hIcon);
750 if (ii.hbmColor) DeleteObject(ii.hbmColor);
751 if (ii.hbmMask) DeleteObject(ii.hbmMask);
752 } else if (infoPtr->hIcon) DrawIcon(hdc,rc.left,rc.top,infoPtr->hIcon);
753}
754
755static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc )
756{
757 RECT rc;
758 HBRUSH hbrush;
759 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
760 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
761 HDC hMemDC;
762 HBITMAP oldbitmap;
763
764 GetClientRect( hwnd, &rc );
765 hbrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
766 hdc, hwnd );
767 FillRect( hdc, &rc, hbrush );
768
769 if (infoPtr->hIcon)
770 {
771 BITMAP bm;
772
773 if(GetObjectType(infoPtr->hIcon) != OBJ_BITMAP) return;
774 if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
775
776 GetObjectA(infoPtr->hIcon, sizeof(bm), &bm);
777 oldbitmap = SelectObject(hMemDC, infoPtr->hIcon);
778
779 // Paint the image in center area
780 if(dwStyle & SS_CENTERIMAGE)
781 {
782 SIZE szbm;
783 SIZE szdc;
784
785 if(bm.bmWidth > rc.right - rc.left)
786 {
787 szdc.cx = 0;
788 szbm.cx = (bm.bmWidth - (rc.right - rc.left)) / 2;
789 bm.bmWidth = rc.right - rc.left;
790 }
791 else
792 {
793 szbm.cx = 0;
794 szdc.cx = ((rc.right - rc.left) - bm.bmWidth) / 2;
795 }
796 if(bm.bmHeight > rc.bottom - rc.top)
797 {
798 szdc.cy = 0;
799 szbm.cy = (bm.bmHeight - (rc.bottom - rc.top)) / 2;
800 bm.bmWidth = rc.bottom - rc.top;
801 }
802 else
803 {
804 szbm.cy = 0;
805 szdc.cy = ((rc.bottom - rc.top) - bm.bmHeight) / 2;
806 }
807 BitBlt(hdc, szdc.cx, szdc.cy, bm.bmWidth, bm.bmHeight, hMemDC,
808 szbm.cx, szbm.cy, SRCCOPY);
809 }
810 else
811 {
812 BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
813 }
814
815 SelectObject(hMemDC, oldbitmap);
816 DeleteDC(hMemDC);
817 }
818}
819
820static void STATIC_PaintMetafilefn(HWND hwnd,HDC hdc)
821{
822 RECT rect;
823 HBRUSH hbrush;
824 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
825
826 GetClientRect(hwnd,&rect);
827 hbrush = SendMessageA(GetParent(hwnd),WM_CTLCOLORSTATIC,hdc,hwnd);
828 FillRect(hdc,&rect,hbrush);
829
830 if (infoPtr->hIcon) PlayEnhMetaFile(hdc,(HENHMETAFILE)infoPtr->hIcon,&rect);
831}
832
833static void STATIC_PaintOwnerDrawfn(HWND hwnd,HDC hdc)
834{
835 DRAWITEMSTRUCT di;
836
837 di.CtlType = ODT_STATIC;
838 di.CtlID = GetWindowLongA(hwnd,GWL_ID);
839 di.itemID = 0;
840 di.itemAction = ODA_DRAWENTIRE;
841 di.itemState = ODS_DEFAULT;
842 di.hwndItem = hwnd;
843 di.hDC = hdc;
844 GetClientRect(hwnd,&di.rcItem);
845 di.itemData = 0;
846
847 SendMessageA(GetParent(hwnd),WM_CTLCOLORSTATIC,hdc,hwnd);
848 SendMessageA(GetParent(hwnd),WM_DRAWITEM,di.CtlID,(LPARAM)&di);
849}
850
851static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc )
852{
853 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
854 RECT rc;
855
856 GetClientRect( hwnd, &rc );
857 switch (dwStyle & SS_TYPEMASK)
858 {
859 case SS_ETCHEDHORZ:
860 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
861 break;
862 case SS_ETCHEDVERT:
863 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
864 break;
865 case SS_ETCHEDFRAME:
866 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
867 break;
868 }
869}
870
871BOOL STATIC_Register()
872{
873 WNDCLASSA wndClass;
874
875//SvL: Don't check this now
876// if (GlobalFindAtomA(STATICCLASSNAME)) return FALSE;
877
878 ZeroMemory(&wndClass,sizeof(WNDCLASSA));
879 wndClass.style = CS_GLOBALCLASS | CS_HREDRAW | CS_PARENTDC;
880 wndClass.lpfnWndProc = (WNDPROC)StaticWndProc;
881 wndClass.cbClsExtra = 0;
882 wndClass.cbWndExtra = sizeof(STATICINFO);
883 wndClass.hCursor = LoadCursorA (0,IDC_ARROWA);
884 wndClass.hbrBackground = (HBRUSH)0;
885 wndClass.lpszClassName = STATICCLASSNAME;
886
887 return RegisterClassA(&wndClass);
888}
889
890
891BOOL STATIC_Unregister()
892{
893 if (GlobalFindAtomA (STATICCLASSNAME))
894 return UnregisterClassA(STATICCLASSNAME,(HINSTANCE)NULL);
895 else return FALSE;
896}
Note: See TracBrowser for help on using the repository browser.