1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxScrollBar
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "scrolbar.h"
18 #include "wx/scrolbar.h"
21 #pragma message disable nosimpint
23 #include <X11/IntrinsicP.h>
25 #include <Xm/RowColumn.h>
26 #include <Xm/ScrollBar.h>
28 #pragma message enable nosimpint
31 #include "wx/motif/private.h"
33 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
34 XmScaleCallbackStruct
*cbs
);
36 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
39 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
41 const wxSize
& size
, long style
,
42 const wxValidator
& validator
,
47 parent
->AddChild(this);
49 m_backgroundColour
= parent
->GetBackgroundColour();
50 m_foregroundColour
= parent
->GetForegroundColour();
51 SetValidator(validator
);
53 m_windowStyle
= style
;
56 m_windowId
= (int)NewControlId();
67 if (style
& wxHORIZONTAL
)
74 if (style
& wxVERTICAL
)
80 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
81 int direction
= (style
& wxHORIZONTAL
) ? XmHORIZONTAL
: XmVERTICAL
;
83 Widget scrollBarWidget
= XtVaCreateManagedWidget("scrollBarWidget",
84 xmScrollBarWidgetClass
, parentWidget
,
85 XmNorientation
, direction
,
88 m_mainWidget
= (Widget
) scrollBarWidget
;
90 XtAddCallback(scrollBarWidget
, XmNvalueChangedCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
91 XtAddCallback(scrollBarWidget
, XmNdragCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
92 XtAddCallback(scrollBarWidget
, XmNdecrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
93 XtAddCallback(scrollBarWidget
, XmNincrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
94 XtAddCallback(scrollBarWidget
, XmNpageDecrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
95 XtAddCallback(scrollBarWidget
, XmNpageIncrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
96 XtAddCallback(scrollBarWidget
, XmNtoTopCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
97 XtAddCallback(scrollBarWidget
, XmNtoBottomCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
99 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, x
, y
, width
, height
);
100 ChangeBackgroundColour();
105 wxScrollBar::~wxScrollBar()
109 void wxScrollBar::SetThumbPosition(int pos
)
113 XtVaSetValues ((Widget
) m_mainWidget
,
119 int wxScrollBar::GetThumbPosition() const
124 XtVaGetValues((Widget
) m_mainWidget
,
125 XmNvalue
, &pos
, NULL
);
132 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
133 bool WXUNUSED(refresh
))
135 m_viewSize
= pageSize
;
136 m_pageSize
= thumbSize
;
137 m_objectSize
= range
;
144 XtVaSetValues((Widget
) m_mainWidget
,
148 XmNsliderSize
, thumbSize
,
149 XmNpageIncrement
, pageSize
,
153 void wxScrollBar::Command(wxCommandEvent
& event
)
155 SetThumbPosition(event
.m_commandInt
);
156 ProcessCommand(event
);
159 void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize
))
162 // Do anything for a scrollbar? A font will never be seen.
165 void wxScrollBar::ChangeBackgroundColour()
167 wxWindow::ChangeBackgroundColour();
169 XtVaSetValues ((Widget
) GetMainWidget(),
170 XmNtroughColor
, m_backgroundColour
.AllocColour(XtDisplay((Widget
) GetMainWidget())),
174 void wxScrollBar::ChangeForegroundColour()
176 wxWindow::ChangeForegroundColour();
179 static void wxScrollBarCallback(Widget
WXUNUSED(widget
), XtPointer clientData
,
180 XmScaleCallbackStruct
*cbs
)
182 wxScrollBar
*scrollBar
= (wxScrollBar
*)clientData
;
183 wxEventType eventType
= wxEVT_NULL
;
189 eventType
= wxEVT_SCROLL_LINEDOWN
;
194 eventType
= wxEVT_SCROLL_LINEUP
;
199 eventType
= wxEVT_SCROLL_THUMBTRACK
;
202 case XmCR_VALUE_CHANGED
:
204 eventType
= wxEVT_SCROLL_THUMBRELEASE
;
207 case XmCR_PAGE_INCREMENT
:
209 eventType
= wxEVT_SCROLL_PAGEDOWN
;
212 case XmCR_PAGE_DECREMENT
:
214 eventType
= wxEVT_SCROLL_PAGEUP
;
219 eventType
= wxEVT_SCROLL_TOP
;
224 eventType
= wxEVT_SCROLL_BOTTOM
;
229 // Should never get here
230 wxFAIL_MSG("Unknown scroll event.");
235 wxScrollEvent
event(eventType
, scrollBar
->GetId());
236 event
.SetEventObject(scrollBar
);
237 event
.SetPosition(cbs
->value
);
238 scrollBar
->GetEventHandler()->ProcessEvent(event
);
240 if (!scrollBar->inSetValue)
241 scrollBar->ProcessCommand(event);