]> git.saurik.com Git - wxWidgets.git/blob - src/motif/radiobut.cpp
Changed m_children to GetChildren() -- not all ports are the same!
[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 m_windowFont = parent->GetFont();
51
52 if (parent) parent->AddChild(this);
53
54 if ( id == -1 )
55 m_windowId = (int)NewControlId();
56 else
57 m_windowId = id;
58
59 m_windowStyle = style ;
60
61 Widget parentWidget = (Widget) parent->GetClientWidget();
62
63 wxString label1(wxStripMenuCodes(label));
64
65 XmString text = XmStringCreateSimple ((char*) (const char*) label1);
66
67 XmFontList fontList = (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay(parentWidget));
68
69 Widget radioButtonWidget = XtVaCreateManagedWidget ("toggle",
70 #if wxUSE_GADGETS
71 xmToggleButtonGadgetClass, parentWidget,
72 #else
73 xmToggleButtonWidgetClass, parentWidget,
74 #endif
75 XmNfontList, fontList,
76 XmNlabelString, text,
77 XmNfillOnSelect, True,
78 XmNindicatorType, XmONE_OF_MANY, // diamond-shape
79 NULL);
80 XmStringFree (text);
81
82 XtAddCallback (radioButtonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxRadioButtonCallback,
83 (XtCallbackProc) this);
84
85 m_mainWidget = (WXWidget) radioButtonWidget;
86
87 XtManageChild (radioButtonWidget);
88
89 SetCanAddEventHandler(TRUE);
90 AttachWidget (parent, m_mainWidget, NULL, pos.x, pos.y, size.x, size.y);
91
92 ChangeBackgroundColour();
93
94 return TRUE;
95 }
96
97 void wxRadioButton::SetValue(bool value)
98 {
99 m_inSetValue = TRUE;
100 XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) value, FALSE);
101 m_inSetValue = FALSE;
102 }
103
104 // Get single selection, for single choice list items
105 bool wxRadioButton::GetValue() const
106 {
107 return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
108 }
109
110 void wxRadioButton::Command (wxCommandEvent & event)
111 {
112 SetValue ( (event.m_commandInt != 0) );
113 ProcessCommand (event);
114 }
115
116 void wxRadioButton::ChangeFont(bool keepOriginalSize)
117 {
118 wxWindow::ChangeFont(keepOriginalSize);
119 }
120
121 void wxRadioButton::ChangeBackgroundColour()
122 {
123 wxWindow::ChangeBackgroundColour();
124 }
125
126 void wxRadioButton::ChangeForegroundColour()
127 {
128 wxWindow::ChangeForegroundColour();
129 }
130
131 void wxRadioButtonCallback (Widget w, XtPointer clientData,
132 XmToggleButtonCallbackStruct * cbs)
133 {
134 if (!cbs->set)
135 return;
136
137 wxRadioButton *item = (wxRadioButton *) clientData;
138 if (item->InSetValue())
139 return;
140
141 wxCommandEvent event (wxEVT_COMMAND_RADIOBUTTON_SELECTED, item->GetId());
142 event.SetEventObject(item);
143
144 item->ProcessCommand (event);
145 }
146