LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/controller - SlsScrollBarManager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 103 294 35.0 %
Date: 2012-08-25 Functions: 11 28 39.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 109 434 25.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "controller/SlsScrollBarManager.hxx"
      31                 :            : 
      32                 :            : #include "SlideSorter.hxx"
      33                 :            : #include "controller/SlideSorterController.hxx"
      34                 :            : #include "controller/SlsVisibleAreaManager.hxx"
      35                 :            : #include "model/SlideSorterModel.hxx"
      36                 :            : #include "model/SlsPageDescriptor.hxx"
      37                 :            : #include "view/SlideSorterView.hxx"
      38                 :            : #include "view/SlsLayouter.hxx"
      39                 :            : #include "view/SlsTheme.hxx"
      40                 :            : #include "Window.hxx"
      41                 :            : #include "sdpage.hxx"
      42                 :            : 
      43                 :            : #include <boost/limits.hpp>
      44                 :            : 
      45                 :            : #include <vcl/scrbar.hxx>
      46                 :            : 
      47                 :            : namespace sd { namespace slidesorter { namespace controller {
      48                 :            : 
      49                 :        130 : ScrollBarManager::ScrollBarManager (SlideSorter& rSlideSorter)
      50                 :            :     : mrSlideSorter(rSlideSorter),
      51                 :            :       mpHorizontalScrollBar(mrSlideSorter.GetHorizontalScrollBar()),
      52                 :            :       mpVerticalScrollBar(mrSlideSorter.GetVerticalScrollBar()),
      53                 :            :       mnHorizontalPosition (0),
      54                 :            :       mnVerticalPosition (0),
      55                 :            :       maScrollBorder (20,20),
      56                 :            :       mnHorizontalScrollFactor (0.15),
      57                 :            :       mnVerticalScrollFactor (0.25),
      58                 :            :       mpScrollBarFiller(mrSlideSorter.GetScrollBarFiller()),
      59                 :            :       maAutoScrollTimer(),
      60                 :            :       maAutoScrollOffset(0,0),
      61                 :            :       mbIsAutoScrollActive(false),
      62                 :            :       mpContentWindow(mrSlideSorter.GetContentWindow()),
      63 [ +  - ][ +  - ]:        130 :       maAutoScrollFunctor()
         [ +  - ][ +  - ]
                 [ +  - ]
      64                 :            : {
      65                 :            :     // Hide the scroll bars by default to prevent display errors while
      66                 :            :     // switching between view shells:  In the short time between initiating
      67                 :            :     // such a switch and the final rearrangement of UI controls the scroll
      68                 :            :     // bars and the filler where displayed in the upper left corner of the
      69                 :            :     // ViewTabBar.
      70         [ +  - ]:        130 :     mpHorizontalScrollBar->Hide();
      71         [ +  - ]:        130 :     mpVerticalScrollBar->Hide();
      72         [ +  - ]:        130 :     mpScrollBarFiller->Hide();
      73                 :            : 
      74         [ +  - ]:        130 :     maAutoScrollTimer.SetTimeout(25);
      75                 :            :     maAutoScrollTimer.SetTimeoutHdl (
      76         [ +  - ]:        130 :         LINK(this, ScrollBarManager, AutoScrollTimeoutHandler));
      77                 :        130 : }
      78                 :            : 
      79                 :            : 
      80                 :            : 
      81                 :            : 
      82 [ +  - ][ +  - ]:        130 : ScrollBarManager::~ScrollBarManager (void)
         [ +  - ][ +  - ]
                 [ +  - ]
      83                 :            : {
      84                 :        130 : }
      85                 :            : 
      86                 :            : 
      87                 :            : 
      88                 :            : 
      89                 :        390 : void ScrollBarManager::LateInitialization (void)
      90                 :            : {
      91                 :        390 : }
      92                 :            : 
      93                 :            : 
      94                 :            : 
      95                 :            : 
      96                 :        260 : void ScrollBarManager::Connect (void)
      97                 :            : {
      98         [ +  - ]:        260 :     if (mpVerticalScrollBar != NULL)
      99                 :            :     {
     100                 :            :         mpVerticalScrollBar->SetScrollHdl (
     101                 :        260 :             LINK(this, ScrollBarManager, VerticalScrollBarHandler));
     102                 :            :     }
     103         [ +  - ]:        260 :     if (mpHorizontalScrollBar != NULL)
     104                 :            :     {
     105                 :            :         mpHorizontalScrollBar->SetScrollHdl(
     106                 :        260 :             LINK(this, ScrollBarManager, HorizontalScrollBarHandler));
     107                 :            :     }
     108                 :        260 : }
     109                 :            : 
     110                 :            : 
     111                 :            : 
     112                 :            : 
     113                 :        260 : void ScrollBarManager::Disconnect (void)
     114                 :            : {
     115         [ +  - ]:        260 :     if (mpVerticalScrollBar != NULL)
     116                 :            :     {
     117                 :        260 :         mpVerticalScrollBar->SetScrollHdl (Link());
     118                 :            :     }
     119         [ +  - ]:        260 :     if (mpHorizontalScrollBar != NULL)
     120                 :            :     {
     121                 :        260 :         mpHorizontalScrollBar->SetScrollHdl (Link());
     122                 :            :     }
     123                 :        260 : }
     124                 :            : 
     125                 :            : 
     126                 :            : 
     127                 :            : 
     128                 :            : /** Placing the scroll bars is an iterative process.  The visibility of one
     129                 :            :     scroll bar affects the remaining size and thus may lead to the other
     130                 :            :     scroll bar becoming visible.
     131                 :            : 
     132                 :            :     First we determine the visibility of the horizontal scroll bar.  After
     133                 :            :     that we do the same for the vertical scroll bar.  To have an initial
     134                 :            :     value for the required size we call the layouter before that.  When one
     135                 :            :     of the two scroll bars is made visible then the size of the browser
     136                 :            :     window changes and a second call to the layouter becomes necessary.
     137                 :            :     That call is made anyway after this method returns.
     138                 :            : */
     139                 :        302 : Rectangle ScrollBarManager::PlaceScrollBars (
     140                 :            :     const Rectangle& rAvailableArea,
     141                 :            :     const bool bIsHorizontalScrollBarAllowed,
     142                 :            :     const bool bIsVerticalScrollBarAllowed)
     143                 :            : {
     144                 :            :     Rectangle aRemainingSpace (DetermineScrollBarVisibilities(
     145                 :            :         rAvailableArea,
     146                 :            :         bIsHorizontalScrollBarAllowed,
     147                 :        302 :         bIsVerticalScrollBarAllowed));
     148                 :            : 
     149 [ -  + ][ -  + ]:        302 :     if (mpHorizontalScrollBar!=NULL && mpHorizontalScrollBar->IsVisible())
                 [ +  - ]
     150                 :          0 :         PlaceHorizontalScrollBar (rAvailableArea);
     151                 :            : 
     152 [ +  - ][ +  + ]:        302 :     if (mpVerticalScrollBar!=NULL && mpVerticalScrollBar->IsVisible())
                 [ +  + ]
     153                 :         24 :         PlaceVerticalScrollBar (rAvailableArea);
     154                 :            : 
     155 [ +  - ][ -  + ]:        302 :     if (mpScrollBarFiller!=NULL && mpScrollBarFiller->IsVisible())
                 [ -  + ]
     156                 :          0 :         PlaceFiller (rAvailableArea);
     157                 :            : 
     158                 :        302 :     return aRemainingSpace;
     159                 :            : }
     160                 :            : 
     161                 :            : 
     162                 :            : 
     163                 :            : 
     164                 :          0 : void ScrollBarManager::PlaceHorizontalScrollBar (const Rectangle& aAvailableArea)
     165                 :            : {
     166                 :            :     // Save the current relative position.
     167                 :          0 :     mnHorizontalPosition = double(mpHorizontalScrollBar->GetThumbPos())
     168                 :          0 :         / double(mpHorizontalScrollBar->GetRange().Len());
     169                 :            : 
     170                 :            :     // Place the scroll bar.
     171         [ #  # ]:          0 :     Size aScrollBarSize (mpHorizontalScrollBar->GetSizePixel());
     172                 :          0 :     mpHorizontalScrollBar->SetPosSizePixel (
     173                 :            :         Point(aAvailableArea.Left(),
     174                 :          0 :             aAvailableArea.Bottom()-aScrollBarSize.Height()+1),
     175 [ #  # ][ #  # ]:          0 :         Size (aAvailableArea.GetWidth() - GetVerticalScrollBarWidth(),
     176         [ #  # ]:          0 :             aScrollBarSize.Height()));
     177                 :            : 
     178                 :            :     // Restore the relative position.
     179                 :            :     mpHorizontalScrollBar->SetThumbPos(
     180         [ #  # ]:          0 :         (long)(0.5 + mnHorizontalPosition * mpHorizontalScrollBar->GetRange().Len()));
     181                 :          0 : }
     182                 :            : 
     183                 :            : 
     184                 :            : 
     185                 :            : 
     186                 :         24 : void ScrollBarManager::PlaceVerticalScrollBar (const Rectangle& aArea)
     187                 :            : {
     188                 :         24 :     const double nThumbPosition (mpVerticalScrollBar->GetThumbPos());
     189                 :            : 
     190                 :            :     // Place the scroll bar.
     191         [ +  - ]:         24 :     Size aScrollBarSize (mpVerticalScrollBar->GetSizePixel());
     192                 :         24 :     Point aPosition (aArea.Right()-aScrollBarSize.Width()+1, aArea.Top());
     193 [ +  - ][ +  - ]:         24 :     Size aSize (aScrollBarSize.Width(), aArea.GetHeight() - GetHorizontalScrollBarHeight());
     194         [ +  - ]:         24 :     mpVerticalScrollBar->SetPosSizePixel(aPosition, aSize);
     195                 :            : 
     196                 :            :     // Restore the position.
     197         [ +  - ]:         24 :     mpVerticalScrollBar->SetThumbPos(static_cast<long>(nThumbPosition));
     198                 :         24 :     mnVerticalPosition = nThumbPosition / double(mpVerticalScrollBar->GetRange().Len());
     199                 :         24 : }
     200                 :            : 
     201                 :            : 
     202                 :            : 
     203                 :            : 
     204                 :          0 : void ScrollBarManager::PlaceFiller (const Rectangle& aArea)
     205                 :            : {
     206                 :          0 :     mpScrollBarFiller->SetPosSizePixel(
     207                 :            :         Point(
     208         [ #  # ]:          0 :             aArea.Right()-mpVerticalScrollBar->GetSizePixel().Width()+1,
     209         [ #  # ]:          0 :             aArea.Bottom()-mpHorizontalScrollBar->GetSizePixel().Height()+1),
     210                 :            :         Size (
     211         [ #  # ]:          0 :             mpVerticalScrollBar->GetSizePixel().Width(),
     212         [ #  # ]:          0 :             mpHorizontalScrollBar->GetSizePixel().Height()));
     213                 :          0 : }
     214                 :            : 
     215                 :            : 
     216                 :            : 
     217                 :            : 
     218                 :        302 : void ScrollBarManager::UpdateScrollBars (bool bResetThumbPosition, bool bUseScrolling)
     219                 :            : {
     220 [ +  - ][ +  - ]:        302 :     Rectangle aModelArea (mrSlideSorter.GetView().GetModelArea());
     221         [ +  - ]:        302 :     SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
     222 [ +  - ][ +  - ]:        302 :     Size aWindowModelSize (pWindow->PixelToLogic(pWindow->GetSizePixel()));
     223                 :            : 
     224                 :            :     // The horizontal scroll bar is only shown when the window is
     225                 :            :     // horizontally smaller than the view.
     226 [ +  - ][ +  - ]:        302 :     if (mpHorizontalScrollBar != NULL && mpHorizontalScrollBar->IsVisible())
         [ -  + ][ -  + ]
     227                 :            :     {
     228         [ #  # ]:          0 :         mpHorizontalScrollBar->Show();
     229                 :            :         mpHorizontalScrollBar->SetRange (
     230         [ #  # ]:          0 :             Range(aModelArea.Left(), aModelArea.Right()));
     231         [ #  # ]:          0 :         if (bResetThumbPosition)
     232                 :            :         {
     233         [ #  # ]:          0 :             mpHorizontalScrollBar->SetThumbPos (0);
     234                 :          0 :             mnHorizontalPosition = 0;
     235                 :            :         }
     236                 :            :         else
     237                 :            :             mnHorizontalPosition =
     238                 :          0 :                 double(mpHorizontalScrollBar->GetThumbPos())
     239                 :          0 :                 / double(mpHorizontalScrollBar->GetRange().Len());
     240                 :            : 
     241         [ #  # ]:          0 :         mpHorizontalScrollBar->SetVisibleSize (aWindowModelSize.Width());
     242                 :            : 
     243                 :          0 :         const long nWidth (mpContentWindow->PixelToLogic(
     244   [ #  #  #  # ]:          0 :             mpContentWindow->GetSizePixel()).Width());
     245                 :            :         // Make the line size about 10% of the visible width.
     246                 :          0 :         mpHorizontalScrollBar->SetLineSize (nWidth / 10);
     247                 :            :         // Make the page size about 90% of the visible width.
     248                 :          0 :         mpHorizontalScrollBar->SetPageSize ((nWidth * 9) / 10);
     249                 :            :     }
     250                 :            :     else
     251                 :            :     {
     252                 :        302 :         mnHorizontalPosition = 0;
     253                 :            :     }
     254                 :            : 
     255                 :            :     // The vertical scroll bar is always shown.
     256 [ +  - ][ +  - ]:        302 :     if (mpVerticalScrollBar != NULL && mpVerticalScrollBar->IsVisible())
         [ +  + ][ +  + ]
     257                 :            :     {
     258                 :            :         mpVerticalScrollBar->SetRange (
     259         [ +  - ]:         24 :             Range(aModelArea.Top(), aModelArea.Bottom()));
     260         [ -  + ]:         24 :         if (bResetThumbPosition)
     261                 :            :         {
     262         [ #  # ]:          0 :             mpVerticalScrollBar->SetThumbPos (0);
     263                 :          0 :             mnVerticalPosition = 0;
     264                 :            :         }
     265                 :            :         else
     266                 :            :             mnVerticalPosition =
     267                 :         24 :                 double(mpVerticalScrollBar->GetThumbPos())
     268                 :         24 :                 / double(mpVerticalScrollBar->GetRange().Len());
     269                 :            : 
     270         [ +  - ]:         24 :         mpVerticalScrollBar->SetVisibleSize (aWindowModelSize.Height());
     271                 :            : 
     272                 :         24 :         const long nHeight (mpContentWindow->PixelToLogic(
     273   [ +  -  +  - ]:         48 :             mpContentWindow->GetSizePixel()).Height());
     274                 :            :         // Make the line size about 10% of the visible height.
     275                 :         24 :         mpVerticalScrollBar->SetLineSize (nHeight / 10);
     276                 :            :         // Make the page size about 90% of the visible height.
     277                 :         24 :         mpVerticalScrollBar->SetPageSize ((nHeight * 9) / 10);
     278                 :            :     }
     279                 :            :     else
     280                 :            :     {
     281                 :        278 :         mnVerticalPosition = 0;
     282                 :            :     }
     283                 :            : 
     284                 :            : 
     285                 :        302 :     double nEps (::std::numeric_limits<double>::epsilon());
     286 [ +  - ][ -  + ]:        604 :     if (fabs(mnHorizontalPosition-pWindow->GetVisibleX()) > nEps
         [ -  + ][ +  - ]
     287         [ +  - ]:        302 :         || fabs(mnVerticalPosition-pWindow->GetVisibleY()) > nEps)
     288                 :            :     {
     289 [ #  # ][ #  # ]:          0 :         mrSlideSorter.GetView().InvalidatePageObjectVisibilities();
     290         [ #  # ]:          0 :         if (bUseScrolling)
     291         [ #  # ]:          0 :             pWindow->SetVisibleXY(mnHorizontalPosition, mnVerticalPosition);
     292                 :            :         else
     293         [ #  # ]:          0 :             SetWindowOrigin(mnHorizontalPosition, mnVerticalPosition);
     294         [ +  - ]:        302 :     }
     295                 :        302 : }
     296                 :            : 
     297                 :            : 
     298                 :            : 
     299                 :            : 
     300                 :          0 : IMPL_LINK(ScrollBarManager, VerticalScrollBarHandler, ScrollBar*, pScrollBar)
     301                 :            : {
     302   [ #  #  #  # ]:          0 :     if (pScrollBar!=NULL
           [ #  #  #  # ]
                 [ #  # ]
     303                 :          0 :         && pScrollBar==mpVerticalScrollBar.get()
     304         [ #  # ]:          0 :         && pScrollBar->IsVisible()
     305 [ #  # ][ #  # ]:          0 :         && mrSlideSorter.GetContentWindow()!=NULL)
                 [ #  # ]
     306                 :            :     {
     307                 :          0 :         double nRelativePosition = double(pScrollBar->GetThumbPos())
     308                 :          0 :             / double(pScrollBar->GetRange().Len());
     309                 :          0 :         mrSlideSorter.GetView().InvalidatePageObjectVisibilities();
     310         [ #  # ]:          0 :         mrSlideSorter.GetContentWindow()->SetVisibleXY(-1, nRelativePosition);
     311                 :          0 :         mrSlideSorter.GetController().GetVisibleAreaManager().DeactivateCurrentSlideTracking();
     312                 :            :     }
     313                 :          0 :     return sal_True;
     314                 :            : }
     315                 :            : 
     316                 :            : 
     317                 :            : 
     318                 :            : 
     319                 :          0 : IMPL_LINK(ScrollBarManager, HorizontalScrollBarHandler, ScrollBar*, pScrollBar)
     320                 :            : {
     321   [ #  #  #  # ]:          0 :     if (pScrollBar!=NULL
           [ #  #  #  # ]
                 [ #  # ]
     322                 :          0 :         && pScrollBar==mpHorizontalScrollBar.get()
     323         [ #  # ]:          0 :         && pScrollBar->IsVisible()
     324 [ #  # ][ #  # ]:          0 :         && mrSlideSorter.GetContentWindow()!=NULL)
                 [ #  # ]
     325                 :            :     {
     326                 :          0 :         double nRelativePosition = double(pScrollBar->GetThumbPos())
     327                 :          0 :             / double(pScrollBar->GetRange().Len());
     328                 :          0 :         mrSlideSorter.GetView().InvalidatePageObjectVisibilities();
     329         [ #  # ]:          0 :         mrSlideSorter.GetContentWindow()->SetVisibleXY(nRelativePosition, -1);
     330                 :          0 :         mrSlideSorter.GetController().GetVisibleAreaManager().DeactivateCurrentSlideTracking();
     331                 :            :     }
     332                 :          0 :     return sal_True;
     333                 :            : }
     334                 :            : 
     335                 :            : 
     336                 :            : 
     337                 :            : 
     338                 :          0 : void ScrollBarManager::SetWindowOrigin (
     339                 :            :     double nHorizontalPosition,
     340                 :            :     double nVerticalPosition)
     341                 :            : {
     342                 :          0 :     mnHorizontalPosition = nHorizontalPosition;
     343                 :          0 :     mnVerticalPosition = nVerticalPosition;
     344                 :            : 
     345         [ #  # ]:          0 :     SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
     346         [ #  # ]:          0 :     Size aViewSize (pWindow->GetViewSize());
     347                 :            :     Point aOrigin (
     348                 :          0 :         (long int) (mnHorizontalPosition * aViewSize.Width()),
     349                 :          0 :         (long int) (mnVerticalPosition * aViewSize.Height()));
     350                 :            : 
     351         [ #  # ]:          0 :     pWindow->SetWinViewPos (aOrigin);
     352         [ #  # ]:          0 :     pWindow->UpdateMapMode ();
     353 [ #  # ][ #  # ]:          0 :     pWindow->Invalidate ();
     354                 :          0 : }
     355                 :            : 
     356                 :            : 
     357                 :            : 
     358                 :            : 
     359                 :            : /** Determining the visibility of the scroll bars is quite complicated.  The
     360                 :            :     visibility of one influences that of the other because showing a scroll
     361                 :            :     bar makes the available space smaller and may lead to the need of
     362                 :            :     displaying the other.
     363                 :            :     To solve this we test all four combinations of showing or hiding each
     364                 :            :     scroll bar and use the best one.  The best one is that combination that
     365                 :            :     a) shows the least number of scroll bars with preference of showing the
     366                 :            :     vertical over showing the horizontal and
     367                 :            :     b) when not showing a scroll bar the area used by the page objects fits
     368                 :            :     into the available area in the scroll bars orientation.
     369                 :            : */
     370                 :        302 : Rectangle ScrollBarManager::DetermineScrollBarVisibilities (
     371                 :            :     const Rectangle& rAvailableArea,
     372                 :            :     const bool bIsHorizontalScrollBarAllowed,
     373                 :            :     const bool bIsVerticalScrollBarAllowed)
     374                 :            : {
     375                 :            :     // Test which combination of scroll bars is the best.
     376                 :        302 :     bool bShowHorizontal = false;
     377                 :        302 :     bool bShowVertical = false;
     378         [ +  - ]:        302 :     if (mrSlideSorter.GetModel().GetPageCount() == 0)
     379                 :            :     {
     380                 :            :         // No pages => no scroll bars.
     381                 :            :     }
     382         [ +  + ]:        302 :     else if (TestScrollBarVisibilities(false, false, rAvailableArea))
     383                 :            :     {
     384                 :            :         // Nothing to be done.
     385                 :            :     }
     386   [ +  +  -  + ]:         33 :     else if (bIsHorizontalScrollBarAllowed
                 [ -  + ]
     387                 :          9 :         && TestScrollBarVisibilities(true, false, rAvailableArea))
     388                 :            :     {
     389                 :          0 :         bShowHorizontal = true;
     390                 :            :     }
     391   [ +  -  +  - ]:         48 :     else if (bIsVerticalScrollBarAllowed
                 [ +  - ]
     392                 :         24 :         && TestScrollBarVisibilities(false, true, rAvailableArea))
     393                 :            :     {
     394                 :         24 :         bShowVertical = true;
     395                 :            :     }
     396                 :            :     else
     397                 :            :     {
     398                 :          0 :         bShowHorizontal = true;
     399                 :          0 :         bShowVertical = true;
     400                 :            :     }
     401                 :            : 
     402                 :            :     // Make the visibility of the scroll bars permanent.
     403                 :        302 :     mpVerticalScrollBar->Show(bShowVertical);
     404                 :        302 :     mpHorizontalScrollBar->Show(bShowHorizontal);
     405 [ -  + ][ +  + ]:        302 :     mpScrollBarFiller->Show(bShowVertical && bShowHorizontal);
     406                 :            : 
     407                 :            :     // Adapt the remaining space accordingly.
     408                 :        302 :     Rectangle aRemainingSpace (rAvailableArea);
     409         [ +  + ]:        302 :     if (bShowVertical)
     410                 :         24 :         aRemainingSpace.Right() -= mpVerticalScrollBar->GetSizePixel().Width();
     411         [ -  + ]:        302 :     if (bShowHorizontal)
     412                 :          0 :         aRemainingSpace.Bottom() -= mpHorizontalScrollBar->GetSizePixel().Height();
     413                 :            : 
     414                 :        302 :     return aRemainingSpace;
     415                 :            : }
     416                 :            : 
     417                 :            : 
     418                 :            : 
     419                 :            : 
     420                 :        335 : bool ScrollBarManager::TestScrollBarVisibilities (
     421                 :            :     bool bHorizontalScrollBarVisible,
     422                 :            :     bool bVerticalScrollBarVisible,
     423                 :            :     const Rectangle& rAvailableArea)
     424                 :            : {
     425         [ +  - ]:        335 :     model::SlideSorterModel& rModel (mrSlideSorter.GetModel());
     426                 :            : 
     427                 :            :     // Adapt the available size by subtracting the sizes of the scroll bars
     428                 :            :     // visible in this combination.
     429         [ +  - ]:        335 :     Size aBrowserSize (rAvailableArea.GetSize());
     430         [ +  + ]:        335 :     if (bHorizontalScrollBarVisible)
     431         [ +  - ]:          9 :         aBrowserSize.Height() -= mpHorizontalScrollBar->GetSizePixel().Height();
     432         [ +  + ]:        335 :     if (bVerticalScrollBarVisible)
     433         [ +  - ]:         24 :         aBrowserSize.Width() -= mpVerticalScrollBar->GetSizePixel().Width();
     434                 :            : 
     435                 :            :     // Tell the view to rearrange its page objects and check whether the
     436                 :            :     // page objects can be shown without clipping.
     437 [ +  - ][ +  - ]:        335 :     bool bRearrangeSuccess (mrSlideSorter.GetView().GetLayouter().Rearrange (
     438         [ +  - ]:        335 :         mrSlideSorter.GetView().GetOrientation(),
     439                 :            :         aBrowserSize,
     440 [ +  - ][ +  - ]:        670 :         rModel.GetPageDescriptor(0)->GetPage()->GetSize(),
                 [ +  - ]
     441 [ +  - ][ +  - ]:       1340 :         rModel.GetPageCount()));
         [ +  - ][ +  - ]
     442                 :            : 
     443         [ +  - ]:        335 :     if (bRearrangeSuccess)
     444                 :            :     {
     445 [ +  - ][ +  - ]:        335 :         Size aPageSize = mrSlideSorter.GetView().GetLayouter().GetTotalBoundingBox().GetSize();
         [ +  - ][ +  - ]
     446         [ +  - ]:        335 :         Size aWindowModelSize = mpContentWindow->PixelToLogic(aBrowserSize);
     447                 :            : 
     448                 :            :         // The content may be clipped, i.e. not fully visible, in one
     449                 :            :         // direction only when the scroll bar is visible in that direction.
     450         [ -  + ]:        335 :         if (aPageSize.Width() > aWindowModelSize.Width())
     451         [ #  # ]:          0 :             if ( ! bHorizontalScrollBarVisible)
     452                 :          0 :                 return false;
     453         [ +  + ]:        335 :         if (aPageSize.Height() > aWindowModelSize.Height())
     454         [ +  + ]:         41 :             if ( ! bVerticalScrollBarVisible)
     455                 :         33 :                 return false;
     456                 :            : 
     457                 :        335 :         return true;
     458                 :            :     }
     459                 :            :     else
     460                 :        335 :         return false;
     461                 :            : }
     462                 :            : 
     463                 :            : 
     464                 :            : 
     465                 :            : 
     466                 :          0 : void ScrollBarManager::SetTopLeft (const Point aNewTopLeft)
     467                 :            : {
     468   [ #  #  #  #  :          0 :     if (( ! mpVerticalScrollBar
             #  #  #  # ]
                 [ #  # ]
     469                 :          0 :             || mpVerticalScrollBar->GetThumbPos() == aNewTopLeft.Y())
     470                 :          0 :         && ( ! mpHorizontalScrollBar
     471                 :          0 :             || mpHorizontalScrollBar->GetThumbPos() == aNewTopLeft.X()))
     472                 :          0 :         return;
     473                 :            : 
     474                 :            :     // Flush pending repaints before scrolling to avoid temporary artifacts.
     475         [ #  # ]:          0 :     mrSlideSorter.GetContentWindow()->Update();
     476                 :            : 
     477         [ #  # ]:          0 :     if (mpVerticalScrollBar)
     478                 :            :     {
     479                 :          0 :         mpVerticalScrollBar->SetThumbPos(aNewTopLeft.Y());
     480                 :          0 :         mnVerticalPosition = aNewTopLeft.Y() / double(mpVerticalScrollBar->GetRange().Len());
     481                 :            :     }
     482         [ #  # ]:          0 :     if (mpHorizontalScrollBar)
     483                 :            :     {
     484                 :          0 :         mpHorizontalScrollBar->SetThumbPos(aNewTopLeft.X());
     485                 :          0 :         mnHorizontalPosition = aNewTopLeft.X() / double(mpHorizontalScrollBar->GetRange().Len());
     486                 :            :     }
     487                 :            : 
     488         [ #  # ]:          0 :     mrSlideSorter.GetContentWindow()->SetVisibleXY(mnHorizontalPosition, mnVerticalPosition);
     489                 :          0 :     mrSlideSorter.GetView().InvalidatePageObjectVisibilities();
     490                 :            : }
     491                 :            : 
     492                 :            : 
     493                 :            : 
     494                 :            : 
     495                 :          0 : int ScrollBarManager::GetVerticalScrollBarWidth (void) const
     496                 :            : {
     497 [ #  # ][ #  # ]:          0 :     if (mpVerticalScrollBar != NULL && mpVerticalScrollBar->IsVisible())
                 [ #  # ]
     498                 :          0 :         return mpVerticalScrollBar->GetSizePixel().Width();
     499                 :            :     else
     500                 :          0 :         return 0;
     501                 :            : }
     502                 :            : 
     503                 :            : 
     504                 :            : 
     505                 :            : 
     506                 :         24 : int ScrollBarManager::GetHorizontalScrollBarHeight (void) const
     507                 :            : {
     508 [ +  - ][ -  + ]:         24 :     if (mpHorizontalScrollBar != NULL && mpHorizontalScrollBar->IsVisible())
                 [ -  + ]
     509                 :          0 :         return mpHorizontalScrollBar->GetSizePixel().Height();
     510                 :            :     else
     511                 :         24 :         return 0;
     512                 :            : }
     513                 :            : 
     514                 :            : 
     515                 :            : 
     516                 :            : 
     517                 :          0 : void ScrollBarManager::CalcAutoScrollOffset (const Point& rMouseWindowPosition)
     518                 :            : {
     519         [ #  # ]:          0 :     SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
     520                 :            : 
     521                 :          0 :     int nDx = 0;
     522                 :          0 :     int nDy = 0;
     523                 :            : 
     524                 :          0 :     Size aWindowSize = pWindow->GetOutputSizePixel();
     525 [ #  # ][ #  # ]:          0 :     Rectangle aWindowArea (pWindow->GetPosPixel(), aWindowSize);
     526                 :            :     Rectangle aViewPixelArea (
     527 [ #  # ][ #  # ]:          0 :         pWindow->LogicToPixel(mrSlideSorter.GetView().GetModelArea()));
                 [ #  # ]
     528                 :            : 
     529   [ #  #  #  # ]:          0 :     if (aWindowSize.Width() > maScrollBorder.Width() * 3
         [ #  # ][ #  # ]
     530                 :          0 :         && mpHorizontalScrollBar != NULL
     531         [ #  # ]:          0 :         && mpHorizontalScrollBar->IsVisible())
     532                 :            :     {
     533   [ #  #  #  # ]:          0 :         if (rMouseWindowPosition.X() < maScrollBorder.Width()
                 [ #  # ]
     534                 :          0 :             && aWindowArea.Left() > aViewPixelArea.Left())
     535                 :            :         {
     536                 :            :             nDx = -1 + (int)(mnHorizontalScrollFactor
     537                 :          0 :                 * (rMouseWindowPosition.X() - maScrollBorder.Width()));
     538                 :            :         }
     539                 :            : 
     540   [ #  #  #  # ]:          0 :         if (rMouseWindowPosition.X() >= (aWindowSize.Width() - maScrollBorder.Width())
                 [ #  # ]
     541                 :          0 :             && aWindowArea.Right() < aViewPixelArea.Right())
     542                 :            :         {
     543                 :            :             nDx = 1 + (int)(mnHorizontalScrollFactor
     544                 :          0 :                 * (rMouseWindowPosition.X() - aWindowSize.Width()
     545                 :          0 :                     + maScrollBorder.Width()));
     546                 :            :         }
     547                 :            :     }
     548                 :            : 
     549 [ #  # ][ #  # ]:          0 :     if (aWindowSize.Height() > maScrollBorder.Height() * 3
                 [ #  # ]
     550         [ #  # ]:          0 :         && aWindowSize.Height() < aViewPixelArea.GetHeight())
     551                 :            :     {
     552   [ #  #  #  # ]:          0 :         if (rMouseWindowPosition.Y() < maScrollBorder.Height()
                 [ #  # ]
     553                 :          0 :             && aWindowArea.Top() > aViewPixelArea.Top())
     554                 :            :         {
     555                 :            :             nDy = -1 + (int)(mnVerticalScrollFactor
     556                 :          0 :                 * (rMouseWindowPosition.Y() - maScrollBorder.Height()));
     557                 :            :         }
     558                 :            : 
     559   [ #  #  #  # ]:          0 :         if (rMouseWindowPosition.Y() >= (aWindowSize.Height() - maScrollBorder.Height())
                 [ #  # ]
     560                 :          0 :             && aWindowArea.Bottom() < aViewPixelArea.Bottom())
     561                 :            :         {
     562                 :            :             nDy = 1 + (int)(mnVerticalScrollFactor
     563                 :          0 :                 * (rMouseWindowPosition.Y() - aWindowSize.Height()
     564                 :          0 :                     + maScrollBorder.Height()));
     565                 :            :         }
     566                 :            :     }
     567                 :            : 
     568         [ #  # ]:          0 :     maAutoScrollOffset = Size(nDx,nDy);
     569                 :          0 : }
     570                 :            : 
     571                 :            : 
     572                 :            : 
     573                 :            : 
     574                 :          0 : bool ScrollBarManager::AutoScroll (
     575                 :            :     const Point& rMouseWindowPosition,
     576                 :            :     const ::boost::function<void(void)>& rAutoScrollFunctor)
     577                 :            : {
     578                 :          0 :     maAutoScrollFunctor = rAutoScrollFunctor;
     579                 :          0 :     CalcAutoScrollOffset(rMouseWindowPosition);
     580                 :          0 :     bool bResult (true);
     581         [ #  # ]:          0 :     if ( ! mbIsAutoScrollActive)
     582                 :          0 :         bResult = RepeatAutoScroll();
     583                 :            : 
     584                 :          0 :     return bResult;
     585                 :            : }
     586                 :            : 
     587                 :            : 
     588                 :            : 
     589                 :            : 
     590                 :          0 : void ScrollBarManager::StopAutoScroll (void)
     591                 :            : {
     592                 :          0 :     maAutoScrollTimer.Stop();
     593                 :          0 :     mbIsAutoScrollActive = false;
     594                 :          0 : }
     595                 :            : 
     596                 :            : 
     597                 :            : 
     598                 :            : 
     599                 :          0 : bool ScrollBarManager::RepeatAutoScroll (void)
     600                 :            : {
     601         [ #  # ]:          0 :     if (maAutoScrollOffset != Size(0,0))
     602                 :            :     {
     603         [ #  # ]:          0 :         if (mrSlideSorter.GetViewShell() != NULL)
     604                 :            :         {
     605                 :            :             mrSlideSorter.GetViewShell()->Scroll(
     606                 :          0 :                 maAutoScrollOffset.Width(),
     607                 :          0 :                 maAutoScrollOffset.Height());
     608                 :          0 :             mrSlideSorter.GetView().InvalidatePageObjectVisibilities();
     609                 :            : 
     610         [ #  # ]:          0 :             if (maAutoScrollFunctor)
     611                 :          0 :                 maAutoScrollFunctor();
     612                 :            : 
     613                 :          0 :             mbIsAutoScrollActive = true;
     614                 :          0 :             maAutoScrollTimer.Start();
     615                 :            : 
     616                 :          0 :             return true;
     617                 :            :         }
     618                 :            :     }
     619                 :            : 
     620                 :          0 :     clearAutoScrollFunctor();
     621                 :          0 :     mbIsAutoScrollActive = false;
     622                 :          0 :     return false;
     623                 :            : }
     624                 :            : 
     625                 :          0 : void ScrollBarManager::clearAutoScrollFunctor()
     626                 :            : {
     627         [ #  # ]:          0 :     maAutoScrollFunctor = ::boost::function<void(void)>();
     628                 :          0 : }
     629                 :            : 
     630                 :          0 : IMPL_LINK_NOARG(ScrollBarManager, AutoScrollTimeoutHandler)
     631                 :            : {
     632                 :          0 :     RepeatAutoScroll();
     633                 :            : 
     634                 :          0 :     return 0;
     635                 :            : }
     636                 :            : 
     637                 :            : 
     638                 :            : 
     639                 :            : 
     640                 :          0 : void ScrollBarManager::Scroll(
     641                 :            :     const Orientation eOrientation,
     642                 :            :     const Unit eUnit,
     643                 :            :     const sal_Int32 nDistance)
     644                 :            : {
     645                 :          0 :     bool bIsVertical (false);
     646      [ #  #  # ]:          0 :     switch (eOrientation)
     647                 :            :     {
     648                 :          0 :         case Orientation_Horizontal: bIsVertical = false; break;
     649                 :          0 :         case Orientation_Vertical: bIsVertical = true; break;
     650                 :            :         default:
     651                 :            :             OSL_ASSERT(eOrientation==Orientation_Horizontal || eOrientation==Orientation_Vertical);
     652                 :          0 :             return;
     653                 :            :     }
     654                 :            : 
     655                 :            :     Point aNewTopLeft (
     656                 :          0 :         mpHorizontalScrollBar ? mpHorizontalScrollBar->GetThumbPos() : 0,
     657 [ #  # ][ #  # ]:          0 :         mpVerticalScrollBar ? mpVerticalScrollBar->GetThumbPos() : 0);
     658      [ #  #  # ]:          0 :     switch (eUnit)
     659                 :            :     {
     660                 :            :         case Unit_Pixel:
     661         [ #  # ]:          0 :             if (bIsVertical)
     662                 :          0 :                 aNewTopLeft.Y() += nDistance;
     663                 :            :             else
     664                 :          0 :                 aNewTopLeft.X() += nDistance;
     665                 :          0 :             break;
     666                 :            : 
     667                 :            :         case Unit_Slide:
     668                 :            :         {
     669 [ #  # ][ #  # ]:          0 :             view::Layouter& rLayouter (mrSlideSorter.GetView().GetLayouter());
     670                 :            : 
     671                 :            :             // Calculate estimate of new location.
     672         [ #  # ]:          0 :             if (bIsVertical)
     673         [ #  # ]:          0 :                 aNewTopLeft.Y() += nDistance * rLayouter.GetPageObjectSize().Height();
     674                 :            :             else
     675         [ #  # ]:          0 :                 aNewTopLeft.X() += nDistance * rLayouter.GetPageObjectSize().Width();
     676                 :            : 
     677                 :            :             // Adapt location to show whole slides.
     678         [ #  # ]:          0 :             if (bIsVertical)
     679         [ #  # ]:          0 :                 if (nDistance > 0)
     680                 :            :                 {
     681                 :            :                     const sal_Int32 nIndex (rLayouter.GetIndexAtPoint(
     682                 :          0 :                         Point(aNewTopLeft.X(), aNewTopLeft.Y()+mpVerticalScrollBar->GetVisibleSize()),
     683         [ #  # ]:          0 :                         true));
     684         [ #  # ]:          0 :                     aNewTopLeft.Y() = rLayouter.GetPageObjectBox(nIndex,true).Bottom()
     685                 :          0 :                         - mpVerticalScrollBar->GetVisibleSize();
     686                 :            :                 }
     687                 :            :                 else
     688                 :            :                 {
     689                 :            :                     const sal_Int32 nIndex (rLayouter.GetIndexAtPoint(
     690                 :          0 :                         Point(aNewTopLeft.X(), aNewTopLeft.Y()),
     691         [ #  # ]:          0 :                         true));
     692         [ #  # ]:          0 :                     aNewTopLeft.Y() = rLayouter.GetPageObjectBox(nIndex,true).Top();
     693                 :            :                 }
     694                 :            :             else
     695         [ #  # ]:          0 :                 if (nDistance > 0)
     696                 :            :                 {
     697                 :            :                     const sal_Int32 nIndex (rLayouter.GetIndexAtPoint(
     698                 :          0 :                         Point(aNewTopLeft.X()+mpVerticalScrollBar->GetVisibleSize(), aNewTopLeft.Y()),
     699         [ #  # ]:          0 :                         true));
     700         [ #  # ]:          0 :                     aNewTopLeft.X() = rLayouter.GetPageObjectBox(nIndex,true).Right()
     701                 :          0 :                         - mpVerticalScrollBar->GetVisibleSize();
     702                 :            :                 }
     703                 :            :                 else
     704                 :            :                 {
     705                 :            :                     const sal_Int32 nIndex (rLayouter.GetIndexAtPoint(
     706                 :          0 :                         Point(aNewTopLeft.X(), aNewTopLeft.Y()),
     707         [ #  # ]:          0 :                             true));
     708         [ #  # ]:          0 :                     aNewTopLeft.X() = rLayouter.GetPageObjectBox(nIndex,true).Left();
     709                 :            :                 }
     710                 :            :         }
     711                 :            :     }
     712 [ #  # ][ #  # ]:          0 :     mrSlideSorter.GetController().GetVisibleAreaManager().DeactivateCurrentSlideTracking();
                 [ #  # ]
     713         [ #  # ]:          0 :     SetTopLeft(aNewTopLeft);
     714                 :            : }
     715                 :            : 
     716                 :            : 
     717                 :            : } } } // end of namespace ::sd::slidesorter::controller
     718                 :            : 
     719                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10