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 SetCanAddEventHandler(TRUE
);
99 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
101 ChangeBackgroundColour();
103 //copied from mac/radiobut.cpp (from here till "return TRUE;")
106 if (HasFlag(wxRB_GROUP
))
112 /* search backward for last group start */
113 wxRadioButton
*chief
= (wxRadioButton
*) NULL
;
114 wxWindowList::Node
*node
= parent
->GetChildren().GetLast();
117 wxWindow
*child
= node
->GetData();
118 if (child
->IsKindOf( CLASSINFO( wxRadioButton
) ) )
120 chief
= (wxRadioButton
*) child
;
121 if (child
->HasFlag(wxRB_GROUP
)) break;
123 node
= node
->GetPrevious();
125 AddInCycle( chief
) ;
130 void wxRadioButton::SetValue(bool value
)
132 if (GetValue() == value
)
136 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) value
, FALSE
);
137 m_inSetValue
= FALSE
;
142 // Get single selection, for single choice list items
143 bool wxRadioButton::GetValue() const
145 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
148 void wxRadioButton::Command (wxCommandEvent
& event
)
150 SetValue ( (event
.m_commandInt
!= 0) );
151 ProcessCommand (event
);
154 void wxRadioButton::ChangeFont(bool keepOriginalSize
)
156 wxWindow::ChangeFont(keepOriginalSize
);
159 void wxRadioButton::ChangeBackgroundColour()
161 wxWindow::ChangeBackgroundColour();
163 // What colour should this be?
164 int selectPixel
= wxBLACK
->AllocColour(wxGetDisplay());
166 XtVaSetValues ((Widget
) GetMainWidget(),
167 XmNselectColor
, selectPixel
,
171 void wxRadioButton::ChangeForegroundColour()
173 wxWindow::ChangeForegroundColour();
176 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
177 XmToggleButtonCallbackStruct
* cbs
)
182 wxRadioButton
*item
= (wxRadioButton
*) clientData
;
183 if (item
->InSetValue())
186 //based on mac/radiobut.cpp
187 wxRadioButton
* old
= item
->ClearSelections();
188 item
->SetValue(TRUE
);
192 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
,
194 event
.SetEventObject(old
);
195 event
.SetInt( FALSE
);
196 old
->ProcessCommand(event
);
198 wxCommandEvent
event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, item
->GetId() );
199 event2
.SetEventObject(item
);
200 event2
.SetInt( TRUE
);
201 item
->ProcessCommand(event2
);
204 wxRadioButton
* wxRadioButton::AddInCycle(wxRadioButton
*cycle
)
207 wxRadioButton
* current
;
217 while ((next
= current
->m_cycle
) != cycle
)
218 current
= current
->m_cycle
;
220 current
->m_cycle
= this;
225 wxRadioButton
* wxRadioButton::ClearSelections()
227 wxRadioButton
* cycle
= NextInCycle();
228 wxRadioButton
* old
= 0;
232 while (cycle
!= this)
234 if ( cycle
->GetValue() )
237 cycle
->SetValue(FALSE
);
239 cycle
= cycle
->NextInCycle();
246 void wxRadioButton::RemoveFromCycle()
248 wxRadioButton
* curr
= NextInCycle();
252 if( curr
->NextInCycle() == this )
254 curr
->m_cycle
= this->m_cycle
;
258 curr
= curr
->NextInCycle();