LibreOffice Module sw (master)  1
vbaheaderfooter.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  */
19 #include "vbaheaderfooter.hxx"
20 #include <vbahelper/vbahelper.hxx>
21 #include <tools/diagnose_ex.h>
22 #include <ooo/vba/word/WdHeaderFooterIndex.hpp>
23 #include <com/sun/star/text/XText.hpp>
24 #include <com/sun/star/text/XTextDocument.hpp>
25 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
26 #include "vbarange.hxx"
27 #include <vbahelper/vbashapes.hxx>
28 
29 using namespace ::ooo::vba;
30 using namespace ::com::sun::star;
31 
32 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, bool isHeader, sal_Int32 index ) : SwVbaHeaderFooter_BASE( rParent, rContext ), mxModel( xModel ), mxPageStyleProps( rProps ), mbHeader( isHeader ), mnIndex( index )
33 {
34 }
35 
37 {
38  return mbHeader;
39 }
40 
42 {
43  // seems always false
44  return false;
45 }
46 
47 void SAL_CALL SwVbaHeaderFooter::setLinkToPrevious( sal_Bool /*_linktoprevious*/ )
48 {
49  // not support in Writer
50 }
51 
52 uno::Reference< word::XRange > SAL_CALL SwVbaHeaderFooter::getRange()
53 {
54  OUString sPropsNameText;
55  if( mbHeader )
56  {
57  sPropsNameText = "HeaderText";
58  }
59  else
60  {
61  sPropsNameText = "FooterText";
62  }
63  if( mnIndex == word::WdHeaderFooterIndex::wdHeaderFooterEvenPages )
64  {
65  sPropsNameText += "Left";
66  }
67 
68  uno::Reference< text::XText > xText( mxPageStyleProps->getPropertyValue( sPropsNameText ), uno::UNO_QUERY_THROW );
69  uno::Reference< text::XTextDocument > xDocument( mxModel, uno::UNO_QUERY_THROW );
70  return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, xDocument, xText->getStart(), xText->getEnd(), xText ) );
71 }
72 
73 uno::Any SAL_CALL
75 {
76  // #FIXME: only get the shapes in the current header/footer
77  uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxModel, uno::UNO_QUERY_THROW );
78  //uno::Reference< drawing::XShapes > xShapes( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
79  uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
80  uno::Reference< XCollection > xCol( new ScVbaShapes( this, mxContext, xIndexAccess, mxModel ) );
81  if ( index.hasValue() )
82  return xCol->Item( index, uno::Any() );
83  return uno::makeAny( xCol );
84 }
85 
86 OUString
88 {
89  return OUString("SwVbaHeaderFooter");
90 }
91 
92 uno::Sequence< OUString >
94 {
95  static uno::Sequence< OUString > const aServiceNames
96  {
97  "ooo.vba.word.Pane"
98  };
99  return aServiceNames;
100 }
101 
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool hasValue()
css::uno::Reference< css::frame::XModel2 > mxModel
sal_uInt32 mnIndex
virtual void SAL_CALL setLinkToPrevious(sal_Bool _linktoprevious) override
SwVbaHeaderFooter(const css::uno::Reference< ooo::vba::XHelperInterface > &rParent, const css::uno::Reference< css::uno::XComponentContext > &rContext, const css::uno::Reference< css::frame::XModel > &xModel, const css::uno::Reference< css::beans::XPropertySet > &xProps, bool isHeader, sal_Int32 index)
virtual OUString getServiceImplName() override
sal_Int32 const mnIndex
virtual css::uno::Reference< ::ooo::vba::word::XRange > SAL_CALL getRange() override
virtual sal_Bool SAL_CALL getLinkToPrevious() override
unsigned char sal_Bool
css::uno::Reference< css::uno::XComponentContext > mxContext
css::uno::Reference< css::frame::XModel > mxModel
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual css::uno::Any SAL_CALL Shapes(const css::uno::Any &aIndex) override
css::uno::Reference< css::beans::XPropertySet > mxPageStyleProps
virtual sal_Bool SAL_CALL getIsHeader() override