tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / inc / printfun.hxx
blob04c1019e0f8042b318fc840fe0cce12a7c29b43a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #pragma once
22 #include <memory>
23 #include <map>
24 #include <pagepar.hxx>
25 #include <editutil.hxx>
27 class SfxPrinter;
28 class ScDocShell;
29 class ScDocument;
30 class ScViewData;
31 class SfxItemSet;
32 class ScPageHFItem;
33 class EditTextObject;
34 class MultiSelection;
35 class ScPageBreakData;
36 class ScPreviewLocationData;
37 class ScPrintOptions;
38 class SvxBoxItem;
39 class SvxBrushItem;
40 class SvxShadowItem;
41 class FmFormView;
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
49 struct ScPrintHFParam
51 bool bEnable;
52 bool bDynamic;
53 bool bShared;
54 bool bSharedFirst;
55 tools::Long nHeight; // in total (height + distance + frames)
56 tools::Long nManHeight; // set size (min when dynamic)
57 sal_uInt16 nDistance;
58 sal_uInt16 nLeft; // edges
59 sal_uInt16 nRight;
60 const ScPageHFItem* pLeft;
61 const ScPageHFItem* pRight;
62 const ScPageHFItem* pFirst;
63 const SvxBoxItem* pBorder;
64 const SvxBrushItem* pBack;
65 const SvxShadowItem* pShadow;
68 class ScPageRowEntry
70 private:
71 SCROW nStartRow;
72 SCROW nEndRow;
73 size_t nPagesX;
74 std::vector<bool> aHidden;
75 //! Cache Number of really visible?
77 public:
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;
96 namespace sc
99 struct PrintPageRangesInput
101 bool m_bSkipEmpty;
102 bool m_bPrintArea;
103 ScRange m_aRange;
104 Size m_aDocSize;
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)
114 , m_aRange(rRange)
115 , m_aDocSize(rDocSize)
118 bool operator==(PrintPageRangesInput const& rInput) const
120 return
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;
134 return *this;
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
165 public:
166 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;
173 size_t m_nPagesX;
174 size_t m_nPagesY;
175 size_t m_nTotalY;
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
186 struct ScPrintState
188 SCTAB nPrintTab;
189 SCCOL nStartCol;
190 SCROW nStartRow;
191 SCCOL nEndCol;
192 SCROW nEndRow;
193 bool bPrintAreaValid; // the 4 variables above are set
194 sal_uInt16 nZoom;
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;
203 ScPrintState()
204 : nPrintTab(0)
205 , nStartCol(0)
206 , nStartRow(0)
207 , nEndCol(0)
208 , nEndRow(0)
209 , bPrintAreaValid(false)
210 , nZoom(0)
211 , nTabPages(0)
212 , nTotalPages(0)
213 , nPageStart(0)
214 , nDocPages(0)
218 class ScPrintFunc
220 private:
221 ScDocShell* pDocShell;
222 ScDocument& rDoc;
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
233 bool bUseStyleColor;
234 bool bIsRender;
236 SCTAB nPrintTab;
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;
250 bool bCenterHor;
251 bool bCenterVer;
252 bool bLandscape;
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;
262 ScPrintHFParam aHdr;
263 ScPrintHFParam aFtr;
264 ScPageTableParam aTableParam;
265 ScPageAreaParam aAreaParam;
267 // Calculated values:
268 sal_uInt16 nZoom;
269 bool bPrintCurrentTable;
270 bool bMultiArea;
271 bool mbHasPrintRange;
272 tools::Long nTabPages;
273 tools::Long nTotalPages;
275 tools::Rectangle aPageRect; // Document Twips
277 MapMode aLogicMode; // Set in DoPrint
278 MapMode aOffsetMode;
279 MapMode aTwipMode;
280 double nScaleX;
281 double nScaleY;
283 SCCOL nRepeatStartCol;
284 SCCOL nRepeatEndCol;
285 SCROW nRepeatStartRow;
286 SCROW nRepeatEndRow;
288 SCCOL nStartCol;
289 SCROW nStartRow;
290 SCCOL nEndCol;
291 SCROW nEndRow;
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
309 public:
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);
338 ~ScPrintFunc();
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
355 bool UpdatePages();
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;}
385 private:
386 void Construct( const ScPrintOptions* pOptions );
387 void InitParam( const ScPrintOptions* pOptions );
388 void CalcZoom( sal_uInt16 nRangeNo );
389 void CalcPages();
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 );
401 void InitModes();
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 );
433 void FillPageData();
436 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */