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