Allow unsetting wxMenuItem as start of radio group too.
[wxWidgets.git] / src / osx / anybutton_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/anybutton_osx.cpp
3 // Purpose: wxAnyButton
4 // Author: Stefan Csomor
5 // Created: 1998-01-01 (extracted from button_osx.cpp)
6 // RCS-ID: $Id: anybutton_osx.cpp 67280 2011-03-22 14:17:38Z DS $
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/wxprec.h"
12
13 #include "wx/anybutton.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/panel.h"
17 #include "wx/toplevel.h"
18 #include "wx/dcclient.h"
19 #include "wx/stattext.h"
20 #endif
21
22 #include "wx/stockitem.h"
23
24 #include "wx/osx/private.h"
25
26 BEGIN_EVENT_TABLE(wxAnyButton, wxControl)
27 EVT_ENTER_WINDOW(wxAnyButton::OnEnterWindow)
28 EVT_LEAVE_WINDOW(wxAnyButton::OnLeaveWindow)
29 END_EVENT_TABLE()
30
31 void wxAnyButton::SetLabel(const wxString& label)
32 {
33 if ( HasFlag(wxBU_NOTEXT) )
34 {
35 // just store the label internally but don't really use it for the
36 // button
37 m_labelOrig =
38 m_label = label;
39 return;
40 }
41
42 wxAnyButtonBase::SetLabel(label);
43 }
44
45 wxBitmap wxAnyButton::DoGetBitmap(State which) const
46 {
47 return m_bitmaps[which];
48 }
49
50 void wxAnyButton::DoSetBitmap(const wxBitmap& bitmap, State which)
51 {
52 m_bitmaps[which] = bitmap;
53
54 if ( which == State_Normal )
55 GetPeer()->SetBitmap(bitmap);
56 else if ( which == State_Pressed )
57 {
58 wxButtonImpl* bi = dynamic_cast<wxButtonImpl*> (GetPeer());
59 if ( bi )
60 bi->SetPressedBitmap(bitmap);
61 }
62 InvalidateBestSize();
63 }
64
65 void wxAnyButton::DoSetBitmapPosition(wxDirection dir)
66 {
67 GetPeer()->SetBitmapPosition(dir);
68 InvalidateBestSize();
69 }
70
71 #if wxUSE_MARKUP && wxOSX_USE_COCOA
72
73 bool wxAnyButton::DoSetLabelMarkup(const wxString& markup)
74 {
75 if ( !wxAnyButtonBase::DoSetLabelMarkup(markup) )
76 return false;
77
78 GetPeer()->SetLabelMarkup(markup);
79
80 return true;
81 }
82
83 #endif // wxUSE_MARKUP && wxOSX_USE_COCOA
84
85 void wxAnyButton::OnEnterWindow( wxMouseEvent& WXUNUSED(event))
86 {
87 if ( DoGetBitmap( State_Current ).IsOk() )
88 GetPeer()->SetBitmap( DoGetBitmap( State_Current ) );
89 }
90
91 void wxAnyButton::OnLeaveWindow( wxMouseEvent& WXUNUSED(event))
92 {
93 if ( DoGetBitmap( State_Current ).IsOk() )
94 GetPeer()->SetBitmap( DoGetBitmap( State_Normal ) );
95 }