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

Last change on this file since 2912 was 2852, checked in by cbratschi, 26 years ago

merged with Corel WINE 20000212, added WS_EX_CONTEXTHELP

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