xref: /trunk/main/editeng/inc/editeng/unoedsrc.hxx (revision 9b8096d0)
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 //IAccessibility2 Implementation 2009-----
223      virtual String       GetNumStr(sal_uInt16) const { return XubString();};
224     //IAccessible2 migration fix
225     virtual void					SetUpdateModeForAcc( sal_Bool ) {};
226 	virtual sal_Bool					GetUpdateModeForAcc() const { return sal_True; };
227 //-----IAccessibility2 Implementation 2009
228     /** Query the bounding rectangle of the given character
229 
230         @param nPara[0 .. n]
231         Index of paragraph to query the bounds in.  <p>The virtual
232         character after the last character of the represented text,
233         i.e. the one at position n is a special case.  Because it does
234         not represent an existing character its bounding box is
235         defined in relation to preceding characters.  It should be
236         rougly equivalent to the bounding box of some character when
237         inserted at the end of the text.  Its height typically being
238         the maximal height of all the characters in the text or the
239         height of the preceding character, its width being at least
240         one pixel so that the bounding box is not degenerate.<br>
241 
242         @param nIndex[0 .. m-1]
243         Index of character to query the bounds of
244 
245         @return rectangle in logical coordinates, relative to upper
246         left corner of text. The coordinates returned here are to be
247         interpreted in the map mode given by GetMapMode().
248     */
249     virtual Rectangle		GetCharBounds( sal_uInt16 nPara, sal_uInt16 nIndex ) const = 0;
250 
251     /** Query the bounding rectangle of the given paragraph
252 
253         @param nPara[0 .. n-1]
254         Index of paragraph to query the bounds of
255 
256         @return rectangle in logical coordinates, relative to upper
257         left corner of text. The coordinates returned here are to be
258         interpreted in the map mode given by GetMapMode().
259      */
260     virtual Rectangle		GetParaBounds( sal_uInt16 nPara ) const = 0;
261 
262     /** Query the map mode of the underlying EditEngine/Outliner
263 
264         @return the map mode used on the EditEngine/Outliner. The
265         values returned by GetParaBounds() and GetCharBounds() are to
266         be interpreted in this map mode, the point given to
267         GetIndexAtPoint() is interpreted in this map mode.
268      */
269     virtual MapMode			GetMapMode() const = 0;
270 
271     /** Query the reference output device of the underlying EditEngine/Outliner
272 
273     	@return the OutputDevice used from the EditEngine/Outliner to
274     	format the text. It should be used when performing e.g. font
275     	calculations, since this is usually a printer with fonts and
276     	resolution different from the screen.
277      */
278 	virtual OutputDevice*	GetRefDevice() const = 0;
279 
280     /** Query paragraph and character index of the character at the
281         given point. Returns sal_True on success, sal_False otherwise
282 
283     	@param rPoint
284         Point to query text position of. Is interpreted in logical
285         coordinates, relativ to the upper left corner of the text, and
286         in the map mode given by GetMapMode()
287 
288         @param rPara[0 .. n-1]
289         Index of paragraph the point is within
290 
291         @param rIndex[0 .. m-1]
292         Index of character the point is over
293 
294         @return sal_True, if the point is over any text and both rPara and rIndex are valid
295 
296      */
297     virtual sal_Bool		GetIndexAtPoint( const Point& rPoint, sal_uInt16& rPara, sal_uInt16& rIndex ) const = 0;
298 
299     /** Get the start and the end index of the word at the given index
300 
301         An index value on a word leads from the first character of
302         that word up to and including the last space before the next
303         word. The index values returned do not contain any leading or
304         trailing white-space. If the input indices are invalid,
305         sal_False is returned.
306 
307         @param nPara[0 .. n-1]
308         Index of paragraph to start the search in
309 
310         @param nIndex[0 .. m-1]
311         Index of character to query the search on
312 
313         @param rStart
314         Start index (in the same paragraph)
315 
316         @param rEnd
317         End index (in the same paragraph), this point to the last
318         character still contained in the query
319 
320         @return sal_True, if the result is non-empty
321      */
322     virtual sal_Bool		GetWordIndices( sal_uInt16 nPara, sal_uInt16 nIndex, sal_uInt16& rStart, sal_uInt16& rEnd ) const = 0;
323 
324     /** Query range of similar attributes
325 
326     	Please note that the range returned is half-open: [nStartIndex,nEndIndex)
327 
328     	@param nStartIndex
329         Herein, the start index of the range of similar attributes is returned
330 
331     	@param nEndIndex
332         Herein, the end index (exclusive) of the range of similar attributes is returned
333 
334         @param nIndex
335         The character index from which the range of similar attributed characters is requested
336 
337         @return sal_True, if the range has been successfully determined
338      */
339 	//IAccessibility2 Implementation 2009-----
340 //    virtual sal_Bool 		GetAttributeRun( sal_uInt16& nStartIndex, sal_uInt16& nEndIndex, sal_uInt16 nPara, sal_uInt16 nIndex ) const = 0;
341     virtual sal_Bool 		GetAttributeRun( sal_uInt16& nStartIndex, sal_uInt16& nEndIndex, sal_uInt16 nPara, sal_uInt16 nIndex, sal_Bool bInCell = sal_False ) const = 0;
342 	//-----IAccessibility2 Implementation 2009
343 
344     /** Query number of lines in the formatted paragraph
345 
346         @param nPara[0 .. n-1]
347         Index of paragraph to query number of lines in
348 
349         @return number of lines in given paragraph
350 
351      */
352     virtual sal_uInt16			GetLineCount( sal_uInt16 nPara ) const = 0;
353 
354     /** Query line length
355 
356         @param nPara[0 .. n-1]
357         Index of paragraph to query line length in
358 
359         @param nLine[0 .. m-1]
360         Index of line in paragraph to query line length of
361 
362      */
363     virtual sal_uInt16			GetLineLen( sal_uInt16 nPara, sal_uInt16 nLine ) const = 0;
364 
365     /** Query bounds of line in paragraph
366 
367         @param rStart [output param; 0 .. text_len]
368         The index in the paragraph text that belongs to the chara at the start of the line
369 
370         @param rEnd [output param; 0 .. text_len]
371         The index in the paragraph text that follows the last chara in the line
372 
373         @param nParagraph[0 .. n-1]
374         Index of paragraph to query line length in
375 
376         @param nLine[0 .. m-1]
377         Index of line in paragraph to query line length of
378 
379      */
380     virtual void            GetLineBoundaries( /*out*/sal_uInt16 &rStart, /*out*/sal_uInt16 &rEnd, sal_uInt16 nParagraph, sal_uInt16 nLine ) const = 0;
381 
382     /** Query the line number for a index in the paragraphs text
383 
384         @param nPara[0 .. n-1]
385         Index of paragraph to query line length in
386 
387         @param nIndex[0 .. m-1]
388         Index of of the chara in the paragraph text
389 
390         @returns [0 .. k-1]
391         The line number of the chara in the paragraph
392      */
393     virtual sal_uInt16          GetLineNumberAtIndex( sal_uInt16 nPara, sal_uInt16 nIndex ) const = 0;
394 
395     /** Delete given text range and reformat text
396 
397     	@param rSelection
398         The text range to be deleted
399 
400         @return sal_True if text has been successfully deleted
401      */
402     virtual sal_Bool		Delete( const ESelection& rSelection ) = 0;
403 
404      /** Insert/Replace given text in given range and reformat text
405 
406      	 @param rText
407          Text to insert/replace
408 
409          @param rSel
410          Selection where text should be replaced. The empty selection inserts
411 
412          @return sal_True if text has been successfully inserted
413       */
414 	virtual sal_Bool		InsertText( const String& rText, const ESelection& rSel ) = 0;
415 
416      /** Updates the formatting
417 
418      	 @see EditEngine::QuickFormatDoc() for details
419 
420          @return sal_True if text have been successfully reformatted
421       */
422     virtual sal_Bool		QuickFormatDoc( sal_Bool bFull=sal_False ) = 0;
423 
424     /** Get the outline depth of given paragraph
425 
426     	@param nPara
427         Index of the paragraph to query the depth of
428 
429         @return the outline level of the given paragraph. The range is
430         [0,n), where n is the maximal outline level.
431      */
432     virtual sal_Int16		GetDepth( sal_uInt16 nPara ) const = 0;
433 
434     /** Set the outline depth of given paragraph
435 
436     	@param nPara
437         Index of the paragraph to set the depth of
438 
439         @param nNewDepth
440         The depth to set on the given paragraph. The range is
441         [0,n), where n is the maximal outline level.
442 
443         @return sal_True, if depth could be successfully set. Reasons for
444         failure are e.g. the text does not support outline level
445         (EditEngine), or the depth range is exceeded.
446      */
447     virtual sal_Bool		SetDepth( sal_uInt16 nPara, sal_Int16 nNewDepth ) = 0;
448 
449     virtual sal_Int16 GetNumberingStartValue( sal_uInt16 nPara );
450     virtual void SetNumberingStartValue( sal_uInt16 nPara, sal_Int16 nNumberingStartValue );
451 
452     virtual sal_Bool IsParaIsNumberingRestart( sal_uInt16 nPara );
453     virtual void SetParaIsNumberingRestart( sal_uInt16 nPara, sal_Bool bParaIsNumberingRestart );
454 };
455 
456 /** Encapsulates the document view for the purpose of unified
457     EditEngine/Outliner access.
458 
459 	This one has to be different from the SvxEditViewForwarder, since
460 	the latter is only valid in edit mode.
461  */
462 class EDITENG_DLLPUBLIC SvxViewForwarder
463 {
464 public:
465 	virtual				~SvxViewForwarder();
466 
467     /** Query state of forwarder
468 
469     	@return sal_False, if no longer valid
470      */
471 	virtual sal_Bool		IsValid() const = 0;
472 
473     /** Query visible area of the view containing the text
474 
475     	@return the visible rectangle of the text, i.e. the part of
476     	the EditEngine or Outliner that is currently on screen. The
477     	values are already in screen coordinates (pixel), and have to
478     	be relative to the EditEngine/Outliner's upper left corner.
479      */
480     virtual Rectangle	GetVisArea() const = 0;
481 
482     /** Convert from logical, EditEngine-relative coordinates to screen coordinates
483 
484     	@param rPoint
485         Point in logical, EditEngine-relative coordinates.
486 
487     	@param rMapMode
488         The map mode to interpret the coordinates in.
489 
490         @return the point in screen coordinates
491      */
492     virtual Point		LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const = 0;
493 
494     /** Convert from screen to logical, EditEngine-relative coordinates
495 
496     	@param rPoint
497         Point in screen coordinates
498 
499     	@param rMapMode
500         The map mode to interpret the coordinates in.
501 
502         @return the point in logical coordinates.
503      */
504     virtual Point		PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const = 0;
505 
506 };
507 
508 
509 /** Encapsulates EditView and OutlinerView for the purpose of unified
510     EditEngine/Outliner access
511  */
512 class SvxEditViewForwarder : public SvxViewForwarder
513 {
514 public:
515 
516     /** Query current selection.
517 
518     	@param rSelection
519         Contains the current selection after method call
520 
521     	@return sal_False, if there is no view or no selection (the empty selection _is_ a selection)
522 
523      */
524     virtual sal_Bool GetSelection( ESelection& rSelection ) const = 0;
525 
526     /** Set selection in view.
527 
528     	@param rSelection
529         The selection to set
530 
531     	@return sal_False, if there is no view or selection is invalid
532      */
533     virtual sal_Bool SetSelection( const ESelection& rSelection ) = 0;
534 
535     /** Copy current selection to clipboard.
536 
537     	@return sal_False if no selection or no view (the empty selection _is_ a selection)
538      */
539     virtual sal_Bool Copy() = 0;
540 
541     /** Cut current selection to clipboard.
542 
543     	@eturn sal_False if no selection or no view (the empty selection _is_ a selection)
544      */
545     virtual sal_Bool Cut() = 0;
546 
547     /** Paste clipboard into current selection.
548 
549     	@return sal_False if no view or no selection (the empty selection _is_ a selection)
550      */
551     virtual sal_Bool Paste() = 0;
552 
553 //IAccessibility2 Implementation 2009-----
554     virtual sal_Bool IsWrongSpelledWordAtPos( sal_Int32, sal_Int32 ) { return sal_False; };
555     virtual sal_Bool IsShapeParaFocusable( ) { return sal_True; };
556     virtual sal_Bool BreakParaWrongList(sal_Int32, sal_uInt16&, sal_uInt16&, sal_Int32){ return sal_False; };
557 //-----IAccessibility2 Implementation 2009
558 };
559 
560 #endif
561 
562