LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/view - SlsPageObjectLayouter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 65 89 73.0 %
Date: 2012-08-25 Functions: 7 8 87.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 48 111 43.2 %

           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 "view/SlsPageObjectLayouter.hxx"
      31                 :            : 
      32                 :            : #include "model/SlsPageDescriptor.hxx"
      33                 :            : #include "view/SlsFontProvider.hxx"
      34                 :            : #include "view/SlsTheme.hxx"
      35                 :            : #include "tools/IconCache.hxx"
      36                 :            : #include "Window.hxx"
      37                 :            : #include "res_bmp.hrc"
      38                 :            : 
      39                 :            : namespace sd { namespace slidesorter { namespace view {
      40                 :            : 
      41                 :            : namespace {
      42                 :            : const static sal_Int32 gnLeftPageNumberOffset = 2;
      43                 :            : const static sal_Int32 gnRightPageNumberOffset = 5;
      44                 :            : const static sal_Int32 gnOuterBorderWidth = 5;
      45                 :            : const static sal_Int32 gnInfoAreaMinWidth = 26;
      46                 :            : }
      47                 :            : 
      48                 :        644 : PageObjectLayouter::PageObjectLayouter (
      49                 :            :     const Size& rPageObjectWindowSize,
      50                 :            :     const Size& rPageSize,
      51                 :            :     const SharedSdWindow& rpWindow,
      52                 :            :     const sal_Int32 nPageCount)
      53                 :            :     : mpWindow(rpWindow),
      54                 :            :       maPageObjectSize(rPageObjectWindowSize.Width(), rPageObjectWindowSize.Height()),
      55                 :            :       mnModelToWindowScale(1),
      56                 :            :       maPageObjectBoundingBox(),
      57                 :            :       maPageNumberAreaBoundingBox(),
      58                 :            :       maPreviewBoundingBox(),
      59                 :            :       maTransitionEffectBoundingBox(),
      60         [ +  - ]:        644 :       maTransitionEffectIcon(IconCache::Instance().GetIcon(BMP_FADE_EFFECT_INDICATOR)),
      61 [ +  - ][ +  - ]:       1288 :       mpPageNumberFont(Theme::GetFont(Theme::Font_PageNumber, *rpWindow))
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      62                 :            : {
      63         [ +  - ]:        644 :     const Size aPageNumberAreaSize (GetPageNumberAreaSize(nPageCount));
      64                 :            : 
      65                 :        644 :     const int nMaximumBorderWidth (gnOuterBorderWidth);
      66                 :        644 :     const int nFocusIndicatorWidth (Theme_FocusIndicatorWidth);
      67                 :            : 
      68                 :            :     maPreviewBoundingBox = CalculatePreviewBoundingBox(
      69                 :            :         maPageObjectSize,
      70                 :            :         Size(rPageSize.Width(), rPageSize.Height()),
      71                 :            :         aPageNumberAreaSize.Width(),
      72         [ +  - ]:        644 :         nFocusIndicatorWidth);
      73         [ +  - ]:        644 :     maFocusIndicatorBoundingBox = Rectangle(Point(0,0), maPageObjectSize);
      74                 :            :     maPageObjectBoundingBox = Rectangle(
      75                 :            :         Point(
      76                 :            :             nFocusIndicatorWidth,
      77                 :            :             nFocusIndicatorWidth),
      78                 :            :         Size(
      79                 :        644 :             maPageObjectSize.Width()-2*nFocusIndicatorWidth,
      80         [ +  - ]:       1288 :             maPageObjectSize.Height()-2*nFocusIndicatorWidth));
      81                 :            : 
      82                 :            :     maPageNumberAreaBoundingBox = Rectangle(
      83                 :            :         Point(
      84                 :            :             std::max(gnLeftPageNumberOffset,
      85                 :        644 :                 sal_Int32(maPreviewBoundingBox.Left()
      86                 :            :                 - gnRightPageNumberOffset
      87         [ +  - ]:        644 :                 - aPageNumberAreaSize.Width())),
      88                 :            :             nMaximumBorderWidth),
      89         [ +  - ]:        644 :         aPageNumberAreaSize);
      90                 :            : 
      91         [ +  - ]:        644 :     const Size aIconSize (maTransitionEffectIcon.GetSizePixel());
      92                 :            :     maTransitionEffectBoundingBox = Rectangle(
      93                 :            :         Point(
      94                 :        644 :             (maPreviewBoundingBox.Left() - aIconSize.Width()) / 2,
      95                 :        644 :             maPreviewBoundingBox.Bottom() - aIconSize.Height()),
      96         [ +  - ]:        644 :         aIconSize);
      97                 :        644 : }
      98                 :            : 
      99                 :            : 
     100                 :            : 
     101                 :            : 
     102 [ +  - ][ +  - ]:        644 : PageObjectLayouter::~PageObjectLayouter(void)
     103                 :            : {
     104                 :        644 : }
     105                 :            : 
     106                 :            : 
     107                 :            : 
     108                 :            : 
     109                 :        644 : Rectangle PageObjectLayouter::CalculatePreviewBoundingBox (
     110                 :            :     Size& rPageObjectSize,
     111                 :            :     const Size& rPageSize,
     112                 :            :     const sal_Int32 nPageNumberAreaWidth,
     113                 :            :     const sal_Int32 nFocusIndicatorWidth)
     114                 :            : {
     115         [ +  - ]:        644 :     const sal_Int32 nIconWidth (maTransitionEffectIcon.GetSizePixel().Width());
     116                 :            :     const sal_Int32 nLeftAreaWidth (
     117                 :            :         ::std::max(
     118                 :            :             gnInfoAreaMinWidth,
     119                 :            :             gnRightPageNumberOffset
     120                 :            :                 + ::std::max(
     121                 :            :                     nPageNumberAreaWidth,
     122 [ +  - ][ +  - ]:        644 :                     nIconWidth)));
     123                 :            :     sal_Int32 nPreviewWidth;
     124                 :            :     sal_Int32 nPreviewHeight;
     125                 :        644 :     const double nPageAspectRatio (double(rPageSize.Width()) / double(rPageSize.Height()));
     126         [ +  - ]:        644 :     if (rPageObjectSize.Height() == 0)
     127                 :            :     {
     128                 :            :         // Calculate height so that the preview fills the available
     129                 :            :         // horizontal space completely while observing the aspect ratio of
     130                 :            :         // the preview.
     131                 :        644 :         nPreviewWidth = rPageObjectSize.Width()
     132                 :        644 :             - nLeftAreaWidth - gnOuterBorderWidth - 2*nFocusIndicatorWidth - 1;
     133                 :        644 :         nPreviewHeight = ::basegfx::fround(nPreviewWidth / nPageAspectRatio);
     134                 :        644 :         rPageObjectSize.setHeight(nPreviewHeight + 2*gnOuterBorderWidth + 2*nFocusIndicatorWidth + 1);
     135                 :            :     }
     136         [ #  # ]:          0 :     else if (rPageObjectSize.Width() == 0)
     137                 :            :     {
     138                 :            :         // Calculate the width of the page object so that the preview fills
     139                 :            :         // the available vertical space completely while observing the
     140                 :            :         // aspect ratio of the preview.
     141                 :          0 :         nPreviewHeight = rPageObjectSize.Height() - 2*gnOuterBorderWidth - 2*nFocusIndicatorWidth - 1;
     142                 :          0 :         nPreviewWidth = ::basegfx::fround(nPreviewHeight * nPageAspectRatio);
     143                 :            :         rPageObjectSize.setWidth(nPreviewWidth
     144                 :          0 :             + nLeftAreaWidth + gnOuterBorderWidth + 2*nFocusIndicatorWidth + 1);
     145                 :            : 
     146                 :            :     }
     147                 :            :     else
     148                 :            :     {
     149                 :            :         // The size of the page object is given.  Calculate the size of the
     150                 :            :         // preview.
     151                 :          0 :         nPreviewWidth = rPageObjectSize.Width()
     152                 :          0 :             - nLeftAreaWidth - gnOuterBorderWidth - 2*nFocusIndicatorWidth - 1;
     153                 :          0 :         nPreviewHeight = rPageObjectSize.Height()
     154                 :          0 :             - gnOuterBorderWidth - 2*nFocusIndicatorWidth - 1;
     155         [ #  # ]:          0 :         if (double(nPreviewWidth)/double(nPreviewHeight) > nPageAspectRatio)
     156                 :          0 :             nPreviewWidth = ::basegfx::fround(nPreviewHeight * nPageAspectRatio);
     157                 :            :         else
     158                 :          0 :             nPreviewHeight = ::basegfx::fround(nPreviewWidth / nPageAspectRatio);
     159                 :            :     }
     160                 :            :     // When the preview does not fill the available space completely then
     161                 :            :     // place it flush right and vertically centered.
     162                 :        644 :     const int nLeft (rPageObjectSize.Width()
     163                 :        644 :         - gnOuterBorderWidth - nPreviewWidth - nFocusIndicatorWidth - 1);
     164                 :        644 :     const int nTop ((rPageObjectSize.Height() - nPreviewHeight)/2);
     165                 :            :     return Rectangle(
     166                 :            :         nLeft,
     167                 :            :         nTop,
     168                 :            :         nLeft + nPreviewWidth,
     169         [ +  - ]:        644 :         nTop + nPreviewHeight);
     170                 :            : }
     171                 :            : 
     172                 :            : 
     173                 :            : 
     174                 :            : 
     175                 :       2708 : Rectangle PageObjectLayouter::GetBoundingBox (
     176                 :            :     const model::SharedPageDescriptor& rpPageDescriptor,
     177                 :            :     const Part ePart,
     178                 :            :     const CoordinateSystem eCoordinateSystem)
     179                 :            : {
     180                 :            :     OSL_ASSERT(rpPageDescriptor);
     181 [ +  - ][ +  - ]:       2708 :     Point aLocation (rpPageDescriptor ? rpPageDescriptor->GetLocation() : Point(0,0));
     182         [ +  - ]:       2708 :     return GetBoundingBox(aLocation, ePart, eCoordinateSystem);
     183                 :            : }
     184                 :            : 
     185                 :            : 
     186                 :            : 
     187                 :            : 
     188                 :       4411 : Rectangle PageObjectLayouter::GetBoundingBox (
     189                 :            :     const Point& rPageObjectLocation,
     190                 :            :     const Part ePart,
     191                 :            :     const CoordinateSystem eCoordinateSystem)
     192                 :            : {
     193         [ +  - ]:       4411 :     Rectangle aBoundingBox;
     194   [ +  +  +  +  :       4411 :     switch (ePart)
                -  -  - ]
     195                 :            :     {
     196                 :            :         case FocusIndicator:
     197                 :       1777 :             aBoundingBox = maFocusIndicatorBoundingBox;
     198                 :       1777 :             break;
     199                 :            : 
     200                 :            :         case PageObject:
     201                 :            :         case MouseOverIndicator:
     202                 :        147 :             aBoundingBox = maPageObjectBoundingBox;
     203                 :        147 :             break;
     204                 :            : 
     205                 :            :         case Preview:
     206                 :       1810 :             aBoundingBox = maPreviewBoundingBox;
     207                 :       1810 :             break;
     208                 :            : 
     209                 :            :         case PageNumber:
     210                 :        677 :             aBoundingBox = maPageNumberAreaBoundingBox;
     211                 :        677 :             break;
     212                 :            : 
     213                 :            :         case Name:
     214                 :          0 :             aBoundingBox = maPageNumberAreaBoundingBox;
     215                 :          0 :             break;
     216                 :            : 
     217                 :            :         case TransitionEffectIndicator:
     218                 :          0 :             aBoundingBox = maTransitionEffectBoundingBox;
     219                 :          0 :             break;
     220                 :            :     }
     221                 :            : 
     222                 :            :     // Adapt coordinates to the requested coordinate system.
     223                 :       4411 :     Point aLocation (rPageObjectLocation);
     224         [ +  + ]:       4411 :     if (eCoordinateSystem == WindowCoordinateSystem)
     225                 :       1409 :         aLocation += mpWindow->GetMapMode().GetOrigin();
     226                 :            : 
     227                 :            :     return Rectangle(
     228                 :       4411 :         aBoundingBox.TopLeft() + aLocation,
     229 [ +  - ][ +  - ]:       8822 :         aBoundingBox.BottomRight() + aLocation);
     230                 :            : }
     231                 :            : 
     232                 :            : 
     233                 :            : 
     234                 :            : 
     235                 :       1409 : Size PageObjectLayouter::GetSize (
     236                 :            :     const Part ePart,
     237                 :            :     const CoordinateSystem eCoordinateSystem)
     238                 :            : {
     239 [ +  - ][ +  - ]:       1409 :     return GetBoundingBox(Point(0,0), ePart, eCoordinateSystem).GetSize();
     240                 :            : }
     241                 :            : 
     242                 :            : 
     243                 :            : 
     244                 :            : 
     245                 :        644 : Size PageObjectLayouter::GetPageNumberAreaSize (const int nPageCount)
     246                 :            : {
     247                 :            :     OSL_ASSERT(mpWindow);
     248                 :            : 
     249                 :            :     // Set the correct font.
     250         [ +  - ]:        644 :     Font aOriginalFont (mpWindow->GetFont());
     251         [ +  - ]:        644 :     if (mpPageNumberFont)
     252         [ +  - ]:        644 :         mpWindow->SetFont(*mpPageNumberFont);
     253                 :            : 
     254         [ +  - ]:        644 :     String sPageNumberTemplate;
     255         [ +  - ]:        644 :     if (nPageCount < 10)
     256         [ +  - ]:        644 :         sPageNumberTemplate = rtl::OUString("9");
     257         [ #  # ]:          0 :     else if (nPageCount < 100)
     258         [ #  # ]:          0 :         sPageNumberTemplate = rtl::OUString("99");
     259         [ #  # ]:          0 :     else if (nPageCount < 200)
     260                 :            :         // Just for the case that 1 is narrower than 9.
     261         [ #  # ]:          0 :         sPageNumberTemplate = rtl::OUString("199");
     262         [ #  # ]:          0 :     else if (nPageCount < 1000)
     263         [ #  # ]:          0 :         sPageNumberTemplate = rtl::OUString("999");
     264                 :            :     else
     265         [ #  # ]:          0 :         sPageNumberTemplate = rtl::OUString("9999");
     266                 :            :     // More then 9999 pages are not handled.
     267                 :            : 
     268                 :            :     const Size aSize (
     269                 :        644 :         mpWindow->GetTextWidth(sPageNumberTemplate),
     270   [ +  -  +  - ]:       1288 :         mpWindow->GetTextHeight());
     271                 :            : 
     272         [ +  - ]:        644 :     mpWindow->SetFont(aOriginalFont);
     273                 :            : 
     274 [ +  - ][ +  - ]:        644 :     return aSize;
     275                 :            : }
     276                 :            : 
     277                 :            : 
     278                 :            : 
     279                 :            : 
     280                 :          0 : Image PageObjectLayouter::GetTransitionEffectIcon (void) const
     281                 :            : {
     282                 :          0 :     return maTransitionEffectIcon;
     283                 :            : }
     284                 :            : 
     285                 :            : 
     286                 :            : } } } // end of namespace ::sd::slidesorter::view
     287                 :            : 
     288                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10