summaryrefslogtreecommitdiff
path: root/svx/inc/svx/unoedsrc.hxx
blob: b60ec2d58640fc6ecb49bc4202a57479ef904d7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * 
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: unoedsrc.hxx,v $
 * $Revision: 1.6 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _SVX_UNOEDSRC_HXX
#define _SVX_UNOEDSRC_HXX

#include <com/sun/star/accessibility/TextSegment.hpp>

#include <tools/solar.h>
#include <i18npool/lang.h>
#include <tools/link.hxx>
#include <tools/gen.hxx>
#include <vcl/mapmod.hxx>
#include <tools/string.hxx>
#ifndef _SV_COLOR_HXX //autogen
#include <tools/color.hxx>
#endif
#include <svl/poolitem.hxx>
#include <svl/itempool.hxx>
#include "svx/svxdllapi.h"

#include <list>

struct ESelection;
struct EFieldInfo;
struct EBulletInfo;
class OutputDevice;
class String;
class SfxItemSet;
class SvUShorts;
class SvxTextForwarder;
class SvxViewForwarder;
class SvxEditViewForwarder;
class SvxFieldItem;
class SfxBroadcaster;
class EECharAttribArray;
class SvxUnoTextRangeBase;

typedef std::list< SvxUnoTextRangeBase* > SvxUnoTextRangeBaseList;

/**	Wrapper class for unified EditEngine/Outliner access

    This class wraps a textual object, which might or might not
    contain an EditEngine/Outliner. Is used e.g. for filling an
    EditEngine with the content of a cell, note page or page template.
*/
class SVX_DLLPUBLIC SvxEditSource
{
public:
    virtual					~SvxEditSource();

    /// Returns a new reference to the same object. This is a shallow copy
    virtual SvxEditSource*		Clone() const = 0;

    /** Query the text forwarder

        @return the text forwarder, or NULL if the underlying object is dead
     */
    virtual SvxTextForwarder*	GetTextForwarder() = 0;

    /** Query the view forwarder

        @return the view forwarder, or NULL if the underlying object
        is dead, or if no view is available

        @derive default implementation provided, overriding is optional
     */
     virtual SvxViewForwarder*	GetViewForwarder();

    /** Query the edit view forwarder

        @param bCreate
        Determines whether an EditView should be created, if there is
        none active. If set to sal_True, and the underlying object is
        not in EditMode, the text forwarder changes and the object is
        set to EditMode.

        @return the edit view forwarder, or NULL if the underlying
        object is dead, or if no view is available (if bCreate is
        sal_False, NULL is also returned if the object is not in
        EditMode)

        @derive default implementation provided, overriding is optional

        @attention If this method is called with bCreate equal to
        sal_True, all previously returned text forwarder can become
        invalid
     */
     virtual SvxEditViewForwarder*	GetEditViewForwarder( sal_Bool bCreate = sal_False );

    /// Write back data to model
    virtual void				UpdateData() = 0;

    /** Returns broadcaster the underlying edit engine's events are sent from

        @derive default implementation provided, overriding is optional
     */
    virtual SfxBroadcaster&		GetBroadcaster() const;

    /** adds the given SvxUnoTextRangeBase to the text object
        capsulated by this SvxEditSource. This allows the text
        object to inform all created text ranges about changes
        and also allows to re use already created instances.
        All SvxUnoTextRangeBase must remove itself with
        removeRange() before theire deleted. */
    virtual void addRange( SvxUnoTextRangeBase* pNewRange );

    /** removes the given SvxUnoTextRangeBase from the text
        object capsulated by this SvxEditSource. This text range
        will not be informed any longer of changes on the underlying
        text and will also not re used anymore. */
    virtual void removeRange( SvxUnoTextRangeBase* pOldRange );

    /** returns a const list of all text ranges that are registered
        for the underlying text object. */
    virtual const SvxUnoTextRangeBaseList& getRanges() const;
};


/**	Contains an EditEngine or an Outliner and unifies access to them.

    The EditEngine-UNO objects use this class only. To reflect changes
    not only in the EditEngine, but also in the model data, call
    SvxEditSource::UpdateData(). This copies back the data to the model's
    EditTextObject/OutlinerParaObject.
 */
class SVX_DLLPUBLIC SvxTextForwarder
{
public:
    virtual				~SvxTextForwarder();

