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
21 #include <Xm/ScrollBar.h>
23 #pragma message enable nosimpint
26 #include "wx/motif/private.h"
28 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
29 XmScaleCallbackStruct
*cbs
);
32 bool wxScrollBar::Create(wxWindow
*parent
, wxWindowID id
,
34 const wxSize
& size
, long style
,
35 const wxValidator
& validator
,
38 if( !CreateControl( parent
, id
, pos
, size
, style
, validator
, name
) )
43 ( style
& wxHORIZONTAL
) ? wxSize( 140, 16 ) : wxSize( 16, 140 );
44 if( size
.x
!= -1 ) newSize
.x
= size
.x
;
45 if( size
.y
!= -1 ) newSize
.y
= size
.y
;
47 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
50 DoCreateScrollBar( (WXWidget
)parentWidget
,
51 (wxOrientation
)(style
& (wxHORIZONTAL
|wxVERTICAL
)),
52 (void (*)())wxScrollBarCallback
);
55 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
,
56 pos
.x
, pos
.y
, newSize
.x
, newSize
.y
);
61 wxScrollBar::~wxScrollBar()
65 void wxScrollBar::SetThumbPosition(int pos
)
67 XtVaSetValues ((Widget
) m_mainWidget
,
72 int wxScrollBar::GetThumbPosition() const
75 XtVaGetValues((Widget
) m_mainWidget
,
76 XmNvalue
, &pos
, NULL
);
80 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
81 bool WXUNUSED(refresh
))
83 m_viewSize
= pageSize
;
84 m_pageSize
= thumbSize
;
92 XtVaSetValues((Widget
) m_mainWidget
,
96 XmNsliderSize
, thumbSize
,
97 XmNpageIncrement
, pageSize
,
101 void wxScrollBar::Command(wxCommandEvent
& event
)
103 SetThumbPosition(event
.GetInt());
104 ProcessCommand(event
);
107 void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize
))
110 // Do anything for a scrollbar? A font will never be seen.
113 void wxScrollBar::ChangeBackgroundColour()
115 wxWindow::ChangeBackgroundColour();
117 XtVaSetValues ((Widget
) GetMainWidget(),
118 XmNtroughColor
, m_backgroundColour
.AllocColour(XtDisplay((Widget
) GetMainWidget())),
122 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
123 XmScaleCallbackStruct
*cbs
)
125 wxScrollBar
*scrollBar
= (wxScrollBar
*)wxGetWindowFromTable(widget
);
126 wxCHECK_RET( scrollBar
, wxT("invalid widget in scrollbar callback") );
128 wxOrientation orientation
= (wxOrientation
)wxPtrToUInt(clientData
);
129 wxEventType eventType
= wxEVT_NULL
;
135 eventType
= wxEVT_SCROLL_LINEDOWN
;
140 eventType
= wxEVT_SCROLL_LINEUP
;
145 eventType
= wxEVT_SCROLL_THUMBTRACK
;
148 case XmCR_VALUE_CHANGED
:
150 eventType
= wxEVT_SCROLL_THUMBRELEASE
;
153 case XmCR_PAGE_INCREMENT
:
155 eventType
= wxEVT_SCROLL_PAGEDOWN
;
158 case XmCR_PAGE_DECREMENT
:
160 eventType
= wxEVT_SCROLL_PAGEUP
;
165 eventType
= wxEVT_SCROLL_TOP
;
170 eventType
= wxEVT_SCROLL_BOTTOM
;
175 // Should never get here
176 wxFAIL_MSG("Unknown scroll event.");
181 wxScrollEvent
event(eventType
, scrollBar
->GetId(),
182 cbs
->value
, orientation
);
183 event
.SetEventObject(scrollBar
);
184 scrollBar
->HandleWindowEvent(event
);