]>
Commit | Line | Data |
---|---|---|
4bb6408c JS |
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" | |
a4294b78 JS |
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); | |
4bb6408c JS |
30 | |
31 | #if !USE_SHARED_LIBRARY | |
32 | IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl) | |
33 | #endif | |
34 | ||
a4294b78 JS |
35 | wxRadioButton::wxRadioButton() |
36 | { | |
37 | m_labelWidget = (WXWidget) 0; | |
38 | m_formWidget = (WXWidget) 0; | |
39 | } | |
40 | ||
4bb6408c JS |
41 | bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, |
42 | const wxString& label, | |
43 | const wxPoint& pos, | |
44 | const wxSize& size, long style, | |
45 | const wxValidator& validator, | |
46 | const wxString& name) | |
47 | { | |
48 | SetName(name); | |
49 | SetValidator(validator); | |
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 | ||
a4294b78 | 60 | Widget parentWidget = (Widget) parent->GetClientWidget(); |
4bb6408c | 61 | |
a4294b78 JS |
62 | wxString label1(wxStripMenuCodes(label)); |
63 | ||
64 | XmString text = XmStringCreateSimple ((char*) (const char*) label1); | |
65 | ||
66 | Widget formWidget = XtVaCreateManagedWidget ((char*) (const char*) name, | |
67 | xmFormWidgetClass, parentWidget, | |
68 | XmNmarginHeight, 0, | |
69 | XmNmarginWidth, 0, | |
70 | NULL); | |
71 | ||
72 | m_formWidget = (WXWidget) formWidget; | |
73 | ||
74 | Widget labelWidget = XtVaCreateManagedWidget ((char*) (const char*) label1, | |
75 | #if wxUSE_GADGETS | |
76 | xmLabelGadgetClass, | |
77 | formWidget, | |
78 | #else | |
79 | xmLabelWidgetClass, formWidget, | |
80 | #endif | |
81 | XmNlabelString, text, | |
82 | NULL); | |
83 | m_labelWidget = (WXWidget) labelWidget; | |
84 | /* TODO | |
85 | if (labelFont) | |
86 | XtVaSetValues (labelWidget, | |
87 | XmNfontList, labelFont->GetInternalFont (XtDisplay(formWidget)), | |
88 | NULL); | |
89 | */ | |
90 | ||
91 | XmStringFree (text); | |
92 | ||
93 | Widget radioButtonWidget = XtVaCreateManagedWidget ("toggle", | |
94 | #if wxUSE_GADGETS | |
95 | xmToggleButtonGadgetClass, formWidget, | |
96 | #else | |
97 | xmToggleButtonWidgetClass, formWidget, | |
98 | #endif | |
99 | NULL); | |
100 | XtAddCallback (radioButtonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxRadioButtonCallback, | |
101 | (XtCallbackProc) this); | |
102 | ||
103 | m_mainWidget = (WXWidget) radioButtonWidget; | |
104 | ||
105 | /* TODO | |
106 | if (labelFont) | |
107 | XtVaSetValues (radioButtonWidget, | |
108 | XmNfontList, labelFont->GetInternalFont (XtDisplay(formWidget)), | |
109 | NULL); | |
110 | */ | |
111 | ||
112 | if (labelWidget) | |
113 | XtVaSetValues (labelWidget, | |
114 | XmNtopAttachment, XmATTACH_FORM, | |
115 | XmNleftAttachment, XmATTACH_FORM, | |
116 | XmNbottomAttachment, XmATTACH_FORM, | |
117 | XmNalignment, XmALIGNMENT_BEGINNING, | |
118 | NULL); | |
119 | XtVaSetValues (radioButtonWidget, | |
120 | XmNleftOffset, 4, | |
121 | XmNtopAttachment, XmATTACH_FORM, | |
122 | XmNbottomAttachment, XmATTACH_FORM, | |
123 | XmNleftAttachment, (Widget) m_labelWidget ? XmATTACH_WIDGET : XmATTACH_FORM, | |
124 | XmNleftWidget, (Widget) m_labelWidget ? (Widget) m_labelWidget : formWidget, | |
125 | NULL); | |
126 | ||
127 | XtManageChild (radioButtonWidget); | |
128 | ||
129 | SetCanAddEventHandler(TRUE); | |
130 | AttachWidget (parent, m_mainWidget, m_formWidget, pos.x, pos.y, size.x, size.y); | |
131 | ||
132 | SetFont(* parent->GetFont()); | |
133 | ChangeColour(m_mainWidget); | |
134 | ||
135 | return TRUE; | |
4bb6408c JS |
136 | } |
137 | ||
138 | void wxRadioButton::SetValue(bool value) | |
139 | { | |
a4294b78 JS |
140 | m_inSetValue = TRUE; |
141 | XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) value, FALSE); | |
142 | m_inSetValue = FALSE; | |
4bb6408c JS |
143 | } |
144 | ||
145 | // Get single selection, for single choice list items | |
146 | bool wxRadioButton::GetValue() const | |
147 | { | |
a4294b78 | 148 | return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0); |
4bb6408c JS |
149 | } |
150 | ||
151 | void wxRadioButton::Command (wxCommandEvent & event) | |
152 | { | |
153 | SetValue ( (event.m_commandInt != 0) ); | |
154 | ProcessCommand (event); | |
155 | } | |
156 | ||
a4294b78 JS |
157 | void wxRadioButtonCallback (Widget w, XtPointer clientData, |
158 | XmToggleButtonCallbackStruct * cbs) | |
159 | { | |
160 | if (!cbs->set) | |
161 | return; | |
162 | ||
163 | wxRadioButton *item = (wxRadioButton *) clientData; | |
164 | if (item->InSetValue()) | |
165 | return; | |
166 | ||
167 | wxCommandEvent event (wxEVT_COMMAND_RADIOBUTTON_SELECTED, item->GetId()); | |
168 | event.SetEventObject(item); | |
169 | ||
170 | item->ProcessCommand (event); | |
171 | } | |
4bb6408c | 172 |