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 IMPLEMENT_DYNAMIC_CLASS(wxSlider
, wxControl
)
37 BEGIN_EVENT_TABLE(wxSlider
, wxControl
)
52 bool wxSlider::Create(wxWindow
*parent
, wxWindowID id
,
53 int value
, int minValue
, int maxValue
,
55 const wxSize
& size
, long style
,
56 const wxValidator
& validator
,
59 if ( !((style
& wxSL_HORIZONTAL
) || (style
& wxSL_VERTICAL
)) )
60 style
|= wxSL_HORIZONTAL
;
63 SetValidator(validator
);
64 m_backgroundColour
= parent
->GetBackgroundColour();
65 m_foregroundColour
= parent
->GetForegroundColour();
67 if (parent
) parent
->AddChild(this);
70 m_windowStyle
= style
;
74 m_windowId
= (int)NewControlId();
78 m_rangeMax
= maxValue
;
79 m_rangeMin
= minValue
;
81 // Not used in Motif, I think
82 m_pageSize
= (int)((maxValue
-minValue
)/10);
84 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
86 Widget sliderWidget
= XtVaCreateManagedWidget ("sliderWidget",
87 xmScaleWidgetClass
, parentWidget
,
89 (((m_windowStyle
& wxSL_VERTICAL
) == wxSL_VERTICAL
) ? XmVERTICAL
: XmHORIZONTAL
),
90 XmNprocessingDirection
,
91 (((m_windowStyle
& wxSL_VERTICAL
) == wxSL_VERTICAL
) ? XmMAX_ON_TOP
: XmMAX_ON_RIGHT
),
98 m_mainWidget
= (WXWidget
) sliderWidget
;
101 #pragma message disable codcauunr
102 // VMS gives here the compiler warning :
103 // statement either is unreachable or causes unreachable code
105 if(style
& wxSL_NOTIFY_DRAG
)
106 XtAddCallback (sliderWidget
, XmNdragCallback
,
107 (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
109 XtAddCallback (sliderWidget
, XmNvalueChangedCallback
,
110 (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
112 #pragma message enable codcauunr
115 XtAddCallback (sliderWidget
, XmNdragCallback
, (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
117 m_font
= parent
->GetFont();
120 SetCanAddEventHandler(TRUE
);
121 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
123 ChangeBackgroundColour();
128 wxSlider::~wxSlider()
132 int wxSlider::GetValue() const
135 XtVaGetValues ((Widget
) m_mainWidget
, XmNvalue
, &val
, NULL
);
139 void wxSlider::SetValue(int value
)
141 XtVaSetValues ((Widget
) m_mainWidget
, XmNvalue
, value
, NULL
);
144 void wxSlider::GetSize(int *width
, int *height
) const
146 wxControl::GetSize(width
, height
);
149 void wxSlider::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
151 Widget widget
= (Widget
) m_mainWidget
;
153 bool managed
= XtIsManaged(widget
);
156 XtUnmanageChild (widget
);
158 if (((m_windowStyle
& wxHORIZONTAL
) == wxHORIZONTAL
) && (width
> -1))
160 XtVaSetValues (widget
, XmNscaleWidth
, wxMax (width
, 10), NULL
);
163 if (((m_windowStyle
& wxVERTICAL
) == wxVERTICAL
) && (height
> -1))
165 XtVaSetValues (widget
, XmNscaleHeight
, wxMax (height
, 10), NULL
);
168 int xx
= x
; int yy
= y
;
169 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
171 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
172 XtVaSetValues (widget
, XmNx
, xx
, NULL
);
173 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
174 XtVaSetValues (widget
, XmNy
, yy
, NULL
);
177 XtManageChild (widget
);
180 void wxSlider::SetRange(int minValue
, int maxValue
)
182 m_rangeMin
= minValue
;
183 m_rangeMax
= maxValue
;
185 XtVaSetValues ((Widget
) m_mainWidget
, XmNminimum
, minValue
, XmNmaximum
, maxValue
, NULL
);
188 // For trackbars only
189 void wxSlider::SetTickFreq(int n
, int WXUNUSED(pos
))
191 // Not implemented in Motif
195 void wxSlider::SetPageSize(int pageSize
)
197 // Not implemented in Motif
198 m_pageSize
= pageSize
;
201 int wxSlider::GetPageSize() const
206 void wxSlider::ClearSel()
208 // Not implemented in Motif
211 void wxSlider::ClearTicks()
213 // Not implemented in Motif
216 void wxSlider::SetLineSize(int lineSize
)
218 // Not implemented in Motif
219 m_lineSize
= lineSize
;
222 int wxSlider::GetLineSize() const
224 // Not implemented in Motif
228 int wxSlider::GetSelEnd() const
230 // Not implemented in Motif
234 int wxSlider::GetSelStart() const
236 // Not implemented in Motif
240 void wxSlider::SetSelection(int WXUNUSED(minPos
), int WXUNUSED(maxPos
))
242 // Not implemented in Motif
245 void wxSlider::SetThumbLength(int WXUNUSED(len
))
247 // Not implemented in Motif (?)
250 int wxSlider::GetThumbLength() const
252 // Not implemented in Motif (?)
256 void wxSlider::SetTick(int WXUNUSED(tickPos
))
258 // Not implemented in Motif
261 void wxSlider::Command (wxCommandEvent
& event
)
263 SetValue (event
.GetInt());
264 ProcessCommand (event
);
267 void wxSlider::ChangeFont(bool keepOriginalSize
)
269 wxWindow::ChangeFont(keepOriginalSize
);
272 void wxSlider::ChangeBackgroundColour()
274 wxWindow::ChangeBackgroundColour();
277 void wxSlider::ChangeForegroundColour()
279 wxWindow::ChangeForegroundColour();
282 void wxSliderCallback (Widget widget
, XtPointer clientData
, XmScaleCallbackStruct
* cbs
)
284 wxSlider
*slider
= (wxSlider
*) clientData
;
287 case XmCR_VALUE_CHANGED
:
291 // TODO: the XmCR_VALUE_CHANGED case should be handled
292 // differently (it's not sent continually as the slider moves).
293 // In which case we need a similar behaviour for other platforms.
295 wxScrollEvent
event(wxEVT_SCROLL_THUMBTRACK
, slider
->GetId());
296 XtVaGetValues (widget
, XmNvalue
, &event
.m_commandInt
, NULL
);
297 event
.SetEventObject(slider
);
298 slider
->ProcessCommand(event
);
300 // Also send a wxCommandEvent for compatibility.
301 wxCommandEvent
event2(wxEVT_COMMAND_SLIDER_UPDATED
, slider
->GetId());
302 event2
.SetEventObject(slider
);
303 event2
.SetInt( event
.GetInt() );
304 slider
->ProcessCommand(event2
);