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