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

Last change on this file since 5120 was 4800, checked in by sandervl, 25 years ago

edit + static control fixes

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