]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/radiobut.cpp
Fix GetNextItem for virtual wxListCtrl, and improve behavior for wxLIST_NEXT_ALL.
[wxWidgets.git] / src / mac / carbon / radiobut.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: radiobut.cpp
3// Purpose: wxRadioButton
4// Author: AUTHOR
43524b15 5// Modified by: JS Lair (99/11/15) adding the cyclic group notion for radiobox
e9576ca5
SC
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
3dee36ae 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878 12#include "wx/wxprec.h"
e9576ca5 13
179e085f
RN
14#if wxUSE_RADIOBTN
15
d8c736e5 16#include "wx/radiobut.h"
43524b15 17#include "wx/mac/uma.h"
079c842c 18
e9576ca5 19IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
079c842c 20
1dd52151 21
43524b15
DS
22bool wxRadioButton::Create( wxWindow *parent,
23 wxWindowID id,
24 const wxString& label,
25 const wxPoint& pos,
26 const wxSize& size,
27 long style,
28 const wxValidator& validator,
29 const wxString& name )
e9576ca5 30{
43524b15 31 m_macIsUserPane = false;
3dee36ae 32
43524b15 33 if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
b45ed7a2 34 return false;
3dee36ae 35
43524b15 36 m_label = label;
3dee36ae 37
43524b15 38 Rect bounds = wxMacGetBoundsForControl( this, pos, size );
3dee36ae 39
43524b15
DS
40 m_peer = new wxMacControl( this );
41 OSStatus err = CreateRadioButtonControl(
42 MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, CFSTR(""),
43 0, false /* no autotoggle */, m_peer->GetControlRefAddr() );
44 verify_noerr( err );
4c37f124 45
43524b15 46 MacPostControlCreate( pos, size );
e9576ca5 47
43524b15 48 m_cycle = this;
3dee36ae 49
43524b15 50 if (HasFlag( wxRB_GROUP ))
079c842c 51 {
43524b15 52 AddInCycle( NULL );
079c842c 53 }
3dee36ae
WS
54 else
55 {
43524b15
DS
56 // search backward for last group start
57 wxRadioButton *chief = NULL;
3dee36ae
WS
58 wxWindowList::compatibility_iterator node = parent->GetChildren().GetLast();
59 while (node)
60 {
61 wxWindow *child = node->GetData();
43524b15 62 if (child->IsKindOf( CLASSINFO( wxRadioButton ) ))
3dee36ae 63 {
43524b15
DS
64 chief = (wxRadioButton*)child;
65 if (child->HasFlag( wxRB_GROUP ))
66 break;
3dee36ae 67 }
43524b15 68
3dee36ae
WS
69 node = node->GetPrevious();
70 }
43524b15
DS
71
72 AddInCycle( chief );
3dee36ae 73 }
43524b15 74
3dee36ae 75 return true;
e9576ca5
SC
76}
77
992b3f1d
JS
78wxRadioButton::~wxRadioButton()
79{
80 RemoveFromCycle();
81}
82
1dd52151 83void wxRadioButton::SetValue(bool val)
e9576ca5 84{
e40298d5 85 wxRadioButton *cycle;
43524b15
DS
86 if (m_peer->GetValue() == val)
87 return;
3dee36ae 88
43524b15 89 m_peer->SetValue( val );
3dee36ae 90 if (val)
20b69855 91 {
43524b15
DS
92 cycle = this->NextInCycle();
93 if (cycle != NULL)
20b69855 94 {
43524b15 95 while (cycle != this)
3dee36ae 96 {
43524b15
DS
97 cycle->SetValue( false );
98 cycle = cycle->NextInCycle();
3dee36ae
WS
99 }
100 }
20b69855 101 }
e9576ca5
SC
102}
103
e9576ca5
SC
104bool wxRadioButton::GetValue() const
105{
43524b15 106 return m_peer->GetValue();
e9576ca5
SC
107}
108
43524b15 109void wxRadioButton::Command(wxCommandEvent& event)
e9576ca5 110{
43524b15
DS
111 SetValue( (event.GetInt() != 0) );
112 ProcessCommand( event );
e9576ca5
SC
113}
114
43524b15 115wxInt32 wxRadioButton::MacControlHit( WXEVENTHANDLERREF WXUNUSED(handler), WXEVENTREF WXUNUSED(event) )
1dd52151 116{
4c37f124 117 // if already set -> no action
43524b15 118 if (GetValue())
8028be3a 119 return noErr;
3dee36ae 120
8028be3a 121 wxRadioButton *cycle;
43524b15
DS
122 cycle = this->NextInCycle();
123 if (cycle != NULL)
124 {
125 while (cycle != this)
126 {
127 if (cycle->GetValue())
128 cycle->SetValue( false );
129
130 cycle = cycle->NextInCycle();
8028be3a 131 }
f0822896
SC
132 }
133
43524b15 134 SetValue( true );
f0822896 135
43524b15
DS
136 wxCommandEvent event2( wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
137 event2.SetEventObject( this );
f0822896 138 event2.SetInt( true );
43524b15
DS
139 ProcessCommand( event2 );
140
141 return noErr;
1dd52151
UJ
142}
143
144wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle)
145{
716d0327 146 wxRadioButton *current;
3dee36ae 147
43524b15 148 if (cycle == NULL)
3dee36ae 149 {
43524b15 150 m_cycle = this;
3dee36ae
WS
151 }
152 else
153 {
43524b15 154 current = cycle;
716d0327 155 while (current->m_cycle != cycle)
43524b15
DS
156 current = current->m_cycle;
157
158 m_cycle = cycle;
159 current->m_cycle = this;
3dee36ae 160 }
43524b15
DS
161
162 return m_cycle;
3dee36ae 163}
179e085f 164
992b3f1d
JS
165void wxRadioButton::RemoveFromCycle()
166{
43524b15 167 if ((m_cycle == NULL) || (m_cycle == this))
992b3f1d 168 return;
43524b15
DS
169
170 // Find the previous one and make it point to the next one
171 wxRadioButton* prev = this;
172 while (prev->m_cycle != this)
173 prev = prev->m_cycle;
174
175 prev->m_cycle = m_cycle;
992b3f1d
JS
176}
177
179e085f 178#endif