Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2008 by Sun Microsystems, Inc.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #include "vbarevisions.hxx"
29 : : #include "vbarevision.hxx"
30 : : #include <cppuhelper/implbase2.hxx>
31 : : #include <com/sun/star/document/XRedlinesSupplier.hpp>
32 : : #include <com/sun/star/text/XTextRangeCompare.hpp>
33 : :
34 : : using namespace ::ooo::vba;
35 : : using namespace ::com::sun::star;
36 : :
37 : : typedef ::cppu::WeakImplHelper1< container::XEnumeration > RevisionEnumeration_BASE;
38 : : typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > RevisionCollectionHelper_BASE;
39 : : typedef std::vector< uno::Reference< beans::XPropertySet > > RevisionMap;
40 : :
41 [ # # ]: 0 : class RedlinesEnumeration : public RevisionEnumeration_BASE
42 : : {
43 : : RevisionMap mRevisionMap;
44 : : RevisionMap::iterator mIt;
45 : : public:
46 [ # # ]: 0 : RedlinesEnumeration( const RevisionMap& sMap ) : mRevisionMap( sMap ), mIt( mRevisionMap.begin() ) {}
47 : 0 : virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException)
48 : : {
49 [ # # ]: 0 : return ( mIt != mRevisionMap.end() );
50 : : }
51 : 0 : virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
52 : : {
53 [ # # ][ # # ]: 0 : if ( !hasMoreElements() )
54 [ # # ]: 0 : throw container::NoSuchElementException();
55 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xRevision( *mIt++ );
56 [ # # ]: 0 : return uno::makeAny( xRevision ) ;
57 : : }
58 : : };
59 : :
60 [ # # ]: 0 : class RevisionCollectionHelper : public RevisionCollectionHelper_BASE
61 : : {
62 : : RevisionMap mRevisionMap;
63 : : public:
64 : : RevisionCollectionHelper( const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XTextRange >& xTextRange ) throw (uno::RuntimeException);
65 : :
66 : : // XElementAccess
67 : 0 : virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) { return beans::XPropertySet::static_type(0); }
68 : 0 : virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) { return ( !mRevisionMap.empty() ); }
69 : : // XIndexAccess
70 : 0 : virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) { return mRevisionMap.size(); }
71 : 0 : virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException )
72 : : {
73 [ # # ][ # # ]: 0 : if ( Index < 0 || Index >= getCount() )
[ # # ]
74 [ # # ]: 0 : throw lang::IndexOutOfBoundsException();
75 : :
76 : 0 : return uno::makeAny( mRevisionMap[ Index ] );
77 : :
78 : : }
79 : : // XEnumerationAccess
80 : 0 : virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException)
81 : : {
82 [ # # ][ # # ]: 0 : return new RedlinesEnumeration( mRevisionMap );
83 : : }
84 : : };
85 : :
86 [ # # ]: 0 : RevisionCollectionHelper::RevisionCollectionHelper( const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XTextRange >& xTextRange ) throw (uno::RuntimeException)
87 : : {
88 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRangeCompare > xTRC( xTextRange->getText(), uno::UNO_QUERY_THROW );
[ # # ]
89 [ # # ]: 0 : uno::Reference< document::XRedlinesSupplier > xRedlinesSupp( xModel, uno::UNO_QUERY_THROW );
90 [ # # ][ # # ]: 0 : uno::Reference< container::XIndexAccess > xRedlines( xRedlinesSupp->getRedlines(), uno::UNO_QUERY_THROW );
[ # # ]
91 [ # # ][ # # ]: 0 : sal_Int32 nCount = xRedlines->getCount();
92 [ # # ]: 0 : for( sal_Int32 index = 0; index < nCount; index++ )
93 : : {
94 [ # # ][ # # ]: 0 : uno::Reference< text::XTextRange > xRedlineRange( xRedlines->getByIndex( index ), uno::UNO_QUERY_THROW );
[ # # ]
95 [ # # ][ # # ]: 0 : if( xTRC->compareRegionStarts( xTextRange, xRedlineRange ) >= 0 && xTRC->compareRegionEnds( xTextRange, xRedlineRange ) <= 0 )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
96 : : {
97 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xRedlineProps( xRedlineRange, uno::UNO_QUERY_THROW );
98 [ # # ]: 0 : mRevisionMap.push_back( xRedlineProps );
99 : : }
100 : 0 : }
101 : 0 : }
102 [ # # ]: 0 : class RevisionsEnumeration : public EnumerationHelperImpl
103 : : {
104 : : uno::Reference< frame::XModel > m_xModel;
105 : : public:
106 : 0 : RevisionsEnumeration( 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 ), m_xModel( xModel ) {}
107 : :
108 : 0 : virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
109 : : {
110 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xRevision( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
[ # # ]
111 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< word::XRevision > ( new SwVbaRevision( m_xParent, m_xContext, m_xModel, xRevision ) ) );
[ # # ][ # # ]
[ # # ]
112 : : }
113 : :
114 : : };
115 : :
116 [ # # ][ # # ]: 0 : SwVbaRevisions::SwVbaRevisions( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XTextRange >& xTextRange ): SwVbaRevisions_BASE( xParent, xContext, new RevisionCollectionHelper( xModel, xTextRange ) ), mxModel( xModel )
[ # # ]
117 : : {
118 : 0 : }
119 : :
120 : 0 : SwVbaRevisions::SwVbaRevisions( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel, const uno::Reference< container::XIndexAccess >& xIndexAccess ): SwVbaRevisions_BASE( xParent, xContext, xIndexAccess ), mxModel( xModel )
121 : : {
122 : 0 : }
123 : :
124 : : // XEnumerationAccess
125 : : uno::Type
126 : 0 : SwVbaRevisions::getElementType() throw (uno::RuntimeException)
127 : : {
128 : 0 : return word::XRevision::static_type(0);
129 : : }
130 : : uno::Reference< container::XEnumeration >
131 : 0 : SwVbaRevisions::createEnumeration() throw (uno::RuntimeException)
132 : : {
133 [ # # ]: 0 : uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
134 [ # # ][ # # ]: 0 : return new RevisionsEnumeration( this, mxContext, xEnumAccess->createEnumeration(), mxModel );
[ # # ][ # # ]
[ # # ][ # # ]
135 : : }
136 : :
137 : : uno::Any
138 : 0 : SwVbaRevisions::createCollectionObject( const css::uno::Any& aSource )
139 : : {
140 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xRevision( aSource, uno::UNO_QUERY_THROW );
141 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< word::XRevision > ( new SwVbaRevision( this, mxContext, mxModel, xRevision ) ) );
[ # # ][ # # ]
[ # # ]
142 : : }
143 : :
144 : 0 : void SAL_CALL SwVbaRevisions::AcceptAll( ) throw (css::uno::RuntimeException)
145 : : {
146 : : // First we need to put all the redline into a vector, because if the redline is accepted,
147 : : // it will auto delete in the document.
148 [ # # ]: 0 : std::vector< uno::Reference< word::XRevision > > aRevisions;
149 [ # # ]: 0 : uno::Reference< container::XEnumeration > xEnumeration = createEnumeration();
150 [ # # ][ # # ]: 0 : while( xEnumeration->hasMoreElements() )
[ # # ]
151 : : {
152 [ # # ][ # # ]: 0 : uno::Reference< word::XRevision > xRevision( xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
[ # # ]
153 [ # # ]: 0 : aRevisions.push_back( xRevision );
154 : 0 : }
155 : :
156 : 0 : std::vector< uno::Reference< word::XRevision > >::iterator it = aRevisions.begin();
157 [ # # ][ # # ]: 0 : for( ; it != aRevisions.end(); ++it )
158 : : {
159 : 0 : uno::Reference< word::XRevision > xRevision( *it );
160 [ # # ][ # # ]: 0 : xRevision->Accept();
161 : 0 : }
162 : 0 : }
163 : :
164 : 0 : void SAL_CALL SwVbaRevisions::RejectAll( ) throw (css::uno::RuntimeException)
165 : : {
166 [ # # ]: 0 : throw uno::RuntimeException();
167 : : }
168 : :
169 : : rtl::OUString
170 : 0 : SwVbaRevisions::getServiceImplName()
171 : : {
172 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaRevisions"));
173 : : }
174 : :
175 : : css::uno::Sequence<rtl::OUString>
176 : 0 : SwVbaRevisions::getServiceNames()
177 : : {
178 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > sNames;
[ # # ][ # # ]
179 [ # # ]: 0 : if ( sNames.getLength() == 0 )
180 : : {
181 : 0 : sNames.realloc( 1 );
182 [ # # ]: 0 : sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Revisions") );
183 : : }
184 : 0 : return sNames;
185 : : }
186 : :
187 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|