xref: /AOO41X/main/editeng/inc/editeng/unoedsrc.hxx (revision 4d7c9de063a797b8b4f3d45e3561e82ad1f8ef1f)
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;
GetNumStr(sal_uInt16) const222      virtual String       GetNumStr(sal_uInt16) const { return XubString();};
223     //IAccessible2 migration fix
SetUpdateModeForAcc(sal_Bool)224     virtual void                    SetUpdateModeForAcc( sal_Bool ) {};
GetUpdateModeForAcc() const225     virtual sal_Bool                    GetUpdateModeForAcc() const { return sal_True; };
226     /** Query the bounding rectangle of the given character
227 
228         @param nPara[0 .. n]
229         Index of paragraph to query the bounds in.  <p>The virtual
230         character after the last character of the represented text,
231         i.e. the one at position n is a special case.  Because it does
232         not represent an existing character its bounding box is
233         defined in relation to preceding characters.  It should be
234         rougly equivalent to the bounding box of some character when
235         inserted at the end of the text.  Its height typically being
236         the maximal height of all the characters in the text or the
237         height of the preceding character, its width being at least
238         one pixel so that the bounding box is not degenerate.<br>
239 
240         @param nIndex[0 .. m-1]
241         Index of character to query the bounds of
242 
243         @return rectangle in logical coordinates, relative to upper
244         left corner of text. The coordinates returned here are to be
245         interpreted in the map mode given by GetMapMode().
246     */
247     virtual Rectangle       GetCharBounds( sal_uInt16 nPara, sal_uInt16 nIndex ) const = 0;
248 
249     /** Query the bounding rectangle of the given paragraph
250 
251         @param nPara[0 .. n-1]
252         Index of paragraph to query the bounds of
253 
254         @return rectangle in logical coordinates, relative to upper
255         left corner of text. The coordinates returned here are to be
256         interpreted in the map mode given by GetMapMode().
257      */
258     virtual Rectangle       GetParaBounds( sal_uInt16 nPara ) const = 0;
259 
260     /** Query the map mode of the underlying EditEngine/Outliner
261 
262         @return the map mode used on the EditEngine/Outliner. The
263         values returned by GetParaBounds() and GetCharBounds() are to
264         be interpreted in this map mode, the point given to
265         GetIndexAtPoint() is interpreted in this map mode.
266      */
267     virtual MapMode         GetMapMode() const = 0;
268 
269     /** Query the reference output device of the underlying EditEngine/Outliner
270 
271         @return the OutputDevice used from the EditEngine/Outliner to
272         format the text. It should be used when performing e.g. font
273         calculations, since this is usually a printer with fonts and
274         resolution different from the screen.
275      */
276     virtual OutputDevice*   GetRefDevice() const = 0;
277 
278     /** Query paragraph and character index of the character at the
279         given point. Returns sal_True on success, sal_False otherwise
280 
281         @param rPoint
282         Point to query text position of. Is interpreted in logical
283         coordinates, relativ to the upper left corner of the text, and
284         in the map mode given by GetMapMode()
285 
286         @param rPara[0 .. n-1]
287         Index of paragraph the point is within
288 
289         @param rIndex[0 .. m-1]
290         Index of character the point is over
291 
292         @return sal_True, if the point is over any text and both rPara and rIndex are valid
293 
294      */
295     virtual sal_Bool        GetIndexAtPoint( const Point& rPoint, sal_uInt16& rPara, sal_uInt16& rIndex ) const = 0;
296 
297     /** Get the start and the end index of the word at the given index
298 
299         An index value on a word leads from the first character of
300         that word up to and including the last space before the next
301         word. The index values returned do not contain any leading or
302         trailing white-space. If the input indices are invalid,
303         sal_False is returned.
304 
305         @param nPara[0 .. n-1]
306         Index of paragraph to start the search in
307 
308         @param nIndex[0 .. m-1]
309         Index of character to query the search on
310 
311         @param rStart
312         Start index (in the same paragraph)
313 
314         @param rEnd
315         End index (in the same paragraph), this point to the last
316         character still contained in the query
317 
318         @return sal_True, if the result is non-empty
319      */
320     virtual sal_Bool        GetWordIndices( sal_uInt16 nPara, sal_uInt16 nIndex, sal_uInt16& rStart, sal_uInt16& rEnd ) const = 0;
321 
322     /** Query range of similar attributes
323 
324         Please note that the range returned is half-open: [nStartIndex,nEndIndex)
325 
326         @param nStartIndex
327         Herein, the start index of the range of similar attributes is returned
328 
329         @param nEndIndex
330         Herein, the end index (exclusive) of the range of similar attributes is returned
331 
332         @param nIndex
333         The character index from which the range of similar attributed characters is requested
334 
335         @return sal_True, if the range has been successfully determined
336      */
337 //    virtual sal_Bool      GetAttributeRun( sal_uInt16& nStartIndex, sal_uInt16& nEndIndex, sal_uInt16 nPara, sal_uInt16 nIndex ) const = 0;
338     virtual sal_Bool        GetAttributeRun( sal_uInt16& nStartIndex, sal_uInt16& nEndIndex, sal_uInt16 nPara, sal_uInt16 nIndex, sal_Bool bInCell = sal_False ) 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 
IsWrongSpelledWordAtPos(sal_Int32,sal_Int32)549     virtual sal_Bool IsWrongSpelledWordAtPos( sal_Int32, sal_Int32 ) { return sal_False; };
IsShapeParaFocusable()550     virtual sal_Bool IsShapeParaFocusable( ) { return sal_True; };
BreakParaWrongList(sal_Int32,sal_uInt16 &,sal_uInt16 &,sal_Int32)551     virtual sal_Bool BreakParaWrongList(sal_Int32, sal_uInt16&, sal_uInt16&, sal_Int32){ return sal_False; };
552 };
553 
554 #endif
555 
556