]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/radiobut.cpp
Set HTML data even in Unicode mode
[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#include "wx/wxprec.h"
e9576ca5 13
179e085f
RN
14#if wxUSE_RADIOBTN
15
d8c736e5 16#include "wx/radiobut.h"
079c842c 17
e9576ca5 18IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
079c842c 19
d497dca4 20#include "wx/mac/uma.h"
1dd52151 21
e9576ca5 22bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
e40298d5 23 const wxString& label,
e9576ca5
SC
24 const wxPoint& pos,
25 const wxSize& size, long style,
26 const wxValidator& validator,
27 const wxString& name)
28{
3dee36ae
WS
29 m_macIsUserPane = false ;
30
b45ed7a2
VZ
31 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
32 return false;
3dee36ae 33
facd6764
SC
34 m_label = label ;
35
36 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
3dee36ae 37
b905d6cc 38 m_peer = new wxMacControl(this) ;
3dee36ae 39 verify_noerr ( CreateRadioButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") ,
5ca0d812 40 0 , false /* no autotoggle */ , m_peer->GetControlRefAddr() ) );
3dee36ae 41
4c37f124 42
facd6764 43 MacPostControlCreate(pos,size) ;
e9576ca5 44
3dee36ae
WS
45 m_cycle = this ;
46
47 if (HasFlag(wxRB_GROUP))
079c842c 48 {
3dee36ae 49 AddInCycle( NULL ) ;
079c842c 50 }
3dee36ae
WS
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;
e9576ca5
SC
69}
70
992b3f1d
JS
71wxRadioButton::~wxRadioButton()
72{
73 RemoveFromCycle();
74}
75
1dd52151 76void wxRadioButton::SetValue(bool val)
e9576ca5 77{
e40298d5 78 wxRadioButton *cycle;
20b69855 79 if ( m_peer->GetValue() == val )
e40298d5 80 return ;
3dee36ae 81
20b69855 82 m_peer->SetValue( val ) ;
3dee36ae 83 if (val)
20b69855
SC
84 {
85 cycle=this->NextInCycle();
3dee36ae 86 if (cycle!=NULL)
20b69855 87 {
3dee36ae
WS
88 while (cycle!=this)
89 {
90 cycle->SetValue(false);
91 cycle=cycle->NextInCycle();
92 }
93 }
20b69855 94 }
e9576ca5
SC
95}
96
e9576ca5
SC
97bool wxRadioButton::GetValue() const
98{
5ca0d812 99 return m_peer->GetValue() ;
e9576ca5
SC
100}
101
102void wxRadioButton::Command (wxCommandEvent & event)
103{
1dd52151 104 SetValue ( (event.GetInt() != 0) );
e9576ca5
SC
105 ProcessCommand (event);
106}
107
3dee36ae 108wxInt32 wxRadioButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
1dd52151 109{
4c37f124 110 // if already set -> no action
f0822896 111 if ( GetValue() )
8028be3a 112 return noErr;
3dee36ae 113
8028be3a 114 wxRadioButton *cycle;
f0822896
SC
115 cycle=this->NextInCycle();
116 if (cycle!=NULL) {
8028be3a 117 while (cycle!=this) {
e40298d5 118 if ( cycle->GetValue() ) {
e40298d5 119 cycle->SetValue(false);
e40298d5 120 }
8028be3a
RD
121 cycle=cycle->NextInCycle();
122 }
f0822896
SC
123 }
124
8028be3a 125 SetValue(true) ;
f0822896 126
f0822896
SC
127 wxCommandEvent event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
128 event2.SetEventObject(this);
129 event2.SetInt( true );
130 ProcessCommand(event2);
4c37f124 131 return noErr ;
1dd52151
UJ
132}
133
134wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle)
135{
e40298d5 136 wxRadioButton *next,*current;
3dee36ae
WS
137
138 if (cycle==NULL)
139 {
e40298d5
JS
140 m_cycle=this;
141 return(this);
3dee36ae
WS
142 }
143 else
144 {
e40298d5 145 current=cycle;
3dee36ae 146 while ((next=current->m_cycle)!=cycle)
e40298d5 147 current=current->m_cycle;
3dee36ae
WS
148 m_cycle=cycle;
149 current->m_cycle=this;
150 return(cycle);
151 }
152}
179e085f 153
992b3f1d
JS
154void 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
179e085f 170#endif