1 /////////////////////////////////////////////////////////////////////////////
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 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
22 bool wxRadioButton::Create( wxWindow
*parent
,
24 const wxString
& label
,
28 const wxValidator
& validator
,
29 const wxString
& name
)
31 m_macIsUserPane
= false;
33 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
36 m_labelOrig
= m_label
= label
;
38 m_peer
= wxWidgetImpl::CreateRadioButton( this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() );
40 MacPostControlCreate( pos
, size
);
44 if (HasFlag( wxRB_GROUP
))
50 // search backward for last group start
51 wxRadioButton
*chief
= NULL
;
52 wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetLast();
55 wxWindow
*child
= node
->GetData();
56 if (child
->IsKindOf( CLASSINFO( wxRadioButton
) ))
58 chief
= (wxRadioButton
*)child
;
59 if (child
->HasFlag( wxRB_GROUP
))
63 node
= node
->GetPrevious();
72 wxRadioButton::~wxRadioButton()
77 void wxRadioButton::SetValue(bool val
)
80 if (m_peer
->GetValue() == val
)
83 m_peer
->SetValue( val
);
86 cycle
= this->NextInCycle();
91 cycle
->SetValue( false );
92 cycle
= cycle
->NextInCycle();
98 bool wxRadioButton::GetValue() const
100 return m_peer
->GetValue() != 0;
103 void wxRadioButton::Command(wxCommandEvent
& event
)
105 SetValue( (event
.GetInt() != 0) );
106 ProcessCommand( event
);
109 bool wxRadioButton::OSXHandleClicked( double WXUNUSED(timestampsec
) )
111 if ( !m_peer
->ButtonClickDidStateChange() )
113 // if already set -> no action
118 wxRadioButton
*cycle
;
119 cycle
= this->NextInCycle();
122 while (cycle
!= this)
124 if (cycle
->GetValue())
125 cycle
->SetValue( false );
127 cycle
= cycle
->NextInCycle();
133 wxCommandEvent
event2( wxEVT_COMMAND_RADIOBUTTON_SELECTED
, m_windowId
);
134 event2
.SetEventObject( this );
135 event2
.SetInt( true );
136 ProcessCommand( event2
);
141 wxRadioButton
*wxRadioButton::AddInCycle(wxRadioButton
*cycle
)
143 wxRadioButton
*current
;
152 while (current
->m_cycle
!= cycle
)
153 current
= current
->m_cycle
;
156 current
->m_cycle
= this;
162 void wxRadioButton::RemoveFromCycle()
164 if ((m_cycle
== NULL
) || (m_cycle
== this))
167 // Find the previous one and make it point to the next one
168 wxRadioButton
* prev
= this;
169 while (prev
->m_cycle
!= this)
170 prev
= prev
->m_cycle
;
172 prev
->m_cycle
= m_cycle
;