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