1 /////////////////////////////////////////////////////////////////////////////
2 // Name: univ/radiobut.cpp
3 // Purpose: wxRadioButton implementation
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "univradiobut.h"
24 #include "wx/wxprec.h"
33 #include "wx/dcclient.h"
34 #include "wx/radiobut.h"
35 #include "wx/validate.h"
38 #include "wx/univ/theme.h"
39 #include "wx/univ/renderer.h"
40 #include "wx/univ/inphand.h"
41 #include "wx/univ/colschem.h"
43 // ============================================================================
45 // ============================================================================
47 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 wxRadioButton::wxRadioButton()
58 wxRadioButton::wxRadioButton(wxWindow
*parent
,
60 const wxString
& label
,
64 const wxValidator
& validator
,
69 Create(parent
, id
, label
, pos
, size
, style
, validator
, name
);
72 bool wxRadioButton::Create(wxWindow
*parent
,
74 const wxString
&label
,
78 const wxValidator
& validator
,
81 if ( !wxCheckBox::Create(parent
, id
, label
, pos
, size
, style
,
90 // ----------------------------------------------------------------------------
91 // radio button methods
92 // ----------------------------------------------------------------------------
94 void wxRadioButton::OnCheck()
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);
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
) )
109 nodeStart
= nodeStart
->GetPrevious();
112 // now clear all radio buttons from the starting one until the next
113 // one with wxRB_GROUP style
116 wxWindow
*win
= nodeStart
->GetData();
119 wxRadioButton
*btn
= wxDynamicCast(win
, wxRadioButton
);
126 nodeStart
= nodeStart
->GetNext();
128 (nodeStart
->GetData()->GetWindowStyle() & wxRB_GROUP
) )
130 // we reached the next group
136 void wxRadioButton::ChangeValue(bool value
)
138 if ( value
== IsChecked() )
143 wxCheckBox::ChangeValue(value
);
145 else // attempt to clear a radio button - this can't be done
147 // but still refresh as our PRESSED flag changed
152 void wxRadioButton::ClearValue()
160 void wxRadioButton::SendEvent()
162 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, GetId());
163 InitCommandEvent(event
);
164 event
.SetInt(IsChecked());
168 // ----------------------------------------------------------------------------
169 // overridden wxCheckBox methods
170 // ----------------------------------------------------------------------------
172 wxSize
wxRadioButton::GetBitmapSize() const
174 wxBitmap bmp
= GetBitmap(State_Normal
, Status_Checked
);
175 return bmp
.Ok() ? wxSize(bmp
.GetWidth(), bmp
.GetHeight())
176 : GetRenderer()->GetRadioBitmapSize();
179 void wxRadioButton::DoDraw(wxControlRenderer
*renderer
)
181 wxDC
& dc
= renderer
->GetDC();
182 dc
.SetFont(GetFont());
183 dc
.SetTextForeground(GetForegroundColour());
185 int flags
= GetStateFlags();
186 Status status
= GetStatus();
187 if ( status
== Status_Checked
)
188 flags
|= wxCONTROL_CHECKED
;
190 renderer
->GetRenderer()->
193 GetBitmap(GetState(flags
), status
),
196 GetWindowStyle() & wxALIGN_RIGHT
? wxALIGN_RIGHT
201 #endif // wxUSE_RADIOBTN