]> git.saurik.com Git - wxWidgets.git/blob - src/generic/scrolwin.cpp
Added mouse wheel support for MSW. It generates a wxMouseEvent with a
[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 int w, h;
391 m_targetWindow->GetClientSize(&w, &h);
392
393 int oldXScroll = m_xScrollPosition;
394 int oldYScroll = m_yScrollPosition;
395
396 if (m_xScrollLines > 0)
397 {
398 // Calculate page size i.e. number of scroll units you get on the
399 // current client window
400 int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 );
401 if (noPagePositions < 1) noPagePositions = 1;
402
403 // Correct position if greater than extent of canvas minus
404 // the visible portion of it or if below zero
405 m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition);
406 m_xScrollPosition = wxMax( 0, m_xScrollPosition );
407
408 SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, m_xScrollLines);
409 // The amount by which we scroll when paging
410 SetScrollPageSize(wxHORIZONTAL, noPagePositions);
411 }
412 else
413 {
414 m_xScrollPosition = 0;
415 SetScrollbar (wxHORIZONTAL, 0, 0, 0, FALSE);
416 }
417
418 if (m_yScrollLines > 0)
419 {
420 // Calculate page size i.e. number of scroll units you get on the
421 // current client window
422 int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 );
423 if (noPagePositions < 1) noPagePositions = 1;
424
425 // Correct position if greater than extent of canvas minus
426 // the visible portion of it or if below zero
427 m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition );
428 m_yScrollPosition = wxMax( 0, m_yScrollPosition );
429
430 SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, m_yScrollLines);
431 // The amount by which we scroll when paging
432 SetScrollPageSize(wxVERTICAL, noPagePositions);
433 }
434 else
435 {
436 m_yScrollPosition = 0;
437 SetScrollbar (wxVERTICAL, 0, 0, 0, FALSE);
438 }
439
440 if (oldXScroll != m_xScrollPosition)
441 {
442 if (m_xScrollingEnabled)
443 m_targetWindow->ScrollWindow( m_xScrollPixelsPerLine * (oldXScroll-m_xScrollPosition), 0, (const wxRect *) NULL );
444 else
445 m_targetWindow->Refresh();
446 }
447
448 if (oldYScroll != m_yScrollPosition)
449 {
450 if (m_yScrollingEnabled)
451 m_targetWindow->ScrollWindow( 0, m_yScrollPixelsPerLine * (oldYScroll-m_yScrollPosition), (const wxRect *) NULL );
452 else
453 m_targetWindow->Refresh();
454 }
455 }
456
457 // Override this function if you don't want to have wxGenericScrolledWindow
458 // automatically change the origin according to the scroll position.
459 void wxGenericScrolledWindow::PrepareDC(wxDC& dc)
460 {
461 dc.SetDeviceOrigin( -m_xScrollPosition * m_xScrollPixelsPerLine,
462 -m_yScrollPosition * m_yScrollPixelsPerLine );
463 dc.SetUserScale( m_scaleX, m_scaleY );
464 }
465
466 #if WXWIN_COMPATIBILITY
467 void wxGenericScrolledWindow::GetScrollUnitsPerPage (int *x_page, int *y_page) const
468 {
469 *x_page = GetScrollPageSize(wxHORIZONTAL);
470 *y_page = GetScrollPageSize(wxVERTICAL);
471 }
472
473 void wxGenericScrolledWindow::CalcUnscrolledPosition(int x, int y, float *xx, float *yy) const
474 {
475 if ( xx )
476 *xx = (float)(x + m_xScrollPosition * m_xScrollPixelsPerLine);
477 if ( yy )
478 *yy = (float)(y + m_yScrollPosition * m_yScrollPixelsPerLine);
479 }
480 #endif // WXWIN_COMPATIBILITY
481
482 void wxGenericScrolledWindow::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const
483 {
484 if ( x_unit )
485 *x_unit = m_xScrollPixelsPerLine;
486 if ( y_unit )
487 *y_unit = m_yScrollPixelsPerLine;
488 }
489
490 int wxGenericScrolledWindow::GetScrollPageSize(int orient) const
491 {
492 if ( orient == wxHORIZONTAL )
493 return m_xScrollLinesPerPage;
494 else
495 return m_yScrollLinesPerPage;
496 }
497
498 void wxGenericScrolledWindow::SetScrollPageSize(int orient, int pageSize)
499 {
500 if ( orient == wxHORIZONTAL )
501 m_xScrollLinesPerPage = pageSize;
502 else
503 m_yScrollLinesPerPage = pageSize;
504 }
505
506 /*
507 * Scroll to given position (scroll position, not pixel position)
508 */
509 void wxGenericScrolledWindow::Scroll( int x_pos, int y_pos )
510 {
511 if (!m_targetWindow)
512 return;
513
514 if (((x_pos == -1) || (x_pos == m_xScrollPosition)) &&
515 ((y_pos == -1) || (y_pos == m_yScrollPosition))) return;
516
517 int w, h;
518 m_targetWindow->GetClientSize(&w, &h);
519
520 if ((x_pos != -1) && (m_xScrollPixelsPerLine))
521 {
522 int old_x = m_xScrollPosition;
523 m_xScrollPosition = x_pos;
524
525 // Calculate page size i.e. number of scroll units you get on the
526 // current client window
527 int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 );
528 if (noPagePositions < 1) noPagePositions = 1;
529
530 // Correct position if greater than extent of canvas minus
531 // the visible portion of it or if below zero
532 m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition );
533 m_xScrollPosition = wxMax( 0, m_xScrollPosition );
534
535 if (old_x != m_xScrollPosition) {
536 m_targetWindow->SetScrollPos( wxHORIZONTAL, m_xScrollPosition, TRUE );
537 m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0 );
538 }
539 }
540 if ((y_pos != -1) && (m_yScrollPixelsPerLine))
541 {
542 int old_y = m_yScrollPosition;
543 m_yScrollPosition = y_pos;
544
545 // Calculate page size i.e. number of scroll units you get on the
546 // current client window
547 int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 );
548 if (noPagePositions < 1) noPagePositions = 1;
549
550 // Correct position if greater than extent of canvas minus
551 // the visible portion of it or if below zero
552 m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition );
553 m_yScrollPosition = wxMax( 0, m_yScrollPosition );
554
555 if (old_y != m_yScrollPosition) {
556 m_targetWindow->SetScrollPos( wxVERTICAL, m_yScrollPosition, TRUE );
557 m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine );
558 }
559 }
560
561 #ifdef __WXMAC__
562 m_targetWindow->MacUpdateImmediately();
563 #endif
564 }
565
566 void wxGenericScrolledWindow::EnableScrolling (bool x_scroll, bool y_scroll)
567 {
568 m_xScrollingEnabled = x_scroll;
569 m_yScrollingEnabled = y_scroll;
570 }
571
572 void wxGenericScrolledWindow::GetVirtualSize (int *x, int *y) const
573 {
574 if ( x )
575 *x = m_xScrollPixelsPerLine * m_xScrollLines;
576 if ( y )
577 *y = m_yScrollPixelsPerLine * m_yScrollLines;
578 }
579
580 // Where the current view starts from
581 void wxGenericScrolledWindow::GetViewStart (int *x, int *y) const
582 {
583 if ( x )
584 *x = m_xScrollPosition;
585 if ( y )
586 *y = m_yScrollPosition;
587 }
588
589 void wxGenericScrolledWindow::CalcScrolledPosition(int x, int y, int *xx, int *yy) const
590 {
591 if ( xx )
592 *xx = x - m_xScrollPosition * m_xScrollPixelsPerLine;
593 if ( yy )
594 *yy = y - m_yScrollPosition * m_yScrollPixelsPerLine;
595 }
596
597 void wxGenericScrolledWindow::CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const
598 {
599 if ( xx )
600 *xx = x + m_xScrollPosition * m_xScrollPixelsPerLine;
601 if ( yy )
602 *yy = y + m_yScrollPosition * m_yScrollPixelsPerLine;
603 }
604
605 // ----------------------------------------------------------------------------
606 // event handlers
607 // ----------------------------------------------------------------------------
608
609 // Default OnSize resets scrollbars, if any
610 void wxGenericScrolledWindow::OnSize(wxSizeEvent& WXUNUSED(event))
611 {
612 #if wxUSE_CONSTRAINTS
613 if (GetAutoLayout())
614 Layout();
615 #endif
616
617 AdjustScrollbars();
618 }
619
620 // This calls OnDraw, having adjusted the origin according to the current
621 // scroll position
622 void wxGenericScrolledWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
623 {
624 wxPaintDC dc(this);
625 PrepareDC(dc);
626
627 OnDraw(dc);
628 }
629
630 // kbd handling: notice that we use OnChar() and not OnKeyDown() for
631 // compatibility here - if we used OnKeyDown(), the programs which process
632 // arrows themselves in their OnChar() would never get the message and like
633 // this they always have the priority
634 void wxGenericScrolledWindow::OnChar(wxKeyEvent& event)
635 {
636 int stx, sty, // view origin
637 szx, szy, // view size (total)
638 clix, cliy; // view size (on screen)
639
640 ViewStart(&stx, &sty);
641 GetClientSize(&clix, &cliy);
642 GetVirtualSize(&szx, &szy);
643
644 if( m_xScrollPixelsPerLine )
645 {
646 clix /= m_xScrollPixelsPerLine;
647 szx /= m_xScrollPixelsPerLine;
648 }
649 else
650 {
651 clix = 0;
652 szx = -1;
653 }
654 if( m_yScrollPixelsPerLine )
655 {
656 cliy /= m_yScrollPixelsPerLine;
657 szy /= m_yScrollPixelsPerLine;
658 }
659 else
660 {
661 cliy = 0;
662 szy = -1;
663 }
664
665 int dsty;
666 switch ( event.KeyCode() )
667 {
668 case WXK_PAGEUP:
669 case WXK_PRIOR:
670 dsty = sty - (5 * cliy / 6);
671 Scroll(-1, (dsty == -1) ? 0 : dsty);
672 break;
673
674 case WXK_PAGEDOWN:
675 case WXK_NEXT:
676 Scroll(-1, sty + (5 * cliy / 6));
677 break;
678
679 case WXK_HOME:
680 Scroll(0, event.ControlDown() ? 0 : -1);
681 break;
682
683 case WXK_END:
684 Scroll(szx - clix, event.ControlDown() ? szy - cliy : -1);
685 break;
686
687 case WXK_UP:
688 Scroll(-1, sty - 1);
689 break;
690
691 case WXK_DOWN:
692 Scroll(-1, sty + 1);
693 break;
694
695 case WXK_LEFT:
696 Scroll(stx - 1, -1);
697 break;
698
699 case WXK_RIGHT:
700 Scroll(stx + 1, -1);
701 break;
702
703 default:
704 // not for us
705 event.Skip();
706 }
707 }
708
709
710 void wxGenericScrolledWindow::OnMouseWheel(wxMouseEvent& event)
711 {
712 int lines;
713 int vsx, vsy;
714
715 m_wheelRotation += event.GetWheelRotation();
716 lines = m_wheelRotation / event.GetWheelDelta();
717 m_wheelRotation -= lines * event.GetWheelDelta();
718
719 if (lines != 0) {
720 lines *= event.GetLinesPerAction();
721 GetViewStart(&vsx, &vsy);
722 Scroll(-1, vsy - lines);
723 }
724 }
725
726
727
728