]>
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 | |
77ffb593 | 9 | // Licence: wxWidgets licence |
4bb6408c JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
14f355c2 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
4bb6408c JS |
13 | #pragma implementation "slider.h" |
14 | #endif | |
15 | ||
1248b41f MB |
16 | // For compilers that support precompilation, includes "wx.h". |
17 | #include "wx/wxprec.h" | |
18 | ||
4bb6408c | 19 | #include "wx/slider.h" |
a4294b78 JS |
20 | #include "wx/utils.h" |
21 | ||
338dd992 JJ |
22 | #ifdef __VMS__ |
23 | #pragma message disable nosimpint | |
24 | #endif | |
a4294b78 JS |
25 | #include <Xm/Xm.h> |
26 | #include <Xm/Label.h> | |
27 | #include <Xm/LabelG.h> | |
28 | #include <Xm/RowColumn.h> | |
29 | #include <Xm/Scale.h> | |
338dd992 JJ |
30 | #ifdef __VMS__ |
31 | #pragma message enable nosimpint | |
32 | #endif | |
a4294b78 | 33 | |
3096bd2f | 34 | #include "wx/motif/private.h" |
a4294b78 JS |
35 | |
36 | void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs); | |
4bb6408c | 37 | |
4bb6408c JS |
38 | IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl) |
39 | ||
40 | BEGIN_EVENT_TABLE(wxSlider, wxControl) | |
41 | END_EVENT_TABLE() | |
4bb6408c JS |
42 | |
43 | ||
44 | ||
45 | // Slider | |
46 | wxSlider::wxSlider() | |
47 | { | |
2d120f83 JS |
48 | m_pageSize = 1; |
49 | m_lineSize = 1; | |
50 | m_rangeMax = 0; | |
51 | m_rangeMin = 0; | |
4bb6408c JS |
52 | } |
53 | ||
54 | bool wxSlider::Create(wxWindow *parent, wxWindowID id, | |
2d120f83 JS |
55 | int value, int minValue, int maxValue, |
56 | const wxPoint& pos, | |
57 | const wxSize& size, long style, | |
58 | const wxValidator& validator, | |
59 | const wxString& name) | |
93e73c74 | 60 | { |
ba7ce6a0 MB |
61 | if ( !((style & wxSL_HORIZONTAL) || (style & wxSL_VERTICAL)) ) |
62 | style |= wxSL_HORIZONTAL; | |
31528cd3 | 63 | |
93e73c74 MB |
64 | if( !CreateControl( parent, id, pos, size, style, validator, name ) ) |
65 | return false; | |
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 | |
338dd992 JJ |
92 | #ifdef __VMS__ |
93 | #pragma message disable codcauunr | |
94 | // VMS gives here the compiler warning : | |
95 | // statement either is unreachable or causes unreachable code | |
96 | #endif | |
a4294b78 JS |
97 | if(style & wxSL_NOTIFY_DRAG) |
98 | XtAddCallback (sliderWidget, XmNdragCallback, | |
2d120f83 | 99 | (XtCallbackProc) wxSliderCallback, (XtPointer) this); |
a4294b78 JS |
100 | else |
101 | XtAddCallback (sliderWidget, XmNvalueChangedCallback, | |
2d120f83 | 102 | (XtCallbackProc) wxSliderCallback, (XtPointer) this); |
338dd992 JJ |
103 | #ifdef __VMS__ |
104 | #pragma message enable codcauunr | |
105 | #endif | |
31528cd3 | 106 | |
a4294b78 | 107 | XtAddCallback (sliderWidget, XmNdragCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this); |
31528cd3 | 108 | |
4b5f3fe6 | 109 | ChangeFont(FALSE); |
a4294b78 | 110 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); |
31528cd3 | 111 | |
0d57be45 | 112 | ChangeBackgroundColour(); |
31528cd3 | 113 | |
a4294b78 | 114 | return TRUE; |
4bb6408c JS |
115 | } |
116 | ||
117 | wxSlider::~wxSlider() | |
118 | { | |
119 | } | |
120 | ||
121 | int wxSlider::GetValue() const | |
122 | { | |
a4294b78 JS |
123 | int val; |
124 | XtVaGetValues ((Widget) m_mainWidget, XmNvalue, &val, NULL); | |
125 | return val; | |
4bb6408c JS |
126 | } |
127 | ||
128 | void wxSlider::SetValue(int value) | |
129 | { | |
a4294b78 | 130 | XtVaSetValues ((Widget) m_mainWidget, XmNvalue, value, NULL); |
4bb6408c JS |
131 | } |
132 | ||
bfc6fde4 | 133 | void wxSlider::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
4bb6408c | 134 | { |
2d120f83 | 135 | Widget widget = (Widget) m_mainWidget; |
31528cd3 | 136 | |
2d120f83 | 137 | bool managed = XtIsManaged(widget); |
31528cd3 | 138 | |
2d120f83 JS |
139 | if (managed) |
140 | XtUnmanageChild (widget); | |
31528cd3 | 141 | |
2d120f83 JS |
142 | if (((m_windowStyle & wxHORIZONTAL) == wxHORIZONTAL) && (width > -1)) |
143 | { | |
144 | XtVaSetValues (widget, XmNscaleWidth, wxMax (width, 10), NULL); | |
145 | } | |
31528cd3 | 146 | |
2d120f83 JS |
147 | if (((m_windowStyle & wxVERTICAL) == wxVERTICAL) && (height > -1)) |
148 | { | |
149 | XtVaSetValues (widget, XmNscaleHeight, wxMax (height, 10), NULL); | |
150 | } | |
31528cd3 | 151 | |
2d120f83 JS |
152 | int xx = x; int yy = y; |
153 | AdjustForParentClientOrigin(xx, yy, sizeFlags); | |
31528cd3 | 154 | |
2d120f83 JS |
155 | if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
156 | XtVaSetValues (widget, XmNx, xx, NULL); | |
157 | if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
158 | XtVaSetValues (widget, XmNy, yy, NULL); | |
31528cd3 | 159 | |
2d120f83 JS |
160 | if (managed) |
161 | XtManageChild (widget); | |
4bb6408c JS |
162 | } |
163 | ||
164 | void wxSlider::SetRange(int minValue, int maxValue) | |
165 | { | |
166 | m_rangeMin = minValue; | |
167 | m_rangeMax = maxValue; | |
31528cd3 | 168 | |
a4294b78 | 169 | XtVaSetValues ((Widget) m_mainWidget, XmNminimum, minValue, XmNmaximum, maxValue, NULL); |
4bb6408c JS |
170 | } |
171 | ||
172 | // For trackbars only | |
4bb6408c JS |
173 | void wxSlider::SetPageSize(int pageSize) |
174 | { | |
a4294b78 | 175 | // Not implemented in Motif |
4bb6408c JS |
176 | m_pageSize = pageSize; |
177 | } | |
178 | ||
179 | int wxSlider::GetPageSize() const | |
180 | { | |
181 | return m_pageSize; | |
182 | } | |
183 | ||
4bb6408c JS |
184 | void wxSlider::SetLineSize(int lineSize) |
185 | { | |
a4294b78 | 186 | // Not implemented in Motif |
4bb6408c | 187 | m_lineSize = lineSize; |
4bb6408c JS |
188 | } |
189 | ||
190 | int wxSlider::GetLineSize() const | |
191 | { | |
a4294b78 JS |
192 | // Not implemented in Motif |
193 | return m_lineSize; | |
4bb6408c JS |
194 | } |
195 | ||
a4294b78 | 196 | void wxSlider::SetThumbLength(int WXUNUSED(len)) |
4bb6408c | 197 | { |
a4294b78 | 198 | // Not implemented in Motif (?) |
4bb6408c JS |
199 | } |
200 | ||
201 | int wxSlider::GetThumbLength() const | |
202 | { | |
a4294b78 | 203 | // Not implemented in Motif (?) |
4bb6408c JS |
204 | return 0; |
205 | } | |
206 | ||
4bb6408c JS |
207 | void wxSlider::Command (wxCommandEvent & event) |
208 | { | |
2d120f83 JS |
209 | SetValue (event.GetInt()); |
210 | ProcessCommand (event); | |
4bb6408c JS |
211 | } |
212 | ||
93e73c74 MB |
213 | void wxSliderCallback (Widget widget, XtPointer clientData, |
214 | XmScaleCallbackStruct * cbs) | |
4bb6408c | 215 | { |
a4294b78 | 216 | wxSlider *slider = (wxSlider *) clientData; |
93e73c74 MB |
217 | wxEventType scrollEvent; |
218 | ||
a4294b78 JS |
219 | switch (cbs->reason) |
220 | { | |
2d120f83 | 221 | case XmCR_VALUE_CHANGED: |
93e73c74 MB |
222 | scrollEvent = wxEVT_SCROLL_THUMBRELEASE; |
223 | break; | |
224 | ||
2d120f83 | 225 | case XmCR_DRAG: |
93e73c74 MB |
226 | scrollEvent = wxEVT_SCROLL_THUMBTRACK; |
227 | break; | |
228 | ||
2d120f83 | 229 | default: |
93e73c74 | 230 | return; |
a4294b78 | 231 | } |
93e73c74 MB |
232 | |
233 | wxScrollEvent event(scrollEvent, slider->GetId()); | |
234 | XtVaGetValues (widget, XmNvalue, &event.m_commandInt, NULL); | |
235 | event.SetEventObject(slider); | |
236 | slider->GetEventHandler()->ProcessEvent(event); | |
237 | ||
238 | // Also send a wxCommandEvent for compatibility. | |
239 | wxCommandEvent event2(wxEVT_COMMAND_SLIDER_UPDATED, slider->GetId()); | |
240 | event2.SetEventObject(slider); | |
241 | event2.SetInt( event.GetInt() ); | |
242 | slider->GetEventHandler()->ProcessEvent(event2); | |
4bb6408c JS |
243 | } |
244 |