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
20 #include "wx/radiobut.h"
24 #pragma message disable nosimpint
27 #include <Xm/LabelG.h>
28 #include <Xm/ToggleB.h>
29 #include <Xm/ToggleBG.h>
30 #include <Xm/RowColumn.h>
33 #pragma message enable nosimpint
36 #include "wx/motif/private.h"
38 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
39 XmToggleButtonCallbackStruct
* cbs
);
41 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
43 wxRadioButton::wxRadioButton()
47 bool wxRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
48 const wxString
& label
,
50 const wxSize
& size
, long style
,
51 const wxValidator
& validator
,
55 SetValidator(validator
);
56 m_backgroundColour
= parent
->GetBackgroundColour();
57 m_foregroundColour
= parent
->GetForegroundColour();
58 m_font
= parent
->GetFont();
60 if (parent
) parent
->AddChild(this);
63 m_windowId
= (int)NewControlId();
67 m_windowStyle
= style
;
69 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
71 wxString
label1(wxStripMenuCodes(label
));
73 XmString text
= XmStringCreateSimple ((char*) (const char*) label1
);
75 XmFontList fontList
= (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(parentWidget
));
77 Widget radioButtonWidget
= XtVaCreateManagedWidget ("toggle",
79 xmToggleButtonGadgetClass
, parentWidget
,
81 xmToggleButtonWidgetClass
, parentWidget
,
83 XmNfontList
, fontList
,
85 XmNfillOnSelect
, True
,
86 XmNindicatorType
, XmONE_OF_MANY
, // diamond-shape
91 #pragma message disable voiincconext
92 // VMS gives here the compiler warning:
93 // conversion from pointer to function to void* permitted
96 XtAddCallback (radioButtonWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxRadioButtonCallback
,
97 (XtCallbackProc
) this);
99 #pragma message enable voiincconext
102 m_mainWidget
= (WXWidget
) radioButtonWidget
;
104 XtManageChild (radioButtonWidget
);
106 SetCanAddEventHandler(TRUE
);
107 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
109 ChangeBackgroundColour();
114 void wxRadioButton::SetValue(bool value
)
117 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) value
, FALSE
);
118 m_inSetValue
= FALSE
;
121 // Get single selection, for single choice list items
122 bool wxRadioButton::GetValue() const
124 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
127 void wxRadioButton::Command (wxCommandEvent
& event
)
129 SetValue ( (event
.m_commandInt
!= 0) );
130 ProcessCommand (event
);
133 void wxRadioButton::ChangeFont(bool keepOriginalSize
)
135 wxWindow::ChangeFont(keepOriginalSize
);
138 void wxRadioButton::ChangeBackgroundColour()
140 wxWindow::ChangeBackgroundColour();
142 // What colour should this be?
143 int selectPixel
= wxBLACK
->AllocColour(wxGetDisplay());
145 XtVaSetValues ((Widget
) GetMainWidget(),
146 XmNselectColor
, selectPixel
,
150 void wxRadioButton::ChangeForegroundColour()
152 wxWindow::ChangeForegroundColour();
155 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
156 XmToggleButtonCallbackStruct
* cbs
)
161 wxRadioButton
*item
= (wxRadioButton
*) clientData
;
162 if (item
->InSetValue())
165 wxCommandEvent
event (wxEVT_COMMAND_RADIOBUTTON_SELECTED
, item
->GetId());
166 event
.SetEventObject(item
);
168 item
->ProcessCommand (event
);