]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/radiobut.cpp
set error to GSOCK_TIMEOUT if the socket timed out (modified and extended patch 1303554)
[wxWidgets.git] / src / mac / carbon / 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 #include "wx/wxprec.h"
13
14 #if wxUSE_RADIOBTN
15
16 #include "wx/radiobut.h"
17
18 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
19
20 #include "wx/mac/uma.h"
21
22 bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
23 const wxString& label,
24 const wxPoint& pos,
25 const wxSize& size, long style,
26 const wxValidator& validator,
27 const wxString& name)
28 {
29 m_macIsUserPane = false ;
30
31 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
32 return false;
33
34 m_label = label ;
35
36 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
37
38 m_peer = new wxMacControl(this) ;
39 verify_noerr ( CreateRadioButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") ,
40 0 , false /* no autotoggle */ , m_peer->GetControlRefAddr() ) );
41
42
43 MacPostControlCreate(pos,size) ;
44
45 m_cycle = this ;
46
47 if (HasFlag(wxRB_GROUP))
48 {
49 AddInCycle( NULL ) ;
50 }
51 else
52 {
53 /* search backward for last group start */
54 wxRadioButton *chief = (wxRadioButton*) NULL;
55 wxWindowList::compatibility_iterator node = parent->GetChildren().GetLast();
56 while (node)
57 {
58 wxWindow *child = node->GetData();
59 if (child->IsKindOf( CLASSINFO( wxRadioButton ) ) )
60 {
61 chief = (wxRadioButton*) child;
62 if (child->HasFlag(wxRB_GROUP)) break;
63 }
64 node = node->GetPrevious();
65 }
66 AddInCycle( chief ) ;
67 }
68 return true;
69 }
70
71 wxRadioButton::~wxRadioButton()
72 {
73 RemoveFromCycle();
74 }
75
76 void wxRadioButton::SetValue(bool val)
77 {
78 wxRadioButton *cycle;
79 if ( m_peer->GetValue() == val )
80 return ;
81
82 m_peer->SetValue( val ) ;
83 if (val)
84 {
85 cycle=this->NextInCycle();
86 if (cycle!=NULL)
87 {
88 while (cycle!=this)
89 {
90 cycle->SetValue(false);
91 cycle=cycle->NextInCycle();
92 }
93 }
94 }
95 }
96
97 bool wxRadioButton::GetValue() const
98 {
99 return m_peer->GetValue() ;
100 }
101
102 void wxRadioButton::Command (wxCommandEvent & event)
103 {
104 SetValue ( (event.GetInt() != 0) );
105 ProcessCommand (event);
106 }
107
108 wxInt32 wxRadioButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
109 {
110 // if already set -> no action
111 if ( GetValue() )
112 return noErr;
113
114 wxRadioButton *cycle;
115 cycle=this->NextInCycle();
116 if (cycle!=NULL) {
117 while (cycle!=this) {
118 if ( cycle->GetValue() ) {
119 cycle->SetValue(false);
120 }
121 cycle=cycle->NextInCycle();
122 }
123 }
124
125 SetValue(true) ;
126
127 wxCommandEvent event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
128 event2.SetEventObject(this);
129 event2.SetInt( true );
130 ProcessCommand(event2);
131 return noErr ;
132 }
133
134 wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle)
135 {
136 wxRadioButton *next,*current;
137
138 if (cycle==NULL)
139 {
140 m_cycle=this;
141 return(this);
142 }
143 else
144 {
145 current=cycle;
146 while ((next=current->m_cycle)!=cycle)
147 current=current->m_cycle;
148 m_cycle=cycle;
149 current->m_cycle=this;
150 return(cycle);
151 }
152 }
153
154 void wxRadioButton::RemoveFromCycle()
155 {
156 if (m_cycle==NULL || m_cycle == this)
157 {
158 return;
159 }
160 else
161 {
162 // Find the previous one and make it point to the next one
163 wxRadioButton* prev = this;
164 while (prev->m_cycle != this)
165 prev = prev->m_cycle;
166 prev->m_cycle = m_cycle;
167 }
168 }
169
170 #endif