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 : using ::rtl::OUString;
38 :
39 2 : SwXRedlines::SwXRedlines(SwDoc* _pDoc) :
40 2 : SwUnoCollection(_pDoc)
41 : {
42 2 : }
43 :
44 4 : SwXRedlines::~SwXRedlines()
45 : {
46 4 : }
47 :
48 0 : sal_Int32 SwXRedlines::getCount( ) throw(uno::RuntimeException)
49 : {
50 0 : SolarMutexGuard aGuard;
51 0 : if(!IsValid())
52 0 : throw uno::RuntimeException();
53 0 : const SwRedlineTbl& rRedTbl = GetDoc()->GetRedlineTbl();
54 0 : return rRedTbl.size();
55 : }
56 :
57 0 : uno::Any SwXRedlines::getByIndex(sal_Int32 nIndex)
58 : throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException )
59 : {
60 0 : SolarMutexGuard aGuard;
61 0 : if(!IsValid())
62 0 : throw uno::RuntimeException();
63 0 : const SwRedlineTbl& rRedTbl = GetDoc()->GetRedlineTbl();
64 0 : uno::Any aRet;
65 0 : if ((rRedTbl.size() > static_cast<size_t>(nIndex)) && (nIndex >= 0))
66 : {
67 0 : uno::Reference <beans::XPropertySet> xRet = SwXRedlines::GetObject( *rRedTbl[nIndex], *GetDoc() );
68 0 : aRet <<= xRet;
69 : }
70 : else
71 0 : throw lang::IndexOutOfBoundsException();
72 0 : return aRet;
73 : }
74 :
75 0 : uno::Reference< container::XEnumeration > SwXRedlines::createEnumeration(void)
76 : throw( uno::RuntimeException )
77 : {
78 0 : SolarMutexGuard aGuard;
79 0 : if(!IsValid())
80 0 : throw uno::RuntimeException();
81 0 : return uno::Reference< container::XEnumeration >(new SwXRedlineEnumeration(*GetDoc()));
82 : }
83 :
84 0 : uno::Type SwXRedlines::getElementType( ) throw(uno::RuntimeException)
85 : {
86 0 : return ::getCppuType((uno::Reference<beans::XPropertySet>*)0);
87 : }
88 :
89 4 : sal_Bool SwXRedlines::hasElements( ) throw(uno::RuntimeException)
90 : {
91 4 : SolarMutexGuard aGuard;
92 4 : if(!IsValid())
93 0 : throw uno::RuntimeException();
94 4 : const SwRedlineTbl& rRedTbl = GetDoc()->GetRedlineTbl();
95 4 : return rRedTbl.size() > 0;
96 : }
97 :
98 0 : OUString SwXRedlines::getImplementationName(void) throw( uno::RuntimeException )
99 : {
100 0 : return C2U("SwXRedlines");
101 : }
102 :
103 0 : sal_Bool SwXRedlines::supportsService(const rtl::OUString& /*ServiceName*/)
104 : throw( uno::RuntimeException )
105 : {
106 : OSL_FAIL("not implemented");
107 0 : return sal_False;
108 : }
109 :
110 0 : uno::Sequence< OUString > SwXRedlines::getSupportedServiceNames(void)
111 : throw( uno::RuntimeException )
112 : {
113 : OSL_FAIL("not implemented");
114 0 : return uno::Sequence< OUString >();
115 : }
116 :
117 0 : beans::XPropertySet* SwXRedlines::GetObject( SwRedline& rRedline, SwDoc& rDoc )
118 : {
119 0 : SwPageDesc* pStdDesc = rDoc.GetPageDescFromPool(RES_POOLPAGE_STANDARD);
120 0 : SwIterator<SwXRedline,SwPageDesc> aIter(*pStdDesc);
121 0 : SwXRedline* pxRedline = aIter.First();
122 0 : while(pxRedline)
123 : {
124 0 : if(pxRedline->GetRedline() == &rRedline)
125 0 : break;
126 0 : pxRedline = aIter.Next();
127 : }
128 0 : if( !pxRedline )
129 0 : pxRedline = new SwXRedline(rRedline, rDoc);
130 0 : return pxRedline;
131 : }
132 :
133 0 : SwXRedlineEnumeration::SwXRedlineEnumeration(SwDoc& rDoc) :
134 : pDoc(&rDoc),
135 0 : nCurrentIndex(0)
136 : {
137 0 : pDoc->GetPageDescFromPool(RES_POOLPAGE_STANDARD)->Add(this);
138 0 : }
139 :
140 0 : SwXRedlineEnumeration::~SwXRedlineEnumeration()
141 : {
142 0 : }
143 :
144 0 : sal_Bool SwXRedlineEnumeration::hasMoreElements(void) throw( uno::RuntimeException )
145 : {
146 0 : if(!pDoc)
147 0 : throw uno::RuntimeException();
148 0 : return pDoc->GetRedlineTbl().size() > nCurrentIndex;
149 : }
150 :
151 0 : uno::Any SwXRedlineEnumeration::nextElement(void)
152 : throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
153 : {
154 0 : if(!pDoc)
155 0 : throw uno::RuntimeException();
156 0 : const SwRedlineTbl& rRedTbl = pDoc->GetRedlineTbl();
157 0 : if( rRedTbl.size() <= nCurrentIndex )
158 0 : throw container::NoSuchElementException();
159 0 : uno::Reference <beans::XPropertySet> xRet = SwXRedlines::GetObject( *rRedTbl[nCurrentIndex++], *pDoc );
160 0 : uno::Any aRet;
161 0 : aRet <<= xRet;
162 0 : return aRet;
163 : }
164 :
165 0 : rtl::OUString SwXRedlineEnumeration::getImplementationName(void) throw( uno::RuntimeException )
166 : {
167 0 : return C2U("SwXRedlineEnumeration");
168 : }
169 :
170 0 : sal_Bool SwXRedlineEnumeration::supportsService(const rtl::OUString& /*ServiceName*/) throw( uno::RuntimeException )
171 : {
172 0 : return sal_False;
173 : }
174 :
175 0 : uno::Sequence< OUString > SwXRedlineEnumeration::getSupportedServiceNames(void) throw( uno::RuntimeException )
176 : {
177 0 : return uno::Sequence< OUString >();
178 : }
179 :
180 0 : void SwXRedlineEnumeration::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
181 : {
182 0 : ClientModify(this, pOld, pNew);
183 0 : if(!GetRegisteredIn())
184 0 : pDoc = 0;
185 0 : }
186 :
187 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|