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
,
55 SetValidator(validator
);
57 if (parent
) parent
->AddChild(this);
59 SetBackgroundColour(parent
->GetBackgroundColour());
60 SetForegroundColour(parent
->GetForegroundColour());
63 m_windowId
= (int)NewControlId();
72 m_windowStyle
= style
;
75 if (m_windowStyle
& wxRB_GROUP
)
76 groupStyle
= WS_GROUP
;
78 // long msStyle = groupStyle | RADIO_FLAGS;
79 long msStyle
= groupStyle
| BS_AUTORADIOBUTTON
| WS_CHILD
| WS_VISIBLE
;
82 WXDWORD exStyle
= Determine3DEffects(0, &want3D
) ;
84 // Even with extended styles, need to combine with WS_BORDER
85 // for them to look right.
87 if ( want3D || wxStyleHasBorder(m_windowStyle) )
91 m_hWnd
= (WXHWND
) CreateWindowEx(exStyle
, RADIO_CLASS
, (const wxChar
*)label
,
93 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
95 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create radiobutton") );
100 Ctl3dSubclassCtl((HWND
) m_hWnd
);
105 SetFont(parent
->GetFont());
107 // Subclass again for purposes of dialog editing mode
108 SubclassWin((WXHWND
)m_hWnd
);
113 if (label
!= wxT(""))
115 int label_width
, label_height
;
116 GetTextExtent(label
, &label_width
, &label_height
, NULL
, NULL
, & this->GetFont());
118 width
= (int)(label_width
+ RADIO_SIZE
);
121 height
= (int)(label_height
);
122 if (height
< RADIO_SIZE
)
135 SetSize(x
, y
, width
, height
);
141 void wxRadioButton::SetLabel(const wxString
& label
)
143 SetWindowText((HWND
) GetHWND(), (const wxChar
*)label
);
146 void wxRadioButton::SetValue(bool value
)
148 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
149 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
152 // Get single selection
153 bool wxRadioButton::GetValue(void) const
155 return (SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0L) != 0);
158 void wxRadioButton::Command (wxCommandEvent
& event
)
160 SetValue ( (event
.m_commandInt
!= 0) );
161 ProcessCommand (event
);
167 bool wxBitmapRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
168 const wxBitmap
*bitmap
,
170 const wxSize
& size
, long style
,
171 const wxValidator
& validator
,
172 const wxString
& name
)
175 SetValidator(validator
);
177 if (parent
) parent
->AddChild(this);
178 SetBackgroundColour(parent
->GetBackgroundColour());
179 SetForegroundColour(parent
->GetForegroundColour());
182 m_windowId
= (int)NewControlId();
190 m_windowStyle
= style
;
193 if (m_windowStyle
& wxRB_GROUP
)
194 groupStyle
= WS_GROUP
;
196 // long msStyle = groupStyle | RADIO_FLAGS;
197 long msStyle
= groupStyle
| BS_RADIOBUTTON
| WS_CHILD
| WS_VISIBLE
;
199 m_hWnd
= (WXHWND
) CreateWindowEx(MakeExtendedStyle(m_windowStyle
), RADIO_CLASS
, "toggle",
201 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
203 wxCHECK_MSG( m_hWnd
, "Failed to create radio button", FALSE
);
206 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
208 Ctl3dSubclassCtl((HWND
) GetHWND());
213 // Subclass again for purposes of dialog editing mode
214 SubclassWin(GetHWND());
216 SetSize(x
, y
, width
, height
);
221 void wxBitmapRadioButton::SetLabel(const wxBitmap
*bitmap
)
225 void wxBitmapRadioButton::SetValue(bool value
)
227 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
228 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
231 // Get single selection, for single choice list items
232 bool wxBitmapRadioButton::GetValue(void) const
234 return (bool)SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0L);