]> git.saurik.com Git - wxWidgets.git/blob - src/motif/slider.cpp
Fixed detection of Meta key state so that NumLock isn't misdetected as Meta.
[wxWidgets.git] / src / motif / slider.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/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 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #if wxUSE_SLIDER
16
17 #include "wx/slider.h"
18
19 #ifndef WX_PRECOMP
20 #include "wx/utils.h"
21 #endif
22
23 #ifdef __VMS__
24 #pragma message disable nosimpint
25 #endif
26 #include <Xm/Xm.h>
27 #include <Xm/Label.h>
28 #include <Xm/LabelG.h>
29 #include <Xm/RowColumn.h>
30 #include <Xm/Scale.h>
31 #ifdef __VMS__
32 #pragma message enable nosimpint
33 #endif
34
35 #include "wx/motif/private.h"
36
37 static void wxSliderCallback (Widget widget, XtPointer clientData, XmScaleCallbackStruct * cbs);
38
39 IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
40
41 BEGIN_EVENT_TABLE(wxSlider, wxControl)
42 END_EVENT_TABLE()
43
44
45
46 // Slider
47 wxSlider::wxSlider()
48 {
49 m_pageSize = 1;
50 m_lineSize = 1;
51 m_rangeMax = 0;
52 m_rangeMin = 0;
53 }
54
55 bool wxSlider::Create(wxWindow *parent, wxWindowID id,
56 int value, int minValue, int maxValue,
57 const wxPoint& pos,
58 const wxSize& size, long style,
59 const wxValidator& validator,
60 const wxString& name)
61 {
62 if ( !((style & wxSL_HORIZONTAL) || (style & wxSL_VERTICAL)) )
63 style |= wxSL_HORIZONTAL;
64
65 if( !CreateControl( parent, id, pos, size, style, validator, name ) )
66 return false;
67 PreCreation();
68
69 m_lineSize = 1;
70 m_windowStyle = style;
71
72 m_rangeMax = maxValue;
73 m_rangeMin = minValue;
74
75 // Not used in Motif, I think
76 m_pageSize = (int)((maxValue-minValue)/10);
77
78 Widget parentWidget = (Widget) parent->GetClientWidget();
79
80 Widget sliderWidget = XtVaCreateManagedWidget ("sliderWidget",
81 xmScaleWidgetClass, parentWidget,
82 XmNorientation,
83 (((m_windowStyle & wxSL_VERTICAL) == wxSL_VERTICAL) ? XmVERTICAL : XmHORIZONTAL),
84 XmNprocessingDirection,
85 (((m_windowStyle & wxSL_VERTICAL) == wxSL_VERTICAL) ? XmMAX_ON_TOP : XmMAX_ON_RIGHT),
86 XmNmaximum, maxValue,
87 XmNminimum, minValue,
88 XmNvalue, value,
89 XmNshowValue, True,
90 NULL);
91
92 m_mainWidget = (WXWidget) sliderWidget;
93
94 XtAddCallback (sliderWidget, XmNvalueChangedCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this);
95 XtAddCallback (sliderWidget, XmNdragCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this);
96
97 PostCreation();
98 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
99
100 return true;
101 }
102
103 wxSlider::~wxSlider()
104 {
105 }
106
107 int wxSlider::GetValue() const
108 {
109 int val;
110 XtVaGetValues ((Widget) m_mainWidget, XmNvalue, &val, NULL);
111 return val;
112 }
113
114 void wxSlider::SetValue(int value)
115 {
116 XtVaSetValues ((Widget) m_mainWidget, XmNvalue, value, NULL);
117 }
118
119 void wxSlider::DoSetSize(int x, int y, int width, int height, int sizeFlags)
120 {
121 Widget widget = (Widget) m_mainWidget;
122
123 bool managed = XtIsManaged(widget);
124
125 if (managed)
126 XtUnmanageChild (widget);
127
128 if (((m_windowStyle & wxHORIZONTAL) == wxHORIZONTAL) && (width > -1))
129 {
130 XtVaSetValues (widget, XmNscaleWidth, wxMax (width, 10), NULL);
131 }
132
133 if (((m_windowStyle & wxVERTICAL) == wxVERTICAL) && (height > -1))
134 {
135 XtVaSetValues (widget, XmNscaleHeight, wxMax (height, 10), NULL);
136 }
137
138 int xx = x; int yy = y;
139 AdjustForParentClientOrigin(xx, yy, sizeFlags);
140
141 if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
142 XtVaSetValues (widget, XmNx, xx, NULL);
143 if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
144 XtVaSetValues (widget, XmNy, yy, NULL);
145
146 if (managed)
147 XtManageChild (widget);
148 }
149
150 void wxSlider::SetRange(int minValue, int maxValue)
151 {
152 m_rangeMin = minValue;
153 m_rangeMax = maxValue;
154
155 XtVaSetValues ((Widget) m_mainWidget, XmNminimum, minValue, XmNmaximum, maxValue, NULL);
156 }
157
158 // For trackbars only
159 void wxSlider::SetPageSize(int pageSize)
160 {
161 // Not implemented in Motif
162 m_pageSize = pageSize;
163 }
164
165 int wxSlider::GetPageSize() const
166 {
167 return m_pageSize;
168 }
169
170 void wxSlider::SetLineSize(int lineSize)
171 {
172 // Not implemented in Motif
173 m_lineSize = lineSize;
174 }
175
176 int wxSlider::GetLineSize() const
177 {
178 // Not implemented in Motif
179 return m_lineSize;
180 }
181
182 void wxSlider::SetThumbLength(int WXUNUSED(len))
183 {
184 // Not implemented in Motif (?)
185 }
186
187 int wxSlider::GetThumbLength() const
188 {
189 // Not implemented in Motif (?)
190 return 0;
191 }
192
193 void wxSlider::Command (wxCommandEvent & event)
194 {
195 SetValue (event.GetInt());
196 ProcessCommand (event);
197 }
198
199 void wxSliderCallback (Widget widget, XtPointer clientData,
200 XmScaleCallbackStruct * cbs)
201 {
202 wxSlider *slider = (wxSlider *) clientData;
203 wxEventType scrollEvent;
204
205 switch (cbs->reason)
206 {
207 case XmCR_VALUE_CHANGED:
208 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
209 break;
210
211 case XmCR_DRAG:
212 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
213 break;
214
215 default:
216 return;
217 }
218
219 wxScrollEvent event(scrollEvent, slider->GetId());
220 int commandInt = event.GetInt();
221 XtVaGetValues (widget, XmNvalue, &commandInt, NULL);
222 event.SetInt(commandInt);
223 event.SetEventObject(slider);
224 slider->HandleWindowEvent(event);
225
226 // Also send a wxCommandEvent for compatibility.
227 wxCommandEvent event2(wxEVT_COMMAND_SLIDER_UPDATED, slider->GetId());
228 event2.SetEventObject(slider);
229 event2.SetInt( event.GetInt() );
230 slider->HandleWindowEvent(event2);
231 }
232
233 #endif // wxUSE_SLIDER