]>
Commit | Line | Data |
---|---|---|
4bb6408c JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: slider.cpp | |
3 | // Purpose: wxSlider | |
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 "slider.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/slider.h" | |
a4294b78 JS |
17 | #include "wx/utils.h" |
18 | ||
338dd992 JJ |
19 | #ifdef __VMS__ |
20 | #pragma message disable nosimpint | |
21 | #endif | |
a4294b78 JS |
22 | #include <Xm/Xm.h> |
23 | #include <Xm/Label.h> | |
24 | #include <Xm/LabelG.h> | |
25 | #include <Xm/RowColumn.h> | |
26 | #include <Xm/Scale.h> | |
338dd992 JJ |
27 | #ifdef __VMS__ |
28 | #pragma message enable nosimpint | |
29 | #endif | |
a4294b78 | 30 | |
3096bd2f | 31 | #include "wx/motif/private.h" |
a4294b78 JS |
32 | |
33 | void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs); | |
4bb6408c JS |
34 | |
35 | #if !USE_SHARED_LIBRARY | |
36 | IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) | |
37 | ||
38 | BEGIN_EVENT_TABLE(wxSlider, wxControl) | |
39 | END_EVENT_TABLE() | |
40 | #endif | |
41 | ||
42 | ||
43 | ||
44 | // Slider | |
45 | wxSlider::wxSlider() | |
46 | { | |
2d120f83 JS |
47 | m_pageSize = 1; |
48 | m_lineSize = 1; | |
49 | m_rangeMax = 0; | |
50 | m_rangeMin = 0; | |
51 | m_tickFreq = 0; | |
4bb6408c JS |
52 | } |
53 | ||
54 | bool wxSlider::Create(wxWindow *parent, wxWindowID id, | |
2d120f83 JS |
55 | int value, int minValue, int maxValue, |
56 | const wxPoint& pos, | |
57 | const wxSize& size, long style, | |
58 | const wxValidator& validator, | |
59 | const wxString& name) | |
ba7ce6a0 MB |
60 | { |
61 | if ( !((style & wxSL_HORIZONTAL) || (style & wxSL_VERTICAL)) ) | |
62 | style |= wxSL_HORIZONTAL; | |
63 | ||
4bb6408c JS |
64 | SetName(name); |
65 | SetValidator(validator); | |
0d57be45 JS |
66 | m_backgroundColour = parent->GetBackgroundColour(); |
67 | m_foregroundColour = parent->GetForegroundColour(); | |
31528cd3 | 68 | |
4bb6408c | 69 | if (parent) parent->AddChild(this); |
31528cd3 | 70 | |
4bb6408c JS |
71 | m_lineSize = 1; |
72 | m_windowStyle = style; | |
73 | m_tickFreq = 0; | |
31528cd3 | 74 | |
4bb6408c | 75 | if ( id == -1 ) |
2d120f83 | 76 | m_windowId = (int)NewControlId(); |
4bb6408c | 77 | else |
2d120f83 | 78 | m_windowId = id; |
31528cd3 | 79 | |
4bb6408c JS |
80 | m_rangeMax = maxValue; |
81 | m_rangeMin = minValue; | |
31528cd3 | 82 | |
a4294b78 | 83 | // Not used in Motif, I think |
4bb6408c | 84 | m_pageSize = (int)((maxValue-minValue)/10); |
31528cd3 | 85 | |
a4294b78 | 86 | Widget parentWidget = (Widget) parent->GetClientWidget(); |
31528cd3 | 87 | |
a4294b78 | 88 | Widget sliderWidget = XtVaCreateManagedWidget ("sliderWidget", |
2d120f83 JS |
89 | xmScaleWidgetClass, parentWidget, |
90 | XmNorientation, | |
91 | (((m_windowStyle & wxSL_VERTICAL) == wxSL_VERTICAL) ? XmVERTICAL : XmHORIZONTAL), | |
92 | XmNprocessingDirection, | |
93 | (((m_windowStyle & wxSL_VERTICAL) == wxSL_VERTICAL) ? XmMAX_ON_TOP : XmMAX_ON_RIGHT), | |
94 | XmNmaximum, maxValue, | |
95 | XmNminimum, minValue, | |
96 | XmNvalue, value, | |
97 | XmNshowValue, True, | |
98 | NULL); | |
31528cd3 | 99 | |
a4294b78 | 100 | m_mainWidget = (WXWidget) sliderWidget; |
31528cd3 | 101 | |
338dd992 JJ |
102 | #ifdef __VMS__ |
103 | #pragma message disable codcauunr | |
104 | // VMS gives here the compiler warning : | |
105 | // statement either is unreachable or causes unreachable code | |
106 | #endif | |
a4294b78 JS |
107 | if(style & wxSL_NOTIFY_DRAG) |
108 | XtAddCallback (sliderWidget, XmNdragCallback, | |
2d120f83 | 109 | (XtCallbackProc) wxSliderCallback, (XtPointer) this); |
a4294b78 JS |
110 | else |
111 | XtAddCallback (sliderWidget, XmNvalueChangedCallback, | |
2d120f83 | 112 | (XtCallbackProc) wxSliderCallback, (XtPointer) this); |
338dd992 JJ |
113 | #ifdef __VMS__ |
114 | #pragma message enable codcauunr | |
115 | #endif | |
31528cd3 | 116 | |
a4294b78 | 117 | XtAddCallback (sliderWidget, XmNdragCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this); |
31528cd3 | 118 | |
da175b2c | 119 | m_font = parent->GetFont(); |
31528cd3 | 120 | |
4b5f3fe6 | 121 | ChangeFont(FALSE); |
a4294b78 JS |
122 | SetCanAddEventHandler(TRUE); |
123 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); | |
31528cd3 | 124 | |
0d57be45 | 125 | ChangeBackgroundColour(); |
31528cd3 | 126 | |
a4294b78 | 127 | return TRUE; |
4bb6408c JS |
128 | } |
129 | ||
130 | wxSlider::~wxSlider() | |
131 | { | |
132 | } | |
133 | ||
134 | int wxSlider::GetValue() const | |
135 | { | |
a4294b78 JS |
136 | int val; |
137 | XtVaGetValues ((Widget) m_mainWidget, XmNvalue, &val, NULL); | |
138 | return val; | |
4bb6408c JS |
139 | } |
140 | ||
141 | void wxSlider::SetValue(int value) | |
142 | { | |
a4294b78 | 143 | XtVaSetValues ((Widget) m_mainWidget, XmNvalue, value, NULL); |
4bb6408c JS |
144 | } |
145 | ||
146 | void wxSlider::GetSize(int *width, int *height) const | |
147 | { | |
a4294b78 | 148 | wxControl::GetSize(width, height); |
4bb6408c JS |
149 | } |
150 | ||
bfc6fde4 | 151 | void wxSlider::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
4bb6408c | 152 | { |
2d120f83 | 153 | Widget widget = (Widget) m_mainWidget; |
31528cd3 | 154 | |
2d120f83 | 155 | bool managed = XtIsManaged(widget); |
31528cd3 | 156 | |
2d120f83 JS |
157 | if (managed) |
158 | XtUnmanageChild (widget); | |
31528cd3 | 159 | |
2d120f83 JS |
160 | if (((m_windowStyle & wxHORIZONTAL) == wxHORIZONTAL) && (width > -1)) |
161 | { | |
162 | XtVaSetValues (widget, XmNscaleWidth, wxMax (width, 10), NULL); | |
163 | } | |
31528cd3 | 164 | |
2d120f83 JS |
165 | if (((m_windowStyle & wxVERTICAL) == wxVERTICAL) && (height > -1)) |
166 | { | |
167 | XtVaSetValues (widget, XmNscaleHeight, wxMax (height, 10), NULL); | |
168 | } | |
31528cd3 | 169 | |
2d120f83 JS |
170 | int xx = x; int yy = y; |
171 | AdjustForParentClientOrigin(xx, yy, sizeFlags); | |
31528cd3 | 172 | |
2d120f83 JS |
173 | if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
174 | XtVaSetValues (widget, XmNx, xx, NULL); | |
175 | if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
176 | XtVaSetValues (widget, XmNy, yy, NULL); | |
31528cd3 | 177 | |
2d120f83 JS |
178 | if (managed) |
179 | XtManageChild (widget); | |
4bb6408c JS |
180 | } |
181 | ||
182 | void wxSlider::SetRange(int minValue, int maxValue) | |
183 | { | |
184 | m_rangeMin = minValue; | |
185 | m_rangeMax = maxValue; | |
31528cd3 | 186 | |
a4294b78 | 187 | XtVaSetValues ((Widget) m_mainWidget, XmNminimum, minValue, XmNmaximum, maxValue, NULL); |
4bb6408c JS |
188 | } |
189 | ||
190 | // For trackbars only | |
af111fc3 | 191 | void wxSlider::SetTickFreq(int n, int WXUNUSED(pos)) |
4bb6408c | 192 | { |
a4294b78 | 193 | // Not implemented in Motif |
4bb6408c JS |
194 | m_tickFreq = n; |
195 | } | |
196 | ||
197 | void wxSlider::SetPageSize(int pageSize) | |
198 | { | |
a4294b78 | 199 | // Not implemented in Motif |
4bb6408c JS |
200 | m_pageSize = pageSize; |
201 | } | |
202 | ||
203 | int wxSlider::GetPageSize() const | |
204 | { | |
205 | return m_pageSize; | |
206 | } | |
207 | ||
208 | void wxSlider::ClearSel() | |
209 | { | |
a4294b78 | 210 | // Not implemented in Motif |
4bb6408c JS |
211 | } |
212 | ||
213 | void wxSlider::ClearTicks() | |
214 | { | |
a4294b78 | 215 | // Not implemented in Motif |
4bb6408c JS |
216 | } |
217 | ||
218 | void wxSlider::SetLineSize(int lineSize) | |
219 | { | |
a4294b78 | 220 | // Not implemented in Motif |
4bb6408c | 221 | m_lineSize = lineSize; |
4bb6408c JS |
222 | } |
223 | ||
224 | int wxSlider::GetLineSize() const | |
225 | { | |
a4294b78 JS |
226 | // Not implemented in Motif |
227 | return m_lineSize; | |
4bb6408c JS |
228 | } |
229 | ||
230 | int wxSlider::GetSelEnd() const | |
231 | { | |
a4294b78 | 232 | // Not implemented in Motif |
4bb6408c JS |
233 | return 0; |
234 | } | |
235 | ||
236 | int wxSlider::GetSelStart() const | |
237 | { | |
a4294b78 | 238 | // Not implemented in Motif |
4bb6408c JS |
239 | return 0; |
240 | } | |
241 | ||
a4294b78 | 242 | void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos)) |
4bb6408c | 243 | { |
a4294b78 | 244 | // Not implemented in Motif |
4bb6408c JS |
245 | } |
246 | ||
a4294b78 | 247 | void wxSlider::SetThumbLength(int WXUNUSED(len)) |
4bb6408c | 248 | { |
a4294b78 | 249 | // Not implemented in Motif (?) |
4bb6408c JS |
250 | } |
251 | ||
252 | int wxSlider::GetThumbLength() const | |
253 | { | |
a4294b78 | 254 | // Not implemented in Motif (?) |
4bb6408c JS |
255 | return 0; |
256 | } | |
257 | ||
a4294b78 | 258 | void wxSlider::SetTick(int WXUNUSED(tickPos)) |
4bb6408c | 259 | { |
a4294b78 | 260 | // Not implemented in Motif |
4bb6408c JS |
261 | } |
262 | ||
263 | void wxSlider::Command (wxCommandEvent & event) | |
264 | { | |
2d120f83 JS |
265 | SetValue (event.GetInt()); |
266 | ProcessCommand (event); | |
4bb6408c JS |
267 | } |
268 | ||
4b5f3fe6 | 269 | void wxSlider::ChangeFont(bool keepOriginalSize) |
0d57be45 | 270 | { |
4b5f3fe6 | 271 | wxWindow::ChangeFont(keepOriginalSize); |
0d57be45 JS |
272 | } |
273 | ||
274 | void wxSlider::ChangeBackgroundColour() | |
275 | { | |
321db4b6 | 276 | wxWindow::ChangeBackgroundColour(); |
0d57be45 JS |
277 | } |
278 | ||
279 | void wxSlider::ChangeForegroundColour() | |
280 | { | |
321db4b6 | 281 | wxWindow::ChangeForegroundColour(); |
0d57be45 JS |
282 | } |
283 | ||
a4294b78 | 284 | void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs) |
4bb6408c | 285 | { |
a4294b78 JS |
286 | wxSlider *slider = (wxSlider *) clientData; |
287 | switch (cbs->reason) | |
288 | { | |
2d120f83 JS |
289 | case XmCR_VALUE_CHANGED: |
290 | case XmCR_DRAG: | |
291 | default: | |
a4294b78 JS |
292 | { |
293 | // TODO: the XmCR_VALUE_CHANGED case should be handled | |
294 | // differently (it's not sent continually as the slider moves). | |
295 | // In which case we need a similar behaviour for other platforms. | |
31528cd3 | 296 | |
a4294b78 JS |
297 | wxScrollEvent event(wxEVT_SCROLL_THUMBTRACK, slider->GetId()); |
298 | XtVaGetValues (widget, XmNvalue, &event.m_commandInt, NULL); | |
299 | event.SetEventObject(slider); | |
300 | slider->ProcessCommand(event); | |
31528cd3 | 301 | |
55acd85e JS |
302 | // Also send a wxCommandEvent for compatibility. |
303 | wxCommandEvent event2(wxEVT_COMMAND_SLIDER_UPDATED, slider->GetId()); | |
304 | event2.SetEventObject(slider); | |
305 | slider->ProcessCommand(event2); | |
a4294b78 JS |
306 | break; |
307 | } | |
308 | } | |
4bb6408c JS |
309 | } |
310 |