]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/radiobut.cpp
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::Create(wxWindow
*parent
, const wxWindowID id
,
37 const wxString
& label
,
39 const wxSize
& size
, const long style
,
40 const wxValidator
& validator
,
44 SetValidator(validator
);
46 if (parent
) parent
->AddChild(this);
48 SetBackgroundColour(parent
->GetDefaultBackgroundColour());
49 SetForegroundColour(parent
->GetDefaultForegroundColour());
52 m_windowId
= (int)NewControlId();
61 m_windowStyle
= style
;
64 if (m_windowStyle
& wxRB_GROUP
)
65 groupStyle
= WS_GROUP
;
67 // long msStyle = groupStyle | RADIO_FLAGS;
68 long msStyle
= groupStyle
| BS_RADIOBUTTON
| WS_CHILD
| WS_VISIBLE
;
71 WXDWORD exStyle
= Determine3DEffects(0, &want3D
) ;
73 // Even with extended styles, need to combine with WS_BORDER
74 // for them to look right.
75 if (want3D
&& ((m_windowStyle
& wxSIMPLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
76 (m_windowStyle
& wxSUNKEN_BORDER
) || (m_windowStyle
& wxDOUBLE_BORDER
)))
79 m_hWnd
= (WXHWND
) CreateWindowEx(exStyle
, RADIO_CLASS
, (const char *)label
,
81 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
85 Ctl3dSubclassCtl((HWND
) m_hWnd
);
90 SetFont(* parent
->GetFont());
92 // Subclass again for purposes of dialog editing mode
93 SubclassWin((WXHWND
)m_hWnd
);
100 float label_width
, label_height
;
101 GetTextExtent(label
, &label_width
, &label_height
, NULL
, NULL
, GetFont());
103 width
= (int)(label_width
+ RADIO_SIZE
);
106 height
= (int)(label_height
);
107 if (height
< RADIO_SIZE
)
120 SetSize(x
, y
, width
, height
);
126 void wxRadioButton::SetLabel(const wxString
& label
)
128 SetWindowText((HWND
) GetHWND(), (const char *)label
);
131 void wxRadioButton::SetValue(const bool value
)
133 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
134 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
137 // Get single selection, for single choice list items
138 bool wxRadioButton::GetValue(void) const
140 return (SendMessage((HWND
) GetHWND(), BM_SETCHECK
, 0, 0L) != 0);
143 WXHBRUSH
wxRadioButton::OnCtlColor(const WXHDC pDC
, const WXHWND pWnd
, const WXUINT nCtlColor
,
144 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
149 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
150 return (WXHBRUSH
) hbrush
;
154 if (GetParent()->GetTransparentBackground())
155 SetBkMode((HDC
) pDC
, TRANSPARENT
);
157 SetBkMode((HDC
) pDC
, OPAQUE
);
159 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
160 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
162 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
164 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
165 // has a zero usage count.
166 // backgroundBrush->RealizeResource();
167 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
170 void wxRadioButton::Command (wxCommandEvent
& event
)
172 SetValue ( (event
.m_commandInt
!= 0) );
173 ProcessCommand (event
);
179 bool wxBitmapRadioButton::Create(wxWindow
*parent
, const wxWindowID id
,
180 const wxBitmap
*bitmap
,
182 const wxSize
& size
, const long style
,
183 const wxValidator
& validator
,
184 const wxString
& name
)
187 SetValidator(validator
);
189 if (parent
) parent
->AddChild(this);
190 SetBackgroundColour(parent
->GetDefaultBackgroundColour());
191 SetForegroundColour(parent
->GetDefaultForegroundColour());
194 m_windowId
= (int)NewControlId();
202 m_windowStyle
= style
;
205 if (m_windowStyle
& wxRB_GROUP
)
206 groupStyle
= WS_GROUP
;
208 // long msStyle = groupStyle | RADIO_FLAGS;
209 long msStyle
= groupStyle
| BS_RADIOBUTTON
| WS_CHILD
| WS_VISIBLE
;
211 m_hWnd
= (WXHWND
) CreateWindowEx(MakeExtendedStyle(m_windowStyle
), RADIO_CLASS
, "toggle",
213 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
215 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
217 Ctl3dSubclassCtl((HWND
) GetHWND());
222 // Subclass again for purposes of dialog editing mode
223 SubclassWin(GetHWND());
225 SetSize(x
, y
, width
, height
);
230 void wxBitmapRadioButton::SetLabel(const wxBitmap
*bitmap
)
234 void wxBitmapRadioButton::SetValue(const bool value
)
236 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
237 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
240 // Get single selection, for single choice list items
241 bool wxBitmapRadioButton::GetValue(void) const
243 return (bool)SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0L);