1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/radiobut.cpp
3 // Purpose: wxRadioButton
5 // Modified by: JS Lair (99/11/15) adding the cyclic group notion for radiobox
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/radiobut.h"
17 #include "wx/osx/private.h"
19 bool wxRadioButton::Create( wxWindow
*parent
,
21 const wxString
& label
,
25 const wxValidator
& validator
,
26 const wxString
& name
)
30 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
33 m_labelOrig
= m_label
= label
;
35 SetPeer(wxWidgetImpl::CreateRadioButton( this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() ));
37 MacPostControlCreate( pos
, size
);
41 if (HasFlag( wxRB_GROUP
))
47 // search backward for last group start
48 wxRadioButton
*chief
= NULL
;
49 wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetLast();
52 wxWindow
*child
= node
->GetData();
53 if (child
->IsKindOf( CLASSINFO( wxRadioButton
) ))
55 chief
= (wxRadioButton
*)child
;
56 if (child
->HasFlag( wxRB_GROUP
))
60 node
= node
->GetPrevious();
69 wxRadioButton::~wxRadioButton()
74 void wxRadioButton::SetValue(bool val
)
77 if (GetPeer()->GetValue() == val
)
80 GetPeer()->SetValue( val
);
83 cycle
= this->NextInCycle();
88 cycle
->SetValue( false );
89 cycle
= cycle
->NextInCycle();
95 bool wxRadioButton::GetValue() const
97 return GetPeer()->GetValue() != 0;
100 void wxRadioButton::Command(wxCommandEvent
& event
)
102 SetValue( (event
.GetInt() != 0) );
103 ProcessCommand( event
);
106 bool wxRadioButton::OSXHandleClicked( double WXUNUSED(timestampsec
) )
108 if ( !GetPeer()->ButtonClickDidStateChange() )
110 // if already set -> no action
115 wxRadioButton
*cycle
;
116 cycle
= this->NextInCycle();
119 while (cycle
!= this)
121 if (cycle
->GetValue())
122 cycle
->SetValue( false );
124 cycle
= cycle
->NextInCycle();
130 wxCommandEvent
event2( wxEVT_COMMAND_RADIOBUTTON_SELECTED
, m_windowId
);
131 event2
.SetEventObject( this );
132 event2
.SetInt( true );
133 ProcessCommand( event2
);
138 wxRadioButton
*wxRadioButton::AddInCycle(wxRadioButton
*cycle
)
140 wxRadioButton
*current
;
149 while (current
->m_cycle
!= cycle
)
150 current
= current
->m_cycle
;
153 current
->m_cycle
= this;
159 void wxRadioButton::RemoveFromCycle()
161 if ((m_cycle
== NULL
) || (m_cycle
== this))
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
;
169 prev
->m_cycle
= m_cycle
;