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
24 #include "address.hxx"
25 #include <editeng/unotext.hxx>
26 #include <svl/lstner.hxx>
27 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
28 #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/lang/XUnoTunnel.hpp>
31 #include <cppuhelper/implbase.hxx>
32 #include <cppuhelper/weakref.hxx>
34 #include <rtl/ref.hxx>
41 class SvxEditEngineForwarder
;
45 class ScSimpleEditSource
;
46 class ScCellEditSource
;
47 class ScEditEngineDefaulter
;
48 class ScFieldEditEngine
;
49 class ScHeaderFooterTextObj
;
51 struct ScHeaderFieldData
;
53 enum class ScHeaderFooterPart
{ LEFT
, CENTER
, RIGHT
};
55 // ScHeaderFooterContentObj is a dumb container which must be re-written into
56 // the page template using setPropertyValue
58 class ScHeaderFooterContentObj
: public cppu::WeakImplHelper
<
59 css::sheet::XHeaderFooterContent
,
60 css::lang::XUnoTunnel
,
61 css::lang::XServiceInfo
>
64 rtl::Reference
<ScHeaderFooterTextObj
> mxLeftText
;
65 rtl::Reference
<ScHeaderFooterTextObj
> mxCenterText
;
66 rtl::Reference
<ScHeaderFooterTextObj
> mxRightText
;
69 ScHeaderFooterContentObj();
70 virtual ~ScHeaderFooterContentObj();
72 // for ScPageHFItem (using getImplementation)
73 const EditTextObject
* GetLeftEditObject() const;
74 const EditTextObject
* GetCenterEditObject() const;
75 const EditTextObject
* GetRightEditObject() const;
77 void Init( const EditTextObject
* pLeft
,
78 const EditTextObject
* pCenter
,
79 const EditTextObject
* pRight
);
81 // XHeaderFooterContent
82 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
83 getLeftText() throw(css::uno::RuntimeException
, std::exception
) override
;
84 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
85 getCenterText() throw(css::uno::RuntimeException
, std::exception
) override
;
86 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
87 getRightText() throw(css::uno::RuntimeException
, std::exception
) override
;
90 virtual sal_Int64 SAL_CALL
getSomething( const css::uno::Sequence
<
91 sal_Int8
>& aIdentifier
)
92 throw(css::uno::RuntimeException
, std::exception
) override
;
94 static const css::uno::Sequence
<sal_Int8
>& getUnoTunnelId();
95 static rtl::Reference
<ScHeaderFooterContentObj
> getImplementation(const css::uno::Reference
<css::sheet::XHeaderFooterContent
>& rObj
);
98 virtual OUString SAL_CALL
getImplementationName()
99 throw(css::uno::RuntimeException
, std::exception
) override
;
100 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
)
101 throw(css::uno::RuntimeException
, std::exception
) override
;
102 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames()
103 throw(css::uno::RuntimeException
, std::exception
) override
;
107 // ScHeaderFooterTextData: shared data between sub objects of a ScHeaderFooterTextObj
109 class ScHeaderFooterTextData
112 std::unique_ptr
<EditTextObject
> mpTextObj
;
113 css::uno::WeakReference
<css::sheet::XHeaderFooterContent
> xContentObj
;
114 ScHeaderFooterPart nPart
;
115 ScEditEngineDefaulter
* pEditEngine
;
116 SvxEditEngineForwarder
* pForwarder
;
120 ScHeaderFooterTextData(const ScHeaderFooterTextData
&) = delete;
121 const ScHeaderFooterTextData
& operator=(const ScHeaderFooterTextData
&) = delete;
122 ScHeaderFooterTextData(
123 css::uno::WeakReference
<css::sheet::XHeaderFooterContent
> xContent
, ScHeaderFooterPart nP
, const EditTextObject
* pTextObj
);
124 ~ScHeaderFooterTextData();
127 SvxTextForwarder
* GetTextForwarder();
129 void UpdateData(EditEngine
& rEditEngine
);
130 ScEditEngineDefaulter
* GetEditEngine() { GetTextForwarder(); return pEditEngine
; }
132 ScHeaderFooterPart
GetPart() const { return nPart
; }
133 const css::uno::Reference
<css::sheet::XHeaderFooterContent
> GetContentObj() const { return xContentObj
; }
135 const EditTextObject
* GetTextObject() const { return mpTextObj
.get(); }
139 * Each of these instances represent, the left, center or right part of the
140 * header of footer of a page.
142 * ScHeaderFooterTextObj changes the text in a ScHeaderFooterContentObj.
144 class ScHeaderFooterTextObj
: public cppu::WeakImplHelper
<
146 css::text::XTextRangeMover
,
147 css::container::XEnumerationAccess
,
148 css::text::XTextFieldsSupplier
,
149 css::lang::XServiceInfo
>
152 ScHeaderFooterTextData aTextData
;
153 rtl::Reference
<SvxUnoText
> mxUnoText
;
155 void CreateUnoText_Impl();
158 ScHeaderFooterTextObj(
159 css::uno::WeakReference
<css::sheet::XHeaderFooterContent
> xContent
, ScHeaderFooterPart nP
, const EditTextObject
* pTextObj
);
160 virtual ~ScHeaderFooterTextObj();
162 const EditTextObject
* GetTextObject() const;
163 const SvxUnoText
& GetUnoText();
165 static void FillDummyFieldData( ScHeaderFieldData
& rData
);
168 virtual void SAL_CALL
insertTextContent( const css::uno::Reference
< css::text::XTextRange
>& xRange
,
169 const css::uno::Reference
< css::text::XTextContent
>& xContent
,
171 throw(css::lang::IllegalArgumentException
,
172 css::uno::RuntimeException
, std::exception
) override
;
173 virtual void SAL_CALL
removeTextContent( const css::uno::Reference
< css::text::XTextContent
>& xContent
)
174 throw(css::container::NoSuchElementException
,
175 css::uno::RuntimeException
, std::exception
) override
;
178 virtual css::uno::Reference
< css::text::XTextCursor
> SAL_CALL
179 createTextCursor() throw(css::uno::RuntimeException
, std::exception
) override
;
180 virtual css::uno::Reference
< css::text::XTextCursor
> SAL_CALL
181 createTextCursorByRange( const css::uno::Reference
< css::text::XTextRange
>& aTextPosition
)
182 throw(css::uno::RuntimeException
, std::exception
) override
;
183 virtual void SAL_CALL
insertString( const css::uno::Reference
< css::text::XTextRange
>& xRange
,
184 const OUString
& aString
, sal_Bool bAbsorb
)
185 throw(css::uno::RuntimeException
, std::exception
) override
;
186 virtual void SAL_CALL
insertControlCharacter( const css::uno::Reference
< css::text::XTextRange
>& xRange
,
187 sal_Int16 nControlCharacter
, sal_Bool bAbsorb
)
188 throw(css::lang::IllegalArgumentException
,
189 css::uno::RuntimeException
, std::exception
) override
;
192 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
193 getText() throw(css::uno::RuntimeException
, std::exception
) override
;
194 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
195 getStart() throw(css::uno::RuntimeException
, std::exception
) override
;
196 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
197 getEnd() throw(css::uno::RuntimeException
, std::exception
) override
;
198 virtual OUString SAL_CALL
getString() throw(css::uno::RuntimeException
, std::exception
) override
;
199 virtual void SAL_CALL
setString( const OUString
& aString
)
200 throw(css::uno::RuntimeException
, std::exception
) override
;
203 virtual void SAL_CALL
moveTextRange( const css::uno::Reference
< css::text::XTextRange
>& xRange
,
204 sal_Int16 nParagraphs
)
205 throw(css::uno::RuntimeException
, std::exception
) override
;
207 // XEnumerationAccess
208 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
209 createEnumeration() throw(css::uno::RuntimeException
, std::exception
) override
;
212 virtual css::uno::Type SAL_CALL
getElementType()
213 throw(css::uno::RuntimeException
, std::exception
) override
;
214 virtual sal_Bool SAL_CALL
hasElements() throw(css::uno::RuntimeException
, std::exception
) override
;
216 // XTextFieldsSupplier
217 virtual css::uno::Reference
< css::container::XEnumerationAccess
> SAL_CALL
218 getTextFields() throw(css::uno::RuntimeException
, std::exception
) override
;
219 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
220 getTextFieldMasters() throw(css::uno::RuntimeException
, std::exception
) override
;
223 virtual OUString SAL_CALL
getImplementationName()
224 throw(css::uno::RuntimeException
, std::exception
) override
;
225 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
)
226 throw(css::uno::RuntimeException
, std::exception
) override
;
227 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames()
228 throw(css::uno::RuntimeException
, std::exception
) override
;
232 // derived cursor objects for getImplementation and getText/getStart/getEnd
234 //! uno3: SvxUnoTextCursor is not derived from XUnoTunnel, but should be (?)
236 class ScCellTextCursor
: public SvxUnoTextCursor
241 ScCellTextCursor(const ScCellTextCursor
& rOther
);
242 ScCellTextCursor(ScCellObj
& rText
);
243 virtual ~ScCellTextCursor() throw();
245 ScCellObj
& GetCellObj() const { return rTextObj
; }
247 // SvxUnoTextCursor methods reimplemented here:
248 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
249 getText() throw(css::uno::RuntimeException
, std::exception
) override
;
250 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
251 getStart() throw(css::uno::RuntimeException
, std::exception
) override
;
252 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
253 getEnd() throw(css::uno::RuntimeException
, std::exception
) override
;
256 virtual sal_Int64 SAL_CALL
getSomething( const css::uno::Sequence
< sal_Int8
>& aIdentifier
)
257 throw(css::uno::RuntimeException
, std::exception
) override
;
259 static const css::uno::Sequence
<sal_Int8
>& getUnoTunnelId();
260 static ScCellTextCursor
* getImplementation(const css::uno::Reference
< css::uno::XInterface
>& rObj
);
263 class ScHeaderFooterTextCursor
: public SvxUnoTextCursor
266 ScHeaderFooterTextObj
& rTextObj
;
269 ScHeaderFooterTextCursor(const ScHeaderFooterTextCursor
& rOther
);
270 ScHeaderFooterTextCursor(ScHeaderFooterTextObj
& rText
);
271 virtual ~ScHeaderFooterTextCursor() throw();
273 // SvxUnoTextCursor methods reimplemented here:
274 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
275 getText() throw(css::uno::RuntimeException
, std::exception
) override
;
276 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
277 getStart() throw(css::uno::RuntimeException
, std::exception
) override
;
278 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
279 getEnd() throw(css::uno::RuntimeException
, std::exception
) override
;
282 virtual sal_Int64 SAL_CALL
getSomething( const css::uno::Sequence
< sal_Int8
>& aIdentifier
)
283 throw(css::uno::RuntimeException
, std::exception
) override
;
285 static const css::uno::Sequence
<sal_Int8
>& getUnoTunnelId();
286 static ScHeaderFooterTextCursor
* getImplementation(const css::uno::Reference
<css::uno::XInterface
>& rObj
);
289 class ScDrawTextCursor
: public SvxUnoTextCursor
292 css::uno::Reference
< css::text::XText
> xParentText
;
295 ScDrawTextCursor(const ScDrawTextCursor
& rOther
);
296 ScDrawTextCursor( const css::uno::Reference
< css::text::XText
>& xParent
,
297 const SvxUnoTextBase
& rText
);
298 virtual ~ScDrawTextCursor() throw();
300 // SvxUnoTextCursor methods reimplemented here:
301 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
302 getText() throw(css::uno::RuntimeException
, std::exception
) override
;
303 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
304 getStart() throw(css::uno::RuntimeException
, std::exception
) override
;
305 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
306 getEnd() throw(css::uno::RuntimeException
, std::exception
) override
;
309 virtual sal_Int64 SAL_CALL
getSomething( const css::uno::Sequence
< sal_Int8
>& aIdentifier
)
310 throw(css::uno::RuntimeException
, std::exception
) override
;
312 static const css::uno::Sequence
<sal_Int8
>& getUnoTunnelId();
313 static ScDrawTextCursor
* getImplementation(const css::uno::Reference
<css::uno::XInterface
>& rObj
);
316 // ScAnnotationTextCursor isn't needed anymore - SvxUnoTextCursor is used instead
318 // ScEditEngineTextObj for formatted cell content that is not inserted in a cell or header/footer
319 // (used for XML export of change tracking contents)
321 class ScSimpleEditSourceHelper
323 ScEditEngineDefaulter
* pEditEngine
;
324 SvxEditEngineForwarder
* pForwarder
;
325 ScSimpleEditSource
* pOriginalSource
;
328 ScSimpleEditSourceHelper();
329 ~ScSimpleEditSourceHelper();
331 ScSimpleEditSource
* GetOriginalSource() const { return pOriginalSource
; }
332 ScEditEngineDefaulter
* GetEditEngine() const { return pEditEngine
; }
335 class ScEditEngineTextObj
: public ScSimpleEditSourceHelper
, public SvxUnoText
338 ScEditEngineTextObj();
339 virtual ~ScEditEngineTextObj() throw();
341 void SetText( const EditTextObject
& rTextObject
);
342 EditTextObject
* CreateTextObject();
345 // ScCellTextData: shared data between sub objects of a cell text object
347 class ScCellTextData
: public SfxListener
350 ScDocShell
* pDocShell
;
352 ScFieldEditEngine
* pEditEngine
;
353 SvxEditEngineForwarder
* pForwarder
;
354 ScCellEditSource
* pOriginalSource
;
361 ScCellTextData(ScDocShell
* pDocSh
, const ScAddress
& rP
);
362 virtual ~ScCellTextData();
364 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
366 // helper functions for ScSharedCellEditSource:
367 virtual SvxTextForwarder
* GetTextForwarder();
369 ScFieldEditEngine
* GetEditEngine() { GetTextForwarder(); return pEditEngine
; }
371 ScCellEditSource
* GetOriginalSource(); // used as argument for SvxUnoText ctor
373 // used for ScCellEditSource:
374 ScDocShell
* GetDocShell() const { return pDocShell
; }
375 const ScAddress
& GetCellPos() const { return aCellPos
; }
377 bool IsDirty() const { return bDirty
; }
378 void SetDoUpdate(bool bValue
) { bDoUpdate
= bValue
; }
381 class ScCellTextObj
: public ScCellTextData
, public SvxUnoText
384 ScCellTextObj(ScDocShell
* pDocSh
, const ScAddress
& rP
);
385 virtual ~ScCellTextObj() throw();
390 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */