]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/radiobut.cpp
corrected preproc condition
[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
e40298d5 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "radiobut.h"
14#endif
15
d8c736e5 16#include "wx/defs.h"
e9576ca5 17
d8c736e5 18#include "wx/radiobut.h"
079c842c 19
d8c736e5 20#if !USE_SHARED_LIBRARY
e9576ca5 21IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
d8c736e5 22#endif
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{
facd6764
SC
33 m_macIsUserPane = FALSE ;
34
b45ed7a2
VZ
35 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
36 return false;
e40298d5 37
facd6764
SC
38 m_label = label ;
39
40 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
e40298d5 41
4c37f124
SC
42 verify_noerr ( CreateRadioButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") ,
43 0 , false /* no autotoggle */ , (ControlRef*) &m_macControl ) ) ;
44
facd6764 45 MacPostControlCreate(pos,size) ;
e9576ca5 46
aa6c945b 47 m_cycle = this ;
c503ab84 48
0a67a93b
SC
49 if (HasFlag(wxRB_GROUP))
50 {
e40298d5 51 AddInCycle( NULL ) ;
0a67a93b
SC
52 }
53 else
54 {
55 /* search backward for last group start */
56 wxRadioButton *chief = (wxRadioButton*) NULL;
57 wxWindowList::Node *node = parent->GetChildren().GetLast();
58 while (node)
079c842c 59 {
0a67a93b
SC
60 wxWindow *child = node->GetData();
61 if (child->IsKindOf( CLASSINFO( wxRadioButton ) ) )
62 {
63 chief = (wxRadioButton*) child;
64 if (child->HasFlag(wxRB_GROUP)) break;
65 }
66 node = node->GetPrevious();
079c842c 67 }
0a67a93b
SC
68 AddInCycle( chief ) ;
69 }
70 return TRUE;
e9576ca5
SC
71}
72
1dd52151 73void wxRadioButton::SetValue(bool val)
e9576ca5 74{
e40298d5 75 wxRadioButton *cycle;
facd6764 76 if ( GetControl32BitValue( (ControlRef) m_macControl ) == val )
e40298d5
JS
77 return ;
78
facd6764 79 ::SetControl32BitValue( (ControlRef) m_macControl , val ) ;
2f1ae414
SC
80 if (val)
81 {
e40298d5
JS
82 cycle=this->NextInCycle();
83 if (cycle!=NULL) {
84 while (cycle!=this) {
85 cycle->SetValue(false);
86 cycle=cycle->NextInCycle();
87 }
88 }
89 }
73969f3f 90 MacRedrawControl() ;
e9576ca5
SC
91}
92
e9576ca5
SC
93bool wxRadioButton::GetValue() const
94{
facd6764 95 return ::GetControl32BitValue( (ControlRef) m_macControl ) ;
e9576ca5
SC
96}
97
98void wxRadioButton::Command (wxCommandEvent & event)
99{
1dd52151 100 SetValue ( (event.GetInt() != 0) );
e9576ca5
SC
101 ProcessCommand (event);
102}
103
4c37f124 104wxInt32 wxRadioButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
1dd52151 105{
4c37f124 106 // if already set -> no action
f0822896 107 if ( GetValue() )
4c37f124 108 return noErr;
f0822896 109
e40298d5 110 wxRadioButton *cycle, *old = NULL ;
f0822896
SC
111 cycle=this->NextInCycle();
112 if (cycle!=NULL) {
e40298d5
JS
113 while (cycle!=this) {
114 if ( cycle->GetValue() ) {
115 old = cycle ;
116 cycle->SetValue(false);
117 }
118 cycle=cycle->NextInCycle();
119 }
f0822896
SC
120 }
121
e40298d5 122 SetValue(true) ;
f0822896
SC
123
124 if ( old ) {
125 wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, old->m_windowId );
126 event.SetEventObject(old);
127 event.SetInt( false );
128 old->ProcessCommand(event);
129 }
130 wxCommandEvent event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
131 event2.SetEventObject(this);
132 event2.SetInt( true );
133 ProcessCommand(event2);
4c37f124 134 return noErr ;
1dd52151
UJ
135}
136
137wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle)
138{
e40298d5
JS
139 wxRadioButton *next,*current;
140
141 if (cycle==NULL) {
142 m_cycle=this;
143 return(this);
144 }
145 else {
146 current=cycle;
147 while ((next=current->m_cycle)!=cycle)
148 current=current->m_cycle;
149 m_cycle=cycle;
150 current->m_cycle=this;
151 return(cycle);
152 }
1dd52151 153}