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
) // Don't let wxPanel catch the size events. RR.
174 m_scrollHelper
->HandleOnSize((wxSizeEvent
&)event
);
178 if ( wxEvtHandler::ProcessEvent(event
) )
181 // reset the skipped flag to FALSE as it might have been set to TRUE in
182 // ProcessEvent() above
185 if ( evType
== wxEVT_PAINT
)
187 m_scrollHelper
->HandleOnPaint((wxPaintEvent
&)event
);
191 if ( evType
== wxEVT_SCROLLWIN_TOP
||
192 evType
== wxEVT_SCROLLWIN_BOTTOM
||
193 evType
== wxEVT_SCROLLWIN_LINEUP
||
194 evType
== wxEVT_SCROLLWIN_LINEDOWN
||
195 evType
== wxEVT_SCROLLWIN_PAGEUP
||
196 evType
== wxEVT_SCROLLWIN_PAGEDOWN
||
197 evType
== wxEVT_SCROLLWIN_THUMBTRACK
||
198 evType
== wxEVT_SCROLLWIN_THUMBRELEASE
)
200 m_scrollHelper
->HandleOnScroll((wxScrollWinEvent
&)event
);
201 return !event
.GetSkipped();
204 if ( evType
== wxEVT_ENTER_WINDOW
)
206 m_scrollHelper
->HandleOnMouseEnter((wxMouseEvent
&)event
);
208 else if ( evType
== wxEVT_LEAVE_WINDOW
)
210 m_scrollHelper
->HandleOnMouseLeave((wxMouseEvent
&)event
);
213 else if ( evType
== wxEVT_MOUSEWHEEL
)
215 m_scrollHelper
->HandleOnMouseWheel((wxMouseEvent
&)event
);
217 #endif // wxUSE_MOUSEWHEEL
218 else if ( evType
== wxEVT_CHAR
)
220 m_scrollHelper
->HandleOnChar((wxKeyEvent
&)event
);
221 return !event
.GetSkipped();
227 // ----------------------------------------------------------------------------
228 // wxScrollHelper construction
229 // ----------------------------------------------------------------------------
231 wxScrollHelper::wxScrollHelper(wxWindow
*win
)
233 m_xScrollPixelsPerLine
=
234 m_yScrollPixelsPerLine
=
239 m_xScrollLinesPerPage
=
240 m_yScrollLinesPerPage
= 0;
242 m_xScrollingEnabled
=
243 m_yScrollingEnabled
= TRUE
;
252 m_targetWindow
= (wxWindow
*)NULL
;
254 m_timerAutoScroll
= (wxTimer
*)NULL
;
260 void wxScrollHelper::SetWindow(wxWindow
*win
)
262 wxCHECK_RET( win
, _T("wxScrollHelper needs a window to scroll") );
264 m_targetWindow
= m_win
= win
;
266 // install the event handler which will intercept the events we're
268 m_win
->PushEventHandler(new wxScrollHelperEvtHandler(this));
271 wxScrollHelper::~wxScrollHelper()
275 if ( m_targetWindow
)
276 m_targetWindow
->PopEventHandler(TRUE
/* do delete it */);
279 // ----------------------------------------------------------------------------
280 // setting scrolling parameters
281 // ----------------------------------------------------------------------------
283 void wxScrollHelper::SetScrollbars(int pixelsPerUnitX
,
293 CalcUnscrolledPosition(xPos
, yPos
, &xpos
, &ypos
);
296 (noUnitsX
!= 0 && m_xScrollLines
== 0) ||
297 (noUnitsX
< m_xScrollLines
&& xpos
> pixelsPerUnitX
*noUnitsX
) ||
299 (noUnitsY
!= 0 && m_yScrollLines
== 0) ||
300 (noUnitsY
< m_yScrollLines
&& ypos
> pixelsPerUnitY
*noUnitsY
) ||
301 (xPos
!= m_xScrollPosition
) ||
302 (yPos
!= m_yScrollPosition
)
305 m_xScrollPixelsPerLine
= pixelsPerUnitX
;
306 m_yScrollPixelsPerLine
= pixelsPerUnitY
;
307 m_xScrollPosition
= xPos
;
308 m_yScrollPosition
= yPos
;
309 m_xScrollLines
= noUnitsX
;
310 m_yScrollLines
= noUnitsY
;
313 // Sorry, some Motif-specific code to implement a backing pixmap
314 // for the wxRETAINED style. Implementing a backing store can't
315 // be entirely generic because it relies on the wxWindowDC implementation
316 // to duplicate X drawing calls for the backing pixmap.
318 if ( m_targetWindow
->GetWindowStyle() & wxRETAINED
)
320 Display
* dpy
= XtDisplay((Widget
)m_targetWindow
->GetMainWidget());
322 int totalPixelWidth
= m_xScrollLines
* m_xScrollPixelsPerLine
;
323 int totalPixelHeight
= m_yScrollLines
* m_yScrollPixelsPerLine
;
324 if (m_targetWindow
->GetBackingPixmap() &&
325 !((m_targetWindow
->GetPixmapWidth() == totalPixelWidth
) &&
326 (m_targetWindow
->GetPixmapHeight() == totalPixelHeight
)))
328 XFreePixmap (dpy
, (Pixmap
) m_targetWindow
->GetBackingPixmap());
329 m_targetWindow
->SetBackingPixmap((WXPixmap
) 0);
332 if (!m_targetWindow
->GetBackingPixmap() &&
333 (noUnitsX
!= 0) && (noUnitsY
!= 0))
335 int depth
= wxDisplayDepth();
336 m_targetWindow
->SetPixmapWidth(totalPixelWidth
);
337 m_targetWindow
->SetPixmapHeight(totalPixelHeight
);
338 m_targetWindow
->SetBackingPixmap((WXPixmap
) XCreatePixmap (dpy
, RootWindow (dpy
, DefaultScreen (dpy
)),
339 m_targetWindow
->GetPixmapWidth(), m_targetWindow
->GetPixmapHeight(), depth
));
347 if (do_refresh
&& !noRefresh
)
348 m_targetWindow
->Refresh(TRUE
, GetRect());
351 m_targetWindow
->MacUpdateImmediately() ;
355 // ----------------------------------------------------------------------------
356 // target window handling
357 // ----------------------------------------------------------------------------
359 void wxScrollHelper::SetTargetWindow( wxWindow
*target
)
361 wxASSERT_MSG( target
, wxT("target window must not be NULL") );
362 m_targetWindow
= target
;
365 wxWindow
*wxScrollHelper::GetTargetWindow() const
367 return m_targetWindow
;
370 // ----------------------------------------------------------------------------
371 // scrolling implementation itself
372 // ----------------------------------------------------------------------------
374 void wxScrollHelper::HandleOnScroll(wxScrollWinEvent
& event
)
376 int nScrollInc
= CalcScrollInc(event
);
377 if ( nScrollInc
== 0 )
379 // can't scroll further
385 int orient
= event
.GetOrientation();
386 if (orient
== wxHORIZONTAL
)
388 m_xScrollPosition
+= nScrollInc
;
389 m_targetWindow
->SetScrollPos(wxHORIZONTAL
, m_xScrollPosition
);
393 m_yScrollPosition
+= nScrollInc
;
394 m_targetWindow
->SetScrollPos(wxVERTICAL
, m_yScrollPosition
);
397 bool needsRefresh
= FALSE
;
400 if (orient
== wxHORIZONTAL
)
402 if ( m_xScrollingEnabled
)
404 dx
= -m_xScrollPixelsPerLine
* nScrollInc
;
413 if ( m_yScrollingEnabled
)
415 dy
= -m_yScrollPixelsPerLine
* nScrollInc
;
425 m_targetWindow
->Refresh(TRUE
, GetRect());
429 m_targetWindow
->ScrollWindow(dx
, dy
, GetRect());
433 m_targetWindow
->MacUpdateImmediately() ;
437 int wxScrollHelper::CalcScrollInc(wxScrollWinEvent
& event
)
439 int pos
= event
.GetPosition();
440 int orient
= event
.GetOrientation();
443 if (event
.GetEventType() == wxEVT_SCROLLWIN_TOP
)
445 if (orient
== wxHORIZONTAL
)
446 nScrollInc
= - m_xScrollPosition
;
448 nScrollInc
= - m_yScrollPosition
;
450 if (event
.GetEventType() == wxEVT_SCROLLWIN_BOTTOM
)
452 if (orient
== wxHORIZONTAL
)
453 nScrollInc
= m_xScrollLines
- m_xScrollPosition
;
455 nScrollInc
= m_yScrollLines
- m_yScrollPosition
;
457 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEUP
)
461 if (event
.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN
)
465 if (event
.GetEventType() == wxEVT_SCROLLWIN_PAGEUP
)
467 if (orient
== wxHORIZONTAL
)
468 nScrollInc
= -GetScrollPageSize(wxHORIZONTAL
);
470 nScrollInc
= -GetScrollPageSize(wxVERTICAL
);
472 if (event
.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN
)
474 if (orient
== wxHORIZONTAL
)
475 nScrollInc
= GetScrollPageSize(wxHORIZONTAL
);
477 nScrollInc
= GetScrollPageSize(wxVERTICAL
);
479 if ((event
.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK
) ||
480 (event
.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE
))
482 if (orient
== wxHORIZONTAL
)
483 nScrollInc
= pos
- m_xScrollPosition
;
485 nScrollInc
= pos
- m_yScrollPosition
;
488 if (orient
== wxHORIZONTAL
)
490 if (m_xScrollPixelsPerLine
> 0)
493 GetTargetSize(&w
, &h
);
495 int nMaxWidth
= m_xScrollLines
*m_xScrollPixelsPerLine
;
496 int noPositions
= (int) ( ((nMaxWidth
- w
)/(double)m_xScrollPixelsPerLine
) + 0.5 );
500 if ( (m_xScrollPosition
+ nScrollInc
) < 0 )
501 nScrollInc
= -m_xScrollPosition
; // As -ve as we can go
502 else if ( (m_xScrollPosition
+ nScrollInc
) > noPositions
)
503 nScrollInc
= noPositions
- m_xScrollPosition
; // As +ve as we can go
506 m_targetWindow
->Refresh(TRUE
, GetRect());
510 if (m_yScrollPixelsPerLine
> 0)
513 GetTargetSize(&w
, &h
);
515 int nMaxHeight
= m_yScrollLines
*m_yScrollPixelsPerLine
;
516 int noPositions
= (int) ( ((nMaxHeight
- h
)/(double)m_yScrollPixelsPerLine
) + 0.5 );
520 if ( (m_yScrollPosition
+ nScrollInc
) < 0 )
521 nScrollInc
= -m_yScrollPosition
; // As -ve as we can go
522 else if ( (m_yScrollPosition
+ nScrollInc
) > noPositions
)
523 nScrollInc
= noPositions
- m_yScrollPosition
; // As +ve as we can go
526 m_targetWindow
->Refresh(TRUE
, GetRect());
532 // Adjust the scrollbars - new version.
533 void wxScrollHelper::AdjustScrollbars()
536 m_targetWindow
->MacUpdateImmediately();
540 GetTargetSize(&w
, &h
);
542 int oldXScroll
= m_xScrollPosition
;
543 int oldYScroll
= m_yScrollPosition
;
545 if (m_xScrollLines
> 0)
547 // Calculate page size i.e. number of scroll units you get on the
548 // current client window
549 int noPagePositions
= (int) ( (w
/(double)m_xScrollPixelsPerLine
) + 0.5 );
550 if (noPagePositions
< 1) noPagePositions
= 1;
551 if ( noPagePositions
> m_xScrollLines
)
552 noPagePositions
= m_xScrollLines
;
554 // Correct position if greater than extent of canvas minus
555 // the visible portion of it or if below zero
556 m_xScrollPosition
= wxMin( m_xScrollLines
-noPagePositions
, m_xScrollPosition
);
557 m_xScrollPosition
= wxMax( 0, m_xScrollPosition
);
559 m_targetWindow
->SetScrollbar(wxHORIZONTAL
, m_xScrollPosition
, noPagePositions
, m_xScrollLines
);
560 // The amount by which we scroll when paging
561 SetScrollPageSize(wxHORIZONTAL
, noPagePositions
);
565 m_xScrollPosition
= 0;
566 m_targetWindow
->SetScrollbar (wxHORIZONTAL
, 0, 0, 0, FALSE
);
569 if (m_yScrollLines
> 0)
571 // Calculate page size i.e. number of scroll units you get on the
572 // current client window
573 int noPagePositions
= (int) ( (h
/(double)m_yScrollPixelsPerLine
) + 0.5 );
574 if (noPagePositions
< 1) noPagePositions
= 1;
575 if ( noPagePositions
> m_yScrollLines
)
576 noPagePositions
= m_yScrollLines
;
578 // Correct position if greater than extent of canvas minus
579 // the visible portion of it or if below zero
580 m_yScrollPosition
= wxMin( m_yScrollLines
-noPagePositions
, m_yScrollPosition
);
581 m_yScrollPosition
= wxMax( 0, m_yScrollPosition
);
583 m_targetWindow
->SetScrollbar(wxVERTICAL
, m_yScrollPosition
, noPagePositions
, m_yScrollLines
);
584 // The amount by which we scroll when paging
585 SetScrollPageSize(wxVERTICAL
, noPagePositions
);
589 m_yScrollPosition
= 0;
590 m_targetWindow
->SetScrollbar (wxVERTICAL
, 0, 0, 0, FALSE
);
593 if (oldXScroll
!= m_xScrollPosition
)
595 if (m_xScrollingEnabled
)
596 m_targetWindow
->ScrollWindow( m_xScrollPixelsPerLine
* (oldXScroll
-m_xScrollPosition
), 0,
599 m_targetWindow
->Refresh(TRUE
, GetRect());
602 if (oldYScroll
!= m_yScrollPosition
)
604 if (m_yScrollingEnabled
)
605 m_targetWindow
->ScrollWindow( 0, m_yScrollPixelsPerLine
* (oldYScroll
-m_yScrollPosition
),
608 m_targetWindow
->Refresh(TRUE
, GetRect());
612 m_targetWindow
->MacUpdateImmediately();
616 void wxScrollHelper::DoPrepareDC(wxDC
& dc
)
618 wxPoint pt
= dc
.GetDeviceOrigin();
619 dc
.SetDeviceOrigin( pt
.x
- m_xScrollPosition
* m_xScrollPixelsPerLine
,
620 pt
.y
- m_yScrollPosition
* m_yScrollPixelsPerLine
);
621 dc
.SetUserScale( m_scaleX
, m_scaleY
);
624 void wxScrollHelper::GetScrollPixelsPerUnit (int *x_unit
, int *y_unit
) const
627 *x_unit
= m_xScrollPixelsPerLine
;
629 *y_unit
= m_yScrollPixelsPerLine
;
632 int wxScrollHelper::GetScrollPageSize(int orient
) const
634 if ( orient
== wxHORIZONTAL
)
635 return m_xScrollLinesPerPage
;
637 return m_yScrollLinesPerPage
;
640 void wxScrollHelper::SetScrollPageSize(int orient
, int pageSize
)
642 if ( orient
== wxHORIZONTAL
)
643 m_xScrollLinesPerPage
= pageSize
;
645 m_yScrollLinesPerPage
= pageSize
;
649 * Scroll to given position (scroll position, not pixel position)
651 void wxScrollHelper::Scroll( int x_pos
, int y_pos
)
656 if (((x_pos
== -1) || (x_pos
== m_xScrollPosition
)) &&
657 ((y_pos
== -1) || (y_pos
== m_yScrollPosition
))) return;
660 m_targetWindow
->MacUpdateImmediately();
664 GetTargetSize(&w
, &h
);
666 if ((x_pos
!= -1) && (m_xScrollPixelsPerLine
))
668 int old_x
= m_xScrollPosition
;
669 m_xScrollPosition
= x_pos
;
671 // Calculate page size i.e. number of scroll units you get on the
672 // current client window
673 int noPagePositions
= (int) ( (w
/(double)m_xScrollPixelsPerLine
) + 0.5 );
674 if (noPagePositions
< 1) noPagePositions
= 1;
676 // Correct position if greater than extent of canvas minus
677 // the visible portion of it or if below zero
678 m_xScrollPosition
= wxMin( m_xScrollLines
-noPagePositions
, m_xScrollPosition
);
679 m_xScrollPosition
= wxMax( 0, m_xScrollPosition
);
681 if (old_x
!= m_xScrollPosition
) {
682 m_targetWindow
->SetScrollPos( wxHORIZONTAL
, m_xScrollPosition
);
683 m_targetWindow
->ScrollWindow( (old_x
-m_xScrollPosition
)*m_xScrollPixelsPerLine
, 0,
687 if ((y_pos
!= -1) && (m_yScrollPixelsPerLine
))
689 int old_y
= m_yScrollPosition
;
690 m_yScrollPosition
= y_pos
;
692 // Calculate page size i.e. number of scroll units you get on the
693 // current client window
694 int noPagePositions
= (int) ( (h
/(double)m_yScrollPixelsPerLine
) + 0.5 );
695 if (noPagePositions
< 1) noPagePositions
= 1;
697 // Correct position if greater than extent of canvas minus
698 // the visible portion of it or if below zero
699 m_yScrollPosition
= wxMin( m_yScrollLines
-noPagePositions
, m_yScrollPosition
);
700 m_yScrollPosition
= wxMax( 0, m_yScrollPosition
);
702 if (old_y
!= m_yScrollPosition
) {
703 m_targetWindow
->SetScrollPos( wxVERTICAL
, m_yScrollPosition
);
704 m_targetWindow
->ScrollWindow( 0, (old_y
-m_yScrollPosition
)*m_yScrollPixelsPerLine
,
710 m_targetWindow
->MacUpdateImmediately();
715 void wxScrollHelper::EnableScrolling (bool x_scroll
, bool y_scroll
)
717 m_xScrollingEnabled
= x_scroll
;
718 m_yScrollingEnabled
= y_scroll
;
721 void wxScrollHelper::GetVirtualSize (int *x
, int *y
) const
724 *x
= m_xScrollPixelsPerLine
* m_xScrollLines
;
726 *y
= m_yScrollPixelsPerLine
* m_yScrollLines
;
729 // Where the current view starts from
730 void wxScrollHelper::GetViewStart (int *x
, int *y
) const
733 *x
= m_xScrollPosition
;
735 *y
= m_yScrollPosition
;
738 void wxScrollHelper::CalcScrolledPosition(int x
, int y
, int *xx
, int *yy
) const
741 *xx
= x
- m_xScrollPosition
* m_xScrollPixelsPerLine
;
743 *yy
= y
- m_yScrollPosition
* m_yScrollPixelsPerLine
;
746 void wxScrollHelper::CalcUnscrolledPosition(int x
, int y
, int *xx
, int *yy
) const
749 *xx
= x
+ m_xScrollPosition
* m_xScrollPixelsPerLine
;
751 *yy
= y
+ m_yScrollPosition
* m_yScrollPixelsPerLine
;
754 // ----------------------------------------------------------------------------
756 // ----------------------------------------------------------------------------
758 // Default OnSize resets scrollbars, if any
759 void wxScrollHelper::HandleOnSize(wxSizeEvent
& WXUNUSED(event
))
761 #if wxUSE_CONSTRAINTS
762 if ( m_targetWindow
->GetAutoLayout() )
763 m_targetWindow
->Layout();
769 // This calls OnDraw, having adjusted the origin according to the current
771 void wxScrollHelper::HandleOnPaint(wxPaintEvent
& WXUNUSED(event
))
773 wxPaintDC
dc(m_targetWindow
);
779 // kbd handling: notice that we use OnChar() and not OnKeyDown() for
780 // compatibility here - if we used OnKeyDown(), the programs which process
781 // arrows themselves in their OnChar() would never get the message and like
782 // this they always have the priority
783 void wxScrollHelper::HandleOnChar(wxKeyEvent
& event
)
785 int stx
, sty
, // view origin
786 szx
, szy
, // view size (total)
787 clix
, cliy
; // view size (on screen)
789 GetViewStart(&stx
, &sty
);
790 GetTargetSize(&clix
, &cliy
);
791 GetVirtualSize(&szx
, &szy
);
793 if( m_xScrollPixelsPerLine
)
795 clix
/= m_xScrollPixelsPerLine
;
796 szx
/= m_xScrollPixelsPerLine
;
803 if( m_yScrollPixelsPerLine
)
805 cliy
/= m_yScrollPixelsPerLine
;
806 szy
/= m_yScrollPixelsPerLine
;
814 int xScrollOld
= m_xScrollPosition
,
815 yScrollOld
= m_yScrollPosition
;
818 switch ( event
.KeyCode() )
822 dsty
= sty
- (5 * cliy
/ 6);
823 Scroll(-1, (dsty
== -1) ? 0 : dsty
);
828 Scroll(-1, sty
+ (5 * cliy
/ 6));
832 Scroll(0, event
.ControlDown() ? 0 : -1);
836 Scroll(szx
- clix
, event
.ControlDown() ? szy
- cliy
: -1);
860 if ( m_xScrollPosition
!= xScrollOld
)
862 wxScrollWinEvent
event(wxEVT_SCROLLWIN_THUMBTRACK
, m_xScrollPosition
,
864 event
.SetEventObject(m_win
);
865 m_win
->GetEventHandler()->ProcessEvent(event
);
868 if ( m_yScrollPosition
!= yScrollOld
)
870 wxScrollWinEvent
event(wxEVT_SCROLLWIN_THUMBTRACK
, m_yScrollPosition
,
872 event
.SetEventObject(m_win
);
873 m_win
->GetEventHandler()->ProcessEvent(event
);
877 // ----------------------------------------------------------------------------
878 // autoscroll stuff: these functions deal with sending fake scroll events when
879 // a captured mouse is being held outside the window
880 // ----------------------------------------------------------------------------
882 bool wxScrollHelper::SendAutoScrollEvents(wxScrollWinEvent
& event
) const
884 // only send the event if the window is scrollable in this direction
885 wxWindow
*win
= (wxWindow
*)event
.GetEventObject();
886 return win
->HasScrollbar(event
.GetOrientation());
889 void wxScrollHelper::StopAutoScrolling()
891 if ( m_timerAutoScroll
)
893 delete m_timerAutoScroll
;
894 m_timerAutoScroll
= (wxTimer
*)NULL
;
898 void wxScrollHelper::HandleOnMouseEnter(wxMouseEvent
& event
)
905 void wxScrollHelper::HandleOnMouseLeave(wxMouseEvent
& event
)
907 // don't prevent the usual processing of the event from taking place
910 // when a captured mouse leave a scrolled window we start generate
911 // scrolling events to allow, for example, extending selection beyond the
912 // visible area in some controls
913 if ( wxWindow::GetCapture() == m_targetWindow
)
915 // where is the mouse leaving?
917 wxPoint pt
= event
.GetPosition();
920 orient
= wxHORIZONTAL
;
928 else // we're lower or to the right of the window
930 wxSize size
= m_targetWindow
->GetClientSize();
933 orient
= wxHORIZONTAL
;
934 pos
= m_xScrollLines
;
936 else if ( pt
.y
> size
.y
)
939 pos
= m_yScrollLines
;
941 else // this should be impossible
943 // but seems to happen sometimes under wxMSW - maybe it's a bug
944 // there but for now just ignore it
946 //wxFAIL_MSG( _T("can't understand where has mouse gone") );
952 // only start the auto scroll timer if the window can be scrolled in
954 if ( !m_targetWindow
->HasScrollbar(orient
) )
957 delete m_timerAutoScroll
;
958 m_timerAutoScroll
= new wxAutoScrollTimer
960 m_targetWindow
, this,
961 pos
== 0 ? wxEVT_SCROLLWIN_LINEUP
962 : wxEVT_SCROLLWIN_LINEDOWN
,
966 m_timerAutoScroll
->Start(50); // FIXME: make configurable
972 void wxScrollHelper::HandleOnMouseWheel(wxMouseEvent
& event
)
974 m_wheelRotation
+= event
.GetWheelRotation();
975 int lines
= m_wheelRotation
/ event
.GetWheelDelta();
976 m_wheelRotation
-= lines
* event
.GetWheelDelta();
980 lines
*= event
.GetLinesPerAction();
983 GetViewStart(&vsx
, &vsy
);
984 Scroll(-1, vsy
- lines
);
988 #endif // wxUSE_MOUSEWHEEL
990 // ----------------------------------------------------------------------------
991 // wxGenericScrolledWindow implementation
992 // ----------------------------------------------------------------------------
994 IMPLEMENT_DYNAMIC_CLASS(wxGenericScrolledWindow
, wxPanel
)
996 bool wxGenericScrolledWindow::Create(wxWindow
*parent
,
1001 const wxString
& name
)
1003 m_targetWindow
= this;
1005 bool ok
= wxPanel::Create(parent
, id
, pos
, size
, style
, name
);
1008 // we need to process arrows ourselves for scrolling
1009 m_lDlgCode
|= DLGC_WANTARROWS
;
1015 wxGenericScrolledWindow::~wxGenericScrolledWindow()
1019 #if WXWIN_COMPATIBILITY
1020 void wxGenericScrolledWindow::GetScrollUnitsPerPage (int *x_page
, int *y_page
) const
1022 *x_page
= GetScrollPageSize(wxHORIZONTAL
);
1023 *y_page
= GetScrollPageSize(wxVERTICAL
);
1026 void wxGenericScrolledWindow::CalcUnscrolledPosition(int x
, int y
, float *xx
, float *yy
) const
1029 *xx
= (float)(x
+ m_xScrollPosition
* m_xScrollPixelsPerLine
);
1031 *yy
= (float)(y
+ m_yScrollPosition
* m_yScrollPixelsPerLine
);
1033 #endif // WXWIN_COMPATIBILITY