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