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 switch ( event
.GetEventType() )
179 case wxEVT_SCROLLWIN_TOP
:
180 case wxEVT_SCROLLWIN_BOTTOM
:
181 case wxEVT_SCROLLWIN_LINEUP
:
182 case wxEVT_SCROLLWIN_LINEDOWN
:
183 case wxEVT_SCROLLWIN_PAGEUP
:
184 case wxEVT_SCROLLWIN_PAGEDOWN
:
185 case wxEVT_SCROLLWIN_THUMBTRACK
:
186 case wxEVT_SCROLLWIN_THUMBRELEASE
:
187 m_scrollHelper
->HandleOnScroll((wxScrollWinEvent
&)event
);
188 return !event
.GetSkipped();
191 m_scrollHelper
->HandleOnPaint((wxPaintEvent
&)event
);
195 m_scrollHelper
->HandleOnSize((wxSizeEvent
&)event
);
199 m_scrollHelper
->HandleOnChar((wxKeyEvent
&)event
);
200 return !event
.GetSkipped();
202 case wxEVT_ENTER_WINDOW
:
203 m_scrollHelper
->HandleOnMouseEnter((wxMouseEvent
&)event
);
206 case wxEVT_LEAVE_WINDOW
:
207 m_scrollHelper
->HandleOnMouseLeave((wxMouseEvent
&)event
);
210 case wxEVT_MOUSEWHEEL
:
211 m_scrollHelper
->HandleOnMouseWheel((wxMouseEvent
&)event
);
218 // ----------------------------------------------------------------------------
219 // wxScrollHelper construction
220 // ----------------------------------------------------------------------------
222 wxScrollHelper::wxScrollHelper(wxWindow
*win
)
224 m_xScrollPixelsPerLine
=
225 m_yScrollPixelsPerLine
=
230 m_xScrollLinesPerPage
=
231 m_yScrollLinesPerPage
= 0;
233 m_xScrollingEnabled
=
234 m_yScrollingEnabled
= TRUE
;
241 m_targetWindow
= (wxWindow
*)NULL
;
243 m_timerAutoScroll
= (wxTimer
*)NULL
;
249 void wxScrollHelper::SetWindow(wxWindow
*win
)
251 wxCHECK_RET( win
, _T("wxScrollHelper needs a window to scroll") );
253 m_targetWindow
= m_win
= win
;
255 // install the event handler which will intercept the events we're
257 m_win
->PushEventHandler(new wxScrollHelperEvtHandler(this));
260 wxScrollHelper::~wxScrollHelper()
264 if ( m_targetWindow
)
265 m_targetWindow
->PopEventHandler(TRUE
/* do delete it */);
268 // ----------------------------------------------------------------------------
269 // setting scrolling parameters
270 // ----------------------------------------------------------------------------
272 void wxScrollHelper::SetScrollbars(int pixelsPerUnitX
,
282 CalcUnscrolledPosition(xPos
, yPos
, &xpos
, &ypos
);
285 (noUnitsX
!= 0 && m_xScrollLines
== 0) ||
286 (noUnitsX
< m_xScrollLines
&& xpos
> pixelsPerUnitX
*noUnitsX
) ||
288 (noUnitsY
!= 0 && m_yScrollLines
== 0) ||
289 (noUnitsY
< m_yScrollLines
&& ypos
> pixelsPerUnitY
*noUnitsY
) ||
290 (xPos
!= m_xScrollPosition
) ||
291 (yPos
!= m_yScrollPosition
)
294 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
295 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
296 m_xScrollPosition
= xPos
;
297 m_yScrollPosition
= yPos
;
298 m_xScrollLines
= noUnitsX
;
299 m_yScrollLines
= noUnitsY
;
302 // Sorry, some Motif-specific code to implement a backing pixmap
303 // for the wxRETAINED style. Implementing a backing store can't
304 // be entirely generic because it relies on the wxWindowDC implementation
305 // to duplicate X drawing calls for the backing pixmap.
307 if ( m_targetWindow
->GetWindowStyle() & wxRETAINED
)
309 Display
* dpy
= XtDisplay((Widget
)m_targetWindow
->GetMainWidget());
311 int totalPixelWidth
= m_xScrollLines
* m_xScrollPixelsPerLine
;
312 int totalPixelHeight
= m_yScrollLines
* m_yScrollPixelsPerLine
;
313 if (m_targetWindow
->m_backingPixmap
&&
314 !((m_targetWindow
->m_pixmapWidth
== totalPixelWidth
) &&
315 (m_targetWindow
->m_pixmapHeight
== totalPixelHeight
)))
317 XFreePixmap (dpy
, (Pixmap
) m_targetWindow
->m_backingPixmap
);
318 m_targetWindow
->m_backingPixmap
= (WXPixmap
) 0;
321 if (!m_targetWindow
->m_backingPixmap
&&
322 (noUnitsX
!= 0) && (noUnitsY
!= 0))
324 int depth
= wxDisplayDepth();
325 m_pixmapWidth
= totalPixelWidth
;
326 m_pixmapHeight
= totalPixelHeight
;
327 m_backingPixmap
= (WXPixmap
) XCreatePixmap (dpy
, RootWindow (dpy
, DefaultScreen (dpy
)),
328 m_pixmapWidth
, m_pixmapHeight
, depth
);
336 if (do_refresh
&& !noRefresh
)
337 m_targetWindow
->Refresh(TRUE
, GetRect());
340 m_targetWindow
->MacUpdateImmediately() ;
344 // ----------------------------------------------------------------------------
345 // target window handling
346 // ----------------------------------------------------------------------------
348 void wxScrollHelper::SetTargetWindow( wxWindow
*target
)
350 wxASSERT_MSG( target
, wxT("target window must not be NULL") );
351 m_targetWindow
= target
;
354 wxWindow
*wxScrollHelper::GetTargetWindow() const
356 return m_targetWindow
;
359 // ----------------------------------------------------------------------------
360 // scrolling implementation itself
361 // ----------------------------------------------------------------------------
363 void wxScrollHelper::HandleOnScroll(wxScrollWinEvent
& event
)
365 int nScrollInc
= CalcScrollInc(event
);
366 if ( nScrollInc
== 0 )
368 // can't scroll further
374 int orient
= event
.GetOrientation();
375 if (orient
== wxHORIZONTAL
)
377 m_xScrollPosition
+= nScrollInc
;
378 m_targetWindow
->SetScrollPos(wxHORIZONTAL
, m_xScrollPosition
, FALSE
);
382 m_yScrollPosition
+= nScrollInc
;
383 m_targetWindow
->SetScrollPos(wxVERTICAL
, m_yScrollPosition
, FALSE
);
386 bool needsRefresh
= FALSE
;
389 if (orient
== wxHORIZONTAL
)
391 if ( m_xScrollingEnabled
)
393 dx
= -m_xScrollPixelsPerLine
* nScrollInc
;
402 if ( m_yScrollingEnabled
)
404 dy
= -m_yScrollPixelsPerLine
* nScrollInc
;
414 m_targetWindow
->Refresh(TRUE
, GetRect());
418 m_targetWindow
->ScrollWindow(dx
, dy
, GetRect());
422 m_targetWindow
->MacUpdateImmediately() ;
426 int wxScrollHelper::CalcScrollInc(wxScrollWinEvent
& event
)
428 int pos
= event
.GetPosition();
429 int orient
= event
.GetOrientation();
432 if (event
.GetEventType() == wxEVT_SCROLLWIN_TOP
)
434 if (orient
== wxHORIZONTAL
)
435 nScrollInc
= - m_xScrollPosition
;
437 nScrollInc
= - m_yScrollPosition
;
439 if (event
.GetEventType() == wxEVT_SCROLLWIN_BOTTOM
)
441 if (orient
== wxHORIZONTAL
)
442 nScrollInc
= m_xScrollLines
- m_xScrollPosition
;
444 nScrollInc
= m_yScrollLines
- m_yScrollPosition
;
446 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEUP
)
450 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN
)
454 if (event
.GetEventType() == wxEVT_SCROLLWIN_PAGEUP
)
456 if (orient
== wxHORIZONTAL
)
457 nScrollInc
= -GetScrollPageSize(wxHORIZONTAL
);
459 nScrollInc
= -GetScrollPageSize(wxVERTICAL
);
461 if (event
.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN
)
463 if (orient
== wxHORIZONTAL
)
464 nScrollInc
= GetScrollPageSize(wxHORIZONTAL
);
466 nScrollInc
= GetScrollPageSize(wxVERTICAL
);
468 if ((event
.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK
) ||
469 (event
.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE
))
471 if (orient
== wxHORIZONTAL
)
472 nScrollInc
= pos
- m_xScrollPosition
;
474 nScrollInc
= pos
- m_yScrollPosition
;
477 if (orient
== wxHORIZONTAL
)
479 if (m_xScrollPixelsPerLine
> 0)
482 GetTargetSize(&w
, &h
);
484 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
485 int noPositions
= (int) ( ((nMaxWidth
- w
)/(double)m_xScrollPixelsPerLine
) + 0.5 );
489 if ( (m_xScrollPosition
+ nScrollInc
) < 0 )
490 nScrollInc
= -m_xScrollPosition
; // As -ve as we can go
491 else if ( (m_xScrollPosition
+ nScrollInc
) > noPositions
)
492 nScrollInc
= noPositions
- m_xScrollPosition
; // As +ve as we can go
495 m_targetWindow
->Refresh(TRUE
, GetRect());
499 if (m_yScrollPixelsPerLine
> 0)
502 GetTargetSize(&w
, &h
);
504 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
505 int noPositions
= (int) ( ((nMaxHeight
- h
)/(double)m_yScrollPixelsPerLine
) + 0.5 );
509 if ( (m_yScrollPosition
+ nScrollInc
) < 0 )
510 nScrollInc
= -m_yScrollPosition
; // As -ve as we can go
511 else if ( (m_yScrollPosition
+ nScrollInc
) > noPositions
)
512 nScrollInc
= noPositions
- m_yScrollPosition
; // As +ve as we can go
515 m_targetWindow
->Refresh(TRUE
, GetRect());
521 // Adjust the scrollbars - new version.
522 void wxScrollHelper::AdjustScrollbars()
525 m_targetWindow
->MacUpdateImmediately();
529 GetTargetSize(&w
, &h
);
531 int oldXScroll
= m_xScrollPosition
;
532 int oldYScroll
= m_yScrollPosition
;
534 if (m_xScrollLines
> 0)
536 // Calculate page size i.e. number of scroll units you get on the
537 // current client window
538 int noPagePositions
= (int) ( (w
/(double)m_xScrollPixelsPerLine
) + 0.5 );
539 if (noPagePositions
< 1) noPagePositions
= 1;
540 if ( noPagePositions
> m_xScrollLines
)
541 noPagePositions
= m_xScrollLines
;
543 // Correct position if greater than extent of canvas minus
544 // the visible portion of it or if below zero
545 m_xScrollPosition
= wxMin( m_xScrollLines
-noPagePositions
, m_xScrollPosition
);
546 m_xScrollPosition
= wxMax( 0, m_xScrollPosition
);
548 m_targetWindow
->SetScrollbar(wxHORIZONTAL
, m_xScrollPosition
, noPagePositions
, m_xScrollLines
);
549 // The amount by which we scroll when paging
550 SetScrollPageSize(wxHORIZONTAL
, noPagePositions
);
554 m_xScrollPosition
= 0;
555 m_targetWindow
->SetScrollbar (wxHORIZONTAL
, 0, 0, 0, FALSE
);
558 if (m_yScrollLines
> 0)
560 // Calculate page size i.e. number of scroll units you get on the
561 // current client window
562 int noPagePositions
= (int) ( (h
/(double)m_yScrollPixelsPerLine
) + 0.5 );
563 if (noPagePositions
< 1) noPagePositions
= 1;
564 if ( noPagePositions
> m_yScrollLines
)
565 noPagePositions
= m_yScrollLines
;
567 // Correct position if greater than extent of canvas minus
568 // the visible portion of it or if below zero
569 m_yScrollPosition
= wxMin( m_yScrollLines
-noPagePositions
, m_yScrollPosition
);
570 m_yScrollPosition
= wxMax( 0, m_yScrollPosition
);
572 m_targetWindow
->SetScrollbar(wxVERTICAL
, m_yScrollPosition
, noPagePositions
, m_yScrollLines
);
573 // The amount by which we scroll when paging
574 SetScrollPageSize(wxVERTICAL
, noPagePositions
);
578 m_yScrollPosition
= 0;
579 m_targetWindow
->SetScrollbar (wxVERTICAL
, 0, 0, 0, FALSE
);
582 if (oldXScroll
!= m_xScrollPosition
)
584 if (m_xScrollingEnabled
)
585 m_targetWindow
->ScrollWindow( m_xScrollPixelsPerLine
* (oldXScroll
-m_xScrollPosition
), 0,
588 m_targetWindow
->Refresh(TRUE
, GetRect());
591 if (oldYScroll
!= m_yScrollPosition
)
593 if (m_yScrollingEnabled
)
594 m_targetWindow
->ScrollWindow( 0, m_yScrollPixelsPerLine
* (oldYScroll
-m_yScrollPosition
),
597 m_targetWindow
->Refresh(TRUE
, GetRect());
601 m_targetWindow
->MacUpdateImmediately();
605 void wxScrollHelper::DoPrepareDC(wxDC
& dc
)
607 wxPoint pt
= dc
.GetDeviceOrigin();
608 dc
.SetDeviceOrigin( pt
.x
- m_xScrollPosition
* m_xScrollPixelsPerLine
,
609 pt
.y
- m_yScrollPosition
* m_yScrollPixelsPerLine
);
610 dc
.SetUserScale( m_scaleX
, m_scaleY
);
613 void wxScrollHelper::GetScrollPixelsPerUnit (int *x_unit
, int *y_unit
) const
616 *x_unit
= m_xScrollPixelsPerLine
;
618 *y_unit
= m_yScrollPixelsPerLine
;
621 int wxScrollHelper::GetScrollPageSize(int orient
) const
623 if ( orient
== wxHORIZONTAL
)
624 return m_xScrollLinesPerPage
;
626 return m_yScrollLinesPerPage
;
629 void wxScrollHelper::SetScrollPageSize(int orient
, int pageSize
)
631 if ( orient
== wxHORIZONTAL
)
632 m_xScrollLinesPerPage
= pageSize
;
634 m_yScrollLinesPerPage
= pageSize
;
638 * Scroll to given position (scroll position, not pixel position)
640 void wxScrollHelper::Scroll( int x_pos
, int y_pos
)
645 if (((x_pos
== -1) || (x_pos
== m_xScrollPosition
)) &&
646 ((y_pos
== -1) || (y_pos
== m_yScrollPosition
))) return;
649 m_targetWindow
->MacUpdateImmediately();
653 GetTargetSize(&w
, &h
);
655 if ((x_pos
!= -1) && (m_xScrollPixelsPerLine
))
657 int old_x
= m_xScrollPosition
;
658 m_xScrollPosition
= x_pos
;
660 // Calculate page size i.e. number of scroll units you get on the
661 // current client window
662 int noPagePositions
= (int) ( (w
/(double)m_xScrollPixelsPerLine
) + 0.5 );
663 if (noPagePositions
< 1) noPagePositions
= 1;
665 // Correct position if greater than extent of canvas minus
666 // the visible portion of it or if below zero
667 m_xScrollPosition
= wxMin( m_xScrollLines
-noPagePositions
, m_xScrollPosition
);
668 m_xScrollPosition
= wxMax( 0, m_xScrollPosition
);
670 if (old_x
!= m_xScrollPosition
) {
671 m_targetWindow
->SetScrollPos( wxHORIZONTAL
, m_xScrollPosition
, FALSE
);
672 m_targetWindow
->ScrollWindow( (old_x
-m_xScrollPosition
)*m_xScrollPixelsPerLine
, 0,
676 if ((y_pos
!= -1) && (m_yScrollPixelsPerLine
))
678 int old_y
= m_yScrollPosition
;
679 m_yScrollPosition
= y_pos
;
681 // Calculate page size i.e. number of scroll units you get on the
682 // current client window
683 int noPagePositions
= (int) ( (h
/(double)m_yScrollPixelsPerLine
) + 0.5 );
684 if (noPagePositions
< 1) noPagePositions
= 1;
686 // Correct position if greater than extent of canvas minus
687 // the visible portion of it or if below zero
688 m_yScrollPosition
= wxMin( m_yScrollLines
-noPagePositions
, m_yScrollPosition
);
689 m_yScrollPosition
= wxMax( 0, m_yScrollPosition
);
691 if (old_y
!= m_yScrollPosition
) {
692 m_targetWindow
->SetScrollPos( wxVERTICAL
, m_yScrollPosition
, FALSE
);
693 m_targetWindow
->ScrollWindow( 0, (old_y
-m_yScrollPosition
)*m_yScrollPixelsPerLine
,
699 m_targetWindow
->MacUpdateImmediately();
704 void wxScrollHelper::EnableScrolling (bool x_scroll
, bool y_scroll
)
706 m_xScrollingEnabled
= x_scroll
;
707 m_yScrollingEnabled
= y_scroll
;
710 void wxScrollHelper::GetVirtualSize (int *x
, int *y
) const
713 *x
= m_xScrollPixelsPerLine
* m_xScrollLines
;
715 *y
= m_yScrollPixelsPerLine
* m_yScrollLines
;
718 // Where the current view starts from
719 void wxScrollHelper::GetViewStart (int *x
, int *y
) const
722 *x
= m_xScrollPosition
;
724 *y
= m_yScrollPosition
;
727 void wxScrollHelper::CalcScrolledPosition(int x
, int y
, int *xx
, int *yy
) const
730 *xx
= x
- m_xScrollPosition
* m_xScrollPixelsPerLine
;
732 *yy
= y
- m_yScrollPosition
* m_yScrollPixelsPerLine
;
735 void wxScrollHelper::CalcUnscrolledPosition(int x
, int y
, int *xx
, int *yy
) const
738 *xx
= x
+ m_xScrollPosition
* m_xScrollPixelsPerLine
;
740 *yy
= y
+ m_yScrollPosition
* m_yScrollPixelsPerLine
;
743 // ----------------------------------------------------------------------------
745 // ----------------------------------------------------------------------------
747 // Default OnSize resets scrollbars, if any
748 void wxScrollHelper::HandleOnSize(wxSizeEvent
& WXUNUSED(event
))
750 #if wxUSE_CONSTRAINTS
751 if ( m_targetWindow
->GetAutoLayout() )
752 m_targetWindow
->Layout();
758 // This calls OnDraw, having adjusted the origin according to the current
760 void wxScrollHelper::HandleOnPaint(wxPaintEvent
& WXUNUSED(event
))
762 wxPaintDC
dc(m_targetWindow
);
768 // kbd handling: notice that we use OnChar() and not OnKeyDown() for
769 // compatibility here - if we used OnKeyDown(), the programs which process
770 // arrows themselves in their OnChar() would never get the message and like
771 // this they always have the priority
772 void wxScrollHelper::HandleOnChar(wxKeyEvent
& event
)
774 int stx
, sty
, // view origin
775 szx
, szy
, // view size (total)
776 clix
, cliy
; // view size (on screen)
778 GetViewStart(&stx
, &sty
);
779 GetTargetSize(&clix
, &cliy
);
780 GetVirtualSize(&szx
, &szy
);
782 if( m_xScrollPixelsPerLine
)
784 clix
/= m_xScrollPixelsPerLine
;
785 szx
/= m_xScrollPixelsPerLine
;
792 if( m_yScrollPixelsPerLine
)
794 cliy
/= m_yScrollPixelsPerLine
;
795 szy
/= m_yScrollPixelsPerLine
;
804 switch ( event
.KeyCode() )
808 dsty
= sty
- (5 * cliy
/ 6);
809 Scroll(-1, (dsty
== -1) ? 0 : dsty
);
814 Scroll(-1, sty
+ (5 * cliy
/ 6));
818 Scroll(0, event
.ControlDown() ? 0 : -1);
822 Scroll(szx
- clix
, event
.ControlDown() ? szy
- cliy
: -1);
847 // ----------------------------------------------------------------------------
848 // autoscroll stuff: these functions deal with sending fake scroll events when
849 // a captured mouse is being held outside the window
850 // ----------------------------------------------------------------------------
852 bool wxScrollHelper::SendAutoScrollEvents(wxScrollWinEvent
& event
) const
854 // only send the event if the window is scrollable in this direction
855 wxWindow
*win
= (wxWindow
*)event
.GetEventObject();
856 return win
->HasScrollbar(event
.GetOrientation());
859 void wxScrollHelper::StopAutoScrolling()
861 if ( m_timerAutoScroll
)
863 delete m_timerAutoScroll
;
864 m_timerAutoScroll
= (wxTimer
*)NULL
;
868 void wxScrollHelper::HandleOnMouseEnter(wxMouseEvent
& event
)
875 void wxScrollHelper::HandleOnMouseLeave(wxMouseEvent
& event
)
877 // don't prevent the usual processing of the event from taking place
880 // when a captured mouse leave a scrolled window we start generate
881 // scrolling events to allow, for example, extending selection beyond the
882 // visible area in some controls
883 if ( wxWindow::GetCapture() == m_targetWindow
)
885 // where is the mouse leaving?
887 wxPoint pt
= event
.GetPosition();
890 orient
= wxHORIZONTAL
;
898 else // we're lower or to the right of the window
900 wxSize size
= m_targetWindow
->GetClientSize();
903 orient
= wxHORIZONTAL
;
904 pos
= m_xScrollLines
;
906 else if ( pt
.y
> size
.y
)
909 pos
= m_yScrollLines
;
911 else // this should be impossible
913 // but seems to happen sometimes under wxMSW - maybe it's a bug
914 // there but for now just ignore it
916 //wxFAIL_MSG( _T("can't understand where has mouse gone") );
922 // only start the auto scroll timer if the window can be scrolled in
924 if ( !m_targetWindow
->HasScrollbar(orient
) )
927 delete m_timerAutoScroll
;
928 m_timerAutoScroll
= new wxAutoScrollTimer
930 m_targetWindow
, this,
931 pos
== 0 ? wxEVT_SCROLLWIN_LINEUP
932 : wxEVT_SCROLLWIN_LINEDOWN
,
936 m_timerAutoScroll
->Start(50); // FIXME: make configurable
940 void wxScrollHelper::HandleOnMouseWheel(wxMouseEvent
& event
)
942 m_wheelRotation
+= event
.GetWheelRotation();
943 int lines
= m_wheelRotation
/ event
.GetWheelDelta();
944 m_wheelRotation
-= lines
* event
.GetWheelDelta();
948 lines
*= event
.GetLinesPerAction();
951 GetViewStart(&vsx
, &vsy
);
952 Scroll(-1, vsy
- lines
);
956 // ----------------------------------------------------------------------------
957 // wxGenericScrolledWindow implementation
958 // ----------------------------------------------------------------------------
960 IMPLEMENT_DYNAMIC_CLASS(wxGenericScrolledWindow
, wxPanel
)
962 bool wxGenericScrolledWindow::Create(wxWindow
*parent
,
967 const wxString
& name
)
969 m_targetWindow
= this;
971 bool ok
= wxPanel::Create(parent
, id
, pos
, size
, style
, name
);
974 // we need to process arrows ourselves for scrolling
975 m_lDlgCode
|= DLGC_WANTARROWS
;
981 wxGenericScrolledWindow::~wxGenericScrolledWindow()
985 #if WXWIN_COMPATIBILITY
986 void wxGenericScrolledWindow::GetScrollUnitsPerPage (int *x_page
, int *y_page
) const
988 *x_page
= GetScrollPageSize(wxHORIZONTAL
);
989 *y_page
= GetScrollPageSize(wxVERTICAL
);
992 void wxGenericScrolledWindow::CalcUnscrolledPosition(int x
, int y
, float *xx
, float *yy
) const
995 *xx
= (float)(x
+ m_xScrollPosition
* m_xScrollPixelsPerLine
);
997 *yy
= (float)(y
+ m_yScrollPosition
* m_yScrollPixelsPerLine
);
999 #endif // WXWIN_COMPATIBILITY