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 bool wxRadioButton::Create(wxWindow
*parent
,
55 const wxString
&label
,
59 const wxValidator
& validator
,
62 if ( !wxCheckBox::Create(parent
, id
, label
, pos
, size
, style
,
71 // ----------------------------------------------------------------------------
72 // radio button methods
73 // ----------------------------------------------------------------------------
75 void wxRadioButton::OnCheck()
77 // clear all others radio buttons in our group: for this we need to
78 // find the radio button which is the first in the group, i.e. the one
79 // with wxRB_GROUP style
80 const wxWindowList
& siblings
= GetParent()->GetChildren();
81 wxWindowList::compatibility_iterator nodeStart
= siblings
.Find(this);
84 // stop if we found a radio button with wxRB_GROUP style or it we
85 // are at the first control
86 if ( !nodeStart
->GetPrevious() ||
87 (nodeStart
->GetData()->GetWindowStyle() & wxRB_GROUP
) )
90 nodeStart
= nodeStart
->GetPrevious();
93 // now clear all radio buttons from the starting one until the next
94 // one with wxRB_GROUP style
97 wxWindow
*win
= nodeStart
->GetData();
100 wxRadioButton
*btn
= wxDynamicCast(win
, wxRadioButton
);
107 nodeStart
= nodeStart
->GetNext();
109 (nodeStart
->GetData()->GetWindowStyle() & wxRB_GROUP
) )
111 // we reached the next group
117 void wxRadioButton::ChangeValue(bool value
)
119 if ( value
== IsChecked() )
124 wxCheckBox::ChangeValue(value
);
126 else // attempt to clear a radio button - this can't be done
128 // but still refresh as our PRESSED flag changed
133 void wxRadioButton::ClearValue()
141 void wxRadioButton::SendEvent()
143 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, GetId());
144 InitCommandEvent(event
);
145 event
.SetInt(IsChecked());
149 // ----------------------------------------------------------------------------
150 // overridden wxCheckBox methods
151 // ----------------------------------------------------------------------------
153 wxSize
wxRadioButton::GetBitmapSize() const
155 wxBitmap bmp
= GetBitmap(State_Normal
, Status_Checked
);
156 return bmp
.Ok() ? wxSize(bmp
.GetWidth(), bmp
.GetHeight())
157 : GetRenderer()->GetRadioBitmapSize();
160 void wxRadioButton::DoDraw(wxControlRenderer
*renderer
)
162 wxDC
& dc
= renderer
->GetDC();
163 dc
.SetFont(GetFont());
164 dc
.SetTextForeground(GetForegroundColour());
166 int flags
= GetStateFlags();
167 Status status
= GetStatus();
168 if ( status
== Status_Checked
)
169 flags
|= wxCONTROL_CHECKED
;
171 renderer
->GetRenderer()->
174 GetBitmap(GetState(flags
), status
),
177 GetWindowStyle() & wxALIGN_RIGHT
? wxALIGN_RIGHT
182 #endif // wxUSE_RADIOBTN