Replace workaround of resize to invalidate with an explicit SfxHint
[LibreOffice.git] / sw / inc / pagepreviewlayout.hxx
blob7a6bccc6555574318283a7b6f5d61e317efcd4a4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
24 #include <vector>
25 // datatypes sal_xyz
26 #include <sal/types.h>
27 // classes <Point>, <Size> and <Rectangle>
28 #include <tools/gen.hxx>
29 // RenderContext type
30 #include <vcl/outdev.hxx>
31 // datatype <SwTwips>
32 #include "swtypes.hxx"
33 #include <prevwpage.hxx>
35 class SwViewShell;
36 class SwRootFrame;
37 class SwPageFrame;
38 class Fraction;
39 struct PreviewPage;
41 /** page preview functionality in the writer */
42 class SwPagePreviewLayout
44 private:
45 friend class SwViewShell;
47 /// number of horizontal and vertical twips for spacing between the pages.
48 static constexpr SwTwips gnXFree = 4 * 142;
49 static constexpr SwTwips gnYFree = 4 * 142;
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 SwRootFrame& mrLayoutRootFrame;
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;
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;
77 Size maMaxPageSize;
78 tools::Rectangle maPreviewDocRect;
79 SwTwips mnColWidth;
80 SwTwips mnRowHeight;
81 SwTwips mnPreviewLayoutWidth;
82 SwTwips mnPreviewLayoutHeight;
83 bool mbDoesLayoutColsFitIntoWindow;
84 bool mbDoesLayoutRowsFitIntoWindow;
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 tools::Rectangle maPaintedPreviewDocRect;
94 sal_uInt16 mnSelectedPageNum;
96 std::vector<std::unique_ptr<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 */
106 void Clear_();
108 /** helper method to clear preview page layout sizes */
109 void ClearPreviewLayoutSizes();
111 /** helper method to clear data in preview page vectors */
112 void ClearPreviewPageData();
114 /** calculate page preview layout sizes */
115 void CalcPreviewLayoutSizes();
117 /** apply new zoom at given view shell
119 @param _aNewZoom
120 input parameter - new zoom percentage
122 void ApplyNewZoomAtViewShell( sal_uInt8 _aNewZoom );
124 /** calculate additional paint offset
126 helper method called by <Prepare> in order to calculate an additional
127 paint offset to center output in given window size.
128 The booleans <mbDoesLayoutRowsFitIntoWindow> and <mbDoesLayoutColsFitIntoWindow>
129 are also determined.
130 preconditions:
131 (1) preview layout is given (number of rows and columns).
132 (2) window size is given.
133 (3) height of row and width of column are calculated.
134 (4) paint offset of start page is calculated.
136 void CalcAdditionalPaintOffset();
138 /** calculate painted preview document rectangle
140 helper method called by <Prepare> in order to calculate the rectangle,
141 which will be painted for the document arranged by the given preview
142 layout.
143 preconditions:
144 (1) paint offset of document preview is calculated.
145 (2) size of document preview is calculated.
146 (3) additional paint offset is calculated - see <CalcAdditionalPaintOffset>.
148 void CalcDocPreviewPaintRect();
150 /** determines preview data for a given page and a given preview offset
152 @param _rPage
153 input parameter - constant reference to page frame, for which the
154 preview data will be calculated.
156 @param _rPreviewOffset
157 input parameter - constant reference to the offset the given page has
158 in the current preview window.
159 Note: Offset can be negative.
161 @param _opPreviewPage
162 output parameter - calculated preview data.
164 void CalcPreviewDataForPage( const SwPageFrame& _rPage,
165 const Point& _rPreviewOffset,
166 PreviewPage* _opPreviewPage );
168 /** calculate preview pages
170 helper method called by <Prepare> in order to determine which pages
171 will be visible in the current preview and calculate the data needed
172 to paint these pages. Also the accessible pages with its needed data
173 are determined.
175 void CalcPreviewPages();
177 /** get preview page by physical page number
179 @param _nPageNum
180 input parameter - physical page number of page, for which the preview
181 page will be returned.
183 @return pointer to preview page of current preview pages. If page doesn't
184 belongs to current preview pages, <0> is returned.
186 const PreviewPage* GetPreviewPageByPageNum( const sal_uInt16 _nPageNum ) const;
188 /** paint selection mark at page */
189 void PaintSelectMarkAtPage(vcl::RenderContext& rRenderContext, const PreviewPage* _aSelectedPreviewPage) const;
191 public:
192 /** constructor of <SwPagePreviewLayout>
194 @param _rParentViewShell
195 input parameter - reference to the view shell the page preview
196 layout belongs to. Reference will be hold as member <mrParentViewShell>.
197 Adjustments/Changes at this view shell:
198 (1) Adjustment of the mapping mode at the output device.
199 (2) Change of the zoom at the view options.
200 (3) Preparations for paint of the page preview.
202 @param _rLayoutRootFrame
203 input parameter - constant reference to the root frame of the layout.
204 Reference will be hold as member <mrLayoutRootFrame> in order to get
205 access to the page frames.
207 SwPagePreviewLayout( SwViewShell& _rParentViewShell,
208 const SwRootFrame& _rLayoutRootFrame );
210 /** destructor of <SwPagePreviewLayout> */
211 ~SwPagePreviewLayout()
213 ClearPreviewPageData();
216 /** init page preview layout
218 initialize the page preview settings for a given layout.
219 side effects:
220 (1) If parameter <_bCalcScale> is true, mapping mode with calculated
221 scaling is set at the output device and the zoom at the view options of
222 the given view shell is set with the calculated scaling.
224 @param _nCols
225 input parameter - initial number of page columns in the preview.
227 @param _nRows
228 input parameter - initial number of page rows in the preview.
230 @param _rPxWinSize
231 input parameter - window size in which the preview will be displayed and
232 for which the scaling will be calculated.
234 void Init( const sal_uInt16 _nCols,
235 const sal_uInt16 _nRows,
236 const Size& _rPxWinSize
239 /** method to adjust page preview layout to document changes */
240 void ReInit();
242 /** prepare paint of page preview
244 With the valid preview layout settings - calculated and set by method
245 <Init(..)> - the paint of a specific part of the virtual preview
246 document is prepared. The corresponding part is given by either
247 a start page (parameter <_nProposedStartPageNum>) or an absolute position
248 (parameter <_aProposedStartPoint>).
249 The accessibility preview will also be updated via a corresponding
250 method call.
252 @param _nProposedStartPageNum [0..<number of document pages>]
253 input parameter - proposed number of page, which should be painted in
254 the left-top-corner in the current output device. input parameter
255 <_bStartWithPageAtFirstCol> influences, if proposed page is actual
256 painted in the left-top-corner.
258 @param _nProposedStartPos [(0,0)..<PreviewDocumentSize>]
259 input parameter - proposed absolute position in the virtual preview
260 document, which should be painted in the left-top-corner in the current
261 output device.
263 @param _rPxWinSize
264 input parameter - pixel size of window the preview will be painted in.
266 @param _onStartPageNum
267 output parameter - physical number of page, which will be painted in the
268 left-top-corner in the current output device.
270 @param _orDocPreviewPaintRect
271 output parameter - rectangle of preview document, which will be painted.
273 @param _bStartWithPageAtFirstCol
274 input parameter with default value "true" - controls, if start page
275 is set to page in first column the proposed start page is located.
277 @return boolean, indicating, if prepare of preview paint was successful.
279 bool Prepare( const sal_uInt16 _nProposedStartPageNum,
280 const Point& rProposedStartPos,
281 const Size& _rPxWinSize,
282 sal_uInt16& _onStartPageNum,
283 tools::Rectangle& _orDocPreviewPaintRect,
284 const bool _bStartWithPageAtFirstCol = true
287 /** get selected page number */
288 sal_uInt16 SelectedPage()
290 return mnSelectedPageNum;
293 /** set selected page number */
294 void SetSelectedPage( sal_uInt16 _nSelectedPageNum )
296 mnSelectedPageNum = _nSelectedPageNum;
299 /** get the maximal preview pages */
300 sal_uInt16 GetMaxPreviewPages() const
302 return mnPages;
305 /** paint prepared preview
307 @param _aOutRect
308 input parameter - Twip rectangle of window, which should be painted.
310 @return boolean, indicating, if paint of preview was performed
312 bool Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rOutRect) const;
314 /** repaint pages on page preview
316 method to invalidate visible pages due to changes in a different
317 view shell.
319 void Repaint(const tools::Rectangle& rInvalidCoreRect) const;
321 /** paint to mark new selected page
323 Perform paint for current selected page in order to unmark it.
324 Set new selected page and perform paint to mark this page.
326 @param _nNewSelectedPage
327 input parameter - physical number of page, which will be marked as selected.
329 void MarkNewSelectedPage( const sal_uInt16 _nSelectedPage );
331 /** calculate start position for new scale
333 calculate new start position for a new scale. Calculation bases on the
334 current visible part of the document arranged in the given preview layout.
335 preconditions:
336 (1) new scaling is already set at the given output device.
338 @return Point, start position for new scale
340 Point GetPreviewStartPosForNewScale( const Fraction& _aNewScale,
341 const Fraction& _aOldScale,
342 const Size& _aNewWinSize ) const;
344 /** determines, if page with given page number is visible in preview
346 @param _nPageNum
347 input parameter - physical number of page, for which it will be
348 determined, if it is visible.
350 @return boolean, indicating, if page with given page number is visible
351 in preview.
353 bool IsPageVisible( const sal_uInt16 _nPageNum ) const;
355 /** calculate data to bring new selected page into view.
357 @param _nHoriMove
358 input parameter - positive/negative number of columns the current
359 selected page have to be moved.
361 @param _nVertMove
362 input parameter - positive/negative number of rows the current
363 selected page have to be moved.
365 @param _orNewSelectedPage
366 output parameter - number of new selected page
368 @param _orNewStartPage
369 output parameter - number of new start page
371 @param _orNewStartPos
372 output parameter - new start position in document preview
374 void CalcStartValuesForSelectedPageMove( const sal_Int16 _nHoriMove,
375 const sal_Int16 _nVertMove,
376 sal_uInt16& _orNewSelectedPage,
377 sal_uInt16& _orNewStartPage,
378 Point& _orNewStartPos ) const;
380 /** checks, if given position is inside a shown document page
382 @param _aPreviewPos
383 input parameter - position inside the visible preview window.
385 @param _orDocPos
386 output parameter - corresponding position in the document, if given
387 preview position is inside a shown document page, not an empty page.
388 If not, its value is <Point( 0, 0 )>.
390 @param _obPosInEmptyPage
391 output parameter - indicates, that given preview position lays inside
392 an shown empty page.
394 @param _onPageNum
395 output parameter - corresponding physical number of page, if given
396 preview position is inside a shown document page, considers also empty
397 pages. If not, its value is <0>.
399 @return boolean - indicating, that given preview position lays inside
400 a shown document preview page, not an empty page.
402 bool IsPreviewPosInDocPreviewPage( const Point& rPreviewPos,
403 Point& _orDocPos,
404 bool& _obPosInEmptyPage,
405 sal_uInt16& _onPageNum ) const;
407 bool DoesPreviewLayoutRowsFitIntoWindow() const
409 return mbDoesLayoutRowsFitIntoWindow;
412 bool DoesPreviewLayoutColsFitIntoWindow() const
414 return mbDoesLayoutColsFitIntoWindow;
417 bool PreviewLayoutValid() const
419 return mbLayoutInfoValid && mbLayoutSizesValid && mbPaintInfoValid;
422 /** determine preview window page scroll amount
424 @param _nWinPagesToScroll
425 input parameter - number of preview window pages the scroll amount has
426 to be calculated for. Negative values for preview window page up
427 scrolling, positive values for preview window page down scrolling.
429 @return scroll amount in SwTwips
431 SwTwips GetWinPagesScrollAmount( const sal_Int16 _nWinPagesToScroll ) const;
433 /** determine row the page with the given number is in
435 @param _nPageNum
436 input parameter - physical page number of page, for which the row in
437 preview layout has to be calculated.
439 @return number of row the page with the given physical page number is in
441 sal_uInt16 GetRowOfPage( sal_uInt16 _nPageNum ) const;
443 /** determine column the page with the given number is in
445 @param _nPageNum
446 input parameter - physical page number of page, for which the column in
447 preview layout has to be calculated.
449 @return number of column the page with the given physical page number is in
451 sal_uInt16 GetColOfPage( sal_uInt16 _nPageNum ) const;
453 Size GetPreviewDocSize() const;
455 /** get size of a preview page by its physical page number
457 @param _nPageNum
458 input parameter - physical page number of preview page, for which the
459 page size has to be returned.
461 @return an object of class <Size>
463 Size GetPreviewPageSizeByPageNum( sal_uInt16 _nPageNum ) const;
465 /** get virtual page number by its physical page number
467 @param _nPageNum
468 input parameter - physical page number of preview page, for which the
469 virtual page number has to be determined.
471 @return virtual page number of page given by its physical page number,
472 if the page is in the current preview pages vector, otherwise 0.
474 sal_uInt16 GetVirtPageNumByPageNum( sal_uInt16 _nPageNum ) const;
476 /** enable/disable book preview */
477 bool SetBookPreviewMode( const bool _bEnableBookPreview,
478 sal_uInt16& _onStartPageNum,
479 tools::Rectangle& _orDocPreviewPaintRect );
481 /** Convert relative to absolute page numbers (see PrintEmptyPages) */
482 sal_uInt16 ConvertRelativeToAbsolutePageNum( sal_uInt16 _nRelPageNum ) const;
484 /** Convert absolute to relative page numbers (see PrintEmptyPages) */
485 sal_uInt16 ConvertAbsoluteToRelativePageNum( sal_uInt16 _nAbsPageNum ) const;
487 SwViewShell& GetParentViewShell()
489 return mrParentViewShell;
493 #endif // INCLUDED_SW_INC_PAGEPREVIEWLAYOUT_HXX
495 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */