summaryrefslogtreecommitdiffstats
path: root/vbahelper/source/vbahelper/vbapagesetupbase.cxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /vbahelper/source/vbahelper/vbapagesetupbase.cxx
parentInitial commit. (diff)
downloadlibreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz
libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vbahelper/source/vbahelper/vbapagesetupbase.cxx')
-rw-r--r--vbahelper/source/vbahelper/vbapagesetupbase.cxx308
1 files changed, 308 insertions, 0 deletions
diff --git a/vbahelper/source/vbahelper/vbapagesetupbase.cxx b/vbahelper/source/vbahelper/vbapagesetupbase.cxx
new file mode 100644
index 000000000..d50fe188c
--- /dev/null
+++ b/vbahelper/source/vbahelper/vbapagesetupbase.cxx
@@ -0,0 +1,308 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#include <vbahelper/vbapagesetupbase.hxx>
+#include <basic/sberrors.hxx>
+#include <com/sun/star/beans/XPropertySet.hpp>
+
+using namespace ::com::sun::star;
+using namespace ::ooo::vba;
+
+VbaPageSetupBase::VbaPageSetupBase(const uno::Reference< XHelperInterface >& xParent,
+ const uno::Reference< uno::XComponentContext >& xContext )
+ : VbaPageSetupBase_BASE( xParent, xContext )
+ , mnOrientLandscape(0)
+ , mnOrientPortrait(0)
+{
+}
+
+double SAL_CALL VbaPageSetupBase::getTopMargin()
+{
+ sal_Int32 topMargin = 0;
+
+ try
+ {
+ bool headerOn = false;
+
+ uno::Any aValue = mxPageProps->getPropertyValue( "HeaderIsOn" );
+ aValue >>= headerOn;
+
+ aValue = mxPageProps->getPropertyValue( "TopMargin" );
+ aValue >>= topMargin;
+
+ if( headerOn )
+ {
+ sal_Int32 headerHeight = 0;
+ aValue = mxPageProps->getPropertyValue( "HeaderHeight" );
+ aValue >>= headerHeight;
+ topMargin = topMargin + headerHeight;
+ }
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ return Millimeter::getInPoints( topMargin );
+}
+
+void SAL_CALL VbaPageSetupBase::setTopMargin( double margin )
+{
+ sal_Int32 topMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
+
+ try
+ {
+ bool headerOn = false;
+
+ uno::Any aValue = mxPageProps->getPropertyValue( "HeaderIsOn" );
+ aValue >>= headerOn;
+
+ if( headerOn )
+ {
+ sal_Int32 headerHeight = 0;
+ aValue = mxPageProps->getPropertyValue( "HeaderHeight" );
+ aValue >>= headerHeight;
+ topMargin -= headerHeight;
+ }
+
+ mxPageProps->setPropertyValue( "TopMargin" , uno::Any(topMargin) );
+ }
+ catch( uno::Exception& )
+ {
+ }
+}
+
+double SAL_CALL VbaPageSetupBase::getBottomMargin()
+{
+ sal_Int32 bottomMargin = 0;
+
+ try
+ {
+ bool footerOn = false;
+
+ uno::Any aValue = mxPageProps->getPropertyValue( "FooterIsOn" );
+ aValue >>= footerOn;
+
+ aValue = mxPageProps->getPropertyValue( "BottomMargin" );
+ aValue >>= bottomMargin;
+
+ if( footerOn )
+ {
+ sal_Int32 footerHeight = 0;
+ aValue = mxPageProps->getPropertyValue( "FooterHeight" );
+ aValue >>= footerHeight;
+ bottomMargin += footerHeight;
+ }
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ return Millimeter::getInPoints( bottomMargin );
+}
+
+void SAL_CALL VbaPageSetupBase::setBottomMargin( double margin )
+{
+ sal_Int32 bottomMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
+
+ try
+ {
+ bool footerOn = false;
+
+ uno::Any aValue = mxPageProps->getPropertyValue( "FooterIsOn" );
+ aValue >>= footerOn;
+
+ if( footerOn )
+ {
+ sal_Int32 footerHeight = 0;
+ aValue = mxPageProps->getPropertyValue( "FooterHeight" );
+ aValue >>= footerHeight;
+ bottomMargin -= footerHeight;
+ }
+
+ mxPageProps->setPropertyValue( "BottomMargin", uno::Any(bottomMargin) );
+ }
+ catch( uno::Exception& )
+ {
+ }
+}
+
+double SAL_CALL VbaPageSetupBase::getRightMargin()
+{
+ sal_Int32 rightMargin = 0;
+ try
+ {
+ uno::Any aValue = mxPageProps->getPropertyValue( "RightMargin" );
+ aValue >>= rightMargin;
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ return Millimeter::getInPoints( rightMargin );
+}
+
+void SAL_CALL VbaPageSetupBase::setRightMargin( double margin )
+{
+ sal_Int32 rightMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
+ try
+ {
+ mxPageProps->setPropertyValue( "RightMargin", uno::Any(rightMargin) );
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+}
+
+double SAL_CALL VbaPageSetupBase::getLeftMargin()
+{
+ sal_Int32 leftMargin = 0;
+ try
+ {
+ uno::Any aValue = mxPageProps->getPropertyValue( "LeftMargin" );
+ aValue >>= leftMargin;
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ return Millimeter::getInPoints( leftMargin );
+}
+
+void SAL_CALL VbaPageSetupBase::setLeftMargin( double margin )
+{
+ sal_Int32 leftMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
+ try
+ {
+ mxPageProps->setPropertyValue( "LeftMargin", uno::Any(leftMargin) );
+ }
+ catch( uno::Exception& )
+ {
+ }
+}
+
+double VbaPageSetupBase::getHeaderMargin()
+{
+ sal_Int32 headerMargin = 0;
+ try
+ {
+ uno::Any aValue = mxPageProps->getPropertyValue( "TopMargin" );
+ aValue >>= headerMargin;
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ return Millimeter::getInPoints( headerMargin );
+}
+
+void VbaPageSetupBase::setHeaderMargin( double margin )
+{
+ sal_Int32 headerMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
+ try
+ {
+ mxPageProps->setPropertyValue( "TopMargin", uno::Any(headerMargin) );
+ }
+ catch( uno::Exception& )
+ {
+ }
+}
+
+double VbaPageSetupBase::getFooterMargin()
+{
+ sal_Int32 footerMargin = 0;
+ try
+ {
+ uno::Any aValue = mxPageProps->getPropertyValue( "BottomMargin" );
+ aValue >>= footerMargin;
+ }
+ catch( uno::Exception& )
+ {
+ }
+
+ return Millimeter::getInPoints( footerMargin );
+}
+
+void VbaPageSetupBase::setFooterMargin( double margin )
+{
+ sal_Int32 footerMargin = Millimeter::getInHundredthsOfOneMillimeter( margin );
+ try
+ {
+ mxPageProps->setPropertyValue( "BottomMargin", uno::Any(footerMargin) );
+ }
+ catch( uno::Exception& )
+ {
+ }
+}
+
+sal_Int32 SAL_CALL VbaPageSetupBase::getOrientation()
+{
+ sal_Int32 orientation = mnOrientPortrait;
+ try
+ {
+ bool isLandscape = false;
+ uno::Any aValue = mxPageProps->getPropertyValue( "IsLandscape" );
+ aValue >>= isLandscape;
+
+ if( isLandscape )
+ {
+ orientation = mnOrientLandscape;
+ }
+ }
+ catch( uno::Exception& )
+ {
+ }
+ return orientation;
+}
+
+void SAL_CALL VbaPageSetupBase::setOrientation( sal_Int32 orientation )
+{
+ if( ( orientation != mnOrientPortrait ) &&
+ ( orientation != mnOrientLandscape ) )
+ {
+ DebugHelper::runtimeexception(ERRCODE_BASIC_BAD_PARAMETER );
+ }
+
+ try
+ {
+ bool isLandscape = false;
+ uno::Any aValue = mxPageProps->getPropertyValue( "IsLandscape" );
+ aValue >>= isLandscape;
+
+ bool switchOrientation = false;
+ if(( isLandscape && orientation != mnOrientLandscape ) ||
+ ( !isLandscape && orientation != mnOrientPortrait ))
+ {
+ switchOrientation = true;
+ }
+
+ if( switchOrientation )
+ {
+ uno::Any aHeight = mxPageProps->getPropertyValue( "Height" );
+ uno::Any aWidth = mxPageProps->getPropertyValue( "Width" );
+ mxPageProps->setPropertyValue( "IsLandscape", uno::Any(!isLandscape) );
+ mxPageProps->setPropertyValue( "Width" , aHeight );
+ mxPageProps->setPropertyValue( "Height" , aWidth );
+ }
+ }
+ catch( uno::Exception& )
+ {
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */