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