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