1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/slider.cpp
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
16 #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 BEGIN_EVENT_TABLE(wxSlider
, wxControl
)
52 bool wxSlider::Create(wxWindow
*parent
, wxWindowID id
,
53 int value
, int minValue
, int maxValue
,
55 const wxSize
& size
, long style
,
56 const wxValidator
& validator
,
59 if ( !((style
& wxSL_HORIZONTAL
) || (style
& wxSL_VERTICAL
)) )
60 style
|= wxSL_HORIZONTAL
;
62 if( !CreateControl( parent
, id
, pos
, size
, style
, validator
, name
) )
67 m_windowStyle
= style
;
69 m_rangeMax
= maxValue
;
70 m_rangeMin
= minValue
;
72 // Not used in Motif, I think
73 m_pageSize
= (int)((maxValue
-minValue
)/10);
75 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
77 Widget sliderWidget
= XtVaCreateManagedWidget ("sliderWidget",
78 xmScaleWidgetClass
, parentWidget
,
80 (((m_windowStyle
& wxSL_VERTICAL
) == wxSL_VERTICAL
) ? XmVERTICAL
: XmHORIZONTAL
),
81 XmNprocessingDirection
,
82 (((m_windowStyle
& wxSL_VERTICAL
) == wxSL_VERTICAL
) ? XmMAX_ON_TOP
: XmMAX_ON_RIGHT
),
89 m_mainWidget
= (WXWidget
) sliderWidget
;
91 XtAddCallback (sliderWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
92 XtAddCallback (sliderWidget
, XmNdragCallback
, (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
95 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
100 wxSlider::~wxSlider()
104 int wxSlider::GetValue() const
107 XtVaGetValues ((Widget
) m_mainWidget
, XmNvalue
, &val
, NULL
);
111 void wxSlider::SetValue(int value
)
113 XtVaSetValues ((Widget
) m_mainWidget
, XmNvalue
, value
, NULL
);
116 void wxSlider::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
118 Widget widget
= (Widget
) m_mainWidget
;
120 bool managed
= XtIsManaged(widget
);
123 XtUnmanageChild (widget
);
125 if (((m_windowStyle
& wxHORIZONTAL
) == wxHORIZONTAL
) && (width
> -1))
127 XtVaSetValues (widget
, XmNscaleWidth
, wxMax (width
, 10), NULL
);
130 if (((m_windowStyle
& wxVERTICAL
) == wxVERTICAL
) && (height
> -1))
132 XtVaSetValues (widget
, XmNscaleHeight
, wxMax (height
, 10), NULL
);
135 int xx
= x
; int yy
= y
;
136 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
138 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
139 XtVaSetValues (widget
, XmNx
, xx
, NULL
);
140 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
141 XtVaSetValues (widget
, XmNy
, yy
, NULL
);
144 XtManageChild (widget
);
147 void wxSlider::SetRange(int minValue
, int maxValue
)
149 m_rangeMin
= minValue
;
150 m_rangeMax
= maxValue
;
152 XtVaSetValues ((Widget
) m_mainWidget
, XmNminimum
, minValue
, XmNmaximum
, maxValue
, NULL
);
155 // For trackbars only
156 void wxSlider::SetPageSize(int pageSize
)
158 // Not implemented in Motif
159 m_pageSize
= pageSize
;
162 int wxSlider::GetPageSize() const
167 void wxSlider::SetLineSize(int lineSize
)
169 // Not implemented in Motif
170 m_lineSize
= lineSize
;
173 int wxSlider::GetLineSize() const
175 // Not implemented in Motif
179 void wxSlider::SetThumbLength(int WXUNUSED(len
))
181 // Not implemented in Motif (?)
184 int wxSlider::GetThumbLength() const
186 // Not implemented in Motif (?)
190 void wxSlider::Command (wxCommandEvent
& event
)
192 SetValue (event
.GetInt());
193 ProcessCommand (event
);
196 void wxSliderCallback (Widget widget
, XtPointer clientData
,
197 XmScaleCallbackStruct
* cbs
)
199 wxSlider
*slider
= (wxSlider
*) clientData
;
200 wxEventType scrollEvent
;
204 case XmCR_VALUE_CHANGED
:
205 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
209 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
216 wxScrollEvent
event(scrollEvent
, slider
->GetId());
217 int commandInt
= event
.GetInt();
218 XtVaGetValues (widget
, XmNvalue
, &commandInt
, NULL
);
219 event
.SetInt(commandInt
);
220 event
.SetEventObject(slider
);
221 slider
->HandleWindowEvent(event
);
223 // Also send a wxCommandEvent for compatibility.
224 wxCommandEvent
event2(wxEVT_SLIDER
, slider
->GetId());
225 event2
.SetEventObject(slider
);
226 event2
.SetInt( event
.GetInt() );
227 slider
->HandleWindowEvent(event2
);
230 #endif // wxUSE_SLIDER