LCOV - code coverage report
Current view: top level - sw/inc - pagepreviewlayout.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 15 0.0 %
Date: 2014-04-14 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_SW_INC_PAGEPREVIEWLAYOUT_HXX
      21             : #define INCLUDED_SW_INC_PAGEPREVIEWLAYOUT_HXX
      22             : 
      23             : // template class <std::vector>
      24             : #include <vector>
      25             : // datatypes sal_xyz
      26             : #include <sal/types.h>
      27             : // classes <Point>, <Size> and <Rectangle>
      28             : #include <tools/gen.hxx>
      29             : // datatype <SwTwips>
      30             : #include <swtypes.hxx>
      31             : 
      32             : class SwViewShell;
      33             : class SwRootFrm;
      34             : class SwPageFrm;
      35             : class Fraction;
      36             : struct PreviewPage;
      37             : 
      38             : /** page preview functionality in the writer
      39             : 
      40             :     @author OD
      41             : */
      42             : class SwPagePreviewLayout
      43             : {
      44             : private:
      45             :     friend class SwViewShell;
      46             : 
      47             :     /// number of horizontal and vertical twips for spacing between the pages.
      48             :     const SwTwips mnXFree;
      49             :     const SwTwips mnYFree;
      50             : 
      51             :     /// view shell the print preview is generated for.
      52             :     SwViewShell& mrParentViewShell;
      53             :     /// top layout frame of the layout for accessing the pages
      54             :     const SwRootFrm& mrLayoutRootFrm;
      55             : 
      56             :     /** boolean indicating, if the layout information (number of columns and rows)
      57             :        are valid. */
      58             :     bool        mbLayoutInfoValid;
      59             :     /** boolean indicating, if the calculated print preview layout sizes
      60             :        ( windows size in twips, maximal page size, column width, row height,
      61             :          width and height of a print preview page, size of the print preview
      62             :          document ) are valid */
      63             :     bool        mbLayoutSizesValid;
      64             :     /** boolean indicating, if the paint information ( physical number of
      65             :          start page, start column and row, paint offsets, rectangle visible of
      66             :          the print preview document. */
      67             :     bool        mbPaintInfoValid;
      68             : 
      69             :     Size        maWinSize;
      70             :     sal_uInt16  mnCols;
      71             :     sal_uInt16  mnRows;
      72             :     sal_uInt16  mnPages;
      73             :     // #i18143# - the book preview is controlled by this flag
      74             :     bool        mbBookPreview;
      75             :     bool        mbBookPreviewModeToggled;
      76             : 
      77             :     Size        maMaxPageSize;
      78             :     Rectangle   maPreviewDocRect;
      79             :     SwTwips     mnColWidth;
      80             :     SwTwips     mnRowHeight;
      81             :     SwTwips     mnPreviewLayoutWidth;
      82             :     SwTwips     mnPreviewLayoutHeight;
      83             :     bool        mbDoesLayoutColsFitIntoWindow;
      84             :     bool        mbDoesLayoutRowsFitIntoWindow;
      85             : 
      86             :     sal_uInt16  mnPaintPhyStartPageNum;
      87             :     sal_uInt16  mnPaintStartCol;
      88             :     sal_uInt16  mnPaintStartRow;
      89             :     bool        mbNoPageVisible;
      90             :     Point       maPaintStartPageOffset;
      91             :     Point       maPaintPreviewDocOffset;
      92             :     Point       maAdditionalPaintOffset;
      93             :     Rectangle   maPaintedPreviewDocRect;
      94             :     sal_uInt16  mnSelectedPageNum;
      95             : 
      96             :     std::vector<PreviewPage*> maPreviewPages;
      97             : 
      98             :     /** #i22014# - internal booleans to indicate, that a new print
      99             :        preview layout has been created during a paint. */
     100             :     mutable bool mbInPaint;
     101             :     mutable bool mbNewLayoutDuringPaint;
     102             : 
     103             :     bool mbPrintEmptyPages;
     104             : 
     105             :     /** clear internal data about current page preview
     106             : 
     107             :         @author OD
     108             :     */
     109             :     void _Clear();
     110             : 
     111             :     /** helper method to clear preview page layout sizes
     112             : 
     113             :         @author OD
     114             :     */
     115             :     void _ClearPreviewLayoutSizes();
     116             : 
     117             :     /** helper method to clear data in preview page vectors
     118             : 
     119             :         @author OD
     120             :     */
     121             :     void _ClearPreviewPageData();
     122             : 
     123             :     /** calculate page preview layout sizes
     124             : 
     125             :         @author OD
     126             :     */
     127             :     void _CalcPreviewLayoutSizes();
     128             : 
     129             :     /** apply new zoom at given view shell
     130             : 
     131             :         @author OD
     132             : 
     133             :         @param _aNewZoom
     134             :         input parameter - new zoom percentage
     135             :     */
     136             :     void _ApplyNewZoomAtViewShell( sal_uInt8 _aNewZoom );
     137             : 
     138             :     /** calculate additional paint offset
     139             : 
     140             :         helper method called by <Prepare> in order to calculate an additional
     141             :         paint offset to center output in given window size.
     142             :         The booleans <mbDoesLayoutRowsFitIntoWindow> and <mbDoesLayoutColsFitIntoWindow>
     143             :         are also determined.
     144             :         preconditions:
     145             :         (1) preview layout is given (number of rows and columns).
     146             :         (2) window size is given.
     147             :         (3) height of row and width of column are calculated.
     148             :         (4) paint offset of start page is calculated.
     149             : 
     150             :         @author OD
     151             :     */
     152             :     void _CalcAdditionalPaintOffset();
     153             : 
     154             :     /** calculate painted preview document rectangle
     155             : 
     156             :         helper method called by <Prepare> in order to calculate the rectangle,
     157             :         which will be painted for the document arranged by the given preview
     158             :         layout.
     159             :         preconditions:
     160             :         (1) paint offset of document preview is calculated.
     161             :         (2) size of document preview is calculated.
     162             :         (3) additional paint offset is calculated - see <_CalcAdditionalPaintOffset>.
     163             : 
     164             :         @author OD
     165             :     */
     166             :     void _CalcDocPreviewPaintRect();
     167             : 
     168             :     /** determines preview data for a given page and a given preview offset
     169             : 
     170             :         @author OD
     171             : 
     172             :         @param _rPage
     173             :         input parameter - constant reference to page frame, for which the
     174             :         preview data will be calculated.
     175             : 
     176             :         @param _rPreviewOffset
     177             :         input parameter - constant reference to the offset the given page has
     178             :         in the current preview window.
     179             :         Note: Offset can be negative.
     180             : 
     181             :         @param _opPreviewPage
     182             :         output parameter - calculated preview data.
     183             : 
     184             :         @return boolean, indicating, if calculation was successful.
     185             :     */
     186             :     bool _CalcPreviewDataForPage( const SwPageFrm& _rPage,
     187             :                                   const Point& _rPreviewOffset,
     188             :                                   PreviewPage* _opPreviewPage );
     189             : 
     190             :     /** calculate preview pages
     191             : 
     192             :         helper method called by <Prepare> in order to determine which pages
     193             :         will be visible in the current preview and calculate the data needed
     194             :         to paint these pages. Also the accessible pages with its needed data
     195             :         are determined.
     196             : 
     197             :         @author OD
     198             :     */
     199             :     void _CalcPreviewPages();
     200             : 
     201             :     /** get preview page by physical page number
     202             : 
     203             :         @author OD
     204             : 
     205             :         @param _nPageNum
     206             :         input parameter - physical page number of page, for which the preview
     207             :         page will be returned.
     208             : 
     209             :         @return pointer to preview page of current preview pages. If page doesn't
     210             :         belongs to current preview pages, <0> is returned.
     211             :     */
     212             :     const PreviewPage* _GetPreviewPageByPageNum( const sal_uInt16 _nPageNum ) const;
     213             : 
     214             :     /** paint selection mark at page
     215             : 
     216             :         @author OD
     217             :     */
     218             :     void _PaintSelectMarkAtPage( const PreviewPage* _aSelectedPreviewPage ) const;
     219             : 
     220             : public:
     221             :     /** constructor of <SwPagePreviewLayout>
     222             : 
     223             :         @author OD
     224             : 
     225             :         @param _rParentViewShell
     226             :         input parameter - reference to the view shell the page preview
     227             :         layout belongs to. Reference will be hold as member <mrParentViewShell>.
     228             :         Adjustments/Changes at this view shell:
     229             :         (1) Adjustment of the mapping mode at the output device.
     230             :         (2) Change of the zoom at the view options.
     231             :         (3) Preparations for paint of the page preview.
     232             : 
     233             :         @param _rLayoutRootFrm
     234             :         input parameter - constant reference to the root frame of the layout.
     235             :         Reference will be hold as member <mrLayoutRootFrm> in order to get
     236             :         access to the page frames.
     237             :     */
     238             :     SwPagePreviewLayout( SwViewShell& _rParentViewShell,
     239             :                          const SwRootFrm&    _rLayoutRootFrm );
     240             : 
     241             :     /** destructor of <SwPagePreviewLayout>
     242             : 
     243             :         @author
     244             :     */
     245           0 :     inline ~SwPagePreviewLayout()
     246           0 :     {
     247           0 :         _ClearPreviewPageData();
     248           0 :     }
     249             : 
     250             :     /** init page preview layout
     251             : 
     252             :         initialize the page preview settings for a given layout.
     253             :         side effects:
     254             :         (1) If parameter <_bCalcScale> is true, mapping mode with calculated
     255             :         scaling is set at the output device and the zoom at the view options of
     256             :         the given view shell is set with the calculated scaling.
     257             : 
     258             :         @author OD
     259             : 
     260             :         @param _nCols
     261             :         input parameter - initial number of page columns in the preview.
     262             : 
     263             :         @param _nRows
     264             :         input parameter - initial number of page rows in the preview.
     265             : 
     266             :         @param _rPxWinSize
     267             :         input parameter - window size in which the preview will be displayed and
     268             :         for which the scaling will be calculated.
     269             : 
     270             :         @param _bCalcScale
     271             :         input parameter - control, if method should calculate the needed
     272             :         scaling for the proposed preview layout for the given window size
     273             :         and sets the scaling at the output device and the view options.
     274             : 
     275             :         @return boolean, indicating, if preview layout is successful initialized.
     276             :     */
     277             :     bool Init( const sal_uInt16 _nCols,
     278             :                const sal_uInt16 _nRows,
     279             :                const Size&      _rPxWinSize,
     280             :                const bool       _bCalcScale
     281             :               );
     282             : 
     283             :     /** method to adjust page preview layout to document changes
     284             : 
     285             :         @author OD
     286             : 
     287             :         @return boolean, indicating, if preview layout is successful initialized.
     288             :     */
     289             :     bool ReInit();
     290             : 
     291             :     /** prepare paint of page preview
     292             : 
     293             :         With the valid preview layout settings - calculated and set by method
     294             :         <Init(..)> - the paint of a specific part of the virtual preview
     295             :         document is prepared. The corresponding part is given by either
     296             :         a start page (parameter <_nProposedStartPageNum>) or a absolute position
     297             :         (parameter <_aProposedStartPoint>).
     298             :         The accessibility preview will also be updated via a corresponding
     299             :         method call.
     300             : 
     301             :         @author OD
     302             : 
     303             :         @param _nProposedStartPageNum [0..<number of document pages>]
     304             :         input parameter - proposed number of page, which should be painted in
     305             :         the left-top-corner in the current output device. input parameter
     306             :         <_bStartWithPageAtFirstCol> influences, if proposed page is actual
     307             :         painted in the left-top-corner.
     308             : 
     309             :         @param _nProposedStartPos [(0,0)..<PreviewDocumentSize>]
     310             :         input parameter - proposed absolute position in the virtual preview
     311             :         document, which should be painted in the left-top-corner in the current
     312             :         output device.
     313             : 
     314             :         @param _rPxWinSize
     315             :         input parameter - pixel size of window the preview will be painted in.
     316             : 
     317             :         @param _onStartPageNum
     318             :         output parameter - physical number of page, which will be painted in the
     319             :         left-top-corner in the current output device.
     320             : 
     321             :         @param _orDocPreviewPaintRect
     322             :         output parameter - rectangle of preview document, which will be painted.
     323             : 
     324             :         @param _bStartWithPageAtFirstCol
     325             :         input parameter with default value "true" - controls, if start page
     326             :         is set to page in first column the proposed start page is located.
     327             : 
     328             :         @return boolean, indicating, if prepare of preview paint was successful.
     329             :     */
     330             :     bool Prepare( const sal_uInt16 _nProposedStartPageNum,
     331             :                   const Point      _aProposedStartPos,
     332             :                   const Size&      _rPxWinSize,
     333             :                   sal_uInt16&      _onStartPageNum,
     334             :                   Rectangle&       _orDocPreviewPaintRect,
     335             :                   const bool       _bStartWithPageAtFirstCol = true
     336             :                 );
     337             : 
     338             :     /** get selected page number
     339             : 
     340             :         @author OD
     341             :     */
     342           0 :     inline sal_uInt16 SelectedPage()
     343             :     {
     344           0 :         return mnSelectedPageNum;
     345             :     }
     346             : 
     347             :     /** set selected page number
     348             : 
     349             :         @author OD
     350             :     */
     351           0 :     inline void SetSelectedPage( sal_uInt16 _nSelectedPageNum )
     352             :     {
     353           0 :         mnSelectedPageNum = _nSelectedPageNum;
     354           0 :     }
     355             : 
     356             :     /** paint prepared preview
     357             : 
     358             :         @author OD
     359             : 
     360             :         @param _aOutRect
     361             :         input parameter - Twip rectangle of window, which should be painted.
     362             : 
     363             :         @return boolean, indicating, if paint of preview was performed
     364             :     */
     365             :     bool Paint( const Rectangle _aOutRect ) const;
     366             : 
     367             :     /** repaint pages on page preview
     368             : 
     369             :         method to invalidate visible pages due to changes in a different
     370             :         view shell.
     371             : 
     372             :         @author OD
     373             :     */
     374             :     void Repaint( const Rectangle _aInvalidCoreRect ) const;
     375             : 
     376             :     /** paint to mark new selected page
     377             : 
     378             :         Perform paint for current selected page in order to unmark it.
     379             :         Set new selected page and perform paint to mark this page.
     380             : 
     381             :         @author OD
     382             : 
     383             :         @param _nNewSelectedPage
     384             :         input parameter - physical number of page, which will be marked as selected.
     385             :     */
     386             :     void MarkNewSelectedPage( const sal_uInt16 _nSelectedPage );
     387             : 
     388             :     /** calculate start position for new scale
     389             : 
     390             :         calculate new start position for a new scale. Calculation bases on the
     391             :         current visible part of the document arranged in the given preview layout.
     392             :         preconditions:
     393             :         (1) new scaling is already set at the given output device.
     394             : 
     395             :         @author OD
     396             : 
     397             :         @return Point, start position for new scale
     398             :     */
     399             :     Point GetPreviewStartPosForNewScale( const Fraction& _aNewScale,
     400             :                                          const Fraction& _aOldScale,
     401             :                                          const Size&     _aNewWinSize ) const;
     402             : 
     403             :     /** determines, if page with given page number is visible in preview
     404             : 
     405             :         @author OD
     406             : 
     407             :         @param _nPageNum
     408             :         input parameter - physical number of page, for which it will be
     409             :         determined, if it is visible.
     410             : 
     411             :         @return boolean, indicating, if page with given page number is visible
     412             :         in preview.
     413             :     */
     414             :     bool IsPageVisible( const sal_uInt16 _nPageNum ) const;
     415             : 
     416             :     /** calculate data to bring new selected page into view.
     417             : 
     418             :         @author OD
     419             : 
     420             :         @param _nHoriMove
     421             :         input parameter - positive/negative number of columns the current
     422             :         selected page have to be moved.
     423             : 
     424             :         @param _nVertMove
     425             :         input parameter - positive/negative number of rows the current
     426             :         selected page have to be moved.
     427             : 
     428             :         @param _orNewSelectedPage
     429             :         output parameter - number of new selected page
     430             : 
     431             :         @param _orNewStartPage
     432             :         output parameter - number of new start page
     433             : 
     434             :         @param _orNewStartPos
     435             :         output parameter - new start position in document preview
     436             : 
     437             :         @return boolean - indicating, that move was sucessful.
     438             :     */
     439             :     bool CalcStartValuesForSelectedPageMove( const sal_Int16  _nHoriMove,
     440             :                                              const sal_Int16  _nVertMove,
     441             :                                              sal_uInt16&      _orNewSelectedPage,
     442             :                                              sal_uInt16&      _orNewStartPage,
     443             :                                              Point&           _orNewStartPos ) const;
     444             : 
     445             :     /** checks, if given position is inside a shown document page
     446             : 
     447             :         @author OD
     448             : 
     449             :         @param _aPreviewPos
     450             :         input parameter - position inside the visible preview window.
     451             : 
     452             :         @param _orDocPos
     453             :         output parameter - corresponding position in the document, if given
     454             :         preview position is inside a shown document page, not an empty page.
     455             :         If not, its value is <Point( 0, 0 )>.
     456             : 
     457             :         @param _obPosInEmptyPage
     458             :         output parameter - indicates, that given preview position lays inside
     459             :         an shown empty page.
     460             : 
     461             :         @param _onPageNum
     462             :         output parameter - corresponding physical number of page, if given
     463             :         preview position is inside a shown document page, considers also empty
     464             :         pages. If not, its value is <0>.
     465             : 
     466             :         @return boolean - indicating, that given preview position lays inside
     467             :         a shown document preview page, not an empty page.
     468             :     */
     469             :     bool IsPreviewPosInDocPreviewPage( const Point  _aPreviewPos,
     470             :                                    Point&       _orDocPos,
     471             :                                    bool&        _obPosInEmptyPage,
     472             :                                    sal_uInt16&  _onPageNum ) const;
     473             : 
     474           0 :     inline bool DoesPreviewLayoutRowsFitIntoWindow() const
     475             :     {
     476           0 :         return mbDoesLayoutRowsFitIntoWindow;
     477             :     }
     478             : 
     479           0 :     inline bool DoesPreviewLayoutColsFitIntoWindow() const
     480             :     {
     481           0 :         return mbDoesLayoutColsFitIntoWindow;
     482             :     }
     483             : 
     484           0 :     inline bool PreviewLayoutValid() const
     485             :     {
     486           0 :         return mbLayoutInfoValid && mbLayoutSizesValid && mbPaintInfoValid;
     487             :     }
     488             : 
     489             :     /** determine preview window page scroll amount
     490             : 
     491             :         @author OD
     492             : 
     493             :         @param _nWinPagesToScroll
     494             :         input parameter - number of preview window pages the scroll amount has
     495             :         to be calculated for. Negative values for preview window page up
     496             :         scrolling, positive values for preview window page down scrolling.
     497             : 
     498             :         @return scroll amount in SwTwips
     499             :     */
     500             :     SwTwips GetWinPagesScrollAmount( const sal_Int16 _nWinPagesToScroll ) const;
     501             : 
     502             :     /** determine row the page with the given number is in
     503             : 
     504             :         @author OD
     505             : 
     506             :         @param _nPageNum
     507             :         input parameter - physical page number of page, for which the row in
     508             :         preview layout has to be calculated.
     509             : 
     510             :         @return number of row the page with the given physical page number is in
     511             :     */
     512             :     sal_uInt16 GetRowOfPage( sal_uInt16 _nPageNum ) const;
     513             : 
     514             :     /** determine column the page with the given number is in
     515             : 
     516             :         @author OD
     517             : 
     518             :         @param _nPageNum
     519             :         input parameter - physical page number of page, for which the column in
     520             :         preview layout has to be calculated.
     521             : 
     522             :         @return number of column the page with the given physical page number is in
     523             :     */
     524             :     sal_uInt16 GetColOfPage( sal_uInt16 _nPageNum ) const;
     525             : 
     526             :     Size GetPreviewDocSize() const;
     527             : 
     528             :     /** get size of a preview page by its physical page number
     529             : 
     530             :         @author OD
     531             : 
     532             :         @param _nPageNum
     533             :         input parameter - pysical page number of preview page, for which the
     534             :         page size has to be returned.
     535             : 
     536             :         @return an object of class <Size>
     537             :     */
     538             :     Size GetPreviewPageSizeByPageNum( sal_uInt16 _nPageNum ) const;
     539             : 
     540             :     /** get virtual page number by its physical page number
     541             : 
     542             :         @author OD
     543             : 
     544             :         @param _nPageNum
     545             :         input parameter - pysical page number of preview page, for which the
     546             :         virtual page number has to be determined.
     547             : 
     548             :         @return virtual page number of page given by its physical page number,
     549             :         if the page is in the current preview pages vector, otherwise 0.
     550             :     */
     551             :     sal_uInt16 GetVirtPageNumByPageNum( sal_uInt16 _nPageNum ) const;
     552             : 
     553             :     /** enable/disable book preview
     554             : 
     555             :         @author OD
     556             :     */
     557             :     bool SetBookPreviewMode( const bool  _bEnableBookPreview,
     558             :                              sal_uInt16& _onStartPageNum,
     559             :                              Rectangle&  _orDocPreviewPaintRect );
     560             : 
     561             :     /** Convert relative to absolute page numbers (see PrintEmptyPages)
     562             : 
     563             :         @author FME
     564             :     */
     565             :     sal_uInt16 ConvertRelativeToAbsolutePageNum( sal_uInt16 _nRelPageNum ) const;
     566             : 
     567             :     /** Convert absolute to relative page numbers (see PrintEmptyPages)
     568             : 
     569             :         @author FME
     570             :     */
     571             :     sal_uInt16 ConvertAbsoluteToRelativePageNum( sal_uInt16 _nAbsPageNum ) const;
     572             : 
     573             :     /** get the number of preview pages
     574             : 
     575             :         @author FME
     576             :     */
     577             :     sal_uInt16 GetNumberOfPreviewPages() { return sal::static_int_cast< sal_uInt16 >(maPreviewPages.size()); }
     578             : };
     579             : 
     580             : #endif // INCLUDED_SW_INC_PAGEPREVIEWLAYOUT_HXX
     581             : 
     582             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10