    virtual USHORT		GetParagraphCount() const = 0;
    virtual USHORT		GetTextLen( USHORT nParagraph ) const = 0;
    virtual String		GetText( const ESelection& rSel ) const = 0;
    virtual SfxItemSet	GetAttribs( const ESelection& rSel, BOOL bOnlyHardAttrib = 0 ) const = 0;
    virtual	SfxItemSet  GetParaAttribs( USHORT nPara ) const = 0;
    virtual void		SetParaAttribs( USHORT nPara, const SfxItemSet& rSet ) = 0;
    virtual void        RemoveAttribs( const ESelection& rSelection, sal_Bool bRemoveParaAttribs, sal_uInt16 nWhich ) = 0;
    virtual void		GetPortions( USHORT nPara, SvUShorts& rList ) const = 0;

    virtual USHORT		GetItemState( const ESelection& rSel, USHORT nWhich ) const = 0;
    virtual USHORT		GetItemState( USHORT nPara, USHORT nWhich ) const = 0;

    virtual void		QuickInsertText( const String& rText, const ESelection& rSel ) = 0;
    virtual void		QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel ) = 0;
    virtual void		QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel ) = 0;
    virtual void		QuickInsertLineBreak( const ESelection& rSel ) = 0;

    virtual XubString    CalcFieldValue( const SvxFieldItem& rField, USHORT nPara, USHORT nPos, Color*& rpTxtColor, Color*& rpFldColor ) = 0;

    virtual SfxItemPool* GetPool() const = 0;

    virtual const SfxItemSet*   GetEmptyItemSetPtr() = 0;
 
    // implementation functions for XParagraphAppend and XTextPortionAppend
    virtual void        AppendParagraph() = 0;
    virtual xub_StrLen  AppendTextPortion( USHORT nPara, const String &rText, const SfxItemSet &rSet ) = 0;
    
    // XTextCopy
    virtual void        CopyText(const SvxTextForwarder& rSource) = 0; 

    /** Query state of forwarder

        @return sal_False, if no longer valid
     */
    virtual BOOL			IsValid() const = 0;

    /** Query language of character at given position on the underlying edit engine

        @param nPara[0 .. n-1]
        Index of paragraph to query language in

        @param nIndex[0 .. m-1]
        Index of character to query language of
     */
    virtual LanguageType	GetLanguage( USHORT nPara, USHORT nIndex ) const = 0;

    /** Query number of fields in the underlying edit engine

        @param nPara[0 .. n-1]
        Index of paragraph to query field number in
     */
    virtual USHORT			GetFieldCount( USHORT nPara ) const = 0;

    /** Query information for given field number in the underlying edit engine

        @param nPara[0 .. n-1]
        Index of paragraph to query field info in

        @param nField[0 .. m-1]
        Index of field to query information of
     */
    virtual EFieldInfo		GetFieldInfo( USHORT nPara, USHORT nField ) const = 0;

    /** Query information regarding bullets for given paragraph on the underlying edit engine

        @param nPara[0 .. n-1]
        Index of paragraph to query bullet info on
     */
    virtual EBulletInfo     GetBulletInfo( USHORT nPara ) const = 0;

    /** Query the bounding rectangle of the given character

        @param nPara[0 .. n]
        Index of paragraph to query the bounds in.  <p>The virtual
        character after the last character of the represented text,
        i.e. the one at position n is a special case.  Because it does
        not represent an existing character its bounding box is
        defined in relation to preceding characters.  It should be
        rougly equivalent to the bounding box of some character when
        inserted at the end of the text.  Its height typically being
        the maximal height of all the characters in the text or the
        height of the preceding character, its width being at least
        one pixel so that the bounding box is not degenerate.<br>

        @param nIndex[0 .. m-1]
        Index of character to query the bounds of

        @return rectangle in logical coordinates, relative to upper
        left corner of text. The coordinates returned here are to be
        interpreted in the map mode given by GetMapMode().
    */
    virtual Rectangle		GetCharBounds( USHORT nPara, USHORT nIndex ) const = 0;

    /** Query the bounding rectangle of the given paragraph

        @param nPara[0 .. n-1]
        Index of paragraph to query the bounds of

        @return rectangle in logical coordinates, relative to upper
        left corner of text. The coordinates returned here are to be
        interpreted in the map mode given by GetMapMode().
     */
    virtual Rectangle		GetParaBounds( USHORT nPara ) const = 0;

    /** Query the map mode of the underlying EditEngine/Outliner

        @return the map mode used on the EditEngine/Outliner. The
        values returned by GetParaBounds() and GetCharBounds() are to
        be interpreted in this map mode, the point given to
        GetIndexAtPoint() is interpreted in this map mode.
     */
    virtual MapMode			GetMapMode() const = 0;

    /** Query the reference output device of the underlying EditEngine/Outliner

        @return the OutputDevice used from the EditEngine/Outliner to
        format the text. It should be used when performing e.g. font
        calculations, since this is usually a printer with fonts and
        resolution different from the screen.
     */
    virtual OutputDevice*	GetRefDevice() const = 0;

    /** Query paragraph and character index of the character at the
        given point. Returns sal_True on success, sal_False otherwise

        @param rPoint
        Point to query text position of. Is interpreted in logical
        coordinates, relativ to the upper left corner of the text, and
        in the map mode given by GetMapMode()

        @param rPara[0 .. n-1]
        Index of paragraph the point is within

        @param rIndex[0 .. m-1]
        Index of character the point is over

        @return sal_True, if the point is over any text and both rPara and rIndex are valid

     */
    virtual sal_Bool		GetIndexAtPoint( const Point& rPoint, USHORT& rPara, USHORT& rIndex ) const = 0;

    /** Get the start and the end index of the word at the given index

        An index value on a word leads from the first character of
        that word up to and including the last space before the next
        word. The index values returned do not contain any leading or
        trailing white-space. If the input indices are invalid,
        sal_False is returned.

        @param nPara[0 .. n-1]
        Index of paragraph to start the search in

        @param nIndex[0 .. m-1]
        Index of character to query the search on

        @param rStart
        Start index (in the same paragraph)

        @param rEnd
        End index (in the same paragraph), this point to the last
        character still contained in the query

        @return sal_True, if the result is non-empty
     */
    virtual sal_Bool		GetWordIndices( USHORT nPara, USHORT nIndex, USHORT& rStart, USHORT& rEnd ) const = 0;

    /** Query range of similar attributes

        Please note that the range returned is half-open: [nStartIndex,nEndIndex)

        @param nStartIndex
        Herein, the start index of the range of similar attributes is returned

        @param nEndIndex
        Herein, the end index (exclusive) of the range of similar attributes is returned

        @param nIndex
        The character index from which the range of similar attributed characters is requested

        @return sal_True, if the range has been successfully determined
     */
    virtual sal_Bool 		GetAttributeRun( USHORT& nStartIndex, USHORT& nEndIndex, USHORT nPara, USHORT nIndex ) const = 0;

    /** Query number of lines in the formatted paragraph

        @param nPara[0 .. n-1]
        Index of paragraph to query number of lines in

        @return number of lines in given paragraph

     */
    virtual USHORT			GetLineCount( USHORT nPara ) const = 0;

    /** Query line length

        @param nPara[0 .. n-1]
        Index of paragraph to query line length in

        @param nLine[0 .. m-1]
        Index of line in paragraph to query line length of

     */
    virtual USHORT			GetLineLen( USHORT nPara, USHORT nLine ) const = 0;
    
    /** Query bounds of line in paragraph

        @param rStart [output param; 0 .. text_len]
        The index in the paragraph text that belongs to the chara at the start of the line
        
        @param rEnd [output param; 0 .. text_len]
        The index in the paragraph text that follows the last chara in the line
        
        @param nParagraph[0 .. n-1]
        Index of paragraph to query line length in

        @param nLine[0 .. m-1]
        Index of line in paragraph to query line length of

     */
    virtual void            GetLineBoundaries( /*out*/USHORT &rStart, /*out*/USHORT &rEnd, USHORT nParagraph, USHORT nLine ) const = 0;
    
    /** Query the line number for a index in the paragraphs text

        @param nPara[0 .. n-1]
        Index of paragraph to query line length in

        @param nIndex[0 .. m-1]
        Index of of the chara in the paragraph text

        @returns [0 .. k-1]
        The line number of the chara in the paragraph
     */
    virtual USHORT          GetLineNumberAtIndex( USHORT nPara, USHORT nIndex ) const = 0;

    /** Delete given text range and reformat text

        @param rSelection
        The text range to be deleted

        @return sal_True if text has been successfully deleted
     */
    virtual sal_Bool		Delete( const ESelection& rSelection ) = 0;

     /** Insert/Replace given text in given range and reformat text

          @param rText
         Text to insert/replace

         @param rSel
         Selection where text should be replaced. The empty selection inserts

         @return sal_True if text has been successfully inserted
      */
    virtual sal_Bool		InsertText( const String& rText, const ESelection& rSel ) = 0;

     /** Updates the formatting

          @see EditEngine::QuickFormatDoc() for details

         @return sal_True if text have been successfully reformatted
      */
    virtual sal_Bool		QuickFormatDoc( BOOL bFull=FALSE ) = 0;

    /** Get the outline depth of given paragraph

        @param nPara
        Index of the paragraph to query the depth of

        @return the outline level of the given paragraph. The range is
        [0,n), where n is the maximal outline level.
     */
    virtual sal_Int16		GetDepth( USHORT nPara ) const = 0;

    /** Set the outline depth of given paragraph

        @param nPara
        Index of the paragraph to set the depth of

        @param nNewDepth
        The depth to set on the given paragraph. The range is
        [0,n), where n is the maximal outline level.

        @return TRUE, if depth could be successfully set. Reasons for
        failure are e.g. the text does not support outline level
        (EditEngine), or the depth range is exceeded.
     */
    virtual sal_Bool		SetDepth( USHORT nPara, sal_Int16 nNewDepth ) = 0;

    virtual sal_Int16 GetNumberingStartValue( sal_uInt16 nPara );
    virtual void SetNumberingStartValue( sal_uInt16 nPara, sal_Int16 nNumberingStartValue );

    virtual sal_Bool IsParaIsNumberingRestart( sal_uInt16 nPara );
    virtual void SetParaIsNumberingRestart( sal_uInt16 nPara, sal_Bool bParaIsNumberingRestart );
};

