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 SC_PRINTFUN_HXX
21 : #define SC_PRINTFUN_HXX
22 :
23 :
24 : #include "pagepar.hxx"
25 : #include "editutil.hxx"
26 :
27 : #include <vcl/print.hxx>
28 :
29 : class SfxPrinter;
30 : class ScDocShell;
31 : class ScDocument;
32 : class ScViewData;
33 : class SfxItemSet;
34 : class ScPageHFItem;
35 : class EditTextObject;
36 : class MultiSelection;
37 : class ScHeaderEditEngine;
38 : class ScPageBreakData;
39 : class ScPreviewLocationData;
40 : class ScPrintOptions;
41 : class SvxBoxItem;
42 : class SvxBrushItem;
43 : class SvxShadowItem;
44 : class FmFormView;
45 :
46 : #define RANGENO_NORANGE USHRT_MAX
47 :
48 : #define PRINT_HEADER_WIDTH (1.0 * TWIPS_PER_CM)
49 : #define PRINT_HEADER_HEIGHT (12.8 * TWIPS_PER_POINT)
50 : #define PRINT_HEADER_FONTHEIGHT 200
51 :
52 :
53 : // Settings for headers/footers
54 : struct ScPrintHFParam
55 : {
56 : bool bEnable;
57 : bool bDynamic;
58 : bool bShared;
59 : long nHeight; // in total (height + distance + frames)
60 : long nManHeight; // set size (min when dynamic)
61 : sal_uInt16 nDistance;
62 : sal_uInt16 nLeft; // edges
63 : sal_uInt16 nRight;
64 : const ScPageHFItem* pLeft;
65 : const ScPageHFItem* pRight;
66 : const SvxBoxItem* pBorder;
67 : const SvxBrushItem* pBack;
68 : const SvxShadowItem* pShadow;
69 : };
70 :
71 :
72 : struct ScPrintState // Save Variables from ScPrintFunc
73 : {
74 : SCTAB nPrintTab;
75 : SCCOL nStartCol;
76 : SCROW nStartRow;
77 : SCCOL nEndCol;
78 : SCROW nEndRow;
79 : sal_uInt16 nZoom;
80 : size_t nPagesX;
81 : size_t nPagesY;
82 : long nTabPages;
83 : long nTotalPages;
84 : long nPageStart;
85 : long nDocPages;
86 : };
87 :
88 : class ScPageRowEntry
89 : {
90 : private:
91 : SCROW nStartRow;
92 : SCROW nEndRow;
93 : size_t nPagesX;
94 : bool* pHidden;
95 : //! Cache Number of really visible?
96 :
97 : public:
98 0 : ScPageRowEntry() { nStartRow = nEndRow = 0; nPagesX = 0; pHidden = NULL; }
99 0 : ~ScPageRowEntry() { delete[] pHidden; }
100 :
101 : ScPageRowEntry(const ScPageRowEntry& r);
102 : const ScPageRowEntry& operator=(const ScPageRowEntry& r);
103 :
104 0 : SCROW GetStartRow() const { return nStartRow; }
105 0 : SCROW GetEndRow() const { return nEndRow; }
106 0 : size_t GetPagesX() const { return nPagesX; }
107 0 : void SetStartRow(SCROW n) { nStartRow = n; }
108 0 : void SetEndRow(SCROW n) { nEndRow = n; }
109 :
110 : void SetPagesX(size_t nNew);
111 : void SetHidden(size_t nX);
112 : bool IsHidden(size_t nX) const;
113 :
114 : size_t CountVisible() const;
115 : };
116 :
117 : class ScPrintFunc
118 : {
119 : private:
120 : ScDocShell* pDocShell;
121 : ScDocument* pDoc;
122 : SfxPrinter* pPrinter;
123 : OutputDevice* pDev;
124 : FmFormView* pDrawView;
125 :
126 : MapMode aOldPrinterMode; // MapMode befor the call
127 :
128 : Point aSrcOffset; // Paper-1/100 mm
129 : Point aOffset; // scaled by a factor of page size
130 : sal_uInt16 nManualZoom; // Zoom in Preview (percent)
131 : bool bClearWin; // Clear output before
132 : bool bUseStyleColor;
133 : bool bIsRender;
134 :
135 : SCTAB nPrintTab;
136 : long nPageStart; // Offset for the first page
137 : long nDocPages; // Number of Pages in Document
138 :
139 : const ScRange* pUserArea; // Selection, if set in dialog
140 :
141 : const SfxItemSet* pParamSet; // Selected template
142 : bool bState; // created from State-struct
143 :
144 : // Parameter from template:
145 : sal_uInt16 nLeftMargin;
146 : sal_uInt16 nTopMargin;
147 : sal_uInt16 nRightMargin;
148 : sal_uInt16 nBottomMargin;
149 : bool bCenterHor;
150 : bool bCenterVer;
151 : bool bLandscape;
152 : bool bSourceRangeValid;
153 :
154 : sal_uInt16 nPageUsage;
155 : Size aPageSize; // Printer Twips
156 : const SvxBoxItem* pBorderItem;
157 : const SvxBrushItem* pBackgroundItem;
158 : const SvxShadowItem* pShadowItem;
159 :
160 : ScRange aLastSourceRange;
161 : ScPrintHFParam aHdr;
162 : ScPrintHFParam aFtr;
163 : ScPageTableParam aTableParam;
164 : ScPageAreaParam aAreaParam;
165 :
166 : // Calculated values:
167 : sal_uInt16 nZoom;
168 : bool bPrintCurrentTable;
169 : bool bMultiArea;
170 : bool mbHasPrintRange;
171 : long nTabPages;
172 : long nTotalPages;
173 :
174 : Rectangle aPageRect; // Document Twips
175 :
176 : MapMode aLogicMode; // Set in DoPrint
177 : MapMode aOffsetMode;
178 : MapMode aTwipMode;
179 : double nScaleX;
180 : double nScaleY;
181 :
182 : SCCOL nRepeatStartCol;
183 : SCCOL nRepeatEndCol;
184 : SCROW nRepeatStartRow;
185 : SCROW nRepeatEndRow;
186 :
187 : SCCOL nStartCol;
188 : SCROW nStartRow;
189 : SCCOL nEndCol;
190 : SCROW nEndRow;
191 :
192 : std::vector< SCCOL > maPageEndX;
193 : std::vector< SCROW > maPageEndY;
194 : std::vector< ScPageRowEntry> maPageRows;
195 :
196 : size_t nPagesX;
197 : size_t nPagesY;
198 : size_t nTotalY;
199 :
200 : ScHeaderEditEngine* pEditEngine;
201 : SfxItemSet* pEditDefaults;
202 :
203 : ScHeaderFieldData aFieldData;
204 :
205 : std::vector<ScAddress> aNotePosList; // The order of notes
206 :
207 : ScPageBreakData* pPageData; // for recording the breaks etc.
208 :
209 : public:
210 : ScPrintFunc( ScDocShell* pShell, SfxPrinter* pNewPrinter, SCTAB nTab,
211 : long nPage = 0, long nDocP = 0,
212 : const ScRange* pArea = NULL,
213 : const ScPrintOptions* pOptions = NULL,
214 : ScPageBreakData* pData = NULL );
215 :
216 : // ctors for device other than printer - for preview and pdf:
217 :
218 : ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell, SCTAB nTab,
219 : long nPage = 0, long nDocP = 0,
220 : const ScRange* pArea = NULL,
221 : const ScPrintOptions* pOptions = NULL );
222 :
223 : ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell,
224 : const ScPrintState& rState,
225 : const ScPrintOptions* pOptions );
226 :
227 : ~ScPrintFunc();
228 :
229 : static void DrawToDev( ScDocument* pDoc, OutputDevice* pDev, double nPrintFactor,
230 : const Rectangle& rBound, ScViewData* pViewData, bool bMetaFile );
231 :
232 : void SetDrawView( FmFormView* pNew );
233 :
234 : void SetOffset( const Point& rOfs );
235 : void SetManualZoom( sal_uInt16 nNewZoom );
236 : void SetDateTime( const Date& rDate, const Time& rTime );
237 :
238 : void SetClearFlag( bool bFlag );
239 : void SetUseStyleColor( bool bFlag );
240 : void SetRenderFlag( bool bFlag );
241 :
242 : void SetExclusivelyDrawOleAndDrawObjects();//for printing selected objects without surrounding cell contents
243 :
244 : bool UpdatePages();
245 :
246 : void ApplyPrintSettings(); // Already called from DoPrint()
247 : long DoPrint( const MultiSelection& rPageRanges,
248 : long nStartPage, long nDisplayStart, bool bDoPrint,
249 : ScPreviewLocationData* pLocationData );
250 :
251 : // Query values - immediately
252 :
253 0 : Size GetPageSize() const { return aPageSize; }
254 : Size GetDataSize() const;
255 : void GetScaleData( Size& rPhysSize, long& rDocHdr, long& rDocFtr );
256 0 : long GetFirstPageNo() const { return aTableParam.nFirstPageNo; }
257 :
258 : // Query last value - after DoPrint!!
259 :
260 : double GetScaleX() const { return nScaleX; }
261 : double GetScaleY() const { return nScaleY; }
262 0 : long GetTotalPages() const { return nTotalPages; }
263 0 : sal_uInt16 GetZoom() const { return nZoom; }
264 :
265 : void ResetBreaks( SCTAB nTab );
266 :
267 : void GetPrintState( ScPrintState& rState );
268 : bool GetLastSourceRange( ScRange& rRange ) const;
269 0 : sal_uInt16 GetLeftMargin() const{return nLeftMargin;}
270 0 : sal_uInt16 GetRightMargin() const{return nRightMargin;}
271 0 : sal_uInt16 GetTopMargin() const{return nTopMargin;}
272 0 : sal_uInt16 GetBottomMargin() const{return nBottomMargin;}
273 : void SetLeftMargin(sal_uInt16 nRulerLeftDistance){ nLeftMargin = nRulerLeftDistance; }
274 : void SetRightMargin(sal_uInt16 nRulerRightDistance){ nRightMargin = nRulerRightDistance; }
275 : void SetTopMargin(sal_uInt16 nRulerTopDistance){ nTopMargin = nRulerTopDistance; }
276 : void SetBottomMargin(sal_uInt16 nRulerBottomDistance){ nBottomMargin = nRulerBottomDistance; }
277 0 : ScPrintHFParam GetHeader(){return aHdr;}
278 0 : ScPrintHFParam GetFooter(){return aFtr;}
279 :
280 : bool HasPrintRange() const;
281 :
282 : private:
283 : void Construct( const ScPrintOptions* pOptions );
284 : void InitParam( const ScPrintOptions* pOptions );
285 : void CalcZoom( sal_uInt16 nRangeNo );
286 : void CalcPages();
287 : long CountPages();
288 : long CountNotePages();
289 :
290 : bool AdjustPrintArea( bool bNew );
291 :
292 : Size GetDocPageSize();
293 :
294 : long TextHeight( const EditTextObject* pObject );
295 : void MakeEditEngine();
296 : void UpdateHFHeight( ScPrintHFParam& rParam );
297 :
298 : void InitModes();
299 :
300 : bool IsLeft( long nPageNo );
301 : bool IsMirror( long nPageNo );
302 : void ReplaceFields( long nPageNo ); // changes Text in pEditEngine
303 : void MakeTableString(); // sets aTableStr
304 :
305 : void PrintPage( long nPageNo,
306 : SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
307 : bool bDoPrint, ScPreviewLocationData* pLocationData );
308 : void PrintArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
309 : long nScrX, long nScrY,
310 : bool bShLeft, bool bShTop, bool bShRight, bool bShBottom );
311 : void LocateArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
312 : long nScrX, long nScrY, bool bRepCol, bool bRepRow,
313 : ScPreviewLocationData& rLocationData );
314 : void PrintColHdr( SCCOL nX1, SCCOL nX2, long nScrX, long nScrY );
315 : void PrintRowHdr( SCROW nY1, SCROW nY2, long nScrX, long nScrY );
316 : void LocateColHdr( SCCOL nX1, SCCOL nX2, long nScrX, long nScrY,
317 : bool bRepCol, ScPreviewLocationData& rLocationData );
318 : void LocateRowHdr( SCROW nY1, SCROW nY2, long nScrX, long nScrY,
319 : bool bRepRow, ScPreviewLocationData& rLocationData );
320 : void PrintHF( long nPageNo, bool bHeader, long nStartY,
321 : bool bDoPrint, ScPreviewLocationData* pLocationData );
322 :
323 : long PrintNotes( long nPageNo, long nNoteStart, bool bDoPrint, ScPreviewLocationData* pLocationData );
324 : long DoNotes( long nNoteStart, bool bDoPrint, ScPreviewLocationData* pLocationData );
325 :
326 : void DrawBorder( long nScrX, long nScrY, long nScrW, long nScrH,
327 : const SvxBoxItem* pBorderData,
328 : const SvxBrushItem* pBackground,
329 : const SvxShadowItem* pShadow );
330 :
331 : void FillPageData();
332 : };
333 :
334 : #endif
335 :
336 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|