1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "slider.h"
16 #include "wx/slider.h"
20 #pragma message disable nosimpint
24 #include <Xm/LabelG.h>
25 #include <Xm/RowColumn.h>
28 #pragma message enable nosimpint
31 #include "wx/motif/private.h"
33 void wxSliderCallback (Widget widget
, XtPointer clientData
, XmScaleCallbackStruct
* cbs
);
35 IMPLEMENT_DYNAMIC_CLASS(wxSlider
, wxControl
)
37 BEGIN_EVENT_TABLE(wxSlider
, wxControl
)
51 bool wxSlider::Create(wxWindow
*parent
, wxWindowID id
,
52 int value
, int minValue
, int maxValue
,
54 const wxSize
& size
, long style
,
55 const wxValidator
& validator
,
58 if ( !((style
& wxSL_HORIZONTAL
) || (style
& wxSL_VERTICAL
)) )
59 style
|= wxSL_HORIZONTAL
;
61 if( !CreateControl( parent
, id
, pos
, size
, style
, validator
, name
) )
65 m_windowStyle
= style
;
67 m_rangeMax
= maxValue
;
68 m_rangeMin
= minValue
;
70 // Not used in Motif, I think
71 m_pageSize
= (int)((maxValue
-minValue
)/10);
73 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
75 Widget sliderWidget
= XtVaCreateManagedWidget ("sliderWidget",
76 xmScaleWidgetClass
, parentWidget
,
78 (((m_windowStyle
& wxSL_VERTICAL
) == wxSL_VERTICAL
) ? XmVERTICAL
: XmHORIZONTAL
),
79 XmNprocessingDirection
,
80 (((m_windowStyle
& wxSL_VERTICAL
) == wxSL_VERTICAL
) ? XmMAX_ON_TOP
: XmMAX_ON_RIGHT
),
87 m_mainWidget
= (WXWidget
) sliderWidget
;
90 #pragma message disable codcauunr
91 // VMS gives here the compiler warning :
92 // statement either is unreachable or causes unreachable code
94 if(style
& wxSL_NOTIFY_DRAG
)
95 XtAddCallback (sliderWidget
, XmNdragCallback
,
96 (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
98 XtAddCallback (sliderWidget
, XmNvalueChangedCallback
,
99 (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
101 #pragma message enable codcauunr
104 XtAddCallback (sliderWidget
, XmNdragCallback
, (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
107 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
109 ChangeBackgroundColour();
114 wxSlider::~wxSlider()
118 int wxSlider::GetValue() const
121 XtVaGetValues ((Widget
) m_mainWidget
, XmNvalue
, &val
, NULL
);
125 void wxSlider::SetValue(int value
)
127 XtVaSetValues ((Widget
) m_mainWidget
, XmNvalue
, value
, NULL
);
130 void wxSlider::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
132 Widget widget
= (Widget
) m_mainWidget
;
134 bool managed
= XtIsManaged(widget
);
137 XtUnmanageChild (widget
);
139 if (((m_windowStyle
& wxHORIZONTAL
) == wxHORIZONTAL
) && (width
> -1))
141 XtVaSetValues (widget
, XmNscaleWidth
, wxMax (width
, 10), NULL
);
144 if (((m_windowStyle
& wxVERTICAL
) == wxVERTICAL
) && (height
> -1))
146 XtVaSetValues (widget
, XmNscaleHeight
, wxMax (height
, 10), NULL
);
149 int xx
= x
; int yy
= y
;
150 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
152 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
153 XtVaSetValues (widget
, XmNx
, xx
, NULL
);
154 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
155 XtVaSetValues (widget
, XmNy
, yy
, NULL
);
158 XtManageChild (widget
);
161 void wxSlider::SetRange(int minValue
, int maxValue
)
163 m_rangeMin
= minValue
;
164 m_rangeMax
= maxValue
;
166 XtVaSetValues ((Widget
) m_mainWidget
, XmNminimum
, minValue
, XmNmaximum
, maxValue
, NULL
);
169 // For trackbars only
170 void wxSlider::SetPageSize(int pageSize
)
172 // Not implemented in Motif
173 m_pageSize
= pageSize
;
176 int wxSlider::GetPageSize() const
181 void wxSlider::SetLineSize(int lineSize
)
183 // Not implemented in Motif
184 m_lineSize
= lineSize
;
187 int wxSlider::GetLineSize() const
189 // Not implemented in Motif
193 void wxSlider::SetThumbLength(int WXUNUSED(len
))
195 // Not implemented in Motif (?)
198 int wxSlider::GetThumbLength() const
200 // Not implemented in Motif (?)
204 void wxSlider::Command (wxCommandEvent
& event
)
206 SetValue (event
.GetInt());
207 ProcessCommand (event
);
210 void wxSliderCallback (Widget widget
, XtPointer clientData
,
211 XmScaleCallbackStruct
* cbs
)
213 wxSlider
*slider
= (wxSlider
*) clientData
;
214 wxEventType scrollEvent
;
218 case XmCR_VALUE_CHANGED
:
219 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
223 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
230 wxScrollEvent
event(scrollEvent
, slider
->GetId());
231 XtVaGetValues (widget
, XmNvalue
, &event
.m_commandInt
, NULL
);
232 event
.SetEventObject(slider
);
233 slider
->GetEventHandler()->ProcessEvent(event
);
235 // Also send a wxCommandEvent for compatibility.
236 wxCommandEvent
event2(wxEVT_COMMAND_SLIDER_UPDATED
, slider
->GetId());
237 event2
.SetEventObject(slider
);
238 event2
.SetInt( event
.GetInt() );
239 slider
->GetEventHandler()->ProcessEvent(event2
);