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/implbase3.hxx>
32 #include <cppuhelper/implbase5.hxx>
34 #include <rtl/ref.hxx>
37 #include <boost/noncopyable.hpp>
41 class SvxEditEngineForwarder
;
45 class ScSimpleEditSource
;
46 class ScCellEditSource
;
47 class ScEditEngineDefaulter
;
48 class ScFieldEditEngine
;
49 class ScHeaderFooterTextObj
;
51 struct ScHeaderFieldData
;
53 #define SC_HDFT_LEFT 0
54 #define SC_HDFT_CENTER 1
55 #define SC_HDFT_RIGHT 2
57 // ScHeaderFooterContentObj is a dumb container which must be re-written into
58 // the page template using setPropertyValue
60 class ScHeaderFooterContentObj
: public cppu::WeakImplHelper3
<
61 com::sun::star::sheet::XHeaderFooterContent
,
62 com::sun::star::lang::XUnoTunnel
,
63 com::sun::star::lang::XServiceInfo
>
66 rtl::Reference
<ScHeaderFooterTextObj
> mxLeftText
;
67 rtl::Reference
<ScHeaderFooterTextObj
> mxCenterText
;
68 rtl::Reference
<ScHeaderFooterTextObj
> mxRightText
;
70 ScHeaderFooterContentObj(); // disabled
73 ScHeaderFooterContentObj( const EditTextObject
* pLeft
,
74 const EditTextObject
* pCenter
,
75 const EditTextObject
* pRight
);
76 virtual ~ScHeaderFooterContentObj();
78 // for ScPageHFItem (using getImplementation)
79 const EditTextObject
* GetLeftEditObject() const;
80 const EditTextObject
* GetCenterEditObject() const;
81 const EditTextObject
* GetRightEditObject() const;
83 // XHeaderFooterContent
84 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XText
> SAL_CALL
85 getLeftText() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
86 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XText
> SAL_CALL
87 getCenterText() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
88 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XText
> SAL_CALL
89 getRightText() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
92 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
<
93 sal_Int8
>& aIdentifier
)
94 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
96 static const com::sun::star::uno::Sequence
<sal_Int8
>& getUnoTunnelId();
97 static rtl::Reference
<ScHeaderFooterContentObj
> getImplementation(const css::uno::Reference
<css::sheet::XHeaderFooterContent
>& rObj
);
100 virtual OUString SAL_CALL
getImplementationName()
101 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
102 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
)
103 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
104 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames()
105 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
108 // ScHeaderFooterTextData: shared data between sub objects of a ScHeaderFooterTextObj
110 class ScHeaderFooterTextData
: boost::noncopyable
113 EditTextObject
* mpTextObj
;
114 rtl::Reference
<ScHeaderFooterContentObj
> rContentObj
;
116 ScEditEngineDefaulter
* pEditEngine
;
117 SvxEditEngineForwarder
* pForwarder
;
121 ScHeaderFooterTextData(
122 rtl::Reference
<ScHeaderFooterContentObj
> const & rContent
, sal_uInt16 nP
, const EditTextObject
* pTextObj
);
123 ~ScHeaderFooterTextData();
126 SvxTextForwarder
* GetTextForwarder();
128 void UpdateData(EditEngine
& rEditEngine
);
129 ScEditEngineDefaulter
* GetEditEngine() { GetTextForwarder(); return pEditEngine
; }
131 sal_uInt16
GetPart() const { return nPart
; }
132 rtl::Reference
<ScHeaderFooterContentObj
> GetContentObj() const { return rContentObj
; }
134 const EditTextObject
* GetTextObject() const { return mpTextObj
;}
138 * Each of these instances represent, the left, center or right part of the
139 * header of footer of a page.
141 * ScHeaderFooterTextObj changes the text in a ScHeaderFooterContentObj.
143 class ScHeaderFooterTextObj
: public cppu::WeakImplHelper5
<
144 com::sun::star::text::XText
,
145 com::sun::star::text::XTextRangeMover
,
146 com::sun::star::container::XEnumerationAccess
,
147 com::sun::star::text::XTextFieldsSupplier
,
148 com::sun::star::lang::XServiceInfo
>
151 ScHeaderFooterTextData aTextData
;
152 rtl::Reference
<SvxUnoText
> mxUnoText
;
154 void CreateUnoText_Impl();
157 ScHeaderFooterTextObj(
158 rtl::Reference
<ScHeaderFooterContentObj
> const & rContent
, sal_uInt16 nP
, const EditTextObject
* pTextObj
);
159 virtual ~ScHeaderFooterTextObj();
161 const EditTextObject
* GetTextObject() const;
162 const SvxUnoText
& GetUnoText();
164 static void FillDummyFieldData( ScHeaderFieldData
& rData
);
167 virtual void SAL_CALL
insertTextContent( const ::com::sun::star::uno::Reference
<
168 ::com::sun::star::text::XTextRange
>& xRange
,
169 const ::com::sun::star::uno::Reference
<
170 ::com::sun::star::text::XTextContent
>& xContent
,
172 throw(::com::sun::star::lang::IllegalArgumentException
,
173 ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
174 virtual void SAL_CALL
removeTextContent( const ::com::sun::star::uno::Reference
<
175 ::com::sun::star::text::XTextContent
>& xContent
)
176 throw(::com::sun::star::container::NoSuchElementException
,
177 ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
180 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextCursor
> SAL_CALL
181 createTextCursor() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
182 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextCursor
> SAL_CALL
183 createTextCursorByRange( const ::com::sun::star::uno::Reference
<
184 ::com::sun::star::text::XTextRange
>& aTextPosition
)
185 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
186 virtual void SAL_CALL
insertString( const ::com::sun::star::uno::Reference
<
187 ::com::sun::star::text::XTextRange
>& xRange
,
188 const OUString
& aString
, sal_Bool bAbsorb
)
189 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
190 virtual void SAL_CALL
insertControlCharacter( const ::com::sun::star::uno::Reference
<
191 ::com::sun::star::text::XTextRange
>& xRange
,
192 sal_Int16 nControlCharacter
, sal_Bool bAbsorb
)
193 throw(::com::sun::star::lang::IllegalArgumentException
,
194 ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
197 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XText
> SAL_CALL
198 getText() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
199 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> SAL_CALL
200 getStart() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
201 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> SAL_CALL
202 getEnd() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
203 virtual OUString SAL_CALL
getString() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
204 virtual void SAL_CALL
setString( const OUString
& aString
)
205 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
208 virtual void SAL_CALL
moveTextRange( const ::com::sun::star::uno::Reference
<
209 ::com::sun::star::text::XTextRange
>& xRange
,
210 sal_Int16 nParagraphs
)
211 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
213 // XEnumerationAccess
214 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XEnumeration
> SAL_CALL
215 createEnumeration() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
218 virtual ::com::sun::star::uno::Type SAL_CALL
getElementType()
219 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
220 virtual sal_Bool SAL_CALL
hasElements() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
222 // XTextFieldsSupplier
223 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XEnumerationAccess
> SAL_CALL
224 getTextFields() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
225 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
> SAL_CALL
226 getTextFieldMasters() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
229 virtual OUString SAL_CALL
getImplementationName()
230 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
231 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
)
232 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
233 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames()
234 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
237 // derived cursor objects for getImplementation and getText/getStart/getEnd
239 //! uno3: SvxUnoTextCursor is not derived from XUnoTunnel, but should be (?)
241 class ScCellTextCursor
: public SvxUnoTextCursor
246 ScCellTextCursor(const ScCellTextCursor
& rOther
);
247 ScCellTextCursor(ScCellObj
& rText
);
248 virtual ~ScCellTextCursor() throw();
250 ScCellObj
& GetCellObj() const { return rTextObj
; }
252 // SvxUnoTextCursor methods reimplemented here:
253 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XText
> SAL_CALL
254 getText() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
255 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> SAL_CALL
256 getStart() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
257 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> SAL_CALL
258 getEnd() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
261 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
<
262 sal_Int8
>& aIdentifier
)
263 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
265 static const com::sun::star::uno::Sequence
<sal_Int8
>& getUnoTunnelId();
266 static ScCellTextCursor
* getImplementation(const css::uno::Reference
< css::uno::XInterface
>& rObj
);
269 class ScHeaderFooterTextCursor
: public SvxUnoTextCursor
272 ScHeaderFooterTextObj
& rTextObj
;
275 ScHeaderFooterTextCursor(const ScHeaderFooterTextCursor
& rOther
);
276 ScHeaderFooterTextCursor(ScHeaderFooterTextObj
& rText
);
277 virtual ~ScHeaderFooterTextCursor() throw();
279 // SvxUnoTextCursor methods reimplemented here:
280 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XText
> SAL_CALL
281 getText() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
282 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> SAL_CALL
283 getStart() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
284 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> SAL_CALL
285 getEnd() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
288 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
<
289 sal_Int8
>& aIdentifier
)
290 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
292 static const com::sun::star::uno::Sequence
<sal_Int8
>& getUnoTunnelId();
293 static ScHeaderFooterTextCursor
* getImplementation(const css::uno::Reference
<css::uno::XInterface
>& rObj
);
296 class ScDrawTextCursor
: public SvxUnoTextCursor
299 com::sun::star::uno::Reference
< com::sun::star::text::XText
> xParentText
;
302 ScDrawTextCursor(const ScDrawTextCursor
& rOther
);
303 ScDrawTextCursor( const com::sun::star::uno::Reference
<
304 com::sun::star::text::XText
>& xParent
,
305 const SvxUnoTextBase
& rText
);
306 virtual ~ScDrawTextCursor() throw();
308 // SvxUnoTextCursor methods reimplemented here:
309 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XText
> SAL_CALL
310 getText() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
311 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> SAL_CALL
312 getStart() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
313 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> SAL_CALL
314 getEnd() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
317 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
<
318 sal_Int8
>& aIdentifier
)
319 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
321 static const com::sun::star::uno::Sequence
<sal_Int8
>& getUnoTunnelId();
322 static ScDrawTextCursor
* getImplementation(const css::uno::Reference
<css::uno::XInterface
>& rObj
);
325 // ScAnnotationTextCursor isn't needed anymore - SvxUnoTextCursor is used instead
327 // ScEditEngineTextObj for formatted cell content that is not inserted in a cell or header/footer
328 // (used for XML export of change tracking contents)
330 class ScSimpleEditSourceHelper
332 ScEditEngineDefaulter
* pEditEngine
;
333 SvxEditEngineForwarder
* pForwarder
;
334 ScSimpleEditSource
* pOriginalSource
;
337 ScSimpleEditSourceHelper();
338 ~ScSimpleEditSourceHelper();
340 ScSimpleEditSource
* GetOriginalSource() const { return pOriginalSource
; }
341 ScEditEngineDefaulter
* GetEditEngine() const { return pEditEngine
; }
344 class ScEditEngineTextObj
: public ScSimpleEditSourceHelper
, public SvxUnoText
347 ScEditEngineTextObj();
348 virtual ~ScEditEngineTextObj() throw();
350 void SetText( const EditTextObject
& rTextObject
);
351 EditTextObject
* CreateTextObject();
354 // ScCellTextData: shared data between sub objects of a cell text object
356 class ScCellTextData
: public SfxListener
359 ScDocShell
* pDocShell
;
361 ScFieldEditEngine
* pEditEngine
;
362 SvxEditEngineForwarder
* pForwarder
;
363 ScCellEditSource
* pOriginalSource
;
370 virtual void GetCellText(const ScAddress
& rCellPos
, OUString
& rText
);
373 ScCellTextData(ScDocShell
* pDocSh
, const ScAddress
& rP
);
374 virtual ~ScCellTextData();
376 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) SAL_OVERRIDE
;
378 // helper functions for ScSharedCellEditSource:
379 virtual SvxTextForwarder
* GetTextForwarder();
381 ScFieldEditEngine
* GetEditEngine() { GetTextForwarder(); return pEditEngine
; }
383 ScCellEditSource
* GetOriginalSource(); // used as argument for SvxUnoText ctor
385 // used for ScCellEditSource:
386 ScDocShell
* GetDocShell() const { return pDocShell
; }
387 const ScAddress
& GetCellPos() const { return aCellPos
; }
389 void SetDirty(bool bValue
) { bDirty
= bValue
; }
390 bool IsDirty() const { return bDirty
; }
391 void SetDoUpdate(bool bValue
) { bDoUpdate
= bValue
; }
394 class ScCellTextObj
: public ScCellTextData
, public SvxUnoText
397 ScCellTextObj(ScDocShell
* pDocSh
, const ScAddress
& rP
);
398 virtual ~ScCellTextObj() throw();
403 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */