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
,
55 if ( !((style
& wxSL_HORIZONTAL
) || (style
& wxSL_VERTICAL
)) )
56 style
|= wxSL_HORIZONTAL
;
59 SetValidator(validator
);
60 m_backgroundColour
= parent
->GetBackgroundColour();
61 m_foregroundColour
= parent
->GetForegroundColour();
63 if (parent
) parent
->AddChild(this);
66 m_windowStyle
= style
;
70 m_windowId
= (int)NewControlId();
74 m_rangeMax
= maxValue
;
75 m_rangeMin
= minValue
;
77 // Not used in Motif, I think
78 m_pageSize
= (int)((maxValue
-minValue
)/10);
80 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
82 Widget sliderWidget
= XtVaCreateManagedWidget ("sliderWidget",
83 xmScaleWidgetClass
, parentWidget
,
85 (((m_windowStyle
& wxSL_VERTICAL
) == wxSL_VERTICAL
) ? XmVERTICAL
: XmHORIZONTAL
),
86 XmNprocessingDirection
,
87 (((m_windowStyle
& wxSL_VERTICAL
) == wxSL_VERTICAL
) ? XmMAX_ON_TOP
: XmMAX_ON_RIGHT
),
94 m_mainWidget
= (WXWidget
) sliderWidget
;
96 if(style
& wxSL_NOTIFY_DRAG
)
97 XtAddCallback (sliderWidget
, XmNdragCallback
,
98 (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
100 XtAddCallback (sliderWidget
, XmNvalueChangedCallback
,
101 (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
103 XtAddCallback (sliderWidget
, XmNdragCallback
, (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
105 m_font
= parent
->GetFont();
108 SetCanAddEventHandler(TRUE
);
109 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
111 ChangeBackgroundColour();
116 wxSlider::~wxSlider()
120 int wxSlider::GetValue() const
123 XtVaGetValues ((Widget
) m_mainWidget
, XmNvalue
, &val
, NULL
);
127 void wxSlider::SetValue(int value
)
129 XtVaSetValues ((Widget
) m_mainWidget
, XmNvalue
, value
, NULL
);
132 void wxSlider::GetSize(int *width
, int *height
) const
134 wxControl::GetSize(width
, height
);
137 void wxSlider::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
139 Widget widget
= (Widget
) m_mainWidget
;
141 bool managed
= XtIsManaged(widget
);
144 XtUnmanageChild (widget
);
146 if (((m_windowStyle
& wxHORIZONTAL
) == wxHORIZONTAL
) && (width
> -1))
148 XtVaSetValues (widget
, XmNscaleWidth
, wxMax (width
, 10), NULL
);
151 if (((m_windowStyle
& wxVERTICAL
) == wxVERTICAL
) && (height
> -1))
153 XtVaSetValues (widget
, XmNscaleHeight
, wxMax (height
, 10), NULL
);
156 int xx
= x
; int yy
= y
;
157 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
159 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
160 XtVaSetValues (widget
, XmNx
, xx
, NULL
);
161 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
162 XtVaSetValues (widget
, XmNy
, yy
, NULL
);
165 XtManageChild (widget
);
168 void wxSlider::SetRange(int minValue
, int maxValue
)
170 m_rangeMin
= minValue
;
171 m_rangeMax
= maxValue
;
173 XtVaSetValues ((Widget
) m_mainWidget
, XmNminimum
, minValue
, XmNmaximum
, maxValue
, NULL
);
176 // For trackbars only
177 void wxSlider::SetTickFreq(int n
, int WXUNUSED(pos
))
179 // Not implemented in Motif
183 void wxSlider::SetPageSize(int pageSize
)
185 // Not implemented in Motif
186 m_pageSize
= pageSize
;
189 int wxSlider::GetPageSize() const
194 void wxSlider::ClearSel()
196 // Not implemented in Motif
199 void wxSlider::ClearTicks()
201 // Not implemented in Motif
204 void wxSlider::SetLineSize(int lineSize
)
206 // Not implemented in Motif
207 m_lineSize
= lineSize
;
210 int wxSlider::GetLineSize() const
212 // Not implemented in Motif
216 int wxSlider::GetSelEnd() const
218 // Not implemented in Motif
222 int wxSlider::GetSelStart() const
224 // Not implemented in Motif
228 void wxSlider::SetSelection(int WXUNUSED(minPos
), int WXUNUSED(maxPos
))
230 // Not implemented in Motif
233 void wxSlider::SetThumbLength(int WXUNUSED(len
))
235 // Not implemented in Motif (?)
238 int wxSlider::GetThumbLength() const
240 // Not implemented in Motif (?)
244 void wxSlider::SetTick(int WXUNUSED(tickPos
))
246 // Not implemented in Motif
249 void wxSlider::Command (wxCommandEvent
& event
)
251 SetValue (event
.GetInt());
252 ProcessCommand (event
);
255 void wxSlider::ChangeFont(bool keepOriginalSize
)
257 wxWindow::ChangeFont(keepOriginalSize
);
260 void wxSlider::ChangeBackgroundColour()
262 wxWindow::ChangeBackgroundColour();
265 void wxSlider::ChangeForegroundColour()
267 wxWindow::ChangeForegroundColour();
270 void wxSliderCallback (Widget widget
, XtPointer clientData
, XmScaleCallbackStruct
* cbs
)
272 wxSlider
*slider
= (wxSlider
*) clientData
;
275 case XmCR_VALUE_CHANGED
:
279 // TODO: the XmCR_VALUE_CHANGED case should be handled
280 // differently (it's not sent continually as the slider moves).
281 // In which case we need a similar behaviour for other platforms.
283 wxScrollEvent
event(wxEVT_SCROLL_THUMBTRACK
, slider
->GetId());
284 XtVaGetValues (widget
, XmNvalue
, &event
.m_commandInt
, NULL
);
285 event
.SetEventObject(slider
);
286 slider
->ProcessCommand(event
);
288 // Also send a wxCommandEvent for compatibility.
289 wxCommandEvent
event2(wxEVT_COMMAND_SLIDER_UPDATED
, slider
->GetId());
290 event2
.SetEventObject(slider
);
291 slider
->ProcessCommand(event2
);