]>
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
, wxWindowID id
,
37 const wxString
& label
,
39 const wxSize
& size
, long style
,
40 const wxValidator
& validator
,
44 SetValidator(validator
);
46 if (parent
) parent
->AddChild(this);
48 SetBackgroundColour(parent
->GetBackgroundColour());
49 SetForegroundColour(parent
->GetForegroundColour());
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.
76 if ( want3D || wxStyleHasBorder(m_windowStyle) )
80 m_hWnd
= (WXHWND
) CreateWindowEx(exStyle
, RADIO_CLASS
, (const char *)label
,
82 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
84 wxCHECK_MSG( m_hWnd
, FALSE
, "Failed to create radiobutton" );
89 Ctl3dSubclassCtl((HWND
) m_hWnd
);
94 SetFont(* parent
->GetFont());
96 // Subclass again for purposes of dialog editing mode
97 SubclassWin((WXHWND
)m_hWnd
);
104 int label_width
, label_height
;
105 GetTextExtent(label
, &label_width
, &label_height
, NULL
, NULL
, GetFont());
107 width
= (int)(label_width
+ RADIO_SIZE
);
110 height
= (int)(label_height
);
111 if (height
< RADIO_SIZE
)
124 SetSize(x
, y
, width
, height
);
130 void wxRadioButton::SetLabel(const wxString
& label
)
132 SetWindowText((HWND
) GetHWND(), (const char *)label
);
135 void wxRadioButton::SetValue(bool value
)
137 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
138 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
141 // Get single selection, for single choice list items
142 bool wxRadioButton::GetValue(void) const
144 return (SendMessage((HWND
) GetHWND(), BM_SETCHECK
, 0, 0L) != 0);
147 WXHBRUSH
wxRadioButton::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
148 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
153 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
154 return (WXHBRUSH
) hbrush
;
158 if (GetParent()->GetTransparentBackground())
159 SetBkMode((HDC
) pDC
, TRANSPARENT
);
161 SetBkMode((HDC
) pDC
, OPAQUE
);
163 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
164 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
166 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
168 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
169 // has a zero usage count.
170 // backgroundBrush->RealizeResource();
171 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
174 void wxRadioButton::Command (wxCommandEvent
& event
)
176 SetValue ( (event
.m_commandInt
!= 0) );
177 ProcessCommand (event
);
183 bool wxBitmapRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
184 const wxBitmap
*bitmap
,
186 const wxSize
& size
, long style
,
187 const wxValidator
& validator
,
188 const wxString
& name
)
191 SetValidator(validator
);
193 if (parent
) parent
->AddChild(this);
194 SetBackgroundColour(parent
->GetBackgroundColour());
195 SetForegroundColour(parent
->GetForegroundColour());
198 m_windowId
= (int)NewControlId();
206 m_windowStyle
= style
;
209 if (m_windowStyle
& wxRB_GROUP
)
210 groupStyle
= WS_GROUP
;
212 // long msStyle = groupStyle | RADIO_FLAGS;
213 long msStyle
= groupStyle
| BS_RADIOBUTTON
| WS_CHILD
| WS_VISIBLE
;
215 m_hWnd
= (WXHWND
) CreateWindowEx(MakeExtendedStyle(m_windowStyle
), RADIO_CLASS
, "toggle",
217 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
219 wxCHECK_MSG( m_hWnd
, "Failed to create radio button", FALSE
);
222 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
224 Ctl3dSubclassCtl((HWND
) GetHWND());
229 // Subclass again for purposes of dialog editing mode
230 SubclassWin(GetHWND());
232 SetSize(x
, y
, width
, height
);
237 void wxBitmapRadioButton::SetLabel(const wxBitmap
*bitmap
)
241 void wxBitmapRadioButton::SetValue(bool value
)
243 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
244 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
247 // Get single selection, for single choice list items
248 bool wxBitmapRadioButton::GetValue(void) const
250 return (bool)SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0L);