]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/radiobut.cpp
Cleanup
[wxWidgets.git] / src / mac / carbon / 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 #ifdef __GNUG__
13 #pragma implementation "radiobut.h"
14 #endif
15
16 #include "wx/defs.h"
17
18 #include "wx/radiobut.h"
19
20 #if !USE_SHARED_LIBRARY
21 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
22 #endif
23
24 #include "wx/mac/uma.h"
25
26 bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
27 const wxString& label,
28 const wxPoint& pos,
29 const wxSize& size, long style,
30 const wxValidator& validator,
31 const wxString& name)
32 {
33 m_macIsUserPane = FALSE ;
34
35 if ( !wxControl::Create(parent, id, pos, size, style, validator, name) )
36 return false;
37
38 m_label = label ;
39
40 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
41
42 m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 1,
43 kControlRadioButtonProc , (long) this ) ;
44
45 MacPostControlCreate(pos,size) ;
46
47 m_cycle = this ;
48
49 if (HasFlag(wxRB_GROUP))
50 {
51 AddInCycle( NULL ) ;
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)
59 {
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();
67 }
68 AddInCycle( chief ) ;
69 }
70 return TRUE;
71 }
72
73 void wxRadioButton::SetValue(bool val)
74 {
75 wxRadioButton *cycle;
76 if ( GetControl32BitValue( (ControlRef) m_macControl ) == val )
77 return ;
78
79 ::SetControl32BitValue( (ControlRef) m_macControl , val ) ;
80 if (val)
81 {
82 cycle=this->NextInCycle();
83 if (cycle!=NULL) {
84 while (cycle!=this) {
85 cycle->SetValue(false);
86 cycle=cycle->NextInCycle();
87 }
88 }
89 }
90 MacRedrawControl() ;
91 }
92
93 bool wxRadioButton::GetValue() const
94 {
95 return ::GetControl32BitValue( (ControlRef) m_macControl ) ;
96 }
97
98 void wxRadioButton::Command (wxCommandEvent & event)
99 {
100 SetValue ( (event.GetInt() != 0) );
101 ProcessCommand (event);
102 }
103
104 void wxRadioButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown))
105 {
106 if ( GetValue() )
107 return ;
108
109 wxRadioButton *cycle, *old = NULL ;
110 cycle=this->NextInCycle();
111 if (cycle!=NULL) {
112 while (cycle!=this) {
113 if ( cycle->GetValue() ) {
114 old = cycle ;
115 cycle->SetValue(false);
116 }
117 cycle=cycle->NextInCycle();
118 }
119 }
120
121 SetValue(true) ;
122
123 if ( old ) {
124 wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, old->m_windowId );
125 event.SetEventObject(old);
126 event.SetInt( false );
127 old->ProcessCommand(event);
128 }
129 wxCommandEvent event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
130 event2.SetEventObject(this);
131 event2.SetInt( true );
132 ProcessCommand(event2);
133 }
134
135 wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle)
136 {
137 wxRadioButton *next,*current;
138
139 if (cycle==NULL) {
140 m_cycle=this;
141 return(this);
142 }
143 else {
144 current=cycle;
145 while ((next=current->m_cycle)!=cycle)
146 current=current->m_cycle;
147 m_cycle=cycle;
148 current->m_cycle=this;
149 return(cycle);
150 }
151 }