]> git.saurik.com Git - wxWidgets.git/blob - src/motif/scrolbar.cpp
removed non existing unzip.h from the filelist.txt and regenerated everything
[wxWidgets.git] / src / motif / scrolbar.cpp
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/defs.h"
17
18 #include "wx/scrolbar.h"
19
20 #ifdef __VMS__
21 #pragma message disable nosimpint
22 #endif
23 #include <X11/IntrinsicP.h>
24 #include <Xm/Xm.h>
25 #include <Xm/RowColumn.h>
26 #include <Xm/ScrollBar.h>
27 #ifdef __VMS__
28 #pragma message enable nosimpint
29 #endif
30
31 #include "wx/motif/private.h"
32
33 static void wxScrollBarCallback(Widget widget, XtPointer clientData,
34 XmScaleCallbackStruct *cbs);
35
36 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
37
38 // Scrollbar
39 bool 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);
49 m_backgroundColour = parent->GetBackgroundColour();
50 m_foregroundColour = parent->GetForegroundColour();
51 SetValidator(validator);
52
53 m_windowStyle = style;
54
55 if ( id == -1 )
56 m_windowId = (int)NewControlId();
57 else
58 m_windowId = id;
59
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 XtAddCallback(scrollBarWidget, XmNvalueChangedCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
91 XtAddCallback(scrollBarWidget, XmNdragCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
92 XtAddCallback(scrollBarWidget, XmNdecrementCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
93 XtAddCallback(scrollBarWidget, XmNincrementCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
94 XtAddCallback(scrollBarWidget, XmNpageDecrementCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
95 XtAddCallback(scrollBarWidget, XmNpageIncrementCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
96 XtAddCallback(scrollBarWidget, XmNtoTopCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
97 XtAddCallback(scrollBarWidget, XmNtoBottomCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this);
98
99 SetCanAddEventHandler(TRUE);
100 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, x, y, width, height);
101 ChangeBackgroundColour();
102
103 return TRUE;
104 }
105
106 wxScrollBar::~wxScrollBar()
107 {
108 }
109
110 void wxScrollBar::SetThumbPosition(int pos)
111 {
112 if (m_mainWidget)
113 {
114 XtVaSetValues ((Widget) m_mainWidget,
115 XmNvalue, pos,
116 NULL);
117 }
118 }
119
120 int wxScrollBar::GetThumbPosition() const
121 {
122 if (m_mainWidget)
123 {
124 int pos;
125 XtVaGetValues((Widget) m_mainWidget,
126 XmNvalue, &pos, NULL);
127 return pos;
128 }
129 else
130 return 0;
131 }
132
133 void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
134 bool WXUNUSED(refresh))
135 {
136 m_viewSize = pageSize;
137 m_pageSize = thumbSize;
138 m_objectSize = range;
139
140 if (range == 0)
141 range = 1;
142 if (thumbSize == 0)
143 thumbSize = 1;
144
145 XtVaSetValues((Widget) m_mainWidget,
146 XmNvalue, position,
147 XmNminimum, 0,
148 XmNmaximum, range,
149 XmNsliderSize, thumbSize,
150 XmNpageIncrement, pageSize,
151 NULL);
152 }
153
154 void wxScrollBar::Command(wxCommandEvent& event)
155 {
156 SetThumbPosition(event.m_commandInt);
157 ProcessCommand(event);
158 }
159
160 void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize))
161 {
162 // TODO
163 // Do anything for a scrollbar? A font will never be seen.
164 }
165
166 void wxScrollBar::ChangeBackgroundColour()
167 {
168 wxWindow::ChangeBackgroundColour();
169
170 XtVaSetValues ((Widget) GetMainWidget(),
171 XmNtroughColor, m_backgroundColour.AllocColour(XtDisplay((Widget) GetMainWidget())),
172 NULL);
173 }
174
175 void wxScrollBar::ChangeForegroundColour()
176 {
177 wxWindow::ChangeForegroundColour();
178 }
179
180 static void wxScrollBarCallback(Widget WXUNUSED(widget), XtPointer clientData,
181 XmScaleCallbackStruct *cbs)
182 {
183 wxScrollBar *scrollBar = (wxScrollBar *)clientData;
184 wxEventType eventType = wxEVT_NULL;
185
186 switch (cbs->reason)
187 {
188 case XmCR_INCREMENT:
189 {
190 eventType = wxEVT_SCROLL_LINEDOWN;
191 break;
192 }
193 case XmCR_DECREMENT:
194 {
195 eventType = wxEVT_SCROLL_LINEUP;
196 break;
197 }
198 case XmCR_DRAG:
199 {
200 eventType = wxEVT_SCROLL_THUMBTRACK;
201 break;
202 }
203 case XmCR_VALUE_CHANGED:
204 {
205 eventType = wxEVT_SCROLL_THUMBRELEASE;
206 break;
207 }
208 case XmCR_PAGE_INCREMENT:
209 {
210 eventType = wxEVT_SCROLL_PAGEDOWN;
211 break;
212 }
213 case XmCR_PAGE_DECREMENT:
214 {
215 eventType = wxEVT_SCROLL_PAGEUP;
216 break;
217 }
218 case XmCR_TO_TOP:
219 {
220 eventType = wxEVT_SCROLL_TOP;
221 break;
222 }
223 case XmCR_TO_BOTTOM:
224 {
225 eventType = wxEVT_SCROLL_BOTTOM;
226 break;
227 }
228 default:
229 {
230 // Should never get here
231 wxFAIL_MSG("Unknown scroll event.");
232 break;
233 }
234 }
235
236 wxScrollEvent event(eventType, scrollBar->GetId());
237 event.SetEventObject(scrollBar);
238 event.SetPosition(cbs->value);
239 scrollBar->GetEventHandler()->ProcessEvent(event);
240 /*
241 if (!scrollBar->inSetValue)
242 scrollBar->ProcessCommand(event);
243 */
244 }
245