source: branches/swt/src/user32/button.cpp@ 22096

Last change on this file since 22096 was 22096, checked in by rousseau, 11 years ago

Cleanup button text alignment fix

File size: 35.0 KB
Line 
1/* $Id: button.cpp,v 1.47 2003-04-02 12:58:01 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 LRESULT result = 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 result;
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 && IsWindowVisible(hwnd)) {
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 /*
779 * BS_CENTER is not a single bit-flag, but is actually BS_LEFT | BS_RIGHT.
780 * So we need an extra compare to distinguish it.
781 * TODO: Scan for more occurences like this and other multi-bit flags
782 */
783 if ((dwStyle & BS_CENTER) == BS_LEFT) format = DT_LEFT;
784 else if ((dwStyle & BS_CENTER) == BS_CENTER) format = DT_CENTER;
785 else if (((dwStyle & BS_RIGHT) == BS_RIGHT) || ((dwExStyle & WS_EX_RIGHT) == BS_RIGHT)) format = DT_RIGHT;
786 else format = defHorz;
787
788 if (dwStyle & BS_TOP) format |= DT_TOP;
789 else if (dwStyle & BS_VCENTER) format |= DT_VCENTER;
790 else if (dwStyle & BS_BOTTOM) format |= DT_BOTTOM;
791 else format |= defVert;
792
793 if (!(dwStyle & BS_MULTILINE)) format |= DT_SINGLELINE;
794
795 return format;
796}
797
798/**********************************************************************
799 * This method will actually do the drawing of the pushbutton
800 * depending on it's state and the pushedState parameter.
801 */
802static void BUTTON_DrawPushButton(
803 HWND hwnd,
804 HDC hDC,
805 WORD action,
806 BOOL pushedState )
807{
808 RECT rc, focus_rect;
809 HPEN hOldPen;
810 HBRUSH hOldBrush;
811 BUTTONINFO *infoPtr = (BUTTONINFO *)GetInfoPtr(hwnd);
812 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
813 int xBorderOffset, yBorderOffset;
814 xBorderOffset = yBorderOffset = 0;
815 INT textLen;
816 char* text;
817
818 GetClientRect( hwnd, &rc );
819
820 /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
821 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
822 BUTTON_SEND_CTLCOLOR( hwnd, hDC );
823 hOldPen = (HPEN)SelectObject(hDC, GetSysColorPen(COLOR_WINDOWFRAME));
824 hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
825 SetBkMode(hDC, TRANSPARENT);
826
827 if ((dwStyle & 0x000f) == BS_DEFPUSHBUTTON)
828 {
829 Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
830 InflateRect( &rc, -1, -1 );
831 }
832
833 UINT uState = DFCS_BUTTONPUSH;
834
835 if (pushedState)
836 {
837 if ( (dwStyle & 0x000f) == BS_DEFPUSHBUTTON )
838 uState |= DFCS_FLAT;
839 else
840 uState |= DFCS_PUSHED;
841 }
842
843 if (dwStyle & BS_FLAT) uState |= DFCS_FLAT;
844
845 DrawFrameControl( hDC, &rc, DFC_BUTTON, uState );
846 InflateRect( &rc, -2, -2 );
847
848 focus_rect = rc;
849
850 if (pushedState)
851 {
852 rc.left += 2; /* To position the text down and right */
853 rc.top += 2;
854 }
855
856
857 /* draw button label, if any:
858 *
859 * In win9x we don't show text if there is a bitmap or icon.
860 * I don't know about win31 so I leave it as it was for win31.
861 * Dennis Björklund 12 Jul, 99
862 */
863 textLen = GetWindowTextLengthA(hwnd);
864 if ((textLen > 0) && (!(dwStyle & (BS_ICON|BS_BITMAP))))
865 {
866 INT format = BUTTON_GetTextFormat(dwStyle,GetWindowLongA(hwnd,GWL_EXSTYLE),DT_CENTER,DT_VCENTER);
867
868 textLen++;
869 text = (char*)malloc(textLen);
870 GetWindowTextA(hwnd,text,textLen);
871
872 if (dwStyle & WS_DISABLED) DrawDisabledText(hDC,text,&rc,format); else
873 {
874 SetTextColor(hDC,GetSysColor(COLOR_BTNTEXT));
875 DrawTextA(hDC,text,-1,&rc,format);
876 /* do we have the focus?
877 * Win9x draws focus last with a size prop. to the button
878 */
879 }
880 free(text);
881 }
882 if ( ((dwStyle & BS_ICON) || (dwStyle & BS_BITMAP) ) &&
883 (infoPtr->hImage != 0) )
884 {
885 int yOffset, xOffset;
886 int imageWidth, imageHeight;
887
888 /*
889 * We extract the size of the image from the handle.
890 */
891 if (dwStyle & BS_ICON)
892 {
893 ICONINFO iconInfo;
894 BITMAP bm;
895
896 GetIconInfo((HICON)infoPtr->hImage,&iconInfo);
897 if (iconInfo.hbmColor)
898 {
899 GetObjectA(iconInfo.hbmColor,sizeof(BITMAP),&bm);
900 imageWidth = bm.bmWidth;
901 imageHeight = bm.bmHeight;
902 } else
903 {
904 GetObjectA(iconInfo.hbmMask,sizeof(BITMAP),&bm);
905 imageWidth = bm.bmWidth;
906 imageHeight = bm.bmHeight/2;
907 }
908
909 if (iconInfo.hbmColor) DeleteObject(iconInfo.hbmColor);
910 if (iconInfo.hbmMask) DeleteObject(iconInfo.hbmMask);
911
912 }
913 else
914 {
915 BITMAP bm;
916
917 GetObjectA (infoPtr->hImage, sizeof(BITMAP), &bm);
918
919 imageWidth = bm.bmWidth;
920 imageHeight = bm.bmHeight;
921 }
922
923 /* Center the bitmap */
924 xOffset = (((rc.right - rc.left) - 2*xBorderOffset) - imageWidth ) / 2;
925 yOffset = (((rc.bottom - rc.top) - 2*yBorderOffset) - imageHeight) / 2;
926
927 /* If the image is too big for the button then create a region*/
928 if(xOffset < 0 || yOffset < 0)
929 {
930 HRGN hBitmapRgn = 0;
931 hBitmapRgn = CreateRectRgn(
932 rc.left + xBorderOffset, rc.top +yBorderOffset,
933 rc.right - xBorderOffset, rc.bottom - yBorderOffset);
934 SelectClipRgn(hDC, hBitmapRgn);
935 DeleteObject(hBitmapRgn);
936 }
937
938 /* Let minimum 1 space from border */
939 xOffset++, yOffset++;
940
941 /*
942 * Draw the image now.
943 */
944 if (dwStyle & BS_ICON)
945 {
946 DrawIcon(hDC,
947 rc.left + xOffset, rc.top + yOffset,
948 (HICON)infoPtr->hImage);
949 }
950 else
951 {
952 HDC hdcMem;
953
954 hdcMem = CreateCompatibleDC (hDC);
955 SelectObject (hdcMem, (HBITMAP)infoPtr->hImage);
956 BitBlt(hDC,
957 rc.left + xOffset,
958 rc.top + yOffset,
959 imageWidth, imageHeight,
960 hdcMem, 0, 0, SRCCOPY);
961
962 DeleteDC (hdcMem);
963 }
964
965 if(xOffset < 0 || yOffset < 0)
966 {
967 SelectClipRgn(hDC, 0);
968 }
969 }
970
971 SelectObject( hDC, hOldPen );
972 SelectObject( hDC, hOldBrush );
973
974 if ((infoPtr->state & BUTTON_HASFOCUS) && IsWindowEnabled(hwnd))
975 {
976 InflateRect( &focus_rect, -1, -1 );
977 DrawFocusRect( hDC, &focus_rect );
978 }
979}
980
981
982static void DrawDisabledText(HDC hdc,char* text,RECT* rtext,UINT format)
983{
984 COLORREF textColor = (GetSysColor(COLOR_GRAYTEXT) == GetBkColor(hdc)) ? COLOR_BTNTEXT:COLOR_GRAYTEXT;
985 RECT rect = *rtext;
986 COLORREF oldMode;
987
988 //CB: bug in Open32 DrawText: underscore is always black! -> two black lines!
989 SetTextColor(hdc,GetSysColor(COLOR_3DHILIGHT));
990 DrawTextA(hdc,text,-1,&rect,format);
991 SetTextColor(hdc,GetSysColor(COLOR_GRAYTEXT));
992 oldMode = SetBkMode(hdc,TRANSPARENT);
993 OffsetRect(&rect,-1,-1);
994 DrawTextA(hdc,text,-1,&rect,format);
995 SetBkMode(hdc,oldMode);
996}
997
998/**********************************************************************
999 * Check Box & Radio Button Functions
1000 */
1001
1002static void CB_Paint(HWND hwnd,HDC hDC,WORD action)
1003{
1004 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
1005 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
1006 RECT rbox, rtext, client;
1007 HBRUSH hBrush, hOldBrush;
1008 HPEN hPen, hOldPen;
1009 COLORREF colour;
1010 int textLen, delta;
1011 char* text = NULL;
1012
1013 /*
1014 * if the button has a bitmap/icon, draw a normal pushbutton
1015 * instead of a radion button.
1016 */
1017 if (infoPtr->hImage != 0)
1018 {
1019 BOOL bHighLighted = ((infoPtr->state & BUTTON_HIGHLIGHTED) ||
1020 (infoPtr->state & BUTTON_CHECKED));
1021
1022 BUTTON_DrawPushButton(hwnd,
1023 hDC,
1024 action,
1025 bHighLighted);
1026 return;
1027 }
1028
1029 textLen = 0;
1030 GetClientRect(hwnd, &client);
1031 rbox = rtext = client;
1032
1033 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
1034
1035#ifdef __WIN32OS2__
1036 //(Auto)Check, (Auto)Radio & (Auto)3State buttons send WM_CTLCOLORSTATIC
1037 //instead of WM_CTLCOLORBTN (verified in NT4)
1038 hBrush = SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, hDC, (LPARAM)hwnd );
1039 if (!hBrush) /* did the app forget to call defwindowproc ? */
1040 hBrush = DefWindowProcW( GetParent(hwnd), WM_CTLCOLORSTATIC, hDC, (LPARAM)hwnd );
1041#endif
1042
1043 if (dwStyle & BS_LEFTTEXT)
1044 {
1045 /* magic +4 is what CTL3D expects */
1046
1047 rtext.right -= checkBoxWidth + 4;
1048 //CB: space for focus rect
1049 rtext.left++;
1050 rtext.right++;
1051 rbox.left = rbox.right - checkBoxWidth;
1052 }
1053 else
1054 {
1055 rtext.left += checkBoxWidth + 4;
1056 rbox.right = checkBoxWidth;
1057 }
1058
1059 /* Draw the check-box bitmap */
1060
1061 textLen = GetWindowTextLengthA(hwnd);
1062 if (textLen > 0)
1063 {
1064 textLen++;
1065 text = (char*)malloc(textLen);
1066 GetWindowTextA(hwnd,text,textLen);
1067 }
1068 if ((action == ODA_DRAWENTIRE) || (action == ODA_SELECT))
1069 {
1070 UINT state;
1071
1072 /* Since WM_ERASEBKGND does nothing, first prepare background */
1073 if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush );
1074 else FillRect( hDC, &client, hBrush );
1075
1076 if (((dwStyle & 0x0f) == BS_RADIOBUTTON) ||
1077 ((dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) state = DFCS_BUTTONRADIO;
1078 else if (infoPtr->state & BUTTON_3STATE) state = DFCS_BUTTON3STATE;
1079 else state = DFCS_BUTTONCHECK;
1080
1081 if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) state |= DFCS_CHECKED;
1082
1083 if (infoPtr->state & BUTTON_HIGHLIGHTED) state |= DFCS_PUSHED;
1084
1085 if (dwStyle & WS_DISABLED) state |= DFCS_INACTIVE;
1086
1087 if (dwStyle & BS_FLAT) state |= DFCS_FLAT;
1088
1089 DrawFrameControl( hDC, &rbox, DFC_BUTTON, state );
1090
1091 if( text && action != ODA_SELECT )
1092 {
1093 INT format = BUTTON_GetTextFormat(dwStyle,GetWindowLongA(hwnd,GWL_EXSTYLE),DT_TOP,DT_VCENTER);
1094
1095 if (dwStyle & WS_DISABLED) DrawDisabledText(hDC,text,&rtext,format);
1096 else DrawTextA(hDC,text,-1,&rtext,format);
1097 }
1098 }
1099
1100 if ((action == ODA_FOCUS) ||
1101 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS) && IsWindowEnabled(hwnd)))
1102 {
1103 /* again, this is what CTL3D expects */
1104
1105 SetRectEmpty(&rbox);
1106 if(textLen > 0)
1107 DrawTextA(hDC,text,-1,&rbox,DT_SINGLELINE | DT_CALCRECT);
1108 textLen = rbox.bottom - rbox.top;
1109 delta = ((rtext.bottom - rtext.top) - textLen)/2;
1110 rbox.bottom = (rbox.top = rtext.top + delta - 1) + textLen + 2;
1111 textLen = rbox.right - rbox.left;
1112 rbox.right = (rbox.left += --rtext.left) + textLen + 2;
1113 IntersectRect(&rbox, &rbox, &rtext);
1114 DrawFocusRect( hDC, &rbox );
1115 }
1116 if (text) free(text);
1117}
1118
1119
1120/**********************************************************************
1121 * BUTTON_CheckAutoRadioButton
1122 *
1123 * wndPtr is checked, uncheck every other auto radio button in group
1124 */
1125static void BUTTON_CheckAutoRadioButton(HWND hwnd)
1126{
1127 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
1128 HWND parent, sibling, start;
1129
1130 if (!(dwStyle & WS_CHILD)) return;
1131 parent = GetParent(hwnd);
1132 /* assure that starting control is not disabled or invisible */
1133 //start = sibling = GetNextDlgGroupItem( parent, hwnd, TRUE );
1134 //@YD: bugfix
1135 //CB: doesn't work!
1136 start = sibling = GetNextDlgGroupItem( parent, hwnd, TRUE );
1137 do
1138 {
1139 if (!sibling) break;
1140 if ((hwnd != sibling) &&
1141 ((GetWindowLongA(sibling,GWL_STYLE) & 0x0f) == BS_AUTORADIOBUTTON))
1142 SendMessageA( sibling, BM_SETCHECK, BUTTON_UNCHECKED, 0 );
1143 sibling = GetNextDlgGroupItem( parent, sibling, FALSE );
1144 } while (sibling != start);
1145}
1146
1147
1148/**********************************************************************
1149 * Group Box Functions
1150 */
1151
1152static void GB_Paint(HWND hwnd,HDC hDC,WORD action)
1153{
1154 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
1155 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
1156 RECT rc, rcFrame;
1157 TEXTMETRICA tm;
1158 INT textLen;
1159 char* text;
1160 HBRUSH hbr;
1161
1162 if (action != ODA_DRAWENTIRE) return;
1163
1164 /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */
1165 hbr = GetControlBrush( hwnd, hDC, CTLCOLOR_STATIC );
1166
1167 GetClientRect(hwnd,&rc);
1168
1169 rcFrame = rc;
1170
1171 if (infoPtr->hFont)
1172 SelectObject (hDC, infoPtr->hFont);
1173 GetTextMetricsA (hDC, &tm);
1174 rcFrame.top += (tm.tmHeight / 2) - 1;
1175 DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT);
1176
1177 textLen = GetWindowTextLengthA(hwnd);
1178 if (textLen > 0)
1179 {
1180 INT format = BUTTON_GetTextFormat(dwStyle,GetWindowLongA(hwnd,GWL_EXSTYLE),DT_LEFT,DT_TOP) | DT_NOCLIP | DT_SINGLELINE;
1181
1182 textLen++;
1183 text = (char*)malloc(textLen);
1184 GetWindowTextA(hwnd,text,textLen);
1185 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
1186 rc.left += 10;
1187
1188 if (dwStyle & WS_DISABLED) {
1189 DrawDisabledText(hDC,text,&rc,format);
1190 }
1191 else
1192 {
1193 SetTextColor(hDC,GetSysColor(COLOR_BTNTEXT));
1194 DrawTextA(hDC,text,-1,&rc,format);
1195 }
1196
1197 free(text);
1198 }
1199}
1200
1201
1202/**********************************************************************
1203 * User Button Functions
1204 */
1205
1206static void UB_Paint(HWND hwnd,HDC hDC,WORD action)
1207{
1208 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
1209 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
1210 RECT rc;
1211 HBRUSH hBrush;
1212 if (action == ODA_SELECT) return;
1213
1214 GetClientRect(hwnd,&rc);
1215
1216 if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont );
1217 hBrush = GetControlBrush( hwnd, hDC, CTLCOLOR_BTN );
1218
1219 FillRect( hDC, &rc, hBrush );
1220 if ((action == ODA_FOCUS) ||
1221 ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS) && IsWindowEnabled(hwnd)))
1222 {
1223 DrawFocusRect( hDC, &rc );
1224 InflateRect(&rc,-1,-1);
1225 }
1226}
1227
1228
1229/**********************************************************************
1230 * Ownerdrawn Button Functions
1231 */
1232
1233static void OB_Paint(HWND hwnd,HDC hDC,WORD action)
1234{
1235 BUTTONINFO* infoPtr = (BUTTONINFO*)GetInfoPtr(hwnd);
1236 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
1237 DRAWITEMSTRUCT dis;
1238
1239 dis.CtlType = ODT_BUTTON;
1240 dis.CtlID = GetWindowLongA(hwnd,GWL_ID);
1241 dis.itemID = 0;
1242 dis.itemAction = action;
1243 dis.itemState = ((infoPtr->state & BUTTON_HASFOCUS) ? ODS_FOCUS : 0) |
1244 ((infoPtr->state & BUTTON_HIGHLIGHTED) ? ODS_SELECTED : 0) |
1245 ((dwStyle & WS_DISABLED) ? ODS_DISABLED : 0);
1246 dis.hwndItem = hwnd;
1247 dis.hDC = hDC;
1248 dis.itemData = 0;
1249 GetClientRect( hwnd, &dis.rcItem );
1250
1251 SetBkColor( hDC, GetSysColor( COLOR_BTNFACE ) );
1252
1253 dprintf(("OWNERDRAW button %x, enabled %d", hwnd, !(dwStyle & WS_DISABLED)));
1254 SendMessageA( GetParent(hwnd), WM_DRAWITEM,
1255 GetWindowLongA(hwnd,GWL_ID), (LPARAM)&dis );
1256}
1257
1258BOOL BUTTON_Register()
1259{
1260 WNDCLASSA wndClass;
1261
1262//SvL: Don't check this now
1263// if (GlobalFindAtomA(BUTTONCLASSNAME)) return FALSE;
1264
1265 ZeroMemory(&wndClass,sizeof(WNDCLASSA));
1266 wndClass.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW | CS_PARENTDC | CS_DBLCLKS;
1267 wndClass.lpfnWndProc = (WNDPROC)ButtonWndProc;
1268 wndClass.cbClsExtra = 0;
1269 wndClass.cbWndExtra = sizeof(BUTTONINFO);
1270 wndClass.hCursor = LoadCursorA(0,IDC_ARROWA);
1271 wndClass.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
1272 wndClass.lpszClassName = BUTTONCLASSNAME;
1273
1274 return RegisterClassA(&wndClass);
1275}
1276
1277BOOL BUTTON_Unregister()
1278{
1279 if (GlobalFindAtomA(BUTTONCLASSNAME))
1280 return UnregisterClassA(BUTTONCLASSNAME,(HINSTANCE)NULL);
1281 else return FALSE;
1282}
Note: See TracBrowser for help on using the repository browser.