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