LCOV - code coverage report
Current view: top level - sw/source/core/view - pagepreviewlayout.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 623 0.0 %
Date: 2012-08-25 Functions: 0 35 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 650 0.0 %

           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                 :            : #include <pagepreviewlayout.hxx>
      30                 :            : #include <prevwpage.hxx>
      31                 :            : 
      32                 :            : #include <algorithm>
      33                 :            : #include <vcl/window.hxx>
      34                 :            : #include <rootfrm.hxx>
      35                 :            : #include <pagefrm.hxx>
      36                 :            : #include <viewsh.hxx>
      37                 :            : #include <viewimp.hxx>
      38                 :            : #include <viewopt.hxx>
      39                 :            : #include <swregion.hxx>
      40                 :            : #include <comcore.hrc>
      41                 :            : // OD 19.02.2003 #107369# - method <SwAlignRect(..)>
      42                 :            : #include <frmtool.hxx>
      43                 :            : // OD 24.09.2003 #i19975#
      44                 :            : #include <sfx2/zoomitem.hxx>
      45                 :            : #include <printdata.hxx>
      46                 :            : 
      47                 :            : #include <IDocumentDeviceAccess.hxx>
      48                 :            : 
      49                 :            : // OD 20.02.2003 #107369# - method to update statics for paint
      50                 :            : // Note: method defined in '/sw/source/core/layout/paintfrm.cxx'
      51                 :            : extern void SwCalcPixStatics( OutputDevice *pOut );
      52                 :            : 
      53                 :            : // =============================================================================
      54                 :            : // methods to initialize page preview layout
      55                 :            : // =============================================================================
      56                 :          0 : SwPagePreviewLayout::SwPagePreviewLayout( ViewShell& _rParentViewShell,
      57                 :            :                                           const SwRootFrm& _rLayoutRootFrm )
      58                 :            :     : mnXFree ( 4*142 ),
      59                 :            :       mnYFree ( 4*142 ),
      60                 :            :       mrParentViewShell( _rParentViewShell ),
      61                 :          0 :       mrLayoutRootFrm ( _rLayoutRootFrm )
      62                 :            : {
      63         [ #  # ]:          0 :     _Clear();
      64                 :            : 
      65                 :            :     // OD 2004-03-05 #i18143#
      66                 :          0 :     mbBookPreview = false;
      67                 :          0 :     mbBookPreviewModeToggled = false;
      68                 :            : 
      69 [ #  # ][ #  # ]:          0 :     mbPrintEmptyPages = mrParentViewShell.getIDocumentDeviceAccess()->getPrintData().IsPrintEmptyPages();
      70                 :          0 : }
      71                 :            : 
      72                 :          0 : void SwPagePreviewLayout::_Clear()
      73                 :            : {
      74                 :          0 :     mbLayoutInfoValid = mbLayoutSizesValid = mbPaintInfoValid = false;
      75                 :            : 
      76                 :          0 :     maWinSize.Width() = 0;
      77                 :          0 :     maWinSize.Height() = 0;
      78                 :          0 :     mnCols = mnRows = 0;
      79                 :            : 
      80                 :          0 :     _ClearPrevwLayoutSizes();
      81                 :            : 
      82                 :          0 :     mbDoesLayoutRowsFitIntoWindow = false;
      83                 :          0 :     mbDoesLayoutColsFitIntoWindow = false;
      84                 :            : 
      85                 :          0 :     mnPaintPhyStartPageNum = 0;
      86                 :          0 :     mnPaintStartCol = mnPaintStartRow = 0;
      87                 :          0 :     mbNoPageVisible = false;
      88                 :          0 :     maPaintStartPageOffset.X() = 0;
      89                 :          0 :     maPaintStartPageOffset.Y() = 0;
      90                 :          0 :     maPaintPreviewDocOffset.X() = 0;
      91                 :          0 :     maPaintPreviewDocOffset.Y() = 0;
      92                 :          0 :     maAdditionalPaintOffset.X() = 0;
      93                 :          0 :     maAdditionalPaintOffset.Y() = 0;
      94                 :          0 :     maPaintedPrevwDocRect.Left() = 0;
      95                 :          0 :     maPaintedPrevwDocRect.Top() = 0;
      96                 :          0 :     maPaintedPrevwDocRect.Right() = 0;
      97                 :          0 :     maPaintedPrevwDocRect.Bottom() = 0;
      98                 :          0 :     mnSelectedPageNum = 0;
      99                 :          0 :     _ClearPrevwPageData();
     100                 :            : 
     101                 :            :     // OD 07.11.2003 #i22014#
     102                 :          0 :     mbInPaint = false;
     103                 :          0 :     mbNewLayoutDuringPaint = false;
     104                 :          0 : }
     105                 :            : 
     106                 :          0 : void SwPagePreviewLayout::_ClearPrevwLayoutSizes()
     107                 :            : {
     108                 :          0 :     mnPages = 0;
     109                 :            : 
     110                 :          0 :     maMaxPageSize.Width() = 0;
     111                 :          0 :     maMaxPageSize.Height() = 0;
     112                 :          0 :     maPreviewDocRect.Left() = maPreviewDocRect.Top() = 0;
     113                 :          0 :     maPreviewDocRect.Right() = maPreviewDocRect.Bottom() = 0;
     114                 :          0 :     mnColWidth = mnRowHeight = 0;
     115                 :          0 :     mnPrevwLayoutWidth = mnPrevwLayoutHeight = 0;
     116                 :          0 : }
     117                 :            : 
     118                 :          0 : void SwPagePreviewLayout::_ClearPrevwPageData()
     119                 :            : {
     120 [ #  # ][ #  # ]:          0 :     for ( std::vector<PrevwPage*>::iterator aPageDelIter = maPrevwPages.begin();
     121                 :          0 :           aPageDelIter != maPrevwPages.end();
     122                 :            :           ++aPageDelIter )
     123                 :            :     {
     124                 :          0 :         delete (*aPageDelIter);
     125                 :            :     }
     126                 :          0 :     maPrevwPages.clear();
     127                 :          0 : }
     128                 :            : 
     129                 :            : /** calculate page preview layout sizes
     130                 :            : 
     131                 :            :     OD 18.12.2002 #103492#
     132                 :            : 
     133                 :            :     @author OD
     134                 :            : */
     135                 :          0 : void SwPagePreviewLayout::_CalcPrevwLayoutSizes()
     136                 :            : {
     137                 :            :     // calculate maximal page size; calculate also number of pages
     138                 :            : 
     139                 :          0 :     const SwPageFrm* pPage = static_cast<const SwPageFrm*>(mrLayoutRootFrm.Lower());
     140         [ #  # ]:          0 :     while ( pPage )
     141                 :            :     {
     142 [ #  # ][ #  # ]:          0 :         if ( !mbBookPreview && !mbPrintEmptyPages && pPage->IsEmptyPage() )
         [ #  # ][ #  # ]
     143                 :            :         {
     144                 :          0 :             pPage = static_cast<const SwPageFrm*>(pPage->GetNext());
     145                 :          0 :             continue;
     146                 :            :         }
     147                 :            : 
     148                 :          0 :         ++mnPages;
     149                 :          0 :         pPage->Calc();
     150                 :          0 :         const Size& rPageSize = pPage->Frm().SSize();
     151         [ #  # ]:          0 :         if ( rPageSize.Width() > maMaxPageSize.Width() )
     152                 :          0 :             maMaxPageSize.Width() = rPageSize.Width();
     153         [ #  # ]:          0 :         if ( rPageSize.Height() > maMaxPageSize.Height() )
     154                 :          0 :             maMaxPageSize.Height() = rPageSize.Height();
     155                 :          0 :         pPage = static_cast<const SwPageFrm*>(pPage->GetNext());
     156                 :            :     }
     157                 :            :     // calculate and set column width and row height
     158                 :          0 :     mnColWidth = maMaxPageSize.Width() + mnXFree;
     159                 :          0 :     mnRowHeight = maMaxPageSize.Height() + mnYFree;
     160                 :            : 
     161                 :            :     // calculate and set preview layout width and height
     162                 :          0 :     mnPrevwLayoutWidth = mnCols * mnColWidth + mnXFree;
     163                 :          0 :     mnPrevwLayoutHeight = mnRows * mnRowHeight + mnYFree;
     164                 :            : 
     165                 :            :     // calculate document rectangle in preview layout
     166                 :            :     {
     167                 :          0 :         Size aDocSize;
     168                 :            :         // document width
     169                 :          0 :         aDocSize.Width() = mnPrevwLayoutWidth;
     170                 :            : 
     171                 :            :         // document height
     172                 :            :         // determine number of rows needed for <nPages> in preview layout
     173                 :            :         // OD 19.02.2003 #107369# - use method <GetRowOfPage(..)>.
     174                 :          0 :         sal_uInt16 nDocRows = GetRowOfPage( mnPages );
     175                 :          0 :         aDocSize.Height() = nDocRows * maMaxPageSize.Height() +
     176                 :          0 :                             (nDocRows+1) * mnYFree;
     177                 :          0 :         maPreviewDocRect.SetPos( Point( 0, 0 ) );
     178         [ #  # ]:          0 :         maPreviewDocRect.SetSize( aDocSize );
     179                 :            :     }
     180                 :          0 : }
     181                 :            : 
     182                 :            : /** init page preview layout
     183                 :            : 
     184                 :            :     OD 11.12.2002 #103492#
     185                 :            :     initialize the page preview settings for a given layout.
     186                 :            :     side effects:
     187                 :            :     (1) If parameter <_bCalcScale> is true, mapping mode with calculated
     188                 :            :     scaling is set at the output device and the zoom at the view options of
     189                 :            :     the given view shell is set with the calculated scaling.
     190                 :            : 
     191                 :            :     @author OD
     192                 :            : */
     193                 :          0 : bool SwPagePreviewLayout::Init( const sal_uInt16 _nCols,
     194                 :            :                                 const sal_uInt16 _nRows,
     195                 :            :                                 const Size&      _rPxWinSize,
     196                 :            :                                 const bool       _bCalcScale
     197                 :            :                               )
     198                 :            : {
     199                 :            :     // check environment and parameters
     200                 :            :     {
     201 [ #  # ][ #  # ]:          0 :         bool bColsRowsValid = (_nCols != 0) && (_nRows != 0);
     202                 :            :         OSL_ENSURE( bColsRowsValid, "preview layout parameters not correct - preview layout can *not* be initialized" );
     203         [ #  # ]:          0 :         if ( !bColsRowsValid )
     204                 :          0 :             return false;
     205                 :            : 
     206                 :          0 :         bool bPxWinSizeValid = (_rPxWinSize.Width() >= 0) &&
     207 [ #  # ][ #  # ]:          0 :                                (_rPxWinSize.Height() >= 0);
     208                 :            :         OSL_ENSURE( bPxWinSizeValid, "no window size - preview layout can *not* be initialized" );
     209         [ #  # ]:          0 :         if ( !bPxWinSizeValid )
     210                 :          0 :             return false;
     211                 :            :     }
     212                 :            : 
     213                 :            :     // environment and parameters ok
     214                 :            : 
     215                 :            :     // clear existing preview settings
     216                 :          0 :     _Clear();
     217                 :            : 
     218                 :            :     // set layout information columns and rows
     219                 :          0 :     mnCols = _nCols;
     220                 :          0 :     mnRows = _nRows;
     221                 :            : 
     222                 :          0 :     _CalcPrevwLayoutSizes();
     223                 :            : 
     224                 :            :     // validate layout information
     225                 :          0 :     mbLayoutInfoValid = true;
     226                 :            : 
     227         [ #  # ]:          0 :     if ( _bCalcScale )
     228                 :            :     {
     229                 :            :         // calculate scaling
     230         [ #  # ]:          0 :         MapMode aMapMode( MAP_TWIP );
     231         [ #  # ]:          0 :         Size aWinSize = mrParentViewShell.GetOut()->PixelToLogic( _rPxWinSize, aMapMode );
     232         [ #  # ]:          0 :         Fraction aXScale( aWinSize.Width(), mnPrevwLayoutWidth );
     233         [ #  # ]:          0 :         Fraction aYScale( aWinSize.Height(), mnPrevwLayoutHeight );
     234 [ #  # ][ #  # ]:          0 :         if( aXScale < aYScale )
     235         [ #  # ]:          0 :             aYScale = aXScale;
     236                 :            :         {
     237                 :            :             // adjust scaling for Drawing layer.
     238 [ #  # ][ #  # ]:          0 :             aYScale *= Fraction( 1000, 1 );
     239         [ #  # ]:          0 :             long nNewNuminator = aYScale.operator long();
     240         [ #  # ]:          0 :             if( nNewNuminator < 1 )
     241                 :          0 :                 nNewNuminator = 1;
     242 [ #  # ][ #  # ]:          0 :             aYScale = Fraction( nNewNuminator, 1000 );
     243                 :            :             // propagate scaling as zoom percentage to view options for font cache
     244         [ #  # ]:          0 :             _ApplyNewZoomAtViewShell( static_cast<sal_uInt8>(nNewNuminator/10) );
     245                 :            :         }
     246         [ #  # ]:          0 :         aMapMode.SetScaleY( aYScale );
     247         [ #  # ]:          0 :         aMapMode.SetScaleX( aYScale );
     248                 :            :         // set created mapping mode with calculated scaling at output device.
     249         [ #  # ]:          0 :         mrParentViewShell.GetOut()->SetMapMode( aMapMode );
     250                 :            :         // OD 20.02.2003 #107369# - update statics for paint.
     251 [ #  # ][ #  # ]:          0 :         ::SwCalcPixStatics( mrParentViewShell.GetOut() );
     252                 :            :     }
     253                 :            : 
     254                 :            :     // set window size in twips
     255                 :          0 :     maWinSize = mrParentViewShell.GetOut()->PixelToLogic( _rPxWinSize );
     256                 :            :     // validate layout sizes
     257                 :          0 :     mbLayoutSizesValid = true;
     258                 :            : 
     259                 :          0 :     return true;
     260                 :            : }
     261                 :            : 
     262                 :            : /** apply new zoom at given view shell
     263                 :            : 
     264                 :            :     OD 11.12.2002 #103492# - implementation of <_ApplyNewZoomAtViewShell>
     265                 :            : 
     266                 :            :     @author OD
     267                 :            : */
     268                 :          0 : void SwPagePreviewLayout::_ApplyNewZoomAtViewShell( sal_uInt8 _aNewZoom )
     269                 :            : {
     270         [ #  # ]:          0 :     SwViewOption aNewViewOptions = *(mrParentViewShell.GetViewOptions());
     271         [ #  # ]:          0 :     if ( aNewViewOptions.GetZoom() != _aNewZoom )
     272                 :            :     {
     273                 :          0 :         aNewViewOptions.SetZoom( _aNewZoom );
     274                 :            :         //#i19975# - consider zoom type.
     275                 :          0 :         enum SvxZoomType eZoomType = SVX_ZOOM_PERCENT;
     276                 :          0 :         aNewViewOptions.SetZoomType( eZoomType );
     277         [ #  # ]:          0 :         mrParentViewShell.ApplyViewOptions( aNewViewOptions );
     278         [ #  # ]:          0 :     }
     279                 :          0 : }
     280                 :            : 
     281                 :            : /** method to adjust page preview layout to document changes
     282                 :            : 
     283                 :            :     OD 18.12.2002 #103492#
     284                 :            : 
     285                 :            :     @author OD
     286                 :            : */
     287                 :          0 : bool SwPagePreviewLayout::ReInit()
     288                 :            : {
     289                 :            :     // check environment and parameters
     290                 :            :     {
     291 [ #  # ][ #  # ]:          0 :         bool bLayoutSettingsValid = mbLayoutInfoValid && mbLayoutSizesValid;
     292                 :            :         OSL_ENSURE( bLayoutSettingsValid,
     293                 :            :                 "no valid preview layout info/sizes - no re-init of page preview layout");
     294         [ #  # ]:          0 :         if ( !bLayoutSettingsValid )
     295                 :          0 :             return false;
     296                 :            :     }
     297                 :            : 
     298                 :          0 :     _ClearPrevwLayoutSizes();
     299                 :          0 :     _CalcPrevwLayoutSizes();
     300                 :            : 
     301                 :          0 :     return true;
     302                 :            : }
     303                 :            : 
     304                 :            : // =============================================================================
     305                 :            : // methods to prepare paint of page preview
     306                 :            : // =============================================================================
     307                 :            : /** prepare paint of page preview
     308                 :            : 
     309                 :            :     OD 12.12.2002 #103492#
     310                 :            :     OD 21.03.2003 #108282# - delete parameter _onStartPageVirtNum
     311                 :            : 
     312                 :            :     @author OD, _nProposedStartPageNum, _onStartPageNum are absolute
     313                 :            : */
     314                 :          0 : bool SwPagePreviewLayout::Prepare( const sal_uInt16 _nProposedStartPageNum,
     315                 :            :                                    const Point      _aProposedStartPos,
     316                 :            :                                    const Size&      _rPxWinSize,
     317                 :            :                                    sal_uInt16&      _onStartPageNum,
     318                 :            :                                    Rectangle&       _orDocPreviewPaintRect,
     319                 :            :                                    const bool       _bStartWithPageAtFirstCol
     320                 :            :                                  )
     321                 :            : {
     322                 :          0 :     sal_uInt16 nProposedStartPageNum = ConvertAbsoluteToRelativePageNum( _nProposedStartPageNum );
     323                 :            :     // check environment and parameters
     324                 :            :     {
     325 [ #  # ][ #  # ]:          0 :         bool bLayoutSettingsValid = mbLayoutInfoValid && mbLayoutSizesValid;
     326                 :            :         OSL_ENSURE( bLayoutSettingsValid,
     327                 :            :                 "no valid preview layout info/sizes - no prepare of preview paint");
     328         [ #  # ]:          0 :         if ( !bLayoutSettingsValid )
     329                 :          0 :             return false;
     330                 :            : 
     331                 :          0 :         bool bStartPageRangeValid = nProposedStartPageNum <= mnPages;
     332                 :            :         OSL_ENSURE( bStartPageRangeValid,
     333                 :            :                 "proposed start page not existing - no prepare of preview paint");
     334         [ #  # ]:          0 :         if ( !bStartPageRangeValid )
     335                 :          0 :             return false;
     336                 :            : 
     337                 :            :         bool bStartPosRangeValid =
     338                 :          0 :                 _aProposedStartPos.X() >= 0 && _aProposedStartPos.Y() >= 0 &&
     339                 :          0 :                 _aProposedStartPos.X() <= maPreviewDocRect.Right() &&
     340 [ #  # ][ #  #  :          0 :                 _aProposedStartPos.Y() <= maPreviewDocRect.Bottom();
             #  #  #  # ]
     341                 :            :         OSL_ENSURE( bStartPosRangeValid,
     342                 :            :                 "proposed start position out of range - no prepare of preview paint");
     343         [ #  # ]:          0 :         if ( !bStartPosRangeValid )
     344                 :          0 :             return false;
     345                 :            : 
     346 [ #  # ][ #  # ]:          0 :         bool bWinSizeValid = _rPxWinSize.Width() != 0 && _rPxWinSize.Height() != 0;
     347                 :            :        OSL_ENSURE( bWinSizeValid, "no window size - no prepare of preview paint");
     348         [ #  # ]:          0 :         if ( !bWinSizeValid )
     349                 :          0 :             return false;
     350                 :            : 
     351                 :            :         bool bStartInfoValid = _nProposedStartPageNum > 0 ||
     352 [ #  # ][ #  # ]:          0 :                                _aProposedStartPos != Point(0,0);
                 [ #  # ]
     353         [ #  # ]:          0 :         if ( !bStartInfoValid )
     354                 :          0 :             nProposedStartPageNum = 1;
     355                 :            :     }
     356                 :            : 
     357                 :            :     // environment and parameter ok
     358                 :            : 
     359                 :            :     // update window size at preview setting data
     360                 :          0 :     maWinSize = mrParentViewShell.GetOut()->PixelToLogic( _rPxWinSize );
     361                 :            : 
     362                 :          0 :     mbNoPageVisible = false;
     363         [ #  # ]:          0 :     if ( nProposedStartPageNum > 0 )
     364                 :            :     {
     365                 :            :         // determine column and row of proposed start page in virtual preview layout
     366                 :          0 :         sal_uInt16 nColOfProposed = GetColOfPage( nProposedStartPageNum );
     367                 :          0 :         sal_uInt16 nRowOfProposed = GetRowOfPage( nProposedStartPageNum );
     368                 :            :         // determine start page
     369         [ #  # ]:          0 :         if ( _bStartWithPageAtFirstCol )
     370                 :            :         {
     371                 :            :             // OD 19.02.2003 #107369# - leaving left-top-corner blank is
     372                 :            :             // controlled by <mbBookPreview>.
     373 [ #  # ][ #  # ]:          0 :             if ( mbBookPreview &&
                 [ #  # ]
     374                 :            :                  ( nProposedStartPageNum == 1 || nRowOfProposed == 1 )
     375                 :            :                )
     376                 :          0 :                 mnPaintPhyStartPageNum = 1;
     377                 :            :             else
     378                 :          0 :                 mnPaintPhyStartPageNum = nProposedStartPageNum - (nColOfProposed-1);
     379                 :            :         }
     380                 :            :         else
     381                 :          0 :             mnPaintPhyStartPageNum = nProposedStartPageNum;
     382                 :            : 
     383                 :          0 :         mnPaintPhyStartPageNum = ConvertRelativeToAbsolutePageNum( mnPaintPhyStartPageNum );
     384                 :            : 
     385                 :            :         // set starting column
     386         [ #  # ]:          0 :         if ( _bStartWithPageAtFirstCol )
     387                 :          0 :             mnPaintStartCol = 1;
     388                 :            :         else
     389                 :          0 :             mnPaintStartCol = nColOfProposed;
     390                 :            :         // set starting row
     391                 :          0 :         mnPaintStartRow = nRowOfProposed;
     392                 :            :         // page offset == (-1,-1), indicating no offset and paint of free space.
     393                 :          0 :         maPaintStartPageOffset.X() = -1;
     394                 :          0 :         maPaintStartPageOffset.Y() = -1;
     395                 :            :         // virtual preview document offset.
     396         [ #  # ]:          0 :         if ( _bStartWithPageAtFirstCol )
     397                 :          0 :             maPaintPreviewDocOffset.X() = 0;
     398                 :            :         else
     399                 :          0 :             maPaintPreviewDocOffset.X() = (nColOfProposed-1) * mnColWidth;
     400                 :          0 :         maPaintPreviewDocOffset.Y() = (nRowOfProposed-1) * mnRowHeight;
     401                 :            :     }
     402                 :            :     else
     403                 :            :     {
     404                 :            :         // determine column and row of proposed start position.
     405                 :            :         // Note: paint starts at point (0,0)
     406                 :            :         sal_uInt16 nColOfProposed =
     407                 :          0 :                 static_cast<sal_uInt16>(_aProposedStartPos.X() / mnColWidth) + 1;
     408                 :            :         sal_uInt16 nRowOfProposed =
     409                 :          0 :                 static_cast<sal_uInt16>(_aProposedStartPos.Y() / mnRowHeight) + 1;
     410                 :            :         // determine start page == page at proposed start position
     411                 :            :         // OD 19.02.2003 #107369# - leaving left-top-corner blank is
     412                 :            :         // controlled by <mbBookPreview>.
     413 [ #  # ][ #  # ]:          0 :         if ( mbBookPreview &&
                 [ #  # ]
     414                 :            :              ( nRowOfProposed == 1 && nColOfProposed == 1 )
     415                 :            :            )
     416                 :          0 :             mnPaintPhyStartPageNum = 1;
     417                 :            :         else
     418                 :            :         {
     419                 :            :             // OD 19.02.2003 #107369# - leaving left-top-corner blank is
     420                 :            :             // controlled by <mbBookPreview>.
     421                 :          0 :             mnPaintPhyStartPageNum = (nRowOfProposed-1) * mnCols + nColOfProposed;
     422         [ #  # ]:          0 :             if ( mbBookPreview )
     423                 :          0 :                 --mnPaintPhyStartPageNum;
     424         [ #  # ]:          0 :             if ( mnPaintPhyStartPageNum > mnPages )
     425                 :            :             {
     426                 :            :                 // no page will be visible, because shown part of document
     427                 :            :                 // preview is the last row to the right of the last page
     428                 :          0 :                 mnPaintPhyStartPageNum = mnPages;
     429                 :          0 :                 mbNoPageVisible = true;
     430                 :            :             }
     431                 :            :         }
     432                 :            :         // set starting column and starting row
     433                 :          0 :         mnPaintStartCol = nColOfProposed;
     434                 :          0 :         mnPaintStartRow = nRowOfProposed;
     435                 :            :         // page offset
     436                 :          0 :         maPaintStartPageOffset.X() =
     437                 :          0 :                 (_aProposedStartPos.X() % mnColWidth) - mnXFree;
     438                 :          0 :         maPaintStartPageOffset.Y() =
     439                 :          0 :                 (_aProposedStartPos.Y() % mnRowHeight) - mnYFree;
     440                 :            :         // virtual preview document offset.
     441                 :          0 :         maPaintPreviewDocOffset = _aProposedStartPos;
     442                 :            :     }
     443                 :            : 
     444                 :            :     // determine additional paint offset, if preview layout fits into window.
     445                 :          0 :     _CalcAdditionalPaintOffset();
     446                 :            : 
     447                 :            :     // determine rectangle to be painted from document preview
     448                 :          0 :     _CalcDocPrevwPaintRect();
     449                 :          0 :     _orDocPreviewPaintRect = maPaintedPrevwDocRect;
     450                 :            : 
     451                 :            :     // OD 20.01.2003 #103492# - shift visible preview document area to the left,
     452                 :            :     // if on the right is an area left blank.
     453         [ #  # ]:          0 :     if ( !mbDoesLayoutColsFitIntoWindow &&
           [ #  #  #  # ]
     454                 :          0 :          maPaintedPrevwDocRect.GetWidth() < maWinSize.Width() )
     455                 :            :     {
     456                 :            :         maPaintedPrevwDocRect.Move(
     457                 :          0 :                 -(maWinSize.Width() - maPaintedPrevwDocRect.GetWidth()), 0 );
     458                 :            :         Prepare( 0, maPaintedPrevwDocRect.TopLeft(),
     459                 :            :                  _rPxWinSize, _onStartPageNum,
     460                 :          0 :                  _orDocPreviewPaintRect, _bStartWithPageAtFirstCol );
     461                 :            :     }
     462                 :            : 
     463                 :            :     // OD 20.01.2003 #103492# - shift visible preview document area to the top,
     464                 :            :     // if on the botton is an area left blank.
     465   [ #  #  #  #  :          0 :     if ( mbBookPreviewModeToggled &&
           #  # ][ #  # ]
     466                 :          0 :          maPaintedPrevwDocRect.Bottom() == maPreviewDocRect.Bottom() &&
     467                 :          0 :          maPaintedPrevwDocRect.GetHeight() < maWinSize.Height() )
     468                 :            :     {
     469         [ #  # ]:          0 :         if ( mbDoesLayoutRowsFitIntoWindow )
     470                 :            :         {
     471         [ #  # ]:          0 :             if ( maPaintedPrevwDocRect.GetHeight() < mnPrevwLayoutHeight)
     472                 :            :             {
     473                 :            :                 maPaintedPrevwDocRect.Move(
     474                 :          0 :                         0, -(mnPrevwLayoutHeight - maPaintedPrevwDocRect.GetHeight()) );
     475                 :            :                 Prepare( 0, maPaintedPrevwDocRect.TopLeft(),
     476                 :            :                          _rPxWinSize, _onStartPageNum,
     477                 :          0 :                          _orDocPreviewPaintRect, _bStartWithPageAtFirstCol );
     478                 :            :             }
     479                 :            :         }
     480                 :            :         else
     481                 :            :         {
     482                 :            :             maPaintedPrevwDocRect.Move(
     483                 :          0 :                     0, -(maWinSize.Height() - maPaintedPrevwDocRect.GetHeight()) );
     484                 :            :             Prepare( 0, maPaintedPrevwDocRect.TopLeft(),
     485                 :            :                      _rPxWinSize, _onStartPageNum,
     486                 :          0 :                      _orDocPreviewPaintRect, _bStartWithPageAtFirstCol );
     487                 :            :         }
     488                 :            :     }
     489                 :            : 
     490                 :            :     // determine preview pages - visible pages with needed data for paint and
     491                 :            :     // accessible pages with needed data.
     492                 :          0 :     _CalcPreviewPages();
     493                 :            : 
     494                 :            :     // OD 07.11.2003 #i22014# - indicate new layout, if print preview is in paint
     495         [ #  # ]:          0 :     if ( mbInPaint )
     496                 :            :     {
     497                 :          0 :         mbNewLayoutDuringPaint = true;
     498                 :            :     }
     499                 :            : 
     500                 :            :     // validate paint data
     501                 :          0 :     mbPaintInfoValid = true;
     502                 :            : 
     503                 :            :     // return start page
     504                 :          0 :     _onStartPageNum = mnPaintPhyStartPageNum;
     505                 :            : 
     506                 :          0 :     return true;
     507                 :            : }
     508                 :            : 
     509                 :            : /** calculate additional paint offset
     510                 :            : 
     511                 :            :     OD 12.12.2002 #103492#
     512                 :            : 
     513                 :            :     @author OD
     514                 :            : */
     515                 :          0 : void SwPagePreviewLayout::_CalcAdditionalPaintOffset()
     516                 :            : {
     517   [ #  #  #  # ]:          0 :     if ( mnPrevwLayoutWidth <= maWinSize.Width() &&
                 [ #  # ]
     518                 :          0 :          maPaintStartPageOffset.X() <= 0 )
     519                 :            :     {
     520                 :          0 :         mbDoesLayoutColsFitIntoWindow = true;
     521                 :          0 :         maAdditionalPaintOffset.X() = (maWinSize.Width() - mnPrevwLayoutWidth) / 2;
     522                 :            :     }
     523                 :            :     else
     524                 :            :     {
     525                 :          0 :         mbDoesLayoutColsFitIntoWindow = false;
     526                 :          0 :         maAdditionalPaintOffset.X() = 0;
     527                 :            :     }
     528                 :            : 
     529   [ #  #  #  # ]:          0 :     if ( mnPrevwLayoutHeight <= maWinSize.Height() &&
                 [ #  # ]
     530                 :          0 :          maPaintStartPageOffset.Y() <= 0 )
     531                 :            :     {
     532                 :          0 :         mbDoesLayoutRowsFitIntoWindow = true;
     533                 :          0 :         maAdditionalPaintOffset.Y() = (maWinSize.Height() - mnPrevwLayoutHeight) / 2;
     534                 :            :     }
     535                 :            :     else
     536                 :            :     {
     537                 :          0 :         mbDoesLayoutRowsFitIntoWindow = false;
     538                 :          0 :         maAdditionalPaintOffset.Y() = 0;
     539                 :            :     }
     540                 :          0 : }
     541                 :            : 
     542                 :            : /** calculate painted preview document rectangle
     543                 :            : 
     544                 :            :     OD 12.12.2002 #103492#
     545                 :            : 
     546                 :            :     @author OD
     547                 :            : */
     548                 :          0 : void SwPagePreviewLayout::_CalcDocPrevwPaintRect()
     549                 :            : {
     550                 :          0 :     Point aTopLeftPos = maPaintPreviewDocOffset;
     551                 :          0 :     maPaintedPrevwDocRect.SetPos( aTopLeftPos );
     552                 :            : 
     553                 :          0 :     Size aSize;
     554         [ #  # ]:          0 :     if ( mbDoesLayoutColsFitIntoWindow )
     555                 :            :         //aSize.Width() = mnPrevwLayoutWidth;
     556                 :          0 :         aSize.Width() = Min( mnPrevwLayoutWidth,
     557         [ #  # ]:          0 :                              maPreviewDocRect.GetWidth() - aTopLeftPos.X() );
     558                 :            :     else
     559         [ #  # ]:          0 :         aSize.Width() = Min( maPreviewDocRect.GetWidth() - aTopLeftPos.X(),
     560                 :          0 :                              maWinSize.Width() - maAdditionalPaintOffset.X() );
     561         [ #  # ]:          0 :     if ( mbDoesLayoutRowsFitIntoWindow )
     562                 :            :         //aSize.Height() = mnPrevwLayoutHeight;
     563                 :          0 :         aSize.Height() = Min( mnPrevwLayoutHeight,
     564         [ #  # ]:          0 :                               maPreviewDocRect.GetHeight() - aTopLeftPos.Y() );
     565                 :            :     else
     566         [ #  # ]:          0 :         aSize.Height() = Min( maPreviewDocRect.GetHeight() - aTopLeftPos.Y(),
     567                 :          0 :                               maWinSize.Height() - maAdditionalPaintOffset.Y() );
     568         [ #  # ]:          0 :     maPaintedPrevwDocRect.SetSize( aSize );
     569                 :          0 : }
     570                 :            : 
     571                 :            : /** calculate preview pages
     572                 :            : 
     573                 :            :     OD 12.12.2002 #103492#
     574                 :            : 
     575                 :            :     @author OD
     576                 :            : */
     577                 :          0 : void SwPagePreviewLayout::_CalcPreviewPages()
     578                 :            : {
     579         [ #  # ]:          0 :     _ClearPrevwPageData();
     580                 :            : 
     581         [ #  # ]:          0 :     if ( mbNoPageVisible )
     582                 :          0 :         return;
     583                 :            : 
     584                 :            :     // determine start page frame
     585         [ #  # ]:          0 :     const SwPageFrm* pStartPage = mrLayoutRootFrm.GetPageByPageNum( mnPaintPhyStartPageNum );
     586                 :            : 
     587                 :            :     // calculate initial paint offset
     588                 :          0 :     Point aInitialPaintOffset;
     589         [ #  # ]:          0 :     if ( maPaintStartPageOffset != Point( -1, -1 ) )
     590                 :          0 :         aInitialPaintOffset = Point(0,0) - maPaintStartPageOffset;
     591                 :            :     else
     592                 :          0 :         aInitialPaintOffset = Point( mnXFree, mnYFree );
     593                 :          0 :     aInitialPaintOffset += maAdditionalPaintOffset;
     594                 :            : 
     595                 :            :     // prepare loop data
     596                 :          0 :     const SwPageFrm* pPage = pStartPage;
     597                 :          0 :     sal_uInt16 nCurrCol = mnPaintStartCol;
     598                 :          0 :     sal_uInt16 nConsideredRows = 0;
     599                 :          0 :     Point aCurrPaintOffset = aInitialPaintOffset;
     600                 :            :     // loop on pages to determine preview background retangles
     601 [ #  # ][ #  # ]:          0 :     while ( pPage &&
           [ #  #  #  # ]
                 [ #  # ]
     602                 :          0 :             (!mbDoesLayoutRowsFitIntoWindow || nConsideredRows < mnRows) &&
     603                 :          0 :             aCurrPaintOffset.Y() < maWinSize.Height()
     604                 :            :           )
     605                 :            :     {
     606 [ #  # ][ #  # ]:          0 :         if ( !mbBookPreview && !mbPrintEmptyPages && pPage->IsEmptyPage() )
         [ #  # ][ #  # ]
     607                 :            :         {
     608                 :          0 :             pPage = static_cast<const SwPageFrm*>(pPage->GetNext());
     609                 :          0 :             continue;
     610                 :            :         }
     611                 :            : 
     612         [ #  # ]:          0 :         pPage->Calc();
     613                 :            : 
     614                 :            :         // consider only pages, which have to be painted.
     615         [ #  # ]:          0 :         if ( nCurrCol < mnPaintStartCol )
     616                 :            :         {
     617                 :            :             // calculate data of unvisible page needed for accessibility
     618         [ #  # ]:          0 :             PrevwPage* pPrevwPage = new PrevwPage;
     619                 :            :             Point aCurrAccOffset = aCurrPaintOffset -
     620                 :          0 :                            Point( (mnPaintStartCol-nCurrCol) * mnColWidth, 0 );
     621                 :          0 :             _CalcPreviewDataForPage( *(pPage), aCurrAccOffset, pPrevwPage );
     622                 :          0 :             pPrevwPage->bVisible = false;
     623         [ #  # ]:          0 :             maPrevwPages.push_back( pPrevwPage );
     624                 :            :             // continue with next page and next column
     625                 :          0 :             pPage = static_cast<const SwPageFrm*>(pPage->GetNext());
     626                 :          0 :             ++nCurrCol;
     627                 :          0 :             continue;
     628                 :            :         }
     629         [ #  # ]:          0 :         if ( aCurrPaintOffset.X() < maWinSize.Width() )
     630                 :            :         {
     631                 :            :             // OD 19.02.2003 #107369# - leaving left-top-corner blank is
     632                 :            :             // controlled by <mbBookPreview>.
     633 [ #  # ][ #  # ]:          0 :             if ( mbBookPreview && pPage->GetPhyPageNum() == 1 && mnCols != 1 && nCurrCol == 1
         [ #  # ][ #  # ]
                 [ #  # ]
     634                 :            :                )
     635                 :            :             {
     636                 :            :                 // first page in 2nd column
     637                 :            :                 // --> continue with increased paint offset and next column
     638                 :          0 :                 aCurrPaintOffset.X() += mnColWidth;
     639                 :          0 :                 ++nCurrCol;
     640                 :          0 :                 continue;
     641                 :            :             }
     642                 :            : 
     643                 :            :             // calculate data of visible page
     644         [ #  # ]:          0 :             PrevwPage* pPrevwPage = new PrevwPage;
     645                 :          0 :             _CalcPreviewDataForPage( *(pPage), aCurrPaintOffset, pPrevwPage );
     646                 :          0 :             pPrevwPage->bVisible = true;
     647         [ #  # ]:          0 :             maPrevwPages.push_back( pPrevwPage );
     648                 :            :         }
     649                 :            :         else
     650                 :            :         {
     651                 :            :             // calculate data of unvisible page needed for accessibility
     652         [ #  # ]:          0 :             PrevwPage* pPrevwPage = new PrevwPage;
     653                 :          0 :             _CalcPreviewDataForPage( *(pPage), aCurrPaintOffset, pPrevwPage );
     654                 :          0 :             pPrevwPage->bVisible = false;
     655         [ #  # ]:          0 :             maPrevwPages.push_back( pPrevwPage );
     656                 :            :         }
     657                 :            : 
     658                 :            :         // prepare data for next loop
     659                 :          0 :         pPage = static_cast<const SwPageFrm*>(pPage->GetNext());
     660                 :            : 
     661                 :          0 :         aCurrPaintOffset.X() += mnColWidth;
     662                 :          0 :         ++nCurrCol;
     663         [ #  # ]:          0 :         if ( nCurrCol > mnCols )
     664                 :            :         {
     665                 :          0 :             ++nConsideredRows;
     666                 :          0 :             aCurrPaintOffset.X() = aInitialPaintOffset.X();
     667                 :          0 :             nCurrCol = 1;
     668                 :          0 :             aCurrPaintOffset.Y() += mnRowHeight;
     669                 :            :         }
     670                 :            :     }
     671                 :            : }
     672                 :            : 
     673                 :            : /** determines preview data for a given page and a given preview offset
     674                 :            : 
     675                 :            :     OD 13.12.2002 #103492#
     676                 :            : 
     677                 :            :     @author OD
     678                 :            : */
     679                 :          0 : bool SwPagePreviewLayout::_CalcPreviewDataForPage( const SwPageFrm& _rPage,
     680                 :            :                                                    const Point& _rPrevwOffset,
     681                 :            :                                                    PrevwPage* _opPrevwPage )
     682                 :            : {
     683                 :            :     // page frame
     684                 :          0 :     _opPrevwPage->pPage = &_rPage;
     685                 :            :     // size of page frame
     686         [ #  # ]:          0 :     if ( _rPage.IsEmptyPage() )
     687                 :            :     {
     688         [ #  # ]:          0 :         if ( _rPage.GetPhyPageNum() % 2 == 0 )
     689                 :          0 :             _opPrevwPage->aPageSize = _rPage.GetPrev()->Frm().SSize();
     690                 :            :         else
     691                 :          0 :             _opPrevwPage->aPageSize = _rPage.GetNext()->Frm().SSize();
     692                 :            :     }
     693                 :            :     else
     694                 :          0 :         _opPrevwPage->aPageSize = _rPage.Frm().SSize();
     695                 :            :     // position of page in preview window
     696                 :          0 :     Point aPrevwWinOffset( _rPrevwOffset );
     697         [ #  # ]:          0 :     if ( _opPrevwPage->aPageSize.Width() < maMaxPageSize.Width() )
     698                 :          0 :         aPrevwWinOffset.X() += ( maMaxPageSize.Width() - _opPrevwPage->aPageSize.Width() ) / 2;
     699         [ #  # ]:          0 :     if ( _opPrevwPage->aPageSize.Height() < maMaxPageSize.Height() )
     700                 :          0 :         aPrevwWinOffset.Y() += ( maMaxPageSize.Height() - _opPrevwPage->aPageSize.Height() ) / 2;
     701                 :          0 :     _opPrevwPage->aPrevwWinPos = aPrevwWinOffset;
     702                 :            :     // logic position of page and mapping offset for paint
     703         [ #  # ]:          0 :     if ( _rPage.IsEmptyPage() )
     704                 :            :     {
     705                 :          0 :         _opPrevwPage->aLogicPos = _opPrevwPage->aPrevwWinPos;
     706                 :          0 :         _opPrevwPage->aMapOffset = Point( 0, 0 );
     707                 :            :     }
     708                 :            :     else
     709                 :            :     {
     710                 :          0 :         _opPrevwPage->aLogicPos = _rPage.Frm().Pos();
     711                 :          0 :         _opPrevwPage->aMapOffset = _opPrevwPage->aPrevwWinPos - _opPrevwPage->aLogicPos;
     712                 :            :     }
     713                 :            : 
     714                 :          0 :     return true;
     715                 :            : }
     716                 :            : 
     717                 :            : /** enable/disable book preview
     718                 :            : 
     719                 :            :     OD 2004-03-04 #i18143#
     720                 :            : 
     721                 :            :     @author OD
     722                 :            : */
     723                 :          0 : bool SwPagePreviewLayout::SetBookPreviewMode( const bool _bEnableBookPreview,
     724                 :            :                                               sal_uInt16& _onStartPageNum,
     725                 :            :                                               Rectangle&  _orDocPreviewPaintRect )
     726                 :            : {
     727                 :          0 :     bool bRet = false;
     728                 :            : 
     729         [ #  # ]:          0 :     if ( mbBookPreview != _bEnableBookPreview)
     730                 :            :     {
     731                 :          0 :         mbBookPreview = _bEnableBookPreview;
     732                 :            :         // re-initialize page preview layout
     733                 :          0 :         ReInit();
     734                 :            :         // re-prepare page preview layout
     735                 :            :         {
     736                 :          0 :             mbBookPreviewModeToggled = true;
     737                 :          0 :             Point aProposedStartPos( maPaintPreviewDocOffset );
     738                 :            :             // if proposed start position is below virtual preview document
     739                 :            :             // bottom, adjust it to the virtual preview document bottom
     740         [ #  # ]:          0 :             if ( aProposedStartPos.Y() > maPreviewDocRect.Bottom() )
     741                 :            :             {
     742                 :          0 :                 aProposedStartPos.Y() = maPreviewDocRect.Bottom();
     743                 :            :             }
     744                 :            :             Prepare( 0, aProposedStartPos,
     745                 :          0 :                      mrParentViewShell.GetOut()->LogicToPixel( maWinSize ),
     746 [ #  # ][ #  # ]:          0 :                      _onStartPageNum, _orDocPreviewPaintRect );
     747                 :          0 :             mbBookPreviewModeToggled = false;
     748                 :            :         }
     749                 :            : 
     750                 :          0 :         bRet = true;
     751                 :            :     }
     752                 :            : 
     753                 :          0 :     return bRet;
     754                 :            : }
     755                 :            : 
     756                 :            : // =============================================================================
     757                 :            : // methods to determine new data for changing the current shown part of the
     758                 :            : // document preview.
     759                 :            : // =============================================================================
     760                 :            : /** calculate start position for new scale
     761                 :            : 
     762                 :            :     OD 12.12.2002 #103492#
     763                 :            : 
     764                 :            :     @author OD
     765                 :            : */
     766                 :          0 : Point SwPagePreviewLayout::GetPreviewStartPosForNewScale(
     767                 :            :                           const Fraction& _aNewScale,
     768                 :            :                           const Fraction& _aOldScale,
     769                 :            :                           const Size&     _aNewWinSize ) const
     770                 :            : {
     771                 :          0 :     Point aNewPaintStartPos = maPaintedPrevwDocRect.TopLeft();
     772         [ #  # ]:          0 :     if ( _aNewScale < _aOldScale )
     773                 :            :     {
     774                 :            :         // increase paint width by moving start point to left.
     775         [ #  # ]:          0 :         if ( mnPrevwLayoutWidth < _aNewWinSize.Width() )
     776                 :          0 :             aNewPaintStartPos.X() = 0;
     777         [ #  # ]:          0 :         else if ( maPaintedPrevwDocRect.GetWidth() < _aNewWinSize.Width() )
     778                 :            :         {
     779                 :          0 :             aNewPaintStartPos.X() -=
     780                 :          0 :                 (_aNewWinSize.Width() - maPaintedPrevwDocRect.GetWidth()) / 2;
     781         [ #  # ]:          0 :             if ( aNewPaintStartPos.X() < 0)
     782                 :          0 :                 aNewPaintStartPos.X() = 0;
     783                 :            :         }
     784                 :            : 
     785         [ #  # ]:          0 :         if ( !mbDoesLayoutRowsFitIntoWindow )
     786                 :            :         {
     787                 :            :             // increase paint height by moving start point to top.
     788         [ #  # ]:          0 :             if ( mnPrevwLayoutHeight < _aNewWinSize.Height() )
     789                 :            :             {
     790                 :          0 :                 aNewPaintStartPos.Y() =
     791                 :          0 :                     ( (mnPaintStartRow - 1) * mnRowHeight );
     792                 :            :             }
     793         [ #  # ]:          0 :             else if ( maPaintedPrevwDocRect.GetHeight() < _aNewWinSize.Height() )
     794                 :            :             {
     795                 :          0 :                 aNewPaintStartPos.Y() -=
     796                 :          0 :                     (_aNewWinSize.Height() - maPaintedPrevwDocRect.GetHeight()) / 2;
     797         [ #  # ]:          0 :                 if ( aNewPaintStartPos.Y() < 0)
     798                 :          0 :                     aNewPaintStartPos.Y() = 0;
     799                 :            :             }
     800                 :            :         }
     801                 :            :     }
     802                 :            :     else
     803                 :            :     {
     804                 :            :         // decrease paint width by moving start point to right
     805         [ #  # ]:          0 :         if ( maPaintedPrevwDocRect.GetWidth() > _aNewWinSize.Width() )
     806                 :          0 :             aNewPaintStartPos.X() +=
     807                 :          0 :                 (maPaintedPrevwDocRect.GetWidth() - _aNewWinSize.Width()) / 2;
     808                 :            :         // decrease paint height by moving start point to bottom
     809         [ #  # ]:          0 :         if ( maPaintedPrevwDocRect.GetHeight() > _aNewWinSize.Height() )
     810                 :            :         {
     811                 :          0 :             aNewPaintStartPos.Y() +=
     812                 :          0 :                 (maPaintedPrevwDocRect.GetHeight() - _aNewWinSize.Height()) / 2;
     813                 :            :             // check, if new y-position is outside document preview
     814         [ #  # ]:          0 :             if ( aNewPaintStartPos.Y() > maPreviewDocRect.Bottom() )
     815                 :          0 :                 aNewPaintStartPos.Y() =
     816                 :          0 :                         Max( 0L, maPreviewDocRect.Bottom() - mnPrevwLayoutHeight );
     817                 :            :         }
     818                 :            :     }
     819                 :            : 
     820                 :          0 :     return aNewPaintStartPos;
     821                 :            : }
     822                 :            : 
     823                 :            : /** determines, if page with given page number is visible in preview
     824                 :            : 
     825                 :            :     @author OD, _nPageNum is absolut!
     826                 :            : */
     827                 :          0 : bool SwPagePreviewLayout::IsPageVisible( const sal_uInt16 _nPageNum ) const
     828                 :            : {
     829                 :          0 :     const PrevwPage* pPrevwPage = _GetPrevwPageByPageNum( _nPageNum );
     830 [ #  # ][ #  # ]:          0 :     return pPrevwPage && pPrevwPage->bVisible;
     831                 :            : }
     832                 :            : 
     833                 :            : /** calculate data to bring new selected page into view.
     834                 :            : 
     835                 :            :     @author OD, IN/OUT parameters are absolute page numbers!!!
     836                 :            : */
     837                 :          0 : bool SwPagePreviewLayout::CalcStartValuesForSelectedPageMove(
     838                 :            :                                 const sal_Int16  _nHoriMove,
     839                 :            :                                 const sal_Int16  _nVertMove,
     840                 :            :                                 sal_uInt16&      _orNewSelectedPage,
     841                 :            :                                 sal_uInt16&      _orNewStartPage,
     842                 :            :                                 Point&           _orNewStartPos ) const
     843                 :            : {
     844                 :            :     // determine position of current selected page
     845                 :          0 :     sal_uInt16 nTmpRelSelPageNum = ConvertAbsoluteToRelativePageNum( mnSelectedPageNum );
     846                 :          0 :     sal_uInt16 nNewRelSelectedPageNum = nTmpRelSelPageNum;
     847                 :            : 
     848                 :            :     // leaving left-top-corner blank is controlled
     849                 :            :     // by <mbBookPreview>.
     850         [ #  # ]:          0 :     if ( mbBookPreview )
     851                 :            :     {
     852                 :            :         // Note: consider that left-top-corner is left blank --> +1
     853                 :          0 :         ++nTmpRelSelPageNum;
     854                 :            :     }
     855                 :          0 :     sal_uInt16 nTmpCol = nTmpRelSelPageNum % mnCols;
     856                 :          0 :     sal_uInt16 nCurrRow = nTmpRelSelPageNum / mnCols;
     857         [ #  # ]:          0 :     if ( nTmpCol > 0 )
     858                 :          0 :         ++nCurrRow;
     859                 :            : 
     860                 :            :     // determine new selected page number
     861                 :            :     {
     862         [ #  # ]:          0 :         if ( _nHoriMove != 0 )
     863                 :            :         {
     864         [ #  # ]:          0 :             if ( (nNewRelSelectedPageNum + _nHoriMove) < 1 )
     865                 :          0 :                 nNewRelSelectedPageNum = 1;
     866         [ #  # ]:          0 :             else if ( (nNewRelSelectedPageNum + _nHoriMove) > mnPages )
     867                 :          0 :                 nNewRelSelectedPageNum = mnPages;
     868                 :            :             else
     869                 :          0 :                 nNewRelSelectedPageNum = nNewRelSelectedPageNum + _nHoriMove;
     870                 :            :         }
     871         [ #  # ]:          0 :         if ( _nVertMove != 0 )
     872                 :            :         {
     873         [ #  # ]:          0 :             if ( (nNewRelSelectedPageNum + (_nVertMove * mnCols)) < 1 )
     874                 :          0 :                 nNewRelSelectedPageNum = 1;
     875         [ #  # ]:          0 :             else if ( (nNewRelSelectedPageNum + (_nVertMove * mnCols)) > mnPages )
     876                 :          0 :                 nNewRelSelectedPageNum = mnPages;
     877                 :            :             else
     878                 :          0 :                 nNewRelSelectedPageNum += ( _nVertMove * mnCols );
     879                 :            :         }
     880                 :            :     }
     881                 :            : 
     882                 :          0 :     sal_uInt16 nNewStartPage = mnPaintPhyStartPageNum;
     883                 :          0 :     Point aNewStartPos = Point(0,0);
     884                 :            : 
     885                 :          0 :     sal_uInt16 nNewAbsSelectedPageNum = ConvertRelativeToAbsolutePageNum( nNewRelSelectedPageNum );
     886 [ #  # ][ #  # ]:          0 :     if ( !IsPageVisible( nNewAbsSelectedPageNum ) )
     887                 :            :     {
     888 [ #  # ][ #  # ]:          0 :         if ( _nHoriMove != 0 && _nVertMove != 0 )
     889                 :            :         {
     890                 :            :             OSL_FAIL( "missing implementation for moving preview selected page horizontal AND vertical");
     891                 :          0 :             return false;
     892                 :            :         }
     893                 :            : 
     894                 :            :         // new selected page has to be brought into view considering current
     895                 :            :         // visible preview.
     896                 :          0 :         sal_Int16 nTotalRows = GetRowOfPage( mnPages );
     897 [ #  # ][ #  # ]:          0 :         if ( (_nHoriMove > 0 || _nVertMove > 0) &&
         [ #  # ][ #  # ]
                 [ #  # ]
     898                 :            :              mbDoesLayoutRowsFitIntoWindow &&
     899                 :            :              mbDoesLayoutColsFitIntoWindow &&
     900                 :            :              nCurrRow > nTotalRows - mnRows )
     901                 :            :         {
     902                 :            :             // new proposed start page = left-top-corner of last possible
     903                 :            :             // preview page.
     904                 :          0 :             nNewStartPage = (nTotalRows - mnRows) * mnCols + 1;
     905                 :            :             // leaving left-top-corner blank is controlled
     906                 :            :             // by <mbBookPreview>.
     907         [ #  # ]:          0 :             if ( mbBookPreview )
     908                 :            :             {
     909                 :            :                 // Note: decrease new proposed start page number by one,
     910                 :            :                 // because of blank left-top-corner
     911                 :          0 :                 --nNewStartPage;
     912                 :            :             }
     913                 :          0 :             nNewStartPage = ConvertRelativeToAbsolutePageNum( nNewStartPage );
     914                 :            :         }
     915                 :            :         else
     916                 :            :         {
     917                 :            :             // new proposed start page = new selected page.
     918                 :          0 :             nNewStartPage = ConvertRelativeToAbsolutePageNum( nNewRelSelectedPageNum );
     919                 :            :         }
     920                 :            :     }
     921                 :            : 
     922                 :          0 :     _orNewSelectedPage = nNewAbsSelectedPageNum;
     923                 :          0 :     _orNewStartPage = nNewStartPage;
     924                 :          0 :     _orNewStartPos = aNewStartPos;
     925                 :            : 
     926                 :          0 :     return true;
     927                 :            : }
     928                 :            : 
     929                 :            : /** checks, if given position is inside a shown document page
     930                 :            : 
     931                 :            :     @author OD
     932                 :            : */
     933                 :            : struct PrevwPosInsidePagePred
     934                 :            : {
     935                 :            :     const Point mnPrevwPos;
     936                 :          0 :     PrevwPosInsidePagePred( const Point _nPrevwPos ) : mnPrevwPos( _nPrevwPos ) {};
     937                 :          0 :     bool operator() ( const PrevwPage* _pPrevwPage )
     938                 :            :     {
     939         [ #  # ]:          0 :         if ( _pPrevwPage->bVisible )
     940                 :            :         {
     941         [ #  # ]:          0 :             Rectangle aPrevwPageRect( _pPrevwPage->aPrevwWinPos, _pPrevwPage->aPageSize );
     942         [ #  # ]:          0 :             return aPrevwPageRect.IsInside( mnPrevwPos ) ? true : false;
     943                 :            :         }
     944                 :            :         else
     945                 :          0 :             return false;
     946                 :            :     }
     947                 :            : };
     948                 :            : 
     949                 :          0 : bool SwPagePreviewLayout::IsPrevwPosInDocPrevwPage( const Point  _aPrevwPos,
     950                 :            :                                                     Point&       _orDocPos,
     951                 :            :                                                     bool&        _obPosInEmptyPage,
     952                 :            :                                                     sal_uInt16&  _onPageNum ) const
     953                 :            : {
     954                 :            :     bool bIsPosInsideDoc;
     955                 :            : 
     956                 :            :     // initialize variable parameter values.
     957                 :          0 :     _orDocPos.X() = 0;
     958                 :          0 :     _orDocPos.Y() = 0;
     959                 :          0 :     _obPosInEmptyPage = false;
     960                 :          0 :     _onPageNum = 0;
     961                 :            : 
     962                 :            :     std::vector<PrevwPage*>::const_iterator aFoundPrevwPageIter =
     963                 :            :             std::find_if( maPrevwPages.begin(), maPrevwPages.end(),
     964         [ #  # ]:          0 :                           PrevwPosInsidePagePred( _aPrevwPos ) );
     965                 :            : 
     966 [ #  # ][ #  # ]:          0 :     if ( aFoundPrevwPageIter == maPrevwPages.end() )
     967                 :            :         // given preview position outside a document page.
     968                 :          0 :         bIsPosInsideDoc = false;
     969                 :            :     else
     970                 :            :     {
     971                 :          0 :         _onPageNum = (*aFoundPrevwPageIter)->pPage->GetPhyPageNum();
     972         [ #  # ]:          0 :         if ( (*aFoundPrevwPageIter)->pPage->IsEmptyPage() )
     973                 :            :         {
     974                 :            :             // given preview position inside an empty page
     975                 :          0 :             bIsPosInsideDoc = false;
     976                 :          0 :             _obPosInEmptyPage = true;
     977                 :            :         }
     978                 :            :         else
     979                 :            :         {
     980                 :            :             // given preview position inside a normal page
     981                 :          0 :             bIsPosInsideDoc = true;
     982                 :            :             _orDocPos = _aPrevwPos -
     983                 :          0 :                         (*aFoundPrevwPageIter)->aPrevwWinPos +
     984                 :          0 :                         (*aFoundPrevwPageIter)->aLogicPos;
     985                 :            :         }
     986                 :            :     }
     987                 :            : 
     988                 :          0 :     return bIsPosInsideDoc;
     989                 :            : }
     990                 :            : 
     991                 :            : /** determine window page scroll amount
     992                 :            : 
     993                 :            :     @author OD
     994                 :            : */
     995                 :          0 : SwTwips SwPagePreviewLayout::GetWinPagesScrollAmount(
     996                 :            :                                 const sal_Int16 _nWinPagesToScroll ) const
     997                 :            : {
     998                 :            :     SwTwips nScrollAmount;
     999         [ #  # ]:          0 :     if ( mbDoesLayoutRowsFitIntoWindow )
    1000                 :            :     {
    1001                 :          0 :         nScrollAmount = (mnPrevwLayoutHeight - mnYFree) * _nWinPagesToScroll;
    1002                 :            :     }
    1003                 :            :     else
    1004                 :          0 :         nScrollAmount = _nWinPagesToScroll * maPaintedPrevwDocRect.GetHeight();
    1005                 :            : 
    1006                 :            :     // check, if preview layout size values are valid.
    1007                 :            :     // If not, the checks for an adjustment of the scroll amount aren't useful.
    1008         [ #  # ]:          0 :     if ( mbLayoutSizesValid )
    1009                 :            :     {
    1010         [ #  # ]:          0 :         if ( (maPaintedPrevwDocRect.Top() + nScrollAmount) <= 0 )
    1011                 :          0 :             nScrollAmount = -maPaintedPrevwDocRect.Top();
    1012                 :            : 
    1013                 :            :         // correct scroll amount
    1014   [ #  #  #  # ]:          0 :         if ( nScrollAmount > 0 &&
                 [ #  # ]
    1015                 :          0 :              maPaintedPrevwDocRect.Bottom() == maPreviewDocRect.Bottom()
    1016                 :            :            )
    1017                 :            :         {
    1018                 :          0 :             nScrollAmount = 0;
    1019                 :            :         }
    1020                 :            :         else
    1021                 :            :         {
    1022         [ #  # ]:          0 :             while ( (maPaintedPrevwDocRect.Top() + nScrollAmount + mnYFree) >= maPreviewDocRect.GetHeight() )
    1023                 :            :             {
    1024                 :          0 :                 nScrollAmount -= mnRowHeight;
    1025                 :            :             }
    1026                 :            :         }
    1027                 :            :     }
    1028                 :            : 
    1029                 :          0 :     return nScrollAmount;
    1030                 :            : }
    1031                 :            : 
    1032                 :            : // =============================================================================
    1033                 :            : // methods to paint page preview layout
    1034                 :            : // =============================================================================
    1035                 :            : /** paint prepared preview
    1036                 :            : 
    1037                 :            :     OD 12.12.2002 #103492#
    1038                 :            : 
    1039                 :            :     @author OD
    1040                 :            : */
    1041                 :          0 : bool SwPagePreviewLayout::Paint( const Rectangle  _aOutRect ) const
    1042                 :            : {
    1043                 :            :     // check environment and parameters
    1044                 :            :     {
    1045   [ #  #  #  # ]:          0 :         if ( !mrParentViewShell.GetWin() &&
                 [ #  # ]
    1046                 :          0 :              !mrParentViewShell.GetOut()->GetConnectMetaFile() )
    1047                 :          0 :             return false;
    1048                 :            : 
    1049                 :            :         OSL_ENSURE( mbPaintInfoValid,
    1050                 :            :                 "invalid preview settings - no paint of preview" );
    1051         [ #  # ]:          0 :         if ( !mbPaintInfoValid )
    1052                 :          0 :             return false;
    1053                 :            :     }
    1054                 :            : 
    1055                 :            :     // OD 17.11.2003 #i22014# - no paint, if <superfluous> flag is set at layout
    1056         [ #  # ]:          0 :     if ( mrLayoutRootFrm.IsSuperfluous() )
    1057                 :            :     {
    1058                 :          0 :         return true;
    1059                 :            :     }
    1060                 :            : 
    1061                 :            :     // environment and parameter ok
    1062                 :            : 
    1063                 :            :     // OD 07.11.2003 #i22014#
    1064         [ #  # ]:          0 :     if ( mbInPaint )
    1065                 :            :     {
    1066                 :          0 :         return false;
    1067                 :            :     }
    1068                 :          0 :     mbInPaint = true;
    1069                 :            : 
    1070                 :          0 :     OutputDevice* pOutputDev = mrParentViewShell.GetOut();
    1071                 :            : 
    1072                 :            :     // prepare paint
    1073         [ #  # ]:          0 :     if ( maPrevwPages.size() > 0 )
    1074                 :            :     {
    1075                 :          0 :         mrParentViewShell.Imp()->bFirstPageInvalid = sal_False;
    1076                 :          0 :         mrParentViewShell.Imp()->pFirstVisPage =
    1077                 :          0 :                 const_cast<SwPageFrm*>(maPrevwPages[0]->pPage);
    1078                 :            :     }
    1079                 :            : 
    1080                 :            :     // paint preview background
    1081                 :            :     {
    1082 [ #  # ][ #  # ]:          0 :         SwRegionRects aPreviewBackgrdRegion( _aOutRect );
    1083                 :            :         // calculate preview background rectangles
    1084 [ #  # ][ #  # ]:          0 :         for ( std::vector<PrevwPage*>::const_iterator aPageIter = maPrevwPages.begin();
    1085                 :          0 :               aPageIter != maPrevwPages.end();
    1086                 :            :               ++aPageIter )
    1087                 :            :         {
    1088         [ #  # ]:          0 :             if ( (*aPageIter)->bVisible )
    1089                 :            :             {
    1090                 :            :                 aPreviewBackgrdRegion -=
    1091         [ #  # ]:          0 :                         SwRect( (*aPageIter)->aPrevwWinPos, (*aPageIter)->aPageSize );
    1092                 :            :             }
    1093                 :            :         }
    1094                 :            :         // paint preview background rectangles
    1095         [ #  # ]:          0 :         mrParentViewShell._PaintDesktop( aPreviewBackgrdRegion );
    1096                 :            :     }
    1097                 :            : 
    1098                 :            :     // prepare data for paint of pages
    1099         [ #  # ]:          0 :     const Rectangle aPxOutRect( pOutputDev->LogicToPixel( _aOutRect ) );
    1100                 :            : 
    1101         [ #  # ]:          0 :     MapMode aMapMode( pOutputDev->GetMapMode() );
    1102         [ #  # ]:          0 :     MapMode aSavedMapMode = aMapMode;
    1103                 :            : 
    1104         [ #  # ]:          0 :     const Font& rEmptyPgFont = SwPageFrm::GetEmptyPageFont();
    1105                 :            : 
    1106 [ #  # ][ #  # ]:          0 :     for ( std::vector<PrevwPage*>::const_iterator aPageIter = maPrevwPages.begin();
    1107                 :          0 :           aPageIter != maPrevwPages.end();
    1108                 :            :           ++aPageIter )
    1109                 :            :     {
    1110         [ #  # ]:          0 :         if ( !(*aPageIter)->bVisible )
    1111                 :          0 :             continue;
    1112                 :            : 
    1113         [ #  # ]:          0 :         Rectangle aPageRect( (*aPageIter)->aLogicPos, (*aPageIter)->aPageSize );
    1114         [ #  # ]:          0 :         aMapMode.SetOrigin( (*aPageIter)->aMapOffset );
    1115         [ #  # ]:          0 :         pOutputDev->SetMapMode( aMapMode );
    1116         [ #  # ]:          0 :         Rectangle aPxPaintRect = pOutputDev->LogicToPixel( aPageRect );
    1117 [ #  # ][ #  # ]:          0 :         if ( aPxOutRect.IsOver( aPxPaintRect) )
    1118                 :            :         {
    1119         [ #  # ]:          0 :             if ( (*aPageIter)->pPage->IsEmptyPage() )
    1120                 :            :             {
    1121         [ #  # ]:          0 :                 const Color aRetouche( mrParentViewShell.Imp()->GetRetoucheColor() );
    1122         [ #  # ]:          0 :                 if( pOutputDev->GetFillColor() != aRetouche )
    1123         [ #  # ]:          0 :                     pOutputDev->SetFillColor( aRetouche );
    1124         [ #  # ]:          0 :                 pOutputDev->SetLineColor(); // OD 20.02.2003 #107369# - no line color
    1125                 :            :                 // OD 20.02.2003 #107369# - use aligned page rectangle
    1126                 :            :                 {
    1127         [ #  # ]:          0 :                     SwRect aTmpPageRect( aPageRect );
    1128         [ #  # ]:          0 :                     ::SwAlignRect( aTmpPageRect, &mrParentViewShell);
    1129         [ #  # ]:          0 :                     aPageRect = aTmpPageRect.SVRect();
    1130                 :            :                 }
    1131         [ #  # ]:          0 :                 pOutputDev->DrawRect( aPageRect );
    1132                 :            : 
    1133                 :            :                 // paint empty page text
    1134         [ #  # ]:          0 :                 Font aOldFont( pOutputDev->GetFont() );
    1135         [ #  # ]:          0 :                 pOutputDev->SetFont( rEmptyPgFont );
    1136                 :            :                 pOutputDev->DrawText( aPageRect, SW_RESSTR( STR_EMPTYPAGE ),
    1137                 :            :                                     TEXT_DRAW_VCENTER |
    1138                 :            :                                     TEXT_DRAW_CENTER |
    1139 [ #  # ][ #  # ]:          0 :                                     TEXT_DRAW_CLIP );
         [ #  # ][ #  # ]
    1140         [ #  # ]:          0 :                 pOutputDev->SetFont( aOldFont );
    1141                 :            :                 // paint shadow and border for empty page
    1142                 :            :                 // OD 19.02.2003 #107369# - use new method to paint page border and shadow
    1143 [ #  # ][ #  # ]:          0 :                 SwPageFrm::PaintBorderAndShadow( aPageRect, &mrParentViewShell, true, false, true );
                 [ #  # ]
    1144                 :            :             }
    1145                 :            :             else
    1146                 :            :             {
    1147         [ #  # ]:          0 :                 mrParentViewShell.aVisArea = aPageRect;
    1148         [ #  # ]:          0 :                 aPxPaintRect.Intersection( aPxOutRect );
    1149         [ #  # ]:          0 :                 Rectangle aPaintRect = pOutputDev->PixelToLogic( aPxPaintRect );
    1150         [ #  # ]:          0 :                 mrParentViewShell.Paint( aPaintRect );
    1151                 :            :                 // --> OD 2007-08-15 #i80691#
    1152                 :            :                 // paint page border and shadow
    1153                 :            :                 {
    1154                 :          0 :                     SwRect aPageBorderRect;
    1155                 :            :                     SwPageFrm::GetBorderAndShadowBoundRect( SwRect( aPageRect ), &mrParentViewShell, aPageBorderRect,
    1156 [ #  # ][ #  # ]:          0 :                         (*aPageIter)->pPage->IsLeftShadowNeeded(), (*aPageIter)->pPage->IsRightShadowNeeded(), true );
         [ #  # ][ #  # ]
    1157 [ #  # ][ #  # ]:          0 :                     const Region aDLRegion(aPageBorderRect.SVRect());
    1158         [ #  # ]:          0 :                     mrParentViewShell.DLPrePaint2(aDLRegion);
    1159 [ #  # ][ #  # ]:          0 :                     SwPageFrm::PaintBorderAndShadow( aPageRect, &mrParentViewShell, true, false, true );
    1160 [ #  # ][ #  # ]:          0 :                     mrParentViewShell.DLPostPaint2(true);
    1161                 :            :                 }
    1162                 :            :                 // <--
    1163                 :            :             }
    1164                 :            :             // OD 07.11.2003 #i22014# - stop painting, because new print
    1165                 :            :             // preview layout is created during paint.
    1166         [ #  # ]:          0 :             if ( mbNewLayoutDuringPaint )
    1167                 :            :             {
    1168                 :            :                 break;
    1169                 :            :             }
    1170                 :            : 
    1171         [ #  # ]:          0 :             if ( (*aPageIter)->pPage->GetPhyPageNum() == mnSelectedPageNum )
    1172                 :            :             {
    1173         [ #  # ]:          0 :                 _PaintSelectMarkAtPage( (*aPageIter) );
    1174                 :            :             }
    1175                 :            : 
    1176                 :            :         }
    1177                 :            :     }
    1178                 :            : 
    1179                 :            :     // OD 17.11.2003 #i22014# - no update of accessible preview, if a new
    1180                 :            :     // print preview layout is created during paint.
    1181         [ #  # ]:          0 :     if ( !mbNewLayoutDuringPaint )
    1182                 :            :     {
    1183                 :            :         // update at accessiblilty interface
    1184                 :            :         mrParentViewShell.Imp()->UpdateAccessiblePreview(
    1185                 :            :                         maPrevwPages,
    1186                 :          0 :                         aMapMode.GetScaleX(),
    1187         [ #  # ]:          0 :                         mrLayoutRootFrm.GetPageByPageNum( mnSelectedPageNum ),
    1188         [ #  # ]:          0 :                         maWinSize );
    1189                 :            :     }
    1190                 :            : 
    1191         [ #  # ]:          0 :     pOutputDev->SetMapMode( aSavedMapMode );
    1192                 :          0 :     mrParentViewShell.aVisArea.Clear();
    1193                 :            : 
    1194                 :            :     // OD 07.11.2003 #i22014#
    1195                 :          0 :     mbInPaint = false;
    1196                 :          0 :     mbNewLayoutDuringPaint = false;
    1197                 :            : 
    1198 [ #  # ][ #  # ]:          0 :     return true;
    1199                 :            : }
    1200                 :            : 
    1201                 :            : /** repaint pages on page preview
    1202                 :            : 
    1203                 :            :     OD 18.12.2002 #103492#
    1204                 :            : 
    1205                 :            :     @author OD
    1206                 :            : */
    1207                 :          0 : void SwPagePreviewLayout::Repaint( const Rectangle _aInvalidCoreRect ) const
    1208                 :            : {
    1209                 :            :     // check environment and parameters
    1210                 :            :     {
    1211   [ #  #  #  # ]:          0 :         if ( !mrParentViewShell.GetWin() &&
                 [ #  # ]
    1212                 :          0 :              !mrParentViewShell.GetOut()->GetConnectMetaFile() )
    1213                 :          0 :             return;
    1214                 :            : 
    1215                 :            :         OSL_ENSURE( mbPaintInfoValid,
    1216                 :            :                 "invalid preview settings - no paint of preview" );
    1217         [ #  # ]:          0 :         if ( !mbPaintInfoValid )
    1218                 :          0 :             return;
    1219                 :            :     }
    1220                 :            : 
    1221                 :            :     // environment and parameter ok
    1222                 :            : 
    1223                 :            :     // prepare paint
    1224         [ #  # ]:          0 :     if ( maPrevwPages.size() > 0 )
    1225                 :            :     {
    1226                 :          0 :         mrParentViewShell.Imp()->bFirstPageInvalid = sal_False;
    1227                 :          0 :         mrParentViewShell.Imp()->pFirstVisPage =
    1228                 :          0 :                 const_cast<SwPageFrm*>(maPrevwPages[0]->pPage);
    1229                 :            :     }
    1230                 :            : 
    1231                 :            :     // invalidate visible pages, which overlap the invalid core rectangle
    1232 [ #  # ][ #  # ]:          0 :     for ( std::vector<PrevwPage*>::const_iterator aPageIter = maPrevwPages.begin();
    1233                 :          0 :           aPageIter != maPrevwPages.end();
    1234                 :            :           ++aPageIter )
    1235                 :            :     {
    1236         [ #  # ]:          0 :         if ( !(*aPageIter)->bVisible )
    1237                 :          0 :             continue;
    1238                 :            : 
    1239         [ #  # ]:          0 :         Rectangle aPageRect( (*aPageIter)->aLogicPos, (*aPageIter)->aPageSize );
    1240 [ #  # ][ #  # ]:          0 :         if ( _aInvalidCoreRect.IsOver( aPageRect ) )
    1241                 :            :         {
    1242         [ #  # ]:          0 :             aPageRect.Intersection( _aInvalidCoreRect );
    1243                 :          0 :             Rectangle aInvalidPrevwRect = aPageRect;
    1244                 :            :             aInvalidPrevwRect.SetPos( aInvalidPrevwRect.TopLeft() -
    1245                 :          0 :                                       (*aPageIter)->aLogicPos +
    1246                 :          0 :                                       (*aPageIter)->aPrevwWinPos );
    1247         [ #  # ]:          0 :             mrParentViewShell.GetWin()->Invalidate( aInvalidPrevwRect );
    1248                 :            :         }
    1249                 :            :     }
    1250                 :            : }
    1251                 :            : 
    1252                 :            : /** paint selection mark at page
    1253                 :            : 
    1254                 :            :     OD 17.12.2002 #103492#
    1255                 :            : 
    1256                 :            :     @author OD
    1257                 :            : */
    1258                 :          0 : void SwPagePreviewLayout::_PaintSelectMarkAtPage(
    1259                 :            :                                     const PrevwPage* _aSelectedPrevwPage ) const
    1260                 :            : {
    1261                 :          0 :     OutputDevice* pOutputDev = mrParentViewShell.GetOut();
    1262         [ #  # ]:          0 :     MapMode aMapMode( pOutputDev->GetMapMode() );
    1263                 :            :     // save mapping mode of output device
    1264         [ #  # ]:          0 :     MapMode aSavedMapMode = aMapMode;
    1265                 :            :     // save fill and line color of output device
    1266                 :          0 :     Color aFill( pOutputDev->GetFillColor() );
    1267                 :          0 :     Color aLine( pOutputDev->GetLineColor() );
    1268                 :            : 
    1269                 :            :     // determine selection mark color
    1270                 :          0 :     Color aSelPgLineColor(COL_LIGHTBLUE);
    1271                 :            :     const StyleSettings& rSettings =
    1272                 :          0 :         mrParentViewShell.GetWin()->GetSettings().GetStyleSettings();
    1273         [ #  # ]:          0 :     if ( rSettings.GetHighContrastMode() )
    1274                 :          0 :         aSelPgLineColor = rSettings.GetHighlightTextColor();
    1275                 :            : 
    1276                 :            :     // set needed mapping mode at output device
    1277         [ #  # ]:          0 :     aMapMode.SetOrigin( _aSelectedPrevwPage->aMapOffset );
    1278         [ #  # ]:          0 :     pOutputDev->SetMapMode( aMapMode );
    1279                 :            : 
    1280                 :            :     // calculate page rectangle in pixel coordinates
    1281                 :            :     SwRect aPageRect( _aSelectedPrevwPage->aLogicPos,
    1282                 :          0 :                          _aSelectedPrevwPage->aPageSize );
    1283                 :            :     // OD 19.02.2003 #107369# - use aligned page rectangle, as it is used for
    1284                 :            :     // page border and shadow paint - see <SwPageFrm::PaintBorderAndShadow(..)>
    1285         [ #  # ]:          0 :     ::SwAlignRect( aPageRect, &mrParentViewShell);
    1286 [ #  # ][ #  # ]:          0 :     Rectangle aPxPageRect = pOutputDev->LogicToPixel( aPageRect.SVRect() );
    1287                 :            : 
    1288                 :            :     // draw two rectangle
    1289                 :            :     // OD 19.02.2003 #107369# - adjust position of select mark rectangle
    1290                 :          0 :     Rectangle aRect( aPxPageRect.Left(), aPxPageRect.Top(),
    1291         [ #  # ]:          0 :                        aPxPageRect.Right(), aPxPageRect.Bottom() );
    1292         [ #  # ]:          0 :     aRect = pOutputDev->PixelToLogic( aRect );
    1293         [ #  # ]:          0 :     pOutputDev->SetFillColor(); // OD 20.02.2003 #107369# - no fill color
    1294         [ #  # ]:          0 :     pOutputDev->SetLineColor( aSelPgLineColor );
    1295         [ #  # ]:          0 :     pOutputDev->DrawRect( aRect );
    1296                 :            :     // OD 19.02.2003 #107369# - adjust position of select mark rectangle
    1297                 :          0 :     aRect = Rectangle( aPxPageRect.Left()+1, aPxPageRect.Top()+1,
    1298         [ #  # ]:          0 :                        aPxPageRect.Right()-1, aPxPageRect.Bottom()-1 );
    1299         [ #  # ]:          0 :     aRect = pOutputDev->PixelToLogic( aRect );
    1300         [ #  # ]:          0 :     pOutputDev->DrawRect( aRect );
    1301                 :            : 
    1302                 :            :     // reset fill and line color of output device
    1303         [ #  # ]:          0 :     pOutputDev->SetFillColor( aFill );
    1304         [ #  # ]:          0 :     pOutputDev->SetLineColor( aLine );
    1305                 :            : 
    1306                 :            :     // reset mapping mode of output device
    1307 [ #  # ][ #  # ]:          0 :     pOutputDev->SetMapMode( aSavedMapMode );
                 [ #  # ]
    1308                 :          0 : }
    1309                 :            : 
    1310                 :            : /** paint to mark new selected page
    1311                 :            : 
    1312                 :            :     OD 17.12.2002 #103492#
    1313                 :            :     Perform paint for current selected page in order to unmark it.
    1314                 :            :     Set new selected page and perform paint to mark this page.
    1315                 :            : 
    1316                 :            :     @author OD, _nSelectedPage, mnSelectedPage are absolut
    1317                 :            : */
    1318                 :          0 : void SwPagePreviewLayout::MarkNewSelectedPage( const sal_uInt16 _nSelectedPage )
    1319                 :            : {
    1320                 :          0 :     sal_uInt16 nOldSelectedPageNum = mnSelectedPageNum;
    1321                 :          0 :     mnSelectedPageNum = _nSelectedPage;
    1322                 :            : 
    1323                 :            :     // re-paint for current selected page in order to umark it.
    1324                 :          0 :     const PrevwPage* pOldSelectedPrevwPage = _GetPrevwPageByPageNum( nOldSelectedPageNum );
    1325 [ #  # ][ #  # ]:          0 :     if ( pOldSelectedPrevwPage && pOldSelectedPrevwPage->bVisible )
    1326                 :            :     {
    1327                 :            :         // OD 20.02.2003 #107369# - invalidate only areas of selection mark.
    1328                 :            :         SwRect aPageRect( pOldSelectedPrevwPage->aPrevwWinPos,
    1329                 :          0 :                               pOldSelectedPrevwPage->aPageSize );
    1330         [ #  # ]:          0 :         ::SwAlignRect( aPageRect, &mrParentViewShell);
    1331                 :          0 :         OutputDevice* pOutputDev = mrParentViewShell.GetOut();
    1332 [ #  # ][ #  # ]:          0 :         Rectangle aPxPageRect = pOutputDev->LogicToPixel( aPageRect.SVRect() );
    1333                 :            :         // invalidate top mark line
    1334                 :          0 :         Rectangle aInvalPxRect( aPxPageRect.Left(), aPxPageRect.Top(),
    1335         [ #  # ]:          0 :                                 aPxPageRect.Right(), aPxPageRect.Top()+1 );
    1336 [ #  # ][ #  # ]:          0 :         mrParentViewShell.GetWin()->Invalidate( pOutputDev->PixelToLogic( aInvalPxRect ) );
    1337                 :            :         // invalidate right mark line
    1338                 :          0 :         aInvalPxRect = Rectangle( aPxPageRect.Right()-1, aPxPageRect.Top(),
    1339         [ #  # ]:          0 :                                   aPxPageRect.Right(), aPxPageRect.Bottom() );
    1340 [ #  # ][ #  # ]:          0 :         mrParentViewShell.GetWin()->Invalidate( pOutputDev->PixelToLogic( aInvalPxRect ) );
    1341                 :            :         // invalidate bottom mark line
    1342                 :          0 :         aInvalPxRect = Rectangle( aPxPageRect.Left(), aPxPageRect.Bottom()-1,
    1343         [ #  # ]:          0 :                                   aPxPageRect.Right(), aPxPageRect.Bottom() );
    1344 [ #  # ][ #  # ]:          0 :         mrParentViewShell.GetWin()->Invalidate( pOutputDev->PixelToLogic( aInvalPxRect ) );
    1345                 :            :         // invalidate left mark line
    1346                 :          0 :         aInvalPxRect = Rectangle( aPxPageRect.Left(), aPxPageRect.Top(),
    1347         [ #  # ]:          0 :                                   aPxPageRect.Left()+1, aPxPageRect.Bottom() );
    1348 [ #  # ][ #  # ]:          0 :         mrParentViewShell.GetWin()->Invalidate( pOutputDev->PixelToLogic( aInvalPxRect ) );
    1349                 :            :     }
    1350                 :            : 
    1351                 :            :     // re-paint for new selected page in order to mark it.
    1352                 :          0 :     const PrevwPage* pNewSelectedPrevwPage = _GetPrevwPageByPageNum( _nSelectedPage );
    1353 [ #  # ][ #  # ]:          0 :     if ( pNewSelectedPrevwPage && pNewSelectedPrevwPage->bVisible )
    1354                 :          0 :         _PaintSelectMarkAtPage( pNewSelectedPrevwPage );
    1355                 :          0 : }
    1356                 :            : 
    1357                 :            : 
    1358                 :            : // =============================================================================
    1359                 :            : // helper methods
    1360                 :            : // =============================================================================
    1361                 :            : /** get preview page by physical page number
    1362                 :            : 
    1363                 :            :     OD 17.12.2002 #103492#
    1364                 :            : 
    1365                 :            :     @author OD
    1366                 :            : */
    1367                 :            : struct EqualsPageNumPred
    1368                 :            : {
    1369                 :            :     const sal_uInt16 mnPageNum;
    1370                 :          0 :     EqualsPageNumPred( const sal_uInt16 _nPageNum ) : mnPageNum( _nPageNum ) {};
    1371                 :          0 :     bool operator() ( const PrevwPage* _pPrevwPage )
    1372                 :            :     {
    1373                 :          0 :         return _pPrevwPage->pPage->GetPhyPageNum() == mnPageNum;
    1374                 :            :     }
    1375                 :            : };
    1376                 :            : 
    1377                 :          0 : const PrevwPage* SwPagePreviewLayout::_GetPrevwPageByPageNum( const sal_uInt16 _nPageNum ) const
    1378                 :            : {
    1379                 :            :     std::vector<PrevwPage*>::const_iterator aFoundPrevwPageIter =
    1380                 :            :             std::find_if( maPrevwPages.begin(), maPrevwPages.end(),
    1381         [ #  # ]:          0 :                           EqualsPageNumPred( _nPageNum ) );
    1382                 :            : 
    1383 [ #  # ][ #  # ]:          0 :     if ( aFoundPrevwPageIter == maPrevwPages.end() )
    1384                 :          0 :         return 0;
    1385                 :            :     else
    1386                 :          0 :         return (*aFoundPrevwPageIter);
    1387                 :            : }
    1388                 :            : 
    1389                 :            : /** determine row the page with the given number is in
    1390                 :            : 
    1391                 :            :     OD 17.01.2003 #103492#
    1392                 :            : 
    1393                 :            :     @author OD, _nPageNum is relative
    1394                 :            : */
    1395                 :          0 : sal_uInt16 SwPagePreviewLayout::GetRowOfPage( sal_uInt16 _nPageNum ) const
    1396                 :            : {
    1397                 :            :     // OD 19.02.2003 #107369# - leaving left-top-corner blank is controlled
    1398                 :            :     // by <mbBookPreview>.
    1399         [ #  # ]:          0 :     if ( mbBookPreview )
    1400                 :            :     {
    1401                 :            :         // Note: increase given physical page number by one, because left-top-corner
    1402                 :            :         //       in the preview layout is left blank.
    1403                 :          0 :         ++_nPageNum;
    1404                 :            :     }
    1405                 :            : 
    1406                 :          0 :     sal_uInt16 nRow = (_nPageNum) / mnCols;
    1407         [ #  # ]:          0 :     if ( ( (_nPageNum) % mnCols ) > 0 )
    1408                 :          0 :         ++nRow;
    1409                 :            : 
    1410                 :          0 :     return nRow;
    1411                 :            : }
    1412                 :            : 
    1413                 :            : /** determine column the page with the given number is in
    1414                 :            : 
    1415                 :            :     OD 17.01.2003 #103492#
    1416                 :            : 
    1417                 :            :     @author OD, _nPageNum is relative
    1418                 :            : */
    1419                 :          0 : sal_uInt16 SwPagePreviewLayout::GetColOfPage( sal_uInt16 _nPageNum ) const
    1420                 :            : {
    1421                 :            :     // OD 19.02.2003 #107369# - leaving left-top-corner blank is controlled
    1422                 :            :     // by <mbBookPreview>.
    1423         [ #  # ]:          0 :     if ( mbBookPreview )
    1424                 :            :     {
    1425                 :            :         // Note: increase given physical page number by one, because left-top-corner
    1426                 :            :         //       in the preview layout is left blank.
    1427                 :          0 :         ++_nPageNum;
    1428                 :            :     }
    1429                 :            : 
    1430                 :          0 :     sal_uInt16 nCol = (_nPageNum) % mnCols;
    1431         [ #  # ]:          0 :     if ( nCol == 0 )
    1432                 :          0 :         nCol = mnCols;
    1433                 :            : 
    1434                 :          0 :     return nCol;
    1435                 :            : }
    1436                 :            : 
    1437                 :          0 : Size SwPagePreviewLayout::GetPrevwDocSize() const
    1438                 :            : {
    1439                 :            :     OSL_ENSURE( PreviewLayoutValid(), "PagePreviewLayout not valid" );
    1440                 :          0 :     return maPreviewDocRect.GetSize();
    1441                 :            : }
    1442                 :            : 
    1443                 :            : /** get size of a preview page by its physical page number
    1444                 :            : 
    1445                 :            :     OD 15.01.2003 #103492#
    1446                 :            : 
    1447                 :            :     @author OD
    1448                 :            : */
    1449                 :          0 : Size SwPagePreviewLayout::GetPrevwPageSizeByPageNum( sal_uInt16 _nPageNum ) const
    1450                 :            : {
    1451                 :          0 :     const PrevwPage* pPrevwPage = _GetPrevwPageByPageNum( _nPageNum );
    1452         [ #  # ]:          0 :     if ( pPrevwPage )
    1453                 :            :     {
    1454                 :          0 :         return pPrevwPage->aPageSize;
    1455                 :            :     }
    1456                 :            :     else
    1457                 :            :     {
    1458                 :          0 :         return Size( 0, 0 );
    1459                 :            :     }
    1460                 :            : }
    1461                 :            : 
    1462                 :            : /** get virtual page number by its physical page number
    1463                 :            : 
    1464                 :            :     OD 21.03.2003 #108282#
    1465                 :            : 
    1466                 :            :     @author OD
    1467                 :            : */
    1468                 :          0 : sal_uInt16 SwPagePreviewLayout::GetVirtPageNumByPageNum( sal_uInt16 _nPageNum ) const
    1469                 :            : {
    1470                 :          0 :     const PrevwPage* pPrevwPage = _GetPrevwPageByPageNum( _nPageNum );
    1471         [ #  # ]:          0 :     if ( pPrevwPage )
    1472                 :            :     {
    1473                 :          0 :         return pPrevwPage->pPage->GetVirtPageNum();
    1474                 :            :     }
    1475                 :            :     else
    1476                 :            :     {
    1477                 :          0 :         return 0;
    1478                 :            :     }
    1479                 :            : }
    1480                 :            : 
    1481                 :            : /** Convert absolute to relative page numbers (see PrintEmptyPages)
    1482                 :            : 
    1483                 :            :     @author FME
    1484                 :            : */
    1485                 :          0 : sal_uInt16 SwPagePreviewLayout::ConvertAbsoluteToRelativePageNum( sal_uInt16 _nAbsPageNum ) const
    1486                 :            : {
    1487 [ #  # ][ #  # ]:          0 :     if ( mbBookPreview || mbPrintEmptyPages || !_nAbsPageNum )
                 [ #  # ]
    1488                 :            :     {
    1489                 :          0 :         return _nAbsPageNum;
    1490                 :            :     }
    1491                 :            : 
    1492                 :          0 :     const SwPageFrm* pTmpPage = static_cast<const SwPageFrm*>(mrLayoutRootFrm.Lower());
    1493                 :            : 
    1494                 :          0 :     sal_uInt16 nRet = 1;
    1495                 :            : 
    1496 [ #  # ][ #  # ]:          0 :     while ( pTmpPage && pTmpPage->GetPhyPageNum() != _nAbsPageNum )
                 [ #  # ]
    1497                 :            :     {
    1498         [ #  # ]:          0 :         if ( !pTmpPage->IsEmptyPage() )
    1499                 :          0 :             ++nRet;
    1500                 :            : 
    1501                 :          0 :         pTmpPage = static_cast<const SwPageFrm*>( pTmpPage->GetNext() );
    1502                 :            :     }
    1503                 :            : 
    1504                 :          0 :     return nRet;
    1505                 :            : }
    1506                 :            : 
    1507                 :            : /** Convert relative to absolute page numbers (see PrintEmptyPages)
    1508                 :            : 
    1509                 :            :     @author FME
    1510                 :            : */
    1511                 :          0 : sal_uInt16 SwPagePreviewLayout::ConvertRelativeToAbsolutePageNum( sal_uInt16 _nRelPageNum ) const
    1512                 :            : {
    1513 [ #  # ][ #  # ]:          0 :     if ( mbBookPreview || mbPrintEmptyPages || !_nRelPageNum )
                 [ #  # ]
    1514                 :            :     {
    1515                 :          0 :         return _nRelPageNum;
    1516                 :            :     }
    1517                 :            : 
    1518                 :          0 :     const SwPageFrm* pTmpPage = static_cast<const SwPageFrm*>(mrLayoutRootFrm.Lower());
    1519                 :          0 :     const SwPageFrm* pRet = 0;
    1520                 :            : 
    1521                 :          0 :     sal_uInt16 i = 0;
    1522 [ #  # ][ #  # ]:          0 :     while( pTmpPage && i != _nRelPageNum )
                 [ #  # ]
    1523                 :            :     {
    1524         [ #  # ]:          0 :         if ( !pTmpPage->IsEmptyPage() )
    1525                 :          0 :             ++i;
    1526                 :            : 
    1527                 :          0 :         pRet = pTmpPage;
    1528                 :          0 :         pTmpPage = static_cast<const SwPageFrm*>( pTmpPage->GetNext() );
    1529                 :            :     }
    1530                 :            : 
    1531                 :          0 :     return pRet->GetPhyPageNum();
    1532                 :            : }
    1533                 :            : 
    1534                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10