]> git.saurik.com Git - wxWidgets.git/blame - src/motif/slider.cpp
removed Win16 code (patch 905241), last version with remains of Win16 support tagged...
[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
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
4bb6408c
JS
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
33void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs);
4bb6408c 34
4bb6408c
JS
35IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
36
37BEGIN_EVENT_TABLE(wxSlider, wxControl)
38END_EVENT_TABLE()
4bb6408c
JS
39
40
41
42// Slider
43wxSlider::wxSlider()
44{
2d120f83
JS
45 m_pageSize = 1;
46 m_lineSize = 1;
47 m_rangeMax = 0;
48 m_rangeMin = 0;
4bb6408c
JS
49}
50
51bool wxSlider::Create(wxWindow *parent, wxWindowID id,
2d120f83
JS
52 int value, int minValue, int maxValue,
53 const wxPoint& pos,
54 const wxSize& size, long style,
55 const wxValidator& validator,
56 const wxString& name)
93e73c74 57{
ba7ce6a0
MB
58 if ( !((style & wxSL_HORIZONTAL) || (style & wxSL_VERTICAL)) )
59 style |= wxSL_HORIZONTAL;
31528cd3 60
93e73c74
MB
61 if( !CreateControl( parent, id, pos, size, style, validator, name ) )
62 return false;
31528cd3 63
4bb6408c
JS
64 m_lineSize = 1;
65 m_windowStyle = style;
31528cd3 66
4bb6408c
JS
67 m_rangeMax = maxValue;
68 m_rangeMin = minValue;
31528cd3 69
a4294b78 70 // Not used in Motif, I think
4bb6408c 71 m_pageSize = (int)((maxValue-minValue)/10);
31528cd3 72
a4294b78 73 Widget parentWidget = (Widget) parent->GetClientWidget();
31528cd3 74
a4294b78 75 Widget sliderWidget = XtVaCreateManagedWidget ("sliderWidget",
2d120f83
JS
76 xmScaleWidgetClass, parentWidget,
77 XmNorientation,
78 (((m_windowStyle & wxSL_VERTICAL) == wxSL_VERTICAL) ? XmVERTICAL : XmHORIZONTAL),
79 XmNprocessingDirection,
80 (((m_windowStyle & wxSL_VERTICAL) == wxSL_VERTICAL) ? XmMAX_ON_TOP : XmMAX_ON_RIGHT),
81 XmNmaximum, maxValue,
82 XmNminimum, minValue,
83 XmNvalue, value,
84 XmNshowValue, True,
85 NULL);
31528cd3 86
a4294b78 87 m_mainWidget = (WXWidget) sliderWidget;
31528cd3 88
338dd992
JJ
89#ifdef __VMS__
90#pragma message disable codcauunr
91 // VMS gives here the compiler warning :
92 // statement either is unreachable or causes unreachable code
93#endif
a4294b78
JS
94 if(style & wxSL_NOTIFY_DRAG)
95 XtAddCallback (sliderWidget, XmNdragCallback,
2d120f83 96 (XtCallbackProc) wxSliderCallback, (XtPointer) this);
a4294b78
JS
97 else
98 XtAddCallback (sliderWidget, XmNvalueChangedCallback,
2d120f83 99 (XtCallbackProc) wxSliderCallback, (XtPointer) this);
338dd992
JJ
100#ifdef __VMS__
101#pragma message enable codcauunr
102#endif
31528cd3 103
a4294b78 104 XtAddCallback (sliderWidget, XmNdragCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this);
31528cd3 105
4b5f3fe6 106 ChangeFont(FALSE);
a4294b78 107 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
31528cd3 108
0d57be45 109 ChangeBackgroundColour();
31528cd3 110
a4294b78 111 return TRUE;
4bb6408c
JS
112}
113
114wxSlider::~wxSlider()
115{
116}
117
118int wxSlider::GetValue() const
119{
a4294b78
JS
120 int val;
121 XtVaGetValues ((Widget) m_mainWidget, XmNvalue, &val, NULL);
122 return val;
4bb6408c
JS
123}
124
125void wxSlider::SetValue(int value)
126{
a4294b78 127 XtVaSetValues ((Widget) m_mainWidget, XmNvalue, value, NULL);
4bb6408c
JS
128}
129
bfc6fde4 130void wxSlider::DoSetSize(int x, int y, int width, int height, int sizeFlags)
4bb6408c 131{
2d120f83 132 Widget widget = (Widget) m_mainWidget;
31528cd3 133
2d120f83 134 bool managed = XtIsManaged(widget);
31528cd3 135
2d120f83
JS
136 if (managed)
137 XtUnmanageChild (widget);
31528cd3 138
2d120f83
JS
139 if (((m_windowStyle & wxHORIZONTAL) == wxHORIZONTAL) && (width > -1))
140 {
141 XtVaSetValues (widget, XmNscaleWidth, wxMax (width, 10), NULL);
142 }
31528cd3 143
2d120f83
JS
144 if (((m_windowStyle & wxVERTICAL) == wxVERTICAL) && (height > -1))
145 {
146 XtVaSetValues (widget, XmNscaleHeight, wxMax (height, 10), NULL);
147 }
31528cd3 148
2d120f83
JS
149 int xx = x; int yy = y;
150 AdjustForParentClientOrigin(xx, yy, sizeFlags);
31528cd3 151
2d120f83
JS
152 if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
153 XtVaSetValues (widget, XmNx, xx, NULL);
154 if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
155 XtVaSetValues (widget, XmNy, yy, NULL);
31528cd3 156
2d120f83
JS
157 if (managed)
158 XtManageChild (widget);
4bb6408c
JS
159}
160
161void wxSlider::SetRange(int minValue, int maxValue)
162{
163 m_rangeMin = minValue;
164 m_rangeMax = maxValue;
31528cd3 165
a4294b78 166 XtVaSetValues ((Widget) m_mainWidget, XmNminimum, minValue, XmNmaximum, maxValue, NULL);
4bb6408c
JS
167}
168
169// For trackbars only
4bb6408c
JS
170void wxSlider::SetPageSize(int pageSize)
171{
a4294b78 172 // Not implemented in Motif
4bb6408c
JS
173 m_pageSize = pageSize;
174}
175
176int wxSlider::GetPageSize() const
177{
178 return m_pageSize;
179}
180
4bb6408c
JS
181void wxSlider::SetLineSize(int lineSize)
182{
a4294b78 183 // Not implemented in Motif
4bb6408c 184 m_lineSize = lineSize;
4bb6408c
JS
185}
186
187int wxSlider::GetLineSize() const
188{
a4294b78
JS
189 // Not implemented in Motif
190 return m_lineSize;
4bb6408c
JS
191}
192
a4294b78 193void wxSlider::SetThumbLength(int WXUNUSED(len))
4bb6408c 194{
a4294b78 195 // Not implemented in Motif (?)
4bb6408c
JS
196}
197
198int wxSlider::GetThumbLength() const
199{
a4294b78 200 // Not implemented in Motif (?)
4bb6408c
JS
201 return 0;
202}
203
4bb6408c
JS
204void wxSlider::Command (wxCommandEvent & event)
205{
2d120f83
JS
206 SetValue (event.GetInt());
207 ProcessCommand (event);
4bb6408c
JS
208}
209
93e73c74
MB
210void wxSliderCallback (Widget widget, XtPointer clientData,
211 XmScaleCallbackStruct * cbs)
4bb6408c 212{
a4294b78 213 wxSlider *slider = (wxSlider *) clientData;
93e73c74
MB
214 wxEventType scrollEvent;
215
a4294b78
JS
216 switch (cbs->reason)
217 {
2d120f83 218 case XmCR_VALUE_CHANGED:
93e73c74
MB
219 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
220 break;
221
2d120f83 222 case XmCR_DRAG:
93e73c74
MB
223 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
224 break;
225
2d120f83 226 default:
93e73c74 227 return;
a4294b78 228 }
93e73c74
MB
229
230 wxScrollEvent event(scrollEvent, slider->GetId());
231 XtVaGetValues (widget, XmNvalue, &event.m_commandInt, NULL);
232 event.SetEventObject(slider);
233 slider->GetEventHandler()->ProcessEvent(event);
234
235 // Also send a wxCommandEvent for compatibility.
236 wxCommandEvent event2(wxEVT_COMMAND_SLIDER_UPDATED, slider->GetId());
237 event2.SetEventObject(slider);
238 event2.SetInt( event.GetInt() );
239 slider->GetEventHandler()->ProcessEvent(event2);
4bb6408c
JS
240}
241