1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxScrollBar
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
16 #include "wx/scrolbar.h"
19 #pragma message disable nosimpint
20 #define XtDisplay XTDISPLAY
23 #include <Xm/ScrollBar.h>
25 #pragma message enable nosimpint
28 #include "wx/motif/private.h"
30 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
31 XmScaleCallbackStruct
*cbs
);
33 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
36 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
38 const wxSize
& size
, long style
,
39 const wxValidator
& validator
,
42 if( !CreateControl( parent
, id
, pos
, size
, style
, validator
, name
) )
46 ( style
& wxHORIZONTAL
) ? wxSize( 140, 16 ) : wxSize( 16, 140 );
47 if( size
.x
!= -1 ) newSize
.x
= size
.x
;
48 if( size
.y
!= -1 ) newSize
.y
= size
.y
;
50 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
53 DoCreateScrollBar( (WXWidget
)parentWidget
,
54 (wxOrientation
)(style
& (wxHORIZONTAL
|wxVERTICAL
)),
55 (void (*)())wxScrollBarCallback
);
57 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
,
58 pos
.x
, pos
.y
, newSize
.x
, newSize
.y
);
59 ChangeBackgroundColour();
64 wxScrollBar::~wxScrollBar()
68 void wxScrollBar::SetThumbPosition(int pos
)
70 XtVaSetValues ((Widget
) m_mainWidget
,
75 int wxScrollBar::GetThumbPosition() const
78 XtVaGetValues((Widget
) m_mainWidget
,
79 XmNvalue
, &pos
, NULL
);
83 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
84 bool WXUNUSED(refresh
))
86 m_viewSize
= pageSize
;
87 m_pageSize
= thumbSize
;
95 XtVaSetValues((Widget
) m_mainWidget
,
99 XmNsliderSize
, thumbSize
,
100 XmNpageIncrement
, pageSize
,
104 void wxScrollBar::Command(wxCommandEvent
& event
)
106 SetThumbPosition(event
.GetInt());
107 ProcessCommand(event
);
110 void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize
))
113 // Do anything for a scrollbar? A font will never be seen.
116 void wxScrollBar::ChangeBackgroundColour()
118 wxWindow::ChangeBackgroundColour();
120 XtVaSetValues ((Widget
) GetMainWidget(),
121 XmNtroughColor
, m_backgroundColour
.AllocColour(XtDisplay((Widget
) GetMainWidget())),
125 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
126 XmScaleCallbackStruct
*cbs
)
128 wxScrollBar
*scrollBar
= (wxScrollBar
*)wxGetWindowFromTable(widget
);
129 wxOrientation orientation
= (wxOrientation
)wxPtrToUInt(clientData
);
130 wxEventType eventType
= wxEVT_NULL
;
136 eventType
= wxEVT_SCROLL_LINEDOWN
;
141 eventType
= wxEVT_SCROLL_LINEUP
;
146 eventType
= wxEVT_SCROLL_THUMBTRACK
;
149 case XmCR_VALUE_CHANGED
:
151 eventType
= wxEVT_SCROLL_THUMBRELEASE
;
154 case XmCR_PAGE_INCREMENT
:
156 eventType
= wxEVT_SCROLL_PAGEDOWN
;
159 case XmCR_PAGE_DECREMENT
:
161 eventType
= wxEVT_SCROLL_PAGEUP
;
166 eventType
= wxEVT_SCROLL_TOP
;
171 eventType
= wxEVT_SCROLL_BOTTOM
;
176 // Should never get here
177 wxFAIL_MSG("Unknown scroll event.");
182 wxScrollEvent
event(eventType
, scrollBar
->GetId(),
183 cbs
->value
, orientation
);
184 event
.SetEventObject(scrollBar
);
185 scrollBar
->GetEventHandler()->ProcessEvent(event
);