]> git.saurik.com Git - wxWidgets.git/blob - src/generic/scrolwin.cpp
forced redraw before scrolling
[wxWidgets.git] / src / generic / scrolwin.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/scrolwin.cpp
3 // Purpose: wxGenericScrolledWindow implementation
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "scrolwin.h"
22 #endif
23
24 #ifdef __VMS
25 #define XtDisplay XTDISPLAY
26 #endif
27
28 // For compilers that support precompilation, includes "wx.h".
29 #include "wx/wxprec.h"
30
31 #ifdef __BORLANDC__
32 #pragma hdrstop
33 #endif
34
35 #include "wx/utils.h"
36 #include "wx/dcclient.h"
37
38 #include "wx/generic/scrolwin.h"
39 #include "wx/panel.h"
40
41 #ifdef __WXMSW__
42 #include "windows.h"
43 #endif
44
45 #ifdef __WXMOTIF__
46 // For wxRETAINED implementation
47 #ifdef __VMS__ //VMS's Xm.h is not (yet) compatible with C++
48 //This code switches off the compiler warnings
49 # pragma message disable nosimpint
50 #endif
51 #include <Xm/Xm.h>
52 #ifdef __VMS__
53 # pragma message enable nosimpint
54 #endif
55 #endif
56
57 #ifndef __WXGTK__
58 #include "wx/scrolwin.h"
59 IMPLEMENT_CLASS(wxScrolledWindow, wxGenericScrolledWindow)
60 #endif
61
62 // ----------------------------------------------------------------------------
63 // event tables
64 // ----------------------------------------------------------------------------
65
66 BEGIN_EVENT_TABLE(wxGenericScrolledWindow, wxPanel)
67 EVT_SCROLLWIN(wxGenericScrolledWindow::OnScroll)
68 EVT_SIZE(wxGenericScrolledWindow::OnSize)
69 EVT_PAINT(wxGenericScrolledWindow::OnPaint)
70 EVT_CHAR(wxGenericScrolledWindow::OnChar)
71 EVT_MOUSEWHEEL(wxGenericScrolledWindow::OnMouseWheel)
72 END_EVENT_TABLE()
73
74 IMPLEMENT_DYNAMIC_CLASS(wxGenericScrolledWindow, wxPanel)
75
76 // ============================================================================
77 // implementation
78 // ============================================================================
79
80 // ----------------------------------------------------------------------------
81 // wxGenericScrolledWindow creation
82 // ----------------------------------------------------------------------------
83
84 wxGenericScrolledWindow::wxGenericScrolledWindow()
85 {
86 m_xScrollPixelsPerLine = 0;
87 m_yScrollPixelsPerLine = 0;
88 m_xScrollingEnabled = TRUE;
89 m_yScrollingEnabled = TRUE;
90 m_xScrollPosition = 0;
91 m_yScrollPosition = 0;
92 m_xScrollLines = 0;
93 m_yScrollLines = 0;
94 m_xScrollLinesPerPage = 0;
95 m_yScrollLinesPerPage = 0;
96 m_scaleX = 1.0;
97 m_scaleY = 1.0;
98 m_wheelRotation = 0;
99 m_targetWindow = (wxWindow*) NULL;
100 }
101
102 bool wxGenericScrolledWindow::Create(wxWindow *parent,
103 wxWindowID id,
104 const wxPoint& pos,
105 const wxSize& size,
106 long style,
107 const wxString& name)
108 {
109 m_xScrollPixelsPerLine = 0;
110 m_yScrollPixelsPerLine = 0;
111 m_xScrollingEnabled = TRUE;
112 m_yScrollingEnabled = TRUE;
113 m_xScrollPosition = 0;
114 m_yScrollPosition = 0;
115 m_xScrollLines = 0;
116 m_yScrollLines = 0;
117 m_xScrollLinesPerPage = 0;
118 m_yScrollLinesPerPage = 0;
119 m_scaleX = 1.0;
120 m_scaleY = 1.0;
121 m_wheelRotation = 0;
122
123 m_targetWindow = this;
124
125 bool ok = wxPanel::Create(parent, id, pos, size, style, name);
126
127 #ifdef __WXMSW__
128 // we need to process arrows ourselves for scrolling
129 m_lDlgCode |= DLGC_WANTARROWS;
130 #endif // __WXMSW__
131
132 return ok;
133 }
134
135 wxGenericScrolledWindow::~wxGenericScrolledWindow()
136 {
137 }
138
139 // ----------------------------------------------------------------------------
140 // setting scrolling parameters
141 // ----------------------------------------------------------------------------
142
143 /*
144 * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
145 * noUnitsX/noUnitsY: : no. units per scrollbar
146 */
147 void wxGenericScrolledWindow::SetScrollbars (int pixelsPerUnitX, int pixelsPerUnitY,
148 int noUnitsX, int noUnitsY,
149 int xPos, int yPos, bool noRefresh )
150 {
151 int xpos, ypos;
152
153 CalcUnscrolledPosition(xPos, yPos, &xpos, &ypos);
154 bool do_refresh =
155 (
156 (noUnitsX != 0 && m_xScrollLines == 0) ||
157 (noUnitsX < m_xScrollLines && xpos > pixelsPerUnitX*noUnitsX) ||
158
159 (noUnitsY != 0 && m_yScrollLines == 0) ||
160 (noUnitsY < m_yScrollLines && ypos > pixelsPerUnitY*noUnitsY) ||
161 (xPos != m_xScrollPosition) ||
162 (yPos != m_yScrollPosition)
163 // (pixelsPerUnitX != m_xScrollPixelsPerLine) ||
164 // (pixelsPerUnitY != m_yScrollPixelsPerLine)
165 );
166
167 m_xScrollPixelsPerLine = pixelsPerUnitX;
168 m_yScrollPixelsPerLine = pixelsPerUnitY;
169 m_xScrollPosition = xPos;
170 m_yScrollPosition = yPos;
171 m_xScrollLines = noUnitsX;
172 m_yScrollLines = noUnitsY;
173
174 #ifdef __WXMOTIF__
175 // Sorry, some Motif-specific code to implement a backing pixmap
176 // for the wxRETAINED style. Implementing a backing store can't
177 // be entirely generic because it relies on the wxWindowDC implementation
178 // to duplicate X drawing calls for the backing pixmap.
179
180 if ((m_windowStyle & wxRETAINED) == wxRETAINED)
181 {
182 Display* dpy = XtDisplay((Widget) GetMainWidget());
183
184 int totalPixelWidth = m_xScrollLines * m_xScrollPixelsPerLine;
185 int totalPixelHeight = m_yScrollLines * m_yScrollPixelsPerLine;
186 if (m_backingPixmap &&
187 !((m_pixmapWidth == totalPixelWidth) &&
188 (m_pixmapHeight == totalPixelHeight)))
189 {
190 XFreePixmap (dpy, (Pixmap) m_backingPixmap);
191 m_backingPixmap = (WXPixmap) 0;
192 }
193
194 if (!m_backingPixmap &&
195 (noUnitsX != 0) && (noUnitsY != 0))
196 {
197 int depth = wxDisplayDepth();
198 m_pixmapWidth = totalPixelWidth;
199 m_pixmapHeight = totalPixelHeight;
200 m_backingPixmap = (WXPixmap) XCreatePixmap (dpy, RootWindow (dpy, DefaultScreen (dpy)),
201 m_pixmapWidth, m_pixmapHeight, depth);
202 }
203
204 }
205 #endif // Motif
206
207 AdjustScrollbars();
208
209 if (do_refresh && !noRefresh)
210 m_targetWindow->Refresh();
211
212 #ifdef __WXMSW__
213 // GRG: if this turns out to be really necessary, we could
214 // at least move it to the above if { ... } so that it is
215 // only done if noRefresh = FALSE (the default). OTOH, if
216 // this doesn't break anything, which seems to be the
217 // case, we could just leave it out.
218
219 // Necessary?
220 // UpdateWindow ((HWND) m_targetWindow->GetHWND());
221 #endif
222 #ifdef __WXMAC__
223 m_targetWindow->MacUpdateImmediately() ;
224 #endif
225 }
226
227 // ----------------------------------------------------------------------------
228 // target window handling
229 // ----------------------------------------------------------------------------
230
231 void wxGenericScrolledWindow::SetTargetWindow( wxWindow *target )
232 {
233 wxASSERT_MSG( target, wxT("target window must not be NULL") );
234 m_targetWindow = target;
235 }
236
237 wxWindow *wxGenericScrolledWindow::GetTargetWindow()
238 {
239 return m_targetWindow;
240 }
241
242 // ----------------------------------------------------------------------------
243 // scrolling implementation itself
244 // ----------------------------------------------------------------------------
245
246 void wxGenericScrolledWindow::OnScroll(wxScrollWinEvent& event)
247 {
248 int orient = event.GetOrientation();
249
250 int nScrollInc = CalcScrollInc(event);
251 if (nScrollInc == 0) return;
252
253 if (orient == wxHORIZONTAL)
254 {
255 int newPos = m_xScrollPosition + nScrollInc;
256 SetScrollPos(wxHORIZONTAL, newPos, TRUE );
257 }
258 else
259 {
260 int newPos = m_yScrollPosition + nScrollInc;
261 SetScrollPos(wxVERTICAL, newPos, TRUE );
262 }
263
264 if (orient == wxHORIZONTAL)
265 {
266 m_xScrollPosition += nScrollInc;
267 }
268 else
269 {
270 m_yScrollPosition += nScrollInc;
271 }
272
273 if (orient == wxHORIZONTAL)
274 {
275 if (m_xScrollingEnabled)
276 m_targetWindow->ScrollWindow(-m_xScrollPixelsPerLine * nScrollInc, 0, (const wxRect *) NULL);
277 else
278 m_targetWindow->Refresh();
279 }
280 else
281 {
282 if (m_yScrollingEnabled)
283 m_targetWindow->ScrollWindow(0, -m_yScrollPixelsPerLine * nScrollInc, (const wxRect *) NULL);
284 else
285 m_targetWindow->Refresh();
286 }
287 #ifdef __WXMAC__
288 m_targetWindow->MacUpdateImmediately() ;
289 #endif
290 }
291
292 int wxGenericScrolledWindow::CalcScrollInc(wxScrollWinEvent& event)
293 {
294 int pos = event.GetPosition();
295 int orient = event.GetOrientation();
296
297 int nScrollInc = 0;
298 if (event.GetEventType() == wxEVT_SCROLLWIN_TOP)
299 {
300 if (orient == wxHORIZONTAL)
301 nScrollInc = - m_xScrollPosition;
302 else
303 nScrollInc = - m_yScrollPosition;
304 } else
305 if (event.GetEventType() == wxEVT_SCROLLWIN_BOTTOM)
306 {
307 if (orient == wxHORIZONTAL)
308 nScrollInc = m_xScrollLines - m_xScrollPosition;
309 else
310 nScrollInc = m_yScrollLines - m_yScrollPosition;
311 } else
312 if (event.GetEventType() == wxEVT_SCROLLWIN_LINEUP)
313 {
314 nScrollInc = -1;
315 } else
316 if (event.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN)
317 {
318 nScrollInc = 1;
319 } else
320 if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEUP)
321 {
322 if (orient == wxHORIZONTAL)
323 nScrollInc = -GetScrollPageSize(wxHORIZONTAL);
324 else
325 nScrollInc = -GetScrollPageSize(wxVERTICAL);
326 } else
327 if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN)
328 {
329 if (orient == wxHORIZONTAL)
330 nScrollInc = GetScrollPageSize(wxHORIZONTAL);
331 else
332 nScrollInc = GetScrollPageSize(wxVERTICAL);
333 } else
334 if ((event.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK) ||
335 (event.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE))
336 {
337 if (orient == wxHORIZONTAL)
338 nScrollInc = pos - m_xScrollPosition;
339 else
340 nScrollInc = pos - m_yScrollPosition;
341 }
342
343 if (orient == wxHORIZONTAL)
344 {
345 if (m_xScrollPixelsPerLine > 0)
346 {
347 int w, h;
348 m_targetWindow->GetClientSize(&w, &h);
349
350 int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine;
351 int noPositions = (int) ( ((nMaxWidth - w)/(double)m_xScrollPixelsPerLine) + 0.5 );
352 if (noPositions < 0)
353 noPositions = 0;
354
355 if ( (m_xScrollPosition + nScrollInc) < 0 )
356 nScrollInc = -m_xScrollPosition; // As -ve as we can go
357 else if ( (m_xScrollPosition + nScrollInc) > noPositions )
358 nScrollInc = noPositions - m_xScrollPosition; // As +ve as we can go
359 }
360 else
361 m_targetWindow->Refresh();
362 }
363 else
364 {
365 if (m_yScrollPixelsPerLine > 0)
366 {
367 int w, h;
368 m_targetWindow->GetClientSize(&w, &h);
369
370 int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine;
371 int noPositions = (int) ( ((nMaxHeight - h)/(double)m_yScrollPixelsPerLine) + 0.5 );
372 if (noPositions < 0)
373 noPositions = 0;
374
375 if ( (m_yScrollPosition + nScrollInc) < 0 )
376 nScrollInc = -m_yScrollPosition; // As -ve as we can go
377 else if ( (m_yScrollPosition + nScrollInc) > noPositions )
378 nScrollInc = noPositions - m_yScrollPosition; // As +ve as we can go
379 }
380 else
381 m_targetWindow->Refresh();
382 }
383
384 return nScrollInc;
385 }
386
387 // Adjust the scrollbars - new version.
388 void wxGenericScrolledWindow::AdjustScrollbars()
389 {
390 #ifdef __WXMAC__
391 m_targetWindow->MacUpdateImmediately();
392 #endif
393
394 int w, h;
395 m_targetWindow->GetClientSize(&w, &h);
396
397 int oldXScroll = m_xScrollPosition;
398 int oldYScroll = m_yScrollPosition;
399
400 if (m_xScrollLines > 0)
401 {
402 // Calculate page size i.e. number of scroll units you get on the
403 // current client window
404 int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 );
405 if (noPagePositions < 1) noPagePositions = 1;
406
407 // Correct position if greater than extent of canvas minus
408 // the visible portion of it or if below zero
409 m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition);
410 m_xScrollPosition = wxMax( 0, m_xScrollPosition );
411
412 SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, m_xScrollLines);
413 // The amount by which we scroll when paging
414 SetScrollPageSize(wxHORIZONTAL, noPagePositions);
415 }
416 else
417 {
418 m_xScrollPosition = 0;
419 SetScrollbar (wxHORIZONTAL, 0, 0, 0, FALSE);
420 }
421
422 if (m_yScrollLines > 0)
423 {
424 // Calculate page size i.e. number of scroll units you get on the
425 // current client window
426 int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 );
427 if (noPagePositions < 1) noPagePositions = 1;
428
429 // Correct position if greater than extent of canvas minus
430 // the visible portion of it or if below zero
431 m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition );
432 m_yScrollPosition = wxMax( 0, m_yScrollPosition );
433
434 SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, m_yScrollLines);
435 // The amount by which we scroll when paging
436 SetScrollPageSize(wxVERTICAL, noPagePositions);
437 }
438 else
439 {
440 m_yScrollPosition = 0;
441 SetScrollbar (wxVERTICAL, 0, 0, 0, FALSE);
442 }
443
444 if (oldXScroll != m_xScrollPosition)
445 {
446 if (m_xScrollingEnabled)
447 m_targetWindow->ScrollWindow( m_xScrollPixelsPerLine * (oldXScroll-m_xScrollPosition), 0, (const wxRect *) NULL );
448 else
449 m_targetWindow->Refresh();
450 }
451
452 if (oldYScroll != m_yScrollPosition)
453 {
454 if (m_yScrollingEnabled)
455 m_targetWindow->ScrollWindow( 0, m_yScrollPixelsPerLine * (oldYScroll-m_yScrollPosition), (const wxRect *) NULL );
456 else
457 m_targetWindow->Refresh();
458 }
459
460 #ifdef __WXMAC__
461 m_targetWindow->MacUpdateImmediately();
462 #endif
463 }
464
465 // Override this function if you don't want to have wxGenericScrolledWindow
466 // automatically change the origin according to the scroll position.
467 void wxGenericScrolledWindow::PrepareDC(wxDC& dc)
468 {
469 dc.SetDeviceOrigin( -m_xScrollPosition * m_xScrollPixelsPerLine,
470 -m_yScrollPosition * m_yScrollPixelsPerLine );
471 dc.SetUserScale( m_scaleX, m_scaleY );
472 }
473
474 #if WXWIN_COMPATIBILITY
475 void wxGenericScrolledWindow::GetScrollUnitsPerPage (int *x_page, int *y_page) const
476 {
477 *x_page = GetScrollPageSize(wxHORIZONTAL);
478 *y_page = GetScrollPageSize(wxVERTICAL);
479 }
480
481 void wxGenericScrolledWindow::CalcUnscrolledPosition(int x, int y, float *xx, float *yy) const
482 {
483 if ( xx )
484 *xx = (float)(x + m_xScrollPosition * m_xScrollPixelsPerLine);
485 if ( yy )
486 *yy = (float)(y + m_yScrollPosition * m_yScrollPixelsPerLine);
487 }
488 #endif // WXWIN_COMPATIBILITY
489
490 void wxGenericScrolledWindow::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const
491 {
492 if ( x_unit )
493 *x_unit = m_xScrollPixelsPerLine;
494 if ( y_unit )
495 *y_unit = m_yScrollPixelsPerLine;
496 }
497
498 int wxGenericScrolledWindow::GetScrollPageSize(int orient) const
499 {
500 if ( orient == wxHORIZONTAL )
501 return m_xScrollLinesPerPage;
502 else
503 return m_yScrollLinesPerPage;
504 }
505
506 void wxGenericScrolledWindow::SetScrollPageSize(int orient, int pageSize)
507 {
508 if ( orient == wxHORIZONTAL )
509 m_xScrollLinesPerPage = pageSize;
510 else
511 m_yScrollLinesPerPage = pageSize;
512 }
513
514 /*
515 * Scroll to given position (scroll position, not pixel position)
516 */
517 void wxGenericScrolledWindow::Scroll( int x_pos, int y_pos )
518 {
519 if (!m_targetWindow)
520 return;
521
522 if (((x_pos == -1) || (x_pos == m_xScrollPosition)) &&
523 ((y_pos == -1) || (y_pos == m_yScrollPosition))) return;
524
525 #ifdef __WXMAC__
526 m_targetWindow->MacUpdateImmediately();
527 #endif
528
529 int w, h;
530 m_targetWindow->GetClientSize(&w, &h);
531
532 if ((x_pos != -1) && (m_xScrollPixelsPerLine))
533 {
534 int old_x = m_xScrollPosition;
535 m_xScrollPosition = x_pos;
536
537 // Calculate page size i.e. number of scroll units you get on the
538 // current client window
539 int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 );
540 if (noPagePositions < 1) noPagePositions = 1;
541
542 // Correct position if greater than extent of canvas minus
543 // the visible portion of it or if below zero
544 m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition );
545 m_xScrollPosition = wxMax( 0, m_xScrollPosition );
546
547 if (old_x != m_xScrollPosition) {
548 m_targetWindow->SetScrollPos( wxHORIZONTAL, m_xScrollPosition, TRUE );
549 m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0 );
550 }
551 }
552 if ((y_pos != -1) && (m_yScrollPixelsPerLine))
553 {
554 int old_y = m_yScrollPosition;
555 m_yScrollPosition = y_pos;
556
557 // Calculate page size i.e. number of scroll units you get on the
558 // current client window
559 int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 );
560 if (noPagePositions < 1) noPagePositions = 1;
561
562 // Correct position if greater than extent of canvas minus
563 // the visible portion of it or if below zero
564 m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition );
565 m_yScrollPosition = wxMax( 0, m_yScrollPosition );
566
567 if (old_y != m_yScrollPosition) {
568 m_targetWindow->SetScrollPos( wxVERTICAL, m_yScrollPosition, TRUE );
569 m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine );
570 }
571 }
572
573 #ifdef __WXMAC__
574 m_targetWindow->MacUpdateImmediately();
575 #endif
576
577 }
578
579 void wxGenericScrolledWindow::EnableScrolling (bool x_scroll, bool y_scroll)
580 {
581 m_xScrollingEnabled = x_scroll;
582 m_yScrollingEnabled = y_scroll;
583 }
584
585 void wxGenericScrolledWindow::GetVirtualSize (int *x, int *y) const
586 {
587 if ( x )
588 *x = m_xScrollPixelsPerLine * m_xScrollLines;
589 if ( y )
590 *y = m_yScrollPixelsPerLine * m_yScrollLines;
591 }
592
593 // Where the current view starts from
594 void wxGenericScrolledWindow::GetViewStart (int *x, int *y) const
595 {
596 if ( x )
597 *x = m_xScrollPosition;
598 if ( y )
599 *y = m_yScrollPosition;
600 }
601
602 void wxGenericScrolledWindow::CalcScrolledPosition(int x, int y, int *xx, int *yy) const
603 {
604 if ( xx )
605 *xx = x - m_xScrollPosition * m_xScrollPixelsPerLine;
606 if ( yy )
607 *yy = y - m_yScrollPosition * m_yScrollPixelsPerLine;
608 }
609
610 void wxGenericScrolledWindow::CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const
611 {
612 if ( xx )
613 *xx = x + m_xScrollPosition * m_xScrollPixelsPerLine;
614 if ( yy )
615 *yy = y + m_yScrollPosition * m_yScrollPixelsPerLine;
616 }
617
618 // ----------------------------------------------------------------------------
619 // event handlers
620 // ----------------------------------------------------------------------------
621
622 // Default OnSize resets scrollbars, if any
623 void wxGenericScrolledWindow::OnSize(wxSizeEvent& WXUNUSED(event))
624 {
625 #if wxUSE_CONSTRAINTS
626 if (GetAutoLayout())
627 Layout();
628 #endif
629
630 AdjustScrollbars();
631 }
632
633 // This calls OnDraw, having adjusted the origin according to the current
634 // scroll position
635 void wxGenericScrolledWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
636 {
637 wxPaintDC dc(this);
638 PrepareDC(dc);
639
640 OnDraw(dc);
641 }
642
643 // kbd handling: notice that we use OnChar() and not OnKeyDown() for
644 // compatibility here - if we used OnKeyDown(), the programs which process
645 // arrows themselves in their OnChar() would never get the message and like
646 // this they always have the priority
647 void wxGenericScrolledWindow::OnChar(wxKeyEvent& event)
648 {
649 int stx, sty, // view origin
650 szx, szy, // view size (total)
651 clix, cliy; // view size (on screen)
652
653 ViewStart(&stx, &sty);
654 GetClientSize(&clix, &cliy);
655 GetVirtualSize(&szx, &szy);
656
657 if( m_xScrollPixelsPerLine )
658 {
659 clix /= m_xScrollPixelsPerLine;
660 szx /= m_xScrollPixelsPerLine;
661 }
662 else
663 {
664 clix = 0;
665 szx = -1;
666 }
667 if( m_yScrollPixelsPerLine )
668 {
669 cliy /= m_yScrollPixelsPerLine;
670 szy /= m_yScrollPixelsPerLine;
671 }
672 else
673 {
674 cliy = 0;
675 szy = -1;
676 }
677
678 int dsty;
679 switch ( event.KeyCode() )
680 {
681 case WXK_PAGEUP:
682 case WXK_PRIOR:
683 dsty = sty - (5 * cliy / 6);
684 Scroll(-1, (dsty == -1) ? 0 : dsty);
685 break;
686
687 case WXK_PAGEDOWN:
688 case WXK_NEXT:
689 Scroll(-1, sty + (5 * cliy / 6));
690 break;
691
692 case WXK_HOME:
693 Scroll(0, event.ControlDown() ? 0 : -1);
694 break;
695
696 case WXK_END:
697 Scroll(szx - clix, event.ControlDown() ? szy - cliy : -1);
698 break;
699
700 case WXK_UP:
701 Scroll(-1, sty - 1);
702 break;
703
704 case WXK_DOWN:
705 Scroll(-1, sty + 1);
706 break;
707
708 case WXK_LEFT:
709 Scroll(stx - 1, -1);
710 break;
711
712 case WXK_RIGHT:
713 Scroll(stx + 1, -1);
714 break;
715
716 default:
717 // not for us
718 event.Skip();
719 }
720 }
721
722
723 void wxGenericScrolledWindow::OnMouseWheel(wxMouseEvent& event)
724 {
725 int lines;
726 int vsx, vsy;
727
728 m_wheelRotation += event.GetWheelRotation();
729 lines = m_wheelRotation / event.GetWheelDelta();
730 m_wheelRotation -= lines * event.GetWheelDelta();
731
732 if (lines != 0) {
733 lines *= event.GetLinesPerAction();
734 GetViewStart(&vsx, &vsy);
735 Scroll(-1, vsy - lines);
736 }
737 }
738
739
740
741