1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/univ/radiobut.cpp
3 // Purpose: wxRadioButton implementation
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 #include "wx/wxprec.h"
27 #include "wx/radiobut.h"
30 #include "wx/dcclient.h"
31 #include "wx/validate.h"
34 #include "wx/univ/theme.h"
35 #include "wx/univ/renderer.h"
36 #include "wx/univ/inphand.h"
37 #include "wx/univ/colschem.h"
39 // ============================================================================
41 // ============================================================================
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 bool wxRadioButton::Create(wxWindow
*parent
,
49 const wxString
&label
,
53 const wxValidator
& validator
,
56 if ( !wxCheckBox::Create(parent
, id
, label
, pos
, size
, style
,
65 // ----------------------------------------------------------------------------
66 // radio button methods
67 // ----------------------------------------------------------------------------
69 void wxRadioButton::OnCheck()
71 // clear all others radio buttons in our group: for this we need to
72 // find the radio button which is the first in the group, i.e. the one
73 // with wxRB_GROUP style
74 const wxWindowList
& siblings
= GetParent()->GetChildren();
75 wxWindowList::compatibility_iterator nodeStart
= siblings
.Find(this);
78 // stop if we found a radio button with wxRB_GROUP style or it we
79 // are at the first control
80 if ( !nodeStart
->GetPrevious() ||
81 (nodeStart
->GetData()->GetWindowStyle() & wxRB_GROUP
) )
84 nodeStart
= nodeStart
->GetPrevious();
87 // now clear all radio buttons from the starting one until the next
88 // one with wxRB_GROUP style
91 wxWindow
*win
= nodeStart
->GetData();
94 wxRadioButton
*btn
= wxDynamicCast(win
, wxRadioButton
);
101 nodeStart
= nodeStart
->GetNext();
103 (nodeStart
->GetData()->GetWindowStyle() & wxRB_GROUP
) )
105 // we reached the next group
111 void wxRadioButton::ChangeValue(bool value
)
113 if ( value
== IsChecked() )
118 wxCheckBox::ChangeValue(value
);
120 else // attempt to clear a radio button - this can't be done
122 // but still refresh as our PRESSED flag changed
127 void wxRadioButton::ClearValue()
135 void wxRadioButton::SendEvent()
137 wxCommandEvent
event(wxEVT_RADIOBUTTON
, GetId());
138 InitCommandEvent(event
);
139 event
.SetInt(IsChecked());
143 // ----------------------------------------------------------------------------
144 // overridden wxCheckBox methods
145 // ----------------------------------------------------------------------------
147 wxSize
wxRadioButton::GetBitmapSize() const
149 wxBitmap bmp
= GetBitmap(State_Normal
, Status_Checked
);
150 return bmp
.IsOk() ? wxSize(bmp
.GetWidth(), bmp
.GetHeight())
151 : GetRenderer()->GetRadioBitmapSize();
154 void wxRadioButton::DoDraw(wxControlRenderer
*renderer
)
156 wxDC
& dc
= renderer
->GetDC();
157 dc
.SetFont(GetFont());
158 dc
.SetTextForeground(GetForegroundColour());
160 int flags
= GetStateFlags();
161 Status status
= GetStatus();
162 if ( status
== Status_Checked
)
163 flags
|= wxCONTROL_CHECKED
;
165 renderer
->GetRenderer()->
168 GetBitmap(GetState(flags
), status
),
171 GetWindowStyle() & wxALIGN_RIGHT
? wxALIGN_RIGHT
176 #endif // wxUSE_RADIOBTN