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"
20 #pragma message disable nosimpint
24 #include <Xm/LabelG.h>
25 #include <Xm/RowColumn.h>
28 #pragma message enable nosimpint
31 #include "wx/motif/private.h"
33 void wxSliderCallback (Widget widget
, XtPointer clientData
, XmScaleCallbackStruct
* cbs
);
35 #if !USE_SHARED_LIBRARY
36 IMPLEMENT_DYNAMIC_CLASS(wxSlider
, wxControl
)
38 BEGIN_EVENT_TABLE(wxSlider
, wxControl
)
54 bool wxSlider::Create(wxWindow
*parent
, wxWindowID id
,
55 int value
, int minValue
, int maxValue
,
57 const wxSize
& size
, long style
,
58 const wxValidator
& validator
,
61 if ( !((style
& wxSL_HORIZONTAL
) || (style
& wxSL_VERTICAL
)) )
62 style
|= wxSL_HORIZONTAL
;
65 SetValidator(validator
);
66 m_backgroundColour
= parent
->GetBackgroundColour();
67 m_foregroundColour
= parent
->GetForegroundColour();
69 if (parent
) parent
->AddChild(this);
72 m_windowStyle
= style
;
76 m_windowId
= (int)NewControlId();
80 m_rangeMax
= maxValue
;
81 m_rangeMin
= minValue
;
83 // Not used in Motif, I think
84 m_pageSize
= (int)((maxValue
-minValue
)/10);
86 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
88 Widget sliderWidget
= XtVaCreateManagedWidget ("sliderWidget",
89 xmScaleWidgetClass
, parentWidget
,
91 (((m_windowStyle
& wxSL_VERTICAL
) == wxSL_VERTICAL
) ? XmVERTICAL
: XmHORIZONTAL
),
92 XmNprocessingDirection
,
93 (((m_windowStyle
& wxSL_VERTICAL
) == wxSL_VERTICAL
) ? XmMAX_ON_TOP
: XmMAX_ON_RIGHT
),
100 m_mainWidget
= (WXWidget
) sliderWidget
;
103 #pragma message disable codcauunr
104 // VMS gives here the compiler warning :
105 // statement either is unreachable or causes unreachable code
107 if(style
& wxSL_NOTIFY_DRAG
)
108 XtAddCallback (sliderWidget
, XmNdragCallback
,
109 (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
111 XtAddCallback (sliderWidget
, XmNvalueChangedCallback
,
112 (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
114 #pragma message enable codcauunr
117 XtAddCallback (sliderWidget
, XmNdragCallback
, (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
119 m_font
= parent
->GetFont();
122 SetCanAddEventHandler(TRUE
);
123 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
125 ChangeBackgroundColour();
130 wxSlider::~wxSlider()
134 int wxSlider::GetValue() const
137 XtVaGetValues ((Widget
) m_mainWidget
, XmNvalue
, &val
, NULL
);
141 void wxSlider::SetValue(int value
)
143 XtVaSetValues ((Widget
) m_mainWidget
, XmNvalue
, value
, NULL
);
146 void wxSlider::GetSize(int *width
, int *height
) const
148 wxControl::GetSize(width
, height
);
151 void wxSlider::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
153 Widget widget
= (Widget
) m_mainWidget
;
155 bool managed
= XtIsManaged(widget
);
158 XtUnmanageChild (widget
);
160 if (((m_windowStyle
& wxHORIZONTAL
) == wxHORIZONTAL
) && (width
> -1))
162 XtVaSetValues (widget
, XmNscaleWidth
, wxMax (width
, 10), NULL
);
165 if (((m_windowStyle
& wxVERTICAL
) == wxVERTICAL
) && (height
> -1))
167 XtVaSetValues (widget
, XmNscaleHeight
, wxMax (height
, 10), NULL
);
170 int xx
= x
; int yy
= y
;
171 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
173 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
174 XtVaSetValues (widget
, XmNx
, xx
, NULL
);
175 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
176 XtVaSetValues (widget
, XmNy
, yy
, NULL
);
179 XtManageChild (widget
);
182 void wxSlider::SetRange(int minValue
, int maxValue
)
184 m_rangeMin
= minValue
;
185 m_rangeMax
= maxValue
;
187 XtVaSetValues ((Widget
) m_mainWidget
, XmNminimum
, minValue
, XmNmaximum
, maxValue
, NULL
);
190 // For trackbars only
191 void wxSlider::SetTickFreq(int n
, int WXUNUSED(pos
))
193 // Not implemented in Motif
197 void wxSlider::SetPageSize(int pageSize
)
199 // Not implemented in Motif
200 m_pageSize
= pageSize
;
203 int wxSlider::GetPageSize() const
208 void wxSlider::ClearSel()
210 // Not implemented in Motif
213 void wxSlider::ClearTicks()
215 // Not implemented in Motif
218 void wxSlider::SetLineSize(int lineSize
)
220 // Not implemented in Motif
221 m_lineSize
= lineSize
;
224 int wxSlider::GetLineSize() const
226 // Not implemented in Motif
230 int wxSlider::GetSelEnd() const
232 // Not implemented in Motif
236 int wxSlider::GetSelStart() const
238 // Not implemented in Motif
242 void wxSlider::SetSelection(int WXUNUSED(minPos
), int WXUNUSED(maxPos
))
244 // Not implemented in Motif
247 void wxSlider::SetThumbLength(int WXUNUSED(len
))
249 // Not implemented in Motif (?)
252 int wxSlider::GetThumbLength() const
254 // Not implemented in Motif (?)
258 void wxSlider::SetTick(int WXUNUSED(tickPos
))
260 // Not implemented in Motif
263 void wxSlider::Command (wxCommandEvent
& event
)
265 SetValue (event
.GetInt());
266 ProcessCommand (event
);
269 void wxSlider::ChangeFont(bool keepOriginalSize
)
271 wxWindow::ChangeFont(keepOriginalSize
);
274 void wxSlider::ChangeBackgroundColour()
276 wxWindow::ChangeBackgroundColour();
279 void wxSlider::ChangeForegroundColour()
281 wxWindow::ChangeForegroundColour();
284 void wxSliderCallback (Widget widget
, XtPointer clientData
, XmScaleCallbackStruct
* cbs
)
286 wxSlider
*slider
= (wxSlider
*) clientData
;
289 case XmCR_VALUE_CHANGED
:
293 // TODO: the XmCR_VALUE_CHANGED case should be handled
294 // differently (it's not sent continually as the slider moves).
295 // In which case we need a similar behaviour for other platforms.
297 wxScrollEvent
event(wxEVT_SCROLL_THUMBTRACK
, slider
->GetId());
298 XtVaGetValues (widget
, XmNvalue
, &event
.m_commandInt
, NULL
);
299 event
.SetEventObject(slider
);
300 slider
->ProcessCommand(event
);
302 // Also send a wxCommandEvent for compatibility.
303 wxCommandEvent
event2(wxEVT_COMMAND_SLIDER_UPDATED
, slider
->GetId());
304 event2
.SetEventObject(slider
);
305 slider
->ProcessCommand(event2
);