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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "radiobut.h"
16 #include "wx/wxprec.h"
20 #include "wx/radiobut.h"
22 #if !USE_SHARED_LIBRARY
23 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
26 #include "wx/mac/uma.h"
28 bool wxRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
29 const wxString
& label
,
31 const wxSize
& size
, long style
,
32 const wxValidator
& validator
,
35 m_macIsUserPane
= FALSE
;
37 if ( !wxControl::Create(parent
, id
, pos
, size
, style
, validator
, name
) )
42 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
44 m_peer
= new wxMacControl() ;
45 verify_noerr ( CreateRadioButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") ,
46 0 , false /* no autotoggle */ , m_peer
->GetControlRefAddr() ) );
49 MacPostControlCreate(pos
,size
) ;
53 if (HasFlag(wxRB_GROUP
))
59 /* search backward for last group start */
60 wxRadioButton
*chief
= (wxRadioButton
*) NULL
;
61 wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetLast();
64 wxWindow
*child
= node
->GetData();
65 if (child
->IsKindOf( CLASSINFO( wxRadioButton
) ) )
67 chief
= (wxRadioButton
*) child
;
68 if (child
->HasFlag(wxRB_GROUP
)) break;
70 node
= node
->GetPrevious();
77 void wxRadioButton::SetValue(bool val
)
80 if ( m_peer
->GetValue() == val
)
83 m_peer
->SetValue( val
) ;
86 cycle
=this->NextInCycle();
91 cycle
->SetValue(false);
92 cycle
=cycle
->NextInCycle();
98 bool wxRadioButton::GetValue() const
100 return m_peer
->GetValue() ;
103 void wxRadioButton::Command (wxCommandEvent
& event
)
105 SetValue ( (event
.GetInt() != 0) );
106 ProcessCommand (event
);
109 wxInt32
wxRadioButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
111 // if already set -> no action
115 wxRadioButton
*cycle
, *old
= NULL
;
116 cycle
=this->NextInCycle();
118 while (cycle
!=this) {
119 if ( cycle
->GetValue() ) {
121 cycle
->SetValue(false);
123 cycle
=cycle
->NextInCycle();
130 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, old
->m_windowId
);
131 event
.SetEventObject(old
);
132 event
.SetInt( false );
133 old
->ProcessCommand(event
);
135 wxCommandEvent
event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, m_windowId
);
136 event2
.SetEventObject(this);
137 event2
.SetInt( true );
138 ProcessCommand(event2
);
142 wxRadioButton
*wxRadioButton::AddInCycle(wxRadioButton
*cycle
)
144 wxRadioButton
*next
,*current
;
152 while ((next
=current
->m_cycle
)!=cycle
)
153 current
=current
->m_cycle
;
155 current
->m_cycle
=this;