1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/container/XChild.hpp>
28 #include <com/sun/star/container/XEnumerationAccess.hpp>
29 #include <com/sun/star/text/XTextContent.hpp>
30 #include <com/sun/star/text/XTextField.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <cppuhelper/implbase.hxx>
35 #include <unobaseclass.hxx>
36 #include <unocoll.hxx>
38 typedef std::deque
<css::uno::Reference
<css::text::XTextRange
>> TextRangeList_t
;
42 class SwFormatContentControl
;
43 class SwContentControl
;
46 * UNO API wrapper around an SwContentControl, exposed as the com.sun.star.text.ContentControl
49 class SwXContentControl final
50 : public cppu::WeakImplHelper
<css::lang::XServiceInfo
, css::container::XEnumerationAccess
,
51 css::text::XTextContent
, css::text::XText
,
52 css::beans::XPropertySet
>
55 sw::UnoImplPtr
<Impl
> m_pImpl
;
58 void AttachImpl(const css::uno::Reference
<css::text::XTextRange
>& xTextRange
,
61 ~SwXContentControl() override
;
63 SwXContentControl(const SwXContentControl
&) = delete;
64 SwXContentControl
& operator=(const SwXContentControl
&) = delete;
66 SwXContentControl(SwDoc
* pDoc
, SwContentControl
* pContentControl
,
67 const css::uno::Reference
<css::text::XText
>& xParentText
,
68 std::unique_ptr
<const TextRangeList_t
> pPortions
);
70 SwXContentControl(SwDoc
* pDoc
);
73 static rtl::Reference
<SwXContentControl
>
74 CreateXContentControl(SwContentControl
& rContentControl
,
75 const css::uno::Reference
<css::text::XText
>& xParentText
= nullptr,
76 std::unique_ptr
<const TextRangeList_t
>&& pPortions
77 = std::unique_ptr
<const TextRangeList_t
>());
79 static rtl::Reference
<SwXContentControl
> CreateXContentControl(SwDoc
& rDoc
);
81 /// Initializes params with position of the attribute content (without CH_TXTATR).
82 bool SetContentRange(SwTextNode
*& rpNode
, sal_Int32
& rStart
, sal_Int32
& rEnd
) const;
83 const css::uno::Reference
<css::text::XText
>& GetParentText() const;
86 OUString SAL_CALL
getImplementationName() override
;
87 sal_Bool SAL_CALL
supportsService(const OUString
& rServiceName
) override
;
88 css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
91 void SAL_CALL
dispose() override
;
93 addEventListener(const css::uno::Reference
<css::lang::XEventListener
>& xListener
) override
;
95 removeEventListener(const css::uno::Reference
<css::lang::XEventListener
>& xListener
) override
;
98 css::uno::Type SAL_CALL
getElementType() override
;
99 sal_Bool SAL_CALL
hasElements() override
;
101 // XEnumerationAccess
102 css::uno::Reference
<css::container::XEnumeration
> SAL_CALL
createEnumeration() override
;
105 void SAL_CALL
attach(const css::uno::Reference
<css::text::XTextRange
>& xTextRange
) override
;
106 css::uno::Reference
<css::text::XTextRange
> SAL_CALL
getAnchor() override
;
109 css::uno::Reference
<css::text::XText
> SAL_CALL
getText() override
;
110 css::uno::Reference
<css::text::XTextRange
> SAL_CALL
getStart() override
;
111 css::uno::Reference
<css::text::XTextRange
> SAL_CALL
getEnd() override
;
112 OUString SAL_CALL
getString() override
;
113 void SAL_CALL
setString(const OUString
& rString
) override
;
116 css::uno::Reference
<css::text::XTextCursor
> SAL_CALL
createTextCursor() override
;
117 css::uno::Reference
<css::text::XTextCursor
> SAL_CALL
createTextCursorByRange(
118 const css::uno::Reference
<css::text::XTextRange
>& xTextPosition
) override
;
119 void SAL_CALL
insertString(const css::uno::Reference
<css::text::XTextRange
>& xRange
,
120 const OUString
& aString
, sal_Bool bAbsorb
) override
;
121 void SAL_CALL
insertControlCharacter(const css::uno::Reference
<css::text::XTextRange
>& xRange
,
122 sal_Int16 nControlCharacter
, sal_Bool bAbsorb
) override
;
125 void SAL_CALL
insertTextContent(const css::uno::Reference
<css::text::XTextRange
>& xRange
,
126 const css::uno::Reference
<css::text::XTextContent
>& xContent
,
127 sal_Bool bAbsorb
) override
;
129 removeTextContent(const css::uno::Reference
<css::text::XTextContent
>& xContent
) override
;
132 css::uno::Reference
<css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() override
;
133 void SAL_CALL
setPropertyValue(const OUString
& rPropertyName
,
134 const css::uno::Any
& rValue
) override
;
135 css::uno::Any SAL_CALL
getPropertyValue(const OUString
& rPropertyName
) override
;
136 void SAL_CALL
addPropertyChangeListener(
137 const OUString
& rPropertyName
,
138 const css::uno::Reference
<css::beans::XPropertyChangeListener
>& xListener
) override
;
139 void SAL_CALL
removePropertyChangeListener(
140 const OUString
& rPropertyName
,
141 const css::uno::Reference
<css::beans::XPropertyChangeListener
>& xListener
) override
;
142 void SAL_CALL
addVetoableChangeListener(
143 const OUString
& rPropertyName
,
144 const css::uno::Reference
<css::beans::XVetoableChangeListener
>& xListener
) override
;
145 void SAL_CALL
removeVetoableChangeListener(
146 const OUString
& rPropertyName
,
147 const css::uno::Reference
<css::beans::XVetoableChangeListener
>& xListener
) override
;
150 /// UNO wrapper around SwContentControlManager.
151 class SwXContentControls final
: public cppu::WeakImplHelper
<css::container::XIndexAccess
>,
152 public SwUnoCollection
154 ~SwXContentControls() override
;
157 SwXContentControls(SwDoc
* pDoc
);
160 sal_Int32 SAL_CALL
getCount() override
;
161 css::uno::Any SAL_CALL
getByIndex(sal_Int32 nIndex
) override
;
164 css::uno::Type SAL_CALL
getElementType() override
;
165 sal_Bool SAL_CALL
hasElements() override
;
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */