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 INCLUDED_EDITENG_UNOEDSRC_HXX
21 #define INCLUDED_EDITENG_UNOEDSRC_HXX
23 #include <i18nlangtag/lang.h>
24 #include <rtl/ustring.hxx>
25 #include <tools/gen.hxx>
26 #include <vcl/mapmod.hxx>
27 #include <svl/poolitem.hxx>
28 #include <editeng/editengdllapi.h>
29 #include <editeng/editeng.hxx>
39 class SvxTextForwarder
;
40 class SvxViewForwarder
;
41 class SvxEditViewForwarder
;
44 class SvxUnoTextRangeBase
;
46 typedef std::vector
< SvxUnoTextRangeBase
* > SvxUnoTextRangeBaseVec
;
48 /** Wrapper class for unified EditEngine/Outliner access
50 This class wraps a textual object, which might or might not
51 contain an EditEngine/Outliner. Is used e.g. for filling an
52 EditEngine with the content of a cell, note page or page template.
54 class EDITENG_DLLPUBLIC SvxEditSource
57 SvxEditSource() = default;
58 SvxEditSource(SvxEditSource
const &) = default;
59 SvxEditSource(SvxEditSource
&&) = default;
60 SvxEditSource
& operator =(SvxEditSource
const &) = default;
61 SvxEditSource
& operator =(SvxEditSource
&&) = default;
63 virtual ~SvxEditSource();
65 /// Returns a new reference to the same object. This is a shallow copy
66 virtual std::unique_ptr
<SvxEditSource
> Clone() const = 0;
68 /** Query the text forwarder
70 @return the text forwarder, or NULL if the underlying object is dead
72 virtual SvxTextForwarder
* GetTextForwarder() = 0;
74 /** Query the view forwarder
76 @return the view forwarder, or NULL if the underlying object
77 is dead, or if no view is available
79 @derive default implementation provided, overriding is optional
81 virtual SvxViewForwarder
* GetViewForwarder();
83 /** Query the edit view forwarder
86 Determines whether an EditView should be created, if there is
87 none active. If set to sal_True, and the underlying object is
88 not in EditMode, the text forwarder changes and the object is
91 @return the edit view forwarder, or NULL if the underlying
92 object is dead, or if no view is available (if bCreate is
93 sal_False, NULL is also returned if the object is not in
96 @derive default implementation provided, overriding is optional
98 @attention If this method is called with bCreate equal to
99 sal_True, all previously returned text forwarder can become
102 virtual SvxEditViewForwarder
* GetEditViewForwarder( bool bCreate
= false );
104 /// Write back data to model
105 virtual void UpdateData() = 0;
107 /** Returns broadcaster the underlying edit engine's events are sent from
109 @derive default implementation provided, overriding is optional
111 virtual SfxBroadcaster
& GetBroadcaster() const;
113 /** adds the given SvxUnoTextRangeBase to the text object
114 capsulated by this SvxEditSource. This allows the text
115 object to inform all created text ranges about changes
116 and also allows to re use already created instances.
117 All SvxUnoTextRangeBase must remove itself with
118 removeRange() before they are deleted. */
119 virtual void addRange( SvxUnoTextRangeBase
* pNewRange
);
121 /** removes the given SvxUnoTextRangeBase from the text
122 object capsulated by this SvxEditSource. This text range
123 will not be informed any longer of changes on the underlying
124 text and will also not re used anymore. */
125 virtual void removeRange( SvxUnoTextRangeBase
* pOldRange
);
127 /** returns a const list of all text ranges that are registered
128 for the underlying text object. */
129 virtual const SvxUnoTextRangeBaseVec
& getRanges() const;
133 /** Contains an EditEngine or an Outliner and unifies access to them.
135 The EditEngine-UNO objects use this class only. To reflect changes
136 not only in the EditEngine, but also in the model data, call
137 SvxEditSource::UpdateData(). This copies back the data to the model's
138 EditTextObject/OutlinerParaObject.
140 class EDITENG_DLLPUBLIC SvxTextForwarder
143 virtual ~SvxTextForwarder() COVERITY_NOEXCEPT_FALSE
;
145 virtual sal_Int32
GetParagraphCount() const = 0;
146 virtual sal_Int32
GetTextLen( sal_Int32 nParagraph
) const = 0;
147 virtual OUString
GetText( const ESelection
& rSel
) const = 0;
148 virtual SfxItemSet
GetAttribs( const ESelection
& rSel
, EditEngineAttribs nOnlyHardAttrib
= EditEngineAttribs::All
) const = 0;
149 virtual SfxItemSet
GetParaAttribs( sal_Int32 nPara
) const = 0;
150 virtual void SetParaAttribs( sal_Int32 nPara
, const SfxItemSet
& rSet
) = 0;
151 virtual void RemoveAttribs( const ESelection
& rSelection
) = 0;
152 virtual void GetPortions( sal_Int32 nPara
, std::vector
<sal_Int32
>& rList
) const = 0;
154 virtual SfxItemState
GetItemState( const ESelection
& rSel
, sal_uInt16 nWhich
) const = 0;
155 virtual SfxItemState
GetItemState( sal_Int32 nPara
, sal_uInt16 nWhich
) const = 0;
157 virtual void QuickInsertText( const OUString
& rText
, const ESelection
& rSel
) = 0;
158 virtual void QuickInsertField( const SvxFieldItem
& rFld
, const ESelection
& rSel
) = 0;
159 virtual void QuickSetAttribs( const SfxItemSet
& rSet
, const ESelection
& rSel
) = 0;
160 virtual void QuickInsertLineBreak( const ESelection
& rSel
) = 0;
162 virtual OUString
CalcFieldValue( const SvxFieldItem
& rField
, sal_Int32 nPara
, sal_Int32 nPos
, std::optional
<Color
>& rpTxtColor
, std::optional
<Color
>& rpFldColor
) = 0;
163 virtual void FieldClicked( const SvxFieldItem
& rField
) = 0;
165 virtual SfxItemPool
* GetPool() const = 0;
167 virtual const SfxItemSet
* GetEmptyItemSetPtr() = 0;
169 // implementation functions for XParagraphAppend and XTextPortionAppend
170 virtual void AppendParagraph() = 0;
171 virtual sal_Int32
AppendTextPortion( sal_Int32 nPara
, const OUString
&rText
, const SfxItemSet
&rSet
) = 0;
174 virtual void CopyText(const SvxTextForwarder
& rSource
) = 0;
176 /** Query state of forwarder
178 @return false, if no longer valid
180 virtual bool IsValid() const = 0;
182 /** Query language of character at given position on the underlying edit engine
184 @param nPara[0 .. n-1]
185 Index of paragraph to query language in
187 @param nIndex[0 .. m-1]
188 Index of character to query language of
190 virtual LanguageType
GetLanguage( sal_Int32 nPara
, sal_Int32 nIndex
) const = 0;
192 /** Query number of fields in the underlying edit engine
194 @param nPara[0 .. n-1]
195 Index of paragraph to query field number in
197 virtual sal_Int32
GetFieldCount( sal_Int32 nPara
) const = 0;
199 /** Query information for given field number in the underlying edit engine
201 @param nPara[0 .. n-1]
202 Index of paragraph to query field info in
204 @param nField[0 .. m-1]
205 Index of field to query information of
207 virtual EFieldInfo
GetFieldInfo( sal_Int32 nPara
, sal_uInt16 nField
) const = 0;
209 /** Query information regarding bullets for given paragraph on the underlying edit engine
211 @param nPara[0 .. n-1]
212 Index of paragraph to query bullet info on
214 virtual EBulletInfo
GetBulletInfo( sal_Int32 nPara
) const = 0;
216 /** Query the bounding rectangle of the given character
219 Index of paragraph to query the bounds in. <p>The virtual
220 character after the last character of the represented text,
221 i.e. the one at position n is a special case. Because it does
222 not represent an existing character its bounding box is
223 defined in relation to preceding characters. It should be
224 roughly equivalent to the bounding box of some character when
225 inserted at the end of the text. Its height typically being
226 the maximal height of all the characters in the text or the
227 height of the preceding character, its width being at least
228 one pixel so that the bounding box is not degenerate.<br>
230 @param nIndex[0 .. m-1]
231 Index of character to query the bounds of
233 @return rectangle in logical coordinates, relative to upper
234 left corner of text. The coordinates returned here are to be
235 interpreted in the map mode given by GetMapMode().
237 virtual tools::Rectangle
GetCharBounds( sal_Int32 nPara
, sal_Int32 nIndex
) const = 0;
239 /** Query the bounding rectangle of the given paragraph
241 @param nPara[0 .. n-1]
242 Index of paragraph to query the bounds of
244 @return rectangle in logical coordinates, relative to upper
245 left corner of text. The coordinates returned here are to be
246 interpreted in the map mode given by GetMapMode().
248 virtual tools::Rectangle
GetParaBounds( sal_Int32 nPara
) const = 0;
250 /** Query the map mode of the underlying EditEngine/Outliner
252 @return the map mode used on the EditEngine/Outliner. The
253 values returned by GetParaBounds() and GetCharBounds() are to
254 be interpreted in this map mode, the point given to
255 GetIndexAtPoint() is interpreted in this map mode.
257 virtual MapMode
GetMapMode() const = 0;
259 /** Query the reference output device of the underlying EditEngine/Outliner
261 @return the OutputDevice used from the EditEngine/Outliner to
262 format the text. It should be used when performing e.g. font
263 calculations, since this is usually a printer with fonts and
264 resolution different from the screen.
266 virtual OutputDevice
* GetRefDevice() const = 0;
268 /** Query paragraph and character index of the character at the
269 given point. Returns sal_True on success, sal_False otherwise
272 Point to query text position of. Is interpreted in logical
273 coordinates, relative to the upper left corner of the text, and
274 in the map mode given by GetMapMode()
276 @param rPara[0 .. n-1]
277 Index of paragraph the point is within
279 @param rIndex[0 .. m-1]
280 Index of character the point is over
282 @return true, if the point is over any text and both rPara and rIndex are valid
285 virtual bool GetIndexAtPoint( const Point
& rPoint
, sal_Int32
& rPara
, sal_Int32
& rIndex
) const = 0;
287 /** Get the start and the end index of the word at the given index
289 An index value on a word leads from the first character of
290 that word up to and including the last space before the next
291 word. The index values returned do not contain any leading or
292 trailing white-space. If the input indices are invalid,
293 sal_False is returned.
295 @param nPara[0 .. n-1]
296 Index of paragraph to start the search in
298 @param nIndex[0 .. m-1]
299 Index of character to query the search on
302 Start index (in the same paragraph)
305 End index (in the same paragraph), this point to the last
306 character still contained in the query
308 @return true, if the result is non-empty
310 virtual bool GetWordIndices( sal_Int32 nPara
, sal_Int32 nIndex
, sal_Int32
& rStart
, sal_Int32
& rEnd
) const = 0;
312 /** Query range of similar attributes
314 Please note that the range returned is half-open: [nStartIndex,nEndIndex)
317 Herein, the start index of the range of similar attributes is returned
320 Herein, the end index (exclusive) of the range of similar attributes is returned
323 The character index from which the range of similar attributed characters is requested
325 @return true, if the range has been successfully determined
327 virtual bool GetAttributeRun( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
, sal_Int32 nPara
, sal_Int32 nIndex
, bool bInCell
= false ) const = 0;
329 /** Query number of lines in the formatted paragraph
331 @param nPara[0 .. n-1]
332 Index of paragraph to query number of lines in
334 @return number of lines in given paragraph
337 virtual sal_Int32
GetLineCount( sal_Int32 nPara
) const = 0;
339 /** Query line length
341 @param nPara[0 .. n-1]
342 Index of paragraph to query line length in
344 @param nLine[0 .. m-1]
345 Index of line in paragraph to query line length of
348 virtual sal_Int32
GetLineLen( sal_Int32 nPara
, sal_Int32 nLine
) const = 0;
350 /** Query bounds of line in paragraph
352 @param rStart [output param; 0 .. text_len]
353 The index in the paragraph text that belongs to the chara at the start of the line
355 @param rEnd [output param; 0 .. text_len]
356 The index in the paragraph text that follows the last chara in the line
358 @param nParagraph[0 .. n-1]
359 Index of paragraph to query line length in
361 @param nLine[0 .. m-1]
362 Index of line in paragraph to query line length of
365 virtual void GetLineBoundaries( /*out*/sal_Int32
&rStart
, /*out*/sal_Int32
&rEnd
, sal_Int32 nParagraph
, sal_Int32 nLine
) const = 0;
367 /** Query the line number for an index in the paragraphs text
369 @param nPara[0 .. n-1]
370 Index of paragraph to query line length in
372 @param nIndex[0 .. m-1]
373 Index of the char in the paragraph text
376 The line number of the char in the paragraph
378 virtual sal_Int32
GetLineNumberAtIndex( sal_Int32 nPara
, sal_Int32 nIndex
) const = 0;
380 /** Delete given text range and reformat text
383 The text range to be deleted
385 @return true if text has been successfully deleted
387 virtual bool Delete( const ESelection
& rSelection
) = 0;
389 /** Insert/Replace given text in given range and reformat text
392 Text to insert/replace
395 Selection where text should be replaced. The empty selection inserts
397 @return true if text has been successfully inserted
399 virtual bool InsertText( const OUString
& rText
, const ESelection
& rSel
) = 0;
401 /** Updates the formatting
403 @see EditEngine::QuickFormatDoc() for details
405 @return true if text have been successfully reformatted
407 virtual bool QuickFormatDoc( bool bFull
= false ) = 0;
409 /** Get the outline depth of given paragraph
412 Index of the paragraph to query the depth of
414 @return the outline level of the given paragraph. The range is
415 [0,n), where n is the maximal outline level.
417 virtual sal_Int16
GetDepth( sal_Int32 nPara
) const = 0;
419 /** Set the outline depth of given paragraph
422 Index of the paragraph to set the depth of
425 The depth to set on the given paragraph. The range is
426 [0,n), where n is the maximal outline level.
428 @return true, if depth could be successfully set. Reasons for
429 failure are e.g. the text does not support outline level
430 (EditEngine), or the depth range is exceeded.
432 virtual bool SetDepth( sal_Int32 nPara
, sal_Int16 nNewDepth
) = 0;
434 virtual sal_Int32
GetNumberingStartValue( sal_Int32 nPara
);
435 virtual void SetNumberingStartValue( sal_Int32 nPara
, sal_Int32 nNumberingStartValue
);
437 virtual bool IsParaIsNumberingRestart( sal_Int32 nPara
);
438 virtual void SetParaIsNumberingRestart( sal_Int32 nPara
, bool bParaIsNumberingRestart
);
441 /** Encapsulates the document view for the purpose of unified
442 EditEngine/Outliner access.
444 This one has to be different from the SvxEditViewForwarder, since
445 the latter is only valid in edit mode.
447 class EDITENG_DLLPUBLIC SvxViewForwarder
450 virtual ~SvxViewForwarder();
452 /** Query state of forwarder
454 @return sal_False, if no longer valid
456 virtual bool IsValid() const = 0;
458 /** Convert from logical, EditEngine-relative coordinates to screen coordinates
461 Point in logical, EditEngine-relative coordinates.
464 The map mode to interpret the coordinates in.
466 @return the point in screen coordinates
468 virtual Point
LogicToPixel( const Point
& rPoint
, const MapMode
& rMapMode
) const = 0;
470 /** Convert from screen to logical, EditEngine-relative coordinates
473 Point in screen coordinates
476 The map mode to interpret the coordinates in.
478 @return the point in logical coordinates.
480 virtual Point
PixelToLogic( const Point
& rPoint
, const MapMode
& rMapMode
) const = 0;
485 /** Encapsulates EditView and OutlinerView for the purpose of unified
486 EditEngine/Outliner access
488 class SvxEditViewForwarder
: public SvxViewForwarder
492 /** Query current selection.
495 Contains the current selection after method call
497 @return false, if there is no view or no selection (the empty selection _is_ a selection)
500 virtual bool GetSelection( ESelection
& rSelection
) const = 0;
502 /** Set selection in view.
507 @return false, if there is no view or selection is invalid
509 virtual bool SetSelection( const ESelection
& rSelection
) = 0;
511 /** Copy current selection to clipboard.
513 @return false if no selection or no view (the empty selection _is_ a selection)
515 virtual bool Copy() = 0;
517 /** Cut current selection to clipboard.
519 @return false if no selection or no view (the empty selection _is_ a selection)
521 virtual bool Cut() = 0;
523 /** Paste clipboard into current selection.
525 @return false if no view or no selection (the empty selection _is_ a selection)
527 virtual bool Paste() = 0;
533 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */