1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
19 #include <vbahelper/vbapagesetupbase.hxx>
20 #include <basic/sberrors.hxx>
21 #include <com/sun/star/beans/XPropertySet.hpp>
23 using namespace ::com::sun::star
;
24 using namespace ::ooo::vba
;
26 VbaPageSetupBase::VbaPageSetupBase(const uno::Reference
< XHelperInterface
>& xParent
,
27 const uno::Reference
< uno::XComponentContext
>& xContext
)
28 : VbaPageSetupBase_BASE( xParent
, xContext
)
29 , mnOrientLandscape(0)
34 double SAL_CALL
VbaPageSetupBase::getTopMargin()
36 sal_Int32 topMargin
= 0;
40 bool headerOn
= false;
42 uno::Any aValue
= mxPageProps
->getPropertyValue( "HeaderIsOn" );
45 aValue
= mxPageProps
->getPropertyValue( "TopMargin" );
50 sal_Int32 headerHeight
= 0;
51 aValue
= mxPageProps
->getPropertyValue( "HeaderHeight" );
52 aValue
>>= headerHeight
;
53 topMargin
= topMargin
+ headerHeight
;
56 catch( uno::Exception
& )
60 return Millimeter::getInPoints( topMargin
);
63 void SAL_CALL
VbaPageSetupBase::setTopMargin( double margin
)
65 sal_Int32 topMargin
= Millimeter::getInHundredthsOfOneMillimeter( margin
);
69 bool headerOn
= false;
71 uno::Any aValue
= mxPageProps
->getPropertyValue( "HeaderIsOn" );
76 sal_Int32 headerHeight
= 0;
77 aValue
= mxPageProps
->getPropertyValue( "HeaderHeight" );
78 aValue
>>= headerHeight
;
79 topMargin
-= headerHeight
;
82 mxPageProps
->setPropertyValue( "TopMargin" , uno::Any(topMargin
) );
84 catch( uno::Exception
& )
89 double SAL_CALL
VbaPageSetupBase::getBottomMargin()
91 sal_Int32 bottomMargin
= 0;
95 bool footerOn
= false;
97 uno::Any aValue
= mxPageProps
->getPropertyValue( "FooterIsOn" );
100 aValue
= mxPageProps
->getPropertyValue( "BottomMargin" );
101 aValue
>>= bottomMargin
;
105 sal_Int32 footerHeight
= 0;
106 aValue
= mxPageProps
->getPropertyValue( "FooterHeight" );
107 aValue
>>= footerHeight
;
108 bottomMargin
+= footerHeight
;
111 catch( uno::Exception
& )
115 return Millimeter::getInPoints( bottomMargin
);
118 void SAL_CALL
VbaPageSetupBase::setBottomMargin( double margin
)
120 sal_Int32 bottomMargin
= Millimeter::getInHundredthsOfOneMillimeter( margin
);
124 bool footerOn
= false;
126 uno::Any aValue
= mxPageProps
->getPropertyValue( "FooterIsOn" );
131 sal_Int32 footerHeight
= 0;
132 aValue
= mxPageProps
->getPropertyValue( "FooterHeight" );
133 aValue
>>= footerHeight
;
134 bottomMargin
-= footerHeight
;
137 mxPageProps
->setPropertyValue( "BottomMargin", uno::Any(bottomMargin
) );
139 catch( uno::Exception
& )
144 double SAL_CALL
VbaPageSetupBase::getRightMargin()
146 sal_Int32 rightMargin
= 0;
149 uno::Any aValue
= mxPageProps
->getPropertyValue( "RightMargin" );
150 aValue
>>= rightMargin
;
152 catch( uno::Exception
& )
156 return Millimeter::getInPoints( rightMargin
);
159 void SAL_CALL
VbaPageSetupBase::setRightMargin( double margin
)
161 sal_Int32 rightMargin
= Millimeter::getInHundredthsOfOneMillimeter( margin
);
164 mxPageProps
->setPropertyValue( "RightMargin", uno::Any(rightMargin
) );
166 catch( uno::Exception
& )
172 double SAL_CALL
VbaPageSetupBase::getLeftMargin()
174 sal_Int32 leftMargin
= 0;
177 uno::Any aValue
= mxPageProps
->getPropertyValue( "LeftMargin" );
178 aValue
>>= leftMargin
;
180 catch( uno::Exception
& )
184 return Millimeter::getInPoints( leftMargin
);
187 void SAL_CALL
VbaPageSetupBase::setLeftMargin( double margin
)
189 sal_Int32 leftMargin
= Millimeter::getInHundredthsOfOneMillimeter( margin
);
192 mxPageProps
->setPropertyValue( "LeftMargin", uno::Any(leftMargin
) );
194 catch( uno::Exception
& )
199 double VbaPageSetupBase::getHeaderMargin()
201 sal_Int32 headerMargin
= 0;
204 uno::Any aValue
= mxPageProps
->getPropertyValue( "TopMargin" );
205 aValue
>>= headerMargin
;
207 catch( uno::Exception
& )
211 return Millimeter::getInPoints( headerMargin
);
214 void VbaPageSetupBase::setHeaderMargin( double margin
)
216 sal_Int32 headerMargin
= Millimeter::getInHundredthsOfOneMillimeter( margin
);
219 mxPageProps
->setPropertyValue( "TopMargin", uno::Any(headerMargin
) );
221 catch( uno::Exception
& )
226 double VbaPageSetupBase::getFooterMargin()
228 sal_Int32 footerMargin
= 0;
231 uno::Any aValue
= mxPageProps
->getPropertyValue( "BottomMargin" );
232 aValue
>>= footerMargin
;
234 catch( uno::Exception
& )
238 return Millimeter::getInPoints( footerMargin
);
241 void VbaPageSetupBase::setFooterMargin( double margin
)
243 sal_Int32 footerMargin
= Millimeter::getInHundredthsOfOneMillimeter( margin
);
246 mxPageProps
->setPropertyValue( "BottomMargin", uno::Any(footerMargin
) );
248 catch( uno::Exception
& )
253 sal_Int32 SAL_CALL
VbaPageSetupBase::getOrientation()
255 sal_Int32 orientation
= mnOrientPortrait
;
258 bool isLandscape
= false;
259 uno::Any aValue
= mxPageProps
->getPropertyValue( "IsLandscape" );
260 aValue
>>= isLandscape
;
264 orientation
= mnOrientLandscape
;
267 catch( uno::Exception
& )
273 void SAL_CALL
VbaPageSetupBase::setOrientation( sal_Int32 orientation
)
275 if( ( orientation
!= mnOrientPortrait
) &&
276 ( orientation
!= mnOrientLandscape
) )
278 DebugHelper::runtimeexception(ERRCODE_BASIC_BAD_PARAMETER
);
283 bool isLandscape
= false;
284 uno::Any aValue
= mxPageProps
->getPropertyValue( "IsLandscape" );
285 aValue
>>= isLandscape
;
287 bool switchOrientation
= false;
288 if(( isLandscape
&& orientation
!= mnOrientLandscape
) ||
289 ( !isLandscape
&& orientation
!= mnOrientPortrait
))
291 switchOrientation
= true;
294 if( switchOrientation
)
296 uno::Any aHeight
= mxPageProps
->getPropertyValue( "Height" );
297 uno::Any aWidth
= mxPageProps
->getPropertyValue( "Width" );
298 mxPageProps
->setPropertyValue( "IsLandscape", uno::Any(!isLandscape
) );
299 mxPageProps
->setPropertyValue( "Width" , aHeight
);
300 mxPageProps
->setPropertyValue( "Height" , aWidth
);
303 catch( uno::Exception
& )
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */