]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/radiobut.cpp
moving native format generation into bitmap ref data because of the owner semantics...
[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
65571936 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
d8c736e5 22#if !USE_SHARED_LIBRARY
e9576ca5 23IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
d8c736e5 24#endif
079c842c 25
d497dca4 26#include "wx/mac/uma.h"
1dd52151 27
e9576ca5 28bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
e40298d5 29 const wxString& label,
e9576ca5
SC
30 const wxPoint& pos,
31 const wxSize& size, long style,
32 const wxValidator& validator,
33 const wxString& name)
34{
facd6764
SC
35 m_macIsUserPane = FALSE ;
36
b45ed7a2
VZ
37 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
38 return false;
e40298d5 39
facd6764
SC
40 m_label = label ;
41
42 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
e40298d5 43
21fd5529 44 m_peer = new wxMacControl() ;
4c37f124 45 verify_noerr ( CreateRadioButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") ,
5ca0d812 46 0 , false /* no autotoggle */ , m_peer->GetControlRefAddr() ) );
21fd5529 47
4c37f124 48
facd6764 49 MacPostControlCreate(pos,size) ;
e9576ca5 50
aa6c945b 51 m_cycle = this ;
c503ab84 52
0a67a93b
SC
53 if (HasFlag(wxRB_GROUP))
54 {
e40298d5 55 AddInCycle( NULL ) ;
0a67a93b
SC
56 }
57 else
58 {
59 /* search backward for last group start */
60 wxRadioButton *chief = (wxRadioButton*) NULL;
affd2611 61 wxWindowList::compatibility_iterator node = parent->GetChildren().GetLast();
0a67a93b 62 while (node)
079c842c 63 {
0a67a93b
SC
64 wxWindow *child = node->GetData();
65 if (child->IsKindOf( CLASSINFO( wxRadioButton ) ) )
66 {
67 chief = (wxRadioButton*) child;
68 if (child->HasFlag(wxRB_GROUP)) break;
69 }
70 node = node->GetPrevious();
079c842c 71 }
0a67a93b
SC
72 AddInCycle( chief ) ;
73 }
74 return TRUE;
e9576ca5
SC
75}
76
1dd52151 77void wxRadioButton::SetValue(bool val)
e9576ca5 78{
e40298d5 79 wxRadioButton *cycle;
20b69855 80 if ( m_peer->GetValue() == val )
e40298d5
JS
81 return ;
82
20b69855
SC
83 m_peer->SetValue( val ) ;
84 if (val)
85 {
86 cycle=this->NextInCycle();
87 if (cycle!=NULL)
88 {
89 while (cycle!=this)
90 {
91 cycle->SetValue(false);
92 cycle=cycle->NextInCycle();
e40298d5 93 }
20b69855
SC
94 }
95 }
e9576ca5
SC
96}
97
e9576ca5
SC
98bool wxRadioButton::GetValue() const
99{
5ca0d812 100 return m_peer->GetValue() ;
e9576ca5
SC
101}
102
103void wxRadioButton::Command (wxCommandEvent & event)
104{
1dd52151 105 SetValue ( (event.GetInt() != 0) );
e9576ca5
SC
106 ProcessCommand (event);
107}
108
4c37f124 109wxInt32 wxRadioButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
1dd52151 110{
4c37f124 111 // if already set -> no action
f0822896 112 if ( GetValue() )
4c37f124 113 return noErr;
f0822896 114
e40298d5 115 wxRadioButton *cycle, *old = NULL ;
f0822896
SC
116 cycle=this->NextInCycle();
117 if (cycle!=NULL) {
e40298d5
JS
118 while (cycle!=this) {
119 if ( cycle->GetValue() ) {
120 old = cycle ;
121 cycle->SetValue(false);
122 }
123 cycle=cycle->NextInCycle();
124 }
f0822896
SC
125 }
126
e40298d5 127 SetValue(true) ;
f0822896
SC
128
129 if ( old ) {
130 wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, old->m_windowId );
131 event.SetEventObject(old);
132 event.SetInt( false );
133 old->ProcessCommand(event);
134 }
135 wxCommandEvent event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
136 event2.SetEventObject(this);
137 event2.SetInt( true );
138 ProcessCommand(event2);
4c37f124 139 return noErr ;
1dd52151
UJ
140}
141
142wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle)
143{
e40298d5
JS
144 wxRadioButton *next,*current;
145
146 if (cycle==NULL) {
147 m_cycle=this;
148 return(this);
149 }
150 else {
151 current=cycle;
152 while ((next=current->m_cycle)!=cycle)
153 current=current->m_cycle;
154 m_cycle=cycle;
155 current->m_cycle=this;
156 return(cycle);
157 }
1dd52151 158}
179e085f
RN
159
160#endif