a11y: Simplify OCommonAccessibleComponent::getAccessibleIndexInParent
[LibreOffice.git] / sw / inc / unoparagraph.hxx
bloba4936991fd605b518e1ac11cd35b74659e63e0f0
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 #ifndef INCLUDED_SW_INC_UNOPARAGRAPH_HXX
21 #define INCLUDED_SW_INC_UNOPARAGRAPH_HXX
23 #include <memory>
24 #include <optional>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/beans/XPropertyState.hpp>
29 #include <com/sun/star/beans/XMultiPropertySet.hpp>
30 #include <com/sun/star/beans/XTolerantMultiPropertySet.hpp>
31 #include <com/sun/star/container/XEnumerationAccess.hpp>
32 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
33 #include <com/sun/star/text/XTextContent.hpp>
34 #include <com/sun/star/text/XTextRange.hpp>
36 #include <comphelper/interfacecontainer4.hxx>
37 #include <cppuhelper/implbase.hxx>
39 #include <sfx2/Metadatable.hxx>
40 #include <svl/listener.hxx>
42 #include "unobaseclass.hxx"
44 class SfxItemPropertySet;
45 struct SfxItemPropertyMapEntry;
46 class SwPaM;
47 class SwUnoCursor;
48 class SwStartNode;
49 class SwTextNode;
50 class SwTableBox;
51 class SwXText;
52 class SwXTextPortionEnumeration;
54 typedef ::cppu::ImplInheritanceHelper
55 < ::sfx2::MetadatableMixin
56 , css::lang::XServiceInfo
57 , css::beans::XPropertySet
58 , css::beans::XPropertyState
59 , css::beans::XMultiPropertySet
60 , css::beans::XTolerantMultiPropertySet
61 , css::container::XEnumerationAccess
62 , css::container::XContentEnumerationAccess
63 , css::text::XTextContent
64 , css::text::XTextRange
65 > SwXParagraph_Base;
67 class SwXParagraph final
68 : public SwXParagraph_Base
71 private:
73 virtual ~SwXParagraph() override;
75 SwXParagraph(css::uno::Reference< SwXText > const & xParent,
76 SwTextNode & rTextNode,
77 const sal_Int32 nSelStart, const sal_Int32 nSelEnd);
79 /// descriptor
80 SwXParagraph();
82 /// @throws beans::UnknownPropertyException
83 /// @throws beans::PropertyVetoException
84 /// @throws lang::IllegalArgumentException
85 /// @throws lang::WrappedTargetException
86 /// @throws uno::RuntimeException
87 void SetPropertyValues_Impl(
88 const css::uno::Sequence< OUString >& rPropertyNames,
89 const css::uno::Sequence< css::uno::Any >& rValues );
90 /// @throws beans::UnknownPropertyException
91 /// @throws lang::WrappedTargetException
92 /// @throws uno::RuntimeException
93 css::uno::Sequence< css::uno::Any > GetPropertyValues_Impl(
94 const css::uno::Sequence< OUString >& rPropertyNames);
95 SwTextNode& GetTextNodeOrThrow();
96 /// @throws uno::RuntimeException
97 static void GetSinglePropertyValue_Impl(
98 const SfxItemPropertyMapEntry& rEntry,
99 const SfxItemSet& rSet,
100 css::uno::Any& rAny );
101 /// @throws uno::RuntimeException
102 css::uno::Sequence< css::beans::GetDirectPropertyTolerantResult >
103 GetPropertyValuesTolerant_Impl(
104 const css::uno::Sequence< OUString >& rPropertyNames,
105 bool bDirectValuesOnly);
107 public:
109 static rtl::Reference<SwXParagraph>
110 CreateXParagraph(SwDoc & rDoc, SwTextNode * pTextNode,
111 css::uno::Reference<SwXText> const& xParentText,
112 const sal_Int32 nSelStart = -1, const sal_Int32 nSelEnd = - 1);
114 const SwTextNode * GetTextNode() const { return m_pTextNode; }
115 bool IsDescriptor() const { return m_bIsDescriptor; }
116 /// make rPaM select the paragraph
117 bool SelectPaM(SwPaM & rPaM);
118 /// for SwXText
119 void attachToText(SwXText & rParent, SwTextNode & rTextNode);
121 // MetadatableMixin
122 virtual ::sfx2::Metadatable* GetCoreObject() override;
123 virtual css::uno::Reference< css::frame::XModel >
124 GetModel() override;
126 // XServiceInfo
127 virtual OUString SAL_CALL getImplementationName() override;
128 virtual sal_Bool SAL_CALL supportsService(
129 const OUString& rServiceName) override;
130 virtual css::uno::Sequence< OUString > SAL_CALL
131 getSupportedServiceNames() override;
133 // XComponent
134 virtual void SAL_CALL dispose() override;
135 virtual void SAL_CALL addEventListener(
136 const css::uno::Reference< css::lang::XEventListener > & xListener) override;
137 virtual void SAL_CALL removeEventListener(
138 const css::uno::Reference< css::lang::XEventListener > & xListener) override;
140 // XPropertySet
141 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
142 getPropertySetInfo() override;
143 virtual void SAL_CALL setPropertyValue(
144 const OUString& rPropertyName,
145 const css::uno::Any& rValue) override;
146 virtual css::uno::Any SAL_CALL getPropertyValue(
147 const OUString& rPropertyName) override;
148 virtual void SAL_CALL addPropertyChangeListener(
149 const OUString& rPropertyName,
150 const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener) override;
151 virtual void SAL_CALL removePropertyChangeListener(
152 const OUString& rPropertyName,
153 const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener) override;
154 virtual void SAL_CALL addVetoableChangeListener(
155 const OUString& rPropertyName,
156 const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener) override;
157 virtual void SAL_CALL removeVetoableChangeListener(
158 const OUString& rPropertyName,
159 const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener) override;
161 // XPropertyState
162 virtual css::beans::PropertyState SAL_CALL
163 getPropertyState(const OUString& rPropertyName) override;
164 virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL
165 getPropertyStates(
166 const css::uno::Sequence< OUString >& rPropertyNames) override;
167 virtual void SAL_CALL setPropertyToDefault(
168 const OUString& rPropertyName) override;
169 virtual css::uno::Any SAL_CALL getPropertyDefault(
170 const OUString& rPropertyName) override;
172 // XMultiPropertySet
173 virtual void SAL_CALL setPropertyValues(
174 const css::uno::Sequence< OUString >& rPropertyNames,
175 const css::uno::Sequence< css::uno::Any >& rValues) override;
176 virtual css::uno::Sequence< css::uno::Any >
177 SAL_CALL getPropertyValues(
178 const css::uno::Sequence< OUString >& rPropertyNames) override;
179 virtual void SAL_CALL addPropertiesChangeListener(
180 const css::uno::Sequence< OUString >& rPropertyNames,
181 const css::uno::Reference< css::beans::XPropertiesChangeListener >& xListener) override;
182 virtual void SAL_CALL removePropertiesChangeListener(
183 const css::uno::Reference< css::beans::XPropertiesChangeListener >& xListener) override;
184 virtual void SAL_CALL firePropertiesChangeEvent(
185 const css::uno::Sequence< OUString >& rPropertyNames,
186 const css::uno::Reference< css::beans::XPropertiesChangeListener >& xListener) override;
188 // XTolerantMultiPropertySet
189 virtual css::uno::Sequence< css::beans::SetPropertyTolerantFailed > SAL_CALL
190 setPropertyValuesTolerant(
191 const css::uno::Sequence< OUString >& rPropertyNames,
192 const css::uno::Sequence< css::uno::Any >& rValues) override;
193 virtual css::uno::Sequence< css::beans::GetPropertyTolerantResult > SAL_CALL
194 getPropertyValuesTolerant(
195 const css::uno::Sequence< OUString >& rPropertyNames) override;
196 virtual css::uno::Sequence<
197 css::beans::GetDirectPropertyTolerantResult > SAL_CALL
198 getDirectPropertyValuesTolerant(
199 const css::uno::Sequence< OUString >& rPropertyNames) override;
201 // XElementAccess
202 virtual css::uno::Type SAL_CALL getElementType() override;
203 virtual sal_Bool SAL_CALL hasElements() override;
205 // XEnumerationAccess
206 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
207 createEnumeration() override;
209 // XContentEnumerationAccess
210 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
211 createContentEnumeration(const OUString& rServiceName) override;
212 virtual css::uno::Sequence< OUString > SAL_CALL
213 getAvailableServiceNames() override;
215 // XTextContent
216 virtual void SAL_CALL attach(
217 const css::uno::Reference< css::text::XTextRange > & xTextRange) override;
218 virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getAnchor() override;
220 // XTextRange
221 virtual css::uno::Reference< css::text::XText >
222 SAL_CALL getText() override;
223 virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override;
224 virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override;
225 virtual OUString SAL_CALL getString() override;
226 virtual void SAL_CALL setString(const OUString& rString) override;
228 /// tries to return less data, but may return more than just text fields
229 rtl::Reference<SwXTextPortionEnumeration> createTextFieldsEnumeration();
231 private:
232 std::mutex m_Mutex; // just for OInterfaceContainerHelper4
233 ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> m_EventListeners;
234 SfxItemPropertySet const& m_rPropSet;
235 bool m_bIsDescriptor;
236 sal_Int32 m_nSelectionStartPos;
237 sal_Int32 m_nSelectionEndPos;
238 OUString m_sText;
239 css::uno::Reference<SwXText> m_xParentText;
240 SwTextNode* m_pTextNode;
241 struct MySvtListener : public SvtListener
243 SwXParagraph& m_rThis;
244 MySvtListener(SwXParagraph& rThis) : m_rThis(rThis) {}
245 virtual void Notify(const SfxHint& rHint) override;
247 std::optional<MySvtListener> moSvtListener;
251 struct SwXParagraphEnumeration
252 : public SwSimpleEnumeration_Base
254 static rtl::Reference<SwXParagraphEnumeration> Create(
255 css::uno::Reference< css::text::XText > const & xParent,
256 const std::shared_ptr<SwUnoCursor>& pCursor,
257 const CursorType eType,
258 /// only for CursorType::TableText
259 SwTableBox const*const pTableBox = nullptr);
262 #endif // INCLUDED_SW_INC_UNOPARAGRAPH_HXX
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */