]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/motif/slider.cpp
Thread fixes (but they still don't work at all...)
[wxWidgets.git] / src / motif / slider.cpp
... / ...
CommitLineData
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"
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);
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{
41 m_pageSize = 1;
42 m_lineSize = 1;
43 m_rangeMax = 0;
44 m_rangeMin = 0;
45 m_tickFreq = 0;
46}
47
48bool wxSlider::Create(wxWindow *parent, wxWindowID id,
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)
54{
55 SetName(name);
56 SetValidator(validator);
57 m_backgroundColour = parent->GetBackgroundColour();
58 m_foregroundColour = parent->GetForegroundColour();
59
60 if (parent) parent->AddChild(this);
61
62 m_lineSize = 1;
63 m_windowStyle = style;
64 m_tickFreq = 0;
65
66 if ( id == -1 )
67 m_windowId = (int)NewControlId();
68 else
69 m_windowId = id;
70
71 m_rangeMax = maxValue;
72 m_rangeMin = minValue;
73
74 // Not used in Motif, I think
75 m_pageSize = (int)((maxValue-minValue)/10);
76
77 Widget parentWidget = (Widget) parent->GetClientWidget();
78
79 Widget sliderWidget = XtVaCreateManagedWidget ("sliderWidget",
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
91 m_mainWidget = (WXWidget) sliderWidget;
92
93 if(style & wxSL_NOTIFY_DRAG)
94 XtAddCallback (sliderWidget, XmNdragCallback,
95 (XtCallbackProc) wxSliderCallback, (XtPointer) this);
96 else
97 XtAddCallback (sliderWidget, XmNvalueChangedCallback,
98 (XtCallbackProc) wxSliderCallback, (XtPointer) this);
99
100 XtAddCallback (sliderWidget, XmNdragCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this);
101
102 m_windowFont = parent->GetFont();
103
104 ChangeFont(FALSE);
105 SetCanAddEventHandler(TRUE);
106 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
107
108 ChangeBackgroundColour();
109
110 return TRUE;
111}
112
113wxSlider::~wxSlider()
114{
115}
116
117int wxSlider::GetValue() const
118{
119 int val;
120 XtVaGetValues ((Widget) m_mainWidget, XmNvalue, &val, NULL);
121 return val;
122}
123
124void wxSlider::SetValue(int value)
125{
126 XtVaSetValues ((Widget) m_mainWidget, XmNvalue, value, NULL);
127}
128
129void wxSlider::GetSize(int *width, int *height) const
130{
131 wxControl::GetSize(width, height);
132}
133
134void wxSlider::SetSize(int x, int y, int width, int height, int sizeFlags)
135{
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);
163}
164
165void wxSlider::SetRange(int minValue, int maxValue)
166{
167 m_rangeMin = minValue;
168 m_rangeMax = maxValue;
169
170 XtVaSetValues ((Widget) m_mainWidget, XmNminimum, minValue, XmNmaximum, maxValue, NULL);
171}
172
173// For trackbars only
174void wxSlider::SetTickFreq(int n, int pos)
175{
176 // Not implemented in Motif
177 m_tickFreq = n;
178}
179
180void wxSlider::SetPageSize(int pageSize)
181{
182 // Not implemented in Motif
183 m_pageSize = pageSize;
184}
185
186int wxSlider::GetPageSize() const
187{
188 return m_pageSize;
189}
190
191void wxSlider::ClearSel()
192{
193 // Not implemented in Motif
194}
195
196void wxSlider::ClearTicks()
197{
198 // Not implemented in Motif
199}
200
201void wxSlider::SetLineSize(int lineSize)
202{
203 // Not implemented in Motif
204 m_lineSize = lineSize;
205}
206
207int wxSlider::GetLineSize() const
208{
209 // Not implemented in Motif
210 return m_lineSize;
211}
212
213int wxSlider::GetSelEnd() const
214{
215 // Not implemented in Motif
216 return 0;
217}
218
219int wxSlider::GetSelStart() const
220{
221 // Not implemented in Motif
222 return 0;
223}
224
225void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos))
226{
227 // Not implemented in Motif
228}
229
230void wxSlider::SetThumbLength(int WXUNUSED(len))
231{
232 // Not implemented in Motif (?)
233}
234
235int wxSlider::GetThumbLength() const
236{
237 // Not implemented in Motif (?)
238 return 0;
239}
240
241void wxSlider::SetTick(int WXUNUSED(tickPos))
242{
243 // Not implemented in Motif
244}
245
246void wxSlider::Command (wxCommandEvent & event)
247{
248 SetValue (event.GetInt());
249 ProcessCommand (event);
250}
251
252void wxSlider::ChangeFont(bool keepOriginalSize)
253{
254 wxWindow::ChangeFont(keepOriginalSize);
255}
256
257void wxSlider::ChangeBackgroundColour()
258{
259 wxWindow::ChangeBackgroundColour();
260}
261
262void wxSlider::ChangeForegroundColour()
263{
264 wxWindow::ChangeForegroundColour();
265}
266
267void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs)
268{
269 wxSlider *slider = (wxSlider *) clientData;
270 switch (cbs->reason)
271 {
272 case XmCR_VALUE_CHANGED:
273 case XmCR_DRAG:
274 default:
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.
279
280 wxScrollEvent event(wxEVT_SCROLL_THUMBTRACK, slider->GetId());
281 XtVaGetValues (widget, XmNvalue, &event.m_commandInt, NULL);
282 event.SetEventObject(slider);
283 slider->ProcessCommand(event);
284
285 // Also send a wxCommandEvent for compatibility.
286 wxCommandEvent event2(wxEVT_COMMAND_SLIDER_UPDATED, slider->GetId());
287 event2.SetEventObject(slider);
288 slider->ProcessCommand(event2);
289 break;
290 }
291 }
292}
293