]> git.saurik.com Git - wxWidgets.git/blob - src/motif/slider.cpp
move generic part of AdjustSize() and status bar methods to the base class
[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
68 m_lineSize = 1;
69 m_windowStyle = style;
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 XtAddCallback (sliderWidget, XmNvalueChangedCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this);
94 XtAddCallback (sliderWidget, XmNdragCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this);
95
96 ChangeFont(false);
97 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
98
99 ChangeBackgroundColour();
100
101 return true;
102 }
103
104 wxSlider::~wxSlider()
105 {
106 }
107
108 int wxSlider::GetValue() const
109 {
110 int val;
111 XtVaGetValues ((Widget) m_mainWidget, XmNvalue, &val, NULL);
112 return val;
113 }
114
115 void wxSlider::SetValue(int value)
116 {
117 XtVaSetValues ((Widget) m_mainWidget, XmNvalue, value, NULL);
118 }
119
120 void wxSlider::DoSetSize(int x, int y, int width, int height, int sizeFlags)
121 {
122 Widget widget = (Widget) m_mainWidget;
123
124 bool managed = XtIsManaged(widget);
125
126 if (managed)
127 XtUnmanageChild (widget);
128
129 if (((m_windowStyle & wxHORIZONTAL) == wxHORIZONTAL) && (width > -1))
130 {
131 XtVaSetValues (widget, XmNscaleWidth, wxMax (width, 10), NULL);
132 }
133
134 if (((m_windowStyle & wxVERTICAL) == wxVERTICAL) && (height > -1))
135 {
136 XtVaSetValues (widget, XmNscaleHeight, wxMax (height, 10), NULL);
137 }
138
139 int xx = x; int yy = y;
140 AdjustForParentClientOrigin(xx, yy, sizeFlags);
141
142 if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
143 XtVaSetValues (widget, XmNx, xx, NULL);
144 if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
145 XtVaSetValues (widget, XmNy, yy, NULL);
146
147 if (managed)
148 XtManageChild (widget);
149 }
150
151 void wxSlider::SetRange(int minValue, int maxValue)
152 {
153 m_rangeMin = minValue;
154 m_rangeMax = maxValue;
155
156 XtVaSetValues ((Widget) m_mainWidget, XmNminimum, minValue, XmNmaximum, maxValue, NULL);
157 }
158
159 // For trackbars only
160 void wxSlider::SetPageSize(int pageSize)
161 {
162 // Not implemented in Motif
163 m_pageSize = pageSize;
164 }
165
166 int wxSlider::GetPageSize() const
167 {
168 return m_pageSize;
169 }
170
171 void wxSlider::SetLineSize(int lineSize)
172 {
173 // Not implemented in Motif
174 m_lineSize = lineSize;
175 }
176
177 int wxSlider::GetLineSize() const
178 {
179 // Not implemented in Motif
180 return m_lineSize;
181 }
182
183 void wxSlider::SetThumbLength(int WXUNUSED(len))
184 {
185 // Not implemented in Motif (?)
186 }
187
188 int wxSlider::GetThumbLength() const
189 {
190 // Not implemented in Motif (?)
191 return 0;
192 }
193
194 void wxSlider::Command (wxCommandEvent & event)
195 {
196 SetValue (event.GetInt());
197 ProcessCommand (event);
198 }
199
200 void wxSliderCallback (Widget widget, XtPointer clientData,
201 XmScaleCallbackStruct * cbs)
202 {
203 wxSlider *slider = (wxSlider *) clientData;
204 wxEventType scrollEvent;
205
206 switch (cbs->reason)
207 {
208 case XmCR_VALUE_CHANGED:
209 scrollEvent = wxEVT_SCROLL_THUMBRELEASE;
210 break;
211
212 case XmCR_DRAG:
213 scrollEvent = wxEVT_SCROLL_THUMBTRACK;
214 break;
215
216 default:
217 return;
218 }
219
220 wxScrollEvent event(scrollEvent, slider->GetId());
221 int commandInt = event.GetInt();
222 XtVaGetValues (widget, XmNvalue, &commandInt, NULL);
223 event.SetInt(commandInt);
224 event.SetEventObject(slider);
225 slider->GetEventHandler()->ProcessEvent(event);
226
227 // Also send a wxCommandEvent for compatibility.
228 wxCommandEvent event2(wxEVT_COMMAND_SLIDER_UPDATED, slider->GetId());
229 event2.SetEventObject(slider);
230 event2.SetInt( event.GetInt() );
231 slider->GetEventHandler()->ProcessEvent(event2);
232 }
233
234 #endif // wxUSE_SLIDER