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_font
= 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_font
.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();
125 // What colour should this be?
126 int selectPixel
= wxBLACK
->AllocColour(wxGetDisplay());
128 XtVaSetValues ((Widget
) GetMainWidget(),
129 XmNselectColor
, selectPixel
,
133 void wxRadioButton::ChangeForegroundColour()
135 wxWindow::ChangeForegroundColour();
138 void wxRadioButtonCallback (Widget w
, XtPointer clientData
,
139 XmToggleButtonCallbackStruct
* cbs
)
144 wxRadioButton
*item
= (wxRadioButton
*) clientData
;
145 if (item
->InSetValue())
148 wxCommandEvent
event (wxEVT_COMMAND_RADIOBUTTON_SELECTED
, item
->GetId());
149 event
.SetEventObject(item
);
151 item
->ProcessCommand (event
);