]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/motif/slider.cpp
fixed wxTaskBarIcon compilation
[wxWidgets.git] / src / motif / slider.cpp
... / ...
CommitLineData
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#ifdef __VMS__
20#pragma message disable nosimpint
21#endif
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>
27#ifdef __VMS__
28#pragma message enable nosimpint
29#endif
30
31#include "wx/motif/private.h"
32
33void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs);
34
35IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
36
37BEGIN_EVENT_TABLE(wxSlider, wxControl)
38END_EVENT_TABLE()
39
40
41
42// Slider
43wxSlider::wxSlider()
44{
45 m_pageSize = 1;
46 m_lineSize = 1;
47 m_rangeMax = 0;
48 m_rangeMin = 0;
49 m_tickFreq = 0;
50}
51
52bool wxSlider::Create(wxWindow *parent, wxWindowID id,
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)
58{
59 if ( !((style & wxSL_HORIZONTAL) || (style & wxSL_VERTICAL)) )
60 style |= wxSL_HORIZONTAL;
61
62 SetName(name);
63 SetValidator(validator);
64 m_backgroundColour = parent->GetBackgroundColour();
65 m_foregroundColour = parent->GetForegroundColour();
66
67 if (parent) parent->AddChild(this);
68
69 m_lineSize = 1;
70 m_windowStyle = style;
71 m_tickFreq = 0;
72
73 if ( id == -1 )
74 m_windowId = (int)NewControlId();
75 else
76 m_windowId = id;
77
78 m_rangeMax = maxValue;
79 m_rangeMin = minValue;
80
81 // Not used in Motif, I think
82 m_pageSize = (int)((maxValue-minValue)/10);
83
84 Widget parentWidget = (Widget) parent->GetClientWidget();
85
86 Widget sliderWidget = XtVaCreateManagedWidget ("sliderWidget",
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);
97
98 m_mainWidget = (WXWidget) sliderWidget;
99
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
105 if(style & wxSL_NOTIFY_DRAG)
106 XtAddCallback (sliderWidget, XmNdragCallback,
107 (XtCallbackProc) wxSliderCallback, (XtPointer) this);
108 else
109 XtAddCallback (sliderWidget, XmNvalueChangedCallback,
110 (XtCallbackProc) wxSliderCallback, (XtPointer) this);
111#ifdef __VMS__
112#pragma message enable codcauunr
113#endif
114
115 XtAddCallback (sliderWidget, XmNdragCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this);
116
117 m_font = parent->GetFont();
118
119 ChangeFont(FALSE);
120 SetCanAddEventHandler(TRUE);
121 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
122
123 ChangeBackgroundColour();
124
125 return TRUE;
126}
127
128wxSlider::~wxSlider()
129{
130}
131
132int wxSlider::GetValue() const
133{
134 int val;
135 XtVaGetValues ((Widget) m_mainWidget, XmNvalue, &val, NULL);
136 return val;
137}
138
139void wxSlider::SetValue(int value)
140{
141 XtVaSetValues ((Widget) m_mainWidget, XmNvalue, value, NULL);
142}
143
144void wxSlider::GetSize(int *width, int *height) const
145{
146 wxControl::GetSize(width, height);
147}
148
149void wxSlider::DoSetSize(int x, int y, int width, int height, int sizeFlags)
150{
151 Widget widget = (Widget) m_mainWidget;
152
153 bool managed = XtIsManaged(widget);
154
155 if (managed)
156 XtUnmanageChild (widget);
157
158 if (((m_windowStyle & wxHORIZONTAL) == wxHORIZONTAL) && (width > -1))
159 {
160 XtVaSetValues (widget, XmNscaleWidth, wxMax (width, 10), NULL);
161 }
162
163 if (((m_windowStyle & wxVERTICAL) == wxVERTICAL) && (height > -1))
164 {
165 XtVaSetValues (widget, XmNscaleHeight, wxMax (height, 10), NULL);
166 }
167
168 int xx = x; int yy = y;
169 AdjustForParentClientOrigin(xx, yy, sizeFlags);
170
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);
175
176 if (managed)
177 XtManageChild (widget);
178}
179
180void wxSlider::SetRange(int minValue, int maxValue)
181{
182 m_rangeMin = minValue;
183 m_rangeMax = maxValue;
184
185 XtVaSetValues ((Widget) m_mainWidget, XmNminimum, minValue, XmNmaximum, maxValue, NULL);
186}
187
188// For trackbars only
189void wxSlider::SetTickFreq(int n, int WXUNUSED(pos))
190{
191 // Not implemented in Motif
192 m_tickFreq = n;
193}
194
195void wxSlider::SetPageSize(int pageSize)
196{
197 // Not implemented in Motif
198 m_pageSize = pageSize;
199}
200
201int wxSlider::GetPageSize() const
202{
203 return m_pageSize;
204}
205
206void wxSlider::ClearSel()
207{
208 // Not implemented in Motif
209}
210
211void wxSlider::ClearTicks()
212{
213 // Not implemented in Motif
214}
215
216void wxSlider::SetLineSize(int lineSize)
217{
218 // Not implemented in Motif
219 m_lineSize = lineSize;
220}
221
222int wxSlider::GetLineSize() const
223{
224 // Not implemented in Motif
225 return m_lineSize;
226}
227
228int wxSlider::GetSelEnd() const
229{
230 // Not implemented in Motif
231 return 0;
232}
233
234int wxSlider::GetSelStart() const
235{
236 // Not implemented in Motif
237 return 0;
238}
239
240void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos))
241{
242 // Not implemented in Motif
243}
244
245void wxSlider::SetThumbLength(int WXUNUSED(len))
246{
247 // Not implemented in Motif (?)
248}
249
250int wxSlider::GetThumbLength() const
251{
252 // Not implemented in Motif (?)
253 return 0;
254}
255
256void wxSlider::SetTick(int WXUNUSED(tickPos))
257{
258 // Not implemented in Motif
259}
260
261void wxSlider::Command (wxCommandEvent & event)
262{
263 SetValue (event.GetInt());
264 ProcessCommand (event);
265}
266
267void wxSlider::ChangeFont(bool keepOriginalSize)
268{
269 wxWindow::ChangeFont(keepOriginalSize);
270}
271
272void wxSlider::ChangeBackgroundColour()
273{
274 wxWindow::ChangeBackgroundColour();
275}
276
277void wxSlider::ChangeForegroundColour()
278{
279 wxWindow::ChangeForegroundColour();
280}
281
282void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs)
283{
284 wxSlider *slider = (wxSlider *) clientData;
285 switch (cbs->reason)
286 {
287 case XmCR_VALUE_CHANGED:
288 case XmCR_DRAG:
289 default:
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.
294
295 wxScrollEvent event(wxEVT_SCROLL_THUMBTRACK, slider->GetId());
296 XtVaGetValues (widget, XmNvalue, &event.m_commandInt, NULL);
297 event.SetEventObject(slider);
298 slider->ProcessCommand(event);
299
300 // Also send a wxCommandEvent for compatibility.
301 wxCommandEvent event2(wxEVT_COMMAND_SLIDER_UPDATED, slider->GetId());
302 event2.SetEventObject(slider);
303 event2.SetInt( event.GetInt() );
304 slider->ProcessCommand(event2);
305 break;
306 }
307 }
308}
309