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"
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 m_peer
= new wxMacControl() ;
43 verify_noerr ( CreateRadioButtonControl( MAC_WXHWND(parent
->MacGetTopLevelWindowRef()) , &bounds
, CFSTR("") ,
44 0 , false /* no autotoggle */ , m_peer
->GetControlRefAddr() ) );
47 MacPostControlCreate(pos
,size
) ;
51 if (HasFlag(wxRB_GROUP
))
57 /* search backward for last group start */
58 wxRadioButton
*chief
= (wxRadioButton
*) NULL
;
59 wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetLast();
62 wxWindow
*child
= node
->GetData();
63 if (child
->IsKindOf( CLASSINFO( wxRadioButton
) ) )
65 chief
= (wxRadioButton
*) child
;
66 if (child
->HasFlag(wxRB_GROUP
)) break;
68 node
= node
->GetPrevious();
75 void wxRadioButton::SetValue(bool val
)
78 if ( m_peer
->GetValue() == val
)
81 m_peer
->SetValue( val
) ;
84 cycle
=this->NextInCycle();
87 cycle
->SetValue(false);
88 cycle
=cycle
->NextInCycle();
95 bool wxRadioButton::GetValue() const
97 return m_peer
->GetValue() ;
100 void wxRadioButton::Command (wxCommandEvent
& event
)
102 SetValue ( (event
.GetInt() != 0) );
103 ProcessCommand (event
);
106 wxInt32
wxRadioButton::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
108 // if already set -> no action
112 wxRadioButton
*cycle
, *old
= NULL
;
113 cycle
=this->NextInCycle();
115 while (cycle
!=this) {
116 if ( cycle
->GetValue() ) {
118 cycle
->SetValue(false);
120 cycle
=cycle
->NextInCycle();
127 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, old
->m_windowId
);
128 event
.SetEventObject(old
);
129 event
.SetInt( false );
130 old
->ProcessCommand(event
);
132 wxCommandEvent
event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, m_windowId
);
133 event2
.SetEventObject(this);
134 event2
.SetInt( true );
135 ProcessCommand(event2
);
139 wxRadioButton
*wxRadioButton::AddInCycle(wxRadioButton
*cycle
)
141 wxRadioButton
*next
,*current
;
149 while ((next
=current
->m_cycle
)!=cycle
)
150 current
=current
->m_cycle
;
152 current
->m_cycle
=this;