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 : #include "vbapagesetup.hxx"
20 : #include "cellsuno.hxx"
21 : #include "convuno.hxx"
22 : #include "rangelst.hxx"
23 : #include "excelvbahelper.hxx"
24 : #include <com/sun/star/sheet/XPrintAreas.hpp>
25 : #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
26 : #include <com/sun/star/text/XText.hpp>
27 : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
28 : #include <com/sun/star/container/XNameAccess.hpp>
29 : #include <ooo/vba/excel/XlPageOrientation.hpp>
30 : #include <ooo/vba/excel/XlOrder.hpp>
31 : #include <ooo/vba/excel/Constants.hpp>
32 : #include <i18nutil/paper.hxx>
33 : #include <sal/macros.h>
34 : #include <algorithm>
35 : #include <filter/msfilter/util.hxx>
36 :
37 : using namespace ::com::sun::star;
38 : using namespace ::ooo::vba;
39 :
40 : #define ZOOM_IN 10
41 : #define ZOOM_MAX 400
42 :
43 : bool getScRangeListForAddress( const OUString& sName, ScDocShell* pDocSh, ScRange& refRange, ScRangeList& aCellRanges, formula::FormulaGrammar::AddressConvention aConv = formula::FormulaGrammar::CONV_XL_A1 ) throw ( uno::RuntimeException );
44 :
45 56 : ScVbaPageSetup::ScVbaPageSetup(const uno::Reference< XHelperInterface >& xParent,
46 : const uno::Reference< uno::XComponentContext >& xContext,
47 : const uno::Reference< sheet::XSpreadsheet >& xSheet,
48 : const uno::Reference< frame::XModel >& xModel) throw (uno::RuntimeException):
49 56 : ScVbaPageSetup_BASE( xParent, xContext ), mxSheet( xSheet ), mbIsLandscape( false )
50 : {
51 : // query for current page style
52 56 : mxModel.set( xModel, uno::UNO_QUERY_THROW );
53 56 : uno::Reference< beans::XPropertySet > xSheetProps( mxSheet, uno::UNO_QUERY_THROW );
54 112 : uno::Any aValue = xSheetProps->getPropertyValue("PageStyle");
55 112 : OUString aStyleName;
56 56 : aValue >>= aStyleName;
57 :
58 112 : uno::Reference< style::XStyleFamiliesSupplier > xStyleFamiliesSup( mxModel, uno::UNO_QUERY_THROW );
59 112 : uno::Reference< container::XNameAccess > xStyleFamilies = xStyleFamiliesSup->getStyleFamilies();
60 112 : uno::Reference< container::XNameAccess > xPageStyle( xStyleFamilies->getByName("PageStyles"), uno::UNO_QUERY_THROW );
61 56 : mxPageProps.set( xPageStyle->getByName(aStyleName), uno::UNO_QUERY_THROW );
62 56 : mnOrientLandscape = excel::XlPageOrientation::xlLandscape;
63 56 : mnOrientPortrait = excel::XlPageOrientation::xlPortrait;
64 112 : mxPageProps->getPropertyValue("IsLandscape") >>= mbIsLandscape;
65 56 : }
66 :
67 0 : OUString SAL_CALL ScVbaPageSetup::getPrintArea() throw (css::uno::RuntimeException, std::exception)
68 : {
69 0 : OUString aPrintArea;
70 0 : uno::Reference< sheet::XPrintAreas > xPrintAreas( mxSheet, uno::UNO_QUERY_THROW );
71 0 : uno::Sequence< table::CellRangeAddress > aSeq = xPrintAreas->getPrintAreas();
72 0 : sal_Int32 nCount = aSeq.getLength();
73 0 : if( nCount )
74 : {
75 0 : ScAddress::Details aDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 );
76 0 : sal_uInt16 nFlags = SCA_VALID;
77 0 : nFlags |= ( SCA_TAB_ABSOLUTE | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB2_ABSOLUTE | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE );
78 0 : ScRangeList aRangeList;
79 0 : for( sal_Int32 i=0; i<nCount; i++ )
80 : {
81 0 : ScRange aRange;
82 0 : ScUnoConversion::FillScRange( aRange, aSeq[i] );
83 0 : aRangeList.Append( aRange );
84 : }
85 0 : ScDocument* pDoc = excel::getDocShell( mxModel )->GetDocument();
86 0 : aRangeList.Format( aPrintArea, nFlags, pDoc, formula::FormulaGrammar::CONV_XL_A1, ',' );
87 : }
88 :
89 0 : return aPrintArea;
90 : }
91 :
92 0 : void SAL_CALL ScVbaPageSetup::setPrintArea( const OUString& rAreas ) throw (css::uno::RuntimeException, std::exception)
93 : {
94 0 : uno::Reference< sheet::XPrintAreas > xPrintAreas( mxSheet, uno::UNO_QUERY_THROW );
95 0 : if( rAreas.isEmpty() ||
96 0 : rAreas.equalsIgnoreAsciiCase( "FALSE" ) )
97 : {
98 : // print the whole sheet
99 0 : uno::Sequence< table::CellRangeAddress > aSeq;
100 0 : xPrintAreas->setPrintAreas( aSeq );
101 : }
102 : else
103 : {
104 0 : ScRangeList aCellRanges;
105 0 : ScRange aRange;
106 0 : if( getScRangeListForAddress( rAreas, excel::getDocShell( mxModel ) , aRange, aCellRanges ) )
107 : {
108 0 : uno::Sequence< table::CellRangeAddress > aSeq( aCellRanges.size() );
109 0 : for ( size_t i = 0, nRanges = aCellRanges.size(); i < nRanges; ++i )
110 : {
111 0 : ScRange* pRange = aCellRanges[ i ];
112 0 : table::CellRangeAddress aRangeAddress;
113 0 : ScUnoConversion::FillApiRange( aRangeAddress, *pRange );
114 0 : aSeq[ i++ ] = aRangeAddress;
115 : }
116 0 : xPrintAreas->setPrintAreas( aSeq );
117 0 : }
118 0 : }
119 0 : }
120 :
121 1 : double SAL_CALL ScVbaPageSetup::getHeaderMargin() throw (css::uno::RuntimeException)
122 : {
123 1 : return VbaPageSetupBase::getHeaderMargin();
124 : }
125 :
126 1 : void SAL_CALL ScVbaPageSetup::setHeaderMargin( double margin ) throw (css::uno::RuntimeException)
127 : {
128 1 : VbaPageSetupBase::setHeaderMargin( margin );
129 1 : }
130 :
131 1 : double SAL_CALL ScVbaPageSetup::getFooterMargin() throw (css::uno::RuntimeException)
132 : {
133 1 : return VbaPageSetupBase::getFooterMargin();
134 : }
135 :
136 1 : void SAL_CALL ScVbaPageSetup::setFooterMargin( double margin ) throw (css::uno::RuntimeException)
137 : {
138 1 : VbaPageSetupBase::setFooterMargin( margin );
139 1 : }
140 :
141 3 : uno::Any SAL_CALL ScVbaPageSetup::getFitToPagesTall() throw (css::uno::RuntimeException, std::exception)
142 : {
143 3 : return mxPageProps->getPropertyValue("ScaleToPagesY");
144 : }
145 :
146 1 : void SAL_CALL ScVbaPageSetup::setFitToPagesTall( const uno::Any& fitToPagesTall) throw (css::uno::RuntimeException, std::exception)
147 : {
148 1 : sal_uInt16 scaleToPageY = 0;
149 : try
150 : {
151 : sal_Bool aValue;
152 1 : if( fitToPagesTall.getValueTypeClass() != uno::TypeClass_BOOLEAN || (fitToPagesTall >>= aValue))
153 : {
154 1 : fitToPagesTall >>= scaleToPageY;
155 : }
156 :
157 1 : mxPageProps->setPropertyValue("ScaleToPagesY", uno::makeAny( scaleToPageY ));
158 : }
159 0 : catch( uno::Exception& )
160 : {
161 : }
162 1 : }
163 :
164 3 : uno::Any SAL_CALL ScVbaPageSetup::getFitToPagesWide() throw (css::uno::RuntimeException, std::exception)
165 : {
166 3 : return mxPageProps->getPropertyValue("ScaleToPagesX");
167 : }
168 :
169 1 : void SAL_CALL ScVbaPageSetup::setFitToPagesWide( const uno::Any& fitToPagesWide) throw (css::uno::RuntimeException, std::exception)
170 : {
171 1 : sal_uInt16 scaleToPageX = 0;
172 : try
173 : {
174 1 : sal_Bool aValue = false;
175 1 : if( fitToPagesWide.getValueTypeClass() != uno::TypeClass_BOOLEAN || (fitToPagesWide >>= aValue))
176 : {
177 1 : fitToPagesWide >>= scaleToPageX;
178 : }
179 :
180 1 : mxPageProps->setPropertyValue("ScaleToPagesX", uno::makeAny( scaleToPageX ));
181 : }
182 0 : catch( uno::Exception& )
183 : {
184 : }
185 1 : }
186 :
187 5 : uno::Any SAL_CALL ScVbaPageSetup::getZoom() throw (css::uno::RuntimeException, std::exception)
188 : {
189 5 : return mxPageProps->getPropertyValue("PageScale");
190 : }
191 :
192 3 : void SAL_CALL ScVbaPageSetup::setZoom( const uno::Any& zoom) throw (css::uno::RuntimeException, std::exception)
193 : {
194 3 : sal_uInt16 pageScale = 0;
195 : try
196 : {
197 3 : if( zoom.getValueTypeClass() == uno::TypeClass_BOOLEAN )
198 : {
199 2 : sal_Bool aValue = false;
200 2 : zoom >>= aValue;
201 2 : if( aValue )
202 : {
203 0 : DebugHelper::exception(SbERR_BAD_PARAMETER, OUString() );
204 : }
205 : }
206 : else
207 : {
208 1 : zoom >>= pageScale;
209 1 : if(( pageScale < ZOOM_IN )||( pageScale > ZOOM_MAX ))
210 : {
211 0 : DebugHelper::exception(SbERR_BAD_PARAMETER, OUString() );
212 : }
213 : }
214 :
215 : // these only exist in S08
216 3 : sal_uInt16 nScale = 0;
217 3 : mxPageProps->setPropertyValue("ScaleToPages", uno::makeAny( nScale ));
218 3 : mxPageProps->setPropertyValue("ScaleToPagesX", uno::makeAny( nScale ));
219 3 : mxPageProps->setPropertyValue("ScaleToPagesY", uno::makeAny( nScale ));
220 : }
221 0 : catch( beans::UnknownPropertyException& )
222 : {
223 0 : if( pageScale == 0 )
224 : {
225 0 : DebugHelper::exception(SbERR_BAD_PARAMETER, OUString() );
226 : }
227 : }
228 0 : catch( uno::Exception& )
229 : {
230 : }
231 :
232 3 : mxPageProps->setPropertyValue("PageScale", uno::makeAny( pageScale ));
233 3 : }
234 :
235 1 : OUString SAL_CALL ScVbaPageSetup::getLeftHeader() throw (css::uno::RuntimeException, std::exception)
236 : {
237 1 : OUString leftHeader;
238 : try
239 : {
240 1 : uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue("RightPageHeaderContent"), uno::UNO_QUERY_THROW);
241 1 : if( xHeaderContent.is() )
242 : {
243 1 : uno::Reference< text::XText > xText = xHeaderContent->getLeftText();
244 1 : leftHeader = xText->getString();
245 1 : }
246 : }
247 0 : catch( uno::Exception& )
248 : {
249 : }
250 :
251 1 : return leftHeader;
252 : }
253 :
254 1 : void SAL_CALL ScVbaPageSetup::setLeftHeader( const OUString& leftHeader) throw (css::uno::RuntimeException, std::exception)
255 : {
256 : try
257 : {
258 1 : uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue("RightPageHeaderContent"), uno::UNO_QUERY_THROW);
259 1 : if( xHeaderContent.is() )
260 : {
261 1 : uno::Reference< text::XText > xText = xHeaderContent->getLeftText();
262 1 : xText->setString( leftHeader );
263 1 : mxPageProps->setPropertyValue("RightPageHeaderContent", uno::makeAny(xHeaderContent) );
264 1 : }
265 : }
266 0 : catch( uno::Exception& )
267 : {
268 : }
269 1 : }
270 :
271 1 : OUString SAL_CALL ScVbaPageSetup::getCenterHeader() throw (css::uno::RuntimeException, std::exception)
272 : {
273 1 : OUString centerHeader;
274 : try
275 : {
276 1 : uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue("RightPageHeaderContent"), uno::UNO_QUERY_THROW);
277 1 : if( xHeaderContent.is() )
278 : {
279 1 : uno::Reference< text::XText > xText = xHeaderContent->getCenterText();
280 1 : centerHeader = xText->getString();
281 1 : }
282 : }
283 0 : catch( uno::Exception& )
284 : {
285 : }
286 :
287 1 : return centerHeader;
288 : }
289 :
290 1 : void SAL_CALL ScVbaPageSetup::setCenterHeader( const OUString& centerHeader) throw (css::uno::RuntimeException, std::exception)
291 : {
292 : try
293 : {
294 1 : uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue("RightPageHeaderContent"), uno::UNO_QUERY_THROW);
295 1 : if( xHeaderContent.is() )
296 : {
297 1 : uno::Reference< text::XText > xText = xHeaderContent->getCenterText();
298 1 : xText->setString( centerHeader );
299 1 : mxPageProps->setPropertyValue("RightPageHeaderContent", uno::makeAny(xHeaderContent) );
300 1 : }
301 : }
302 0 : catch( uno::Exception& )
303 : {
304 : }
305 1 : }
306 :
307 1 : OUString SAL_CALL ScVbaPageSetup::getRightHeader() throw (css::uno::RuntimeException, std::exception)
308 : {
309 1 : OUString rightHeader;
310 : try
311 : {
312 1 : uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue("RightPageHeaderContent"), uno::UNO_QUERY_THROW);
313 1 : if( xHeaderContent.is() )
314 : {
315 1 : uno::Reference< text::XText > xText = xHeaderContent->getRightText();
316 1 : rightHeader = xText->getString();
317 1 : }
318 : }
319 0 : catch( uno::Exception& )
320 : {
321 : }
322 :
323 1 : return rightHeader;
324 : }
325 :
326 1 : void SAL_CALL ScVbaPageSetup::setRightHeader( const OUString& rightHeader) throw (css::uno::RuntimeException, std::exception)
327 : {
328 : try
329 : {
330 1 : uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue("RightPageHeaderContent"), uno::UNO_QUERY_THROW);
331 1 : if( xHeaderContent.is() )
332 : {
333 1 : uno::Reference< text::XText > xText = xHeaderContent->getRightText();
334 1 : xText->setString( rightHeader );
335 1 : mxPageProps->setPropertyValue("RightPageHeaderContent", uno::makeAny(xHeaderContent) );
336 1 : }
337 : }
338 0 : catch( uno::Exception& )
339 : {
340 : }
341 1 : }
342 :
343 1 : OUString SAL_CALL ScVbaPageSetup::getLeftFooter() throw (css::uno::RuntimeException, std::exception)
344 : {
345 1 : OUString leftFooter;
346 : try
347 : {
348 1 : uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue("RightPageFooterContent"), uno::UNO_QUERY_THROW);
349 1 : if( xFooterContent.is() )
350 : {
351 1 : uno::Reference< text::XText > xText = xFooterContent->getLeftText();
352 1 : leftFooter = xText->getString();
353 1 : }
354 : }
355 0 : catch( uno::Exception& )
356 : {
357 : }
358 :
359 1 : return leftFooter;
360 : }
361 :
362 1 : void SAL_CALL ScVbaPageSetup::setLeftFooter( const OUString& leftFooter) throw (css::uno::RuntimeException, std::exception)
363 : {
364 : try
365 : {
366 1 : uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue("RightPageFooterContent"), uno::UNO_QUERY_THROW);
367 1 : if( xFooterContent.is() )
368 : {
369 1 : uno::Reference< text::XText > xText = xFooterContent->getLeftText();
370 1 : xText->setString( leftFooter );
371 1 : mxPageProps->setPropertyValue("RightPageFooterContent", uno::makeAny(xFooterContent) );
372 1 : }
373 : }
374 0 : catch( uno::Exception& )
375 : {
376 : }
377 1 : }
378 :
379 1 : OUString SAL_CALL ScVbaPageSetup::getCenterFooter() throw (css::uno::RuntimeException, std::exception)
380 : {
381 1 : OUString centerFooter;
382 : try
383 : {
384 1 : uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue("RightPageFooterContent"), uno::UNO_QUERY_THROW);
385 1 : if( xFooterContent.is() )
386 : {
387 1 : uno::Reference< text::XText > xText = xFooterContent->getCenterText();
388 1 : centerFooter = xText->getString();
389 1 : }
390 : }
391 0 : catch( uno::Exception& )
392 : {
393 : }
394 :
395 1 : return centerFooter;
396 : }
397 :
398 1 : void SAL_CALL ScVbaPageSetup::setCenterFooter( const OUString& centerFooter) throw (css::uno::RuntimeException, std::exception)
399 : {
400 : try
401 : {
402 1 : uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue("RightPageFooterContent"), uno::UNO_QUERY_THROW);
403 1 : if( xFooterContent.is() )
404 : {
405 1 : uno::Reference< text::XText > xText = xFooterContent->getCenterText();
406 1 : xText->setString( centerFooter );
407 1 : mxPageProps->setPropertyValue("RightPageFooterContent", uno::makeAny(xFooterContent) );
408 1 : }
409 : }
410 0 : catch( uno::Exception& )
411 : {
412 : }
413 :
414 1 : }
415 :
416 1 : OUString SAL_CALL ScVbaPageSetup::getRightFooter() throw (css::uno::RuntimeException, std::exception)
417 : {
418 1 : OUString rightFooter;
419 : try
420 : {
421 1 : uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue("RightPageFooterContent"), uno::UNO_QUERY_THROW);
422 1 : if( xFooterContent.is() )
423 : {
424 1 : uno::Reference< text::XText > xText = xFooterContent->getRightText();
425 1 : rightFooter = xText->getString();
426 1 : }
427 : }
428 0 : catch( uno::Exception& )
429 : {
430 : }
431 :
432 1 : return rightFooter;
433 : }
434 :
435 1 : void SAL_CALL ScVbaPageSetup::setRightFooter( const OUString& rightFooter) throw (css::uno::RuntimeException, std::exception)
436 : {
437 : try
438 : {
439 1 : uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue("RightPageFooterContent"), uno::UNO_QUERY_THROW);
440 1 : if( xFooterContent.is() )
441 : {
442 1 : uno::Reference< text::XText > xText = xFooterContent->getRightText();
443 1 : xText->setString( rightFooter );
444 1 : mxPageProps->setPropertyValue("RightPageFooterContent", uno::makeAny(xFooterContent) );
445 1 : }
446 : }
447 0 : catch( uno::Exception& )
448 : {
449 : }
450 1 : }
451 :
452 2 : sal_Int32 SAL_CALL ScVbaPageSetup::getOrder() throw (css::uno::RuntimeException, std::exception)
453 : {
454 2 : sal_Int32 order = excel::XlOrder::xlDownThenOver;
455 : try
456 : {
457 2 : uno::Any aValue = mxPageProps->getPropertyValue("PrintDownFirst");
458 2 : sal_Bool bPrintDownFirst = false;
459 2 : aValue >>= bPrintDownFirst;
460 2 : if( !bPrintDownFirst )
461 1 : order = excel::XlOrder::xlOverThenDown;
462 : }
463 0 : catch( uno::Exception& )
464 : {
465 : }
466 :
467 2 : return order;
468 : }
469 :
470 1 : void SAL_CALL ScVbaPageSetup::setOrder( sal_Int32 order) throw (css::uno::RuntimeException, std::exception)
471 : {
472 1 : sal_Bool bOrder = sal_True;
473 1 : switch( order )
474 : {
475 : case excel::XlOrder::xlDownThenOver:
476 0 : break;
477 : case excel::XlOrder::xlOverThenDown:
478 1 : bOrder = false;
479 1 : break;
480 : default:
481 0 : DebugHelper::exception(SbERR_BAD_PARAMETER, OUString() );
482 : }
483 :
484 : try
485 : {
486 1 : mxPageProps->setPropertyValue("PrintDownFirst", uno::makeAny( bOrder ));
487 : }
488 0 : catch( uno::Exception& )
489 : {
490 : }
491 1 : }
492 :
493 2 : sal_Int32 SAL_CALL ScVbaPageSetup::getFirstPageNumber() throw (css::uno::RuntimeException, std::exception)
494 : {
495 2 : sal_Int16 number = 0;
496 : try
497 : {
498 2 : uno::Any aValue = mxPageProps->getPropertyValue("FirstPageNumber");
499 2 : aValue >>= number;
500 : }
501 0 : catch( uno::Exception& )
502 : {
503 : }
504 :
505 2 : if( number ==0 )
506 : {
507 1 : number = excel::Constants::xlAutomatic;
508 : }
509 :
510 2 : return number;
511 : }
512 :
513 1 : void SAL_CALL ScVbaPageSetup::setFirstPageNumber( sal_Int32 firstPageNumber) throw (css::uno::RuntimeException, std::exception)
514 : {
515 1 : if( firstPageNumber == excel::Constants::xlAutomatic )
516 0 : firstPageNumber = 0;
517 :
518 : try
519 : {
520 1 : uno::Any aValue;
521 1 : aValue <<= (sal_Int16)firstPageNumber;
522 1 : mxPageProps->setPropertyValue("FirstPageNumber", aValue );
523 : }
524 0 : catch( uno::Exception& )
525 : {
526 : }
527 1 : }
528 :
529 2 : sal_Bool SAL_CALL ScVbaPageSetup::getCenterVertically() throw (css::uno::RuntimeException, std::exception)
530 : {
531 2 : sal_Bool centerVertically = false;
532 : try
533 : {
534 2 : uno::Any aValue = mxPageProps->getPropertyValue("CenterVertically");
535 2 : aValue >>= centerVertically;
536 : }
537 0 : catch( uno::Exception& )
538 : {
539 : }
540 2 : return centerVertically;
541 : }
542 :
543 1 : void SAL_CALL ScVbaPageSetup::setCenterVertically( sal_Bool centerVertically) throw (css::uno::RuntimeException, std::exception)
544 : {
545 : try
546 : {
547 1 : mxPageProps->setPropertyValue("CenterVertically", uno::makeAny( centerVertically ));
548 : }
549 0 : catch( uno::Exception& )
550 : {
551 : }
552 1 : }
553 :
554 2 : sal_Bool SAL_CALL ScVbaPageSetup::getCenterHorizontally() throw (css::uno::RuntimeException, std::exception)
555 : {
556 2 : sal_Bool centerHorizontally = false;
557 : try
558 : {
559 2 : uno::Any aValue = mxPageProps->getPropertyValue("CenterHorizontally");
560 2 : aValue >>= centerHorizontally;
561 : }
562 0 : catch( uno::Exception& )
563 : {
564 : }
565 2 : return centerHorizontally;
566 : }
567 :
568 1 : void SAL_CALL ScVbaPageSetup::setCenterHorizontally( sal_Bool centerHorizontally) throw (css::uno::RuntimeException, std::exception)
569 : {
570 : try
571 : {
572 1 : mxPageProps->setPropertyValue("CenterHorizontally", uno::makeAny( centerHorizontally ));
573 : }
574 0 : catch( uno::Exception& )
575 : {
576 : }
577 1 : }
578 :
579 2 : sal_Bool SAL_CALL ScVbaPageSetup::getPrintHeadings() throw (css::uno::RuntimeException, std::exception)
580 : {
581 2 : sal_Bool printHeadings = false;
582 : try
583 : {
584 2 : uno::Any aValue = mxPageProps->getPropertyValue("PrintHeaders");
585 2 : aValue >>= printHeadings;
586 : }
587 0 : catch( uno::Exception& )
588 : {
589 : }
590 2 : return printHeadings;
591 : }
592 :
593 1 : void SAL_CALL ScVbaPageSetup::setPrintHeadings( sal_Bool printHeadings) throw (css::uno::RuntimeException, std::exception)
594 : {
595 : try
596 : {
597 1 : mxPageProps->setPropertyValue("PrintHeaders", uno::makeAny( printHeadings ));
598 : }
599 0 : catch( uno::Exception& )
600 : {
601 : }
602 1 : }
603 :
604 0 : sal_Bool SAL_CALL ScVbaPageSetup::getPrintGridlines() throw (uno::RuntimeException, std::exception)
605 : {
606 0 : return false;
607 : }
608 :
609 0 : void SAL_CALL ScVbaPageSetup::setPrintGridlines( sal_Bool /*_printgridlines*/ ) throw (uno::RuntimeException, std::exception)
610 : {
611 0 : }
612 :
613 0 : OUString SAL_CALL ScVbaPageSetup::getPrintTitleRows() throw (uno::RuntimeException, std::exception)
614 : {
615 0 : return OUString();
616 : }
617 0 : void SAL_CALL ScVbaPageSetup::setPrintTitleRows( const OUString& /*_printtitlerows*/ ) throw (css::uno::RuntimeException, std::exception)
618 : {
619 0 : }
620 0 : OUString SAL_CALL ScVbaPageSetup::getPrintTitleColumns() throw (uno::RuntimeException, std::exception)
621 : {
622 0 : return OUString();
623 : }
624 :
625 0 : void SAL_CALL ScVbaPageSetup::setPrintTitleColumns( const OUString& /*_printtitlecolumns*/ ) throw (uno::RuntimeException, std::exception)
626 : {
627 0 : }
628 :
629 2 : sal_Int32 SAL_CALL ScVbaPageSetup::getPaperSize() throw (uno::RuntimeException, std::exception)
630 : {
631 2 : awt::Size aSize; // current papersize
632 2 : mxPageProps->getPropertyValue( "Size" ) >>= aSize;
633 2 : if ( mbIsLandscape )
634 2 : ::std::swap( aSize.Width, aSize.Height );
635 :
636 2 : sal_Int32 nPaperSizeIndex = msfilter::util::PaperSizeConv::getMSPaperSizeIndex( aSize );
637 2 : if ( nPaperSizeIndex == 0 )
638 0 : nPaperSizeIndex = excel::XlPaperSize::xlPaperUser;
639 2 : return nPaperSizeIndex;
640 : }
641 :
642 1 : void SAL_CALL ScVbaPageSetup::setPaperSize( sal_Int32 papersize ) throw (uno::RuntimeException, std::exception)
643 : {
644 1 : if ( papersize != excel::XlPaperSize::xlPaperUser )
645 : {
646 1 : awt::Size aPaperSize;
647 1 : const msfilter::util::ApiPaperSize& rConvertedSize = msfilter::util::PaperSizeConv::getApiSizeForMSPaperSizeIndex( papersize );
648 1 : aPaperSize.Height = rConvertedSize.mnHeight;
649 1 : aPaperSize.Width = rConvertedSize.mnWidth;
650 1 : if ( mbIsLandscape )
651 1 : ::std::swap( aPaperSize.Width, aPaperSize.Height );
652 1 : mxPageProps->setPropertyValue( "Size", uno::makeAny( aPaperSize ) );
653 : }
654 1 : }
655 :
656 : OUString
657 0 : ScVbaPageSetup::getServiceImplName()
658 : {
659 0 : return OUString("ScVbaPageSetup");
660 : }
661 :
662 : uno::Sequence< OUString >
663 0 : ScVbaPageSetup::getServiceNames()
664 : {
665 0 : static uno::Sequence< OUString > aServiceNames;
666 0 : if ( aServiceNames.getLength() == 0 )
667 : {
668 0 : aServiceNames.realloc( 1 );
669 0 : aServiceNames[ 0 ] = "ooo.vba.excel.PageSetup";
670 : }
671 0 : return aServiceNames;
672 : }
673 :
674 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|