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