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 XmString text
= XmStringCreateSimple ((char*) (const char*) label1
);
77 XmFontList fontList
= (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(parentWidget
));
79 Widget radioButtonWidget
= XtVaCreateManagedWidget ("toggle",
81 xmToggleButtonGadgetClass
, parentWidget
,
83 xmToggleButtonWidgetClass
, parentWidget
,
85 XmNfontList
, fontList
,
87 XmNfillOnSelect
, True
,
88 XmNindicatorType
, XmONE_OF_MANY
, // diamond-shape
92 XtAddCallback (radioButtonWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxRadioButtonCallback
,
95 m_mainWidget
= (WXWidget
) radioButtonWidget
;
97 XtManageChild (radioButtonWidget
);
99 SetCanAddEventHandler(TRUE
);
100 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
102 ChangeBackgroundColour();
104 //copied from mac/radiobut.cpp (from here till "return TRUE;")
107 if (HasFlag(wxRB_GROUP
))
113 /* search backward for last group start */
114 wxRadioButton
*chief
= (wxRadioButton
*) NULL
;
115 wxWindowList::Node
*node
= parent
->GetChildren().GetLast();
118 wxWindow
*child
= node
->GetData();
119 if (child
->IsKindOf( CLASSINFO( wxRadioButton
) ) )
121 chief
= (wxRadioButton
*) child
;
122 if (child
->HasFlag(wxRB_GROUP
)) break;
124 node
= node
->GetPrevious();
126 AddInCycle( chief
) ;
131 void wxRadioButton::SetValue(bool value
)
133 if (GetValue() == value
)
137 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) value
, FALSE
);
138 m_inSetValue
= FALSE
;
143 // Get single selection, for single choice list items
144 bool wxRadioButton::GetValue() const
146 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
149 void wxRadioButton::Command (wxCommandEvent
& event
)
151 SetValue ( (event
.m_commandInt
!= 0) );
152 ProcessCommand (event
);
155 void wxRadioButton::ChangeFont(bool keepOriginalSize
)
157 wxWindow::ChangeFont(keepOriginalSize
);
160 void wxRadioButton::ChangeBackgroundColour()
162 wxWindow::ChangeBackgroundColour();
164 // What colour should this be?
165 int selectPixel
= wxBLACK
->AllocColour(wxGetDisplay());
167 XtVaSetValues ((Widget
) GetMainWidget(),
168 XmNselectColor
, selectPixel
,
172 void wxRadioButton::ChangeForegroundColour()
174 wxWindow::ChangeForegroundColour();
177 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
178 XmToggleButtonCallbackStruct
* cbs
)
183 wxRadioButton
*item
= (wxRadioButton
*) clientData
;
184 if (item
->InSetValue())
187 //based on mac/radiobut.cpp
188 wxRadioButton
* old
= item
->ClearSelections();
189 item
->SetValue(TRUE
);
193 wxCommandEvent
event(wxEVT_COMMAND_RADIOBUTTON_SELECTED
,
195 event
.SetEventObject(old
);
196 event
.SetInt( FALSE
);
197 old
->ProcessCommand(event
);
199 wxCommandEvent
event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED
, item
->GetId() );
200 event2
.SetEventObject(item
);
201 event2
.SetInt( TRUE
);
202 item
->ProcessCommand(event2
);
205 wxRadioButton
* wxRadioButton::AddInCycle(wxRadioButton
*cycle
)
208 wxRadioButton
* current
;
218 while ((next
= current
->m_cycle
) != cycle
)
219 current
= current
->m_cycle
;
221 current
->m_cycle
= this;
226 wxRadioButton
* wxRadioButton::ClearSelections()
228 wxRadioButton
* cycle
= NextInCycle();
229 wxRadioButton
* old
= 0;
233 while (cycle
!= this)
235 if ( cycle
->GetValue() )
238 cycle
->SetValue(FALSE
);
240 cycle
= cycle
->NextInCycle();
247 void wxRadioButton::RemoveFromCycle()
249 wxRadioButton
* curr
= NextInCycle();
253 if( curr
->NextInCycle() == this )
255 curr
->m_cycle
= this->m_cycle
;
259 curr
= curr
->NextInCycle();