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" 
  26 #include "wx/os2/private.h" 
  28 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
) 
  30 void wxRadioButton::Init() 
  32     m_bFocusJustSet 
= FALSE
; 
  33 } // end of wxRadioButton::Init 
  35 void wxRadioButton::Command ( 
  36   wxCommandEvent
&                   rEvent
 
  39     SetValue ((rEvent
.GetInt() != 0) ); 
  40     ProcessCommand (rEvent
); 
  41 } // end of wxRadioButton::Command 
  43 bool wxRadioButton::Create( 
  46 , const wxString
&                   rsLabel
 
  51 , const wxValidator
&                rValidator
 
  53 , const wxString
&                   rsName
 
  56     if ( !CreateControl( pParent
 
  67     long                            lSstyle 
= HasFlag(wxRB_GROUP
) ? WS_GROUP 
: 0; 
  69     lSstyle 
|= BS_AUTORADIOBUTTON
; 
  71     if (HasFlag(wxCLIP_SIBLINGS
)) 
  72         lSstyle 
|= WS_CLIPSIBLINGS
; 
  74     if (!OS2CreateControl( _T("BUTTON") 
  83     if (HasFlag(wxRB_GROUP
)) 
  86     SetFont(*wxSMALL_FONT
); 
  93 } // end of wxRadioButton::Create 
  95 wxSize 
wxRadioButton::DoGetBestSize() const 
  97     static int                      snRadioSize 
= 0; 
 103         vDC
.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
)); 
 104         snRadioSize 
= vDC
.GetCharHeight(); 
 107     wxString                        sStr 
= GetLabel(); 
 117         nRadioWidth 
+= snRadioSize 
+ GetCharWidth(); 
 118         if (nRadioHeight 
< snRadioSize
) 
 119             nRadioHeight 
= snRadioSize
; 
 123         nRadioWidth  
= snRadioSize
; 
 124         nRadioHeight 
= snRadioSize
; 
 126     return wxSize( nRadioWidth
 
 129 } // end of wxRadioButton::DoGetBestSize 
 132 // Get single selection, for single choice list items 
 134 bool wxRadioButton::GetValue() const 
 136     return((::WinSendMsg((HWND
) GetHWND(), BM_QUERYCHECK
, (MPARAM
)0L, (MPARAM
)0L) != 0)); 
 137 } // end of wxRadioButton::GetValue 
 139 bool wxRadioButton::OS2Command( 
 144     if (wParam 
== BN_CLICKED
) 
 146         wxCommandEvent              
rEvent( wxEVT_COMMAND_RADIOBUTTON_SELECTED
 
 150         rEvent
.SetEventObject(this); 
 151         ProcessCommand(rEvent
); 
 156 } // end of wxRadioButton::OS2Command 
 158 void wxRadioButton::SetFocus() 
 160     // when the radio button receives a WM_SETFOCUS message it generates a 
 161     // BN_CLICKED which is totally unexpected and leads to catastrophic results 
 162     // if you pop up a dialog from the radio button event handler as, when the 
 163     // dialog is dismissed, the focus is returned to the radio button which 
 164     // generates BN_CLICKED which leads to showing another dialog and so on 
 167     // to aviod this, we drop the pseudo BN_CLICKED events generated when the 
 168     // button gains focus 
 169     m_bFocusJustSet 
= TRUE
; 
 171     wxControl::SetFocus(); 
 174 void wxRadioButton::SetLabel( 
 175   const wxString
&                   rsLabel
 
 178     ::WinSetWindowText((HWND
)GetHWND(), (const char *)rsLabel
.c_str()); 
 179 } // end of wxRadioButton::SetLabel 
 181 void wxRadioButton::SetValue( 
 185     ::WinSendMsg((HWND
)GetHWND(), BM_SETCHECK
, (MPARAM
)bValue
, (MPARAM
)0); 
 186 } // end of wxRadioButton::SetValue