Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / inc / unoport.hxx
blob1315334d39923a1010437f90f9b5b6516b86882d
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 .
19 #ifndef INCLUDED_SW_SOURCE_CORE_INC_UNOPORT_HXX
20 #define INCLUDED_SW_SOURCE_CORE_INC_UNOPORT_HXX
22 #include <memory>
23 #include <deque>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/text/XTextRange.hpp>
27 #include <com/sun/star/container/XEnumeration.hpp>
28 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
29 #include <com/sun/star/beans/XPropertyState.hpp>
30 #include <com/sun/star/beans/XMultiPropertySet.hpp>
31 #include <com/sun/star/beans/XTolerantMultiPropertySet.hpp>
32 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <cppuhelper/implbase.hxx>
36 #include <svl/itemprop.hxx>
37 #include <svl/listener.hxx>
39 #include <unocrsr.hxx>
41 namespace com::sun::star::beans { struct PropertyValue; }
42 namespace com::sun::star::text { class XTextField; }
43 namespace com::sun::star::text { class XFootnote; }
45 class SwFrameFormat;
46 class SwRangeRedline;
47 class SwTextRuby;
49 typedef std::deque<
50 css::uno::Reference< css::text::XTextRange > >
51 TextRangeList_t;
53 enum SwTextPortionType
55 PORTION_TEXT,
56 PORTION_FIELD,
57 PORTION_FRAME,
58 PORTION_FOOTNOTE,
59 PORTION_REFMARK_START,
60 PORTION_REFMARK_END,
61 PORTION_TOXMARK_START,
62 PORTION_TOXMARK_END,
63 PORTION_BOOKMARK_START,
64 PORTION_BOOKMARK_END,
65 PORTION_REDLINE_START,
66 PORTION_REDLINE_END,
67 PORTION_RUBY_START,
68 PORTION_RUBY_END,
69 PORTION_SOFT_PAGEBREAK,
70 PORTION_META,
71 PORTION_FIELD_START,
72 PORTION_FIELD_SEP,
73 PORTION_FIELD_END,
74 PORTION_FIELD_START_END,
75 PORTION_ANNOTATION,
76 PORTION_ANNOTATION_END,
77 PORTION_LINEBREAK,
78 PORTION_CONTENT_CONTROL,
79 PORTION_LIST_AUTOFMT
82 class SwXTextPortion : public cppu::WeakImplHelper
84 css::beans::XTolerantMultiPropertySet,
85 css::beans::XMultiPropertySet,
86 css::beans::XPropertySet,
87 css::text::XTextRange,
88 css::beans::XPropertyState,
89 css::container::XContentEnumerationAccess,
90 css::lang::XServiceInfo
92 public SvtListener
94 private:
96 const SfxItemPropertySet * m_pPropSet;
97 const css::uno::Reference< css::text::XText >
98 m_xParentText;
99 css::uno::Reference< css::text::XTextContent >
100 m_xRefMark;
101 css::uno::Reference< css::text::XTextContent >
102 m_xTOXMark;
103 css::uno::Reference< css::text::XTextContent >
104 m_xBookmark;
105 css::uno::Reference< css::text::XFootnote >
106 m_xFootnote;
107 css::uno::Reference< css::text::XTextField >
108 m_xTextField;
109 css::uno::Reference< css::text::XTextContent >
110 m_xMeta;
111 css::uno::Reference<css::text::XTextContent> m_xLineBreak;
112 css::uno::Reference<css::text::XTextContent> m_xContentControl;
113 std::optional< css::uno::Any > m_oRubyText;
114 std::optional< css::uno::Any > m_oRubyStyle;
115 std::optional< css::uno::Any > m_oRubyAdjust;
116 std::optional< css::uno::Any > m_oRubyIsAbove;
117 std::optional< css::uno::Any > m_oRubyPosition;
118 sw::UnoCursorPointer m_pUnoCursor;
120 SwFrameFormat* m_pFrameFormat;
121 const SwTextPortionType m_ePortionType;
123 bool m_bIsCollapsed;
125 /// Expose the paragraph's RES_PARATR_LIST_AUTOFMT, not the char props of the underlying (empty)
126 /// text.
127 bool m_bIsListAutoFormat;
129 void init(const SwUnoCursor* pPortionCursor);
131 protected:
132 /// @throws css::beans::UnknownPropertyException
133 /// @throws css::beans::PropertyVetoException
134 /// @throws css::lang::IllegalArgumentException
135 /// @throws css::lang::WrappedTargetException
136 /// @throws css::uno::RuntimeException
137 void SetPropertyValues_Impl(
138 const css::uno::Sequence< OUString >& aPropertyNames,
139 const css::uno::Sequence< css::uno::Any >& aValues );
140 /// @throws css::beans::UnknownPropertyException
141 /// @throws css::lang::WrappedTargetException
142 /// @throws css::uno::RuntimeException
143 css::uno::Sequence< css::uno::Any > GetPropertyValues_Impl(
144 const css::uno::Sequence< OUString >& aPropertyNames );
146 void GetPropertyValue( css::uno::Any &rVal,
147 const SfxItemPropertyMapEntry& rEntry, SwUnoCursor *pUnoCursor, std::unique_ptr<SfxItemSet> &pSet );
149 /// @throws css::uno::RuntimeException
150 css::uno::Sequence<css::beans::GetDirectPropertyTolerantResult> GetPropertyValuesTolerant_Impl(
151 const css::uno::Sequence< OUString >& rPropertyNames, bool bDirectValuesOnly );
153 virtual ~SwXTextPortion() override;
155 virtual void Notify(const SfxHint& rHint) override;
157 public:
158 SwXTextPortion(const SwUnoCursor* pPortionCursor, css::uno::Reference< css::text::XText > xParent, SwTextPortionType eType );
159 SwXTextPortion(const SwUnoCursor* pPortionCursor, css::uno::Reference< css::text::XText > xParent, SwFrameFormat& rFormat );
161 // for Ruby
162 SwXTextPortion(const SwUnoCursor* pPortionCursor,
163 SwTextRuby const& rAttr,
164 css::uno::Reference< css::text::XText > xParent,
165 bool bIsEnd );
167 //XTextRange
168 virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override;
169 virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override;
170 virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override;
171 virtual OUString SAL_CALL getString() override;
172 virtual void SAL_CALL setString(const OUString& aString) override;
174 //XTolerantMultiPropertySet
175 virtual css::uno::Sequence< css::beans::SetPropertyTolerantFailed > SAL_CALL setPropertyValuesTolerant( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues ) override;
176 virtual css::uno::Sequence< css::beans::GetPropertyTolerantResult > SAL_CALL getPropertyValuesTolerant( const css::uno::Sequence< OUString >& aPropertyNames ) override;
177 virtual css::uno::Sequence< css::beans::GetDirectPropertyTolerantResult > SAL_CALL getDirectPropertyValuesTolerant( const css::uno::Sequence< OUString >& aPropertyNames ) override;
179 //XMultiPropertySet
180 virtual void SAL_CALL setPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues ) override;
181 virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames ) override;
182 virtual void SAL_CALL addPropertiesChangeListener( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener >& xListener ) override;
183 virtual void SAL_CALL removePropertiesChangeListener( const css::uno::Reference< css::beans::XPropertiesChangeListener >& xListener ) override;
184 virtual void SAL_CALL firePropertiesChangeEvent( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener >& xListener ) override;
186 //XPropertySet
187 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
188 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
189 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
190 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
191 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
192 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
193 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
195 //XPropertyState
196 virtual css::beans::PropertyState SAL_CALL getPropertyState( const OUString& PropertyName ) override;
197 virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL getPropertyStates( const css::uno::Sequence< OUString >& aPropertyName ) override;
198 virtual void SAL_CALL setPropertyToDefault( const OUString& PropertyName ) override;
199 virtual css::uno::Any SAL_CALL getPropertyDefault( const OUString& aPropertyName ) override;
201 //XServiceInfo
202 virtual OUString SAL_CALL getImplementationName() override;
203 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
204 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
206 //XContentEnumerationAccess
207 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createContentEnumeration(const OUString& aServiceName) override;
208 virtual css::uno::Sequence< OUString > SAL_CALL getAvailableServiceNames() override;
210 void SetRefMark( css::uno::Reference< css::text::XTextContent > const & xMark)
211 { m_xRefMark = xMark; }
213 void SetTOXMark( css::uno::Reference< css::text::XTextContent > const & xMark)
214 { m_xTOXMark = xMark; }
216 void SetBookmark( css::uno::Reference< css::text::XTextContent > const & xMark)
217 { m_xBookmark = xMark; }
219 void SetFootnote( css::uno::Reference< css::text::XFootnote > const & xNote)
220 { m_xFootnote = xNote; }
222 void SetTextField( css::uno::Reference< css::text::XTextField> const & xField)
223 { m_xTextField = xField; }
225 void SetMeta( css::uno::Reference< css::text::XTextContent > const & xMeta)
226 { m_xMeta = xMeta; }
228 void SetLineBreak(css::uno::Reference<css::text::XTextContent> const& xLineBreak)
230 m_xLineBreak = xLineBreak;
233 void SetContentControl(const css::uno::Reference<css::text::XTextContent>& xContentControl)
235 m_xContentControl = xContentControl;
238 void SetCollapsed(bool bSet) { m_bIsCollapsed = bSet;}
240 SwTextPortionType GetTextPortionType() const { return m_ePortionType; }
242 SwUnoCursor& GetCursor() const
243 { return *m_pUnoCursor; }
246 class SwXTextPortionEnumeration final
247 : public ::cppu::WeakImplHelper
248 < css::container::XEnumeration
249 , css::lang::XServiceInfo
252 TextRangeList_t m_Portions; // contains all portions, filled by ctor
253 sw::UnoCursorPointer m_pUnoCursor;
255 virtual ~SwXTextPortionEnumeration() override;
257 public:
258 /// @param bOnlyTextFields tries to return less data, but may return more than just text fields
259 SwXTextPortionEnumeration(SwPaM& rParaCursor,
260 css::uno::Reference< css::text::XText > const & xParent,
261 const sal_Int32 nStart, const sal_Int32 nEnd, bool bOnlyTextFields = false );
263 SwXTextPortionEnumeration(SwPaM& rParaCursor,
264 TextRangeList_t && rPortions );
266 //XEnumeration
267 virtual sal_Bool SAL_CALL hasMoreElements() override;
268 virtual css::uno::Any SAL_CALL nextElement() override;
270 //XServiceInfo
271 virtual OUString SAL_CALL getImplementationName() override;
272 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
273 virtual css::uno::Sequence< OUString > SAL_CALL
274 getSupportedServiceNames() override;
277 class SwXRedlinePortion final : public SwXTextPortion
279 private:
280 SwRangeRedline const& m_rRedline;
282 bool Validate();
284 using SwXTextPortion::GetPropertyValue;
286 virtual ~SwXRedlinePortion() override;
288 public:
289 SwXRedlinePortion(
290 SwRangeRedline const& rRedline,
291 SwUnoCursor const* pPortionCursor,
292 css::uno::Reference< css::text::XText > const& xParent,
293 bool const bIsStart);
295 /// @throws std::exception
296 static css::uno::Any GetPropertyValue(
297 std::u16string_view PropertyName, SwRangeRedline const& rRedline);
298 /// @throws std::exception
299 static css::uno::Sequence< css::beans::PropertyValue > CreateRedlineProperties(
300 SwRangeRedline const& rRedline, bool const bIsStart);
302 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
303 getImplementationId() override;
305 // XPropertySet
306 virtual css::uno::Any SAL_CALL getPropertyValue(
307 const OUString& rPropertyName) override;
310 #endif
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */