]> git.saurik.com Git - wxWidgets.git/blame - src/mac/radiobut.cpp
Misc small mods
[wxWidgets.git] / src / mac / radiobut.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: radiobut.cpp
3// Purpose: wxRadioButton
4// Author: AUTHOR
1dd52151 5// Modified by: JS Lair (99/11/15) adding the cyclic groupe notion for radiobox
e9576ca5
SC
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
079c842c 18
e9576ca5 19IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
079c842c
RR
20
21BEGIN_EVENT_TABLE(wxRadioButton, wxControl)
22 EVT_IDLE( wxRadioButton::OnIdle )
23END_EVENT_TABLE()
e9576ca5 24
1dd52151
UJ
25#include <wx/mac/uma.h>
26
e9576ca5
SC
27bool 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{
1dd52151
UJ
34 Rect bounds ;
35 Str255 title ;
36
37 m_cycle=NULL;
38
39 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
e9576ca5 40
1dd52151
UJ
41 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 1,
42 kControlRadioButtonProc , (long) this ) ;
43
44 MacPostControlCreate() ;
e9576ca5 45
079c842c
RR
46 return TRUE;
47}
48
49void 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 );
e9576ca5
SC
93}
94
1dd52151 95void wxRadioButton::SetValue(bool val)
e9576ca5 96{
1dd52151
UJ
97 int i;
98 wxRadioButton *cycle;
99
100 ::SetControlValue( m_macControl , val ) ;
101
2f1ae414
SC
102 if (val)
103 {
1dd52151
UJ
104 cycle=this->NextInCycle();
105 if (cycle!=NULL) {
106 while (cycle!=this) {
107 cycle->SetValue(false);
108 cycle=cycle->NextInCycle();
109 }
110 }
111 }
e9576ca5
SC
112}
113
e9576ca5
SC
114bool wxRadioButton::GetValue() const
115{
1dd52151 116 return ::GetControlValue( m_macControl ) ;
e9576ca5
SC
117}
118
119void wxRadioButton::Command (wxCommandEvent & event)
120{
1dd52151 121 SetValue ( (event.GetInt() != 0) );
e9576ca5
SC
122 ProcessCommand (event);
123}
124
1dd52151
UJ
125void wxRadioButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
126{
127 SetValue(true) ;
8208e181
SC
128 wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
129 event.SetEventObject(this);
130 ProcessCommand(event);
1dd52151
UJ
131}
132
133wxRadioButton *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}