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 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 bool wxRadioButton::Create(wxWindow
*parent
,
50 const wxString
&label
,
54 const wxValidator
& validator
,
57 if ( !wxCheckBox::Create(parent
, id
, label
, pos
, size
, style
,
66 // ----------------------------------------------------------------------------
67 // radio button methods
68 // ----------------------------------------------------------------------------
70 void wxRadioButton::OnCheck()
72 // clear all others radio buttons in our group: for this we need to
73 // find the radio button which is the first in the group, i.e. the one
74 // with wxRB_GROUP style
75 const wxWindowList
& siblings
= GetParent()->GetChildren();
76 wxWindowList::compatibility_iterator nodeStart
= siblings
.Find(this);
79 // stop if we found a radio button with wxRB_GROUP style or it we
80 // are at the first control
81 if ( !nodeStart
->GetPrevious() ||
82 (nodeStart
->GetData()->GetWindowStyle() & wxRB_GROUP
) )
85 nodeStart
= nodeStart
->GetPrevious();
88 // now clear all radio buttons from the starting one until the next
89 // one with wxRB_GROUP style
92 wxWindow
*win
= nodeStart
->GetData();
95 wxRadioButton
*btn
= wxDynamicCast(win
, wxRadioButton
);
102 nodeStart
= nodeStart
->GetNext();
104 (nodeStart
->GetData()->GetWindowStyle() & wxRB_GROUP
) )
106 // we reached the next group
112 void wxRadioButton::ChangeValue(bool value
)
114 if ( value
== IsChecked() )
119 wxCheckBox::ChangeValue(value
);
121 else // attempt to clear a radio button - this can't be done
123 // but still refresh as our PRESSED flag changed
128 void wxRadioButton::ClearValue()
136 void wxRadioButton::SendEvent()
138 wxCommandEvent
event(wxEVT_RADIOBUTTON
, GetId());
139 InitCommandEvent(event
);
140 event
.SetInt(IsChecked());
144 // ----------------------------------------------------------------------------
145 // overridden wxCheckBox methods
146 // ----------------------------------------------------------------------------
148 wxSize
wxRadioButton::GetBitmapSize() const
150 wxBitmap bmp
= GetBitmap(State_Normal
, Status_Checked
);
151 return bmp
.IsOk() ? wxSize(bmp
.GetWidth(), bmp
.GetHeight())
152 : GetRenderer()->GetRadioBitmapSize();
155 void wxRadioButton::DoDraw(wxControlRenderer
*renderer
)
157 wxDC
& dc
= renderer
->GetDC();
158 dc
.SetFont(GetFont());
159 dc
.SetTextForeground(GetForegroundColour());
161 int flags
= GetStateFlags();
162 Status status
= GetStatus();
163 if ( status
== Status_Checked
)
164 flags
|= wxCONTROL_CHECKED
;
166 renderer
->GetRenderer()->
169 GetBitmap(GetState(flags
), status
),
172 GetWindowStyle() & wxALIGN_RIGHT
? wxALIGN_RIGHT
177 #endif // wxUSE_RADIOBTN