]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/radiobut.cpp
respect styles during creation as well
[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
1dd52151 75void wxRadioButton::SetValue(bool val)
e9576ca5 76{
e40298d5 77 wxRadioButton *cycle;
20b69855 78 if ( m_peer->GetValue() == val )
e40298d5 79 return ;
3dee36ae 80
20b69855 81 m_peer->SetValue( val ) ;
3dee36ae 82 if (val)
20b69855
SC
83 {
84 cycle=this->NextInCycle();
3dee36ae 85 if (cycle!=NULL)
20b69855 86 {
3dee36ae
WS
87 while (cycle!=this)
88 {
89 cycle->SetValue(false);
90 cycle=cycle->NextInCycle();
91 }
92 }
20b69855 93 }
e9576ca5
SC
94}
95
e9576ca5
SC
96bool wxRadioButton::GetValue() const
97{
5ca0d812 98 return m_peer->GetValue() ;
e9576ca5
SC
99}
100
101void wxRadioButton::Command (wxCommandEvent & event)
102{
1dd52151 103 SetValue ( (event.GetInt() != 0) );
e9576ca5
SC
104 ProcessCommand (event);
105}
106
3dee36ae 107wxInt32 wxRadioButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
1dd52151 108{
4c37f124 109 // if already set -> no action
f0822896 110 if ( GetValue() )
8028be3a 111 return noErr;
3dee36ae 112
8028be3a 113 wxRadioButton *cycle;
f0822896
SC
114 cycle=this->NextInCycle();
115 if (cycle!=NULL) {
8028be3a 116 while (cycle!=this) {
e40298d5 117 if ( cycle->GetValue() ) {
e40298d5 118 cycle->SetValue(false);
e40298d5 119 }
8028be3a
RD
120 cycle=cycle->NextInCycle();
121 }
f0822896
SC
122 }
123
8028be3a 124 SetValue(true) ;
f0822896 125
f0822896
SC
126 wxCommandEvent event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
127 event2.SetEventObject(this);
128 event2.SetInt( true );
129 ProcessCommand(event2);
4c37f124 130 return noErr ;
1dd52151
UJ
131}
132
133wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle)
134{
e40298d5 135 wxRadioButton *next,*current;
3dee36ae
WS
136
137 if (cycle==NULL)
138 {
e40298d5
JS
139 m_cycle=this;
140 return(this);
3dee36ae
WS
141 }
142 else
143 {
e40298d5 144 current=cycle;
3dee36ae 145 while ((next=current->m_cycle)!=cycle)
e40298d5 146 current=current->m_cycle;
3dee36ae
WS
147 m_cycle=cycle;
148 current->m_cycle=this;
149 return(cycle);
150 }
151}
179e085f
RN
152
153#endif