1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxRadioButton
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "radiobut.h"
16 #include "wx/radiobut.h"
20 #include <Xm/LabelG.h>
21 #include <Xm/ToggleB.h>
22 #include <Xm/ToggleBG.h>
23 #include <Xm/RowColumn.h>
26 #include <wx/motif/private.h>
28 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
29 XmToggleButtonCallbackStruct
* cbs
);
31 #if !USE_SHARED_LIBRARY
32 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
35 wxRadioButton::wxRadioButton()
37 m_labelWidget
= (WXWidget
) 0;
38 m_formWidget
= (WXWidget
) 0;
41 bool wxRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
42 const wxString
& label
,
44 const wxSize
& size
, long style
,
45 const wxValidator
& validator
,
49 SetValidator(validator
);
50 m_backgroundColour
= parent
->GetBackgroundColour();
51 m_foregroundColour
= parent
->GetForegroundColour();
53 if (parent
) parent
->AddChild(this);
56 m_windowId
= (int)NewControlId();
60 m_windowStyle
= style
;
62 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
64 wxString
label1(wxStripMenuCodes(label
));
66 XmString text
= XmStringCreateSimple ((char*) (const char*) label1
);
68 Widget formWidget
= XtVaCreateManagedWidget ((char*) (const char*) name
,
69 xmFormWidgetClass
, parentWidget
,
74 m_formWidget
= (WXWidget
) formWidget
;
76 Widget labelWidget
= XtVaCreateManagedWidget ((char*) (const char*) label1
,
81 xmLabelWidgetClass
, formWidget
,
85 m_labelWidget
= (WXWidget
) labelWidget
;
88 XtVaSetValues (labelWidget,
89 XmNfontList, labelFont->GetInternalFont (XtDisplay(formWidget)),
95 Widget radioButtonWidget
= XtVaCreateManagedWidget ("toggle",
97 xmToggleButtonGadgetClass
, formWidget
,
99 xmToggleButtonWidgetClass
, formWidget
,
102 XtAddCallback (radioButtonWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxRadioButtonCallback
,
103 (XtCallbackProc
) this);
105 m_mainWidget
= (WXWidget
) radioButtonWidget
;
109 XtVaSetValues (radioButtonWidget,
110 XmNfontList, labelFont->GetInternalFont (XtDisplay(formWidget)),
115 XtVaSetValues (labelWidget
,
116 XmNtopAttachment
, XmATTACH_FORM
,
117 XmNleftAttachment
, XmATTACH_FORM
,
118 XmNbottomAttachment
, XmATTACH_FORM
,
119 XmNalignment
, XmALIGNMENT_BEGINNING
,
121 XtVaSetValues (radioButtonWidget
,
123 XmNtopAttachment
, XmATTACH_FORM
,
124 XmNbottomAttachment
, XmATTACH_FORM
,
125 XmNleftAttachment
, (Widget
) m_labelWidget
? XmATTACH_WIDGET
: XmATTACH_FORM
,
126 XmNleftWidget
, (Widget
) m_labelWidget
? (Widget
) m_labelWidget
: formWidget
,
129 XtManageChild (radioButtonWidget
);
131 SetCanAddEventHandler(TRUE
);
132 AttachWidget (parent
, m_mainWidget
, m_formWidget
, pos
.x
, pos
.y
, size
.x
, size
.y
);
134 SetFont(* parent
->GetFont());
135 ChangeBackgroundColour();
140 void wxRadioButton::SetValue(bool value
)
143 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) value
, FALSE
);
144 m_inSetValue
= FALSE
;
147 // Get single selection, for single choice list items
148 bool wxRadioButton::GetValue() const
150 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
153 void wxRadioButton::Command (wxCommandEvent
& event
)
155 SetValue ( (event
.m_commandInt
!= 0) );
156 ProcessCommand (event
);
159 void wxRadioButton::ChangeFont()
164 void wxRadioButton::ChangeBackgroundColour()
169 void wxRadioButton::ChangeForegroundColour()
174 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
175 XmToggleButtonCallbackStruct
* cbs
)
180 wxRadioButton
*item
= (wxRadioButton
*) clientData
;
181 if (item
->InSetValue())
184 wxCommandEvent
event (wxEVT_COMMAND_RADIOBUTTON_SELECTED
, item
->GetId());
185 event
.SetEventObject(item
);
187 item
->ProcessCommand (event
);