]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/radiobut.cpp
fixing a scope error introduced in 1.41
[wxWidgets.git] / src / mac / classic / radiobut.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: radiobut.cpp
3 // Purpose: wxRadioButton
4 // Author: AUTHOR
5 // Modified by: JS Lair (99/11/15) adding the cyclic groupe notion for radiobox
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/defs.h"
13
14 #include "wx/radiobut.h"
15
16 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
17
18 #include "wx/mac/uma.h"
19
20 bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
21 const wxString& label,
22 const wxPoint& pos,
23 const wxSize& size, long style,
24 const wxValidator& validator,
25 const wxString& name)
26 {
27 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
28 return false;
29
30 Rect bounds ;
31 Str255 title ;
32
33 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
34
35 m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1,
36 kControlRadioButtonProc , (long) this ) ;
37
38 MacPostControlCreate() ;
39
40 m_cycle = this ;
41
42 if (HasFlag(wxRB_GROUP))
43 {
44 AddInCycle( NULL ) ;
45 }
46 else
47 {
48 /* search backward for last group start */
49 wxRadioButton *chief = (wxRadioButton*) NULL;
50 wxWindowList::Node *node = parent->GetChildren().GetLast();
51 while (node)
52 {
53 wxWindow *child = node->GetData();
54 if (child->IsKindOf( CLASSINFO( wxRadioButton ) ) )
55 {
56 chief = (wxRadioButton*) child;
57 if (child->HasFlag(wxRB_GROUP)) break;
58 }
59 node = node->GetPrevious();
60 }
61 AddInCycle( chief ) ;
62 }
63 return TRUE;
64 }
65
66 void wxRadioButton::SetValue(bool val)
67 {
68 wxRadioButton *cycle;
69 if ( GetControl32BitValue( (ControlHandle) m_macControl ) == val )
70 return ;
71
72 ::SetControl32BitValue( (ControlHandle) m_macControl , val ) ;
73 if (val)
74 {
75 cycle=this->NextInCycle();
76 if (cycle!=NULL) {
77 while (cycle!=this) {
78 cycle->SetValue(false);
79 cycle=cycle->NextInCycle();
80 }
81 }
82 }
83 MacRedrawControl() ;
84 }
85
86 bool wxRadioButton::GetValue() const
87 {
88 return ::GetControl32BitValue( (ControlHandle) m_macControl ) ;
89 }
90
91 void wxRadioButton::Command (wxCommandEvent & event)
92 {
93 SetValue ( (event.GetInt() != 0) );
94 ProcessCommand (event);
95 }
96
97 void wxRadioButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown))
98 {
99 if ( GetValue() )
100 return ;
101
102 wxRadioButton *cycle, *old = NULL ;
103 cycle=this->NextInCycle();
104 if (cycle!=NULL) {
105 while (cycle!=this) {
106 if ( cycle->GetValue() ) {
107 old = cycle ;
108 cycle->SetValue(false);
109 }
110 cycle=cycle->NextInCycle();
111 }
112 }
113
114 SetValue(true) ;
115
116 if ( old ) {
117 wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, old->m_windowId );
118 event.SetEventObject(old);
119 event.SetInt( false );
120 old->ProcessCommand(event);
121 }
122 wxCommandEvent event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
123 event2.SetEventObject(this);
124 event2.SetInt( true );
125 ProcessCommand(event2);
126 }
127
128 wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle)
129 {
130 wxRadioButton *next,*current;
131
132 if (cycle==NULL) {
133 m_cycle=this;
134 return(this);
135 }
136 else {
137 current=cycle;
138 while ((next=current->m_cycle)!=cycle)
139 current=current->m_cycle;
140 m_cycle=cycle;
141 current->m_cycle=this;
142 return(cycle);
143 }
144 }