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( )
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 {
66 vos::OGuard aGuard(Application::GetSolarMutex());
67 if(!IsValid())
68 throw uno::RuntimeException();
69 const SwRedlineTbl& rRedTbl = GetDoc()->GetRedlineTbl();
70 uno::Any aRet;
71 if(rRedTbl.Count() > nIndex && nIndex >= 0)
72 {
73 uno::Reference <beans::XPropertySet> xRet = SwXRedlines::GetObject( *rRedTbl.GetObject((sal_uInt16)nIndex), *GetDoc() );
74 aRet <<= xRet;
75 }
76 else
77 throw lang::IndexOutOfBoundsException();
78 return aRet;
79 }
80
createEnumeration(void)81 uno::Reference< container::XEnumeration > SwXRedlines::createEnumeration(void)
82 {
83 vos::OGuard aGuard(Application::GetSolarMutex());
84 if(!IsValid())
85 throw uno::RuntimeException();
86 return uno::Reference< container::XEnumeration >(new SwXRedlineEnumeration(*GetDoc()));
87 }
88
getElementType()89 uno::Type SwXRedlines::getElementType( )
90 {
91 return ::getCppuType((uno::Reference<beans::XPropertySet>*)0);
92 }
93
hasElements()94 sal_Bool SwXRedlines::hasElements( )
95 {
96 vos::OGuard aGuard(Application::GetSolarMutex());
97 if(!IsValid())
98 throw uno::RuntimeException();
99 const SwRedlineTbl& rRedTbl = GetDoc()->GetRedlineTbl();
100 return rRedTbl.Count() > 0;
101 }
102
getImplementationName(void)103 OUString SwXRedlines::getImplementationName(void)
104 {
105 return C2U("SwXRedlines");
106 }
107
supportsService(const rtl::OUString &)108 sal_Bool SwXRedlines::supportsService(const rtl::OUString& /*ServiceName*/)
109 {
110 DBG_ERROR("not implemented");
111 return sal_False;
112 }
113
getSupportedServiceNames(void)114 uno::Sequence< OUString > SwXRedlines::getSupportedServiceNames(void)
115 {
116 DBG_ERROR("not implemented");
117 return uno::Sequence< OUString >();
118 }
119
GetObject(SwRedline & rRedline,SwDoc & rDoc)120 beans::XPropertySet* SwXRedlines::GetObject( SwRedline& rRedline, SwDoc& rDoc )
121 {
122 SwPageDesc* pStdDesc = rDoc.GetPageDescFromPool(RES_POOLPAGE_STANDARD);
123 SwIterator<SwXRedline,SwPageDesc> aIter(*pStdDesc);
124 SwXRedline* pxRedline = aIter.First();
125 while(pxRedline)
126 {
127 if(pxRedline->GetRedline() == &rRedline)
128 break;
129 pxRedline = aIter.Next();
130 }
131 if( !pxRedline )
132 pxRedline = new SwXRedline(rRedline, rDoc);
133 return pxRedline;
134 }
135
SwXRedlineEnumeration(SwDoc & rDoc)136 SwXRedlineEnumeration::SwXRedlineEnumeration(SwDoc& rDoc) :
137 pDoc(&rDoc),
138 nCurrentIndex(0)
139 {
140 pDoc->GetPageDescFromPool(RES_POOLPAGE_STANDARD)->Add(this);
141 }
142
~SwXRedlineEnumeration()143 SwXRedlineEnumeration::~SwXRedlineEnumeration()
144 {
145 }
146
hasMoreElements(void)147 sal_Bool SwXRedlineEnumeration::hasMoreElements(void)
148 {
149 if(!pDoc)
150 throw uno::RuntimeException();
151 return pDoc->GetRedlineTbl().Count() > nCurrentIndex;
152 }
153
nextElement(void)154 uno::Any SwXRedlineEnumeration::nextElement(void)
155 {
156 if(!pDoc)
157 throw uno::RuntimeException();
158 const SwRedlineTbl& rRedTbl = pDoc->GetRedlineTbl();
159 if(!(rRedTbl.Count() > nCurrentIndex))
160 throw container::NoSuchElementException();
161 uno::Reference <beans::XPropertySet> xRet = SwXRedlines::GetObject( *rRedTbl.GetObject(nCurrentIndex++), *pDoc );
162 uno::Any aRet;
163 aRet <<= xRet;
164 return aRet;
165 }
166
getImplementationName(void)167 rtl::OUString SwXRedlineEnumeration::getImplementationName(void)
168 {
169 return C2U("SwXRedlineEnumeration");
170 }
171
supportsService(const rtl::OUString &)172 sal_Bool SwXRedlineEnumeration::supportsService(const rtl::OUString& /*ServiceName*/)
173 {
174 return sal_False;
175 }
176
getSupportedServiceNames(void)177 uno::Sequence< OUString > SwXRedlineEnumeration::getSupportedServiceNames(void)
178 {
179 return uno::Sequence< OUString >();
180 }
181
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)182 void SwXRedlineEnumeration::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
183 {
184 ClientModify(this, pOld, pNew);
185 if(!GetRegisteredIn())
186 pDoc = 0;
187 }
188