1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/scrolwin.cpp
3 // Purpose: wxGenericScrolledWindow implementation
4 // Author: Julian Smart
5 // Modified by: Vadim Zeitlin on 31.08.00: wxScrollHelper allows to implement
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "scrolwin.h"
25 #define XtDisplay XTDISPLAY
28 // For compilers that support precompilation, includes "wx.h".
29 #include "wx/wxprec.h"
36 #include "wx/dcclient.h"
38 #include "wx/scrolwin.h"
43 #include <windows.h> // for DLGC_WANTARROWS
47 // For wxRETAINED implementation
48 #ifdef __VMS__ //VMS's Xm.h is not (yet) compatible with C++
49 //This code switches off the compiler warnings
50 # pragma message disable nosimpint
54 # pragma message enable nosimpint
59 IMPLEMENT_CLASS(wxScrolledWindow
, wxGenericScrolledWindow
)
62 // ----------------------------------------------------------------------------
63 // wxScrollHelperEvtHandler: intercept the events from the window and forward
64 // them to wxScrollHelper
65 // ----------------------------------------------------------------------------
67 class wxScrollHelperEvtHandler
: public wxEvtHandler
70 wxScrollHelperEvtHandler(wxScrollHelper
*scrollHelper
)
72 m_scrollHelper
= scrollHelper
;
75 virtual bool ProcessEvent(wxEvent
& event
);
78 wxScrollHelper
*m_scrollHelper
;
81 // ----------------------------------------------------------------------------
82 // wxAutoScrollTimer: the timer used to generate a stream of scroll events when
83 // a captured mouse is held outside the window
84 // ----------------------------------------------------------------------------
86 class wxAutoScrollTimer
: public wxTimer
89 wxAutoScrollTimer(wxWindow
*winToScroll
, wxScrollHelper
*scroll
,
90 wxEventType eventTypeToSend
,
93 virtual void Notify();
97 wxScrollHelper
*m_scrollHelper
;
98 wxEventType m_eventType
;
103 // ============================================================================
105 // ============================================================================
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 wxAutoScrollTimer::wxAutoScrollTimer(wxWindow
*winToScroll
,
112 wxScrollHelper
*scroll
,
113 wxEventType eventTypeToSend
,
117 m_scrollHelper
= scroll
;
118 m_eventType
= eventTypeToSend
;
123 void wxAutoScrollTimer::Notify()
125 // only do all this as long as the window is capturing the mouse
126 if ( wxWindow::GetCapture() != m_win
)
130 else // we still capture the mouse, continue generating events
132 // first scroll the window if we are allowed to do it
133 wxScrollWinEvent
event1(m_eventType
, m_pos
, m_orient
);
134 event1
.SetEventObject(m_win
);
135 if ( m_scrollHelper
->SendAutoScrollEvents(event1
) &&
136 m_win
->GetEventHandler()->ProcessEvent(event1
) )
138 // and then send a pseudo mouse-move event to refresh the selection
139 wxMouseEvent
event2(wxEVT_MOTION
);
140 wxGetMousePosition(&event2
.m_x
, &event2
.m_y
);
142 // the mouse event coordinates should be client, not screen as
143 // returned by wxGetMousePosition
144 wxWindow
*parentTop
= m_win
;
145 while ( parentTop
->GetParent() )
146 parentTop
= parentTop
->GetParent();
147 wxPoint ptOrig
= parentTop
->GetPosition();
148 event2
.m_x
-= ptOrig
.x
;
149 event2
.m_y
-= ptOrig
.y
;
151 event2
.SetEventObject(m_win
);
153 // FIXME: we don't fill in the other members - ok?
155 m_win
->GetEventHandler()->ProcessEvent(event2
);
157 else // can't scroll further, stop
164 // ----------------------------------------------------------------------------
165 // wxScrollHelperEvtHandler
166 // ----------------------------------------------------------------------------
168 bool wxScrollHelperEvtHandler::ProcessEvent(wxEvent
& event
)
170 if ( wxEvtHandler::ProcessEvent(event
) )
173 // reset the skipped flag to FALSE as it might have been set to TRUE in
174 // ProcessEvent() above
177 wxEventType evType
= event
.GetEventType();
179 if ( evType
== wxEVT_PAINT
)
181 m_scrollHelper
->HandleOnPaint((wxPaintEvent
&)event
);
185 if ( evType
== wxEVT_SCROLLWIN_TOP
||
186 evType
== wxEVT_SCROLLWIN_BOTTOM
||
187 evType
== wxEVT_SCROLLWIN_LINEUP
||
188 evType
== wxEVT_SCROLLWIN_LINEDOWN
||
189 evType
== wxEVT_SCROLLWIN_PAGEUP
||
190 evType
== wxEVT_SCROLLWIN_PAGEDOWN
||
191 evType
== wxEVT_SCROLLWIN_THUMBTRACK
||
192 evType
== wxEVT_SCROLLWIN_THUMBRELEASE
)
194 m_scrollHelper
->HandleOnScroll((wxScrollWinEvent
&)event
);
195 return !event
.GetSkipped();
198 if ( evType
== wxEVT_ENTER_WINDOW
)
200 m_scrollHelper
->HandleOnMouseEnter((wxMouseEvent
&)event
);
202 else if ( evType
== wxEVT_LEAVE_WINDOW
)
204 m_scrollHelper
->HandleOnMouseLeave((wxMouseEvent
&)event
);
207 else if ( evType
== wxEVT_MOUSEWHEEL
)
209 m_scrollHelper
->HandleOnMouseWheel((wxMouseEvent
&)event
);
211 #endif // wxUSE_MOUSEWHEEL
212 else if ( evType
== wxEVT_SIZE
)
214 m_scrollHelper
->HandleOnSize((wxSizeEvent
&)event
);
216 else if ( evType
== wxEVT_CHAR
)
218 m_scrollHelper
->HandleOnChar((wxKeyEvent
&)event
);
219 return !event
.GetSkipped();
225 // ----------------------------------------------------------------------------
226 // wxScrollHelper construction
227 // ----------------------------------------------------------------------------
229 wxScrollHelper::wxScrollHelper(wxWindow
*win
)
231 m_xScrollPixelsPerLine
=
232 m_yScrollPixelsPerLine
=
237 m_xScrollLinesPerPage
=
238 m_yScrollLinesPerPage
= 0;
240 m_xScrollingEnabled
=
241 m_yScrollingEnabled
= TRUE
;
248 m_targetWindow
= (wxWindow
*)NULL
;
250 m_timerAutoScroll
= (wxTimer
*)NULL
;
256 void wxScrollHelper::SetWindow(wxWindow
*win
)
258 wxCHECK_RET( win
, _T("wxScrollHelper needs a window to scroll") );
260 m_targetWindow
= m_win
= win
;
262 // install the event handler which will intercept the events we're
264 m_win
->PushEventHandler(new wxScrollHelperEvtHandler(this));
267 wxScrollHelper::~wxScrollHelper()
271 if ( m_targetWindow
)
272 m_targetWindow
->PopEventHandler(TRUE
/* do delete it */);
275 // ----------------------------------------------------------------------------
276 // setting scrolling parameters
277 // ----------------------------------------------------------------------------
279 void wxScrollHelper::SetScrollbars(int pixelsPerUnitX
,
289 CalcUnscrolledPosition(xPos
, yPos
, &xpos
, &ypos
);
292 (noUnitsX
!= 0 && m_xScrollLines
== 0) ||
293 (noUnitsX
< m_xScrollLines
&& xpos
> pixelsPerUnitX
*noUnitsX
) ||
295 (noUnitsY
!= 0 && m_yScrollLines
== 0) ||
296 (noUnitsY
< m_yScrollLines
&& ypos
> pixelsPerUnitY
*noUnitsY
) ||
297 (xPos
!= m_xScrollPosition
) ||
298 (yPos
!= m_yScrollPosition
)
301 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
302 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
303 m_xScrollPosition
= xPos
;
304 m_yScrollPosition
= yPos
;
305 m_xScrollLines
= noUnitsX
;
306 m_yScrollLines
= noUnitsY
;
309 // Sorry, some Motif-specific code to implement a backing pixmap
310 // for the wxRETAINED style. Implementing a backing store can't
311 // be entirely generic because it relies on the wxWindowDC implementation
312 // to duplicate X drawing calls for the backing pixmap.
314 if ( m_targetWindow
->GetWindowStyle() & wxRETAINED
)
316 Display
* dpy
= XtDisplay((Widget
)m_targetWindow
->GetMainWidget());
318 int totalPixelWidth
= m_xScrollLines
* m_xScrollPixelsPerLine
;
319 int totalPixelHeight
= m_yScrollLines
* m_yScrollPixelsPerLine
;
320 if (m_targetWindow
->m_backingPixmap
&&
321 !((m_targetWindow
->m_pixmapWidth
== totalPixelWidth
) &&
322 (m_targetWindow
->m_pixmapHeight
== totalPixelHeight
)))
324 XFreePixmap (dpy
, (Pixmap
) m_targetWindow
->m_backingPixmap
);
325 m_targetWindow
->m_backingPixmap
= (WXPixmap
) 0;
328 if (!m_targetWindow
->m_backingPixmap
&&
329 (noUnitsX
!= 0) && (noUnitsY
!= 0))
331 int depth
= wxDisplayDepth();
332 m_pixmapWidth
= totalPixelWidth
;
333 m_pixmapHeight
= totalPixelHeight
;
334 m_backingPixmap
= (WXPixmap
) XCreatePixmap (dpy
, RootWindow (dpy
, DefaultScreen (dpy
)),
335 m_pixmapWidth
, m_pixmapHeight
, depth
);
343 if (do_refresh
&& !noRefresh
)
344 m_targetWindow
->Refresh(TRUE
, GetRect());
347 m_targetWindow
->MacUpdateImmediately() ;
351 // ----------------------------------------------------------------------------
352 // target window handling
353 // ----------------------------------------------------------------------------
355 void wxScrollHelper::SetTargetWindow( wxWindow
*target
)
357 wxASSERT_MSG( target
, wxT("target window must not be NULL") );
358 m_targetWindow
= target
;
361 wxWindow
*wxScrollHelper::GetTargetWindow() const
363 return m_targetWindow
;
366 // ----------------------------------------------------------------------------
367 // scrolling implementation itself
368 // ----------------------------------------------------------------------------
370 void wxScrollHelper::HandleOnScroll(wxScrollWinEvent
& event
)
372 int nScrollInc
= CalcScrollInc(event
);
373 if ( nScrollInc
== 0 )
375 // can't scroll further
381 int orient
= event
.GetOrientation();
382 if (orient
== wxHORIZONTAL
)
384 m_xScrollPosition
+= nScrollInc
;
385 m_targetWindow
->SetScrollPos(wxHORIZONTAL
, m_xScrollPosition
, FALSE
);
389 m_yScrollPosition
+= nScrollInc
;
390 m_targetWindow
->SetScrollPos(wxVERTICAL
, m_yScrollPosition
, FALSE
);
393 bool needsRefresh
= FALSE
;
396 if (orient
== wxHORIZONTAL
)
398 if ( m_xScrollingEnabled
)
400 dx
= -m_xScrollPixelsPerLine
* nScrollInc
;
409 if ( m_yScrollingEnabled
)
411 dy
= -m_yScrollPixelsPerLine
* nScrollInc
;
421 m_targetWindow
->Refresh(TRUE
, GetRect());
425 m_targetWindow
->ScrollWindow(dx
, dy
, GetRect());
429 m_targetWindow
->MacUpdateImmediately() ;
433 int wxScrollHelper::CalcScrollInc(wxScrollWinEvent
& event
)
435 int pos
= event
.GetPosition();
436 int orient
= event
.GetOrientation();
439 if (event
.GetEventType() == wxEVT_SCROLLWIN_TOP
)
441 if (orient
== wxHORIZONTAL
)
442 nScrollInc
= - m_xScrollPosition
;
444 nScrollInc
= - m_yScrollPosition
;
446 if (event
.GetEventType() == wxEVT_SCROLLWIN_BOTTOM
)
448 if (orient
== wxHORIZONTAL
)
449 nScrollInc
= m_xScrollLines
- m_xScrollPosition
;
451 nScrollInc
= m_yScrollLines
- m_yScrollPosition
;
453 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEUP
)
457 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN
)
461 if (event
.GetEventType() == wxEVT_SCROLLWIN_PAGEUP
)
463 if (orient
== wxHORIZONTAL
)
464 nScrollInc
= -GetScrollPageSize(wxHORIZONTAL
);
466 nScrollInc
= -GetScrollPageSize(wxVERTICAL
);
468 if (event
.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN
)
470 if (orient
== wxHORIZONTAL
)
471 nScrollInc
= GetScrollPageSize(wxHORIZONTAL
);
473 nScrollInc
= GetScrollPageSize(wxVERTICAL
);
475 if ((event
.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK
) ||
476 (event
.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE
))
478 if (orient
== wxHORIZONTAL
)
479 nScrollInc
= pos
- m_xScrollPosition
;
481 nScrollInc
= pos
- m_yScrollPosition
;
484 if (orient
== wxHORIZONTAL
)
486 if (m_xScrollPixelsPerLine
> 0)
489 GetTargetSize(&w
, &h
);
491 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
492 int noPositions
= (int) ( ((nMaxWidth
- w
)/(double)m_xScrollPixelsPerLine
) + 0.5 );
496 if ( (m_xScrollPosition
+ nScrollInc
) < 0 )
497 nScrollInc
= -m_xScrollPosition
; // As -ve as we can go
498 else if ( (m_xScrollPosition
+ nScrollInc
) > noPositions
)
499 nScrollInc
= noPositions
- m_xScrollPosition
; // As +ve as we can go
502 m_targetWindow
->Refresh(TRUE
, GetRect());
506 if (m_yScrollPixelsPerLine
> 0)
509 GetTargetSize(&w
, &h
);
511 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
512 int noPositions
= (int) ( ((nMaxHeight
- h
)/(double)m_yScrollPixelsPerLine
) + 0.5 );
516 if ( (m_yScrollPosition
+ nScrollInc
) < 0 )
517 nScrollInc
= -m_yScrollPosition
; // As -ve as we can go
518 else if ( (m_yScrollPosition
+ nScrollInc
) > noPositions
)
519 nScrollInc
= noPositions
- m_yScrollPosition
; // As +ve as we can go
522 m_targetWindow
->Refresh(TRUE
, GetRect());
528 // Adjust the scrollbars - new version.
529 void wxScrollHelper::AdjustScrollbars()
532 m_targetWindow
->MacUpdateImmediately();
536 GetTargetSize(&w
, &h
);
538 int oldXScroll
= m_xScrollPosition
;
539 int oldYScroll
= m_yScrollPosition
;
541 if (m_xScrollLines
> 0)
543 // Calculate page size i.e. number of scroll units you get on the
544 // current client window
545 int noPagePositions
= (int) ( (w
/(double)m_xScrollPixelsPerLine
) + 0.5 );
546 if (noPagePositions
< 1) noPagePositions
= 1;
547 if ( noPagePositions
> m_xScrollLines
)
548 noPagePositions
= m_xScrollLines
;
550 // Correct position if greater than extent of canvas minus
551 // the visible portion of it or if below zero
552 m_xScrollPosition
= wxMin( m_xScrollLines
-noPagePositions
, m_xScrollPosition
);
553 m_xScrollPosition
= wxMax( 0, m_xScrollPosition
);
555 m_targetWindow
->SetScrollbar(wxHORIZONTAL
, m_xScrollPosition
, noPagePositions
, m_xScrollLines
);
556 // The amount by which we scroll when paging
557 SetScrollPageSize(wxHORIZONTAL
, noPagePositions
);
561 m_xScrollPosition
= 0;
562 m_targetWindow
->SetScrollbar (wxHORIZONTAL
, 0, 0, 0, FALSE
);
565 if (m_yScrollLines
> 0)
567 // Calculate page size i.e. number of scroll units you get on the
568 // current client window
569 int noPagePositions
= (int) ( (h
/(double)m_yScrollPixelsPerLine
) + 0.5 );
570 if (noPagePositions
< 1) noPagePositions
= 1;
571 if ( noPagePositions
> m_yScrollLines
)
572 noPagePositions
= m_yScrollLines
;
574 // Correct position if greater than extent of canvas minus
575 // the visible portion of it or if below zero
576 m_yScrollPosition
= wxMin( m_yScrollLines
-noPagePositions
, m_yScrollPosition
);
577 m_yScrollPosition
= wxMax( 0, m_yScrollPosition
);
579 m_targetWindow
->SetScrollbar(wxVERTICAL
, m_yScrollPosition
, noPagePositions
, m_yScrollLines
);
580 // The amount by which we scroll when paging
581 SetScrollPageSize(wxVERTICAL
, noPagePositions
);
585 m_yScrollPosition
= 0;
586 m_targetWindow
->SetScrollbar (wxVERTICAL
, 0, 0, 0, FALSE
);
589 if (oldXScroll
!= m_xScrollPosition
)
591 if (m_xScrollingEnabled
)
592 m_targetWindow
->ScrollWindow( m_xScrollPixelsPerLine
* (oldXScroll
-m_xScrollPosition
), 0,
595 m_targetWindow
->Refresh(TRUE
, GetRect());
598 if (oldYScroll
!= m_yScrollPosition
)
600 if (m_yScrollingEnabled
)
601 m_targetWindow
->ScrollWindow( 0, m_yScrollPixelsPerLine
* (oldYScroll
-m_yScrollPosition
),
604 m_targetWindow
->Refresh(TRUE
, GetRect());
608 m_targetWindow
->MacUpdateImmediately();
612 void wxScrollHelper::DoPrepareDC(wxDC
& dc
)
614 wxPoint pt
= dc
.GetDeviceOrigin();
615 dc
.SetDeviceOrigin( pt
.x
- m_xScrollPosition
* m_xScrollPixelsPerLine
,
616 pt
.y
- m_yScrollPosition
* m_yScrollPixelsPerLine
);
617 dc
.SetUserScale( m_scaleX
, m_scaleY
);
620 void wxScrollHelper::GetScrollPixelsPerUnit (int *x_unit
, int *y_unit
) const
623 *x_unit
= m_xScrollPixelsPerLine
;
625 *y_unit
= m_yScrollPixelsPerLine
;
628 int wxScrollHelper::GetScrollPageSize(int orient
) const
630 if ( orient
== wxHORIZONTAL
)
631 return m_xScrollLinesPerPage
;
633 return m_yScrollLinesPerPage
;
636 void wxScrollHelper::SetScrollPageSize(int orient
, int pageSize
)
638 if ( orient
== wxHORIZONTAL
)
639 m_xScrollLinesPerPage
= pageSize
;
641 m_yScrollLinesPerPage
= pageSize
;
645 * Scroll to given position (scroll position, not pixel position)
647 void wxScrollHelper::Scroll( int x_pos
, int y_pos
)
652 if (((x_pos
== -1) || (x_pos
== m_xScrollPosition
)) &&
653 ((y_pos
== -1) || (y_pos
== m_yScrollPosition
))) return;
656 m_targetWindow
->MacUpdateImmediately();
660 GetTargetSize(&w
, &h
);
662 if ((x_pos
!= -1) && (m_xScrollPixelsPerLine
))
664 int old_x
= m_xScrollPosition
;
665 m_xScrollPosition
= x_pos
;
667 // Calculate page size i.e. number of scroll units you get on the
668 // current client window
669 int noPagePositions
= (int) ( (w
/(double)m_xScrollPixelsPerLine
) + 0.5 );
670 if (noPagePositions
< 1) noPagePositions
= 1;
672 // Correct position if greater than extent of canvas minus
673 // the visible portion of it or if below zero
674 m_xScrollPosition
= wxMin( m_xScrollLines
-noPagePositions
, m_xScrollPosition
);
675 m_xScrollPosition
= wxMax( 0, m_xScrollPosition
);
677 if (old_x
!= m_xScrollPosition
) {
678 m_targetWindow
->SetScrollPos( wxHORIZONTAL
, m_xScrollPosition
, FALSE
);
679 m_targetWindow
->ScrollWindow( (old_x
-m_xScrollPosition
)*m_xScrollPixelsPerLine
, 0,
683 if ((y_pos
!= -1) && (m_yScrollPixelsPerLine
))
685 int old_y
= m_yScrollPosition
;
686 m_yScrollPosition
= y_pos
;
688 // Calculate page size i.e. number of scroll units you get on the
689 // current client window
690 int noPagePositions
= (int) ( (h
/(double)m_yScrollPixelsPerLine
) + 0.5 );
691 if (noPagePositions
< 1) noPagePositions
= 1;
693 // Correct position if greater than extent of canvas minus
694 // the visible portion of it or if below zero
695 m_yScrollPosition
= wxMin( m_yScrollLines
-noPagePositions
, m_yScrollPosition
);
696 m_yScrollPosition
= wxMax( 0, m_yScrollPosition
);
698 if (old_y
!= m_yScrollPosition
) {
699 m_targetWindow
->SetScrollPos( wxVERTICAL
, m_yScrollPosition
, FALSE
);
700 m_targetWindow
->ScrollWindow( 0, (old_y
-m_yScrollPosition
)*m_yScrollPixelsPerLine
,
706 m_targetWindow
->MacUpdateImmediately();
711 void wxScrollHelper::EnableScrolling (bool x_scroll
, bool y_scroll
)
713 m_xScrollingEnabled
= x_scroll
;
714 m_yScrollingEnabled
= y_scroll
;
717 void wxScrollHelper::GetVirtualSize (int *x
, int *y
) const
720 *x
= m_xScrollPixelsPerLine
* m_xScrollLines
;
722 *y
= m_yScrollPixelsPerLine
* m_yScrollLines
;
725 // Where the current view starts from
726 void wxScrollHelper::GetViewStart (int *x
, int *y
) const
729 *x
= m_xScrollPosition
;
731 *y
= m_yScrollPosition
;
734 void wxScrollHelper::CalcScrolledPosition(int x
, int y
, int *xx
, int *yy
) const
737 *xx
= x
- m_xScrollPosition
* m_xScrollPixelsPerLine
;
739 *yy
= y
- m_yScrollPosition
* m_yScrollPixelsPerLine
;
742 void wxScrollHelper::CalcUnscrolledPosition(int x
, int y
, int *xx
, int *yy
) const
745 *xx
= x
+ m_xScrollPosition
* m_xScrollPixelsPerLine
;
747 *yy
= y
+ m_yScrollPosition
* m_yScrollPixelsPerLine
;
750 // ----------------------------------------------------------------------------
752 // ----------------------------------------------------------------------------
754 // Default OnSize resets scrollbars, if any
755 void wxScrollHelper::HandleOnSize(wxSizeEvent
& WXUNUSED(event
))
757 #if wxUSE_CONSTRAINTS
758 if ( m_targetWindow
->GetAutoLayout() )
759 m_targetWindow
->Layout();
765 // This calls OnDraw, having adjusted the origin according to the current
767 void wxScrollHelper::HandleOnPaint(wxPaintEvent
& WXUNUSED(event
))
769 wxPaintDC
dc(m_targetWindow
);
775 // kbd handling: notice that we use OnChar() and not OnKeyDown() for
776 // compatibility here - if we used OnKeyDown(), the programs which process
777 // arrows themselves in their OnChar() would never get the message and like
778 // this they always have the priority
779 void wxScrollHelper::HandleOnChar(wxKeyEvent
& event
)
781 int stx
, sty
, // view origin
782 szx
, szy
, // view size (total)
783 clix
, cliy
; // view size (on screen)
785 GetViewStart(&stx
, &sty
);
786 GetTargetSize(&clix
, &cliy
);
787 GetVirtualSize(&szx
, &szy
);
789 if( m_xScrollPixelsPerLine
)
791 clix
/= m_xScrollPixelsPerLine
;
792 szx
/= m_xScrollPixelsPerLine
;
799 if( m_yScrollPixelsPerLine
)
801 cliy
/= m_yScrollPixelsPerLine
;
802 szy
/= m_yScrollPixelsPerLine
;
811 switch ( event
.KeyCode() )
815 dsty
= sty
- (5 * cliy
/ 6);
816 Scroll(-1, (dsty
== -1) ? 0 : dsty
);
821 Scroll(-1, sty
+ (5 * cliy
/ 6));
825 Scroll(0, event
.ControlDown() ? 0 : -1);
829 Scroll(szx
- clix
, event
.ControlDown() ? szy
- cliy
: -1);
854 // ----------------------------------------------------------------------------
855 // autoscroll stuff: these functions deal with sending fake scroll events when
856 // a captured mouse is being held outside the window
857 // ----------------------------------------------------------------------------
859 bool wxScrollHelper::SendAutoScrollEvents(wxScrollWinEvent
& event
) const
861 // only send the event if the window is scrollable in this direction
862 wxWindow
*win
= (wxWindow
*)event
.GetEventObject();
863 return win
->HasScrollbar(event
.GetOrientation());
866 void wxScrollHelper::StopAutoScrolling()
868 if ( m_timerAutoScroll
)
870 delete m_timerAutoScroll
;
871 m_timerAutoScroll
= (wxTimer
*)NULL
;
875 void wxScrollHelper::HandleOnMouseEnter(wxMouseEvent
& event
)
882 void wxScrollHelper::HandleOnMouseLeave(wxMouseEvent
& event
)
884 // don't prevent the usual processing of the event from taking place
887 // when a captured mouse leave a scrolled window we start generate
888 // scrolling events to allow, for example, extending selection beyond the
889 // visible area in some controls
890 if ( wxWindow::GetCapture() == m_targetWindow
)
892 // where is the mouse leaving?
894 wxPoint pt
= event
.GetPosition();
897 orient
= wxHORIZONTAL
;
905 else // we're lower or to the right of the window
907 wxSize size
= m_targetWindow
->GetClientSize();
910 orient
= wxHORIZONTAL
;
911 pos
= m_xScrollLines
;
913 else if ( pt
.y
> size
.y
)
916 pos
= m_yScrollLines
;
918 else // this should be impossible
920 // but seems to happen sometimes under wxMSW - maybe it's a bug
921 // there but for now just ignore it
923 //wxFAIL_MSG( _T("can't understand where has mouse gone") );
929 // only start the auto scroll timer if the window can be scrolled in
931 if ( !m_targetWindow
->HasScrollbar(orient
) )
934 delete m_timerAutoScroll
;
935 m_timerAutoScroll
= new wxAutoScrollTimer
937 m_targetWindow
, this,
938 pos
== 0 ? wxEVT_SCROLLWIN_LINEUP
939 : wxEVT_SCROLLWIN_LINEDOWN
,
943 m_timerAutoScroll
->Start(50); // FIXME: make configurable
949 void wxScrollHelper::HandleOnMouseWheel(wxMouseEvent
& event
)
951 m_wheelRotation
+= event
.GetWheelRotation();
952 int lines
= m_wheelRotation
/ event
.GetWheelDelta();
953 m_wheelRotation
-= lines
* event
.GetWheelDelta();
957 lines
*= event
.GetLinesPerAction();
960 GetViewStart(&vsx
, &vsy
);
961 Scroll(-1, vsy
- lines
);
965 #endif // wxUSE_MOUSEWHEEL
967 // ----------------------------------------------------------------------------
968 // wxGenericScrolledWindow implementation
969 // ----------------------------------------------------------------------------
971 IMPLEMENT_DYNAMIC_CLASS(wxGenericScrolledWindow
, wxPanel
)
973 bool wxGenericScrolledWindow::Create(wxWindow
*parent
,
978 const wxString
& name
)
980 m_targetWindow
= this;
982 bool ok
= wxPanel::Create(parent
, id
, pos
, size
, style
, name
);
985 // we need to process arrows ourselves for scrolling
986 m_lDlgCode
|= DLGC_WANTARROWS
;
992 wxGenericScrolledWindow::~wxGenericScrolledWindow()
996 #if WXWIN_COMPATIBILITY
997 void wxGenericScrolledWindow::GetScrollUnitsPerPage (int *x_page
, int *y_page
) const
999 *x_page
= GetScrollPageSize(wxHORIZONTAL
);
1000 *y_page
= GetScrollPageSize(wxVERTICAL
);
1003 void wxGenericScrolledWindow::CalcUnscrolledPosition(int x
, int y
, float *xx
, float *yy
) const
1006 *xx
= (float)(x
+ m_xScrollPosition
* m_xScrollPixelsPerLine
);
1008 *yy
= (float)(y
+ m_yScrollPosition
* m_yScrollPixelsPerLine
);
1010 #endif // WXWIN_COMPATIBILITY