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"
29 #include "wx/msw/private.h"
31 #if !USE_SHARED_LIBRARY
32 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
33 // 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
,
56 SetValidator(validator
);
58 if (parent
) parent
->AddChild(this);
60 SetBackgroundColour(parent
->GetBackgroundColour());
61 SetForegroundColour(parent
->GetForegroundColour());
64 m_windowId
= (int)NewControlId();
73 m_windowStyle
= style
;
76 if (m_windowStyle
& wxRB_GROUP
)
77 groupStyle
= WS_GROUP
;
79 // long msStyle = groupStyle | RADIO_FLAGS;
80 long msStyle
= groupStyle
| BS_AUTORADIOBUTTON
| WS_CHILD
| WS_VISIBLE
;
83 WXDWORD exStyle
= Determine3DEffects(0, &want3D
) ;
85 // Even with extended styles, need to combine with WS_BORDER
86 // for them to look right.
88 if ( want3D || wxStyleHasBorder(m_windowStyle) )
92 m_hWnd
= (WXHWND
) CreateWindowEx(exStyle
, RADIO_CLASS
, (const char *)label
,
94 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
96 wxCHECK_MSG( m_hWnd
, FALSE
, "Failed to create radiobutton" );
101 Ctl3dSubclassCtl((HWND
) m_hWnd
);
106 SetFont(parent
->GetFont());
108 // Subclass again for purposes of dialog editing mode
109 SubclassWin((WXHWND
)m_hWnd
);
116 int label_width
, label_height
;
117 GetTextExtent(label
, &label_width
, &label_height
, NULL
, NULL
, & GetFont());
119 width
= (int)(label_width
+ RADIO_SIZE
);
122 height
= (int)(label_height
);
123 if (height
< RADIO_SIZE
)
136 SetSize(x
, y
, width
, height
);
142 void wxRadioButton::SetLabel(const wxString
& label
)
144 SetWindowText((HWND
) GetHWND(), (const char *)label
);
147 void wxRadioButton::SetValue(bool value
)
149 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
150 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
153 // Get single selection
154 bool wxRadioButton::GetValue(void) const
156 return (SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0L) != 0);
159 WXHBRUSH
wxRadioButton::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
160 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
165 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
166 return (WXHBRUSH
) hbrush
;
170 if (GetParent()->GetTransparentBackground())
171 SetBkMode((HDC
) pDC
, TRANSPARENT
);
173 SetBkMode((HDC
) pDC
, OPAQUE
);
175 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
176 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
178 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
180 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
181 // has a zero usage count.
182 // backgroundBrush->RealizeResource();
183 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
186 void wxRadioButton::Command (wxCommandEvent
& event
)
188 SetValue ( (event
.m_commandInt
!= 0) );
189 ProcessCommand (event
);
195 bool wxBitmapRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
196 const wxBitmap
*bitmap
,
198 const wxSize
& size
, long style
,
199 const wxValidator
& validator
,
200 const wxString
& name
)
203 SetValidator(validator
);
205 if (parent
) parent
->AddChild(this);
206 SetBackgroundColour(parent
->GetBackgroundColour());
207 SetForegroundColour(parent
->GetForegroundColour());
210 m_windowId
= (int)NewControlId();
218 m_windowStyle
= style
;
221 if (m_windowStyle
& wxRB_GROUP
)
222 groupStyle
= WS_GROUP
;
224 // long msStyle = groupStyle | RADIO_FLAGS;
225 long msStyle
= groupStyle
| BS_RADIOBUTTON
| WS_CHILD
| WS_VISIBLE
;
227 m_hWnd
= (WXHWND
) CreateWindowEx(MakeExtendedStyle(m_windowStyle
), RADIO_CLASS
, "toggle",
229 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
231 wxCHECK_MSG( m_hWnd
, "Failed to create radio button", FALSE
);
234 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
236 Ctl3dSubclassCtl((HWND
) GetHWND());
241 // Subclass again for purposes of dialog editing mode
242 SubclassWin(GetHWND());
244 SetSize(x
, y
, width
, height
);
249 void wxBitmapRadioButton::SetLabel(const wxBitmap
*bitmap
)
253 void wxBitmapRadioButton::SetValue(bool value
)
255 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
256 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
259 // Get single selection, for single choice list items
260 bool wxBitmapRadioButton::GetValue(void) const
262 return (bool)SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0L);