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();
107 void wxRadioButton::SetValue(bool value
)
110 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) value
, FALSE
);
111 m_inSetValue
= FALSE
;
114 // Get single selection, for single choice list items
115 bool wxRadioButton::GetValue() const
117 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
120 void wxRadioButton::Command (wxCommandEvent
& event
)
122 SetValue ( (event
.m_commandInt
!= 0) );
123 ProcessCommand (event
);
126 void wxRadioButton::ChangeFont(bool keepOriginalSize
)
128 wxWindow::ChangeFont(keepOriginalSize
);
131 void wxRadioButton::ChangeBackgroundColour()
133 wxWindow::ChangeBackgroundColour();
135 // What colour should this be?
136 int selectPixel
= wxBLACK
->AllocColour(wxGetDisplay());
138 XtVaSetValues ((Widget
) GetMainWidget(),
139 XmNselectColor
, selectPixel
,
143 void wxRadioButton::ChangeForegroundColour()
145 wxWindow::ChangeForegroundColour();
148 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
149 XmToggleButtonCallbackStruct
* cbs
)
154 wxRadioButton
*item
= (wxRadioButton
*) clientData
;
155 if (item
->InSetValue())
158 wxCommandEvent
event (wxEVT_COMMAND_RADIOBUTTON_SELECTED
, item
->GetId());
159 event
.SetEventObject(item
);
161 item
->ProcessCommand (event
);