1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/vscroll.cpp
3 // Purpose: wxVScrolledWindow implementation
4 // Author: Vadim Zeitlin
5 // Modified by: Brad Anderson, David Warkentin
7 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
31 #include "wx/vscroll.h"
33 #include "wx/utils.h" // For wxMin/wxMax().
35 // ============================================================================
36 // wxVarScrollHelperEvtHandler declaration
37 // ============================================================================
39 // ----------------------------------------------------------------------------
40 // wxScrollHelperEvtHandler: intercept the events from the window and forward
41 // them to wxVarScrollHelperBase
42 // ----------------------------------------------------------------------------
44 class WXDLLEXPORT wxVarScrollHelperEvtHandler
: public wxEvtHandler
47 wxVarScrollHelperEvtHandler(wxVarScrollHelperBase
*scrollHelper
)
49 m_scrollHelper
= scrollHelper
;
52 virtual bool ProcessEvent(wxEvent
& event
);
55 wxVarScrollHelperBase
*m_scrollHelper
;
57 wxDECLARE_NO_COPY_CLASS(wxVarScrollHelperEvtHandler
);
60 // ============================================================================
61 // wxVarScrollHelperEvtHandler implementation
62 // ============================================================================
64 // FIXME: This method totally duplicates a method with the same name in
65 // wxScrollHelperEvtHandler, we really should merge them by reusing the
66 // common parts in wxAnyScrollHelperBase.
67 bool wxVarScrollHelperEvtHandler::ProcessEvent(wxEvent
& event
)
69 wxEventType evType
= event
.GetEventType();
71 // Pass it on to the real handler: notice that we must not call
72 // ProcessEvent() on this object itself as it wouldn't pass it to the next
73 // handler (i.e. the real window) if we're called from a previous handler
74 // (as indicated by "process here only" flag being set) and we do want to
75 // execute the handler defined in the window we're associated with right
76 // now, without waiting until TryAfter() is called from wxEvtHandler.
77 bool processed
= m_nextHandler
->ProcessEvent(event
);
79 // always process the size events ourselves, even if the user code handles
80 // them as well, as we need to AdjustScrollbars()
82 // NB: it is important to do it after processing the event in the normal
83 // way as HandleOnSize() may generate a wxEVT_SIZE itself if the
84 // scrollbar[s] (dis)appear and it should be seen by the user code
86 if ( evType
== wxEVT_SIZE
)
88 m_scrollHelper
->HandleOnSize((wxSizeEvent
&)event
);
92 if ( processed
&& event
.IsCommandEvent())
95 // For wxEVT_PAINT the user code can either handle this event as usual or
96 // override virtual OnDraw(), so if the event hasn't been handled we need
97 // to call this virtual function ourselves.
99 #ifndef __WXUNIVERSAL__
100 // in wxUniversal "processed" will always be true, because
101 // all windows use the paint event to draw themselves.
102 // In this case we can't use this flag to determine if a custom
103 // paint event handler already drew our window and we just
104 // call OnDraw() anyway.
106 #endif // !__WXUNIVERSAL__
107 evType
== wxEVT_PAINT
)
109 m_scrollHelper
->HandleOnPaint((wxPaintEvent
&)event
);
113 // reset the skipped flag (which might have been set to true in
114 // ProcessEvent() above) to be able to test it below
115 bool wasSkipped
= event
.GetSkipped();
119 if ( evType
== wxEVT_SCROLLWIN_TOP
||
120 evType
== wxEVT_SCROLLWIN_BOTTOM
||
121 evType
== wxEVT_SCROLLWIN_LINEUP
||
122 evType
== wxEVT_SCROLLWIN_LINEDOWN
||
123 evType
== wxEVT_SCROLLWIN_PAGEUP
||
124 evType
== wxEVT_SCROLLWIN_PAGEDOWN
||
125 evType
== wxEVT_SCROLLWIN_THUMBTRACK
||
126 evType
== wxEVT_SCROLLWIN_THUMBRELEASE
)
128 m_scrollHelper
->HandleOnScroll((wxScrollWinEvent
&)event
);
129 if ( !event
.GetSkipped() )
131 // it makes sense to indicate that we processed the message as we
132 // did scroll the window (and also notice that wxAutoScrollTimer
133 // relies on our return value to stop scrolling when we are at top
134 // or bottom already)
140 else if ( evType
== wxEVT_MOUSEWHEEL
)
142 m_scrollHelper
->HandleOnMouseWheel((wxMouseEvent
&)event
);
144 #endif // wxUSE_MOUSEWHEEL
145 else if ( evType
== wxEVT_CHAR
&&
146 (m_scrollHelper
->GetOrientation() == wxVERTICAL
) )
148 m_scrollHelper
->HandleOnChar((wxKeyEvent
&)event
);
149 if ( !event
.GetSkipped() )
156 event
.Skip(wasSkipped
);
158 // We called ProcessEvent() on the next handler, meaning that we explicitly
159 // worked around the request to process the event in this handler only. As
160 // explained above, this is unfortunately really necessary but the trouble
161 // is that the event will continue to be post-processed by the previous
162 // handler resulting in duplicate calls to event handlers. Call the special
163 // function below to prevent this from happening, base class DoTryChain()
164 // will check for it and behave accordingly.
166 // And if we're not called from DoTryChain(), this won't do anything anyhow.
167 event
.DidntHonourProcessOnlyIn();
173 // ============================================================================
174 // wxVarScrollHelperBase implementation
175 // ============================================================================
177 // ----------------------------------------------------------------------------
178 // wxVarScrollHelperBase initialization
179 // ----------------------------------------------------------------------------
181 wxVarScrollHelperBase::wxVarScrollHelperBase(wxWindow
*win
)
182 : wxAnyScrollHelperBase(win
)
185 m_sumWheelRotation
= 0;
192 m_physicalScrolling
= true;
195 // by default, the associated window is also the target window
196 DoSetTargetWindow(win
);
199 wxVarScrollHelperBase::~wxVarScrollHelperBase()
204 // ----------------------------------------------------------------------------
205 // wxVarScrollHelperBase various helpers
206 // ----------------------------------------------------------------------------
209 wxVarScrollHelperBase::AssignOrient(wxCoord
& x
,
214 if ( GetOrientation() == wxVERTICAL
)
227 wxVarScrollHelperBase::IncOrient(wxCoord
& x
, wxCoord
& y
, wxCoord inc
)
229 if ( GetOrientation() == wxVERTICAL
)
235 wxCoord
wxVarScrollHelperBase::DoEstimateTotalSize() const
237 // estimate the total height: it is impossible to call
238 // OnGetUnitSize() for every unit because there may be too many of
239 // them, so we just make a guess using some units in the beginning,
240 // some in the end and some in the middle
241 static const size_t NUM_UNITS_TO_SAMPLE
= 10;
244 if ( m_unitMax
< 3*NUM_UNITS_TO_SAMPLE
)
246 // in this case, full calculations are faster and more correct than
248 sizeTotal
= GetUnitsSize(0, m_unitMax
);
250 else // too many units to calculate exactly
252 // look at some units in the beginning/middle/end
254 GetUnitsSize(0, NUM_UNITS_TO_SAMPLE
) +
255 GetUnitsSize(m_unitMax
- NUM_UNITS_TO_SAMPLE
,
257 GetUnitsSize(m_unitMax
/2 - NUM_UNITS_TO_SAMPLE
/2,
258 m_unitMax
/2 + NUM_UNITS_TO_SAMPLE
/2);
260 // use the height of the units we looked as the average
261 sizeTotal
= (wxCoord
)
262 (((float)sizeTotal
/ (3*NUM_UNITS_TO_SAMPLE
)) * m_unitMax
);
268 wxCoord
wxVarScrollHelperBase::GetUnitsSize(size_t unitMin
, size_t unitMax
) const
270 if ( unitMin
== unitMax
)
272 else if ( unitMin
> unitMax
)
273 return -GetUnitsSize(unitMax
, unitMin
);
274 //else: unitMin < unitMax
276 // let the user code know that we're going to need all these units
277 OnGetUnitsSizeHint(unitMin
, unitMax
);
279 // sum up their sizes
281 for ( size_t unit
= unitMin
; unit
< unitMax
; ++unit
)
283 size
+= OnGetUnitSize(unit
);
289 size_t wxVarScrollHelperBase::FindFirstVisibleFromLast(size_t unitLast
, bool full
) const
291 const wxCoord sWindow
= GetOrientationTargetSize();
293 // go upwards until we arrive at a unit such that unitLast is not visible
294 // any more when it is shown
295 size_t unitFirst
= unitLast
;
299 s
+= OnGetUnitSize(unitFirst
);
303 // for this unit to be fully visible we need to go one unit
304 // down, but if it is enough for it to be only partly visible then
305 // this unit will do as well
323 size_t wxVarScrollHelperBase::GetNewScrollPosition(wxScrollWinEvent
& event
) const
325 wxEventType evtType
= event
.GetEventType();
327 if ( evtType
== wxEVT_SCROLLWIN_TOP
)
331 else if ( evtType
== wxEVT_SCROLLWIN_BOTTOM
)
335 else if ( evtType
== wxEVT_SCROLLWIN_LINEUP
)
337 return m_unitFirst
? m_unitFirst
- 1 : 0;
339 else if ( evtType
== wxEVT_SCROLLWIN_LINEDOWN
)
341 return m_unitFirst
+ 1;
343 else if ( evtType
== wxEVT_SCROLLWIN_PAGEUP
)
345 // Page up should do at least as much as line up.
346 return wxMin(FindFirstVisibleFromLast(m_unitFirst
),
347 m_unitFirst
? m_unitFirst
- 1 : 0);
349 else if ( evtType
== wxEVT_SCROLLWIN_PAGEDOWN
)
351 // And page down should do at least as much as line down.
352 if ( GetVisibleEnd() )
353 return wxMax(GetVisibleEnd() - 1, m_unitFirst
+ 1);
355 return wxMax(GetVisibleEnd(), m_unitFirst
+ 1);
357 else if ( evtType
== wxEVT_SCROLLWIN_THUMBRELEASE
)
359 return event
.GetPosition();
361 else if ( evtType
== wxEVT_SCROLLWIN_THUMBTRACK
)
363 return event
.GetPosition();
366 // unknown scroll event?
367 wxFAIL_MSG( wxT("unknown scroll event type?") );
371 void wxVarScrollHelperBase::UpdateScrollbar()
373 // if there is nothing to scroll, remove the scrollbar
380 // see how many units can we fit on screen
381 const wxCoord sWindow
= GetOrientationTargetSize();
383 // do vertical calculations
386 for ( unit
= m_unitFirst
; unit
< m_unitMax
; ++unit
)
391 s
+= OnGetUnitSize(unit
);
394 m_nUnitsVisible
= unit
- m_unitFirst
;
396 int unitsPageSize
= m_nUnitsVisible
;
399 // last unit is only partially visible, we still need the scrollbar and
400 // so we have to "fix" pageSize because if it is equal to m_unitMax
401 // the scrollbar is not shown at all under MSW
405 // set the scrollbar parameters to reflect this
406 m_win
->SetScrollbar(GetOrientation(), m_unitFirst
, unitsPageSize
, m_unitMax
);
409 void wxVarScrollHelperBase::RemoveScrollbar()
412 m_nUnitsVisible
= m_unitMax
;
413 m_win
->SetScrollbar(GetOrientation(), 0, 0, 0);
416 void wxVarScrollHelperBase::DeleteEvtHandler()
418 // search for m_handler in the handler list
419 if ( m_win
&& m_handler
)
421 if ( m_win
->RemoveEventHandler(m_handler
) )
425 //else: something is very wrong, so better [maybe] leak memory than
426 // risk a crash because of double deletion
432 void wxVarScrollHelperBase::DoSetTargetWindow(wxWindow
*target
)
434 m_targetWindow
= target
;
436 target
->MacSetClipChildren( true ) ;
439 // install the event handler which will intercept the events we're
440 // interested in (but only do it for our real window, not the target window
441 // which we scroll - we don't need to hijack its events)
442 if ( m_targetWindow
== m_win
)
444 // if we already have a handler, delete it first
447 m_handler
= new wxVarScrollHelperEvtHandler(this);
448 m_targetWindow
->PushEventHandler(m_handler
);
452 // ----------------------------------------------------------------------------
453 // wxVarScrollHelperBase operations
454 // ----------------------------------------------------------------------------
456 void wxVarScrollHelperBase::SetTargetWindow(wxWindow
*target
)
458 wxCHECK_RET( target
, wxT("target window must not be NULL") );
460 if ( target
== m_targetWindow
)
463 DoSetTargetWindow(target
);
466 void wxVarScrollHelperBase::SetUnitCount(size_t count
)
468 // save the number of units
471 // and our estimate for their total height
472 m_sizeTotal
= EstimateTotalSize();
474 // ScrollToUnit() will update the scrollbar itself if it changes the unit
475 // we pass to it because it's out of [new] range
476 size_t oldScrollPos
= m_unitFirst
;
477 DoScrollToUnit(m_unitFirst
);
478 if ( oldScrollPos
== m_unitFirst
)
480 // but if it didn't do it, we still need to update the scrollbar to
481 // reflect the changed number of units ourselves
486 void wxVarScrollHelperBase::RefreshUnit(size_t unit
)
488 // is this unit visible?
489 if ( !IsVisible(unit
) )
491 // no, it is useless to do anything
495 // calculate the rect occupied by this unit on screen
497 AssignOrient(rect
.width
, rect
.height
,
498 GetNonOrientationTargetSize(), OnGetUnitSize(unit
));
500 for ( size_t n
= GetVisibleBegin(); n
< unit
; ++n
)
502 IncOrient(rect
.x
, rect
.y
, OnGetUnitSize(n
));
506 m_targetWindow
->RefreshRect(rect
);
509 void wxVarScrollHelperBase::RefreshUnits(size_t from
, size_t to
)
511 wxASSERT_MSG( from
<= to
, wxT("RefreshUnits(): empty range") );
513 // clump the range to just the visible units -- it is useless to refresh
515 if ( from
< GetVisibleBegin() )
516 from
= GetVisibleBegin();
518 if ( to
> GetVisibleEnd() )
519 to
= GetVisibleEnd();
521 // calculate the rect occupied by these units on screen
525 int nonorient_size
= GetNonOrientationTargetSize();
527 for ( size_t nBefore
= GetVisibleBegin();
531 orient_pos
+= OnGetUnitSize(nBefore
);
534 for ( size_t nBetween
= from
; nBetween
<= to
; nBetween
++ )
536 orient_size
+= OnGetUnitSize(nBetween
);
540 AssignOrient(rect
.x
, rect
.y
, 0, orient_pos
);
541 AssignOrient(rect
.width
, rect
.height
, nonorient_size
, orient_size
);
544 m_targetWindow
->RefreshRect(rect
);
547 void wxVarScrollHelperBase::RefreshAll()
551 m_targetWindow
->Refresh();
554 bool wxVarScrollHelperBase::ScrollLayout()
556 if ( m_targetWindow
->GetSizer() && m_physicalScrolling
)
558 // adjust the sizer dimensions/position taking into account the
559 // virtual size and scrolled position of the window.
562 AssignOrient(x
, y
, 0, -GetScrollOffset());
565 m_targetWindow
->GetVirtualSize(&w
, &h
);
567 m_targetWindow
->GetSizer()->SetDimension(x
, y
, w
, h
);
571 // fall back to default for LayoutConstraints
572 return m_targetWindow
->wxWindow::Layout();
575 int wxVarScrollHelperBase::VirtualHitTest(wxCoord coord
) const
577 const size_t unitMax
= GetVisibleEnd();
578 for ( size_t unit
= GetVisibleBegin(); unit
< unitMax
; ++unit
)
580 coord
-= OnGetUnitSize(unit
);
588 // ----------------------------------------------------------------------------
589 // wxVarScrollHelperBase scrolling
590 // ----------------------------------------------------------------------------
592 bool wxVarScrollHelperBase::DoScrollToUnit(size_t unit
)
596 // we're empty, code below doesn't make sense in this case
600 // determine the real first unit to scroll to: we shouldn't scroll beyond
602 size_t unitFirstLast
= FindFirstVisibleFromLast(m_unitMax
- 1, true);
603 if ( unit
> unitFirstLast
)
604 unit
= unitFirstLast
;
607 if ( unit
== m_unitFirst
)
614 // remember the currently shown units for the refresh code below
615 size_t unitFirstOld
= GetVisibleBegin(),
616 unitLastOld
= GetVisibleEnd();
621 // the size of scrollbar thumb could have changed
624 // finally refresh the display -- but only redraw as few units as possible
625 // to avoid flicker. We can't do this if we have children because they
627 if ( m_targetWindow
->GetChildren().empty() &&
628 (GetVisibleBegin() >= unitLastOld
|| GetVisibleEnd() <= unitFirstOld
) )
630 // the simplest case: we don't have any old units left, just redraw
632 m_targetWindow
->Refresh();
634 else // scroll the window
636 // Avoid scrolling visible parts of the screen on Mac
638 if (m_physicalScrolling
&& m_targetWindow
->IsShownOnScreen())
640 if ( m_physicalScrolling
)
644 dy
= GetUnitsSize(GetVisibleBegin(), unitFirstOld
);
646 if ( GetOrientation() == wxHORIZONTAL
)
653 m_targetWindow
->ScrollWindow(dx
, dy
);
655 else // !m_physicalScrolling
657 // we still need to invalidate but we can't use ScrollWindow
658 // because physical scrolling is disabled (the user either didn't
659 // want children scrolled and/or doesn't want pixels to be
660 // physically scrolled).
661 m_targetWindow
->Refresh();
668 bool wxVarScrollHelperBase::DoScrollUnits(int units
)
670 units
+= m_unitFirst
;
674 return DoScrollToUnit(units
);
677 bool wxVarScrollHelperBase::DoScrollPages(int pages
)
679 bool didSomething
= false;
686 unit
= GetVisibleEnd();
693 unit
= FindFirstVisibleFromLast(GetVisibleEnd());
697 didSomething
= DoScrollToUnit(unit
);
703 // ----------------------------------------------------------------------------
705 // ----------------------------------------------------------------------------
707 void wxVarScrollHelperBase::HandleOnSize(wxSizeEvent
& event
)
711 // sometimes change in varscrollable window's size can result in
712 // unused empty space after the last item. Fix it by decrementing
713 // first visible item position according to the available space.
715 // determine free space
716 const wxCoord sWindow
= GetOrientationTargetSize();
719 for ( unit
= m_unitFirst
; unit
< m_unitMax
; ++unit
)
724 s
+= OnGetUnitSize(unit
);
726 wxCoord freeSpace
= sWindow
- s
;
728 // decrement first visible item index as long as there is free space
729 size_t idealUnitFirst
;
730 for ( idealUnitFirst
= m_unitFirst
;
734 wxCoord us
= OnGetUnitSize(idealUnitFirst
-1);
735 if ( freeSpace
< us
)
739 m_unitFirst
= idealUnitFirst
;
747 void wxVarScrollHelperBase::HandleOnScroll(wxScrollWinEvent
& event
)
749 if (GetOrientation() != event
.GetOrientation())
755 DoScrollToUnit(GetNewScrollPosition(event
));
758 UpdateMacScrollWindow();
762 void wxVarScrollHelperBase::DoPrepareDC(wxDC
& dc
)
764 if ( m_physicalScrolling
)
766 wxPoint pt
= dc
.GetDeviceOrigin();
768 IncOrient(pt
.x
, pt
.y
, -GetScrollOffset());
770 dc
.SetDeviceOrigin(pt
.x
, pt
.y
);
774 int wxVarScrollHelperBase::DoCalcScrolledPosition(int coord
) const
776 return coord
- GetScrollOffset();
779 int wxVarScrollHelperBase::DoCalcUnscrolledPosition(int coord
) const
781 return coord
+ GetScrollOffset();
786 void wxVarScrollHelperBase::HandleOnMouseWheel(wxMouseEvent
& event
)
788 // we only want to process wheel events for vertical implementations.
789 // There is no way to determine wheel orientation (and on MSW horizontal
790 // wheel rotation just fakes scroll events, rather than sending a MOUSEWHEEL
792 if ( GetOrientation() != wxVERTICAL
)
795 m_sumWheelRotation
+= event
.GetWheelRotation();
796 int delta
= event
.GetWheelDelta();
798 // how much to scroll this time
799 int units_to_scroll
= -(m_sumWheelRotation
/delta
);
800 if ( !units_to_scroll
)
803 m_sumWheelRotation
+= units_to_scroll
*delta
;
805 if ( !event
.IsPageScroll() )
806 DoScrollUnits( units_to_scroll
*event
.GetLinesPerAction() );
807 else // scroll pages instead of units
808 DoScrollPages( units_to_scroll
);
811 #endif // wxUSE_MOUSEWHEEL
814 // ============================================================================
815 // wxVarHVScrollHelper implementation
816 // ============================================================================
818 // ----------------------------------------------------------------------------
819 // wxVarHVScrollHelper operations
820 // ----------------------------------------------------------------------------
822 void wxVarHVScrollHelper::SetRowColumnCount(size_t rowCount
, size_t columnCount
)
824 SetRowCount(rowCount
);
825 SetColumnCount(columnCount
);
828 bool wxVarHVScrollHelper::ScrollToRowColumn(size_t row
, size_t column
)
831 result
|= ScrollToRow(row
);
832 result
|= ScrollToColumn(column
);
836 void wxVarHVScrollHelper::RefreshRowColumn(size_t row
, size_t column
)
838 // is this unit visible?
839 if ( !IsRowVisible(row
) || !IsColumnVisible(column
) )
841 // no, it is useless to do anything
845 // calculate the rect occupied by this cell on screen
846 wxRect v_rect
, h_rect
;
847 v_rect
.height
= OnGetRowHeight(row
);
848 h_rect
.width
= OnGetColumnWidth(column
);
852 for ( n
= GetVisibleRowsBegin(); n
< row
; n
++ )
854 v_rect
.y
+= OnGetRowHeight(n
);
857 for ( n
= GetVisibleColumnsBegin(); n
< column
; n
++ )
859 h_rect
.x
+= OnGetColumnWidth(n
);
862 // refresh but specialize the behaviour if we have a single target window
863 if ( wxVarVScrollHelper::GetTargetWindow() == wxVarHScrollHelper::GetTargetWindow() )
866 v_rect
.width
= h_rect
.width
;
867 wxVarVScrollHelper::GetTargetWindow()->RefreshRect(v_rect
);
872 v_rect
.width
= wxVarVScrollHelper::GetNonOrientationTargetSize();
874 h_rect
.width
= wxVarHScrollHelper::GetNonOrientationTargetSize();
876 wxVarVScrollHelper::GetTargetWindow()->RefreshRect(v_rect
);
877 wxVarHScrollHelper::GetTargetWindow()->RefreshRect(h_rect
);
881 void wxVarHVScrollHelper::RefreshRowsColumns(size_t fromRow
, size_t toRow
,
882 size_t fromColumn
, size_t toColumn
)
884 wxASSERT_MSG( fromRow
<= toRow
|| fromColumn
<= toColumn
,
885 wxT("RefreshRowsColumns(): empty range") );
887 // clump the range to just the visible units -- it is useless to refresh
889 if ( fromRow
< GetVisibleRowsBegin() )
890 fromRow
= GetVisibleRowsBegin();
892 if ( toRow
> GetVisibleRowsEnd() )
893 toRow
= GetVisibleRowsEnd();
895 if ( fromColumn
< GetVisibleColumnsBegin() )
896 fromColumn
= GetVisibleColumnsBegin();
898 if ( toColumn
> GetVisibleColumnsEnd() )
899 toColumn
= GetVisibleColumnsEnd();
901 // calculate the rect occupied by these units on screen
902 wxRect v_rect
, h_rect
;
903 size_t nBefore
, nBetween
;
905 for ( nBefore
= GetVisibleRowsBegin();
909 v_rect
.y
+= OnGetRowHeight(nBefore
);
912 for ( nBetween
= fromRow
; nBetween
<= toRow
; nBetween
++ )
914 v_rect
.height
+= OnGetRowHeight(nBetween
);
917 for ( nBefore
= GetVisibleColumnsBegin();
918 nBefore
< fromColumn
;
921 h_rect
.x
+= OnGetColumnWidth(nBefore
);
924 for ( nBetween
= fromColumn
; nBetween
<= toColumn
; nBetween
++ )
926 h_rect
.width
+= OnGetColumnWidth(nBetween
);
929 // refresh but specialize the behaviour if we have a single target window
930 if ( wxVarVScrollHelper::GetTargetWindow() == wxVarHScrollHelper::GetTargetWindow() )
933 v_rect
.width
= h_rect
.width
;
934 wxVarVScrollHelper::GetTargetWindow()->RefreshRect(v_rect
);
939 v_rect
.width
= wxVarVScrollHelper::GetNonOrientationTargetSize();
941 h_rect
.width
= wxVarHScrollHelper::GetNonOrientationTargetSize();
943 wxVarVScrollHelper::GetTargetWindow()->RefreshRect(v_rect
);
944 wxVarHScrollHelper::GetTargetWindow()->RefreshRect(h_rect
);
948 wxPosition
wxVarHVScrollHelper::VirtualHitTest(wxCoord x
, wxCoord y
) const
950 return wxPosition(wxVarVScrollHelper::VirtualHitTest(y
),
951 wxVarHScrollHelper::VirtualHitTest(x
));
954 void wxVarHVScrollHelper::DoPrepareDC(wxDC
& dc
)
956 wxVarVScrollHelper::DoPrepareDC(dc
);
957 wxVarHScrollHelper::DoPrepareDC(dc
);
960 bool wxVarHVScrollHelper::ScrollLayout()
962 bool layout_result
= false;
963 layout_result
|= wxVarVScrollHelper::ScrollLayout();
964 layout_result
|= wxVarHScrollHelper::ScrollLayout();
965 return layout_result
;
968 wxSize
wxVarHVScrollHelper::GetRowColumnCount() const
970 return wxSize(GetColumnCount(), GetRowCount());
973 wxPosition
wxVarHVScrollHelper::GetVisibleBegin() const
975 return wxPosition(GetVisibleRowsBegin(), GetVisibleColumnsBegin());
978 wxPosition
wxVarHVScrollHelper::GetVisibleEnd() const
980 return wxPosition(GetVisibleRowsEnd(), GetVisibleColumnsEnd());
983 bool wxVarHVScrollHelper::IsVisible(size_t row
, size_t column
) const
985 return IsRowVisible(row
) && IsColumnVisible(column
);
989 // ============================================================================
990 // wx[V/H/HV]ScrolledWindow implementations
991 // ============================================================================
993 IMPLEMENT_ABSTRACT_CLASS(wxVScrolledWindow
, wxPanel
)
994 IMPLEMENT_ABSTRACT_CLASS(wxHScrolledWindow
, wxPanel
)
995 IMPLEMENT_ABSTRACT_CLASS(wxHVScrolledWindow
, wxPanel
)
998 #if WXWIN_COMPATIBILITY_2_8
1000 // ===========================================================================
1001 // wxVarVScrollLegacyAdaptor
1002 // ===========================================================================
1004 size_t wxVarVScrollLegacyAdaptor::GetFirstVisibleLine() const
1005 { return GetVisibleRowsBegin(); }
1007 size_t wxVarVScrollLegacyAdaptor::GetLastVisibleLine() const
1008 { return GetVisibleRowsEnd() - 1; }
1010 size_t wxVarVScrollLegacyAdaptor::GetLineCount() const
1011 { return GetRowCount(); }
1013 void wxVarVScrollLegacyAdaptor::SetLineCount(size_t count
)
1014 { SetRowCount(count
); }
1016 void wxVarVScrollLegacyAdaptor::RefreshLine(size_t line
)
1017 { RefreshRow(line
); }
1019 void wxVarVScrollLegacyAdaptor::RefreshLines(size_t from
, size_t to
)
1020 { RefreshRows(from
, to
); }
1022 bool wxVarVScrollLegacyAdaptor::ScrollToLine(size_t line
)
1023 { return ScrollToRow(line
); }
1025 bool wxVarVScrollLegacyAdaptor::ScrollLines(int lines
)
1026 { return ScrollRows(lines
); }
1028 bool wxVarVScrollLegacyAdaptor::ScrollPages(int pages
)
1029 { return ScrollRowPages(pages
); }
1031 wxCoord
wxVarVScrollLegacyAdaptor::OnGetLineHeight(size_t WXUNUSED(n
)) const
1033 wxFAIL_MSG( wxT("OnGetLineHeight() must be overridden if OnGetRowHeight() isn't!") );
1037 void wxVarVScrollLegacyAdaptor::OnGetLinesHint(size_t WXUNUSED(lineMin
),
1038 size_t WXUNUSED(lineMax
)) const
1042 wxCoord
wxVarVScrollLegacyAdaptor::OnGetRowHeight(size_t n
) const
1044 return OnGetLineHeight(n
);
1047 void wxVarVScrollLegacyAdaptor::OnGetRowsHeightHint(size_t rowMin
,
1048 size_t rowMax
) const
1050 OnGetLinesHint(rowMin
, rowMax
);
1053 #endif // WXWIN_COMPATIBILITY_2_8