]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/radiobut.cpp
A little clarification
[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{
b45ed7a2
VZ
33 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
34 return false;
35
e40298d5
JS
36 Rect bounds ;
37 Str255 title ;
38
39 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
e9576ca5 40
e40298d5
JS
41 m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1,
42 kControlRadioButtonProc , (long) this ) ;
43
44 MacPostControlCreate() ;
e9576ca5 45
aa6c945b 46 m_cycle = this ;
c503ab84 47
0a67a93b
SC
48 if (HasFlag(wxRB_GROUP))
49 {
e40298d5 50 AddInCycle( NULL ) ;
0a67a93b
SC
51 }
52 else
53 {
54 /* search backward for last group start */
55 wxRadioButton *chief = (wxRadioButton*) NULL;
56 wxWindowList::Node *node = parent->GetChildren().GetLast();
57 while (node)
079c842c 58 {
0a67a93b
SC
59 wxWindow *child = node->GetData();
60 if (child->IsKindOf( CLASSINFO( wxRadioButton ) ) )
61 {
62 chief = (wxRadioButton*) child;
63 if (child->HasFlag(wxRB_GROUP)) break;
64 }
65 node = node->GetPrevious();
079c842c 66 }
0a67a93b
SC
67 AddInCycle( chief ) ;
68 }
69 return TRUE;
e9576ca5
SC
70}
71
1dd52151 72void wxRadioButton::SetValue(bool val)
e9576ca5 73{
e40298d5
JS
74 wxRadioButton *cycle;
75 if ( GetControl32BitValue( (ControlHandle) m_macControl ) == val )
76 return ;
77
467e3168 78 ::SetControl32BitValue( (ControlHandle) m_macControl , val ) ;
2f1ae414
SC
79 if (val)
80 {
e40298d5
JS
81 cycle=this->NextInCycle();
82 if (cycle!=NULL) {
83 while (cycle!=this) {
84 cycle->SetValue(false);
85 cycle=cycle->NextInCycle();
86 }
87 }
88 }
73969f3f 89 MacRedrawControl() ;
e9576ca5
SC
90}
91
e9576ca5
SC
92bool wxRadioButton::GetValue() const
93{
467e3168 94 return ::GetControl32BitValue( (ControlHandle) m_macControl ) ;
e9576ca5
SC
95}
96
97void wxRadioButton::Command (wxCommandEvent & event)
98{
1dd52151 99 SetValue ( (event.GetInt() != 0) );
e9576ca5
SC
100 ProcessCommand (event);
101}
102
4b26b60f 103void wxRadioButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown))
1dd52151 104{
f0822896
SC
105 if ( GetValue() )
106 return ;
107
e40298d5 108 wxRadioButton *cycle, *old = NULL ;
f0822896
SC
109 cycle=this->NextInCycle();
110 if (cycle!=NULL) {
e40298d5
JS
111 while (cycle!=this) {
112 if ( cycle->GetValue() ) {
113 old = cycle ;
114 cycle->SetValue(false);
115 }
116 cycle=cycle->NextInCycle();
117 }
f0822896
SC
118 }
119
e40298d5 120 SetValue(true) ;
f0822896
SC
121
122 if ( old ) {
123 wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, old->m_windowId );
124 event.SetEventObject(old);
125 event.SetInt( false );
126 old->ProcessCommand(event);
127 }
128 wxCommandEvent event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
129 event2.SetEventObject(this);
130 event2.SetInt( true );
131 ProcessCommand(event2);
1dd52151
UJ
132}
133
134wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle)
135{
e40298d5
JS
136 wxRadioButton *next,*current;
137
138 if (cycle==NULL) {
139 m_cycle=this;
140 return(this);
141 }
142 else {
143 current=cycle;
144 while ((next=current->m_cycle)!=cycle)
145 current=current->m_cycle;
146 m_cycle=cycle;
147 current->m_cycle=this;
148 return(cycle);
149 }
1dd52151 150}