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 #if !USE_SHARED_LIBRARY
38 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
41 wxRadioButton::wxRadioButton()
45 bool wxRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
46 const wxString
& label
,
48 const wxSize
& size
, long style
,
49 const wxValidator
& validator
,
53 SetValidator(validator
);
54 m_backgroundColour
= parent
->GetBackgroundColour();
55 m_foregroundColour
= parent
->GetForegroundColour();
56 m_font
= parent
->GetFont();
58 if (parent
) parent
->AddChild(this);
61 m_windowId
= (int)NewControlId();
65 m_windowStyle
= style
;
67 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
69 wxString
label1(wxStripMenuCodes(label
));
71 XmString text
= XmStringCreateSimple ((char*) (const char*) label1
);
73 XmFontList fontList
= (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(parentWidget
));
75 Widget radioButtonWidget
= XtVaCreateManagedWidget ("toggle",
77 xmToggleButtonGadgetClass
, parentWidget
,
79 xmToggleButtonWidgetClass
, parentWidget
,
81 XmNfontList
, fontList
,
83 XmNfillOnSelect
, True
,
84 XmNindicatorType
, XmONE_OF_MANY
, // diamond-shape
89 #pragma message disable voiincconext
90 // VMS gives here the compiler warning:
91 // conversion from pointer to function to void* permitted
94 XtAddCallback (radioButtonWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxRadioButtonCallback
,
95 (XtCallbackProc
) this);
97 #pragma message enable voiincconext
100 m_mainWidget
= (WXWidget
) radioButtonWidget
;
102 XtManageChild (radioButtonWidget
);
104 SetCanAddEventHandler(TRUE
);
105 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
107 ChangeBackgroundColour();
112 void wxRadioButton::SetValue(bool value
)
115 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) value
, FALSE
);
116 m_inSetValue
= FALSE
;
119 // Get single selection, for single choice list items
120 bool wxRadioButton::GetValue() const
122 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
125 void wxRadioButton::Command (wxCommandEvent
& event
)
127 SetValue ( (event
.m_commandInt
!= 0) );
128 ProcessCommand (event
);
131 void wxRadioButton::ChangeFont(bool keepOriginalSize
)
133 wxWindow::ChangeFont(keepOriginalSize
);
136 void wxRadioButton::ChangeBackgroundColour()
138 wxWindow::ChangeBackgroundColour();
140 // What colour should this be?
141 int selectPixel
= wxBLACK
->AllocColour(wxGetDisplay());
143 XtVaSetValues ((Widget
) GetMainWidget(),
144 XmNselectColor
, selectPixel
,
148 void wxRadioButton::ChangeForegroundColour()
150 wxWindow::ChangeForegroundColour();
153 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
154 XmToggleButtonCallbackStruct
* cbs
)
159 wxRadioButton
*item
= (wxRadioButton
*) clientData
;
160 if (item
->InSetValue())
163 wxCommandEvent
event (wxEVT_COMMAND_RADIOBUTTON_SELECTED
, item
->GetId());
164 event
.SetEventObject(item
);
166 item
->ProcessCommand (event
);