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