1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 #include "wx/wxprec.h"
28 #include "wx/radiobut.h"
31 #include "wx/dcclient.h"
32 #include "wx/validate.h"
35 #include "wx/univ/theme.h"
36 #include "wx/univ/renderer.h"
37 #include "wx/univ/inphand.h"
38 #include "wx/univ/colschem.h"
40 // ============================================================================
42 // ============================================================================
44 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 bool wxRadioButton::Create(wxWindow
*parent
,
52 const wxString
&label
,
56 const wxValidator
& validator
,
59 if ( !wxCheckBox::Create(parent
, id
, label
, pos
, size
, style
,
68 // ----------------------------------------------------------------------------
69 // radio button methods
70 // ----------------------------------------------------------------------------
72 void wxRadioButton::OnCheck()
74 // clear all others radio buttons in our group: for this we need to
75 // find the radio button which is the first in the group, i.e. the one
76 // with wxRB_GROUP style
77 const wxWindowList
& siblings
= GetParent()->GetChildren();
78 wxWindowList::compatibility_iterator nodeStart
= siblings
.Find(this);
81 // stop if we found a radio button with wxRB_GROUP style or it we
82 // are at the first control
83 if ( !nodeStart
->GetPrevious() ||
84 (nodeStart
->GetData()->GetWindowStyle() & wxRB_GROUP
) )
87 nodeStart
= nodeStart
->GetPrevious();
90 // now clear all radio buttons from the starting one until the next
91 // one with wxRB_GROUP style
94 wxWindow
*win
= nodeStart
->GetData();
97 wxRadioButton
*btn
= wxDynamicCast(win
, wxRadioButton
);
104 nodeStart
= nodeStart
->GetNext();
106 (nodeStart
->GetData()->GetWindowStyle() & wxRB_GROUP
) )
108 // we reached the next group
114 void wxRadioButton::ChangeValue(bool value
)
116 if ( value
== IsChecked() )
121 wxCheckBox::ChangeValue(value
);
123 else // attempt to clear a radio button - this can't be done
125 // but still refresh as our PRESSED flag changed
130 void wxRadioButton::ClearValue()
138 void wxRadioButton::SendEvent()
140 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, GetId());
141 InitCommandEvent(event
);
142 event
.SetInt(IsChecked());
146 // ----------------------------------------------------------------------------
147 // overridden wxCheckBox methods
148 // ----------------------------------------------------------------------------
150 wxSize
wxRadioButton::GetBitmapSize() const
152 wxBitmap bmp
= GetBitmap(State_Normal
, Status_Checked
);
153 return bmp
.Ok() ? wxSize(bmp
.GetWidth(), bmp
.GetHeight())
154 : GetRenderer()->GetRadioBitmapSize();
157 void wxRadioButton::DoDraw(wxControlRenderer
*renderer
)
159 wxDC
& dc
= renderer
->GetDC();
160 dc
.SetFont(GetFont());
161 dc
.SetTextForeground(GetForegroundColour());
163 int flags
= GetStateFlags();
164 Status status
= GetStatus();
165 if ( status
== Status_Checked
)
166 flags
|= wxCONTROL_CHECKED
;
168 renderer
->GetRenderer()->
171 GetBitmap(GetState(flags
), status
),
174 GetWindowStyle() & wxALIGN_RIGHT
? wxALIGN_RIGHT
179 #endif // wxUSE_RADIOBTN