1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _PAGEPREVIEWLAYOUT_HXX
21 #define _PAGEPREVIEWLAYOUT_HXX
23 // template class <std::vector>
26 #include <sal/types.h>
27 // classes <Point>, <Size> and <Rectangle>
28 #include <tools/gen.hxx>
30 #include <swtypes.hxx>
38 // =============================================================================
39 /** page preview functionality in the writer
43 class SwPagePreviewLayout
46 friend class ViewShell
;
48 /// number of horizontal and vertical twips for spacing between the pages.
49 const SwTwips mnXFree
;
50 const SwTwips mnYFree
;
52 /// view shell the print preview is generated for.
53 ViewShell
& mrParentViewShell
;
54 /// top layout frame of the layout for accessing the pages
55 const SwRootFrm
& mrLayoutRootFrm
;
57 /** boolean indicating, if the layout information (number of columns and rows)
59 bool mbLayoutInfoValid
;
60 /** boolean indicating, if the calculated print preview layout sizes
61 ( windows size in twips, maximal page size, column width, row height,
62 width and height of a print preview page, size of the print preview
63 document ) are valid */
64 bool mbLayoutSizesValid
;
65 /** boolean indicating, if the paint information ( physical number of
66 start page, start column and row, paint offsets, rectangle visible of
67 the print preview document. */
68 bool mbPaintInfoValid
;
74 // #i18143# - the book preview is controlled by this flag
76 bool mbBookPreviewModeToggled
;
79 Rectangle maPreviewDocRect
;
82 SwTwips mnPrevwLayoutWidth
;
83 SwTwips mnPrevwLayoutHeight
;
84 bool mbDoesLayoutColsFitIntoWindow
;
85 bool mbDoesLayoutRowsFitIntoWindow
;
87 sal_uInt16 mnPaintPhyStartPageNum
;
88 sal_uInt16 mnPaintStartCol
;
89 sal_uInt16 mnPaintStartRow
;
91 Point maPaintStartPageOffset
;
92 Point maPaintPreviewDocOffset
;
93 Point maAdditionalPaintOffset
;
94 Rectangle maPaintedPrevwDocRect
;
95 sal_uInt16 mnSelectedPageNum
;
97 std::vector
<PrevwPage
*> maPrevwPages
;
99 /** #i22014# - internal booleans to indicate, that a new print
100 preview layout has been created during a paint. */
101 mutable bool mbInPaint
;
102 mutable bool mbNewLayoutDuringPaint
;
104 bool mbPrintEmptyPages
;
106 /** clear internal data about current page preview
112 /** helper method to clear preview page layout sizes
116 void _ClearPrevwLayoutSizes();
118 /** helper method to clear data in preview page vectors
122 void _ClearPrevwPageData();
124 /** calculate page preview layout sizes
128 void _CalcPrevwLayoutSizes();
130 /** apply new zoom at given view shell
135 input parameter - new zoom percentage
137 void _ApplyNewZoomAtViewShell( sal_uInt8 _aNewZoom
);
139 /** calculate additional paint offset
141 helper method called by <Prepare> in order to calculate an additional
142 paint offset to center output in given window size.
143 The booleans <mbDoesLayoutRowsFitIntoWindow> and <mbDoesLayoutColsFitIntoWindow>
146 (1) preview layout is given (number of rows and columns).
147 (2) window size is given.
148 (3) height of row and width of column are calculated.
149 (4) paint offset of start page is calculated.
153 void _CalcAdditionalPaintOffset();
155 /** calculate painted preview document rectangle
157 helper method called by <Prepare> in order to calculate the rectangle,
158 which will be painted for the document arranged by the given preview
161 (1) paint offset of document preview is calculated.
162 (2) size of document preview is calculated.
163 (3) additional paint offset is calculated - see <_CalcAdditionalPaintOffset>.
167 void _CalcDocPrevwPaintRect();
169 /** determines preview data for a given page and a given preview offset
175 input parameter - constant reference to page frame, for which the
176 preview data will be calculated.
179 input parameter - constant reference to the offset the given page has
180 in the current preview window.
181 Note: Offset can be negative.
184 output parameter - calculated preview data.
186 @return boolean, indicating, if calculation was successful.
188 bool _CalcPreviewDataForPage( const SwPageFrm
& _rPage
,
189 const Point
& _rPrevwOffset
,
190 PrevwPage
* _opPrevwPage
);
192 /** calculate preview pages
194 helper method called by <Prepare> in order to determine which pages
195 will be visible in the current preview and calculate the data needed
196 to paint these pages. Also the accessible pages with its needed data
201 void _CalcPreviewPages();
203 /** get preview page by physical page number
208 input parameter - physical page number of page, for which the preview
209 page will be returned.
211 @return pointer to preview page of current preview pages. If page doesn't
212 belongs to current preview pages, <0> is returned.
214 const PrevwPage
* _GetPrevwPageByPageNum( const sal_uInt16 _nPageNum
) const;
216 /** paint selection mark at page
220 void _PaintSelectMarkAtPage( const PrevwPage
* _aSelectedPrevwPage
) const;
223 /** constructor of <SwPagePreviewLayout>
227 @param _rParentViewShell
228 input parameter - reference to the view shell the page preview
229 layout belongs to. Reference will be hold as member <mrParentViewShell>.
230 Adjustments/Changes at this view shell:
231 (1) Adjustment of the mapping mode at the output device.
232 (2) Change of the zoom at the view options.
233 (3) Preparations for paint of the page preview.
235 @param _rLayoutRootFrm
236 input parameter - constant reference to the root frame of the layout.
237 Reference will be hold as member <mrLayoutRootFrm> in order to get
238 access to the page frames.
240 SwPagePreviewLayout( ViewShell
& _rParentViewShell
,
241 const SwRootFrm
& _rLayoutRootFrm
);
243 /** destructor of <SwPagePreviewLayout>
247 inline ~SwPagePreviewLayout()
249 _ClearPrevwPageData();
252 /** init page preview layout
254 initialize the page preview settings for a given layout.
256 (1) If parameter <_bCalcScale> is true, mapping mode with calculated
257 scaling is set at the output device and the zoom at the view options of
258 the given view shell is set with the calculated scaling.
263 input parameter - initial number of page columns in the preview.
266 input parameter - initial number of page rows in the preview.
269 input parameter - window size in which the preview will be displayed and
270 for which the scaling will be calculated.
273 input parameter - control, if method should calculate the needed
274 scaling for the proposed preview layout for the given window size
275 and sets the scaling at the output device and the view options.
277 @return boolean, indicating, if preview layout is successful initialized.
279 bool Init( const sal_uInt16 _nCols
,
280 const sal_uInt16 _nRows
,
281 const Size
& _rPxWinSize
,
282 const bool _bCalcScale
285 /** method to adjust page preview layout to document changes
289 @return boolean, indicating, if preview layout is successful initialized.
293 /** prepare paint of page preview
295 With the valid preview layout settings - calculated and set by method
296 <Init(..)> - the paint of a specific part of the virtual preview
297 document is prepared. The corresponding part is given by either
298 a start page (parameter <_nProposedStartPageNum>) or a absolute position
299 (parameter <_aProposedStartPoint>).
300 The accessibility preview will also be updated via a corresponding
305 @param _nProposedStartPageNum [0..<number of document pages>]
306 input parameter - proposed number of page, which should be painted in
307 the left-top-corner in the current output device. input parameter
308 <_bStartWithPageAtFirstCol> influences, if proposed page is actual
309 painted in the left-top-corner.
311 @param _nProposedStartPos [(0,0)..<PreviewDocumentSize>]
312 input parameter - proposed absolute position in the virtual preview
313 document, which should be painted in the left-top-corner in the current
317 input parameter - pixel size of window the preview will be painted in.
319 @param _onStartPageNum
320 output parameter - physical number of page, which will be painted in the
321 left-top-corner in the current output device.
323 @param _orDocPreviewPaintRect
324 output parameter - rectangle of preview document, which will be painted.
326 @param _bStartWithPageAtFirstCol
327 input parameter with default value "true" - controls, if start page
328 is set to page in first column the proposed start page is located.
330 @return boolean, indicating, if prepare of preview paint was successful.
332 bool Prepare( const sal_uInt16 _nProposedStartPageNum
,
333 const Point _aProposedStartPos
,
334 const Size
& _rPxWinSize
,
335 sal_uInt16
& _onStartPageNum
,
336 Rectangle
& _orDocPreviewPaintRect
,
337 const bool _bStartWithPageAtFirstCol
= true
340 /** get selected page number
344 inline sal_uInt16
SelectedPage()
346 return mnSelectedPageNum
;
349 /** set selected page number
353 inline void SetSelectedPage( sal_uInt16 _nSelectedPageNum
)
355 mnSelectedPageNum
= _nSelectedPageNum
;
358 /** paint prepared preview
363 input parameter - Twip rectangle of window, which should be painted.
365 @return boolean, indicating, if paint of preview was performed
367 bool Paint( const Rectangle _aOutRect
) const;
369 /** repaint pages on page preview
371 method to invalidate visible pages due to changes in a different
376 void Repaint( const Rectangle _aInvalidCoreRect
) const;
378 /** paint to mark new selected page
380 Perform paint for current selected page in order to unmark it.
381 Set new selected page and perform paint to mark this page.
385 @param _nNewSelectedPage
386 input parameter - physical number of page, which will be marked as selected.
388 void MarkNewSelectedPage( const sal_uInt16 _nSelectedPage
);
390 /** calculate start position for new scale
392 calculate new start position for a new scale. Calculation bases on the
393 current visible part of the document arranged in the given preview layout.
395 (1) new scaling is already set at the given output device.
399 @return Point, start position for new scale
401 Point
GetPreviewStartPosForNewScale( const Fraction
& _aNewScale
,
402 const Fraction
& _aOldScale
,
403 const Size
& _aNewWinSize
) const;
405 /** determines, if page with given page number is visible in preview
410 input parameter - physical number of page, for which it will be
411 determined, if it is visible.
413 @return boolean, indicating, if page with given page number is visible
416 bool IsPageVisible( const sal_uInt16 _nPageNum
) const;
418 /** calculate data to bring new selected page into view.
423 input parameter - positive/negative number of columns the current
424 selected page have to be moved.
427 input parameter - positive/negative number of rows the current
428 selected page have to be moved.
430 @param _orNewSelectedPage
431 output parameter - number of new selected page
433 @param _orNewStartPage
434 output parameter - number of new start page
436 @param _orNewStartPos
437 output parameter - new start position in document preview
439 @return boolean - indicating, that move was sucessful.
441 bool CalcStartValuesForSelectedPageMove( const sal_Int16 _nHoriMove
,
442 const sal_Int16 _nVertMove
,
443 sal_uInt16
& _orNewSelectedPage
,
444 sal_uInt16
& _orNewStartPage
,
445 Point
& _orNewStartPos
) const;
447 /** checks, if given position is inside a shown document page
452 input parameter - position inside the visible preview window.
455 output parameter - corresponding position in the document, if given
456 preview position is inside a shown document page, not an empty page.
457 If not, it's value is <Point( 0, 0 )>.
459 @param _obPosInEmptyPage
460 output parameter - indicates, that given preview position lays inside
464 output parameter - corresponding physical number of page, if given
465 preview position is inside a shown document page, considers also empty
466 pages. If not, it's value is <0>.
468 @return boolean - indicating, that given preview position lays inside
469 a shown document preview page, not an empty page.
471 bool IsPrevwPosInDocPrevwPage( const Point _aPrevwPos
,
473 bool& _obPosInEmptyPage
,
474 sal_uInt16
& _onPageNum
) const;
476 inline bool DoesPreviewLayoutRowsFitIntoWindow() const
478 return mbDoesLayoutRowsFitIntoWindow
;
481 inline bool DoesPreviewLayoutColsFitIntoWindow() const
483 return mbDoesLayoutColsFitIntoWindow
;
486 inline bool PreviewLayoutValid() const
488 return mbLayoutInfoValid
&& mbLayoutSizesValid
&& mbPaintInfoValid
;
491 /** determine preview window page scroll amount
495 @param _nWinPagesToScroll
496 input parameter - number of preview window pages the scroll amount has
497 to be calculated for. Negative values for preview window page up
498 scrolling, positive values for preview window page down scrolling.
500 @return scroll amount in SwTwips
502 SwTwips
GetWinPagesScrollAmount( const sal_Int16 _nWinPagesToScroll
) const;
504 /** determine row the page with the given number is in
509 input parameter - physical page number of page, for which the row in
510 preview layout has to be calculated.
512 @return number of row the page with the given physical page number is in
514 sal_uInt16
GetRowOfPage( sal_uInt16 _nPageNum
) const;
516 /** determine column the page with the given number is in
521 input parameter - physical page number of page, for which the column in
522 preview layout has to be calculated.
524 @return number of column the page with the given physical page number is in
526 sal_uInt16
GetColOfPage( sal_uInt16 _nPageNum
) const;
528 Size
GetPrevwDocSize() const;
530 /** get size of a preview page by its physical page number
535 input parameter - pysical page number of preview page, for which the
536 page size has to be returned.
538 @return an object of class <Size>
540 Size
GetPrevwPageSizeByPageNum( sal_uInt16 _nPageNum
) const;
542 /** get virtual page number by its physical page number
547 input parameter - pysical page number of preview page, for which the
548 virtual page number has to be determined.
550 @return virtual page number of page given by its physical page number,
551 if the page is in the current preview pages vector, otherwise 0.
553 sal_uInt16
GetVirtPageNumByPageNum( sal_uInt16 _nPageNum
) const;
555 /** enable/disable book preview
559 bool SetBookPreviewMode( const bool _bEnableBookPreview
,
560 sal_uInt16
& _onStartPageNum
,
561 Rectangle
& _orDocPreviewPaintRect
);
563 /** Convert relative to absolute page numbers (see PrintEmptyPages)
567 sal_uInt16
ConvertRelativeToAbsolutePageNum( sal_uInt16 _nRelPageNum
) const;
569 /** Convert absolute to relative page numbers (see PrintEmptyPages)
573 sal_uInt16
ConvertAbsoluteToRelativePageNum( sal_uInt16 _nAbsPageNum
) const;
575 /** get the number of preview pages
579 sal_uInt16
GetNumberOfPreviewPages() { return sal::static_int_cast
< sal_uInt16
>(maPrevwPages
.size()); }
582 #endif // _PAGEPREVIEWLAYOUT_HXX
584 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */