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