]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/radiobut.cpp
adding metafile and clipboard support
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "radiobut.h"
14 #endif
15
16 #include "wx/wxprec.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_peer = new wxMacControl() ;
43 verify_noerr ( CreateRadioButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") ,
44 0 , false /* no autotoggle */ , m_peer->GetControlRefAddr() ) );
45
46
47 MacPostControlCreate(pos,size) ;
48
49 m_cycle = this ;
50
51 if (HasFlag(wxRB_GROUP))
52 {
53 AddInCycle( NULL ) ;
54 }
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;
73 }
74
75 void wxRadioButton::SetValue(bool val)
76 {
77 wxRadioButton *cycle;
78 if ( m_peer->GetValue() == val )
79 return ;
80
81 m_peer->SetValue( val ) ;
82 if (val)
83 {
84 cycle=this->NextInCycle();
85 if (cycle!=NULL)
86 {
87 while (cycle!=this)
88 {
89 cycle->SetValue(false);
90 cycle=cycle->NextInCycle();
91 }
92 }
93 }
94 }
95
96 bool wxRadioButton::GetValue() const
97 {
98 return m_peer->GetValue() ;
99 }
100
101 void wxRadioButton::Command (wxCommandEvent & event)
102 {
103 SetValue ( (event.GetInt() != 0) );
104 ProcessCommand (event);
105 }
106
107 wxInt32 wxRadioButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
108 {
109 // if already set -> no action
110 if ( GetValue() )
111 return noErr;
112
113 wxRadioButton *cycle, *old = NULL ;
114 cycle=this->NextInCycle();
115 if (cycle!=NULL) {
116 while (cycle!=this) {
117 if ( cycle->GetValue() ) {
118 old = cycle ;
119 cycle->SetValue(false);
120 }
121 cycle=cycle->NextInCycle();
122 }
123 }
124
125 SetValue(true) ;
126
127 if ( old ) {
128 wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, old->m_windowId );
129 event.SetEventObject(old);
130 event.SetInt( false );
131 old->ProcessCommand(event);
132 }
133 wxCommandEvent event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
134 event2.SetEventObject(this);
135 event2.SetInt( true );
136 ProcessCommand(event2);
137 return noErr ;
138 }
139
140 wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle)
141 {
142 wxRadioButton *next,*current;
143
144 if (cycle==NULL) {
145 m_cycle=this;
146 return(this);
147 }
148 else {
149 current=cycle;
150 while ((next=current->m_cycle)!=cycle)
151 current=current->m_cycle;
152 m_cycle=cycle;
153 current->m_cycle=this;
154 return(cycle);
155 }
156 }