]> git.saurik.com Git - wxWidgets.git/blame - src/motif/slider.cpp
1. wxMenu{Item|Bar} modifications for wxMotif
[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
12#ifdef __GNUG__
13#pragma implementation "slider.h"
14#endif
15
16#include "wx/slider.h"
a4294b78
JS
17#include "wx/utils.h"
18
19#include <Xm/Xm.h>
20#include <Xm/Label.h>
21#include <Xm/LabelG.h>
22#include <Xm/RowColumn.h>
23#include <Xm/Scale.h>
24
25#include <wx/motif/private.h>
26
27void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs);
4bb6408c
JS
28
29#if !USE_SHARED_LIBRARY
30IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
31
32BEGIN_EVENT_TABLE(wxSlider, wxControl)
33END_EVENT_TABLE()
34#endif
35
36
37
38// Slider
39wxSlider::wxSlider()
40{
2d120f83
JS
41 m_pageSize = 1;
42 m_lineSize = 1;
43 m_rangeMax = 0;
44 m_rangeMin = 0;
45 m_tickFreq = 0;
4bb6408c
JS
46}
47
48bool wxSlider::Create(wxWindow *parent, wxWindowID id,
2d120f83
JS
49 int value, int minValue, int maxValue,
50 const wxPoint& pos,
51 const wxSize& size, long style,
52 const wxValidator& validator,
53 const wxString& name)
ba7ce6a0
MB
54{
55 if ( !((style & wxSL_HORIZONTAL) || (style & wxSL_VERTICAL)) )
56 style |= wxSL_HORIZONTAL;
57
4bb6408c
JS
58 SetName(name);
59 SetValidator(validator);
0d57be45
JS
60 m_backgroundColour = parent->GetBackgroundColour();
61 m_foregroundColour = parent->GetForegroundColour();
31528cd3 62
4bb6408c 63 if (parent) parent->AddChild(this);
31528cd3 64
4bb6408c
JS
65 m_lineSize = 1;
66 m_windowStyle = style;
67 m_tickFreq = 0;
31528cd3 68
4bb6408c 69 if ( id == -1 )
2d120f83 70 m_windowId = (int)NewControlId();
4bb6408c 71 else
2d120f83 72 m_windowId = id;
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
a4294b78
JS
96 if(style & wxSL_NOTIFY_DRAG)
97 XtAddCallback (sliderWidget, XmNdragCallback,
2d120f83 98 (XtCallbackProc) wxSliderCallback, (XtPointer) this);
a4294b78
JS
99 else
100 XtAddCallback (sliderWidget, XmNvalueChangedCallback,
2d120f83 101 (XtCallbackProc) wxSliderCallback, (XtPointer) this);
31528cd3 102
a4294b78 103 XtAddCallback (sliderWidget, XmNdragCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this);
31528cd3 104
da175b2c 105 m_font = parent->GetFont();
31528cd3 106
4b5f3fe6 107 ChangeFont(FALSE);
a4294b78
JS
108 SetCanAddEventHandler(TRUE);
109 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
31528cd3 110
0d57be45 111 ChangeBackgroundColour();
31528cd3 112
a4294b78 113 return TRUE;
4bb6408c
JS
114}
115
116wxSlider::~wxSlider()
117{
118}
119
120int wxSlider::GetValue() const
121{
a4294b78
JS
122 int val;
123 XtVaGetValues ((Widget) m_mainWidget, XmNvalue, &val, NULL);
124 return val;
4bb6408c
JS
125}
126
127void wxSlider::SetValue(int value)
128{
a4294b78 129 XtVaSetValues ((Widget) m_mainWidget, XmNvalue, value, NULL);
4bb6408c
JS
130}
131
132void wxSlider::GetSize(int *width, int *height) const
133{
a4294b78 134 wxControl::GetSize(width, height);
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
af111fc3 177void wxSlider::SetTickFreq(int n, int WXUNUSED(pos))
4bb6408c 178{
a4294b78 179 // Not implemented in Motif
4bb6408c
JS
180 m_tickFreq = n;
181}
182
183void wxSlider::SetPageSize(int pageSize)
184{
a4294b78 185 // Not implemented in Motif
4bb6408c
JS
186 m_pageSize = pageSize;
187}
188
189int wxSlider::GetPageSize() const
190{
191 return m_pageSize;
192}
193
194void wxSlider::ClearSel()
195{
a4294b78 196 // Not implemented in Motif
4bb6408c
JS
197}
198
199void wxSlider::ClearTicks()
200{
a4294b78 201 // Not implemented in Motif
4bb6408c
JS
202}
203
204void wxSlider::SetLineSize(int lineSize)
205{
a4294b78 206 // Not implemented in Motif
4bb6408c 207 m_lineSize = lineSize;
4bb6408c
JS
208}
209
210int wxSlider::GetLineSize() const
211{
a4294b78
JS
212 // Not implemented in Motif
213 return m_lineSize;
4bb6408c
JS
214}
215
216int wxSlider::GetSelEnd() const
217{
a4294b78 218 // Not implemented in Motif
4bb6408c
JS
219 return 0;
220}
221
222int wxSlider::GetSelStart() const
223{
a4294b78 224 // Not implemented in Motif
4bb6408c
JS
225 return 0;
226}
227
a4294b78 228void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos))
4bb6408c 229{
a4294b78 230 // Not implemented in Motif
4bb6408c
JS
231}
232
a4294b78 233void wxSlider::SetThumbLength(int WXUNUSED(len))
4bb6408c 234{
a4294b78 235 // Not implemented in Motif (?)
4bb6408c
JS
236}
237
238int wxSlider::GetThumbLength() const
239{
a4294b78 240 // Not implemented in Motif (?)
4bb6408c
JS
241 return 0;
242}
243
a4294b78 244void wxSlider::SetTick(int WXUNUSED(tickPos))
4bb6408c 245{
a4294b78 246 // Not implemented in Motif
4bb6408c
JS
247}
248
249void wxSlider::Command (wxCommandEvent & event)
250{
2d120f83
JS
251 SetValue (event.GetInt());
252 ProcessCommand (event);
4bb6408c
JS
253}
254
4b5f3fe6 255void wxSlider::ChangeFont(bool keepOriginalSize)
0d57be45 256{
4b5f3fe6 257 wxWindow::ChangeFont(keepOriginalSize);
0d57be45
JS
258}
259
260void wxSlider::ChangeBackgroundColour()
261{
321db4b6 262 wxWindow::ChangeBackgroundColour();
0d57be45
JS
263}
264
265void wxSlider::ChangeForegroundColour()
266{
321db4b6 267 wxWindow::ChangeForegroundColour();
0d57be45
JS
268}
269
a4294b78 270void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs)
4bb6408c 271{
a4294b78
JS
272 wxSlider *slider = (wxSlider *) clientData;
273 switch (cbs->reason)
274 {
2d120f83
JS
275 case XmCR_VALUE_CHANGED:
276 case XmCR_DRAG:
277 default:
a4294b78
JS
278 {
279 // TODO: the XmCR_VALUE_CHANGED case should be handled
280 // differently (it's not sent continually as the slider moves).
281 // In which case we need a similar behaviour for other platforms.
31528cd3 282
a4294b78
JS
283 wxScrollEvent event(wxEVT_SCROLL_THUMBTRACK, slider->GetId());
284 XtVaGetValues (widget, XmNvalue, &event.m_commandInt, NULL);
285 event.SetEventObject(slider);
286 slider->ProcessCommand(event);
31528cd3 287
55acd85e
JS
288 // Also send a wxCommandEvent for compatibility.
289 wxCommandEvent event2(wxEVT_COMMAND_SLIDER_UPDATED, slider->GetId());
290 event2.SetEventObject(slider);
291 slider->ProcessCommand(event2);
a4294b78
JS
292 break;
293 }
294 }
4bb6408c
JS
295}
296