xref: /aoo41x/main/sc/source/ui/vba/vbapagesetup.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir #include "vbapagesetup.hxx"
28*cdf0e10cSrcweir #include "cellsuno.hxx"
29*cdf0e10cSrcweir #include "convuno.hxx"
30*cdf0e10cSrcweir #include "rangelst.hxx"
31*cdf0e10cSrcweir #include "excelvbahelper.hxx"
32*cdf0e10cSrcweir #include <com/sun/star/sheet/XPrintAreas.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/text/XText.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
37*cdf0e10cSrcweir #include <ooo/vba/excel/XlPageOrientation.hpp>
38*cdf0e10cSrcweir #include <ooo/vba/excel/XlOrder.hpp>
39*cdf0e10cSrcweir #include <ooo/vba/excel/Constants.hpp>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir using namespace ::com::sun::star;
42*cdf0e10cSrcweir using namespace ::ooo::vba;
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #define ZOOM_IN 10
45*cdf0e10cSrcweir #define ZOOM_MAX 400
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir bool getScRangeListForAddress( const rtl::OUString& sName, ScDocShell* pDocSh, ScRange& refRange, ScRangeList& aCellRanges, formula::FormulaGrammar::AddressConvention aConv = formula::FormulaGrammar::CONV_XL_A1 ) throw ( uno::RuntimeException );
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir ScVbaPageSetup::ScVbaPageSetup(const uno::Reference< XHelperInterface >& xParent,
50*cdf0e10cSrcweir 				const uno::Reference< uno::XComponentContext >& xContext,
51*cdf0e10cSrcweir 				const uno::Reference< sheet::XSpreadsheet >& xSheet,
52*cdf0e10cSrcweir 				const uno::Reference< frame::XModel >& xModel) throw (uno::RuntimeException):
53*cdf0e10cSrcweir 	   	ScVbaPageSetup_BASE( xParent, xContext ), mxSheet( xSheet )
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir     // query for current page style
56*cdf0e10cSrcweir     mxModel.set( xModel, uno::UNO_QUERY_THROW );
57*cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xSheetProps( mxSheet, uno::UNO_QUERY_THROW );
58*cdf0e10cSrcweir     uno::Any aValue = xSheetProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PageStyle" )));
59*cdf0e10cSrcweir     rtl::OUString aStyleName;
60*cdf0e10cSrcweir     aValue >>= aStyleName;
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir     uno::Reference< style::XStyleFamiliesSupplier > xStyleFamiliesSup( mxModel, uno::UNO_QUERY_THROW );
63*cdf0e10cSrcweir     uno::Reference< container::XNameAccess > xStyleFamilies = xStyleFamiliesSup->getStyleFamilies();
64*cdf0e10cSrcweir     uno::Reference< container::XNameAccess > xPageStyle( xStyleFamilies->getByName(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyles"))), uno::UNO_QUERY_THROW );
65*cdf0e10cSrcweir     mxPageProps.set( xPageStyle->getByName(aStyleName), uno::UNO_QUERY_THROW );
66*cdf0e10cSrcweir     mnOrientLandscape = excel::XlPageOrientation::xlLandscape;
67*cdf0e10cSrcweir     mnOrientPortrait = excel::XlPageOrientation::xlPortrait;
68*cdf0e10cSrcweir }
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir rtl::OUString SAL_CALL ScVbaPageSetup::getPrintArea() throw (css::uno::RuntimeException)
71*cdf0e10cSrcweir {
72*cdf0e10cSrcweir     String aPrintArea;
73*cdf0e10cSrcweir     uno::Reference< sheet::XPrintAreas > xPrintAreas( mxSheet, uno::UNO_QUERY_THROW );
74*cdf0e10cSrcweir     uno::Sequence< table::CellRangeAddress > aSeq = xPrintAreas->getPrintAreas();
75*cdf0e10cSrcweir     sal_Int32 nCount = aSeq.getLength();
76*cdf0e10cSrcweir     if( nCount )
77*cdf0e10cSrcweir     {
78*cdf0e10cSrcweir         ScAddress::Details aDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 );
79*cdf0e10cSrcweir         sal_uInt16 nFlags = SCA_VALID;
80*cdf0e10cSrcweir         nFlags |= ( SCA_TAB_ABSOLUTE | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB2_ABSOLUTE | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE );
81*cdf0e10cSrcweir 		ScRangeList aRangeList;
82*cdf0e10cSrcweir 		for( sal_Int32 i=0; i<nCount; i++ )
83*cdf0e10cSrcweir 		{
84*cdf0e10cSrcweir 			ScRange aRange;
85*cdf0e10cSrcweir 			ScUnoConversion::FillScRange( aRange, aSeq[i] );
86*cdf0e10cSrcweir 			aRangeList.Append( aRange );
87*cdf0e10cSrcweir 		}
88*cdf0e10cSrcweir 		ScDocument* pDoc = excel::getDocShell( mxModel )->GetDocument();
89*cdf0e10cSrcweir 		aRangeList.Format( aPrintArea, nFlags, pDoc, formula::FormulaGrammar::CONV_XL_A1, ','  );
90*cdf0e10cSrcweir     }
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir     return aPrintArea;
93*cdf0e10cSrcweir }
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir void SAL_CALL ScVbaPageSetup::setPrintArea( const rtl::OUString& rAreas ) throw (css::uno::RuntimeException)
96*cdf0e10cSrcweir {
97*cdf0e10cSrcweir     uno::Reference< sheet::XPrintAreas > xPrintAreas( mxSheet, uno::UNO_QUERY_THROW );
98*cdf0e10cSrcweir     if( rAreas.getLength() == 0 ||
99*cdf0e10cSrcweir         rAreas.equalsIgnoreAsciiCase ( rtl::OUString::createFromAscii("FALSE") ) )
100*cdf0e10cSrcweir     {
101*cdf0e10cSrcweir         // print the whole sheet
102*cdf0e10cSrcweir         uno::Sequence< table::CellRangeAddress > aSeq;
103*cdf0e10cSrcweir         xPrintAreas->setPrintAreas( aSeq );
104*cdf0e10cSrcweir     }
105*cdf0e10cSrcweir     else
106*cdf0e10cSrcweir     {
107*cdf0e10cSrcweir 		ScRangeList aCellRanges;
108*cdf0e10cSrcweir 		ScRange aRange;
109*cdf0e10cSrcweir 		if( getScRangeListForAddress( rAreas, excel::getDocShell( mxModel ) , aRange, aCellRanges ) )
110*cdf0e10cSrcweir 		{
111*cdf0e10cSrcweir 			uno::Sequence< table::CellRangeAddress > aSeq( aCellRanges.Count() );
112*cdf0e10cSrcweir 			sal_uInt16 i=0;
113*cdf0e10cSrcweir 			for( ScRange* pRange = aCellRanges.First(); pRange; pRange = aCellRanges.Next() )
114*cdf0e10cSrcweir 			{
115*cdf0e10cSrcweir 				table::CellRangeAddress aRangeAddress;
116*cdf0e10cSrcweir 				ScUnoConversion::FillApiRange( aRangeAddress, *pRange );
117*cdf0e10cSrcweir 				aSeq[ i++ ] = aRangeAddress;
118*cdf0e10cSrcweir 			}
119*cdf0e10cSrcweir 			xPrintAreas->setPrintAreas( aSeq );
120*cdf0e10cSrcweir 		}
121*cdf0e10cSrcweir     }
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir double SAL_CALL ScVbaPageSetup::getHeaderMargin() throw (css::uno::RuntimeException)
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir     return VbaPageSetupBase::getHeaderMargin();
127*cdf0e10cSrcweir }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir void SAL_CALL ScVbaPageSetup::setHeaderMargin( double margin ) throw (css::uno::RuntimeException)
130*cdf0e10cSrcweir {
131*cdf0e10cSrcweir     VbaPageSetupBase::setHeaderMargin( margin );
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir double SAL_CALL ScVbaPageSetup::getFooterMargin() throw (css::uno::RuntimeException)
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir     return VbaPageSetupBase::getFooterMargin();
137*cdf0e10cSrcweir }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir void SAL_CALL ScVbaPageSetup::setFooterMargin( double margin ) throw (css::uno::RuntimeException)
140*cdf0e10cSrcweir {
141*cdf0e10cSrcweir     VbaPageSetupBase::setFooterMargin( margin );
142*cdf0e10cSrcweir }
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir uno::Any SAL_CALL ScVbaPageSetup::getFitToPagesTall() throw (css::uno::RuntimeException)
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir     return mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ScaleToPagesY")));
147*cdf0e10cSrcweir }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir void SAL_CALL ScVbaPageSetup::setFitToPagesTall( const uno::Any& fitToPagesTall) throw (css::uno::RuntimeException)
150*cdf0e10cSrcweir {
151*cdf0e10cSrcweir     sal_uInt16 scaleToPageY = 0;
152*cdf0e10cSrcweir     try
153*cdf0e10cSrcweir     {
154*cdf0e10cSrcweir         sal_Bool aValue;
155*cdf0e10cSrcweir         if( fitToPagesTall.getValueTypeClass() != uno::TypeClass_BOOLEAN || (fitToPagesTall >>= aValue))
156*cdf0e10cSrcweir         {
157*cdf0e10cSrcweir             fitToPagesTall >>= scaleToPageY;
158*cdf0e10cSrcweir         }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir         mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ScaleToPagesY")), uno::makeAny( scaleToPageY ));
161*cdf0e10cSrcweir     }
162*cdf0e10cSrcweir     catch( uno::Exception& )
163*cdf0e10cSrcweir     {
164*cdf0e10cSrcweir     }
165*cdf0e10cSrcweir }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir uno::Any SAL_CALL ScVbaPageSetup::getFitToPagesWide() throw (css::uno::RuntimeException)
168*cdf0e10cSrcweir {
169*cdf0e10cSrcweir     return mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ScaleToPagesX")));
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir void SAL_CALL ScVbaPageSetup::setFitToPagesWide( const uno::Any& fitToPagesWide) throw (css::uno::RuntimeException)
173*cdf0e10cSrcweir {
174*cdf0e10cSrcweir     sal_uInt16 scaleToPageX = 0;
175*cdf0e10cSrcweir     try
176*cdf0e10cSrcweir     {
177*cdf0e10cSrcweir         sal_Bool aValue = sal_False;
178*cdf0e10cSrcweir         if( fitToPagesWide.getValueTypeClass() != uno::TypeClass_BOOLEAN || (fitToPagesWide >>= aValue))
179*cdf0e10cSrcweir         {
180*cdf0e10cSrcweir             fitToPagesWide >>= scaleToPageX;
181*cdf0e10cSrcweir         }
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir         mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ScaleToPagesX")), uno::makeAny( scaleToPageX ));
184*cdf0e10cSrcweir     }
185*cdf0e10cSrcweir     catch( uno::Exception& )
186*cdf0e10cSrcweir     {
187*cdf0e10cSrcweir     }
188*cdf0e10cSrcweir }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir uno::Any SAL_CALL ScVbaPageSetup::getZoom() throw (css::uno::RuntimeException)
191*cdf0e10cSrcweir {
192*cdf0e10cSrcweir     return mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageScale")));
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir void SAL_CALL ScVbaPageSetup::setZoom( const uno::Any& zoom) throw (css::uno::RuntimeException)
196*cdf0e10cSrcweir {
197*cdf0e10cSrcweir     sal_uInt16 pageScale = 0;
198*cdf0e10cSrcweir     try
199*cdf0e10cSrcweir     {
200*cdf0e10cSrcweir 		if( zoom.getValueTypeClass() == uno::TypeClass_BOOLEAN )
201*cdf0e10cSrcweir 		{
202*cdf0e10cSrcweir 		    sal_Bool aValue = sal_False;
203*cdf0e10cSrcweir 		    zoom >>= aValue;
204*cdf0e10cSrcweir 		    if( aValue )
205*cdf0e10cSrcweir 		    {
206*cdf0e10cSrcweir                 DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
207*cdf0e10cSrcweir 		    }
208*cdf0e10cSrcweir 		}
209*cdf0e10cSrcweir         else
210*cdf0e10cSrcweir         {
211*cdf0e10cSrcweir             zoom >>= pageScale;
212*cdf0e10cSrcweir             if(( pageScale < ZOOM_IN )||( pageScale > ZOOM_MAX ))
213*cdf0e10cSrcweir             {
214*cdf0e10cSrcweir                 DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
215*cdf0e10cSrcweir             }
216*cdf0e10cSrcweir         }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir         // these only exist in S08
219*cdf0e10cSrcweir         sal_uInt16 nScale = 0;
220*cdf0e10cSrcweir         mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ScaleToPages")), uno::makeAny( nScale ));
221*cdf0e10cSrcweir         mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ScaleToPagesX")), uno::makeAny( nScale ));
222*cdf0e10cSrcweir         mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ScaleToPagesY")), uno::makeAny( nScale ));
223*cdf0e10cSrcweir     }
224*cdf0e10cSrcweir     catch( beans::UnknownPropertyException& )
225*cdf0e10cSrcweir     {
226*cdf0e10cSrcweir         if( pageScale == 0 )
227*cdf0e10cSrcweir         {
228*cdf0e10cSrcweir             DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
229*cdf0e10cSrcweir         }
230*cdf0e10cSrcweir     }
231*cdf0e10cSrcweir     catch( uno::Exception& )
232*cdf0e10cSrcweir     {
233*cdf0e10cSrcweir     }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir     mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageScale")), uno::makeAny( pageScale ));
236*cdf0e10cSrcweir }
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir rtl::OUString SAL_CALL ScVbaPageSetup::getLeftHeader() throw (css::uno::RuntimeException)
239*cdf0e10cSrcweir {
240*cdf0e10cSrcweir     rtl::OUString leftHeader;
241*cdf0e10cSrcweir     try
242*cdf0e10cSrcweir     {
243*cdf0e10cSrcweir         uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageHeaderContent"))), uno::UNO_QUERY_THROW);
244*cdf0e10cSrcweir         if( xHeaderContent.is() )
245*cdf0e10cSrcweir         {
246*cdf0e10cSrcweir             uno::Reference< text::XText > xText = xHeaderContent->getLeftText();
247*cdf0e10cSrcweir             leftHeader = xText->getString();
248*cdf0e10cSrcweir         }
249*cdf0e10cSrcweir     }
250*cdf0e10cSrcweir     catch( uno::Exception& )
251*cdf0e10cSrcweir     {
252*cdf0e10cSrcweir     }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir     return leftHeader;
255*cdf0e10cSrcweir }
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir void SAL_CALL ScVbaPageSetup::setLeftHeader( const rtl::OUString& leftHeader) throw (css::uno::RuntimeException)
258*cdf0e10cSrcweir {
259*cdf0e10cSrcweir     try
260*cdf0e10cSrcweir     {
261*cdf0e10cSrcweir         uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageHeaderContent"))), uno::UNO_QUERY_THROW);
262*cdf0e10cSrcweir         if( xHeaderContent.is() )
263*cdf0e10cSrcweir         {
264*cdf0e10cSrcweir             uno::Reference< text::XText > xText = xHeaderContent->getLeftText();
265*cdf0e10cSrcweir             xText->setString( leftHeader );
266*cdf0e10cSrcweir             mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageHeaderContent")), uno::makeAny(xHeaderContent) );
267*cdf0e10cSrcweir         }
268*cdf0e10cSrcweir     }
269*cdf0e10cSrcweir     catch( uno::Exception& )
270*cdf0e10cSrcweir     {
271*cdf0e10cSrcweir     }
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir rtl::OUString SAL_CALL ScVbaPageSetup::getCenterHeader() throw (css::uno::RuntimeException)
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir     rtl::OUString centerHeader;
277*cdf0e10cSrcweir     try
278*cdf0e10cSrcweir     {
279*cdf0e10cSrcweir         uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageHeaderContent"))), uno::UNO_QUERY_THROW);
280*cdf0e10cSrcweir         if( xHeaderContent.is() )
281*cdf0e10cSrcweir         {
282*cdf0e10cSrcweir             uno::Reference< text::XText > xText = xHeaderContent->getCenterText();
283*cdf0e10cSrcweir             centerHeader = xText->getString();
284*cdf0e10cSrcweir         }
285*cdf0e10cSrcweir     }
286*cdf0e10cSrcweir     catch( uno::Exception& )
287*cdf0e10cSrcweir     {
288*cdf0e10cSrcweir     }
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir     return centerHeader;
291*cdf0e10cSrcweir }
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir void SAL_CALL ScVbaPageSetup::setCenterHeader( const rtl::OUString& centerHeader) throw (css::uno::RuntimeException)
294*cdf0e10cSrcweir {
295*cdf0e10cSrcweir     try
296*cdf0e10cSrcweir     {
297*cdf0e10cSrcweir         uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageHeaderContent"))), uno::UNO_QUERY_THROW);
298*cdf0e10cSrcweir         if( xHeaderContent.is() )
299*cdf0e10cSrcweir         {
300*cdf0e10cSrcweir             uno::Reference< text::XText > xText = xHeaderContent->getCenterText();
301*cdf0e10cSrcweir             xText->setString( centerHeader );
302*cdf0e10cSrcweir             mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageHeaderContent")), uno::makeAny(xHeaderContent) );
303*cdf0e10cSrcweir         }
304*cdf0e10cSrcweir     }
305*cdf0e10cSrcweir     catch( uno::Exception& )
306*cdf0e10cSrcweir     {
307*cdf0e10cSrcweir     }
308*cdf0e10cSrcweir }
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir rtl::OUString SAL_CALL ScVbaPageSetup::getRightHeader() throw (css::uno::RuntimeException)
311*cdf0e10cSrcweir {
312*cdf0e10cSrcweir     rtl::OUString rightHeader;
313*cdf0e10cSrcweir     try
314*cdf0e10cSrcweir     {
315*cdf0e10cSrcweir         uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageHeaderContent"))), uno::UNO_QUERY_THROW);
316*cdf0e10cSrcweir         if( xHeaderContent.is() )
317*cdf0e10cSrcweir         {
318*cdf0e10cSrcweir             uno::Reference< text::XText > xText = xHeaderContent->getRightText();
319*cdf0e10cSrcweir             rightHeader = xText->getString();
320*cdf0e10cSrcweir         }
321*cdf0e10cSrcweir     }
322*cdf0e10cSrcweir     catch( uno::Exception& )
323*cdf0e10cSrcweir     {
324*cdf0e10cSrcweir     }
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir     return rightHeader;
327*cdf0e10cSrcweir }
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir void SAL_CALL ScVbaPageSetup::setRightHeader( const rtl::OUString& rightHeader) throw (css::uno::RuntimeException)
330*cdf0e10cSrcweir {
331*cdf0e10cSrcweir     try
332*cdf0e10cSrcweir     {
333*cdf0e10cSrcweir         uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageHeaderContent"))), uno::UNO_QUERY_THROW);
334*cdf0e10cSrcweir         if( xHeaderContent.is() )
335*cdf0e10cSrcweir         {
336*cdf0e10cSrcweir             uno::Reference< text::XText > xText = xHeaderContent->getRightText();
337*cdf0e10cSrcweir             xText->setString( rightHeader );
338*cdf0e10cSrcweir             mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageHeaderContent")), uno::makeAny(xHeaderContent) );
339*cdf0e10cSrcweir         }
340*cdf0e10cSrcweir     }
341*cdf0e10cSrcweir     catch( uno::Exception& )
342*cdf0e10cSrcweir     {
343*cdf0e10cSrcweir     }
344*cdf0e10cSrcweir }
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir rtl::OUString SAL_CALL ScVbaPageSetup::getLeftFooter() throw (css::uno::RuntimeException)
347*cdf0e10cSrcweir {
348*cdf0e10cSrcweir     rtl::OUString leftFooter;
349*cdf0e10cSrcweir     try
350*cdf0e10cSrcweir     {
351*cdf0e10cSrcweir         uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageFooterContent"))), uno::UNO_QUERY_THROW);
352*cdf0e10cSrcweir         if( xFooterContent.is() )
353*cdf0e10cSrcweir         {
354*cdf0e10cSrcweir             uno::Reference< text::XText > xText = xFooterContent->getLeftText();
355*cdf0e10cSrcweir             leftFooter = xText->getString();
356*cdf0e10cSrcweir         }
357*cdf0e10cSrcweir     }
358*cdf0e10cSrcweir     catch( uno::Exception& )
359*cdf0e10cSrcweir     {
360*cdf0e10cSrcweir     }
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir     return leftFooter;
363*cdf0e10cSrcweir }
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir void SAL_CALL ScVbaPageSetup::setLeftFooter( const rtl::OUString& leftFooter) throw (css::uno::RuntimeException)
366*cdf0e10cSrcweir {
367*cdf0e10cSrcweir     try
368*cdf0e10cSrcweir     {
369*cdf0e10cSrcweir         uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageFooterContent"))), uno::UNO_QUERY_THROW);
370*cdf0e10cSrcweir         if( xFooterContent.is() )
371*cdf0e10cSrcweir         {
372*cdf0e10cSrcweir             uno::Reference< text::XText > xText = xFooterContent->getLeftText();
373*cdf0e10cSrcweir             xText->setString( leftFooter );
374*cdf0e10cSrcweir             mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageFooterContent")), uno::makeAny(xFooterContent) );
375*cdf0e10cSrcweir         }
376*cdf0e10cSrcweir     }
377*cdf0e10cSrcweir     catch( uno::Exception& )
378*cdf0e10cSrcweir     {
379*cdf0e10cSrcweir     }
380*cdf0e10cSrcweir }
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir rtl::OUString SAL_CALL ScVbaPageSetup::getCenterFooter() throw (css::uno::RuntimeException)
383*cdf0e10cSrcweir {
384*cdf0e10cSrcweir     rtl::OUString centerFooter;
385*cdf0e10cSrcweir     try
386*cdf0e10cSrcweir     {
387*cdf0e10cSrcweir         uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageFooterContent"))), uno::UNO_QUERY_THROW);
388*cdf0e10cSrcweir         if( xFooterContent.is() )
389*cdf0e10cSrcweir         {
390*cdf0e10cSrcweir             uno::Reference< text::XText > xText = xFooterContent->getCenterText();
391*cdf0e10cSrcweir             centerFooter = xText->getString();
392*cdf0e10cSrcweir         }
393*cdf0e10cSrcweir     }
394*cdf0e10cSrcweir     catch( uno::Exception& )
395*cdf0e10cSrcweir     {
396*cdf0e10cSrcweir     }
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir     return centerFooter;
399*cdf0e10cSrcweir }
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir void SAL_CALL ScVbaPageSetup::setCenterFooter( const rtl::OUString& centerFooter) throw (css::uno::RuntimeException)
402*cdf0e10cSrcweir {
403*cdf0e10cSrcweir     try
404*cdf0e10cSrcweir     {
405*cdf0e10cSrcweir         uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageFooterContent"))), uno::UNO_QUERY_THROW);
406*cdf0e10cSrcweir         if( xFooterContent.is() )
407*cdf0e10cSrcweir         {
408*cdf0e10cSrcweir             uno::Reference< text::XText > xText = xFooterContent->getCenterText();
409*cdf0e10cSrcweir             xText->setString( centerFooter );
410*cdf0e10cSrcweir             mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageFooterContent")), uno::makeAny(xFooterContent) );
411*cdf0e10cSrcweir         }
412*cdf0e10cSrcweir     }
413*cdf0e10cSrcweir     catch( uno::Exception& )
414*cdf0e10cSrcweir     {
415*cdf0e10cSrcweir     }
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir }
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir rtl::OUString SAL_CALL ScVbaPageSetup::getRightFooter() throw (css::uno::RuntimeException)
420*cdf0e10cSrcweir {
421*cdf0e10cSrcweir     rtl::OUString rightFooter;
422*cdf0e10cSrcweir     try
423*cdf0e10cSrcweir     {
424*cdf0e10cSrcweir         uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageFooterContent"))), uno::UNO_QUERY_THROW);
425*cdf0e10cSrcweir         if( xFooterContent.is() )
426*cdf0e10cSrcweir         {
427*cdf0e10cSrcweir             uno::Reference< text::XText > xText = xFooterContent->getRightText();
428*cdf0e10cSrcweir             rightFooter = xText->getString();
429*cdf0e10cSrcweir         }
430*cdf0e10cSrcweir     }
431*cdf0e10cSrcweir     catch( uno::Exception& )
432*cdf0e10cSrcweir     {
433*cdf0e10cSrcweir     }
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir     return rightFooter;
436*cdf0e10cSrcweir }
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir void SAL_CALL ScVbaPageSetup::setRightFooter( const rtl::OUString& rightFooter) throw (css::uno::RuntimeException)
439*cdf0e10cSrcweir {
440*cdf0e10cSrcweir     try
441*cdf0e10cSrcweir     {
442*cdf0e10cSrcweir         uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageFooterContent"))), uno::UNO_QUERY_THROW);
443*cdf0e10cSrcweir         if( xFooterContent.is() )
444*cdf0e10cSrcweir         {
445*cdf0e10cSrcweir             uno::Reference< text::XText > xText = xFooterContent->getRightText();
446*cdf0e10cSrcweir             xText->setString( rightFooter );
447*cdf0e10cSrcweir             mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageFooterContent")), uno::makeAny(xFooterContent) );
448*cdf0e10cSrcweir         }
449*cdf0e10cSrcweir     }
450*cdf0e10cSrcweir     catch( uno::Exception& )
451*cdf0e10cSrcweir     {
452*cdf0e10cSrcweir     }
453*cdf0e10cSrcweir }
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir sal_Int32 SAL_CALL ScVbaPageSetup::getOrder() throw (css::uno::RuntimeException)
456*cdf0e10cSrcweir {
457*cdf0e10cSrcweir     sal_Int32 order = excel::XlOrder::xlDownThenOver;
458*cdf0e10cSrcweir     try
459*cdf0e10cSrcweir     {
460*cdf0e10cSrcweir         uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PrintDownFirst")));
461*cdf0e10cSrcweir         sal_Bool bPrintDownFirst = sal_False;
462*cdf0e10cSrcweir         aValue >>= bPrintDownFirst;
463*cdf0e10cSrcweir         if( !bPrintDownFirst )
464*cdf0e10cSrcweir             order = excel::XlOrder::xlOverThenDown;
465*cdf0e10cSrcweir     }
466*cdf0e10cSrcweir     catch( uno::Exception& )
467*cdf0e10cSrcweir     {
468*cdf0e10cSrcweir     }
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir     return order;
471*cdf0e10cSrcweir }
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir void SAL_CALL ScVbaPageSetup::setOrder( sal_Int32 order) throw (css::uno::RuntimeException)
474*cdf0e10cSrcweir {
475*cdf0e10cSrcweir     sal_Bool bOrder = sal_True;
476*cdf0e10cSrcweir     switch( order )
477*cdf0e10cSrcweir     {
478*cdf0e10cSrcweir         case excel::XlOrder::xlDownThenOver:
479*cdf0e10cSrcweir             break;
480*cdf0e10cSrcweir         case excel::XlOrder::xlOverThenDown:
481*cdf0e10cSrcweir             bOrder = sal_False;
482*cdf0e10cSrcweir             break;
483*cdf0e10cSrcweir         default:
484*cdf0e10cSrcweir             DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
485*cdf0e10cSrcweir     }
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir     try
488*cdf0e10cSrcweir     {
489*cdf0e10cSrcweir         mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PrintDownFirst")), uno::makeAny( bOrder ));
490*cdf0e10cSrcweir     }
491*cdf0e10cSrcweir     catch( uno::Exception& )
492*cdf0e10cSrcweir     {
493*cdf0e10cSrcweir     }
494*cdf0e10cSrcweir }
495*cdf0e10cSrcweir 
496*cdf0e10cSrcweir sal_Int32 SAL_CALL ScVbaPageSetup::getFirstPageNumber() throw (css::uno::RuntimeException)
497*cdf0e10cSrcweir {
498*cdf0e10cSrcweir     sal_Int16 number = 0;
499*cdf0e10cSrcweir     try
500*cdf0e10cSrcweir     {
501*cdf0e10cSrcweir         uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FirstPageNumber")));
502*cdf0e10cSrcweir         aValue >>= number;
503*cdf0e10cSrcweir     }
504*cdf0e10cSrcweir     catch( uno::Exception& )
505*cdf0e10cSrcweir     {
506*cdf0e10cSrcweir     }
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir     if( number ==0 )
509*cdf0e10cSrcweir     {
510*cdf0e10cSrcweir         number = excel::Constants::xlAutomatic;
511*cdf0e10cSrcweir     }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir     return number;
514*cdf0e10cSrcweir }
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir void SAL_CALL ScVbaPageSetup::setFirstPageNumber( sal_Int32 firstPageNumber) throw (css::uno::RuntimeException)
517*cdf0e10cSrcweir {
518*cdf0e10cSrcweir     if( firstPageNumber < 0 )
519*cdf0e10cSrcweir         DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
520*cdf0e10cSrcweir     if( firstPageNumber == excel::Constants::xlAutomatic )
521*cdf0e10cSrcweir         firstPageNumber = 0;
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir     try
524*cdf0e10cSrcweir     {
525*cdf0e10cSrcweir         uno::Any aValue;
526*cdf0e10cSrcweir         aValue <<= (sal_Int16)firstPageNumber;
527*cdf0e10cSrcweir         mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FirstPageNumber")), aValue );
528*cdf0e10cSrcweir     }
529*cdf0e10cSrcweir     catch( uno::Exception& )
530*cdf0e10cSrcweir     {
531*cdf0e10cSrcweir     }
532*cdf0e10cSrcweir }
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir sal_Bool SAL_CALL ScVbaPageSetup::getCenterVertically() throw (css::uno::RuntimeException)
535*cdf0e10cSrcweir {
536*cdf0e10cSrcweir     sal_Bool centerVertically = sal_False;
537*cdf0e10cSrcweir     try
538*cdf0e10cSrcweir     {
539*cdf0e10cSrcweir         uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CenterVertically")));
540*cdf0e10cSrcweir         aValue >>= centerVertically;
541*cdf0e10cSrcweir     }
542*cdf0e10cSrcweir     catch( uno::Exception& )
543*cdf0e10cSrcweir     {
544*cdf0e10cSrcweir     }
545*cdf0e10cSrcweir     return centerVertically;
546*cdf0e10cSrcweir }
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir void SAL_CALL ScVbaPageSetup::setCenterVertically( sal_Bool centerVertically) throw (css::uno::RuntimeException)
549*cdf0e10cSrcweir {
550*cdf0e10cSrcweir     try
551*cdf0e10cSrcweir     {
552*cdf0e10cSrcweir         mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CenterVertically")), uno::makeAny( centerVertically ));
553*cdf0e10cSrcweir     }
554*cdf0e10cSrcweir     catch( uno::Exception& )
555*cdf0e10cSrcweir     {
556*cdf0e10cSrcweir     }
557*cdf0e10cSrcweir }
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir sal_Bool SAL_CALL ScVbaPageSetup::getCenterHorizontally() throw (css::uno::RuntimeException)
560*cdf0e10cSrcweir {
561*cdf0e10cSrcweir     sal_Bool centerHorizontally = sal_False;
562*cdf0e10cSrcweir     try
563*cdf0e10cSrcweir     {
564*cdf0e10cSrcweir         uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CenterHorizontally")));
565*cdf0e10cSrcweir         aValue >>= centerHorizontally;
566*cdf0e10cSrcweir     }
567*cdf0e10cSrcweir     catch( uno::Exception& )
568*cdf0e10cSrcweir     {
569*cdf0e10cSrcweir     }
570*cdf0e10cSrcweir     return centerHorizontally;
571*cdf0e10cSrcweir }
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir void SAL_CALL ScVbaPageSetup::setCenterHorizontally( sal_Bool centerHorizontally) throw (css::uno::RuntimeException)
574*cdf0e10cSrcweir {
575*cdf0e10cSrcweir     try
576*cdf0e10cSrcweir     {
577*cdf0e10cSrcweir         mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CenterHorizontally")), uno::makeAny( centerHorizontally ));
578*cdf0e10cSrcweir     }
579*cdf0e10cSrcweir     catch( uno::Exception& )
580*cdf0e10cSrcweir     {
581*cdf0e10cSrcweir     }
582*cdf0e10cSrcweir }
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir sal_Bool SAL_CALL ScVbaPageSetup::getPrintHeadings() throw (css::uno::RuntimeException)
585*cdf0e10cSrcweir {
586*cdf0e10cSrcweir     sal_Bool printHeadings = sal_False;
587*cdf0e10cSrcweir     try
588*cdf0e10cSrcweir     {
589*cdf0e10cSrcweir         uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PrintHeaders")));
590*cdf0e10cSrcweir         aValue >>= printHeadings;
591*cdf0e10cSrcweir     }
592*cdf0e10cSrcweir     catch( uno::Exception& )
593*cdf0e10cSrcweir     {
594*cdf0e10cSrcweir     }
595*cdf0e10cSrcweir     return printHeadings;
596*cdf0e10cSrcweir }
597*cdf0e10cSrcweir 
598*cdf0e10cSrcweir void SAL_CALL ScVbaPageSetup::setPrintHeadings( sal_Bool printHeadings) throw (css::uno::RuntimeException)
599*cdf0e10cSrcweir {
600*cdf0e10cSrcweir     try
601*cdf0e10cSrcweir     {
602*cdf0e10cSrcweir         mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PrintHeaders")), uno::makeAny( printHeadings ));
603*cdf0e10cSrcweir     }
604*cdf0e10cSrcweir     catch( uno::Exception& )
605*cdf0e10cSrcweir     {
606*cdf0e10cSrcweir     }
607*cdf0e10cSrcweir }
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir rtl::OUString&
610*cdf0e10cSrcweir ScVbaPageSetup::getServiceImplName()
611*cdf0e10cSrcweir {
612*cdf0e10cSrcweir 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaPageSetup") );
613*cdf0e10cSrcweir 	return sImplName;
614*cdf0e10cSrcweir }
615*cdf0e10cSrcweir 
616*cdf0e10cSrcweir uno::Sequence< rtl::OUString >
617*cdf0e10cSrcweir ScVbaPageSetup::getServiceNames()
618*cdf0e10cSrcweir {
619*cdf0e10cSrcweir 	static uno::Sequence< rtl::OUString > aServiceNames;
620*cdf0e10cSrcweir 	if ( aServiceNames.getLength() == 0 )
621*cdf0e10cSrcweir 	{
622*cdf0e10cSrcweir 		aServiceNames.realloc( 1 );
623*cdf0e10cSrcweir 		aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.PageSetup" ) );
624*cdf0e10cSrcweir 	}
625*cdf0e10cSrcweir 	return aServiceNames;
626*cdf0e10cSrcweir }
627