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