]>
Commit | Line | Data |
---|---|---|
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 | |
d8c736e5 | 18 | #include "wx/radiobut.h" |
079c842c | 19 | |
d8c736e5 | 20 | #if !USE_SHARED_LIBRARY |
e9576ca5 | 21 | IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl) |
d8c736e5 | 22 | #endif |
079c842c | 23 | |
d497dca4 | 24 | #include "wx/mac/uma.h" |
1dd52151 | 25 | |
e9576ca5 | 26 | bool 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 | { | |
facd6764 SC |
33 | m_macIsUserPane = FALSE ; |
34 | ||
b45ed7a2 VZ |
35 | if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) |
36 | return false; | |
e40298d5 | 37 | |
facd6764 SC |
38 | m_label = label ; |
39 | ||
40 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; | |
e40298d5 | 41 | |
21fd5529 | 42 | m_peer = new wxMacControl() ; |
4c37f124 | 43 | verify_noerr ( CreateRadioButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , |
5ca0d812 | 44 | 0 , false /* no autotoggle */ , m_peer->GetControlRefAddr() ) ); |
21fd5529 | 45 | |
4c37f124 | 46 | |
facd6764 | 47 | MacPostControlCreate(pos,size) ; |
e9576ca5 | 48 | |
aa6c945b | 49 | m_cycle = this ; |
c503ab84 | 50 | |
0a67a93b SC |
51 | if (HasFlag(wxRB_GROUP)) |
52 | { | |
e40298d5 | 53 | AddInCycle( NULL ) ; |
0a67a93b SC |
54 | } |
55 | else | |
56 | { | |
57 | /* search backward for last group start */ | |
58 | wxRadioButton *chief = (wxRadioButton*) NULL; | |
affd2611 | 59 | wxWindowList::compatibility_iterator node = parent->GetChildren().GetLast(); |
0a67a93b | 60 | while (node) |
079c842c | 61 | { |
0a67a93b SC |
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(); | |
079c842c | 69 | } |
0a67a93b SC |
70 | AddInCycle( chief ) ; |
71 | } | |
72 | return TRUE; | |
e9576ca5 SC |
73 | } |
74 | ||
1dd52151 | 75 | void wxRadioButton::SetValue(bool val) |
e9576ca5 | 76 | { |
e40298d5 | 77 | wxRadioButton *cycle; |
5ca0d812 | 78 | if ( m_peer->GetValue() == val ) |
e40298d5 JS |
79 | return ; |
80 | ||
5ca0d812 | 81 | m_peer->SetValue( val ) ; |
2f1ae414 SC |
82 | if (val) |
83 | { | |
e40298d5 JS |
84 | cycle=this->NextInCycle(); |
85 | if (cycle!=NULL) { | |
86 | while (cycle!=this) { | |
87 | cycle->SetValue(false); | |
88 | cycle=cycle->NextInCycle(); | |
89 | } | |
90 | } | |
91 | } | |
73969f3f | 92 | MacRedrawControl() ; |
e9576ca5 SC |
93 | } |
94 | ||
e9576ca5 SC |
95 | bool wxRadioButton::GetValue() const |
96 | { | |
5ca0d812 | 97 | return m_peer->GetValue() ; |
e9576ca5 SC |
98 | } |
99 | ||
100 | void wxRadioButton::Command (wxCommandEvent & event) | |
101 | { | |
1dd52151 | 102 | SetValue ( (event.GetInt() != 0) ); |
e9576ca5 SC |
103 | ProcessCommand (event); |
104 | } | |
105 | ||
4c37f124 | 106 | wxInt32 wxRadioButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) |
1dd52151 | 107 | { |
4c37f124 | 108 | // if already set -> no action |
f0822896 | 109 | if ( GetValue() ) |
4c37f124 | 110 | return noErr; |
f0822896 | 111 | |
e40298d5 | 112 | wxRadioButton *cycle, *old = NULL ; |
f0822896 SC |
113 | cycle=this->NextInCycle(); |
114 | if (cycle!=NULL) { | |
e40298d5 JS |
115 | while (cycle!=this) { |
116 | if ( cycle->GetValue() ) { | |
117 | old = cycle ; | |
118 | cycle->SetValue(false); | |
119 | } | |
120 | cycle=cycle->NextInCycle(); | |
121 | } | |
f0822896 SC |
122 | } |
123 | ||
e40298d5 | 124 | SetValue(true) ; |
f0822896 SC |
125 | |
126 | if ( old ) { | |
127 | wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, old->m_windowId ); | |
128 | event.SetEventObject(old); | |
129 | event.SetInt( false ); | |
130 | old->ProcessCommand(event); | |
131 | } | |
132 | wxCommandEvent event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId ); | |
133 | event2.SetEventObject(this); | |
134 | event2.SetInt( true ); | |
135 | ProcessCommand(event2); | |
4c37f124 | 136 | return noErr ; |
1dd52151 UJ |
137 | } |
138 | ||
139 | wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle) | |
140 | { | |
e40298d5 JS |
141 | wxRadioButton *next,*current; |
142 | ||
143 | if (cycle==NULL) { | |
144 | m_cycle=this; | |
145 | return(this); | |
146 | } | |
147 | else { | |
148 | current=cycle; | |
149 | while ((next=current->m_cycle)!=cycle) | |
150 | current=current->m_cycle; | |
151 | m_cycle=cycle; | |
152 | current->m_cycle=this; | |
153 | return(cycle); | |
154 | } | |
1dd52151 | 155 | } |