Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SC_INC_TEXTUNO_HXX
21 : #define INCLUDED_SC_INC_TEXTUNO_HXX
22 :
23 : #include "global.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>
33 :
34 : #include <rtl/ref.hxx>
35 : #include "scdllapi.h"
36 :
37 : #include <boost/noncopyable.hpp>
38 :
39 : class EditEngine;
40 : class EditTextObject;
41 : class SvxEditEngineForwarder;
42 : class ScDocShell;
43 : class ScAddress;
44 : class ScCellObj;
45 : class ScSimpleEditSource;
46 : class ScCellEditSource;
47 : class ScEditEngineDefaulter;
48 : class ScFieldEditEngine;
49 : class ScHeaderFooterTextObj;
50 :
51 : struct ScHeaderFieldData;
52 :
53 : #define SC_HDFT_LEFT 0
54 : #define SC_HDFT_CENTER 1
55 : #define SC_HDFT_RIGHT 2
56 :
57 : // ScHeaderFooterContentObj is a dumb container which must be re-written into
58 : // the page template using setPropertyValue
59 :
60 : class ScHeaderFooterContentObj : public cppu::WeakImplHelper3<
61 : com::sun::star::sheet::XHeaderFooterContent,
62 : com::sun::star::lang::XUnoTunnel,
63 : com::sun::star::lang::XServiceInfo >
64 : {
65 : private:
66 : rtl::Reference<ScHeaderFooterTextObj> mxLeftText;
67 : rtl::Reference<ScHeaderFooterTextObj> mxCenterText;
68 : rtl::Reference<ScHeaderFooterTextObj> mxRightText;
69 :
70 : ScHeaderFooterContentObj(); // disabled
71 :
72 : public:
73 : ScHeaderFooterContentObj( const EditTextObject* pLeft,
74 : const EditTextObject* pCenter,
75 : const EditTextObject* pRight );
76 : virtual ~ScHeaderFooterContentObj();
77 :
78 : // for ScPageHFItem (using getImplementation)
79 : const EditTextObject* GetLeftEditObject() const;
80 : const EditTextObject* GetCenterEditObject() const;
81 : const EditTextObject* GetRightEditObject() const;
82 :
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;
90 :
91 : // XUnoTunnel
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;
95 :
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);
98 :
99 : // XServiceInfo
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;
106 : };
107 :
108 : // ScHeaderFooterTextData: shared data between sub objects of a ScHeaderFooterTextObj
109 :
110 : class ScHeaderFooterTextData : boost::noncopyable
111 : {
112 : private:
113 : EditTextObject* mpTextObj;
114 : rtl::Reference<ScHeaderFooterContentObj> rContentObj;
115 : sal_uInt16 nPart;
116 : ScEditEngineDefaulter* pEditEngine;
117 : SvxEditEngineForwarder* pForwarder;
118 : bool bDataValid;
119 :
120 : public:
121 : ScHeaderFooterTextData(
122 : rtl::Reference<ScHeaderFooterContentObj> const & rContent, sal_uInt16 nP, const EditTextObject* pTextObj);
123 : ~ScHeaderFooterTextData();
124 :
125 : // helper functions
126 : SvxTextForwarder* GetTextForwarder();
127 : void UpdateData();
128 : void UpdateData(EditEngine& rEditEngine);
129 37 : ScEditEngineDefaulter* GetEditEngine() { GetTextForwarder(); return pEditEngine; }
130 :
131 2210 : sal_uInt16 GetPart() const { return nPart; }
132 2210 : rtl::Reference<ScHeaderFooterContentObj> GetContentObj() const { return rContentObj; }
133 :
134 5769 : const EditTextObject* GetTextObject() const { return mpTextObj;}
135 : };
136 :
137 : /**
138 : * Each of these instances represent, the left, center or right part of the
139 : * header of footer of a page.
140 : *
141 : * ScHeaderFooterTextObj changes the text in a ScHeaderFooterContentObj.
142 : */
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 >
149 : {
150 : private:
151 : ScHeaderFooterTextData aTextData;
152 : rtl::Reference<SvxUnoText> mxUnoText;
153 :
154 : void CreateUnoText_Impl();
155 :
156 : public:
157 : ScHeaderFooterTextObj(
158 : rtl::Reference<ScHeaderFooterContentObj> const & rContent, sal_uInt16 nP, const EditTextObject* pTextObj);
159 : virtual ~ScHeaderFooterTextObj();
160 :
161 : const EditTextObject* GetTextObject() const;
162 : const SvxUnoText& GetUnoText();
163 :
164 : static void FillDummyFieldData( ScHeaderFieldData& rData );
165 :
166 : // XText
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,
171 : sal_Bool bAbsorb )
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;
178 :
179 : // XSimpleText
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;
195 :
196 : // XTextRange
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;
206 :
207 : // XTextRangeMover
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;
212 :
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;
216 :
217 : // XElementAccess
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;
221 :
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;
227 :
228 : // XServiceInfo
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;
235 : };
236 :
237 : // derived cursor objects for getImplementation and getText/getStart/getEnd
238 :
239 : //! uno3: SvxUnoTextCursor is not derived from XUnoTunnel, but should be (?)
240 :
241 : class ScCellTextCursor : public SvxUnoTextCursor
242 : {
243 : ScCellObj& rTextObj;
244 :
245 : public:
246 : ScCellTextCursor(const ScCellTextCursor& rOther);
247 : ScCellTextCursor(ScCellObj& rText);
248 : virtual ~ScCellTextCursor() throw();
249 :
250 0 : ScCellObj& GetCellObj() const { return rTextObj; }
251 :
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;
259 :
260 : // XUnoTunnel
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;
264 :
265 : static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
266 : static ScCellTextCursor* getImplementation(const css::uno::Reference< css::uno::XInterface>& rObj);
267 : };
268 :
269 : class ScHeaderFooterTextCursor : public SvxUnoTextCursor
270 : {
271 : private:
272 : ScHeaderFooterTextObj& rTextObj;
273 :
274 : public:
275 : ScHeaderFooterTextCursor(const ScHeaderFooterTextCursor& rOther);
276 : ScHeaderFooterTextCursor(ScHeaderFooterTextObj& rText);
277 : virtual ~ScHeaderFooterTextCursor() throw();
278 :
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;
286 :
287 : // XUnoTunnel
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;
291 :
292 : static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
293 : static ScHeaderFooterTextCursor* getImplementation(const css::uno::Reference<css::uno::XInterface>& rObj);
294 : };
295 :
296 : class ScDrawTextCursor : public SvxUnoTextCursor
297 : {
298 : private:
299 : com::sun::star::uno::Reference< com::sun::star::text::XText > xParentText;
300 :
301 : public:
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();
307 :
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;
315 :
316 : // XUnoTunnel
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;
320 :
321 : static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
322 : static ScDrawTextCursor* getImplementation(const css::uno::Reference<css::uno::XInterface>& rObj);
323 : };
324 :
325 : // ScAnnotationTextCursor isn't needed anymore - SvxUnoTextCursor is used instead
326 :
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)
329 :
330 : class ScSimpleEditSourceHelper
331 : {
332 : ScEditEngineDefaulter* pEditEngine;
333 : SvxEditEngineForwarder* pForwarder;
334 : ScSimpleEditSource* pOriginalSource;
335 :
336 : public:
337 : ScSimpleEditSourceHelper();
338 : ~ScSimpleEditSourceHelper();
339 :
340 0 : ScSimpleEditSource* GetOriginalSource() const { return pOriginalSource; }
341 0 : ScEditEngineDefaulter* GetEditEngine() const { return pEditEngine; }
342 : };
343 :
344 : class ScEditEngineTextObj : public ScSimpleEditSourceHelper, public SvxUnoText
345 : {
346 : public:
347 : ScEditEngineTextObj();
348 : virtual ~ScEditEngineTextObj() throw();
349 :
350 : void SetText( const EditTextObject& rTextObject );
351 : EditTextObject* CreateTextObject();
352 : };
353 :
354 : // ScCellTextData: shared data between sub objects of a cell text object
355 :
356 : class ScCellTextData : public SfxListener
357 : {
358 : protected:
359 : ScDocShell* pDocShell;
360 : ScAddress aCellPos;
361 : ScFieldEditEngine* pEditEngine;
362 : SvxEditEngineForwarder* pForwarder;
363 : ScCellEditSource* pOriginalSource;
364 : bool bDataValid;
365 : bool bInUpdate;
366 : bool bDirty;
367 : bool bDoUpdate;
368 :
369 : protected:
370 : virtual void GetCellText(const ScAddress& rCellPos, OUString& rText);
371 :
372 : public:
373 : ScCellTextData(ScDocShell* pDocSh, const ScAddress& rP);
374 : virtual ~ScCellTextData();
375 :
376 : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
377 :
378 : // helper functions for ScSharedCellEditSource:
379 : virtual SvxTextForwarder* GetTextForwarder();
380 : void UpdateData();
381 49 : ScFieldEditEngine* GetEditEngine() { GetTextForwarder(); return pEditEngine; }
382 :
383 : ScCellEditSource* GetOriginalSource(); // used as argument for SvxUnoText ctor
384 :
385 : // used for ScCellEditSource:
386 29 : ScDocShell* GetDocShell() const { return pDocShell; }
387 29 : const ScAddress& GetCellPos() const { return aCellPos; }
388 :
389 : void SetDirty(bool bValue) { bDirty = bValue; }
390 0 : bool IsDirty() const { return bDirty; }
391 0 : void SetDoUpdate(bool bValue) { bDoUpdate = bValue; }
392 : };
393 :
394 : class ScCellTextObj : public ScCellTextData, public SvxUnoText
395 : {
396 : public:
397 : ScCellTextObj(ScDocShell* pDocSh, const ScAddress& rP);
398 : virtual ~ScCellTextObj() throw();
399 : };
400 :
401 : #endif
402 :
403 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|