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