]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/scrolbar.cpp
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"
18 #include <X11/IntrinsicP.h>
20 #include <Xm/RowColumn.h>
21 #include <Xm/ScrollBar.h>
23 #include <wx/motif/private.h>
25 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
26 XmScaleCallbackStruct
*cbs
);
28 #if !USE_SHARED_LIBRARY
29 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
33 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
35 const wxSize
& size
, long style
,
36 const wxValidator
& validator
,
41 parent
->AddChild(this);
43 m_backgroundColour
= parent
->GetBackgroundColour();
44 m_foregroundColour
= parent
->GetForegroundColour();
45 SetValidator(validator
);
47 m_windowStyle
= style
;
50 m_windowId
= (int)NewControlId();
61 if (style
& wxHORIZONTAL
)
68 if (style
& wxVERTICAL
)
74 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
75 int direction
= (style
& wxHORIZONTAL
) ? XmHORIZONTAL
: XmVERTICAL
;
77 Widget scrollBarWidget
= XtVaCreateManagedWidget("scrollBarWidget",
78 xmScrollBarWidgetClass
, parentWidget
,
79 XmNorientation
, direction
,
82 m_mainWidget
= (Widget
) scrollBarWidget
;
84 // This will duplicate other events
85 // XtAddCallback(scrollBarWidget, XmNvalueChangedCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
86 XtAddCallback(scrollBarWidget
, XmNdragCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
87 XtAddCallback(scrollBarWidget
, XmNdecrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
88 XtAddCallback(scrollBarWidget
, XmNincrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
89 XtAddCallback(scrollBarWidget
, XmNpageDecrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
90 XtAddCallback(scrollBarWidget
, XmNpageIncrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
91 XtAddCallback(scrollBarWidget
, XmNtoTopCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
92 XtAddCallback(scrollBarWidget
, XmNtoBottomCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
94 SetCanAddEventHandler(TRUE
);
95 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, x
, y
, width
, height
);
96 ChangeBackgroundColour();
101 wxScrollBar::~wxScrollBar()
105 void wxScrollBar::SetThumbPosition(int pos
)
109 XtVaSetValues ((Widget
) m_mainWidget
,
115 int wxScrollBar::GetThumbPosition() const
120 XtVaGetValues((Widget
) m_mainWidget
,
121 XmNvalue
, &pos
, NULL
);
128 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
131 m_viewSize
= pageSize
;
132 m_pageSize
= thumbSize
;
133 m_objectSize
= range
;
140 XtVaSetValues((Widget
) m_mainWidget
,
144 XmNsliderSize
, thumbSize
,
145 XmNpageIncrement
, pageSize
,
149 void wxScrollBar::Command(wxCommandEvent
& event
)
151 SetThumbPosition(event
.m_commandInt
);
152 ProcessCommand(event
);
155 void wxScrollBar::ChangeFont(bool keepOriginalSize
)
158 // Do anything for a scrollbar? A font will never be seen.
161 void wxScrollBar::ChangeBackgroundColour()
163 wxWindow::ChangeBackgroundColour();
165 XtVaSetValues ((Widget
) GetMainWidget(),
166 XmNtroughColor
, m_backgroundColour
.AllocColour(XtDisplay((Widget
) GetMainWidget())),
170 void wxScrollBar::ChangeForegroundColour()
172 wxWindow::ChangeForegroundColour();
175 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
176 XmScaleCallbackStruct
*cbs
)
178 wxScrollBar
*scrollBar
= (wxScrollBar
*)clientData
;
180 wxEventType eventType
= wxEVT_NULL
;
185 eventType
= wxEVT_SCROLL_LINEDOWN
;
190 eventType
= wxEVT_SCROLL_LINEUP
;
195 eventType
= wxEVT_SCROLL_THUMBTRACK
;
198 case XmCR_VALUE_CHANGED
:
200 // TODO: Should this be intercepted too, or will it cause
202 eventType
= wxEVT_SCROLL_THUMBTRACK
;
205 case XmCR_PAGE_INCREMENT
:
207 eventType
= wxEVT_SCROLL_PAGEDOWN
;
210 case XmCR_PAGE_DECREMENT
:
212 eventType
= wxEVT_SCROLL_PAGEUP
;
217 eventType
= wxEVT_SCROLL_TOP
;
222 eventType
= wxEVT_SCROLL_BOTTOM
;
227 // Should never get here
228 wxFAIL_MSG("Unknown scroll event.");
233 wxScrollEvent
event(eventType
, scrollBar
->GetId());
234 event
.SetEventObject(scrollBar
);
235 event
.SetPosition(cbs
->value
);
236 scrollBar
->GetEventHandler()->ProcessEvent(event
);
238 if (!scrollBar->inSetValue)
239 scrollBar->ProcessCommand(event);