1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "slider.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #include "wx/slider.h"
27 #pragma message disable nosimpint
31 #include <Xm/LabelG.h>
32 #include <Xm/RowColumn.h>
35 #pragma message enable nosimpint
38 #include "wx/motif/private.h"
40 void wxSliderCallback (Widget widget
, XtPointer clientData
, XmScaleCallbackStruct
* cbs
);
42 IMPLEMENT_DYNAMIC_CLASS(wxSlider
, wxControl
)
44 BEGIN_EVENT_TABLE(wxSlider
, wxControl
)
58 bool wxSlider::Create(wxWindow
*parent
, wxWindowID id
,
59 int value
, int minValue
, int maxValue
,
61 const wxSize
& size
, long style
,
62 const wxValidator
& validator
,
65 if ( !((style
& wxSL_HORIZONTAL
) || (style
& wxSL_VERTICAL
)) )
66 style
|= wxSL_HORIZONTAL
;
68 if( !CreateControl( parent
, id
, pos
, size
, style
, validator
, name
) )
72 m_windowStyle
= style
;
74 m_rangeMax
= maxValue
;
75 m_rangeMin
= minValue
;
77 // Not used in Motif, I think
78 m_pageSize
= (int)((maxValue
-minValue
)/10);
80 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
82 Widget sliderWidget
= XtVaCreateManagedWidget ("sliderWidget",
83 xmScaleWidgetClass
, parentWidget
,
85 (((m_windowStyle
& wxSL_VERTICAL
) == wxSL_VERTICAL
) ? XmVERTICAL
: XmHORIZONTAL
),
86 XmNprocessingDirection
,
87 (((m_windowStyle
& wxSL_VERTICAL
) == wxSL_VERTICAL
) ? XmMAX_ON_TOP
: XmMAX_ON_RIGHT
),
94 m_mainWidget
= (WXWidget
) sliderWidget
;
97 #pragma message disable codcauunr
98 // VMS gives here the compiler warning :
99 // statement either is unreachable or causes unreachable code
101 if(style
& wxSL_NOTIFY_DRAG
)
102 XtAddCallback (sliderWidget
, XmNdragCallback
,
103 (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
105 XtAddCallback (sliderWidget
, XmNvalueChangedCallback
,
106 (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
108 #pragma message enable codcauunr
111 XtAddCallback (sliderWidget
, XmNdragCallback
, (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
114 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
116 ChangeBackgroundColour();
121 wxSlider::~wxSlider()
125 int wxSlider::GetValue() const
128 XtVaGetValues ((Widget
) m_mainWidget
, XmNvalue
, &val
, NULL
);
132 void wxSlider::SetValue(int value
)
134 XtVaSetValues ((Widget
) m_mainWidget
, XmNvalue
, value
, NULL
);
137 void wxSlider::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
139 Widget widget
= (Widget
) m_mainWidget
;
141 bool managed
= XtIsManaged(widget
);
144 XtUnmanageChild (widget
);
146 if (((m_windowStyle
& wxHORIZONTAL
) == wxHORIZONTAL
) && (width
> -1))
148 XtVaSetValues (widget
, XmNscaleWidth
, wxMax (width
, 10), NULL
);
151 if (((m_windowStyle
& wxVERTICAL
) == wxVERTICAL
) && (height
> -1))
153 XtVaSetValues (widget
, XmNscaleHeight
, wxMax (height
, 10), NULL
);
156 int xx
= x
; int yy
= y
;
157 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
159 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
160 XtVaSetValues (widget
, XmNx
, xx
, NULL
);
161 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
162 XtVaSetValues (widget
, XmNy
, yy
, NULL
);
165 XtManageChild (widget
);
168 void wxSlider::SetRange(int minValue
, int maxValue
)
170 m_rangeMin
= minValue
;
171 m_rangeMax
= maxValue
;
173 XtVaSetValues ((Widget
) m_mainWidget
, XmNminimum
, minValue
, XmNmaximum
, maxValue
, NULL
);
176 // For trackbars only
177 void wxSlider::SetPageSize(int pageSize
)
179 // Not implemented in Motif
180 m_pageSize
= pageSize
;
183 int wxSlider::GetPageSize() const
188 void wxSlider::SetLineSize(int lineSize
)
190 // Not implemented in Motif
191 m_lineSize
= lineSize
;
194 int wxSlider::GetLineSize() const
196 // Not implemented in Motif
200 void wxSlider::SetThumbLength(int WXUNUSED(len
))
202 // Not implemented in Motif (?)
205 int wxSlider::GetThumbLength() const
207 // Not implemented in Motif (?)
211 void wxSlider::Command (wxCommandEvent
& event
)
213 SetValue (event
.GetInt());
214 ProcessCommand (event
);
217 void wxSliderCallback (Widget widget
, XtPointer clientData
,
218 XmScaleCallbackStruct
* cbs
)
220 wxSlider
*slider
= (wxSlider
*) clientData
;
221 wxEventType scrollEvent
;
225 case XmCR_VALUE_CHANGED
:
226 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
230 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
237 wxScrollEvent
event(scrollEvent
, slider
->GetId());
238 int commandInt
= event
.GetInt();
239 XtVaGetValues (widget
, XmNvalue
, &commandInt
, NULL
);
240 event
.SetInt(commandInt
);
241 event
.SetEventObject(slider
);
242 slider
->GetEventHandler()->ProcessEvent(event
);
244 // Also send a wxCommandEvent for compatibility.
245 wxCommandEvent
event2(wxEVT_COMMAND_SLIDER_UPDATED
, slider
->GetId());
246 event2
.SetEventObject(slider
);
247 event2
.SetInt( event
.GetInt() );
248 slider
->GetEventHandler()->ProcessEvent(event2
);
251 #endif // wxUSE_SLIDER