1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxScrollBar
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "scrolbar.h"
17 #include "wx/scrolbar.h"
20 #pragma message disable nosimpint
21 #define XtDisplay XTDISPLAY
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
,
43 if( !CreateControl( parent
, id
, pos
, size
, style
, validator
, name
) )
47 ( style
& wxHORIZONTAL
) ? wxSize( 140, 16 ) : wxSize( 16, 140 );
48 if( size
.x
!= -1 ) newSize
.x
= size
.x
;
49 if( size
.y
!= -1 ) newSize
.y
= size
.y
;
51 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
54 DoCreateScrollBar( (WXWidget
)parentWidget
,
55 (wxOrientation
)(style
& (wxHORIZONTAL
|wxVERTICAL
)),
56 (void (*)())wxScrollBarCallback
);
58 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
,
59 pos
.x
, pos
.y
, newSize
.x
, newSize
.y
);
60 ChangeBackgroundColour();
65 wxScrollBar::~wxScrollBar()
69 void wxScrollBar::SetThumbPosition(int pos
)
71 XtVaSetValues ((Widget
) m_mainWidget
,
76 int wxScrollBar::GetThumbPosition() const
79 XtVaGetValues((Widget
) m_mainWidget
,
80 XmNvalue
, &pos
, NULL
);
84 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
85 bool WXUNUSED(refresh
))
87 m_viewSize
= pageSize
;
88 m_pageSize
= thumbSize
;
96 XtVaSetValues((Widget
) m_mainWidget
,
100 XmNsliderSize
, thumbSize
,
101 XmNpageIncrement
, pageSize
,
105 void wxScrollBar::Command(wxCommandEvent
& event
)
107 SetThumbPosition(event
.m_commandInt
);
108 ProcessCommand(event
);
111 void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize
))
114 // Do anything for a scrollbar? A font will never be seen.
117 void wxScrollBar::ChangeBackgroundColour()
119 wxWindow::ChangeBackgroundColour();
121 XtVaSetValues ((Widget
) GetMainWidget(),
122 XmNtroughColor
, m_backgroundColour
.AllocColour(XtDisplay((Widget
) GetMainWidget())),
126 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
127 XmScaleCallbackStruct
*cbs
)
129 wxScrollBar
*scrollBar
= (wxScrollBar
*)wxGetWindowFromTable(widget
);
130 wxOrientation orientation
= (wxOrientation
)(int)clientData
;
131 wxEventType eventType
= wxEVT_NULL
;
137 eventType
= wxEVT_SCROLL_LINEDOWN
;
142 eventType
= wxEVT_SCROLL_LINEUP
;
147 eventType
= wxEVT_SCROLL_THUMBTRACK
;
150 case XmCR_VALUE_CHANGED
:
152 eventType
= wxEVT_SCROLL_THUMBRELEASE
;
155 case XmCR_PAGE_INCREMENT
:
157 eventType
= wxEVT_SCROLL_PAGEDOWN
;
160 case XmCR_PAGE_DECREMENT
:
162 eventType
= wxEVT_SCROLL_PAGEUP
;
167 eventType
= wxEVT_SCROLL_TOP
;
172 eventType
= wxEVT_SCROLL_BOTTOM
;
177 // Should never get here
178 wxFAIL_MSG("Unknown scroll event.");
183 wxScrollEvent
event(eventType
, scrollBar
->GetId(),
184 cbs
->value
, orientation
);
185 event
.SetEventObject(scrollBar
);
186 scrollBar
->GetEventHandler()->ProcessEvent(event
);