1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWidgets 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"
19 #include "wx/slider.h"
23 #pragma message disable nosimpint
27 #include <Xm/LabelG.h>
28 #include <Xm/RowColumn.h>
31 #pragma message enable nosimpint
34 #include "wx/motif/private.h"
36 void wxSliderCallback (Widget widget
, XtPointer clientData
, XmScaleCallbackStruct
* cbs
);
38 IMPLEMENT_DYNAMIC_CLASS(wxSlider
, wxControl
)
40 BEGIN_EVENT_TABLE(wxSlider
, wxControl
)
54 bool wxSlider::Create(wxWindow
*parent
, wxWindowID id
,
55 int value
, int minValue
, int maxValue
,
57 const wxSize
& size
, long style
,
58 const wxValidator
& validator
,
61 if ( !((style
& wxSL_HORIZONTAL
) || (style
& wxSL_VERTICAL
)) )
62 style
|= wxSL_HORIZONTAL
;
64 if( !CreateControl( parent
, id
, pos
, size
, style
, validator
, name
) )
68 m_windowStyle
= style
;
70 m_rangeMax
= maxValue
;
71 m_rangeMin
= minValue
;
73 // Not used in Motif, I think
74 m_pageSize
= (int)((maxValue
-minValue
)/10);
76 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
78 Widget sliderWidget
= XtVaCreateManagedWidget ("sliderWidget",
79 xmScaleWidgetClass
, parentWidget
,
81 (((m_windowStyle
& wxSL_VERTICAL
) == wxSL_VERTICAL
) ? XmVERTICAL
: XmHORIZONTAL
),
82 XmNprocessingDirection
,
83 (((m_windowStyle
& wxSL_VERTICAL
) == wxSL_VERTICAL
) ? XmMAX_ON_TOP
: XmMAX_ON_RIGHT
),
90 m_mainWidget
= (WXWidget
) sliderWidget
;
93 #pragma message disable codcauunr
94 // VMS gives here the compiler warning :
95 // statement either is unreachable or causes unreachable code
97 if(style
& wxSL_NOTIFY_DRAG
)
98 XtAddCallback (sliderWidget
, XmNdragCallback
,
99 (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
101 XtAddCallback (sliderWidget
, XmNvalueChangedCallback
,
102 (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
104 #pragma message enable codcauunr
107 XtAddCallback (sliderWidget
, XmNdragCallback
, (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
110 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
112 ChangeBackgroundColour();
117 wxSlider::~wxSlider()
121 int wxSlider::GetValue() const
124 XtVaGetValues ((Widget
) m_mainWidget
, XmNvalue
, &val
, NULL
);
128 void wxSlider::SetValue(int value
)
130 XtVaSetValues ((Widget
) m_mainWidget
, XmNvalue
, value
, NULL
);
133 void wxSlider::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
135 Widget widget
= (Widget
) m_mainWidget
;
137 bool managed
= XtIsManaged(widget
);
140 XtUnmanageChild (widget
);
142 if (((m_windowStyle
& wxHORIZONTAL
) == wxHORIZONTAL
) && (width
> -1))
144 XtVaSetValues (widget
, XmNscaleWidth
, wxMax (width
, 10), NULL
);
147 if (((m_windowStyle
& wxVERTICAL
) == wxVERTICAL
) && (height
> -1))
149 XtVaSetValues (widget
, XmNscaleHeight
, wxMax (height
, 10), NULL
);
152 int xx
= x
; int yy
= y
;
153 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
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
);
161 XtManageChild (widget
);
164 void wxSlider::SetRange(int minValue
, int maxValue
)
166 m_rangeMin
= minValue
;
167 m_rangeMax
= maxValue
;
169 XtVaSetValues ((Widget
) m_mainWidget
, XmNminimum
, minValue
, XmNmaximum
, maxValue
, NULL
);
172 // For trackbars only
173 void wxSlider::SetPageSize(int pageSize
)
175 // Not implemented in Motif
176 m_pageSize
= pageSize
;
179 int wxSlider::GetPageSize() const
184 void wxSlider::SetLineSize(int lineSize
)
186 // Not implemented in Motif
187 m_lineSize
= lineSize
;
190 int wxSlider::GetLineSize() const
192 // Not implemented in Motif
196 void wxSlider::SetThumbLength(int WXUNUSED(len
))
198 // Not implemented in Motif (?)
201 int wxSlider::GetThumbLength() const
203 // Not implemented in Motif (?)
207 void wxSlider::Command (wxCommandEvent
& event
)
209 SetValue (event
.GetInt());
210 ProcessCommand (event
);
213 void wxSliderCallback (Widget widget
, XtPointer clientData
,
214 XmScaleCallbackStruct
* cbs
)
216 wxSlider
*slider
= (wxSlider
*) clientData
;
217 wxEventType scrollEvent
;
221 case XmCR_VALUE_CHANGED
:
222 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
226 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
233 wxScrollEvent
event(scrollEvent
, slider
->GetId());
234 XtVaGetValues (widget
, XmNvalue
, &event
.m_commandInt
, NULL
);
235 event
.SetEventObject(slider
);
236 slider
->GetEventHandler()->ProcessEvent(event
);
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
);