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 #include "wx/wxprec.h"
29 #include "wx/dcclient.h"
30 #include "wx/radiobut.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 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 bool wxRadioButton::Create(wxWindow
*parent
,
51 const wxString
&label
,
55 const wxValidator
& validator
,
58 if ( !wxCheckBox::Create(parent
, id
, label
, pos
, size
, style
,
67 // ----------------------------------------------------------------------------
68 // radio button methods
69 // ----------------------------------------------------------------------------
71 void wxRadioButton::OnCheck()
73 // clear all others radio buttons in our group: for this we need to
74 // find the radio button which is the first in the group, i.e. the one
75 // with wxRB_GROUP style
76 const wxWindowList
& siblings
= GetParent()->GetChildren();
77 wxWindowList::compatibility_iterator nodeStart
= siblings
.Find(this);
80 // stop if we found a radio button with wxRB_GROUP style or it we
81 // are at the first control
82 if ( !nodeStart
->GetPrevious() ||
83 (nodeStart
->GetData()->GetWindowStyle() & wxRB_GROUP
) )
86 nodeStart
= nodeStart
->GetPrevious();
89 // now clear all radio buttons from the starting one until the next
90 // one with wxRB_GROUP style
93 wxWindow
*win
= nodeStart
->GetData();
96 wxRadioButton
*btn
= wxDynamicCast(win
, wxRadioButton
);
103 nodeStart
= nodeStart
->GetNext();
105 (nodeStart
->GetData()->GetWindowStyle() & wxRB_GROUP
) )
107 // we reached the next group
113 void wxRadioButton::ChangeValue(bool value
)
115 if ( value
== IsChecked() )
120 wxCheckBox::ChangeValue(value
);
122 else // attempt to clear a radio button - this can't be done
124 // but still refresh as our PRESSED flag changed
129 void wxRadioButton::ClearValue()
137 void wxRadioButton::SendEvent()
139 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, GetId());
140 InitCommandEvent(event
);
141 event
.SetInt(IsChecked());
145 // ----------------------------------------------------------------------------
146 // overridden wxCheckBox methods
147 // ----------------------------------------------------------------------------
149 wxSize
wxRadioButton::GetBitmapSize() const
151 wxBitmap bmp
= GetBitmap(State_Normal
, Status_Checked
);
152 return bmp
.Ok() ? wxSize(bmp
.GetWidth(), bmp
.GetHeight())
153 : GetRenderer()->GetRadioBitmapSize();
156 void wxRadioButton::DoDraw(wxControlRenderer
*renderer
)
158 wxDC
& dc
= renderer
->GetDC();
159 dc
.SetFont(GetFont());
160 dc
.SetTextForeground(GetForegroundColour());
162 int flags
= GetStateFlags();
163 Status status
= GetStatus();
164 if ( status
== Status_Checked
)
165 flags
|= wxCONTROL_CHECKED
;
167 renderer
->GetRenderer()->
170 GetBitmap(GetState(flags
), status
),
173 GetWindowStyle() & wxALIGN_RIGHT
? wxALIGN_RIGHT
178 #endif // wxUSE_RADIOBTN