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 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <tools/debug.hxx>
30cdf0e10cSrcweir #include <vos/mutex.hxx>
31cdf0e10cSrcweir #include <vcl/svapp.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <unoredlines.hxx>
34cdf0e10cSrcweir #include <unoredline.hxx>
35cdf0e10cSrcweir #include <unomid.h>
36cdf0e10cSrcweir #include <pagedesc.hxx>
37cdf0e10cSrcweir #include "poolfmt.hxx"
38cdf0e10cSrcweir #include <doc.hxx>
39cdf0e10cSrcweir #include <docary.hxx>
40cdf0e10cSrcweir #include <redline.hxx>
41cdf0e10cSrcweir #include <switerator.hxx>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir using namespace ::com::sun::star;
44cdf0e10cSrcweir using ::rtl::OUString;
45cdf0e10cSrcweir 
SwXRedlines(SwDoc * _pDoc)46cdf0e10cSrcweir SwXRedlines::SwXRedlines(SwDoc* _pDoc) :
47cdf0e10cSrcweir 	SwUnoCollection(_pDoc)
48cdf0e10cSrcweir {
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
~SwXRedlines()51cdf0e10cSrcweir SwXRedlines::~SwXRedlines()
52cdf0e10cSrcweir {
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
getCount()55cdf0e10cSrcweir sal_Int32 SwXRedlines::getCount(  ) throw(uno::RuntimeException)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
58cdf0e10cSrcweir 	if(!IsValid())
59cdf0e10cSrcweir 		throw uno::RuntimeException();
60cdf0e10cSrcweir 	const SwRedlineTbl& rRedTbl = GetDoc()->GetRedlineTbl();
61cdf0e10cSrcweir 	return rRedTbl.Count();
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
getByIndex(sal_Int32 nIndex)64cdf0e10cSrcweir uno::Any SwXRedlines::getByIndex(sal_Int32 nIndex)
65cdf0e10cSrcweir 	throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
68cdf0e10cSrcweir 	if(!IsValid())
69cdf0e10cSrcweir 		throw uno::RuntimeException();
70cdf0e10cSrcweir 	const SwRedlineTbl& rRedTbl = GetDoc()->GetRedlineTbl();
71cdf0e10cSrcweir 	uno::Any aRet;
72cdf0e10cSrcweir 	if(rRedTbl.Count() > nIndex && nIndex >= 0)
73cdf0e10cSrcweir 	{
74cdf0e10cSrcweir 		uno::Reference <beans::XPropertySet> xRet = SwXRedlines::GetObject( *rRedTbl.GetObject((sal_uInt16)nIndex), *GetDoc() );
75cdf0e10cSrcweir 		aRet <<= xRet;
76cdf0e10cSrcweir 	}
77cdf0e10cSrcweir 	else
78cdf0e10cSrcweir 		throw lang::IndexOutOfBoundsException();
79cdf0e10cSrcweir 	return aRet;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
createEnumeration(void)82cdf0e10cSrcweir uno::Reference< container::XEnumeration >  SwXRedlines::createEnumeration(void)
83cdf0e10cSrcweir 	throw( uno::RuntimeException )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
86cdf0e10cSrcweir 	if(!IsValid())
87cdf0e10cSrcweir 		throw uno::RuntimeException();
88cdf0e10cSrcweir 	return uno::Reference< container::XEnumeration >(new SwXRedlineEnumeration(*GetDoc()));
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
getElementType()91cdf0e10cSrcweir uno::Type SwXRedlines::getElementType(  ) throw(uno::RuntimeException)
92cdf0e10cSrcweir {
93cdf0e10cSrcweir 	return ::getCppuType((uno::Reference<beans::XPropertySet>*)0);
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
hasElements()96cdf0e10cSrcweir sal_Bool SwXRedlines::hasElements(  ) throw(uno::RuntimeException)
97cdf0e10cSrcweir {
98cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
99cdf0e10cSrcweir 	if(!IsValid())
100cdf0e10cSrcweir 		throw uno::RuntimeException();
101cdf0e10cSrcweir 	const SwRedlineTbl& rRedTbl = GetDoc()->GetRedlineTbl();
102cdf0e10cSrcweir 	return rRedTbl.Count() > 0;
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
getImplementationName(void)105cdf0e10cSrcweir OUString SwXRedlines::getImplementationName(void) throw( uno::RuntimeException )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	return C2U("SwXRedlines");
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
supportsService(const rtl::OUString &)110cdf0e10cSrcweir sal_Bool SwXRedlines::supportsService(const rtl::OUString& /*ServiceName*/)
111cdf0e10cSrcweir 	throw( uno::RuntimeException )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir 	DBG_ERROR("not implemented");
114cdf0e10cSrcweir 	return sal_False;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
getSupportedServiceNames(void)117cdf0e10cSrcweir uno::Sequence< OUString > SwXRedlines::getSupportedServiceNames(void)
118cdf0e10cSrcweir 	throw( uno::RuntimeException )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir 	DBG_ERROR("not implemented");
121cdf0e10cSrcweir 	return uno::Sequence< OUString >();
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
GetObject(SwRedline & rRedline,SwDoc & rDoc)124cdf0e10cSrcweir beans::XPropertySet* 	SwXRedlines::GetObject( SwRedline& rRedline, SwDoc& rDoc )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir 	SwPageDesc* pStdDesc = rDoc.GetPageDescFromPool(RES_POOLPAGE_STANDARD);
127cdf0e10cSrcweir 	SwIterator<SwXRedline,SwPageDesc> aIter(*pStdDesc);
128cdf0e10cSrcweir 	SwXRedline* pxRedline = aIter.First();
129cdf0e10cSrcweir 	while(pxRedline)
130cdf0e10cSrcweir 	{
131cdf0e10cSrcweir 		if(pxRedline->GetRedline() == &rRedline)
132cdf0e10cSrcweir 			break;
133cdf0e10cSrcweir 		pxRedline = aIter.Next();
134cdf0e10cSrcweir 	}
135cdf0e10cSrcweir 	if( !pxRedline )
136cdf0e10cSrcweir 		pxRedline = new SwXRedline(rRedline, rDoc);
137cdf0e10cSrcweir 	return pxRedline;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
SwXRedlineEnumeration(SwDoc & rDoc)140cdf0e10cSrcweir SwXRedlineEnumeration::SwXRedlineEnumeration(SwDoc& rDoc) :
141cdf0e10cSrcweir 	pDoc(&rDoc),
142cdf0e10cSrcweir 	nCurrentIndex(0)
143cdf0e10cSrcweir {
144cdf0e10cSrcweir 	pDoc->GetPageDescFromPool(RES_POOLPAGE_STANDARD)->Add(this);
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
~SwXRedlineEnumeration()147cdf0e10cSrcweir SwXRedlineEnumeration::~SwXRedlineEnumeration()
148cdf0e10cSrcweir {
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
hasMoreElements(void)151cdf0e10cSrcweir sal_Bool SwXRedlineEnumeration::hasMoreElements(void) throw( uno::RuntimeException )
152cdf0e10cSrcweir {
153cdf0e10cSrcweir 	if(!pDoc)
154cdf0e10cSrcweir 		throw uno::RuntimeException();
155cdf0e10cSrcweir 	return pDoc->GetRedlineTbl().Count() > nCurrentIndex;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
nextElement(void)158cdf0e10cSrcweir uno::Any SwXRedlineEnumeration::nextElement(void)
159cdf0e10cSrcweir 	throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir 	if(!pDoc)
162cdf0e10cSrcweir 		throw uno::RuntimeException();
163cdf0e10cSrcweir 	const SwRedlineTbl& rRedTbl = pDoc->GetRedlineTbl();
164cdf0e10cSrcweir 	if(!(rRedTbl.Count() > nCurrentIndex))
165cdf0e10cSrcweir 		throw container::NoSuchElementException();
166cdf0e10cSrcweir 	uno::Reference <beans::XPropertySet> xRet = SwXRedlines::GetObject( *rRedTbl.GetObject(nCurrentIndex++), *pDoc );
167cdf0e10cSrcweir 	uno::Any aRet;
168cdf0e10cSrcweir 	aRet <<= xRet;
169cdf0e10cSrcweir 	return aRet;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
getImplementationName(void)172cdf0e10cSrcweir rtl::OUString SwXRedlineEnumeration::getImplementationName(void) throw( uno::RuntimeException )
173cdf0e10cSrcweir {
174cdf0e10cSrcweir 	return C2U("SwXRedlineEnumeration");
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
supportsService(const rtl::OUString &)177cdf0e10cSrcweir sal_Bool SwXRedlineEnumeration::supportsService(const rtl::OUString& /*ServiceName*/) throw( uno::RuntimeException )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir 	return sal_False;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
getSupportedServiceNames(void)182cdf0e10cSrcweir uno::Sequence< OUString > SwXRedlineEnumeration::getSupportedServiceNames(void) throw( uno::RuntimeException )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir 	return uno::Sequence< OUString >();
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)187cdf0e10cSrcweir void SwXRedlineEnumeration::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
188cdf0e10cSrcweir {
189cdf0e10cSrcweir 	ClientModify(this, pOld, pNew);
190cdf0e10cSrcweir 	if(!GetRegisteredIn())
191cdf0e10cSrcweir 		pDoc = 0;
192cdf0e10cSrcweir }
193