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 INCLUDED_SW_INC_PAGEPREVIEWLAYOUT_HXX
21 #define INCLUDED_SW_INC_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 <vcl/outdev.hxx>
32 #include "swtypes.hxx"
40 /** page preview functionality in the writer */
41 class SwPagePreviewLayout
44 friend class SwViewShell
;
46 /// number of horizontal and vertical twips for spacing between the pages.
47 static constexpr SwTwips gnXFree
= 4 * 142;
48 static constexpr SwTwips gnYFree
= 4 * 142;
50 /// view shell the print preview is generated for.
51 SwViewShell
& mrParentViewShell
;
52 /// top layout frame of the layout for accessing the pages
53 const SwRootFrame
& mrLayoutRootFrame
;
55 /** boolean indicating, if the layout information (number of columns and rows)
57 bool mbLayoutInfoValid
;
58 /** boolean indicating, if the calculated print preview layout sizes
59 ( windows size in twips, maximal page size, column width, row height,
60 width and height of a print preview page, size of the print preview
61 document ) are valid */
62 bool mbLayoutSizesValid
;
63 /** boolean indicating, if the paint information ( physical number of
64 start page, start column and row, paint offsets, rectangle visible of
65 the print preview document. */
66 bool mbPaintInfoValid
;
72 // #i18143# - the book preview is controlled by this flag
74 bool mbBookPreviewModeToggled
;
77 tools::Rectangle maPreviewDocRect
;
80 SwTwips mnPreviewLayoutWidth
;
81 SwTwips mnPreviewLayoutHeight
;
82 bool mbDoesLayoutColsFitIntoWindow
;
83 bool mbDoesLayoutRowsFitIntoWindow
;
85 sal_uInt16 mnPaintPhyStartPageNum
;
86 sal_uInt16 mnPaintStartCol
;
87 sal_uInt16 mnPaintStartRow
;
89 Point maPaintStartPageOffset
;
90 Point maPaintPreviewDocOffset
;
91 Point maAdditionalPaintOffset
;
92 tools::Rectangle maPaintedPreviewDocRect
;
93 sal_uInt16 mnSelectedPageNum
;
95 std::vector
<std::unique_ptr
<PreviewPage
>> maPreviewPages
;
97 /** #i22014# - internal booleans to indicate, that a new print
98 preview layout has been created during a paint. */
99 mutable bool mbInPaint
;
100 mutable bool mbNewLayoutDuringPaint
;
102 bool mbPrintEmptyPages
;
104 /** clear internal data about current page preview */
107 /** helper method to clear preview page layout sizes */
108 void ClearPreviewLayoutSizes();
110 /** helper method to clear data in preview page vectors */
111 void ClearPreviewPageData();
113 /** calculate page preview layout sizes */
114 void CalcPreviewLayoutSizes();
116 /** apply new zoom at given view shell
119 input parameter - new zoom percentage
121 void ApplyNewZoomAtViewShell( sal_uInt8 _aNewZoom
);
123 /** calculate additional paint offset
125 helper method called by <Prepare> in order to calculate an additional
126 paint offset to center output in given window size.
127 The booleans <mbDoesLayoutRowsFitIntoWindow> and <mbDoesLayoutColsFitIntoWindow>
130 (1) preview layout is given (number of rows and columns).
131 (2) window size is given.
132 (3) height of row and width of column are calculated.
133 (4) paint offset of start page is calculated.
135 void CalcAdditionalPaintOffset();
137 /** calculate painted preview document rectangle
139 helper method called by <Prepare> in order to calculate the rectangle,
140 which will be painted for the document arranged by the given preview
143 (1) paint offset of document preview is calculated.
144 (2) size of document preview is calculated.
145 (3) additional paint offset is calculated - see <CalcAdditionalPaintOffset>.
147 void CalcDocPreviewPaintRect();
149 /** determines preview data for a given page and a given preview offset
152 input parameter - constant reference to page frame, for which the
153 preview data will be calculated.
155 @param _rPreviewOffset
156 input parameter - constant reference to the offset the given page has
157 in the current preview window.
158 Note: Offset can be negative.
160 @param _opPreviewPage
161 output parameter - calculated preview data.
163 void CalcPreviewDataForPage( const SwPageFrame
& _rPage
,
164 const Point
& _rPreviewOffset
,
165 PreviewPage
* _opPreviewPage
);
167 /** calculate preview pages
169 helper method called by <Prepare> in order to determine which pages
170 will be visible in the current preview and calculate the data needed
171 to paint these pages. Also the accessible pages with its needed data
174 void CalcPreviewPages();
176 /** get preview page by physical page number
179 input parameter - physical page number of page, for which the preview
180 page will be returned.
182 @return pointer to preview page of current preview pages. If page doesn't
183 belongs to current preview pages, <0> is returned.
185 const PreviewPage
* GetPreviewPageByPageNum( const sal_uInt16 _nPageNum
) const;
187 /** paint selection mark at page */
188 void PaintSelectMarkAtPage(vcl::RenderContext
& rRenderContext
, const PreviewPage
* _aSelectedPreviewPage
) const;
191 /** constructor of <SwPagePreviewLayout>
193 @param _rParentViewShell
194 input parameter - reference to the view shell the page preview
195 layout belongs to. Reference will be hold as member <mrParentViewShell>.
196 Adjustments/Changes at this view shell:
197 (1) Adjustment of the mapping mode at the output device.
198 (2) Change of the zoom at the view options.
199 (3) Preparations for paint of the page preview.
201 @param _rLayoutRootFrame
202 input parameter - constant reference to the root frame of the layout.
203 Reference will be hold as member <mrLayoutRootFrame> in order to get
204 access to the page frames.
206 SwPagePreviewLayout( SwViewShell
& _rParentViewShell
,
207 const SwRootFrame
& _rLayoutRootFrame
);
209 /** destructor of <SwPagePreviewLayout> */
210 ~SwPagePreviewLayout()
212 ClearPreviewPageData();
215 /** init page preview layout
217 initialize the page preview settings for a given layout.
219 (1) If parameter <_bCalcScale> is true, mapping mode with calculated
220 scaling is set at the output device and the zoom at the view options of
221 the given view shell is set with the calculated scaling.
224 input parameter - initial number of page columns in the preview.
227 input parameter - initial number of page rows in the preview.
230 input parameter - window size in which the preview will be displayed and
231 for which the scaling will be calculated.
233 void Init( const sal_uInt16 _nCols
,
234 const sal_uInt16 _nRows
,
235 const Size
& _rPxWinSize
238 /** method to adjust page preview layout to document changes */
241 /** prepare paint of page preview
243 With the valid preview layout settings - calculated and set by method
244 <Init(..)> - the paint of a specific part of the virtual preview
245 document is prepared. The corresponding part is given by either
246 a start page (parameter <_nProposedStartPageNum>) or a absolute position
247 (parameter <_aProposedStartPoint>).
248 The accessibility preview will also be updated via a corresponding
251 @param _nProposedStartPageNum [0..<number of document pages>]
252 input parameter - proposed number of page, which should be painted in
253 the left-top-corner in the current output device. input parameter
254 <_bStartWithPageAtFirstCol> influences, if proposed page is actual
255 painted in the left-top-corner.
257 @param _nProposedStartPos [(0,0)..<PreviewDocumentSize>]
258 input parameter - proposed absolute position in the virtual preview
259 document, which should be painted in the left-top-corner in the current
263 input parameter - pixel size of window the preview will be painted in.
265 @param _onStartPageNum
266 output parameter - physical number of page, which will be painted in the
267 left-top-corner in the current output device.
269 @param _orDocPreviewPaintRect
270 output parameter - rectangle of preview document, which will be painted.
272 @param _bStartWithPageAtFirstCol
273 input parameter with default value "true" - controls, if start page
274 is set to page in first column the proposed start page is located.
276 @return boolean, indicating, if prepare of preview paint was successful.
278 bool Prepare( const sal_uInt16 _nProposedStartPageNum
,
279 const Point
& rProposedStartPos
,
280 const Size
& _rPxWinSize
,
281 sal_uInt16
& _onStartPageNum
,
282 tools::Rectangle
& _orDocPreviewPaintRect
,
283 const bool _bStartWithPageAtFirstCol
= true
286 /** get selected page number */
287 sal_uInt16
SelectedPage()
289 return mnSelectedPageNum
;
292 /** set selected page number */
293 void SetSelectedPage( sal_uInt16 _nSelectedPageNum
)
295 mnSelectedPageNum
= _nSelectedPageNum
;
298 /** paint prepared preview
301 input parameter - Twip rectangle of window, which should be painted.
303 @return boolean, indicating, if paint of preview was performed
305 bool Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rOutRect
) const;
307 /** repaint pages on page preview
309 method to invalidate visible pages due to changes in a different
312 void Repaint(const tools::Rectangle
& rInvalidCoreRect
) const;
314 /** paint to mark new selected page
316 Perform paint for current selected page in order to unmark it.
317 Set new selected page and perform paint to mark this page.
319 @param _nNewSelectedPage
320 input parameter - physical number of page, which will be marked as selected.
322 void MarkNewSelectedPage( const sal_uInt16 _nSelectedPage
);
324 /** calculate start position for new scale
326 calculate new start position for a new scale. Calculation bases on the
327 current visible part of the document arranged in the given preview layout.
329 (1) new scaling is already set at the given output device.
331 @return Point, start position for new scale
333 Point
GetPreviewStartPosForNewScale( const Fraction
& _aNewScale
,
334 const Fraction
& _aOldScale
,
335 const Size
& _aNewWinSize
) const;
337 /** determines, if page with given page number is visible in preview
340 input parameter - physical number of page, for which it will be
341 determined, if it is visible.
343 @return boolean, indicating, if page with given page number is visible
346 bool IsPageVisible( const sal_uInt16 _nPageNum
) const;
348 /** calculate data to bring new selected page into view.
351 input parameter - positive/negative number of columns the current
352 selected page have to be moved.
355 input parameter - positive/negative number of rows the current
356 selected page have to be moved.
358 @param _orNewSelectedPage
359 output parameter - number of new selected page
361 @param _orNewStartPage
362 output parameter - number of new start page
364 @param _orNewStartPos
365 output parameter - new start position in document preview
367 void CalcStartValuesForSelectedPageMove( const sal_Int16 _nHoriMove
,
368 const sal_Int16 _nVertMove
,
369 sal_uInt16
& _orNewSelectedPage
,
370 sal_uInt16
& _orNewStartPage
,
371 Point
& _orNewStartPos
) const;
373 /** checks, if given position is inside a shown document page
376 input parameter - position inside the visible preview window.
379 output parameter - corresponding position in the document, if given
380 preview position is inside a shown document page, not an empty page.
381 If not, its value is <Point( 0, 0 )>.
383 @param _obPosInEmptyPage
384 output parameter - indicates, that given preview position lays inside
388 output parameter - corresponding physical number of page, if given
389 preview position is inside a shown document page, considers also empty
390 pages. If not, its value is <0>.
392 @return boolean - indicating, that given preview position lays inside
393 a shown document preview page, not an empty page.
395 bool IsPreviewPosInDocPreviewPage( const Point
& rPreviewPos
,
397 bool& _obPosInEmptyPage
,
398 sal_uInt16
& _onPageNum
) const;
400 bool DoesPreviewLayoutRowsFitIntoWindow() const
402 return mbDoesLayoutRowsFitIntoWindow
;
405 bool DoesPreviewLayoutColsFitIntoWindow() const
407 return mbDoesLayoutColsFitIntoWindow
;
410 bool PreviewLayoutValid() const
412 return mbLayoutInfoValid
&& mbLayoutSizesValid
&& mbPaintInfoValid
;
415 /** determine preview window page scroll amount
417 @param _nWinPagesToScroll
418 input parameter - number of preview window pages the scroll amount has
419 to be calculated for. Negative values for preview window page up
420 scrolling, positive values for preview window page down scrolling.
422 @return scroll amount in SwTwips
424 SwTwips
GetWinPagesScrollAmount( const sal_Int16 _nWinPagesToScroll
) const;
426 /** determine row the page with the given number is in
429 input parameter - physical page number of page, for which the row in
430 preview layout has to be calculated.
432 @return number of row the page with the given physical page number is in
434 sal_uInt16
GetRowOfPage( sal_uInt16 _nPageNum
) const;
436 /** determine column the page with the given number is in
439 input parameter - physical page number of page, for which the column in
440 preview layout has to be calculated.
442 @return number of column the page with the given physical page number is in
444 sal_uInt16
GetColOfPage( sal_uInt16 _nPageNum
) const;
446 Size
GetPreviewDocSize() const;
448 /** get size of a preview page by its physical page number
451 input parameter - physical page number of preview page, for which the
452 page size has to be returned.
454 @return an object of class <Size>
456 Size
GetPreviewPageSizeByPageNum( sal_uInt16 _nPageNum
) const;
458 /** get virtual page number by its physical page number
461 input parameter - physical page number of preview page, for which the
462 virtual page number has to be determined.
464 @return virtual page number of page given by its physical page number,
465 if the page is in the current preview pages vector, otherwise 0.
467 sal_uInt16
GetVirtPageNumByPageNum( sal_uInt16 _nPageNum
) const;
469 /** enable/disable book preview */
470 bool SetBookPreviewMode( const bool _bEnableBookPreview
,
471 sal_uInt16
& _onStartPageNum
,
472 tools::Rectangle
& _orDocPreviewPaintRect
);
474 /** Convert relative to absolute page numbers (see PrintEmptyPages) */
475 sal_uInt16
ConvertRelativeToAbsolutePageNum( sal_uInt16 _nRelPageNum
) const;
477 /** Convert absolute to relative page numbers (see PrintEmptyPages) */
478 sal_uInt16
ConvertAbsoluteToRelativePageNum( sal_uInt16 _nAbsPageNum
) const;
480 SwViewShell
& GetParentViewShell()
482 return mrParentViewShell
;
486 #endif // INCLUDED_SW_INC_PAGEPREVIEWLAYOUT_HXX
488 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */