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