]> git.saurik.com Git - wxWidgets.git/blame - src/msw/button.cpp
* Apply patch #735595. Add miminumAcceptable{Height,Width}
[wxWidgets.git] / src / msw / button.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
cd0b1709 2// Name: msw/button.cpp
2bda0e17
KB
3// Purpose: wxButton
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa
JS
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
edccf428
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
cd0b1709 19
2bda0e17 20#ifdef __GNUG__
edccf428 21 #pragma implementation "button.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
edccf428 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
1e6feb95
VZ
31#if wxUSE_BUTTON
32
2bda0e17 33#ifndef WX_PRECOMP
bac409a0 34 #include "wx/app.h"
edccf428
VZ
35 #include "wx/button.h"
36 #include "wx/brush.h"
4e938f5b 37 #include "wx/panel.h"
8a4df159 38 #include "wx/bmpbuttn.h"
fb39c7ec
RR
39 #include "wx/settings.h"
40 #include "wx/dcscreen.h"
2bda0e17
KB
41#endif
42
43#include "wx/msw/private.h"
44
edccf428
VZ
45// ----------------------------------------------------------------------------
46// macros
47// ----------------------------------------------------------------------------
48
cd0b1709 49IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
2bda0e17 50
edccf428
VZ
51// this macro tries to adjust the default button height to a reasonable value
52// using the char height as the base
1c4a764c 53#define BUTTON_HEIGHT_FROM_CHAR_HEIGHT(cy) (11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)/10)
2bda0e17 54
edccf428
VZ
55// ============================================================================
56// implementation
57// ============================================================================
58
59// ----------------------------------------------------------------------------
60// creation/destruction
61// ----------------------------------------------------------------------------
62
63bool wxButton::Create(wxWindow *parent,
64 wxWindowID id,
65 const wxString& label,
66 const wxPoint& pos,
67 const wxSize& size,
68 long style,
69 const wxValidator& validator,
70 const wxString& name)
2bda0e17 71{
5b2f31eb 72 if ( !CreateControl(parent, id, pos, size, style, validator, name) )
edccf428
VZ
73 return FALSE;
74
8292017c
VZ
75 WXDWORD exstyle;
76 WXDWORD msStyle = MSWGetStyle(style, &exstyle);
77
78#ifdef __WIN32__
79 // if the label contains several lines we must explicitly tell the button
80 // about it or it wouldn't draw it correctly ("\n"s would just appear as
81 // black boxes)
82 //
83 // NB: we do it here and not in MSWGetStyle() because we need the label
84 // value and m_label is not set yet when MSWGetStyle() is called;
85 // besides changing BS_MULTILINE during run-time is pointless anyhow
86 if ( label.find(_T('\n')) != wxString::npos )
87 {
88 msStyle |= BS_MULTILINE;
89 }
90#endif // __WIN32__
91
92 return MSWCreateControl(_T("BUTTON"), msStyle, pos, size, label, exstyle);
5b2f31eb
VZ
93}
94
95wxButton::~wxButton()
96{
97}
edccf428 98
5b2f31eb
VZ
99// ----------------------------------------------------------------------------
100// flags
101// ----------------------------------------------------------------------------
cd0b1709 102
5b2f31eb
VZ
103WXDWORD wxButton::MSWGetStyle(long style, WXDWORD *exstyle) const
104{
105 // buttons never have an external border, they draw their own one
106 WXDWORD msStyle = wxControl::MSWGetStyle
107 (
108 (style & ~wxBORDER_MASK) | wxBORDER_NONE, exstyle
109 );
f6bcfd97 110
5b2f31eb
VZ
111 // we must use WS_CLIPSIBLINGS with the buttons or they would draw over
112 // each other in any resizeable dialog which has more than one button in
113 // the bottom
114 msStyle |= WS_CLIPSIBLINGS;
b0766406 115
f6bcfd97 116#ifdef __WIN32__
5b2f31eb
VZ
117 // don't use "else if" here: weird as it is, but you may combine wxBU_LEFT
118 // and wxBU_RIGHT to get BS_CENTER!
119 if ( style & wxBU_LEFT )
f6bcfd97 120 msStyle |= BS_LEFT;
5b2f31eb 121 if ( style & wxBU_RIGHT )
f6bcfd97 122 msStyle |= BS_RIGHT;
5b2f31eb 123 if ( style & wxBU_TOP )
f6bcfd97 124 msStyle |= BS_TOP;
5b2f31eb 125 if ( style & wxBU_BOTTOM )
f6bcfd97 126 msStyle |= BS_BOTTOM;
5b2f31eb 127#endif // __WIN32__
edccf428 128
5b2f31eb 129 return msStyle;
2bda0e17
KB
130}
131
edccf428
VZ
132// ----------------------------------------------------------------------------
133// size management including autosizing
134// ----------------------------------------------------------------------------
135
f68586e5 136wxSize wxButton::DoGetBestSize() const
2bda0e17 137{
4438caf4 138 int wBtn;
1e023926 139 GetTextExtent(wxGetWindowText(GetHWND()), &wBtn, NULL);
edccf428 140
4438caf4
VZ
141 int wChar, hChar;
142 wxGetCharSize(GetHWND(), &wChar, &hChar, &GetFont());
143
1e023926 144 // add a margin -- the button is wider than just its label
4438caf4
VZ
145 wBtn += 3*wChar;
146
147 // the button height is proportional to the height of the font used
148 int hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar);
edccf428 149
1e023926
VZ
150 // all buttons have at least the standard size unless the user explicitly
151 // wants them to be of smaller size and used wxBU_EXACTFIT style when
152 // creating the button
153 if ( !HasFlag(wxBU_EXACTFIT) )
188b9f2e
RD
154 {
155 wxSize sz = GetDefaultSize();
1e023926
VZ
156 if (wBtn > sz.x)
157 sz.x = wBtn;
158 if (hBtn > sz.y)
159 sz.y = hBtn;
160
188b9f2e
RD
161 return sz;
162 }
a63f2bec 163
1e023926 164 return wxSize(wBtn, hBtn);
2bda0e17
KB
165}
166
e1f36ff8 167/* static */
1e6feb95 168wxSize wxButtonBase::GetDefaultSize()
e1f36ff8 169{
8c3c31d4 170 static wxSize s_sizeBtn;
e1f36ff8 171
8c3c31d4
VZ
172 if ( s_sizeBtn.x == 0 )
173 {
174 wxScreenDC dc;
a756f210 175 dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
8c3c31d4
VZ
176
177 // the size of a standard button in the dialog units is 50x14,
178 // translate this to pixels
179 // NB1: the multipliers come from the Windows convention
180 // NB2: the extra +1/+2 were needed to get the size be the same as the
181 // size of the buttons in the standard dialog - I don't know how
182 // this happens, but on my system this size is 75x23 in pixels and
183 // 23*8 isn't even divisible by 14... Would be nice to understand
184 // why these constants are needed though!
185 s_sizeBtn.x = (50 * (dc.GetCharWidth() + 1))/4;
186 s_sizeBtn.y = ((14 * dc.GetCharHeight()) + 2)/8;
187 }
e1f36ff8 188
8c3c31d4 189 return s_sizeBtn;
e1f36ff8
VZ
190}
191
4438caf4 192// ----------------------------------------------------------------------------
036da5e3 193// default button handling
4438caf4
VZ
194// ----------------------------------------------------------------------------
195
d78f09e2
VZ
196/*
197 "Everything you ever wanted to know about the default buttons" or "Why do we
198 have to do all this?"
199
200 In MSW the default button should be activated when the user presses Enter
201 and the current control doesn't process Enter itself somehow. This is
202 handled by ::DefWindowProc() (or maybe ::DefDialogProc()) using DM_SETDEFID
203 Another aspect of "defaultness" is that the default button has different
204 appearance: this is due to BS_DEFPUSHBUTTON style which is completely
7fb1b2b4
VZ
205 separate from DM_SETDEFID stuff (!). Also note that BS_DEFPUSHBUTTON should
206 be unset if our parent window is not active so it should be unset whenever
207 we lose activation and set back when we regain it.
d78f09e2
VZ
208
209 Final complication is that when a button is active, it should be the default
210 one, i.e. pressing Enter on a button always activates it and not another
211 one.
212
213 We handle this by maintaining a permanent and a temporary default items in
214 wxControlContainer (both may be NULL). When a button becomes the current
215 control (i.e. gets focus) it sets itself as the temporary default which
216 ensures that it has the right appearance and that Enter will be redirected
217 to it. When the button loses focus, it unsets the temporary default and so
218 the default item will be the permanent default -- that is the default button
219 if any had been set or none otherwise, which is just what we want.
220
7fb1b2b4
VZ
221 NB: all this is quite complicated by now and the worst is that normally
222 it shouldn't be necessary at all as for the normal Windows programs
223 DefWindowProc() and IsDialogMessage() take care of all this
224 automatically -- however in wxWindows programs this doesn't work for
225 nested hierarchies (i.e. a notebook inside a notebook) for unknown
226 reason and so we have to reproduce all this code ourselves. It would be
227 very nice if we could avoid doing it.
d78f09e2
VZ
228 */
229
036da5e3 230// set this button as the (permanently) default one in its panel
edccf428 231void wxButton::SetDefault()
2bda0e17 232{
edccf428 233 wxWindow *parent = GetParent();
2bda0e17 234
036da5e3
VZ
235 wxCHECK_RET( parent, _T("button without parent?") );
236
7fb1b2b4 237 // set this one as the default button both for wxWindows ...
036da5e3 238 wxWindow *winOldDefault = parent->SetDefaultItem(this);
036da5e3 239
7fb1b2b4
VZ
240 // ... and Windows
241 SetDefaultStyle(wxDynamicCast(winOldDefault, wxButton), FALSE);
242 SetDefaultStyle(this, TRUE);
036da5e3
VZ
243}
244
7fb1b2b4 245// set this button as being currently default
036da5e3
VZ
246void wxButton::SetTmpDefault()
247{
248 wxWindow *parent = GetParent();
249
250 wxCHECK_RET( parent, _T("button without parent?") );
251
252 wxWindow *winOldDefault = parent->GetDefaultItem();
253 parent->SetTmpDefaultItem(this);
7fb1b2b4
VZ
254
255 SetDefaultStyle(wxDynamicCast(winOldDefault, wxButton), FALSE);
256 SetDefaultStyle(this, TRUE);
036da5e3
VZ
257}
258
7fb1b2b4 259// unset this button as currently default, it may still stay permanent default
036da5e3
VZ
260void wxButton::UnsetTmpDefault()
261{
262 wxWindow *parent = GetParent();
263
264 wxCHECK_RET( parent, _T("button without parent?") );
265
266 parent->SetTmpDefaultItem(NULL);
267
268 wxWindow *winOldDefault = parent->GetDefaultItem();
7fb1b2b4
VZ
269
270 SetDefaultStyle(this, FALSE);
271 SetDefaultStyle(wxDynamicCast(winOldDefault, wxButton), TRUE);
036da5e3 272}
8ed57d93 273
036da5e3
VZ
274/* static */
275void
7fb1b2b4 276wxButton::SetDefaultStyle(wxButton *btn, bool on)
036da5e3 277{
7fb1b2b4
VZ
278 // we may be called with NULL pointer -- simpler to do the check here than
279 // in the caller which does wxDynamicCast()
280 if ( !btn )
281 return;
282
283 // first, let DefDlgProc() know about the new default button
284 if ( on )
5d1d2d46 285 {
7fb1b2b4
VZ
286 // we shouldn't set BS_DEFPUSHBUTTON for any button if we don't have
287 // focus at all any more
288 if ( !wxTheApp->IsActive() )
289 return;
cd0b1709 290
7fb1b2b4
VZ
291 // look for a panel-like window
292 wxWindow *win = btn->GetParent();
293 while ( win && !win->HasFlag(wxTAB_TRAVERSAL) )
294 win = win->GetParent();
295
296 if ( win )
be4017f8 297 {
7fb1b2b4
VZ
298 ::SendMessage(GetHwndOf(win), DM_SETDEFID, btn->GetId(), 0L);
299
300 // sending DM_SETDEFID also changes the button style to
301 // BS_DEFPUSHBUTTON so there is nothing more to do
be4017f8 302 }
5d1d2d46
VZ
303 }
304
7fb1b2b4
VZ
305 // then also change the style as needed
306 long style = ::GetWindowLong(GetHwndOf(btn), GWL_STYLE);
307 if ( !(style & BS_DEFPUSHBUTTON) == on )
be4017f8 308 {
7fb1b2b4
VZ
309 // don't do it with the owner drawn buttons because it will
310 // reset BS_OWNERDRAW style bit too (as BS_OWNERDRAW &
311 // BS_DEFPUSHBUTTON != 0)!
036da5e3
VZ
312 if ( (style & BS_OWNERDRAW) != BS_OWNERDRAW )
313 {
7fb1b2b4
VZ
314 ::SendMessage(GetHwndOf(btn), BM_SETSTYLE,
315 on ? style | BS_DEFPUSHBUTTON
316 : style & ~BS_DEFPUSHBUTTON,
317 1L /* redraw */);
036da5e3 318 }
7fb1b2b4 319 else // owner drawn
036da5e3 320 {
7fb1b2b4
VZ
321 // redraw the button - it will notice itself that it's
322 // [not] the default one [any longer]
323 btn->Refresh();
036da5e3 324 }
be4017f8 325 }
7fb1b2b4 326 //else: already has correct style
2bda0e17
KB
327}
328
edccf428
VZ
329// ----------------------------------------------------------------------------
330// helpers
331// ----------------------------------------------------------------------------
332
333bool wxButton::SendClickEvent()
2bda0e17 334{
edccf428
VZ
335 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
336 event.SetEventObject(this);
337
338 return ProcessCommand(event);
2bda0e17
KB
339}
340
edccf428 341void wxButton::Command(wxCommandEvent & event)
2bda0e17 342{
edccf428 343 ProcessCommand(event);
2bda0e17
KB
344}
345
edccf428
VZ
346// ----------------------------------------------------------------------------
347// event/message handlers
348// ----------------------------------------------------------------------------
2bda0e17 349
33ac7e6f 350bool wxButton::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
edccf428
VZ
351{
352 bool processed = FALSE;
57c0af52 353 switch ( param )
edccf428 354 {
5aab763c
RD
355 // NOTE: Apparently older versions (NT 4?) of the common controls send
356 // BN_DOUBLECLICKED but not a second BN_CLICKED for owner-drawn
357 // buttons, so in order to send two EVET_BUTTON events we should
358 // catch both types. Currently (Feb 2003) up-to-date versions of
359 // win98, win2k and winXP all send two BN_CLICKED messages for
360 // all button types, so we don't catch BN_DOUBLECLICKED anymore
361 // in order to not get 3 EVT_BUTTON events. If this is a problem
362 // then we need to figure out which version of the comctl32 changed
363 // this behaviour and test for it.
364
a95e38c0
VZ
365 case 1: // message came from an accelerator
366 case BN_CLICKED: // normal buttons send this
57c0af52
VZ
367 processed = SendClickEvent();
368 break;
edccf428 369 }
2bda0e17 370
edccf428 371 return processed;
2bda0e17
KB
372}
373
678cd6de
VZ
374long wxButton::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
375{
036da5e3
VZ
376 // when we receive focus, we want to temporary become the default button in
377 // our parent panel so that pressing "Enter" would activate us -- and when
378 // losing it we should restore the previous default button as well
be4017f8 379 if ( nMsg == WM_SETFOCUS )
678cd6de 380 {
036da5e3 381 SetTmpDefault();
be4017f8 382
036da5e3
VZ
383 // let the default processing take place too
384 }
385 else if ( nMsg == WM_KILLFOCUS )
386 {
387 UnsetTmpDefault();
678cd6de 388 }
a95e38c0
VZ
389 else if ( nMsg == WM_LBUTTONDBLCLK )
390 {
f6bcfd97
BP
391 // emulate a click event to force an owner-drawn button to change its
392 // appearance - without this, it won't do it
393 (void)wxControl::MSWWindowProc(WM_LBUTTONDOWN, wParam, lParam);
394
036da5e3 395 // and continue with processing the message normally as well
a95e38c0 396 }
678cd6de
VZ
397
398 // let the base class do all real processing
399 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
400}
cd0b1709
VZ
401
402// ----------------------------------------------------------------------------
403// owner-drawn buttons support
404// ----------------------------------------------------------------------------
405
406#ifdef __WIN32__
407
408// drawing helpers
409
410static void DrawButtonText(HDC hdc,
411 RECT *pRect,
412 const wxString& text,
413 COLORREF col)
414{
415 COLORREF colOld = SetTextColor(hdc, col);
416 int modeOld = SetBkMode(hdc, TRANSPARENT);
417
0fa939c2 418 ::DrawText(hdc, text, text.length(), pRect, DT_CENTER | DT_VCENTER);
cd0b1709
VZ
419
420 SetBkMode(hdc, modeOld);
421 SetTextColor(hdc, colOld);
422}
423
424static void DrawRect(HDC hdc, const RECT& r)
425{
426 MoveToEx(hdc, r.left, r.top, NULL);
427 LineTo(hdc, r.right, r.top);
428 LineTo(hdc, r.right, r.bottom);
429 LineTo(hdc, r.left, r.bottom);
430 LineTo(hdc, r.left, r.top);
431}
432
433void wxButton::MakeOwnerDrawn()
434{
435 long style = GetWindowLong(GetHwnd(), GWL_STYLE);
9750fc42 436 if ( (style & BS_OWNERDRAW) != BS_OWNERDRAW )
cd0b1709
VZ
437 {
438 // make it so
439 style |= BS_OWNERDRAW;
440 SetWindowLong(GetHwnd(), GWL_STYLE, style);
441 }
442}
443
444bool wxButton::SetBackgroundColour(const wxColour &colour)
445{
446 if ( !wxControl::SetBackgroundColour(colour) )
447 {
448 // nothing to do
449 return FALSE;
450 }
451
452 MakeOwnerDrawn();
453
454 Refresh();
455
456 return TRUE;
457}
458
459bool wxButton::SetForegroundColour(const wxColour &colour)
460{
461 if ( !wxControl::SetForegroundColour(colour) )
462 {
463 // nothing to do
464 return FALSE;
465 }
466
467 MakeOwnerDrawn();
468
469 Refresh();
470
471 return TRUE;
472}
473
474/*
475 The button frame looks like this normally:
476
477 WWWWWWWWWWWWWWWWWWB
16162a64
GRG
478 WHHHHHHHHHHHHHHHHGB W = white (HILIGHT)
479 WH GB H = light grey (LIGHT)
480 WH GB G = dark grey (SHADOW)
481 WH GB B = black (DKSHADOW)
482 WH GB
cd0b1709
VZ
483 WGGGGGGGGGGGGGGGGGB
484 BBBBBBBBBBBBBBBBBBB
485
486 When the button is selected, the button becomes like this (the total button
487 size doesn't change):
488
489 BBBBBBBBBBBBBBBBBBB
490 BWWWWWWWWWWWWWWWWBB
16162a64
GRG
491 BWHHHHHHHHHHHHHHGBB
492 BWH GBB
493 BWH GBB
cd0b1709
VZ
494 BWGGGGGGGGGGGGGGGBB
495 BBBBBBBBBBBBBBBBBBB
496 BBBBBBBBBBBBBBBBBBB
497
498 When the button is pushed (while selected) it is like:
499
500 BBBBBBBBBBBBBBBBBBB
501 BGGGGGGGGGGGGGGGGGB
502 BG GB
503 BG GB
504 BG GB
16162a64 505 BG GB
cd0b1709
VZ
506 BGGGGGGGGGGGGGGGGGB
507 BBBBBBBBBBBBBBBBBBB
508*/
509
510static void DrawButtonFrame(HDC hdc, const RECT& rectBtn,
511 bool selected, bool pushed)
512{
513 RECT r;
514 CopyRect(&r, &rectBtn);
515
16162a64
GRG
516 HPEN hpenBlack = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW)),
517 hpenGrey = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW)),
518 hpenLightGr = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DLIGHT)),
519 hpenWhite = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT));
cd0b1709
VZ
520
521 HPEN hpenOld = (HPEN)SelectObject(hdc, hpenBlack);
522
523 r.right--;
524 r.bottom--;
525
526 if ( pushed )
527 {
528 DrawRect(hdc, r);
529
530 (void)SelectObject(hdc, hpenGrey);
531 InflateRect(&r, -1, -1);
532
533 DrawRect(hdc, r);
534 }
535 else // !pushed
536 {
537 if ( selected )
538 {
539 DrawRect(hdc, r);
540
541 InflateRect(&r, -1, -1);
542 }
543
544 MoveToEx(hdc, r.left, r.bottom, NULL);
545 LineTo(hdc, r.right, r.bottom);
546 LineTo(hdc, r.right, r.top - 1);
547
548 (void)SelectObject(hdc, hpenWhite);
549 MoveToEx(hdc, r.left, r.bottom - 1, NULL);
550 LineTo(hdc, r.left, r.top);
551 LineTo(hdc, r.right, r.top);
552
16162a64
GRG
553 (void)SelectObject(hdc, hpenLightGr);
554 MoveToEx(hdc, r.left + 1, r.bottom - 2, NULL);
555 LineTo(hdc, r.left + 1, r.top + 1);
556 LineTo(hdc, r.right - 1, r.top + 1);
557
cd0b1709
VZ
558 (void)SelectObject(hdc, hpenGrey);
559 MoveToEx(hdc, r.left + 1, r.bottom - 1, NULL);
560 LineTo(hdc, r.right - 1, r.bottom - 1);
561 LineTo(hdc, r.right - 1, r.top);
562 }
563
564 (void)SelectObject(hdc, hpenOld);
565 DeleteObject(hpenWhite);
16162a64 566 DeleteObject(hpenLightGr);
cd0b1709
VZ
567 DeleteObject(hpenGrey);
568 DeleteObject(hpenBlack);
569}
570
571bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis)
572{
573 LPDRAWITEMSTRUCT lpDIS = (LPDRAWITEMSTRUCT)wxdis;
574
575 RECT rectBtn;
576 CopyRect(&rectBtn, &lpDIS->rcItem);
577
578 COLORREF colBg = wxColourToRGB(GetBackgroundColour()),
579 colFg = wxColourToRGB(GetForegroundColour());
580
581 HDC hdc = lpDIS->hDC;
582 UINT state = lpDIS->itemState;
583
584 // first, draw the background
585 HBRUSH hbrushBackground = ::CreateSolidBrush(colBg);
586
587 FillRect(hdc, &rectBtn, hbrushBackground);
588
589 // draw the border for the current state
590 bool selected = (state & ODS_SELECTED) != 0;
591 if ( !selected )
592 {
593 wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
594 if ( panel )
595 {
596 selected = panel->GetDefaultItem() == this;
597 }
598 }
599 bool pushed = (SendMessage(GetHwnd(), BM_GETSTATE, 0, 0) & BST_PUSHED) != 0;
600
601 DrawButtonFrame(hdc, rectBtn, selected, pushed);
602
603 // draw the focus rect if needed
604 if ( state & ODS_FOCUS )
605 {
606 RECT rectFocus;
607 CopyRect(&rectFocus, &rectBtn);
608
609 // I don't know where does this constant come from, but this is how
610 // Windows draws them
611 InflateRect(&rectFocus, -4, -4);
612
613 DrawFocusRect(hdc, &rectFocus);
614 }
615
9750fc42
VZ
616 if ( pushed )
617 {
618 // the label is shifted by 1 pixel to create "pushed" effect
619 OffsetRect(&rectBtn, 1, 1);
620 }
621
cd0b1709
VZ
622 DrawButtonText(hdc, &rectBtn, GetLabel(),
623 state & ODS_DISABLED ? GetSysColor(COLOR_GRAYTEXT)
624 : colFg);
625
626 ::DeleteObject(hbrushBackground);
627
cd0b1709
VZ
628 return TRUE;
629}
630
631#endif // __WIN32__
1e6feb95
VZ
632
633#endif // wxUSE_BUTTON
634