]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/slider.cpp
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
);
58 if (parent
) parent
->AddChild(this);
61 m_windowStyle
= style
;
65 m_windowId
= (int)NewControlId();
69 m_rangeMax
= maxValue
;
70 m_rangeMin
= minValue
;
72 // Not used in Motif, I think
73 m_pageSize
= (int)((maxValue
-minValue
)/10);
75 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
77 Widget sliderWidget
= XtVaCreateManagedWidget ("sliderWidget",
78 xmScaleWidgetClass
, parentWidget
,
80 (((m_windowStyle
& wxSL_VERTICAL
) == wxSL_VERTICAL
) ? XmVERTICAL
: XmHORIZONTAL
),
81 XmNprocessingDirection
,
82 (((m_windowStyle
& wxSL_VERTICAL
) == wxSL_VERTICAL
) ? XmMAX_ON_TOP
: XmMAX_ON_RIGHT
),
89 m_mainWidget
= (WXWidget
) sliderWidget
;
91 if(style
& wxSL_NOTIFY_DRAG
)
92 XtAddCallback (sliderWidget
, XmNdragCallback
,
93 (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
95 XtAddCallback (sliderWidget
, XmNvalueChangedCallback
,
96 (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
98 XtAddCallback (sliderWidget
, XmNdragCallback
, (XtCallbackProc
) wxSliderCallback
, (XtPointer
) this);
100 SetCanAddEventHandler(TRUE
);
101 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
103 SetFont(* parent
->GetFont());
104 ChangeColour(m_mainWidget
);
109 wxSlider::~wxSlider()
113 int wxSlider::GetValue() const
116 XtVaGetValues ((Widget
) m_mainWidget
, XmNvalue
, &val
, NULL
);
120 void wxSlider::SetValue(int value
)
122 XtVaSetValues ((Widget
) m_mainWidget
, XmNvalue
, value
, NULL
);
125 void wxSlider::GetSize(int *width
, int *height
) const
127 wxControl::GetSize(width
, height
);
130 void wxSlider::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
132 Widget widget
= (Widget
) m_mainWidget
;
134 bool managed
= XtIsManaged(widget
);
137 XtUnmanageChild (widget
);
139 if (((m_windowStyle
& wxHORIZONTAL
) == wxHORIZONTAL
) && (width
> -1))
141 XtVaSetValues (widget
, XmNscaleWidth
, wxMax (width
, 10), NULL
);
144 if (((m_windowStyle
& wxVERTICAL
) == wxVERTICAL
) && (height
> -1))
146 XtVaSetValues (widget
, XmNscaleHeight
, wxMax (height
, 10), NULL
);
149 int xx
= x
; int yy
= y
;
150 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
152 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
153 XtVaSetValues (widget
, XmNx
, xx
, NULL
);
154 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
155 XtVaSetValues (widget
, XmNy
, yy
, NULL
);
158 XtManageChild (widget
);
161 void wxSlider::SetRange(int minValue
, int maxValue
)
163 m_rangeMin
= minValue
;
164 m_rangeMax
= maxValue
;
166 XtVaSetValues ((Widget
) m_mainWidget
, XmNminimum
, minValue
, XmNmaximum
, maxValue
, NULL
);
169 // For trackbars only
170 void wxSlider::SetTickFreq(int n
, int pos
)
172 // Not implemented in Motif
176 void wxSlider::SetPageSize(int pageSize
)
178 // Not implemented in Motif
179 m_pageSize
= pageSize
;
182 int wxSlider::GetPageSize() const
187 void wxSlider::ClearSel()
189 // Not implemented in Motif
192 void wxSlider::ClearTicks()
194 // Not implemented in Motif
197 void wxSlider::SetLineSize(int lineSize
)
199 // Not implemented in Motif
200 m_lineSize
= lineSize
;
203 int wxSlider::GetLineSize() const
205 // Not implemented in Motif
209 int wxSlider::GetSelEnd() const
211 // Not implemented in Motif
215 int wxSlider::GetSelStart() const
217 // Not implemented in Motif
221 void wxSlider::SetSelection(int WXUNUSED(minPos
), int WXUNUSED(maxPos
))
223 // Not implemented in Motif
226 void wxSlider::SetThumbLength(int WXUNUSED(len
))
228 // Not implemented in Motif (?)
231 int wxSlider::GetThumbLength() const
233 // Not implemented in Motif (?)
237 void wxSlider::SetTick(int WXUNUSED(tickPos
))
239 // Not implemented in Motif
242 void wxSlider::Command (wxCommandEvent
& event
)
244 SetValue (event
.GetInt());
245 ProcessCommand (event
);
248 void wxSliderCallback (Widget widget
, XtPointer clientData
, XmScaleCallbackStruct
* cbs
)
250 wxSlider
*slider
= (wxSlider
*) clientData
;
253 case XmCR_VALUE_CHANGED
:
257 // TODO: the XmCR_VALUE_CHANGED case should be handled
258 // differently (it's not sent continually as the slider moves).
259 // In which case we need a similar behaviour for other platforms.
261 wxScrollEvent
event(wxEVT_SCROLL_THUMBTRACK
, slider
->GetId());
262 XtVaGetValues (widget
, XmNvalue
, &event
.m_commandInt
, NULL
);
263 event
.SetEventObject(slider
);
264 slider
->ProcessCommand(event
);