]>
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 | |
566d84a7 | 343 | m_targetWindow->SetVirtualSizeHints( noUnitsX * pixelsPerUnitX, noUnitsY * pixelsPerUnitY ); |
a58a12e9 VZ |
344 | |
345 | if (do_refresh && !noRefresh) | |
1e6feb95 | 346 | m_targetWindow->Refresh(TRUE, GetRect()); |
a58a12e9 | 347 | |
7c74e7fe | 348 | #ifdef __WXMAC__ |
d80cd92a | 349 | m_targetWindow->MacUpdateImmediately() ; |
c801d85f KB |
350 | #endif |
351 | } | |
352 | ||
d80cd92a | 353 | // ---------------------------------------------------------------------------- |
af4088f1 | 354 | // [target] window handling |
d80cd92a | 355 | // ---------------------------------------------------------------------------- |
ecab4dba | 356 | |
349efbaa | 357 | void wxScrollHelper::DeleteEvtHandler() |
ecab4dba | 358 | { |
248d771c VZ |
359 | // search for m_handler in the handler list |
360 | if ( m_win && m_handler ) | |
349efbaa | 361 | { |
74f6bbf9 | 362 | if ( m_win->RemoveEventHandler(m_handler) ) |
248d771c | 363 | { |
74f6bbf9 | 364 | delete m_handler; |
248d771c | 365 | } |
74f6bbf9 VZ |
366 | //else: something is very wrong, so better [maybe] leak memory than |
367 | // risk a crash because of double deletion | |
248d771c | 368 | |
74f6bbf9 | 369 | m_handler = NULL; |
349efbaa VZ |
370 | } |
371 | } | |
372 | ||
373 | void wxScrollHelper::SetWindow(wxWindow *win) | |
374 | { | |
375 | wxCHECK_RET( win, _T("wxScrollHelper needs a window to scroll") ); | |
376 | ||
377 | m_win = win; | |
378 | ||
af4088f1 VZ |
379 | // by default, the associated window is also the target window |
380 | DoSetTargetWindow(win); | |
349efbaa VZ |
381 | } |
382 | ||
af4088f1 | 383 | void wxScrollHelper::DoSetTargetWindow(wxWindow *target) |
349efbaa | 384 | { |
ecab4dba | 385 | m_targetWindow = target; |
349efbaa VZ |
386 | |
387 | // install the event handler which will intercept the events we're | |
af4088f1 VZ |
388 | // interested in (but only do it for our real window, not the target window |
389 | // which we scroll - we don't need to hijack its events) | |
390 | if ( m_targetWindow == m_win ) | |
13ff9344 | 391 | { |
248d771c VZ |
392 | // if we already have a handler, delete it first |
393 | DeleteEvtHandler(); | |
394 | ||
13ff9344 JS |
395 | m_handler = new wxScrollHelperEvtHandler(this); |
396 | m_targetWindow->PushEventHandler(m_handler); | |
397 | } | |
349efbaa VZ |
398 | } |
399 | ||
af4088f1 | 400 | void wxScrollHelper::SetTargetWindow(wxWindow *target) |
349efbaa VZ |
401 | { |
402 | wxCHECK_RET( target, wxT("target window must not be NULL") ); | |
403 | ||
404 | if ( target == m_targetWindow ) | |
405 | return; | |
406 | ||
af4088f1 | 407 | DoSetTargetWindow(target); |
ecab4dba RR |
408 | } |
409 | ||
1e6feb95 | 410 | wxWindow *wxScrollHelper::GetTargetWindow() const |
ecab4dba RR |
411 | { |
412 | return m_targetWindow; | |
413 | } | |
414 | ||
d80cd92a VZ |
415 | // ---------------------------------------------------------------------------- |
416 | // scrolling implementation itself | |
417 | // ---------------------------------------------------------------------------- | |
418 | ||
1e6feb95 | 419 | void wxScrollHelper::HandleOnScroll(wxScrollWinEvent& event) |
c801d85f | 420 | { |
139adb6a | 421 | int nScrollInc = CalcScrollInc(event); |
1e6feb95 | 422 | if ( nScrollInc == 0 ) |
139adb6a | 423 | { |
1e6feb95 VZ |
424 | // can't scroll further |
425 | event.Skip(); | |
426 | ||
427 | return; | |
139adb6a | 428 | } |
c801d85f | 429 | |
1e6feb95 | 430 | int orient = event.GetOrientation(); |
139adb6a RR |
431 | if (orient == wxHORIZONTAL) |
432 | { | |
433 | m_xScrollPosition += nScrollInc; | |
5f3286d1 | 434 | m_win->SetScrollPos(wxHORIZONTAL, m_xScrollPosition); |
139adb6a | 435 | } |
c801d85f | 436 | else |
139adb6a RR |
437 | { |
438 | m_yScrollPosition += nScrollInc; | |
5f3286d1 | 439 | m_win->SetScrollPos(wxVERTICAL, m_yScrollPosition); |
139adb6a | 440 | } |
a58a12e9 | 441 | |
1e6feb95 VZ |
442 | bool needsRefresh = FALSE; |
443 | int dx = 0, | |
444 | dy = 0; | |
139adb6a RR |
445 | if (orient == wxHORIZONTAL) |
446 | { | |
1e6feb95 VZ |
447 | if ( m_xScrollingEnabled ) |
448 | { | |
449 | dx = -m_xScrollPixelsPerLine * nScrollInc; | |
450 | } | |
139adb6a | 451 | else |
1e6feb95 VZ |
452 | { |
453 | needsRefresh = TRUE; | |
454 | } | |
139adb6a | 455 | } |
c801d85f | 456 | else |
139adb6a | 457 | { |
1e6feb95 VZ |
458 | if ( m_yScrollingEnabled ) |
459 | { | |
460 | dy = -m_yScrollPixelsPerLine * nScrollInc; | |
461 | } | |
139adb6a | 462 | else |
1e6feb95 VZ |
463 | { |
464 | needsRefresh = TRUE; | |
465 | } | |
466 | } | |
467 | ||
468 | if ( needsRefresh ) | |
469 | { | |
470 | m_targetWindow->Refresh(TRUE, GetRect()); | |
471 | } | |
472 | else | |
473 | { | |
474 | m_targetWindow->ScrollWindow(dx, dy, GetRect()); | |
3d2b9c20 | 475 | } |
1e6feb95 | 476 | |
7c74e7fe | 477 | #ifdef __WXMAC__ |
d80cd92a | 478 | m_targetWindow->MacUpdateImmediately() ; |
7c74e7fe | 479 | #endif |
c801d85f KB |
480 | } |
481 | ||
1e6feb95 | 482 | int wxScrollHelper::CalcScrollInc(wxScrollWinEvent& event) |
c801d85f | 483 | { |
ecab4dba RR |
484 | int pos = event.GetPosition(); |
485 | int orient = event.GetOrientation(); | |
c801d85f | 486 | |
ecab4dba | 487 | int nScrollInc = 0; |
1a8caf94 | 488 | if (event.GetEventType() == wxEVT_SCROLLWIN_TOP) |
c801d85f | 489 | { |
ecab4dba RR |
490 | if (orient == wxHORIZONTAL) |
491 | nScrollInc = - m_xScrollPosition; | |
492 | else | |
493 | nScrollInc = - m_yScrollPosition; | |
1a8caf94 RR |
494 | } else |
495 | if (event.GetEventType() == wxEVT_SCROLLWIN_BOTTOM) | |
496 | { | |
ecab4dba RR |
497 | if (orient == wxHORIZONTAL) |
498 | nScrollInc = m_xScrollLines - m_xScrollPosition; | |
499 | else | |
500 | nScrollInc = m_yScrollLines - m_yScrollPosition; | |
1a8caf94 RR |
501 | } else |
502 | if (event.GetEventType() == wxEVT_SCROLLWIN_LINEUP) | |
503 | { | |
ecab4dba | 504 | nScrollInc = -1; |
1a8caf94 RR |
505 | } else |
506 | if (event.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN) | |
507 | { | |
ecab4dba | 508 | nScrollInc = 1; |
1a8caf94 RR |
509 | } else |
510 | if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEUP) | |
511 | { | |
ecab4dba RR |
512 | if (orient == wxHORIZONTAL) |
513 | nScrollInc = -GetScrollPageSize(wxHORIZONTAL); | |
514 | else | |
515 | nScrollInc = -GetScrollPageSize(wxVERTICAL); | |
1a8caf94 RR |
516 | } else |
517 | if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN) | |
518 | { | |
ecab4dba RR |
519 | if (orient == wxHORIZONTAL) |
520 | nScrollInc = GetScrollPageSize(wxHORIZONTAL); | |
521 | else | |
522 | nScrollInc = GetScrollPageSize(wxVERTICAL); | |
1a8caf94 RR |
523 | } else |
524 | if ((event.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK) || | |
525 | (event.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE)) | |
526 | { | |
ecab4dba RR |
527 | if (orient == wxHORIZONTAL) |
528 | nScrollInc = pos - m_xScrollPosition; | |
529 | else | |
530 | nScrollInc = pos - m_yScrollPosition; | |
c801d85f | 531 | } |
88150e60 | 532 | |
ecab4dba RR |
533 | if (orient == wxHORIZONTAL) |
534 | { | |
a58a12e9 | 535 | if (m_xScrollPixelsPerLine > 0) |
ecab4dba RR |
536 | { |
537 | int w, h; | |
1e6feb95 | 538 | GetTargetSize(&w, &h); |
ecab4dba RR |
539 | |
540 | int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine; | |
541 | int noPositions = (int) ( ((nMaxWidth - w)/(double)m_xScrollPixelsPerLine) + 0.5 ); | |
542 | if (noPositions < 0) | |
d80cd92a | 543 | noPositions = 0; |
ecab4dba RR |
544 | |
545 | if ( (m_xScrollPosition + nScrollInc) < 0 ) | |
d80cd92a | 546 | nScrollInc = -m_xScrollPosition; // As -ve as we can go |
ecab4dba | 547 | else if ( (m_xScrollPosition + nScrollInc) > noPositions ) |
d80cd92a | 548 | nScrollInc = noPositions - m_xScrollPosition; // As +ve as we can go |
ecab4dba RR |
549 | } |
550 | else | |
1e6feb95 | 551 | m_targetWindow->Refresh(TRUE, GetRect()); |
9d9355c6 VZ |
552 | } |
553 | else | |
ecab4dba | 554 | { |
a58a12e9 | 555 | if (m_yScrollPixelsPerLine > 0) |
d80cd92a | 556 | { |
ecab4dba | 557 | int w, h; |
1e6feb95 | 558 | GetTargetSize(&w, &h); |
a58a12e9 | 559 | |
ecab4dba RR |
560 | int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine; |
561 | int noPositions = (int) ( ((nMaxHeight - h)/(double)m_yScrollPixelsPerLine) + 0.5 ); | |
562 | if (noPositions < 0) | |
d80cd92a | 563 | noPositions = 0; |
a58a12e9 | 564 | |
ecab4dba | 565 | if ( (m_yScrollPosition + nScrollInc) < 0 ) |
d80cd92a | 566 | nScrollInc = -m_yScrollPosition; // As -ve as we can go |
ecab4dba | 567 | else if ( (m_yScrollPosition + nScrollInc) > noPositions ) |
d80cd92a | 568 | nScrollInc = noPositions - m_yScrollPosition; // As +ve as we can go |
ecab4dba RR |
569 | } |
570 | else | |
1e6feb95 | 571 | m_targetWindow->Refresh(TRUE, GetRect()); |
9d9355c6 | 572 | } |
9d9355c6 | 573 | |
ecab4dba | 574 | return nScrollInc; |
c801d85f KB |
575 | } |
576 | ||
577 | // Adjust the scrollbars - new version. | |
1e6feb95 | 578 | void wxScrollHelper::AdjustScrollbars() |
c801d85f | 579 | { |
aeb313f3 SC |
580 | #ifdef __WXMAC__ |
581 | m_targetWindow->MacUpdateImmediately(); | |
582 | #endif | |
583 | ||
566d84a7 RL |
584 | int w = 0, h = 0; |
585 | int oldw, oldh; | |
a58a12e9 | 586 | |
27d029c7 RR |
587 | int oldXScroll = m_xScrollPosition; |
588 | int oldYScroll = m_yScrollPosition; | |
c801d85f | 589 | |
566d84a7 RL |
590 | do { |
591 | GetTargetSize(&w, 0); | |
c801d85f | 592 | |
566d84a7 RL |
593 | if (m_xScrollPixelsPerLine == 0) |
594 | { | |
595 | m_xScrollLines = 0; | |
596 | m_xScrollPosition = 0; | |
597 | m_win->SetScrollbar (wxHORIZONTAL, 0, 0, 0, FALSE); | |
598 | } | |
599 | else | |
600 | { | |
601 | m_xScrollLines = m_targetWindow->GetVirtualSize().GetWidth() / m_xScrollPixelsPerLine; | |
602 | ||
603 | // Calculate page size i.e. number of scroll units you get on the | |
604 | // current client window | |
605 | int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 ); | |
606 | if (noPagePositions < 1) noPagePositions = 1; | |
607 | if ( noPagePositions > m_xScrollLines ) | |
608 | noPagePositions = m_xScrollLines; | |
609 | ||
610 | // Correct position if greater than extent of canvas minus | |
611 | // the visible portion of it or if below zero | |
612 | m_xScrollPosition = wxMin( m_xScrollLines - noPagePositions, m_xScrollPosition); | |
613 | m_xScrollPosition = wxMax( 0, m_xScrollPosition ); | |
614 | ||
615 | m_win->SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, m_xScrollLines); | |
616 | // The amount by which we scroll when paging | |
617 | SetScrollPageSize(wxHORIZONTAL, noPagePositions); | |
618 | } | |
c801d85f | 619 | |
566d84a7 | 620 | GetTargetSize(0, &h); |
a58a12e9 | 621 | |
566d84a7 RL |
622 | if (m_yScrollPixelsPerLine == 0) |
623 | { | |
624 | m_yScrollLines = 0; | |
625 | m_yScrollPosition = 0; | |
626 | m_win->SetScrollbar (wxVERTICAL, 0, 0, 0, FALSE); | |
627 | } | |
628 | else | |
629 | { | |
630 | m_yScrollLines = m_targetWindow->GetVirtualSize().GetHeight() / m_yScrollPixelsPerLine; | |
631 | ||
632 | // Calculate page size i.e. number of scroll units you get on the | |
633 | // current client window | |
634 | int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 ); | |
635 | if (noPagePositions < 1) noPagePositions = 1; | |
636 | if ( noPagePositions > m_yScrollLines ) | |
637 | noPagePositions = m_yScrollLines; | |
638 | ||
639 | // Correct position if greater than extent of canvas minus | |
640 | // the visible portion of it or if below zero | |
641 | m_yScrollPosition = wxMin( m_yScrollLines - noPagePositions, m_yScrollPosition ); | |
642 | m_yScrollPosition = wxMax( 0, m_yScrollPosition ); | |
643 | ||
644 | m_win->SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, m_yScrollLines); | |
645 | // The amount by which we scroll when paging | |
646 | SetScrollPageSize(wxVERTICAL, noPagePositions); | |
647 | } | |
c801d85f | 648 | |
566d84a7 | 649 | // If a scrollbar (dis)appeared as a result of this, adjust them again. |
139adb6a | 650 | |
566d84a7 RL |
651 | oldw = w; |
652 | oldh = h; | |
653 | ||
654 | GetTargetSize( &w, &h ); | |
655 | } while ( w != oldw && h != oldh ); | |
656 | ||
657 | #ifdef __WXMOTIF__ | |
658 | // Sorry, some Motif-specific code to implement a backing pixmap | |
659 | // for the wxRETAINED style. Implementing a backing store can't | |
660 | // be entirely generic because it relies on the wxWindowDC implementation | |
661 | // to duplicate X drawing calls for the backing pixmap. | |
662 | ||
663 | if ( m_targetWindow->GetWindowStyle() & wxRETAINED ) | |
139adb6a | 664 | { |
566d84a7 RL |
665 | Display* dpy = XtDisplay((Widget)m_targetWindow->GetMainWidget()); |
666 | ||
667 | int totalPixelWidth = m_xScrollLines * m_xScrollPixelsPerLine; | |
668 | int totalPixelHeight = m_yScrollLines * m_yScrollPixelsPerLine; | |
669 | if (m_targetWindow->GetBackingPixmap() && | |
670 | !((m_targetWindow->GetPixmapWidth() == totalPixelWidth) && | |
671 | (m_targetWindow->GetPixmapHeight() == totalPixelHeight))) | |
672 | { | |
673 | XFreePixmap (dpy, (Pixmap) m_targetWindow->GetBackingPixmap()); | |
674 | m_targetWindow->SetBackingPixmap((WXPixmap) 0); | |
675 | } | |
676 | ||
677 | if (!m_targetWindow->GetBackingPixmap() && | |
9b66c26a | 678 | (m_xScrollLines != 0) && (m_yScrollLines != 0)) |
566d84a7 RL |
679 | { |
680 | int depth = wxDisplayDepth(); | |
681 | m_targetWindow->SetPixmapWidth(totalPixelWidth); | |
682 | m_targetWindow->SetPixmapHeight(totalPixelHeight); | |
683 | m_targetWindow->SetBackingPixmap((WXPixmap) XCreatePixmap (dpy, RootWindow (dpy, DefaultScreen (dpy)), | |
684 | m_targetWindow->GetPixmapWidth(), m_targetWindow->GetPixmapHeight(), depth)); | |
685 | } | |
686 | ||
139adb6a | 687 | } |
566d84a7 | 688 | #endif // Motif |
a58a12e9 | 689 | |
27d029c7 RR |
690 | if (oldXScroll != m_xScrollPosition) |
691 | { | |
692 | if (m_xScrollingEnabled) | |
566d84a7 | 693 | m_targetWindow->ScrollWindow( m_xScrollPixelsPerLine * (oldXScroll - m_xScrollPosition), 0, |
1e6feb95 | 694 | GetRect() ); |
27d029c7 | 695 | else |
1e6feb95 | 696 | m_targetWindow->Refresh(TRUE, GetRect()); |
27d029c7 | 697 | } |
a58a12e9 | 698 | |
27d029c7 RR |
699 | if (oldYScroll != m_yScrollPosition) |
700 | { | |
701 | if (m_yScrollingEnabled) | |
1e6feb95 VZ |
702 | m_targetWindow->ScrollWindow( 0, m_yScrollPixelsPerLine * (oldYScroll-m_yScrollPosition), |
703 | GetRect() ); | |
27d029c7 | 704 | else |
1e6feb95 | 705 | m_targetWindow->Refresh(TRUE, GetRect()); |
27d029c7 | 706 | } |
aeb313f3 SC |
707 | |
708 | #ifdef __WXMAC__ | |
709 | m_targetWindow->MacUpdateImmediately(); | |
710 | #endif | |
c801d85f KB |
711 | } |
712 | ||
1e6feb95 | 713 | void wxScrollHelper::DoPrepareDC(wxDC& dc) |
c801d85f | 714 | { |
1e6feb95 VZ |
715 | wxPoint pt = dc.GetDeviceOrigin(); |
716 | dc.SetDeviceOrigin( pt.x - m_xScrollPosition * m_xScrollPixelsPerLine, | |
717 | pt.y - m_yScrollPosition * m_yScrollPixelsPerLine ); | |
139adb6a | 718 | dc.SetUserScale( m_scaleX, m_scaleY ); |
c801d85f KB |
719 | } |
720 | ||
566d84a7 RL |
721 | void wxScrollHelper::SetScrollRate( int xstep, int ystep ) |
722 | { | |
723 | int old_x = m_xScrollPixelsPerLine * m_xScrollPosition; | |
724 | int old_y = m_yScrollPixelsPerLine * m_yScrollPosition; | |
725 | ||
726 | m_xScrollPixelsPerLine = xstep; | |
727 | m_yScrollPixelsPerLine = ystep; | |
728 | ||
729 | int new_x = m_xScrollPixelsPerLine * m_xScrollPosition; | |
730 | int new_y = m_yScrollPixelsPerLine * m_yScrollPosition; | |
731 | ||
732 | m_win->SetScrollPos( wxHORIZONTAL, m_xScrollPosition ); | |
733 | m_win->SetScrollPos( wxVERTICAL, m_yScrollPosition ); | |
734 | m_targetWindow->ScrollWindow( old_x - new_x, old_y - new_y ); | |
735 | ||
736 | AdjustScrollbars(); | |
737 | } | |
738 | ||
1e6feb95 | 739 | void wxScrollHelper::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const |
c801d85f | 740 | { |
a0bc2c1d VZ |
741 | if ( x_unit ) |
742 | *x_unit = m_xScrollPixelsPerLine; | |
743 | if ( y_unit ) | |
744 | *y_unit = m_yScrollPixelsPerLine; | |
c801d85f KB |
745 | } |
746 | ||
1e6feb95 | 747 | int wxScrollHelper::GetScrollPageSize(int orient) const |
c801d85f KB |
748 | { |
749 | if ( orient == wxHORIZONTAL ) | |
750 | return m_xScrollLinesPerPage; | |
751 | else | |
752 | return m_yScrollLinesPerPage; | |
753 | } | |
754 | ||
1e6feb95 | 755 | void wxScrollHelper::SetScrollPageSize(int orient, int pageSize) |
c801d85f KB |
756 | { |
757 | if ( orient == wxHORIZONTAL ) | |
758 | m_xScrollLinesPerPage = pageSize; | |
759 | else | |
760 | m_yScrollLinesPerPage = pageSize; | |
761 | } | |
762 | ||
763 | /* | |
764 | * Scroll to given position (scroll position, not pixel position) | |
765 | */ | |
1e6feb95 | 766 | void wxScrollHelper::Scroll( int x_pos, int y_pos ) |
c801d85f | 767 | { |
8b089c5e JS |
768 | if (!m_targetWindow) |
769 | return; | |
770 | ||
a58a12e9 | 771 | if (((x_pos == -1) || (x_pos == m_xScrollPosition)) && |
139adb6a | 772 | ((y_pos == -1) || (y_pos == m_yScrollPosition))) return; |
a58a12e9 | 773 | |
aeb313f3 SC |
774 | #ifdef __WXMAC__ |
775 | m_targetWindow->MacUpdateImmediately(); | |
776 | #endif | |
777 | ||
139adb6a | 778 | int w, h; |
1e6feb95 | 779 | GetTargetSize(&w, &h); |
c801d85f | 780 | |
8775b357 | 781 | if ((x_pos != -1) && (m_xScrollPixelsPerLine)) |
c801d85f | 782 | { |
ed673c6a | 783 | int old_x = m_xScrollPosition; |
139adb6a | 784 | m_xScrollPosition = x_pos; |
a58a12e9 | 785 | |
3d2b9c20 RR |
786 | // Calculate page size i.e. number of scroll units you get on the |
787 | // current client window | |
ecab4dba | 788 | int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 ); |
139adb6a RR |
789 | if (noPagePositions < 1) noPagePositions = 1; |
790 | ||
791 | // Correct position if greater than extent of canvas minus | |
3d2b9c20 | 792 | // the visible portion of it or if below zero |
139adb6a RR |
793 | m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition ); |
794 | m_xScrollPosition = wxMax( 0, m_xScrollPosition ); | |
a58a12e9 | 795 | |
f6bcfd97 | 796 | if (old_x != m_xScrollPosition) { |
5f3286d1 | 797 | m_win->SetScrollPos( wxHORIZONTAL, m_xScrollPosition ); |
1e6feb95 VZ |
798 | m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0, |
799 | GetRect() ); | |
f6bcfd97 | 800 | } |
c801d85f | 801 | } |
8775b357 | 802 | if ((y_pos != -1) && (m_yScrollPixelsPerLine)) |
c801d85f | 803 | { |
ed673c6a | 804 | int old_y = m_yScrollPosition; |
139adb6a | 805 | m_yScrollPosition = y_pos; |
a58a12e9 | 806 | |
3d2b9c20 RR |
807 | // Calculate page size i.e. number of scroll units you get on the |
808 | // current client window | |
ecab4dba | 809 | int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 ); |
139adb6a RR |
810 | if (noPagePositions < 1) noPagePositions = 1; |
811 | ||
812 | // Correct position if greater than extent of canvas minus | |
3d2b9c20 | 813 | // the visible portion of it or if below zero |
139adb6a RR |
814 | m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition ); |
815 | m_yScrollPosition = wxMax( 0, m_yScrollPosition ); | |
d2c52078 | 816 | |
f6bcfd97 | 817 | if (old_y != m_yScrollPosition) { |
5f3286d1 | 818 | m_win->SetScrollPos( wxVERTICAL, m_yScrollPosition ); |
1e6feb95 VZ |
819 | m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine, |
820 | GetRect() ); | |
f6bcfd97 | 821 | } |
c801d85f | 822 | } |
a58a12e9 | 823 | |
7c74e7fe | 824 | #ifdef __WXMAC__ |
3d2b9c20 | 825 | m_targetWindow->MacUpdateImmediately(); |
7c74e7fe | 826 | #endif |
aeb313f3 | 827 | |
c801d85f KB |
828 | } |
829 | ||
1e6feb95 | 830 | void wxScrollHelper::EnableScrolling (bool x_scroll, bool y_scroll) |
c801d85f | 831 | { |
139adb6a RR |
832 | m_xScrollingEnabled = x_scroll; |
833 | m_yScrollingEnabled = y_scroll; | |
c801d85f KB |
834 | } |
835 | ||
c801d85f | 836 | // Where the current view starts from |
1e6feb95 | 837 | void wxScrollHelper::GetViewStart (int *x, int *y) const |
c801d85f | 838 | { |
a0bc2c1d VZ |
839 | if ( x ) |
840 | *x = m_xScrollPosition; | |
841 | if ( y ) | |
842 | *y = m_yScrollPosition; | |
c801d85f KB |
843 | } |
844 | ||
8c2f3797 | 845 | void wxScrollHelper::DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const |
c801d85f | 846 | { |
a0bc2c1d VZ |
847 | if ( xx ) |
848 | *xx = x - m_xScrollPosition * m_xScrollPixelsPerLine; | |
849 | if ( yy ) | |
850 | *yy = y - m_yScrollPosition * m_yScrollPixelsPerLine; | |
c801d85f KB |
851 | } |
852 | ||
8c2f3797 | 853 | void wxScrollHelper::DoCalcUnscrolledPosition(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 | 859 | } |
d80cd92a VZ |
860 | |
861 | // ---------------------------------------------------------------------------- | |
862 | // event handlers | |
863 | // ---------------------------------------------------------------------------- | |
864 | ||
865 | // Default OnSize resets scrollbars, if any | |
1e6feb95 | 866 | void wxScrollHelper::HandleOnSize(wxSizeEvent& WXUNUSED(event)) |
d80cd92a | 867 | { |
566d84a7 RL |
868 | if( m_targetWindow != m_win ) |
869 | m_targetWindow->SetVirtualSize( m_targetWindow->GetClientSize() ); | |
870 | ||
871 | m_win->SetVirtualSize( m_win->GetClientSize() ); | |
872 | ||
873 | #if wxUSE_CONSTRAINTS | |
874 | if (m_win->GetAutoLayout()) | |
875 | m_win->Layout(); | |
876 | #endif | |
d80cd92a VZ |
877 | } |
878 | ||
879 | // This calls OnDraw, having adjusted the origin according to the current | |
880 | // scroll position | |
1e6feb95 | 881 | void wxScrollHelper::HandleOnPaint(wxPaintEvent& WXUNUSED(event)) |
d80cd92a | 882 | { |
af4088f1 VZ |
883 | // don't use m_targetWindow here, this is always called for ourselves |
884 | wxPaintDC dc(m_win); | |
1e6feb95 | 885 | DoPrepareDC(dc); |
d80cd92a VZ |
886 | |
887 | OnDraw(dc); | |
888 | } | |
889 | ||
438e3558 VZ |
890 | // kbd handling: notice that we use OnChar() and not OnKeyDown() for |
891 | // compatibility here - if we used OnKeyDown(), the programs which process | |
892 | // arrows themselves in their OnChar() would never get the message and like | |
893 | // this they always have the priority | |
1e6feb95 | 894 | void wxScrollHelper::HandleOnChar(wxKeyEvent& event) |
d80cd92a VZ |
895 | { |
896 | int stx, sty, // view origin | |
897 | szx, szy, // view size (total) | |
898 | clix, cliy; // view size (on screen) | |
899 | ||
1e6feb95 VZ |
900 | GetViewStart(&stx, &sty); |
901 | GetTargetSize(&clix, &cliy); | |
566d84a7 | 902 | m_targetWindow->GetVirtualSize(&szx, &szy); |
56dade3c RL |
903 | |
904 | if( m_xScrollPixelsPerLine ) | |
905 | { | |
906 | clix /= m_xScrollPixelsPerLine; | |
d7da9756 | 907 | szx /= m_xScrollPixelsPerLine; |
56dade3c RL |
908 | } |
909 | else | |
910 | { | |
911 | clix = 0; | |
d7da9756 | 912 | szx = -1; |
56dade3c RL |
913 | } |
914 | if( m_yScrollPixelsPerLine ) | |
915 | { | |
916 | cliy /= m_yScrollPixelsPerLine; | |
917 | szy /= m_yScrollPixelsPerLine; | |
918 | } | |
919 | else | |
920 | { | |
921 | cliy = 0; | |
d7da9756 | 922 | szy = -1; |
56dade3c | 923 | } |
d80cd92a | 924 | |
39c869a6 VZ |
925 | int xScrollOld = m_xScrollPosition, |
926 | yScrollOld = m_yScrollPosition; | |
927 | ||
ecb01792 | 928 | int dsty; |
d80cd92a VZ |
929 | switch ( event.KeyCode() ) |
930 | { | |
931 | case WXK_PAGEUP: | |
932 | case WXK_PRIOR: | |
ecb01792 RL |
933 | dsty = sty - (5 * cliy / 6); |
934 | Scroll(-1, (dsty == -1) ? 0 : dsty); | |
d80cd92a VZ |
935 | break; |
936 | ||
937 | case WXK_PAGEDOWN: | |
938 | case WXK_NEXT: | |
939 | Scroll(-1, sty + (5 * cliy / 6)); | |
940 | break; | |
941 | ||
d80cd92a VZ |
942 | case WXK_HOME: |
943 | Scroll(0, event.ControlDown() ? 0 : -1); | |
944 | break; | |
945 | ||
946 | case WXK_END: | |
4acd108c | 947 | Scroll(szx - clix, event.ControlDown() ? szy - cliy : -1); |
d80cd92a VZ |
948 | break; |
949 | ||
950 | case WXK_UP: | |
951 | Scroll(-1, sty - 1); | |
952 | break; | |
953 | ||
954 | case WXK_DOWN: | |
955 | Scroll(-1, sty + 1); | |
956 | break; | |
957 | ||
958 | case WXK_LEFT: | |
959 | Scroll(stx - 1, -1); | |
960 | break; | |
961 | ||
962 | case WXK_RIGHT: | |
963 | Scroll(stx + 1, -1); | |
964 | break; | |
965 | ||
966 | default: | |
967 | // not for us | |
968 | event.Skip(); | |
969 | } | |
39c869a6 VZ |
970 | |
971 | if ( m_xScrollPosition != xScrollOld ) | |
972 | { | |
973 | wxScrollWinEvent event(wxEVT_SCROLLWIN_THUMBTRACK, m_xScrollPosition, | |
974 | wxHORIZONTAL); | |
975 | event.SetEventObject(m_win); | |
976 | m_win->GetEventHandler()->ProcessEvent(event); | |
977 | } | |
978 | ||
979 | if ( m_yScrollPosition != yScrollOld ) | |
980 | { | |
981 | wxScrollWinEvent event(wxEVT_SCROLLWIN_THUMBTRACK, m_yScrollPosition, | |
982 | wxVERTICAL); | |
983 | event.SetEventObject(m_win); | |
984 | m_win->GetEventHandler()->ProcessEvent(event); | |
985 | } | |
d80cd92a | 986 | } |
d2c52078 | 987 | |
1e6feb95 VZ |
988 | // ---------------------------------------------------------------------------- |
989 | // autoscroll stuff: these functions deal with sending fake scroll events when | |
990 | // a captured mouse is being held outside the window | |
991 | // ---------------------------------------------------------------------------- | |
992 | ||
993 | bool wxScrollHelper::SendAutoScrollEvents(wxScrollWinEvent& event) const | |
994 | { | |
995 | // only send the event if the window is scrollable in this direction | |
996 | wxWindow *win = (wxWindow *)event.GetEventObject(); | |
997 | return win->HasScrollbar(event.GetOrientation()); | |
998 | } | |
999 | ||
1000 | void wxScrollHelper::StopAutoScrolling() | |
1001 | { | |
1002 | if ( m_timerAutoScroll ) | |
1003 | { | |
1004 | delete m_timerAutoScroll; | |
1005 | m_timerAutoScroll = (wxTimer *)NULL; | |
1006 | } | |
1007 | } | |
d2c52078 | 1008 | |
1e6feb95 | 1009 | void wxScrollHelper::HandleOnMouseEnter(wxMouseEvent& event) |
d2c52078 | 1010 | { |
1e6feb95 VZ |
1011 | StopAutoScrolling(); |
1012 | ||
1013 | event.Skip(); | |
1014 | } | |
d2c52078 | 1015 | |
1e6feb95 VZ |
1016 | void wxScrollHelper::HandleOnMouseLeave(wxMouseEvent& event) |
1017 | { | |
1018 | // don't prevent the usual processing of the event from taking place | |
1019 | event.Skip(); | |
1020 | ||
1021 | // when a captured mouse leave a scrolled window we start generate | |
1022 | // scrolling events to allow, for example, extending selection beyond the | |
1023 | // visible area in some controls | |
1024 | if ( wxWindow::GetCapture() == m_targetWindow ) | |
1025 | { | |
1026 | // where is the mouse leaving? | |
1027 | int pos, orient; | |
1028 | wxPoint pt = event.GetPosition(); | |
1029 | if ( pt.x < 0 ) | |
1030 | { | |
1031 | orient = wxHORIZONTAL; | |
1032 | pos = 0; | |
1033 | } | |
1034 | else if ( pt.y < 0 ) | |
1035 | { | |
1036 | orient = wxVERTICAL; | |
1037 | pos = 0; | |
1038 | } | |
1039 | else // we're lower or to the right of the window | |
1040 | { | |
1041 | wxSize size = m_targetWindow->GetClientSize(); | |
1042 | if ( pt.x > size.x ) | |
1043 | { | |
1044 | orient = wxHORIZONTAL; | |
1045 | pos = m_xScrollLines; | |
1046 | } | |
1047 | else if ( pt.y > size.y ) | |
1048 | { | |
1049 | orient = wxVERTICAL; | |
1050 | pos = m_yScrollLines; | |
1051 | } | |
1052 | else // this should be impossible | |
1053 | { | |
1054 | // but seems to happen sometimes under wxMSW - maybe it's a bug | |
1055 | // there but for now just ignore it | |
1056 | ||
1057 | //wxFAIL_MSG( _T("can't understand where has mouse gone") ); | |
1058 | ||
1059 | return; | |
1060 | } | |
1061 | } | |
1062 | ||
1063 | // only start the auto scroll timer if the window can be scrolled in | |
1064 | // this direction | |
1065 | if ( !m_targetWindow->HasScrollbar(orient) ) | |
1066 | return; | |
1067 | ||
1068 | delete m_timerAutoScroll; | |
1069 | m_timerAutoScroll = new wxAutoScrollTimer | |
1070 | ( | |
1071 | m_targetWindow, this, | |
1072 | pos == 0 ? wxEVT_SCROLLWIN_LINEUP | |
1073 | : wxEVT_SCROLLWIN_LINEDOWN, | |
1074 | pos, | |
1075 | orient | |
1076 | ); | |
1077 | m_timerAutoScroll->Start(50); // FIXME: make configurable | |
1078 | } | |
1079 | } | |
1080 | ||
e421922f VZ |
1081 | #if wxUSE_MOUSEWHEEL |
1082 | ||
1e6feb95 VZ |
1083 | void wxScrollHelper::HandleOnMouseWheel(wxMouseEvent& event) |
1084 | { | |
d2c52078 | 1085 | m_wheelRotation += event.GetWheelRotation(); |
1e6feb95 | 1086 | int lines = m_wheelRotation / event.GetWheelDelta(); |
d2c52078 RD |
1087 | m_wheelRotation -= lines * event.GetWheelDelta(); |
1088 | ||
1e6feb95 VZ |
1089 | if (lines != 0) |
1090 | { | |
d2c52078 | 1091 | lines *= event.GetLinesPerAction(); |
1e6feb95 | 1092 | |
b6b85bdc JS |
1093 | wxScrollWinEvent newEvent; |
1094 | ||
ac6f6ffc | 1095 | newEvent.SetPosition(0); |
b6b85bdc JS |
1096 | newEvent.SetOrientation(wxVERTICAL); |
1097 | newEvent.m_eventObject = m_win; | |
1098 | if (lines > 0) | |
1099 | newEvent.m_eventType = wxEVT_SCROLLWIN_LINEUP; | |
1100 | else | |
1101 | newEvent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN; | |
1102 | ||
1103 | int times = abs(lines); | |
1104 | for (; times > 0; times --) | |
1105 | m_win->GetEventHandler()->ProcessEvent(newEvent); | |
1106 | ||
1107 | /* Old Way */ | |
1108 | // int vsx, vsy; | |
1109 | // GetViewStart(&vsx, &vsy); | |
ac6f6ffc | 1110 | // Scroll(-1, vsy - lines); |
d2c52078 RD |
1111 | } |
1112 | } | |
1113 | ||
e421922f VZ |
1114 | #endif // wxUSE_MOUSEWHEEL |
1115 | ||
1e6feb95 VZ |
1116 | // ---------------------------------------------------------------------------- |
1117 | // wxGenericScrolledWindow implementation | |
1118 | // ---------------------------------------------------------------------------- | |
1119 | ||
1120 | IMPLEMENT_DYNAMIC_CLASS(wxGenericScrolledWindow, wxPanel) | |
1121 | ||
349efbaa VZ |
1122 | BEGIN_EVENT_TABLE(wxGenericScrolledWindow, wxPanel) |
1123 | EVT_PAINT(wxGenericScrolledWindow::OnPaint) | |
1124 | END_EVENT_TABLE() | |
1125 | ||
1e6feb95 VZ |
1126 | bool wxGenericScrolledWindow::Create(wxWindow *parent, |
1127 | wxWindowID id, | |
1128 | const wxPoint& pos, | |
1129 | const wxSize& size, | |
1130 | long style, | |
1131 | const wxString& name) | |
1132 | { | |
1133 | m_targetWindow = this; | |
1134 | ||
1135 | bool ok = wxPanel::Create(parent, id, pos, size, style, name); | |
1136 | ||
1e6feb95 VZ |
1137 | return ok; |
1138 | } | |
1139 | ||
1140 | wxGenericScrolledWindow::~wxGenericScrolledWindow() | |
1141 | { | |
1142 | } | |
d2c52078 | 1143 | |
30486297 RD |
1144 | bool wxGenericScrolledWindow::Layout() |
1145 | { | |
566d84a7 | 1146 | if (GetSizer() && m_targetWindow == this) |
30486297 | 1147 | { |
566d84a7 RL |
1148 | // If we're the scroll target, take into account the |
1149 | // virtual size and scrolled position of the window. | |
1150 | ||
30486297 RD |
1151 | int x, y, w, h; |
1152 | CalcScrolledPosition(0,0, &x,&y); | |
1153 | GetVirtualSize(&w, &h); | |
1154 | GetSizer()->SetDimension(x, y, w, h); | |
1155 | return TRUE; | |
1156 | } | |
7152f0c6 VZ |
1157 | |
1158 | // fall back to default for LayoutConstraints | |
1159 | return wxPanel::Layout(); | |
30486297 RD |
1160 | } |
1161 | ||
566d84a7 RL |
1162 | void wxGenericScrolledWindow::DoSetVirtualSize( int x, int y ) |
1163 | { | |
1164 | wxPanel::DoSetVirtualSize( x, y ); | |
1165 | AdjustScrollbars(); | |
1166 | } | |
1167 | ||
349efbaa VZ |
1168 | void wxGenericScrolledWindow::OnPaint(wxPaintEvent& event) |
1169 | { | |
1170 | // the user code didn't really draw the window if we got here, so set this | |
1171 | // flag to try to call OnDraw() later | |
1172 | m_handler->ResetDrawnFlag(); | |
1173 | ||
1174 | event.Skip(); | |
1175 | } | |
1176 | ||
0cf5b099 VZ |
1177 | #ifdef __WXMSW__ |
1178 | long | |
1179 | wxGenericScrolledWindow::MSWWindowProc(WXUINT nMsg, | |
1180 | WXWPARAM wParam, | |
1181 | WXLPARAM lParam) | |
1182 | { | |
1183 | long rc = wxPanel::MSWWindowProc(nMsg, wParam, lParam); | |
1184 | ||
1185 | // we need to process arrows ourselves for scrolling | |
1186 | if ( nMsg == WM_GETDLGCODE ) | |
1187 | { | |
1188 | rc |= DLGC_WANTARROWS; | |
1189 | } | |
1190 | ||
1191 | return rc; | |
1192 | } | |
1193 | ||
1194 | #endif // __WXMSW__ | |
1195 | ||
1e6feb95 | 1196 | #if WXWIN_COMPATIBILITY |
349efbaa | 1197 | |
1e6feb95 VZ |
1198 | void wxGenericScrolledWindow::GetScrollUnitsPerPage (int *x_page, int *y_page) const |
1199 | { | |
1200 | *x_page = GetScrollPageSize(wxHORIZONTAL); | |
1201 | *y_page = GetScrollPageSize(wxVERTICAL); | |
1202 | } | |
d2c52078 | 1203 | |
1e6feb95 VZ |
1204 | void wxGenericScrolledWindow::CalcUnscrolledPosition(int x, int y, float *xx, float *yy) const |
1205 | { | |
1206 | if ( xx ) | |
1207 | *xx = (float)(x + m_xScrollPosition * m_xScrollPixelsPerLine); | |
1208 | if ( yy ) | |
1209 | *yy = (float)(y + m_yScrollPosition * m_yScrollPixelsPerLine); | |
1210 | } | |
349efbaa | 1211 | |
1e6feb95 | 1212 | #endif // WXWIN_COMPATIBILITY |
d2c52078 | 1213 | |
3a8c693a VZ |
1214 | #endif // !wxGTK |
1215 | ||
566d84a7 | 1216 | // vi:sts=4:sw=4:et |