1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23 #include <vbahelper/vbapagesetupbase.hxx>
24
25 using namespace ::com::sun::star;
26 using namespace ::ooo::vba;
27
VbaPageSetupBase(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext)28 VbaPageSetupBase::VbaPageSetupBase(const uno::Reference< XHelperInterface >& xParent,
29 const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException): VbaPageSetupBase_BASE( xParent, xContext )
30 {
31 }
32
getTopMargin()33 double SAL_CALL VbaPageSetupBase::getTopMargin() throw (css::uno::RuntimeException)
34 {
35 sal_Bool headerOn = sal_False;
36 sal_Int32 topMargin = 0;
37 sal_Int32 headerHeight = 0;
38
39 try
40 {
41 uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn")));
42 aValue >>= headerOn;
43
44 aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin")));
45 aValue >>= topMargin;
46
47 if( headerOn )
48 {
49 aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderHeight")));
50 aValue >>= headerHeight;
51 topMargin = topMargin + headerHeight;
52 }
53 }
54 catch( uno::Exception& )
55 {
56 }
57
58 return Millimeter::getInPoints( topMargin );
59 }
60
setTopMargin(double margin)61 void SAL_CALL VbaPageSetupBase::setTopMargin( double margin ) throw (css::uno::RuntimeException)
62 {
63 sal_Int32 topMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
64 sal_Bool headerOn = sal_False;
65 sal_Int32 headerHeight = 0;
66
67 try
68 {
69 uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn")));
70 aValue >>= headerOn;
71
72 if( headerOn )
73 {
74 aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderHeight")));
75 aValue >>= headerHeight;
76 topMargin -= headerHeight;
77 }
78
79 aValue <<= topMargin;
80 mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin")), aValue );
81 }
82 catch( uno::Exception& )
83 {
84 }
85 }
86
getBottomMargin()87 double SAL_CALL VbaPageSetupBase::getBottomMargin() throw (css::uno::RuntimeException)
88 {
89 sal_Bool footerOn = sal_False;
90 sal_Int32 bottomMargin = 0;
91 sal_Int32 footerHeight = 0;
92
93 try
94 {
95 uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsOn")));
96 aValue >>= footerOn;
97
98 aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin")));
99 aValue >>= bottomMargin;
100
101 if( footerOn )
102 {
103 aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterHeight")));
104 aValue >>= footerHeight;
105 bottomMargin += footerHeight;
106 }
107 }
108 catch( uno::Exception& )
109 {
110 }
111
112 return Millimeter::getInPoints( bottomMargin );
113 }
114
setBottomMargin(double margin)115 void SAL_CALL VbaPageSetupBase::setBottomMargin( double margin ) throw (css::uno::RuntimeException)
116 {
117 sal_Int32 bottomMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
118 sal_Bool footerOn = sal_False;
119 sal_Int32 footerHeight = 0;
120
121 try
122 {
123 uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsOn")));
124 aValue >>= footerOn;
125
126 if( footerOn )
127 {
128 aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterHeight")));
129 aValue >>= footerHeight;
130 bottomMargin -= footerHeight;
131 }
132
133 aValue <<= bottomMargin;
134 mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin")), aValue );
135 }
136 catch( uno::Exception& )
137 {
138 }
139 }
140
getRightMargin()141 double SAL_CALL VbaPageSetupBase::getRightMargin() throw (css::uno::RuntimeException)
142 {
143 sal_Int32 rightMargin = 0;
144 try
145 {
146 uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightMargin")));
147 aValue >>= rightMargin;
148 }
149 catch( uno::Exception& )
150 {
151 }
152
153 return Millimeter::getInPoints( rightMargin );;
154 }
155
setRightMargin(double margin)156 void SAL_CALL VbaPageSetupBase::setRightMargin( double margin ) throw (css::uno::RuntimeException)
157 {
158 sal_Int32 rightMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
159 try
160 {
161 uno::Any aValue;
162 aValue <<= rightMargin;
163 mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightMargin")), aValue );
164 }
165 catch( uno::Exception& )
166 {
167 }
168
169 }
170
getLeftMargin()171 double SAL_CALL VbaPageSetupBase::getLeftMargin() throw (css::uno::RuntimeException)
172 {
173 sal_Int32 leftMargin = 0;
174 try
175 {
176 uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin")));
177 aValue >>= leftMargin;
178 }
179 catch( uno::Exception& )
180 {
181 }
182
183 return Millimeter::getInPoints( leftMargin );;
184 }
185
setLeftMargin(double margin)186 void SAL_CALL VbaPageSetupBase::setLeftMargin( double margin ) throw (css::uno::RuntimeException)
187 {
188 sal_Int32 leftMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
189 try
190 {
191 uno::Any aValue;
192 aValue <<= leftMargin;
193 mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin")), aValue );
194 }
195 catch( uno::Exception& )
196 {
197 }
198 }
199
getHeaderMargin()200 double SAL_CALL VbaPageSetupBase::getHeaderMargin() throw (css::uno::RuntimeException)
201 {
202 sal_Int32 headerMargin = 0;
203 try
204 {
205 uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin")));
206 aValue >>= headerMargin;
207 }
208 catch( uno::Exception& )
209 {
210 }
211
212 return Millimeter::getInPoints( headerMargin );;
213 }
214
setHeaderMargin(double margin)215 void SAL_CALL VbaPageSetupBase::setHeaderMargin( double margin ) throw (css::uno::RuntimeException)
216 {
217 sal_Int32 headerMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
218 try
219 {
220 uno::Any aValue;
221 aValue <<= headerMargin;
222 mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin")), aValue );
223 }
224 catch( uno::Exception& )
225 {
226 }
227 }
228
getFooterMargin()229 double SAL_CALL VbaPageSetupBase::getFooterMargin() throw (css::uno::RuntimeException)
230 {
231 sal_Int32 footerMargin = 0;
232 try
233 {
234 uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin")));
235 aValue >>= footerMargin;
236 }
237 catch( uno::Exception& )
238 {
239 }
240
241 return Millimeter::getInPoints( footerMargin );;
242 }
243
setFooterMargin(double margin)244 void SAL_CALL VbaPageSetupBase::setFooterMargin( double margin ) throw (css::uno::RuntimeException)
245 {
246 sal_Int32 footerMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
247 try
248 {
249 uno::Any aValue;
250 aValue <<= footerMargin;
251 mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin")), aValue );
252 }
253 catch( uno::Exception& )
254 {
255 }
256 }
257
getOrientation()258 sal_Int32 SAL_CALL VbaPageSetupBase::getOrientation() throw (css::uno::RuntimeException)
259 {
260 sal_Int32 orientation = mnOrientPortrait;
261 try
262 {
263 sal_Bool isLandscape = sal_False;
264 uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IsLandscape")));
265 aValue >>= isLandscape;
266
267 if( isLandscape )
268 {
269 orientation = mnOrientLandscape;
270 }
271 }
272 catch( uno::Exception& )
273 {
274 }
275 return orientation;
276 }
277
setOrientation(sal_Int32 orientation)278 void SAL_CALL VbaPageSetupBase::setOrientation( sal_Int32 orientation ) throw (css::uno::RuntimeException)
279 {
280 if( ( orientation != mnOrientPortrait ) &&
281 ( orientation != mnOrientLandscape ) )
282 {
283 DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
284 }
285
286 try
287 {
288 sal_Bool isLandscape = sal_False;
289 uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IsLandscape")));
290 aValue >>= isLandscape;
291
292 sal_Bool switchOrientation = sal_False;
293 if(( isLandscape && orientation != mnOrientLandscape ) ||
294 ( !isLandscape && orientation != mnOrientPortrait ))
295 {
296 switchOrientation = sal_True;
297 }
298
299 if( switchOrientation )
300 {
301 aValue <<= !isLandscape;
302 uno::Any aHeight = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Height")));
303 uno::Any aWidth = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Width")));
304 mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IsLandscape")), aValue );
305 mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Width")), aHeight );
306 mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Height")), aWidth );
307 }
308
309 if( isLandscape )
310 {
311 orientation = mnOrientLandscape;
312 }
313 }
314 catch( uno::Exception& )
315 {
316 }
317 }
318
319