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