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"
18 #include "wx/radiobut.h"
20 #if !USE_SHARED_LIBRARY
21 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
24 #include "wx/mac/uma.h"
26 bool wxRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
27 const wxString
& label
,
29 const wxSize
& size
, long style
,
30 const wxValidator
& validator
,
36 MacPreControlCreate( parent
, id
, label
, pos
, size
,style
, validator
, name
, &bounds
, title
) ;
38 m_macControl
= ::NewControl( parent
->MacGetRootWindow() , &bounds
, title
, false , 0 , 0 , 1,
39 kControlRadioButtonProc
, (long) this ) ;
41 MacPostControlCreate() ;
45 if (HasFlag(wxRB_GROUP
))
51 /* search backward for last group start */
52 wxRadioButton
*chief
= (wxRadioButton
*) NULL
;
53 wxWindowList::Node
*node
= parent
->GetChildren().GetLast();
56 wxWindow
*child
= node
->GetData();
57 if (child
->IsKindOf( CLASSINFO( wxRadioButton
) ) )
59 chief
= (wxRadioButton
*) child
;
60 if (child
->HasFlag(wxRB_GROUP
)) break;
62 node
= node
->GetPrevious();
69 void wxRadioButton::SetValue(bool val
)
73 if ( GetControlValue( m_macControl
) == val
)
76 ::SetControlValue( m_macControl
, val
) ;
79 cycle
=this->NextInCycle();
82 cycle
->SetValue(false);
83 cycle
=cycle
->NextInCycle();
90 bool wxRadioButton::GetValue() const
92 return ::GetControlValue( m_macControl
) ;
95 void wxRadioButton::Command (wxCommandEvent
& event
)
97 SetValue ( (event
.GetInt() != 0) );
98 ProcessCommand (event
);
101 void wxRadioButton::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
106 wxRadioButton
*cycle
, *old
= NULL
;
107 cycle
=this->NextInCycle();
109 while (cycle
!=this) {
110 if ( cycle
->GetValue() ) {
112 cycle
->SetValue(false);
114 cycle
=cycle
->NextInCycle();
121 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, old
->m_windowId
);
122 event
.SetEventObject(old
);
123 event
.SetInt( false );
124 old
->ProcessCommand(event
);
126 wxCommandEvent
event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, m_windowId
);
127 event2
.SetEventObject(this);
128 event2
.SetInt( true );
129 ProcessCommand(event2
);
132 wxRadioButton
*wxRadioButton::AddInCycle(wxRadioButton
*cycle
)
134 wxRadioButton
*next
,*current
;
142 while ((next
=current
->m_cycle
)!=cycle
)
143 current
=current
->m_cycle
;
145 current
->m_cycle
=this;