xref: /aoo42x/main/sw/source/ui/vba/vbaheaderfooter.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #include "vbaheaderfooter.hxx"
24 #include <vbahelper/vbahelper.hxx>
25 #include <tools/diagnose_ex.h>
26 #include <ooo/vba/word/WdHeaderFooterIndex.hpp>
27 #include <com/sun/star/text/XText.hpp>
28 #include <com/sun/star/text/XTextDocument.hpp>
29 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
30 #include "vbarange.hxx"
31 #include <vbahelper/vbashapes.hxx>
32 
33 using namespace ::ooo::vba;
34 using namespace ::com::sun::star;
35 
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)36 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 )
37 {
38 }
39 
getIsHeader()40 sal_Bool SAL_CALL SwVbaHeaderFooter::getIsHeader() throw (uno::RuntimeException)
41 {
42     return mbHeader;
43 }
44 
getLinkToPrevious()45 sal_Bool SAL_CALL SwVbaHeaderFooter::getLinkToPrevious() throw (uno::RuntimeException)
46 {
47     // seems always false
48     return sal_False;
49 }
50 
setLinkToPrevious(::sal_Bool)51 void SAL_CALL SwVbaHeaderFooter::setLinkToPrevious( ::sal_Bool /*_linktoprevious*/ ) throw (uno::RuntimeException)
52 {
53     // not support in Writer
54 }
55 
getRange()56 uno::Reference< word::XRange > SAL_CALL SwVbaHeaderFooter::getRange() throw (uno::RuntimeException)
57 {
58     rtl::OUString sPropsNameText;
59     if( mbHeader )
60     {
61         sPropsNameText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderText") );
62     }
63     else
64     {
65         sPropsNameText = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterText") );
66     }
67     if( mnIndex == word::WdHeaderFooterIndex::wdHeaderFooterEvenPages )
68     {
69         sPropsNameText.concat( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Left") ) );
70     }
71 
72     uno::Reference< text::XText > xText( mxPageStyleProps->getPropertyValue( sPropsNameText ), uno::UNO_QUERY_THROW );
73     uno::Reference< text::XTextDocument > xDocument( mxModel, uno::UNO_QUERY_THROW );
74     return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, xDocument, xText->getStart(), xText->getEnd(), xText ) );
75 }
76 
77 uno::Any SAL_CALL
Shapes(const uno::Any & index)78 SwVbaHeaderFooter::Shapes( const uno::Any& index ) throw (uno::RuntimeException)
79 {
80     uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxModel, uno::UNO_QUERY_THROW );
81     //uno::Reference< drawing::XShapes > xShapes( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
82     uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
83     uno::Reference< XCollection > xCol( new ScVbaShapes( this, mxContext, xIndexAccess, mxModel ) );
84     if ( index.hasValue() )
85         return xCol->Item( index, uno::Any() );
86     return uno::makeAny( xCol );
87 }
88 
89 rtl::OUString&
getServiceImplName()90 SwVbaHeaderFooter::getServiceImplName()
91 {
92 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaHeaderFooter") );
93 	return sImplName;
94 }
95 
96 uno::Sequence< rtl::OUString >
getServiceNames()97 SwVbaHeaderFooter::getServiceNames()
98 {
99 	static uno::Sequence< rtl::OUString > aServiceNames;
100 	if ( aServiceNames.getLength() == 0 )
101 	{
102 		aServiceNames.realloc( 1 );
103 		aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Pane" ) );
104 	}
105 	return aServiceNames;
106 }
107 
108