1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxRadioButton
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "radiobut.h"
17 #define XtDisplay XTDISPLAY
22 #include "wx/radiobut.h"
26 #pragma message disable nosimpint
29 #include <Xm/LabelG.h>
30 #include <Xm/ToggleB.h>
31 #include <Xm/ToggleBG.h>
32 #include <Xm/RowColumn.h>
35 #pragma message enable nosimpint
38 #include "wx/motif/private.h"
40 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
41 XmToggleButtonCallbackStruct
* cbs
);
43 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
45 wxRadioButton::wxRadioButton()
49 bool wxRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
50 const wxString
& label
,
52 const wxSize
& size
, long style
,
53 const wxValidator
& validator
,
57 SetValidator(validator
);
58 m_backgroundColour
= parent
->GetBackgroundColour();
59 m_foregroundColour
= parent
->GetForegroundColour();
60 m_font
= parent
->GetFont();
62 if (parent
) parent
->AddChild(this);
65 m_windowId
= (int)NewControlId();
69 m_windowStyle
= style
;
71 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
73 wxString
label1(wxStripMenuCodes(label
));
75 wxXmString
text( label1
);
77 WXFontType fontType
= m_font
.GetFontType(XtDisplay(parentWidget
));
79 Widget radioButtonWidget
= XtVaCreateManagedWidget ("toggle",
81 xmToggleButtonGadgetClass
, parentWidget
,
83 xmToggleButtonWidgetClass
, parentWidget
,
85 wxFont::GetFontTag(), fontType
,
86 XmNlabelString
, text(),
87 XmNfillOnSelect
, True
,
88 XmNindicatorType
, XmONE_OF_MANY
, // diamond-shape
91 XtAddCallback (radioButtonWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxRadioButtonCallback
,
94 m_mainWidget
= (WXWidget
) radioButtonWidget
;
96 XtManageChild (radioButtonWidget
);
98 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
100 ChangeBackgroundColour();
102 //copied from mac/radiobut.cpp (from here till "return TRUE;")
105 if (HasFlag(wxRB_GROUP
))
111 /* search backward for last group start */
112 wxRadioButton
*chief
= (wxRadioButton
*) NULL
;
113 wxWindowList::Node
*node
= parent
->GetChildren().GetLast();
116 wxWindow
*child
= node
->GetData();
117 if (child
->IsKindOf( CLASSINFO( wxRadioButton
) ) )
119 chief
= (wxRadioButton
*) child
;
120 if (child
->HasFlag(wxRB_GROUP
)) break;
122 node
= node
->GetPrevious();
124 AddInCycle( chief
) ;
129 void wxRadioButton::SetValue(bool value
)
131 if (GetValue() == value
)
135 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) value
, FALSE
);
136 m_inSetValue
= FALSE
;
141 // Get single selection, for single choice list items
142 bool wxRadioButton::GetValue() const
144 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
147 void wxRadioButton::Command (wxCommandEvent
& event
)
149 SetValue ( (event
.m_commandInt
!= 0) );
150 ProcessCommand (event
);
153 void wxRadioButton::ChangeFont(bool keepOriginalSize
)
155 wxWindow::ChangeFont(keepOriginalSize
);
158 void wxRadioButton::ChangeBackgroundColour()
160 wxWindow::ChangeBackgroundColour();
162 // What colour should this be?
163 int selectPixel
= wxBLACK
->AllocColour(XtDisplay((Widget
)m_mainWidget
));
165 XtVaSetValues ((Widget
) GetMainWidget(),
166 XmNselectColor
, selectPixel
,
170 void wxRadioButton::ChangeForegroundColour()
172 wxWindow::ChangeForegroundColour();
175 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
176 XmToggleButtonCallbackStruct
* cbs
)
181 wxRadioButton
*item
= (wxRadioButton
*) clientData
;
182 if (item
->InSetValue())
185 //based on mac/radiobut.cpp
186 wxRadioButton
* old
= item
->ClearSelections();
187 item
->SetValue(TRUE
);
191 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
,
193 event
.SetEventObject(old
);
194 event
.SetInt( FALSE
);
195 old
->ProcessCommand(event
);
197 wxCommandEvent
event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, item
->GetId() );
198 event2
.SetEventObject(item
);
199 event2
.SetInt( TRUE
);
200 item
->ProcessCommand(event2
);
203 wxRadioButton
* wxRadioButton::AddInCycle(wxRadioButton
*cycle
)
206 wxRadioButton
* current
;
216 while ((next
= current
->m_cycle
) != cycle
)
217 current
= current
->m_cycle
;
219 current
->m_cycle
= this;
224 wxRadioButton
* wxRadioButton::ClearSelections()
226 wxRadioButton
* cycle
= NextInCycle();
227 wxRadioButton
* old
= 0;
231 while (cycle
!= this)
233 if ( cycle
->GetValue() )
236 cycle
->SetValue(FALSE
);
238 cycle
= cycle
->NextInCycle();
245 void wxRadioButton::RemoveFromCycle()
247 wxRadioButton
* curr
= NextInCycle();
251 if( curr
->NextInCycle() == this )
253 curr
->m_cycle
= this->m_cycle
;
257 curr
= curr
->NextInCycle();