1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/scrolbar.cpp
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"
15 #include "wx/scrolbar.h"
18 #pragma message disable nosimpint
19 #define XtDisplay XTDISPLAY
22 #include <Xm/ScrollBar.h>
24 #pragma message enable nosimpint
27 #include "wx/motif/private.h"
29 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
30 XmScaleCallbackStruct
*cbs
);
32 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar
, wxControl
)
35 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
37 const wxSize
& size
, long style
,
38 const wxValidator
& validator
,
41 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
);
58 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
,
59 pos
.x
, pos
.y
, newSize
.x
, newSize
.y
);
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 wxCHECK_RET( scrollBar
, _T("invalid widget in scrollbar callback") );
131 wxOrientation orientation
= (wxOrientation
)wxPtrToUInt(clientData
);
132 wxEventType eventType
= wxEVT_NULL
;
138 eventType
= wxEVT_SCROLL_LINEDOWN
;
143 eventType
= wxEVT_SCROLL_LINEUP
;
148 eventType
= wxEVT_SCROLL_THUMBTRACK
;
151 case XmCR_VALUE_CHANGED
:
153 eventType
= wxEVT_SCROLL_THUMBRELEASE
;
156 case XmCR_PAGE_INCREMENT
:
158 eventType
= wxEVT_SCROLL_PAGEDOWN
;
161 case XmCR_PAGE_DECREMENT
:
163 eventType
= wxEVT_SCROLL_PAGEUP
;
168 eventType
= wxEVT_SCROLL_TOP
;
173 eventType
= wxEVT_SCROLL_BOTTOM
;
178 // Should never get here
179 wxFAIL_MSG("Unknown scroll event.");
184 wxScrollEvent
event(eventType
, scrollBar
->GetId(),
185 cbs
->value
, orientation
);
186 event
.SetEventObject(scrollBar
);
187 scrollBar
->HandleWindowEvent(event
);