More Motif changes (colour/font stuff)
[wxWidgets.git] / src / motif / radiobut.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: radiobut.cpp
3 // Purpose: wxRadioButton
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "radiobut.h"
14 #endif
15
16 #include "wx/radiobut.h"
17 #include "wx/utils.h"
18
19 #include <Xm/Label.h>
20 #include <Xm/LabelG.h>
21 #include <Xm/ToggleB.h>
22 #include <Xm/ToggleBG.h>
23 #include <Xm/RowColumn.h>
24 #include <Xm/Form.h>
25
26 #include <wx/motif/private.h>
27
28 void wxRadioButtonCallback (Widget w, XtPointer clientData,
29 XmToggleButtonCallbackStruct * cbs);
30
31 #if !USE_SHARED_LIBRARY
32 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
33 #endif
34
35 wxRadioButton::wxRadioButton()
36 {
37 }
38
39 bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
40 const wxString& label,
41 const wxPoint& pos,
42 const wxSize& size, long style,
43 const wxValidator& validator,
44 const wxString& name)
45 {
46 SetName(name);
47 SetValidator(validator);
48 m_backgroundColour = parent->GetBackgroundColour();
49 m_foregroundColour = parent->GetForegroundColour();
50
51 if (parent) parent->AddChild(this);
52
53 if ( id == -1 )
54 m_windowId = (int)NewControlId();
55 else
56 m_windowId = id;
57
58 m_windowStyle = style ;
59
60 Widget parentWidget = (Widget) parent->GetClientWidget();
61
62 wxString label1(wxStripMenuCodes(label));
63
64 XmString text = XmStringCreateSimple ((char*) (const char*) label1);
65
66
67 Widget radioButtonWidget = XtVaCreateManagedWidget ("toggle",
68 #if wxUSE_GADGETS
69 xmToggleButtonGadgetClass, parentWidget,
70 #else
71 xmToggleButtonWidgetClass, parentWidget,
72 #endif
73 XmNlabelString, text,
74 XmNfillOnSelect, True,
75 XmNindicatorType, XmONE_OF_MANY, // diamond-shape
76 NULL);
77 XmStringFree (text);
78
79 XtAddCallback (radioButtonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxRadioButtonCallback,
80 (XtCallbackProc) this);
81
82 m_mainWidget = (WXWidget) radioButtonWidget;
83
84 XtManageChild (radioButtonWidget);
85
86 SetCanAddEventHandler(TRUE);
87 AttachWidget (parent, m_mainWidget, NULL, pos.x, pos.y, size.x, size.y);
88
89 SetFont(* parent->GetFont());
90 ChangeBackgroundColour();
91
92 return TRUE;
93 }
94
95 void wxRadioButton::SetValue(bool value)
96 {
97 m_inSetValue = TRUE;
98 XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) value, FALSE);
99 m_inSetValue = FALSE;
100 }
101
102 // Get single selection, for single choice list items
103 bool wxRadioButton::GetValue() const
104 {
105 return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
106 }
107
108 void wxRadioButton::Command (wxCommandEvent & event)
109 {
110 SetValue ( (event.m_commandInt != 0) );
111 ProcessCommand (event);
112 }
113
114 void wxRadioButton::ChangeFont()
115 {
116 wxWindow::ChangeFont();
117 }
118
119 void wxRadioButton::ChangeBackgroundColour()
120 {
121 wxWindow::ChangeBackgroundColour();
122 }
123
124 void wxRadioButton::ChangeForegroundColour()
125 {
126 wxWindow::ChangeForegroundColour();
127 }
128
129 void wxRadioButtonCallback (Widget w, XtPointer clientData,
130 XmToggleButtonCallbackStruct * cbs)
131 {
132 if (!cbs->set)
133 return;
134
135 wxRadioButton *item = (wxRadioButton *) clientData;
136 if (item->InSetValue())
137 return;
138
139 wxCommandEvent event (wxEVT_COMMAND_RADIOBUTTON_SELECTED, item->GetId());
140 event.SetEventObject(item);
141
142 item->ProcessCommand (event);
143 }
144