1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/radiobut.cpp
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
WXUNUSED(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 */;
85 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
86 msStyle
|= WS_CLIPSIBLINGS
;
90 WXDWORD exStyle
= Determine3DEffects(0, &want3D
) ;
92 // Even with extended styles, need to combine with WS_BORDER
93 // for them to look right.
95 if ( want3D || wxStyleHasBorder(m_windowStyle) )
99 m_hWnd
= (WXHWND
) CreateWindowEx(exStyle
, RADIO_CLASS
, (const wxChar
*)label
,
101 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
103 wxCHECK_MSG( m_hWnd
, FALSE
, wxT("Failed to create radiobutton") );
108 Ctl3dSubclassCtl((HWND
) m_hWnd
);
113 SetFont(parent
->GetFont());
115 // Subclass again for purposes of dialog editing mode
116 SubclassWin((WXHWND
)m_hWnd
);
121 if (label
!= wxT(""))
123 int label_width
, label_height
;
124 GetTextExtent(label
, &label_width
, &label_height
, NULL
, NULL
, & this->GetFont());
126 width
= (int)(label_width
+ RADIO_SIZE
);
129 height
= (int)(label_height
);
130 if (height
< RADIO_SIZE
)
143 SetSize(x
, y
, width
, height
);
145 // for compatibility with wxGTK, the first radio button in a group is
146 // always checked (this makes sense anyhow as you need to ensure that at
147 // least one button in the group is checked and this is the simlpest way to
149 if ( m_windowStyle
& wxRB_GROUP
)
156 void wxRadioButton::SetLabel(const wxString
& label
)
158 SetWindowText((HWND
) GetHWND(), (const wxChar
*)label
);
161 void wxRadioButton::SetValue(bool value
)
163 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
164 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
167 // Get single selection
168 bool wxRadioButton::GetValue(void) const
170 return (SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0L) != 0);
173 void wxRadioButton::Command (wxCommandEvent
& event
)
175 SetValue ( (event
.m_commandInt
!= 0) );
176 ProcessCommand (event
);
179 WXHBRUSH
wxRadioButton::OnCtlColor(WXHDC pDC
, WXHWND
WXUNUSED(pWnd
), WXUINT
WXUNUSED(nCtlColor
),
185 WXUINT
WXUNUSED(message
),
186 WXWPARAM
WXUNUSED(wParam
),
187 WXLPARAM
WXUNUSED(lParam
)
194 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
195 return (WXHBRUSH
) hbrush
;
197 #endif // wxUSE_CTL3D
200 if (GetParent()->GetTransparentBackground())
201 SetBkMode(hdc
, TRANSPARENT
);
203 SetBkMode(hdc
, OPAQUE
);
205 wxColour colBack
= GetBackgroundColour();
208 colBack
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
210 ::SetBkColor(hdc
, wxColourToRGB(colBack
));
211 ::SetTextColor(hdc
, wxColourToRGB(GetForegroundColour()));
213 wxBrush
*brush
= wxTheBrushList
->FindOrCreateBrush(colBack
, wxSOLID
);
215 return (WXHBRUSH
)brush
->GetResourceHandle();
220 bool wxBitmapRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
221 const wxBitmap
*bitmap
,
223 const wxSize
& size
, long style
,
224 const wxValidator
& validator
,
225 const wxString
& name
)
228 SetValidator(validator
);
230 if (parent
) parent
->AddChild(this);
231 SetBackgroundColour(parent
->GetBackgroundColour());
232 SetForegroundColour(parent
->GetForegroundColour());
235 m_windowId
= (int)NewControlId();
243 m_windowStyle
= style
;
246 if (m_windowStyle
& wxRB_GROUP
)
247 groupStyle
= WS_GROUP
;
249 // long msStyle = groupStyle | RADIO_FLAGS;
250 long msStyle
= groupStyle
| BS_RADIOBUTTON
| WS_CHILD
| WS_VISIBLE
;
252 m_hWnd
= (WXHWND
) CreateWindowEx(MakeExtendedStyle(m_windowStyle
), RADIO_CLASS
, "toggle",
254 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
256 wxCHECK_MSG( m_hWnd
, "Failed to create radio button", FALSE
);
259 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
261 Ctl3dSubclassCtl((HWND
) GetHWND());
266 // Subclass again for purposes of dialog editing mode
267 SubclassWin(GetHWND());
269 SetSize(x
, y
, width
, height
);
274 void wxBitmapRadioButton::SetLabel(const wxBitmap
*bitmap
)
278 void wxBitmapRadioButton::SetValue(bool value
)
280 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
281 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
284 // Get single selection, for single choice list items
285 bool wxBitmapRadioButton::GetValue(void) const
287 return (bool)SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0L);
292 #endif // wxUSE_RADIOBTN