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 extern void wxAssociateWinWithHandle( HWND hWnd
36 void wxRadioButton::Init()
38 m_bFocusJustSet
= FALSE
;
39 } // end of wxRadioButton::Init
41 void wxRadioButton::Command (
42 wxCommandEvent
& rEvent
45 SetValue ((rEvent
.GetInt() != 0) );
46 ProcessCommand (rEvent
);
47 } // end of wxRadioButton::Command
49 bool wxRadioButton::Create(
52 , const wxString
& rsLabel
57 , const wxValidator
& rValidator
59 , const wxString
& rsName
62 if ( !CreateControl( pParent
73 long lSstyle
= HasFlag(wxRB_GROUP
) ? WS_GROUP
: 0;
75 lSstyle
|= BS_AUTORADIOBUTTON
;
77 if (HasFlag(wxCLIP_SIBLINGS
))
78 lSstyle
|= WS_CLIPSIBLINGS
;
80 if (!OS2CreateControl( _T("BUTTON")
89 wxAssociateWinWithHandle(m_hWnd
, this);
90 if (HasFlag(wxRB_GROUP
))
93 SetFont(*wxSMALL_FONT
);
100 } // end of wxRadioButton::Create
102 wxSize
wxRadioButton::DoGetBestSize() const
104 static int snRadioSize
= 0;
110 vDC
.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
111 snRadioSize
= vDC
.GetCharHeight();
114 wxString sStr
= GetLabel();
124 nRadioWidth
+= snRadioSize
+ GetCharWidth();
125 if (nRadioHeight
< snRadioSize
)
126 nRadioHeight
= snRadioSize
;
130 nRadioWidth
= snRadioSize
;
131 nRadioHeight
= snRadioSize
;
133 return wxSize( nRadioWidth
136 } // end of wxRadioButton::DoGetBestSize
139 // Get single selection, for single choice list items
141 bool wxRadioButton::GetValue() const
143 return((::WinSendMsg((HWND
) GetHWND(), BM_QUERYCHECK
, (MPARAM
)0L, (MPARAM
)0L) != 0));
144 } // end of wxRadioButton::GetValue
146 bool wxRadioButton::OS2Command(
151 if (wParam
== BN_CLICKED
)
153 wxCommandEvent
rEvent( wxEVT_COMMAND_RADIOBUTTON_SELECTED
157 rEvent
.SetEventObject(this);
158 ProcessCommand(rEvent
);
163 } // end of wxRadioButton::OS2Command
165 void wxRadioButton::SetFocus()
167 // when the radio button receives a WM_SETFOCUS message it generates a
168 // BN_CLICKED which is totally unexpected and leads to catastrophic results
169 // if you pop up a dialog from the radio button event handler as, when the
170 // dialog is dismissed, the focus is returned to the radio button which
171 // generates BN_CLICKED which leads to showing another dialog and so on
174 // to aviod this, we drop the pseudo BN_CLICKED events generated when the
175 // button gains focus
176 m_bFocusJustSet
= TRUE
;
178 wxControl::SetFocus();
181 void wxRadioButton::SetLabel(
182 const wxString
& rsLabel
185 ::WinSetWindowText((HWND
)GetHWND(), (const char *)rsLabel
.c_str());
186 } // end of wxRadioButton::SetLabel
188 void wxRadioButton::SetValue(
192 ::WinSendMsg((HWND
)GetHWND(), BM_SETCHECK
, (MPARAM
)bValue
, (MPARAM
)0);
193 } // end of wxRadioButton::SetValue
195 MRESULT
wxRadioButton::OS2WindowProc(
201 if (uMsg
== WM_SETFOCUS
)
203 m_bFocusJustSet
= TRUE
;
205 MRESULT mRc
= wxControl::OS2WindowProc( uMsg
210 m_bFocusJustSet
= FALSE
;
213 return wxControl::OS2WindowProc( uMsg
217 } // end of wxRadioButton::OS2WindowProc