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