]> git.saurik.com Git - wxWidgets.git/blame - src/motif/scrolbar.cpp
[ 1509599 ] 'Split pickers page in widgets sample' with more icons and rebaking.
[wxWidgets.git] / src / motif / scrolbar.cpp
CommitLineData
4bb6408c 1/////////////////////////////////////////////////////////////////////////////
355b4d3d 2// Name: src/motif/scrolbar.cpp
4bb6408c
JS
3// Purpose: wxScrollBar
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
1248b41f
MB
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
4bb6408c
JS
15#include "wx/scrolbar.h"
16
338dd992
JJ
17#ifdef __VMS__
18#pragma message disable nosimpint
c698eae5 19#define XtDisplay XTDISPLAY
338dd992 20#endif
47bc1060 21#include <Xm/Xm.h>
47bc1060 22#include <Xm/ScrollBar.h>
338dd992
JJ
23#ifdef __VMS__
24#pragma message enable nosimpint
25#endif
47bc1060 26
3096bd2f 27#include "wx/motif/private.h"
47bc1060 28
8aa04e8b 29static void wxScrollBarCallback(Widget widget, XtPointer clientData,
47bc1060
JS
30 XmScaleCallbackStruct *cbs);
31
4bb6408c 32IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
4bb6408c
JS
33
34// Scrollbar
35bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
36 const wxPoint& pos,
37 const wxSize& size, long style,
38 const wxValidator& validator,
39 const wxString& name)
40{
6c33b24c
MB
41 if( !CreateControl( parent, id, pos, size, style, validator, name ) )
42 return false;
47bc1060 43
6c33b24c
MB
44 wxSize newSize =
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;
47bc1060 48
6c33b24c 49 Widget parentWidget = (Widget) parent->GetClientWidget();
47bc1060 50
6c33b24c
MB
51 m_mainWidget =
52 DoCreateScrollBar( (WXWidget)parentWidget,
53 (wxOrientation)(style & (wxHORIZONTAL|wxVERTICAL)),
54 (void (*)())wxScrollBarCallback );
47bc1060 55
6c33b24c
MB
56 AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
57 pos.x, pos.y, newSize.x, newSize.y);
0d57be45 58 ChangeBackgroundColour();
47bc1060 59
6c33b24c 60 return true;
4bb6408c
JS
61}
62
63wxScrollBar::~wxScrollBar()
64{
65}
66
4fabb575 67void wxScrollBar::SetThumbPosition(int pos)
4bb6408c 68{
6c33b24c
MB
69 XtVaSetValues ((Widget) m_mainWidget,
70 XmNvalue, pos,
71 NULL);
4bb6408c
JS
72}
73
4fabb575 74int wxScrollBar::GetThumbPosition() const
4bb6408c 75{
6c33b24c
MB
76 int pos;
77 XtVaGetValues((Widget) m_mainWidget,
78 XmNvalue, &pos, NULL);
79 return pos;
4bb6408c
JS
80}
81
82void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
af111fc3 83 bool WXUNUSED(refresh))
4bb6408c
JS
84{
85 m_viewSize = pageSize;
86 m_pageSize = thumbSize;
87 m_objectSize = range;
88
47bc1060
JS
89 if (range == 0)
90 range = 1;
91 if (thumbSize == 0)
92 thumbSize = 1;
4bb6408c 93
47bc1060
JS
94 XtVaSetValues((Widget) m_mainWidget,
95 XmNvalue, position,
96 XmNminimum, 0,
97 XmNmaximum, range,
98 XmNsliderSize, thumbSize,
99 XmNpageIncrement, pageSize,
100 NULL);
101}
4bb6408c
JS
102
103void wxScrollBar::Command(wxCommandEvent& event)
104{
687706f5 105 SetThumbPosition(event.GetInt());
4bb6408c
JS
106 ProcessCommand(event);
107}
108
af111fc3 109void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize))
0d57be45
JS
110{
111 // TODO
b412f9be 112 // Do anything for a scrollbar? A font will never be seen.
0d57be45
JS
113}
114
115void wxScrollBar::ChangeBackgroundColour()
116{
b412f9be 117 wxWindow::ChangeBackgroundColour();
15d5ab67
JS
118
119 XtVaSetValues ((Widget) GetMainWidget(),
120 XmNtroughColor, m_backgroundColour.AllocColour(XtDisplay((Widget) GetMainWidget())),
121 NULL);
0d57be45
JS
122}
123
6c33b24c
MB
124static void wxScrollBarCallback(Widget widget, XtPointer clientData,
125 XmScaleCallbackStruct *cbs)
47bc1060 126{
6c33b24c 127 wxScrollBar *scrollBar = (wxScrollBar*)wxGetWindowFromTable(widget);
a4588fd1 128 wxOrientation orientation = (wxOrientation)wxPtrToUInt(clientData);
47bc1060 129 wxEventType eventType = wxEVT_NULL;
bdeca1d1 130
47bc1060
JS
131 switch (cbs->reason)
132 {
133 case XmCR_INCREMENT:
134 {
135 eventType = wxEVT_SCROLL_LINEDOWN;
136 break;
137 }
138 case XmCR_DECREMENT:
139 {
140 eventType = wxEVT_SCROLL_LINEUP;
141 break;
142 }
143 case XmCR_DRAG:
144 {
145 eventType = wxEVT_SCROLL_THUMBTRACK;
146 break;
147 }
148 case XmCR_VALUE_CHANGED:
149 {
bdeca1d1 150 eventType = wxEVT_SCROLL_THUMBRELEASE;
47bc1060
JS
151 break;
152 }
153 case XmCR_PAGE_INCREMENT:
154 {
155 eventType = wxEVT_SCROLL_PAGEDOWN;
156 break;
157 }
158 case XmCR_PAGE_DECREMENT:
159 {
160 eventType = wxEVT_SCROLL_PAGEUP;
161 break;
162 }
163 case XmCR_TO_TOP:
164 {
165 eventType = wxEVT_SCROLL_TOP;
166 break;
167 }
168 case XmCR_TO_BOTTOM:
169 {
170 eventType = wxEVT_SCROLL_BOTTOM;
171 break;
172 }
173 default:
174 {
175 // Should never get here
176 wxFAIL_MSG("Unknown scroll event.");
177 break;
178 }
179 }
180
6c33b24c
MB
181 wxScrollEvent event(eventType, scrollBar->GetId(),
182 cbs->value, orientation);
47bc1060 183 event.SetEventObject(scrollBar);
47bc1060 184 scrollBar->GetEventHandler()->ProcessEvent(event);
47bc1060 185}