1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxRadioButton
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
22 #include "wx/radiobut.h"
26 #include "wx/msw/private.h"
28 #if !USE_SHARED_LIBRARY
29 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
32 bool wxRadioButton::OS2Command(WXUINT param
, WXWORD id
)
34 if (param
== BN_CLICKED
)
36 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, m_windowId
);
37 event
.SetEventObject( this );
38 ProcessCommand(event
);
44 bool wxRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
45 const wxString
& label
,
47 const wxSize
& size
, long style
,
48 const wxValidator
& validator
,
52 SetValidator(validator
);
54 if (parent
) parent
->AddChild(this);
56 SetBackgroundColour(parent
->GetBackgroundColour());
57 SetForegroundColour(parent
->GetForegroundColour());
60 m_windowId
= (int)NewControlId();
69 m_windowStyle
= style
;
71 // TODO create radiobutton
74 if (m_windowStyle & wxRB_GROUP)
75 groupStyle = WS_GROUP;
77 // long msStyle = groupStyle | RADIO_FLAGS;
78 long msStyle = groupStyle | BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE ;
81 WXDWORD exStyle = Determine3DEffects(0, &want3D) ;
83 m_hWnd = (WXHWND) CreateWindowEx(exStyle, RADIO_CLASS, (const wxChar *)label,
85 (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL);
87 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create radiobutton") );
90 SetFont(parent->GetFont());
92 // Subclass again for purposes of dialog editing mode
93 SubclassWin((WXHWND)m_hWnd);
101 int label_width
, label_height
;
102 GetTextExtent(label
, &label_width
, &label_height
, NULL
, NULL
, & this->GetFont());
104 width
= (int)(label_width
+ RADIO_SIZE
);
107 height
= (int)(label_height
);
108 if (height
< RADIO_SIZE
)
121 SetSize(x
, y
, width
, height
);
125 void wxRadioButton::SetLabel(const wxString
& label
)
130 void wxRadioButton::SetValue(bool value
)
135 // Get single selection, for single choice list items
136 bool wxRadioButton::GetValue() const
142 void wxRadioButton::Command (wxCommandEvent
& event
)
144 SetValue ( (event
.m_commandInt
!= 0) );
145 ProcessCommand (event
);
148 bool wxBitmapRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
149 const wxBitmap
*bitmap
,
151 const wxSize
& size
, long style
,
152 const wxValidator
& validator
,
153 const wxString
& name
)
156 SetValidator(validator
);
158 if (parent
) parent
->AddChild(this);
159 SetBackgroundColour(parent
->GetBackgroundColour());
160 SetForegroundColour(parent
->GetForegroundColour());
163 m_windowId
= (int)NewControlId();
171 m_windowStyle
= style
;
174 if (m_windowStyle
& wxRB_GROUP
)
175 groupStyle
= WS_GROUP
;
179 // long msStyle = groupStyle | RADIO_FLAGS;
180 // long msStyle = groupStyle | BS_RADIOBUTTON | WS_CHILD | WS_VISIBLE ;
182 m_hWnd = (WXHWND) CreateWindowEx(MakeExtendedStyle(m_windowStyle), RADIO_CLASS, "toggle",
184 (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL);
186 wxCHECK_MSG( m_hWnd, "Failed to create radio button", FALSE );
189 // Subclass again for purposes of dialog editing mode
190 SubclassWin(GetHWND());
192 SetSize(x
, y
, width
, height
);
197 void wxBitmapRadioButton::SetLabel(const wxBitmap
*bitmap
)
201 void wxBitmapRadioButton::SetValue(bool value
)
203 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
204 // SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L);
207 // Get single selection, for single choice list items
208 bool wxBitmapRadioButton::GetValue(void) const
210 // return (bool)SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L);