1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: textuno.hxx,v $
10 * $Revision: 1.15.32.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_TEXTSUNO_HXX
32 #define SC_TEXTSUNO_HXX
34 #include "global.hxx" // ScRange, ScAddress
35 #include "address.hxx"
36 #include <svx/unotext.hxx>
37 #include <svtools/brdcst.hxx>
38 #include <svtools/lstner.hxx>
39 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
40 #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
41 #include <com/sun/star/lang/XServiceInfo.hpp>
42 #include <com/sun/star/lang/XUnoTunnel.hpp>
43 #include <cppuhelper/implbase3.hxx>
44 #include <cppuhelper/implbase5.hxx>
49 class SvxEditEngineForwarder
;
53 class ScSimpleEditSource
;
54 class ScSharedCellEditSource
;
55 class ScEditEngineDefaulter
;
56 class ScFieldEditEngine
;
58 struct ScHeaderFieldData
;
61 #define SC_HDFT_LEFT 0
62 #define SC_HDFT_CENTER 1
63 #define SC_HDFT_RIGHT 2
66 // ScHeaderFooterContentObj ist ein dummer Container, der per setPropertyValue
67 // wieder in die Seitenvorlage geschrieben werden muss
69 class ScHeaderFooterContentObj
: public cppu::WeakImplHelper3
<
70 com::sun::star::sheet::XHeaderFooterContent
,
71 com::sun::star::lang::XUnoTunnel
,
72 com::sun::star::lang::XServiceInfo
>
75 EditTextObject
* pLeftText
;
76 EditTextObject
* pCenterText
;
77 EditTextObject
* pRightText
;
80 ScHeaderFooterContentObj(); // disabled
83 ScHeaderFooterContentObj( const EditTextObject
* pLeft
,
84 const EditTextObject
* pCenter
,
85 const EditTextObject
* pRight
);
86 virtual ~ScHeaderFooterContentObj();
88 // fuer ScPageHFItem (per getImplementation)
89 const EditTextObject
* GetLeftEditObject() const { return pLeftText
; }
90 const EditTextObject
* GetCenterEditObject() const { return pCenterText
; }
91 const EditTextObject
* GetRightEditObject() const { return pRightText
; }
93 void AddListener( SfxListener
& rListener
);
94 void RemoveListener( SfxListener
& rListener
);
96 void UpdateText( USHORT nPart
, EditEngine
& rSource
);
98 // XHeaderFooterContent
99 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XText
> SAL_CALL
100 getLeftText() throw(::com::sun::star::uno::RuntimeException
);
101 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XText
> SAL_CALL
102 getCenterText() throw(::com::sun::star::uno::RuntimeException
);
103 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XText
> SAL_CALL
104 getRightText() throw(::com::sun::star::uno::RuntimeException
);
107 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
<
108 sal_Int8
>& aIdentifier
)
109 throw(::com::sun::star::uno::RuntimeException
);
111 static const com::sun::star::uno::Sequence
<sal_Int8
>& getUnoTunnelId();
112 static ScHeaderFooterContentObj
* getImplementation( const com::sun::star::uno::Reference
<
113 com::sun::star::sheet::XHeaderFooterContent
> xObj
);
116 virtual ::rtl::OUString SAL_CALL
getImplementationName()
117 throw(::com::sun::star::uno::RuntimeException
);
118 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
)
119 throw(::com::sun::star::uno::RuntimeException
);
120 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames()
121 throw(::com::sun::star::uno::RuntimeException
);
125 // ScHeaderFooterTextData: shared data between sub objects of a ScHeaderFooterTextObj
127 class ScHeaderFooterTextData
: public SfxListener
130 ScHeaderFooterContentObj
& rContentObj
;
132 ScEditEngineDefaulter
* pEditEngine
;
133 SvxEditEngineForwarder
* pForwarder
;
138 ScHeaderFooterTextData( ScHeaderFooterContentObj
& rContent
,
140 ~ScHeaderFooterTextData();
142 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
);
145 SvxTextForwarder
* GetTextForwarder();
147 ScEditEngineDefaulter
* GetEditEngine() { GetTextForwarder(); return pEditEngine
; }
149 USHORT
GetPart() const { return nPart
; }
150 ScHeaderFooterContentObj
& GetContentObj() const { return rContentObj
; }
153 // ScHeaderFooterTextObj veraendert den Text in einem ScHeaderFooterContentObj
155 class ScHeaderFooterTextObj
: public cppu::WeakImplHelper5
<
156 com::sun::star::text::XText
,
157 com::sun::star::text::XTextRangeMover
,
158 com::sun::star::container::XEnumerationAccess
,
159 com::sun::star::text::XTextFieldsSupplier
,
160 com::sun::star::lang::XServiceInfo
>
163 ScHeaderFooterTextData aTextData
;
164 SvxUnoText
* pUnoText
;
166 void CreateUnoText_Impl();
169 ScHeaderFooterTextObj( ScHeaderFooterContentObj
& rContent
,
171 virtual ~ScHeaderFooterTextObj();
173 const SvxUnoText
& GetUnoText();
175 static void FillDummyFieldData( ScHeaderFieldData
& rData
);
178 virtual void SAL_CALL
insertTextContent( const ::com::sun::star::uno::Reference
<
179 ::com::sun::star::text::XTextRange
>& xRange
,
180 const ::com::sun::star::uno::Reference
<
181 ::com::sun::star::text::XTextContent
>& xContent
,
183 throw(::com::sun::star::lang::IllegalArgumentException
,
184 ::com::sun::star::uno::RuntimeException
);
185 virtual void SAL_CALL
removeTextContent( const ::com::sun::star::uno::Reference
<
186 ::com::sun::star::text::XTextContent
>& xContent
)
187 throw(::com::sun::star::container::NoSuchElementException
,
188 ::com::sun::star::uno::RuntimeException
);
191 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextCursor
> SAL_CALL
192 createTextCursor() throw(::com::sun::star::uno::RuntimeException
);
193 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextCursor
> SAL_CALL
194 createTextCursorByRange( const ::com::sun::star::uno::Reference
<
195 ::com::sun::star::text::XTextRange
>& aTextPosition
)
196 throw(::com::sun::star::uno::RuntimeException
);
197 virtual void SAL_CALL
insertString( const ::com::sun::star::uno::Reference
<
198 ::com::sun::star::text::XTextRange
>& xRange
,
199 const ::rtl::OUString
& aString
, sal_Bool bAbsorb
)
200 throw(::com::sun::star::uno::RuntimeException
);
201 virtual void SAL_CALL
insertControlCharacter( const ::com::sun::star::uno::Reference
<
202 ::com::sun::star::text::XTextRange
>& xRange
,
203 sal_Int16 nControlCharacter
, sal_Bool bAbsorb
)
204 throw(::com::sun::star::lang::IllegalArgumentException
,
205 ::com::sun::star::uno::RuntimeException
);
208 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XText
> SAL_CALL
209 getText() throw(::com::sun::star::uno::RuntimeException
);
210 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> SAL_CALL
211 getStart() throw(::com::sun::star::uno::RuntimeException
);
212 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> SAL_CALL
213 getEnd() throw(::com::sun::star::uno::RuntimeException
);
214 virtual ::rtl::OUString SAL_CALL
getString() throw(::com::sun::star::uno::RuntimeException
);
215 virtual void SAL_CALL
setString( const ::rtl::OUString
& aString
)
216 throw(::com::sun::star::uno::RuntimeException
);
219 virtual void SAL_CALL
moveTextRange( const ::com::sun::star::uno::Reference
<
220 ::com::sun::star::text::XTextRange
>& xRange
,
221 sal_Int16 nParagraphs
)
222 throw(::com::sun::star::uno::RuntimeException
);
224 // XEnumerationAccess
225 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XEnumeration
> SAL_CALL
226 createEnumeration() throw(::com::sun::star::uno::RuntimeException
);
229 virtual ::com::sun::star::uno::Type SAL_CALL
getElementType()
230 throw(::com::sun::star::uno::RuntimeException
);
231 virtual sal_Bool SAL_CALL
hasElements() throw(::com::sun::star::uno::RuntimeException
);
233 // XTextFieldsSupplier
234 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XEnumerationAccess
> SAL_CALL
235 getTextFields() throw(::com::sun::star::uno::RuntimeException
);
236 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
> SAL_CALL
237 getTextFieldMasters() throw(::com::sun::star::uno::RuntimeException
);
240 virtual ::rtl::OUString SAL_CALL
getImplementationName()
241 throw(::com::sun::star::uno::RuntimeException
);
242 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
)
243 throw(::com::sun::star::uno::RuntimeException
);
244 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames()
245 throw(::com::sun::star::uno::RuntimeException
);
249 // derived cursor objects for getImplementation and getText/getStart/getEnd
251 //! uno3: SvxUnoTextCursor is not derived from XUnoTunnel, but should be (?)
253 class ScCellTextCursor
: public SvxUnoTextCursor
258 ScCellTextCursor(const ScCellTextCursor
& rOther
);
259 ScCellTextCursor(ScCellObj
& rText
);
260 virtual ~ScCellTextCursor() throw();
262 ScCellObj
& GetCellObj() const { return rTextObj
; }
264 // SvxUnoTextCursor methods reimplemented here:
265 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XText
> SAL_CALL
266 getText() throw(::com::sun::star::uno::RuntimeException
);
267 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> SAL_CALL
268 getStart() throw(::com::sun::star::uno::RuntimeException
);
269 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> SAL_CALL
270 getEnd() throw(::com::sun::star::uno::RuntimeException
);
273 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
<
274 sal_Int8
>& aIdentifier
)
275 throw(::com::sun::star::uno::RuntimeException
);
277 static const com::sun::star::uno::Sequence
<sal_Int8
>& getUnoTunnelId();
278 static ScCellTextCursor
* getImplementation( const com::sun::star::uno::Reference
<
279 com::sun::star::uno::XInterface
> xObj
);
282 class ScHeaderFooterTextCursor
: public SvxUnoTextCursor
285 ScHeaderFooterTextObj
& rTextObj
;
288 ScHeaderFooterTextCursor(const ScHeaderFooterTextCursor
& rOther
);
289 ScHeaderFooterTextCursor(ScHeaderFooterTextObj
& rText
);
290 virtual ~ScHeaderFooterTextCursor() throw();
292 // SvxUnoTextCursor methods reimplemented here:
293 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XText
> SAL_CALL
294 getText() throw(::com::sun::star::uno::RuntimeException
);
295 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> SAL_CALL
296 getStart() throw(::com::sun::star::uno::RuntimeException
);
297 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> SAL_CALL
298 getEnd() throw(::com::sun::star::uno::RuntimeException
);
301 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
<
302 sal_Int8
>& aIdentifier
)
303 throw(::com::sun::star::uno::RuntimeException
);
305 static const com::sun::star::uno::Sequence
<sal_Int8
>& getUnoTunnelId();
306 static ScHeaderFooterTextCursor
* getImplementation( const com::sun::star::uno::Reference
<
307 com::sun::star::uno::XInterface
> xObj
);
310 class ScDrawTextCursor
: public SvxUnoTextCursor
313 com::sun::star::uno::Reference
< com::sun::star::text::XText
> xParentText
;
316 ScDrawTextCursor(const ScDrawTextCursor
& rOther
);
317 ScDrawTextCursor( const com::sun::star::uno::Reference
<
318 com::sun::star::text::XText
>& xParent
,
319 const SvxUnoTextBase
& rText
);
320 virtual ~ScDrawTextCursor() throw();
322 // SvxUnoTextCursor methods reimplemented here:
323 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XText
> SAL_CALL
324 getText() throw(::com::sun::star::uno::RuntimeException
);
325 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> SAL_CALL
326 getStart() throw(::com::sun::star::uno::RuntimeException
);
327 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::text::XTextRange
> SAL_CALL
328 getEnd() throw(::com::sun::star::uno::RuntimeException
);
331 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
<
332 sal_Int8
>& aIdentifier
)
333 throw(::com::sun::star::uno::RuntimeException
);
335 static const com::sun::star::uno::Sequence
<sal_Int8
>& getUnoTunnelId();
336 static ScDrawTextCursor
* getImplementation( const com::sun::star::uno::Reference
<
337 com::sun::star::uno::XInterface
> xObj
);
341 // ScAnnotationTextCursor isn't needed anymore - SvxUnoTextCursor is used instead
344 // ScEditEngineTextObj for formatted cell content that is not inserted in a cell or header/footer
345 // (used for XML export of change tracking contents)
347 class ScSimpleEditSourceHelper
349 ScEditEngineDefaulter
* pEditEngine
;
350 SvxEditEngineForwarder
* pForwarder
;
351 ScSimpleEditSource
* pOriginalSource
;
354 ScSimpleEditSourceHelper();
355 ~ScSimpleEditSourceHelper();
357 ScSimpleEditSource
* GetOriginalSource() const { return pOriginalSource
; }
358 ScEditEngineDefaulter
* GetEditEngine() const { return pEditEngine
; }
361 class ScEditEngineTextObj
: public ScSimpleEditSourceHelper
, public SvxUnoText
364 ScEditEngineTextObj();
365 virtual ~ScEditEngineTextObj() throw();
367 void SetText( const EditTextObject
& rTextObject
);
368 EditTextObject
* CreateTextObject();
372 // ScCellTextData: shared data between sub objects of a cell text object
374 class ScCellTextData
: public SfxListener
377 ScDocShell
* pDocShell
;
379 ScFieldEditEngine
* pEditEngine
;
380 SvxEditEngineForwarder
* pForwarder
;
381 ScSharedCellEditSource
* pOriginalSource
;
388 virtual void GetCellText(const ScAddress
& rCellPos
, String
& rText
);
391 ScCellTextData(ScDocShell
* pDocSh
, const ScAddress
& rP
);
392 virtual ~ScCellTextData();
394 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
);
396 // helper functions for ScSharedCellEditSource:
397 virtual SvxTextForwarder
* GetTextForwarder();
399 ScFieldEditEngine
* GetEditEngine() { GetTextForwarder(); return pEditEngine
; }
401 ScSharedCellEditSource
* GetOriginalSource(); // used as argument for SvxUnoText ctor
403 // used for ScCellEditSource:
404 ScDocShell
* GetDocShell() const { return pDocShell
; }
405 const ScAddress
& GetCellPos() const { return aCellPos
; }
407 void SetDirty(BOOL bValue
) { bDirty
= bValue
; }
408 BOOL
IsDirty() const { return bDirty
; }
409 void SetDoUpdate(BOOL bValue
) { bDoUpdate
= bValue
; }
412 class ScCellTextObj
: public ScCellTextData
, public SvxUnoText
415 ScCellTextObj(ScDocShell
* pDocSh
, const ScAddress
& rP
);
416 virtual ~ScCellTextObj() throw();