]> git.saurik.com Git - wxWidgets.git/blob - src/osx/radiobut_osx.cpp
Update version to 2.9.4 in version.bkl too and rebake everything.
[wxWidgets.git] / src / osx / radiobut_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/radiobut.cpp
3 // Purpose: wxRadioButton
4 // Author: AUTHOR
5 // Modified by: JS Lair (99/11/15) adding the cyclic group notion for radiobox
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #if wxUSE_RADIOBTN
15
16 #include "wx/radiobut.h"
17 #include "wx/osx/private.h"
18
19 bool wxRadioButton::Create( wxWindow *parent,
20 wxWindowID id,
21 const wxString& label,
22 const wxPoint& pos,
23 const wxSize& size,
24 long style,
25 const wxValidator& validator,
26 const wxString& name )
27 {
28 DontCreatePeer();
29
30 if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
31 return false;
32
33 m_labelOrig = m_label = label;
34
35 SetPeer(wxWidgetImpl::CreateRadioButton( this, parent, id, label, pos, size, style, GetExtraStyle() ));
36
37 MacPostControlCreate( pos, size );
38
39 m_cycle = this;
40
41 if (HasFlag( wxRB_GROUP ))
42 {
43 AddInCycle( NULL );
44 }
45 else
46 {
47 // search backward for last group start
48 wxRadioButton *chief = NULL;
49 wxWindowList::compatibility_iterator node = parent->GetChildren().GetLast();
50 while (node)
51 {
52 wxWindow *child = node->GetData();
53 if (child->IsKindOf( CLASSINFO( wxRadioButton ) ))
54 {
55 chief = (wxRadioButton*)child;
56 if (child->HasFlag( wxRB_GROUP ))
57 break;
58 }
59
60 node = node->GetPrevious();
61 }
62
63 AddInCycle( chief );
64 }
65
66 return true;
67 }
68
69 wxRadioButton::~wxRadioButton()
70 {
71 RemoveFromCycle();
72 }
73
74 void wxRadioButton::SetValue(bool val)
75 {
76 wxRadioButton *cycle;
77 if (GetPeer()->GetValue() == val)
78 return;
79
80 GetPeer()->SetValue( val );
81 if (val)
82 {
83 cycle = this->NextInCycle();
84 if (cycle != NULL)
85 {
86 while (cycle != this)
87 {
88 cycle->SetValue( false );
89 cycle = cycle->NextInCycle();
90 }
91 }
92 }
93 }
94
95 bool wxRadioButton::GetValue() const
96 {
97 return GetPeer()->GetValue() != 0;
98 }
99
100 void wxRadioButton::Command(wxCommandEvent& event)
101 {
102 SetValue( (event.GetInt() != 0) );
103 ProcessCommand( event );
104 }
105
106 bool wxRadioButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
107 {
108 if ( !GetPeer()->ButtonClickDidStateChange() )
109 {
110 // if already set -> no action
111 if (GetValue())
112 return true;
113 }
114
115 wxRadioButton *cycle;
116 cycle = this->NextInCycle();
117 if (cycle != NULL)
118 {
119 while (cycle != this)
120 {
121 if (cycle->GetValue())
122 cycle->SetValue( false );
123
124 cycle = cycle->NextInCycle();
125 }
126 }
127
128 SetValue( true );
129
130 wxCommandEvent event2( wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
131 event2.SetEventObject( this );
132 event2.SetInt( true );
133 ProcessCommand( event2 );
134
135 return true;
136 }
137
138 wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle)
139 {
140 wxRadioButton *current;
141
142 if (cycle == NULL)
143 {
144 m_cycle = this;
145 }
146 else
147 {
148 current = cycle;
149 while (current->m_cycle != cycle)
150 current = current->m_cycle;
151
152 m_cycle = cycle;
153 current->m_cycle = this;
154 }
155
156 return m_cycle;
157 }
158
159 void wxRadioButton::RemoveFromCycle()
160 {
161 if ((m_cycle == NULL) || (m_cycle == this))
162 return;
163
164 // Find the previous one and make it point to the next one
165 wxRadioButton* prev = this;
166 while (prev->m_cycle != this)
167 prev = prev->m_cycle;
168
169 prev->m_cycle = m_cycle;
170 }
171
172 #endif