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"
21 #include <Xm/LabelG.h>
22 #include <Xm/RowColumn.h>
25 #include <wx/motif/private.h>
27 void wxSliderCallback (Widget widget
, XtPointer clientData
, XmScaleCallbackStruct
* cbs
);
29 #if !USE_SHARED_LIBRARY
30 IMPLEMENT_DYNAMIC_CLASS(wxSlider
, wxControl
)
32 BEGIN_EVENT_TABLE(wxSlider
, wxControl
)
48 bool wxSlider::Create(wxWindow
*parent
, wxWindowID id
,
49 int value
, int minValue
, int maxValue
,
51 const wxSize
& size
, long style
,
52 const wxValidator
& validator
,
56 SetValidator(validator
);
57 m_backgroundColour
= parent
->GetBackgroundColour();
58 m_foregroundColour
= parent
->GetForegroundColour();
60 if (parent
) parent
->AddChild(this);
63 m_windowStyle
= style
;
67 m_windowId
= (int)NewControlId();
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 if(style
& wxSL_NOTIFY_DRAG
)
94 XtAddCallback (sliderWidget
, XmNdragCallback
,
95 (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
97 XtAddCallback (sliderWidget
, XmNvalueChangedCallback
,
98 (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
100 XtAddCallback (sliderWidget
, XmNdragCallback
, (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
102 m_windowFont
= parent
->GetFont();
105 SetCanAddEventHandler(TRUE
);
106 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
108 ChangeBackgroundColour();
113 wxSlider::~wxSlider()
117 int wxSlider::GetValue() const
120 XtVaGetValues ((Widget
) m_mainWidget
, XmNvalue
, &val
, NULL
);
124 void wxSlider::SetValue(int value
)
126 XtVaSetValues ((Widget
) m_mainWidget
, XmNvalue
, value
, NULL
);
129 void wxSlider::GetSize(int *width
, int *height
) const
131 wxControl::GetSize(width
, height
);
134 void wxSlider::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
136 Widget widget
= (Widget
) m_mainWidget
;
138 bool managed
= XtIsManaged(widget
);
141 XtUnmanageChild (widget
);
143 if (((m_windowStyle
& wxHORIZONTAL
) == wxHORIZONTAL
) && (width
> -1))
145 XtVaSetValues (widget
, XmNscaleWidth
, wxMax (width
, 10), NULL
);
148 if (((m_windowStyle
& wxVERTICAL
) == wxVERTICAL
) && (height
> -1))
150 XtVaSetValues (widget
, XmNscaleHeight
, wxMax (height
, 10), NULL
);
153 int xx
= x
; int yy
= y
;
154 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
156 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
157 XtVaSetValues (widget
, XmNx
, xx
, NULL
);
158 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
159 XtVaSetValues (widget
, XmNy
, yy
, NULL
);
162 XtManageChild (widget
);
165 void wxSlider::SetRange(int minValue
, int maxValue
)
167 m_rangeMin
= minValue
;
168 m_rangeMax
= maxValue
;
170 XtVaSetValues ((Widget
) m_mainWidget
, XmNminimum
, minValue
, XmNmaximum
, maxValue
, NULL
);
173 // For trackbars only
174 void wxSlider::SetTickFreq(int n
, int pos
)
176 // Not implemented in Motif
180 void wxSlider::SetPageSize(int pageSize
)
182 // Not implemented in Motif
183 m_pageSize
= pageSize
;
186 int wxSlider::GetPageSize() const
191 void wxSlider::ClearSel()
193 // Not implemented in Motif
196 void wxSlider::ClearTicks()
198 // Not implemented in Motif
201 void wxSlider::SetLineSize(int lineSize
)
203 // Not implemented in Motif
204 m_lineSize
= lineSize
;
207 int wxSlider::GetLineSize() const
209 // Not implemented in Motif
213 int wxSlider::GetSelEnd() const
215 // Not implemented in Motif
219 int wxSlider::GetSelStart() const
221 // Not implemented in Motif
225 void wxSlider::SetSelection(int WXUNUSED(minPos
), int WXUNUSED(maxPos
))
227 // Not implemented in Motif
230 void wxSlider::SetThumbLength(int WXUNUSED(len
))
232 // Not implemented in Motif (?)
235 int wxSlider::GetThumbLength() const
237 // Not implemented in Motif (?)
241 void wxSlider::SetTick(int WXUNUSED(tickPos
))
243 // Not implemented in Motif
246 void wxSlider::Command (wxCommandEvent
& event
)
248 SetValue (event
.GetInt());
249 ProcessCommand (event
);
252 void wxSlider::ChangeFont(bool keepOriginalSize
)
254 wxWindow::ChangeFont(keepOriginalSize
);
257 void wxSlider::ChangeBackgroundColour()
259 wxWindow::ChangeBackgroundColour();
262 void wxSlider::ChangeForegroundColour()
264 wxWindow::ChangeForegroundColour();
267 void wxSliderCallback (Widget widget
, XtPointer clientData
, XmScaleCallbackStruct
* cbs
)
269 wxSlider
*slider
= (wxSlider
*) clientData
;
272 case XmCR_VALUE_CHANGED
:
276 // TODO: the XmCR_VALUE_CHANGED case should be handled
277 // differently (it's not sent continually as the slider moves).
278 // In which case we need a similar behaviour for other platforms.
280 wxScrollEvent
event(wxEVT_SCROLL_THUMBTRACK
, slider
->GetId());
281 XtVaGetValues (widget
, XmNvalue
, &event
.m_commandInt
, NULL
);
282 event
.SetEventObject(slider
);
283 slider
->ProcessCommand(event
);
285 // Also send a wxCommandEvent for compatibility.
286 wxCommandEvent
event2(wxEVT_COMMAND_SLIDER_UPDATED
, slider
->GetId());
287 event2
.SetEventObject(slider
);
288 slider
->ProcessCommand(event2
);