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>
32 #include <rtl/ref.hxx>
38 class SvxEditEngineForwarder
;
41 class ScSimpleEditSource
;
42 class ScCellEditSource
;
43 class ScEditEngineDefaulter
;
44 class ScFieldEditEngine
;
45 class ScHeaderFooterTextObj
;
47 struct ScHeaderFieldData
;
49 enum class ScHeaderFooterPart
{ LEFT
, CENTER
, RIGHT
};
51 // ScHeaderFooterContentObj is a dumb container which must be re-written into
52 // the page template using setPropertyValue
54 class ScHeaderFooterContentObj final
: public cppu::WeakImplHelper
<
55 css::sheet::XHeaderFooterContent
,
56 css::lang::XServiceInfo
>
59 rtl::Reference
<ScHeaderFooterTextObj
> mxLeftText
;
60 rtl::Reference
<ScHeaderFooterTextObj
> mxCenterText
;
61 rtl::Reference
<ScHeaderFooterTextObj
> mxRightText
;
64 ScHeaderFooterContentObj();
65 virtual ~ScHeaderFooterContentObj() override
;
67 // for ScPageHFItem (using getImplementation)
68 const EditTextObject
* GetLeftEditObject() const;
69 const EditTextObject
* GetCenterEditObject() const;
70 const EditTextObject
* GetRightEditObject() const;
72 void Init( const EditTextObject
* pLeft
,
73 const EditTextObject
* pCenter
,
74 const EditTextObject
* pRight
);
76 // XHeaderFooterContent
77 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
78 getLeftText() override
;
79 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
80 getCenterText() override
;
81 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
82 getRightText() override
;
84 static rtl::Reference
<ScHeaderFooterContentObj
> getImplementation(const css::uno::Reference
<css::sheet::XHeaderFooterContent
>& rObj
);
87 virtual OUString SAL_CALL
getImplementationName() override
;
88 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
89 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
93 // ScHeaderFooterTextData: shared data between sub objects of a ScHeaderFooterTextObj
95 class ScHeaderFooterTextData
98 std::unique_ptr
<EditTextObject
> mpTextObj
;
99 css::uno::WeakReference
<css::sheet::XHeaderFooterContent
> xContentObj
;
100 ScHeaderFooterPart nPart
;
101 std::unique_ptr
<ScEditEngineDefaulter
> pEditEngine
;
102 std::unique_ptr
<SvxEditEngineForwarder
> pForwarder
;
106 ScHeaderFooterTextData(const ScHeaderFooterTextData
&) = delete;
107 const ScHeaderFooterTextData
& operator=(const ScHeaderFooterTextData
&) = delete;
108 ScHeaderFooterTextData(
109 css::uno::WeakReference
<css::sheet::XHeaderFooterContent
> xContent
, ScHeaderFooterPart nP
, const EditTextObject
* pTextObj
);
110 ~ScHeaderFooterTextData();
113 SvxTextForwarder
* GetTextForwarder();
115 void UpdateData(EditEngine
& rEditEngine
);
116 ScEditEngineDefaulter
* GetEditEngine() { GetTextForwarder(); return pEditEngine
.get(); }
118 ScHeaderFooterPart
GetPart() const { return nPart
; }
119 css::uno::Reference
<css::sheet::XHeaderFooterContent
> GetContentObj() const { return xContentObj
; }
121 const EditTextObject
* GetTextObject() const { return mpTextObj
.get(); }
125 * Each of these instances represent, the left, center or right part of the
126 * header of footer of a page.
128 * ScHeaderFooterTextObj changes the text in a ScHeaderFooterContentObj.
130 class ScHeaderFooterTextObj final
: public cppu::WeakImplHelper
<
132 css::text::XTextRangeMover
,
133 css::container::XEnumerationAccess
,
134 css::text::XTextFieldsSupplier
,
135 css::lang::XServiceInfo
>
138 ScHeaderFooterTextData aTextData
;
139 rtl::Reference
<SvxUnoText
> mxUnoText
;
141 void CreateUnoText_Impl();
144 ScHeaderFooterTextObj(
145 const css::uno::WeakReference
<css::sheet::XHeaderFooterContent
>& xContent
, ScHeaderFooterPart nP
, const EditTextObject
* pTextObj
);
146 virtual ~ScHeaderFooterTextObj() override
;
148 const EditTextObject
* GetTextObject() const;
149 const SvxUnoText
& GetUnoText();
151 static void FillDummyFieldData( ScHeaderFieldData
& rData
);
154 virtual void SAL_CALL
insertTextContent( const css::uno::Reference
< css::text::XTextRange
>& xRange
,
155 const css::uno::Reference
< css::text::XTextContent
>& xContent
,
156 sal_Bool bAbsorb
) override
;
157 virtual void SAL_CALL
removeTextContent( const css::uno::Reference
< css::text::XTextContent
>& xContent
) override
;
160 virtual css::uno::Reference
< css::text::XTextCursor
> SAL_CALL
161 createTextCursor() override
;
162 virtual css::uno::Reference
< css::text::XTextCursor
> SAL_CALL
163 createTextCursorByRange( const css::uno::Reference
< css::text::XTextRange
>& aTextPosition
) override
;
164 virtual void SAL_CALL
insertString( const css::uno::Reference
< css::text::XTextRange
>& xRange
,
165 const OUString
& aString
, sal_Bool bAbsorb
) override
;
166 virtual void SAL_CALL
insertControlCharacter( const css::uno::Reference
< css::text::XTextRange
>& xRange
,
167 sal_Int16 nControlCharacter
, sal_Bool bAbsorb
) override
;
170 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
172 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
174 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
176 virtual OUString SAL_CALL
getString() override
;
177 virtual void SAL_CALL
setString( const OUString
& aString
) override
;
180 virtual void SAL_CALL
moveTextRange( const css::uno::Reference
< css::text::XTextRange
>& xRange
,
181 sal_Int16 nParagraphs
) override
;
183 // XEnumerationAccess
184 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
185 createEnumeration() override
;
188 virtual css::uno::Type SAL_CALL
getElementType() override
;
189 virtual sal_Bool SAL_CALL
hasElements() override
;
191 // XTextFieldsSupplier
192 virtual css::uno::Reference
< css::container::XEnumerationAccess
> SAL_CALL
193 getTextFields() override
;
194 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
195 getTextFieldMasters() override
;
198 virtual OUString SAL_CALL
getImplementationName() override
;
199 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
200 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
204 // derived cursor objects for getImplementation and getText/getStart/getEnd
206 //! uno3: SvxUnoTextCursor is not derived from XUnoTunnel, but should be (?)
208 class ScCellTextCursor final
: public SvxUnoTextCursor
210 rtl::Reference
<ScCellObj
> mxTextObj
;
213 ScCellTextCursor(ScCellObj
& rText
);
214 virtual ~ScCellTextCursor() noexcept override
;
216 ScCellTextCursor(ScCellTextCursor
const &) = default;
217 ScCellTextCursor(ScCellTextCursor
&&) = default;
218 ScCellTextCursor
& operator =(ScCellTextCursor
const &) = delete; // due to SvxUnoTextCursor
219 ScCellTextCursor
& operator =(ScCellTextCursor
&&) = delete; // due to SvxUnoTextCursor
221 ScCellObj
& GetCellObj() const { return *mxTextObj
; }
223 // SvxUnoTextCursor methods reimplemented here:
224 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
226 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
228 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
232 UNO3_GETIMPLEMENTATION_DECL(ScCellTextCursor
)
235 class ScHeaderFooterTextCursor final
: public SvxUnoTextCursor
238 rtl::Reference
<ScHeaderFooterTextObj
> rTextObj
;
241 ScHeaderFooterTextCursor(rtl::Reference
<ScHeaderFooterTextObj
> const & rText
);
242 virtual ~ScHeaderFooterTextCursor() noexcept override
;
244 ScHeaderFooterTextCursor(ScHeaderFooterTextCursor
const &) = default;
245 ScHeaderFooterTextCursor(ScHeaderFooterTextCursor
&&) = default;
246 ScHeaderFooterTextCursor
& operator =(ScHeaderFooterTextCursor
const &) = delete; // due to SvxUnoTextCursor
247 ScHeaderFooterTextCursor
& operator =(ScHeaderFooterTextCursor
&&) = delete; // due to SvxUnoTextCursor
249 // SvxUnoTextCursor methods reimplemented here:
250 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
252 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
254 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
258 UNO3_GETIMPLEMENTATION_DECL(ScHeaderFooterTextCursor
)
261 class ScDrawTextCursor final
: public SvxUnoTextCursor
264 css::uno::Reference
< css::text::XText
> xParentText
;
267 ScDrawTextCursor( css::uno::Reference
< css::text::XText
> xParent
,
268 const SvxUnoTextBase
& rText
);
269 virtual ~ScDrawTextCursor() noexcept override
;
271 ScDrawTextCursor(ScDrawTextCursor
const &) = default;
272 ScDrawTextCursor(ScDrawTextCursor
&&) = default;
273 ScDrawTextCursor
& operator =(ScDrawTextCursor
const &) = delete; // due to SvxUnoTextCursor
274 ScDrawTextCursor
& operator =(ScDrawTextCursor
&&) = delete; // due to SvxUnoTextCursor
276 // SvxUnoTextCursor methods reimplemented here:
277 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
279 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
281 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
285 UNO3_GETIMPLEMENTATION_DECL(ScDrawTextCursor
)
288 // ScAnnotationTextCursor isn't needed anymore - SvxUnoTextCursor is used instead
290 // ScEditEngineTextObj for formatted cell content that is not inserted in a cell or header/footer
291 // (used for XML export of change tracking contents)
293 class ScSimpleEditSourceHelper
295 std::unique_ptr
<ScEditEngineDefaulter
> pEditEngine
;
296 std::unique_ptr
<SvxEditEngineForwarder
> pForwarder
;
297 std::unique_ptr
<ScSimpleEditSource
> pOriginalSource
;
300 ScSimpleEditSourceHelper();
301 ~ScSimpleEditSourceHelper();
303 ScSimpleEditSource
* GetOriginalSource() const { return pOriginalSource
.get(); }
304 ScEditEngineDefaulter
* GetEditEngine() const { return pEditEngine
.get(); }
307 class ScEditEngineTextObj final
: public ScSimpleEditSourceHelper
, public SvxUnoText
310 ScEditEngineTextObj();
311 virtual ~ScEditEngineTextObj() noexcept override
;
313 void SetText( const EditTextObject
& rTextObject
);
314 std::unique_ptr
<EditTextObject
> CreateTextObject();
317 // ScCellTextData: shared data between sub objects of a cell text object
319 class ScCellTextData
: public SfxListener
322 ScDocShell
* pDocShell
;
324 std::unique_ptr
<ScFieldEditEngine
> pEditEngine
;
325 std::unique_ptr
<SvxEditEngineForwarder
> pForwarder
;
326 std::unique_ptr
<ScCellEditSource
> pOriginalSource
;
333 ScCellTextData(ScDocShell
* pDocSh
, const ScAddress
& rP
);
334 virtual ~ScCellTextData() override
;
336 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
338 // helper functions for ScSharedCellEditSource:
339 virtual SvxTextForwarder
* GetTextForwarder();
341 ScFieldEditEngine
* GetEditEngine() { GetTextForwarder(); return pEditEngine
.get(); }
343 ScCellEditSource
* GetOriginalSource(); // used as argument for SvxUnoText ctor
345 // used for ScCellEditSource:
346 ScDocShell
* GetDocShell() const { return pDocShell
; }
347 const ScAddress
& GetCellPos() const { return aCellPos
; }
349 bool IsDirty() const { return bDirty
; }
350 void SetDoUpdate(bool bValue
) { bDoUpdate
= bValue
; }
353 class ScCellTextObj final
: public ScCellTextData
, public SvxUnoText
356 ScCellTextObj(ScDocShell
* pDocSh
, const ScAddress
& rP
);
357 virtual ~ScCellTextObj() COVERITY_NOEXCEPT_FALSE override
;
360 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */