]> git.saurik.com Git - wxWidgets.git/blob - src/generic/vscroll.cpp
added WXDLLIMPEXP_FWD_FOO macros in addition to WXDLLIMPEXP_FOO for use with forward...
[wxWidgets.git] / src / generic / vscroll.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/vscroll.cpp
3 // Purpose: wxVScrolledWindow implementation
4 // Author: Vadim Zeitlin
5 // Modified by: Brad Anderson
6 // Created: 30.05.03
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include "wx/dc.h"
29 #include "wx/sizer.h"
30 #endif
31
32 #include "wx/vscroll.h"
33
34 // ============================================================================
35 // wxVarScrollHelperEvtHandler declaration
36 // ============================================================================
37
38 // ----------------------------------------------------------------------------
39 // wxScrollHelperEvtHandler: intercept the events from the window and forward
40 // them to wxVarScrollHelperBase
41 // ----------------------------------------------------------------------------
42
43 class WXDLLEXPORT wxVarScrollHelperEvtHandler : public wxEvtHandler
44 {
45 public:
46 wxVarScrollHelperEvtHandler(wxVarScrollHelperBase *scrollHelper)
47 {
48 m_scrollHelper = scrollHelper;
49 }
50
51 virtual bool ProcessEvent(wxEvent& event);
52
53 private:
54 wxVarScrollHelperBase *m_scrollHelper;
55
56 DECLARE_NO_COPY_CLASS(wxVarScrollHelperEvtHandler)
57 };
58
59 // ============================================================================
60 // wxVarScrollHelperEvtHandler implementation
61 // ============================================================================
62
63 bool wxVarScrollHelperEvtHandler::ProcessEvent(wxEvent& event)
64 {
65 wxEventType evType = event.GetEventType();
66
67 // pass it on to the real handler
68 bool processed = wxEvtHandler::ProcessEvent(event);
69
70 // always process the size events ourselves, even if the user code handles
71 // them as well, as we need to AdjustScrollbars()
72 //
73 // NB: it is important to do it after processing the event in the normal
74 // way as HandleOnSize() may generate a wxEVT_SIZE itself if the
75 // scrollbar[s] (dis)appear and it should be seen by the user code
76 // after this one
77 if ( evType == wxEVT_SIZE )
78 {
79 m_scrollHelper->HandleOnSize((wxSizeEvent &)event);
80
81 return !event.GetSkipped();
82 }
83
84 if ( processed )
85 {
86 // normally, nothing more to do here - except if we have a command
87 // event
88 if ( event.IsCommandEvent() )
89 {
90 return true;
91 }
92 }
93
94 // reset the skipped flag (which might have been set to true in
95 // ProcessEvent() above) to be able to test it below
96 bool wasSkipped = event.GetSkipped();
97 if ( wasSkipped )
98 event.Skip(false);
99
100 // reset the skipped flag to false as it might have been set to true in
101 // ProcessEvent() above
102 event.Skip(false);
103
104 if ( evType == wxEVT_SCROLLWIN_TOP ||
105 evType == wxEVT_SCROLLWIN_BOTTOM ||
106 evType == wxEVT_SCROLLWIN_LINEUP ||
107 evType == wxEVT_SCROLLWIN_LINEDOWN ||
108 evType == wxEVT_SCROLLWIN_PAGEUP ||
109 evType == wxEVT_SCROLLWIN_PAGEDOWN ||
110 evType == wxEVT_SCROLLWIN_THUMBTRACK ||
111 evType == wxEVT_SCROLLWIN_THUMBRELEASE )
112 {
113 m_scrollHelper->HandleOnScroll((wxScrollWinEvent &)event);
114 if ( !event.GetSkipped() )
115 {
116 // it makes sense to indicate that we processed the message as we
117 // did scroll the window (and also notice that wxAutoScrollTimer
118 // relies on our return value for continuous scrolling)
119 processed = true;
120 wasSkipped = false;
121 }
122 }
123 #if wxUSE_MOUSEWHEEL
124 else if ( evType == wxEVT_MOUSEWHEEL )
125 {
126 m_scrollHelper->HandleOnMouseWheel((wxMouseEvent &)event);
127 }
128 #endif // wxUSE_MOUSEWHEEL
129
130 if ( processed )
131 event.Skip(wasSkipped);
132
133 return processed;
134 }
135
136
137 // ============================================================================
138 // wxVarScrollHelperBase implementation
139 // ============================================================================
140
141 // ----------------------------------------------------------------------------
142 // wxVarScrollHelperBase initialization
143 // ----------------------------------------------------------------------------
144
145 wxVarScrollHelperBase::wxVarScrollHelperBase(wxWindow *win)
146 {
147 wxASSERT_MSG( win, _T("associated window can't be NULL in wxVarScrollHelperBase") );
148
149 #if wxUSE_MOUSEWHEEL
150 m_sumWheelRotation = 0;
151 #endif
152
153 m_unitMax = 0;
154 m_sizeTotal = 0;
155 m_unitFirst = 0;
156
157 m_win =
158 m_targetWindow = (wxWindow *)NULL;
159
160 m_handler = NULL;
161
162 m_win = win;
163
164 // by default, the associated window is also the target window
165 DoSetTargetWindow(win);
166
167 }
168
169 wxVarScrollHelperBase::~wxVarScrollHelperBase()
170 {
171 DeleteEvtHandler();
172 }
173
174 // ----------------------------------------------------------------------------
175 // wxVarScrollHelperBase various helpers
176 // ----------------------------------------------------------------------------
177
178 void
179 wxVarScrollHelperBase::AssignOrient(wxCoord& x,
180 wxCoord& y,
181 wxCoord first,
182 wxCoord second)
183 {
184 if ( GetOrientation() == wxVERTICAL )
185 {
186 x = first;
187 y = second;
188 }
189 else // horizontal
190 {
191 x = second;
192 y = first;
193 }
194 }
195
196 void
197 wxVarScrollHelperBase::IncOrient(wxCoord& x, wxCoord& y, wxCoord inc)
198 {
199 if ( GetOrientation() == wxVERTICAL )
200 y += inc;
201 else
202 x += inc;
203 }
204
205 wxCoord wxVarScrollHelperBase::DoEstimateTotalSize() const
206 {
207 // estimate the total height: it is impossible to call
208 // OnGetUnitSize() for every unit because there may be too many of
209 // them, so we just make a guess using some units in the beginning,
210 // some in the end and some in the middle
211 static const size_t NUM_UNITS_TO_SAMPLE = 10;
212
213 wxCoord sizeTotal;
214 if ( m_unitMax < 3*NUM_UNITS_TO_SAMPLE )
215 {
216 // in this case, full calculations are faster and more correct than
217 // guessing
218 sizeTotal = GetUnitsSize(0, m_unitMax);
219 }
220 else // too many units to calculate exactly
221 {
222 // look at some units in the beginning/middle/end
223 sizeTotal =
224 GetUnitsSize(0, NUM_UNITS_TO_SAMPLE) +
225 GetUnitsSize(m_unitMax - NUM_UNITS_TO_SAMPLE,
226 m_unitMax) +
227 GetUnitsSize(m_unitMax/2 - NUM_UNITS_TO_SAMPLE/2,
228 m_unitMax/2 + NUM_UNITS_TO_SAMPLE/2);
229
230 // use the height of the units we looked as the average
231 sizeTotal = (wxCoord)
232 (((float)sizeTotal / (3*NUM_UNITS_TO_SAMPLE)) * m_unitMax);
233 }
234
235 return sizeTotal;
236 }
237
238 wxCoord wxVarScrollHelperBase::GetUnitsSize(size_t unitMin, size_t unitMax) const
239 {
240 if ( unitMin == unitMax )
241 return 0;
242 else if ( unitMin > unitMax )
243 return -GetUnitsSize(unitMax, unitMin);
244 //else: unitMin < unitMax
245
246 // let the user code know that we're going to need all these units
247 OnGetUnitsSizeHint(unitMin, unitMax);
248
249 // sum up their sizes
250 wxCoord size = 0;
251 for ( size_t unit = unitMin; unit < unitMax; ++unit )
252 {
253 size += OnGetUnitSize(unit);
254 }
255
256 return size;
257 }
258
259 size_t wxVarScrollHelperBase::FindFirstVisibleFromLast(size_t unitLast, bool full) const
260 {
261 const wxCoord sWindow = GetOrientationTargetSize();
262
263 // go upwards until we arrive at a unit such that unitLast is not visible
264 // any more when it is shown
265 size_t unitFirst = unitLast;
266 wxCoord s = 0;
267 for ( ;; )
268 {
269 s += OnGetUnitSize(unitFirst);
270
271 if ( s > sWindow )
272 {
273 // for this unit to be fully visible we need to go one unit
274 // down, but if it is enough for it to be only partly visible then
275 // this unit will do as well
276 if ( full )
277 {
278 ++unitFirst;
279 }
280
281 break;
282 }
283
284 if ( !unitFirst )
285 break;
286
287 --unitFirst;
288 }
289
290 return unitFirst;
291 }
292
293 size_t wxVarScrollHelperBase::GetNewScrollPosition(wxScrollWinEvent& event) const
294 {
295 wxEventType evtType = event.GetEventType();
296
297 if ( evtType == wxEVT_SCROLLWIN_TOP )
298 {
299 return 0;
300 }
301 else if ( evtType == wxEVT_SCROLLWIN_BOTTOM )
302 {
303 return m_unitMax;
304 }
305 else if ( evtType == wxEVT_SCROLLWIN_LINEUP )
306 {
307 return m_unitFirst ? m_unitFirst - 1 : 0;
308 }
309 else if ( evtType == wxEVT_SCROLLWIN_LINEDOWN )
310 {
311 return m_unitFirst + 1;
312 }
313 else if ( evtType == wxEVT_SCROLLWIN_PAGEUP )
314 {
315 return FindFirstVisibleFromLast(m_unitFirst);
316 }
317 else if ( evtType == wxEVT_SCROLLWIN_PAGEDOWN )
318 {
319 if ( GetVisibleEnd() )
320 return GetVisibleEnd() - 1;
321 else
322 return GetVisibleEnd();
323 }
324 else if ( evtType == wxEVT_SCROLLWIN_THUMBRELEASE )
325 {
326 return event.GetPosition();
327 }
328 else if ( evtType == wxEVT_SCROLLWIN_THUMBTRACK )
329 {
330 return event.GetPosition();
331 }
332
333 // unknown scroll event?
334 wxFAIL_MSG( _T("unknown scroll event type?") );
335 return 0;
336 }
337
338 void wxVarScrollHelperBase::UpdateScrollbar()
339 {
340 // if there is nothing to scroll, remove the scrollbar
341 if ( !m_unitMax )
342 {
343 RemoveScrollbar();
344 return;
345 }
346
347 // see how many units can we fit on screen
348 const wxCoord sWindow = GetOrientationTargetSize();
349
350 // do vertical calculations
351 wxCoord s = 0;
352 size_t unit;
353 for ( unit = m_unitFirst; unit < m_unitMax; ++unit )
354 {
355 if ( s > sWindow )
356 break;
357
358 s += OnGetUnitSize(unit);
359 }
360
361 m_nUnitsVisible = unit - m_unitFirst;
362
363 int unitsPageSize = m_nUnitsVisible;
364 if ( s > sWindow )
365 {
366 // last unit is only partially visible, we still need the scrollbar and
367 // so we have to "fix" pageSize because if it is equal to m_unitMax
368 // the scrollbar is not shown at all under MSW
369 --unitsPageSize;
370 }
371
372 // set the scrollbar parameters to reflect this
373 m_win->SetScrollbar(GetOrientation(), m_unitFirst, unitsPageSize, m_unitMax);
374 }
375
376 void wxVarScrollHelperBase::RemoveScrollbar()
377 {
378 m_unitFirst = 0;
379 m_nUnitsVisible = m_unitMax;
380 m_win->SetScrollbar(GetOrientation(), 0, 0, 0);
381 }
382
383 void wxVarScrollHelperBase::DeleteEvtHandler()
384 {
385 // search for m_handler in the handler list
386 if ( m_win && m_handler )
387 {
388 if ( m_win->RemoveEventHandler(m_handler) )
389 {
390 delete m_handler;
391 }
392 //else: something is very wrong, so better [maybe] leak memory than
393 // risk a crash because of double deletion
394
395 m_handler = NULL;
396 }
397 }
398
399 void wxVarScrollHelperBase::DoSetTargetWindow(wxWindow *target)
400 {
401 m_targetWindow = target;
402 #ifdef __WXMAC__
403 target->MacSetClipChildren( true ) ;
404 #endif
405
406 // install the event handler which will intercept the events we're
407 // interested in (but only do it for our real window, not the target window
408 // which we scroll - we don't need to hijack its events)
409 if ( m_targetWindow == m_win )
410 {
411 // if we already have a handler, delete it first
412 DeleteEvtHandler();
413
414 m_handler = new wxVarScrollHelperEvtHandler(this);
415 m_targetWindow->PushEventHandler(m_handler);
416 }
417 }
418
419 // ----------------------------------------------------------------------------
420 // wxVarScrollHelperBase operations
421 // ----------------------------------------------------------------------------
422
423 void wxVarScrollHelperBase::SetTargetWindow(wxWindow *target)
424 {
425 wxCHECK_RET( target, wxT("target window must not be NULL") );
426
427 if ( target == m_targetWindow )
428 return;
429
430 DoSetTargetWindow(target);
431 }
432
433 void wxVarScrollHelperBase::SetUnitCount(size_t count)
434 {
435 // save the number of units
436 m_unitMax = count;
437
438 // and our estimate for their total height
439 m_sizeTotal = EstimateTotalSize();
440
441 // ScrollToUnit() will update the scrollbar itself if it changes the unit
442 // we pass to it because it's out of [new] range
443 size_t oldScrollPos = m_unitFirst;
444 DoScrollToUnit(m_unitFirst);
445 if ( oldScrollPos == m_unitFirst )
446 {
447 // but if it didn't do it, we still need to update the scrollbar to
448 // reflect the changed number of units ourselves
449 UpdateScrollbar();
450 }
451 }
452
453 void wxVarScrollHelperBase::RefreshUnit(size_t unit)
454 {
455 // is this unit visible?
456 if ( !IsVisible(unit) )
457 {
458 // no, it is useless to do anything
459 return;
460 }
461
462 // calculate the rect occupied by this unit on screen
463 wxRect rect;
464 AssignOrient(rect.width, rect.height,
465 GetNonOrientationTargetSize(), OnGetUnitSize(unit));
466
467 for ( size_t n = GetVisibleBegin(); n < unit; ++n )
468 {
469 IncOrient(rect.x, rect.y, OnGetUnitSize(n));
470 }
471
472 // do refresh it
473 m_targetWindow->RefreshRect(rect);
474 }
475
476 void wxVarScrollHelperBase::RefreshUnits(size_t from, size_t to)
477 {
478 wxASSERT_MSG( from <= to, _T("RefreshUnits(): empty range") );
479
480 // clump the range to just the visible units -- it is useless to refresh
481 // the other ones
482 if ( from < GetVisibleBegin() )
483 from = GetVisibleBegin();
484
485 if ( to > GetVisibleEnd() )
486 to = GetVisibleEnd();
487
488 // calculate the rect occupied by these units on screen
489 int orient_size, nonorient_size, orient_pos;
490 orient_size = nonorient_size = orient_pos = 0;
491
492 nonorient_size = GetNonOrientationTargetSize();
493
494 for ( size_t nBefore = GetVisibleBegin();
495 nBefore < from;
496 nBefore++ )
497 {
498 orient_pos += OnGetUnitSize(nBefore);
499 }
500
501 for ( size_t nBetween = from; nBetween <= to; nBetween++ )
502 {
503 orient_size += OnGetUnitSize(nBetween);
504 }
505
506 wxRect rect;
507 AssignOrient(rect.x, rect.y, 0, orient_pos);
508 AssignOrient(rect.width, rect.height, nonorient_size, orient_size);
509
510 // do refresh it
511 m_targetWindow->RefreshRect(rect);
512 }
513
514 void wxVarScrollHelperBase::RefreshAll()
515 {
516 UpdateScrollbar();
517
518 m_targetWindow->Refresh();
519 }
520
521 bool wxVarScrollHelperBase::ScrollLayout()
522 {
523 if ( m_targetWindow->GetSizer() && m_physicalScrolling )
524 {
525 // adjust the sizer dimensions/position taking into account the
526 // virtual size and scrolled position of the window.
527
528 int x, y;
529 AssignOrient(x, y, 0, -GetScrollOffset());
530
531 int w, h;
532 m_targetWindow->GetVirtualSize(&w, &h);
533
534 m_targetWindow->GetSizer()->SetDimension(x, y, w, h);
535 return true;
536 }
537
538 // fall back to default for LayoutConstraints
539 return m_targetWindow->wxWindow::Layout();
540 }
541
542 int wxVarScrollHelperBase::VirtualHitTest(wxCoord coord) const
543 {
544 const size_t unitMax = GetVisibleEnd();
545 for ( size_t unit = GetVisibleBegin(); unit < unitMax; ++unit )
546 {
547 coord -= OnGetUnitSize(unit);
548 if ( coord < 0 )
549 return unit;
550 }
551
552 return wxNOT_FOUND;
553 }
554
555 // ----------------------------------------------------------------------------
556 // wxVarScrollHelperBase scrolling
557 // ----------------------------------------------------------------------------
558
559 bool wxVarScrollHelperBase::DoScrollToUnit(size_t unit)
560 {
561 if ( !m_unitMax )
562 {
563 // we're empty, code below doesn't make sense in this case
564 return false;
565 }
566
567 // determine the real first unit to scroll to: we shouldn't scroll beyond
568 // the end
569 size_t unitFirstLast = FindFirstVisibleFromLast(m_unitMax - 1, true);
570 if ( unit > unitFirstLast )
571 unit = unitFirstLast;
572
573 // anything to do?
574 if ( unit == m_unitFirst )
575 {
576 // no
577 return false;
578 }
579
580
581 // remember the currently shown units for the refresh code below
582 size_t unitFirstOld = GetVisibleBegin(),
583 unitLastOld = GetVisibleEnd();
584
585 m_unitFirst = unit;
586
587
588 // the size of scrollbar thumb could have changed
589 UpdateScrollbar();
590
591 // finally refresh the display -- but only redraw as few units as possible
592 // to avoid flicker. We can't do this if we have children because they
593 // won't be scrolled
594 if ( m_targetWindow->GetChildren().empty() &&
595 GetVisibleBegin() >= unitLastOld || GetVisibleEnd() <= unitFirstOld )
596 {
597 // the simplest case: we don't have any old units left, just redraw
598 // everything
599 m_targetWindow->Refresh();
600 }
601 else // scroll the window
602 {
603 if ( m_physicalScrolling )
604 {
605 wxCoord dx = 0,
606 dy = GetUnitsSize(GetVisibleBegin(), unitFirstOld);
607
608 if ( GetOrientation() == wxHORIZONTAL )
609 {
610 wxCoord tmp = dx;
611 dx = dy;
612 dy = tmp;
613 }
614
615 m_targetWindow->ScrollWindow(dx, dy);
616 }
617 else // !m_physicalScrolling
618 {
619 // we still need to invalidate but we can't use ScrollWindow
620 // because physical scrolling is disabled (the user either didn't
621 // want children scrolled and/or doesn't want pixels to be
622 // physically scrolled).
623 m_targetWindow->Refresh();
624 }
625 }
626
627 return true;
628 }
629
630 bool wxVarScrollHelperBase::DoScrollUnits(int units)
631 {
632 units += m_unitFirst;
633 if ( units < 0 )
634 units = 0;
635
636 return DoScrollToUnit(units);
637 }
638
639 bool wxVarScrollHelperBase::DoScrollPages(int pages)
640 {
641 bool didSomething = false;
642
643 while ( pages )
644 {
645 int unit;
646 if ( pages > 0 )
647 {
648 unit = GetVisibleEnd();
649 if ( unit )
650 --unit;
651 --pages;
652 }
653 else // pages < 0
654 {
655 unit = FindFirstVisibleFromLast(GetVisibleEnd());
656 ++pages;
657 }
658
659 didSomething = DoScrollToUnit(unit);
660 }
661
662 return didSomething;
663 }
664
665 // ----------------------------------------------------------------------------
666 // event handling
667 // ----------------------------------------------------------------------------
668
669 void wxVarScrollHelperBase::HandleOnSize(wxSizeEvent& event)
670 {
671 UpdateScrollbar();
672
673 event.Skip();
674 }
675
676 void wxVarScrollHelperBase::HandleOnScroll(wxScrollWinEvent& event)
677 {
678 if (GetOrientation() != event.GetOrientation())
679 {
680 event.Skip();
681 return;
682 }
683
684 DoScrollToUnit(GetNewScrollPosition(event));
685
686 #ifdef __WXMAC__
687 UpdateMacScrollWindow();
688 #endif // __WXMAC__
689 }
690
691 void wxVarScrollHelperBase::DoPrepareDC(wxDC& dc)
692 {
693 if ( m_physicalScrolling )
694 {
695 wxPoint pt = dc.GetDeviceOrigin();
696
697 IncOrient(pt.x, pt.y, -GetScrollOffset());
698
699 dc.SetDeviceOrigin(pt.x, pt.y);
700 }
701 }
702
703 int wxVarScrollHelperBase::DoCalcScrolledPosition(int coord) const
704 {
705 return coord - GetScrollOffset();
706 }
707
708 int wxVarScrollHelperBase::DoCalcUnscrolledPosition(int coord) const
709 {
710 return coord + GetScrollOffset();
711 }
712
713 #if wxUSE_MOUSEWHEEL
714
715 void wxVarScrollHelperBase::HandleOnMouseWheel(wxMouseEvent& event)
716 {
717 // we only want to process wheel events for vertical implementations.
718 // There is no way to determine wheel orientation (and on MSW horizontal
719 // wheel rotation just fakes scroll events, rather than sending a MOUSEWHEEL
720 // event).
721 if ( GetOrientation() != wxVERTICAL )
722 return;
723
724 m_sumWheelRotation += event.GetWheelRotation();
725 int delta = event.GetWheelDelta();
726
727 // how much to scroll this time
728 int units_to_scroll = -(m_sumWheelRotation/delta);
729 if ( !units_to_scroll )
730 return;
731
732 m_sumWheelRotation += units_to_scroll*delta;
733
734 if ( !event.IsPageScroll() )
735 DoScrollUnits( units_to_scroll*event.GetLinesPerAction() );
736 else // scroll pages instead of units
737 DoScrollPages( units_to_scroll );
738 }
739
740 #endif // wxUSE_MOUSEWHEEL
741
742
743 // ============================================================================
744 // wxVarHVScrollHelper implementation
745 // ============================================================================
746
747 // ----------------------------------------------------------------------------
748 // wxVarHVScrollHelper operations
749 // ----------------------------------------------------------------------------
750
751 void wxVarHVScrollHelper::SetRowColumnCount(size_t rowCount, size_t columnCount)
752 {
753 SetRowCount(rowCount);
754 SetColumnCount(columnCount);
755 }
756
757 bool wxVarHVScrollHelper::ScrollToRowColumn(size_t row, size_t column)
758 {
759 bool result = false;
760 result |= ScrollToRow(row);
761 result |= ScrollToColumn(column);
762 return result;
763 }
764
765 void wxVarHVScrollHelper::RefreshRowColumn(size_t row, size_t column)
766 {
767 // is this unit visible?
768 if ( !IsRowVisible(row) || !IsColumnVisible(column) )
769 {
770 // no, it is useless to do anything
771 return;
772 }
773
774 // calculate the rect occupied by this cell on screen
775 wxRect v_rect, h_rect;
776 v_rect.height = OnGetRowHeight(row);
777 h_rect.width = OnGetColumnWidth(column);
778
779 size_t n;
780
781 for ( n = GetVisibleRowsBegin(); n < row; n++ )
782 {
783 v_rect.y += OnGetRowHeight(n);
784 }
785
786 for ( n = GetVisibleColumnsBegin(); n < column; n++ )
787 {
788 h_rect.x += OnGetColumnWidth(n);
789 }
790
791 // refresh but specialize the behavior if we have a single target window
792 if ( wxVarVScrollHelper::GetTargetWindow() == wxVarHScrollHelper::GetTargetWindow() )
793 {
794 v_rect.x = h_rect.x;
795 v_rect.width = h_rect.width;
796 wxVarVScrollHelper::GetTargetWindow()->RefreshRect(v_rect);
797 }
798 else
799 {
800 v_rect.x = 0;
801 v_rect.width = wxVarVScrollHelper::GetNonOrientationTargetSize();
802 h_rect.y = 0;
803 h_rect.width = wxVarHScrollHelper::GetNonOrientationTargetSize();
804
805 wxVarVScrollHelper::GetTargetWindow()->RefreshRect(v_rect);
806 wxVarHScrollHelper::GetTargetWindow()->RefreshRect(h_rect);
807 }
808 }
809
810 void wxVarHVScrollHelper::RefreshRowsColumns(size_t fromRow, size_t toRow,
811 size_t fromColumn, size_t toColumn)
812 {
813 wxASSERT_MSG( fromRow <= toRow || fromColumn <= toColumn,
814 _T("RefreshRowsColumns(): empty range") );
815
816 // clump the range to just the visible units -- it is useless to refresh
817 // the other ones
818 if ( fromRow < GetVisibleRowsBegin() )
819 fromRow = GetVisibleRowsBegin();
820
821 if ( toRow > GetVisibleRowsEnd() )
822 toRow = GetVisibleRowsEnd();
823
824 if ( fromColumn < GetVisibleColumnsBegin() )
825 fromColumn = GetVisibleColumnsBegin();
826
827 if ( toColumn > GetVisibleColumnsEnd() )
828 toColumn = GetVisibleColumnsEnd();
829
830 // calculate the rect occupied by these units on screen
831 wxRect v_rect, h_rect;
832 size_t nBefore, nBetween;
833
834 for ( nBefore = GetVisibleRowsBegin();
835 nBefore < fromRow;
836 nBefore++ )
837 {
838 v_rect.y += OnGetRowHeight(nBefore);
839 }
840
841 for ( nBetween = fromRow; nBetween <= toRow; nBetween++ )
842 {
843 v_rect.height += OnGetRowHeight(nBetween);
844 }
845
846 for ( nBefore = GetVisibleColumnsBegin();
847 nBefore < fromColumn;
848 nBefore++ )
849 {
850 h_rect.x += OnGetColumnWidth(nBefore);
851 }
852
853 for ( nBetween = fromColumn; nBetween <= toColumn; nBetween++ )
854 {
855 h_rect.width += OnGetColumnWidth(nBetween);
856 }
857
858 // refresh but specialize the behavior if we have a single target window
859 if ( wxVarVScrollHelper::GetTargetWindow() == wxVarHScrollHelper::GetTargetWindow() )
860 {
861 v_rect.x = h_rect.x;
862 v_rect.width = h_rect.width;
863 wxVarVScrollHelper::GetTargetWindow()->RefreshRect(v_rect);
864 }
865 else
866 {
867 v_rect.x = 0;
868 v_rect.width = wxVarVScrollHelper::GetNonOrientationTargetSize();
869 h_rect.y = 0;
870 h_rect.width = wxVarHScrollHelper::GetNonOrientationTargetSize();
871
872 wxVarVScrollHelper::GetTargetWindow()->RefreshRect(v_rect);
873 wxVarHScrollHelper::GetTargetWindow()->RefreshRect(h_rect);
874 }
875 }
876
877 wxPosition wxVarHVScrollHelper::VirtualHitTest(wxCoord x, wxCoord y) const
878 {
879 return wxPosition(wxVarVScrollHelper::VirtualHitTest(y),
880 wxVarHScrollHelper::VirtualHitTest(x));
881 }
882
883 void wxVarHVScrollHelper::DoPrepareDC(wxDC& dc)
884 {
885 wxVarVScrollHelper::DoPrepareDC(dc);
886 wxVarHScrollHelper::DoPrepareDC(dc);
887 }
888
889 bool wxVarHVScrollHelper::ScrollLayout()
890 {
891 bool layout_result = false;
892 layout_result |= wxVarVScrollHelper::ScrollLayout();
893 layout_result |= wxVarHScrollHelper::ScrollLayout();
894 return layout_result;
895 }
896
897 wxSize wxVarHVScrollHelper::GetRowColumnCount() const
898 {
899 return wxSize(GetColumnCount(), GetRowCount());
900 }
901
902 wxPosition wxVarHVScrollHelper::GetVisibleBegin() const
903 {
904 return wxPosition(GetVisibleRowsBegin(), GetVisibleColumnsBegin());
905 }
906
907 wxPosition wxVarHVScrollHelper::GetVisibleEnd() const
908 {
909 return wxPosition(GetVisibleRowsEnd(), GetVisibleColumnsEnd());
910 }
911
912 bool wxVarHVScrollHelper::IsVisible(size_t row, size_t column) const
913 {
914 return IsRowVisible(row) && IsColumnVisible(column);
915 }
916
917
918 // ============================================================================
919 // wx[V/H/HV]ScrolledWindow implementations
920 // ============================================================================
921
922 IMPLEMENT_ABSTRACT_CLASS(wxVScrolledWindow, wxPanel)
923 IMPLEMENT_ABSTRACT_CLASS(wxHScrolledWindow, wxPanel)
924 IMPLEMENT_ABSTRACT_CLASS(wxHVScrolledWindow, wxPanel)
925
926
927 #if WXWIN_COMPATIBILITY_2_8
928
929 // ===========================================================================
930 // wxVarVScrollLegacyAdaptor
931 // ===========================================================================
932
933 size_t wxVarVScrollLegacyAdaptor::GetFirstVisibleLine() const
934 { return GetVisibleRowsBegin(); }
935
936 size_t wxVarVScrollLegacyAdaptor::GetLastVisibleLine() const
937 { return GetVisibleRowsEnd() - 1; }
938
939 size_t wxVarVScrollLegacyAdaptor::GetLineCount() const
940 { return GetRowCount(); }
941
942 void wxVarVScrollLegacyAdaptor::SetLineCount(size_t count)
943 { SetRowCount(count); }
944
945 void wxVarVScrollLegacyAdaptor::RefreshLine(size_t line)
946 { RefreshRow(line); }
947
948 void wxVarVScrollLegacyAdaptor::RefreshLines(size_t from, size_t to)
949 { RefreshRows(from, to); }
950
951 bool wxVarVScrollLegacyAdaptor::ScrollToLine(size_t line)
952 { return ScrollToRow(line); }
953
954 bool wxVarVScrollLegacyAdaptor::ScrollLines(int lines)
955 { return ScrollRows(lines); }
956
957 bool wxVarVScrollLegacyAdaptor::ScrollPages(int pages)
958 { return ScrollRowPages(pages); }
959
960 wxCoord wxVarVScrollLegacyAdaptor::OnGetLineHeight(size_t WXUNUSED(n)) const
961 {
962 wxFAIL_MSG( _T("OnGetLineHeight() must be overridden if OnGetRowHeight() isn't!") );
963 return -1;
964 }
965
966 void wxVarVScrollLegacyAdaptor::OnGetLinesHint( size_t WXUNUSED(lineMin), size_t WXUNUSED(lineMax)) const
967 { }
968
969 #endif