Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <com/sun/star/beans/XPropertySet.hpp>
22 :
23 : #include <osl/mutex.hxx>
24 : #include <vcl/svapp.hxx>
25 :
26 : #include <unoredlines.hxx>
27 : #include <unoredline.hxx>
28 : #include <unomid.h>
29 : #include <pagedesc.hxx>
30 : #include "poolfmt.hxx"
31 : #include <doc.hxx>
32 : #include <docary.hxx>
33 : #include <redline.hxx>
34 : #include <switerator.hxx>
35 :
36 : using namespace ::com::sun::star;
37 :
38 15 : SwXRedlines::SwXRedlines(SwDoc* _pDoc) :
39 15 : SwUnoCollection(_pDoc)
40 : {
41 15 : }
42 :
43 30 : SwXRedlines::~SwXRedlines()
44 : {
45 30 : }
46 :
47 0 : sal_Int32 SwXRedlines::getCount( ) throw(uno::RuntimeException)
48 : {
49 0 : SolarMutexGuard aGuard;
50 0 : if(!IsValid())
51 0 : throw uno::RuntimeException();
52 0 : const SwRedlineTbl& rRedTbl = GetDoc()->GetRedlineTbl();
53 0 : return rRedTbl.size();
54 : }
55 :
56 0 : uno::Any SwXRedlines::getByIndex(sal_Int32 nIndex)
57 : throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException )
58 : {
59 0 : SolarMutexGuard aGuard;
60 0 : if(!IsValid())
61 0 : throw uno::RuntimeException();
62 0 : const SwRedlineTbl& rRedTbl = GetDoc()->GetRedlineTbl();
63 0 : uno::Any aRet;
64 0 : if ((rRedTbl.size() > static_cast<size_t>(nIndex)) && (nIndex >= 0))
65 : {
66 0 : uno::Reference <beans::XPropertySet> xRet = SwXRedlines::GetObject( *rRedTbl[nIndex], *GetDoc() );
67 0 : aRet <<= xRet;
68 : }
69 : else
70 0 : throw lang::IndexOutOfBoundsException();
71 0 : return aRet;
72 : }
73 :
74 0 : uno::Reference< container::XEnumeration > SwXRedlines::createEnumeration(void)
75 : throw( uno::RuntimeException )
76 : {
77 0 : SolarMutexGuard aGuard;
78 0 : if(!IsValid())
79 0 : throw uno::RuntimeException();
80 0 : return uno::Reference< container::XEnumeration >(new SwXRedlineEnumeration(*GetDoc()));
81 : }
82 :
83 0 : uno::Type SwXRedlines::getElementType( ) throw(uno::RuntimeException)
84 : {
85 0 : return ::getCppuType((uno::Reference<beans::XPropertySet>*)0);
86 : }
87 :
88 32 : sal_Bool SwXRedlines::hasElements( ) throw(uno::RuntimeException)
89 : {
90 32 : SolarMutexGuard aGuard;
91 32 : if(!IsValid())
92 0 : throw uno::RuntimeException();
93 32 : const SwRedlineTbl& rRedTbl = GetDoc()->GetRedlineTbl();
94 32 : return rRedTbl.size() > 0;
95 : }
96 :
97 0 : OUString SwXRedlines::getImplementationName(void) throw( uno::RuntimeException )
98 : {
99 0 : return OUString("SwXRedlines");
100 : }
101 :
102 0 : sal_Bool SwXRedlines::supportsService(const OUString& /*ServiceName*/)
103 : throw( uno::RuntimeException )
104 : {
105 : OSL_FAIL("not implemented");
106 0 : return sal_False;
107 : }
108 :
109 0 : uno::Sequence< OUString > SwXRedlines::getSupportedServiceNames(void)
110 : throw( uno::RuntimeException )
111 : {
112 : OSL_FAIL("not implemented");
113 0 : return uno::Sequence< OUString >();
114 : }
115 :
116 0 : beans::XPropertySet* SwXRedlines::GetObject( SwRedline& rRedline, SwDoc& rDoc )
117 : {
118 0 : SwPageDesc* pStdDesc = rDoc.GetPageDescFromPool(RES_POOLPAGE_STANDARD);
119 0 : SwIterator<SwXRedline,SwPageDesc> aIter(*pStdDesc);
120 0 : SwXRedline* pxRedline = aIter.First();
121 0 : while(pxRedline)
122 : {
123 0 : if(pxRedline->GetRedline() == &rRedline)
124 0 : break;
125 0 : pxRedline = aIter.Next();
126 : }
127 0 : if( !pxRedline )
128 0 : pxRedline = new SwXRedline(rRedline, rDoc);
129 0 : return pxRedline;
130 : }
131 :
132 0 : SwXRedlineEnumeration::SwXRedlineEnumeration(SwDoc& rDoc) :
133 : pDoc(&rDoc),
134 0 : nCurrentIndex(0)
135 : {
136 0 : pDoc->GetPageDescFromPool(RES_POOLPAGE_STANDARD)->Add(this);
137 0 : }
138 :
139 0 : SwXRedlineEnumeration::~SwXRedlineEnumeration()
140 : {
141 0 : }
142 :
143 0 : sal_Bool SwXRedlineEnumeration::hasMoreElements(void) throw( uno::RuntimeException )
144 : {
145 0 : if(!pDoc)
146 0 : throw uno::RuntimeException();
147 0 : return pDoc->GetRedlineTbl().size() > nCurrentIndex;
148 : }
149 :
150 0 : uno::Any SwXRedlineEnumeration::nextElement(void)
151 : throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
152 : {
153 0 : if(!pDoc)
154 0 : throw uno::RuntimeException();
155 0 : const SwRedlineTbl& rRedTbl = pDoc->GetRedlineTbl();
156 0 : if( rRedTbl.size() <= nCurrentIndex )
157 0 : throw container::NoSuchElementException();
158 0 : uno::Reference <beans::XPropertySet> xRet = SwXRedlines::GetObject( *rRedTbl[nCurrentIndex++], *pDoc );
159 0 : uno::Any aRet;
160 0 : aRet <<= xRet;
161 0 : return aRet;
162 : }
163 :
164 0 : OUString SwXRedlineEnumeration::getImplementationName(void) throw( uno::RuntimeException )
165 : {
166 0 : return OUString("SwXRedlineEnumeration");
167 : }
168 :
169 0 : sal_Bool SwXRedlineEnumeration::supportsService(const OUString& /*ServiceName*/) throw( uno::RuntimeException )
170 : {
171 0 : return sal_False;
172 : }
173 :
174 0 : uno::Sequence< OUString > SwXRedlineEnumeration::getSupportedServiceNames(void) throw( uno::RuntimeException )
175 : {
176 0 : return uno::Sequence< OUString >();
177 : }
178 :
179 0 : void SwXRedlineEnumeration::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
180 : {
181 0 : ClientModify(this, pOld, pNew);
182 0 : if(!GetRegisteredIn())
183 0 : pDoc = 0;
184 99 : }
185 :
186 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|