]>
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"
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 // This will duplicate other events
89 // XtAddCallback(scrollBarWidget, XmNvalueChangedCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
90 XtAddCallback(scrollBarWidget
, XmNdragCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
91 XtAddCallback(scrollBarWidget
, XmNdecrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
92 XtAddCallback(scrollBarWidget
, XmNincrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
93 XtAddCallback(scrollBarWidget
, XmNpageDecrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
94 XtAddCallback(scrollBarWidget
, XmNpageIncrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
95 XtAddCallback(scrollBarWidget
, XmNtoTopCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
96 XtAddCallback(scrollBarWidget
, XmNtoBottomCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
98 SetCanAddEventHandler(TRUE
);
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
;
184 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 // TODO: Should this be intercepted too, or will it cause
206 eventType
= wxEVT_SCROLL_THUMBTRACK
;
209 case XmCR_PAGE_INCREMENT
:
211 eventType
= wxEVT_SCROLL_PAGEDOWN
;
214 case XmCR_PAGE_DECREMENT
:
216 eventType
= wxEVT_SCROLL_PAGEUP
;
221 eventType
= wxEVT_SCROLL_TOP
;
226 eventType
= wxEVT_SCROLL_BOTTOM
;
231 // Should never get here
232 wxFAIL_MSG("Unknown scroll event.");
237 wxScrollEvent
event(eventType
, scrollBar
->GetId());
238 event
.SetEventObject(scrollBar
);
239 event
.SetPosition(cbs
->value
);
240 scrollBar
->GetEventHandler()->ProcessEvent(event
);
242 if (!scrollBar->inSetValue)
243 scrollBar->ProcessCommand(event);