xref: /aoo4110/main/sw/inc/pagepreviewlayout.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef _PAGEPREVIEWLAYOUT_HXX
23 #define _PAGEPREVIEWLAYOUT_HXX
24 
25 // template class <std::vector>
26 #include <vector>
27 // datatypes sal_xyz
28 #include <sal/types.h>
29 // classes <Point>, <Size> and <Rectangle>
30 #include <tools/gen.hxx>
31 // datatype <SwTwips>
32 #include <swtypes.hxx>
33 
34 class ViewShell;
35 class SwRootFrm;
36 class SwPageFrm;
37 class Fraction;
38 struct PrevwPage;
39 
40 // =============================================================================
41 /** page preview functionality in the writer
42 
43     OD 11.12.2002 #103492# - class <SwPagePreviewLayout>
44 
45     @author OD
46 */
47 class SwPagePreviewLayout
48 {
49 private:
50     friend class ViewShell;
51 
52     // number of horizontal and vertical twips for spacing between the pages.
53     const SwTwips mnXFree;
54     const SwTwips mnYFree;
55 
56     // view shell the print preview is generated for.
57     ViewShell& mrParentViewShell;
58     // top layout frame of the layout for accessing the pages
59     const SwRootFrm& mrLayoutRootFrm;
60 
61     // boolean indicating, if the layout information (number of columns and rows)
62     // are valid.
63     bool        mbLayoutInfoValid;
64     // boolean indicating, if the the calculated print preview layout sizes
65     // ( windows size in twips, maximal page size, column width, row height,
66     //   width and height of a print preview page, size of the print preview
67     //   document ) are valid
68     bool        mbLayoutSizesValid;
69     // boolean indicating, if the the paint information ( physical number of
70     //   start page, start column and row, paint offsets, rectangle visible of
71     //   the print preview document.
72     bool        mbPaintInfoValid;
73 
74     Size        maWinSize;
75     sal_uInt16  mnCols;
76     sal_uInt16  mnRows;
77     sal_uInt16  mnPages;
78     // OD 19.02.2003 #107369# - new flag for leaving blank left-top-corner
79     // OD 2004-03-05 #i18143# - the book preview is controlled by this flag
80     bool        mbBookPreview;
81     bool        mbBookPreviewModeToggled;
82 
83     Size        maMaxPageSize;
84     Rectangle   maPreviewDocRect;
85     SwTwips     mnColWidth;
86     SwTwips     mnRowHeight;
87     SwTwips     mnPrevwLayoutWidth;
88     SwTwips     mnPrevwLayoutHeight;
89     bool        mbDoesLayoutColsFitIntoWindow;
90     bool        mbDoesLayoutRowsFitIntoWindow;
91 
92     sal_uInt16  mnPaintPhyStartPageNum;
93     sal_uInt16  mnPaintStartCol;
94     sal_uInt16  mnPaintStartRow;
95     bool        mbNoPageVisible;
96     Point       maPaintStartPageOffset;
97     Point       maPaintPreviewDocOffset;
98     Point       maAdditionalPaintOffset;
99     Rectangle   maPaintedPrevwDocRect;
100     sal_uInt16  mnSelectedPageNum;
101 
102     std::vector<PrevwPage*> maPrevwPages;
103 
104     // OD 07.11.2003 #i22014# - internal booleans to indicate, that a new print
105     // preview layout has been created during a paint.
106     mutable bool mbInPaint;
107     mutable bool mbNewLayoutDuringPaint;
108 
109     bool mbPrintEmptyPages;
110 
111     /** clear internal data about current page preview
112 
113         OD 11.12.2002 #103492#
114 
115         @author OD
116     */
117     void _Clear();
118 
119     /** helper method to clear preview page layout sizes
120 
121         OD 18.12.2002 #103492#
122 
123         @author OD
124     */
125     void _ClearPrevwLayoutSizes();
126 
127     /** helper method to clear data in preview page vectors
128 
129         OD 13.12.2002 #103492#
130 
131         @author OD
132     */
133     void _ClearPrevwPageData();
134 
135     /** calculate page preview layout sizes
136 
137         OD 18.12.2002 #103492#
138 
139         @author OD
140     */
141     void _CalcPrevwLayoutSizes();
142 
143     /** apply new zoom at given view shell
144 
145         OD 11.12.2002 #103492#
146 
147         @author OD
148 
149         @param _aNewZoom
150         input parameter - new zoom percentage
151     */
152     void _ApplyNewZoomAtViewShell( sal_uInt8 _aNewZoom );
153 
154     /** calculate additional paint offset
155 
156         OD 12.12.2002 #103492#
157         helper method called by <Prepare> in order to calculate an additional
158         paint offset to center output in given window size.
159         The booleans <mbDoesLayoutRowsFitIntoWindow> and <mbDoesLayoutColsFitIntoWindow>
160         are also determined.
161         preconditions:
162         (1) preview layout is given (number of rows and columns).
163         (2) window size is given.
164         (3) height of row and width of column are calculated.
165         (4) paint offset of start page is calculated.
166 
167         @author OD
168     */
169     void _CalcAdditionalPaintOffset();
170 
171     /** calculate painted preview document rectangle
172 
173         OD 12.12.2002 #103492#
174         helper method called by <Prepare> in order to calculate the rectangle,
175         which will be painted for the document arranged by the given preview
176         layout.
177         preconditions:
178         (1) paint offset of document preview is calculated.
179         (2) size of document preview is calculated.
180         (3) additional paint offset is calculated - see <_CalcAdditionalPaintOffset>.
181 
182         @author OD
183     */
184     void _CalcDocPrevwPaintRect();
185 
186     /** determines preview data for a given page and a given preview offset
187 
188         OD 13.12.2002 #103492#
189 
190         @author OD
191 
192         @param _rPage
193         input parameter - constant reference to page frame, for which the
194         preview data will be calculated.
195 
196         @param _rPrevwOffset
197         input parameter - constant reference to the offset the given page has
198         in the current preview window.
199         Note: Offset can be negative.
200 
201         @param _opPrevwPage
202         output parameter - calculated preview data.
203 
204         @return boolean, indicating, if calculation was successful.
205     */
206     bool _CalcPreviewDataForPage( const SwPageFrm& _rPage,
207                                   const Point& _rPrevwOffset,
208                                   PrevwPage* _opPrevwPage );
209 
210     /** calculate preview pages
211 
212         OD 12.12.2002 #103492#
213         helper method called by <Prepare> in order to determine which pages
214         will be visible in the current preview and calculate the data needed
215         to paint these pages. Also the accessible pages with its needed data
216         are determined.
217 
218         @author OD
219     */
220     void _CalcPreviewPages();
221 
222     /** get preview page by physical page number
223 
224         OD 17.12.2002 #103492#
225 
226         @author OD
227 
228         @param _nPageNum
229         input parameter - physical page number of page, for which the preview
230         page will be returned.
231 
232         @return pointer to preview page of current preview pages. If page doesn't
233         belongs to current preview pages, <0> is returned.
234     */
235     const PrevwPage* _GetPrevwPageByPageNum( const sal_uInt16 _nPageNum ) const;
236 
237     /** paint selection mark at page
238 
239         OD 17.12.2002 #103492#
240 
241         @author OD
242     */
243     void _PaintSelectMarkAtPage( const PrevwPage* _aSelectedPrevwPage ) const;
244 
245 public:
246     /** constructor of <SwPagePreviewLayout>
247 
248         OD 11.12.2002 #103492#
249 
250         @author OD
251 
252         @param _rParentViewShell
253         input parameter - reference to the view shell the page preview
254         layout belongs to. Reference will be hold as member <mrParentViewShell>.
255         Adjustments/Changes at this view shell:
256         (1) Adjustment of the mapping mode at the output device.
257         (2) Change of the zoom at the view options.
258         (3) Preparations for paint of the page preview.
259 
260         @param _rLayoutRootFrm
261         input parameter - constant reference to the root frame of the layout.
262         Reference will be hold as member <mrLayoutRootFrm> in order to get
263         access to the page frames.
264     */
265     SwPagePreviewLayout( ViewShell& _rParentViewShell,
266                          const SwRootFrm&    _rLayoutRootFrm );
267 
268     /** destructor of <SwPagePreviewLayout>
269 
270         OD 17.12.2002 #103492#
271 
272         @author
273     */
~SwPagePreviewLayout()274     inline ~SwPagePreviewLayout()
275     {
276         _ClearPrevwPageData();
277     }
278 
279     /** init page preview layout
280 
281         OD 11.12.2002 #103492#
282         initialize the page preview settings for a given layout.
283         side effects:
284         (1) If parameter <_bCalcScale> is true, mapping mode with calculated
285         scaling is set at the output device and the zoom at the view options of
286         the given view shell is set with the calculated scaling.
287 
288         @author OD
289 
290         @param _nCols
291         input parameter - initial number of page columns in the preview.
292 
293         @param _nRows
294         input parameter - initial number of page rows in the preview.
295 
296         @param _rPxWinSize
297         input parameter - window size in which the preview will be displayed and
298         for which the scaling will be calculated.
299 
300         @param _bCalcScale
301         input parameter - control, if method should calculate the needed
302         scaling for the proposed preview layout for the given window size
303         and sets the scaling at the output device and the view options.
304 
305         @return boolean, indicating, if preview layout is successful initialized.
306     */
307     bool Init( const sal_uInt16 _nCols,
308                const sal_uInt16 _nRows,
309                const Size&      _rPxWinSize,
310                const bool       _bCalcScale
311               );
312 
313     /** method to adjust page preview layout to document changes
314 
315         OD 18.12.2002 #103492#
316 
317         @author OD
318 
319         @return boolean, indicating, if preview layout is successful initialized.
320     */
321     bool ReInit();
322 
323     /** prepare paint of page preview
324 
325         OD 12.12.2002 #103492#
326         With the valid preview layout settings - calculated and set by method
327         <Init(..)> - the paint of a specific part of the virtual preview
328         document is prepared. The corresponding part is given by either
329         a start page (parameter <_nProposedStartPageNum>) or a absolute position
330         (parameter <_aProposedStartPoint>).
331         The accessibility preview will also be updated via a corresponding
332         method call.
333         OD 21.03.2003 #108282# - delete parameter _onStartPageVirtNum
334 
335         @author OD
336 
337         @param _nProposedStartPageNum [0..<number of document pages>]
338         input parameter - proposed number of page, which should be painted in
339         the left-top-corner in the current output device. input parameter
340         <_bStartWithPageAtFirstCol> influences, if proposed page is actual
341         painted in the left-top-corner.
342 
343         @param _nProposedStartPos [(0,0)..<PreviewDocumentSize>]
344         input parameter - proposed absolute position in the virtual preview
345         document, which should be painted in the left-top-corner in the current
346         output device.
347 
348         @param _rPxWinSize
349         input parameter - pixel size of window the preview will be painted in.
350 
351         @param _onStartPageNum
352         output parameter - physical number of page, which will be painted in the
353         left-top-corner in the current output device.
354 
355         @param _orDocPreviewPaintRect
356         output parameter - rectangle of preview document, which will be painted.
357 
358         @param _bStartWithPageAtFirstCol
359         input parameter with default value "true" - controls, if start page
360         is set to page in first column the proposed start page is located.
361 
362         @return boolean, indicating, if prepare of preview paint was successful.
363     */
364     bool Prepare( const sal_uInt16 _nProposedStartPageNum,
365                   const Point      _aProposedStartPos,
366                   const Size&      _rPxWinSize,
367                   sal_uInt16&      _onStartPageNum,
368                   Rectangle&       _orDocPreviewPaintRect,
369                   const bool       _bStartWithPageAtFirstCol = true
370                 );
371 
372     /** get selected page number
373 
374         OD 13.12.2002 #103492#
375 
376         @author OD
377     */
SelectedPage()378     inline sal_uInt16 SelectedPage()
379     {
380         return mnSelectedPageNum;
381     }
382 
383     /** set selected page number
384 
385         OD 14.01.2003 #103492#
386 
387         @author OD
388     */
SetSelectedPage(sal_uInt16 _nSelectedPageNum)389     inline void SetSelectedPage( sal_uInt16 _nSelectedPageNum )
390     {
391         mnSelectedPageNum = _nSelectedPageNum;
392     }
393 
394     /** paint prepared preview
395 
396         OD 12.12.2002 #103492#
397 
398         @author OD
399 
400         @param _aOutRect
401         input parameter - Twip rectangle of window, which should be painted.
402 
403         @return boolean, indicating, if paint of preview was performed
404     */
405     bool Paint( const Rectangle _aOutRect ) const;
406 
407     /** repaint pages on page preview
408 
409         OD 18.12.2002 #103492#
410         method to invalidate visible pages due to changes in a different
411         view shell.
412 
413         @author OD
414     */
415     void Repaint( const Rectangle _aInvalidCoreRect ) const;
416 
417     /** paint to mark new selected page
418 
419         OD 17.12.2002 #103492#
420         Perform paint for current selected page in order to unmark it.
421         Set new selected page and perform paint to mark this page.
422 
423         @author OD
424 
425         @param _nNewSelectedPage
426         input parameter - physical number of page, which will be marked as selected.
427     */
428     void MarkNewSelectedPage( const sal_uInt16 _nSelectedPage );
429 
430     /** calculate start position for new scale
431 
432         OD 12.12.2002 #103492#
433         calculate new start position for a new scale. Calculation bases on the
434         current visible part of the document arranged in the given preview layout.
435         preconditions:
436         (1) new scaling is already set at the given output device.
437 
438         @author OD
439 
440         @return Point, start position for new scale
441     */
442     Point GetPreviewStartPosForNewScale( const Fraction& _aNewScale,
443                                          const Fraction& _aOldScale,
444                                          const Size&     _aNewWinSize ) const;
445 
446     /** determines, if page with given page number is visible in preview
447 
448         OD 12.12.2002 #103492#
449 
450         @author OD
451 
452         @param _nPageNum
453         input parameter - physical number of page, for which it will be
454         determined, if it is visible.
455 
456         @return boolean, indicating, if page with given page number is visible
457         in preview.
458     */
459     bool IsPageVisible( const sal_uInt16 _nPageNum ) const;
460 
461     /** calculate data to bring new selected page into view.
462 
463         OD 12.12.2002 #103492#
464 
465         @author OD
466 
467         @param _nHoriMove
468         input parameter - positive/negative number of columns the current
469         selected page have to be moved.
470 
471         @param _nVertMove
472         input parameter - positive/negative number of rows the current
473         selected page have to be moved.
474 
475         @param _orNewSelectedPage
476         output parameter - number of new selected page
477 
478         @param _orNewStartPage
479         output parameter - number of new start page
480 
481         @param _orNewStartPos
482         output parameter - new start position in document preview
483 
484         @return boolean - indicating, that move was sucessful.
485     */
486     bool CalcStartValuesForSelectedPageMove( const sal_Int16  _nHoriMove,
487                                              const sal_Int16  _nVertMove,
488                                              sal_uInt16&      _orNewSelectedPage,
489                                              sal_uInt16&      _orNewStartPage,
490                                              Point&           _orNewStartPos ) const;
491 
492     /** checks, if given position is inside a shown document page
493 
494         OD 17.12.2002 #103492#
495 
496         @author OD
497 
498         @param _aPrevwPos
499         input parameter - position inside the visible preview window.
500 
501         @param _orDocPos
502         output parameter - corresponding position in the document, if given
503         preview position is inside a shown document page, not an empty page.
504         If not, it's value is <Point( 0, 0 )>.
505 
506         @param _obPosInEmptyPage
507         output parameter - indicates, that given preview position lays inside
508         an shown empty page.
509 
510         @param _onPageNum
511         output parameter - corresponding physical number of page, if given
512         preview position is inside a shown document page, considers also empty
513         pages. If not, it's value is <0>.
514 
515         @return boolean - indicating, that given preview position lays inside
516         a shown document preview page, not an empty page.
517     */
518     bool IsPrevwPosInDocPrevwPage( const Point  _aPrevwPos,
519                                    Point&       _orDocPos,
520                                    bool&        _obPosInEmptyPage,
521                                    sal_uInt16&  _onPageNum ) const;
522 
DoesPreviewLayoutRowsFitIntoWindow() const523     inline bool DoesPreviewLayoutRowsFitIntoWindow() const
524     {
525         return mbDoesLayoutRowsFitIntoWindow;
526     }
527 
DoesPreviewLayoutColsFitIntoWindow() const528     inline bool DoesPreviewLayoutColsFitIntoWindow() const
529     {
530         return mbDoesLayoutColsFitIntoWindow;
531     }
532 
PreviewLayoutValid() const533     inline bool PreviewLayoutValid() const
534     {
535         return mbLayoutInfoValid && mbLayoutSizesValid && mbPaintInfoValid;
536     }
537 
538     /** determine preview window page scroll amount
539 
540         OD 17.12.2002 #103492#
541 
542         @author OD
543 
544         @param _nWinPagesToScroll
545         input parameter - number of preview window pages the scroll amount has
546         to be calculated for. Negative values for preview window page up
547         scrolling, positive values for preview window page down scrolling.
548 
549         @return scroll amount in SwTwips
550     */
551     SwTwips GetWinPagesScrollAmount( const sal_Int16 _nWinPagesToScroll ) const;
552 
553     /** determine row the page with the given number is in
554 
555         OD 17.01.2003 #103492#
556 
557         @author OD
558 
559         @param _nPageNum
560         input parameter - physical page number of page, for which the row in
561         preview layout has to be calculated.
562 
563         @return number of row the page with the given physical page number is in
564     */
565     sal_uInt16 GetRowOfPage( sal_uInt16 _nPageNum ) const;
566 
567     /** determine column the page with the given number is in
568 
569         OD 17.01.2003 #103492#
570 
571         @author OD
572 
573         @param _nPageNum
574         input parameter - physical page number of page, for which the column in
575         preview layout has to be calculated.
576 
577         @return number of column the page with the given physical page number is in
578     */
579     sal_uInt16 GetColOfPage( sal_uInt16 _nPageNum ) const;
580 
581     // OD 18.12.2002 #103492#
582     Size GetPrevwDocSize() const;
583 
584     /** get size of a preview page by its physical page number
585 
586         OD 15.01.2003 #103492#
587 
588         @author OD
589 
590         @param _nPageNum
591         input parameter - pysical page number of preview page, for which the
592         page size has to be returned.
593 
594         @return an object of class <Size>
595     */
596     Size GetPrevwPageSizeByPageNum( sal_uInt16 _nPageNum ) const;
597 
598     /** get virtual page number by its physical page number
599 
600         OD 21.03.2003 #108282#
601 
602         @author OD
603 
604         @param _nPageNum
605         input parameter - pysical page number of preview page, for which the
606         virtual page number has to be determined.
607 
608         @return virtual page number of page given by its physical page number,
609         if the page is in the current preview pages vector, otherwise 0.
610     */
611     sal_uInt16 GetVirtPageNumByPageNum( sal_uInt16 _nPageNum ) const;
612 
613     /** enable/disable book preview
614 
615         OD 2004-03-04 #i18143#
616 
617         @author OD
618     */
619     bool SetBookPreviewMode( const bool  _bEnableBookPreview,
620                              sal_uInt16& _onStartPageNum,
621                              Rectangle&  _orDocPreviewPaintRect );
622 
623     /** Convert relative to absolute page numbers (see PrintEmptyPages)
624 
625         @author FME
626     */
627     sal_uInt16 ConvertRelativeToAbsolutePageNum( sal_uInt16 _nRelPageNum ) const;
628 
629     /** Convert absolute to relative page numbers (see PrintEmptyPages)
630 
631         @author FME
632     */
633     sal_uInt16 ConvertAbsoluteToRelativePageNum( sal_uInt16 _nAbsPageNum ) const;
634 
635     /** get the number of preview pages
636 
637         @author FME
638     */
GetNumberOfPreviewPages()639     sal_uInt16 GetNumberOfPreviewPages() { return sal::static_int_cast< sal_uInt16 >(maPrevwPages.size()); }
640 };
641 
642 #endif // _PAGEPREVIEWLAYOUT_HXX
643