]> git.saurik.com Git - wxWidgets.git/blame - src/motif/slider.cpp
compilation fix: test correctly for filter string not being empty in MakeUserDataRec
[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;
31528cd3 67
4bb6408c
JS
68 m_lineSize = 1;
69 m_windowStyle = style;
31528cd3 70
4bb6408c
JS
71 m_rangeMax = maxValue;
72 m_rangeMin = minValue;
31528cd3 73
a4294b78 74 // Not used in Motif, I think
4bb6408c 75 m_pageSize = (int)((maxValue-minValue)/10);
31528cd3 76
a4294b78 77 Widget parentWidget = (Widget) parent->GetClientWidget();
31528cd3 78
a4294b78 79 Widget sliderWidget = XtVaCreateManagedWidget ("sliderWidget",
2d120f83
JS
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);
31528cd3 90
a4294b78 91 m_mainWidget = (WXWidget) sliderWidget;
31528cd3 92
ad60f069 93 XtAddCallback (sliderWidget, XmNvalueChangedCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this);
a4294b78 94 XtAddCallback (sliderWidget, XmNdragCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this);
31528cd3 95
312ebad4 96 ChangeFont(false);
a4294b78 97 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
31528cd3 98
0d57be45 99 ChangeBackgroundColour();
31528cd3 100
312ebad4 101 return true;
4bb6408c
JS
102}
103
104wxSlider::~wxSlider()
105{
106}
107
108int wxSlider::GetValue() const
109{
a4294b78
JS
110 int val;
111 XtVaGetValues ((Widget) m_mainWidget, XmNvalue, &val, NULL);
112 return val;
4bb6408c
JS
113}
114
115void wxSlider::SetValue(int value)
116{
a4294b78 117 XtVaSetValues ((Widget) m_mainWidget, XmNvalue, value, NULL);
4bb6408c
JS
118}
119
bfc6fde4 120void wxSlider::DoSetSize(int x, int y, int width, int height, int sizeFlags)
4bb6408c 121{
2d120f83 122 Widget widget = (Widget) m_mainWidget;
31528cd3 123
2d120f83 124 bool managed = XtIsManaged(widget);
31528cd3 125
2d120f83
JS
126 if (managed)
127 XtUnmanageChild (widget);
31528cd3 128
2d120f83
JS
129 if (((m_windowStyle & wxHORIZONTAL) == wxHORIZONTAL) && (width > -1))
130 {
131 XtVaSetValues (widget, XmNscaleWidth, wxMax (width, 10), NULL);
132 }
31528cd3 133
2d120f83
JS
134 if (((m_windowStyle & wxVERTICAL) == wxVERTICAL) && (height > -1))
135 {
136 XtVaSetValues (widget, XmNscaleHeight, wxMax (height, 10), NULL);
137 }
31528cd3 138
2d120f83
JS
139 int xx = x; int yy = y;
140 AdjustForParentClientOrigin(xx, yy, sizeFlags);
31528cd3 141
2d120f83
JS
142 if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
143 XtVaSetValues (widget, XmNx, xx, NULL);
144 if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
145 XtVaSetValues (widget, XmNy, yy, NULL);
31528cd3 146
2d120f83
JS
147 if (managed)
148 XtManageChild (widget);
4bb6408c
JS
149}
150
151void wxSlider::SetRange(int minValue, int maxValue)
152{
153 m_rangeMin = minValue;
154 m_rangeMax = maxValue;
31528cd3 155
a4294b78 156 XtVaSetValues ((Widget) m_mainWidget, XmNminimum, minValue, XmNmaximum, maxValue, NULL);
4bb6408c
JS
157}
158
159// For trackbars only
4bb6408c
JS
160void wxSlider::SetPageSize(int pageSize)
161{
a4294b78 162 // Not implemented in Motif
4bb6408c
JS
163 m_pageSize = pageSize;
164}
165
166int wxSlider::GetPageSize() const
167{
168 return m_pageSize;
169}
170
4bb6408c
JS
171void wxSlider::SetLineSize(int lineSize)
172{
a4294b78 173 // Not implemented in Motif
4bb6408c 174 m_lineSize = lineSize;
4bb6408c
JS
175}
176
177int wxSlider::GetLineSize() const
178{
a4294b78
JS
179 // Not implemented in Motif
180 return m_lineSize;
4bb6408c
JS
181}
182
a4294b78 183void wxSlider::SetThumbLength(int WXUNUSED(len))
4bb6408c 184{
a4294b78 185 // Not implemented in Motif (?)
4bb6408c
JS
186}
187
188int wxSlider::GetThumbLength() const
189{
a4294b78 190 // Not implemented in Motif (?)
4bb6408c
JS
191 return 0;
192}
193
4bb6408c
JS
194void wxSlider::Command (wxCommandEvent & event)
195{
2d120f83
JS
196 SetValue (event.GetInt());
197 ProcessCommand (event);
4bb6408c
JS
198}
199
93e73c74
MB
200void wxSliderCallback (Widget widget, XtPointer clientData,
201 XmScaleCallbackStruct * cbs)
4bb6408c 202{
a4294b78 203 wxSlider *slider = (wxSlider *) clientData;
93e73c74
MB
204 wxEventType scrollEvent;
205
a4294b78
JS
206 switch (cbs->reason)
207 {
2d120f83 208 case XmCR_VALUE_CHANGED:
93e73c74
MB
209 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
210 break;
211
2d120f83 212 case XmCR_DRAG:
93e73c74
MB
213 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
214 break;
215
2d120f83 216 default:
93e73c74 217 return;
a4294b78 218 }
93e73c74
MB
219
220 wxScrollEvent event(scrollEvent, slider->GetId());
687706f5
KH
221 int commandInt = event.GetInt();
222 XtVaGetValues (widget, XmNvalue, &commandInt, NULL);
223 event.SetInt(commandInt);
93e73c74
MB
224 event.SetEventObject(slider);
225 slider->GetEventHandler()->ProcessEvent(event);
226
227 // Also send a wxCommandEvent for compatibility.
228 wxCommandEvent event2(wxEVT_COMMAND_SLIDER_UPDATED, slider->GetId());
229 event2.SetEventObject(slider);
230 event2.SetInt( event.GetInt() );
231 slider->GetEventHandler()->ProcessEvent(event2);
4bb6408c
JS
232}
233
312ebad4 234#endif // wxUSE_SLIDER