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 "genscrolwin.h"
25 #define XtDisplay XTDISPLAY
28 // For compilers that support precompilation, includes "wx.h".
29 #include "wx/wxprec.h"
35 #if !defined(__WXGTK__) || defined(__WXUNIVERSAL__)
38 #include "wx/dcclient.h"
40 #include "wx/scrolwin.h"
45 #include <windows.h> // for DLGC_WANTARROWS
49 // For wxRETAINED implementation
50 #ifdef __VMS__ //VMS's Xm.h is not (yet) compatible with C++
51 //This code switches off the compiler warnings
52 # pragma message disable nosimpint
56 # pragma message enable nosimpint
60 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 wxEventType evType
= event
.GetEventType();
172 if ( evType
== wxEVT_SIZE
)
174 m_scrollHelper
->HandleOnSize((wxSizeEvent
&)event
);
177 if ( wxEvtHandler::ProcessEvent(event
) )
180 // reset the skipped flag to FALSE as it might have been set to TRUE in
181 // ProcessEvent() above
184 if ( evType
== wxEVT_PAINT
)
186 m_scrollHelper
->HandleOnPaint((wxPaintEvent
&)event
);
190 if ( evType
== wxEVT_SCROLLWIN_TOP
||
191 evType
== wxEVT_SCROLLWIN_BOTTOM
||
192 evType
== wxEVT_SCROLLWIN_LINEUP
||
193 evType
== wxEVT_SCROLLWIN_LINEDOWN
||
194 evType
== wxEVT_SCROLLWIN_PAGEUP
||
195 evType
== wxEVT_SCROLLWIN_PAGEDOWN
||
196 evType
== wxEVT_SCROLLWIN_THUMBTRACK
||
197 evType
== wxEVT_SCROLLWIN_THUMBRELEASE
)
199 m_scrollHelper
->HandleOnScroll((wxScrollWinEvent
&)event
);
200 return !event
.GetSkipped();
203 if ( evType
== wxEVT_ENTER_WINDOW
)
205 m_scrollHelper
->HandleOnMouseEnter((wxMouseEvent
&)event
);
207 else if ( evType
== wxEVT_LEAVE_WINDOW
)
209 m_scrollHelper
->HandleOnMouseLeave((wxMouseEvent
&)event
);
212 else if ( evType
== wxEVT_MOUSEWHEEL
)
214 m_scrollHelper
->HandleOnMouseWheel((wxMouseEvent
&)event
);
216 #endif // wxUSE_MOUSEWHEEL
217 else if ( evType
== wxEVT_CHAR
)
219 m_scrollHelper
->HandleOnChar((wxKeyEvent
&)event
);
220 return !event
.GetSkipped();
226 // ----------------------------------------------------------------------------
227 // wxScrollHelper construction
228 // ----------------------------------------------------------------------------
230 wxScrollHelper::wxScrollHelper(wxWindow
*win
)
232 m_xScrollPixelsPerLine
=
233 m_yScrollPixelsPerLine
=
238 m_xScrollLinesPerPage
=
239 m_yScrollLinesPerPage
= 0;
241 m_xScrollingEnabled
=
242 m_yScrollingEnabled
= TRUE
;
251 m_targetWindow
= (wxWindow
*)NULL
;
253 m_timerAutoScroll
= (wxTimer
*)NULL
;
259 void wxScrollHelper::SetWindow(wxWindow
*win
)
261 wxCHECK_RET( win
, _T("wxScrollHelper needs a window to scroll") );
263 m_targetWindow
= m_win
= win
;
265 // install the event handler which will intercept the events we're
267 m_win
->PushEventHandler(new wxScrollHelperEvtHandler(this));
270 wxScrollHelper::~wxScrollHelper()
274 if ( m_targetWindow
)
275 m_targetWindow
->PopEventHandler(TRUE
/* do delete it */);
278 // ----------------------------------------------------------------------------
279 // setting scrolling parameters
280 // ----------------------------------------------------------------------------
282 void wxScrollHelper::SetScrollbars(int pixelsPerUnitX
,
292 CalcUnscrolledPosition(xPos
, yPos
, &xpos
, &ypos
);
295 (noUnitsX
!= 0 && m_xScrollLines
== 0) ||
296 (noUnitsX
< m_xScrollLines
&& xpos
> pixelsPerUnitX
*noUnitsX
) ||
298 (noUnitsY
!= 0 && m_yScrollLines
== 0) ||
299 (noUnitsY
< m_yScrollLines
&& ypos
> pixelsPerUnitY
*noUnitsY
) ||
300 (xPos
!= m_xScrollPosition
) ||
301 (yPos
!= m_yScrollPosition
)
304 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
305 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
306 m_xScrollPosition
= xPos
;
307 m_yScrollPosition
= yPos
;
308 m_xScrollLines
= noUnitsX
;
309 m_yScrollLines
= noUnitsY
;
312 // Sorry, some Motif-specific code to implement a backing pixmap
313 // for the wxRETAINED style. Implementing a backing store can't
314 // be entirely generic because it relies on the wxWindowDC implementation
315 // to duplicate X drawing calls for the backing pixmap.
317 if ( m_targetWindow
->GetWindowStyle() & wxRETAINED
)
319 Display
* dpy
= XtDisplay((Widget
)m_targetWindow
->GetMainWidget());
321 int totalPixelWidth
= m_xScrollLines
* m_xScrollPixelsPerLine
;
322 int totalPixelHeight
= m_yScrollLines
* m_yScrollPixelsPerLine
;
323 if (m_targetWindow
->GetBackingPixmap() &&
324 !((m_targetWindow
->GetPixmapWidth() == totalPixelWidth
) &&
325 (m_targetWindow
->GetPixmapHeight() == totalPixelHeight
)))
327 XFreePixmap (dpy
, (Pixmap
) m_targetWindow
->GetBackingPixmap());
328 m_targetWindow
->SetBackingPixmap((WXPixmap
) 0);
331 if (!m_targetWindow
->GetBackingPixmap() &&
332 (noUnitsX
!= 0) && (noUnitsY
!= 0))
334 int depth
= wxDisplayDepth();
335 m_targetWindow
->SetPixmapWidth(totalPixelWidth
);
336 m_targetWindow
->SetPixmapHeight(totalPixelHeight
);
337 m_targetWindow
->SetBackingPixmap((WXPixmap
) XCreatePixmap (dpy
, RootWindow (dpy
, DefaultScreen (dpy
)),
338 m_targetWindow
->GetPixmapWidth(), m_targetWindow
->GetPixmapHeight(), depth
));
346 if (do_refresh
&& !noRefresh
)
347 m_targetWindow
->Refresh(TRUE
, GetRect());
350 m_targetWindow
->MacUpdateImmediately() ;
354 // ----------------------------------------------------------------------------
355 // target window handling
356 // ----------------------------------------------------------------------------
358 void wxScrollHelper::SetTargetWindow( wxWindow
*target
)
360 wxASSERT_MSG( target
, wxT("target window must not be NULL") );
361 m_targetWindow
= target
;
364 wxWindow
*wxScrollHelper::GetTargetWindow() const
366 return m_targetWindow
;
369 // ----------------------------------------------------------------------------
370 // scrolling implementation itself
371 // ----------------------------------------------------------------------------
373 void wxScrollHelper::HandleOnScroll(wxScrollWinEvent
& event
)
375 int nScrollInc
= CalcScrollInc(event
);
376 if ( nScrollInc
== 0 )
378 // can't scroll further
384 int orient
= event
.GetOrientation();
385 if (orient
== wxHORIZONTAL
)
387 m_xScrollPosition
+= nScrollInc
;
388 m_targetWindow
->SetScrollPos(wxHORIZONTAL
, m_xScrollPosition
);
392 m_yScrollPosition
+= nScrollInc
;
393 m_targetWindow
->SetScrollPos(wxVERTICAL
, m_yScrollPosition
);
396 bool needsRefresh
= FALSE
;
399 if (orient
== wxHORIZONTAL
)
401 if ( m_xScrollingEnabled
)
403 dx
= -m_xScrollPixelsPerLine
* nScrollInc
;
412 if ( m_yScrollingEnabled
)
414 dy
= -m_yScrollPixelsPerLine
* nScrollInc
;
424 m_targetWindow
->Refresh(TRUE
, GetRect());
428 m_targetWindow
->ScrollWindow(dx
, dy
, GetRect());
432 m_targetWindow
->MacUpdateImmediately() ;
436 int wxScrollHelper::CalcScrollInc(wxScrollWinEvent
& event
)
438 int pos
= event
.GetPosition();
439 int orient
= event
.GetOrientation();
442 if (event
.GetEventType() == wxEVT_SCROLLWIN_TOP
)
444 if (orient
== wxHORIZONTAL
)
445 nScrollInc
= - m_xScrollPosition
;
447 nScrollInc
= - m_yScrollPosition
;
449 if (event
.GetEventType() == wxEVT_SCROLLWIN_BOTTOM
)
451 if (orient
== wxHORIZONTAL
)
452 nScrollInc
= m_xScrollLines
- m_xScrollPosition
;
454 nScrollInc
= m_yScrollLines
- m_yScrollPosition
;
456 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEUP
)
460 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN
)
464 if (event
.GetEventType() == wxEVT_SCROLLWIN_PAGEUP
)
466 if (orient
== wxHORIZONTAL
)
467 nScrollInc
= -GetScrollPageSize(wxHORIZONTAL
);
469 nScrollInc
= -GetScrollPageSize(wxVERTICAL
);
471 if (event
.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN
)
473 if (orient
== wxHORIZONTAL
)
474 nScrollInc
= GetScrollPageSize(wxHORIZONTAL
);
476 nScrollInc
= GetScrollPageSize(wxVERTICAL
);
478 if ((event
.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK
) ||
479 (event
.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE
))
481 if (orient
== wxHORIZONTAL
)
482 nScrollInc
= pos
- m_xScrollPosition
;
484 nScrollInc
= pos
- m_yScrollPosition
;
487 if (orient
== wxHORIZONTAL
)
489 if (m_xScrollPixelsPerLine
> 0)
492 GetTargetSize(&w
, &h
);
494 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
495 int noPositions
= (int) ( ((nMaxWidth
- w
)/(double)m_xScrollPixelsPerLine
) + 0.5 );
499 if ( (m_xScrollPosition
+ nScrollInc
) < 0 )
500 nScrollInc
= -m_xScrollPosition
; // As -ve as we can go
501 else if ( (m_xScrollPosition
+ nScrollInc
) > noPositions
)
502 nScrollInc
= noPositions
- m_xScrollPosition
; // As +ve as we can go
505 m_targetWindow
->Refresh(TRUE
, GetRect());
509 if (m_yScrollPixelsPerLine
> 0)
512 GetTargetSize(&w
, &h
);
514 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
515 int noPositions
= (int) ( ((nMaxHeight
- h
)/(double)m_yScrollPixelsPerLine
) + 0.5 );
519 if ( (m_yScrollPosition
+ nScrollInc
) < 0 )
520 nScrollInc
= -m_yScrollPosition
; // As -ve as we can go
521 else if ( (m_yScrollPosition
+ nScrollInc
) > noPositions
)
522 nScrollInc
= noPositions
- m_yScrollPosition
; // As +ve as we can go
525 m_targetWindow
->Refresh(TRUE
, GetRect());
531 // Adjust the scrollbars - new version.
532 void wxScrollHelper::AdjustScrollbars()
535 m_targetWindow
->MacUpdateImmediately();
539 GetTargetSize(&w
, &h
);
541 int oldXScroll
= m_xScrollPosition
;
542 int oldYScroll
= m_yScrollPosition
;
544 if (m_xScrollLines
> 0)
546 // Calculate page size i.e. number of scroll units you get on the
547 // current client window
548 int noPagePositions
= (int) ( (w
/(double)m_xScrollPixelsPerLine
) + 0.5 );
549 if (noPagePositions
< 1) noPagePositions
= 1;
550 if ( noPagePositions
> m_xScrollLines
)
551 noPagePositions
= m_xScrollLines
;
553 // Correct position if greater than extent of canvas minus
554 // the visible portion of it or if below zero
555 m_xScrollPosition
= wxMin( m_xScrollLines
-noPagePositions
, m_xScrollPosition
);
556 m_xScrollPosition
= wxMax( 0, m_xScrollPosition
);
558 m_targetWindow
->SetScrollbar(wxHORIZONTAL
, m_xScrollPosition
, noPagePositions
, m_xScrollLines
);
559 // The amount by which we scroll when paging
560 SetScrollPageSize(wxHORIZONTAL
, noPagePositions
);
564 m_xScrollPosition
= 0;
565 m_targetWindow
->SetScrollbar (wxHORIZONTAL
, 0, 0, 0, FALSE
);
568 if (m_yScrollLines
> 0)
570 // Calculate page size i.e. number of scroll units you get on the
571 // current client window
572 int noPagePositions
= (int) ( (h
/(double)m_yScrollPixelsPerLine
) + 0.5 );
573 if (noPagePositions
< 1) noPagePositions
= 1;
574 if ( noPagePositions
> m_yScrollLines
)
575 noPagePositions
= m_yScrollLines
;
577 // Correct position if greater than extent of canvas minus
578 // the visible portion of it or if below zero
579 m_yScrollPosition
= wxMin( m_yScrollLines
-noPagePositions
, m_yScrollPosition
);
580 m_yScrollPosition
= wxMax( 0, m_yScrollPosition
);
582 m_targetWindow
->SetScrollbar(wxVERTICAL
, m_yScrollPosition
, noPagePositions
, m_yScrollLines
);
583 // The amount by which we scroll when paging
584 SetScrollPageSize(wxVERTICAL
, noPagePositions
);
588 m_yScrollPosition
= 0;
589 m_targetWindow
->SetScrollbar (wxVERTICAL
, 0, 0, 0, FALSE
);
592 if (oldXScroll
!= m_xScrollPosition
)
594 if (m_xScrollingEnabled
)
595 m_targetWindow
->ScrollWindow( m_xScrollPixelsPerLine
* (oldXScroll
-m_xScrollPosition
), 0,
598 m_targetWindow
->Refresh(TRUE
, GetRect());
601 if (oldYScroll
!= m_yScrollPosition
)
603 if (m_yScrollingEnabled
)
604 m_targetWindow
->ScrollWindow( 0, m_yScrollPixelsPerLine
* (oldYScroll
-m_yScrollPosition
),
607 m_targetWindow
->Refresh(TRUE
, GetRect());
611 m_targetWindow
->MacUpdateImmediately();
615 void wxScrollHelper::DoPrepareDC(wxDC
& dc
)
617 wxPoint pt
= dc
.GetDeviceOrigin();
618 dc
.SetDeviceOrigin( pt
.x
- m_xScrollPosition
* m_xScrollPixelsPerLine
,
619 pt
.y
- m_yScrollPosition
* m_yScrollPixelsPerLine
);
620 dc
.SetUserScale( m_scaleX
, m_scaleY
);
623 void wxScrollHelper::GetScrollPixelsPerUnit (int *x_unit
, int *y_unit
) const
626 *x_unit
= m_xScrollPixelsPerLine
;
628 *y_unit
= m_yScrollPixelsPerLine
;
631 int wxScrollHelper::GetScrollPageSize(int orient
) const
633 if ( orient
== wxHORIZONTAL
)
634 return m_xScrollLinesPerPage
;
636 return m_yScrollLinesPerPage
;
639 void wxScrollHelper::SetScrollPageSize(int orient
, int pageSize
)
641 if ( orient
== wxHORIZONTAL
)
642 m_xScrollLinesPerPage
= pageSize
;
644 m_yScrollLinesPerPage
= pageSize
;
648 * Scroll to given position (scroll position, not pixel position)
650 void wxScrollHelper::Scroll( int x_pos
, int y_pos
)
655 if (((x_pos
== -1) || (x_pos
== m_xScrollPosition
)) &&
656 ((y_pos
== -1) || (y_pos
== m_yScrollPosition
))) return;
659 m_targetWindow
->MacUpdateImmediately();
663 GetTargetSize(&w
, &h
);
665 if ((x_pos
!= -1) && (m_xScrollPixelsPerLine
))
667 int old_x
= m_xScrollPosition
;
668 m_xScrollPosition
= x_pos
;
670 // Calculate page size i.e. number of scroll units you get on the
671 // current client window
672 int noPagePositions
= (int) ( (w
/(double)m_xScrollPixelsPerLine
) + 0.5 );
673 if (noPagePositions
< 1) noPagePositions
= 1;
675 // Correct position if greater than extent of canvas minus
676 // the visible portion of it or if below zero
677 m_xScrollPosition
= wxMin( m_xScrollLines
-noPagePositions
, m_xScrollPosition
);
678 m_xScrollPosition
= wxMax( 0, m_xScrollPosition
);
680 if (old_x
!= m_xScrollPosition
) {
681 m_targetWindow
->SetScrollPos( wxHORIZONTAL
, m_xScrollPosition
);
682 m_targetWindow
->ScrollWindow( (old_x
-m_xScrollPosition
)*m_xScrollPixelsPerLine
, 0,
686 if ((y_pos
!= -1) && (m_yScrollPixelsPerLine
))
688 int old_y
= m_yScrollPosition
;
689 m_yScrollPosition
= y_pos
;
691 // Calculate page size i.e. number of scroll units you get on the
692 // current client window
693 int noPagePositions
= (int) ( (h
/(double)m_yScrollPixelsPerLine
) + 0.5 );
694 if (noPagePositions
< 1) noPagePositions
= 1;
696 // Correct position if greater than extent of canvas minus
697 // the visible portion of it or if below zero
698 m_yScrollPosition
= wxMin( m_yScrollLines
-noPagePositions
, m_yScrollPosition
);
699 m_yScrollPosition
= wxMax( 0, m_yScrollPosition
);
701 if (old_y
!= m_yScrollPosition
) {
702 m_targetWindow
->SetScrollPos( wxVERTICAL
, m_yScrollPosition
);
703 m_targetWindow
->ScrollWindow( 0, (old_y
-m_yScrollPosition
)*m_yScrollPixelsPerLine
,
709 m_targetWindow
->MacUpdateImmediately();
714 void wxScrollHelper::EnableScrolling (bool x_scroll
, bool y_scroll
)
716 m_xScrollingEnabled
= x_scroll
;
717 m_yScrollingEnabled
= y_scroll
;
720 void wxScrollHelper::GetVirtualSize (int *x
, int *y
) const
723 *x
= m_xScrollPixelsPerLine
* m_xScrollLines
;
725 *y
= m_yScrollPixelsPerLine
* m_yScrollLines
;
728 // Where the current view starts from
729 void wxScrollHelper::GetViewStart (int *x
, int *y
) const
732 *x
= m_xScrollPosition
;
734 *y
= m_yScrollPosition
;
737 void wxScrollHelper::CalcScrolledPosition(int x
, int y
, int *xx
, int *yy
) const
740 *xx
= x
- m_xScrollPosition
* m_xScrollPixelsPerLine
;
742 *yy
= y
- m_yScrollPosition
* m_yScrollPixelsPerLine
;
745 void wxScrollHelper::CalcUnscrolledPosition(int x
, int y
, int *xx
, int *yy
) const
748 *xx
= x
+ m_xScrollPosition
* m_xScrollPixelsPerLine
;
750 *yy
= y
+ m_yScrollPosition
* m_yScrollPixelsPerLine
;
753 // ----------------------------------------------------------------------------
755 // ----------------------------------------------------------------------------
757 // Default OnSize resets scrollbars, if any
758 void wxScrollHelper::HandleOnSize(wxSizeEvent
& WXUNUSED(event
))
760 #if wxUSE_CONSTRAINTS
761 if ( m_targetWindow
->GetAutoLayout() )
762 m_targetWindow
->Layout();
768 // This calls OnDraw, having adjusted the origin according to the current
770 void wxScrollHelper::HandleOnPaint(wxPaintEvent
& WXUNUSED(event
))
772 wxPaintDC
dc(m_targetWindow
);
778 // kbd handling: notice that we use OnChar() and not OnKeyDown() for
779 // compatibility here - if we used OnKeyDown(), the programs which process
780 // arrows themselves in their OnChar() would never get the message and like
781 // this they always have the priority
782 void wxScrollHelper::HandleOnChar(wxKeyEvent
& event
)
784 int stx
, sty
, // view origin
785 szx
, szy
, // view size (total)
786 clix
, cliy
; // view size (on screen)
788 GetViewStart(&stx
, &sty
);
789 GetTargetSize(&clix
, &cliy
);
790 GetVirtualSize(&szx
, &szy
);
792 if( m_xScrollPixelsPerLine
)
794 clix
/= m_xScrollPixelsPerLine
;
795 szx
/= m_xScrollPixelsPerLine
;
802 if( m_yScrollPixelsPerLine
)
804 cliy
/= m_yScrollPixelsPerLine
;
805 szy
/= m_yScrollPixelsPerLine
;
813 int xScrollOld
= m_xScrollPosition
,
814 yScrollOld
= m_yScrollPosition
;
817 switch ( event
.KeyCode() )
821 dsty
= sty
- (5 * cliy
/ 6);
822 Scroll(-1, (dsty
== -1) ? 0 : dsty
);
827 Scroll(-1, sty
+ (5 * cliy
/ 6));
831 Scroll(0, event
.ControlDown() ? 0 : -1);
835 Scroll(szx
- clix
, event
.ControlDown() ? szy
- cliy
: -1);
859 if ( m_xScrollPosition
!= xScrollOld
)
861 wxScrollWinEvent
event(wxEVT_SCROLLWIN_THUMBTRACK
, m_xScrollPosition
,
863 event
.SetEventObject(m_win
);
864 m_win
->GetEventHandler()->ProcessEvent(event
);
867 if ( m_yScrollPosition
!= yScrollOld
)
869 wxScrollWinEvent
event(wxEVT_SCROLLWIN_THUMBTRACK
, m_yScrollPosition
,
871 event
.SetEventObject(m_win
);
872 m_win
->GetEventHandler()->ProcessEvent(event
);
876 // ----------------------------------------------------------------------------
877 // autoscroll stuff: these functions deal with sending fake scroll events when
878 // a captured mouse is being held outside the window
879 // ----------------------------------------------------------------------------
881 bool wxScrollHelper::SendAutoScrollEvents(wxScrollWinEvent
& event
) const
883 // only send the event if the window is scrollable in this direction
884 wxWindow
*win
= (wxWindow
*)event
.GetEventObject();
885 return win
->HasScrollbar(event
.GetOrientation());
888 void wxScrollHelper::StopAutoScrolling()
890 if ( m_timerAutoScroll
)
892 delete m_timerAutoScroll
;
893 m_timerAutoScroll
= (wxTimer
*)NULL
;
897 void wxScrollHelper::HandleOnMouseEnter(wxMouseEvent
& event
)
904 void wxScrollHelper::HandleOnMouseLeave(wxMouseEvent
& event
)
906 // don't prevent the usual processing of the event from taking place
909 // when a captured mouse leave a scrolled window we start generate
910 // scrolling events to allow, for example, extending selection beyond the
911 // visible area in some controls
912 if ( wxWindow::GetCapture() == m_targetWindow
)
914 // where is the mouse leaving?
916 wxPoint pt
= event
.GetPosition();
919 orient
= wxHORIZONTAL
;
927 else // we're lower or to the right of the window
929 wxSize size
= m_targetWindow
->GetClientSize();
932 orient
= wxHORIZONTAL
;
933 pos
= m_xScrollLines
;
935 else if ( pt
.y
> size
.y
)
938 pos
= m_yScrollLines
;
940 else // this should be impossible
942 // but seems to happen sometimes under wxMSW - maybe it's a bug
943 // there but for now just ignore it
945 //wxFAIL_MSG( _T("can't understand where has mouse gone") );
951 // only start the auto scroll timer if the window can be scrolled in
953 if ( !m_targetWindow
->HasScrollbar(orient
) )
956 delete m_timerAutoScroll
;
957 m_timerAutoScroll
= new wxAutoScrollTimer
959 m_targetWindow
, this,
960 pos
== 0 ? wxEVT_SCROLLWIN_LINEUP
961 : wxEVT_SCROLLWIN_LINEDOWN
,
965 m_timerAutoScroll
->Start(50); // FIXME: make configurable
971 void wxScrollHelper::HandleOnMouseWheel(wxMouseEvent
& event
)
973 m_wheelRotation
+= event
.GetWheelRotation();
974 int lines
= m_wheelRotation
/ event
.GetWheelDelta();
975 m_wheelRotation
-= lines
* event
.GetWheelDelta();
979 lines
*= event
.GetLinesPerAction();
982 GetViewStart(&vsx
, &vsy
);
983 Scroll(-1, vsy
- lines
);
987 #endif // wxUSE_MOUSEWHEEL
989 // ----------------------------------------------------------------------------
990 // wxGenericScrolledWindow implementation
991 // ----------------------------------------------------------------------------
993 IMPLEMENT_DYNAMIC_CLASS(wxGenericScrolledWindow
, wxPanel
)
995 bool wxGenericScrolledWindow::Create(wxWindow
*parent
,
1000 const wxString
& name
)
1002 m_targetWindow
= this;
1004 bool ok
= wxPanel::Create(parent
, id
, pos
, size
, style
, name
);
1007 // we need to process arrows ourselves for scrolling
1008 m_lDlgCode
|= DLGC_WANTARROWS
;
1014 wxGenericScrolledWindow::~wxGenericScrolledWindow()
1018 #if WXWIN_COMPATIBILITY
1019 void wxGenericScrolledWindow::GetScrollUnitsPerPage (int *x_page
, int *y_page
) const
1021 *x_page
= GetScrollPageSize(wxHORIZONTAL
);
1022 *y_page
= GetScrollPageSize(wxVERTICAL
);
1025 void wxGenericScrolledWindow::CalcUnscrolledPosition(int x
, int y
, float *xx
, float *yy
) const
1028 *xx
= (float)(x
+ m_xScrollPosition
* m_xScrollPixelsPerLine
);
1030 *yy
= (float)(y
+ m_yScrollPosition
* m_yScrollPixelsPerLine
);
1032 #endif // WXWIN_COMPATIBILITY