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 .
22 #include "address.hxx"
23 #include <editeng/unotext.hxx>
24 #include <svl/lstner.hxx>
25 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
26 #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <comphelper/servicehelper.hxx>
29 #include <cppuhelper/implbase.hxx>
30 #include <cppuhelper/weakref.hxx>
31 #include <unotools/weakref.hxx>
33 #include <rtl/ref.hxx>
39 class SvxEditEngineForwarder
;
42 class ScSimpleEditSource
;
43 class ScCellEditSource
;
44 class ScEditEngineDefaulter
;
45 class ScFieldEditEngine
;
46 class ScHeaderFooterTextObj
;
48 struct ScHeaderFieldData
;
50 enum class ScHeaderFooterPart
{ LEFT
, CENTER
, RIGHT
};
52 // ScHeaderFooterContentObj is a dumb container which must be re-written into
53 // the page template using setPropertyValue
55 class ScHeaderFooterContentObj final
: public cppu::WeakImplHelper
<
56 css::sheet::XHeaderFooterContent
,
57 css::lang::XServiceInfo
>
60 rtl::Reference
<ScHeaderFooterTextObj
> mxLeftText
;
61 rtl::Reference
<ScHeaderFooterTextObj
> mxCenterText
;
62 rtl::Reference
<ScHeaderFooterTextObj
> mxRightText
;
65 ScHeaderFooterContentObj();
66 virtual ~ScHeaderFooterContentObj() override
;
68 // for ScPageHFItem (using getImplementation)
69 const EditTextObject
* GetLeftEditObject() const;
70 const EditTextObject
* GetCenterEditObject() const;
71 const EditTextObject
* GetRightEditObject() const;
73 void Init( const EditTextObject
* pLeft
,
74 const EditTextObject
* pCenter
,
75 const EditTextObject
* pRight
);
77 // XHeaderFooterContent
78 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
79 getLeftText() override
;
80 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
81 getCenterText() override
;
82 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
83 getRightText() override
;
85 static rtl::Reference
<ScHeaderFooterContentObj
> getImplementation(const css::uno::Reference
<css::sheet::XHeaderFooterContent
>& rObj
);
88 virtual OUString SAL_CALL
getImplementationName() override
;
89 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
90 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
94 // ScHeaderFooterTextData: shared data between sub objects of a ScHeaderFooterTextObj
96 class ScHeaderFooterTextData
99 std::unique_ptr
<EditTextObject
> mpTextObj
;
100 unotools::WeakReference
<ScHeaderFooterContentObj
> xContentObj
;
101 ScHeaderFooterPart nPart
;
102 std::unique_ptr
<ScEditEngineDefaulter
> pEditEngine
;
103 std::unique_ptr
<SvxEditEngineForwarder
> pForwarder
;
107 ScHeaderFooterTextData(const ScHeaderFooterTextData
&) = delete;
108 const ScHeaderFooterTextData
& operator=(const ScHeaderFooterTextData
&) = delete;
109 ScHeaderFooterTextData(
110 unotools::WeakReference
<ScHeaderFooterContentObj
> xContent
, ScHeaderFooterPart nP
, const EditTextObject
* pTextObj
);
111 ~ScHeaderFooterTextData();
114 SvxTextForwarder
* GetTextForwarder();
116 void UpdateData(EditEngine
& rEditEngine
);
117 ScEditEngineDefaulter
* GetEditEngine() { GetTextForwarder(); return pEditEngine
.get(); }
119 ScHeaderFooterPart
GetPart() const { return nPart
; }
120 rtl::Reference
<ScHeaderFooterContentObj
> GetContentObj() const { return xContentObj
; }
122 const EditTextObject
* GetTextObject() const { return mpTextObj
.get(); }
126 * Each of these instances represent, the left, center or right part of the
127 * header of footer of a page.
129 * ScHeaderFooterTextObj changes the text in a ScHeaderFooterContentObj.
131 class ScHeaderFooterTextObj final
: public cppu::WeakImplHelper
<
133 css::text::XTextRangeMover
,
134 css::container::XEnumerationAccess
,
135 css::text::XTextFieldsSupplier
,
136 css::lang::XServiceInfo
>
139 ScHeaderFooterTextData aTextData
;
140 rtl::Reference
<SvxUnoText
> mxUnoText
;
142 void CreateUnoText_Impl();
145 ScHeaderFooterTextObj(
146 const unotools::WeakReference
<ScHeaderFooterContentObj
>& xContent
, ScHeaderFooterPart nP
, const EditTextObject
* pTextObj
);
147 virtual ~ScHeaderFooterTextObj() override
;
149 const EditTextObject
* GetTextObject() const;
150 const SvxUnoText
& GetUnoText();
152 static void FillDummyFieldData( ScHeaderFieldData
& rData
);
155 virtual void SAL_CALL
insertTextContent( const css::uno::Reference
< css::text::XTextRange
>& xRange
,
156 const css::uno::Reference
< css::text::XTextContent
>& xContent
,
157 sal_Bool bAbsorb
) override
;
158 virtual void SAL_CALL
removeTextContent( const css::uno::Reference
< css::text::XTextContent
>& xContent
) override
;
161 virtual css::uno::Reference
< css::text::XTextCursor
> SAL_CALL
162 createTextCursor() override
;
163 virtual css::uno::Reference
< css::text::XTextCursor
> SAL_CALL
164 createTextCursorByRange( const css::uno::Reference
< css::text::XTextRange
>& aTextPosition
) override
;
165 virtual void SAL_CALL
insertString( const css::uno::Reference
< css::text::XTextRange
>& xRange
,
166 const OUString
& aString
, sal_Bool bAbsorb
) override
;
167 virtual void SAL_CALL
insertControlCharacter( const css::uno::Reference
< css::text::XTextRange
>& xRange
,
168 sal_Int16 nControlCharacter
, sal_Bool bAbsorb
) override
;
171 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
173 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
175 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
177 virtual OUString SAL_CALL
getString() override
;
178 virtual void SAL_CALL
setString( const OUString
& aString
) override
;
181 virtual void SAL_CALL
moveTextRange( const css::uno::Reference
< css::text::XTextRange
>& xRange
,
182 sal_Int16 nParagraphs
) override
;
184 // XEnumerationAccess
185 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
186 createEnumeration() override
;
189 virtual css::uno::Type SAL_CALL
getElementType() override
;
190 virtual sal_Bool SAL_CALL
hasElements() override
;
192 // XTextFieldsSupplier
193 virtual css::uno::Reference
< css::container::XEnumerationAccess
> SAL_CALL
194 getTextFields() override
;
195 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
196 getTextFieldMasters() override
;
199 virtual OUString SAL_CALL
getImplementationName() override
;
200 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
201 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
205 // derived cursor objects for getImplementation and getText/getStart/getEnd
207 //! uno3: SvxUnoTextCursor is not derived from XUnoTunnel, but should be (?)
209 class ScCellTextCursor final
: public SvxUnoTextCursor
211 rtl::Reference
<ScCellObj
> mxTextObj
;
214 ScCellTextCursor(ScCellObj
& rText
);
215 virtual ~ScCellTextCursor() noexcept override
;
217 ScCellTextCursor(ScCellTextCursor
const &) = default;
218 ScCellTextCursor(ScCellTextCursor
&&) = default;
219 ScCellTextCursor
& operator =(ScCellTextCursor
const &) = delete; // due to SvxUnoTextCursor
220 ScCellTextCursor
& operator =(ScCellTextCursor
&&) = delete; // due to SvxUnoTextCursor
222 ScCellObj
& GetCellObj() const { return *mxTextObj
; }
224 // SvxUnoTextCursor methods reimplemented here:
225 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
227 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
229 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
233 UNO3_GETIMPLEMENTATION_DECL(ScCellTextCursor
)
236 class ScHeaderFooterTextCursor final
: public SvxUnoTextCursor
239 rtl::Reference
<ScHeaderFooterTextObj
> rTextObj
;
242 ScHeaderFooterTextCursor(rtl::Reference
<ScHeaderFooterTextObj
> const & rText
);
243 virtual ~ScHeaderFooterTextCursor() noexcept override
;
245 ScHeaderFooterTextCursor(ScHeaderFooterTextCursor
const &) = default;
246 ScHeaderFooterTextCursor(ScHeaderFooterTextCursor
&&) = default;
247 ScHeaderFooterTextCursor
& operator =(ScHeaderFooterTextCursor
const &) = delete; // due to SvxUnoTextCursor
248 ScHeaderFooterTextCursor
& operator =(ScHeaderFooterTextCursor
&&) = delete; // due to SvxUnoTextCursor
250 // SvxUnoTextCursor methods reimplemented here:
251 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
253 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
255 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
259 UNO3_GETIMPLEMENTATION_DECL(ScHeaderFooterTextCursor
)
262 class ScDrawTextCursor final
: public SvxUnoTextCursor
265 css::uno::Reference
< css::text::XText
> xParentText
;
268 ScDrawTextCursor( css::uno::Reference
< css::text::XText
> xParent
,
269 const SvxUnoTextBase
& rText
);
270 virtual ~ScDrawTextCursor() noexcept override
;
272 ScDrawTextCursor(ScDrawTextCursor
const &) = default;
273 ScDrawTextCursor(ScDrawTextCursor
&&) = default;
274 ScDrawTextCursor
& operator =(ScDrawTextCursor
const &) = delete; // due to SvxUnoTextCursor
275 ScDrawTextCursor
& operator =(ScDrawTextCursor
&&) = delete; // due to SvxUnoTextCursor
277 // SvxUnoTextCursor methods reimplemented here:
278 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
280 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
282 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
286 UNO3_GETIMPLEMENTATION_DECL(ScDrawTextCursor
)
289 // ScAnnotationTextCursor isn't needed anymore - SvxUnoTextCursor is used instead
291 // ScEditEngineTextObj for formatted cell content that is not inserted in a cell or header/footer
292 // (used for XML export of change tracking contents)
294 class ScSimpleEditSourceHelper
296 std::unique_ptr
<ScEditEngineDefaulter
> pEditEngine
;
297 std::unique_ptr
<SvxEditEngineForwarder
> pForwarder
;
298 std::unique_ptr
<ScSimpleEditSource
> pOriginalSource
;
301 ScSimpleEditSourceHelper();
302 ~ScSimpleEditSourceHelper();
304 ScSimpleEditSource
* GetOriginalSource() const { return pOriginalSource
.get(); }
305 ScEditEngineDefaulter
* GetEditEngine() const { return pEditEngine
.get(); }
308 class ScEditEngineTextObj final
: public ScSimpleEditSourceHelper
, public SvxUnoText
311 ScEditEngineTextObj();
312 virtual ~ScEditEngineTextObj() noexcept override
;
314 void SetText( const EditTextObject
& rTextObject
);
315 std::unique_ptr
<EditTextObject
> CreateTextObject();
318 // ScCellTextData: shared data between sub objects of a cell text object
320 class ScCellTextData
: public SfxListener
323 ScDocShell
* pDocShell
;
325 std::unique_ptr
<ScFieldEditEngine
> pEditEngine
;
326 std::unique_ptr
<SvxEditEngineForwarder
> pForwarder
;
327 std::unique_ptr
<ScCellEditSource
> pOriginalSource
;
334 ScCellTextData(ScDocShell
* pDocSh
, const ScAddress
& rP
);
335 virtual ~ScCellTextData() override
;
337 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
339 // helper functions for ScSharedCellEditSource:
340 virtual SvxTextForwarder
* GetTextForwarder();
342 ScFieldEditEngine
* GetEditEngine() { GetTextForwarder(); return pEditEngine
.get(); }
344 ScCellEditSource
* GetOriginalSource(); // used as argument for SvxUnoText ctor
346 // used for ScCellEditSource:
347 ScDocShell
* GetDocShell() const { return pDocShell
; }
348 const ScAddress
& GetCellPos() const { return aCellPos
; }
350 bool IsDirty() const { return bDirty
; }
351 void SetDoUpdate(bool bValue
) { bDoUpdate
= bValue
; }
354 class ScCellTextObj final
: public ScCellTextData
, public SvxUnoText
357 ScCellTextObj(ScDocShell
* pDocSh
, const ScAddress
& rP
);
358 virtual ~ScCellTextObj() COVERITY_NOEXCEPT_FALSE override
;
361 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */