1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/scrolbar.cpp
3 // Purpose: wxScrollBar
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
14 #include "wx/scrolbar.h"
17 #pragma message disable nosimpint
20 #include <Xm/ScrollBar.h>
22 #pragma message enable nosimpint
25 #include "wx/motif/private.h"
27 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
28 XmScaleCallbackStruct
*cbs
);
31 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
33 const wxSize
& size
, long style
,
34 const wxValidator
& validator
,
37 if( !CreateControl( parent
, id
, pos
, size
, style
, validator
, name
) )
42 ( style
& wxHORIZONTAL
) ? wxSize( 140, 16 ) : wxSize( 16, 140 );
43 if( size
.x
!= -1 ) newSize
.x
= size
.x
;
44 if( size
.y
!= -1 ) newSize
.y
= size
.y
;
46 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
49 DoCreateScrollBar( (WXWidget
)parentWidget
,
50 (wxOrientation
)(style
& (wxHORIZONTAL
|wxVERTICAL
)),
51 (void (*)())wxScrollBarCallback
);
54 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
,
55 pos
.x
, pos
.y
, newSize
.x
, newSize
.y
);
60 wxScrollBar::~wxScrollBar()
64 void wxScrollBar::SetThumbPosition(int pos
)
66 XtVaSetValues ((Widget
) m_mainWidget
,
71 int wxScrollBar::GetThumbPosition() const
74 XtVaGetValues((Widget
) m_mainWidget
,
75 XmNvalue
, &pos
, NULL
);
79 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
80 bool WXUNUSED(refresh
))
82 m_viewSize
= pageSize
;
83 m_pageSize
= thumbSize
;
91 XtVaSetValues((Widget
) m_mainWidget
,
95 XmNsliderSize
, thumbSize
,
96 XmNpageIncrement
, pageSize
,
100 void wxScrollBar::Command(wxCommandEvent
& event
)
102 SetThumbPosition(event
.GetInt());
103 ProcessCommand(event
);
106 void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize
))
109 // Do anything for a scrollbar? A font will never be seen.
112 void wxScrollBar::ChangeBackgroundColour()
114 wxWindow::ChangeBackgroundColour();
116 XtVaSetValues ((Widget
) GetMainWidget(),
117 XmNtroughColor
, m_backgroundColour
.AllocColour(XtDisplay((Widget
) GetMainWidget())),
121 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
122 XmScaleCallbackStruct
*cbs
)
124 wxScrollBar
*scrollBar
= (wxScrollBar
*)wxGetWindowFromTable(widget
);
125 wxCHECK_RET( scrollBar
, wxT("invalid widget in scrollbar callback") );
127 wxOrientation orientation
= (wxOrientation
)wxPtrToUInt(clientData
);
128 wxEventType eventType
= wxEVT_NULL
;
134 eventType
= wxEVT_SCROLL_LINEDOWN
;
139 eventType
= wxEVT_SCROLL_LINEUP
;
144 eventType
= wxEVT_SCROLL_THUMBTRACK
;
147 case XmCR_VALUE_CHANGED
:
149 eventType
= wxEVT_SCROLL_THUMBRELEASE
;
152 case XmCR_PAGE_INCREMENT
:
154 eventType
= wxEVT_SCROLL_PAGEDOWN
;
157 case XmCR_PAGE_DECREMENT
:
159 eventType
= wxEVT_SCROLL_PAGEUP
;
164 eventType
= wxEVT_SCROLL_TOP
;
169 eventType
= wxEVT_SCROLL_BOTTOM
;
174 // Should never get here
175 wxFAIL_MSG("Unknown scroll event.");
180 wxScrollEvent
event(eventType
, scrollBar
->GetId(),
181 cbs
->value
, orientation
);
182 event
.SetEventObject(scrollBar
);
183 scrollBar
->HandleWindowEvent(event
);