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 #include <Xm/LabelG.h>
21 #include <Xm/ToggleB.h>
22 #include <Xm/ToggleBG.h>
23 #include <Xm/RowColumn.h>
26 #include <wx/motif/private.h>
28 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
29 XmToggleButtonCallbackStruct
* cbs
);
31 #if !USE_SHARED_LIBRARY
32 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton
, wxControl
)
35 wxRadioButton::wxRadioButton()
39 bool wxRadioButton::Create(wxWindow
*parent
, wxWindowID id
,
40 const wxString
& label
,
42 const wxSize
& size
, long style
,
43 const wxValidator
& validator
,
47 SetValidator(validator
);
48 m_backgroundColour
= parent
->GetBackgroundColour();
49 m_foregroundColour
= parent
->GetForegroundColour();
50 m_windowFont
= parent
->GetFont();
52 if (parent
) parent
->AddChild(this);
55 m_windowId
= (int)NewControlId();
59 m_windowStyle
= style
;
61 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
63 wxString
label1(wxStripMenuCodes(label
));
65 XmString text
= XmStringCreateSimple ((char*) (const char*) label1
);
67 XmFontList fontList
= (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(parentWidget
));
69 Widget radioButtonWidget
= XtVaCreateManagedWidget ("toggle",
71 xmToggleButtonGadgetClass
, parentWidget
,
73 xmToggleButtonWidgetClass
, parentWidget
,
75 XmNfontList
, fontList
,
77 XmNfillOnSelect
, True
,
78 XmNindicatorType
, XmONE_OF_MANY
, // diamond-shape
82 XtAddCallback (radioButtonWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxRadioButtonCallback
,
83 (XtCallbackProc
) this);
85 m_mainWidget
= (WXWidget
) radioButtonWidget
;
87 XtManageChild (radioButtonWidget
);
89 SetCanAddEventHandler(TRUE
);
90 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
92 ChangeBackgroundColour();
97 void wxRadioButton::SetValue(bool value
)
100 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) value
, FALSE
);
101 m_inSetValue
= FALSE
;
104 // Get single selection, for single choice list items
105 bool wxRadioButton::GetValue() const
107 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
110 void wxRadioButton::Command (wxCommandEvent
& event
)
112 SetValue ( (event
.m_commandInt
!= 0) );
113 ProcessCommand (event
);
116 void wxRadioButton::ChangeFont(bool keepOriginalSize
)
118 wxWindow::ChangeFont(keepOriginalSize
);
121 void wxRadioButton::ChangeBackgroundColour()
123 wxWindow::ChangeBackgroundColour();
126 void wxRadioButton::ChangeForegroundColour()
128 wxWindow::ChangeForegroundColour();
131 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
132 XmToggleButtonCallbackStruct
* cbs
)
137 wxRadioButton
*item
= (wxRadioButton
*) clientData
;
138 if (item
->InSetValue())
141 wxCommandEvent
event (wxEVT_COMMAND_RADIOBUTTON_SELECTED
, item
->GetId());
142 event
.SetEventObject(item
);
144 item
->ProcessCommand (event
);