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/mac/uma.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
) )
38 Rect bounds
= wxMacGetBoundsForControl( this, pos
, size
);
40 m_peer
= new wxMacControl( this );
41 OSStatus err
= CreateRadioButtonControl(
42 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds
, CFSTR(""),
43 0, false /* no autotoggle */, m_peer
->GetControlRefAddr() );
46 MacPostControlCreate( pos
, size
);
50 if (HasFlag( wxRB_GROUP
))
56 // search backward for last group start
57 wxRadioButton
*chief
= NULL
;
58 wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetLast();
61 wxWindow
*child
= node
->GetData();
62 if (child
->IsKindOf( CLASSINFO( wxRadioButton
) ))
64 chief
= (wxRadioButton
*)child
;
65 if (child
->HasFlag( wxRB_GROUP
))
69 node
= node
->GetPrevious();
78 wxRadioButton::~wxRadioButton()
83 void wxRadioButton::SetValue(bool val
)
86 if (m_peer
->GetValue() == val
)
89 m_peer
->SetValue( val
);
92 cycle
= this->NextInCycle();
97 cycle
->SetValue( false );
98 cycle
= cycle
->NextInCycle();
104 bool wxRadioButton::GetValue() const
106 return m_peer
->GetValue();
109 void wxRadioButton::Command(wxCommandEvent
& event
)
111 SetValue( (event
.GetInt() != 0) );
112 ProcessCommand( event
);
115 wxInt32
wxRadioButton::MacControlHit( WXEVENTHANDLERREF
WXUNUSED(handler
), WXEVENTREF
WXUNUSED(event
) )
117 // if already set -> no action
121 wxRadioButton
*cycle
;
122 cycle
= this->NextInCycle();
125 while (cycle
!= this)
127 if (cycle
->GetValue())
128 cycle
->SetValue( false );
130 cycle
= cycle
->NextInCycle();
136 wxCommandEvent
event2( wxEVT_COMMAND_RADIOBUTTON_SELECTED
, m_windowId
);
137 event2
.SetEventObject( this );
138 event2
.SetInt( true );
139 ProcessCommand( event2
);
144 wxRadioButton
*wxRadioButton::AddInCycle(wxRadioButton
*cycle
)
146 wxRadioButton
*current
;
155 while (current
->m_cycle
!= cycle
)
156 current
= current
->m_cycle
;
159 current
->m_cycle
= this;
165 void wxRadioButton::RemoveFromCycle()
167 if ((m_cycle
== NULL
) || (m_cycle
== this))
170 // Find the previous one and make it point to the next one
171 wxRadioButton
* prev
= this;
172 while (prev
->m_cycle
!= this)
173 prev
= prev
->m_cycle
;
175 prev
->m_cycle
= m_cycle
;