]> git.saurik.com Git - wxWidgets.git/blob - src/osx/tglbtn_osx.cpp
should have been part of r74664: Avoid calling gtk_window_get_position() from "config...
[wxWidgets.git] / src / osx / tglbtn_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/tglbtn_osx.cpp
3 // Purpose: Definition of the wxToggleButton class, which implements a
4 // toggle button under wxMac.
5 // Author: Stefan Csomor
6 // Modified by:
7 // Created: 08.02.01
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declatations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include "wx/wxprec.h"
21
22 #if wxUSE_TOGGLEBTN
23
24 #include "wx/tglbtn.h"
25 #include "wx/osx/private.h"
26 #include "wx/bmpbuttn.h" // for wxDEFAULT_BUTTON_MARGIN
27
28 // ----------------------------------------------------------------------------
29 // macros
30 // ----------------------------------------------------------------------------
31
32 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
33 wxDEFINE_EVENT( wxEVT_TOGGLEBUTTON, wxCommandEvent );
34
35 // ============================================================================
36 // implementation
37 // ============================================================================
38 // ----------------------------------------------------------------------------
39 // wxToggleButton
40 // ----------------------------------------------------------------------------
41
42 bool wxToggleButton::Create(wxWindow *parent, wxWindowID id,
43 const wxString& label,
44 const wxPoint& pos,
45 const wxSize& size, long style,
46 const wxValidator& validator,
47 const wxString& name)
48 {
49 DontCreatePeer();
50
51 m_marginX =
52 m_marginY = 0;
53
54 // FIXME: this hack is needed because we're called from
55 // wxBitmapToggleButton::Create() with this style and we currently use a
56 // different wxWidgetImpl method (CreateBitmapToggleButton() rather than
57 // CreateToggleButton()) for creating bitmap buttons, but we really ought
58 // to unify the creation of buttons of all kinds and then remove
59 // this check
60 if ( style & wxBU_NOTEXT )
61 {
62 return wxControl::Create(parent, id, pos, size, style,
63 validator, name);
64 }
65
66 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
67 return false;
68
69 m_labelOrig = m_label = label ;
70
71 SetPeer(wxWidgetImpl::CreateToggleButton( this, parent, id, label, pos, size, style, GetExtraStyle() )) ;
72
73 MacPostControlCreate(pos,size) ;
74
75 return TRUE;
76 }
77
78 void wxToggleButton::SetValue(bool val)
79 {
80 GetPeer()->SetValue( val ) ;
81 }
82
83 bool wxToggleButton::GetValue() const
84 {
85 return GetPeer()->GetValue() ;
86 }
87
88 void wxToggleButton::Command(wxCommandEvent & event)
89 {
90 SetValue((event.GetInt() != 0));
91 ProcessCommand(event);
92 }
93
94 bool wxToggleButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
95 {
96 wxCommandEvent event(wxEVT_TOGGLEBUTTON, m_windowId);
97 event.SetInt(GetValue());
98 event.SetEventObject(this);
99 ProcessCommand(event);
100 return true ;
101 }
102
103 // ----------------------------------------------------------------------------
104 // wxBitmapToggleButton
105 // ----------------------------------------------------------------------------
106
107 IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxToggleButton)
108
109 bool wxBitmapToggleButton::Create(wxWindow *parent, wxWindowID id,
110 const wxBitmap& label,
111 const wxPoint& pos,
112 const wxSize& size, long style,
113 const wxValidator& validator,
114 const wxString& name)
115 {
116 DontCreatePeer();
117
118 if ( !wxToggleButton::Create(parent, id, wxEmptyString, pos, size, style | wxBU_NOTEXT | wxBU_EXACTFIT, validator, name) )
119 return false;
120
121 m_marginX =
122 m_marginY = wxDEFAULT_BUTTON_MARGIN;
123
124 m_bitmaps[State_Normal] = label;
125
126 SetPeer(wxWidgetImpl::CreateBitmapToggleButton( this, parent, id, label, pos, size, style, GetExtraStyle() ));
127
128 MacPostControlCreate(pos,size) ;
129
130 return TRUE;
131 }
132
133 #endif // wxUSE_TOGGLEBTN
134