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"
27 #include "wx/settings.h"
31 #include "wx/msw/private.h"
33 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
34 // IMPLEMENT_DYNAMIC_CLASS(wxBitmapRadioButton, wxRadioButton)
36 bool wxRadioButton::MSWCommand(WXUINT param
, WXWORD id
)
38 if (param
== BN_CLICKED
)
40 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, m_windowId
);
41 event
.SetEventObject( this );
42 event
.SetInt( GetValue() );
43 ProcessCommand(event
);
49 bool wxRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
50 const wxString
& label
,
52 const wxSize
& size
, long style
,
53 const wxValidator
& validator
,
58 SetValidator(validator
);
59 #endif // wxUSE_VALIDATORS
61 if (parent
) parent
->AddChild(this);
63 SetBackgroundColour(parent
->GetBackgroundColour());
64 SetForegroundColour(parent
->GetForegroundColour());
67 m_windowId
= (int)NewControlId();
76 m_windowStyle
= style
;
79 if (m_windowStyle
& wxRB_GROUP
)
80 groupStyle
= WS_GROUP
;
82 // long msStyle = groupStyle | RADIO_FLAGS;
83 long msStyle
= groupStyle
| BS_AUTORADIOBUTTON
| WS_CHILD
| WS_VISIBLE
/* | WS_CLIPSIBLINGS */;
86 WXDWORD exStyle
= Determine3DEffects(0, &want3D
) ;
88 // Even with extended styles, need to combine with WS_BORDER
89 // for them to look right.
91 if ( want3D || wxStyleHasBorder(m_windowStyle) )
95 m_hWnd
= (WXHWND
) CreateWindowEx(exStyle
, RADIO_CLASS
, (const wxChar
*)label
,
97 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
99 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create radiobutton") );
104 Ctl3dSubclassCtl((HWND
) m_hWnd
);
109 SetFont(parent
->GetFont());
111 // Subclass again for purposes of dialog editing mode
112 SubclassWin((WXHWND
)m_hWnd
);
117 if (label
!= wxT(""))
119 int label_width
, label_height
;
120 GetTextExtent(label
, &label_width
, &label_height
, NULL
, NULL
, & this->GetFont());
122 width
= (int)(label_width
+ RADIO_SIZE
);
125 height
= (int)(label_height
);
126 if (height
< RADIO_SIZE
)
139 SetSize(x
, y
, width
, height
);
145 void wxRadioButton::SetLabel(const wxString
& label
)
147 SetWindowText((HWND
) GetHWND(), (const wxChar
*)label
);
150 void wxRadioButton::SetValue(bool value
)
152 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
153 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
156 // Get single selection
157 bool wxRadioButton::GetValue(void) const
159 return (SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0L) != 0);
162 void wxRadioButton::Command (wxCommandEvent
& event
)
164 SetValue ( (event
.m_commandInt
!= 0) );
165 ProcessCommand (event
);
168 WXHBRUSH
wxRadioButton::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
176 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
177 return (WXHBRUSH
) hbrush
;
179 #endif // wxUSE_CTL3D
182 if (GetParent()->GetTransparentBackground())
183 SetBkMode(hdc
, TRANSPARENT
);
185 SetBkMode(hdc
, OPAQUE
);
187 wxColour colBack
= GetBackgroundColour();
190 colBack
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
192 ::SetBkColor(hdc
, wxColourToRGB(colBack
));
193 ::SetTextColor(hdc
, wxColourToRGB(GetForegroundColour()));
195 wxBrush
*brush
= wxTheBrushList
->FindOrCreateBrush(colBack
, wxSOLID
);
197 return (WXHBRUSH
)brush
->GetResourceHandle();
202 bool wxBitmapRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
203 const wxBitmap
*bitmap
,
205 const wxSize
& size
, long style
,
206 const wxValidator
& validator
,
207 const wxString
& name
)
210 SetValidator(validator
);
212 if (parent
) parent
->AddChild(this);
213 SetBackgroundColour(parent
->GetBackgroundColour());
214 SetForegroundColour(parent
->GetForegroundColour());
217 m_windowId
= (int)NewControlId();
225 m_windowStyle
= style
;
228 if (m_windowStyle
& wxRB_GROUP
)
229 groupStyle
= WS_GROUP
;
231 // long msStyle = groupStyle | RADIO_FLAGS;
232 long msStyle
= groupStyle
| BS_RADIOBUTTON
| WS_CHILD
| WS_VISIBLE
;
234 m_hWnd
= (WXHWND
) CreateWindowEx(MakeExtendedStyle(m_windowStyle
), RADIO_CLASS
, "toggle",
236 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
238 wxCHECK_MSG( m_hWnd
, "Failed to create radio button", FALSE
);
241 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
243 Ctl3dSubclassCtl((HWND
) GetHWND());
248 // Subclass again for purposes of dialog editing mode
249 SubclassWin(GetHWND());
251 SetSize(x
, y
, width
, height
);
256 void wxBitmapRadioButton::SetLabel(const wxBitmap
*bitmap
)
260 void wxBitmapRadioButton::SetValue(bool value
)
262 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
263 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
266 // Get single selection, for single choice list items
267 bool wxBitmapRadioButton::GetValue(void) const
269 return (bool)SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0L);