]>
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 #if !USE_SHARED_LIBRARY
35 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 // This will duplicate other events
91 // XtAddCallback(scrollBarWidget, XmNvalueChangedCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
92 XtAddCallback(scrollBarWidget
, XmNdragCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
93 XtAddCallback(scrollBarWidget
, XmNdecrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
94 XtAddCallback(scrollBarWidget
, XmNincrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
95 XtAddCallback(scrollBarWidget
, XmNpageDecrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
96 XtAddCallback(scrollBarWidget
, XmNpageIncrementCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
97 XtAddCallback(scrollBarWidget
, XmNtoTopCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
98 XtAddCallback(scrollBarWidget
, XmNtoBottomCallback
, (XtCallbackProc
)wxScrollBarCallback
, (XtPointer
)this);
100 SetCanAddEventHandler(TRUE
);
101 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, x
, y
, width
, height
);
102 ChangeBackgroundColour();
107 wxScrollBar::~wxScrollBar()
111 void wxScrollBar::SetThumbPosition(int pos
)
115 XtVaSetValues ((Widget
) m_mainWidget
,
121 int wxScrollBar::GetThumbPosition() const
126 XtVaGetValues((Widget
) m_mainWidget
,
127 XmNvalue
, &pos
, NULL
);
134 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
135 bool WXUNUSED(refresh
))
137 m_viewSize
= pageSize
;
138 m_pageSize
= thumbSize
;
139 m_objectSize
= range
;
146 XtVaSetValues((Widget
) m_mainWidget
,
150 XmNsliderSize
, thumbSize
,
151 XmNpageIncrement
, pageSize
,
155 void wxScrollBar::Command(wxCommandEvent
& event
)
157 SetThumbPosition(event
.m_commandInt
);
158 ProcessCommand(event
);
161 void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize
))
164 // Do anything for a scrollbar? A font will never be seen.
167 void wxScrollBar::ChangeBackgroundColour()
169 wxWindow::ChangeBackgroundColour();
171 XtVaSetValues ((Widget
) GetMainWidget(),
172 XmNtroughColor
, m_backgroundColour
.AllocColour(XtDisplay((Widget
) GetMainWidget())),
176 void wxScrollBar::ChangeForegroundColour()
178 wxWindow::ChangeForegroundColour();
181 static void wxScrollBarCallback(Widget
WXUNUSED(widget
), XtPointer clientData
,
182 XmScaleCallbackStruct
*cbs
)
184 wxScrollBar
*scrollBar
= (wxScrollBar
*)clientData
;
186 wxEventType eventType
= wxEVT_NULL
;
191 eventType
= wxEVT_SCROLL_LINEDOWN
;
196 eventType
= wxEVT_SCROLL_LINEUP
;
201 eventType
= wxEVT_SCROLL_THUMBTRACK
;
204 case XmCR_VALUE_CHANGED
:
206 // TODO: Should this be intercepted too, or will it cause
208 eventType
= wxEVT_SCROLL_THUMBTRACK
;
211 case XmCR_PAGE_INCREMENT
:
213 eventType
= wxEVT_SCROLL_PAGEDOWN
;
216 case XmCR_PAGE_DECREMENT
:
218 eventType
= wxEVT_SCROLL_PAGEUP
;
223 eventType
= wxEVT_SCROLL_TOP
;
228 eventType
= wxEVT_SCROLL_BOTTOM
;
233 // Should never get here
234 wxFAIL_MSG("Unknown scroll event.");
239 wxScrollEvent
event(eventType
, scrollBar
->GetId());
240 event
.SetEventObject(scrollBar
);
241 event
.SetPosition(cbs
->value
);
242 scrollBar
->GetEventHandler()->ProcessEvent(event
);
244 if (!scrollBar->inSetValue)
245 scrollBar->ProcessCommand(event);