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