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 bool wxRadioButton::OS2Command(WXUINT param
, WXWORD id
) 
  32   if (param 
== BN_CLICKED
) 
  34     wxCommandEvent 
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, m_windowId
); 
  35     event
.SetEventObject( this ); 
  36     ProcessCommand(event
); 
  42 bool wxRadioButton::Create(wxWindow 
*parent
, wxWindowID id
, 
  43            const wxString
& label
, 
  45            const wxSize
& size
, long style
, 
  47            const wxValidator
& validator
, 
  53     SetValidator(validator
); 
  56     if (parent
) parent
->AddChild(this); 
  58     SetBackgroundColour(parent
->GetBackgroundColour()); 
  59     SetForegroundColour(parent
->GetForegroundColour()); 
  62         m_windowId 
= (int)NewControlId(); 
  71     m_windowStyle 
= style 
; 
  73 // TODO create radiobutton 
  76   if (m_windowStyle & wxRB_GROUP) 
  77     groupStyle = WS_GROUP; 
  79 //  long msStyle = groupStyle | RADIO_FLAGS; 
  80   long msStyle = groupStyle | BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE ; 
  83   WXDWORD exStyle = Determine3DEffects(0, &want3D) ; 
  85   m_hWnd = (WXHWND) CreateWindowEx(exStyle, RADIO_CLASS, (const wxChar *)label, 
  87                           (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL); 
  89   wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create radiobutton") ); 
  92   SetFont(parent->GetFont()); 
  94   // Subclass again for purposes of dialog editing mode 
  95   SubclassWin((WXHWND)m_hWnd); 
 101   if (label 
!= wxT("")) 
 103     int label_width
, label_height
; 
 104     GetTextExtent(label
, &label_width
, &label_height
, NULL
, NULL
, & this->GetFont()); 
 106       width 
= (int)(label_width 
+ RADIO_SIZE
); 
 109       height 
= (int)(label_height
); 
 110       if (height 
< RADIO_SIZE
) 
 123   SetSize(x
, y
, width
, height
); 
 127 void wxRadioButton::SetLabel(const wxString
& label
) 
 132 void wxRadioButton::SetValue(bool value
) 
 137 // Get single selection, for single choice list items 
 138 bool wxRadioButton::GetValue() const 
 144 void wxRadioButton::Command (wxCommandEvent 
& event
) 
 146   SetValue ( (event
.m_commandInt 
!= 0) ); 
 147   ProcessCommand (event
); 
 153 bool wxBitmapRadioButton::Create(wxWindow 
*parent
, wxWindowID id
, 
 154        const wxBitmap 
*bitmap
, 
 156            const wxSize
& size
, long style
, 
 158            const wxValidator
& validator
, 
 160            const wxString
& name
) 
 164   SetValidator(validator
); 
 167   if (parent
) parent
->AddChild(this); 
 168   SetBackgroundColour(parent
->GetBackgroundColour()); 
 169   SetForegroundColour(parent
->GetForegroundColour()); 
 172     m_windowId 
= (int)NewControlId(); 
 180   m_windowStyle 
= style 
; 
 183   if (m_windowStyle 
& wxRB_GROUP
) 
 184     groupStyle 
= WS_GROUP
; 
 188 //  long msStyle = groupStyle | RADIO_FLAGS; 
 189 //  long msStyle = groupStyle | BS_RADIOBUTTON | WS_CHILD | WS_VISIBLE ; 
 191   m_hWnd = (WXHWND) CreateWindowEx(MakeExtendedStyle(m_windowStyle), RADIO_CLASS, "toggle", 
 193                           (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL); 
 195   wxCHECK_MSG( m_hWnd, "Failed to create radio button", FALSE ); 
 198   // Subclass again for purposes of dialog editing mode 
 199   SubclassWin(GetHWND()); 
 201   SetSize(x
, y
, width
, height
); 
 206 void wxBitmapRadioButton::SetLabel(const wxBitmap 
*bitmap
) 
 210 void wxBitmapRadioButton::SetValue(bool value
) 
 212 // Following necessary for Win32s, because Win32s translate BM_SETCHECK 
 213 //  SendMessage((HWND) GetHWND(), BM_SETCHECK, (WPARAM)value, 0L); 
 216 // Get single selection, for single choice list items 
 217 bool wxBitmapRadioButton::GetValue(void) const 
 219 //  return (bool)SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L);