]>
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 | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "radiobut.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/radiobut.h" | |
17 | ||
079c842c | 18 | |
e9576ca5 | 19 | IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl) |
079c842c | 20 | |
1dd52151 UJ |
21 | #include <wx/mac/uma.h> |
22 | ||
e9576ca5 SC |
23 | bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, |
24 | const wxString& label, | |
25 | const wxPoint& pos, | |
26 | const wxSize& size, long style, | |
27 | const wxValidator& validator, | |
28 | const wxString& name) | |
29 | { | |
1dd52151 UJ |
30 | Rect bounds ; |
31 | Str255 title ; | |
32 | ||
1dd52151 | 33 | MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ; |
e9576ca5 | 34 | |
1dd52151 UJ |
35 | m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 1, |
36 | kControlRadioButtonProc , (long) this ) ; | |
37 | ||
38 | MacPostControlCreate() ; | |
e9576ca5 | 39 | |
0a67a93b SC |
40 | if (HasFlag(wxRB_GROUP)) |
41 | { | |
42 | AddInCycle( NULL ) ; | |
43 | } | |
44 | else | |
45 | { | |
46 | /* search backward for last group start */ | |
47 | wxRadioButton *chief = (wxRadioButton*) NULL; | |
48 | wxWindowList::Node *node = parent->GetChildren().GetLast(); | |
49 | while (node) | |
079c842c | 50 | { |
0a67a93b SC |
51 | wxWindow *child = node->GetData(); |
52 | if (child->IsKindOf( CLASSINFO( wxRadioButton ) ) ) | |
53 | { | |
54 | chief = (wxRadioButton*) child; | |
55 | if (child->HasFlag(wxRB_GROUP)) break; | |
56 | } | |
57 | node = node->GetPrevious(); | |
079c842c | 58 | } |
0a67a93b SC |
59 | AddInCycle( chief ) ; |
60 | } | |
61 | return TRUE; | |
e9576ca5 SC |
62 | } |
63 | ||
1dd52151 | 64 | void wxRadioButton::SetValue(bool val) |
e9576ca5 | 65 | { |
1dd52151 UJ |
66 | int i; |
67 | wxRadioButton *cycle; | |
68 | ||
69 | ::SetControlValue( m_macControl , val ) ; | |
70 | ||
2f1ae414 SC |
71 | if (val) |
72 | { | |
1dd52151 UJ |
73 | cycle=this->NextInCycle(); |
74 | if (cycle!=NULL) { | |
75 | while (cycle!=this) { | |
76 | cycle->SetValue(false); | |
77 | cycle=cycle->NextInCycle(); | |
78 | } | |
79 | } | |
80 | } | |
e9576ca5 SC |
81 | } |
82 | ||
e9576ca5 SC |
83 | bool wxRadioButton::GetValue() const |
84 | { | |
1dd52151 | 85 | return ::GetControlValue( m_macControl ) ; |
e9576ca5 SC |
86 | } |
87 | ||
88 | void wxRadioButton::Command (wxCommandEvent & event) | |
89 | { | |
1dd52151 | 90 | SetValue ( (event.GetInt() != 0) ); |
e9576ca5 SC |
91 | ProcessCommand (event); |
92 | } | |
93 | ||
1dd52151 UJ |
94 | void wxRadioButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) |
95 | { | |
96 | SetValue(true) ; | |
8208e181 SC |
97 | wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId ); |
98 | event.SetEventObject(this); | |
99 | ProcessCommand(event); | |
1dd52151 UJ |
100 | } |
101 | ||
102 | wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle) | |
103 | { | |
104 | wxRadioButton *next,*current; | |
105 | ||
106 | if (cycle==NULL) { | |
107 | m_cycle=this; | |
108 | return(this); | |
109 | } | |
110 | else { | |
111 | current=cycle; | |
0a67a93b SC |
112 | while ((next=current->m_cycle)!=cycle) |
113 | current=current->m_cycle; | |
1dd52151 UJ |
114 | m_cycle=cycle; |
115 | current->m_cycle=this; | |
116 | return(cycle); | |
117 | } | |
118 | } |