fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / excel / xipage.cxx
bloba3d2b2fa57630f4088d58e1d4f2d1d4a2344478e
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 #include "xipage.hxx"
21 #include <svl/itemset.hxx>
22 #include <vcl/graph.hxx>
23 #include "scitems.hxx"
24 #include <svl/eitem.hxx>
25 #include <svl/intitem.hxx>
26 #include <svx/pageitem.hxx>
27 #include <editeng/sizeitem.hxx>
28 #include <editeng/lrspitem.hxx>
29 #include <editeng/ulspitem.hxx>
30 #include <editeng/brushitem.hxx>
31 #include "document.hxx"
32 #include "stlsheet.hxx"
33 #include "attrib.hxx"
34 #include "xistream.hxx"
35 #include "xihelper.hxx"
36 #include "xiescher.hxx"
38 // Page settings ==============================================================
40 XclImpPageSettings::XclImpPageSettings( const XclImpRoot& rRoot ) :
41 XclImpRoot( rRoot )
43 Initialize();
46 void XclImpPageSettings::Initialize()
48 maData.SetDefaults();
49 mbValidPaper = false;
52 void XclImpPageSettings::ReadSetup( XclImpStream& rStrm )
54 OSL_ENSURE_BIFF( GetBiff() >= EXC_BIFF4 );
55 if( GetBiff() < EXC_BIFF4 )
56 return;
58 // BIFF4 - BIFF8
59 sal_uInt16 nFlags;
60 maData.mnPaperSize = rStrm.ReaduInt16();
61 maData.mnScaling = rStrm.ReaduInt16();
62 maData.mnStartPage = rStrm.ReaduInt16();
63 maData.mnFitToWidth = rStrm.ReaduInt16();
64 maData.mnFitToHeight = rStrm.ReaduInt16();
65 nFlags = rStrm.ReaduInt16();
67 mbValidPaper = maData.mbValid = !::get_flag( nFlags, EXC_SETUP_INVALID );
68 maData.mbPrintInRows = ::get_flag( nFlags, EXC_SETUP_INROWS );
69 maData.mbPortrait = ::get_flag( nFlags, EXC_SETUP_PORTRAIT );
70 maData.mbBlackWhite = ::get_flag( nFlags, EXC_SETUP_BLACKWHITE );
71 maData.mbManualStart = true;
73 // new in BIFF5 - BIFF8
74 if( GetBiff() >= EXC_BIFF5 )
76 maData.mnHorPrintRes = rStrm.ReaduInt16();
77 maData.mnVerPrintRes = rStrm.ReaduInt16();
78 maData.mfHeaderMargin = rStrm.ReadDouble();
79 maData.mfFooterMargin = rStrm.ReadDouble();
80 maData.mnCopies = rStrm.ReaduInt16();
82 maData.mbDraftQuality = ::get_flag( nFlags, EXC_SETUP_DRAFT );
83 maData.mbPrintNotes = ::get_flag( nFlags, EXC_SETUP_PRINTNOTES );
84 maData.mbManualStart = ::get_flag( nFlags, EXC_SETUP_STARTPAGE );
88 void XclImpPageSettings::ReadMargin( XclImpStream& rStrm )
90 switch( rStrm.GetRecId() )
92 case EXC_ID_LEFTMARGIN: maData.mfLeftMargin = rStrm.ReadDouble(); break;
93 case EXC_ID_RIGHTMARGIN: maData.mfRightMargin = rStrm.ReadDouble(); break;
94 case EXC_ID_TOPMARGIN: maData.mfTopMargin = rStrm.ReadDouble(); break;
95 case EXC_ID_BOTTOMMARGIN: maData.mfBottomMargin = rStrm.ReadDouble(); break;
96 default: OSL_FAIL( "XclImpPageSettings::ReadMargin - unknown record" );
100 void XclImpPageSettings::ReadCenter( XclImpStream& rStrm )
102 OSL_ENSURE_BIFF( GetBiff() >= EXC_BIFF3 ); // read it anyway
103 bool bCenter = (rStrm.ReaduInt16() != 0);
104 switch( rStrm.GetRecId() )
106 case EXC_ID_HCENTER: maData.mbHorCenter = bCenter; break;
107 case EXC_ID_VCENTER: maData.mbVerCenter = bCenter; break;
108 default: OSL_FAIL( "XclImpPageSettings::ReadCenter - unknown record" );
112 void XclImpPageSettings::ReadHeaderFooter( XclImpStream& rStrm )
114 OUString aString;
115 if( rStrm.GetRecLeft() )
116 aString = (GetBiff() <= EXC_BIFF5) ? rStrm.ReadByteString( false ) : rStrm.ReadUniString();
118 switch( rStrm.GetRecId() )
120 case EXC_ID_HEADER: maData.maHeader = aString; break;
121 case EXC_ID_FOOTER: maData.maFooter = aString; break;
122 default: OSL_FAIL( "XclImpPageSettings::ReadHeaderFooter - unknown record" );
126 void XclImpPageSettings::ReadPageBreaks( XclImpStream& rStrm )
128 ScfUInt16Vec* pVec = 0;
129 switch( rStrm.GetRecId() )
131 case EXC_ID_HORPAGEBREAKS: pVec = &maData.maHorPageBreaks; break;
132 case EXC_ID_VERPAGEBREAKS: pVec = &maData.maVerPageBreaks; break;
133 default: OSL_FAIL( "XclImpPageSettings::ReadPageBreaks - unknown record" );
136 if( pVec )
138 bool bIgnore = GetBiff() == EXC_BIFF8; // ignore start/end columns or rows in BIFF8
140 sal_uInt16 nCount, nBreak;
141 nCount = rStrm.ReaduInt16();
142 pVec->clear();
143 pVec->reserve( nCount );
145 while( nCount-- )
147 nBreak = rStrm.ReaduInt16();
148 if( nBreak )
149 pVec->push_back( nBreak );
150 if( bIgnore )
151 rStrm.Ignore( 4 );
156 void XclImpPageSettings::ReadPrintHeaders( XclImpStream& rStrm )
158 maData.mbPrintHeadings = (rStrm.ReaduInt16() != 0);
161 void XclImpPageSettings::ReadPrintGridLines( XclImpStream& rStrm )
163 maData.mbPrintGrid = (rStrm.ReaduInt16() != 0);
166 void XclImpPageSettings::ReadImgData( XclImpStream& rStrm )
168 Graphic aGraphic = XclImpDrawing::ReadImgData( GetRoot(), rStrm );
169 if( aGraphic.GetType() != GRAPHIC_NONE )
170 maData.mxBrushItem.reset( new SvxBrushItem( aGraphic, GPOS_TILED, ATTR_BACKGROUND ) );
173 void XclImpPageSettings::SetPaperSize( sal_uInt16 nXclPaperSize, bool bPortrait )
175 maData.mnPaperSize = nXclPaperSize;
176 maData.mbPortrait = bPortrait;
177 mbValidPaper = true;
180 namespace {
182 void lclPutMarginItem( SfxItemSet& rItemSet, sal_uInt16 nRecId, double fMarginInch )
184 sal_uInt16 nMarginTwips = XclTools::GetTwipsFromInch( fMarginInch );
185 switch( nRecId )
187 case EXC_ID_TOPMARGIN:
188 case EXC_ID_BOTTOMMARGIN:
190 SvxULSpaceItem aItem( GETITEM( rItemSet, SvxULSpaceItem, ATTR_ULSPACE ) );
191 if( nRecId == EXC_ID_TOPMARGIN )
192 aItem.SetUpperValue( nMarginTwips );
193 else
194 aItem.SetLowerValue( nMarginTwips );
195 rItemSet.Put( aItem );
197 break;
198 case EXC_ID_LEFTMARGIN:
199 case EXC_ID_RIGHTMARGIN:
201 SvxLRSpaceItem aItem( GETITEM( rItemSet, SvxLRSpaceItem, ATTR_LRSPACE ) );
202 if( nRecId == EXC_ID_LEFTMARGIN )
203 aItem.SetLeftValue( nMarginTwips );
204 else
205 aItem.SetRightValue( nMarginTwips );
206 rItemSet.Put( aItem );
208 break;
209 default:
210 OSL_FAIL( "XclImpPageSettings::SetMarginItem - unknown record id" );
214 } // namespace
216 void XclImpPageSettings::Finalize()
218 ScDocument& rDoc = GetDoc();
219 SCTAB nScTab = GetCurrScTab();
221 // *** create page style sheet ***
223 OUStringBuffer aStyleName;
224 aStyleName.appendAscii("PageStyle_");
226 OUString aTableName;
227 if( GetDoc().GetName( nScTab, aTableName ) )
228 aStyleName.append(aTableName);
229 else
230 aStyleName.append(static_cast<sal_Int32>(nScTab+1));
232 ScStyleSheet& rStyleSheet = ScfTools::MakePageStyleSheet(
233 GetStyleSheetPool(), aStyleName.makeStringAndClear(), false);
235 SfxItemSet& rItemSet = rStyleSheet.GetItemSet();
237 // *** page settings ***
239 ScfTools::PutItem( rItemSet, SfxBoolItem( ATTR_PAGE_TOPDOWN, !maData.mbPrintInRows ), true );
240 ScfTools::PutItem( rItemSet, SfxBoolItem( ATTR_PAGE_HORCENTER, maData.mbHorCenter ), true );
241 ScfTools::PutItem( rItemSet, SfxBoolItem( ATTR_PAGE_VERCENTER, maData.mbVerCenter ), true );
242 ScfTools::PutItem( rItemSet, SfxBoolItem( ATTR_PAGE_HEADERS, maData.mbPrintHeadings ), true );
243 ScfTools::PutItem( rItemSet, SfxBoolItem( ATTR_PAGE_GRID, maData.mbPrintGrid ), true );
244 ScfTools::PutItem( rItemSet, SfxBoolItem( ATTR_PAGE_NOTES, maData.mbPrintNotes ), true );
246 sal_uInt16 nStartPage = maData.mbManualStart ? maData.mnStartPage : 0;
247 ScfTools::PutItem( rItemSet, SfxUInt16Item( ATTR_PAGE_FIRSTPAGENO, nStartPage ), true );
249 if( maData.mxBrushItem.get() )
250 rItemSet.Put( *maData.mxBrushItem );
252 if( mbValidPaper )
254 SvxPageItem aPageItem( GETITEM( rItemSet, SvxPageItem, ATTR_PAGE ) );
255 aPageItem.SetLandscape( !maData.mbPortrait );
256 rItemSet.Put( aPageItem );
257 ScfTools::PutItem( rItemSet, SvxSizeItem( ATTR_PAGE_SIZE, maData.GetScPaperSize() ), true );
260 if( maData.mbFitToPages )
261 rItemSet.Put( ScPageScaleToItem( maData.mnFitToWidth, maData.mnFitToHeight ) );
262 else if( maData.mbValid )
263 rItemSet.Put( SfxUInt16Item( ATTR_PAGE_SCALE, maData.mnScaling ) );
265 // *** margin preparations ***
267 double fLeftMargin = maData.mfLeftMargin;
268 double fRightMargin = maData.mfRightMargin;
269 double fTopMargin = maData.mfTopMargin;
270 double fBottomMargin = maData.mfBottomMargin;
271 // distances between header/footer and page area
272 double fHeaderHeight = 0.0;
273 double fHeaderDist = 0.0;
274 double fFooterHeight = 0.0;
275 double fFooterDist = 0.0;
276 // in Calc, "header/footer left/right margin" is X distance between header/footer and page margin
277 double fHdrLeftMargin = maData.mfHdrLeftMargin - maData.mfLeftMargin;
278 double fHdrRightMargin = maData.mfHdrRightMargin - maData.mfRightMargin;
279 double fFtrLeftMargin = maData.mfFtrLeftMargin - maData.mfLeftMargin;
280 double fFtrRightMargin = maData.mfFtrRightMargin - maData.mfRightMargin;
282 // *** header and footer ***
284 XclImpHFConverter aHFConv( GetRoot() );
286 // header
287 bool bHasHeader = !maData.maHeader.isEmpty();
288 SvxSetItem aHdrSetItem( GETITEM( rItemSet, SvxSetItem, ATTR_PAGE_HEADERSET ) );
289 SfxItemSet& rHdrItemSet = aHdrSetItem.GetItemSet();
290 rHdrItemSet.Put( SfxBoolItem( ATTR_PAGE_ON, bHasHeader ) );
291 if( bHasHeader )
293 aHFConv.ParseString( maData.maHeader );
294 aHFConv.FillToItemSet( rItemSet, ATTR_PAGE_HEADERLEFT );
295 aHFConv.FillToItemSet( rItemSet, ATTR_PAGE_HEADERRIGHT );
296 // #i23296# In Calc, "top margin" is distance to header
297 fTopMargin = maData.mfHeaderMargin;
298 // Calc uses distance between header and sheet data area
299 fHeaderHeight = XclTools::GetInchFromTwips( aHFConv.GetTotalHeight() );
300 fHeaderDist = maData.mfTopMargin - maData.mfHeaderMargin - fHeaderHeight;
302 if( fHeaderDist < 0.0 )
304 /* #i23296# Header overlays sheet data:
305 -> set fixed header height to get correct sheet data position. */
306 ScfTools::PutItem( rHdrItemSet, SfxBoolItem( ATTR_PAGE_DYNAMIC, false ), true );
307 // shrink header height
308 long nHdrHeight = XclTools::GetTwipsFromInch( fHeaderHeight + fHeaderDist );
309 ScfTools::PutItem( rHdrItemSet, SvxSizeItem( ATTR_PAGE_SIZE, Size( 0, nHdrHeight ) ), true );
310 lclPutMarginItem( rHdrItemSet, EXC_ID_BOTTOMMARGIN, 0.0 );
312 else
314 // use dynamic header height
315 ScfTools::PutItem( rHdrItemSet, SfxBoolItem( ATTR_PAGE_DYNAMIC, true ), true );
316 lclPutMarginItem( rHdrItemSet, EXC_ID_BOTTOMMARGIN, fHeaderDist );
318 lclPutMarginItem( rHdrItemSet, EXC_ID_LEFTMARGIN, fHdrLeftMargin );
319 lclPutMarginItem( rHdrItemSet, EXC_ID_RIGHTMARGIN, fHdrRightMargin );
320 rItemSet.Put( aHdrSetItem );
322 // footer
323 bool bHasFooter = !maData.maFooter.isEmpty();
324 SvxSetItem aFtrSetItem( GETITEM( rItemSet, SvxSetItem, ATTR_PAGE_FOOTERSET ) );
325 SfxItemSet& rFtrItemSet = aFtrSetItem.GetItemSet();
326 rFtrItemSet.Put( SfxBoolItem( ATTR_PAGE_ON, bHasFooter ) );
327 if( bHasFooter )
329 aHFConv.ParseString( maData.maFooter );
330 aHFConv.FillToItemSet( rItemSet, ATTR_PAGE_FOOTERLEFT );
331 aHFConv.FillToItemSet( rItemSet, ATTR_PAGE_FOOTERRIGHT );
332 // #i23296# In Calc, "bottom margin" is distance to footer
333 fBottomMargin = maData.mfFooterMargin;
334 // Calc uses distance between footer and sheet data area
335 fFooterHeight = XclTools::GetInchFromTwips( aHFConv.GetTotalHeight() );
336 fFooterDist = maData.mfBottomMargin - maData.mfFooterMargin - fFooterHeight;
338 if( fFooterDist < 0.0 )
340 /* #i23296# Footer overlays sheet data:
341 -> set fixed footer height to get correct sheet data end position. */
342 ScfTools::PutItem( rFtrItemSet, SfxBoolItem( ATTR_PAGE_DYNAMIC, false ), true );
343 // shrink footer height
344 long nFtrHeight = XclTools::GetTwipsFromInch( fFooterHeight + fFooterDist );
345 ScfTools::PutItem( rFtrItemSet, SvxSizeItem( ATTR_PAGE_SIZE, Size( 0, nFtrHeight ) ), true );
346 lclPutMarginItem( rFtrItemSet, EXC_ID_TOPMARGIN, 0.0 );
348 else
350 // use dynamic footer height
351 ScfTools::PutItem( rFtrItemSet, SfxBoolItem( ATTR_PAGE_DYNAMIC, true ), true );
352 lclPutMarginItem( rFtrItemSet, EXC_ID_TOPMARGIN, fFooterDist );
354 lclPutMarginItem( rFtrItemSet, EXC_ID_LEFTMARGIN, fFtrLeftMargin );
355 lclPutMarginItem( rFtrItemSet, EXC_ID_RIGHTMARGIN, fFtrRightMargin );
356 rItemSet.Put( aFtrSetItem );
358 // *** set final margins ***
360 lclPutMarginItem( rItemSet, EXC_ID_LEFTMARGIN, fLeftMargin );
361 lclPutMarginItem( rItemSet, EXC_ID_RIGHTMARGIN, fRightMargin );
362 lclPutMarginItem( rItemSet, EXC_ID_TOPMARGIN, fTopMargin );
363 lclPutMarginItem( rItemSet, EXC_ID_BOTTOMMARGIN, fBottomMargin );
365 // *** put style sheet into document ***
367 rDoc.SetPageStyle( nScTab, rStyleSheet.GetName() );
369 // *** page breaks ***
371 ScfUInt16Vec::const_iterator aIt, aEnd;
373 for( aIt = maData.maHorPageBreaks.begin(), aEnd = maData.maHorPageBreaks.end(); aIt != aEnd; ++aIt )
375 SCROW nScRow = static_cast< SCROW >( *aIt );
376 if( nScRow <= MAXROW )
377 rDoc.SetRowBreak(nScRow, nScTab, false, true);
380 for( aIt = maData.maVerPageBreaks.begin(), aEnd = maData.maVerPageBreaks.end(); aIt != aEnd; ++aIt )
382 SCCOL nScCol = static_cast< SCCOL >( *aIt );
383 if( nScCol <= MAXCOL )
384 rDoc.SetColBreak(nScCol, nScTab, false, true);
388 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */