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

Last change on this file since 4606 was 4512, checked in by sandervl, 25 years ago

Paint fix for static controls

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