]> git.saurik.com Git - wxWidgets.git/blame - src/motif/slider.cpp
1. Split{Horizontal|Vertical} now accept negative args to set the
[wxWidgets.git] / src / motif / slider.cpp
CommitLineData
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
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
27void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs);
4bb6408c
JS
28
29#if !USE_SHARED_LIBRARY
30IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
31
32BEGIN_EVENT_TABLE(wxSlider, wxControl)
33END_EVENT_TABLE()
34#endif
35
36
37
38// Slider
39wxSlider::wxSlider()
40{
41 m_pageSize = 1;
42 m_lineSize = 1;
43 m_rangeMax = 0;
44 m_rangeMin = 0;
45 m_tickFreq = 0;
46}
47
48bool 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);
0d57be45
JS
57 m_backgroundColour = parent->GetBackgroundColour();
58 m_foregroundColour = parent->GetForegroundColour();
4bb6408c
JS
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
a4294b78 74 // Not used in Motif, I think
4bb6408c
JS
75 m_pageSize = (int)((maxValue-minValue)/10);
76
a4294b78
JS
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 SetCanAddEventHandler(TRUE);
103 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
4bb6408c 104
a4294b78 105 SetFont(* parent->GetFont());
0d57be45 106 ChangeBackgroundColour();
a4294b78
JS
107
108 return TRUE;
4bb6408c
JS
109}
110
111wxSlider::~wxSlider()
112{
113}
114
115int wxSlider::GetValue() const
116{
a4294b78
JS
117 int val;
118 XtVaGetValues ((Widget) m_mainWidget, XmNvalue, &val, NULL);
119 return val;
4bb6408c
JS
120}
121
122void wxSlider::SetValue(int value)
123{
a4294b78 124 XtVaSetValues ((Widget) m_mainWidget, XmNvalue, value, NULL);
4bb6408c
JS
125}
126
127void wxSlider::GetSize(int *width, int *height) const
128{
a4294b78 129 wxControl::GetSize(width, height);
4bb6408c
JS
130}
131
132void wxSlider::SetSize(int x, int y, int width, int height, int sizeFlags)
133{
a4294b78
JS
134 Widget widget = (Widget) m_mainWidget;
135
136 bool managed = XtIsManaged(widget);
137
138 if (managed)
139 XtUnmanageChild (widget);
140
141 if (((m_windowStyle & wxHORIZONTAL) == wxHORIZONTAL) && (width > -1))
142 {
143 XtVaSetValues (widget, XmNscaleWidth, wxMax (width, 10), NULL);
144 }
145
146 if (((m_windowStyle & wxVERTICAL) == wxVERTICAL) && (height > -1))
147 {
148 XtVaSetValues (widget, XmNscaleHeight, wxMax (height, 10), NULL);
149 }
150
151 int xx = x; int yy = y;
152 AdjustForParentClientOrigin(xx, yy, sizeFlags);
153
154 if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
155 XtVaSetValues (widget, XmNx, xx, NULL);
156 if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
157 XtVaSetValues (widget, XmNy, yy, NULL);
158
159 if (managed)
160 XtManageChild (widget);
4bb6408c
JS
161}
162
163void wxSlider::SetRange(int minValue, int maxValue)
164{
165 m_rangeMin = minValue;
166 m_rangeMax = maxValue;
167
a4294b78 168 XtVaSetValues ((Widget) m_mainWidget, XmNminimum, minValue, XmNmaximum, maxValue, NULL);
4bb6408c
JS
169}
170
171// For trackbars only
172void wxSlider::SetTickFreq(int n, int pos)
173{
a4294b78 174 // Not implemented in Motif
4bb6408c
JS
175 m_tickFreq = n;
176}
177
178void wxSlider::SetPageSize(int pageSize)
179{
a4294b78 180 // Not implemented in Motif
4bb6408c
JS
181 m_pageSize = pageSize;
182}
183
184int wxSlider::GetPageSize() const
185{
186 return m_pageSize;
187}
188
189void wxSlider::ClearSel()
190{
a4294b78 191 // Not implemented in Motif
4bb6408c
JS
192}
193
194void wxSlider::ClearTicks()
195{
a4294b78 196 // Not implemented in Motif
4bb6408c
JS
197}
198
199void wxSlider::SetLineSize(int lineSize)
200{
a4294b78 201 // Not implemented in Motif
4bb6408c 202 m_lineSize = lineSize;
4bb6408c
JS
203}
204
205int wxSlider::GetLineSize() const
206{
a4294b78
JS
207 // Not implemented in Motif
208 return m_lineSize;
4bb6408c
JS
209}
210
211int wxSlider::GetSelEnd() const
212{
a4294b78 213 // Not implemented in Motif
4bb6408c
JS
214 return 0;
215}
216
217int wxSlider::GetSelStart() const
218{
a4294b78 219 // Not implemented in Motif
4bb6408c
JS
220 return 0;
221}
222
a4294b78 223void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos))
4bb6408c 224{
a4294b78 225 // Not implemented in Motif
4bb6408c
JS
226}
227
a4294b78 228void wxSlider::SetThumbLength(int WXUNUSED(len))
4bb6408c 229{
a4294b78 230 // Not implemented in Motif (?)
4bb6408c
JS
231}
232
233int wxSlider::GetThumbLength() const
234{
a4294b78 235 // Not implemented in Motif (?)
4bb6408c
JS
236 return 0;
237}
238
a4294b78 239void wxSlider::SetTick(int WXUNUSED(tickPos))
4bb6408c 240{
a4294b78 241 // Not implemented in Motif
4bb6408c
JS
242}
243
244void wxSlider::Command (wxCommandEvent & event)
245{
246 SetValue (event.GetInt());
247 ProcessCommand (event);
248}
249
0d57be45
JS
250void wxSlider::ChangeFont()
251{
252 // TODO
253}
254
255void wxSlider::ChangeBackgroundColour()
256{
257 // TODO
258}
259
260void wxSlider::ChangeForegroundColour()
261{
262 // TODO
263}
264
a4294b78 265void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs)
4bb6408c 266{
a4294b78
JS
267 wxSlider *slider = (wxSlider *) clientData;
268 switch (cbs->reason)
269 {
270 case XmCR_VALUE_CHANGED:
271 case XmCR_DRAG:
272 default:
273 {
274 // TODO: the XmCR_VALUE_CHANGED case should be handled
275 // differently (it's not sent continually as the slider moves).
276 // In which case we need a similar behaviour for other platforms.
277
278 wxScrollEvent event(wxEVT_SCROLL_THUMBTRACK, slider->GetId());
279 XtVaGetValues (widget, XmNvalue, &event.m_commandInt, NULL);
280 event.SetEventObject(slider);
281 slider->ProcessCommand(event);
282 break;
283 }
284 }
4bb6408c
JS
285}
286