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