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 <swtypes.hxx>
38 /** page preview functionality in the writer
42 class SwPagePreviewLayout
45 friend class SwViewShell
;
47 /// number of horizontal and vertical twips for spacing between the pages.
48 const SwTwips mnXFree
;
49 const SwTwips mnYFree
;
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
;
56 /** boolean indicating, if the layout information (number of columns and rows)
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
;
73 // #i18143# - the book preview is controlled by this flag
75 bool mbBookPreviewModeToggled
;
78 Rectangle maPreviewDocRect
;
81 SwTwips mnPreviewLayoutWidth
;
82 SwTwips mnPreviewLayoutHeight
;
83 bool mbDoesLayoutColsFitIntoWindow
;
84 bool mbDoesLayoutRowsFitIntoWindow
;
86 sal_uInt16 mnPaintPhyStartPageNum
;
87 sal_uInt16 mnPaintStartCol
;
88 sal_uInt16 mnPaintStartRow
;
90 Point maPaintStartPageOffset
;
91 Point maPaintPreviewDocOffset
;
92 Point maAdditionalPaintOffset
;
93 Rectangle maPaintedPreviewDocRect
;
94 sal_uInt16 mnSelectedPageNum
;
96 std::vector
<PreviewPage
*> maPreviewPages
;
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
;
103 bool mbPrintEmptyPages
;
105 /** clear internal data about current page preview
111 /** helper method to clear preview page layout sizes
115 void _ClearPreviewLayoutSizes();
117 /** helper method to clear data in preview page vectors
121 void _ClearPreviewPageData();
123 /** calculate page preview layout sizes
127 void _CalcPreviewLayoutSizes();
129 /** apply new zoom at given view shell
134 input parameter - new zoom percentage
136 void _ApplyNewZoomAtViewShell( sal_uInt8 _aNewZoom
);
138 /** calculate additional paint offset
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>
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.
152 void _CalcAdditionalPaintOffset();
154 /** calculate painted preview document rectangle
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
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>.
166 void _CalcDocPreviewPaintRect();
168 /** determines preview data for a given page and a given preview offset
173 input parameter - constant reference to page frame, for which the
174 preview data will be calculated.
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.
181 @param _opPreviewPage
182 output parameter - calculated preview data.
184 @return boolean, indicating, if calculation was successful.
186 bool _CalcPreviewDataForPage( const SwPageFrm
& _rPage
,
187 const Point
& _rPreviewOffset
,
188 PreviewPage
* _opPreviewPage
);
190 /** calculate preview pages
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
199 void _CalcPreviewPages();
201 /** get preview page by physical page number
206 input parameter - physical page number of page, for which the preview
207 page will be returned.
209 @return pointer to preview page of current preview pages. If page doesn't
210 belongs to current preview pages, <0> is returned.
212 const PreviewPage
* _GetPreviewPageByPageNum( const sal_uInt16 _nPageNum
) const;
214 /** paint selection mark at page
218 void _PaintSelectMarkAtPage(vcl::RenderContext
& rRenderContext
, const PreviewPage
* _aSelectedPreviewPage
) const;
221 /** constructor of <SwPagePreviewLayout>
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.
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.
238 SwPagePreviewLayout( SwViewShell
& _rParentViewShell
,
239 const SwRootFrm
& _rLayoutRootFrm
);
241 /** destructor of <SwPagePreviewLayout>
245 inline ~SwPagePreviewLayout()
247 _ClearPreviewPageData();
250 /** init page preview layout
252 initialize the page preview settings for a given layout.
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.
261 input parameter - initial number of page columns in the preview.
264 input parameter - initial number of page rows in the preview.
267 input parameter - window size in which the preview will be displayed and
268 for which the scaling will be calculated.
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.
275 @return boolean, indicating, if preview layout is successful initialized.
277 bool Init( const sal_uInt16 _nCols
,
278 const sal_uInt16 _nRows
,
279 const Size
& _rPxWinSize
,
280 const bool _bCalcScale
283 /** method to adjust page preview layout to document changes
287 @return boolean, indicating, if preview layout is successful initialized.
291 /** prepare paint of page preview
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
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.
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
315 input parameter - pixel size of window the preview will be painted in.
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.
321 @param _orDocPreviewPaintRect
322 output parameter - rectangle of preview document, which will be painted.
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.
328 @return boolean, indicating, if prepare of preview paint was successful.
330 bool Prepare( const sal_uInt16 _nProposedStartPageNum
,
331 const Point
& rProposedStartPos
,
332 const Size
& _rPxWinSize
,
333 sal_uInt16
& _onStartPageNum
,
334 Rectangle
& _orDocPreviewPaintRect
,
335 const bool _bStartWithPageAtFirstCol
= true
338 /** get selected page number
342 inline sal_uInt16
SelectedPage()
344 return mnSelectedPageNum
;
347 /** set selected page number
351 inline void SetSelectedPage( sal_uInt16 _nSelectedPageNum
)
353 mnSelectedPageNum
= _nSelectedPageNum
;
356 /** paint prepared preview
361 input parameter - Twip rectangle of window, which should be painted.
363 @return boolean, indicating, if paint of preview was performed
365 bool Paint(vcl::RenderContext
& rRenderContext
, const Rectangle
& rOutRect
) const;
367 /** repaint pages on page preview
369 method to invalidate visible pages due to changes in a different
374 void Repaint(const Rectangle
& rInvalidCoreRect
) const;
376 /** paint to mark new selected page
378 Perform paint for current selected page in order to unmark it.
379 Set new selected page and perform paint to mark this page.
383 @param _nNewSelectedPage
384 input parameter - physical number of page, which will be marked as selected.
386 void MarkNewSelectedPage( const sal_uInt16 _nSelectedPage
);
388 /** calculate start position for new scale
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.
393 (1) new scaling is already set at the given output device.
397 @return Point, start position for new scale
399 Point
GetPreviewStartPosForNewScale( const Fraction
& _aNewScale
,
400 const Fraction
& _aOldScale
,
401 const Size
& _aNewWinSize
) const;
403 /** determines, if page with given page number is visible in preview
408 input parameter - physical number of page, for which it will be
409 determined, if it is visible.
411 @return boolean, indicating, if page with given page number is visible
414 bool IsPageVisible( const sal_uInt16 _nPageNum
) const;
416 /** calculate data to bring new selected page into view.
421 input parameter - positive/negative number of columns the current
422 selected page have to be moved.
425 input parameter - positive/negative number of rows the current
426 selected page have to be moved.
428 @param _orNewSelectedPage
429 output parameter - number of new selected page
431 @param _orNewStartPage
432 output parameter - number of new start page
434 @param _orNewStartPos
435 output parameter - new start position in document preview
437 @return boolean - indicating, that move was successful.
439 bool CalcStartValuesForSelectedPageMove( const sal_Int16 _nHoriMove
,
440 const sal_Int16 _nVertMove
,
441 sal_uInt16
& _orNewSelectedPage
,
442 sal_uInt16
& _orNewStartPage
,
443 Point
& _orNewStartPos
) const;
445 /** checks, if given position is inside a shown document page
450 input parameter - position inside the visible preview window.
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 )>.
457 @param _obPosInEmptyPage
458 output parameter - indicates, that given preview position lays inside
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>.
466 @return boolean - indicating, that given preview position lays inside
467 a shown document preview page, not an empty page.
469 bool IsPreviewPosInDocPreviewPage( const Point
& rPreviewPos
,
471 bool& _obPosInEmptyPage
,
472 sal_uInt16
& _onPageNum
) const;
474 inline bool DoesPreviewLayoutRowsFitIntoWindow() const
476 return mbDoesLayoutRowsFitIntoWindow
;
479 inline bool DoesPreviewLayoutColsFitIntoWindow() const
481 return mbDoesLayoutColsFitIntoWindow
;
484 inline bool PreviewLayoutValid() const
486 return mbLayoutInfoValid
&& mbLayoutSizesValid
&& mbPaintInfoValid
;
489 /** determine preview window page scroll amount
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.
498 @return scroll amount in SwTwips
500 SwTwips
GetWinPagesScrollAmount( const sal_Int16 _nWinPagesToScroll
) const;
502 /** determine row the page with the given number is in
507 input parameter - physical page number of page, for which the row in
508 preview layout has to be calculated.
510 @return number of row the page with the given physical page number is in
512 sal_uInt16
GetRowOfPage( sal_uInt16 _nPageNum
) const;
514 /** determine column the page with the given number is in
519 input parameter - physical page number of page, for which the column in
520 preview layout has to be calculated.
522 @return number of column the page with the given physical page number is in
524 sal_uInt16
GetColOfPage( sal_uInt16 _nPageNum
) const;
526 Size
GetPreviewDocSize() const;
528 /** get size of a preview page by its physical page number
533 input parameter - pysical page number of preview page, for which the
534 page size has to be returned.
536 @return an object of class <Size>
538 Size
GetPreviewPageSizeByPageNum( sal_uInt16 _nPageNum
) const;
540 /** get virtual page number by its physical page number
545 input parameter - pysical page number of preview page, for which the
546 virtual page number has to be determined.
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.
551 sal_uInt16
GetVirtPageNumByPageNum( sal_uInt16 _nPageNum
) const;
553 /** enable/disable book preview
557 bool SetBookPreviewMode( const bool _bEnableBookPreview
,
558 sal_uInt16
& _onStartPageNum
,
559 Rectangle
& _orDocPreviewPaintRect
);
561 /** Convert relative to absolute page numbers (see PrintEmptyPages)
565 sal_uInt16
ConvertRelativeToAbsolutePageNum( sal_uInt16 _nRelPageNum
) const;
567 /** Convert absolute to relative page numbers (see PrintEmptyPages)
571 sal_uInt16
ConvertAbsoluteToRelativePageNum( sal_uInt16 _nAbsPageNum
) const;
573 /** get the number of preview pages
577 sal_uInt16
GetNumberOfPreviewPages() { return sal::static_int_cast
< sal_uInt16
>(maPreviewPages
.size()); }
579 SwViewShell
& GetParentViewShell()
581 return mrParentViewShell
;
585 #endif // INCLUDED_SW_INC_PAGEPREVIEWLAYOUT_HXX
587 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */