1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxScrollBar
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "scrolbar.h"
16 #include "wx/scrolbar.h"
19 #pragma message disable nosimpint
21 #include <X11/IntrinsicP.h>
23 #include <Xm/RowColumn.h>
24 #include <Xm/ScrollBar.h>
26 #pragma message enable nosimpint
29 #include "wx/motif/private.h"
31 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
32 XmScaleCallbackStruct
*cbs
);
34 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
37 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
39 const wxSize
& size
, long style
,
40 const wxValidator
& validator
,
45 parent
->AddChild(this);
47 m_backgroundColour
= parent
->GetBackgroundColour();
48 m_foregroundColour
= parent
->GetForegroundColour();
49 SetValidator(validator
);
51 m_windowStyle
= style
;
54 m_windowId
= (int)NewControlId();
65 if (style
& wxHORIZONTAL
)
72 if (style
& wxVERTICAL
)
78 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
79 int direction
= (style
& wxHORIZONTAL
) ? XmHORIZONTAL
: XmVERTICAL
;
81 Widget scrollBarWidget
= XtVaCreateManagedWidget("scrollBarWidget",
82 xmScrollBarWidgetClass
, parentWidget
,
83 XmNorientation
, direction
,
86 m_mainWidget
= (Widget
) scrollBarWidget
;
88 XtAddCallback(scrollBarWidget
, XmNvalueChangedCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
89 XtAddCallback(scrollBarWidget
, XmNdragCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
90 XtAddCallback(scrollBarWidget
, XmNdecrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
91 XtAddCallback(scrollBarWidget
, XmNincrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
92 XtAddCallback(scrollBarWidget
, XmNpageDecrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
93 XtAddCallback(scrollBarWidget
, XmNpageIncrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
94 XtAddCallback(scrollBarWidget
, XmNtoTopCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
95 XtAddCallback(scrollBarWidget
, XmNtoBottomCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
97 SetCanAddEventHandler(TRUE
);
98 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, x
, y
, width
, height
);
99 ChangeBackgroundColour();
104 wxScrollBar::~wxScrollBar()
108 void wxScrollBar::SetThumbPosition(int pos
)
112 XtVaSetValues ((Widget
) m_mainWidget
,
118 int wxScrollBar::GetThumbPosition() const
123 XtVaGetValues((Widget
) m_mainWidget
,
124 XmNvalue
, &pos
, NULL
);
131 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
132 bool WXUNUSED(refresh
))
134 m_viewSize
= pageSize
;
135 m_pageSize
= thumbSize
;
136 m_objectSize
= range
;
143 XtVaSetValues((Widget
) m_mainWidget
,
147 XmNsliderSize
, thumbSize
,
148 XmNpageIncrement
, pageSize
,
152 void wxScrollBar::Command(wxCommandEvent
& event
)
154 SetThumbPosition(event
.m_commandInt
);
155 ProcessCommand(event
);
158 void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize
))
161 // Do anything for a scrollbar? A font will never be seen.
164 void wxScrollBar::ChangeBackgroundColour()
166 wxWindow::ChangeBackgroundColour();
168 XtVaSetValues ((Widget
) GetMainWidget(),
169 XmNtroughColor
, m_backgroundColour
.AllocColour(XtDisplay((Widget
) GetMainWidget())),
173 void wxScrollBar::ChangeForegroundColour()
175 wxWindow::ChangeForegroundColour();
178 static void wxScrollBarCallback(Widget
WXUNUSED(widget
), XtPointer clientData
,
179 XmScaleCallbackStruct
*cbs
)
181 wxScrollBar
*scrollBar
= (wxScrollBar
*)clientData
;
182 wxEventType eventType
= wxEVT_NULL
;
188 eventType
= wxEVT_SCROLL_LINEDOWN
;
193 eventType
= wxEVT_SCROLL_LINEUP
;
198 eventType
= wxEVT_SCROLL_THUMBTRACK
;
201 case XmCR_VALUE_CHANGED
:
203 eventType
= wxEVT_SCROLL_THUMBRELEASE
;
206 case XmCR_PAGE_INCREMENT
:
208 eventType
= wxEVT_SCROLL_PAGEDOWN
;
211 case XmCR_PAGE_DECREMENT
:
213 eventType
= wxEVT_SCROLL_PAGEUP
;
218 eventType
= wxEVT_SCROLL_TOP
;
223 eventType
= wxEVT_SCROLL_BOTTOM
;
228 // Should never get here
229 wxFAIL_MSG("Unknown scroll event.");
234 wxScrollEvent
event(eventType
, scrollBar
->GetId());
235 event
.SetEventObject(scrollBar
);
236 event
.SetPosition(cbs
->value
);
237 scrollBar
->GetEventHandler()->ProcessEvent(event
);
239 if (!scrollBar->inSetValue)
240 scrollBar->ProcessCommand(event);