]> git.saurik.com Git - wxWidgets.git/blob - src/univ/radiobut.cpp
replaced by CHANGES.txt
[wxWidgets.git] / src / univ / radiobut.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: univ/radiobut.cpp
3 // Purpose: wxRadioButton implementation
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 10.09.00
7 // RCS-ID: $Id$
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "univradiobut.h"
22 #endif
23
24 #include "wx/wxprec.h"
25
26 #ifdef __BORLANDC__
27 #pragma hdrstop
28 #endif
29
30 #if wxUSE_RADIOBTN
31
32 #ifndef WX_PRECOMP
33 #include "wx/dcclient.h"
34 #include "wx/radiobut.h"
35 #include "wx/validate.h"
36 #endif
37
38 #include "wx/univ/theme.h"
39 #include "wx/univ/renderer.h"
40 #include "wx/univ/inphand.h"
41 #include "wx/univ/colschem.h"
42
43 // ============================================================================
44 // implementation
45 // ============================================================================
46
47 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
48
49 // ----------------------------------------------------------------------------
50 // wxRadioButton
51 // ----------------------------------------------------------------------------
52
53 wxRadioButton::wxRadioButton()
54 {
55 Init();
56 }
57
58 wxRadioButton::wxRadioButton(wxWindow *parent,
59 wxWindowID id,
60 const wxString& label,
61 const wxPoint& pos,
62 const wxSize& size,
63 long style,
64 const wxValidator& validator,
65 const wxString& name)
66 {
67 Init();
68
69 Create(parent, id, label, pos, size, style, validator, name);
70 }
71
72 bool wxRadioButton::Create(wxWindow *parent,
73 wxWindowID id,
74 const wxString &label,
75 const wxPoint &pos,
76 const wxSize &size,
77 long style,
78 const wxValidator& validator,
79 const wxString &name)
80 {
81 if ( !wxCheckBox::Create(parent, id, label, pos, size, style,
82 validator, name) )
83 {
84 return FALSE;
85 }
86
87 return TRUE;
88 }
89
90 // ----------------------------------------------------------------------------
91 // radio button methods
92 // ----------------------------------------------------------------------------
93
94 void wxRadioButton::OnCheck()
95 {
96 // clear all others radio buttons in our group: for this we need to
97 // find the radio button which is the first in the group, i.e. the one
98 // with wxRB_GROUP style
99 const wxWindowList& siblings = GetParent()->GetChildren();
100 wxWindowList::compatibility_iterator nodeStart = siblings.Find(this);
101 while ( nodeStart )
102 {
103 // stop if we found a radio button with wxRB_GROUP style or it we
104 // are at the first control
105 if ( !nodeStart->GetPrevious() ||
106 (nodeStart->GetData()->GetWindowStyle() & wxRB_GROUP) )
107 break;
108
109 nodeStart = nodeStart->GetPrevious();
110 }
111
112 // now clear all radio buttons from the starting one until the next
113 // one with wxRB_GROUP style
114 while ( nodeStart )
115 {
116 wxWindow *win = nodeStart->GetData();
117 if ( win != this )
118 {
119 wxRadioButton *btn = wxDynamicCast(win, wxRadioButton);
120 if ( btn )
121 {
122 btn->ClearValue();
123 }
124 }
125
126 nodeStart = nodeStart->GetNext();
127 if ( !nodeStart ||
128 (nodeStart->GetData()->GetWindowStyle() & wxRB_GROUP) )
129 {
130 // we reached the next group
131 break;
132 }
133 }
134 }
135
136 void wxRadioButton::ChangeValue(bool value)
137 {
138 if ( value == IsChecked() )
139 return;
140
141 if ( !IsChecked() )
142 {
143 wxCheckBox::ChangeValue(value);
144 }
145 else // attempt to clear a radio button - this can't be done
146 {
147 // but still refresh as our PRESSED flag changed
148 Refresh();
149 }
150 }
151
152 void wxRadioButton::ClearValue()
153 {
154 if ( IsChecked() )
155 {
156 SetValue(FALSE);
157 }
158 }
159
160 void wxRadioButton::SendEvent()
161 {
162 wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, GetId());
163 InitCommandEvent(event);
164 event.SetInt(IsChecked());
165 Command(event);
166 }
167
168 // ----------------------------------------------------------------------------
169 // overridden wxCheckBox methods
170 // ----------------------------------------------------------------------------
171
172 wxSize wxRadioButton::GetBitmapSize() const
173 {
174 wxBitmap bmp = GetBitmap(State_Normal, Status_Checked);
175 return bmp.Ok() ? wxSize(bmp.GetWidth(), bmp.GetHeight())
176 : GetRenderer()->GetRadioBitmapSize();
177 }
178
179 void wxRadioButton::DoDraw(wxControlRenderer *renderer)
180 {
181 wxDC& dc = renderer->GetDC();
182 dc.SetFont(GetFont());
183 dc.SetTextForeground(GetForegroundColour());
184
185 int flags = GetStateFlags();
186 Status status = GetStatus();
187 if ( status == Status_Checked )
188 flags |= wxCONTROL_CHECKED;
189
190 renderer->GetRenderer()->
191 DrawRadioButton(dc,
192 GetLabel(),
193 GetBitmap(GetState(flags), status),
194 renderer->GetRect(),
195 flags,
196 GetWindowStyle() & wxALIGN_RIGHT ? wxALIGN_RIGHT
197 : wxALIGN_LEFT,
198 GetAccelIndex());
199 }
200
201 #endif // wxUSE_RADIOBTN
202