]> git.saurik.com Git - wxWidgets.git/blame - src/motif/scrolbar.cpp
thread fixes for MSW (samples doesn't compile currently under !MSW, will
[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();
0d57be45
JS
164}
165
166void wxScrollBar::ChangeForegroundColour()
167{
b412f9be 168 wxWindow::ChangeForegroundColour();
0d57be45
JS
169}
170
8aa04e8b 171static void wxScrollBarCallback(Widget widget, XtPointer clientData,
47bc1060
JS
172 XmScaleCallbackStruct *cbs)
173{
174 wxScrollBar *scrollBar = (wxScrollBar *)clientData;
175
176 wxEventType eventType = wxEVT_NULL;
177 switch (cbs->reason)
178 {
179 case XmCR_INCREMENT:
180 {
181 eventType = wxEVT_SCROLL_LINEDOWN;
182 break;
183 }
184 case XmCR_DECREMENT:
185 {
186 eventType = wxEVT_SCROLL_LINEUP;
187 break;
188 }
189 case XmCR_DRAG:
190 {
191 eventType = wxEVT_SCROLL_THUMBTRACK;
192 break;
193 }
194 case XmCR_VALUE_CHANGED:
195 {
196 // TODO: Should this be intercepted too, or will it cause
197 // duplicate events?
198 eventType = wxEVT_SCROLL_THUMBTRACK;
199 break;
200 }
201 case XmCR_PAGE_INCREMENT:
202 {
203 eventType = wxEVT_SCROLL_PAGEDOWN;
204 break;
205 }
206 case XmCR_PAGE_DECREMENT:
207 {
208 eventType = wxEVT_SCROLL_PAGEUP;
209 break;
210 }
211 case XmCR_TO_TOP:
212 {
213 eventType = wxEVT_SCROLL_TOP;
214 break;
215 }
216 case XmCR_TO_BOTTOM:
217 {
218 eventType = wxEVT_SCROLL_BOTTOM;
219 break;
220 }
221 default:
222 {
223 // Should never get here
224 wxFAIL_MSG("Unknown scroll event.");
225 break;
226 }
227 }
228
229 wxScrollEvent event(eventType, scrollBar->GetId());
230 event.SetEventObject(scrollBar);
231 event.SetPosition(cbs->value);
232 scrollBar->GetEventHandler()->ProcessEvent(event);
233/*
234 if (!scrollBar->inSetValue)
235 scrollBar->ProcessCommand(event);
236*/
237}
238