xref: /trunk/main/editeng/inc/editeng/unoedsrc.hxx (revision cdf0e10c)
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 _SVX_UNOEDSRC_HXX
29 #define _SVX_UNOEDSRC_HXX
30 
31 #include <com/sun/star/accessibility/TextSegment.hpp>
32 
33 #include <tools/solar.h>
34 #include <i18npool/lang.h>
35 #include <tools/link.hxx>
36 #include <tools/gen.hxx>
37 #include <vcl/mapmod.hxx>
38 #include <tools/string.hxx>
39 #ifndef _SV_COLOR_HXX //autogen
40 #include <tools/color.hxx>
41 #endif
42 #include <svl/poolitem.hxx>
43 #include <svl/itempool.hxx>
44 #include "editeng/editengdllapi.h"
45 
46 #include <list>
47 
48 struct ESelection;
49 struct EFieldInfo;
50 struct EBulletInfo;
51 class OutputDevice;
52 class String;
53 class SfxItemSet;
54 class SvUShorts;
55 class SvxTextForwarder;
56 class SvxViewForwarder;
57 class SvxEditViewForwarder;
58 class SvxFieldItem;
59 class SfxBroadcaster;
60 class EECharAttribArray;
61 class SvxUnoTextRangeBase;
62 
63 typedef std::list< SvxUnoTextRangeBase* > SvxUnoTextRangeBaseList;
64 
65 /**	Wrapper class for unified EditEngine/Outliner access
66 
67 	This class wraps a textual object, which might or might not
68 	contain an EditEngine/Outliner. Is used e.g. for filling an
69 	EditEngine with the content of a cell, note page or page template.
70 */
71 class EDITENG_DLLPUBLIC SvxEditSource
72 {
73 public:
74 	virtual					~SvxEditSource();
75 
76     /// Returns a new reference to the same object. This is a shallow copy
77 	virtual SvxEditSource*		Clone() const = 0;
78 
79     /** Query the text forwarder
80 
81         @return the text forwarder, or NULL if the underlying object is dead
82      */
83 	virtual SvxTextForwarder*	GetTextForwarder() = 0;
84 
85     /** Query the view forwarder
86 
87         @return the view forwarder, or NULL if the underlying object
88         is dead, or if no view is available
89 
90         @derive default implementation provided, overriding is optional
91      */
92  	virtual SvxViewForwarder*	GetViewForwarder();
93 
94     /** Query the edit view forwarder
95 
96     	@param bCreate
97         Determines whether an EditView should be created, if there is
98         none active. If set to sal_True, and the underlying object is
99         not in EditMode, the text forwarder changes and the object is
100         set to EditMode.
101 
102         @return the edit view forwarder, or NULL if the underlying
103         object is dead, or if no view is available (if bCreate is
104         sal_False, NULL is also returned if the object is not in
105         EditMode)
106 
107         @derive default implementation provided, overriding is optional
108 
109         @attention If this method is called with bCreate equal to
110         sal_True, all previously returned text forwarder can become
111         invalid
112      */
113  	virtual SvxEditViewForwarder*	GetEditViewForwarder( sal_Bool bCreate = sal_False );
114 
115     /// Write back data to model
116 	virtual void				UpdateData() = 0;
117 
118     /** Returns broadcaster the underlying edit engine's events are sent from
119 
120         @derive default implementation provided, overriding is optional
121      */
122     virtual SfxBroadcaster&		GetBroadcaster() const;
123 
124 	/** adds the given SvxUnoTextRangeBase to the text object
125 		capsulated by this SvxEditSource. This allows the text
126 		object to inform all created text ranges about changes
127 		and also allows to re use already created instances.
128 		All SvxUnoTextRangeBase must remove itself with
129 		removeRange() before theire deleted. */
130 	virtual void addRange( SvxUnoTextRangeBase* pNewRange );
131 
132 	/** removes the given SvxUnoTextRangeBase from the text
133 		object capsulated by this SvxEditSource. This text range
134 		will not be informed any longer of changes on the underlying
135 		text and will also not re used anymore. */
136 	virtual void removeRange( SvxUnoTextRangeBase* pOldRange );
137 
138 	/** returns a const list of all text ranges that are registered
139 		for the underlying text object. */
140 	virtual const SvxUnoTextRangeBaseList& getRanges() const;
141 };
142 
143 
144 /**	Contains an EditEngine or an Outliner and unifies access to them.
145 
146 	The EditEngine-UNO objects use this class only. To reflect changes
147 	not only in the EditEngine, but also in the model data, call
148 	SvxEditSource::UpdateData(). This copies back the data to the model's
149 	EditTextObject/OutlinerParaObject.
150  */
151 class EDITENG_DLLPUBLIC SvxTextForwarder
152 {
153 public:
154 	virtual				~SvxTextForwarder();
155 
156 	virtual sal_uInt16		GetParagraphCount() const = 0;
157 	virtual sal_uInt16		GetTextLen( sal_uInt16 nParagraph ) const = 0;
158 	virtual String		GetText( const ESelection& rSel ) const = 0;
159 	virtual SfxItemSet	GetAttribs( const ESelection& rSel, sal_Bool bOnlyHardAttrib = 0 ) const = 0;
160 	virtual	SfxItemSet  GetParaAttribs( sal_uInt16 nPara ) const = 0;
161 	virtual void		SetParaAttribs( sal_uInt16 nPara, const SfxItemSet& rSet ) = 0;
162     virtual void        RemoveAttribs( const ESelection& rSelection, sal_Bool bRemoveParaAttribs, sal_uInt16 nWhich ) = 0;
163 	virtual void		GetPortions( sal_uInt16 nPara, SvUShorts& rList ) const = 0;
164 
165 	virtual sal_uInt16		GetItemState( const ESelection& rSel, sal_uInt16 nWhich ) const = 0;
166 	virtual sal_uInt16		GetItemState( sal_uInt16 nPara, sal_uInt16 nWhich ) const = 0;
167 
168 	virtual void		QuickInsertText( const String& rText, const ESelection& rSel ) = 0;
169 	virtual void		QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel ) = 0;
170 	virtual void		QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel ) = 0;
171 	virtual void		QuickInsertLineBreak( const ESelection& rSel ) = 0;
172 
173 	virtual XubString    CalcFieldValue( const SvxFieldItem& rField, sal_uInt16 nPara, sal_uInt16 nPos, Color*& rpTxtColor, Color*& rpFldColor ) = 0;
174 	virtual void 	     FieldClicked( const SvxFieldItem& rField, sal_uInt16 nPara, xub_StrLen nPos ) = 0;
175 
176 	virtual SfxItemPool* GetPool() const = 0;
177 
178     virtual const SfxItemSet*   GetEmptyItemSetPtr() = 0;
179 
180     // implementation functions for XParagraphAppend and XTextPortionAppend
181     virtual void        AppendParagraph() = 0;
182     virtual xub_StrLen  AppendTextPortion( sal_uInt16 nPara, const String &rText, const SfxItemSet &rSet ) = 0;
183 
184     // XTextCopy
185     virtual void        CopyText(const SvxTextForwarder& rSource) = 0;
186 
187     /** Query state of forwarder
188 
189     	@return sal_False, if no longer valid
190      */
191 	virtual sal_Bool			IsValid() const = 0;
192 
193     /** Query language of character at given position on the underlying edit engine
194 
195         @param nPara[0 .. n-1]
196         Index of paragraph to query language in
197 
198         @param nIndex[0 .. m-1]
199         Index of character to query language of
200      */
201     virtual LanguageType	GetLanguage( sal_uInt16 nPara, sal_uInt16 nIndex ) const = 0;
202 
203     /** Query number of fields in the underlying edit engine
204 
205         @param nPara[0 .. n-1]
206         Index of paragraph to query field number in
207      */
208     virtual sal_uInt16			GetFieldCount( sal_uInt16 nPara ) const = 0;
209 
210     /** Query information for given field number in the underlying edit engine
211 
212         @param nPara[0 .. n-1]
213         Index of paragraph to query field info in
214 
215         @param nField[0 .. m-1]
216         Index of field to query information of
217      */
218     virtual EFieldInfo		GetFieldInfo( sal_uInt16 nPara, sal_uInt16 nField ) const = 0;
219 
220     /** Query information regarding bullets for given paragraph on the underlying edit engine
221 
222         @param nPara[0 .. n-1]
223         Index of paragraph to query bullet info on
224      */
225     virtual EBulletInfo     GetBulletInfo( sal_uInt16 nPara ) const = 0;
226 
227     /** Query the bounding rectangle of the given character
228 
229         @param nPara[0 .. n]
230         Index of paragraph to query the bounds in.  <p>The virtual
231         character after the last character of the represented text,
232         i.e. the one at position n is a special case.  Because it does
233         not represent an existing character its bounding box is
234         defined in relation to preceding characters.  It should be
235         rougly equivalent to the bounding box of some character when
236         inserted at the end of the text.  Its height typically being
237         the maximal height of all the characters in the text or the
238         height of the preceding character, its width being at least
239         one pixel so that the bounding box is not degenerate.<br>
240 
241         @param nIndex[0 .. m-1]
242         Index of character to query the bounds of
243 
244         @return rectangle in logical coordinates, relative to upper
245         left corner of text. The coordinates returned here are to be
246         interpreted in the map mode given by GetMapMode().
247     */
248     virtual Rectangle		GetCharBounds( sal_uInt16 nPara, sal_uInt16 nIndex ) const = 0;
249 
250     /** Query the bounding rectangle of the given paragraph
251 
252         @param nPara[0 .. n-1]
253         Index of paragraph to query the bounds of
254 
255         @return rectangle in logical coordinates, relative to upper
256         left corner of text. The coordinates returned here are to be
257         interpreted in the map mode given by GetMapMode().
258      */
259     virtual Rectangle		GetParaBounds( sal_uInt16 nPara ) const = 0;
260 
261     /** Query the map mode of the underlying EditEngine/Outliner
262 
263         @return the map mode used on the EditEngine/Outliner. The
264         values returned by GetParaBounds() and GetCharBounds() are to
265         be interpreted in this map mode, the point given to
266         GetIndexAtPoint() is interpreted in this map mode.
267      */
268     virtual MapMode			GetMapMode() const = 0;
269 
270     /** Query the reference output device of the underlying EditEngine/Outliner
271 
272     	@return the OutputDevice used from the EditEngine/Outliner to
273     	format the text. It should be used when performing e.g. font
274     	calculations, since this is usually a printer with fonts and
275     	resolution different from the screen.
276      */
277 	virtual OutputDevice*	GetRefDevice() const = 0;
278 
279     /** Query paragraph and character index of the character at the
280         given point. Returns sal_True on success, sal_False otherwise
281 
282     	@param rPoint
283         Point to query text position of. Is interpreted in logical
284         coordinates, relativ to the upper left corner of the text, and
285         in the map mode given by GetMapMode()
286 
287         @param rPara[0 .. n-1]
288         Index of paragraph the point is within
289 
290         @param rIndex[0 .. m-1]
291         Index of character the point is over
292 
293         @return sal_True, if the point is over any text and both rPara and rIndex are valid
294 
295      */
296     virtual sal_Bool		GetIndexAtPoint( const Point& rPoint, sal_uInt16& rPara, sal_uInt16& rIndex ) const = 0;
297 
298     /** Get the start and the end index of the word at the given index
299 
300         An index value on a word leads from the first character of
301         that word up to and including the last space before the next
302         word. The index values returned do not contain any leading or
303         trailing white-space. If the input indices are invalid,
304         sal_False is returned.
305 
306         @param nPara[0 .. n-1]
307         Index of paragraph to start the search in
308 
309         @param nIndex[0 .. m-1]
310         Index of character to query the search on
311 
312         @param rStart
313         Start index (in the same paragraph)
314 
315         @param rEnd
316         End index (in the same paragraph), this point to the last
317         character still contained in the query
318 
319         @return sal_True, if the result is non-empty
320      */
321     virtual sal_Bool		GetWordIndices( sal_uInt16 nPara, sal_uInt16 nIndex, sal_uInt16& rStart, sal_uInt16& rEnd ) const = 0;
322 
323     /** Query range of similar attributes
324 
325     	Please note that the range returned is half-open: [nStartIndex,nEndIndex)
326 
327     	@param nStartIndex
328         Herein, the start index of the range of similar attributes is returned
329 
330     	@param nEndIndex
331         Herein, the end index (exclusive) of the range of similar attributes is returned
332 
333         @param nIndex
334         The character index from which the range of similar attributed characters is requested
335 
336         @return sal_True, if the range has been successfully determined
337      */
338     virtual sal_Bool 		GetAttributeRun( sal_uInt16& nStartIndex, sal_uInt16& nEndIndex, sal_uInt16 nPara, sal_uInt16 nIndex ) const = 0;
339 
340     /** Query number of lines in the formatted paragraph
341 
342         @param nPara[0 .. n-1]
343         Index of paragraph to query number of lines in
344 
345         @return number of lines in given paragraph
346 
347      */
348     virtual sal_uInt16			GetLineCount( sal_uInt16 nPara ) const = 0;
349 
350     /** Query line length
351 
352         @param nPara[0 .. n-1]
353         Index of paragraph to query line length in
354 
355         @param nLine[0 .. m-1]
356         Index of line in paragraph to query line length of
357 
358      */
359     virtual sal_uInt16			GetLineLen( sal_uInt16 nPara, sal_uInt16 nLine ) const = 0;
360 
361     /** Query bounds of line in paragraph
362 
363         @param rStart [output param; 0 .. text_len]
364         The index in the paragraph text that belongs to the chara at the start of the line
365 
366         @param rEnd [output param; 0 .. text_len]
367         The index in the paragraph text that follows the last chara in the line
368 
369         @param nParagraph[0 .. n-1]
370         Index of paragraph to query line length in
371 
372         @param nLine[0 .. m-1]
373         Index of line in paragraph to query line length of
374 
375      */
376     virtual void            GetLineBoundaries( /*out*/sal_uInt16 &rStart, /*out*/sal_uInt16 &rEnd, sal_uInt16 nParagraph, sal_uInt16 nLine ) const = 0;
377 
378     /** Query the line number for a index in the paragraphs text
379 
380         @param nPara[0 .. n-1]
381         Index of paragraph to query line length in
382 
383         @param nIndex[0 .. m-1]
384         Index of of the chara in the paragraph text
385 
386         @returns [0 .. k-1]
387         The line number of the chara in the paragraph
388      */
389     virtual sal_uInt16          GetLineNumberAtIndex( sal_uInt16 nPara, sal_uInt16 nIndex ) const = 0;
390 
391     /** Delete given text range and reformat text
392 
393     	@param rSelection
394         The text range to be deleted
395 
396         @return sal_True if text has been successfully deleted
397      */
398     virtual sal_Bool		Delete( const ESelection& rSelection ) = 0;
399 
400      /** Insert/Replace given text in given range and reformat text
401 
402      	 @param rText
403          Text to insert/replace
404 
405          @param rSel
406          Selection where text should be replaced. The empty selection inserts
407 
408          @return sal_True if text has been successfully inserted
409       */
410 	virtual sal_Bool		InsertText( const String& rText, const ESelection& rSel ) = 0;
411 
412      /** Updates the formatting
413 
414      	 @see EditEngine::QuickFormatDoc() for details
415 
416          @return sal_True if text have been successfully reformatted
417       */
418     virtual sal_Bool		QuickFormatDoc( sal_Bool bFull=sal_False ) = 0;
419 
420     /** Get the outline depth of given paragraph
421 
422     	@param nPara
423         Index of the paragraph to query the depth of
424 
425         @return the outline level of the given paragraph. The range is
426         [0,n), where n is the maximal outline level.
427      */
428     virtual sal_Int16		GetDepth( sal_uInt16 nPara ) const = 0;
429 
430     /** Set the outline depth of given paragraph
431 
432     	@param nPara
433         Index of the paragraph to set the depth of
434 
435         @param nNewDepth
436         The depth to set on the given paragraph. The range is
437         [0,n), where n is the maximal outline level.
438 
439         @return sal_True, if depth could be successfully set. Reasons for
440         failure are e.g. the text does not support outline level
441         (EditEngine), or the depth range is exceeded.
442      */
443     virtual sal_Bool		SetDepth( sal_uInt16 nPara, sal_Int16 nNewDepth ) = 0;
444 
445     virtual sal_Int16 GetNumberingStartValue( sal_uInt16 nPara );
446     virtual void SetNumberingStartValue( sal_uInt16 nPara, sal_Int16 nNumberingStartValue );
447 
448     virtual sal_Bool IsParaIsNumberingRestart( sal_uInt16 nPara );
449     virtual void SetParaIsNumberingRestart( sal_uInt16 nPara, sal_Bool bParaIsNumberingRestart );
450 };
451 
452 /** Encapsulates the document view for the purpose of unified
453     EditEngine/Outliner access.
454 
455 	This one has to be different from the SvxEditViewForwarder, since
456 	the latter is only valid in edit mode.
457  */
458 class EDITENG_DLLPUBLIC SvxViewForwarder
459 {
460 public:
461 	virtual				~SvxViewForwarder();
462 
463     /** Query state of forwarder
464 
465     	@return sal_False, if no longer valid
466      */
467 	virtual sal_Bool		IsValid() const = 0;
468 
469     /** Query visible area of the view containing the text
470 
471     	@return the visible rectangle of the text, i.e. the part of
472     	the EditEngine or Outliner that is currently on screen. The
473     	values are already in screen coordinates (pixel), and have to
474     	be relative to the EditEngine/Outliner's upper left corner.
475      */
476     virtual Rectangle	GetVisArea() const = 0;
477 
478     /** Convert from logical, EditEngine-relative coordinates to screen coordinates
479 
480     	@param rPoint
481         Point in logical, EditEngine-relative coordinates.
482 
483     	@param rMapMode
484         The map mode to interpret the coordinates in.
485 
486         @return the point in screen coordinates
487      */
488     virtual Point		LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const = 0;
489 
490     /** Convert from screen to logical, EditEngine-relative coordinates
491 
492     	@param rPoint
493         Point in screen coordinates
494 
495     	@param rMapMode
496         The map mode to interpret the coordinates in.
497 
498         @return the point in logical coordinates.
499      */
500     virtual Point		PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const = 0;
501 
502 };
503 
504 
505 /** Encapsulates EditView and OutlinerView for the purpose of unified
506     EditEngine/Outliner access
507  */
508 class SvxEditViewForwarder : public SvxViewForwarder
509 {
510 public:
511 
512     /** Query current selection.
513 
514     	@param rSelection
515         Contains the current selection after method call
516 
517     	@return sal_False, if there is no view or no selection (the empty selection _is_ a selection)
518 
519      */
520     virtual sal_Bool GetSelection( ESelection& rSelection ) const = 0;
521 
522     /** Set selection in view.
523 
524     	@param rSelection
525         The selection to set
526 
527     	@return sal_False, if there is no view or selection is invalid
528      */
529     virtual sal_Bool SetSelection( const ESelection& rSelection ) = 0;
530 
531     /** Copy current selection to clipboard.
532 
533     	@return sal_False if no selection or no view (the empty selection _is_ a selection)
534      */
535     virtual sal_Bool Copy() = 0;
536 
537     /** Cut current selection to clipboard.
538 
539     	@eturn sal_False if no selection or no view (the empty selection _is_ a selection)
540      */
541     virtual sal_Bool Cut() = 0;
542 
543     /** Paste clipboard into current selection.
544 
545     	@return sal_False if no view or no selection (the empty selection _is_ a selection)
546      */
547     virtual sal_Bool Paste() = 0;
548 
549 };
550 
551 #endif
552 
553