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
10*efeef26fSAndrew Rist *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist *
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.
19*efeef26fSAndrew Rist *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir #include "vbasections.hxx"
24cdf0e10cSrcweir #include "vbasection.hxx"
25cdf0e10cSrcweir #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
26cdf0e10cSrcweir #include <com/sun/star/style/XStyle.hpp>
27cdf0e10cSrcweir #include <docsh.hxx>
28cdf0e10cSrcweir #include <doc.hxx>
29cdf0e10cSrcweir #include "wordvbahelper.hxx"
30cdf0e10cSrcweir
31cdf0e10cSrcweir using namespace ::ooo::vba;
32cdf0e10cSrcweir using namespace ::com::sun::star;
33cdf0e10cSrcweir
34cdf0e10cSrcweir typedef ::cppu::WeakImplHelper1< container::XEnumeration > SectionEnumeration_BASE;
35cdf0e10cSrcweir typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > SectionCollectionHelper_Base;
36cdf0e10cSrcweir typedef std::vector< uno::Reference< beans::XPropertySet > > XSectionVec;
37cdf0e10cSrcweir
38cdf0e10cSrcweir class SectionEnumeration : public SectionEnumeration_BASE
39cdf0e10cSrcweir {
40cdf0e10cSrcweir XSectionVec mxSections;
41cdf0e10cSrcweir XSectionVec::iterator mIt;
42cdf0e10cSrcweir
43cdf0e10cSrcweir public:
SectionEnumeration(const XSectionVec & rVec)44cdf0e10cSrcweir SectionEnumeration( const XSectionVec& rVec ) : mxSections( rVec ), mIt( mxSections.begin() ) {}
hasMoreElements()45cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException)
46cdf0e10cSrcweir {
47cdf0e10cSrcweir return ( mIt != mxSections.end() );
48cdf0e10cSrcweir }
49cdf0e10cSrcweir
nextElement()50cdf0e10cSrcweir virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
51cdf0e10cSrcweir {
52cdf0e10cSrcweir if ( hasMoreElements() )
53cdf0e10cSrcweir return uno::makeAny( *mIt++ );
54cdf0e10cSrcweir throw container::NoSuchElementException();
55cdf0e10cSrcweir }
56cdf0e10cSrcweir };
57cdf0e10cSrcweir
58cdf0e10cSrcweir // here I regard pagestyle as section
59cdf0e10cSrcweir class SectionCollectionHelper : public SectionCollectionHelper_Base
60cdf0e10cSrcweir {
61cdf0e10cSrcweir private:
62cdf0e10cSrcweir uno::Reference< XHelperInterface > mxParent;
63cdf0e10cSrcweir uno::Reference< uno::XComponentContext > mxContext;
64cdf0e10cSrcweir uno::Reference< frame::XModel > mxModel;
65cdf0e10cSrcweir XSectionVec mxSections;
66cdf0e10cSrcweir
67cdf0e10cSrcweir public:
SectionCollectionHelper(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<frame::XModel> & xModel)68cdf0e10cSrcweir SectionCollectionHelper( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) : mxParent( xParent ), mxContext( xContext ), mxModel( xModel )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir uno::Reference< style::XStyleFamiliesSupplier > xSytleFamSupp( mxModel, uno::UNO_QUERY_THROW );
71cdf0e10cSrcweir uno::Reference< container::XNameAccess > xSytleFamNames( xSytleFamSupp->getStyleFamilies(), uno::UNO_QUERY_THROW );
72cdf0e10cSrcweir uno::Reference< container::XIndexAccess > xPageStyles( xSytleFamNames->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyles") ) ), uno::UNO_QUERY_THROW );
73cdf0e10cSrcweir sal_Int32 nCount = xPageStyles->getCount();
74cdf0e10cSrcweir for( sal_Int32 index = 0; index < nCount; ++index )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir uno::Reference< style::XStyle > xStyle( xPageStyles->getByIndex( index ), uno::UNO_QUERY_THROW );
77cdf0e10cSrcweir // only the pagestyles in using are considered
78cdf0e10cSrcweir if( xStyle->isInUse( ) )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPageProps( xStyle, uno::UNO_QUERY_THROW );
81cdf0e10cSrcweir mxSections.push_back( xPageProps );
82cdf0e10cSrcweir }
83cdf0e10cSrcweir }
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
~SectionCollectionHelper()86cdf0e10cSrcweir ~SectionCollectionHelper(){}
87cdf0e10cSrcweir
88cdf0e10cSrcweir // XIndexAccess
getCount()89cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException)
90cdf0e10cSrcweir {
91cdf0e10cSrcweir return mxSections.size();
92cdf0e10cSrcweir }
getByIndex(sal_Int32 Index)93cdf0e10cSrcweir virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
94cdf0e10cSrcweir {
95cdf0e10cSrcweir if ( Index < 0 || Index >= getCount() )
96cdf0e10cSrcweir throw css::lang::IndexOutOfBoundsException();
97cdf0e10cSrcweir
98cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPageProps( mxSections[ Index ], uno::UNO_QUERY_THROW );
99cdf0e10cSrcweir return uno::makeAny( uno::Reference< word::XSection >( new SwVbaSection( mxParent, mxContext, mxModel, xPageProps ) ) );
100cdf0e10cSrcweir }
getElementType()101cdf0e10cSrcweir virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException)
102cdf0e10cSrcweir {
103cdf0e10cSrcweir return word::XSection::static_type(0);
104cdf0e10cSrcweir }
hasElements()105cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir return sal_True;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir // XEnumerationAccess
createEnumeration()110cdf0e10cSrcweir virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException)
111cdf0e10cSrcweir {
112cdf0e10cSrcweir return new SectionEnumeration( mxSections );
113cdf0e10cSrcweir }
114cdf0e10cSrcweir };
115cdf0e10cSrcweir
116cdf0e10cSrcweir class SectionsEnumWrapper : public EnumerationHelperImpl
117cdf0e10cSrcweir {
118cdf0e10cSrcweir uno::Reference< frame::XModel > mxModel;
119cdf0e10cSrcweir public:
SectionsEnumWrapper(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<container::XEnumeration> & xEnumeration,const uno::Reference<frame::XModel> & xModel)120cdf0e10cSrcweir SectionsEnumWrapper( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration, const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( xParent, xContext, xEnumeration ), mxModel( xModel ){}
121cdf0e10cSrcweir
nextElement()122cdf0e10cSrcweir virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPageProps( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
125cdf0e10cSrcweir return uno::makeAny( uno::Reference< word::XSection > ( new SwVbaSection( m_xParent, m_xContext, mxModel, xPageProps ) ) );
126cdf0e10cSrcweir }
127cdf0e10cSrcweir };
128cdf0e10cSrcweir
SwVbaSections(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<frame::XModel> & xModel)129cdf0e10cSrcweir SwVbaSections::SwVbaSections( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel ): SwVbaSections_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new SectionCollectionHelper( xParent, xContext, xModel ) ) ), mxModel( xModel )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir uno::Any SAL_CALL
PageSetup()134cdf0e10cSrcweir SwVbaSections::PageSetup( ) throw (uno::RuntimeException)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir if( m_xIndexAccess->getCount() )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir // check if the first section is our want
139cdf0e10cSrcweir uno::Reference< word::XSection > xSection( m_xIndexAccess->getByIndex( 0 ), uno::UNO_QUERY_THROW );
140cdf0e10cSrcweir return xSection->PageSetup();
141cdf0e10cSrcweir }
142cdf0e10cSrcweir throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("There is no section") ), uno::Reference< uno::XInterface >() );
143cdf0e10cSrcweir }
144cdf0e10cSrcweir
145cdf0e10cSrcweir // XEnumerationAccess
146cdf0e10cSrcweir uno::Type SAL_CALL
getElementType()147cdf0e10cSrcweir SwVbaSections::getElementType() throw (uno::RuntimeException)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir return word::XSection::static_type(0);
150cdf0e10cSrcweir }
151cdf0e10cSrcweir
152cdf0e10cSrcweir uno::Reference< container::XEnumeration > SAL_CALL
createEnumeration()153cdf0e10cSrcweir SwVbaSections::createEnumeration() throw (uno::RuntimeException)
154cdf0e10cSrcweir {
155cdf0e10cSrcweir uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
156cdf0e10cSrcweir return new SectionsEnumWrapper( this, mxContext, xEnumAccess->createEnumeration(), mxModel );
157cdf0e10cSrcweir }
158cdf0e10cSrcweir
159cdf0e10cSrcweir uno::Any
createCollectionObject(const css::uno::Any & aSource)160cdf0e10cSrcweir SwVbaSections::createCollectionObject( const css::uno::Any& aSource )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir return aSource;
163cdf0e10cSrcweir }
164cdf0e10cSrcweir
165cdf0e10cSrcweir rtl::OUString&
getServiceImplName()166cdf0e10cSrcweir SwVbaSections::getServiceImplName()
167cdf0e10cSrcweir {
168cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaSections") );
169cdf0e10cSrcweir return sImplName;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir
172cdf0e10cSrcweir css::uno::Sequence<rtl::OUString>
getServiceNames()173cdf0e10cSrcweir SwVbaSections::getServiceNames()
174cdf0e10cSrcweir {
175cdf0e10cSrcweir static uno::Sequence< rtl::OUString > sNames;
176cdf0e10cSrcweir if ( sNames.getLength() == 0 )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir sNames.realloc( 1 );
179cdf0e10cSrcweir sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Sections") );
180cdf0e10cSrcweir }
181cdf0e10cSrcweir return sNames;
182cdf0e10cSrcweir }
183