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 .
20 #ifndef INCLUDED_SC_INC_TEXTUNO_HXX
21 #define INCLUDED_SC_INC_TEXTUNO_HXX
23 #include "address.hxx"
24 #include <editeng/unotext.hxx>
25 #include <svl/lstner.hxx>
26 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
27 #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/lang/XUnoTunnel.hpp>
30 #include <comphelper/servicehelper.hxx>
31 #include <cppuhelper/implbase.hxx>
32 #include <cppuhelper/weakref.hxx>
34 #include <rtl/ref.hxx>
40 class SvxEditEngineForwarder
;
43 class ScSimpleEditSource
;
44 class ScCellEditSource
;
45 class ScEditEngineDefaulter
;
46 class ScFieldEditEngine
;
47 class ScHeaderFooterTextObj
;
49 struct ScHeaderFieldData
;
51 enum class ScHeaderFooterPart
{ LEFT
, CENTER
, RIGHT
};
53 // ScHeaderFooterContentObj is a dumb container which must be re-written into
54 // the page template using setPropertyValue
56 class ScHeaderFooterContentObj final
: public cppu::WeakImplHelper
<
57 css::sheet::XHeaderFooterContent
,
58 css::lang::XUnoTunnel
,
59 css::lang::XServiceInfo
>
62 rtl::Reference
<ScHeaderFooterTextObj
> mxLeftText
;
63 rtl::Reference
<ScHeaderFooterTextObj
> mxCenterText
;
64 rtl::Reference
<ScHeaderFooterTextObj
> mxRightText
;
67 ScHeaderFooterContentObj();
68 virtual ~ScHeaderFooterContentObj() override
;
70 // for ScPageHFItem (using getImplementation)
71 const EditTextObject
* GetLeftEditObject() const;
72 const EditTextObject
* GetCenterEditObject() const;
73 const EditTextObject
* GetRightEditObject() const;
75 void Init( const EditTextObject
* pLeft
,
76 const EditTextObject
* pCenter
,
77 const EditTextObject
* pRight
);
79 // XHeaderFooterContent
80 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
81 getLeftText() override
;
82 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
83 getCenterText() override
;
84 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
85 getRightText() override
;
88 virtual sal_Int64 SAL_CALL
getSomething( const css::uno::Sequence
<
89 sal_Int8
>& aIdentifier
) override
;
91 static const css::uno::Sequence
<sal_Int8
>& getUnoTunnelId();
92 static rtl::Reference
<ScHeaderFooterContentObj
> getImplementation(const css::uno::Reference
<css::sheet::XHeaderFooterContent
>& rObj
);
95 virtual OUString SAL_CALL
getImplementationName() override
;
96 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
97 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
101 // ScHeaderFooterTextData: shared data between sub objects of a ScHeaderFooterTextObj
103 class ScHeaderFooterTextData
106 std::unique_ptr
<EditTextObject
> mpTextObj
;
107 css::uno::WeakReference
<css::sheet::XHeaderFooterContent
> xContentObj
;
108 ScHeaderFooterPart nPart
;
109 std::unique_ptr
<ScEditEngineDefaulter
> pEditEngine
;
110 std::unique_ptr
<SvxEditEngineForwarder
> pForwarder
;
114 ScHeaderFooterTextData(const ScHeaderFooterTextData
&) = delete;
115 const ScHeaderFooterTextData
& operator=(const ScHeaderFooterTextData
&) = delete;
116 ScHeaderFooterTextData(
117 css::uno::WeakReference
<css::sheet::XHeaderFooterContent
> const & xContent
, ScHeaderFooterPart nP
, const EditTextObject
* pTextObj
);
118 ~ScHeaderFooterTextData();
121 SvxTextForwarder
* GetTextForwarder();
123 void UpdateData(EditEngine
& rEditEngine
);
124 ScEditEngineDefaulter
* GetEditEngine() { GetTextForwarder(); return pEditEngine
.get(); }
126 ScHeaderFooterPart
GetPart() const { return nPart
; }
127 css::uno::Reference
<css::sheet::XHeaderFooterContent
> GetContentObj() const { return xContentObj
; }
129 const EditTextObject
* GetTextObject() const { return mpTextObj
.get(); }
133 * Each of these instances represent, the left, center or right part of the
134 * header of footer of a page.
136 * ScHeaderFooterTextObj changes the text in a ScHeaderFooterContentObj.
138 class ScHeaderFooterTextObj
: public cppu::WeakImplHelper
<
140 css::text::XTextRangeMover
,
141 css::container::XEnumerationAccess
,
142 css::text::XTextFieldsSupplier
,
143 css::lang::XServiceInfo
>
146 ScHeaderFooterTextData aTextData
;
147 rtl::Reference
<SvxUnoText
> mxUnoText
;
149 void CreateUnoText_Impl();
152 ScHeaderFooterTextObj(
153 const css::uno::WeakReference
<css::sheet::XHeaderFooterContent
>& xContent
, ScHeaderFooterPart nP
, const EditTextObject
* pTextObj
);
154 virtual ~ScHeaderFooterTextObj() override
;
156 const EditTextObject
* GetTextObject() const;
157 const SvxUnoText
& GetUnoText();
159 static void FillDummyFieldData( ScHeaderFieldData
& rData
);
162 virtual void SAL_CALL
insertTextContent( const css::uno::Reference
< css::text::XTextRange
>& xRange
,
163 const css::uno::Reference
< css::text::XTextContent
>& xContent
,
164 sal_Bool bAbsorb
) override
;
165 virtual void SAL_CALL
removeTextContent( const css::uno::Reference
< css::text::XTextContent
>& xContent
) override
;
168 virtual css::uno::Reference
< css::text::XTextCursor
> SAL_CALL
169 createTextCursor() override
;
170 virtual css::uno::Reference
< css::text::XTextCursor
> SAL_CALL
171 createTextCursorByRange( const css::uno::Reference
< css::text::XTextRange
>& aTextPosition
) override
;
172 virtual void SAL_CALL
insertString( const css::uno::Reference
< css::text::XTextRange
>& xRange
,
173 const OUString
& aString
, sal_Bool bAbsorb
) override
;
174 virtual void SAL_CALL
insertControlCharacter( const css::uno::Reference
< css::text::XTextRange
>& xRange
,
175 sal_Int16 nControlCharacter
, sal_Bool bAbsorb
) override
;
178 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
180 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
182 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
184 virtual OUString SAL_CALL
getString() override
;
185 virtual void SAL_CALL
setString( const OUString
& aString
) override
;
188 virtual void SAL_CALL
moveTextRange( const css::uno::Reference
< css::text::XTextRange
>& xRange
,
189 sal_Int16 nParagraphs
) override
;
191 // XEnumerationAccess
192 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
193 createEnumeration() override
;
196 virtual css::uno::Type SAL_CALL
getElementType() override
;
197 virtual sal_Bool SAL_CALL
hasElements() override
;
199 // XTextFieldsSupplier
200 virtual css::uno::Reference
< css::container::XEnumerationAccess
> SAL_CALL
201 getTextFields() override
;
202 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
203 getTextFieldMasters() override
;
206 virtual OUString SAL_CALL
getImplementationName() override
;
207 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
208 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
212 // derived cursor objects for getImplementation and getText/getStart/getEnd
214 //! uno3: SvxUnoTextCursor is not derived from XUnoTunnel, but should be (?)
216 class ScCellTextCursor final
: public SvxUnoTextCursor
218 rtl::Reference
<ScCellObj
> mxTextObj
;
221 ScCellTextCursor(ScCellObj
& rText
);
222 virtual ~ScCellTextCursor() throw() override
;
224 ScCellTextCursor(ScCellTextCursor
const &) = default;
225 ScCellTextCursor(ScCellTextCursor
&&) = default;
226 ScCellTextCursor
& operator =(ScCellTextCursor
const &) = delete; // due to SvxUnoTextCursor
227 ScCellTextCursor
& operator =(ScCellTextCursor
&&) = delete; // due to SvxUnoTextCursor
229 ScCellObj
& GetCellObj() const { return *mxTextObj
; }
231 // SvxUnoTextCursor methods reimplemented here:
232 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
234 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
236 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
240 UNO3_GETIMPLEMENTATION_DECL(ScCellTextCursor
)
243 class ScHeaderFooterTextCursor final
: public SvxUnoTextCursor
246 rtl::Reference
<ScHeaderFooterTextObj
> rTextObj
;
249 ScHeaderFooterTextCursor(rtl::Reference
<ScHeaderFooterTextObj
> const & rText
);
250 virtual ~ScHeaderFooterTextCursor() throw() override
;
252 ScHeaderFooterTextCursor(ScHeaderFooterTextCursor
const &) = default;
253 ScHeaderFooterTextCursor(ScHeaderFooterTextCursor
&&) = default;
254 ScHeaderFooterTextCursor
& operator =(ScHeaderFooterTextCursor
const &) = delete; // due to SvxUnoTextCursor
255 ScHeaderFooterTextCursor
& operator =(ScHeaderFooterTextCursor
&&) = delete; // due to SvxUnoTextCursor
257 // SvxUnoTextCursor methods reimplemented here:
258 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
260 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
262 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
266 UNO3_GETIMPLEMENTATION_DECL(ScHeaderFooterTextCursor
)
269 class ScDrawTextCursor final
: public SvxUnoTextCursor
272 css::uno::Reference
< css::text::XText
> xParentText
;
275 ScDrawTextCursor( const css::uno::Reference
< css::text::XText
>& xParent
,
276 const SvxUnoTextBase
& rText
);
277 virtual ~ScDrawTextCursor() throw() override
;
279 ScDrawTextCursor(ScDrawTextCursor
const &) = default;
280 ScDrawTextCursor(ScDrawTextCursor
&&) = default;
281 ScDrawTextCursor
& operator =(ScDrawTextCursor
const &) = delete; // due to SvxUnoTextCursor
282 ScDrawTextCursor
& operator =(ScDrawTextCursor
&&) = delete; // due to SvxUnoTextCursor
284 // SvxUnoTextCursor methods reimplemented here:
285 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
287 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
289 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
293 UNO3_GETIMPLEMENTATION_DECL(ScDrawTextCursor
)
296 // ScAnnotationTextCursor isn't needed anymore - SvxUnoTextCursor is used instead
298 // ScEditEngineTextObj for formatted cell content that is not inserted in a cell or header/footer
299 // (used for XML export of change tracking contents)
301 class ScSimpleEditSourceHelper
303 std::unique_ptr
<ScEditEngineDefaulter
> pEditEngine
;
304 std::unique_ptr
<SvxEditEngineForwarder
> pForwarder
;
305 std::unique_ptr
<ScSimpleEditSource
> pOriginalSource
;
308 ScSimpleEditSourceHelper();
309 ~ScSimpleEditSourceHelper();
311 ScSimpleEditSource
* GetOriginalSource() const { return pOriginalSource
.get(); }
312 ScEditEngineDefaulter
* GetEditEngine() const { return pEditEngine
.get(); }
315 class ScEditEngineTextObj final
: public ScSimpleEditSourceHelper
, public SvxUnoText
318 ScEditEngineTextObj();
319 virtual ~ScEditEngineTextObj() throw() override
;
321 void SetText( const EditTextObject
& rTextObject
);
322 std::unique_ptr
<EditTextObject
> CreateTextObject();
325 // ScCellTextData: shared data between sub objects of a cell text object
327 class ScCellTextData
: public SfxListener
330 ScDocShell
* pDocShell
;
332 std::unique_ptr
<ScFieldEditEngine
> pEditEngine
;
333 std::unique_ptr
<SvxEditEngineForwarder
> pForwarder
;
334 std::unique_ptr
<ScCellEditSource
> pOriginalSource
;
341 ScCellTextData(ScDocShell
* pDocSh
, const ScAddress
& rP
);
342 virtual ~ScCellTextData() override
;
344 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
346 // helper functions for ScSharedCellEditSource:
347 virtual SvxTextForwarder
* GetTextForwarder();
349 ScFieldEditEngine
* GetEditEngine() { GetTextForwarder(); return pEditEngine
.get(); }
351 ScCellEditSource
* GetOriginalSource(); // used as argument for SvxUnoText ctor
353 // used for ScCellEditSource:
354 ScDocShell
* GetDocShell() const { return pDocShell
; }
355 const ScAddress
& GetCellPos() const { return aCellPos
; }
357 bool IsDirty() const { return bDirty
; }
358 void SetDoUpdate(bool bValue
) { bDoUpdate
= bValue
; }
361 class ScCellTextObj final
: public ScCellTextData
, public SvxUnoText
364 ScCellTextObj(ScDocShell
* pDocSh
, const ScAddress
& rP
);
365 virtual ~ScCellTextObj() COVERITY_NOEXCEPT_FALSE override
;
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */