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 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
37 wxRadioButton::wxRadioButton()
41 bool wxRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
42 const wxString
& label
,
44 const wxSize
& size
, long style
,
45 const wxValidator
& validator
,
48 if( !CreateControl( parent
, id
, pos
, size
, style
, validator
, name
) )
52 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
53 Display
* dpy
= XtDisplay(parentWidget
);
55 wxString
label1(GetLabelText(label
));
57 wxXmString
text( label1
);
59 Widget radioButtonWidget
= XtVaCreateManagedWidget ("toggle",
61 xmToggleButtonGadgetClass
, parentWidget
,
63 xmToggleButtonWidgetClass
, parentWidget
,
65 wxFont::GetFontTag(), m_font
.GetFontTypeC(dpy
),
66 XmNlabelString
, text(),
67 XmNfillOnSelect
, True
,
68 XmNindicatorType
, XmONE_OF_MANY
, // diamond-shape
71 XtAddCallback (radioButtonWidget
,
72 XmNvalueChangedCallback
,
73 (XtCallbackProc
)wxRadioButtonCallback
,
76 m_mainWidget
= (WXWidget
) radioButtonWidget
;
78 XtManageChild (radioButtonWidget
);
81 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
,
82 pos
.x
, pos
.y
, size
.x
, size
.y
);
84 //copied from mac/radiobut.cpp (from here till "return true;")
87 if (HasFlag(wxRB_GROUP
))
93 /* search backward for last group start */
94 wxRadioButton
*chief
= NULL
;
95 wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetLast();
98 wxWindow
*child
= node
->GetData();
99 if (child
->IsKindOf( CLASSINFO( wxRadioButton
) ) )
101 chief
= (wxRadioButton
*) child
;
102 if (child
->HasFlag(wxRB_GROUP
)) break;
104 node
= node
->GetPrevious();
106 AddInCycle( chief
) ;
111 void wxRadioButton::SetValue(bool value
)
113 if (GetValue() == value
)
117 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) value
, False
);
118 m_inSetValue
= false;
123 // Get single selection, for single choice list items
124 bool wxRadioButton::GetValue() const
126 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
129 void wxRadioButton::Command (wxCommandEvent
& event
)
131 SetValue ( (event
.GetInt() != 0) );
132 ProcessCommand (event
);
135 void wxRadioButton::ChangeBackgroundColour()
137 wxWindow::ChangeBackgroundColour();
139 // What colour should this be?
140 wxColour colour
= *wxBLACK
;
141 WXPixel selectPixel
= colour
.AllocColour(XtDisplay((Widget
)m_mainWidget
));
143 XtVaSetValues ((Widget
) GetMainWidget(),
144 XmNselectColor
, selectPixel
,
148 void wxRadioButtonCallback (Widget
WXUNUSED(w
), XtPointer clientData
,
149 XmToggleButtonCallbackStruct
* cbs
)
154 wxRadioButton
*item
= (wxRadioButton
*) clientData
;
155 if (item
->InSetValue())
158 //based on mac/radiobut.cpp
159 wxRadioButton
* old
= item
->ClearSelections();
160 item
->SetValue(true);
164 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
,
166 event
.SetEventObject(old
);
167 event
.SetInt( false );
168 old
->ProcessCommand(event
);
170 wxCommandEvent
event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, item
->GetId() );
171 event2
.SetEventObject(item
);
172 event2
.SetInt( true );
173 item
->ProcessCommand(event2
);
176 wxRadioButton
* wxRadioButton::AddInCycle(wxRadioButton
*cycle
)
184 wxRadioButton
* current
= cycle
;
185 while ( current
->m_cycle
!= cycle
)
186 current
= current
->m_cycle
;
188 current
->m_cycle
= this;
194 wxRadioButton
* wxRadioButton::ClearSelections()
196 wxRadioButton
* cycle
= NextInCycle();
197 wxRadioButton
* old
= 0;
201 while (cycle
!= this)
203 if ( cycle
->GetValue() )
206 cycle
->SetValue(false);
208 cycle
= cycle
->NextInCycle();
215 void wxRadioButton::RemoveFromCycle()
217 wxRadioButton
* curr
= NextInCycle();
221 if( curr
->NextInCycle() == this )
223 curr
->m_cycle
= this->m_cycle
;
227 curr
= curr
->NextInCycle();