xref: /aoo41x/main/sc/source/ui/inc/printfun.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SC_PRINTFUN_HXX
29 #define SC_PRINTFUN_HXX
30 
31 
32 #include "pagepar.hxx"
33 #include "editutil.hxx"
34 
35 #ifndef _PRINT_HXX //autogen
36 #include <vcl/print.hxx>
37 #endif
38 
39 class SfxPrinter;
40 class SfxProgress;
41 class ScDocShell;
42 class ScDocument;
43 class ScViewData;
44 class SfxItemSet;
45 class ScPageHFItem;
46 class EditTextObject;
47 class MultiSelection;
48 class ScHeaderEditEngine;
49 class ScPageBreakData;
50 class ScPreviewLocationData;
51 class ScPrintOptions;
52 class SvxBoxItem;
53 class SvxBrushItem;
54 class SvxShadowItem;
55 class FmFormView;
56 
57 #define RANGENO_NORANGE				USHRT_MAX
58 
59 #define PRINT_HEADER_WIDTH			(1.0 * TWIPS_PER_CM)
60 #define PRINT_HEADER_HEIGHT 		(12.8 * TWIPS_PER_POINT)
61 #define PRINT_HEADER_FONTHEIGHT 	200
62 
63 
64 											//	Einstellungen fuer Kopf-/Fusszeilen
65 struct ScPrintHFParam
66 {
67 	sal_Bool				bEnable;
68 	sal_Bool				bDynamic;
69 	sal_Bool				bShared;
70 	long				nHeight;			//	insgesamt (Hoehe+Abstand+Rahmen)
71 	long				nManHeight;			//	eingestellte Groesse (Min. bei dynamisch)
72 	sal_uInt16				nDistance;
73 	sal_uInt16				nLeft;				//	Raender
74 	sal_uInt16				nRight;
75 	const ScPageHFItem* pLeft;
76 	const ScPageHFItem* pRight;
77 	const SvxBoxItem*	pBorder;
78 	const SvxBrushItem* pBack;
79 	const SvxShadowItem* pShadow;
80 };
81 
82 
83 // "Ersatz" fuer SV-JobSetup:
84 
85 class ScJobSetup
86 {
87 public:
88 	ScJobSetup( SfxPrinter* pPrinter );
89 
90 	Size		aUserSize;
91 	MapMode		aUserMapMode;
92 	Paper	ePaper;
93 	Orientation eOrientation;
94 	sal_uInt16		nPaperBin;
95 };
96 
97 struct ScPrintState							//	Variablen aus ScPrintFunc retten
98 {
99 	SCTAB	nPrintTab;
100 	SCCOL	nStartCol;
101 	SCROW	nStartRow;
102 	SCCOL	nEndCol;
103 	SCROW	nEndRow;
104 	sal_uInt16	nZoom;
105 	size_t	nPagesX;
106 	size_t	nPagesY;
107 	long	nTabPages;
108 	long	nTotalPages;
109 	long	nPageStart;
110 	long	nDocPages;
111 };
112 
113 class ScPageRowEntry
114 {
115 private:
116 	SCROW	nStartRow;
117 	SCROW	nEndRow;
118 	size_t	nPagesX;
119 	sal_Bool*	pHidden;
120 	//!		Anzahl wirklich sichtbarer cachen???
121 
122 public:
123 			ScPageRowEntry()	{ nStartRow = nEndRow = 0; nPagesX = 0; pHidden = NULL; }
124 			~ScPageRowEntry()	{ delete[] pHidden; }
125 
126 			ScPageRowEntry(const ScPageRowEntry& r);
127 	const ScPageRowEntry& operator=(const ScPageRowEntry& r);
128 
129 	SCROW	GetStartRow() const		{ return nStartRow; }
130 	SCROW	GetEndRow() const		{ return nEndRow; }
131 	size_t	GetPagesX() const		{ return nPagesX; }
132 	void	SetStartRow(SCROW n)	{ nStartRow = n; }
133 	void	SetEndRow(SCROW n)		{ nEndRow = n; }
134 
135 	void	SetPagesX(size_t nNew);
136 	void	SetHidden(size_t nX);
137 	sal_Bool	IsHidden(size_t nX) const;
138 
139 	size_t	CountVisible() const;
140 };
141 
142 class ScPrintFunc
143 {
144 private:
145 	ScDocShell* 		pDocShell;
146 	ScDocument* 		pDoc;
147 	SfxPrinter* 		pPrinter;
148 	OutputDevice*		pDev;
149 	FmFormView*			pDrawView;
150 
151 	MapMode				aOldPrinterMode;	//	MapMode vor dem Aufruf
152 
153 	Point				aSrcOffset;			//	Papier-1/100 mm
154 	Point				aOffset;			//	mit Faktor aus Seitenformat skaliert
155 	sal_uInt16				nManualZoom;		//	Zoom in Preview (Prozent)
156 	sal_Bool				bClearWin;			//	Ausgabe vorher loeschen
157 	sal_Bool				bUseStyleColor;
158 	sal_Bool				bIsRender;
159 
160 	SCTAB				nPrintTab;
161 	long				nPageStart;			//	Offset fuer erste Seite
162 	long				nDocPages;			//	Seiten im Dokument
163 
164 	const ScRange*		pUserArea;			//	Selektion, wenn im Dialog eingestellt
165 
166 	const SfxItemSet*	pParamSet;			//	eingestellte Vorlage
167 	sal_Bool				bState;				//	aus State-struct erzeugt
168 
169 											//	Parameter aus Vorlage:
170 	sal_uInt16				nLeftMargin;
171 	sal_uInt16				nTopMargin;
172 	sal_uInt16				nRightMargin;
173 	sal_uInt16				nBottomMargin;
174 	sal_Bool				bCenterHor;
175 	sal_Bool				bCenterVer;
176 	sal_Bool				bLandscape;
177 	sal_Bool				bSourceRangeValid;
178 
179 	sal_uInt16				nPageUsage;
180 	Size				aPageSize;			//	Drucker-Twips
181 	const SvxBoxItem*	pBorderItem;
182 	const SvxBrushItem* pBackgroundItem;
183 	const SvxShadowItem* pShadowItem;
184 
185 	ScRange				aLastSourceRange;
186 	ScPrintHFParam		aHdr;
187 	ScPrintHFParam		aFtr;
188 	ScPageTableParam	aTableParam;
189 	ScPageAreaParam 	aAreaParam;
190 
191 											//	berechnete Werte:
192 	sal_uInt16				nZoom;
193 	sal_Bool				bPrintCurrentTable;
194 	sal_Bool				bMultiArea;
195 	long				nTabPages;
196 	long				nTotalPages;
197 
198 	Rectangle			aPageRect;			//	Dokument-Twips
199 
200 	MapMode 			aLogicMode; 		//	in DoPrint gesetzt
201 	MapMode 			aOffsetMode;
202 	MapMode 			aTwipMode;
203 	double				nScaleX;
204 	double				nScaleY;
205 
206 	SCCOL				nRepeatStartCol;
207 	SCCOL				nRepeatEndCol;
208 	SCROW				nRepeatStartRow;
209 	SCROW				nRepeatEndRow;
210 
211 	SCCOL				nStartCol;
212 	SCROW				nStartRow;
213 	SCCOL				nEndCol;
214 	SCROW				nEndRow;
215 
216 	SCCOL*              pPageEndX;			// Seitenaufteilung
217 	SCROW*              pPageEndY;
218 	ScPageRowEntry*		pPageRows;
219 	size_t				nPagesX;
220 	size_t				nPagesY;
221 	size_t				nTotalY;
222 
223 	ScHeaderEditEngine*	pEditEngine;
224 	SfxItemSet* 		pEditDefaults;
225 
226 	ScHeaderFieldData	aFieldData;
227 
228 	List				aNotePosList;		//	Reihenfolge der Notizen
229 
230 	ScPageBreakData*	pPageData;			// zum Eintragen der Umbrueche etc.
231 
232 public:
233 					ScPrintFunc( ScDocShell* pShell, SfxPrinter* pNewPrinter, SCTAB nTab,
234 								 long nPage = 0, long nDocP = 0,
235 								 const ScRange* pArea = NULL,
236 								 const ScPrintOptions* pOptions = NULL,
237 								 ScPageBreakData* pData = NULL );
238 
239 					// ctors for device other than printer - for preview and pdf:
240 
241 					ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell, SCTAB nTab,
242 								 long nPage = 0, long nDocP = 0,
243 								 const ScRange* pArea = NULL,
244 								 const ScPrintOptions* pOptions = NULL );
245 
246 					ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell,
247 								 const ScPrintState& rState,
248 								 const ScPrintOptions* pOptions );
249 
250 					~ScPrintFunc();
251 
252 	static void 	DrawToDev( ScDocument* pDoc, OutputDevice* pDev, double nPrintFactor,
253 								const Rectangle& rBound, ScViewData* pViewData, sal_Bool bMetaFile );
254 
255 	void			SetDrawView( FmFormView* pNew );
256 
257 	void			SetOffset( const Point& rOfs );
258 	void			SetManualZoom( sal_uInt16 nNewZoom );
259 	void			SetDateTime( const Date& rDate, const Time& rTime );
260 
261 	void			SetClearFlag( sal_Bool bFlag );
262 	void			SetUseStyleColor( sal_Bool bFlag );
263 	void			SetRenderFlag( sal_Bool bFlag );
264 
265     void            SetExclusivelyDrawOleAndDrawObjects();//for printing selected objects without surrounding cell contents
266 
267 	sal_Bool			UpdatePages();
268 
269 	void			ApplyPrintSettings();		// aus DoPrint() schon gerufen
270 	long			DoPrint( const MultiSelection& rPageRanges,
271                                 long nStartPage, long nDisplayStart, sal_Bool bDoPrint,
272                                 ScPreviewLocationData* pLocationData );
273 
274 					//	Werte abfragen - sofort
275 
276 	Size			GetPageSize() const { return aPageSize; }
277 	Size			GetDataSize() const;
278 	void			GetScaleData( Size& rPhysSize, long& rDocHdr, long& rDocFtr );
279 	long			GetFirstPageNo() const	{ return aTableParam.nFirstPageNo; }
280 
281 					//	letzte Werte abfragen - nach DoPrint !!!
282 
283 	double			GetScaleX() const { return nScaleX; }
284 	double			GetScaleY() const { return nScaleY; }
285 	long			GetTotalPages() const { return nTotalPages; }
286 	sal_uInt16			GetZoom() const { return nZoom; }
287 
288 	void			ResetBreaks( SCTAB nTab );
289 
290 	void			GetPrintState( ScPrintState& rState );
291 	sal_Bool			GetLastSourceRange( ScRange& rRange ) const;
292     sal_uInt16          GetLeftMargin() const{return nLeftMargin;}
293     sal_uInt16          GetRightMargin() const{return nRightMargin;}
294     sal_uInt16          GetTopMargin() const{return nTopMargin;}
295     sal_uInt16          GetBottomMargin() const{return nBottomMargin;}
296     void            SetLeftMargin(sal_uInt16 nRulerLeftDistance){ nLeftMargin = nRulerLeftDistance; }
297     void            SetRightMargin(sal_uInt16 nRulerRightDistance){ nRightMargin = nRulerRightDistance; }
298     void            SetTopMargin(sal_uInt16 nRulerTopDistance){ nTopMargin = nRulerTopDistance; }
299     void            SetBottomMargin(sal_uInt16 nRulerBottomDistance){ nBottomMargin = nRulerBottomDistance; }
300     ScPrintHFParam  GetHeader(){return aHdr;}
301     ScPrintHFParam  GetFooter(){return aFtr;}
302 
303 private:
304 	void			Construct( const ScPrintOptions* pOptions );
305 	void			InitParam( const ScPrintOptions* pOptions );
306 	void			CalcZoom( sal_uInt16 nRangeNo );
307 	void			CalcPages();
308 	long			CountPages();
309 	long			CountNotePages();
310 
311 	sal_Bool			AdjustPrintArea( sal_Bool bNew );
312 
313 	Size			GetDocPageSize();
314 
315 	long			TextHeight( const EditTextObject* pObject );
316 	void			MakeEditEngine();
317 	void			UpdateHFHeight( ScPrintHFParam& rParam );
318 
319 	void			InitModes();
320 
321 	sal_Bool			IsLeft( long nPageNo );
322 	sal_Bool			IsMirror( long nPageNo );
323 	void			ReplaceFields( long nPageNo );		// aendert Text in pEditEngine
324 	void			MakeTableString();				 	// setzt aTableStr
325 
326 	void			PrintPage( long nPageNo,
327 									SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
328 									sal_Bool bDoPrint, ScPreviewLocationData* pLocationData );
329 	void			PrintArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
330 									long nScrX, long nScrY,
331 									sal_Bool bShLeft, sal_Bool bShTop, sal_Bool bShRight, sal_Bool bShBottom );
332 	void			LocateArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
333 									long nScrX, long nScrY, sal_Bool bRepCol, sal_Bool bRepRow,
334 									ScPreviewLocationData& rLocationData );
335 	void			PrintColHdr( SCCOL nX1, SCCOL nX2, long nScrX, long nScrY );
336 	void			PrintRowHdr( SCROW nY1, SCROW nY2, long nScrX, long nScrY );
337 	void			LocateColHdr( SCCOL nX1, SCCOL nX2, long nScrX, long nScrY,
338 								sal_Bool bRepCol, ScPreviewLocationData& rLocationData );
339 	void			LocateRowHdr( SCROW nY1, SCROW nY2, long nScrX, long nScrY,
340 								sal_Bool bRepRow, ScPreviewLocationData& rLocationData );
341 	void			PrintHF( long nPageNo, sal_Bool bHeader, long nStartY,
342 									sal_Bool bDoPrint, ScPreviewLocationData* pLocationData );
343 
344 	long			PrintNotes( long nPageNo, long nNoteStart, sal_Bool bDoPrint, ScPreviewLocationData* pLocationData );
345 	long			DoNotes( long nNoteStart, sal_Bool bDoPrint, ScPreviewLocationData* pLocationData );
346 
347 	void			DrawBorder( long nScrX, long nScrY, long nScrW, long nScrH,
348 									const SvxBoxItem* pBorderData,
349 									const SvxBrushItem* pBackground,
350 									const SvxShadowItem* pShadow );
351 
352 	void			FillPageData();
353 };
354 
355 
356 
357 #endif
358 
359