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"
16 #define XtDisplay XTDISPLAY
21 #include "wx/radiobut.h"
25 #pragma message disable nosimpint
27 #include <Xm/ToggleB.h>
28 #include <Xm/ToggleBG.h>
30 #pragma message enable nosimpint
33 #include "wx/motif/private.h"
35 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
36 XmToggleButtonCallbackStruct
* cbs
);
38 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
40 wxRadioButton::wxRadioButton()
44 bool wxRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
45 const wxString
& label
,
47 const wxSize
& size
, long style
,
48 const wxValidator
& validator
,
51 if( !CreateControl( parent
, id
, pos
, size
, style
, validator
, name
) )
54 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
55 Display
* dpy
= XtDisplay(parentWidget
);
57 wxString
label1(wxStripMenuCodes(label
));
59 wxXmString
text( label1
);
61 Widget radioButtonWidget
= XtVaCreateManagedWidget ("toggle",
63 xmToggleButtonGadgetClass
, parentWidget
,
65 xmToggleButtonWidgetClass
, parentWidget
,
67 wxFont::GetFontTag(), m_font
.GetFontTypeC(dpy
),
68 XmNlabelString
, text(),
69 XmNfillOnSelect
, True
,
70 XmNindicatorType
, XmONE_OF_MANY
, // diamond-shape
73 XtAddCallback (radioButtonWidget
,
74 XmNvalueChangedCallback
,
75 (XtCallbackProc
)wxRadioButtonCallback
,
78 m_mainWidget
= (WXWidget
) radioButtonWidget
;
80 XtManageChild (radioButtonWidget
);
82 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
,
83 pos
.x
, pos
.y
, size
.x
, size
.y
);
85 ChangeBackgroundColour();
87 //copied from mac/radiobut.cpp (from here till "return true;")
90 if (HasFlag(wxRB_GROUP
))
96 /* search backward for last group start */
97 wxRadioButton
*chief
= (wxRadioButton
*) NULL
;
98 wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetLast();
101 wxWindow
*child
= node
->GetData();
102 if (child
->IsKindOf( CLASSINFO( wxRadioButton
) ) )
104 chief
= (wxRadioButton
*) child
;
105 if (child
->HasFlag(wxRB_GROUP
)) break;
107 node
= node
->GetPrevious();
109 AddInCycle( chief
) ;
114 void wxRadioButton::SetValue(bool value
)
116 if (GetValue() == value
)
120 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) value
, False
);
121 m_inSetValue
= false;
126 // Get single selection, for single choice list items
127 bool wxRadioButton::GetValue() const
129 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
132 void wxRadioButton::Command (wxCommandEvent
& event
)
134 SetValue ( (event
.GetInt() != 0) );
135 ProcessCommand (event
);
138 void wxRadioButton::ChangeBackgroundColour()
140 wxWindow::ChangeBackgroundColour();
142 // What colour should this be?
143 int selectPixel
= wxBLACK
->AllocColour(XtDisplay((Widget
)m_mainWidget
));
145 XtVaSetValues ((Widget
) GetMainWidget(),
146 XmNselectColor
, selectPixel
,
150 void wxRadioButtonCallback (Widget
WXUNUSED(w
), XtPointer clientData
,
151 XmToggleButtonCallbackStruct
* cbs
)
156 wxRadioButton
*item
= (wxRadioButton
*) clientData
;
157 if (item
->InSetValue())
160 //based on mac/radiobut.cpp
161 wxRadioButton
* old
= item
->ClearSelections();
162 item
->SetValue(true);
166 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
,
168 event
.SetEventObject(old
);
169 event
.SetInt( false );
170 old
->ProcessCommand(event
);
172 wxCommandEvent
event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, item
->GetId() );
173 event2
.SetEventObject(item
);
174 event2
.SetInt( true );
175 item
->ProcessCommand(event2
);
178 wxRadioButton
* wxRadioButton::AddInCycle(wxRadioButton
*cycle
)
186 wxRadioButton
* current
= cycle
;
187 while ( current
->m_cycle
!= cycle
)
188 current
= current
->m_cycle
;
190 current
->m_cycle
= this;
196 wxRadioButton
* wxRadioButton::ClearSelections()
198 wxRadioButton
* cycle
= NextInCycle();
199 wxRadioButton
* old
= 0;
203 while (cycle
!= this)
205 if ( cycle
->GetValue() )
208 cycle
->SetValue(false);
210 cycle
= cycle
->NextInCycle();
217 void wxRadioButton::RemoveFromCycle()
219 wxRadioButton
* curr
= NextInCycle();
223 if( curr
->NextInCycle() == this )
225 curr
->m_cycle
= this->m_cycle
;
229 curr
= curr
->NextInCycle();