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

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

hittest workaround for static controls + registerwindowmessage rewrite

File size: 23.3 KB
Line 
1/* $Id: static.cpp,v 1.22 2001-03-25 08:50:42 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 //SvL: If a static window has children, then we can't return HTTRANSPARENT
417 // here. For some reason PM then sends all mouse messages to the parent
418 // of the static window; even if they are intended for the children of
419 // the static window.
420 // TODO: This could break some win32 apps (parent not receiving mouse
421 // message for static window (non-child) area)
422 if(GetWindow(hwnd, GW_HWNDFIRST) != 0) {
423 return HTCLIENT;
424 }
425
426 if (dwStyle & SS_NOTIFY)
427 lResult = HTCLIENT;
428 else lResult = HTTRANSPARENT;
429
430 return lResult;
431}
432
433LRESULT STATIC_GetDlgCode(HWND hwnd,WPARAM wParam,LPARAM lParam)
434{
435 return DLGC_STATIC;
436}
437
438LRESULT STATIC_GetIcon(HWND hwnd,WPARAM wParam,LPARAM lParam)
439{
440 STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
441
442 return infoPtr->hIcon;
443}
444
445LRESULT STATIC_GetImage(HWND hwnd,WPARAM wParam,LPARAM lParam)
446{
447 STATICINFO* infoPtr = (STATICINFO*)GetInfoPtr(hwnd);
448 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & SS_TYPEMASK;
449
450 switch (wParam)
451 {
452 case IMAGE_BITMAP:
453 if (style & SS_BITMAP) return infoPtr->hIcon;
454 break;
455
456 case IMAGE_CURSOR:
457 case IMAGE_ICON:
458 if (style & SS_ICON) return infoPtr->hIcon;
459 break;
460
461 case IMAGE_ENHMETAFILE:
462 if (style & SS_ENHMETAFILE) return infoPtr->hIcon;
463 break;
464
465 default:
466 break;
467 }
468
469 return 0;
470}
471
472LRESULT STATIC_SetImage(HWND hwnd,WPARAM wParam,LPARAM lParam)
473{
474 LRESULT lResult = 0;
475
476 switch (wParam)
477 {
478 case IMAGE_CURSOR:
479 case IMAGE_ICON:
480 lResult = STATIC_SetIcon(hwnd,(HICON)lParam);
481 break;
482
483 case IMAGE_BITMAP:
484 lResult = STATIC_SetBitmap(hwnd,(HBITMAP)lParam);
485 break;
486
487 case IMAGE_ENHMETAFILE:
488 lResult = STATIC_SetMetafile(hwnd,(HENHMETAFILE)lParam);
489 break;
490
491 default:
492 return 0;
493 }
494
495 if (lResult) InvalidateRect(hwnd,NULL,FALSE);
496
497 return lResult;
498}
499
500LRESULT STATIC_SetIconMsg(HWND hwnd,WPARAM wParam,LPARAM lParam)
501{
502 LRESULT lResult;
503
504 lResult = STATIC_SetIcon(hwnd,(HICON)wParam);
505
506 InvalidateRect(hwnd,NULL,FALSE);
507
508 return lResult;
509}
510
511LRESULT STATIC_Click(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
512{
513 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
514
515 if (dwStyle & SS_NOTIFY) SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),STN_CLICKED),hwnd);
516
517 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
518}
519
520LRESULT STATIC_DoubleClick(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
521{
522 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
523
524 if (dwStyle & SS_NOTIFY) SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),STN_DBLCLK),hwnd);
525
526 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
527}
528
529/***********************************************************************
530 * StaticWndProc
531 */
532LRESULT WINAPI StaticWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
533{
534 switch (uMsg)
535 {
536 case WM_NCCREATE:
537 return STATIC_NCCreate(hwnd,wParam,lParam);
538
539 case WM_CREATE:
540 return STATIC_Create(hwnd,wParam,lParam);
541
542 case WM_NCDESTROY:
543 return STATIC_NCDestroy(hwnd,wParam,lParam);
544
545 case WM_PAINT:
546 return STATIC_Paint(hwnd,wParam,lParam);
547
548 case WM_ENABLE:
549 return STATIC_Enable(hwnd,wParam,lParam);
550
551 case WM_SYSCOLORCHANGE:
552 return STATIC_SysColorChange(hwnd,wParam,lParam);
553
554 case WM_SETTEXT:
555 return STATIC_SetText(hwnd,wParam,lParam);
556
557 case WM_GETTEXT:
558 return STATIC_GetText(hwnd,wParam,lParam);
559
560 case WM_GETTEXTLENGTH:
561 return STATIC_GetTextLength(hwnd,wParam,lParam);
562
563 case WM_SETFONT:
564 return STATIC_SetFont(hwnd,wParam,lParam);
565
566 case WM_GETFONT:
567 return STATIC_GetFont(hwnd,wParam,lParam);
568
569 case WM_NCHITTEST:
570 return STATIC_NCHitTest(hwnd,wParam,lParam);
571
572 case WM_GETDLGCODE:
573 return STATIC_GetDlgCode(hwnd,wParam,lParam);
574
575 case WM_LBUTTONDOWN:
576 case WM_NCLBUTTONDOWN:
577 return STATIC_Click(hwnd,uMsg,wParam,lParam);
578
579 case WM_LBUTTONDBLCLK:
580 case WM_NCLBUTTONDBLCLK:
581 return STATIC_DoubleClick(hwnd,uMsg,wParam,lParam);
582
583 case STM_GETIMAGE:
584 return STATIC_GetImage(hwnd,wParam,lParam);
585
586 case STM_GETICON:
587 return STATIC_GetIcon(hwnd,wParam,lParam);
588
589 case STM_SETIMAGE:
590 return STATIC_SetImage(hwnd,wParam,lParam);
591
592 case STM_SETICON:
593 return STATIC_SetIconMsg(hwnd,wParam,lParam);
594
595 case STM_MSGMAX:
596 return 0; //CB: undocumented!
597
598 default:
599 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
600 break;
601 }
602
603 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
604}
605
606
607static void STATIC_PaintTextfn(HWND hwnd, HDC hdc )
608{
609 RECT rc;
610 HBRUSH hBrush;
611 WORD wFormat;
612 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
613 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
614 INT textLen;
615
616 GetClientRect(hwnd,&rc);
617
618 switch (dwStyle & SS_TYPEMASK)
619 {
620 case SS_LEFT:
621 wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
622 break;
623
624 case SS_CENTER:
625 case SS_CENTERIMAGE:
626 wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
627 break;
628
629 case SS_RIGHT:
630 wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP;
631 break;
632
633 case SS_SIMPLE:
634 wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP;
635 break;
636
637 case SS_LEFTNOWORDWRAP:
638 wFormat = DT_LEFT | DT_EXPANDTABS | DT_VCENTER;
639 break;
640
641 default:
642 return;
643 }
644
645 if (dwStyle & SS_NOPREFIX) wFormat |= DT_NOPREFIX;
646 if (dwStyle & SS_ENDELLIPSIS) wFormat |= DT_END_ELLIPSIS;
647 if (dwStyle & SS_PATHELLIPSIS) wFormat |= DT_PATH_ELLIPSIS;
648 if (dwStyle & SS_WORDELLIPSIS) wFormat |= DT_WORD_ELLIPSIS;
649
650 if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont );
651//SvL: This is what the latest Wine code does. Fixes the common color dialog
652#if 1
653 if ((dwStyle & SS_NOPREFIX) || ((dwStyle & SS_TYPEMASK) != SS_SIMPLE))
654 {
655 hBrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
656 hdc, hwnd );
657 if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
658 FillRect( hdc, &rc, hBrush );
659 }
660#else
661 hBrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
662 hdc, hwnd );
663 if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
664 FillRect( hdc, &rc, hBrush );
665#endif
666
667 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc,GetSysColor(COLOR_GRAYTEXT));
668
669 textLen = GetWindowTextLengthA(hwnd);
670 if (textLen > 0)
671 {
672 char* text;
673
674 textLen++;
675 text = (char*)malloc(textLen);
676 GetWindowTextA(hwnd,text,textLen);
677 DrawTextExA(hdc,text,-1,&rc,wFormat,NULL);
678 free(text);
679 }
680}
681
682static void STATIC_PaintRectfn( HWND hwnd, HDC hdc )
683{
684 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
685 RECT rc;
686 HBRUSH hBrush;
687
688 GetClientRect( hwnd, &rc);
689
690 switch (dwStyle & SS_TYPEMASK)
691 {
692 case SS_BLACKRECT:
693 hBrush = CreateSolidBrush(color_windowframe);
694 FillRect( hdc, &rc, hBrush );
695 break;
696 case SS_GRAYRECT:
697 hBrush = CreateSolidBrush(color_background);
698 FillRect( hdc, &rc, hBrush );
699 break;
700 case SS_WHITERECT:
701 hBrush = CreateSolidBrush(color_window);
702 FillRect( hdc, &rc, hBrush );
703 break;
704 case SS_BLACKFRAME:
705 hBrush = CreateSolidBrush(color_windowframe);
706 FrameRect( hdc, &rc, hBrush );
707 break;
708 case SS_GRAYFRAME:
709 hBrush = CreateSolidBrush(color_background);
710 FrameRect( hdc, &rc, hBrush );
711 break;
712 case SS_WHITEFRAME:
713 hBrush = CreateSolidBrush(color_window);
714 FrameRect( hdc, &rc, hBrush );
715 break;
716 default:
717 return;
718 }
719 DeleteObject( hBrush );
720}
721
722
723static void STATIC_PaintIconfn( HWND hwnd, HDC hdc )
724{
725 RECT rc;
726 HBRUSH hbrush;
727 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
728 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
729
730 GetClientRect( hwnd, &rc );
731 hbrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
732 hdc, hwnd );
733 FillRect( hdc, &rc, hbrush );
734 if (dwStyle & SS_CENTERIMAGE)
735 {
736 ICONINFO ii;
737 BITMAP bmp;
738
739 if (!GetIconInfo(infoPtr->hIcon,&ii)) return;
740 if (ii.hbmColor)
741 GetObjectA(ii.hbmColor,sizeof(BITMAP),(LPVOID)&bmp);
742 else
743 {
744 GetObjectA(ii.hbmMask,sizeof(BITMAP),(LPVOID)&bmp);
745 bmp.bmHeight /= 2;
746 }
747 DrawIcon(hdc,(rc.right-bmp.bmWidth)/2,(rc.bottom-bmp.bmHeight)/2,infoPtr->hIcon);
748 if (ii.hbmColor) DeleteObject(ii.hbmColor);
749 if (ii.hbmMask) DeleteObject(ii.hbmMask);
750 } else if (infoPtr->hIcon) DrawIcon(hdc,rc.left,rc.top,infoPtr->hIcon);
751}
752
753static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc )
754{
755 RECT rc;
756 HBRUSH hbrush;
757 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
758 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
759 HDC hMemDC;
760 HBITMAP oldbitmap;
761
762 GetClientRect( hwnd, &rc );
763 hbrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
764 hdc, hwnd );
765 FillRect( hdc, &rc, hbrush );
766
767 if (infoPtr->hIcon)
768 {
769 BITMAP bm;
770
771 if(GetObjectType(infoPtr->hIcon) != OBJ_BITMAP) return;
772 if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
773
774 GetObjectA(infoPtr->hIcon, sizeof(bm), &bm);
775 oldbitmap = SelectObject(hMemDC, infoPtr->hIcon);
776
777 // Paint the image in center area
778 if(dwStyle & SS_CENTERIMAGE)
779 {
780 SIZE szbm;
781 SIZE szdc;
782
783 if(bm.bmWidth > rc.right - rc.left)
784 {
785 szdc.cx = 0;
786 szbm.cx = (bm.bmWidth - (rc.right - rc.left)) / 2;
787 bm.bmWidth = rc.right - rc.left;
788 }
789 else
790 {
791 szbm.cx = 0;
792 szdc.cx = ((rc.right - rc.left) - bm.bmWidth) / 2;
793 }
794 if(bm.bmHeight > rc.bottom - rc.top)
795 {
796 szdc.cy = 0;
797 szbm.cy = (bm.bmHeight - (rc.bottom - rc.top)) / 2;
798 bm.bmWidth = rc.bottom - rc.top;
799 }
800 else
801 {
802 szbm.cy = 0;
803 szdc.cy = ((rc.bottom - rc.top) - bm.bmHeight) / 2;
804 }
805 BitBlt(hdc, szdc.cx, szdc.cy, bm.bmWidth, bm.bmHeight, hMemDC,
806 szbm.cx, szbm.cy, SRCCOPY);
807 }
808 else
809 {
810 BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
811 }
812
813 SelectObject(hMemDC, oldbitmap);
814 DeleteDC(hMemDC);
815 }
816}
817
818static void STATIC_PaintMetafilefn(HWND hwnd,HDC hdc)
819{
820 RECT rect;
821 HBRUSH hbrush;
822 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
823
824 GetClientRect(hwnd,&rect);
825 hbrush = SendMessageA(GetParent(hwnd),WM_CTLCOLORSTATIC,hdc,hwnd);
826 FillRect(hdc,&rect,hbrush);
827
828 if (infoPtr->hIcon) PlayEnhMetaFile(hdc,(HENHMETAFILE)infoPtr->hIcon,&rect);
829}
830
831static void STATIC_PaintOwnerDrawfn(HWND hwnd,HDC hdc)
832{
833 DRAWITEMSTRUCT di;
834
835 di.CtlType = ODT_STATIC;
836 di.CtlID = GetWindowLongA(hwnd,GWL_ID);
837 di.itemID = 0;
838 di.itemAction = ODA_DRAWENTIRE;
839 di.itemState = ODS_DEFAULT;
840 di.hwndItem = hwnd;
841 di.hDC = hdc;
842 GetClientRect(hwnd,&di.rcItem);
843 di.itemData = 0;
844
845 SendMessageA(GetParent(hwnd),WM_CTLCOLORSTATIC,hdc,hwnd);
846 SendMessageA(GetParent(hwnd),WM_DRAWITEM,di.CtlID,(LPARAM)&di);
847}
848
849static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc )
850{
851 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
852 RECT rc;
853
854 GetClientRect( hwnd, &rc );
855 switch (dwStyle & SS_TYPEMASK)
856 {
857 case SS_ETCHEDHORZ:
858 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
859 break;
860 case SS_ETCHEDVERT:
861 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
862 break;
863 case SS_ETCHEDFRAME:
864 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
865 break;
866 }
867}
868
869BOOL STATIC_Register()
870{
871 WNDCLASSA wndClass;
872
873//SvL: Don't check this now
874// if (GlobalFindAtomA(STATICCLASSNAME)) return FALSE;
875
876 ZeroMemory(&wndClass,sizeof(WNDCLASSA));
877 wndClass.style = CS_GLOBALCLASS | CS_HREDRAW | CS_PARENTDC;
878 wndClass.lpfnWndProc = (WNDPROC)StaticWndProc;
879 wndClass.cbClsExtra = 0;
880 wndClass.cbWndExtra = sizeof(STATICINFO);
881 wndClass.hCursor = LoadCursorA (0,IDC_ARROWA);
882 wndClass.hbrBackground = (HBRUSH)0;
883 wndClass.lpszClassName = STATICCLASSNAME;
884
885 return RegisterClassA(&wndClass);
886}
887
888
889BOOL STATIC_Unregister()
890{
891 if (GlobalFindAtomA (STATICCLASSNAME))
892 return UnregisterClassA(STATICCLASSNAME,(HINSTANCE)NULL);
893 else return FALSE;
894}
Note: See TracBrowser for help on using the repository browser.