]>
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 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::SetPosition(int pos
)
109 XtVaSetValues ((Widget
) m_mainWidget
,
115 int wxScrollBar::GetPosition() 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 SetPosition(event
.m_commandInt
);
152 ProcessCommand(event
);
155 void wxScrollBar::ChangeFont(bool keepOriginalSize
)
160 void wxScrollBar::ChangeBackgroundColour()
165 void wxScrollBar::ChangeForegroundColour()
170 void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
171 XmScaleCallbackStruct
*cbs
)
173 wxScrollBar
*scrollBar
= (wxScrollBar
*)clientData
;
175 wxEventType eventType
= wxEVT_NULL
;
180 eventType
= wxEVT_SCROLL_LINEDOWN
;
185 eventType
= wxEVT_SCROLL_LINEUP
;
190 eventType
= wxEVT_SCROLL_THUMBTRACK
;
193 case XmCR_VALUE_CHANGED
:
195 // TODO: Should this be intercepted too, or will it cause
197 eventType
= wxEVT_SCROLL_THUMBTRACK
;
200 case XmCR_PAGE_INCREMENT
:
202 eventType
= wxEVT_SCROLL_PAGEDOWN
;
205 case XmCR_PAGE_DECREMENT
:
207 eventType
= wxEVT_SCROLL_PAGEUP
;
212 eventType
= wxEVT_SCROLL_TOP
;
217 eventType
= wxEVT_SCROLL_BOTTOM
;
222 // Should never get here
223 wxFAIL_MSG("Unknown scroll event.");
228 wxScrollEvent
event(eventType
, scrollBar
->GetId());
229 event
.SetEventObject(scrollBar
);
230 event
.SetPosition(cbs
->value
);
231 scrollBar
->GetEventHandler()->ProcessEvent(event
);
233 if (!scrollBar->inSetValue)
234 scrollBar->ProcessCommand(event);