]>
Commit | Line | Data |
---|---|---|
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 | ||
27 | void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs); | |
4bb6408c JS |
28 | |
29 | #if !USE_SHARED_LIBRARY | |
30 | IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) | |
31 | ||
32 | BEGIN_EVENT_TABLE(wxSlider, wxControl) | |
33 | END_EVENT_TABLE() | |
34 | #endif | |
35 | ||
36 | ||
37 | ||
38 | // Slider | |
39 | wxSlider::wxSlider() | |
40 | { | |
41 | m_pageSize = 1; | |
42 | m_lineSize = 1; | |
43 | m_rangeMax = 0; | |
44 | m_rangeMin = 0; | |
45 | m_tickFreq = 0; | |
46 | } | |
47 | ||
48 | bool 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 | ||
58 | if (parent) parent->AddChild(this); | |
59 | ||
60 | m_lineSize = 1; | |
61 | m_windowStyle = style; | |
62 | m_tickFreq = 0; | |
63 | ||
64 | if ( id == -1 ) | |
65 | m_windowId = (int)NewControlId(); | |
66 | else | |
67 | m_windowId = id; | |
68 | ||
69 | m_rangeMax = maxValue; | |
70 | m_rangeMin = minValue; | |
71 | ||
a4294b78 | 72 | // Not used in Motif, I think |
4bb6408c JS |
73 | m_pageSize = (int)((maxValue-minValue)/10); |
74 | ||
a4294b78 JS |
75 | Widget parentWidget = (Widget) parent->GetClientWidget(); |
76 | ||
77 | Widget sliderWidget = XtVaCreateManagedWidget ("sliderWidget", | |
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); | |
88 | ||
89 | m_mainWidget = (WXWidget) sliderWidget; | |
90 | ||
91 | if(style & wxSL_NOTIFY_DRAG) | |
92 | XtAddCallback (sliderWidget, XmNdragCallback, | |
93 | (XtCallbackProc) wxSliderCallback, (XtPointer) this); | |
94 | else | |
95 | XtAddCallback (sliderWidget, XmNvalueChangedCallback, | |
96 | (XtCallbackProc) wxSliderCallback, (XtPointer) this); | |
97 | ||
98 | XtAddCallback (sliderWidget, XmNdragCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this); | |
99 | ||
100 | SetCanAddEventHandler(TRUE); | |
101 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); | |
4bb6408c | 102 | |
a4294b78 JS |
103 | SetFont(* parent->GetFont()); |
104 | ChangeColour(m_mainWidget); | |
105 | ||
106 | return TRUE; | |
4bb6408c JS |
107 | } |
108 | ||
109 | wxSlider::~wxSlider() | |
110 | { | |
111 | } | |
112 | ||
113 | int wxSlider::GetValue() const | |
114 | { | |
a4294b78 JS |
115 | int val; |
116 | XtVaGetValues ((Widget) m_mainWidget, XmNvalue, &val, NULL); | |
117 | return val; | |
4bb6408c JS |
118 | } |
119 | ||
120 | void wxSlider::SetValue(int value) | |
121 | { | |
a4294b78 | 122 | XtVaSetValues ((Widget) m_mainWidget, XmNvalue, value, NULL); |
4bb6408c JS |
123 | } |
124 | ||
125 | void wxSlider::GetSize(int *width, int *height) const | |
126 | { | |
a4294b78 | 127 | wxControl::GetSize(width, height); |
4bb6408c JS |
128 | } |
129 | ||
130 | void wxSlider::SetSize(int x, int y, int width, int height, int sizeFlags) | |
131 | { | |
a4294b78 JS |
132 | Widget widget = (Widget) m_mainWidget; |
133 | ||
134 | bool managed = XtIsManaged(widget); | |
135 | ||
136 | if (managed) | |
137 | XtUnmanageChild (widget); | |
138 | ||
139 | if (((m_windowStyle & wxHORIZONTAL) == wxHORIZONTAL) && (width > -1)) | |
140 | { | |
141 | XtVaSetValues (widget, XmNscaleWidth, wxMax (width, 10), NULL); | |
142 | } | |
143 | ||
144 | if (((m_windowStyle & wxVERTICAL) == wxVERTICAL) && (height > -1)) | |
145 | { | |
146 | XtVaSetValues (widget, XmNscaleHeight, wxMax (height, 10), NULL); | |
147 | } | |
148 | ||
149 | int xx = x; int yy = y; | |
150 | AdjustForParentClientOrigin(xx, yy, sizeFlags); | |
151 | ||
152 | if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
153 | XtVaSetValues (widget, XmNx, xx, NULL); | |
154 | if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
155 | XtVaSetValues (widget, XmNy, yy, NULL); | |
156 | ||
157 | if (managed) | |
158 | XtManageChild (widget); | |
4bb6408c JS |
159 | } |
160 | ||
161 | void wxSlider::SetRange(int minValue, int maxValue) | |
162 | { | |
163 | m_rangeMin = minValue; | |
164 | m_rangeMax = maxValue; | |
165 | ||
a4294b78 | 166 | XtVaSetValues ((Widget) m_mainWidget, XmNminimum, minValue, XmNmaximum, maxValue, NULL); |
4bb6408c JS |
167 | } |
168 | ||
169 | // For trackbars only | |
170 | void wxSlider::SetTickFreq(int n, int pos) | |
171 | { | |
a4294b78 | 172 | // Not implemented in Motif |
4bb6408c JS |
173 | m_tickFreq = n; |
174 | } | |
175 | ||
176 | void wxSlider::SetPageSize(int pageSize) | |
177 | { | |
a4294b78 | 178 | // Not implemented in Motif |
4bb6408c JS |
179 | m_pageSize = pageSize; |
180 | } | |
181 | ||
182 | int wxSlider::GetPageSize() const | |
183 | { | |
184 | return m_pageSize; | |
185 | } | |
186 | ||
187 | void wxSlider::ClearSel() | |
188 | { | |
a4294b78 | 189 | // Not implemented in Motif |
4bb6408c JS |
190 | } |
191 | ||
192 | void wxSlider::ClearTicks() | |
193 | { | |
a4294b78 | 194 | // Not implemented in Motif |
4bb6408c JS |
195 | } |
196 | ||
197 | void wxSlider::SetLineSize(int lineSize) | |
198 | { | |
a4294b78 | 199 | // Not implemented in Motif |
4bb6408c | 200 | m_lineSize = lineSize; |
4bb6408c JS |
201 | } |
202 | ||
203 | int wxSlider::GetLineSize() const | |
204 | { | |
a4294b78 JS |
205 | // Not implemented in Motif |
206 | return m_lineSize; | |
4bb6408c JS |
207 | } |
208 | ||
209 | int wxSlider::GetSelEnd() const | |
210 | { | |
a4294b78 | 211 | // Not implemented in Motif |
4bb6408c JS |
212 | return 0; |
213 | } | |
214 | ||
215 | int wxSlider::GetSelStart() const | |
216 | { | |
a4294b78 | 217 | // Not implemented in Motif |
4bb6408c JS |
218 | return 0; |
219 | } | |
220 | ||
a4294b78 | 221 | void wxSlider::SetSelection(int WXUNUSED(minPos), int WXUNUSED(maxPos)) |
4bb6408c | 222 | { |
a4294b78 | 223 | // Not implemented in Motif |
4bb6408c JS |
224 | } |
225 | ||
a4294b78 | 226 | void wxSlider::SetThumbLength(int WXUNUSED(len)) |
4bb6408c | 227 | { |
a4294b78 | 228 | // Not implemented in Motif (?) |
4bb6408c JS |
229 | } |
230 | ||
231 | int wxSlider::GetThumbLength() const | |
232 | { | |
a4294b78 | 233 | // Not implemented in Motif (?) |
4bb6408c JS |
234 | return 0; |
235 | } | |
236 | ||
a4294b78 | 237 | void wxSlider::SetTick(int WXUNUSED(tickPos)) |
4bb6408c | 238 | { |
a4294b78 | 239 | // Not implemented in Motif |
4bb6408c JS |
240 | } |
241 | ||
242 | void wxSlider::Command (wxCommandEvent & event) | |
243 | { | |
244 | SetValue (event.GetInt()); | |
245 | ProcessCommand (event); | |
246 | } | |
247 | ||
a4294b78 | 248 | void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs) |
4bb6408c | 249 | { |
a4294b78 JS |
250 | wxSlider *slider = (wxSlider *) clientData; |
251 | switch (cbs->reason) | |
252 | { | |
253 | case XmCR_VALUE_CHANGED: | |
254 | case XmCR_DRAG: | |
255 | default: | |
256 | { | |
257 | // TODO: the XmCR_VALUE_CHANGED case should be handled | |
258 | // differently (it's not sent continually as the slider moves). | |
259 | // In which case we need a similar behaviour for other platforms. | |
260 | ||
261 | wxScrollEvent event(wxEVT_SCROLL_THUMBTRACK, slider->GetId()); | |
262 | XtVaGetValues (widget, XmNvalue, &event.m_commandInt, NULL); | |
263 | event.SetEventObject(slider); | |
264 | slider->ProcessCommand(event); | |
265 | break; | |
266 | } | |
267 | } | |
4bb6408c JS |
268 | } |
269 |