1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #include "vbaheaderfooter.hxx" 28 #include <vbahelper/vbahelper.hxx> 29 #include <tools/diagnose_ex.h> 30 #include <ooo/vba/word/WdHeaderFooterIndex.hpp> 31 #include <com/sun/star/text/XText.hpp> 32 #include <com/sun/star/text/XTextDocument.hpp> 33 #include <com/sun/star/drawing/XDrawPageSupplier.hpp> 34 #include "vbarange.hxx" 35 #include <vbahelper/vbashapes.hxx> 36 37 using namespace ::ooo::vba; 38 using namespace ::com::sun::star; 39 40 SwVbaHeaderFooter::SwVbaHeaderFooter( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< frame::XModel >& xModel, const uno::Reference< beans::XPropertySet >& rProps, sal_Bool isHeader, sal_Int32 index ) throw ( uno::RuntimeException ) : SwVbaHeaderFooter_BASE( rParent, rContext ), mxModel( xModel ), mxPageStyleProps( rProps ), mbHeader( isHeader ), mnIndex( index ) 41 { 42 } 43 44 sal_Bool SAL_CALL SwVbaHeaderFooter::getIsHeader() throw (uno::RuntimeException) 45 { 46 return mbHeader; 47 } 48 49 sal_Bool SAL_CALL SwVbaHeaderFooter::getLinkToPrevious() throw (uno::RuntimeException) 50 { 51 // seems always false 52 return sal_False; 53 } 54 55 void SAL_CALL SwVbaHeaderFooter::setLinkToPrevious( ::sal_Bool /*_linktoprevious*/ ) throw (uno::RuntimeException) 56 { 57 // not support in Writer 58 } 59 60 uno::Reference< word::XRange > SAL_CALL SwVbaHeaderFooter::getRange() throw (uno::RuntimeException) 61 { 62 rtl::OUString sPropsNameText; 63 if( mbHeader ) 64 { 65 sPropsNameText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderText") ); 66 } 67 else 68 { 69 sPropsNameText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterText") ); 70 } 71 if( mnIndex == word::WdHeaderFooterIndex::wdHeaderFooterEvenPages ) 72 { 73 sPropsNameText.concat( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Left") ) ); 74 } 75 76 uno::Reference< text::XText > xText( mxPageStyleProps->getPropertyValue( sPropsNameText ), uno::UNO_QUERY_THROW ); 77 uno::Reference< text::XTextDocument > xDocument( mxModel, uno::UNO_QUERY_THROW ); 78 return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, xDocument, xText->getStart(), xText->getEnd(), xText ) ); 79 } 80 81 uno::Any SAL_CALL 82 SwVbaHeaderFooter::Shapes( const uno::Any& index ) throw (uno::RuntimeException) 83 { 84 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxModel, uno::UNO_QUERY_THROW ); 85 //uno::Reference< drawing::XShapes > xShapes( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW ); 86 uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW ); 87 uno::Reference< XCollection > xCol( new ScVbaShapes( this, mxContext, xIndexAccess, mxModel ) ); 88 if ( index.hasValue() ) 89 return xCol->Item( index, uno::Any() ); 90 return uno::makeAny( xCol ); 91 } 92 93 rtl::OUString& 94 SwVbaHeaderFooter::getServiceImplName() 95 { 96 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaHeaderFooter") ); 97 return sImplName; 98 } 99 100 uno::Sequence< rtl::OUString > 101 SwVbaHeaderFooter::getServiceNames() 102 { 103 static uno::Sequence< rtl::OUString > aServiceNames; 104 if ( aServiceNames.getLength() == 0 ) 105 { 106 aServiceNames.realloc( 1 ); 107 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Pane" ) ); 108 } 109 return aServiceNames; 110 } 111 112