/src/libreoffice/sw/inc/unotextrange.hxx
Line | Count | Source |
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 | | #ifndef INCLUDED_SW_INC_UNOTEXTRANGE_HXX |
21 | | #define INCLUDED_SW_INC_UNOTEXTRANGE_HXX |
22 | | |
23 | | #include <com/sun/star/lang/XServiceInfo.hpp> |
24 | | #include <com/sun/star/beans/XPropertySet.hpp> |
25 | | #include <com/sun/star/beans/XPropertyState.hpp> |
26 | | #include <com/sun/star/container/XIndexAccess.hpp> |
27 | | #include <com/sun/star/container/XEnumerationAccess.hpp> |
28 | | #include <com/sun/star/container/XContentEnumerationAccess.hpp> |
29 | | #include <com/sun/star/text/XTextRange.hpp> |
30 | | #include <com/sun/star/text/XRedline.hpp> |
31 | | |
32 | | #include <cppuhelper/implbase.hxx> |
33 | | #include <svl/listener.hxx> |
34 | | |
35 | | #include "pam.hxx" |
36 | | #include "unobaseclass.hxx" |
37 | | #include <optional> |
38 | | |
39 | | class SwDoc; |
40 | | class SwUnoCursor; |
41 | | class SwFrameFormat; |
42 | | class SwXText; |
43 | | class SfxItemPropertySet; |
44 | | |
45 | | namespace sw::mark { class MarkBase; } |
46 | | |
47 | | class SW_DLLPUBLIC SwUnoInternalPaM final |
48 | | : public SwPaM |
49 | | { |
50 | | |
51 | | private: |
52 | | SwUnoInternalPaM(const SwUnoInternalPaM&) = delete; |
53 | | |
54 | | public: |
55 | | SwUnoInternalPaM(SwDoc& rDoc); |
56 | | virtual ~SwUnoInternalPaM() override; |
57 | | |
58 | | SwUnoInternalPaM& operator=(const SwPaM& rPaM); |
59 | | }; |
60 | | |
61 | | namespace sw { |
62 | | |
63 | | enum class TextRangeMode { |
64 | | RequireTextNode, |
65 | | AllowNonTextNode, |
66 | | AllowTableNode |
67 | | }; |
68 | | |
69 | | void DeepCopyPaM(SwPaM const & rSource, SwPaM & rTarget); |
70 | | |
71 | | SW_DLLPUBLIC bool XTextRangeToSwPaM(SwUnoInternalPaM& rToFill, |
72 | | const css::uno::Reference<css::text::XTextRange> & xTextRange, |
73 | | TextRangeMode eMode = TextRangeMode::RequireTextNode); |
74 | | |
75 | | css::uno::Reference< SwXText > |
76 | | CreateParentXText(SwDoc & rDoc, const SwPosition& rPos); |
77 | | |
78 | | bool GetDefaultTextContentValue(css::uno::Any& rAny, |
79 | | std::u16string_view rPropertyName, sal_uInt16 nWID = 0); |
80 | | |
81 | | } // namespace sw |
82 | | |
83 | | typedef ::cppu::WeakImplHelper |
84 | | < css::lang::XServiceInfo |
85 | | , css::beans::XPropertySet |
86 | | , css::beans::XPropertyState |
87 | | , css::container::XEnumerationAccess |
88 | | , css::container::XContentEnumerationAccess |
89 | | , css::text::XTextRange |
90 | | , css::text::XRedline |
91 | | > SwXTextRange_Base; |
92 | | |
93 | | class SW_DLLPUBLIC SwXTextRange final |
94 | | : public SwXTextRange_Base |
95 | | { |
96 | | |
97 | | private: |
98 | | |
99 | | friend class SwXText; |
100 | | |
101 | | void SetPositions(SwPaM const& rPam); |
102 | | //TODO: new exception type for protected content |
103 | | /// @throws css::uno::RuntimeException |
104 | | void DeleteAndInsert( |
105 | | std::u16string_view aText, ::sw::DeleteAndInsertMode eMode); |
106 | | void Invalidate(); |
107 | | void GetStartPaM(std::optional<SwPaM>& roPaM); |
108 | | void SetMark(::sw::mark::MarkBase& rMark); |
109 | | void InvalidateImpl(); |
110 | | |
111 | | virtual ~SwXTextRange() override; |
112 | | |
113 | | public: |
114 | | |
115 | | enum RangePosition |
116 | | { |
117 | | RANGE_IN_TEXT, // "ordinary" css::text::TextRange |
118 | | RANGE_IS_TABLE, // anchor of a table |
119 | | RANGE_IS_SECTION, // anchor of a section |
120 | | RANGE_IS_BOOKMARK, ///< anchor of a bookmark |
121 | | }; |
122 | | |
123 | | SwXTextRange(SwPaM const & rPam, |
124 | | const css::uno::Reference< css::text::XText > & xParent, |
125 | | const enum RangePosition eRange = RANGE_IN_TEXT, |
126 | | bool isInCell = false); |
127 | | // only for RANGE_IS_TABLE |
128 | | SwXTextRange(SwTableFormat& rTableFormat); |
129 | | // only for RANGE_IS_SECTION |
130 | | SwXTextRange(SwSectionFormat& rSectionFormat); |
131 | | |
132 | 0 | const SwDoc& GetDoc() const { return m_rDoc; } |
133 | 530k | SwDoc& GetDoc() { return m_rDoc; } |
134 | | bool GetPositions(SwPaM & rToFill, |
135 | | ::sw::TextRangeMode eMode = ::sw::TextRangeMode::RequireTextNode) const; |
136 | | |
137 | | sal_Int16 compareRegionStarts(SwXTextRange& rhs); |
138 | | |
139 | | static rtl::Reference< SwXTextRange > CreateXTextRange( |
140 | | SwDoc & rDoc, |
141 | | const SwPosition& rPos, const SwPosition *const pMark, |
142 | | RangePosition eRange = RANGE_IN_TEXT); |
143 | | |
144 | | // XServiceInfo |
145 | | virtual OUString SAL_CALL getImplementationName() override; |
146 | | virtual sal_Bool SAL_CALL supportsService( |
147 | | const OUString& rServiceName) override; |
148 | | virtual css::uno::Sequence< OUString > SAL_CALL |
149 | | getSupportedServiceNames() override; |
150 | | |
151 | | // XPropertySet |
152 | | virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL |
153 | | getPropertySetInfo() override; |
154 | | virtual void SAL_CALL setPropertyValue( |
155 | | const OUString& rPropertyName, |
156 | | const css::uno::Any& rValue) override; |
157 | | virtual css::uno::Any SAL_CALL getPropertyValue( |
158 | | const OUString& rPropertyName) override; |
159 | | virtual void SAL_CALL addPropertyChangeListener( |
160 | | const OUString& rPropertyName, |
161 | | const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener) override; |
162 | | virtual void SAL_CALL removePropertyChangeListener( |
163 | | const OUString& rPropertyName, |
164 | | const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener) override; |
165 | | virtual void SAL_CALL addVetoableChangeListener( |
166 | | const OUString& rPropertyName, |
167 | | const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener) override; |
168 | | virtual void SAL_CALL removeVetoableChangeListener( |
169 | | const OUString& rPropertyName, |
170 | | const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener) override; |
171 | | |
172 | | // XPropertyState |
173 | | virtual css::beans::PropertyState SAL_CALL |
174 | | getPropertyState(const OUString& rPropertyName) override; |
175 | | virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL |
176 | | getPropertyStates( |
177 | | const css::uno::Sequence< OUString >& rPropertyNames) override; |
178 | | virtual void SAL_CALL setPropertyToDefault( |
179 | | const OUString& rPropertyName) override; |
180 | | virtual css::uno::Any SAL_CALL getPropertyDefault( |
181 | | const OUString& rPropertyName) override; |
182 | | |
183 | | // XElementAccess |
184 | | virtual css::uno::Type SAL_CALL getElementType() override; |
185 | | virtual sal_Bool SAL_CALL hasElements() override; |
186 | | |
187 | | // XEnumerationAccess |
188 | | virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL |
189 | | createEnumeration() override; |
190 | | |
191 | | // XContentEnumerationAccess |
192 | | virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL |
193 | | createContentEnumeration(const OUString& rServiceName) override; |
194 | | virtual css::uno::Sequence< OUString > SAL_CALL |
195 | | getAvailableServiceNames() override; |
196 | | |
197 | | // XTextRange |
198 | | virtual css::uno::Reference< css::text::XText > |
199 | | SAL_CALL getText() override; |
200 | | virtual css::uno::Reference< |
201 | | css::text::XTextRange > SAL_CALL getStart() override; |
202 | | virtual css::uno::Reference< |
203 | | css::text::XTextRange > SAL_CALL getEnd() override; |
204 | | virtual OUString SAL_CALL getString() override; |
205 | | virtual void SAL_CALL setString(const OUString& rString) override; |
206 | | |
207 | | // XRedline |
208 | | virtual void SAL_CALL makeRedline( |
209 | | const OUString& rRedlineType, |
210 | | const css::uno::Sequence< css::beans::PropertyValue >& RedlineProperties) override; |
211 | | |
212 | | private: |
213 | | const SfxItemPropertySet& m_rPropSet; |
214 | | const enum RangePosition m_eRangePosition; |
215 | | bool const m_isRangeInCell; //< position created with a cell that has no uno object |
216 | | SwDoc& m_rDoc; |
217 | | css::uno::Reference<css::text::XText> m_xParentText; |
218 | | const SwFrameFormat* m_pTableOrSectionFormat; |
219 | | const ::sw::mark::MarkBase* m_pMark; |
220 | | struct MySvtListener : public SvtListener |
221 | | { |
222 | | SwXTextRange& mrTextRange; |
223 | | |
224 | 791k | MySvtListener(SwXTextRange& rTextRange) : mrTextRange(rTextRange) {} |
225 | | |
226 | | virtual void Notify(const SfxHint&) override; |
227 | | }; |
228 | | std::optional<MySvtListener> moSvtListener; |
229 | | }; |
230 | | |
231 | | typedef ::cppu::WeakImplHelper |
232 | | < css::lang::XServiceInfo |
233 | | , css::container::XIndexAccess |
234 | | > SwXTextRanges_Base; |
235 | | |
236 | | struct SwXTextRanges : public SwXTextRanges_Base |
237 | | { |
238 | | virtual SwUnoCursor* GetCursor() =0; |
239 | | static rtl::Reference<SwXTextRanges> Create(SwPaM* const pCursor); |
240 | | }; |
241 | | |
242 | | #endif // INCLUDED_SW_INC_UNOTEXTRANGE_HXX |
243 | | |
244 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |