source: trunk/src/user32/button.cpp@ 5648

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

YD: button WM_SETFONT bugfix

File size: 33.4 KB
Line 
1/* $Id: button.cpp,v 1.39 2001-05-03 18:13:10 sandervl Exp $ */
2/* File: button.cpp -- Button type widgets
3 *
4 * Copyright (C) 1993 Johannes Ruscheinski
5 * Copyright (C) 1993 David Metcalfe
6 * Copyright (C) 1994 Alexandre Julliard
7 * Copyright (c) 1999 Christoph Bratschi
8 *
9 * Corel version: 20000513
10 * (WINE version: 20000130)
11 *
12 * Status: complete
13 * Version: 5.00
14 */
15
16#include <string.h>
17#include <stdlib.h>
18#include <os2win.h>
19#include "controls.h"
20#include "button.h"
21#include <misc.h>
22#include "initterm.h"
23#include "syscolor.h"
24
25#define DBG_LOCALLOG DBG_button
26#include "dbglocal.h"
27
28#ifdef DEBUG
29char *GetMsgText(int Msg);
30#endif
31
32//Prototypes
33
34static void DrawDisabledText(HDC hdc,char* text,RECT* rtext,UINT format);
35
36static void PB_Paint(HWND hwnd,HDC hDC,WORD action);
37static void CB_Paint(HWND hwnd,HDC hDC,WORD action);
38static void GB_Paint(HWND hwnd,HDC hDC,WORD action);
39static void UB_Paint(HWND hwnd,HDC hDC,WORD action);
40static void OB_Paint(HWND hwnd,HDC hDC,WORD action);
41static void BUTTON_CheckAutoRadioButton(HWND hwnd);
42static void BUTTON_DrawPushButton(HWND hwnd,HDC hDC,WORD action,BOOL pushedState);
43static LRESULT BUTTON_LButtonDown(HWND hwnd,WPARAM wParam,LPARAM lParam);
44
45#define MAX_BTN_TYPE 12
46
47static const WORD maxCheckState[MAX_BTN_TYPE] =
48{
49 BUTTON_UNCHECKED, /* BS_PUSHBUTTON */
50 BUTTON_UNCHECKED, /* BS_DEFPUSHBUTTON */
51 BUTTON_CHECKED, /* BS_CHECKBOX */
52 BUTTON_CHECKED, /* BS_AUTOCHECKBOX */
53 BUTTON_CHECKED, /* BS_RADIOBUTTON */
54 BUTTON_3STATE, /* BS_3STATE */
55 BUTTON_3STATE, /* BS_AUTO3STATE */
56 BUTTON_UNCHECKED, /* BS_GROUPBOX */
57 BUTTON_UNCHECKED, /* BS_USERBUTTON */
58 BUTTON_CHECKED, /* BS_AUTORADIOBUTTON */
59 BUTTON_UNCHECKED, /* Not defined */
60 BUTTON_UNCHECKED /* BS_OWNERDRAW */
61};
62
63typedef void (*pfPaint)(HWND hwnd,HDC hdc,WORD action);
64
65static const pfPaint btnPaintFunc[MAX_BTN_TYPE] =
66{
67 PB_Paint, /* BS_PUSHBUTTON */
68 PB_Paint, /* BS_DEFPUSHBUTTON */
69 CB_Paint, /* BS_CHECKBOX */
70 CB_Paint, /* BS_AUTOCHECKBOX */
71 CB_Paint, /* BS_RADIOBUTTON */
72 CB_Paint, /* BS_3STATE */
73 CB_Paint, /* BS_AUTO3STATE */
74 GB_Paint, /* BS_GROUPBOX */
75 UB_Paint, /* BS_USERBUTTON */
76 CB_Paint, /* BS_AUTORADIOBUTTON */
77 NULL, /* Not defined */
78 OB_Paint /* BS_OWNERDRAW */
79};
80
81#define PAINT_BUTTON(hwnd,style,action) \
82 if (btnPaintFunc[style]) { \
83 HDC hdc = GetDC(hwnd); \
84 (btnPaintFunc[style])(hwnd,hdc,action); \
85 ReleaseDC(hwnd,hdc); }
86
87#define BUTTON_SEND_CTLCOLOR(hwnd,hdc) \
88 SendMessageA( GetParent(hwnd), WM_CTLCOLORBTN, \
89 (hdc),hwnd)
90
91static HBITMAP hbitmapCheckBoxes = 0;
92static WORD checkBoxWidth = 0, checkBoxHeight = 0;
93
94static LRESULT BUTTON_SendNotify(HWND hwnd,DWORD code)
95{
96 return SendMessageA(GetParent(hwnd),WM_COMMAND,MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID),code),hwnd);
97}
98
99static LRESULT BUTTON_GetDlgCode(HWND hwnd,WPARAM wParam,LPARAM lParam)
100{
101 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
102
103 switch (dwStyle & 0x0f)
104 {
105 case BS_AUTOCHECKBOX:
106 case BS_CHECKBOX:
107 return DLGC_WANTCHARS | DLGC_BUTTON;
108
109 case BS_PUSHBUTTON:
110 return DLGC_UNDEFPUSHBUTTON;
111
112 case BS_DEFPUSHBUTTON:
113 return DLGC_DEFPUSHBUTTON;
114
115 case BS_AUTORADIOBUTTON:
116 case BS_RADIOBUTTON:
117 return DLGC_RADIOBUTTON;
118
119 case BS_GROUPBOX:;
120 return DLGC_STATIC;
121
122 default:
123 return DLGC_BUTTON;
124 }
125}
126
127static LRESULT BUTTON_Enable(HWND hwnd,WPARAM wParam,LPARAM lParam)
128{
129 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
130
131 if ((dwStyle & BS_NOTIFY) && !wParam) BUTTON_SendNotify(hwnd,BN_DISABLE);
132
133 //PAINT_BUTTON(hwnd,dwStyle & 0x0f,ODA_DRAWENTIRE);
134 //SvL: 09/10/99 Force it to redraw properly
135 InvalidateRect( hwnd, NULL, FALSE );
136
137 return 0;
138}
139
140static LRESULT BUTTON_Create(HWND hwnd,WPARAM wParam,LPARAM lParam)
141{
142 BUTTONINFO* infoPtr;
143 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & 0x0f;
144
145 if (!hbitmapCheckBoxes)
146 {
147 BITMAP bmp;
148
149 hbitmapCheckBoxes = LoadBitmapA(hInstanceUser32, MAKEINTRESOURCEA(OBM_CHECKBOXES));
150 GetObjectA( hbitmapCheckBoxes, sizeof(bmp), &bmp );
151 if (GetObjectA(hbitmapCheckBoxes,sizeof(bmp),&bmp))
152 {
153 checkBoxWidth = bmp.bmWidth / 4;
154 checkBoxHeight = bmp.bmHeight / 3;
155 } else checkBoxWidth = checkBoxHeight = 0;
156 }
157 if ((style < 0L) || (style >= MAX_BTN_TYPE)) return -1; /* abort */
158
159 infoPtr = (BUTTONINFO*)malloc(sizeof(BUTTONINFO));
160 infoPtr->state = BUTTON_UNCHECKED;
161 infoPtr->hFont = 0;
162 infoPtr->hImage = 0;
163 SetInfoPtr(hwnd,(DWORD)infoPtr);
164
165 return 0;
166}
167
168static LRESULT BUTTON_Destroy(HWND hwnd,WPARAM wParam,LPARAM lParam)
169{
170 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
171
172 free(infoPtr);
173
174 return 0;
175}
176
177static LRESULT BUTTON_EraseBkgnd(HWND hwnd,WPARAM wParam,LPARAM lParam)
178{
179 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & 0x0f;
180 //SvL: TODO: NT does something extra for ownerdrawn buttons; check this
181 if(style == BS_OWNERDRAW) {
182 return DefWindowProcA(hwnd, WM_ERASEBKGND, wParam, lParam);
183 }
184 return 1;
185}
186
187static LRESULT BUTTON_Paint(HWND hwnd,WPARAM wParam,LPARAM lParam)
188{
189 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
190 DWORD style = dwStyle & 0x0f;
191
192 if (dwStyle & BS_NOTIFY) BUTTON_SendNotify(hwnd,BN_PAINT);
193
194 if (btnPaintFunc[style])
195 {
196 PAINTSTRUCT ps;
197
198 HDC hdc = wParam ? (HDC)wParam : BeginPaint(hwnd,&ps);
199 SetBkMode(hdc,OPAQUE);
200 (btnPaintFunc[style])(hwnd,hdc,ODA_DRAWENTIRE);
201 if(!wParam) EndPaint(hwnd,&ps);
202 } else return DefWindowProcA(hwnd,WM_PAINT,wParam,lParam);
203
204 return 0;
205}
206
207static LRESULT BUTTON_LButtonDblClk(HWND hwnd,WPARAM wParam,LPARAM lParam)
208{
209 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
210 DWORD style = dwStyle & 0x0f;
211
212 if(dwStyle & BS_NOTIFY || style == BS_RADIOBUTTON ||
213 style == BS_USERBUTTON || style == BS_OWNERDRAW)
214 BUTTON_SendNotify(hwnd,BN_DOUBLECLICKED);
215 else BUTTON_LButtonDown(hwnd,wParam,lParam);
216
217 return 0;
218}
219
220static LRESULT BUTTON_LButtonDown(HWND hwnd,WPARAM wParam,LPARAM lParam)
221{
222 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
223 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
224 DWORD style = dwStyle & 0x0F;
225
226 if (style == BS_GROUPBOX) return 0;
227 SetCapture(hwnd);
228 SetFocus(hwnd);
229 SendMessageA(hwnd,BM_SETSTATE,TRUE,0);
230 infoPtr->state |= BUTTON_BTNPRESSED;
231
232 if (dwStyle & BS_NOTIFY) BUTTON_SendNotify(hwnd,BN_HILITE);
233
234 return 0;
235}
236
237static LRESULT BUTTON_LButtonUp(HWND hwnd,WPARAM wParam,LPARAM lParam)
238{
239 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
240 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
241 DWORD style = dwStyle & 0x0F;
242 RECT rect;
243 POINT pt;
244
245 pt.x = LOWORD(lParam);
246 pt.y = HIWORD(lParam);
247
248 if (!(infoPtr->state & BUTTON_BTNPRESSED)) return 0;
249 infoPtr->state &= BUTTON_NSTATES;
250 if (!(infoPtr->state & BUTTON_HIGHLIGHTED))
251 {
252 ReleaseCapture();
253 return 0;
254 }
255 SendMessageA(hwnd,BM_SETSTATE,FALSE,0);
256 ReleaseCapture();
257 GetClientRect(hwnd,&rect);
258 if (PtInRect(&rect,pt))
259 {
260 switch(dwStyle & 0x0f)
261 {
262 case BS_AUTOCHECKBOX:
263 SendMessageA(hwnd,BM_SETCHECK,!(infoPtr->state & BUTTON_CHECKED),0);
264 break;
265 case BS_AUTORADIOBUTTON:
266 SendMessageA(hwnd,BM_SETCHECK,TRUE,0);
267 break;
268 case BS_AUTO3STATE:
269 SendMessageA(hwnd,BM_SETCHECK,
270 (infoPtr->state & BUTTON_3STATE) ? 0 :
271 ((infoPtr->state & 3)+1),0);
272 break;
273 }
274 BUTTON_SendNotify(hwnd,BN_CLICKED);
275 }
276
277 if (dwStyle & BS_NOTIFY) BUTTON_SendNotify(hwnd,BN_UNHILITE);
278
279 return 0;
280}
281
282static LRESULT BUTTON_CaptureChanged(HWND hwnd,WPARAM wParam,LPARAM lParam)
283{
284 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
285 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
286
287 if (infoPtr->state & BUTTON_BTNPRESSED)
288 {
289 infoPtr->state &= BUTTON_NSTATES;
290 if (infoPtr->state & BUTTON_HIGHLIGHTED)
291 SendMessageA( hwnd, BM_SETSTATE, FALSE, 0 );
292 }
293
294 if (dwStyle & BS_NOTIFY) BUTTON_SendNotify(hwnd,BN_UNHILITE);
295
296 return 0;
297}
298
299static LRESULT BUTTON_MouseMove(HWND hwnd,WPARAM wParam,LPARAM lParam)
300{
301 if (GetCapture() == hwnd)
302 {
303 RECT rect;
304 POINT pt;
305
306 pt.x = LOWORD(lParam);
307 pt.y = HIWORD(lParam);
308
309 GetClientRect(hwnd,&rect);
310 SendMessageA(hwnd,BM_SETSTATE,PtInRect(&rect,pt),0);
311 }
312
313 return 0;
314}
315
316static LRESULT BUTTON_NCHitTest(HWND hwnd,WPARAM wParam,LPARAM lParam)
317{
318 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & 0x0f;
319
320 if (style == BS_GROUPBOX) return HTTRANSPARENT;
321
322 return DefWindowProcA(hwnd,WM_NCHITTEST,wParam,lParam);
323}
324
325static LRESULT BUTTON_SetText(HWND hwnd,WPARAM wParam,LPARAM lParam)
326{
327 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
328
329 DefWindowProcA(hwnd,WM_SETTEXT,wParam,lParam);
330 if (dwStyle & WS_VISIBLE) PAINT_BUTTON(hwnd,dwStyle & 0x0f,ODA_DRAWENTIRE);
331
332 return 0;
333}
334
335static LRESULT BUTTON_SetFont(HWND hwnd,WPARAM wParam,LPARAM lParam)
336{
337 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
338 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
339
340#ifdef __WIN32OS2__
341 if ((dwStyle & 0x0f) == BS_GROUPBOX) {
342 RECT rc;
343 TEXTMETRICA tm;
344 HDC hdc = GetDC(hwnd);
345 int fh1 = 0, fh2 = 0;
346
347 // select old font (if exists)
348 if (infoPtr->hFont) {
349 SelectObject (hdc, infoPtr->hFont);
350 GetTextMetricsA (hdc, &tm);
351 fh1 = tm.tmHeight;
352 }
353 // select new font (if exists)
354 if (wParam) {
355 SelectObject (hdc, wParam);
356 GetTextMetricsA (hdc, &tm);
357 fh2 = tm.tmHeight;
358 }
359 // Erases top border line and (old) text background
360 GetClientRect(hwnd, &rc);
361 rc.bottom = rc.top + max( fh1, fh2) + 1;
362 HBRUSH hbr = GetControlBrush( hwnd, hdc, CTLCOLOR_STATIC );
363 FillRect(hdc, &rc, hbr);
364 ReleaseDC(hwnd,hdc);
365 }
366#endif
367
368 infoPtr->hFont = (HFONT)wParam;
369 if (lParam && (dwStyle & WS_VISIBLE)) PAINT_BUTTON(hwnd,dwStyle & 0x0f,ODA_DRAWENTIRE);
370
371 return 0;
372}
373
374static LRESULT BUTTON_GetFont(HWND hwnd,WPARAM wParam,LPARAM lParam)
375{
376 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
377
378 return infoPtr->hFont;
379}
380
381static LRESULT BUTTON_KeyDown(HWND hwnd,WPARAM wParam,LPARAM lParam)
382{
383 if (wParam == VK_SPACE)
384 {
385 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
386
387 SendMessageA(hwnd,BM_SETSTATE,TRUE,0);
388 infoPtr->state |= BUTTON_BTNPRESSED;
389 }
390
391 return 0;
392}
393
394static LRESULT BUTTON_KeyUp(HWND hwnd,WPARAM wParam,LPARAM lParam)
395{
396 if (wParam == VK_SPACE)
397 {
398 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
399 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
400
401 if (!(infoPtr->state & BUTTON_BTNPRESSED)) return 0;
402 infoPtr->state &= BUTTON_NSTATES;
403 if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) return 0;
404 SendMessageA(hwnd,BM_SETSTATE,FALSE,0);
405
406 switch(dwStyle & 0x0f)
407 {
408 case BS_AUTOCHECKBOX:
409 SendMessageA(hwnd,BM_SETCHECK,!(infoPtr->state & BUTTON_CHECKED),0);
410 break;
411 case BS_AUTORADIOBUTTON:
412 SendMessageA(hwnd,BM_SETCHECK,TRUE,0);
413 break;
414 case BS_AUTO3STATE:
415 SendMessageA(hwnd,BM_SETCHECK,
416 (infoPtr->state & BUTTON_3STATE) ? 0 :
417 ((infoPtr->state & 3)+1),0);
418 break;
419 }
420 BUTTON_SendNotify(hwnd,BN_CLICKED);
421 }
422
423 return 0;
424}
425
426static LRESULT BUTTON_SysKeyUp(HWND hwnd,WPARAM wParam,LPARAM lParam)
427{
428 if (wParam != VK_TAB) ReleaseCapture();
429
430 return 0;
431}
432
433static LRESULT BUTTON_SetFocus(HWND hwnd,WPARAM wParam,LPARAM lParam)
434{
435 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
436 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
437 DWORD style = dwStyle & 0x0f;
438
439 if (dwStyle & BS_NOTIFY) BUTTON_SendNotify(hwnd,BN_SETFOCUS);
440
441 if (((style == BS_AUTORADIOBUTTON) || (style == BS_RADIOBUTTON)) &&
442 (GetCapture() != hwnd) && !(SendMessageA(hwnd,BM_GETCHECK,0,0) & BST_CHECKED))
443 {
444 /* The notification is sent when the button (BS_AUTORADIOBUTTON)
445 is unckecked and the focus was not given by a mouse click. */
446 if (style == BS_AUTORADIOBUTTON) SendMessageA(hwnd,BM_SETCHECK,TRUE,0);
447 BUTTON_SendNotify(hwnd,BN_CLICKED);
448 }
449
450 infoPtr->state |= BUTTON_HASFOCUS;
451 PAINT_BUTTON(hwnd,style,ODA_FOCUS);
452
453 return 0;
454}
455
456static LRESULT BUTTON_KillFocus(HWND hwnd,WPARAM wParam,LPARAM lParam)
457{
458 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
459 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
460 DWORD style = dwStyle & 0x0f;
461
462 if (dwStyle & BS_NOTIFY) BUTTON_SendNotify(hwnd,BN_KILLFOCUS);
463
464 if (infoPtr->state & BUTTON_HASFOCUS)
465 {
466 infoPtr->state &= ~BUTTON_HASFOCUS;
467 PAINT_BUTTON(hwnd,style,ODA_FOCUS);
468 }
469
470 return 0;
471}
472
473static LRESULT BUTTON_SysColorChange(HWND hwnd,WPARAM wParam,LPARAM lParam)
474{
475 InvalidateRect(hwnd,NULL,FALSE);
476
477 return 0;
478}
479
480static LRESULT BUTTON_Click(HWND hwnd,WPARAM wParam,LPARAM lParam)
481{
482 RECT rect;
483 LPARAM point;
484
485 GetClientRect(hwnd,&rect);
486 point = MAKELPARAM(rect.right/2,rect.bottom/2);
487 SendMessageA(hwnd,WM_LBUTTONDOWN,MK_LBUTTON,point);
488 Sleep(100);
489 SendMessageA(hwnd,WM_LBUTTONUP,0,point);
490
491 return 0;
492}
493
494static LRESULT BUTTON_SetStyle(HWND hwnd,WPARAM wParam,LPARAM lParam)
495{
496 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE),newStyle;
497
498 if ((wParam & 0x0F) >= MAX_BTN_TYPE) return 0;
499 newStyle = (dwStyle & 0xFFFFFFF0) | (wParam & 0x0000000F);
500
501 if (newStyle != dwStyle)
502 {
503 SetWindowLongA(hwnd,GWL_STYLE,newStyle);
504 PAINT_BUTTON(hwnd,newStyle & 0x0F,ODA_DRAWENTIRE);
505 }
506
507 return 0;
508}
509
510static LRESULT BUTTON_SetImage(HWND hwnd,WPARAM wParam,LPARAM lParam)
511{
512 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
513 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
514 HANDLE oldHbitmap = infoPtr->hImage;
515
516 if ((dwStyle & BS_BITMAP) || (dwStyle & BS_ICON))
517 {
518 infoPtr->hImage = (HANDLE)lParam;
519 InvalidateRect(hwnd,NULL,FALSE);
520 }
521
522 return oldHbitmap;
523}
524
525static LRESULT BUTTON_GetImage(HWND hwnd,WPARAM wParam,LPARAM lParam)
526{
527 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
528
529 switch(wParam)
530 {
531 case IMAGE_BITMAP:
532 return (HBITMAP)infoPtr->hImage;
533 case IMAGE_ICON:
534 return (HICON)infoPtr->hImage;
535 default:
536 return (HICON)0;
537 }
538}
539
540static LRESULT BUTTON_GetCheck(HWND hwnd,WPARAM wParam,LPARAM lParam)
541{
542 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
543
544 return infoPtr->state & 3;
545}
546
547static LRESULT BUTTON_SetCheck(HWND hwnd,WPARAM wParam,LPARAM lParam)
548{
549 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
550 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
551 DWORD style = dwStyle & 0x0f;
552
553 if (wParam > maxCheckState[style]) wParam = maxCheckState[style];
554 if ((infoPtr->state & 3) != wParam)
555 {
556 if ((style == BS_RADIOBUTTON) || (style == BS_AUTORADIOBUTTON))
557 {
558 DWORD oldStyle = dwStyle;
559
560 if (wParam)
561 dwStyle |= WS_TABSTOP;
562 else
563 dwStyle &= ~WS_TABSTOP;
564
565 if (oldStyle != dwStyle) SetWindowLongA(hwnd,GWL_STYLE,dwStyle);
566 }
567 infoPtr->state = (infoPtr->state & ~3) | wParam;
568 PAINT_BUTTON(hwnd,style,ODA_SELECT);
569 }
570 if ((style == BS_AUTORADIOBUTTON) && (wParam == BUTTON_CHECKED))
571 BUTTON_CheckAutoRadioButton(hwnd);
572
573 return 0;
574}
575
576static LRESULT BUTTON_GetState(HWND hwnd,WPARAM wParam,LPARAM lParam)
577{
578 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
579
580 return infoPtr->state;
581}
582
583static LRESULT BUTTON_SetState(HWND hwnd,WPARAM wParam,LPARAM lParam)
584{
585 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
586 DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & 0x0F;
587
588 if (wParam)
589 {
590 if (infoPtr->state & BUTTON_HIGHLIGHTED) return 0;
591 infoPtr->state |= BUTTON_HIGHLIGHTED;
592 } else
593 {
594 if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) return 0;
595 infoPtr->state &= ~BUTTON_HIGHLIGHTED;
596 }
597 PAINT_BUTTON(hwnd,style,ODA_SELECT);
598
599 return 0;
600}
601
602/***********************************************************************
603 * ButtonWndProc
604 */
605static
606LRESULT WINAPI ButtonWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
607{
608// dprintf(("ButtonWndProc hwnd: %04x, msg %s, wp %08x lp %08lx\n",
609// hwnd, GetMsgText(uMsg), wParam, lParam));
610
611 switch (uMsg)
612 {
613 case WM_GETDLGCODE:
614 return BUTTON_GetDlgCode(hwnd,wParam,lParam);
615
616 case WM_ENABLE:
617 return BUTTON_Enable(hwnd,wParam,lParam);
618
619 case WM_CREATE:
620 return BUTTON_Create(hwnd,wParam,lParam);
621
622 case WM_DESTROY:
623 return BUTTON_Destroy(hwnd,wParam,lParam);
624
625 case WM_ERASEBKGND:
626 return BUTTON_EraseBkgnd(hwnd,wParam,lParam);
627
628 case WM_PAINT:
629 return BUTTON_Paint(hwnd,wParam,lParam);
630
631 case WM_LBUTTONDBLCLK:
632 return BUTTON_LButtonDblClk(hwnd,wParam,lParam);
633
634 case WM_LBUTTONDOWN:
635 return BUTTON_LButtonDown(hwnd,wParam,lParam);
636
637 case WM_LBUTTONUP:
638 return BUTTON_LButtonUp(hwnd,wParam,lParam);
639
640 case WM_CAPTURECHANGED:
641 return BUTTON_CaptureChanged(hwnd,wParam,lParam);
642
643 case WM_MOUSEMOVE:
644 return BUTTON_MouseMove(hwnd,wParam,lParam);
645
646 case WM_NCHITTEST:
647 return BUTTON_NCHitTest(hwnd,wParam,lParam);
648
649 case WM_SETTEXT:
650 return BUTTON_SetText(hwnd,wParam,lParam);
651
652 case WM_SETFONT:
653 return BUTTON_SetFont(hwnd,wParam,lParam);
654
655 case WM_GETFONT:
656 return BUTTON_GetFont(hwnd,wParam,lParam);
657
658 case WM_KEYDOWN:
659 return BUTTON_KeyDown(hwnd,wParam,lParam);
660
661 case WM_KEYUP:
662 return BUTTON_KeyUp(hwnd,wParam,lParam);
663
664 case WM_SYSKEYUP:
665 return BUTTON_SysKeyUp(hwnd,wParam,lParam);
666
667 case WM_SETFOCUS:
668 return BUTTON_SetFocus(hwnd,wParam,lParam);
669
670 case WM_KILLFOCUS:
671 return BUTTON_KillFocus(hwnd,wParam,lParam);
672
673 case WM_SYSCOLORCHANGE:
674 return BUTTON_SysColorChange(hwnd,wParam,lParam);
675
676 case BM_CLICK:
677 return BUTTON_Click(hwnd,wParam,lParam);
678
679 case BM_SETSTYLE:
680 return BUTTON_SetStyle(hwnd,wParam,lParam);
681
682 case BM_SETIMAGE:
683 return BUTTON_SetImage(hwnd,wParam,lParam);
684
685 case BM_GETIMAGE:
686 return BUTTON_GetImage(hwnd,wParam,lParam);
687
688 case BM_GETCHECK:
689 return BUTTON_GetCheck(hwnd,wParam,lParam);
690
691 case BM_SETCHECK:
692 return BUTTON_SetCheck(hwnd,wParam,lParam);
693
694 case BM_GETSTATE:
695 return BUTTON_GetState(hwnd,wParam,lParam);
696
697 case BM_SETSTATE:
698 return BUTTON_SetState(hwnd,wParam,lParam);
699
700 default:
701 return DefWindowProcA(hwnd,uMsg,wParam,lParam);
702 }
703
704 return 0;
705}
706
707
708/**********************************************************************
709 * Push Button Functions
710 */
711static void PB_Paint( HWND hwnd, HDC hDC, WORD action )
712{
713 BUTTONINFO *infoPtr = (BUTTONINFO *)GetInfoPtr(hwnd);
714 BOOL bHighLighted = (infoPtr->state & BUTTON_HIGHLIGHTED);
715
716 /*
717 * Delegate this to the more generic pushbutton painting
718 * method.
719 */
720 BUTTON_DrawPushButton(hwnd,
721 hDC,
722 action,
723 bHighLighted);
724}
725
726static INT BUTTON_GetTextFormat(DWORD dwStyle,DWORD dwExStyle,INT defHorz,INT defVert)
727{
728 INT format = 0;
729
730 if (dwStyle & BS_LEFT) format = DT_LEFT;
731 else if (dwStyle & BS_CENTER) format = DT_CENTER;
732 else if ((dwStyle & BS_RIGHT) || (dwExStyle & WS_EX_RIGHT)) format = DT_RIGHT;
733 else format = defHorz;
734
735 if (dwStyle & BS_TOP) format |= DT_TOP;
736 else if (dwStyle & BS_VCENTER) format |= DT_VCENTER;
737 else if (dwStyle & BS_BOTTOM) format |= DT_BOTTOM;
738 else format |= defVert;
739
740 if (!(dwStyle & BS_MULTILINE)) format |= DT_SINGLELINE;
741
742 return format;
743}
744
745/**********************************************************************
746 * This method will actually do the drawing of the pushbutton
747 * depending on it's state and the pushedState parameter.
748 */
749static void BUTTON_DrawPushButton(
750 HWND hwnd,
751 HDC hDC,
752 WORD action,
753 BOOL pushedState )
754{
755 RECT rc, focus_rect;
756 HPEN hOldPen;
757 HBRUSH hOldBrush;
758 BUTTONINFO *infoPtr = (BUTTONINFO *)GetInfoPtr(hwnd);
759 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
760 int xBorderOffset, yBorderOffset;
761 xBorderOffset = yBorderOffset = 0;
762 INT textLen;
763 char* text;
764
765 GetClientRect( hwnd, &rc );
766
767 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
768 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
769 BUTTON_SEND_CTLCOLOR( hwnd, hDC );
770 hOldPen = (HPEN)SelectObject(hDC, GetSysColorPen(COLOR_WINDOWFRAME));
771 hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
772 SetBkMode(hDC, TRANSPARENT);
773
774 if ((dwStyle & 0x000f) == BS_DEFPUSHBUTTON)
775 {
776 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
777 InflateRect( &rc, -1, -1 );
778 }
779
780 UINT uState = DFCS_BUTTONPUSH;
781
782 if (pushedState)
783 {
784 if ( (dwStyle & 0x000f) == BS_DEFPUSHBUTTON )
785 uState |= DFCS_FLAT;
786 else
787 uState |= DFCS_PUSHED;
788 }
789
790 if (dwStyle & BS_FLAT) uState |= DFCS_FLAT;
791
792 DrawFrameControl( hDC, &rc, DFC_BUTTON, uState );
793 InflateRect( &rc, -2, -2 );
794
795 focus_rect = rc;
796
797 if (pushedState)
798 {
799 rc.left += 2; /* To position the text down and right */
800 rc.top += 2;
801 }
802
803
804 /* draw button label, if any:
805 *
806 * In win9x we don't show text if there is a bitmap or icon.
807 * I don't know about win31 so I leave it as it was for win31.
808 * Dennis Björklund 12 Jul, 99
809 */
810 textLen = GetWindowTextLengthA(hwnd);
811 if ((textLen > 0) && (!(dwStyle & (BS_ICON|BS_BITMAP))))
812 {
813 INT format = BUTTON_GetTextFormat(dwStyle,GetWindowLongA(hwnd,GWL_EXSTYLE),DT_CENTER,DT_VCENTER);
814
815 textLen++;
816 text = (char*)malloc(textLen);
817 GetWindowTextA(hwnd,text,textLen);
818
819 if (dwStyle & WS_DISABLED) DrawDisabledText(hDC,text,&rc,format); else
820 {
821 SetTextColor(hDC,GetSysColor(COLOR_BTNTEXT));
822 DrawTextA(hDC,text,-1,&rc,format);
823 /* do we have the focus?
824 * Win9x draws focus last with a size prop. to the button
825 */
826 }
827 free(text);
828 }
829 if ( ((dwStyle & BS_ICON) || (dwStyle & BS_BITMAP) ) &&
830 (infoPtr->hImage != 0) )
831 {
832 int yOffset, xOffset;
833 int imageWidth, imageHeight;
834
835 /*
836 * We extract the size of the image from the handle.
837 */
838 if (dwStyle & BS_ICON)
839 {
840 ICONINFO iconInfo;
841 BITMAP bm;
842
843 GetIconInfo((HICON)infoPtr->hImage,&iconInfo);
844 if (iconInfo.hbmColor)
845 {
846 GetObjectA(iconInfo.hbmColor,sizeof(BITMAP),&bm);
847 imageWidth = bm.bmWidth;
848 imageHeight = bm.bmHeight;
849 } else
850 {
851 GetObjectA(iconInfo.hbmMask,sizeof(BITMAP),&bm);
852 imageWidth = bm.bmWidth;
853 imageHeight = bm.bmHeight/2;
854 }
855
856 if (iconInfo.hbmColor) DeleteObject(iconInfo.hbmColor);
857 if (iconInfo.hbmMask) DeleteObject(iconInfo.hbmMask);
858
859 }
860 else
861 {
862 BITMAP bm;
863
864 GetObjectA (infoPtr->hImage, sizeof(BITMAP), &bm);
865
866 imageWidth = bm.bmWidth;
867 imageHeight = bm.bmHeight;
868 }
869
870 /* Center the bitmap */
871 xOffset = (((rc.right - rc.left) - 2*xBorderOffset) - imageWidth ) / 2;
872 yOffset = (((rc.bottom - rc.top) - 2*yBorderOffset) - imageHeight) / 2;
873
874 /* If the image is too big for the button then create a region*/
875 if(xOffset < 0 || yOffset < 0)
876 {
877 HRGN hBitmapRgn = 0;
878 hBitmapRgn = CreateRectRgn(
879 rc.left + xBorderOffset, rc.top +yBorderOffset,
880 rc.right - xBorderOffset, rc.bottom - yBorderOffset);
881 SelectClipRgn(hDC, hBitmapRgn);
882 DeleteObject(hBitmapRgn);
883 }
884
885 /* Let minimum 1 space from border */
886 xOffset++, yOffset++;
887
888 /*
889 * Draw the image now.
890 */
891 if (dwStyle & BS_ICON)
892 {
893 DrawIcon(hDC,
894 rc.left + xOffset, rc.top + yOffset,
895 (HICON)infoPtr->hImage);
896 }
897 else
898 {
899 HDC hdcMem;
900
901 hdcMem = CreateCompatibleDC (hDC);
902 SelectObject (hdcMem, (HBITMAP)infoPtr->hImage);
903 BitBlt(hDC,
904 rc.left + xOffset,
905 rc.top + yOffset,
906 imageWidth, imageHeight,
907 hdcMem, 0, 0, SRCCOPY);
908
909 DeleteDC (hdcMem);
910 }
911
912 if(xOffset < 0 || yOffset < 0)
913 {
914 SelectClipRgn(hDC, 0);
915 }
916 }
917
918 SelectObject( hDC, hOldPen );
919 SelectObject( hDC, hOldBrush );
920
921 if ((infoPtr->state & BUTTON_HASFOCUS) && IsWindowEnabled(hwnd))
922 {
923 InflateRect( &focus_rect, -1, -1 );
924 DrawFocusRect( hDC, &focus_rect );
925 }
926}
927
928
929static void DrawDisabledText(HDC hdc,char* text,RECT* rtext,UINT format)
930{
931 COLORREF textColor = (GetSysColor(COLOR_GRAYTEXT) == GetBkColor(hdc)) ? COLOR_BTNTEXT:COLOR_GRAYTEXT;
932 RECT rect = *rtext;
933 COLORREF oldMode;
934
935 //CB: bug in Open32 DrawText: underscore is always black! -> two black lines!
936 SetTextColor(hdc,GetSysColor(COLOR_3DHILIGHT));
937 DrawTextA(hdc,text,-1,&rect,format);
938 SetTextColor(hdc,GetSysColor(COLOR_GRAYTEXT));
939 oldMode = SetBkMode(hdc,TRANSPARENT);
940 OffsetRect(&rect,-1,-1);
941 DrawTextA(hdc,text,-1,&rect,format);
942 SetBkMode(hdc,oldMode);
943}
944
945/**********************************************************************
946 * Check Box & Radio Button Functions
947 */
948
949static void CB_Paint(HWND hwnd,HDC hDC,WORD action)
950{
951 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
952 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
953 RECT rbox, rtext, client;
954 HBRUSH hBrush, hOldBrush;
955 HPEN hPen, hOldPen;
956 COLORREF colour;
957 int textLen, delta;
958 char* text = NULL;
959
960 /*
961 * if the button has a bitmap/icon, draw a normal pushbutton
962 * instead of a radion button.
963 */
964 if (infoPtr->hImage != 0)
965 {
966 BOOL bHighLighted = ((infoPtr->state & BUTTON_HIGHLIGHTED) ||
967 (infoPtr->state & BUTTON_CHECKED));
968
969 BUTTON_DrawPushButton(hwnd,
970 hDC,
971 action,
972 bHighLighted);
973 return;
974 }
975
976 textLen = 0;
977 GetClientRect(hwnd, &client);
978 rbox = rtext = client;
979
980 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
981
982 /* GetControlBrush16 sends WM_CTLCOLORBTN, plus it returns default brush
983 * if parent didn't return valid one. So we kill two hares at once
984 */
985 hBrush = GetControlBrush( hwnd, hDC, CTLCOLOR_BTN );
986
987 /* In order to make things right, draw the rectangle background! */
988 if ( !(infoPtr->state & BUTTON_HASFOCUS) && (action == ODA_DRAWENTIRE) )
989 {
990 colour = GetBkColor(hDC);
991 hPen = CreatePen( PS_SOLID, 1, colour );
992 if ( hPen )
993 {
994 hOldBrush = SelectObject( hDC, hBrush );
995 hOldPen = SelectObject( hDC, hPen );
996 Rectangle( hDC, client.left, client.top, client.right, client.bottom );
997 SelectObject( hDC, hOldPen );
998 SelectObject( hDC, hOldBrush );
999 DeleteObject( hPen );
1000 }
1001 }
1002
1003 if (dwStyle & BS_LEFTTEXT)
1004 {
1005 /* magic +4 is what CTL3D expects */
1006
1007 rtext.right -= checkBoxWidth + 4;
1008 //CB: space for focus rect
1009 rtext.left++;
1010 rtext.right++;
1011 rbox.left = rbox.right - checkBoxWidth;
1012 }
1013 else
1014 {
1015 rtext.left += checkBoxWidth + 4;
1016 rbox.right = checkBoxWidth;
1017 }
1018
1019 /* Draw the check-box bitmap */
1020
1021 textLen = GetWindowTextLengthA(hwnd);
1022 if (textLen > 0)
1023 {
1024 textLen++;
1025 text = (char*)malloc(textLen);
1026 GetWindowTextA(hwnd,text,textLen);
1027 }
1028 if ((action == ODA_DRAWENTIRE) || (action == ODA_SELECT))
1029 {
1030 UINT state;
1031
1032 if (((dwStyle & 0x0f) == BS_RADIOBUTTON) ||
1033 ((dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) state = DFCS_BUTTONRADIO;
1034 else if (infoPtr->state & BUTTON_3STATE) state = DFCS_BUTTON3STATE;
1035 else state = DFCS_BUTTONCHECK;
1036
1037 if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) state |= DFCS_CHECKED;
1038
1039 if (infoPtr->state & BUTTON_HIGHLIGHTED) state |= DFCS_PUSHED;
1040
1041 if (dwStyle & WS_DISABLED) state |= DFCS_INACTIVE;
1042
1043 if (dwStyle & BS_FLAT) state |= DFCS_FLAT;
1044
1045 DrawFrameControl( hDC, &rbox, DFC_BUTTON, state );
1046
1047 if( text && action != ODA_SELECT )
1048 {
1049 INT format = BUTTON_GetTextFormat(dwStyle,GetWindowLongA(hwnd,GWL_EXSTYLE),DT_TOP,DT_VCENTER);
1050
1051 if (dwStyle & WS_DISABLED) DrawDisabledText(hDC,text,&rtext,format);
1052 else DrawTextA(hDC,text,-1,&rtext,format);
1053 }
1054 }
1055
1056 if ((action == ODA_FOCUS) ||
1057 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS) && IsWindowEnabled(hwnd)))
1058 {
1059 /* again, this is what CTL3D expects */
1060
1061 SetRectEmpty(&rbox);
1062 if(textLen > 0)
1063 DrawTextA(hDC,text,-1,&rbox,DT_SINGLELINE | DT_CALCRECT);
1064 textLen = rbox.bottom - rbox.top;
1065 delta = ((rtext.bottom - rtext.top) - textLen)/2;
1066 rbox.bottom = (rbox.top = rtext.top + delta - 1) + textLen + 2;
1067 textLen = rbox.right - rbox.left;
1068 rbox.right = (rbox.left += --rtext.left) + textLen + 2;
1069 IntersectRect(&rbox, &rbox, &rtext);
1070 DrawFocusRect( hDC, &rbox );
1071 }
1072 if (text) free(text);
1073}
1074
1075
1076/**********************************************************************
1077 * BUTTON_CheckAutoRadioButton
1078 *
1079 * wndPtr is checked, uncheck every other auto radio button in group
1080 */
1081static void BUTTON_CheckAutoRadioButton(HWND hwnd)
1082{
1083 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
1084 HWND parent, sibling, start;
1085
1086 if (!(dwStyle & WS_CHILD)) return;
1087 parent = GetParent(hwnd);
1088 /* assure that starting control is not disabled or invisible */
1089 //start = sibling = GetNextDlgGroupItem( parent, hwnd, TRUE );
1090 //@YD: bugfix
1091 //CB: doesn't work!
1092 start = sibling = GetNextDlgGroupItem( parent, hwnd, FALSE );
1093 do
1094 {
1095 if (!sibling) break;
1096 if ((hwnd != sibling) &&
1097 ((GetWindowLongA(sibling,GWL_STYLE) & 0x0f) == BS_AUTORADIOBUTTON))
1098 SendMessageA( sibling, BM_SETCHECK, BUTTON_UNCHECKED, 0 );
1099 sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
1100 } while (sibling != start);
1101}
1102
1103
1104/**********************************************************************
1105 * Group Box Functions
1106 */
1107
1108static void GB_Paint(HWND hwnd,HDC hDC,WORD action)
1109{
1110 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
1111 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
1112 RECT rc, rcFrame;
1113 TEXTMETRICA tm;
1114 INT textLen;
1115 char* text;
1116 HBRUSH hbr;
1117
1118 if (action != ODA_DRAWENTIRE) return;
1119
1120 /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */
1121 hbr = GetControlBrush( hwnd, hDC, CTLCOLOR_STATIC );
1122
1123 GetClientRect(hwnd,&rc);
1124
1125 rcFrame = rc;
1126
1127 if (infoPtr->hFont)
1128 SelectObject (hDC, infoPtr->hFont);
1129 GetTextMetricsA (hDC, &tm);
1130 rcFrame.top += (tm.tmHeight / 2) - 1;
1131 DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT);
1132
1133 textLen = GetWindowTextLengthA(hwnd);
1134 if (textLen > 0)
1135 {
1136 INT format = BUTTON_GetTextFormat(dwStyle,GetWindowLongA(hwnd,GWL_EXSTYLE),DT_LEFT,DT_TOP) | DT_NOCLIP | DT_SINGLELINE;
1137
1138 textLen++;
1139 text = (char*)malloc(textLen);
1140 GetWindowTextA(hwnd,text,textLen);
1141 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
1142 rc.left += 10;
1143
1144 if (dwStyle & WS_DISABLED) {
1145 DrawDisabledText(hDC,text,&rc,format);
1146 }
1147 else
1148 {
1149 SetTextColor(hDC,GetSysColor(COLOR_BTNTEXT));
1150 DrawTextA(hDC,text,-1,&rc,format);
1151 }
1152
1153 free(text);
1154 }
1155}
1156
1157
1158/**********************************************************************
1159 * User Button Functions
1160 */
1161
1162static void UB_Paint(HWND hwnd,HDC hDC,WORD action)
1163{
1164 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
1165 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
1166 RECT rc;
1167 HBRUSH hBrush;
1168 if (action == ODA_SELECT) return;
1169
1170 GetClientRect(hwnd,&rc);
1171
1172 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
1173 hBrush = GetControlBrush( hwnd, hDC, CTLCOLOR_BTN );
1174
1175 FillRect( hDC, &rc, hBrush );
1176 if ((action == ODA_FOCUS) ||
1177 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS) && IsWindowEnabled(hwnd)))
1178 {
1179 DrawFocusRect( hDC, &rc );
1180 InflateRect(&rc,-1,-1);
1181 }
1182}
1183
1184
1185/**********************************************************************
1186 * Ownerdrawn Button Functions
1187 */
1188
1189static void OB_Paint(HWND hwnd,HDC hDC,WORD action)
1190{
1191 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
1192 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
1193 DRAWITEMSTRUCT dis;
1194
1195 dis.CtlType = ODT_BUTTON;
1196 dis.CtlID = GetWindowLongA(hwnd,GWL_ID);
1197 dis.itemID = 0;
1198 dis.itemAction = action;
1199 dis.itemState = ((infoPtr->state & BUTTON_HASFOCUS) ? ODS_FOCUS : 0) |
1200 ((infoPtr->state & BUTTON_HIGHLIGHTED) ? ODS_SELECTED : 0) |
1201 ((dwStyle & WS_DISABLED) ? ODS_DISABLED : 0);
1202 dis.hwndItem = hwnd;
1203 dis.hDC = hDC;
1204 dis.itemData = 0;
1205 GetClientRect( hwnd, &dis.rcItem );
1206
1207 SetBkColor( hDC, GetSysColor( COLOR_BTNFACE ) );
1208
1209 dprintf(("OWNERDRAW button %x, enabled %d", hwnd, !(dwStyle & WS_DISABLED)));
1210 SendMessageA( GetParent(hwnd), WM_DRAWITEM,
1211 GetWindowLongA(hwnd,GWL_ID), (LPARAM)&dis );
1212}
1213
1214BOOL BUTTON_Register()
1215{
1216 WNDCLASSA wndClass;
1217
1218//SvL: Don't check this now
1219// if (GlobalFindAtomA(BUTTONCLASSNAME)) return FALSE;
1220
1221 ZeroMemory(&wndClass,sizeof(WNDCLASSA));
1222 wndClass.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW | CS_PARENTDC | CS_DBLCLKS;
1223 wndClass.lpfnWndProc = (WNDPROC)ButtonWndProc;
1224 wndClass.cbClsExtra = 0;
1225 wndClass.cbWndExtra = sizeof(BUTTONINFO);
1226 wndClass.hCursor = LoadCursorA(0,IDC_ARROWA);
1227 wndClass.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
1228 wndClass.lpszClassName = BUTTONCLASSNAME;
1229
1230 return RegisterClassA(&wndClass);
1231}
1232
1233BOOL BUTTON_Unregister()
1234{
1235 if (GlobalFindAtomA(BUTTONCLASSNAME))
1236 return UnregisterClassA(BUTTONCLASSNAME,(HINSTANCE)NULL);
1237 else return FALSE;
1238}
Note: See TracBrowser for help on using the repository browser.