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