]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
d80cd92a | 2 | // Name: generic/scrolwin.cpp |
fa3541bd | 3 | // Purpose: wxGenericScrolledWindow implementation |
c801d85f | 4 | // Author: Julian Smart |
566d84a7 RL |
5 | // Modified by: Vadim Zeitlin on 31.08.00: wxScrollHelper allows to implement. |
6 | // Ron Lee on 10.4.02: virtual size / auto scrollbars et al. | |
c801d85f KB |
7 | // Created: 01/02/97 |
8 | // RCS-ID: $Id$ | |
1e6feb95 | 9 | // Copyright: (c) wxWindows team |
a58a12e9 | 10 | // Licence: wxWindows license |
c801d85f KB |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
d80cd92a VZ |
13 | // ============================================================================ |
14 | // declarations | |
15 | // ============================================================================ | |
16 | ||
17 | // ---------------------------------------------------------------------------- | |
18 | // headers | |
19 | // ---------------------------------------------------------------------------- | |
20 | ||
c801d85f | 21 | #ifdef __GNUG__ |
3a8c693a | 22 | #pragma implementation "genscrolwin.h" |
c801d85f KB |
23 | #endif |
24 | ||
bcd055ae JJ |
25 | #ifdef __VMS |
26 | #define XtDisplay XTDISPLAY | |
27 | #endif | |
28 | ||
c801d85f KB |
29 | // For compilers that support precompilation, includes "wx.h". |
30 | #include "wx/wxprec.h" | |
31 | ||
c801d85f | 32 | #ifdef __BORLANDC__ |
d80cd92a | 33 | #pragma hdrstop |
c801d85f KB |
34 | #endif |
35 | ||
3a8c693a VZ |
36 | #if !defined(__WXGTK__) || defined(__WXUNIVERSAL__) |
37 | ||
d80cd92a VZ |
38 | #include "wx/utils.h" |
39 | #include "wx/dcclient.h" | |
40 | ||
1e6feb95 | 41 | #include "wx/scrolwin.h" |
053f9cc1 | 42 | #include "wx/panel.h" |
1e6feb95 | 43 | #include "wx/timer.h" |
95d60b24 | 44 | #include "wx/sizer.h" |
c801d85f | 45 | |
48d1144b | 46 | #ifdef __WXMSW__ |
1e6feb95 | 47 | #include <windows.h> // for DLGC_WANTARROWS |
48d1144b JS |
48 | #endif |
49 | ||
a91b47e8 JS |
50 | #ifdef __WXMOTIF__ |
51 | // For wxRETAINED implementation | |
338dd992 JJ |
52 | #ifdef __VMS__ //VMS's Xm.h is not (yet) compatible with C++ |
53 | //This code switches off the compiler warnings | |
54 | # pragma message disable nosimpint | |
55 | #endif | |
a91b47e8 | 56 | #include <Xm/Xm.h> |
338dd992 JJ |
57 | #ifdef __VMS__ |
58 | # pragma message enable nosimpint | |
59 | #endif | |
a91b47e8 JS |
60 | #endif |
61 | ||
fa3541bd | 62 | IMPLEMENT_CLASS(wxScrolledWindow, wxGenericScrolledWindow) |
fa3541bd | 63 | |
d80cd92a | 64 | // ---------------------------------------------------------------------------- |
1e6feb95 VZ |
65 | // wxScrollHelperEvtHandler: intercept the events from the window and forward |
66 | // them to wxScrollHelper | |
d80cd92a VZ |
67 | // ---------------------------------------------------------------------------- |
68 | ||
349efbaa | 69 | class WXDLLEXPORT wxScrollHelperEvtHandler : public wxEvtHandler |
1e6feb95 VZ |
70 | { |
71 | public: | |
72 | wxScrollHelperEvtHandler(wxScrollHelper *scrollHelper) | |
73 | { | |
74 | m_scrollHelper = scrollHelper; | |
75 | } | |
d80cd92a | 76 | |
1e6feb95 VZ |
77 | virtual bool ProcessEvent(wxEvent& event); |
78 | ||
349efbaa VZ |
79 | void ResetDrawnFlag() { m_hasDrawnWindow = FALSE; } |
80 | ||
1e6feb95 VZ |
81 | private: |
82 | wxScrollHelper *m_scrollHelper; | |
349efbaa VZ |
83 | |
84 | bool m_hasDrawnWindow; | |
1e6feb95 VZ |
85 | }; |
86 | ||
87 | // ---------------------------------------------------------------------------- | |
88 | // wxAutoScrollTimer: the timer used to generate a stream of scroll events when | |
89 | // a captured mouse is held outside the window | |
90 | // ---------------------------------------------------------------------------- | |
91 | ||
92 | class wxAutoScrollTimer : public wxTimer | |
93 | { | |
94 | public: | |
95 | wxAutoScrollTimer(wxWindow *winToScroll, wxScrollHelper *scroll, | |
96 | wxEventType eventTypeToSend, | |
97 | int pos, int orient); | |
98 | ||
99 | virtual void Notify(); | |
100 | ||
101 | private: | |
102 | wxWindow *m_win; | |
103 | wxScrollHelper *m_scrollHelper; | |
104 | wxEventType m_eventType; | |
105 | int m_pos, | |
106 | m_orient; | |
107 | }; | |
d80cd92a VZ |
108 | |
109 | // ============================================================================ | |
110 | // implementation | |
111 | // ============================================================================ | |
112 | ||
113 | // ---------------------------------------------------------------------------- | |
1e6feb95 | 114 | // wxAutoScrollTimer |
d80cd92a VZ |
115 | // ---------------------------------------------------------------------------- |
116 | ||
1e6feb95 VZ |
117 | wxAutoScrollTimer::wxAutoScrollTimer(wxWindow *winToScroll, |
118 | wxScrollHelper *scroll, | |
119 | wxEventType eventTypeToSend, | |
120 | int pos, int orient) | |
c801d85f | 121 | { |
1e6feb95 VZ |
122 | m_win = winToScroll; |
123 | m_scrollHelper = scroll; | |
124 | m_eventType = eventTypeToSend; | |
125 | m_pos = pos; | |
126 | m_orient = orient; | |
c801d85f KB |
127 | } |
128 | ||
1e6feb95 | 129 | void wxAutoScrollTimer::Notify() |
c801d85f | 130 | { |
1e6feb95 VZ |
131 | // only do all this as long as the window is capturing the mouse |
132 | if ( wxWindow::GetCapture() != m_win ) | |
133 | { | |
134 | Stop(); | |
135 | } | |
136 | else // we still capture the mouse, continue generating events | |
137 | { | |
138 | // first scroll the window if we are allowed to do it | |
139 | wxScrollWinEvent event1(m_eventType, m_pos, m_orient); | |
140 | event1.SetEventObject(m_win); | |
141 | if ( m_scrollHelper->SendAutoScrollEvents(event1) && | |
142 | m_win->GetEventHandler()->ProcessEvent(event1) ) | |
143 | { | |
144 | // and then send a pseudo mouse-move event to refresh the selection | |
145 | wxMouseEvent event2(wxEVT_MOTION); | |
146 | wxGetMousePosition(&event2.m_x, &event2.m_y); | |
147 | ||
148 | // the mouse event coordinates should be client, not screen as | |
149 | // returned by wxGetMousePosition | |
150 | wxWindow *parentTop = m_win; | |
151 | while ( parentTop->GetParent() ) | |
152 | parentTop = parentTop->GetParent(); | |
153 | wxPoint ptOrig = parentTop->GetPosition(); | |
154 | event2.m_x -= ptOrig.x; | |
155 | event2.m_y -= ptOrig.y; | |
156 | ||
157 | event2.SetEventObject(m_win); | |
158 | ||
159 | // FIXME: we don't fill in the other members - ok? | |
160 | ||
161 | m_win->GetEventHandler()->ProcessEvent(event2); | |
162 | } | |
163 | else // can't scroll further, stop | |
164 | { | |
165 | Stop(); | |
166 | } | |
167 | } | |
168 | } | |
169 | ||
170 | // ---------------------------------------------------------------------------- | |
171 | // wxScrollHelperEvtHandler | |
172 | // ---------------------------------------------------------------------------- | |
173 | ||
174 | bool wxScrollHelperEvtHandler::ProcessEvent(wxEvent& event) | |
175 | { | |
9a268018 | 176 | wxEventType evType = event.GetEventType(); |
2feed004 | 177 | |
349efbaa VZ |
178 | // the explanation of wxEVT_PAINT processing hack: for historic reasons |
179 | // there are 2 ways to process this event in classes deriving from | |
180 | // wxScrolledWindow. The user code may | |
181 | // | |
182 | // 1. override wxScrolledWindow::OnDraw(dc) | |
183 | // 2. define its own OnPaint() handler | |
184 | // | |
185 | // In addition, in wxUniversal wxWindow defines OnPaint() itself and | |
186 | // always processes the draw event, so we can't just try the window | |
187 | // OnPaint() first and call our HandleOnPaint() if it doesn't process it | |
188 | // (the latter would never be called in wxUniversal). | |
189 | // | |
190 | // So the solution is to have a flag telling us whether the user code drew | |
191 | // anything in the window. We set it to true here but reset it to false in | |
192 | // wxScrolledWindow::OnPaint() handler (which wouldn't be called if the | |
193 | // user code defined OnPaint() in the derived class) | |
194 | m_hasDrawnWindow = TRUE; | |
195 | ||
ff186591 VZ |
196 | // pass it on to the real handler |
197 | bool processed = wxEvtHandler::ProcessEvent(event); | |
198 | ||
199 | // always process the size events ourselves, even if the user code handles | |
200 | // them as well, as we need to AdjustScrollbars() | |
201 | // | |
202 | // NB: it is important to do it after processing the event in the normal | |
203 | // way as HandleOnSize() may generate a wxEVT_SIZE itself if the | |
204 | // scrollbar[s] (dis)appear and it should be seen by the user code | |
205 | // after this one | |
206 | if ( evType == wxEVT_SIZE ) | |
207 | { | |
208 | m_scrollHelper->HandleOnSize((wxSizeEvent &)event); | |
209 | ||
210 | return TRUE; | |
211 | } | |
212 | ||
213 | if ( processed ) | |
349efbaa VZ |
214 | { |
215 | // normally, nothing more to do here - except if it was a paint event | |
216 | // which wasn't really processed, then we'll try to call our | |
217 | // OnDraw() below (from HandleOnPaint) | |
993cfa87 | 218 | if ( m_hasDrawnWindow ) |
349efbaa VZ |
219 | { |
220 | return TRUE; | |
221 | } | |
222 | } | |
2feed004 | 223 | |
1e6feb95 VZ |
224 | // reset the skipped flag to FALSE as it might have been set to TRUE in |
225 | // ProcessEvent() above | |
226 | event.Skip(FALSE); | |
227 | ||
e421922f VZ |
228 | if ( evType == wxEVT_PAINT ) |
229 | { | |
230 | m_scrollHelper->HandleOnPaint((wxPaintEvent &)event); | |
231 | return TRUE; | |
232 | } | |
1e6feb95 | 233 | |
e421922f VZ |
234 | if ( evType == wxEVT_SCROLLWIN_TOP || |
235 | evType == wxEVT_SCROLLWIN_BOTTOM || | |
236 | evType == wxEVT_SCROLLWIN_LINEUP || | |
237 | evType == wxEVT_SCROLLWIN_LINEDOWN || | |
238 | evType == wxEVT_SCROLLWIN_PAGEUP || | |
239 | evType == wxEVT_SCROLLWIN_PAGEDOWN || | |
240 | evType == wxEVT_SCROLLWIN_THUMBTRACK || | |
241 | evType == wxEVT_SCROLLWIN_THUMBRELEASE ) | |
242 | { | |
243 | m_scrollHelper->HandleOnScroll((wxScrollWinEvent &)event); | |
1e6feb95 | 244 | return !event.GetSkipped(); |
e421922f | 245 | } |
1e6feb95 | 246 | |
e421922f VZ |
247 | if ( evType == wxEVT_ENTER_WINDOW ) |
248 | { | |
249 | m_scrollHelper->HandleOnMouseEnter((wxMouseEvent &)event); | |
250 | } | |
251 | else if ( evType == wxEVT_LEAVE_WINDOW ) | |
252 | { | |
253 | m_scrollHelper->HandleOnMouseLeave((wxMouseEvent &)event); | |
254 | } | |
255 | #if wxUSE_MOUSEWHEEL | |
256 | else if ( evType == wxEVT_MOUSEWHEEL ) | |
257 | { | |
258 | m_scrollHelper->HandleOnMouseWheel((wxMouseEvent &)event); | |
259 | } | |
260 | #endif // wxUSE_MOUSEWHEEL | |
e421922f VZ |
261 | else if ( evType == wxEVT_CHAR ) |
262 | { | |
263 | m_scrollHelper->HandleOnChar((wxKeyEvent &)event); | |
264 | return !event.GetSkipped(); | |
1e6feb95 VZ |
265 | } |
266 | ||
267 | return FALSE; | |
268 | } | |
269 | ||
270 | // ---------------------------------------------------------------------------- | |
271 | // wxScrollHelper construction | |
272 | // ---------------------------------------------------------------------------- | |
273 | ||
274 | wxScrollHelper::wxScrollHelper(wxWindow *win) | |
275 | { | |
276 | m_xScrollPixelsPerLine = | |
277 | m_yScrollPixelsPerLine = | |
278 | m_xScrollPosition = | |
279 | m_yScrollPosition = | |
280 | m_xScrollLines = | |
281 | m_yScrollLines = | |
282 | m_xScrollLinesPerPage = | |
139adb6a | 283 | m_yScrollLinesPerPage = 0; |
1e6feb95 VZ |
284 | |
285 | m_xScrollingEnabled = | |
286 | m_yScrollingEnabled = TRUE; | |
287 | ||
288 | m_scaleX = | |
139adb6a | 289 | m_scaleY = 1.0; |
24ce4c18 | 290 | #if wxUSE_MOUSEWHEEL |
d2c52078 | 291 | m_wheelRotation = 0; |
24ce4c18 | 292 | #endif |
a58a12e9 | 293 | |
1e6feb95 VZ |
294 | m_win = |
295 | m_targetWindow = (wxWindow *)NULL; | |
139adb6a | 296 | |
1e6feb95 | 297 | m_timerAutoScroll = (wxTimer *)NULL; |
d7da9756 | 298 | |
349efbaa VZ |
299 | m_handler = NULL; |
300 | ||
1e6feb95 VZ |
301 | if ( win ) |
302 | SetWindow(win); | |
303 | } | |
d7da9756 | 304 | |
1e6feb95 | 305 | wxScrollHelper::~wxScrollHelper() |
d80cd92a | 306 | { |
1e6feb95 VZ |
307 | StopAutoScrolling(); |
308 | ||
349efbaa | 309 | DeleteEvtHandler(); |
d80cd92a VZ |
310 | } |
311 | ||
312 | // ---------------------------------------------------------------------------- | |
313 | // setting scrolling parameters | |
314 | // ---------------------------------------------------------------------------- | |
315 | ||
1e6feb95 VZ |
316 | void wxScrollHelper::SetScrollbars(int pixelsPerUnitX, |
317 | int pixelsPerUnitY, | |
318 | int noUnitsX, | |
319 | int noUnitsY, | |
320 | int xPos, | |
321 | int yPos, | |
322 | bool noRefresh) | |
c801d85f | 323 | { |
b0486e0d SN |
324 | int xpos, ypos; |
325 | ||
326 | CalcUnscrolledPosition(xPos, yPos, &xpos, &ypos); | |
139adb6a RR |
327 | bool do_refresh = |
328 | ( | |
c801d85f | 329 | (noUnitsX != 0 && m_xScrollLines == 0) || |
566d84a7 | 330 | (noUnitsX < m_xScrollLines && xpos > pixelsPerUnitX * noUnitsX) || |
b0486e0d | 331 | |
c801d85f | 332 | (noUnitsY != 0 && m_yScrollLines == 0) || |
566d84a7 | 333 | (noUnitsY < m_yScrollLines && ypos > pixelsPerUnitY * noUnitsY) || |
c801d85f | 334 | (xPos != m_xScrollPosition) || |
b0486e0d | 335 | (yPos != m_yScrollPosition) |
139adb6a | 336 | ); |
a58a12e9 | 337 | |
139adb6a RR |
338 | m_xScrollPixelsPerLine = pixelsPerUnitX; |
339 | m_yScrollPixelsPerLine = pixelsPerUnitY; | |
340 | m_xScrollPosition = xPos; | |
341 | m_yScrollPosition = yPos; | |
a91b47e8 | 342 | |
2b5f62a0 VZ |
343 | // For better backward compatibility we set persisting limits |
344 | // here not just the size. It makes SetScrollbars 'sticky' | |
345 | // emulating the old non-autoscroll behaviour. | |
346 | ||
566d84a7 | 347 | m_targetWindow->SetVirtualSizeHints( noUnitsX * pixelsPerUnitX, noUnitsY * pixelsPerUnitY ); |
a58a12e9 | 348 | |
2b5f62a0 VZ |
349 | // The above should arguably be deprecated, this however we still need. |
350 | ||
351 | m_targetWindow->SetVirtualSize( noUnitsX * pixelsPerUnitX, noUnitsY * pixelsPerUnitY ); | |
dc429f89 | 352 | |
a58a12e9 | 353 | if (do_refresh && !noRefresh) |
1e6feb95 | 354 | m_targetWindow->Refresh(TRUE, GetRect()); |
a58a12e9 | 355 | |
7c74e7fe | 356 | #ifdef __WXMAC__ |
d80cd92a | 357 | m_targetWindow->MacUpdateImmediately() ; |
c801d85f KB |
358 | #endif |
359 | } | |
360 | ||
d80cd92a | 361 | // ---------------------------------------------------------------------------- |
af4088f1 | 362 | // [target] window handling |
d80cd92a | 363 | // ---------------------------------------------------------------------------- |
ecab4dba | 364 | |
349efbaa | 365 | void wxScrollHelper::DeleteEvtHandler() |
ecab4dba | 366 | { |
248d771c VZ |
367 | // search for m_handler in the handler list |
368 | if ( m_win && m_handler ) | |
349efbaa | 369 | { |
74f6bbf9 | 370 | if ( m_win->RemoveEventHandler(m_handler) ) |
248d771c | 371 | { |
74f6bbf9 | 372 | delete m_handler; |
248d771c | 373 | } |
74f6bbf9 VZ |
374 | //else: something is very wrong, so better [maybe] leak memory than |
375 | // risk a crash because of double deletion | |
248d771c | 376 | |
74f6bbf9 | 377 | m_handler = NULL; |
349efbaa VZ |
378 | } |
379 | } | |
380 | ||
381 | void wxScrollHelper::SetWindow(wxWindow *win) | |
382 | { | |
383 | wxCHECK_RET( win, _T("wxScrollHelper needs a window to scroll") ); | |
384 | ||
385 | m_win = win; | |
386 | ||
af4088f1 VZ |
387 | // by default, the associated window is also the target window |
388 | DoSetTargetWindow(win); | |
349efbaa VZ |
389 | } |
390 | ||
af4088f1 | 391 | void wxScrollHelper::DoSetTargetWindow(wxWindow *target) |
349efbaa | 392 | { |
ecab4dba | 393 | m_targetWindow = target; |
349efbaa VZ |
394 | |
395 | // install the event handler which will intercept the events we're | |
af4088f1 VZ |
396 | // interested in (but only do it for our real window, not the target window |
397 | // which we scroll - we don't need to hijack its events) | |
398 | if ( m_targetWindow == m_win ) | |
13ff9344 | 399 | { |
248d771c VZ |
400 | // if we already have a handler, delete it first |
401 | DeleteEvtHandler(); | |
402 | ||
13ff9344 JS |
403 | m_handler = new wxScrollHelperEvtHandler(this); |
404 | m_targetWindow->PushEventHandler(m_handler); | |
405 | } | |
349efbaa VZ |
406 | } |
407 | ||
af4088f1 | 408 | void wxScrollHelper::SetTargetWindow(wxWindow *target) |
349efbaa VZ |
409 | { |
410 | wxCHECK_RET( target, wxT("target window must not be NULL") ); | |
411 | ||
412 | if ( target == m_targetWindow ) | |
413 | return; | |
414 | ||
af4088f1 | 415 | DoSetTargetWindow(target); |
ecab4dba RR |
416 | } |
417 | ||
1e6feb95 | 418 | wxWindow *wxScrollHelper::GetTargetWindow() const |
ecab4dba RR |
419 | { |
420 | return m_targetWindow; | |
421 | } | |
422 | ||
d80cd92a VZ |
423 | // ---------------------------------------------------------------------------- |
424 | // scrolling implementation itself | |
425 | // ---------------------------------------------------------------------------- | |
426 | ||
1e6feb95 | 427 | void wxScrollHelper::HandleOnScroll(wxScrollWinEvent& event) |
c801d85f | 428 | { |
139adb6a | 429 | int nScrollInc = CalcScrollInc(event); |
1e6feb95 | 430 | if ( nScrollInc == 0 ) |
139adb6a | 431 | { |
1e6feb95 VZ |
432 | // can't scroll further |
433 | event.Skip(); | |
434 | ||
435 | return; | |
139adb6a | 436 | } |
c801d85f | 437 | |
1e6feb95 | 438 | int orient = event.GetOrientation(); |
139adb6a RR |
439 | if (orient == wxHORIZONTAL) |
440 | { | |
441 | m_xScrollPosition += nScrollInc; | |
5f3286d1 | 442 | m_win->SetScrollPos(wxHORIZONTAL, m_xScrollPosition); |
139adb6a | 443 | } |
c801d85f | 444 | else |
139adb6a RR |
445 | { |
446 | m_yScrollPosition += nScrollInc; | |
5f3286d1 | 447 | m_win->SetScrollPos(wxVERTICAL, m_yScrollPosition); |
139adb6a | 448 | } |
a58a12e9 | 449 | |
1e6feb95 VZ |
450 | bool needsRefresh = FALSE; |
451 | int dx = 0, | |
452 | dy = 0; | |
139adb6a RR |
453 | if (orient == wxHORIZONTAL) |
454 | { | |
1e6feb95 VZ |
455 | if ( m_xScrollingEnabled ) |
456 | { | |
457 | dx = -m_xScrollPixelsPerLine * nScrollInc; | |
458 | } | |
139adb6a | 459 | else |
1e6feb95 VZ |
460 | { |
461 | needsRefresh = TRUE; | |
462 | } | |
139adb6a | 463 | } |
c801d85f | 464 | else |
139adb6a | 465 | { |
1e6feb95 VZ |
466 | if ( m_yScrollingEnabled ) |
467 | { | |
468 | dy = -m_yScrollPixelsPerLine * nScrollInc; | |
469 | } | |
139adb6a | 470 | else |
1e6feb95 VZ |
471 | { |
472 | needsRefresh = TRUE; | |
473 | } | |
474 | } | |
475 | ||
476 | if ( needsRefresh ) | |
477 | { | |
478 | m_targetWindow->Refresh(TRUE, GetRect()); | |
479 | } | |
480 | else | |
481 | { | |
482 | m_targetWindow->ScrollWindow(dx, dy, GetRect()); | |
3d2b9c20 | 483 | } |
1e6feb95 | 484 | |
7c74e7fe | 485 | #ifdef __WXMAC__ |
d80cd92a | 486 | m_targetWindow->MacUpdateImmediately() ; |
7c74e7fe | 487 | #endif |
c801d85f KB |
488 | } |
489 | ||
1e6feb95 | 490 | int wxScrollHelper::CalcScrollInc(wxScrollWinEvent& event) |
c801d85f | 491 | { |
ecab4dba RR |
492 | int pos = event.GetPosition(); |
493 | int orient = event.GetOrientation(); | |
c801d85f | 494 | |
ecab4dba | 495 | int nScrollInc = 0; |
1a8caf94 | 496 | if (event.GetEventType() == wxEVT_SCROLLWIN_TOP) |
c801d85f | 497 | { |
ecab4dba RR |
498 | if (orient == wxHORIZONTAL) |
499 | nScrollInc = - m_xScrollPosition; | |
500 | else | |
501 | nScrollInc = - m_yScrollPosition; | |
1a8caf94 RR |
502 | } else |
503 | if (event.GetEventType() == wxEVT_SCROLLWIN_BOTTOM) | |
504 | { | |
ecab4dba RR |
505 | if (orient == wxHORIZONTAL) |
506 | nScrollInc = m_xScrollLines - m_xScrollPosition; | |
507 | else | |
508 | nScrollInc = m_yScrollLines - m_yScrollPosition; | |
1a8caf94 RR |
509 | } else |
510 | if (event.GetEventType() == wxEVT_SCROLLWIN_LINEUP) | |
511 | { | |
ecab4dba | 512 | nScrollInc = -1; |
1a8caf94 RR |
513 | } else |
514 | if (event.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN) | |
515 | { | |
ecab4dba | 516 | nScrollInc = 1; |
1a8caf94 RR |
517 | } else |
518 | if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEUP) | |
519 | { | |
ecab4dba RR |
520 | if (orient == wxHORIZONTAL) |
521 | nScrollInc = -GetScrollPageSize(wxHORIZONTAL); | |
522 | else | |
523 | nScrollInc = -GetScrollPageSize(wxVERTICAL); | |
1a8caf94 RR |
524 | } else |
525 | if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN) | |
526 | { | |
ecab4dba RR |
527 | if (orient == wxHORIZONTAL) |
528 | nScrollInc = GetScrollPageSize(wxHORIZONTAL); | |
529 | else | |
530 | nScrollInc = GetScrollPageSize(wxVERTICAL); | |
1a8caf94 RR |
531 | } else |
532 | if ((event.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK) || | |
533 | (event.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE)) | |
534 | { | |
ecab4dba RR |
535 | if (orient == wxHORIZONTAL) |
536 | nScrollInc = pos - m_xScrollPosition; | |
537 | else | |
538 | nScrollInc = pos - m_yScrollPosition; | |
c801d85f | 539 | } |
88150e60 | 540 | |
ecab4dba RR |
541 | if (orient == wxHORIZONTAL) |
542 | { | |
a58a12e9 | 543 | if (m_xScrollPixelsPerLine > 0) |
ecab4dba RR |
544 | { |
545 | int w, h; | |
1e6feb95 | 546 | GetTargetSize(&w, &h); |
ecab4dba RR |
547 | |
548 | int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine; | |
549 | int noPositions = (int) ( ((nMaxWidth - w)/(double)m_xScrollPixelsPerLine) + 0.5 ); | |
550 | if (noPositions < 0) | |
d80cd92a | 551 | noPositions = 0; |
ecab4dba RR |
552 | |
553 | if ( (m_xScrollPosition + nScrollInc) < 0 ) | |
d80cd92a | 554 | nScrollInc = -m_xScrollPosition; // As -ve as we can go |
ecab4dba | 555 | else if ( (m_xScrollPosition + nScrollInc) > noPositions ) |
d80cd92a | 556 | nScrollInc = noPositions - m_xScrollPosition; // As +ve as we can go |
ecab4dba RR |
557 | } |
558 | else | |
1e6feb95 | 559 | m_targetWindow->Refresh(TRUE, GetRect()); |
9d9355c6 VZ |
560 | } |
561 | else | |
ecab4dba | 562 | { |
a58a12e9 | 563 | if (m_yScrollPixelsPerLine > 0) |
d80cd92a | 564 | { |
ecab4dba | 565 | int w, h; |
1e6feb95 | 566 | GetTargetSize(&w, &h); |
a58a12e9 | 567 | |
ecab4dba RR |
568 | int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine; |
569 | int noPositions = (int) ( ((nMaxHeight - h)/(double)m_yScrollPixelsPerLine) + 0.5 ); | |
570 | if (noPositions < 0) | |
d80cd92a | 571 | noPositions = 0; |
a58a12e9 | 572 | |
ecab4dba | 573 | if ( (m_yScrollPosition + nScrollInc) < 0 ) |
d80cd92a | 574 | nScrollInc = -m_yScrollPosition; // As -ve as we can go |
ecab4dba | 575 | else if ( (m_yScrollPosition + nScrollInc) > noPositions ) |
d80cd92a | 576 | nScrollInc = noPositions - m_yScrollPosition; // As +ve as we can go |
ecab4dba RR |
577 | } |
578 | else | |
1e6feb95 | 579 | m_targetWindow->Refresh(TRUE, GetRect()); |
9d9355c6 | 580 | } |
9d9355c6 | 581 | |
ecab4dba | 582 | return nScrollInc; |
c801d85f KB |
583 | } |
584 | ||
585 | // Adjust the scrollbars - new version. | |
1e6feb95 | 586 | void wxScrollHelper::AdjustScrollbars() |
c801d85f | 587 | { |
aeb313f3 SC |
588 | #ifdef __WXMAC__ |
589 | m_targetWindow->MacUpdateImmediately(); | |
590 | #endif | |
591 | ||
566d84a7 RL |
592 | int w = 0, h = 0; |
593 | int oldw, oldh; | |
a58a12e9 | 594 | |
27d029c7 RR |
595 | int oldXScroll = m_xScrollPosition; |
596 | int oldYScroll = m_yScrollPosition; | |
c801d85f | 597 | |
566d84a7 RL |
598 | do { |
599 | GetTargetSize(&w, 0); | |
c801d85f | 600 | |
566d84a7 RL |
601 | if (m_xScrollPixelsPerLine == 0) |
602 | { | |
603 | m_xScrollLines = 0; | |
604 | m_xScrollPosition = 0; | |
605 | m_win->SetScrollbar (wxHORIZONTAL, 0, 0, 0, FALSE); | |
606 | } | |
607 | else | |
608 | { | |
609 | m_xScrollLines = m_targetWindow->GetVirtualSize().GetWidth() / m_xScrollPixelsPerLine; | |
610 | ||
611 | // Calculate page size i.e. number of scroll units you get on the | |
612 | // current client window | |
613 | int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 ); | |
614 | if (noPagePositions < 1) noPagePositions = 1; | |
615 | if ( noPagePositions > m_xScrollLines ) | |
616 | noPagePositions = m_xScrollLines; | |
617 | ||
618 | // Correct position if greater than extent of canvas minus | |
619 | // the visible portion of it or if below zero | |
620 | m_xScrollPosition = wxMin( m_xScrollLines - noPagePositions, m_xScrollPosition); | |
621 | m_xScrollPosition = wxMax( 0, m_xScrollPosition ); | |
622 | ||
623 | m_win->SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, m_xScrollLines); | |
624 | // The amount by which we scroll when paging | |
625 | SetScrollPageSize(wxHORIZONTAL, noPagePositions); | |
626 | } | |
c801d85f | 627 | |
566d84a7 | 628 | GetTargetSize(0, &h); |
a58a12e9 | 629 | |
566d84a7 RL |
630 | if (m_yScrollPixelsPerLine == 0) |
631 | { | |
632 | m_yScrollLines = 0; | |
633 | m_yScrollPosition = 0; | |
634 | m_win->SetScrollbar (wxVERTICAL, 0, 0, 0, FALSE); | |
635 | } | |
636 | else | |
637 | { | |
638 | m_yScrollLines = m_targetWindow->GetVirtualSize().GetHeight() / m_yScrollPixelsPerLine; | |
639 | ||
640 | // Calculate page size i.e. number of scroll units you get on the | |
641 | // current client window | |
642 | int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 ); | |
643 | if (noPagePositions < 1) noPagePositions = 1; | |
644 | if ( noPagePositions > m_yScrollLines ) | |
645 | noPagePositions = m_yScrollLines; | |
646 | ||
647 | // Correct position if greater than extent of canvas minus | |
648 | // the visible portion of it or if below zero | |
649 | m_yScrollPosition = wxMin( m_yScrollLines - noPagePositions, m_yScrollPosition ); | |
650 | m_yScrollPosition = wxMax( 0, m_yScrollPosition ); | |
651 | ||
652 | m_win->SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, m_yScrollLines); | |
653 | // The amount by which we scroll when paging | |
654 | SetScrollPageSize(wxVERTICAL, noPagePositions); | |
655 | } | |
c801d85f | 656 | |
566d84a7 | 657 | // If a scrollbar (dis)appeared as a result of this, adjust them again. |
139adb6a | 658 | |
566d84a7 RL |
659 | oldw = w; |
660 | oldh = h; | |
661 | ||
662 | GetTargetSize( &w, &h ); | |
663 | } while ( w != oldw && h != oldh ); | |
664 | ||
665 | #ifdef __WXMOTIF__ | |
666 | // Sorry, some Motif-specific code to implement a backing pixmap | |
667 | // for the wxRETAINED style. Implementing a backing store can't | |
668 | // be entirely generic because it relies on the wxWindowDC implementation | |
669 | // to duplicate X drawing calls for the backing pixmap. | |
670 | ||
671 | if ( m_targetWindow->GetWindowStyle() & wxRETAINED ) | |
139adb6a | 672 | { |
566d84a7 RL |
673 | Display* dpy = XtDisplay((Widget)m_targetWindow->GetMainWidget()); |
674 | ||
675 | int totalPixelWidth = m_xScrollLines * m_xScrollPixelsPerLine; | |
676 | int totalPixelHeight = m_yScrollLines * m_yScrollPixelsPerLine; | |
677 | if (m_targetWindow->GetBackingPixmap() && | |
678 | !((m_targetWindow->GetPixmapWidth() == totalPixelWidth) && | |
679 | (m_targetWindow->GetPixmapHeight() == totalPixelHeight))) | |
680 | { | |
681 | XFreePixmap (dpy, (Pixmap) m_targetWindow->GetBackingPixmap()); | |
682 | m_targetWindow->SetBackingPixmap((WXPixmap) 0); | |
683 | } | |
684 | ||
685 | if (!m_targetWindow->GetBackingPixmap() && | |
9b66c26a | 686 | (m_xScrollLines != 0) && (m_yScrollLines != 0)) |
566d84a7 RL |
687 | { |
688 | int depth = wxDisplayDepth(); | |
689 | m_targetWindow->SetPixmapWidth(totalPixelWidth); | |
690 | m_targetWindow->SetPixmapHeight(totalPixelHeight); | |
691 | m_targetWindow->SetBackingPixmap((WXPixmap) XCreatePixmap (dpy, RootWindow (dpy, DefaultScreen (dpy)), | |
692 | m_targetWindow->GetPixmapWidth(), m_targetWindow->GetPixmapHeight(), depth)); | |
693 | } | |
694 | ||
139adb6a | 695 | } |
566d84a7 | 696 | #endif // Motif |
a58a12e9 | 697 | |
27d029c7 RR |
698 | if (oldXScroll != m_xScrollPosition) |
699 | { | |
700 | if (m_xScrollingEnabled) | |
566d84a7 | 701 | m_targetWindow->ScrollWindow( m_xScrollPixelsPerLine * (oldXScroll - m_xScrollPosition), 0, |
1e6feb95 | 702 | GetRect() ); |
27d029c7 | 703 | else |
1e6feb95 | 704 | m_targetWindow->Refresh(TRUE, GetRect()); |
27d029c7 | 705 | } |
a58a12e9 | 706 | |
27d029c7 RR |
707 | if (oldYScroll != m_yScrollPosition) |
708 | { | |
709 | if (m_yScrollingEnabled) | |
1e6feb95 VZ |
710 | m_targetWindow->ScrollWindow( 0, m_yScrollPixelsPerLine * (oldYScroll-m_yScrollPosition), |
711 | GetRect() ); | |
27d029c7 | 712 | else |
1e6feb95 | 713 | m_targetWindow->Refresh(TRUE, GetRect()); |
27d029c7 | 714 | } |
aeb313f3 SC |
715 | |
716 | #ifdef __WXMAC__ | |
717 | m_targetWindow->MacUpdateImmediately(); | |
718 | #endif | |
c801d85f KB |
719 | } |
720 | ||
1e6feb95 | 721 | void wxScrollHelper::DoPrepareDC(wxDC& dc) |
c801d85f | 722 | { |
1e6feb95 VZ |
723 | wxPoint pt = dc.GetDeviceOrigin(); |
724 | dc.SetDeviceOrigin( pt.x - m_xScrollPosition * m_xScrollPixelsPerLine, | |
725 | pt.y - m_yScrollPosition * m_yScrollPixelsPerLine ); | |
139adb6a | 726 | dc.SetUserScale( m_scaleX, m_scaleY ); |
c801d85f KB |
727 | } |
728 | ||
566d84a7 RL |
729 | void wxScrollHelper::SetScrollRate( int xstep, int ystep ) |
730 | { | |
731 | int old_x = m_xScrollPixelsPerLine * m_xScrollPosition; | |
732 | int old_y = m_yScrollPixelsPerLine * m_yScrollPosition; | |
733 | ||
734 | m_xScrollPixelsPerLine = xstep; | |
735 | m_yScrollPixelsPerLine = ystep; | |
736 | ||
737 | int new_x = m_xScrollPixelsPerLine * m_xScrollPosition; | |
738 | int new_y = m_yScrollPixelsPerLine * m_yScrollPosition; | |
739 | ||
740 | m_win->SetScrollPos( wxHORIZONTAL, m_xScrollPosition ); | |
741 | m_win->SetScrollPos( wxVERTICAL, m_yScrollPosition ); | |
742 | m_targetWindow->ScrollWindow( old_x - new_x, old_y - new_y ); | |
743 | ||
744 | AdjustScrollbars(); | |
745 | } | |
746 | ||
1e6feb95 | 747 | void wxScrollHelper::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const |
c801d85f | 748 | { |
a0bc2c1d VZ |
749 | if ( x_unit ) |
750 | *x_unit = m_xScrollPixelsPerLine; | |
751 | if ( y_unit ) | |
752 | *y_unit = m_yScrollPixelsPerLine; | |
c801d85f KB |
753 | } |
754 | ||
1e6feb95 | 755 | int wxScrollHelper::GetScrollPageSize(int orient) const |
c801d85f KB |
756 | { |
757 | if ( orient == wxHORIZONTAL ) | |
758 | return m_xScrollLinesPerPage; | |
759 | else | |
760 | return m_yScrollLinesPerPage; | |
761 | } | |
762 | ||
1e6feb95 | 763 | void wxScrollHelper::SetScrollPageSize(int orient, int pageSize) |
c801d85f KB |
764 | { |
765 | if ( orient == wxHORIZONTAL ) | |
766 | m_xScrollLinesPerPage = pageSize; | |
767 | else | |
768 | m_yScrollLinesPerPage = pageSize; | |
769 | } | |
770 | ||
771 | /* | |
772 | * Scroll to given position (scroll position, not pixel position) | |
773 | */ | |
1e6feb95 | 774 | void wxScrollHelper::Scroll( int x_pos, int y_pos ) |
c801d85f | 775 | { |
8b089c5e JS |
776 | if (!m_targetWindow) |
777 | return; | |
778 | ||
a58a12e9 | 779 | if (((x_pos == -1) || (x_pos == m_xScrollPosition)) && |
139adb6a | 780 | ((y_pos == -1) || (y_pos == m_yScrollPosition))) return; |
a58a12e9 | 781 | |
aeb313f3 SC |
782 | #ifdef __WXMAC__ |
783 | m_targetWindow->MacUpdateImmediately(); | |
784 | #endif | |
785 | ||
139adb6a | 786 | int w, h; |
1e6feb95 | 787 | GetTargetSize(&w, &h); |
c801d85f | 788 | |
8775b357 | 789 | if ((x_pos != -1) && (m_xScrollPixelsPerLine)) |
c801d85f | 790 | { |
ed673c6a | 791 | int old_x = m_xScrollPosition; |
139adb6a | 792 | m_xScrollPosition = x_pos; |
a58a12e9 | 793 | |
3d2b9c20 RR |
794 | // Calculate page size i.e. number of scroll units you get on the |
795 | // current client window | |
ecab4dba | 796 | int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 ); |
139adb6a RR |
797 | if (noPagePositions < 1) noPagePositions = 1; |
798 | ||
799 | // Correct position if greater than extent of canvas minus | |
3d2b9c20 | 800 | // the visible portion of it or if below zero |
139adb6a RR |
801 | m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition ); |
802 | m_xScrollPosition = wxMax( 0, m_xScrollPosition ); | |
a58a12e9 | 803 | |
f6bcfd97 | 804 | if (old_x != m_xScrollPosition) { |
5f3286d1 | 805 | m_win->SetScrollPos( wxHORIZONTAL, m_xScrollPosition ); |
1e6feb95 VZ |
806 | m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0, |
807 | GetRect() ); | |
f6bcfd97 | 808 | } |
c801d85f | 809 | } |
8775b357 | 810 | if ((y_pos != -1) && (m_yScrollPixelsPerLine)) |
c801d85f | 811 | { |
ed673c6a | 812 | int old_y = m_yScrollPosition; |
139adb6a | 813 | m_yScrollPosition = y_pos; |
a58a12e9 | 814 | |
3d2b9c20 RR |
815 | // Calculate page size i.e. number of scroll units you get on the |
816 | // current client window | |
ecab4dba | 817 | int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 ); |
139adb6a RR |
818 | if (noPagePositions < 1) noPagePositions = 1; |
819 | ||
820 | // Correct position if greater than extent of canvas minus | |
3d2b9c20 | 821 | // the visible portion of it or if below zero |
139adb6a RR |
822 | m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition ); |
823 | m_yScrollPosition = wxMax( 0, m_yScrollPosition ); | |
d2c52078 | 824 | |
f6bcfd97 | 825 | if (old_y != m_yScrollPosition) { |
5f3286d1 | 826 | m_win->SetScrollPos( wxVERTICAL, m_yScrollPosition ); |
1e6feb95 VZ |
827 | m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine, |
828 | GetRect() ); | |
f6bcfd97 | 829 | } |
c801d85f | 830 | } |
a58a12e9 | 831 | |
7c74e7fe | 832 | #ifdef __WXMAC__ |
3d2b9c20 | 833 | m_targetWindow->MacUpdateImmediately(); |
7c74e7fe | 834 | #endif |
aeb313f3 | 835 | |
c801d85f KB |
836 | } |
837 | ||
1e6feb95 | 838 | void wxScrollHelper::EnableScrolling (bool x_scroll, bool y_scroll) |
c801d85f | 839 | { |
139adb6a RR |
840 | m_xScrollingEnabled = x_scroll; |
841 | m_yScrollingEnabled = y_scroll; | |
c801d85f KB |
842 | } |
843 | ||
c801d85f | 844 | // Where the current view starts from |
1e6feb95 | 845 | void wxScrollHelper::GetViewStart (int *x, int *y) const |
c801d85f | 846 | { |
a0bc2c1d VZ |
847 | if ( x ) |
848 | *x = m_xScrollPosition; | |
849 | if ( y ) | |
850 | *y = m_yScrollPosition; | |
c801d85f KB |
851 | } |
852 | ||
8c2f3797 | 853 | void wxScrollHelper::DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const |
c801d85f | 854 | { |
a0bc2c1d VZ |
855 | if ( xx ) |
856 | *xx = x - m_xScrollPosition * m_xScrollPixelsPerLine; | |
857 | if ( yy ) | |
858 | *yy = y - m_yScrollPosition * m_yScrollPixelsPerLine; | |
c801d85f KB |
859 | } |
860 | ||
8c2f3797 | 861 | void wxScrollHelper::DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) const |
c801d85f | 862 | { |
a0bc2c1d VZ |
863 | if ( xx ) |
864 | *xx = x + m_xScrollPosition * m_xScrollPixelsPerLine; | |
865 | if ( yy ) | |
866 | *yy = y + m_yScrollPosition * m_yScrollPixelsPerLine; | |
c801d85f | 867 | } |
d80cd92a VZ |
868 | |
869 | // ---------------------------------------------------------------------------- | |
870 | // event handlers | |
871 | // ---------------------------------------------------------------------------- | |
872 | ||
873 | // Default OnSize resets scrollbars, if any | |
1e6feb95 | 874 | void wxScrollHelper::HandleOnSize(wxSizeEvent& WXUNUSED(event)) |
d80cd92a | 875 | { |
2b5f62a0 VZ |
876 | if( m_win->GetAutoLayout() ) |
877 | { | |
878 | if ( m_targetWindow != m_win ) | |
879 | m_targetWindow->FitInside(); | |
566d84a7 | 880 | |
2b5f62a0 | 881 | m_win->FitInside(); |
dc429f89 | 882 | |
566d84a7 | 883 | #if wxUSE_CONSTRAINTS |
566d84a7 RL |
884 | m_win->Layout(); |
885 | #endif | |
2b5f62a0 VZ |
886 | } |
887 | else | |
888 | AdjustScrollbars(); | |
d80cd92a VZ |
889 | } |
890 | ||
891 | // This calls OnDraw, having adjusted the origin according to the current | |
892 | // scroll position | |
1e6feb95 | 893 | void wxScrollHelper::HandleOnPaint(wxPaintEvent& WXUNUSED(event)) |
d80cd92a | 894 | { |
af4088f1 VZ |
895 | // don't use m_targetWindow here, this is always called for ourselves |
896 | wxPaintDC dc(m_win); | |
1e6feb95 | 897 | DoPrepareDC(dc); |
d80cd92a VZ |
898 | |
899 | OnDraw(dc); | |
900 | } | |
901 | ||
438e3558 VZ |
902 | // kbd handling: notice that we use OnChar() and not OnKeyDown() for |
903 | // compatibility here - if we used OnKeyDown(), the programs which process | |
904 | // arrows themselves in their OnChar() would never get the message and like | |
905 | // this they always have the priority | |
1e6feb95 | 906 | void wxScrollHelper::HandleOnChar(wxKeyEvent& event) |
d80cd92a VZ |
907 | { |
908 | int stx, sty, // view origin | |
909 | szx, szy, // view size (total) | |
910 | clix, cliy; // view size (on screen) | |
911 | ||
1e6feb95 VZ |
912 | GetViewStart(&stx, &sty); |
913 | GetTargetSize(&clix, &cliy); | |
566d84a7 | 914 | m_targetWindow->GetVirtualSize(&szx, &szy); |
56dade3c RL |
915 | |
916 | if( m_xScrollPixelsPerLine ) | |
917 | { | |
918 | clix /= m_xScrollPixelsPerLine; | |
d7da9756 | 919 | szx /= m_xScrollPixelsPerLine; |
56dade3c RL |
920 | } |
921 | else | |
922 | { | |
923 | clix = 0; | |
d7da9756 | 924 | szx = -1; |
56dade3c RL |
925 | } |
926 | if( m_yScrollPixelsPerLine ) | |
927 | { | |
928 | cliy /= m_yScrollPixelsPerLine; | |
929 | szy /= m_yScrollPixelsPerLine; | |
930 | } | |
931 | else | |
932 | { | |
933 | cliy = 0; | |
d7da9756 | 934 | szy = -1; |
56dade3c | 935 | } |
d80cd92a | 936 | |
39c869a6 VZ |
937 | int xScrollOld = m_xScrollPosition, |
938 | yScrollOld = m_yScrollPosition; | |
939 | ||
ecb01792 | 940 | int dsty; |
d80cd92a VZ |
941 | switch ( event.KeyCode() ) |
942 | { | |
943 | case WXK_PAGEUP: | |
944 | case WXK_PRIOR: | |
ecb01792 RL |
945 | dsty = sty - (5 * cliy / 6); |
946 | Scroll(-1, (dsty == -1) ? 0 : dsty); | |
d80cd92a VZ |
947 | break; |
948 | ||
949 | case WXK_PAGEDOWN: | |
950 | case WXK_NEXT: | |
951 | Scroll(-1, sty + (5 * cliy / 6)); | |
952 | break; | |
953 | ||
d80cd92a VZ |
954 | case WXK_HOME: |
955 | Scroll(0, event.ControlDown() ? 0 : -1); | |
956 | break; | |
957 | ||
958 | case WXK_END: | |
4acd108c | 959 | Scroll(szx - clix, event.ControlDown() ? szy - cliy : -1); |
d80cd92a VZ |
960 | break; |
961 | ||
962 | case WXK_UP: | |
963 | Scroll(-1, sty - 1); | |
964 | break; | |
965 | ||
966 | case WXK_DOWN: | |
967 | Scroll(-1, sty + 1); | |
968 | break; | |
969 | ||
970 | case WXK_LEFT: | |
971 | Scroll(stx - 1, -1); | |
972 | break; | |
973 | ||
974 | case WXK_RIGHT: | |
975 | Scroll(stx + 1, -1); | |
976 | break; | |
977 | ||
978 | default: | |
979 | // not for us | |
980 | event.Skip(); | |
981 | } | |
39c869a6 VZ |
982 | |
983 | if ( m_xScrollPosition != xScrollOld ) | |
984 | { | |
985 | wxScrollWinEvent event(wxEVT_SCROLLWIN_THUMBTRACK, m_xScrollPosition, | |
986 | wxHORIZONTAL); | |
987 | event.SetEventObject(m_win); | |
988 | m_win->GetEventHandler()->ProcessEvent(event); | |
989 | } | |
990 | ||
991 | if ( m_yScrollPosition != yScrollOld ) | |
992 | { | |
993 | wxScrollWinEvent event(wxEVT_SCROLLWIN_THUMBTRACK, m_yScrollPosition, | |
994 | wxVERTICAL); | |
995 | event.SetEventObject(m_win); | |
996 | m_win->GetEventHandler()->ProcessEvent(event); | |
997 | } | |
d80cd92a | 998 | } |
d2c52078 | 999 | |
1e6feb95 VZ |
1000 | // ---------------------------------------------------------------------------- |
1001 | // autoscroll stuff: these functions deal with sending fake scroll events when | |
1002 | // a captured mouse is being held outside the window | |
1003 | // ---------------------------------------------------------------------------- | |
1004 | ||
1005 | bool wxScrollHelper::SendAutoScrollEvents(wxScrollWinEvent& event) const | |
1006 | { | |
1007 | // only send the event if the window is scrollable in this direction | |
1008 | wxWindow *win = (wxWindow *)event.GetEventObject(); | |
1009 | return win->HasScrollbar(event.GetOrientation()); | |
1010 | } | |
1011 | ||
1012 | void wxScrollHelper::StopAutoScrolling() | |
1013 | { | |
1014 | if ( m_timerAutoScroll ) | |
1015 | { | |
1016 | delete m_timerAutoScroll; | |
1017 | m_timerAutoScroll = (wxTimer *)NULL; | |
1018 | } | |
1019 | } | |
d2c52078 | 1020 | |
1e6feb95 | 1021 | void wxScrollHelper::HandleOnMouseEnter(wxMouseEvent& event) |
d2c52078 | 1022 | { |
1e6feb95 VZ |
1023 | StopAutoScrolling(); |
1024 | ||
1025 | event.Skip(); | |
1026 | } | |
d2c52078 | 1027 | |
1e6feb95 VZ |
1028 | void wxScrollHelper::HandleOnMouseLeave(wxMouseEvent& event) |
1029 | { | |
1030 | // don't prevent the usual processing of the event from taking place | |
1031 | event.Skip(); | |
1032 | ||
1033 | // when a captured mouse leave a scrolled window we start generate | |
1034 | // scrolling events to allow, for example, extending selection beyond the | |
1035 | // visible area in some controls | |
1036 | if ( wxWindow::GetCapture() == m_targetWindow ) | |
1037 | { | |
1038 | // where is the mouse leaving? | |
1039 | int pos, orient; | |
1040 | wxPoint pt = event.GetPosition(); | |
1041 | if ( pt.x < 0 ) | |
1042 | { | |
1043 | orient = wxHORIZONTAL; | |
1044 | pos = 0; | |
1045 | } | |
1046 | else if ( pt.y < 0 ) | |
1047 | { | |
1048 | orient = wxVERTICAL; | |
1049 | pos = 0; | |
1050 | } | |
1051 | else // we're lower or to the right of the window | |
1052 | { | |
1053 | wxSize size = m_targetWindow->GetClientSize(); | |
1054 | if ( pt.x > size.x ) | |
1055 | { | |
1056 | orient = wxHORIZONTAL; | |
1057 | pos = m_xScrollLines; | |
1058 | } | |
1059 | else if ( pt.y > size.y ) | |
1060 | { | |
1061 | orient = wxVERTICAL; | |
1062 | pos = m_yScrollLines; | |
1063 | } | |
1064 | else // this should be impossible | |
1065 | { | |
1066 | // but seems to happen sometimes under wxMSW - maybe it's a bug | |
1067 | // there but for now just ignore it | |
1068 | ||
1069 | //wxFAIL_MSG( _T("can't understand where has mouse gone") ); | |
1070 | ||
1071 | return; | |
1072 | } | |
1073 | } | |
1074 | ||
1075 | // only start the auto scroll timer if the window can be scrolled in | |
1076 | // this direction | |
1077 | if ( !m_targetWindow->HasScrollbar(orient) ) | |
1078 | return; | |
1079 | ||
1080 | delete m_timerAutoScroll; | |
1081 | m_timerAutoScroll = new wxAutoScrollTimer | |
1082 | ( | |
1083 | m_targetWindow, this, | |
1084 | pos == 0 ? wxEVT_SCROLLWIN_LINEUP | |
1085 | : wxEVT_SCROLLWIN_LINEDOWN, | |
1086 | pos, | |
1087 | orient | |
1088 | ); | |
1089 | m_timerAutoScroll->Start(50); // FIXME: make configurable | |
1090 | } | |
1091 | } | |
1092 | ||
e421922f VZ |
1093 | #if wxUSE_MOUSEWHEEL |
1094 | ||
1e6feb95 VZ |
1095 | void wxScrollHelper::HandleOnMouseWheel(wxMouseEvent& event) |
1096 | { | |
d2c52078 | 1097 | m_wheelRotation += event.GetWheelRotation(); |
1e6feb95 | 1098 | int lines = m_wheelRotation / event.GetWheelDelta(); |
d2c52078 RD |
1099 | m_wheelRotation -= lines * event.GetWheelDelta(); |
1100 | ||
1e6feb95 VZ |
1101 | if (lines != 0) |
1102 | { | |
1e6feb95 | 1103 | |
b6b85bdc JS |
1104 | wxScrollWinEvent newEvent; |
1105 | ||
ac6f6ffc | 1106 | newEvent.SetPosition(0); |
b6b85bdc JS |
1107 | newEvent.SetOrientation(wxVERTICAL); |
1108 | newEvent.m_eventObject = m_win; | |
b6b85bdc | 1109 | |
9b9337da | 1110 | if (event.IsPageScroll()) |
4b056ef5 RD |
1111 | { |
1112 | if (lines > 0) | |
1113 | newEvent.m_eventType = wxEVT_SCROLLWIN_PAGEUP; | |
1114 | else | |
1115 | newEvent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN; | |
1116 | ||
b6b85bdc | 1117 | m_win->GetEventHandler()->ProcessEvent(newEvent); |
4b056ef5 RD |
1118 | } |
1119 | else | |
1120 | { | |
1121 | lines *= event.GetLinesPerAction(); | |
1122 | if (lines > 0) | |
1123 | newEvent.m_eventType = wxEVT_SCROLLWIN_LINEUP; | |
1124 | else | |
1125 | newEvent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN; | |
b6b85bdc | 1126 | |
4b056ef5 RD |
1127 | int times = abs(lines); |
1128 | for (; times > 0; times--) | |
1129 | m_win->GetEventHandler()->ProcessEvent(newEvent); | |
1130 | } | |
d2c52078 RD |
1131 | } |
1132 | } | |
1133 | ||
e421922f VZ |
1134 | #endif // wxUSE_MOUSEWHEEL |
1135 | ||
1e6feb95 VZ |
1136 | // ---------------------------------------------------------------------------- |
1137 | // wxGenericScrolledWindow implementation | |
1138 | // ---------------------------------------------------------------------------- | |
1139 | ||
1140 | IMPLEMENT_DYNAMIC_CLASS(wxGenericScrolledWindow, wxPanel) | |
1141 | ||
349efbaa VZ |
1142 | BEGIN_EVENT_TABLE(wxGenericScrolledWindow, wxPanel) |
1143 | EVT_PAINT(wxGenericScrolledWindow::OnPaint) | |
1144 | END_EVENT_TABLE() | |
1145 | ||
1e6feb95 VZ |
1146 | bool wxGenericScrolledWindow::Create(wxWindow *parent, |
1147 | wxWindowID id, | |
1148 | const wxPoint& pos, | |
1149 | const wxSize& size, | |
1150 | long style, | |
1151 | const wxString& name) | |
1152 | { | |
1153 | m_targetWindow = this; | |
1154 | ||
1155 | bool ok = wxPanel::Create(parent, id, pos, size, style, name); | |
1156 | ||
1e6feb95 VZ |
1157 | return ok; |
1158 | } | |
1159 | ||
1160 | wxGenericScrolledWindow::~wxGenericScrolledWindow() | |
1161 | { | |
1162 | } | |
d2c52078 | 1163 | |
30486297 RD |
1164 | bool wxGenericScrolledWindow::Layout() |
1165 | { | |
566d84a7 | 1166 | if (GetSizer() && m_targetWindow == this) |
30486297 | 1167 | { |
566d84a7 RL |
1168 | // If we're the scroll target, take into account the |
1169 | // virtual size and scrolled position of the window. | |
1170 | ||
30486297 RD |
1171 | int x, y, w, h; |
1172 | CalcScrolledPosition(0,0, &x,&y); | |
1173 | GetVirtualSize(&w, &h); | |
1174 | GetSizer()->SetDimension(x, y, w, h); | |
1175 | return TRUE; | |
1176 | } | |
7152f0c6 VZ |
1177 | |
1178 | // fall back to default for LayoutConstraints | |
1179 | return wxPanel::Layout(); | |
30486297 RD |
1180 | } |
1181 | ||
2b5f62a0 VZ |
1182 | void wxGenericScrolledWindow::DoSetVirtualSize(int x, int y) |
1183 | { | |
1184 | wxPanel::DoSetVirtualSize( x, y ); | |
1185 | AdjustScrollbars(); | |
1186 | ||
1187 | #if wxUSE_CONSTRAINTS | |
1188 | if (GetAutoLayout()) | |
1189 | Layout(); | |
1190 | #endif | |
1191 | } | |
1192 | ||
349efbaa VZ |
1193 | void wxGenericScrolledWindow::OnPaint(wxPaintEvent& event) |
1194 | { | |
1195 | // the user code didn't really draw the window if we got here, so set this | |
1196 | // flag to try to call OnDraw() later | |
1197 | m_handler->ResetDrawnFlag(); | |
1198 | ||
1199 | event.Skip(); | |
1200 | } | |
1201 | ||
0cf5b099 VZ |
1202 | #ifdef __WXMSW__ |
1203 | long | |
1204 | wxGenericScrolledWindow::MSWWindowProc(WXUINT nMsg, | |
1205 | WXWPARAM wParam, | |
1206 | WXLPARAM lParam) | |
1207 | { | |
1208 | long rc = wxPanel::MSWWindowProc(nMsg, wParam, lParam); | |
1209 | ||
1210 | // we need to process arrows ourselves for scrolling | |
1211 | if ( nMsg == WM_GETDLGCODE ) | |
1212 | { | |
1213 | rc |= DLGC_WANTARROWS; | |
1214 | } | |
1215 | ||
1216 | return rc; | |
1217 | } | |
1218 | ||
1219 | #endif // __WXMSW__ | |
1220 | ||
1e6feb95 | 1221 | #if WXWIN_COMPATIBILITY |
349efbaa | 1222 | |
1e6feb95 VZ |
1223 | void wxGenericScrolledWindow::GetScrollUnitsPerPage (int *x_page, int *y_page) const |
1224 | { | |
1225 | *x_page = GetScrollPageSize(wxHORIZONTAL); | |
1226 | *y_page = GetScrollPageSize(wxVERTICAL); | |
1227 | } | |
d2c52078 | 1228 | |
1e6feb95 VZ |
1229 | void wxGenericScrolledWindow::CalcUnscrolledPosition(int x, int y, float *xx, float *yy) const |
1230 | { | |
1231 | if ( xx ) | |
1232 | *xx = (float)(x + m_xScrollPosition * m_xScrollPixelsPerLine); | |
1233 | if ( yy ) | |
1234 | *yy = (float)(y + m_yScrollPosition * m_yScrollPixelsPerLine); | |
1235 | } | |
349efbaa | 1236 | |
1e6feb95 | 1237 | #endif // WXWIN_COMPATIBILITY |
d2c52078 | 1238 | |
3a8c693a VZ |
1239 | #endif // !wxGTK |
1240 | ||
566d84a7 | 1241 | // vi:sts=4:sw=4:et |