1*efeef26fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*efeef26fSAndrew Rist * distributed with this work for additional information 6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance 9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*efeef26fSAndrew Rist * software distributed under the License is distributed on an 15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the 17*efeef26fSAndrew Rist * specific language governing permissions and limitations 18*efeef26fSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*efeef26fSAndrew Rist *************************************************************/ 21*efeef26fSAndrew Rist 22*efeef26fSAndrew Rist 23cdf0e10cSrcweir #include "vbapagesetup.hxx" 24cdf0e10cSrcweir #include <com/sun/star/text/XText.hpp> 25cdf0e10cSrcweir #include <com/sun/star/text/XPageCursor.hpp> 26cdf0e10cSrcweir #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> 27cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 28cdf0e10cSrcweir #include <ooo/vba/word/WdSectionStart.hpp> 29cdf0e10cSrcweir #include <ooo/vba/word/WdOrientation.hpp> 30cdf0e10cSrcweir #include "wordvbahelper.hxx" 31cdf0e10cSrcweir 32cdf0e10cSrcweir using namespace ::com::sun::star; 33cdf0e10cSrcweir using namespace ::ooo::vba; 34cdf0e10cSrcweir 35cdf0e10cSrcweir SwVbaPageSetup::SwVbaPageSetup(const uno::Reference< XHelperInterface >& xParent, 36cdf0e10cSrcweir const uno::Reference< uno::XComponentContext >& xContext, 37cdf0e10cSrcweir const uno::Reference< frame::XModel >& xModel, 38cdf0e10cSrcweir const uno::Reference< beans::XPropertySet >& xProps ) throw (uno::RuntimeException): 39cdf0e10cSrcweir SwVbaPageSetup_BASE( xParent, xContext ) 40cdf0e10cSrcweir { 41cdf0e10cSrcweir mxModel.set( xModel, uno::UNO_QUERY_THROW ); 42cdf0e10cSrcweir mxPageProps.set( xProps, uno::UNO_QUERY_THROW ); 43cdf0e10cSrcweir mnOrientPortrait = word::WdOrientation::wdOrientPortrait; 44cdf0e10cSrcweir mnOrientLandscape = word::WdOrientation::wdOrientLandscape; 45cdf0e10cSrcweir } 46cdf0e10cSrcweir 47cdf0e10cSrcweir double SAL_CALL SwVbaPageSetup::getGutter() throw (uno::RuntimeException) 48cdf0e10cSrcweir { 49cdf0e10cSrcweir // not support in Writer 50cdf0e10cSrcweir return 0; 51cdf0e10cSrcweir } 52cdf0e10cSrcweir 53cdf0e10cSrcweir void SAL_CALL SwVbaPageSetup::setGutter( double _gutter ) throw (uno::RuntimeException) 54cdf0e10cSrcweir { 55cdf0e10cSrcweir // default add gutter into left margin 56cdf0e10cSrcweir if( _gutter != 0 ) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir double margin = VbaPageSetupBase::getLeftMargin() + _gutter; 59cdf0e10cSrcweir VbaPageSetupBase::setLeftMargin( margin ); 60cdf0e10cSrcweir } 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir double SAL_CALL SwVbaPageSetup::getHeaderDistance() throw (uno::RuntimeException) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir sal_Bool isHeaderOn = sal_False; 66cdf0e10cSrcweir mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn"))) >>= isHeaderOn; 67cdf0e10cSrcweir if( !isHeaderOn ) 68cdf0e10cSrcweir mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn")), uno::makeAny( sal_True ) ); 69cdf0e10cSrcweir return VbaPageSetupBase::getHeaderMargin(); 70cdf0e10cSrcweir } 71cdf0e10cSrcweir 72cdf0e10cSrcweir /** 73cdf0e10cSrcweir * changes the value of TopMargin to the value of new MS-Word-HeaderDistance. Subtracts the difference 74cdf0e10cSrcweir * between old TopMargin and the new headerDistance from the value of HeaderSpacing (which defines the 75cdf0e10cSrcweir * space between the header and the body of the text). calculates the new HeaderHeight (= height of the 76cdf0e10cSrcweir * header + headerBodyDistance). 77cdf0e10cSrcweir * 78cdf0e10cSrcweir * @param: headerDistance is the value that is set in MS Word for the distance from the top of the page 79cdf0e10cSrcweir * to the header 80cdf0e10cSrcweir */ 81cdf0e10cSrcweir void SAL_CALL SwVbaPageSetup::setHeaderDistance( double _headerdistance ) throw (uno::RuntimeException) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir sal_Int32 newHeaderDistance = Millimeter::getInHundredthsOfOneMillimeter( _headerdistance ); 84cdf0e10cSrcweir sal_Bool isHeaderOn = sal_False; 85cdf0e10cSrcweir sal_Int32 aktTopMargin = 0; 86cdf0e10cSrcweir sal_Int32 aktSpacing = 0; 87cdf0e10cSrcweir sal_Int32 aktHeaderHeight = 0; 88cdf0e10cSrcweir 89cdf0e10cSrcweir mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn"))) >>= isHeaderOn; 90cdf0e10cSrcweir if( !isHeaderOn ) 91cdf0e10cSrcweir mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn")), uno::makeAny( sal_True ) ); 92cdf0e10cSrcweir 93cdf0e10cSrcweir mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin"))) >>= aktTopMargin; 94cdf0e10cSrcweir mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderBodyDistance"))) >>= aktSpacing; 95cdf0e10cSrcweir mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderHeight"))) >>= aktHeaderHeight; 96cdf0e10cSrcweir 97cdf0e10cSrcweir sal_Int32 newSpacing = aktSpacing - ( newHeaderDistance - aktTopMargin ); 98cdf0e10cSrcweir sal_Int32 height = aktHeaderHeight - aktSpacing; 99cdf0e10cSrcweir sal_Int32 newHeaderHeight = newSpacing + height; 100cdf0e10cSrcweir 101cdf0e10cSrcweir mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin")), uno::makeAny( newHeaderDistance ) ); 102cdf0e10cSrcweir mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderBodyDistance")), uno::makeAny( newSpacing ) ); 103cdf0e10cSrcweir mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderHeight")), uno::makeAny( newHeaderHeight ) ); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir double SAL_CALL SwVbaPageSetup::getFooterDistance() throw (uno::RuntimeException) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir sal_Bool isFooterOn = sal_False; 109cdf0e10cSrcweir mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsOn"))) >>= isFooterOn; 110cdf0e10cSrcweir if( !isFooterOn ) 111cdf0e10cSrcweir mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsOn")), uno::makeAny( sal_True ) ); 112cdf0e10cSrcweir return VbaPageSetupBase::getFooterMargin(); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir void SAL_CALL SwVbaPageSetup::setFooterDistance( double _footerdistance ) throw (uno::RuntimeException) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir sal_Int32 newFooterDistance = Millimeter::getInHundredthsOfOneMillimeter( _footerdistance ); 118cdf0e10cSrcweir sal_Bool isFooterOn = sal_False; 119cdf0e10cSrcweir sal_Int32 aktBottomMargin = 0; 120cdf0e10cSrcweir sal_Int32 aktSpacing = 0; 121cdf0e10cSrcweir sal_Int32 aktFooterHeight = 0; 122cdf0e10cSrcweir 123cdf0e10cSrcweir mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsOn"))) >>= isFooterOn; 124cdf0e10cSrcweir if( !isFooterOn ) 125cdf0e10cSrcweir mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsOn")), uno::makeAny( sal_True ) ); 126cdf0e10cSrcweir 127cdf0e10cSrcweir mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin"))) >>= aktBottomMargin; 128cdf0e10cSrcweir mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterBodyDistance"))) >>= aktSpacing; 129cdf0e10cSrcweir mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterHeight"))) >>= aktFooterHeight; 130cdf0e10cSrcweir 131cdf0e10cSrcweir sal_Int32 newSpacing = aktSpacing - ( newFooterDistance - aktBottomMargin ); 132cdf0e10cSrcweir sal_Int32 height = aktFooterHeight - aktSpacing; 133cdf0e10cSrcweir sal_Int32 newFooterHeight = newSpacing + height; 134cdf0e10cSrcweir 135cdf0e10cSrcweir mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin")), uno::makeAny( newFooterDistance ) ); 136cdf0e10cSrcweir mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterBodyDistance")), uno::makeAny( newSpacing ) ); 137cdf0e10cSrcweir mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterHeight")), uno::makeAny( newFooterHeight ) ); 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir sal_Bool SAL_CALL SwVbaPageSetup::getDifferentFirstPageHeaderFooter() throw (uno::RuntimeException) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir rtl::OUString pageStyle = getStyleOfFirstPage(); 143cdf0e10cSrcweir if( pageStyle.equalsAscii( "First Page" ) ) 144cdf0e10cSrcweir return sal_True; 145cdf0e10cSrcweir 146cdf0e10cSrcweir return sal_False; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir void SAL_CALL SwVbaPageSetup::setDifferentFirstPageHeaderFooter( sal_Bool status ) throw (uno::RuntimeException) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir if( status == getDifferentFirstPageHeaderFooter() ) 152cdf0e10cSrcweir return; 153cdf0e10cSrcweir 154cdf0e10cSrcweir rtl::OUString newStyle; 155cdf0e10cSrcweir if( status ) 156cdf0e10cSrcweir newStyle = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("First Page") ); 157cdf0e10cSrcweir else 158cdf0e10cSrcweir newStyle = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Standard") ); 159cdf0e10cSrcweir 160cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xStyleProps( word::getCurrentPageStyle( mxModel ), uno::UNO_QUERY_THROW ); 161cdf0e10cSrcweir sal_Int32 nTopMargin = 0; 162cdf0e10cSrcweir xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin"))) >>= nTopMargin; 163cdf0e10cSrcweir sal_Int32 nBottomMargin = 0; 164cdf0e10cSrcweir xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin"))) >>= nBottomMargin; 165cdf0e10cSrcweir sal_Int32 nLeftMargin = 0; 166cdf0e10cSrcweir xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin"))) >>= nLeftMargin; 167cdf0e10cSrcweir sal_Int32 nRightMargin = 0; 168cdf0e10cSrcweir xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightMargin"))) >>= nRightMargin; 169cdf0e10cSrcweir sal_Int32 nHeaderHeight = 0; 170cdf0e10cSrcweir xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderHeight"))) >>= nHeaderHeight; 171cdf0e10cSrcweir sal_Int32 nFooterHeight = 0; 172cdf0e10cSrcweir xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterHeight"))) >>= nFooterHeight; 173cdf0e10cSrcweir 174cdf0e10cSrcweir sal_Bool isHeaderOn = sal_False; 175cdf0e10cSrcweir xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn"))) >>= isHeaderOn; 176cdf0e10cSrcweir if( isHeaderOn ) 177cdf0e10cSrcweir { 178cdf0e10cSrcweir nTopMargin += nHeaderHeight; 179cdf0e10cSrcweir nBottomMargin += nFooterHeight; 180cdf0e10cSrcweir xStyleProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn")), uno::makeAny( sal_False ) ); 181cdf0e10cSrcweir xStyleProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsOn")), uno::makeAny( sal_False ) ); 182cdf0e10cSrcweir } 183cdf0e10cSrcweir uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( mxModel ), uno::UNO_QUERY_THROW ); 184cdf0e10cSrcweir if( xPageCursor->getPage() != 1 ) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir xPageCursor->jumpToFirstPage(); 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xCursorProps( xPageCursor, uno::UNO_QUERY_THROW ); 190cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xTableProps( xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ), uno::UNO_QUERY ); 191cdf0e10cSrcweir if( xTableProps.is() ) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir xTableProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageDescName") ), uno::makeAny( newStyle ) ); 194cdf0e10cSrcweir } 195cdf0e10cSrcweir else 196cdf0e10cSrcweir { 197cdf0e10cSrcweir xCursorProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageDescName") ), uno::makeAny( newStyle ) ); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xFirstPageProps( word::getCurrentPageStyle( mxModel ), uno::UNO_QUERY_THROW ); 201cdf0e10cSrcweir xFirstPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin") ), uno::makeAny( nTopMargin ) ); 202cdf0e10cSrcweir xFirstPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin") ), uno::makeAny( nBottomMargin ) ); 203cdf0e10cSrcweir xFirstPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin") ), uno::makeAny( nLeftMargin ) ); 204cdf0e10cSrcweir xFirstPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightMargin") ), uno::makeAny( nRightMargin ) ); 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir rtl::OUString SwVbaPageSetup::getStyleOfFirstPage() throw (uno::RuntimeException) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir rtl::OUString styleFirstPage; 210cdf0e10cSrcweir uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( mxModel ), uno::UNO_QUERY_THROW ); 211cdf0e10cSrcweir if( xPageCursor->getPage() != 1 ) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir xPageCursor->jumpToFirstPage(); 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xCursorProps( xPageCursor, uno::UNO_QUERY_THROW ); 217cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xTableProps( xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ), uno::UNO_QUERY ); 218cdf0e10cSrcweir if( xTableProps.is() ) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir xTableProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageDescName") ) ) >>= styleFirstPage; 221cdf0e10cSrcweir } 222cdf0e10cSrcweir else 223cdf0e10cSrcweir { 224cdf0e10cSrcweir xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageDescName") ) ) >>= styleFirstPage; 225cdf0e10cSrcweir } 226cdf0e10cSrcweir return styleFirstPage; 227cdf0e10cSrcweir } 228cdf0e10cSrcweir 229cdf0e10cSrcweir ::sal_Int32 SAL_CALL SwVbaPageSetup::getSectionStart() throw (uno::RuntimeException) 230cdf0e10cSrcweir { 231cdf0e10cSrcweir // FIXME: 232cdf0e10cSrcweir sal_Int32 wdSectionStart = word::WdSectionStart::wdSectionNewPage; 233cdf0e10cSrcweir uno::Reference< container::XNamed > xNamed( mxPageProps, uno::UNO_QUERY_THROW ); 234cdf0e10cSrcweir rtl::OUString sStyleName = xNamed->getName(); 235cdf0e10cSrcweir //mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Name") ) ) >>= sStyleName; 236cdf0e10cSrcweir if( sStyleName.equalsAscii("Left Page") ) 237cdf0e10cSrcweir wdSectionStart = word::WdSectionStart::wdSectionEvenPage; 238cdf0e10cSrcweir else if( sStyleName.equalsAscii("Right Page") ) 239cdf0e10cSrcweir wdSectionStart = word::WdSectionStart::wdSectionOddPage; 240cdf0e10cSrcweir else 241cdf0e10cSrcweir wdSectionStart = word::WdSectionStart::wdSectionNewPage; 242cdf0e10cSrcweir return wdSectionStart; 243cdf0e10cSrcweir } 244cdf0e10cSrcweir 245cdf0e10cSrcweir void SAL_CALL SwVbaPageSetup::setSectionStart( ::sal_Int32 /*_sectionstart*/ ) throw (uno::RuntimeException) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir // fail to find corresponding feature in Writer 248cdf0e10cSrcweir // #FIXME: 249cdf0e10cSrcweir } 250cdf0e10cSrcweir 251cdf0e10cSrcweir rtl::OUString& 252cdf0e10cSrcweir SwVbaPageSetup::getServiceImplName() 253cdf0e10cSrcweir { 254cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaPageSetup") ); 255cdf0e10cSrcweir return sImplName; 256cdf0e10cSrcweir } 257cdf0e10cSrcweir 258cdf0e10cSrcweir uno::Sequence< rtl::OUString > 259cdf0e10cSrcweir SwVbaPageSetup::getServiceNames() 260cdf0e10cSrcweir { 261cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 262cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir aServiceNames.realloc( 1 ); 265cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.PageSetup" ) ); 266cdf0e10cSrcweir } 267cdf0e10cSrcweir return aServiceNames; 268cdf0e10cSrcweir } 269