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 IMPLEMENT_DYNAMIC_CLASS(wxSlider
, wxControl
)
41 BEGIN_EVENT_TABLE(wxSlider
, wxControl
)
55 bool wxSlider::Create(wxWindow
*parent
, wxWindowID id
,
56 int value
, int minValue
, int maxValue
,
58 const wxSize
& size
, long style
,
59 const wxValidator
& validator
,
62 if ( !((style
& wxSL_HORIZONTAL
) || (style
& wxSL_VERTICAL
)) )
63 style
|= wxSL_HORIZONTAL
;
65 if( !CreateControl( parent
, id
, pos
, size
, style
, validator
, name
) )
69 m_windowStyle
= style
;
71 m_rangeMax
= maxValue
;
72 m_rangeMin
= minValue
;
74 // Not used in Motif, I think
75 m_pageSize
= (int)((maxValue
-minValue
)/10);
77 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
79 Widget sliderWidget
= XtVaCreateManagedWidget ("sliderWidget",
80 xmScaleWidgetClass
, parentWidget
,
82 (((m_windowStyle
& wxSL_VERTICAL
) == wxSL_VERTICAL
) ? XmVERTICAL
: XmHORIZONTAL
),
83 XmNprocessingDirection
,
84 (((m_windowStyle
& wxSL_VERTICAL
) == wxSL_VERTICAL
) ? XmMAX_ON_TOP
: XmMAX_ON_RIGHT
),
91 m_mainWidget
= (WXWidget
) sliderWidget
;
93 XtAddCallback (sliderWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
94 XtAddCallback (sliderWidget
, XmNdragCallback
, (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
97 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
99 ChangeBackgroundColour();
104 wxSlider::~wxSlider()
108 int wxSlider::GetValue() const
111 XtVaGetValues ((Widget
) m_mainWidget
, XmNvalue
, &val
, NULL
);
115 void wxSlider::SetValue(int value
)
117 XtVaSetValues ((Widget
) m_mainWidget
, XmNvalue
, value
, NULL
);
120 void wxSlider::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
122 Widget widget
= (Widget
) m_mainWidget
;
124 bool managed
= XtIsManaged(widget
);
127 XtUnmanageChild (widget
);
129 if (((m_windowStyle
& wxHORIZONTAL
) == wxHORIZONTAL
) && (width
> -1))
131 XtVaSetValues (widget
, XmNscaleWidth
, wxMax (width
, 10), NULL
);
134 if (((m_windowStyle
& wxVERTICAL
) == wxVERTICAL
) && (height
> -1))
136 XtVaSetValues (widget
, XmNscaleHeight
, wxMax (height
, 10), NULL
);
139 int xx
= x
; int yy
= y
;
140 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
142 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
143 XtVaSetValues (widget
, XmNx
, xx
, NULL
);
144 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
145 XtVaSetValues (widget
, XmNy
, yy
, NULL
);
148 XtManageChild (widget
);
151 void wxSlider::SetRange(int minValue
, int maxValue
)
153 m_rangeMin
= minValue
;
154 m_rangeMax
= maxValue
;
156 XtVaSetValues ((Widget
) m_mainWidget
, XmNminimum
, minValue
, XmNmaximum
, maxValue
, NULL
);
159 // For trackbars only
160 void wxSlider::SetPageSize(int pageSize
)
162 // Not implemented in Motif
163 m_pageSize
= pageSize
;
166 int wxSlider::GetPageSize() const
171 void wxSlider::SetLineSize(int lineSize
)
173 // Not implemented in Motif
174 m_lineSize
= lineSize
;
177 int wxSlider::GetLineSize() const
179 // Not implemented in Motif
183 void wxSlider::SetThumbLength(int WXUNUSED(len
))
185 // Not implemented in Motif (?)
188 int wxSlider::GetThumbLength() const
190 // Not implemented in Motif (?)
194 void wxSlider::Command (wxCommandEvent
& event
)
196 SetValue (event
.GetInt());
197 ProcessCommand (event
);
200 void wxSliderCallback (Widget widget
, XtPointer clientData
,
201 XmScaleCallbackStruct
* cbs
)
203 wxSlider
*slider
= (wxSlider
*) clientData
;
204 wxEventType scrollEvent
;
208 case XmCR_VALUE_CHANGED
:
209 scrollEvent
= wxEVT_SCROLL_THUMBRELEASE
;
213 scrollEvent
= wxEVT_SCROLL_THUMBTRACK
;
220 wxScrollEvent
event(scrollEvent
, slider
->GetId());
221 int commandInt
= event
.GetInt();
222 XtVaGetValues (widget
, XmNvalue
, &commandInt
, NULL
);
223 event
.SetInt(commandInt
);
224 event
.SetEventObject(slider
);
225 slider
->GetEventHandler()->ProcessEvent(event
);
227 // Also send a wxCommandEvent for compatibility.
228 wxCommandEvent
event2(wxEVT_COMMAND_SLIDER_UPDATED
, slider
->GetId());
229 event2
.SetEventObject(slider
);
230 event2
.SetInt( event
.GetInt() );
231 slider
->GetEventHandler()->ProcessEvent(event2
);
234 #endif // wxUSE_SLIDER