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

Last change on this file since 3153 was 3153, checked in by cbratschi, 25 years ago

merged with Corel 20000317, small icon

File size: 21.6 KB
Line 
1/* $Id: static.cpp,v 1.19 2000-03-18 16:13:37 cbratschi 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 hBrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
616 hdc, hwnd );
617 if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH);
618 FillRect( hdc, &rc, hBrush );
619
620 if (!IsWindowEnabled(hwnd)) SetTextColor(hdc,GetSysColor(COLOR_GRAYTEXT));
621
622 textLen = GetWindowTextLengthA(hwnd);
623 if (textLen > 0)
624 {
625 char* text;
626
627 textLen++;
628 text = (char*)malloc(textLen);
629 GetWindowTextA(hwnd,text,textLen);
630 DrawTextExA(hdc,text,-1,&rc,wFormat,NULL);
631 free(text);
632 }
633}
634
635static void STATIC_PaintRectfn( HWND hwnd, HDC hdc )
636{
637 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
638 RECT rc;
639 HBRUSH hBrush;
640
641 GetClientRect( hwnd, &rc);
642
643 switch (dwStyle & SS_TYPEMASK)
644 {
645 case SS_BLACKRECT:
646 hBrush = CreateSolidBrush(color_windowframe);
647 FillRect( hdc, &rc, hBrush );
648 break;
649 case SS_GRAYRECT:
650 hBrush = CreateSolidBrush(color_background);
651 FillRect( hdc, &rc, hBrush );
652 break;
653 case SS_WHITERECT:
654 hBrush = CreateSolidBrush(color_window);
655 FillRect( hdc, &rc, hBrush );
656 break;
657 case SS_BLACKFRAME:
658 hBrush = CreateSolidBrush(color_windowframe);
659 FrameRect( hdc, &rc, hBrush );
660 break;
661 case SS_GRAYFRAME:
662 hBrush = CreateSolidBrush(color_background);
663 FrameRect( hdc, &rc, hBrush );
664 break;
665 case SS_WHITEFRAME:
666 hBrush = CreateSolidBrush(color_window);
667 FrameRect( hdc, &rc, hBrush );
668 break;
669 default:
670 return;
671 }
672 DeleteObject( hBrush );
673}
674
675
676static void STATIC_PaintIconfn( HWND hwnd, HDC hdc )
677{
678 RECT rc;
679 HBRUSH hbrush;
680 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
681 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
682
683 GetClientRect( hwnd, &rc );
684 hbrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
685 hdc, hwnd );
686 FillRect( hdc, &rc, hbrush );
687 if (dwStyle & SS_CENTERIMAGE)
688 {
689 ICONINFO ii;
690 BITMAP bmp;
691
692 if (!GetIconInfo(infoPtr->hIcon,&ii)) return;
693 if (ii.hbmColor)
694 GetObjectA(ii.hbmColor,sizeof(BITMAP),(LPVOID)&bmp);
695 else
696 {
697 GetObjectA(ii.hbmMask,sizeof(BITMAP),(LPVOID)&bmp);
698 bmp.bmHeight /= 2;
699 }
700 DrawIcon(hdc,(rc.right-bmp.bmWidth)/2,(rc.bottom-bmp.bmHeight)/2,infoPtr->hIcon);
701 if (ii.hbmColor) DeleteObject(ii.hbmColor);
702 if (ii.hbmMask) DeleteObject(ii.hbmMask);
703 } else if (infoPtr->hIcon) DrawIcon(hdc,rc.left,rc.top,infoPtr->hIcon);
704}
705
706static void STATIC_PaintBitmapfn(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 HDC hMemDC;
713 HBITMAP oldbitmap;
714
715 GetClientRect( hwnd, &rc );
716 hbrush = SendMessageA( GetParent(hwnd), WM_CTLCOLORSTATIC,
717 hdc, hwnd );
718 FillRect( hdc, &rc, hbrush );
719
720 if (infoPtr->hIcon)
721 {
722 BITMAP bm;
723
724 if(GetObjectType(infoPtr->hIcon) != OBJ_BITMAP) return;
725 if (!(hMemDC = CreateCompatibleDC( hdc ))) return;
726
727 GetObjectA(infoPtr->hIcon, sizeof(bm), &bm);
728 oldbitmap = SelectObject(hMemDC, infoPtr->hIcon);
729
730 // Paint the image in center area
731 if(dwStyle & SS_CENTERIMAGE)
732 {
733 SIZE szbm;
734 SIZE szdc;
735
736 if(bm.bmWidth > rc.right - rc.left)
737 {
738 szdc.cx = 0;
739 szbm.cx = (bm.bmWidth - (rc.right - rc.left)) / 2;
740 bm.bmWidth = rc.right - rc.left;
741 }
742 else
743 {
744 szbm.cx = 0;
745 szdc.cx = ((rc.right - rc.left) - bm.bmWidth) / 2;
746 }
747 if(bm.bmHeight > rc.bottom - rc.top)
748 {
749 szdc.cy = 0;
750 szbm.cy = (bm.bmHeight - (rc.bottom - rc.top)) / 2;
751 bm.bmWidth = rc.bottom - rc.top;
752 }
753 else
754 {
755 szbm.cy = 0;
756 szdc.cy = ((rc.bottom - rc.top) - bm.bmHeight) / 2;
757 }
758 BitBlt(hdc, szdc.cx, szdc.cy, bm.bmWidth, bm.bmHeight, hMemDC,
759 szbm.cx, szbm.cy, SRCCOPY);
760 }
761 else
762 {
763 BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
764 }
765
766 SelectObject(hMemDC, oldbitmap);
767 DeleteDC(hMemDC);
768 }
769}
770
771static void STATIC_PaintMetafilefn(HWND hwnd,HDC hdc)
772{
773 RECT rect;
774 HBRUSH hbrush;
775 STATICINFO *infoPtr = (STATICINFO *)GetInfoPtr(hwnd);
776
777 GetClientRect(hwnd,&rect);
778 hbrush = SendMessageA(GetParent(hwnd),WM_CTLCOLORSTATIC,hdc,hwnd);
779 FillRect(hdc,&rect,hbrush);
780
781 if (infoPtr->hIcon) PlayEnhMetaFile(hdc,(HENHMETAFILE)infoPtr->hIcon,&rect);
782}
783
784static void STATIC_PaintOwnerDrawfn(HWND hwnd,HDC hdc)
785{
786 DRAWITEMSTRUCT di;
787
788 di.CtlType = ODT_STATIC;
789 di.CtlID = GetWindowLongA(hwnd,GWL_ID);
790 di.itemID = 0;
791 di.itemAction = ODA_DRAWENTIRE;
792 di.itemState = ODS_DEFAULT;
793 di.hwndItem = hwnd;
794 di.hDC = hdc;
795 GetClientRect(hwnd,&di.rcItem);
796 di.itemData = 0;
797
798 SendMessageA(GetParent(hwnd),WM_CTLCOLORSTATIC,hdc,hwnd);
799 SendMessageA(GetParent(hwnd),WM_DRAWITEM,di.CtlID,(LPARAM)&di);
800}
801
802static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc )
803{
804 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
805 RECT rc;
806
807 GetClientRect( hwnd, &rc );
808 switch (dwStyle & SS_TYPEMASK)
809 {
810 case SS_ETCHEDHORZ:
811 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
812 break;
813 case SS_ETCHEDVERT:
814 DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
815 break;
816 case SS_ETCHEDFRAME:
817 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
818 break;
819 }
820}
821
822BOOL STATIC_Register()
823{
824 WNDCLASSA wndClass;
825
826//SvL: Don't check this now
827// if (GlobalFindAtomA(STATICCLASSNAME)) return FALSE;
828
829 ZeroMemory(&wndClass,sizeof(WNDCLASSA));
830 wndClass.style = CS_GLOBALCLASS | CS_HREDRAW | CS_PARENTDC;
831 wndClass.lpfnWndProc = (WNDPROC)StaticWndProc;
832 wndClass.cbClsExtra = 0;
833 wndClass.cbWndExtra = sizeof(STATICINFO);
834 wndClass.hCursor = LoadCursorA (0,IDC_ARROWA);
835 wndClass.hbrBackground = (HBRUSH)0;
836 wndClass.lpszClassName = STATICCLASSNAME;
837
838 return RegisterClassA(&wndClass);
839}
840
841
842BOOL STATIC_Unregister()
843{
844 if (GlobalFindAtomA (STATICCLASSNAME))
845 return UnregisterClassA(STATICCLASSNAME,(HINSTANCE)NULL);
846 else return FALSE;
847}
Note: See TracBrowser for help on using the repository browser.