1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/slider.cpp
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"
17 #include "wx/slider.h"
24 #pragma message disable nosimpint
28 #include <Xm/LabelG.h>
29 #include <Xm/RowColumn.h>
32 #pragma message enable nosimpint
35 #include "wx/motif/private.h"
37 static void wxSliderCallback (Widget widget
, XtPointer clientData
, XmScaleCallbackStruct
* cbs
);
39 BEGIN_EVENT_TABLE(wxSlider
, wxControl
)
53 bool wxSlider::Create(wxWindow
*parent
, wxWindowID id
,
54 int value
, int minValue
, int maxValue
,
56 const wxSize
& size
, long style
,
57 const wxValidator
& validator
,
60 if ( !((style
& wxSL_HORIZONTAL
) || (style
& wxSL_VERTICAL
)) )
61 style
|= wxSL_HORIZONTAL
;
63 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
);
101 wxSlider::~wxSlider()
105 int wxSlider::GetValue() const
108 XtVaGetValues ((Widget
) m_mainWidget
, XmNvalue
, &val
, NULL
);
112 void wxSlider::SetValue(int value
)
114 XtVaSetValues ((Widget
) m_mainWidget
, XmNvalue
, value
, NULL
);
117 void wxSlider::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
119 Widget widget
= (Widget
) m_mainWidget
;
121 bool managed
= XtIsManaged(widget
);
124 XtUnmanageChild (widget
);
126 if (((m_windowStyle
& wxHORIZONTAL
) == wxHORIZONTAL
) && (width
> -1))
128 XtVaSetValues (widget
, XmNscaleWidth
, wxMax (width
, 10), NULL
);
131 if (((m_windowStyle
& wxVERTICAL
) == wxVERTICAL
) && (height
> -1))
133 XtVaSetValues (widget
, XmNscaleHeight
, wxMax (height
, 10), NULL
);
136 int xx
= x
; int yy
= y
;
137 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
139 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
140 XtVaSetValues (widget
, XmNx
, xx
, NULL
);
141 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
142 XtVaSetValues (widget
, XmNy
, yy
, NULL
);
145 XtManageChild (widget
);
148 void wxSlider::SetRange(int minValue
, int maxValue
)
150 m_rangeMin
= minValue
;
151 m_rangeMax
= maxValue
;
153 XtVaSetValues ((Widget
) m_mainWidget
, XmNminimum
, minValue
, XmNmaximum
, maxValue
, NULL
);
156 // For trackbars only
157 void wxSlider::SetPageSize(int pageSize
)
159 // Not implemented in Motif
160 m_pageSize
= pageSize
;
163 int wxSlider::GetPageSize() const
168 void wxSlider::SetLineSize(int lineSize
)
170 // Not implemented in Motif
171 m_lineSize
= lineSize
;
174 int wxSlider::GetLineSize() const
176 // Not implemented in Motif
180 void wxSlider::SetThumbLength(int WXUNUSED(len
))
182 // Not implemented in Motif (?)
185 int wxSlider::GetThumbLength() const
187 // Not implemented in Motif (?)
191 void wxSlider::Command (wxCommandEvent
& event
)
193 SetValue (event
.GetInt());
194 ProcessCommand (event
);
197 void wxSliderCallback (Widget widget
, XtPointer clientData
,
198 XmScaleCallbackStruct
* cbs
)
200 wxSlider
*slider
= (wxSlider
*) clientData
;
201 wxEventType scrollEvent
;
205 case XmCR_VALUE_CHANGED
:
206 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
210 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
217 wxScrollEvent
event(scrollEvent
, slider
->GetId());
218 int commandInt
= event
.GetInt();
219 XtVaGetValues (widget
, XmNvalue
, &commandInt
, NULL
);
220 event
.SetInt(commandInt
);
221 event
.SetEventObject(slider
);
222 slider
->HandleWindowEvent(event
);
224 // Also send a wxCommandEvent for compatibility.
225 wxCommandEvent
event2(wxEVT_SLIDER
, slider
->GetId());
226 event2
.SetEventObject(slider
);
227 event2
.SetInt( event
.GetInt() );
228 slider
->HandleWindowEvent(event2
);
231 #endif // wxUSE_SLIDER