1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef _SVX_UNOEDSRC_HXX
21 #define _SVX_UNOEDSRC_HXX
23 #include <com/sun/star/accessibility/TextSegment.hpp>
25 #include <tools/solar.h>
26 #include <i18nlangtag/lang.h>
27 #include <tools/gen.hxx>
28 #include <vcl/mapmod.hxx>
29 #include <tools/string.hxx>
30 #include <tools/color.hxx>
31 #include <svl/poolitem.hxx>
32 #include <svl/itempool.hxx>
33 #include "editeng/editengdllapi.h"
43 class SvxTextForwarder
;
44 class SvxViewForwarder
;
45 class SvxEditViewForwarder
;
48 class SvxUnoTextRangeBase
;
50 typedef std::list
< SvxUnoTextRangeBase
* > SvxUnoTextRangeBaseList
;
52 /** Wrapper class for unified EditEngine/Outliner access
54 This class wraps a textual object, which might or might not
55 contain an EditEngine/Outliner. Is used e.g. for filling an
56 EditEngine with the content of a cell, note page or page template.
58 class EDITENG_DLLPUBLIC SvxEditSource
61 virtual ~SvxEditSource();
63 /// Returns a new reference to the same object. This is a shallow copy
64 virtual SvxEditSource
* Clone() const = 0;
66 /** Query the text forwarder
68 @return the text forwarder, or NULL if the underlying object is dead
70 virtual SvxTextForwarder
* GetTextForwarder() = 0;
72 /** Query the view forwarder
74 @return the view forwarder, or NULL if the underlying object
75 is dead, or if no view is available
77 @derive default implementation provided, overriding is optional
79 virtual SvxViewForwarder
* GetViewForwarder();
81 /** Query the edit view forwarder
84 Determines whether an EditView should be created, if there is
85 none active. If set to sal_True, and the underlying object is
86 not in EditMode, the text forwarder changes and the object is
89 @return the edit view forwarder, or NULL if the underlying
90 object is dead, or if no view is available (if bCreate is
91 sal_False, NULL is also returned if the object is not in
94 @derive default implementation provided, overriding is optional
96 @attention If this method is called with bCreate equal to
97 sal_True, all previously returned text forwarder can become
100 virtual SvxEditViewForwarder
* GetEditViewForwarder( sal_Bool bCreate
= sal_False
);
102 /// Write back data to model
103 virtual void UpdateData() = 0;
105 /** Returns broadcaster the underlying edit engine's events are sent from
107 @derive default implementation provided, overriding is optional
109 virtual SfxBroadcaster
& GetBroadcaster() const;
111 /** adds the given SvxUnoTextRangeBase to the text object
112 capsulated by this SvxEditSource. This allows the text
113 object to inform all created text ranges about changes
114 and also allows to re use already created instances.
115 All SvxUnoTextRangeBase must remove itself with
116 removeRange() before theire deleted. */
117 virtual void addRange( SvxUnoTextRangeBase
* pNewRange
);
119 /** removes the given SvxUnoTextRangeBase from the text
120 object capsulated by this SvxEditSource. This text range
121 will not be informed any longer of changes on the underlying
122 text and will also not re used anymore. */
123 virtual void removeRange( SvxUnoTextRangeBase
* pOldRange
);
125 /** returns a const list of all text ranges that are registered
126 for the underlying text object. */
127 virtual const SvxUnoTextRangeBaseList
& getRanges() const;
131 /** Contains an EditEngine or an Outliner and unifies access to them.
133 The EditEngine-UNO objects use this class only. To reflect changes
134 not only in the EditEngine, but also in the model data, call
135 SvxEditSource::UpdateData(). This copies back the data to the model's
136 EditTextObject/OutlinerParaObject.
138 class EDITENG_DLLPUBLIC SvxTextForwarder
141 virtual ~SvxTextForwarder();
143 virtual sal_Int32
GetParagraphCount() const = 0;
144 virtual sal_uInt16
GetTextLen( sal_Int32 nParagraph
) const = 0;
145 virtual String
GetText( const ESelection
& rSel
) const = 0;
146 virtual SfxItemSet
GetAttribs( const ESelection
& rSel
, sal_Bool bOnlyHardAttrib
= 0 ) const = 0;
147 virtual SfxItemSet
GetParaAttribs( sal_Int32 nPara
) const = 0;
148 virtual void SetParaAttribs( sal_Int32 nPara
, const SfxItemSet
& rSet
) = 0;
149 virtual void RemoveAttribs( const ESelection
& rSelection
, sal_Bool bRemoveParaAttribs
, sal_uInt16 nWhich
) = 0;
150 virtual void GetPortions( sal_Int32 nPara
, std::vector
<sal_uInt16
>& rList
) const = 0;
152 virtual sal_uInt16
GetItemState( const ESelection
& rSel
, sal_uInt16 nWhich
) const = 0;
153 virtual sal_uInt16
GetItemState( sal_Int32 nPara
, sal_uInt16 nWhich
) const = 0;
155 virtual void QuickInsertText( const String
& rText
, const ESelection
& rSel
) = 0;
156 virtual void QuickInsertField( const SvxFieldItem
& rFld
, const ESelection
& rSel
) = 0;
157 virtual void QuickSetAttribs( const SfxItemSet
& rSet
, const ESelection
& rSel
) = 0;
158 virtual void QuickInsertLineBreak( const ESelection
& rSel
) = 0;
160 virtual OUString
CalcFieldValue( const SvxFieldItem
& rField
, sal_Int32 nPara
, sal_uInt16 nPos
, Color
*& rpTxtColor
, Color
*& rpFldColor
) = 0;
161 virtual void FieldClicked( const SvxFieldItem
& rField
, sal_Int32 nPara
, xub_StrLen nPos
) = 0;
163 virtual SfxItemPool
* GetPool() const = 0;
165 virtual const SfxItemSet
* GetEmptyItemSetPtr() = 0;
167 // implementation functions for XParagraphAppend and XTextPortionAppend
168 virtual void AppendParagraph() = 0;
169 virtual xub_StrLen
AppendTextPortion( sal_Int32 nPara
, const String
&rText
, const SfxItemSet
&rSet
) = 0;
172 virtual void CopyText(const SvxTextForwarder
& rSource
) = 0;
174 /** Query state of forwarder
176 @return sal_False, if no longer valid
178 virtual sal_Bool
IsValid() const = 0;
180 /** Query language of character at given position on the underlying edit engine
182 @param nPara[0 .. n-1]
183 Index of paragraph to query language in
185 @param nIndex[0 .. m-1]
186 Index of character to query language of
188 virtual LanguageType
GetLanguage( sal_Int32 nPara
, sal_uInt16 nIndex
) const = 0;
190 /** Query number of fields in the underlying edit engine
192 @param nPara[0 .. n-1]
193 Index of paragraph to query field number in
195 virtual sal_uInt16
GetFieldCount( sal_Int32 nPara
) const = 0;
197 /** Query information for given field number in the underlying edit engine
199 @param nPara[0 .. n-1]
200 Index of paragraph to query field info in
202 @param nField[0 .. m-1]
203 Index of field to query information of
205 virtual EFieldInfo
GetFieldInfo( sal_Int32 nPara
, sal_uInt16 nField
) const = 0;
207 /** Query information regarding bullets for given paragraph on the underlying edit engine
209 @param nPara[0 .. n-1]
210 Index of paragraph to query bullet info on
212 virtual EBulletInfo
GetBulletInfo( sal_Int32 nPara
) const = 0;
214 /** Query the bounding rectangle of the given character
217 Index of paragraph to query the bounds in. <p>The virtual
218 character after the last character of the represented text,
219 i.e. the one at position n is a special case. Because it does
220 not represent an existing character its bounding box is
221 defined in relation to preceding characters. It should be
222 rougly equivalent to the bounding box of some character when
223 inserted at the end of the text. Its height typically being
224 the maximal height of all the characters in the text or the
225 height of the preceding character, its width being at least
226 one pixel so that the bounding box is not degenerate.<br>
228 @param nIndex[0 .. m-1]
229 Index of character to query the bounds of
231 @return rectangle in logical coordinates, relative to upper
232 left corner of text. The coordinates returned here are to be
233 interpreted in the map mode given by GetMapMode().
235 virtual Rectangle
GetCharBounds( sal_Int32 nPara
, sal_uInt16 nIndex
) const = 0;
237 /** Query the bounding rectangle of the given paragraph
239 @param nPara[0 .. n-1]
240 Index of paragraph to query the bounds of
242 @return rectangle in logical coordinates, relative to upper
243 left corner of text. The coordinates returned here are to be
244 interpreted in the map mode given by GetMapMode().
246 virtual Rectangle
GetParaBounds( sal_Int32 nPara
) const = 0;
248 /** Query the map mode of the underlying EditEngine/Outliner
250 @return the map mode used on the EditEngine/Outliner. The
251 values returned by GetParaBounds() and GetCharBounds() are to
252 be interpreted in this map mode, the point given to
253 GetIndexAtPoint() is interpreted in this map mode.
255 virtual MapMode
GetMapMode() const = 0;
257 /** Query the reference output device of the underlying EditEngine/Outliner
259 @return the OutputDevice used from the EditEngine/Outliner to
260 format the text. It should be used when performing e.g. font
261 calculations, since this is usually a printer with fonts and
262 resolution different from the screen.
264 virtual OutputDevice
* GetRefDevice() const = 0;
266 /** Query paragraph and character index of the character at the
267 given point. Returns sal_True on success, sal_False otherwise
270 Point to query text position of. Is interpreted in logical
271 coordinates, relativ to the upper left corner of the text, and
272 in the map mode given by GetMapMode()
274 @param rPara[0 .. n-1]
275 Index of paragraph the point is within
277 @param rIndex[0 .. m-1]
278 Index of character the point is over
280 @return sal_True, if the point is over any text and both rPara and rIndex are valid
283 virtual sal_Bool
GetIndexAtPoint( const Point
& rPoint
, sal_Int32
& rPara
, sal_uInt16
& rIndex
) const = 0;
285 /** Get the start and the end index of the word at the given index
287 An index value on a word leads from the first character of
288 that word up to and including the last space before the next
289 word. The index values returned do not contain any leading or
290 trailing white-space. If the input indices are invalid,
291 sal_False is returned.
293 @param nPara[0 .. n-1]
294 Index of paragraph to start the search in
296 @param nIndex[0 .. m-1]
297 Index of character to query the search on
300 Start index (in the same paragraph)
303 End index (in the same paragraph), this point to the last
304 character still contained in the query
306 @return sal_True, if the result is non-empty
308 virtual sal_Bool
GetWordIndices( sal_Int32 nPara
, sal_uInt16 nIndex
, sal_uInt16
& rStart
, sal_uInt16
& rEnd
) const = 0;
310 /** Query range of similar attributes
312 Please note that the range returned is half-open: [nStartIndex,nEndIndex)
315 Herein, the start index of the range of similar attributes is returned
318 Herein, the end index (exclusive) of the range of similar attributes is returned
321 The character index from which the range of similar attributed characters is requested
323 @return sal_True, if the range has been successfully determined
325 virtual sal_Bool
GetAttributeRun( sal_uInt16
& nStartIndex
, sal_uInt16
& nEndIndex
, sal_Int32 nPara
, sal_uInt16 nIndex
) const = 0;
327 /** Query number of lines in the formatted paragraph
329 @param nPara[0 .. n-1]
330 Index of paragraph to query number of lines in
332 @return number of lines in given paragraph
335 virtual sal_uInt16
GetLineCount( sal_Int32 nPara
) const = 0;
337 /** Query line length
339 @param nPara[0 .. n-1]
340 Index of paragraph to query line length in
342 @param nLine[0 .. m-1]
343 Index of line in paragraph to query line length of
346 virtual sal_uInt16
GetLineLen( sal_Int32 nPara
, sal_uInt16 nLine
) const = 0;
348 /** Query bounds of line in paragraph
350 @param rStart [output param; 0 .. text_len]
351 The index in the paragraph text that belongs to the chara at the start of the line
353 @param rEnd [output param; 0 .. text_len]
354 The index in the paragraph text that follows the last chara in the line
356 @param nParagraph[0 .. n-1]
357 Index of paragraph to query line length in
359 @param nLine[0 .. m-1]
360 Index of line in paragraph to query line length of
363 virtual void GetLineBoundaries( /*out*/sal_uInt16
&rStart
, /*out*/sal_uInt16
&rEnd
, sal_Int32 nParagraph
, sal_uInt16 nLine
) const = 0;
365 /** Query the line number for a index in the paragraphs text
367 @param nPara[0 .. n-1]
368 Index of paragraph to query line length in
370 @param nIndex[0 .. m-1]
371 Index of of the chara in the paragraph text
374 The line number of the chara in the paragraph
376 virtual sal_uInt16
GetLineNumberAtIndex( sal_Int32 nPara
, sal_uInt16 nIndex
) const = 0;
378 /** Delete given text range and reformat text
381 The text range to be deleted
383 @return sal_True if text has been successfully deleted
385 virtual sal_Bool
Delete( const ESelection
& rSelection
) = 0;
387 /** Insert/Replace given text in given range and reformat text
390 Text to insert/replace
393 Selection where text should be replaced. The empty selection inserts
395 @return sal_True if text has been successfully inserted
397 virtual sal_Bool
InsertText( const String
& rText
, const ESelection
& rSel
) = 0;
399 /** Updates the formatting
401 @see EditEngine::QuickFormatDoc() for details
403 @return sal_True if text have been successfully reformatted
405 virtual sal_Bool
QuickFormatDoc( sal_Bool bFull
=sal_False
) = 0;
407 /** Get the outline depth of given paragraph
410 Index of the paragraph to query the depth of
412 @return the outline level of the given paragraph. The range is
413 [0,n), where n is the maximal outline level.
415 virtual sal_Int16
GetDepth( sal_Int32 nPara
) const = 0;
417 /** Set the outline depth of given paragraph
420 Index of the paragraph to set the depth of
423 The depth to set on the given paragraph. The range is
424 [0,n), where n is the maximal outline level.
426 @return sal_True, if depth could be successfully set. Reasons for
427 failure are e.g. the text does not support outline level
428 (EditEngine), or the depth range is exceeded.
430 virtual sal_Bool
SetDepth( sal_Int32 nPara
, sal_Int16 nNewDepth
) = 0;
432 virtual sal_Int16
GetNumberingStartValue( sal_Int32 nPara
);
433 virtual void SetNumberingStartValue( sal_Int32 nPara
, sal_Int16 nNumberingStartValue
);
435 virtual sal_Bool
IsParaIsNumberingRestart( sal_Int32 nPara
);
436 virtual void SetParaIsNumberingRestart( sal_Int32 nPara
, sal_Bool bParaIsNumberingRestart
);
439 /** Encapsulates the document view for the purpose of unified
440 EditEngine/Outliner access.
442 This one has to be different from the SvxEditViewForwarder, since
443 the latter is only valid in edit mode.
445 class EDITENG_DLLPUBLIC SvxViewForwarder
448 virtual ~SvxViewForwarder();
450 /** Query state of forwarder
452 @return sal_False, if no longer valid
454 virtual sal_Bool
IsValid() const = 0;
456 /** Query visible area of the view containing the text
458 @return the visible rectangle of the text, i.e. the part of
459 the EditEngine or Outliner that is currently on screen. The
460 values are already in screen coordinates (pixel), and have to
461 be relative to the EditEngine/Outliner's upper left corner.
463 virtual Rectangle
GetVisArea() const = 0;
465 /** Convert from logical, EditEngine-relative coordinates to screen coordinates
468 Point in logical, EditEngine-relative coordinates.
471 The map mode to interpret the coordinates in.
473 @return the point in screen coordinates
475 virtual Point
LogicToPixel( const Point
& rPoint
, const MapMode
& rMapMode
) const = 0;
477 /** Convert from screen to logical, EditEngine-relative coordinates
480 Point in screen coordinates
483 The map mode to interpret the coordinates in.
485 @return the point in logical coordinates.
487 virtual Point
PixelToLogic( const Point
& rPoint
, const MapMode
& rMapMode
) const = 0;
492 /** Encapsulates EditView and OutlinerView for the purpose of unified
493 EditEngine/Outliner access
495 class SvxEditViewForwarder
: public SvxViewForwarder
499 /** Query current selection.
502 Contains the current selection after method call
504 @return sal_False, if there is no view or no selection (the empty selection _is_ a selection)
507 virtual sal_Bool
GetSelection( ESelection
& rSelection
) const = 0;
509 /** Set selection in view.
514 @return sal_False, if there is no view or selection is invalid
516 virtual sal_Bool
SetSelection( const ESelection
& rSelection
) = 0;
518 /** Copy current selection to clipboard.
520 @return sal_False if no selection or no view (the empty selection _is_ a selection)
522 virtual sal_Bool
Copy() = 0;
524 /** Cut current selection to clipboard.
526 @eturn sal_False if no selection or no view (the empty selection _is_ a selection)
528 virtual sal_Bool
Cut() = 0;
530 /** Paste clipboard into current selection.
532 @return sal_False if no view or no selection (the empty selection _is_ a selection)
534 virtual sal_Bool
Paste() = 0;
540 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */