]>
Commit | Line | Data |
---|---|---|
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 | ||
25 | void wxScrollBarCallback(Widget widget, XtPointer clientData, | |
26 | XmScaleCallbackStruct *cbs); | |
27 | ||
4bb6408c JS |
28 | #if !USE_SHARED_LIBRARY |
29 | IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl) | |
4bb6408c JS |
30 | #endif |
31 | ||
32 | // Scrollbar | |
33 | bool 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 | ||
101 | wxScrollBar::~wxScrollBar() | |
102 | { | |
103 | } | |
104 | ||
47bc1060 | 105 | void wxScrollBar::SetPosition(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 | ||
115 | int wxScrollBar::GetPosition() const | |
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 | ||
128 | void 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 | |
149 | void wxScrollBar::Command(wxCommandEvent& event) | |
150 | { | |
151 | SetPosition(event.m_commandInt); | |
152 | ProcessCommand(event); | |
153 | } | |
154 | ||
0d57be45 JS |
155 | void wxScrollBar::ChangeFont() |
156 | { | |
157 | // TODO | |
158 | } | |
159 | ||
160 | void wxScrollBar::ChangeBackgroundColour() | |
161 | { | |
162 | // TODO | |
163 | } | |
164 | ||
165 | void wxScrollBar::ChangeForegroundColour() | |
166 | { | |
167 | // TODO | |
168 | } | |
169 | ||
47bc1060 JS |
170 | void wxScrollBarCallback(Widget widget, XtPointer clientData, |
171 | XmScaleCallbackStruct *cbs) | |
172 | { | |
173 | wxScrollBar *scrollBar = (wxScrollBar *)clientData; | |
174 | ||
175 | wxEventType eventType = wxEVT_NULL; | |
176 | switch (cbs->reason) | |
177 | { | |
178 | case XmCR_INCREMENT: | |
179 | { | |
180 | eventType = wxEVT_SCROLL_LINEDOWN; | |
181 | break; | |
182 | } | |
183 | case XmCR_DECREMENT: | |
184 | { | |
185 | eventType = wxEVT_SCROLL_LINEUP; | |
186 | break; | |
187 | } | |
188 | case XmCR_DRAG: | |
189 | { | |
190 | eventType = wxEVT_SCROLL_THUMBTRACK; | |
191 | break; | |
192 | } | |
193 | case XmCR_VALUE_CHANGED: | |
194 | { | |
195 | // TODO: Should this be intercepted too, or will it cause | |
196 | // duplicate events? | |
197 | eventType = wxEVT_SCROLL_THUMBTRACK; | |
198 | break; | |
199 | } | |
200 | case XmCR_PAGE_INCREMENT: | |
201 | { | |
202 | eventType = wxEVT_SCROLL_PAGEDOWN; | |
203 | break; | |
204 | } | |
205 | case XmCR_PAGE_DECREMENT: | |
206 | { | |
207 | eventType = wxEVT_SCROLL_PAGEUP; | |
208 | break; | |
209 | } | |
210 | case XmCR_TO_TOP: | |
211 | { | |
212 | eventType = wxEVT_SCROLL_TOP; | |
213 | break; | |
214 | } | |
215 | case XmCR_TO_BOTTOM: | |
216 | { | |
217 | eventType = wxEVT_SCROLL_BOTTOM; | |
218 | break; | |
219 | } | |
220 | default: | |
221 | { | |
222 | // Should never get here | |
223 | wxFAIL_MSG("Unknown scroll event."); | |
224 | break; | |
225 | } | |
226 | } | |
227 | ||
228 | wxScrollEvent event(eventType, scrollBar->GetId()); | |
229 | event.SetEventObject(scrollBar); | |
230 | event.SetPosition(cbs->value); | |
231 | scrollBar->GetEventHandler()->ProcessEvent(event); | |
232 | /* | |
233 | if (!scrollBar->inSetValue) | |
234 | scrollBar->ProcessCommand(event); | |
235 | */ | |
236 | } | |
237 |