1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
24 #include <pagepar.hxx>
25 #include <editutil.hxx>
35 class ScPageBreakData
;
36 class ScPreviewLocationData
;
43 #define RANGENO_NORANGE USHRT_MAX
45 constexpr sal_Int64 PRINT_HEADER_WIDTH
= o3tl::toTwips(1, o3tl::Length::cm
);
46 constexpr sal_Int64 PRINT_HEADER_HEIGHT
= o3tl::toTwips(12.8, o3tl::Length::pt
);
48 // Settings for headers/footers
55 tools::Long nHeight
; // in total (height + distance + frames)
56 tools::Long nManHeight
; // set size (min when dynamic)
58 sal_uInt16 nLeft
; // edges
60 const ScPageHFItem
* pLeft
;
61 const ScPageHFItem
* pRight
;
62 const ScPageHFItem
* pFirst
;
63 const SvxBoxItem
* pBorder
;
64 const SvxBrushItem
* pBack
;
65 const SvxShadowItem
* pShadow
;
74 std::vector
<bool> aHidden
;
75 //! Cache Number of really visible?
78 ScPageRowEntry() { nStartRow
= nEndRow
= 0; nPagesX
= 0; }
80 ScPageRowEntry(const ScPageRowEntry
& r
);
81 ScPageRowEntry
& operator=(const ScPageRowEntry
& r
);
83 SCROW
GetStartRow() const { return nStartRow
; }
84 SCROW
GetEndRow() const { return nEndRow
; }
85 size_t GetPagesX() const { return nPagesX
; }
86 void SetStartRow(SCROW n
) { nStartRow
= n
; }
87 void SetEndRow(SCROW n
) { nEndRow
= n
; }
89 void SetPagesX(size_t nNew
);
90 void SetHidden(size_t nX
);
91 bool IsHidden(size_t nX
) const;
93 size_t CountVisible() const;
99 struct PrintPageRangesInput
106 PrintPageRangesInput()
107 : m_bSkipEmpty(false)
108 , m_bPrintArea(false)
111 PrintPageRangesInput(bool bSkipEmpty
, bool bPrintArea
, ScRange
const& rRange
, Size
const& rDocSize
)
112 : m_bSkipEmpty(bSkipEmpty
)
113 , m_bPrintArea(bPrintArea
)
115 , m_aDocSize(rDocSize
)
118 bool operator==(PrintPageRangesInput
const& rInput
) const
121 m_bSkipEmpty
== rInput
.m_bSkipEmpty
&&
122 m_bPrintArea
== rInput
.m_bPrintArea
&&
123 m_aRange
== rInput
.m_aRange
&&
124 m_aDocSize
== rInput
.m_aDocSize
;
127 PrintPageRangesInput
& operator=(PrintPageRangesInput
const& rInput
)
129 m_bSkipEmpty
= rInput
.m_bSkipEmpty
;
130 m_bPrintArea
= rInput
.m_bPrintArea
;
131 m_aRange
= rInput
.m_aRange
;
132 m_aDocSize
= rInput
.m_aDocSize
;
137 SCROW
getStartRow() const
139 return m_aRange
.aStart
.Row();
142 SCROW
getEndRow() const
144 return m_aRange
.aEnd
.Row();
147 SCCOL
getStartColumn() const
149 return m_aRange
.aStart
.Col();
152 SCCOL
getEndColumn() const
154 return m_aRange
.aEnd
.Col();
157 SCTAB
getPrintTab() const
159 return m_aRange
.aStart
.Tab();
163 class PrintPageRanges
168 // use shared_ptr to avoid copying this (potentially large) data back and forth
169 std::shared_ptr
<std::vector
<SCCOL
>> m_xPageEndX
;
170 std::shared_ptr
<std::vector
<SCROW
>> m_xPageEndY
;
171 std::shared_ptr
<std::map
<size_t, ScPageRowEntry
>> m_xPageRows
;
177 PrintPageRangesInput m_aInput
;
179 void calculate(ScDocument
& rDoc
, PrintPageRangesInput
const& rInput
);
182 } // end sc namespace
184 // Used to save expensive-to-compute data from ScPrintFunc in between
185 // uses of ScPrintFunc
193 bool bPrintAreaValid
; // the 4 variables above are set
195 tools::Long nTabPages
;
196 tools::Long nTotalPages
;
197 tools::Long nPageStart
;
198 tools::Long nDocPages
;
200 // Additional state of page ranges
201 sc::PrintPageRanges m_aRanges
;
209 , bPrintAreaValid(false)
221 ScDocShell
* pDocShell
;
223 VclPtr
<SfxPrinter
> pPrinter
;
224 VclPtr
<OutputDevice
> pDev
;
225 FmFormView
* pDrawView
;
227 MapMode aOldPrinterMode
; // MapMode before the call
229 Point aSrcOffset
; // Paper-1/100 mm
230 Point aOffset
; // scaled by a factor of page size
231 sal_uInt16 nManualZoom
; // Zoom in Preview (percent)
232 bool bClearWin
; // Clear output before
237 tools::Long nPageStart
; // Offset for the first page
238 tools::Long nDocPages
; // Number of Pages in Document
240 const ScRange
* pUserArea
; // Selection, if set in dialog
242 const SfxItemSet
* pParamSet
; // Selected template
243 bool bFromPrintState
; // created from State-struct
245 // Parameter from template:
246 sal_uInt16 nLeftMargin
;
247 sal_uInt16 nTopMargin
;
248 sal_uInt16 nRightMargin
;
249 sal_uInt16 nBottomMargin
;
253 bool bSourceRangeValid
;
255 SvxPageUsage nPageUsage
;
256 Size aPageSize
; // Printer Twips
257 const SvxBoxItem
* pBorderItem
;
258 const SvxBrushItem
* pBackgroundItem
;
259 const SvxShadowItem
* pShadowItem
;
261 ScRange aLastSourceRange
;
264 ScPageTableParam aTableParam
;
265 ScPageAreaParam aAreaParam
;
267 // Calculated values:
269 bool bPrintCurrentTable
;
271 bool mbHasPrintRange
;
272 tools::Long nTabPages
;
273 tools::Long nTotalPages
;
275 tools::Rectangle aPageRect
; // Document Twips
277 MapMode aLogicMode
; // Set in DoPrint
283 SCCOL nRepeatStartCol
;
285 SCROW nRepeatStartRow
;
292 bool bPrintAreaValid
; // the 4 variables above are set
294 sc::PrintPageRanges m_aRanges
;
296 std::unique_ptr
<ScHeaderEditEngine
> pEditEngine
;
297 std::unique_ptr
<SfxItemSet
> pEditDefaults
;
299 ScHeaderFieldData aFieldData
;
301 std::vector
<ScAddress
> aNotePosList
; // The order of notes
303 ScPageBreakData
* pPageData
; // for recording the breaks etc.
305 Size aPrintPageSize
; // print page size in Print dialog
306 bool bPrintPageLandscape
; // print page orientation in Print dialog
307 bool bUsePrintDialogSetting
; // use Print dialog setting
310 ScPrintFunc( ScDocShell
* pShell
, SfxPrinter
* pNewPrinter
, SCTAB nTab
,
311 tools::Long nPage
= 0, tools::Long nDocP
= 0,
312 const ScRange
* pArea
= nullptr,
313 const ScPrintOptions
* pOptions
= nullptr,
314 ScPageBreakData
* pData
= nullptr,
315 Size aPrintPageSize
= {},
316 bool bPrintPageLandscape
= false,
317 bool bUsePrintDialogSetting
= false );
319 ScPrintFunc( ScDocShell
* pShell
, SfxPrinter
* pNewPrinter
,
320 const ScPrintState
& rState
, const ScPrintOptions
* pOptions
,
321 Size aPrintPageSize
= {},
322 bool bPrintPageLandscape
= false,
323 bool bUsePrintDialogSetting
= false );
325 // ctors for device other than printer - for preview and pdf:
327 ScPrintFunc( OutputDevice
* pOutDev
, ScDocShell
* pShell
, SCTAB nTab
,
328 tools::Long nPage
= 0, tools::Long nDocP
= 0,
329 const ScRange
* pArea
= nullptr,
330 const ScPrintOptions
* pOptions
= nullptr );
332 ScPrintFunc( OutputDevice
* pOutDev
, ScDocShell
* pShell
,
333 const ScPrintState
& rState
,
334 const ScPrintOptions
* pOptions
, Size aPrintPageSize
= {},
335 bool bPrintPageLandscape
= false,
336 bool bUsePrintDialogSetting
= false);
340 static void DrawToDev( ScDocument
& rDoc
, OutputDevice
* pDev
, double nPrintFactor
,
341 const tools::Rectangle
& rBound
, ScViewData
* pViewData
, bool bMetaFile
);
343 void SetDrawView( FmFormView
* pNew
);
345 void SetOffset( const Point
& rOfs
);
346 void SetManualZoom( sal_uInt16 nNewZoom
);
347 void SetDateTime( const DateTime
& );
349 void SetClearFlag( bool bFlag
);
350 void SetUseStyleColor( bool bFlag
);
351 void SetRenderFlag( bool bFlag
);
353 void SetExclusivelyDrawOleAndDrawObjects();//for printing selected objects without surrounding cell contents
357 void ApplyPrintSettings(); // Already called from DoPrint()
358 tools::Long
DoPrint( const MultiSelection
& rPageRanges
,
359 tools::Long nStartPage
, tools::Long nDisplayStart
, bool bDoPrint
,
360 ScPreviewLocationData
* pLocationData
);
362 // Query values - immediately
364 const Size
& GetPageSize() const { return aPageSize
; }
365 Size
GetDataSize() const;
366 void GetScaleData( Size
& rPhysSize
, tools::Long
& rDocHdr
, tools::Long
& rDocFtr
);
367 tools::Long
GetFirstPageNo() const { return aTableParam
.nFirstPageNo
; }
369 tools::Long
GetTotalPages() const { return nTotalPages
; }
370 sal_uInt16
GetZoom() const { return nZoom
; }
372 void ResetBreaks( SCTAB nTab
);
374 void GetPrintState(ScPrintState
& rState
);
375 bool GetLastSourceRange( ScRange
& rRange
) const;
376 sal_uInt16
GetLeftMargin() const{return nLeftMargin
;}
377 sal_uInt16
GetRightMargin() const{return nRightMargin
;}
378 sal_uInt16
GetTopMargin() const{return nTopMargin
;}
379 sal_uInt16
GetBottomMargin() const{return nBottomMargin
;}
380 const ScPrintHFParam
& GetHeader() const {return aHdr
;}
381 const ScPrintHFParam
& GetFooter() const {return aFtr
;}
383 bool HasPrintRange() const { return mbHasPrintRange
;}
386 void Construct( const ScPrintOptions
* pOptions
);
387 void InitParam( const ScPrintOptions
* pOptions
);
388 void CalcZoom( sal_uInt16 nRangeNo
);
390 tools::Long
CountPages();
391 tools::Long
CountNotePages();
393 bool AdjustPrintArea( bool bNew
);
395 Size
GetDocPageSize();
397 tools::Long
TextHeight( const EditTextObject
* pObject
);
398 void MakeEditEngine();
399 void UpdateHFHeight( ScPrintHFParam
& rParam
);
403 bool IsLeft( tools::Long nPageNo
);
404 bool IsMirror( tools::Long nPageNo
);
405 void MakeTableString(); // sets aTableStr
407 void PrintPage( tools::Long nPageNo
,
408 SCCOL nX1
, SCROW nY1
, SCCOL nX2
, SCROW nY2
,
409 bool bDoPrint
, ScPreviewLocationData
* pLocationData
);
410 void PrintArea( SCCOL nX1
, SCROW nY1
, SCCOL nX2
, SCROW nY2
,
411 tools::Long nScrX
, tools::Long nScrY
,
412 bool bShLeft
, bool bShTop
, bool bShRight
, bool bShBottom
);
413 void LocateArea( SCCOL nX1
, SCROW nY1
, SCCOL nX2
, SCROW nY2
,
414 tools::Long nScrX
, tools::Long nScrY
, bool bRepCol
, bool bRepRow
,
415 ScPreviewLocationData
& rLocationData
);
416 void PrintColHdr( SCCOL nX1
, SCCOL nX2
, tools::Long nScrX
, tools::Long nScrY
);
417 void PrintRowHdr( SCROW nY1
, SCROW nY2
, tools::Long nScrX
, tools::Long nScrY
);
418 void LocateColHdr( SCCOL nX1
, SCCOL nX2
, tools::Long nScrX
, tools::Long nScrY
,
419 bool bRepCol
, ScPreviewLocationData
& rLocationData
);
420 void LocateRowHdr( SCROW nY1
, SCROW nY2
, tools::Long nScrX
, tools::Long nScrY
,
421 bool bRepRow
, ScPreviewLocationData
& rLocationData
);
422 void PrintHF( tools::Long nPageNo
, bool bHeader
, tools::Long nStartY
,
423 bool bDoPrint
, ScPreviewLocationData
* pLocationData
);
425 tools::Long
PrintNotes( tools::Long nPageNo
, tools::Long nNoteStart
, bool bDoPrint
, ScPreviewLocationData
* pLocationData
);
426 tools::Long
DoNotes( tools::Long nNoteStart
, bool bDoPrint
, ScPreviewLocationData
* pLocationData
);
428 void DrawBorder( tools::Long nScrX
, tools::Long nScrY
, tools::Long nScrW
, tools::Long nScrH
,
429 const SvxBoxItem
* pBorderData
,
430 const SvxBrushItem
* pBackground
,
431 const SvxShadowItem
* pShadow
);
436 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */