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 SetFont(*wxSMALL_FONT
);
95 } // end of wxRadioButton::Create
97 wxSize
wxRadioButton::DoGetBestSize() const
99 static int snRadioSize
= 0;
105 vDC
.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
106 snRadioSize
= vDC
.GetCharHeight();
109 wxString sStr
= GetLabel();
119 nRadioWidth
+= snRadioSize
+ GetCharWidth();
120 if (nRadioHeight
< snRadioSize
)
121 nRadioHeight
= snRadioSize
;
125 nRadioWidth
= snRadioSize
;
126 nRadioHeight
= snRadioSize
;
128 return wxSize( nRadioWidth
131 } // end of wxRadioButton::DoGetBestSize
134 // Get single selection, for single choice list items
136 bool wxRadioButton::GetValue() const
138 return((::WinSendMsg((HWND
) GetHWND(), BM_QUERYCHECK
, (MPARAM
)0L, (MPARAM
)0L) != 0));
139 } // end of wxRadioButton::GetValue
141 bool wxRadioButton::OS2Command(
146 if (wParam
== BN_CLICKED
)
148 wxCommandEvent
rEvent( wxEVT_COMMAND_RADIOBUTTON_SELECTED
152 rEvent
.SetEventObject(this);
153 ProcessCommand(rEvent
);
158 } // end of wxRadioButton::OS2Command
160 void wxRadioButton::SetFocus()
162 // when the radio button receives a WM_SETFOCUS message it generates a
163 // BN_CLICKED which is totally unexpected and leads to catastrophic results
164 // if you pop up a dialog from the radio button event handler as, when the
165 // dialog is dismissed, the focus is returned to the radio button which
166 // generates BN_CLICKED which leads to showing another dialog and so on
169 // to aviod this, we drop the pseudo BN_CLICKED events generated when the
170 // button gains focus
171 m_bFocusJustSet
= TRUE
;
173 wxControl::SetFocus();
176 void wxRadioButton::SetLabel(
177 const wxString
& rsLabel
180 ::WinSetWindowText((HWND
)GetHWND(), (const char *)rsLabel
.c_str());
181 } // end of wxRadioButton::SetLabel
183 void wxRadioButton::SetValue(
187 ::WinSendMsg((HWND
)GetHWND(), BM_SETCHECK
, (MPARAM
)bValue
, (MPARAM
)0);
188 } // end of wxRadioButton::SetValue