1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #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 static 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
;
92 XtAddCallback (sliderWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
93 XtAddCallback (sliderWidget
, XmNdragCallback
, (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
96 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
98 ChangeBackgroundColour();
103 wxSlider::~wxSlider()
107 int wxSlider::GetValue() const
110 XtVaGetValues ((Widget
) m_mainWidget
, XmNvalue
, &val
, NULL
);
114 void wxSlider::SetValue(int value
)
116 XtVaSetValues ((Widget
) m_mainWidget
, XmNvalue
, value
, NULL
);
119 void wxSlider::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
121 Widget widget
= (Widget
) m_mainWidget
;
123 bool managed
= XtIsManaged(widget
);
126 XtUnmanageChild (widget
);
128 if (((m_windowStyle
& wxHORIZONTAL
) == wxHORIZONTAL
) && (width
> -1))
130 XtVaSetValues (widget
, XmNscaleWidth
, wxMax (width
, 10), NULL
);
133 if (((m_windowStyle
& wxVERTICAL
) == wxVERTICAL
) && (height
> -1))
135 XtVaSetValues (widget
, XmNscaleHeight
, wxMax (height
, 10), NULL
);
138 int xx
= x
; int yy
= y
;
139 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
141 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
142 XtVaSetValues (widget
, XmNx
, xx
, NULL
);
143 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
144 XtVaSetValues (widget
, XmNy
, yy
, NULL
);
147 XtManageChild (widget
);
150 void wxSlider::SetRange(int minValue
, int maxValue
)
152 m_rangeMin
= minValue
;
153 m_rangeMax
= maxValue
;
155 XtVaSetValues ((Widget
) m_mainWidget
, XmNminimum
, minValue
, XmNmaximum
, maxValue
, NULL
);
158 // For trackbars only
159 void wxSlider::SetPageSize(int pageSize
)
161 // Not implemented in Motif
162 m_pageSize
= pageSize
;
165 int wxSlider::GetPageSize() const
170 void wxSlider::SetLineSize(int lineSize
)
172 // Not implemented in Motif
173 m_lineSize
= lineSize
;
176 int wxSlider::GetLineSize() const
178 // Not implemented in Motif
182 void wxSlider::SetThumbLength(int WXUNUSED(len
))
184 // Not implemented in Motif (?)
187 int wxSlider::GetThumbLength() const
189 // Not implemented in Motif (?)
193 void wxSlider::Command (wxCommandEvent
& event
)
195 SetValue (event
.GetInt());
196 ProcessCommand (event
);
199 void wxSliderCallback (Widget widget
, XtPointer clientData
,
200 XmScaleCallbackStruct
* cbs
)
202 wxSlider
*slider
= (wxSlider
*) clientData
;
203 wxEventType scrollEvent
;
207 case XmCR_VALUE_CHANGED
:
208 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
212 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
219 wxScrollEvent
event(scrollEvent
, slider
->GetId());
220 int commandInt
= event
.GetInt();
221 XtVaGetValues (widget
, XmNvalue
, &commandInt
, NULL
);
222 event
.SetInt(commandInt
);
223 event
.SetEventObject(slider
);
224 slider
->GetEventHandler()->ProcessEvent(event
);
226 // Also send a wxCommandEvent for compatibility.
227 wxCommandEvent
event2(wxEVT_COMMAND_SLIDER_UPDATED
, slider
->GetId());
228 event2
.SetEventObject(slider
);
229 event2
.SetInt( event
.GetInt() );
230 slider
->GetEventHandler()->ProcessEvent(event2
);
233 #endif // wxUSE_SLIDER