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

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

menu + groupbox fixes

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