]> git.saurik.com Git - wxWidgets.git/blame - src/motif/scrolbar.cpp
test
[wxWidgets.git] / src / motif / scrolbar.cpp
CommitLineData
4bb6408c
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: scrolbar.cpp
3// Purpose: wxScrollBar
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
31528cd3 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "scrolbar.h"
14#endif
15
16#include "wx/scrolbar.h"
17
338dd992
JJ
18#ifdef __VMS__
19#pragma message disable nosimpint
20#endif
47bc1060
JS
21#include <X11/IntrinsicP.h>
22#include <Xm/Xm.h>
23#include <Xm/RowColumn.h>
24#include <Xm/ScrollBar.h>
338dd992
JJ
25#ifdef __VMS__
26#pragma message enable nosimpint
27#endif
47bc1060 28
3096bd2f 29#include "wx/motif/private.h"
47bc1060 30
8aa04e8b 31static void wxScrollBarCallback(Widget widget, XtPointer clientData,
47bc1060
JS
32 XmScaleCallbackStruct *cbs);
33
4bb6408c
JS
34#if !USE_SHARED_LIBRARY
35IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
4bb6408c
JS
36#endif
37
38// Scrollbar
39bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
40 const wxPoint& pos,
41 const wxSize& size, long style,
42 const wxValidator& validator,
43 const wxString& name)
44{
45 if (!parent)
46 return FALSE;
47 parent->AddChild(this);
48 SetName(name);
0d57be45
JS
49 m_backgroundColour = parent->GetBackgroundColour();
50 m_foregroundColour = parent->GetForegroundColour();
51 SetValidator(validator);
31528cd3 52
4bb6408c
JS
53 m_windowStyle = style;
54
55 if ( id == -1 )
31528cd3 56 m_windowId = (int)NewControlId();
4bb6408c 57 else
31528cd3 58 m_windowId = id;
4bb6408c 59
47bc1060
JS
60 int x = pos.x;
61 int y = pos.y;
62 int width = size.x;
63 int height = size.y;
64
65 if (width == -1)
66 {
67 if (style & wxHORIZONTAL)
68 width = 140;
69 else
70 width = 12;
71 }
72 if (height == -1)
73 {
74 if (style & wxVERTICAL)
75 height = 140;
76 else
77 height = 12;
78 }
79
80 Widget parentWidget = (Widget) parent->GetClientWidget();
81 int direction = (style & wxHORIZONTAL) ? XmHORIZONTAL: XmVERTICAL;
82
83 Widget scrollBarWidget = XtVaCreateManagedWidget("scrollBarWidget",
84 xmScrollBarWidgetClass, parentWidget,
85 XmNorientation, direction,
86 NULL);
87
88 m_mainWidget = (Widget) scrollBarWidget;
89
90 // This will duplicate other events
91 // XtAddCallback(scrollBarWidget, XmNvalueChangedCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
92 XtAddCallback(scrollBarWidget, XmNdragCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
93 XtAddCallback(scrollBarWidget, XmNdecrementCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
94 XtAddCallback(scrollBarWidget, XmNincrementCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
95 XtAddCallback(scrollBarWidget, XmNpageDecrementCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
96 XtAddCallback(scrollBarWidget, XmNpageIncrementCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
97 XtAddCallback(scrollBarWidget, XmNtoTopCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
98 XtAddCallback(scrollBarWidget, XmNtoBottomCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
99
100 SetCanAddEventHandler(TRUE);
101 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, x, y, width, height);
0d57be45 102 ChangeBackgroundColour();
47bc1060 103
4bb6408c
JS
104 return TRUE;
105}
106
107wxScrollBar::~wxScrollBar()
108{
109}
110
4fabb575 111void wxScrollBar::SetThumbPosition(int pos)
4bb6408c 112{
47bc1060
JS
113 if (m_mainWidget)
114 {
115 XtVaSetValues ((Widget) m_mainWidget,
116 XmNvalue, pos,
117 NULL);
118 }
4bb6408c
JS
119}
120
4fabb575 121int wxScrollBar::GetThumbPosition() const
4bb6408c 122{
47bc1060
JS
123 if (m_mainWidget)
124 {
125 int pos;
126 XtVaGetValues((Widget) m_mainWidget,
127 XmNvalue, &pos, NULL);
128 return pos;
129 }
130 else
131 return 0;
4bb6408c
JS
132}
133
134void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
af111fc3 135 bool WXUNUSED(refresh))
4bb6408c
JS
136{
137 m_viewSize = pageSize;
138 m_pageSize = thumbSize;
139 m_objectSize = range;
140
47bc1060
JS
141 if (range == 0)
142 range = 1;
143 if (thumbSize == 0)
144 thumbSize = 1;
4bb6408c 145
47bc1060
JS
146 XtVaSetValues((Widget) m_mainWidget,
147 XmNvalue, position,
148 XmNminimum, 0,
149 XmNmaximum, range,
150 XmNsliderSize, thumbSize,
151 XmNpageIncrement, pageSize,
152 NULL);
153}
4bb6408c
JS
154
155void wxScrollBar::Command(wxCommandEvent& event)
156{
c0ed460c 157 SetThumbPosition(event.m_commandInt);
4bb6408c
JS
158 ProcessCommand(event);
159}
160
af111fc3 161void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize))
0d57be45
JS
162{
163 // TODO
b412f9be 164 // Do anything for a scrollbar? A font will never be seen.
0d57be45
JS
165}
166
167void wxScrollBar::ChangeBackgroundColour()
168{
b412f9be 169 wxWindow::ChangeBackgroundColour();
15d5ab67
JS
170
171 XtVaSetValues ((Widget) GetMainWidget(),
172 XmNtroughColor, m_backgroundColour.AllocColour(XtDisplay((Widget) GetMainWidget())),
173 NULL);
0d57be45
JS
174}
175
176void wxScrollBar::ChangeForegroundColour()
177{
b412f9be 178 wxWindow::ChangeForegroundColour();
0d57be45
JS
179}
180
af111fc3 181static void wxScrollBarCallback(Widget WXUNUSED(widget), XtPointer clientData,
47bc1060
JS
182 XmScaleCallbackStruct *cbs)
183{
184 wxScrollBar *scrollBar = (wxScrollBar *)clientData;
185
186 wxEventType eventType = wxEVT_NULL;
187 switch (cbs->reason)
188 {
189 case XmCR_INCREMENT:
190 {
191 eventType = wxEVT_SCROLL_LINEDOWN;
192 break;
193 }
194 case XmCR_DECREMENT:
195 {
196 eventType = wxEVT_SCROLL_LINEUP;
197 break;
198 }
199 case XmCR_DRAG:
200 {
201 eventType = wxEVT_SCROLL_THUMBTRACK;
202 break;
203 }
204 case XmCR_VALUE_CHANGED:
205 {
206 // TODO: Should this be intercepted too, or will it cause
207 // duplicate events?
208 eventType = wxEVT_SCROLL_THUMBTRACK;
209 break;
210 }
211 case XmCR_PAGE_INCREMENT:
212 {
213 eventType = wxEVT_SCROLL_PAGEDOWN;
214 break;
215 }
216 case XmCR_PAGE_DECREMENT:
217 {
218 eventType = wxEVT_SCROLL_PAGEUP;
219 break;
220 }
221 case XmCR_TO_TOP:
222 {
223 eventType = wxEVT_SCROLL_TOP;
224 break;
225 }
226 case XmCR_TO_BOTTOM:
227 {
228 eventType = wxEVT_SCROLL_BOTTOM;
229 break;
230 }
231 default:
232 {
233 // Should never get here
234 wxFAIL_MSG("Unknown scroll event.");
235 break;
236 }
237 }
238
239 wxScrollEvent event(eventType, scrollBar->GetId());
240 event.SetEventObject(scrollBar);
241 event.SetPosition(cbs->value);
242 scrollBar->GetEventHandler()->ProcessEvent(event);
243/*
244 if (!scrollBar->inSetValue)
245 scrollBar->ProcessCommand(event);
246*/
247}
248