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