1 #ifndef _PAGEPREVIEWLAYOUT_HXX
2 #define _PAGEPREVIEWLAYOUT_HXX
4 // template class <std::vector>
8 // classes <Point>, <Size> and <Rectangle>
9 #include <tools/gen.hxx>
11 #include <swtypes.hxx>
19 // =============================================================================
20 /** page preview functionality in the writer
22 OD 11.12.2002 #103492# - class <SwPagePreviewLayout>
26 class SwPagePreviewLayout
29 friend class ViewShell
;
31 // number of horizontal and vertical twips for spacing between the pages.
32 const SwTwips mnXFree
;
33 const SwTwips mnYFree
;
35 // view shell the print preview is generated for.
36 ViewShell
& mrParentViewShell
;
37 // top layout frame of the layout for accessing the pages
38 const SwRootFrm
& mrLayoutRootFrm
;
40 // boolean indicating, if the layout information (number of columns and rows)
42 bool mbLayoutInfoValid
;
43 // boolean indicating, if the the calculated print preview layout sizes
44 // ( windows size in twips, maximal page size, column width, row height,
45 // width and height of a print preview page, size of the print preview
46 // document ) are valid
47 bool mbLayoutSizesValid
;
48 // boolean indicating, if the the paint information ( physical number of
49 // start page, start column and row, paint offsets, rectangle visible of
50 // the print preview document.
51 bool mbPaintInfoValid
;
57 // OD 19.02.2003 #107369# - new flag for leaving blank left-top-corner
58 // OD 2004-03-05 #i18143# - the book preview is controlled by this flag
60 bool mbBookPreviewModeToggled
;
63 Rectangle maPreviewDocRect
;
66 SwTwips mnPrevwLayoutWidth
;
67 SwTwips mnPrevwLayoutHeight
;
68 bool mbDoesLayoutColsFitIntoWindow
;
69 bool mbDoesLayoutRowsFitIntoWindow
;
71 sal_uInt16 mnPaintPhyStartPageNum
;
72 sal_uInt16 mnPaintStartCol
;
73 sal_uInt16 mnPaintStartRow
;
75 Point maPaintStartPageOffset
;
76 Point maPaintPreviewDocOffset
;
77 Point maAdditionalPaintOffset
;
78 Rectangle maPaintedPrevwDocRect
;
79 sal_uInt16 mnSelectedPageNum
;
81 std::vector
<PrevwPage
*> maPrevwPages
;
83 // OD 07.11.2003 #i22014# - internal booleans to indicate, that a new print
84 // preview layout has been created during a paint.
85 mutable bool mbInPaint
;
86 mutable bool mbNewLayoutDuringPaint
;
88 bool mbPrintEmptyPages
;
90 /** clear internal data about current page preview
92 OD 11.12.2002 #103492#
98 /** helper method to clear preview page layout sizes
100 OD 18.12.2002 #103492#
104 void _ClearPrevwLayoutSizes();
106 /** helper method to clear data in preview page vectors
108 OD 13.12.2002 #103492#
112 void _ClearPrevwPageData();
114 /** calculate page preview layout sizes
116 OD 18.12.2002 #103492#
120 void _CalcPrevwLayoutSizes();
122 /** apply new zoom at given view shell
124 OD 11.12.2002 #103492#
129 input parameter - new zoom percentage
131 void _ApplyNewZoomAtViewShell( sal_uInt8 _aNewZoom
);
133 /** calculate additional paint offset
135 OD 12.12.2002 #103492#
136 helper method called by <Prepare> in order to calculate an additional
137 paint offset to center output in given window size.
138 The booleans <mbDoesLayoutRowsFitIntoWindow> and <mbDoesLayoutColsFitIntoWindow>
141 (1) preview layout is given (number of rows and columns).
142 (2) window size is given.
143 (3) height of row and width of column are calculated.
144 (4) paint offset of start page is calculated.
148 void _CalcAdditionalPaintOffset();
150 /** calculate painted preview document rectangle
152 OD 12.12.2002 #103492#
153 helper method called by <Prepare> in order to calculate the rectangle,
154 which will be painted for the document arranged by the given preview
157 (1) paint offset of document preview is calculated.
158 (2) size of document preview is calculated.
159 (3) additional paint offset is calculated - see <_CalcAdditionalPaintOffset>.
163 void _CalcDocPrevwPaintRect();
165 /** determines preview data for a given page and a given preview offset
167 OD 13.12.2002 #103492#
172 input parameter - constant reference to page frame, for which the
173 preview data will be calculated.
176 input parameter - constant reference to the offset the given page has
177 in the current preview window.
178 Note: Offset can be negative.
181 output parameter - calculated preview data.
183 @return boolean, indicating, if calculation was successful.
185 bool _CalcPreviewDataForPage( const SwPageFrm
& _rPage
,
186 const Point
& _rPrevwOffset
,
187 PrevwPage
* _opPrevwPage
);
189 /** calculate preview pages
191 OD 12.12.2002 #103492#
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
203 OD 17.12.2002 #103492#
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
218 OD 17.12.2002 #103492#
222 void _PaintSelectMarkAtPage( const PrevwPage
* _aSelectedPrevwPage
) const;
225 /** constructor of <SwPagePreviewLayout>
227 OD 11.12.2002 #103492#
231 @param _rParentViewShell
232 input parameter - reference to the view shell the page preview
233 layout belongs to. Reference will be hold as member <mrParentViewShell>.
234 Adjustments/Changes at this view shell:
235 (1) Adjustment of the mapping mode at the output device.
236 (2) Change of the zoom at the view options.
237 (3) Preparations for paint of the page preview.
239 @param _rLayoutRootFrm
240 input parameter - constant reference to the root frame of the layout.
241 Reference will be hold as member <mrLayoutRootFrm> in order to get
242 access to the page frames.
244 SwPagePreviewLayout( ViewShell
& _rParentViewShell
,
245 const SwRootFrm
& _rLayoutRootFrm
);
247 /** destructor of <SwPagePreviewLayout>
249 OD 17.12.2002 #103492#
253 inline ~SwPagePreviewLayout()
255 _ClearPrevwPageData();
258 /** init page preview layout
260 OD 11.12.2002 #103492#
261 initialize the page preview settings for a given layout.
263 (1) If parameter <_bCalcScale> is true, mapping mode with calculated
264 scaling is set at the output device and the zoom at the view options of
265 the given view shell is set with the calculated scaling.
270 input parameter - initial number of page columns in the preview.
273 input parameter - initial number of page rows in the preview.
276 input parameter - window size in which the preview will be displayed and
277 for which the scaling will be calculated.
280 input parameter - control, if method should calculate the needed
281 scaling for the proposed preview layout for the given window size
282 and sets the scaling at the output device and the view options.
284 @return boolean, indicating, if preview layout is successful initialized.
286 bool Init( const sal_uInt16 _nCols
,
287 const sal_uInt16 _nRows
,
288 const Size
& _rPxWinSize
,
289 const bool _bCalcScale
292 /** method to adjust page preview layout to document changes
294 OD 18.12.2002 #103492#
298 @return boolean, indicating, if preview layout is successful initialized.
302 /** prepare paint of page preview
304 OD 12.12.2002 #103492#
305 With the valid preview layout settings - calculated and set by method
306 <Init(..)> - the paint of a specific part of the virtual preview
307 document is prepared. The corresponding part is given by either
308 a start page (parameter <_nProposedStartPageNum>) or a absolute position
309 (parameter <_aProposedStartPoint>).
310 The accessibility preview will also be updated via a corresponding
312 OD 21.03.2003 #108282# - delete parameter _onStartPageVirtNum
316 @param _nProposedStartPageNum [0..<number of document pages>]
317 input parameter - proposed number of page, which should be painted in
318 the left-top-corner in the current output device. input parameter
319 <_bStartWithPageAtFirstCol> influences, if proposed page is actual
320 painted in the left-top-corner.
322 @param _nProposedStartPos [(0,0)..<PreviewDocumentSize>]
323 input parameter - proposed absolute position in the virtual preview
324 document, which should be painted in the left-top-corner in the current
328 input parameter - pixel size of window the preview will be painted in.
330 @param _onStartPageNum
331 output parameter - physical number of page, which will be painted in the
332 left-top-corner in the current output device.
334 @param _orDocPreviewPaintRect
335 output parameter - rectangle of preview document, which will be painted.
337 @param _bStartWithPageAtFirstCol
338 input parameter with default value "true" - controls, if start page
339 is set to page in first column the proposed start page is located.
341 @return boolean, indicating, if prepare of preview paint was successful.
343 bool Prepare( const sal_uInt16 _nProposedStartPageNum
,
344 const Point _aProposedStartPos
,
345 const Size
& _rPxWinSize
,
346 sal_uInt16
& _onStartPageNum
,
347 Rectangle
& _orDocPreviewPaintRect
,
348 const bool _bStartWithPageAtFirstCol
= true
351 /** get selected page number
353 OD 13.12.2002 #103492#
357 inline sal_uInt16
SelectedPage()
359 return mnSelectedPageNum
;
362 /** set selected page number
364 OD 14.01.2003 #103492#
368 inline void SetSelectedPage( sal_uInt16 _nSelectedPageNum
)
370 mnSelectedPageNum
= _nSelectedPageNum
;
373 /** paint prepared preview
375 OD 12.12.2002 #103492#
380 input parameter - Twip rectangle of window, which should be painted.
382 @return boolean, indicating, if paint of preview was performed
384 bool Paint( const Rectangle _aOutRect
) const;
386 /** repaint pages on page preview
388 OD 18.12.2002 #103492#
389 method to invalidate visible pages due to changes in a different
394 void Repaint( const Rectangle _aInvalidCoreRect
) const;
396 /** paint to mark new selected page
398 OD 17.12.2002 #103492#
399 Perform paint for current selected page in order to unmark it.
400 Set new selected page and perform paint to mark this page.
404 @param _nNewSelectedPage
405 input parameter - physical number of page, which will be marked as selected.
407 void MarkNewSelectedPage( const sal_uInt16 _nSelectedPage
);
409 /** calculate start position for new scale
411 OD 12.12.2002 #103492#
412 calculate new start position for a new scale. Calculation bases on the
413 current visible part of the document arranged in the given preview layout.
415 (1) new scaling is already set at the given output device.
419 @return Point, start position for new scale
421 Point
GetPreviewStartPosForNewScale( const Fraction
& _aNewScale
,
422 const Fraction
& _aOldScale
,
423 const Size
& _aNewWinSize
) const;
425 /** determines, if page with given page number is visible in preview
427 OD 12.12.2002 #103492#
432 input parameter - physical number of page, for which it will be
433 determined, if it is visible.
435 @return boolean, indicating, if page with given page number is visible
438 bool IsPageVisible( const sal_uInt16 _nPageNum
) const;
440 /** calculate data to bring new selected page into view.
442 OD 12.12.2002 #103492#
447 input parameter - positive/negative number of columns the current
448 selected page have to be moved.
451 input parameter - positive/negative number of rows the current
452 selected page have to be moved.
454 @param _orNewSelectedPage
455 output parameter - number of new selected page
457 @param _orNewStartPage
458 output parameter - number of new start page
460 @param _orNewStartPos
461 output parameter - new start position in document preview
463 @return boolean - indicating, that move was sucessful.
465 bool CalcStartValuesForSelectedPageMove( const sal_Int16 _nHoriMove
,
466 const sal_Int16 _nVertMove
,
467 sal_uInt16
& _orNewSelectedPage
,
468 sal_uInt16
& _orNewStartPage
,
469 Point
& _orNewStartPos
) const;
471 /** checks, if given position is inside a shown document page
473 OD 17.12.2002 #103492#
478 input parameter - position inside the visible preview window.
481 output parameter - corresponding position in the document, if given
482 preview position is inside a shown document page, not an empty page.
483 If not, it's value is <Point( 0, 0 )>.
485 @param _obPosInEmptyPage
486 output parameter - indicates, that given preview position lays inside
490 output parameter - corresponding physical number of page, if given
491 preview position is inside a shown document page, considers also empty
492 pages. If not, it's value is <0>.
494 @return boolean - indicating, that given preview position lays inside
495 a shown document preview page, not an empty page.
497 bool IsPrevwPosInDocPrevwPage( const Point _aPrevwPos
,
499 bool& _obPosInEmptyPage
,
500 sal_uInt16
& _onPageNum
) const;
502 inline bool DoesPreviewLayoutRowsFitIntoWindow() const
504 return mbDoesLayoutRowsFitIntoWindow
;
507 inline bool DoesPreviewLayoutColsFitIntoWindow() const
509 return mbDoesLayoutColsFitIntoWindow
;
512 inline bool PreviewLayoutValid() const
514 return mbLayoutInfoValid
&& mbLayoutSizesValid
&& mbPaintInfoValid
;
517 /** determine preview window page scroll amount
519 OD 17.12.2002 #103492#
523 @param _nWinPagesToScroll
524 input parameter - number of preview window pages the scroll amount has
525 to be calculated for. Negative values for preview window page up
526 scrolling, positive values for preview window page down scrolling.
528 @return scroll amount in SwTwips
530 SwTwips
GetWinPagesScrollAmount( const sal_Int16 _nWinPagesToScroll
) const;
532 /** determine row the page with the given number is in
534 OD 17.01.2003 #103492#
539 input parameter - physical page number of page, for which the row in
540 preview layout has to be calculated.
542 @return number of row the page with the given physical page number is in
544 sal_uInt16
GetRowOfPage( sal_uInt16 _nPageNum
) const;
546 /** determine column the page with the given number is in
548 OD 17.01.2003 #103492#
553 input parameter - physical page number of page, for which the column in
554 preview layout has to be calculated.
556 @return number of column the page with the given physical page number is in
558 sal_uInt16
GetColOfPage( sal_uInt16 _nPageNum
) const;
560 // OD 18.12.2002 #103492#
561 Size
GetMaxPageSize() const;
563 // OD 18.12.2002 #103492#
564 Size
GetPrevwDocSize() const;
566 /** get size of a preview page by its physical page number
568 OD 15.01.2003 #103492#
573 input parameter - pysical page number of preview page, for which the
574 page size has to be returned.
576 @return an object of class <Size>
578 Size
GetPrevwPageSizeByPageNum( sal_uInt16 _nPageNum
) const;
580 /** get virtual page number by its physical page number
582 OD 21.03.2003 #108282#
587 input parameter - pysical page number of preview page, for which the
588 virtual page number has to be determined.
590 @return virtual page number of page given by its physical page number,
591 if the page is in the current preview pages vector, otherwise 0.
593 sal_uInt16
GetVirtPageNumByPageNum( sal_uInt16 _nPageNum
) const;
595 /** enable/disable book preview
597 OD 2004-03-04 #i18143#
601 bool SetBookPreviewMode( const bool _bEnableBookPreview
,
602 sal_uInt16
& _onStartPageNum
,
603 Rectangle
& _orDocPreviewPaintRect
);
605 /** Convert relative to absolute page numbers (see PrintEmptyPages)
609 sal_uInt16
ConvertRelativeToAbsolutePageNum( sal_uInt16 _nRelPageNum
) const;
611 /** Convert absolute to relative page numbers (see PrintEmptyPages)
615 sal_uInt16
ConvertAbsoluteToRelativePageNum( sal_uInt16 _nAbsPageNum
) const;
617 /** get the number of preview pages
621 sal_uInt16
GetNumberOfPreviewPages() { return sal::static_int_cast
< sal_uInt16
>(maPrevwPages
.size()); }
624 #endif // _PAGEPREVIEWLAYOUT_HXX