xref: /aoo41x/main/sw/inc/pagepreviewlayout.hxx (revision cdf0e10c)
1 #ifndef _PAGEPREVIEWLAYOUT_HXX
2 #define _PAGEPREVIEWLAYOUT_HXX
3 
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>
12 
13 class ViewShell;
14 class SwRootFrm;
15 class SwPageFrm;
16 class Fraction;
17 struct PrevwPage;
18 
19 // =============================================================================
20 /** page preview functionality in the writer
21 
22     OD 11.12.2002 #103492# - class <SwPagePreviewLayout>
23 
24     @author OD
25 */
26 class SwPagePreviewLayout
27 {
28 private:
29     friend class ViewShell;
30 
31     // number of horizontal and vertical twips for spacing between the pages.
32     const SwTwips mnXFree;
33     const SwTwips mnYFree;
34 
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;
39 
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;
52 
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;
61 
62     Size        maMaxPageSize;
63     Rectangle   maPreviewDocRect;
64     SwTwips     mnColWidth;
65     SwTwips     mnRowHeight;
66     SwTwips     mnPrevwLayoutWidth;
67     SwTwips     mnPrevwLayoutHeight;
68     bool        mbDoesLayoutColsFitIntoWindow;
69     bool        mbDoesLayoutRowsFitIntoWindow;
70 
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;
80 
81     std::vector<PrevwPage*> maPrevwPages;
82 
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;
87 
88     bool mbPrintEmptyPages;
89 
90     /** clear internal data about current page preview
91 
92         OD 11.12.2002 #103492#
93 
94         @author OD
95     */
96     void _Clear();
97 
98     /** helper method to clear preview page layout sizes
99 
100         OD 18.12.2002 #103492#
101 
102         @author OD
103     */
104     void _ClearPrevwLayoutSizes();
105 
106     /** helper method to clear data in preview page vectors
107 
108         OD 13.12.2002 #103492#
109 
110         @author OD
111     */
112     void _ClearPrevwPageData();
113 
114     /** calculate page preview layout sizes
115 
116         OD 18.12.2002 #103492#
117 
118         @author OD
119     */
120     void _CalcPrevwLayoutSizes();
121 
122     /** apply new zoom at given view shell
123 
124         OD 11.12.2002 #103492#
125 
126         @author OD
127 
128         @param _aNewZoom
129         input parameter - new zoom percentage
130     */
131     void _ApplyNewZoomAtViewShell( sal_uInt8 _aNewZoom );
132 
133     /** calculate additional paint offset
134 
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.
145 
146         @author OD
147     */
148     void _CalcAdditionalPaintOffset();
149 
150     /** calculate painted preview document rectangle
151 
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>.
160 
161         @author OD
162     */
163     void _CalcDocPrevwPaintRect();
164 
165     /** determines preview data for a given page and a given preview offset
166 
167         OD 13.12.2002 #103492#
168 
169         @author OD
170 
171         @param _rPage
172         input parameter - constant reference to page frame, for which the
173         preview data will be calculated.
174 
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.
179 
180         @param _opPrevwPage
181         output parameter - calculated preview data.
182 
183         @return boolean, indicating, if calculation was successful.
184     */
185     bool _CalcPreviewDataForPage( const SwPageFrm& _rPage,
186                                   const Point& _rPrevwOffset,
187                                   PrevwPage* _opPrevwPage );
188 
189     /** calculate preview pages
190 
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.
196 
197         @author OD
198     */
199     void _CalcPreviewPages();
200 
201     /** get preview page by physical page number
202 
203         OD 17.12.2002 #103492#
204 
205         @author OD
206 
207         @param _nPageNum
208         input parameter - physical page number of page, for which the preview
209         page will be returned.
210 
211         @return pointer to preview page of current preview pages. If page doesn't
212         belongs to current preview pages, <0> is returned.
213     */
214     const PrevwPage* _GetPrevwPageByPageNum( const sal_uInt16 _nPageNum ) const;
215 
216     /** paint selection mark at page
217 
218         OD 17.12.2002 #103492#
219 
220         @author OD
221     */
222     void _PaintSelectMarkAtPage( const PrevwPage* _aSelectedPrevwPage ) const;
223 
224 public:
225     /** constructor of <SwPagePreviewLayout>
226 
227         OD 11.12.2002 #103492#
228 
229         @author OD
230 
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.
238 
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.
243     */
244     SwPagePreviewLayout( ViewShell& _rParentViewShell,
245                          const SwRootFrm&    _rLayoutRootFrm );
246 
247     /** destructor of <SwPagePreviewLayout>
248 
249         OD 17.12.2002 #103492#
250 
251         @author
252     */
253     inline ~SwPagePreviewLayout()
254     {
255         _ClearPrevwPageData();
256     }
257 
258     /** init page preview layout
259 
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.
266 
267         @author OD
268 
269         @param _nCols
270         input parameter - initial number of page columns in the preview.
271 
272         @param _nRows
273         input parameter - initial number of page rows in the preview.
274 
275         @param _rPxWinSize
276         input parameter - window size in which the preview will be displayed and
277         for which the scaling will be calculated.
278 
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.
283 
284         @return boolean, indicating, if preview layout is successful initialized.
285     */
286     bool Init( const sal_uInt16 _nCols,
287                const sal_uInt16 _nRows,
288                const Size&      _rPxWinSize,
289                const bool       _bCalcScale
290               );
291 
292     /** method to adjust page preview layout to document changes
293 
294         OD 18.12.2002 #103492#
295 
296         @author OD
297 
298         @return boolean, indicating, if preview layout is successful initialized.
299     */
300     bool ReInit();
301 
302     /** prepare paint of page preview
303 
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
313 
314         @author OD
315 
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.
321 
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.
326 
327         @param _rPxWinSize
328         input parameter - pixel size of window the preview will be painted in.
329 
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.
333 
334         @param _orDocPreviewPaintRect
335         output parameter - rectangle of preview document, which will be painted.
336 
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.
340 
341         @return boolean, indicating, if prepare of preview paint was successful.
342     */
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
349                 );
350 
351     /** get selected page number
352 
353         OD 13.12.2002 #103492#
354 
355         @author OD
356     */
357     inline sal_uInt16 SelectedPage()
358     {
359         return mnSelectedPageNum;
360     }
361 
362     /** set selected page number
363 
364         OD 14.01.2003 #103492#
365 
366         @author OD
367     */
368     inline void SetSelectedPage( sal_uInt16 _nSelectedPageNum )
369     {
370         mnSelectedPageNum = _nSelectedPageNum;
371     }
372 
373     /** paint prepared preview
374 
375         OD 12.12.2002 #103492#
376 
377         @author OD
378 
379         @param _aOutRect
380         input parameter - Twip rectangle of window, which should be painted.
381 
382         @return boolean, indicating, if paint of preview was performed
383     */
384     bool Paint( const Rectangle _aOutRect ) const;
385 
386     /** repaint pages on page preview
387 
388         OD 18.12.2002 #103492#
389         method to invalidate visible pages due to changes in a different
390         view shell.
391 
392         @author OD
393     */
394     void Repaint( const Rectangle _aInvalidCoreRect ) const;
395 
396     /** paint to mark new selected page
397 
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.
401 
402         @author OD
403 
404         @param _nNewSelectedPage
405         input parameter - physical number of page, which will be marked as selected.
406     */
407     void MarkNewSelectedPage( const sal_uInt16 _nSelectedPage );
408 
409     /** calculate start position for new scale
410 
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.
416 
417         @author OD
418 
419         @return Point, start position for new scale
420     */
421     Point GetPreviewStartPosForNewScale( const Fraction& _aNewScale,
422                                          const Fraction& _aOldScale,
423                                          const Size&     _aNewWinSize ) const;
424 
425     /** determines, if page with given page number is visible in preview
426 
427         OD 12.12.2002 #103492#
428 
429         @author OD
430 
431         @param _nPageNum
432         input parameter - physical number of page, for which it will be
433         determined, if it is visible.
434 
435         @return boolean, indicating, if page with given page number is visible
436         in preview.
437     */
438     bool IsPageVisible( const sal_uInt16 _nPageNum ) const;
439 
440     /** calculate data to bring new selected page into view.
441 
442         OD 12.12.2002 #103492#
443 
444         @author OD
445 
446         @param _nHoriMove
447         input parameter - positive/negative number of columns the current
448         selected page have to be moved.
449 
450         @param _nVertMove
451         input parameter - positive/negative number of rows the current
452         selected page have to be moved.
453 
454         @param _orNewSelectedPage
455         output parameter - number of new selected page
456 
457         @param _orNewStartPage
458         output parameter - number of new start page
459 
460         @param _orNewStartPos
461         output parameter - new start position in document preview
462 
463         @return boolean - indicating, that move was sucessful.
464     */
465     bool CalcStartValuesForSelectedPageMove( const sal_Int16  _nHoriMove,
466                                              const sal_Int16  _nVertMove,
467                                              sal_uInt16&      _orNewSelectedPage,
468                                              sal_uInt16&      _orNewStartPage,
469                                              Point&           _orNewStartPos ) const;
470 
471     /** checks, if given position is inside a shown document page
472 
473         OD 17.12.2002 #103492#
474 
475         @author OD
476 
477         @param _aPrevwPos
478         input parameter - position inside the visible preview window.
479 
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 )>.
484 
485         @param _obPosInEmptyPage
486         output parameter - indicates, that given preview position lays inside
487         an shown empty page.
488 
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>.
493 
494         @return boolean - indicating, that given preview position lays inside
495         a shown document preview page, not an empty page.
496     */
497     bool IsPrevwPosInDocPrevwPage( const Point  _aPrevwPos,
498                                    Point&       _orDocPos,
499                                    bool&        _obPosInEmptyPage,
500                                    sal_uInt16&  _onPageNum ) const;
501 
502     inline bool DoesPreviewLayoutRowsFitIntoWindow() const
503     {
504         return mbDoesLayoutRowsFitIntoWindow;
505     }
506 
507     inline bool DoesPreviewLayoutColsFitIntoWindow() const
508     {
509         return mbDoesLayoutColsFitIntoWindow;
510     }
511 
512     inline bool PreviewLayoutValid() const
513     {
514         return mbLayoutInfoValid && mbLayoutSizesValid && mbPaintInfoValid;
515     }
516 
517     /** determine preview window page scroll amount
518 
519         OD 17.12.2002 #103492#
520 
521         @author OD
522 
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.
527 
528         @return scroll amount in SwTwips
529     */
530     SwTwips GetWinPagesScrollAmount( const sal_Int16 _nWinPagesToScroll ) const;
531 
532     /** determine row the page with the given number is in
533 
534         OD 17.01.2003 #103492#
535 
536         @author OD
537 
538         @param _nPageNum
539         input parameter - physical page number of page, for which the row in
540         preview layout has to be calculated.
541 
542         @return number of row the page with the given physical page number is in
543     */
544     sal_uInt16 GetRowOfPage( sal_uInt16 _nPageNum ) const;
545 
546     /** determine column the page with the given number is in
547 
548         OD 17.01.2003 #103492#
549 
550         @author OD
551 
552         @param _nPageNum
553         input parameter - physical page number of page, for which the column in
554         preview layout has to be calculated.
555 
556         @return number of column the page with the given physical page number is in
557     */
558     sal_uInt16 GetColOfPage( sal_uInt16 _nPageNum ) const;
559 
560     // OD 18.12.2002 #103492#
561     Size GetPrevwDocSize() const;
562 
563     /** get size of a preview page by its physical page number
564 
565         OD 15.01.2003 #103492#
566 
567         @author OD
568 
569         @param _nPageNum
570         input parameter - pysical page number of preview page, for which the
571         page size has to be returned.
572 
573         @return an object of class <Size>
574     */
575     Size GetPrevwPageSizeByPageNum( sal_uInt16 _nPageNum ) const;
576 
577     /** get virtual page number by its physical page number
578 
579         OD 21.03.2003 #108282#
580 
581         @author OD
582 
583         @param _nPageNum
584         input parameter - pysical page number of preview page, for which the
585         virtual page number has to be determined.
586 
587         @return virtual page number of page given by its physical page number,
588         if the page is in the current preview pages vector, otherwise 0.
589     */
590     sal_uInt16 GetVirtPageNumByPageNum( sal_uInt16 _nPageNum ) const;
591 
592     /** enable/disable book preview
593 
594         OD 2004-03-04 #i18143#
595 
596         @author OD
597     */
598     bool SetBookPreviewMode( const bool  _bEnableBookPreview,
599                              sal_uInt16& _onStartPageNum,
600                              Rectangle&  _orDocPreviewPaintRect );
601 
602     /** Convert relative to absolute page numbers (see PrintEmptyPages)
603 
604         @author FME
605     */
606     sal_uInt16 ConvertRelativeToAbsolutePageNum( sal_uInt16 _nRelPageNum ) const;
607 
608     /** Convert absolute to relative page numbers (see PrintEmptyPages)
609 
610         @author FME
611     */
612     sal_uInt16 ConvertAbsoluteToRelativePageNum( sal_uInt16 _nAbsPageNum ) const;
613 
614     /** get the number of preview pages
615 
616         @author FME
617     */
618     sal_uInt16 GetNumberOfPreviewPages() { return sal::static_int_cast< sal_uInt16 >(maPrevwPages.size()); }
619 };
620 
621 #endif // _PAGEPREVIEWLAYOUT_HXX
622