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 ProcessCommand(event
);
48 bool wxRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
49 const wxString
& label
,
51 const wxSize
& size
, long style
,
52 const wxValidator
& validator
,
57 SetValidator(validator
);
58 #endif // wxUSE_VALIDATORS
60 if (parent
) parent
->AddChild(this);
62 SetBackgroundColour(parent
->GetBackgroundColour());
63 SetForegroundColour(parent
->GetForegroundColour());
66 m_windowId
= (int)NewControlId();
75 m_windowStyle
= style
;
78 if (m_windowStyle
& wxRB_GROUP
)
79 groupStyle
= WS_GROUP
;
81 // long msStyle = groupStyle | RADIO_FLAGS;
82 long msStyle
= groupStyle
| BS_AUTORADIOBUTTON
| WS_CHILD
| WS_VISIBLE
/* | WS_CLIPSIBLINGS */;
85 WXDWORD exStyle
= Determine3DEffects(0, &want3D
) ;
87 // Even with extended styles, need to combine with WS_BORDER
88 // for them to look right.
90 if ( want3D || wxStyleHasBorder(m_windowStyle) )
94 m_hWnd
= (WXHWND
) CreateWindowEx(exStyle
, RADIO_CLASS
, (const wxChar
*)label
,
96 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
98 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create radiobutton") );
103 Ctl3dSubclassCtl((HWND
) m_hWnd
);
108 SetFont(parent
->GetFont());
110 // Subclass again for purposes of dialog editing mode
111 SubclassWin((WXHWND
)m_hWnd
);
116 if (label
!= wxT(""))
118 int label_width
, label_height
;
119 GetTextExtent(label
, &label_width
, &label_height
, NULL
, NULL
, & this->GetFont());
121 width
= (int)(label_width
+ RADIO_SIZE
);
124 height
= (int)(label_height
);
125 if (height
< RADIO_SIZE
)
138 SetSize(x
, y
, width
, height
);
144 void wxRadioButton::SetLabel(const wxString
& label
)
146 SetWindowText((HWND
) GetHWND(), (const wxChar
*)label
);
149 void wxRadioButton::SetValue(bool value
)
151 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
152 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
155 // Get single selection
156 bool wxRadioButton::GetValue(void) const
158 return (SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0L) != 0);
161 void wxRadioButton::Command (wxCommandEvent
& event
)
163 SetValue ( (event
.m_commandInt
!= 0) );
164 ProcessCommand (event
);
167 WXHBRUSH
wxRadioButton::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
175 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
176 return (WXHBRUSH
) hbrush
;
178 #endif // wxUSE_CTL3D
181 if (GetParent()->GetTransparentBackground())
182 SetBkMode(hdc
, TRANSPARENT
);
184 SetBkMode(hdc
, OPAQUE
);
186 wxColour colBack
= GetBackgroundColour();
189 colBack
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
191 ::SetBkColor(hdc
, wxColourToRGB(colBack
));
192 ::SetTextColor(hdc
, wxColourToRGB(GetForegroundColour()));
194 wxBrush
*brush
= wxTheBrushList
->FindOrCreateBrush(colBack
, wxSOLID
);
196 return (WXHBRUSH
)brush
->GetResourceHandle();
201 bool wxBitmapRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
202 const wxBitmap
*bitmap
,
204 const wxSize
& size
, long style
,
205 const wxValidator
& validator
,
206 const wxString
& name
)
209 SetValidator(validator
);
211 if (parent
) parent
->AddChild(this);
212 SetBackgroundColour(parent
->GetBackgroundColour());
213 SetForegroundColour(parent
->GetForegroundColour());
216 m_windowId
= (int)NewControlId();
224 m_windowStyle
= style
;
227 if (m_windowStyle
& wxRB_GROUP
)
228 groupStyle
= WS_GROUP
;
230 // long msStyle = groupStyle | RADIO_FLAGS;
231 long msStyle
= groupStyle
| BS_RADIOBUTTON
| WS_CHILD
| WS_VISIBLE
;
233 m_hWnd
= (WXHWND
) CreateWindowEx(MakeExtendedStyle(m_windowStyle
), RADIO_CLASS
, "toggle",
235 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
237 wxCHECK_MSG( m_hWnd
, "Failed to create radio button", FALSE
);
240 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
242 Ctl3dSubclassCtl((HWND
) GetHWND());
247 // Subclass again for purposes of dialog editing mode
248 SubclassWin(GetHWND());
250 SetSize(x
, y
, width
, height
);
255 void wxBitmapRadioButton::SetLabel(const wxBitmap
*bitmap
)
259 void wxBitmapRadioButton::SetValue(bool value
)
261 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
262 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
265 // Get single selection, for single choice list items
266 bool wxBitmapRadioButton::GetValue(void) const
268 return (bool)SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0L);