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 <vbahelper/vbapagesetupbase.hxx>
20 :
21 : using namespace ::com::sun::star;
22 : using namespace ::ooo::vba;
23 :
24 56 : VbaPageSetupBase::VbaPageSetupBase(const uno::Reference< XHelperInterface >& xParent,
25 : const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
26 : : VbaPageSetupBase_BASE( xParent, xContext )
27 : , mnOrientLandscape(0)
28 56 : , mnOrientPortrait(0)
29 : {
30 56 : }
31 :
32 2 : double SAL_CALL VbaPageSetupBase::getTopMargin() throw (css::uno::RuntimeException, std::exception)
33 : {
34 2 : sal_Bool headerOn = sal_False;
35 2 : sal_Int32 topMargin = 0;
36 2 : sal_Int32 headerHeight = 0;
37 :
38 : try
39 : {
40 2 : uno::Any aValue = mxPageProps->getPropertyValue( "HeaderIsOn" );
41 2 : aValue >>= headerOn;
42 :
43 2 : aValue = mxPageProps->getPropertyValue( "TopMargin" );
44 2 : aValue >>= topMargin;
45 :
46 2 : if( headerOn )
47 : {
48 1 : aValue = mxPageProps->getPropertyValue( "HeaderHeight" );
49 1 : aValue >>= headerHeight;
50 1 : topMargin = topMargin + headerHeight;
51 2 : }
52 : }
53 0 : catch( uno::Exception& )
54 : {
55 : }
56 :
57 2 : return Millimeter::getInPoints( topMargin );
58 : }
59 :
60 2 : void SAL_CALL VbaPageSetupBase::setTopMargin( double margin ) throw (css::uno::RuntimeException, std::exception)
61 : {
62 2 : sal_Int32 topMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
63 2 : sal_Bool headerOn = sal_False;
64 2 : sal_Int32 headerHeight = 0;
65 :
66 : try
67 : {
68 2 : uno::Any aValue = mxPageProps->getPropertyValue( "HeaderIsOn" );
69 2 : aValue >>= headerOn;
70 :
71 2 : if( headerOn )
72 : {
73 1 : aValue = mxPageProps->getPropertyValue( "HeaderHeight" );
74 1 : aValue >>= headerHeight;
75 1 : topMargin -= headerHeight;
76 : }
77 :
78 2 : aValue <<= topMargin;
79 2 : mxPageProps->setPropertyValue( "TopMargin" , aValue );
80 : }
81 0 : catch( uno::Exception& )
82 : {
83 : }
84 2 : }
85 :
86 2 : double SAL_CALL VbaPageSetupBase::getBottomMargin() throw (css::uno::RuntimeException, std::exception)
87 : {
88 2 : sal_Bool footerOn = sal_False;
89 2 : sal_Int32 bottomMargin = 0;
90 2 : sal_Int32 footerHeight = 0;
91 :
92 : try
93 : {
94 2 : uno::Any aValue = mxPageProps->getPropertyValue( "FooterIsOn" );
95 2 : aValue >>= footerOn;
96 :
97 2 : aValue = mxPageProps->getPropertyValue( "BottomMargin" );
98 2 : aValue >>= bottomMargin;
99 :
100 2 : if( footerOn )
101 : {
102 1 : aValue = mxPageProps->getPropertyValue( "FooterHeight" );
103 1 : aValue >>= footerHeight;
104 1 : bottomMargin += footerHeight;
105 2 : }
106 : }
107 0 : catch( uno::Exception& )
108 : {
109 : }
110 :
111 2 : return Millimeter::getInPoints( bottomMargin );
112 : }
113 :
114 2 : void SAL_CALL VbaPageSetupBase::setBottomMargin( double margin ) throw (css::uno::RuntimeException, std::exception)
115 : {
116 2 : sal_Int32 bottomMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
117 2 : sal_Bool footerOn = sal_False;
118 2 : sal_Int32 footerHeight = 0;
119 :
120 : try
121 : {
122 2 : uno::Any aValue = mxPageProps->getPropertyValue( "FooterIsOn" );
123 2 : aValue >>= footerOn;
124 :
125 2 : if( footerOn )
126 : {
127 1 : aValue = mxPageProps->getPropertyValue( "FooterHeight" );
128 1 : aValue >>= footerHeight;
129 1 : bottomMargin -= footerHeight;
130 : }
131 :
132 2 : aValue <<= bottomMargin;
133 2 : mxPageProps->setPropertyValue( "BottomMargin" , aValue );
134 : }
135 0 : catch( uno::Exception& )
136 : {
137 : }
138 2 : }
139 :
140 1 : double SAL_CALL VbaPageSetupBase::getRightMargin() throw (css::uno::RuntimeException, std::exception)
141 : {
142 1 : sal_Int32 rightMargin = 0;
143 : try
144 : {
145 1 : uno::Any aValue = mxPageProps->getPropertyValue( "RightMargin" );
146 1 : aValue >>= rightMargin;
147 : }
148 0 : catch( uno::Exception& )
149 : {
150 : }
151 :
152 1 : return Millimeter::getInPoints( rightMargin );
153 : }
154 :
155 1 : void SAL_CALL VbaPageSetupBase::setRightMargin( double margin ) throw (css::uno::RuntimeException, std::exception)
156 : {
157 1 : sal_Int32 rightMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
158 : try
159 : {
160 1 : uno::Any aValue;
161 1 : aValue <<= rightMargin;
162 1 : mxPageProps->setPropertyValue( "RightMargin" , aValue );
163 : }
164 0 : catch( uno::Exception& )
165 : {
166 : }
167 :
168 1 : }
169 :
170 1 : double SAL_CALL VbaPageSetupBase::getLeftMargin() throw (css::uno::RuntimeException, std::exception)
171 : {
172 1 : sal_Int32 leftMargin = 0;
173 : try
174 : {
175 1 : uno::Any aValue = mxPageProps->getPropertyValue( "LeftMargin" );
176 1 : aValue >>= leftMargin;
177 : }
178 0 : catch( uno::Exception& )
179 : {
180 : }
181 :
182 1 : return Millimeter::getInPoints( leftMargin );
183 : }
184 :
185 1 : void SAL_CALL VbaPageSetupBase::setLeftMargin( double margin ) throw (css::uno::RuntimeException, std::exception)
186 : {
187 1 : sal_Int32 leftMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
188 : try
189 : {
190 1 : uno::Any aValue;
191 1 : aValue <<= leftMargin;
192 1 : mxPageProps->setPropertyValue( "LeftMargin" , aValue );
193 : }
194 0 : catch( uno::Exception& )
195 : {
196 : }
197 1 : }
198 :
199 1 : double SAL_CALL VbaPageSetupBase::getHeaderMargin() throw (css::uno::RuntimeException)
200 : {
201 1 : sal_Int32 headerMargin = 0;
202 : try
203 : {
204 1 : uno::Any aValue = mxPageProps->getPropertyValue( "TopMargin" );
205 1 : aValue >>= headerMargin;
206 : }
207 0 : catch( uno::Exception& )
208 : {
209 : }
210 :
211 1 : return Millimeter::getInPoints( headerMargin );
212 : }
213 :
214 1 : void SAL_CALL VbaPageSetupBase::setHeaderMargin( double margin ) throw (css::uno::RuntimeException)
215 : {
216 1 : sal_Int32 headerMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
217 : try
218 : {
219 1 : uno::Any aValue;
220 1 : aValue <<= headerMargin;
221 1 : mxPageProps->setPropertyValue( "TopMargin" , aValue );
222 : }
223 0 : catch( uno::Exception& )
224 : {
225 : }
226 1 : }
227 :
228 1 : double SAL_CALL VbaPageSetupBase::getFooterMargin() throw (css::uno::RuntimeException)
229 : {
230 1 : sal_Int32 footerMargin = 0;
231 : try
232 : {
233 1 : uno::Any aValue = mxPageProps->getPropertyValue( "BottomMargin" );
234 1 : aValue >>= footerMargin;
235 : }
236 0 : catch( uno::Exception& )
237 : {
238 : }
239 :
240 1 : return Millimeter::getInPoints( footerMargin );
241 : }
242 :
243 1 : void SAL_CALL VbaPageSetupBase::setFooterMargin( double margin ) throw (css::uno::RuntimeException)
244 : {
245 1 : sal_Int32 footerMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
246 : try
247 : {
248 1 : uno::Any aValue;
249 1 : aValue <<= footerMargin;
250 1 : mxPageProps->setPropertyValue( "BottomMargin" , aValue );
251 : }
252 0 : catch( uno::Exception& )
253 : {
254 : }
255 1 : }
256 :
257 1 : sal_Int32 SAL_CALL VbaPageSetupBase::getOrientation() throw (css::uno::RuntimeException, std::exception)
258 : {
259 1 : sal_Int32 orientation = mnOrientPortrait;
260 : try
261 : {
262 1 : sal_Bool isLandscape = sal_False;
263 1 : uno::Any aValue = mxPageProps->getPropertyValue( "IsLandscape" );
264 1 : aValue >>= isLandscape;
265 :
266 1 : if( isLandscape )
267 : {
268 1 : orientation = mnOrientLandscape;
269 1 : }
270 : }
271 0 : catch( uno::Exception& )
272 : {
273 : }
274 1 : return orientation;
275 : }
276 :
277 1 : void SAL_CALL VbaPageSetupBase::setOrientation( sal_Int32 orientation ) throw (css::uno::RuntimeException, std::exception)
278 : {
279 2 : if( ( orientation != mnOrientPortrait ) &&
280 1 : ( orientation != mnOrientLandscape ) )
281 : {
282 0 : DebugHelper::exception(SbERR_BAD_PARAMETER, OUString() );
283 : }
284 :
285 : try
286 : {
287 1 : sal_Bool isLandscape = sal_False;
288 1 : uno::Any aValue = mxPageProps->getPropertyValue( "IsLandscape" );
289 1 : aValue >>= isLandscape;
290 :
291 1 : sal_Bool switchOrientation = sal_False;
292 2 : if(( isLandscape && orientation != mnOrientLandscape ) ||
293 2 : ( !isLandscape && orientation != mnOrientPortrait ))
294 : {
295 1 : switchOrientation = sal_True;
296 : }
297 :
298 1 : if( switchOrientation )
299 : {
300 1 : aValue <<= !isLandscape;
301 1 : uno::Any aHeight = mxPageProps->getPropertyValue( "Height" );
302 2 : uno::Any aWidth = mxPageProps->getPropertyValue( "Width" );
303 1 : mxPageProps->setPropertyValue( "IsLandscape" , aValue );
304 1 : mxPageProps->setPropertyValue( "Width" , aHeight );
305 2 : mxPageProps->setPropertyValue( "Height" , aWidth );
306 1 : }
307 : }
308 0 : catch( uno::Exception& )
309 : {
310 : }
311 1 : }
312 :
313 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|