]> git.saurik.com Git - wxWidgets.git/blob - src/mac/radiobut.cpp
Fixed HandleMouseWheel to be __WIN32__ sensitive
[wxWidgets.git] / src / mac / radiobut.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: radiobut.cpp
3 // Purpose: wxRadioButton
4 // Author: AUTHOR
5 // Modified by: JS Lair (99/11/15) adding the cyclic groupe notion for radiobox
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "radiobut.h"
14 #endif
15
16 #include "wx/radiobut.h"
17
18
19 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
20
21 BEGIN_EVENT_TABLE(wxRadioButton, wxControl)
22 EVT_IDLE( wxRadioButton::OnIdle )
23 END_EVENT_TABLE()
24
25 #include <wx/mac/uma.h>
26
27 bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
28 const wxString& label,
29 const wxPoint& pos,
30 const wxSize& size, long style,
31 const wxValidator& validator,
32 const wxString& name)
33 {
34 Rect bounds ;
35 Str255 title ;
36
37 m_cycle=NULL;
38
39 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
40
41 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 1,
42 kControlRadioButtonProc , (long) this ) ;
43
44 MacPostControlCreate() ;
45
46 return TRUE;
47 }
48
49 void wxRadioButton::OnIdle( wxIdleEvent &event )
50 {
51 if (!m_cycle && HasFlag(wxRB_GROUP))
52 {
53 // we are a stand-alone radiobutton and have
54 // the group flag indicating we have to collect
55 // the other radiobuttons belonging to this one
56
57 bool reached_this = FALSE;
58 wxRadioButton *m_radioButtonCycle = NULL;
59 m_radioButtonCycle = AddInCycle( m_radioButtonCycle );
60
61 wxWindow *parent = GetParent();
62 wxNode *node = parent->GetChildren().First();
63 while (node)
64 {
65 wxWindow *child = (wxWindow*) node->Data();
66
67 node = node->Next();
68
69 // start searching behind current radiobutton
70 if (!reached_this)
71 {
72 reached_this = (this == child);
73 continue;
74 }
75
76 if (child->IsKindOf( CLASSINFO ( wxRadioButton ) ))
77 {
78 wxRadioButton *rb = (wxRadioButton*) child;
79
80 // already reached next group
81 if (rb->HasFlag(wxRB_GROUP)) break;
82
83 // part of a radiobox
84 if (rb->NextInCycle()) break;
85
86 m_radioButtonCycle = rb->AddInCycle( m_radioButtonCycle );
87 }
88 }
89
90 }
91
92 event.Skip( TRUE );
93 }
94
95 void wxRadioButton::SetValue(bool val)
96 {
97 int i;
98 wxRadioButton *cycle;
99
100 ::SetControlValue( m_macControl , val ) ;
101
102 if (val)
103 {
104 cycle=this->NextInCycle();
105 if (cycle!=NULL) {
106 while (cycle!=this) {
107 cycle->SetValue(false);
108 cycle=cycle->NextInCycle();
109 }
110 }
111 }
112 }
113
114 bool wxRadioButton::GetValue() const
115 {
116 return ::GetControlValue( m_macControl ) ;
117 }
118
119 void wxRadioButton::Command (wxCommandEvent & event)
120 {
121 SetValue ( (event.GetInt() != 0) );
122 ProcessCommand (event);
123 }
124
125 void wxRadioButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
126 {
127 SetValue(true) ;
128 wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
129 event.SetEventObject(this);
130 ProcessCommand(event);
131 }
132
133 wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle)
134 {
135 wxRadioButton *next,*current;
136
137 if (cycle==NULL) {
138 m_cycle=this;
139 return(this);
140 }
141 else {
142 current=cycle;
143 while ((next=current->m_cycle)!=cycle) current=current->m_cycle;
144 m_cycle=cycle;
145 current->m_cycle=this;
146 return(cycle);
147 }
148 }