]> git.saurik.com Git - wxWidgets.git/blame - src/motif/slider.cpp
undid change of r44565: not taking hyphens into account entirely is a bad idea as...
[wxWidgets.git] / src / motif / slider.cpp
CommitLineData
4bb6408c 1/////////////////////////////////////////////////////////////////////////////
7520f3da 2// Name: src/motif/slider.cpp
4bb6408c
JS
3// Purpose: wxSlider
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
312ebad4 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
1248b41f
MB
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
312ebad4
WS
15#if wxUSE_SLIDER
16
4bb6408c 17#include "wx/slider.h"
de6185e2
WS
18
19#ifndef WX_PRECOMP
20 #include "wx/utils.h"
21#endif
a4294b78 22
338dd992
JJ
23#ifdef __VMS__
24#pragma message disable nosimpint
25#endif
a4294b78
JS
26#include <Xm/Xm.h>
27#include <Xm/Label.h>
28#include <Xm/LabelG.h>
29#include <Xm/RowColumn.h>
30#include <Xm/Scale.h>
338dd992
JJ
31#ifdef __VMS__
32#pragma message enable nosimpint
33#endif
a4294b78 34
3096bd2f 35#include "wx/motif/private.h"
a4294b78 36
ad60f069 37static void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs);
4bb6408c 38
4bb6408c
JS
39IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
40
41BEGIN_EVENT_TABLE(wxSlider, wxControl)
42END_EVENT_TABLE()
4bb6408c
JS
43
44
45
46// Slider
47wxSlider::wxSlider()
48{
2d120f83
JS
49 m_pageSize = 1;
50 m_lineSize = 1;
51 m_rangeMax = 0;
52 m_rangeMin = 0;
4bb6408c
JS
53}
54
55bool wxSlider::Create(wxWindow *parent, wxWindowID id,
2d120f83
JS
56 int value, int minValue, int maxValue,
57 const wxPoint& pos,
58 const wxSize& size, long style,
59 const wxValidator& validator,
60 const wxString& name)
93e73c74 61{
ba7ce6a0
MB
62 if ( !((style & wxSL_HORIZONTAL) || (style & wxSL_VERTICAL)) )
63 style |= wxSL_HORIZONTAL;
31528cd3 64
93e73c74
MB
65 if( !CreateControl( parent, id, pos, size, style, validator, name ) )
66 return false;
105fbe1f 67 PreCreation();
31528cd3 68
4bb6408c
JS
69 m_lineSize = 1;
70 m_windowStyle = style;
31528cd3 71
4bb6408c
JS
72 m_rangeMax = maxValue;
73 m_rangeMin = minValue;
31528cd3 74
a4294b78 75 // Not used in Motif, I think
4bb6408c 76 m_pageSize = (int)((maxValue-minValue)/10);
31528cd3 77
a4294b78 78 Widget parentWidget = (Widget) parent->GetClientWidget();
31528cd3 79
a4294b78 80 Widget sliderWidget = XtVaCreateManagedWidget ("sliderWidget",
2d120f83
JS
81 xmScaleWidgetClass, parentWidget,
82 XmNorientation,
83 (((m_windowStyle & wxSL_VERTICAL) == wxSL_VERTICAL) ? XmVERTICAL : XmHORIZONTAL),
84 XmNprocessingDirection,
85 (((m_windowStyle & wxSL_VERTICAL) == wxSL_VERTICAL) ? XmMAX_ON_TOP : XmMAX_ON_RIGHT),
86 XmNmaximum, maxValue,
87 XmNminimum, minValue,
88 XmNvalue, value,
89 XmNshowValue, True,
90 NULL);
31528cd3 91
a4294b78 92 m_mainWidget = (WXWidget) sliderWidget;
31528cd3 93
ad60f069 94 XtAddCallback (sliderWidget, XmNvalueChangedCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this);
a4294b78 95 XtAddCallback (sliderWidget, XmNdragCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this);
31528cd3 96
105fbe1f 97 PostCreation();
a4294b78 98 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
31528cd3 99
312ebad4 100 return true;
4bb6408c
JS
101}
102
103wxSlider::~wxSlider()
104{
105}
106
107int wxSlider::GetValue() const
108{
a4294b78
JS
109 int val;
110 XtVaGetValues ((Widget) m_mainWidget, XmNvalue, &val, NULL);
111 return val;
4bb6408c
JS
112}
113
114void wxSlider::SetValue(int value)
115{
a4294b78 116 XtVaSetValues ((Widget) m_mainWidget, XmNvalue, value, NULL);
4bb6408c
JS
117}
118
bfc6fde4 119void wxSlider::DoSetSize(int x, int y, int width, int height, int sizeFlags)
4bb6408c 120{
2d120f83 121 Widget widget = (Widget) m_mainWidget;
31528cd3 122
2d120f83 123 bool managed = XtIsManaged(widget);
31528cd3 124
2d120f83
JS
125 if (managed)
126 XtUnmanageChild (widget);
31528cd3 127
2d120f83
JS
128 if (((m_windowStyle & wxHORIZONTAL) == wxHORIZONTAL) && (width > -1))
129 {
130 XtVaSetValues (widget, XmNscaleWidth, wxMax (width, 10), NULL);
131 }
31528cd3 132
2d120f83
JS
133 if (((m_windowStyle & wxVERTICAL) == wxVERTICAL) && (height > -1))
134 {
135 XtVaSetValues (widget, XmNscaleHeight, wxMax (height, 10), NULL);
136 }
31528cd3 137
2d120f83
JS
138 int xx = x; int yy = y;
139 AdjustForParentClientOrigin(xx, yy, sizeFlags);
31528cd3 140
2d120f83
JS
141 if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
142 XtVaSetValues (widget, XmNx, xx, NULL);
143 if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
144 XtVaSetValues (widget, XmNy, yy, NULL);
31528cd3 145
2d120f83
JS
146 if (managed)
147 XtManageChild (widget);
4bb6408c
JS
148}
149
150void wxSlider::SetRange(int minValue, int maxValue)
151{
152 m_rangeMin = minValue;
153 m_rangeMax = maxValue;
31528cd3 154
a4294b78 155 XtVaSetValues ((Widget) m_mainWidget, XmNminimum, minValue, XmNmaximum, maxValue, NULL);
4bb6408c
JS
156}
157
158// For trackbars only
4bb6408c
JS
159void wxSlider::SetPageSize(int pageSize)
160{
a4294b78 161 // Not implemented in Motif
4bb6408c
JS
162 m_pageSize = pageSize;
163}
164
165int wxSlider::GetPageSize() const
166{
167 return m_pageSize;
168}
169
4bb6408c
JS
170void wxSlider::SetLineSize(int lineSize)
171{
a4294b78 172 // Not implemented in Motif
4bb6408c 173 m_lineSize = lineSize;
4bb6408c
JS
174}
175
176int wxSlider::GetLineSize() const
177{
a4294b78
JS
178 // Not implemented in Motif
179 return m_lineSize;
4bb6408c
JS
180}
181
a4294b78 182void wxSlider::SetThumbLength(int WXUNUSED(len))
4bb6408c 183{
a4294b78 184 // Not implemented in Motif (?)
4bb6408c
JS
185}
186
187int wxSlider::GetThumbLength() const
188{
a4294b78 189 // Not implemented in Motif (?)
4bb6408c
JS
190 return 0;
191}
192
4bb6408c
JS
193void wxSlider::Command (wxCommandEvent & event)
194{
2d120f83
JS
195 SetValue (event.GetInt());
196 ProcessCommand (event);
4bb6408c
JS
197}
198
93e73c74
MB
199void wxSliderCallback (Widget widget, XtPointer clientData,
200 XmScaleCallbackStruct * cbs)
4bb6408c 201{
a4294b78 202 wxSlider *slider = (wxSlider *) clientData;
93e73c74
MB
203 wxEventType scrollEvent;
204
a4294b78
JS
205 switch (cbs->reason)
206 {
2d120f83 207 case XmCR_VALUE_CHANGED:
93e73c74
MB
208 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
209 break;
210
2d120f83 211 case XmCR_DRAG:
93e73c74
MB
212 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
213 break;
214
2d120f83 215 default:
93e73c74 216 return;
a4294b78 217 }
93e73c74
MB
218
219 wxScrollEvent event(scrollEvent, slider->GetId());
687706f5
KH
220 int commandInt = event.GetInt();
221 XtVaGetValues (widget, XmNvalue, &commandInt, NULL);
222 event.SetInt(commandInt);
93e73c74 223 event.SetEventObject(slider);
937013e0 224 slider->HandleWindowEvent(event);
93e73c74
MB
225
226 // Also send a wxCommandEvent for compatibility.
227 wxCommandEvent event2(wxEVT_COMMAND_SLIDER_UPDATED, slider->GetId());
228 event2.SetEventObject(slider);
229 event2.SetInt( event.GetInt() );
937013e0 230 slider->HandleWindowEvent(event2);
4bb6408c
JS
231}
232
312ebad4 233#endif // wxUSE_SLIDER