xref: /trunk/main/sc/inc/textuno.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SC_TEXTSUNO_HXX
29 #define SC_TEXTSUNO_HXX
30 
31 #include "global.hxx"           // ScRange, ScAddress
32 #include "address.hxx"
33 #include <editeng/unotext.hxx>
34 #include <svl/brdcst.hxx>
35 #include <svl/lstner.hxx>
36 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
37 #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
38 #include <com/sun/star/lang/XServiceInfo.hpp>
39 #include <com/sun/star/lang/XUnoTunnel.hpp>
40 #include <cppuhelper/implbase3.hxx>
41 #include <cppuhelper/implbase5.hxx>
42 #include "scdllapi.h"
43 
44 class EditEngine;
45 class EditTextObject;
46 class SvxEditEngineForwarder;
47 class ScDocShell;
48 class ScAddress;
49 class ScCellObj;
50 class ScSimpleEditSource;
51 class ScSharedCellEditSource;
52 class ScEditEngineDefaulter;
53 class ScFieldEditEngine;
54 
55 struct ScHeaderFieldData;
56 
57 
58 #define SC_HDFT_LEFT    0
59 #define SC_HDFT_CENTER  1
60 #define SC_HDFT_RIGHT   2
61 
62 
63 //  ScHeaderFooterContentObj ist ein dummer Container, der per setPropertyValue
64 //  wieder in die Seitenvorlage geschrieben werden muss
65 
66 class ScHeaderFooterContentObj : public cppu::WeakImplHelper3<
67                             com::sun::star::sheet::XHeaderFooterContent,
68                             com::sun::star::lang::XUnoTunnel,
69                             com::sun::star::lang::XServiceInfo >
70 {
71 private:
72     EditTextObject* pLeftText;
73     EditTextObject* pCenterText;
74     EditTextObject* pRightText;
75     SfxBroadcaster  aBC;
76 
77     ScHeaderFooterContentObj(); // disabled
78 
79 public:
80                             ScHeaderFooterContentObj( const EditTextObject* pLeft,
81                                                       const EditTextObject* pCenter,
82                                                       const EditTextObject* pRight );
83     virtual                 ~ScHeaderFooterContentObj();
84 
85                             // fuer ScPageHFItem (per getImplementation)
86     const EditTextObject*   GetLeftEditObject() const   { return pLeftText; }
87     const EditTextObject*   GetCenterEditObject() const { return pCenterText; }
88     const EditTextObject*   GetRightEditObject() const  { return pRightText; }
89 
90     void                    AddListener( SfxListener& rListener );
91     void                    RemoveListener( SfxListener& rListener );
92 
93     void                    UpdateText( sal_uInt16 nPart, EditEngine& rSource );
94 
95                             // XHeaderFooterContent
96     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > SAL_CALL
97                             getLeftText() throw(::com::sun::star::uno::RuntimeException);
98     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > SAL_CALL
99                             getCenterText() throw(::com::sun::star::uno::RuntimeException);
100     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > SAL_CALL
101                             getRightText() throw(::com::sun::star::uno::RuntimeException);
102 
103                             // XUnoTunnel
104     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence<
105                                     sal_Int8 >& aIdentifier )
106                                 throw(::com::sun::star::uno::RuntimeException);
107 
108     static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
109     static ScHeaderFooterContentObj* getImplementation( const com::sun::star::uno::Reference<
110                                     com::sun::star::sheet::XHeaderFooterContent> xObj );
111 
112                             // XServiceInfo
113     virtual ::rtl::OUString SAL_CALL getImplementationName()
114                                 throw(::com::sun::star::uno::RuntimeException);
115     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
116                                 throw(::com::sun::star::uno::RuntimeException);
117     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
118                                 throw(::com::sun::star::uno::RuntimeException);
119 };
120 
121 
122 //  ScHeaderFooterTextData: shared data between sub objects of a ScHeaderFooterTextObj
123 
124 class ScHeaderFooterTextData : public SfxListener
125 {
126 private:
127     ScHeaderFooterContentObj&   rContentObj;
128     sal_uInt16                      nPart;
129     ScEditEngineDefaulter*      pEditEngine;
130     SvxEditEngineForwarder*     pForwarder;
131     sal_Bool                        bDataValid;
132     sal_Bool                        bInUpdate;
133 
134 public:
135                             ScHeaderFooterTextData( ScHeaderFooterContentObj& rContent,
136                                                     sal_uInt16 nP );
137                             ~ScHeaderFooterTextData();
138 
139     virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
140 
141                             // helper functions
142     SvxTextForwarder*       GetTextForwarder();
143     void                    UpdateData();
144     ScEditEngineDefaulter*  GetEditEngine() { GetTextForwarder(); return pEditEngine; }
145 
146     sal_uInt16                  GetPart() const         { return nPart; }
147     ScHeaderFooterContentObj& GetContentObj() const { return rContentObj; }
148 };
149 
150 //  ScHeaderFooterTextObj veraendert den Text in einem ScHeaderFooterContentObj
151 
152 class ScHeaderFooterTextObj : public cppu::WeakImplHelper5<
153                             com::sun::star::text::XText,
154                             com::sun::star::text::XTextRangeMover,
155                             com::sun::star::container::XEnumerationAccess,
156                             com::sun::star::text::XTextFieldsSupplier,
157                             com::sun::star::lang::XServiceInfo >
158 {
159 private:
160     ScHeaderFooterTextData      aTextData;
161     SvxUnoText*                 pUnoText;
162 
163     void                    CreateUnoText_Impl();
164 
165 public:
166                             ScHeaderFooterTextObj( ScHeaderFooterContentObj& rContent,
167                                                     sal_uInt16 nP );
168     virtual                 ~ScHeaderFooterTextObj();
169 
170     const SvxUnoText&       GetUnoText();
171 
172     static void             FillDummyFieldData( ScHeaderFieldData& rData );
173 
174                             // XText
175     virtual void SAL_CALL   insertTextContent( const ::com::sun::star::uno::Reference<
176                                     ::com::sun::star::text::XTextRange >& xRange,
177                                 const ::com::sun::star::uno::Reference<
178                                     ::com::sun::star::text::XTextContent >& xContent,
179                                 sal_Bool bAbsorb )
180                                     throw(::com::sun::star::lang::IllegalArgumentException,
181                                     ::com::sun::star::uno::RuntimeException);
182     virtual void SAL_CALL   removeTextContent( const ::com::sun::star::uno::Reference<
183                                 ::com::sun::star::text::XTextContent >& xContent )
184                                     throw(::com::sun::star::container::NoSuchElementException,
185                                             ::com::sun::star::uno::RuntimeException);
186 
187                             // XSimpleText
188     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextCursor > SAL_CALL
189                             createTextCursor() throw(::com::sun::star::uno::RuntimeException);
190     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextCursor > SAL_CALL
191                             createTextCursorByRange( const ::com::sun::star::uno::Reference<
192                                         ::com::sun::star::text::XTextRange >& aTextPosition )
193                                     throw(::com::sun::star::uno::RuntimeException);
194     virtual void SAL_CALL   insertString( const ::com::sun::star::uno::Reference<
195                                         ::com::sun::star::text::XTextRange >& xRange,
196                                         const ::rtl::OUString& aString, sal_Bool bAbsorb )
197                                     throw(::com::sun::star::uno::RuntimeException);
198     virtual void SAL_CALL   insertControlCharacter( const ::com::sun::star::uno::Reference<
199                                         ::com::sun::star::text::XTextRange >& xRange,
200                                         sal_Int16 nControlCharacter, sal_Bool bAbsorb )
201                                     throw(::com::sun::star::lang::IllegalArgumentException,
202                                         ::com::sun::star::uno::RuntimeException);
203 
204                             // XTextRange
205     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > SAL_CALL
206                             getText() throw(::com::sun::star::uno::RuntimeException);
207     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL
208                             getStart() throw(::com::sun::star::uno::RuntimeException);
209     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL
210                             getEnd() throw(::com::sun::star::uno::RuntimeException);
211     virtual ::rtl::OUString SAL_CALL getString() throw(::com::sun::star::uno::RuntimeException);
212     virtual void SAL_CALL   setString( const ::rtl::OUString& aString )
213                                     throw(::com::sun::star::uno::RuntimeException);
214 
215                             // XTextRangeMover
216     virtual void SAL_CALL   moveTextRange( const ::com::sun::star::uno::Reference<
217                                         ::com::sun::star::text::XTextRange >& xRange,
218                                         sal_Int16 nParagraphs )
219                                     throw(::com::sun::star::uno::RuntimeException);
220 
221                             // XEnumerationAccess
222     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL
223                             createEnumeration() throw(::com::sun::star::uno::RuntimeException);
224 
225                             // XElementAccess
226     virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
227                                 throw(::com::sun::star::uno::RuntimeException);
228     virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException);
229 
230                             // XTextFieldsSupplier
231     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumerationAccess > SAL_CALL
232                             getTextFields() throw(::com::sun::star::uno::RuntimeException);
233     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL
234                             getTextFieldMasters() throw(::com::sun::star::uno::RuntimeException);
235 
236                             // XServiceInfo
237     virtual ::rtl::OUString SAL_CALL getImplementationName()
238                                 throw(::com::sun::star::uno::RuntimeException);
239     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
240                                 throw(::com::sun::star::uno::RuntimeException);
241     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
242                                 throw(::com::sun::star::uno::RuntimeException);
243 };
244 
245 
246 //  derived cursor objects for getImplementation and getText/getStart/getEnd
247 
248 //! uno3: SvxUnoTextCursor is not derived from XUnoTunnel, but should be (?)
249 
250 class ScCellTextCursor : public SvxUnoTextCursor
251 {
252     ScCellObj&              rTextObj;
253 
254 public:
255                             ScCellTextCursor(const ScCellTextCursor& rOther);
256                             ScCellTextCursor(ScCellObj& rText);
257         virtual                                 ~ScCellTextCursor() throw();
258 
259     ScCellObj&              GetCellObj() const  { return rTextObj; }
260 
261                             // SvxUnoTextCursor methods reimplemented here:
262     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > SAL_CALL
263                             getText() throw(::com::sun::star::uno::RuntimeException);
264     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL
265                             getStart() throw(::com::sun::star::uno::RuntimeException);
266     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL
267                             getEnd() throw(::com::sun::star::uno::RuntimeException);
268 
269                             // XUnoTunnel
270     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence<
271                                     sal_Int8 >& aIdentifier )
272                                 throw(::com::sun::star::uno::RuntimeException);
273 
274     static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
275     static ScCellTextCursor* getImplementation( const com::sun::star::uno::Reference<
276                                     com::sun::star::uno::XInterface> xObj );
277 };
278 
279 class ScHeaderFooterTextCursor : public SvxUnoTextCursor
280 {
281 private:
282     ScHeaderFooterTextObj&  rTextObj;
283 
284 public:
285                             ScHeaderFooterTextCursor(const ScHeaderFooterTextCursor& rOther);
286                             ScHeaderFooterTextCursor(ScHeaderFooterTextObj& rText);
287         virtual                                 ~ScHeaderFooterTextCursor() throw();
288 
289                             // SvxUnoTextCursor methods reimplemented here:
290     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > SAL_CALL
291                             getText() throw(::com::sun::star::uno::RuntimeException);
292     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL
293                             getStart() throw(::com::sun::star::uno::RuntimeException);
294     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL
295                             getEnd() throw(::com::sun::star::uno::RuntimeException);
296 
297                             // XUnoTunnel
298     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence<
299                                     sal_Int8 >& aIdentifier )
300                                 throw(::com::sun::star::uno::RuntimeException);
301 
302     static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
303     static ScHeaderFooterTextCursor* getImplementation( const com::sun::star::uno::Reference<
304                                     com::sun::star::uno::XInterface> xObj );
305 };
306 
307 class ScDrawTextCursor : public SvxUnoTextCursor
308 {
309 private:
310     com::sun::star::uno::Reference< com::sun::star::text::XText > xParentText;
311 
312 public:
313                             ScDrawTextCursor(const ScDrawTextCursor& rOther);
314                             ScDrawTextCursor( const com::sun::star::uno::Reference<
315                                                 com::sun::star::text::XText >& xParent,
316                                             const SvxUnoTextBase& rText );
317     virtual                  ~ScDrawTextCursor() throw();
318 
319                             // SvxUnoTextCursor methods reimplemented here:
320     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XText > SAL_CALL
321                             getText() throw(::com::sun::star::uno::RuntimeException);
322     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL
323                             getStart() throw(::com::sun::star::uno::RuntimeException);
324     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL
325                             getEnd() throw(::com::sun::star::uno::RuntimeException);
326 
327                             // XUnoTunnel
328     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence<
329                                     sal_Int8 >& aIdentifier )
330                                 throw(::com::sun::star::uno::RuntimeException);
331 
332     static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
333     static ScDrawTextCursor* getImplementation( const com::sun::star::uno::Reference<
334                                     com::sun::star::uno::XInterface> xObj );
335 };
336 
337 
338 // ScAnnotationTextCursor isn't needed anymore - SvxUnoTextCursor is used instead
339 
340 
341 //  ScEditEngineTextObj for formatted cell content that is not inserted in a cell or header/footer
342 //  (used for XML export of change tracking contents)
343 
344 class ScSimpleEditSourceHelper
345 {
346     ScEditEngineDefaulter*  pEditEngine;
347     SvxEditEngineForwarder* pForwarder;
348     ScSimpleEditSource*     pOriginalSource;
349 
350 public:
351             ScSimpleEditSourceHelper();
352             ~ScSimpleEditSourceHelper();
353 
354     ScSimpleEditSource* GetOriginalSource() const   { return pOriginalSource; }
355     ScEditEngineDefaulter* GetEditEngine() const    { return pEditEngine; }
356 };
357 
358 class ScEditEngineTextObj : public ScSimpleEditSourceHelper, public SvxUnoText
359 {
360 public:
361                         ScEditEngineTextObj();
362         virtual                         ~ScEditEngineTextObj() throw();
363 
364     void                SetText( const EditTextObject& rTextObject );
365     EditTextObject*     CreateTextObject();
366 };
367 
368 
369 //  ScCellTextData: shared data between sub objects of a cell text object
370 
371 class ScCellTextData : public SfxListener
372 {
373 protected:
374     ScDocShell*             pDocShell;
375     ScAddress               aCellPos;
376     ScFieldEditEngine*      pEditEngine;
377     SvxEditEngineForwarder* pForwarder;
378     ScSharedCellEditSource* pOriginalSource;
379     sal_Bool                    bDataValid;
380     sal_Bool                    bInUpdate;
381     sal_Bool                    bDirty;
382     sal_Bool                    bDoUpdate;
383 
384 protected:
385     virtual void            GetCellText(const ScAddress& rCellPos, String& rText);
386 
387 public:
388                             ScCellTextData(ScDocShell* pDocSh, const ScAddress& rP);
389     virtual                 ~ScCellTextData();
390 
391     virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
392 
393                             // helper functions for ScSharedCellEditSource:
394     virtual SvxTextForwarder* GetTextForwarder();
395     void                    UpdateData();
396     ScFieldEditEngine*      GetEditEngine() { GetTextForwarder(); return pEditEngine; }
397 
398     ScSharedCellEditSource* GetOriginalSource();        // used as argument for SvxUnoText ctor
399 
400                             // used for ScCellEditSource:
401     ScDocShell*             GetDocShell() const     { return pDocShell; }
402     const ScAddress&        GetCellPos() const      { return aCellPos; }
403 
404     void                    SetDirty(sal_Bool bValue)   { bDirty = bValue; }
405     sal_Bool                    IsDirty() const         { return bDirty; }
406     void                    SetDoUpdate(sal_Bool bValue)    { bDoUpdate = bValue; }
407 };
408 
409 class ScCellTextObj : public ScCellTextData, public SvxUnoText
410 {
411 public:
412                 ScCellTextObj(ScDocShell* pDocSh, const ScAddress& rP);
413         virtual         ~ScCellTextObj() throw();
414 };
415 
416 
417 #endif
418 
419