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 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/radiobut.h"
18 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
20 #include "wx/mac/uma.h"
22 bool wxRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
23 const wxString
& label
,
25 const wxSize
& size
, long style
,
26 const wxValidator
& validator
,
29 m_macIsUserPane
= false ;
31 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
36 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
38 m_peer
= new wxMacControl(this) ;
39 verify_noerr ( CreateRadioButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") ,
40 0 , false /* no autotoggle */ , m_peer
->GetControlRefAddr() ) );
43 MacPostControlCreate(pos
,size
) ;
47 if (HasFlag(wxRB_GROUP
))
53 /* search backward for last group start */
54 wxRadioButton
*chief
= (wxRadioButton
*) NULL
;
55 wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetLast();
58 wxWindow
*child
= node
->GetData();
59 if (child
->IsKindOf( CLASSINFO( wxRadioButton
) ) )
61 chief
= (wxRadioButton
*) child
;
62 if (child
->HasFlag(wxRB_GROUP
)) break;
64 node
= node
->GetPrevious();
71 wxRadioButton::~wxRadioButton()
76 void wxRadioButton::SetValue(bool val
)
79 if ( m_peer
->GetValue() == val
)
82 m_peer
->SetValue( val
) ;
85 cycle
=this->NextInCycle();
90 cycle
->SetValue(false);
91 cycle
=cycle
->NextInCycle();
97 bool wxRadioButton::GetValue() const
99 return m_peer
->GetValue() ;
102 void wxRadioButton::Command (wxCommandEvent
& event
)
104 SetValue ( (event
.GetInt() != 0) );
105 ProcessCommand (event
);
108 wxInt32
wxRadioButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
110 // if already set -> no action
114 wxRadioButton
*cycle
;
115 cycle
=this->NextInCycle();
117 while (cycle
!=this) {
118 if ( cycle
->GetValue() ) {
119 cycle
->SetValue(false);
121 cycle
=cycle
->NextInCycle();
127 wxCommandEvent
event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, m_windowId
);
128 event2
.SetEventObject(this);
129 event2
.SetInt( true );
130 ProcessCommand(event2
);
134 wxRadioButton
*wxRadioButton::AddInCycle(wxRadioButton
*cycle
)
136 wxRadioButton
*next
,*current
;
146 while ((next
=current
->m_cycle
)!=cycle
)
147 current
=current
->m_cycle
;
149 current
->m_cycle
=this;
154 void wxRadioButton::RemoveFromCycle()
156 if (m_cycle
==NULL
|| m_cycle
== this)
162 // Find the previous one and make it point to the next one
163 wxRadioButton
* prev
= this;
164 while (prev
->m_cycle
!= this)
165 prev
= prev
->m_cycle
;
166 prev
->m_cycle
= m_cycle
;