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
) )
45 ( style
& wxHORIZONTAL
) ? wxSize( 140, 16 ) : wxSize( 16, 140 );
46 if( size
.x
!= -1 ) newSize
.x
= size
.x
;
47 if( size
.y
!= -1 ) newSize
.y
= size
.y
;
49 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
52 DoCreateScrollBar( (WXWidget
)parentWidget
,
53 (wxOrientation
)(style
& (wxHORIZONTAL
|wxVERTICAL
)),
54 (void (*)())wxScrollBarCallback
);
56 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
,
57 pos
.x
, pos
.y
, newSize
.x
, newSize
.y
);
58 ChangeBackgroundColour();
63 wxScrollBar::~wxScrollBar()
67 void wxScrollBar::SetThumbPosition(int pos
)
69 XtVaSetValues ((Widget
) m_mainWidget
,
74 int wxScrollBar::GetThumbPosition() const
77 XtVaGetValues((Widget
) m_mainWidget
,
78 XmNvalue
, &pos
, NULL
);
82 void wxScrollBar::SetScrollbar(int position
, int thumbSize
, int range
, int pageSize
,
83 bool WXUNUSED(refresh
))
85 m_viewSize
= pageSize
;
86 m_pageSize
= thumbSize
;
94 XtVaSetValues((Widget
) m_mainWidget
,
98 XmNsliderSize
, thumbSize
,
99 XmNpageIncrement
, pageSize
,
103 void wxScrollBar::Command(wxCommandEvent
& event
)
105 SetThumbPosition(event
.GetInt());
106 ProcessCommand(event
);
109 void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize
))
112 // Do anything for a scrollbar? A font will never be seen.
115 void wxScrollBar::ChangeBackgroundColour()
117 wxWindow::ChangeBackgroundColour();
119 XtVaSetValues ((Widget
) GetMainWidget(),
120 XmNtroughColor
, m_backgroundColour
.AllocColour(XtDisplay((Widget
) GetMainWidget())),
124 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
125 XmScaleCallbackStruct
*cbs
)
127 wxScrollBar
*scrollBar
= (wxScrollBar
*)wxGetWindowFromTable(widget
);
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
->GetEventHandler()->ProcessEvent(event
);