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