1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxRadioButton
5 // Modified by: JS Lair (99/11/15) adding the cyclic groupe notion for radiobox
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "radiobut.h"
16 #include "wx/radiobut.h"
19 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
21 BEGIN_EVENT_TABLE(wxRadioButton
, wxControl
)
22 EVT_IDLE( wxRadioButton::OnIdle
)
25 #include <wx/mac/uma.h>
27 bool wxRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
28 const wxString
& label
,
30 const wxSize
& size
, long style
,
31 const wxValidator
& validator
,
39 MacPreControlCreate( parent
, id
, label
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
41 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, title
, true , 0 , 0 , 1,
42 kControlRadioButtonProc
, (long) this ) ;
44 MacPostControlCreate() ;
49 void wxRadioButton::OnIdle( wxIdleEvent
&event
)
51 if (!m_cycle
&& HasFlag(wxRB_GROUP
))
53 // we are a stand-alone radiobutton and have
54 // the group flag indicating we have to collect
55 // the other radiobuttons belonging to this one
57 bool reached_this
= FALSE
;
58 wxRadioButton
*m_radioButtonCycle
= NULL
;
59 m_radioButtonCycle
= AddInCycle( m_radioButtonCycle
);
61 wxWindow
*parent
= GetParent();
62 wxNode
*node
= parent
->GetChildren().First();
65 wxWindow
*child
= (wxWindow
*) node
->Data();
69 // start searching behind current radiobutton
72 reached_this
= (this == child
);
76 if (child
->IsKindOf( CLASSINFO ( wxRadioButton
) ))
78 wxRadioButton
*rb
= (wxRadioButton
*) child
;
80 // already reached next group
81 if (rb
->HasFlag(wxRB_GROUP
)) break;
84 if (rb
->NextInCycle()) break;
86 m_radioButtonCycle
= rb
->AddInCycle( m_radioButtonCycle
);
95 void wxRadioButton::SetValue(bool val
)
100 ::SetControlValue( m_macControl
, val
) ;
104 cycle
=this->NextInCycle();
106 while (cycle
!=this) {
107 cycle
->SetValue(false);
108 cycle
=cycle
->NextInCycle();
114 bool wxRadioButton::GetValue() const
116 return ::GetControlValue( m_macControl
) ;
119 void wxRadioButton::Command (wxCommandEvent
& event
)
121 SetValue ( (event
.GetInt() != 0) );
122 ProcessCommand (event
);
125 void wxRadioButton::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
128 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, m_windowId
);
129 event
.SetEventObject(this);
130 ProcessCommand(event
);
133 wxRadioButton
*wxRadioButton::AddInCycle(wxRadioButton
*cycle
)
135 wxRadioButton
*next
,*current
;
143 while ((next
=current
->m_cycle
)!=cycle
) current
=current
->m_cycle
;
145 current
->m_cycle
=this;