/** Encapsulates the document view for the purpose of unified
    EditEngine/Outliner access.

    This one has to be different from the SvxEditViewForwarder, since
    the latter is only valid in edit mode.
 */
class SVX_DLLPUBLIC SvxViewForwarder
{
public:
    virtual				~SvxViewForwarder();

    /** Query state of forwarder

        @return sal_False, if no longer valid
     */
    virtual BOOL		IsValid() const = 0;

    /** Query visible area of the view containing the text

        @return the visible rectangle of the text, i.e. the part of
        the EditEngine or Outliner that is currently on screen. The
        values are already in screen coordinates (pixel), and have to
        be relative to the EditEngine/Outliner's upper left corner.
     */
    virtual Rectangle	GetVisArea() const = 0;

    /** Convert from logical, EditEngine-relative coordinates to screen coordinates

        @param rPoint
        Point in logical, EditEngine-relative coordinates.

        @param rMapMode
        The map mode to interpret the coordinates in.

        @return the point in screen coordinates
     */
    virtual Point		LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const = 0;

    /** Convert from screen to logical, EditEngine-relative coordinates

        @param rPoint
        Point in screen coordinates

        @param rMapMode
        The map mode to interpret the coordinates in.

        @return the point in logical coordinates.
     */
    virtual Point		PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const = 0;

};


/** Encapsulates EditView and OutlinerView for the purpose of unified
    EditEngine/Outliner access
 */
class SvxEditViewForwarder : public SvxViewForwarder
{
public:

    /** Query current selection.

        @param rSelection
        Contains the current selection after method call

        @return sal_False, if there is no view or no selection (the empty selection _is_ a selection)

     */
    virtual sal_Bool GetSelection( ESelection& rSelection ) const = 0;

    /** Set selection in view.

        @param rSelection
        The selection to set

        @return sal_False, if there is no view or selection is invalid
     */
    virtual sal_Bool SetSelection( const ESelection& rSelection ) = 0;

    /** Copy current selection to clipboard.

        @return sal_False if no selection or no view (the empty selection _is_ a selection)
     */
    virtual sal_Bool Copy() = 0;

    /** Cut current selection to clipboard.

        @eturn sal_False if no selection or no view (the empty selection _is_ a selection)
     */
    virtual sal_Bool Cut() = 0;

    /** Paste clipboard into current selection.

        @return sal_False if no view or no selection (the empty selection _is_ a selection)
     */
    virtual sal_Bool Paste() = 0;

};

#endif