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