]>
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.
75 if ( want3D
|| wxStyleHasBorder(m_windowStyle
) )
78 m_hWnd
= (WXHWND
) CreateWindowEx(exStyle
, RADIO_CLASS
, (const char *)label
,
80 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
82 wxCHECK_MSG( m_hWnd
, FALSE
, "Failed to create radiobutton" );
87 Ctl3dSubclassCtl((HWND
) m_hWnd
);
92 SetFont(* parent
->GetFont());
94 // Subclass again for purposes of dialog editing mode
95 SubclassWin((WXHWND
)m_hWnd
);
102 int label_width
, label_height
;
103 GetTextExtent(label
, &label_width
, &label_height
, NULL
, NULL
, GetFont());
105 width
= (int)(label_width
+ RADIO_SIZE
);
108 height
= (int)(label_height
);
109 if (height
< RADIO_SIZE
)
122 SetSize(x
, y
, width
, height
);
128 void wxRadioButton::SetLabel(const wxString
& label
)
130 SetWindowText((HWND
) GetHWND(), (const char *)label
);
133 void wxRadioButton::SetValue(bool value
)
135 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
136 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
139 // Get single selection, for single choice list items
140 bool wxRadioButton::GetValue(void) const
142 return (SendMessage((HWND
) GetHWND(), BM_SETCHECK
, 0, 0L) != 0);
145 WXHBRUSH
wxRadioButton::OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
146 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
151 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
152 return (WXHBRUSH
) hbrush
;
156 if (GetParent()->GetTransparentBackground())
157 SetBkMode((HDC
) pDC
, TRANSPARENT
);
159 SetBkMode((HDC
) pDC
, OPAQUE
);
161 ::SetBkColor((HDC
) pDC
, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
162 ::SetTextColor((HDC
) pDC
, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
164 wxBrush
*backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour(), wxSOLID
);
166 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
167 // has a zero usage count.
168 // backgroundBrush->RealizeResource();
169 return (WXHBRUSH
) backgroundBrush
->GetResourceHandle();
172 void wxRadioButton::Command (wxCommandEvent
& event
)
174 SetValue ( (event
.m_commandInt
!= 0) );
175 ProcessCommand (event
);
181 bool wxBitmapRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
182 const wxBitmap
*bitmap
,
184 const wxSize
& size
, long style
,
185 const wxValidator
& validator
,
186 const wxString
& name
)
189 SetValidator(validator
);
191 if (parent
) parent
->AddChild(this);
192 SetBackgroundColour(parent
->GetBackgroundColour());
193 SetForegroundColour(parent
->GetForegroundColour());
196 m_windowId
= (int)NewControlId();
204 m_windowStyle
= style
;
207 if (m_windowStyle
& wxRB_GROUP
)
208 groupStyle
= WS_GROUP
;
210 // long msStyle = groupStyle | RADIO_FLAGS;
211 long msStyle
= groupStyle
| BS_RADIOBUTTON
| WS_CHILD
| WS_VISIBLE
;
213 m_hWnd
= (WXHWND
) CreateWindowEx(MakeExtendedStyle(m_windowStyle
), RADIO_CLASS
, "toggle",
215 (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
, wxGetInstance(), NULL
);
217 wxCHECK_MSG( m_hWnd
, "Failed to create radio button", FALSE
);
220 if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS
))
222 Ctl3dSubclassCtl((HWND
) GetHWND());
227 // Subclass again for purposes of dialog editing mode
228 SubclassWin(GetHWND());
230 SetSize(x
, y
, width
, height
);
235 void wxBitmapRadioButton::SetLabel(const wxBitmap
*bitmap
)
239 void wxBitmapRadioButton::SetValue(bool value
)
241 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
242 SendMessage((HWND
) GetHWND(), BM_SETCHECK
, (WPARAM
)value
, 0L);
245 // Get single selection, for single choice list items
246 bool wxBitmapRadioButton::GetValue(void) const
248 return (bool)SendMessage((HWND
) GetHWND(), BM_GETCHECK
, 0, 0L);