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 #pragma message disable nosimpint
23 #include <Xm/LabelG.h>
24 #include <Xm/ToggleB.h>
25 #include <Xm/ToggleBG.h>
26 #include <Xm/RowColumn.h>
29 #pragma message enable nosimpint
32 #include "wx/motif/private.h"
34 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
35 XmToggleButtonCallbackStruct
* cbs
);
37 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
39 wxRadioButton::wxRadioButton()
43 bool wxRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
44 const wxString
& label
,
46 const wxSize
& size
, long style
,
47 const wxValidator
& validator
,
51 SetValidator(validator
);
52 m_backgroundColour
= parent
->GetBackgroundColour();
53 m_foregroundColour
= parent
->GetForegroundColour();
54 m_font
= parent
->GetFont();
56 if (parent
) parent
->AddChild(this);
59 m_windowId
= (int)NewControlId();
63 m_windowStyle
= style
;
65 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
67 wxString
label1(wxStripMenuCodes(label
));
69 XmString text
= XmStringCreateSimple ((char*) (const char*) label1
);
71 XmFontList fontList
= (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(parentWidget
));
73 Widget radioButtonWidget
= XtVaCreateManagedWidget ("toggle",
75 xmToggleButtonGadgetClass
, parentWidget
,
77 xmToggleButtonWidgetClass
, parentWidget
,
79 XmNfontList
, fontList
,
81 XmNfillOnSelect
, True
,
82 XmNindicatorType
, XmONE_OF_MANY
, // diamond-shape
87 #pragma message disable voiincconext
88 // VMS gives here the compiler warning:
89 // conversion from pointer to function to void* permitted
92 XtAddCallback (radioButtonWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxRadioButtonCallback
,
93 (XtCallbackProc
) this);
95 #pragma message enable voiincconext
98 m_mainWidget
= (WXWidget
) radioButtonWidget
;
100 XtManageChild (radioButtonWidget
);
102 SetCanAddEventHandler(TRUE
);
103 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
105 ChangeBackgroundColour();
110 void wxRadioButton::SetValue(bool value
)
113 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) value
, FALSE
);
114 m_inSetValue
= FALSE
;
117 // Get single selection, for single choice list items
118 bool wxRadioButton::GetValue() const
120 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
123 void wxRadioButton::Command (wxCommandEvent
& event
)
125 SetValue ( (event
.m_commandInt
!= 0) );
126 ProcessCommand (event
);
129 void wxRadioButton::ChangeFont(bool keepOriginalSize
)
131 wxWindow::ChangeFont(keepOriginalSize
);
134 void wxRadioButton::ChangeBackgroundColour()
136 wxWindow::ChangeBackgroundColour();
138 // What colour should this be?
139 int selectPixel
= wxBLACK
->AllocColour(wxGetDisplay());
141 XtVaSetValues ((Widget
) GetMainWidget(),
142 XmNselectColor
, selectPixel
,
146 void wxRadioButton::ChangeForegroundColour()
148 wxWindow::ChangeForegroundColour();
151 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
152 XmToggleButtonCallbackStruct
* cbs
)
157 wxRadioButton
*item
= (wxRadioButton
*) clientData
;
158 if (item
->InSetValue())
161 wxCommandEvent
event (wxEVT_COMMAND_RADIOBUTTON_SELECTED
, item
->GetId());
162 event
.SetEventObject(item
);
164 item
->ProcessCommand (event
);