1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/radiobut.cpp
3 // Purpose: wxRadioButton
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
14 #include "wx/radiobut.h"
21 #pragma message disable nosimpint
23 #include <Xm/ToggleB.h>
24 #include <Xm/ToggleBG.h>
26 #pragma message enable nosimpint
29 #include "wx/motif/private.h"
31 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
32 XmToggleButtonCallbackStruct
* cbs
);
34 wxRadioButton::wxRadioButton()
38 bool wxRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
39 const wxString
& label
,
41 const wxSize
& size
, long style
,
42 const wxValidator
& validator
,
45 if( !CreateControl( parent
, id
, pos
, size
, style
, validator
, name
) )
49 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
50 Display
* dpy
= XtDisplay(parentWidget
);
52 wxString
label1(GetLabelText(label
));
54 wxXmString
text( label1
);
56 Widget radioButtonWidget
= XtVaCreateManagedWidget ("toggle",
58 xmToggleButtonGadgetClass
, parentWidget
,
60 xmToggleButtonWidgetClass
, parentWidget
,
62 wxFont::GetFontTag(), m_font
.GetFontTypeC(dpy
),
63 XmNlabelString
, text(),
64 XmNfillOnSelect
, True
,
65 XmNindicatorType
, XmONE_OF_MANY
, // diamond-shape
68 XtAddCallback (radioButtonWidget
,
69 XmNvalueChangedCallback
,
70 (XtCallbackProc
)wxRadioButtonCallback
,
73 m_mainWidget
= (WXWidget
) radioButtonWidget
;
75 XtManageChild (radioButtonWidget
);
78 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
,
79 pos
.x
, pos
.y
, size
.x
, size
.y
);
81 //copied from mac/radiobut.cpp (from here till "return true;")
84 if (HasFlag(wxRB_GROUP
))
90 /* search backward for last group start */
91 wxRadioButton
*chief
= NULL
;
92 wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetLast();
95 wxWindow
*child
= node
->GetData();
96 if (child
->IsKindOf( CLASSINFO( wxRadioButton
) ) )
98 chief
= (wxRadioButton
*) child
;
99 if (child
->HasFlag(wxRB_GROUP
)) break;
101 node
= node
->GetPrevious();
103 AddInCycle( chief
) ;
108 void wxRadioButton::SetValue(bool value
)
110 if (GetValue() == value
)
114 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) value
, False
);
115 m_inSetValue
= false;
120 // Get single selection, for single choice list items
121 bool wxRadioButton::GetValue() const
123 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
126 void wxRadioButton::Command (wxCommandEvent
& event
)
128 SetValue ( (event
.GetInt() != 0) );
129 ProcessCommand (event
);
132 void wxRadioButton::ChangeBackgroundColour()
134 wxWindow::ChangeBackgroundColour();
136 // What colour should this be?
137 wxColour colour
= *wxBLACK
;
138 WXPixel selectPixel
= colour
.AllocColour(XtDisplay((Widget
)m_mainWidget
));
140 XtVaSetValues ((Widget
) GetMainWidget(),
141 XmNselectColor
, selectPixel
,
145 void wxRadioButtonCallback (Widget
WXUNUSED(w
), XtPointer clientData
,
146 XmToggleButtonCallbackStruct
* cbs
)
151 wxRadioButton
*item
= (wxRadioButton
*) clientData
;
152 if (item
->InSetValue())
155 //based on mac/radiobut.cpp
156 wxRadioButton
* old
= item
->ClearSelections();
157 item
->SetValue(true);
161 wxCommandEvent
event(wxEVT_RADIOBUTTON
,
163 event
.SetEventObject(old
);
164 event
.SetInt( false );
165 old
->ProcessCommand(event
);
167 wxCommandEvent
event2(wxEVT_RADIOBUTTON
, item
->GetId() );
168 event2
.SetEventObject(item
);
169 event2
.SetInt( true );
170 item
->ProcessCommand(event2
);
173 wxRadioButton
* wxRadioButton::AddInCycle(wxRadioButton
*cycle
)
181 wxRadioButton
* current
= cycle
;
182 while ( current
->m_cycle
!= cycle
)
183 current
= current
->m_cycle
;
185 current
->m_cycle
= this;
191 wxRadioButton
* wxRadioButton::ClearSelections()
193 wxRadioButton
* cycle
= NextInCycle();
194 wxRadioButton
* old
= 0;
198 while (cycle
!= this)
200 if ( cycle
->GetValue() )
203 cycle
->SetValue(false);
205 cycle
= cycle
->NextInCycle();
212 void wxRadioButton::RemoveFromCycle()
214 wxRadioButton
* curr
= NextInCycle();
218 if( curr
->NextInCycle() == this )
220 curr
->m_cycle
= this->m_cycle
;
224 curr
= curr
->NextInCycle();