1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxRadioButton
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
22 #include "wx/radiobut.h"
24 #include "wx/dcscreen.h"
25 #include "wx/settings.h"
28 #include "wx/os2/private.h"
30 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
32 void wxRadioButton::Init()
34 m_bFocusJustSet
= FALSE
;
35 } // end of wxRadioButton::Init
37 void wxRadioButton::Command (
38 wxCommandEvent
& rEvent
41 SetValue ((rEvent
.GetInt() != 0) );
42 ProcessCommand (rEvent
);
43 } // end of wxRadioButton::Command
45 bool wxRadioButton::Create(
48 , const wxString
& rsLabel
53 , const wxValidator
& rValidator
55 , const wxString
& rsName
58 if ( !CreateControl( pParent
69 long lSstyle
= HasFlag(wxRB_GROUP
) ? WS_GROUP
: 0;
71 lSstyle
|= BS_AUTORADIOBUTTON
;
73 if (HasFlag(wxCLIP_SIBLINGS
))
74 lSstyle
|= WS_CLIPSIBLINGS
;
76 if (!OS2CreateControl( _T("BUTTON")
85 if (HasFlag(wxRB_GROUP
))
88 wxFont
* pTextFont
= new wxFont( 10
101 } // end of wxRadioButton::Create
103 wxSize
wxRadioButton::DoGetBestSize() const
105 static int snRadioSize
= 0;
111 vDC
.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
112 snRadioSize
= vDC
.GetCharHeight();
115 wxString sStr
= GetLabel();
125 nRadioWidth
+= snRadioSize
+ GetCharWidth();
126 if (nRadioHeight
< snRadioSize
)
127 nRadioHeight
= snRadioSize
;
131 nRadioWidth
= snRadioSize
;
132 nRadioHeight
= snRadioSize
;
134 return wxSize( nRadioWidth
137 } // end of wxRadioButton::DoGetBestSize
140 // Get single selection, for single choice list items
142 bool wxRadioButton::GetValue() const
144 return((::WinSendMsg((HWND
) GetHWND(), BM_QUERYCHECK
, (MPARAM
)0L, (MPARAM
)0L) != 0));
145 } // end of wxRadioButton::GetValue
147 bool wxRadioButton::OS2Command(
152 if (wParam
== BN_CLICKED
)
154 wxCommandEvent
rEvent( wxEVT_COMMAND_RADIOBUTTON_SELECTED
158 rEvent
.SetEventObject(this);
159 ProcessCommand(rEvent
);
164 } // end of wxRadioButton::OS2Command
166 void wxRadioButton::SetFocus()
168 // when the radio button receives a WM_SETFOCUS message it generates a
169 // BN_CLICKED which is totally unexpected and leads to catastrophic results
170 // if you pop up a dialog from the radio button event handler as, when the
171 // dialog is dismissed, the focus is returned to the radio button which
172 // generates BN_CLICKED which leads to showing another dialog and so on
175 // to aviod this, we drop the pseudo BN_CLICKED events generated when the
176 // button gains focus
177 m_bFocusJustSet
= TRUE
;
179 wxControl::SetFocus();
182 void wxRadioButton::SetLabel(
183 const wxString
& rsLabel
186 ::WinSetWindowText((HWND
)GetHWND(), (const char *)rsLabel
.c_str());
187 } // end of wxRadioButton::SetLabel
189 void wxRadioButton::SetValue(
193 ::WinSendMsg((HWND
)GetHWND(), BM_SETCHECK
, (MPARAM
)bValue
, (MPARAM
)0);
194 } // end of wxRadioButton::SetValue