1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/radiobut.cpp
3 // Purpose: wxRadioButton
5 // Modified by: JS Lair (99/11/15) adding the cyclic group notion for radiobox
7 // Copyright: (c) AUTHOR
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
15 #include "wx/radiobut.h"
16 #include "wx/osx/private.h"
18 bool wxRadioButton::Create( wxWindow
*parent
,
20 const wxString
& label
,
24 const wxValidator
& validator
,
25 const wxString
& name
)
29 if ( !wxControl::Create( parent
, id
, pos
, size
, style
, validator
, name
) )
32 m_labelOrig
= m_label
= label
;
34 SetPeer(wxWidgetImpl::CreateRadioButton( this, parent
, id
, label
, pos
, size
, style
, GetExtraStyle() ));
36 MacPostControlCreate( pos
, size
);
40 if (HasFlag( wxRB_GROUP
))
46 // search backward for last group start
47 wxRadioButton
*chief
= NULL
;
48 wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetLast();
51 wxWindow
*child
= node
->GetData();
52 if (child
->IsKindOf( CLASSINFO( wxRadioButton
) ))
54 chief
= (wxRadioButton
*)child
;
55 if (child
->HasFlag( wxRB_GROUP
))
59 node
= node
->GetPrevious();
68 wxRadioButton::~wxRadioButton()
73 void wxRadioButton::SetValue(bool val
)
76 if (GetPeer()->GetValue() == val
)
79 GetPeer()->SetValue( val
);
82 cycle
= this->NextInCycle();
87 cycle
->SetValue( false );
88 cycle
= cycle
->NextInCycle();
94 bool wxRadioButton::GetValue() const
96 return GetPeer()->GetValue() != 0;
99 void wxRadioButton::Command(wxCommandEvent
& event
)
101 SetValue( (event
.GetInt() != 0) );
102 ProcessCommand( event
);
105 bool wxRadioButton::OSXHandleClicked( double WXUNUSED(timestampsec
) )
107 if ( !GetPeer()->ButtonClickDidStateChange() )
109 // if already set -> no action
114 wxRadioButton
*cycle
;
115 cycle
= this->NextInCycle();
118 while (cycle
!= this)
120 if (cycle
->GetValue())
121 cycle
->SetValue( false );
123 cycle
= cycle
->NextInCycle();
129 wxCommandEvent
event2( wxEVT_RADIOBUTTON
, m_windowId
);
130 event2
.SetEventObject( this );
131 event2
.SetInt( true );
132 ProcessCommand( event2
);
137 wxRadioButton
*wxRadioButton::AddInCycle(wxRadioButton
*cycle
)
139 wxRadioButton
*current
;
148 while (current
->m_cycle
!= cycle
)
149 current
= current
->m_cycle
;
152 current
->m_cycle
= this;
158 void wxRadioButton::RemoveFromCycle()
160 if ((m_cycle
== NULL
) || (m_cycle
== this))
163 // Find the previous one and make it point to the next one
164 wxRadioButton
* prev
= this;
165 while (prev
->m_cycle
!= this)
166 prev
= prev
->m_cycle
;
168 prev
->m_cycle
= m_cycle
;