1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxRadioButton
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "radiobut.h"
17 #define XtDisplay XTDISPLAY
22 #include "wx/radiobut.h"
26 #pragma message disable nosimpint
28 #include <Xm/ToggleB.h>
29 #include <Xm/ToggleBG.h>
31 #pragma message enable nosimpint
34 #include "wx/motif/private.h"
36 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
37 XmToggleButtonCallbackStruct
* cbs
);
39 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
41 wxRadioButton::wxRadioButton()
45 bool wxRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
46 const wxString
& label
,
48 const wxSize
& size
, long style
,
49 const wxValidator
& validator
,
52 if( !CreateControl( parent
, id
, pos
, size
, style
, validator
, name
) )
55 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
57 wxString
label1(wxStripMenuCodes(label
));
59 wxXmString
text( label1
);
61 WXFontType fontType
= m_font
.GetFontType(XtDisplay(parentWidget
));
63 Widget radioButtonWidget
= XtVaCreateManagedWidget ("toggle",
65 xmToggleButtonGadgetClass
, parentWidget
,
67 xmToggleButtonWidgetClass
, parentWidget
,
69 wxFont::GetFontTag(), fontType
,
70 XmNlabelString
, text(),
71 XmNfillOnSelect
, True
,
72 XmNindicatorType
, XmONE_OF_MANY
, // diamond-shape
75 XtAddCallback (radioButtonWidget
,
76 XmNvalueChangedCallback
,
77 (XtCallbackProc
)wxRadioButtonCallback
,
80 m_mainWidget
= (WXWidget
) radioButtonWidget
;
82 XtManageChild (radioButtonWidget
);
84 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
,
85 pos
.x
, pos
.y
, size
.x
, size
.y
);
87 ChangeBackgroundColour();
89 //copied from mac/radiobut.cpp (from here till "return TRUE;")
92 if (HasFlag(wxRB_GROUP
))
98 /* search backward for last group start */
99 wxRadioButton
*chief
= (wxRadioButton
*) NULL
;
100 wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetLast();
103 wxWindow
*child
= node
->GetData();
104 if (child
->IsKindOf( CLASSINFO( wxRadioButton
) ) )
106 chief
= (wxRadioButton
*) child
;
107 if (child
->HasFlag(wxRB_GROUP
)) break;
109 node
= node
->GetPrevious();
111 AddInCycle( chief
) ;
116 void wxRadioButton::SetValue(bool value
)
118 if (GetValue() == value
)
122 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) value
, FALSE
);
123 m_inSetValue
= FALSE
;
128 // Get single selection, for single choice list items
129 bool wxRadioButton::GetValue() const
131 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
134 void wxRadioButton::Command (wxCommandEvent
& event
)
136 SetValue ( (event
.m_commandInt
!= 0) );
137 ProcessCommand (event
);
140 void wxRadioButton::ChangeBackgroundColour()
142 wxWindow::ChangeBackgroundColour();
144 // What colour should this be?
145 int selectPixel
= wxBLACK
->AllocColour(XtDisplay((Widget
)m_mainWidget
));
147 XtVaSetValues ((Widget
) GetMainWidget(),
148 XmNselectColor
, selectPixel
,
152 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
153 XmToggleButtonCallbackStruct
* cbs
)
158 wxRadioButton
*item
= (wxRadioButton
*) clientData
;
159 if (item
->InSetValue())
162 //based on mac/radiobut.cpp
163 wxRadioButton
* old
= item
->ClearSelections();
164 item
->SetValue(TRUE
);
168 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
,
170 event
.SetEventObject(old
);
171 event
.SetInt( FALSE
);
172 old
->ProcessCommand(event
);
174 wxCommandEvent
event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, item
->GetId() );
175 event2
.SetEventObject(item
);
176 event2
.SetInt( TRUE
);
177 item
->ProcessCommand(event2
);
180 wxRadioButton
* wxRadioButton::AddInCycle(wxRadioButton
*cycle
)
183 wxRadioButton
* current
;
193 while ((next
= current
->m_cycle
) != cycle
)
194 current
= current
->m_cycle
;
196 current
->m_cycle
= this;
201 wxRadioButton
* wxRadioButton::ClearSelections()
203 wxRadioButton
* cycle
= NextInCycle();
204 wxRadioButton
* old
= 0;
208 while (cycle
!= this)
210 if ( cycle
->GetValue() )
213 cycle
->SetValue(FALSE
);
215 cycle
= cycle
->NextInCycle();
222 void wxRadioButton::RemoveFromCycle()
224 wxRadioButton
* curr
= NextInCycle();
228 if( curr
->NextInCycle() == this )
230 curr
->m_cycle
= this->m_cycle
;
234 curr
= curr
->NextInCycle();