1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxScrollBar
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "scrolbar.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
20 #include "wx/scrolbar.h"
23 #pragma message disable nosimpint
24 #define XtDisplay XTDISPLAY
27 #include <Xm/ScrollBar.h>
29 #pragma message enable nosimpint
32 #include "wx/motif/private.h"
34 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
35 XmScaleCallbackStruct
*cbs
);
37 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
40 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
42 const wxSize
& size
, long style
,
43 const wxValidator
& validator
,
46 if( !CreateControl( parent
, id
, pos
, size
, style
, validator
, name
) )
50 ( style
& wxHORIZONTAL
) ? wxSize( 140, 16 ) : wxSize( 16, 140 );
51 if( size
.x
!= -1 ) newSize
.x
= size
.x
;
52 if( size
.y
!= -1 ) newSize
.y
= size
.y
;
54 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
57 DoCreateScrollBar( (WXWidget
)parentWidget
,
58 (wxOrientation
)(style
& (wxHORIZONTAL
|wxVERTICAL
)),
59 (void (*)())wxScrollBarCallback
);
61 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
,
62 pos
.x
, pos
.y
, newSize
.x
, newSize
.y
);
63 ChangeBackgroundColour();
68 wxScrollBar::~wxScrollBar()
72 void wxScrollBar::SetThumbPosition(int pos
)
74 XtVaSetValues ((Widget
) m_mainWidget
,
79 int wxScrollBar::GetThumbPosition() const
82 XtVaGetValues((Widget
) m_mainWidget
,
83 XmNvalue
, &pos
, NULL
);
87 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
88 bool WXUNUSED(refresh
))
90 m_viewSize
= pageSize
;
91 m_pageSize
= thumbSize
;
99 XtVaSetValues((Widget
) m_mainWidget
,
103 XmNsliderSize
, thumbSize
,
104 XmNpageIncrement
, pageSize
,
108 void wxScrollBar::Command(wxCommandEvent
& event
)
110 SetThumbPosition(event
.m_commandInt
);
111 ProcessCommand(event
);
114 void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize
))
117 // Do anything for a scrollbar? A font will never be seen.
120 void wxScrollBar::ChangeBackgroundColour()
122 wxWindow::ChangeBackgroundColour();
124 XtVaSetValues ((Widget
) GetMainWidget(),
125 XmNtroughColor
, m_backgroundColour
.AllocColour(XtDisplay((Widget
) GetMainWidget())),
129 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
130 XmScaleCallbackStruct
*cbs
)
132 wxScrollBar
*scrollBar
= (wxScrollBar
*)wxGetWindowFromTable(widget
);
133 wxOrientation orientation
= (wxOrientation
)(int)clientData
;
134 wxEventType eventType
= wxEVT_NULL
;
140 eventType
= wxEVT_SCROLL_LINEDOWN
;
145 eventType
= wxEVT_SCROLL_LINEUP
;
150 eventType
= wxEVT_SCROLL_THUMBTRACK
;
153 case XmCR_VALUE_CHANGED
:
155 eventType
= wxEVT_SCROLL_THUMBRELEASE
;
158 case XmCR_PAGE_INCREMENT
:
160 eventType
= wxEVT_SCROLL_PAGEDOWN
;
163 case XmCR_PAGE_DECREMENT
:
165 eventType
= wxEVT_SCROLL_PAGEUP
;
170 eventType
= wxEVT_SCROLL_TOP
;
175 eventType
= wxEVT_SCROLL_BOTTOM
;
180 // Should never get here
181 wxFAIL_MSG("Unknown scroll event.");
186 wxScrollEvent
event(eventType
, scrollBar
->GetId(),
187 cbs
->value
, orientation
);
188 event
.SetEventObject(scrollBar
);
189 scrollBar
->GetEventHandler()->ProcessEvent(event
);