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