1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/motif/radiobut.cpp 
   3 // Purpose:     wxRadioButton 
   4 // Author:      Julian Smart 
   8 // Copyright:   (c) Julian Smart 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  15 #include "wx/radiobut.h" 
  22 #pragma message disable nosimpint 
  24 #include <Xm/ToggleB.h> 
  25 #include <Xm/ToggleBG.h> 
  27 #pragma message enable nosimpint 
  30 #include "wx/motif/private.h" 
  32 void wxRadioButtonCallback (Widget w
, XtPointer clientData
, 
  33                             XmToggleButtonCallbackStruct 
* cbs
); 
  35 wxRadioButton::wxRadioButton() 
  39 bool wxRadioButton::Create(wxWindow 
*parent
, wxWindowID id
, 
  40                            const wxString
& label
, 
  42                            const wxSize
& size
, long style
, 
  43                            const wxValidator
& validator
, 
  46     if( !CreateControl( parent
, id
, pos
, size
, style
, validator
, name 
) ) 
  50     Widget parentWidget 
= (Widget
) parent
->GetClientWidget(); 
  51     Display
* dpy 
= XtDisplay(parentWidget
); 
  53     wxString 
label1(GetLabelText(label
)); 
  55     wxXmString 
text( label1 
); 
  57     Widget radioButtonWidget 
= XtVaCreateManagedWidget ("toggle", 
  59         xmToggleButtonGadgetClass
, parentWidget
, 
  61         xmToggleButtonWidgetClass
, parentWidget
, 
  63         wxFont::GetFontTag(), m_font
.GetFontTypeC(dpy
), 
  64         XmNlabelString
, text(), 
  65         XmNfillOnSelect
, True
, 
  66         XmNindicatorType
, XmONE_OF_MANY
, // diamond-shape 
  69     XtAddCallback (radioButtonWidget
, 
  70                    XmNvalueChangedCallback
, 
  71                    (XtCallbackProc
)wxRadioButtonCallback
, 
  74     m_mainWidget 
= (WXWidget
) radioButtonWidget
; 
  76     XtManageChild (radioButtonWidget
); 
  79     AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, 
  80                   pos
.x
, pos
.y
, size
.x
, size
.y
); 
  82     //copied from mac/radiobut.cpp (from here till "return true;") 
  85     if (HasFlag(wxRB_GROUP
)) 
  91         /* search backward for last group start */ 
  92         wxRadioButton 
*chief 
= NULL
; 
  93         wxWindowList::compatibility_iterator node 
= parent
->GetChildren().GetLast(); 
  96             wxWindow 
*child 
= node
->GetData(); 
  97             if (child
->IsKindOf( CLASSINFO( wxRadioButton 
) ) ) 
  99                 chief 
= (wxRadioButton
*) child
; 
 100                 if (child
->HasFlag(wxRB_GROUP
)) break; 
 102             node 
= node
->GetPrevious(); 
 104         AddInCycle( chief 
) ; 
 109 void wxRadioButton::SetValue(bool value
) 
 111     if (GetValue() == value
) 
 115     XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) value
, False
); 
 116     m_inSetValue 
= false; 
 121 // Get single selection, for single choice list items 
 122 bool wxRadioButton::GetValue() const 
 124     return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0); 
 127 void wxRadioButton::Command (wxCommandEvent 
& event
) 
 129     SetValue ( (event
.GetInt() != 0) ); 
 130     ProcessCommand (event
); 
 133 void wxRadioButton::ChangeBackgroundColour() 
 135     wxWindow::ChangeBackgroundColour(); 
 137     // What colour should this be? 
 138     wxColour colour 
= *wxBLACK
; 
 139     WXPixel selectPixel 
= colour
.AllocColour(XtDisplay((Widget
)m_mainWidget
)); 
 141     XtVaSetValues ((Widget
) GetMainWidget(), 
 142           XmNselectColor
, selectPixel
, 
 146 void wxRadioButtonCallback (Widget 
WXUNUSED(w
), XtPointer clientData
, 
 147                             XmToggleButtonCallbackStruct 
* cbs
) 
 152     wxRadioButton 
*item 
= (wxRadioButton 
*) clientData
; 
 153     if (item
->InSetValue()) 
 156     //based on mac/radiobut.cpp 
 157     wxRadioButton
* old 
= item
->ClearSelections(); 
 158     item
->SetValue(true); 
 162         wxCommandEvent 
event(wxEVT_RADIOBUTTON
, 
 164         event
.SetEventObject(old
); 
 165         event
.SetInt( false ); 
 166         old
->ProcessCommand(event
); 
 168     wxCommandEvent 
event2(wxEVT_RADIOBUTTON
, item
->GetId() ); 
 169     event2
.SetEventObject(item
); 
 170     event2
.SetInt( true ); 
 171     item
->ProcessCommand(event2
); 
 174 wxRadioButton
* wxRadioButton::AddInCycle(wxRadioButton 
*cycle
) 
 182         wxRadioButton
* current 
= cycle
; 
 183         while ( current
->m_cycle 
!= cycle 
) 
 184             current 
= current
->m_cycle
; 
 186         current
->m_cycle 
= this; 
 192 wxRadioButton
* wxRadioButton::ClearSelections() 
 194     wxRadioButton
* cycle 
= NextInCycle(); 
 195     wxRadioButton
* old 
= 0; 
 199         while (cycle 
!= this) 
 201             if ( cycle
->GetValue() ) 
 204                 cycle
->SetValue(false); 
 206             cycle 
= cycle
->NextInCycle(); 
 213 void wxRadioButton::RemoveFromCycle() 
 215     wxRadioButton
* curr 
= NextInCycle(); 
 219         if( curr
->NextInCycle() == this ) 
 221             curr
->m_cycle 
= this->m_cycle
; 
 225         curr 
= curr
->NextInCycle();