merge the formfield patch from ooo-build
[ooovba.git] / sw / inc / pagepreviewlayout.hxx
blob589e2850b1ab37f25cb9760ce33d2eb297fb50ec
1 #ifndef _PAGEPREVIEWLAYOUT_HXX
2 #define _PAGEPREVIEWLAYOUT_HXX
4 // template class <std::vector>
5 #include <vector>
6 // datatypes sal_xyz
7 #include <sal/types.h>
8 // classes <Point>, <Size> and <Rectangle>
9 #include <tools/gen.hxx>
10 // datatype <SwTwips>
11 #include <swtypes.hxx>
13 class ViewShell;
14 class SwRootFrm;
15 class SwPageFrm;
16 class Fraction;
17 struct PrevwPage;
19 // =============================================================================
20 /** page preview functionality in the writer
22 OD 11.12.2002 #103492# - class <SwPagePreviewLayout>
24 @author OD
26 class SwPagePreviewLayout
28 private:
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)
41 // are valid.
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;
53 Size maWinSize;
54 sal_uInt16 mnCols;
55 sal_uInt16 mnRows;
56 sal_uInt16 mnPages;
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
59 bool mbBookPreview;
60 bool mbBookPreviewModeToggled;
62 Size maMaxPageSize;
63 Rectangle maPreviewDocRect;
64 SwTwips mnColWidth;
65 SwTwips mnRowHeight;
66 SwTwips mnPrevwLayoutWidth;
67 SwTwips mnPrevwLayoutHeight;
68 bool mbDoesLayoutColsFitIntoWindow;
69 bool mbDoesLayoutRowsFitIntoWindow;
71 sal_uInt16 mnPaintPhyStartPageNum;
72 sal_uInt16 mnPaintStartCol;
73 sal_uInt16 mnPaintStartRow;
74 bool mbNoPageVisible;
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#
94 @author OD
96 void _Clear();
98 /** helper method to clear preview page layout sizes
100 OD 18.12.2002 #103492#
102 @author OD
104 void _ClearPrevwLayoutSizes();
106 /** helper method to clear data in preview page vectors
108 OD 13.12.2002 #103492#
110 @author OD
112 void _ClearPrevwPageData();
114 /** calculate page preview layout sizes
116 OD 18.12.2002 #103492#
118 @author OD
120 void _CalcPrevwLayoutSizes();
122 /** apply new zoom at given view shell
124 OD 11.12.2002 #103492#
126 @author OD
128 @param _aNewZoom
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>
139 are also determined.
140 preconditions:
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.
146 @author OD
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
155 layout.
156 preconditions:
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>.
161 @author OD
163 void _CalcDocPrevwPaintRect();
165 /** determines preview data for a given page and a given preview offset
167 OD 13.12.2002 #103492#
169 @author OD
171 @param _rPage
172 input parameter - constant reference to page frame, for which the
173 preview data will be calculated.
175 @param _rPrevwOffset
176 input parameter - constant reference to the offset the given page has
177 in the current preview window.
178 Note: Offset can be negative.
180 @param _opPrevwPage
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
195 are determined.
197 @author OD
199 void _CalcPreviewPages();
201 /** get preview page by physical page number
203 OD 17.12.2002 #103492#
205 @author OD
207 @param _nPageNum
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#
220 @author OD
222 void _PaintSelectMarkAtPage( const PrevwPage* _aSelectedPrevwPage ) const;
224 public:
225 /** constructor of <SwPagePreviewLayout>
227 OD 11.12.2002 #103492#
229 @author OD
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#
251 @author
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.
262 side effects:
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.
267 @author OD
269 @param _nCols
270 input parameter - initial number of page columns in the preview.
272 @param _nRows
273 input parameter - initial number of page rows in the preview.
275 @param _rPxWinSize
276 input parameter - window size in which the preview will be displayed and
277 for which the scaling will be calculated.
279 @param _bCalcScale
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#
296 @author OD
298 @return boolean, indicating, if preview layout is successful initialized.
300 bool ReInit();
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
311 method call.
312 OD 21.03.2003 #108282# - delete parameter _onStartPageVirtNum
314 @author OD
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
325 output device.
327 @param _rPxWinSize
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#
355 @author OD
357 inline sal_uInt16 SelectedPage()
359 return mnSelectedPageNum;
362 /** set selected page number
364 OD 14.01.2003 #103492#
366 @author OD
368 inline void SetSelectedPage( sal_uInt16 _nSelectedPageNum )
370 mnSelectedPageNum = _nSelectedPageNum;
373 /** paint prepared preview
375 OD 12.12.2002 #103492#
377 @author OD
379 @param _aOutRect
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
390 view shell.
392 @author OD
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.
402 @author OD
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.
414 preconditions:
415 (1) new scaling is already set at the given output device.
417 @author OD
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#
429 @author OD
431 @param _nPageNum
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
436 in preview.
438 bool IsPageVisible( const sal_uInt16 _nPageNum ) const;
440 /** calculate data to bring new selected page into view.
442 OD 12.12.2002 #103492#
444 @author OD
446 @param _nHoriMove
447 input parameter - positive/negative number of columns the current
448 selected page have to be moved.
450 @param _nVertMove
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#
475 @author OD
477 @param _aPrevwPos
478 input parameter - position inside the visible preview window.
480 @param _orDocPos
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
487 an shown empty page.
489 @param _onPageNum
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,
498 Point& _orDocPos,
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#
521 @author OD
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#
536 @author OD
538 @param _nPageNum
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#
550 @author OD
552 @param _nPageNum
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#
570 @author OD
572 @param _nPageNum
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#
584 @author OD
586 @param _nPageNum
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#
599 @author OD
601 bool SetBookPreviewMode( const bool _bEnableBookPreview,
602 sal_uInt16& _onStartPageNum,
603 Rectangle& _orDocPreviewPaintRect );
605 /** Convert relative to absolute page numbers (see PrintEmptyPages)
607 @author FME
609 sal_uInt16 ConvertRelativeToAbsolutePageNum( sal_uInt16 _nRelPageNum ) const;
611 /** Convert absolute to relative page numbers (see PrintEmptyPages)
613 @author FME
615 sal_uInt16 ConvertAbsoluteToRelativePageNum( sal_uInt16 _nAbsPageNum ) const;
617 /** get the number of preview pages
619 @author FME
621 sal_uInt16 GetNumberOfPreviewPages() { return sal::static_int_cast< sal_uInt16 >(maPrevwPages.size()); }
624 #endif // _PAGEPREVIEWLAYOUT_HXX