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 SetCanAddEventHandler(TRUE
);
100 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, x
, y
, width
, height
);
101 ChangeBackgroundColour();
106 wxScrollBar::~wxScrollBar()
110 void wxScrollBar::SetThumbPosition(int pos
)
114 XtVaSetValues ((Widget
) m_mainWidget
,
120 int wxScrollBar::GetThumbPosition() const
125 XtVaGetValues((Widget
) m_mainWidget
,
126 XmNvalue
, &pos
, NULL
);
133 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
134 bool WXUNUSED(refresh
))
136 m_viewSize
= pageSize
;
137 m_pageSize
= thumbSize
;
138 m_objectSize
= range
;
145 XtVaSetValues((Widget
) m_mainWidget
,
149 XmNsliderSize
, thumbSize
,
150 XmNpageIncrement
, pageSize
,
154 void wxScrollBar::Command(wxCommandEvent
& event
)
156 SetThumbPosition(event
.m_commandInt
);
157 ProcessCommand(event
);
160 void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize
))
163 // Do anything for a scrollbar? A font will never be seen.
166 void wxScrollBar::ChangeBackgroundColour()
168 wxWindow::ChangeBackgroundColour();
170 XtVaSetValues ((Widget
) GetMainWidget(),
171 XmNtroughColor
, m_backgroundColour
.AllocColour(XtDisplay((Widget
) GetMainWidget())),
175 void wxScrollBar::ChangeForegroundColour()
177 wxWindow::ChangeForegroundColour();
180 static void wxScrollBarCallback(Widget
WXUNUSED(widget
), XtPointer clientData
,
181 XmScaleCallbackStruct
*cbs
)
183 wxScrollBar
*scrollBar
= (wxScrollBar
*)clientData
;
184 wxEventType eventType
= wxEVT_NULL
;
190 eventType
= wxEVT_SCROLL_LINEDOWN
;
195 eventType
= wxEVT_SCROLL_LINEUP
;
200 eventType
= wxEVT_SCROLL_THUMBTRACK
;
203 case XmCR_VALUE_CHANGED
:
205 eventType
= wxEVT_SCROLL_THUMBRELEASE
;
208 case XmCR_PAGE_INCREMENT
:
210 eventType
= wxEVT_SCROLL_PAGEDOWN
;
213 case XmCR_PAGE_DECREMENT
:
215 eventType
= wxEVT_SCROLL_PAGEUP
;
220 eventType
= wxEVT_SCROLL_TOP
;
225 eventType
= wxEVT_SCROLL_BOTTOM
;
230 // Should never get here
231 wxFAIL_MSG("Unknown scroll event.");
236 wxScrollEvent
event(eventType
, scrollBar
->GetId());
237 event
.SetEventObject(scrollBar
);
238 event
.SetPosition(cbs
->value
);
239 scrollBar
->GetEventHandler()->ProcessEvent(event
);
241 if (!scrollBar->inSetValue)
242 scrollBar->ProcessCommand(event);