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 #if !USE_SHARED_LIBRARY
33 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
34 // IMPLEMENT_DYNAMIC_CLASS(wxBitmapRadioButton, wxRadioButton)
37 bool wxRadioButton::MSWCommand(WXUINT param
, WXWORD id
)
39 if (param
== BN_CLICKED
)
41 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, m_windowId
);
42 event
.SetEventObject( this );
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
,
57 SetValidator(validator
);
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
, _T("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
);
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 WXHBRUSH
wxRadioButton::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
161 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
166 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
167 return (WXHBRUSH
) hbrush
;
171 if (GetParent()->GetTransparentBackground())
172 SetBkMode((HDC
) pDC
, TRANSPARENT
);
174 SetBkMode((HDC
) pDC
, OPAQUE
);
176 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
177 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
179 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
181 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
182 // has a zero usage count.
183 // backgroundBrush->RealizeResource();
184 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
187 void wxRadioButton::Command (wxCommandEvent
& event
)
189 SetValue ( (event
.m_commandInt
!= 0) );
190 ProcessCommand (event
);
196 bool wxBitmapRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
197 const wxBitmap
*bitmap
,
199 const wxSize
& size
, long style
,
200 const wxValidator
& validator
,
201 const wxString
& name
)
204 SetValidator(validator
);
206 if (parent
) parent
->AddChild(this);
207 SetBackgroundColour(parent
->GetBackgroundColour());
208 SetForegroundColour(parent
->GetForegroundColour());
211 m_windowId
= (int)NewControlId();
219 m_windowStyle
= style
;
222 if (m_windowStyle
& wxRB_GROUP
)
223 groupStyle
= WS_GROUP
;
225 // long msStyle = groupStyle | RADIO_FLAGS;
226 long msStyle
= groupStyle
| BS_RADIOBUTTON
| WS_CHILD
| WS_VISIBLE
;
228 m_hWnd
= (WXHWND
) CreateWindowEx(MakeExtendedStyle(m_windowStyle
), RADIO_CLASS
, "toggle",
230 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
232 wxCHECK_MSG( m_hWnd
, "Failed to create radio button", FALSE
);
235 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
237 Ctl3dSubclassCtl((HWND
) GetHWND());
242 // Subclass again for purposes of dialog editing mode
243 SubclassWin(GetHWND());
245 SetSize(x
, y
, width
, height
);
250 void wxBitmapRadioButton::SetLabel(const wxBitmap
*bitmap
)
254 void wxBitmapRadioButton::SetValue(bool value
)
256 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
257 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
260 // Get single selection, for single choice list items
261 bool wxBitmapRadioButton::GetValue(void) const
263 return (bool)SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0L);