]> git.saurik.com Git - wxWidgets.git/blame - src/motif/slider.cpp
Doc mods, sash window bug
[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)
4bb6408c
JS
54{
55 SetName(name);
56 SetValidator(validator);
0d57be45
JS
57 m_backgroundColour = parent->GetBackgroundColour();
58 m_foregroundColour = parent->GetForegroundColour();
2d120f83 59
4bb6408c 60 if (parent) parent->AddChild(this);
2d120f83 61
4bb6408c
JS
62 m_lineSize = 1;
63 m_windowStyle = style;
64 m_tickFreq = 0;
2d120f83 65
4bb6408c 66 if ( id == -1 )
2d120f83 67 m_windowId = (int)NewControlId();
4bb6408c 68 else
2d120f83
JS
69 m_windowId = id;
70
4bb6408c
JS
71 m_rangeMax = maxValue;
72 m_rangeMin = minValue;
2d120f83 73
a4294b78 74 // Not used in Motif, I think
4bb6408c 75 m_pageSize = (int)((maxValue-minValue)/10);
2d120f83 76
a4294b78 77 Widget parentWidget = (Widget) parent->GetClientWidget();
2d120f83 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);
90
a4294b78 91 m_mainWidget = (WXWidget) sliderWidget;
2d120f83 92
a4294b78
JS
93 if(style & wxSL_NOTIFY_DRAG)
94 XtAddCallback (sliderWidget, XmNdragCallback,
2d120f83 95 (XtCallbackProc) wxSliderCallback, (XtPointer) this);
a4294b78
JS
96 else
97 XtAddCallback (sliderWidget, XmNvalueChangedCallback,
2d120f83
JS
98 (XtCallbackProc) wxSliderCallback, (XtPointer) this);
99
a4294b78 100 XtAddCallback (sliderWidget, XmNdragCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this);
2d120f83 101
4b5f3fe6 102 m_windowFont = parent->GetFont();
2d120f83 103
4b5f3fe6 104 ChangeFont(FALSE);
a4294b78
JS
105 SetCanAddEventHandler(TRUE);
106 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
2d120f83 107
0d57be45 108 ChangeBackgroundColour();
2d120f83 109
a4294b78 110 return TRUE;
4bb6408c
JS
111}
112
113wxSlider::~wxSlider()
114{
115}
116
117int wxSlider::GetValue() const
118{
a4294b78
JS
119 int val;
120 XtVaGetValues ((Widget) m_mainWidget, XmNvalue, &val, NULL);
121 return val;
4bb6408c
JS
122}
123
124void wxSlider::SetValue(int value)
125{
a4294b78 126 XtVaSetValues ((Widget) m_mainWidget, XmNvalue, value, NULL);
4bb6408c
JS
127}
128
129void wxSlider::GetSize(int *width, int *height) const
130{
a4294b78 131 wxControl::GetSize(width, height);
4bb6408c
JS
132}
133
134void wxSlider::SetSize(int x, int y, int width, int height, int sizeFlags)
135{
2d120f83
JS
136 Widget widget = (Widget) m_mainWidget;
137
138 bool managed = XtIsManaged(widget);
139
140 if (managed)
141 XtUnmanageChild (widget);
142
143 if (((m_windowStyle & wxHORIZONTAL) == wxHORIZONTAL) && (width > -1))
144 {
145 XtVaSetValues (widget, XmNscaleWidth, wxMax (width, 10), NULL);
146 }
147
148 if (((m_windowStyle & wxVERTICAL) == wxVERTICAL) && (height > -1))
149 {
150 XtVaSetValues (widget, XmNscaleHeight, wxMax (height, 10), NULL);
151 }
152
153 int xx = x; int yy = y;
154 AdjustForParentClientOrigin(xx, yy, sizeFlags);
155
156 if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
157 XtVaSetValues (widget, XmNx, xx, NULL);
158 if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
159 XtVaSetValues (widget, XmNy, yy, NULL);
160
161 if (managed)
162 XtManageChild (widget);
4bb6408c
JS
163}
164
165void wxSlider::SetRange(int minValue, int maxValue)
166{
167 m_rangeMin = minValue;
168 m_rangeMax = maxValue;
2d120f83 169
a4294b78 170 XtVaSetValues ((Widget) m_mainWidget, XmNminimum, minValue, XmNmaximum, maxValue, NULL);
4bb6408c
JS
171}
172
173// For trackbars only
174void wxSlider::SetTickFreq(int n, int pos)
175{
a4294b78 176 // Not implemented in Motif
4bb6408c
JS
177 m_tickFreq = n;
178}
179
180void wxSlider::SetPageSize(int pageSize)
181{
a4294b78 182 // Not implemented in Motif
4bb6408c
JS
183 m_pageSize = pageSize;
184}
185
186int wxSlider::GetPageSize() const
187{
188 return m_pageSize;
189}
190
191void wxSlider::ClearSel()
192{
a4294b78 193 // Not implemented in Motif
4bb6408c
JS
194}
195
196void wxSlider::ClearTicks()
197{
a4294b78 198 // Not implemented in Motif
4bb6408c
JS
199}
200
201void wxSlider::SetLineSize(int lineSize)
202{
a4294b78 203 // Not implemented in Motif
4bb6408c 204 m_lineSize = lineSize;
4bb6408c
JS
205}
206
207int wxSlider::GetLineSize() const
208{
a4294b78
JS
209 // Not implemented in Motif
210 return m_lineSize;
4bb6408c
JS
211}
212
213int wxSlider::GetSelEnd() const
214{
a4294b78 215 // Not implemented in Motif
4bb6408c
JS
216 return 0;
217}
218
219int wxSlider::GetSelStart() const
220{
a4294b78 221 // Not implemented in Motif
4bb6408c
JS
222 return 0;
223}
224
a4294b78 225void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos))
4bb6408c 226{
a4294b78 227 // Not implemented in Motif
4bb6408c
JS
228}
229
a4294b78 230void wxSlider::SetThumbLength(int WXUNUSED(len))
4bb6408c 231{
a4294b78 232 // Not implemented in Motif (?)
4bb6408c
JS
233}
234
235int wxSlider::GetThumbLength() const
236{
a4294b78 237 // Not implemented in Motif (?)
4bb6408c
JS
238 return 0;
239}
240
a4294b78 241void wxSlider::SetTick(int WXUNUSED(tickPos))
4bb6408c 242{
a4294b78 243 // Not implemented in Motif
4bb6408c
JS
244}
245
246void wxSlider::Command (wxCommandEvent & event)
247{
2d120f83
JS
248 SetValue (event.GetInt());
249 ProcessCommand (event);
4bb6408c
JS
250}
251
4b5f3fe6 252void wxSlider::ChangeFont(bool keepOriginalSize)
0d57be45 253{
4b5f3fe6 254 wxWindow::ChangeFont(keepOriginalSize);
0d57be45
JS
255}
256
257void wxSlider::ChangeBackgroundColour()
258{
321db4b6 259 wxWindow::ChangeBackgroundColour();
0d57be45
JS
260}
261
262void wxSlider::ChangeForegroundColour()
263{
321db4b6 264 wxWindow::ChangeForegroundColour();
0d57be45
JS
265}
266
a4294b78 267void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs)
4bb6408c 268{
a4294b78
JS
269 wxSlider *slider = (wxSlider *) clientData;
270 switch (cbs->reason)
271 {
2d120f83
JS
272 case XmCR_VALUE_CHANGED:
273 case XmCR_DRAG:
274 default:
a4294b78
JS
275 {
276 // TODO: the XmCR_VALUE_CHANGED case should be handled
277 // differently (it's not sent continually as the slider moves).
278 // In which case we need a similar behaviour for other platforms.
2d120f83 279
a4294b78
JS
280 wxScrollEvent event(wxEVT_SCROLL_THUMBTRACK, slider->GetId());
281 XtVaGetValues (widget, XmNvalue, &event.m_commandInt, NULL);
282 event.SetEventObject(slider);
283 slider->ProcessCommand(event);
2d120f83 284
55acd85e
JS
285 // Also send a wxCommandEvent for compatibility.
286 wxCommandEvent event2(wxEVT_COMMAND_SLIDER_UPDATED, slider->GetId());
287 event2.SetEventObject(slider);
288 slider->ProcessCommand(event2);
a4294b78
JS
289 break;
290 }
291 }
4bb6408c
JS
292}
293