1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxRadioButton
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "radiobut.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/radiobut.h"
30 #include "wx/msw/private.h"
32 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
33 // IMPLEMENT_DYNAMIC_CLASS(wxBitmapRadioButton, wxRadioButton)
35 bool wxRadioButton::MSWCommand(WXUINT param
, WXWORD id
)
37 if (param
== BN_CLICKED
)
39 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, m_windowId
);
40 event
.SetEventObject( this );
41 ProcessCommand(event
);
47 bool wxRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
48 const wxString
& label
,
50 const wxSize
& size
, long style
,
51 const wxValidator
& validator
,
56 SetValidator(validator
);
57 #endif // wxUSE_VALIDATORS
59 if (parent
) parent
->AddChild(this);
61 SetBackgroundColour(parent
->GetBackgroundColour());
62 SetForegroundColour(parent
->GetForegroundColour());
65 m_windowId
= (int)NewControlId();
74 m_windowStyle
= style
;
77 if (m_windowStyle
& wxRB_GROUP
)
78 groupStyle
= WS_GROUP
;
80 // long msStyle = groupStyle | RADIO_FLAGS;
81 long msStyle
= groupStyle
| BS_AUTORADIOBUTTON
| WS_CHILD
| WS_VISIBLE
;
84 WXDWORD exStyle
= Determine3DEffects(0, &want3D
) ;
86 // Even with extended styles, need to combine with WS_BORDER
87 // for them to look right.
89 if ( want3D || wxStyleHasBorder(m_windowStyle) )
93 m_hWnd
= (WXHWND
) CreateWindowEx(exStyle
, RADIO_CLASS
, (const wxChar
*)label
,
95 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
97 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create radiobutton") );
102 Ctl3dSubclassCtl((HWND
) m_hWnd
);
107 SetFont(parent
->GetFont());
109 // Subclass again for purposes of dialog editing mode
110 SubclassWin((WXHWND
)m_hWnd
);
115 if (label
!= wxT(""))
117 int label_width
, label_height
;
118 GetTextExtent(label
, &label_width
, &label_height
, NULL
, NULL
, & this->GetFont());
120 width
= (int)(label_width
+ RADIO_SIZE
);
123 height
= (int)(label_height
);
124 if (height
< RADIO_SIZE
)
137 SetSize(x
, y
, width
, height
);
143 void wxRadioButton::SetLabel(const wxString
& label
)
145 SetWindowText((HWND
) GetHWND(), (const wxChar
*)label
);
148 void wxRadioButton::SetValue(bool value
)
150 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
151 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
154 // Get single selection
155 bool wxRadioButton::GetValue(void) const
157 return (SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0L) != 0);
160 void wxRadioButton::Command (wxCommandEvent
& event
)
162 SetValue ( (event
.m_commandInt
!= 0) );
163 ProcessCommand (event
);
169 bool wxBitmapRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
170 const wxBitmap
*bitmap
,
172 const wxSize
& size
, long style
,
173 const wxValidator
& validator
,
174 const wxString
& name
)
177 SetValidator(validator
);
179 if (parent
) parent
->AddChild(this);
180 SetBackgroundColour(parent
->GetBackgroundColour());
181 SetForegroundColour(parent
->GetForegroundColour());
184 m_windowId
= (int)NewControlId();
192 m_windowStyle
= style
;
195 if (m_windowStyle
& wxRB_GROUP
)
196 groupStyle
= WS_GROUP
;
198 // long msStyle = groupStyle | RADIO_FLAGS;
199 long msStyle
= groupStyle
| BS_RADIOBUTTON
| WS_CHILD
| WS_VISIBLE
;
201 m_hWnd
= (WXHWND
) CreateWindowEx(MakeExtendedStyle(m_windowStyle
), RADIO_CLASS
, "toggle",
203 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
205 wxCHECK_MSG( m_hWnd
, "Failed to create radio button", FALSE
);
208 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
210 Ctl3dSubclassCtl((HWND
) GetHWND());
215 // Subclass again for purposes of dialog editing mode
216 SubclassWin(GetHWND());
218 SetSize(x
, y
, width
, height
);
223 void wxBitmapRadioButton::SetLabel(const wxBitmap
*bitmap
)
227 void wxBitmapRadioButton::SetValue(bool value
)
229 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
230 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
233 // Get single selection, for single choice list items
234 bool wxBitmapRadioButton::GetValue(void) const
236 return (bool)SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0L);