]>
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 | |
31528cd3 | 9 | // Licence: wxWindows licence |
4bb6408c JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "scrolbar.h" | |
14 | #endif | |
15 | ||
f6045f99 GD |
16 | #include "wx/defs.h" |
17 | ||
4bb6408c JS |
18 | #include "wx/scrolbar.h" |
19 | ||
338dd992 JJ |
20 | #ifdef __VMS__ |
21 | #pragma message disable nosimpint | |
22 | #endif | |
47bc1060 JS |
23 | #include <X11/IntrinsicP.h> |
24 | #include <Xm/Xm.h> | |
25 | #include <Xm/RowColumn.h> | |
26 | #include <Xm/ScrollBar.h> | |
338dd992 JJ |
27 | #ifdef __VMS__ |
28 | #pragma message enable nosimpint | |
29 | #endif | |
47bc1060 | 30 | |
3096bd2f | 31 | #include "wx/motif/private.h" |
47bc1060 | 32 | |
8aa04e8b | 33 | static void wxScrollBarCallback(Widget widget, XtPointer clientData, |
47bc1060 JS |
34 | XmScaleCallbackStruct *cbs); |
35 | ||
4bb6408c | 36 | IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl) |
4bb6408c JS |
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); | |
0d57be45 JS |
49 | m_backgroundColour = parent->GetBackgroundColour(); |
50 | m_foregroundColour = parent->GetForegroundColour(); | |
51 | SetValidator(validator); | |
31528cd3 | 52 | |
4bb6408c JS |
53 | m_windowStyle = style; |
54 | ||
55 | if ( id == -1 ) | |
31528cd3 | 56 | m_windowId = (int)NewControlId(); |
4bb6408c | 57 | else |
31528cd3 | 58 | m_windowId = id; |
4bb6408c | 59 | |
47bc1060 JS |
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 | ||
bdeca1d1 | 90 | XtAddCallback(scrollBarWidget, XmNvalueChangedCallback, (XtCallbackProc)wxScrollBarCallback, (XtPointer)this); |
47bc1060 JS |
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); | |
0d57be45 | 101 | ChangeBackgroundColour(); |
47bc1060 | 102 | |
4bb6408c JS |
103 | return TRUE; |
104 | } | |
105 | ||
106 | wxScrollBar::~wxScrollBar() | |
107 | { | |
108 | } | |
109 | ||
4fabb575 | 110 | void wxScrollBar::SetThumbPosition(int pos) |
4bb6408c | 111 | { |
47bc1060 JS |
112 | if (m_mainWidget) |
113 | { | |
114 | XtVaSetValues ((Widget) m_mainWidget, | |
115 | XmNvalue, pos, | |
116 | NULL); | |
117 | } | |
4bb6408c JS |
118 | } |
119 | ||
4fabb575 | 120 | int wxScrollBar::GetThumbPosition() const |
4bb6408c | 121 | { |
47bc1060 JS |
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; | |
4bb6408c JS |
131 | } |
132 | ||
133 | void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize, | |
af111fc3 | 134 | bool WXUNUSED(refresh)) |
4bb6408c JS |
135 | { |
136 | m_viewSize = pageSize; | |
137 | m_pageSize = thumbSize; | |
138 | m_objectSize = range; | |
139 | ||
47bc1060 JS |
140 | if (range == 0) |
141 | range = 1; | |
142 | if (thumbSize == 0) | |
143 | thumbSize = 1; | |
4bb6408c | 144 | |
47bc1060 JS |
145 | XtVaSetValues((Widget) m_mainWidget, |
146 | XmNvalue, position, | |
147 | XmNminimum, 0, | |
148 | XmNmaximum, range, | |
149 | XmNsliderSize, thumbSize, | |
150 | XmNpageIncrement, pageSize, | |
151 | NULL); | |
152 | } | |
4bb6408c JS |
153 | |
154 | void wxScrollBar::Command(wxCommandEvent& event) | |
155 | { | |
c0ed460c | 156 | SetThumbPosition(event.m_commandInt); |
4bb6408c JS |
157 | ProcessCommand(event); |
158 | } | |
159 | ||
af111fc3 | 160 | void wxScrollBar::ChangeFont(bool WXUNUSED(keepOriginalSize)) |
0d57be45 JS |
161 | { |
162 | // TODO | |
b412f9be | 163 | // Do anything for a scrollbar? A font will never be seen. |
0d57be45 JS |
164 | } |
165 | ||
166 | void wxScrollBar::ChangeBackgroundColour() | |
167 | { | |
b412f9be | 168 | wxWindow::ChangeBackgroundColour(); |
15d5ab67 JS |
169 | |
170 | XtVaSetValues ((Widget) GetMainWidget(), | |
171 | XmNtroughColor, m_backgroundColour.AllocColour(XtDisplay((Widget) GetMainWidget())), | |
172 | NULL); | |
0d57be45 JS |
173 | } |
174 | ||
175 | void wxScrollBar::ChangeForegroundColour() | |
176 | { | |
b412f9be | 177 | wxWindow::ChangeForegroundColour(); |
0d57be45 JS |
178 | } |
179 | ||
af111fc3 | 180 | static void wxScrollBarCallback(Widget WXUNUSED(widget), XtPointer clientData, |
47bc1060 JS |
181 | XmScaleCallbackStruct *cbs) |
182 | { | |
183 | wxScrollBar *scrollBar = (wxScrollBar *)clientData; | |
47bc1060 | 184 | wxEventType eventType = wxEVT_NULL; |
bdeca1d1 | 185 | |
47bc1060 JS |
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 | { | |
bdeca1d1 | 205 | eventType = wxEVT_SCROLL_THUMBRELEASE; |
47bc1060 JS |
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 |