]>
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
);
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 SetCanAddEventHandler(TRUE
);
103 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
105 SetFont(* parent
->GetFont());
106 ChangeBackgroundColour();
111 wxSlider::~wxSlider()
115 int wxSlider::GetValue() const
118 XtVaGetValues ((Widget
) m_mainWidget
, XmNvalue
, &val
, NULL
);
122 void wxSlider::SetValue(int value
)
124 XtVaSetValues ((Widget
) m_mainWidget
, XmNvalue
, value
, NULL
);
127 void wxSlider::GetSize(int *width
, int *height
) const
129 wxControl::GetSize(width
, height
);
132 void wxSlider::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
134 Widget widget
= (Widget
) m_mainWidget
;
136 bool managed
= XtIsManaged(widget
);
139 XtUnmanageChild (widget
);
141 if (((m_windowStyle
& wxHORIZONTAL
) == wxHORIZONTAL
) && (width
> -1))
143 XtVaSetValues (widget
, XmNscaleWidth
, wxMax (width
, 10), NULL
);
146 if (((m_windowStyle
& wxVERTICAL
) == wxVERTICAL
) && (height
> -1))
148 XtVaSetValues (widget
, XmNscaleHeight
, wxMax (height
, 10), NULL
);
151 int xx
= x
; int yy
= y
;
152 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
154 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
155 XtVaSetValues (widget
, XmNx
, xx
, NULL
);
156 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
157 XtVaSetValues (widget
, XmNy
, yy
, NULL
);
160 XtManageChild (widget
);
163 void wxSlider::SetRange(int minValue
, int maxValue
)
165 m_rangeMin
= minValue
;
166 m_rangeMax
= maxValue
;
168 XtVaSetValues ((Widget
) m_mainWidget
, XmNminimum
, minValue
, XmNmaximum
, maxValue
, NULL
);
171 // For trackbars only
172 void wxSlider::SetTickFreq(int n
, int pos
)
174 // Not implemented in Motif
178 void wxSlider::SetPageSize(int pageSize
)
180 // Not implemented in Motif
181 m_pageSize
= pageSize
;
184 int wxSlider::GetPageSize() const
189 void wxSlider::ClearSel()
191 // Not implemented in Motif
194 void wxSlider::ClearTicks()
196 // Not implemented in Motif
199 void wxSlider::SetLineSize(int lineSize
)
201 // Not implemented in Motif
202 m_lineSize
= lineSize
;
205 int wxSlider::GetLineSize() const
207 // Not implemented in Motif
211 int wxSlider::GetSelEnd() const
213 // Not implemented in Motif
217 int wxSlider::GetSelStart() const
219 // Not implemented in Motif
223 void wxSlider::SetSelection(int WXUNUSED(minPos
), int WXUNUSED(maxPos
))
225 // Not implemented in Motif
228 void wxSlider::SetThumbLength(int WXUNUSED(len
))
230 // Not implemented in Motif (?)
233 int wxSlider::GetThumbLength() const
235 // Not implemented in Motif (?)
239 void wxSlider::SetTick(int WXUNUSED(tickPos
))
241 // Not implemented in Motif
244 void wxSlider::Command (wxCommandEvent
& event
)
246 SetValue (event
.GetInt());
247 ProcessCommand (event
);
250 void wxSlider::ChangeFont()
255 void wxSlider::ChangeBackgroundColour()
260 void wxSlider::ChangeForegroundColour()
265 void wxSliderCallback (Widget widget
, XtPointer clientData
, XmScaleCallbackStruct
* cbs
)
267 wxSlider
*slider
= (wxSlider
*) clientData
;
270 case XmCR_VALUE_CHANGED
:
274 // TODO: the XmCR_VALUE_CHANGED case should be handled
275 // differently (it's not sent continually as the slider moves).
276 // In which case we need a similar behaviour for other platforms.
278 wxScrollEvent
event(wxEVT_SCROLL_THUMBTRACK
, slider
->GetId());
279 XtVaGetValues (widget
, XmNvalue
, &event
.m_commandInt
, NULL
);
280 event
.SetEventObject(slider
);
281 slider
->ProcessCommand(event
);