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
90 XtAddCallback (radioButtonWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxRadioButtonCallback
,
93 m_mainWidget
= (WXWidget
) radioButtonWidget
;
95 XtManageChild (radioButtonWidget
);
97 SetCanAddEventHandler(TRUE
);
98 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
100 ChangeBackgroundColour();
105 void wxRadioButton::SetValue(bool value
)
108 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) value
, FALSE
);
109 m_inSetValue
= FALSE
;
112 // Get single selection, for single choice list items
113 bool wxRadioButton::GetValue() const
115 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
118 void wxRadioButton::Command (wxCommandEvent
& event
)
120 SetValue ( (event
.m_commandInt
!= 0) );
121 ProcessCommand (event
);
124 void wxRadioButton::ChangeFont(bool keepOriginalSize
)
126 wxWindow::ChangeFont(keepOriginalSize
);
129 void wxRadioButton::ChangeBackgroundColour()
131 wxWindow::ChangeBackgroundColour();
133 // What colour should this be?
134 int selectPixel
= wxBLACK
->AllocColour(wxGetDisplay());
136 XtVaSetValues ((Widget
) GetMainWidget(),
137 XmNselectColor
, selectPixel
,
141 void wxRadioButton::ChangeForegroundColour()
143 wxWindow::ChangeForegroundColour();
146 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
147 XmToggleButtonCallbackStruct
* cbs
)
152 wxRadioButton
*item
= (wxRadioButton
*) clientData
;
153 if (item
->InSetValue())
156 wxCommandEvent
event (wxEVT_COMMAND_RADIOBUTTON_SELECTED
, item
->GetId());
157 event
.SetEventObject(item
);
159 item
->ProcessCommand (event
);