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 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
;
250 m_targetWindow
= (wxWindow
*)NULL
;
252 m_timerAutoScroll
= (wxTimer
*)NULL
;
258 void wxScrollHelper::SetWindow(wxWindow
*win
)
260 wxCHECK_RET( win
, _T("wxScrollHelper needs a window to scroll") );
262 m_targetWindow
= m_win
= win
;
264 // install the event handler which will intercept the events we're
266 m_win
->PushEventHandler(new wxScrollHelperEvtHandler(this));
269 wxScrollHelper::~wxScrollHelper()
273 if ( m_targetWindow
)
274 m_targetWindow
->PopEventHandler(TRUE
/* do delete it */);
277 // ----------------------------------------------------------------------------
278 // setting scrolling parameters
279 // ----------------------------------------------------------------------------
281 void wxScrollHelper::SetScrollbars(int pixelsPerUnitX
,
291 CalcUnscrolledPosition(xPos
, yPos
, &xpos
, &ypos
);
294 (noUnitsX
!= 0 && m_xScrollLines
== 0) ||
295 (noUnitsX
< m_xScrollLines
&& xpos
> pixelsPerUnitX
*noUnitsX
) ||
297 (noUnitsY
!= 0 && m_yScrollLines
== 0) ||
298 (noUnitsY
< m_yScrollLines
&& ypos
> pixelsPerUnitY
*noUnitsY
) ||
299 (xPos
!= m_xScrollPosition
) ||
300 (yPos
!= m_yScrollPosition
)
303 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
304 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
305 m_xScrollPosition
= xPos
;
306 m_yScrollPosition
= yPos
;
307 m_xScrollLines
= noUnitsX
;
308 m_yScrollLines
= noUnitsY
;
311 // Sorry, some Motif-specific code to implement a backing pixmap
312 // for the wxRETAINED style. Implementing a backing store can't
313 // be entirely generic because it relies on the wxWindowDC implementation
314 // to duplicate X drawing calls for the backing pixmap.
316 if ( m_targetWindow
->GetWindowStyle() & wxRETAINED
)
318 Display
* dpy
= XtDisplay((Widget
)m_targetWindow
->GetMainWidget());
320 int totalPixelWidth
= m_xScrollLines
* m_xScrollPixelsPerLine
;
321 int totalPixelHeight
= m_yScrollLines
* m_yScrollPixelsPerLine
;
322 if (m_targetWindow
->GetBackingPixmap() &&
323 !((m_targetWindow
->GetPixmapWidth() == totalPixelWidth
) &&
324 (m_targetWindow
->GetPixmapHeight() == totalPixelHeight
)))
326 XFreePixmap (dpy
, (Pixmap
) m_targetWindow
->GetBackingPixmap());
327 m_targetWindow
->SetBackingPixmap((WXPixmap
) 0);
330 if (!m_targetWindow
->GetBackingPixmap() &&
331 (noUnitsX
!= 0) && (noUnitsY
!= 0))
333 int depth
= wxDisplayDepth();
334 m_targetWindow
->SetPixmapWidth(totalPixelWidth
);
335 m_targetWindow
->SetPixmapHeight(totalPixelHeight
);
336 m_targetWindow
->SetBackingPixmap((WXPixmap
) XCreatePixmap (dpy
, RootWindow (dpy
, DefaultScreen (dpy
)),
337 m_targetWindow
->GetPixmapWidth(), m_targetWindow
->GetPixmapHeight(), depth
));
345 if (do_refresh
&& !noRefresh
)
346 m_targetWindow
->Refresh(TRUE
, GetRect());
349 m_targetWindow
->MacUpdateImmediately() ;
353 // ----------------------------------------------------------------------------
354 // target window handling
355 // ----------------------------------------------------------------------------
357 void wxScrollHelper::SetTargetWindow( wxWindow
*target
)
359 wxASSERT_MSG( target
, wxT("target window must not be NULL") );
360 m_targetWindow
= target
;
363 wxWindow
*wxScrollHelper::GetTargetWindow() const
365 return m_targetWindow
;
368 // ----------------------------------------------------------------------------
369 // scrolling implementation itself
370 // ----------------------------------------------------------------------------
372 void wxScrollHelper::HandleOnScroll(wxScrollWinEvent
& event
)
374 int nScrollInc
= CalcScrollInc(event
);
375 if ( nScrollInc
== 0 )
377 // can't scroll further
383 int orient
= event
.GetOrientation();
384 if (orient
== wxHORIZONTAL
)
386 m_xScrollPosition
+= nScrollInc
;
387 m_targetWindow
->SetScrollPos(wxHORIZONTAL
, m_xScrollPosition
);
391 m_yScrollPosition
+= nScrollInc
;
392 m_targetWindow
->SetScrollPos(wxVERTICAL
, m_yScrollPosition
);
395 bool needsRefresh
= FALSE
;
398 if (orient
== wxHORIZONTAL
)
400 if ( m_xScrollingEnabled
)
402 dx
= -m_xScrollPixelsPerLine
* nScrollInc
;
411 if ( m_yScrollingEnabled
)
413 dy
= -m_yScrollPixelsPerLine
* nScrollInc
;
423 m_targetWindow
->Refresh(TRUE
, GetRect());
427 m_targetWindow
->ScrollWindow(dx
, dy
, GetRect());
431 m_targetWindow
->MacUpdateImmediately() ;
435 int wxScrollHelper::CalcScrollInc(wxScrollWinEvent
& event
)
437 int pos
= event
.GetPosition();
438 int orient
= event
.GetOrientation();
441 if (event
.GetEventType() == wxEVT_SCROLLWIN_TOP
)
443 if (orient
== wxHORIZONTAL
)
444 nScrollInc
= - m_xScrollPosition
;
446 nScrollInc
= - m_yScrollPosition
;
448 if (event
.GetEventType() == wxEVT_SCROLLWIN_BOTTOM
)
450 if (orient
== wxHORIZONTAL
)
451 nScrollInc
= m_xScrollLines
- m_xScrollPosition
;
453 nScrollInc
= m_yScrollLines
- m_yScrollPosition
;
455 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEUP
)
459 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN
)
463 if (event
.GetEventType() == wxEVT_SCROLLWIN_PAGEUP
)
465 if (orient
== wxHORIZONTAL
)
466 nScrollInc
= -GetScrollPageSize(wxHORIZONTAL
);
468 nScrollInc
= -GetScrollPageSize(wxVERTICAL
);
470 if (event
.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN
)
472 if (orient
== wxHORIZONTAL
)
473 nScrollInc
= GetScrollPageSize(wxHORIZONTAL
);
475 nScrollInc
= GetScrollPageSize(wxVERTICAL
);
477 if ((event
.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK
) ||
478 (event
.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE
))
480 if (orient
== wxHORIZONTAL
)
481 nScrollInc
= pos
- m_xScrollPosition
;
483 nScrollInc
= pos
- m_yScrollPosition
;
486 if (orient
== wxHORIZONTAL
)
488 if (m_xScrollPixelsPerLine
> 0)
491 GetTargetSize(&w
, &h
);
493 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
494 int noPositions
= (int) ( ((nMaxWidth
- w
)/(double)m_xScrollPixelsPerLine
) + 0.5 );
498 if ( (m_xScrollPosition
+ nScrollInc
) < 0 )
499 nScrollInc
= -m_xScrollPosition
; // As -ve as we can go
500 else if ( (m_xScrollPosition
+ nScrollInc
) > noPositions
)
501 nScrollInc
= noPositions
- m_xScrollPosition
; // As +ve as we can go
504 m_targetWindow
->Refresh(TRUE
, GetRect());
508 if (m_yScrollPixelsPerLine
> 0)
511 GetTargetSize(&w
, &h
);
513 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
514 int noPositions
= (int) ( ((nMaxHeight
- h
)/(double)m_yScrollPixelsPerLine
) + 0.5 );
518 if ( (m_yScrollPosition
+ nScrollInc
) < 0 )
519 nScrollInc
= -m_yScrollPosition
; // As -ve as we can go
520 else if ( (m_yScrollPosition
+ nScrollInc
) > noPositions
)
521 nScrollInc
= noPositions
- m_yScrollPosition
; // As +ve as we can go
524 m_targetWindow
->Refresh(TRUE
, GetRect());
530 // Adjust the scrollbars - new version.
531 void wxScrollHelper::AdjustScrollbars()
534 m_targetWindow
->MacUpdateImmediately();
538 GetTargetSize(&w
, &h
);
540 int oldXScroll
= m_xScrollPosition
;
541 int oldYScroll
= m_yScrollPosition
;
543 if (m_xScrollLines
> 0)
545 // Calculate page size i.e. number of scroll units you get on the
546 // current client window
547 int noPagePositions
= (int) ( (w
/(double)m_xScrollPixelsPerLine
) + 0.5 );
548 if (noPagePositions
< 1) noPagePositions
= 1;
549 if ( noPagePositions
> m_xScrollLines
)
550 noPagePositions
= m_xScrollLines
;
552 // Correct position if greater than extent of canvas minus
553 // the visible portion of it or if below zero
554 m_xScrollPosition
= wxMin( m_xScrollLines
-noPagePositions
, m_xScrollPosition
);
555 m_xScrollPosition
= wxMax( 0, m_xScrollPosition
);
557 m_targetWindow
->SetScrollbar(wxHORIZONTAL
, m_xScrollPosition
, noPagePositions
, m_xScrollLines
);
558 // The amount by which we scroll when paging
559 SetScrollPageSize(wxHORIZONTAL
, noPagePositions
);
563 m_xScrollPosition
= 0;
564 m_targetWindow
->SetScrollbar (wxHORIZONTAL
, 0, 0, 0, FALSE
);
567 if (m_yScrollLines
> 0)
569 // Calculate page size i.e. number of scroll units you get on the
570 // current client window
571 int noPagePositions
= (int) ( (h
/(double)m_yScrollPixelsPerLine
) + 0.5 );
572 if (noPagePositions
< 1) noPagePositions
= 1;
573 if ( noPagePositions
> m_yScrollLines
)
574 noPagePositions
= m_yScrollLines
;
576 // Correct position if greater than extent of canvas minus
577 // the visible portion of it or if below zero
578 m_yScrollPosition
= wxMin( m_yScrollLines
-noPagePositions
, m_yScrollPosition
);
579 m_yScrollPosition
= wxMax( 0, m_yScrollPosition
);
581 m_targetWindow
->SetScrollbar(wxVERTICAL
, m_yScrollPosition
, noPagePositions
, m_yScrollLines
);
582 // The amount by which we scroll when paging
583 SetScrollPageSize(wxVERTICAL
, noPagePositions
);
587 m_yScrollPosition
= 0;
588 m_targetWindow
->SetScrollbar (wxVERTICAL
, 0, 0, 0, FALSE
);
591 if (oldXScroll
!= m_xScrollPosition
)
593 if (m_xScrollingEnabled
)
594 m_targetWindow
->ScrollWindow( m_xScrollPixelsPerLine
* (oldXScroll
-m_xScrollPosition
), 0,
597 m_targetWindow
->Refresh(TRUE
, GetRect());
600 if (oldYScroll
!= m_yScrollPosition
)
602 if (m_yScrollingEnabled
)
603 m_targetWindow
->ScrollWindow( 0, m_yScrollPixelsPerLine
* (oldYScroll
-m_yScrollPosition
),
606 m_targetWindow
->Refresh(TRUE
, GetRect());
610 m_targetWindow
->MacUpdateImmediately();
614 void wxScrollHelper::DoPrepareDC(wxDC
& dc
)
616 wxPoint pt
= dc
.GetDeviceOrigin();
617 dc
.SetDeviceOrigin( pt
.x
- m_xScrollPosition
* m_xScrollPixelsPerLine
,
618 pt
.y
- m_yScrollPosition
* m_yScrollPixelsPerLine
);
619 dc
.SetUserScale( m_scaleX
, m_scaleY
);
622 void wxScrollHelper::GetScrollPixelsPerUnit (int *x_unit
, int *y_unit
) const
625 *x_unit
= m_xScrollPixelsPerLine
;
627 *y_unit
= m_yScrollPixelsPerLine
;
630 int wxScrollHelper::GetScrollPageSize(int orient
) const
632 if ( orient
== wxHORIZONTAL
)
633 return m_xScrollLinesPerPage
;
635 return m_yScrollLinesPerPage
;
638 void wxScrollHelper::SetScrollPageSize(int orient
, int pageSize
)
640 if ( orient
== wxHORIZONTAL
)
641 m_xScrollLinesPerPage
= pageSize
;
643 m_yScrollLinesPerPage
= pageSize
;
647 * Scroll to given position (scroll position, not pixel position)
649 void wxScrollHelper::Scroll( int x_pos
, int y_pos
)
654 if (((x_pos
== -1) || (x_pos
== m_xScrollPosition
)) &&
655 ((y_pos
== -1) || (y_pos
== m_yScrollPosition
))) return;
658 m_targetWindow
->MacUpdateImmediately();
662 GetTargetSize(&w
, &h
);
664 if ((x_pos
!= -1) && (m_xScrollPixelsPerLine
))
666 int old_x
= m_xScrollPosition
;
667 m_xScrollPosition
= x_pos
;
669 // Calculate page size i.e. number of scroll units you get on the
670 // current client window
671 int noPagePositions
= (int) ( (w
/(double)m_xScrollPixelsPerLine
) + 0.5 );
672 if (noPagePositions
< 1) noPagePositions
= 1;
674 // Correct position if greater than extent of canvas minus
675 // the visible portion of it or if below zero
676 m_xScrollPosition
= wxMin( m_xScrollLines
-noPagePositions
, m_xScrollPosition
);
677 m_xScrollPosition
= wxMax( 0, m_xScrollPosition
);
679 if (old_x
!= m_xScrollPosition
) {
680 m_targetWindow
->SetScrollPos( wxHORIZONTAL
, m_xScrollPosition
);
681 m_targetWindow
->ScrollWindow( (old_x
-m_xScrollPosition
)*m_xScrollPixelsPerLine
, 0,
685 if ((y_pos
!= -1) && (m_yScrollPixelsPerLine
))
687 int old_y
= m_yScrollPosition
;
688 m_yScrollPosition
= y_pos
;
690 // Calculate page size i.e. number of scroll units you get on the
691 // current client window
692 int noPagePositions
= (int) ( (h
/(double)m_yScrollPixelsPerLine
) + 0.5 );
693 if (noPagePositions
< 1) noPagePositions
= 1;
695 // Correct position if greater than extent of canvas minus
696 // the visible portion of it or if below zero
697 m_yScrollPosition
= wxMin( m_yScrollLines
-noPagePositions
, m_yScrollPosition
);
698 m_yScrollPosition
= wxMax( 0, m_yScrollPosition
);
700 if (old_y
!= m_yScrollPosition
) {
701 m_targetWindow
->SetScrollPos( wxVERTICAL
, m_yScrollPosition
);
702 m_targetWindow
->ScrollWindow( 0, (old_y
-m_yScrollPosition
)*m_yScrollPixelsPerLine
,
708 m_targetWindow
->MacUpdateImmediately();
713 void wxScrollHelper::EnableScrolling (bool x_scroll
, bool y_scroll
)
715 m_xScrollingEnabled
= x_scroll
;
716 m_yScrollingEnabled
= y_scroll
;
719 void wxScrollHelper::GetVirtualSize (int *x
, int *y
) const
722 *x
= m_xScrollPixelsPerLine
* m_xScrollLines
;
724 *y
= m_yScrollPixelsPerLine
* m_yScrollLines
;
727 // Where the current view starts from
728 void wxScrollHelper::GetViewStart (int *x
, int *y
) const
731 *x
= m_xScrollPosition
;
733 *y
= m_yScrollPosition
;
736 void wxScrollHelper::CalcScrolledPosition(int x
, int y
, int *xx
, int *yy
) const
739 *xx
= x
- m_xScrollPosition
* m_xScrollPixelsPerLine
;
741 *yy
= y
- m_yScrollPosition
* m_yScrollPixelsPerLine
;
744 void wxScrollHelper::CalcUnscrolledPosition(int x
, int y
, int *xx
, int *yy
) const
747 *xx
= x
+ m_xScrollPosition
* m_xScrollPixelsPerLine
;
749 *yy
= y
+ m_yScrollPosition
* m_yScrollPixelsPerLine
;
752 // ----------------------------------------------------------------------------
754 // ----------------------------------------------------------------------------
756 // Default OnSize resets scrollbars, if any
757 void wxScrollHelper::HandleOnSize(wxSizeEvent
& WXUNUSED(event
))
759 #if wxUSE_CONSTRAINTS
760 if ( m_targetWindow
->GetAutoLayout() )
761 m_targetWindow
->Layout();
767 // This calls OnDraw, having adjusted the origin according to the current
769 void wxScrollHelper::HandleOnPaint(wxPaintEvent
& WXUNUSED(event
))
771 wxPaintDC
dc(m_targetWindow
);
777 // kbd handling: notice that we use OnChar() and not OnKeyDown() for
778 // compatibility here - if we used OnKeyDown(), the programs which process
779 // arrows themselves in their OnChar() would never get the message and like
780 // this they always have the priority
781 void wxScrollHelper::HandleOnChar(wxKeyEvent
& event
)
783 int stx
, sty
, // view origin
784 szx
, szy
, // view size (total)
785 clix
, cliy
; // view size (on screen)
787 GetViewStart(&stx
, &sty
);
788 GetTargetSize(&clix
, &cliy
);
789 GetVirtualSize(&szx
, &szy
);
791 if( m_xScrollPixelsPerLine
)
793 clix
/= m_xScrollPixelsPerLine
;
794 szx
/= m_xScrollPixelsPerLine
;
801 if( m_yScrollPixelsPerLine
)
803 cliy
/= m_yScrollPixelsPerLine
;
804 szy
/= m_yScrollPixelsPerLine
;
812 int xScrollOld
= m_xScrollPosition
,
813 yScrollOld
= m_yScrollPosition
;
816 switch ( event
.KeyCode() )
820 dsty
= sty
- (5 * cliy
/ 6);
821 Scroll(-1, (dsty
== -1) ? 0 : dsty
);
826 Scroll(-1, sty
+ (5 * cliy
/ 6));
830 Scroll(0, event
.ControlDown() ? 0 : -1);
834 Scroll(szx
- clix
, event
.ControlDown() ? szy
- cliy
: -1);
858 if ( m_xScrollPosition
!= xScrollOld
)
860 wxScrollWinEvent
event(wxEVT_SCROLLWIN_THUMBTRACK
, m_xScrollPosition
,
862 event
.SetEventObject(m_win
);
863 m_win
->GetEventHandler()->ProcessEvent(event
);
866 if ( m_yScrollPosition
!= yScrollOld
)
868 wxScrollWinEvent
event(wxEVT_SCROLLWIN_THUMBTRACK
, m_yScrollPosition
,
870 event
.SetEventObject(m_win
);
871 m_win
->GetEventHandler()->ProcessEvent(event
);
875 // ----------------------------------------------------------------------------
876 // autoscroll stuff: these functions deal with sending fake scroll events when
877 // a captured mouse is being held outside the window
878 // ----------------------------------------------------------------------------
880 bool wxScrollHelper::SendAutoScrollEvents(wxScrollWinEvent
& event
) const
882 // only send the event if the window is scrollable in this direction
883 wxWindow
*win
= (wxWindow
*)event
.GetEventObject();
884 return win
->HasScrollbar(event
.GetOrientation());
887 void wxScrollHelper::StopAutoScrolling()
889 if ( m_timerAutoScroll
)
891 delete m_timerAutoScroll
;
892 m_timerAutoScroll
= (wxTimer
*)NULL
;
896 void wxScrollHelper::HandleOnMouseEnter(wxMouseEvent
& event
)
903 void wxScrollHelper::HandleOnMouseLeave(wxMouseEvent
& event
)
905 // don't prevent the usual processing of the event from taking place
908 // when a captured mouse leave a scrolled window we start generate
909 // scrolling events to allow, for example, extending selection beyond the
910 // visible area in some controls
911 if ( wxWindow::GetCapture() == m_targetWindow
)
913 // where is the mouse leaving?
915 wxPoint pt
= event
.GetPosition();
918 orient
= wxHORIZONTAL
;
926 else // we're lower or to the right of the window
928 wxSize size
= m_targetWindow
->GetClientSize();
931 orient
= wxHORIZONTAL
;
932 pos
= m_xScrollLines
;
934 else if ( pt
.y
> size
.y
)
937 pos
= m_yScrollLines
;
939 else // this should be impossible
941 // but seems to happen sometimes under wxMSW - maybe it's a bug
942 // there but for now just ignore it
944 //wxFAIL_MSG( _T("can't understand where has mouse gone") );
950 // only start the auto scroll timer if the window can be scrolled in
952 if ( !m_targetWindow
->HasScrollbar(orient
) )
955 delete m_timerAutoScroll
;
956 m_timerAutoScroll
= new wxAutoScrollTimer
958 m_targetWindow
, this,
959 pos
== 0 ? wxEVT_SCROLLWIN_LINEUP
960 : wxEVT_SCROLLWIN_LINEDOWN
,
964 m_timerAutoScroll
->Start(50); // FIXME: make configurable
970 void wxScrollHelper::HandleOnMouseWheel(wxMouseEvent
& event
)
972 m_wheelRotation
+= event
.GetWheelRotation();
973 int lines
= m_wheelRotation
/ event
.GetWheelDelta();
974 m_wheelRotation
-= lines
* event
.GetWheelDelta();
978 lines
*= event
.GetLinesPerAction();
981 GetViewStart(&vsx
, &vsy
);
982 Scroll(-1, vsy
- lines
);
986 #endif // wxUSE_MOUSEWHEEL
988 // ----------------------------------------------------------------------------
989 // wxGenericScrolledWindow implementation
990 // ----------------------------------------------------------------------------
992 IMPLEMENT_DYNAMIC_CLASS(wxGenericScrolledWindow
, wxPanel
)
994 bool wxGenericScrolledWindow::Create(wxWindow
*parent
,
999 const wxString
& name
)
1001 m_targetWindow
= this;
1003 bool ok
= wxPanel::Create(parent
, id
, pos
, size
, style
, name
);
1006 // we need to process arrows ourselves for scrolling
1007 m_lDlgCode
|= DLGC_WANTARROWS
;
1013 wxGenericScrolledWindow::~wxGenericScrolledWindow()
1017 #if WXWIN_COMPATIBILITY
1018 void wxGenericScrolledWindow::GetScrollUnitsPerPage (int *x_page
, int *y_page
) const
1020 *x_page
= GetScrollPageSize(wxHORIZONTAL
);
1021 *y_page
= GetScrollPageSize(wxVERTICAL
);
1024 void wxGenericScrolledWindow::CalcUnscrolledPosition(int x
, int y
, float *xx
, float *yy
) const
1027 *xx
= (float)(x
+ m_xScrollPosition
* m_xScrollPixelsPerLine
);
1029 *yy
= (float)(y
+ m_yScrollPosition
* m_yScrollPixelsPerLine
);
1031 #endif // WXWIN_COMPATIBILITY