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
,
33 m_macIsUserPane
= FALSE
;
35 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
40 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
42 verify_noerr ( CreateRadioButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") ,
43 0 , false /* no autotoggle */ , (ControlRef
*) &m_macControl
) ) ;
45 MacPostControlCreate(pos
,size
) ;
49 if (HasFlag(wxRB_GROUP
))
55 /* search backward for last group start */
56 wxRadioButton
*chief
= (wxRadioButton
*) NULL
;
57 wxWindowList::Node
*node
= parent
->GetChildren().GetLast();
60 wxWindow
*child
= node
->GetData();
61 if (child
->IsKindOf( CLASSINFO( wxRadioButton
) ) )
63 chief
= (wxRadioButton
*) child
;
64 if (child
->HasFlag(wxRB_GROUP
)) break;
66 node
= node
->GetPrevious();
73 void wxRadioButton::SetValue(bool val
)
76 if ( GetControl32BitValue( (ControlRef
) m_macControl
) == val
)
79 ::SetControl32BitValue( (ControlRef
) m_macControl
, val
) ;
82 cycle
=this->NextInCycle();
85 cycle
->SetValue(false);
86 cycle
=cycle
->NextInCycle();
93 bool wxRadioButton::GetValue() const
95 return ::GetControl32BitValue( (ControlRef
) m_macControl
) ;
98 void wxRadioButton::Command (wxCommandEvent
& event
)
100 SetValue ( (event
.GetInt() != 0) );
101 ProcessCommand (event
);
104 wxInt32
wxRadioButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
106 // if already set -> no action
110 wxRadioButton
*cycle
, *old
= NULL
;
111 cycle
=this->NextInCycle();
113 while (cycle
!=this) {
114 if ( cycle
->GetValue() ) {
116 cycle
->SetValue(false);
118 cycle
=cycle
->NextInCycle();
125 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, old
->m_windowId
);
126 event
.SetEventObject(old
);
127 event
.SetInt( false );
128 old
->ProcessCommand(event
);
130 wxCommandEvent
event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, m_windowId
);
131 event2
.SetEventObject(this);
132 event2
.SetInt( true );
133 ProcessCommand(event2
);
137 wxRadioButton
*wxRadioButton::AddInCycle(wxRadioButton
*cycle
)
139 wxRadioButton
*next
,*current
;
147 while ((next
=current
->m_cycle
)!=cycle
)
148 current
=current
->m_cycle
;
150 current
->m_cycle
=this;