Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / unocore / unoredlines.cxx
blob572bb7756647a29e1d53e8e9b7b88d3c62c96fc0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/beans/XPropertySet.hpp>
21 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
22 #include <cppuhelper/supportsservice.hxx>
24 #include <vcl/svapp.hxx>
25 #include <o3tl/safeint.hxx>
26 #include <osl/diagnose.h>
28 #include <unoredlines.hxx>
29 #include <unoredline.hxx>
30 #include <pagedesc.hxx>
31 #include <poolfmt.hxx>
32 #include <doc.hxx>
33 #include <IDocumentRedlineAccess.hxx>
34 #include <IDocumentStylePoolAccess.hxx>
35 #include <docary.hxx>
36 #include <redline.hxx>
38 using namespace ::com::sun::star;
40 SwXRedlines::SwXRedlines(SwDoc* _pDoc) :
41 SwUnoCollection(_pDoc)
45 SwXRedlines::~SwXRedlines()
49 sal_Int32 SwXRedlines::getCount( )
51 SolarMutexGuard aGuard;
52 if(!IsValid())
53 throw uno::RuntimeException();
54 const SwRedlineTable& rRedTable = GetDoc()->getIDocumentRedlineAccess().GetRedlineTable();
55 return rRedTable.size();
58 uno::Any SwXRedlines::getByIndex(sal_Int32 nIndex)
60 SolarMutexGuard aGuard;
61 if(!IsValid())
62 throw uno::RuntimeException();
63 const SwRedlineTable& rRedTable = GetDoc()->getIDocumentRedlineAccess().GetRedlineTable();
64 if ((nIndex < 0) || (rRedTable.size() <= o3tl::make_unsigned(nIndex)))
65 throw lang::IndexOutOfBoundsException();
67 uno::Reference <beans::XPropertySet> xRet = SwXRedlines::GetObject( *rRedTable[nIndex], *GetDoc() );
68 return uno::Any(xRet);
71 uno::Reference< container::XEnumeration > SwXRedlines::createEnumeration()
73 SolarMutexGuard aGuard;
74 if(!IsValid())
75 throw uno::RuntimeException();
76 return uno::Reference< container::XEnumeration >(new SwXRedlineEnumeration(*GetDoc()));
79 uno::Type SwXRedlines::getElementType( )
81 return cppu::UnoType<beans::XPropertySet>::get();
84 sal_Bool SwXRedlines::hasElements( )
86 SolarMutexGuard aGuard;
87 if(!IsValid())
88 throw uno::RuntimeException();
89 const SwRedlineTable& rRedTable = GetDoc()->getIDocumentRedlineAccess().GetRedlineTable();
90 return !rRedTable.empty();
93 OUString SwXRedlines::getImplementationName()
95 return "SwXRedlines";
98 sal_Bool SwXRedlines::supportsService(const OUString& ServiceName)
100 return cppu::supportsService(this, ServiceName);
103 uno::Sequence< OUString > SwXRedlines::getSupportedServiceNames()
105 OSL_FAIL("not implemented");
106 return uno::Sequence< OUString >();
109 beans::XPropertySet* SwXRedlines::GetObject( SwRangeRedline& rRedline, SwDoc& rDoc )
111 SwXRedline* pXRedline(nullptr);
112 sw::FindRedlineHint aHint(rRedline, &pXRedline);
113 rDoc.getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier().Broadcast(aHint);
114 return pXRedline ? pXRedline : new SwXRedline(rRedline, rDoc);
117 SwXRedlineEnumeration::SwXRedlineEnumeration(SwDoc& rDoc) :
118 m_pDoc(&rDoc),
119 m_nCurrentIndex(0)
121 StartListening(m_pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier());
124 SwXRedlineEnumeration::~SwXRedlineEnumeration()
128 sal_Bool SwXRedlineEnumeration::hasMoreElements()
130 if(!m_pDoc)
131 throw uno::RuntimeException();
132 return m_pDoc->getIDocumentRedlineAccess().GetRedlineTable().size() > m_nCurrentIndex;
135 uno::Any SwXRedlineEnumeration::nextElement()
137 if(!m_pDoc)
138 throw uno::RuntimeException();
139 const SwRedlineTable& rRedTable = m_pDoc->getIDocumentRedlineAccess().GetRedlineTable();
140 if( rRedTable.size() <= m_nCurrentIndex )
141 throw container::NoSuchElementException();
142 uno::Reference <beans::XPropertySet> xRet = SwXRedlines::GetObject( *rRedTable[m_nCurrentIndex++], *m_pDoc );
143 uno::Any aRet;
144 aRet <<= xRet;
145 return aRet;
148 OUString SwXRedlineEnumeration::getImplementationName()
150 return "SwXRedlineEnumeration";
153 sal_Bool SwXRedlineEnumeration::supportsService(const OUString& ServiceName)
155 return cppu::supportsService(this, ServiceName);
158 uno::Sequence< OUString > SwXRedlineEnumeration::getSupportedServiceNames()
160 return uno::Sequence< OUString >();
163 void SwXRedlineEnumeration::Notify( const SfxHint& rHint )
165 if(rHint.GetId() == SfxHintId::Dying)
166 m_pDoc = nullptr;
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */