Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / editeng / unoedsrc.hxx
blob007633616b19f7b68b4d80bc1fe035c84f4cd9ee
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <tools/fontenum.hxx>
27 #include <vcl/mapmod.hxx>
28 #include <svl/poolitem.hxx>
29 #include <editeng/editengdllapi.h>
30 #include <editeng/editeng.hxx>
32 #include <vector>
34 struct ESelection;
35 struct EFieldInfo;
36 struct EBulletInfo;
37 class Color;
38 class OutputDevice;
39 class SfxItemSet;
40 class SvxTextForwarder;
41 class SvxViewForwarder;
42 class SvxEditViewForwarder;
43 class SvxFieldItem;
44 class SfxBroadcaster;
45 class SvxUnoTextRangeBase;
47 typedef std::vector< SvxUnoTextRangeBase* > SvxUnoTextRangeBaseVec;
49 /** Wrapper class for unified EditEngine/Outliner access
51 This class wraps a textual object, which might or might not
52 contain an EditEngine/Outliner. Is used e.g. for filling an
53 EditEngine with the content of a cell, note page or page template.
55 class EDITENG_DLLPUBLIC SvxEditSource
57 public:
58 SvxEditSource() = default;
59 SvxEditSource(SvxEditSource const &) = default;
60 SvxEditSource(SvxEditSource &&) = default;
61 SvxEditSource & operator =(SvxEditSource const &) = default;
62 SvxEditSource & operator =(SvxEditSource &&) = default;
64 virtual ~SvxEditSource();
66 /// Returns a new reference to the same object. This is a shallow copy
67 virtual std::unique_ptr<SvxEditSource> Clone() const = 0;
69 /** Query the text forwarder
71 @return the text forwarder, or NULL if the underlying object is dead
73 virtual SvxTextForwarder* GetTextForwarder() = 0;
75 /** Query the view forwarder
77 @return the view forwarder, or NULL if the underlying object
78 is dead, or if no view is available
80 @derive default implementation provided, overriding is optional
82 virtual SvxViewForwarder* GetViewForwarder();
84 /** Query the edit view forwarder
86 @param bCreate
87 Determines whether an EditView should be created, if there is
88 none active. If set to sal_True, and the underlying object is
89 not in EditMode, the text forwarder changes and the object is
90 set to EditMode.
92 @return the edit view forwarder, or NULL if the underlying
93 object is dead, or if no view is available (if bCreate is
94 sal_False, NULL is also returned if the object is not in
95 EditMode)
97 @derive default implementation provided, overriding is optional
99 @attention If this method is called with bCreate equal to
100 sal_True, all previously returned text forwarder can become
101 invalid
103 virtual SvxEditViewForwarder* GetEditViewForwarder( bool bCreate = false );
105 /// Write back data to model
106 virtual void UpdateData() = 0;
108 /** Returns broadcaster the underlying edit engine's events are sent from
110 @derive default implementation provided, overriding is optional
112 virtual SfxBroadcaster& GetBroadcaster() const;
114 /** adds the given SvxUnoTextRangeBase to the text object
115 capsulated by this SvxEditSource. This allows the text
116 object to inform all created text ranges about changes
117 and also allows to re use already created instances.
118 All SvxUnoTextRangeBase must remove itself with
119 removeRange() before they are deleted. */
120 virtual void addRange( SvxUnoTextRangeBase* pNewRange );
122 /** removes the given SvxUnoTextRangeBase from the text
123 object capsulated by this SvxEditSource. This text range
124 will not be informed any longer of changes on the underlying
125 text and will also not re used anymore. */
126 virtual void removeRange( SvxUnoTextRangeBase* pOldRange );
128 /** returns a const list of all text ranges that are registered
129 for the underlying text object. */
130 virtual const SvxUnoTextRangeBaseVec& getRanges() const;
134 /** Contains an EditEngine or an Outliner and unifies access to them.
136 The EditEngine-UNO objects use this class only. To reflect changes
137 not only in the EditEngine, but also in the model data, call
138 SvxEditSource::UpdateData(). This copies back the data to the model's
139 EditTextObject/OutlinerParaObject.
141 class EDITENG_DLLPUBLIC SvxTextForwarder
143 public:
144 virtual ~SvxTextForwarder() COVERITY_NOEXCEPT_FALSE;
146 virtual sal_Int32 GetParagraphCount() const = 0;
147 virtual sal_Int32 GetTextLen( sal_Int32 nParagraph ) const = 0;
148 virtual OUString GetText( const ESelection& rSel ) const = 0;
149 virtual SfxItemSet GetAttribs( const ESelection& rSel, EditEngineAttribs nOnlyHardAttrib = EditEngineAttribs::All ) const = 0;
150 virtual SfxItemSet GetParaAttribs( sal_Int32 nPara ) const = 0;
151 virtual void SetParaAttribs( sal_Int32 nPara, const SfxItemSet& rSet ) = 0;
152 virtual void RemoveAttribs( const ESelection& rSelection ) = 0;
153 virtual void GetPortions( sal_Int32 nPara, std::vector<sal_Int32>& rList ) const = 0;
155 virtual SfxItemState GetItemState( const ESelection& rSel, sal_uInt16 nWhich ) const = 0;
156 virtual SfxItemState GetItemState( sal_Int32 nPara, sal_uInt16 nWhich ) const = 0;
158 virtual void QuickInsertText( const OUString& rText, const ESelection& rSel ) = 0;
159 virtual void QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel ) = 0;
160 virtual void QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel ) = 0;
161 virtual void QuickInsertLineBreak( const ESelection& rSel ) = 0;
163 virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, std::optional<Color>& rpTxtColor, std::optional<Color>& rpFldColor, std::optional<FontLineStyle>& rpFldLineStyle ) = 0;
164 virtual void FieldClicked( const SvxFieldItem& rField ) = 0;
166 virtual SfxItemPool* GetPool() const = 0;
168 virtual const SfxItemSet* GetEmptyItemSetPtr() = 0;
170 // implementation functions for XParagraphAppend and XTextPortionAppend
171 virtual void AppendParagraph() = 0;
172 virtual sal_Int32 AppendTextPortion( sal_Int32 nPara, const OUString &rText, const SfxItemSet &rSet ) = 0;
174 // XTextCopy
175 virtual void CopyText(const SvxTextForwarder& rSource) = 0;
177 /** Query state of forwarder
179 @return false, if no longer valid
181 virtual bool IsValid() const = 0;
183 /** Query language of character at given position on the underlying edit engine
185 @param nPara[0 .. n-1]
186 Index of paragraph to query language in
188 @param nIndex[0 .. m-1]
189 Index of character to query language of
191 virtual LanguageType GetLanguage( sal_Int32 nPara, sal_Int32 nIndex ) const = 0;
193 /** Query number of fields in the underlying edit engine
195 @param nPara[0 .. n-1]
196 Index of paragraph to query field number in
198 virtual sal_Int32 GetFieldCount( sal_Int32 nPara ) const = 0;
200 /** Query information for given field number in the underlying edit engine
202 @param nPara[0 .. n-1]
203 Index of paragraph to query field info in
205 @param nField[0 .. m-1]
206 Index of field to query information of
208 virtual EFieldInfo GetFieldInfo( sal_Int32 nPara, sal_uInt16 nField ) const = 0;
210 /** Query information regarding bullets for given paragraph on the underlying edit engine
212 @param nPara[0 .. n-1]
213 Index of paragraph to query bullet info on
215 virtual EBulletInfo GetBulletInfo( sal_Int32 nPara ) const = 0;
217 /** Query the bounding rectangle of the given character
219 @param nPara[0 .. n]
220 Index of paragraph to query the bounds in. <p>The virtual
221 character after the last character of the represented text,
222 i.e. the one at position n is a special case. Because it does
223 not represent an existing character its bounding box is
224 defined in relation to preceding characters. It should be
225 roughly equivalent to the bounding box of some character when
226 inserted at the end of the text. Its height typically being
227 the maximal height of all the characters in the text or the
228 height of the preceding character, its width being at least
229 one pixel so that the bounding box is not degenerate.<br>
231 @param nIndex[0 .. m-1]
232 Index of character to query the bounds of
234 @return rectangle in logical coordinates, relative to upper
235 left corner of text. The coordinates returned here are to be
236 interpreted in the map mode given by GetMapMode().
238 virtual tools::Rectangle GetCharBounds( sal_Int32 nPara, sal_Int32 nIndex ) const = 0;
240 /** Query the bounding rectangle of the given paragraph
242 @param nPara[0 .. n-1]
243 Index of paragraph to query the bounds of
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().
249 virtual tools::Rectangle GetParaBounds( sal_Int32 nPara ) const = 0;
251 /** Query the map mode of the underlying EditEngine/Outliner
253 @return the map mode used on the EditEngine/Outliner. The
254 values returned by GetParaBounds() and GetCharBounds() are to
255 be interpreted in this map mode, the point given to
256 GetIndexAtPoint() is interpreted in this map mode.
258 virtual MapMode GetMapMode() const = 0;
260 /** Query the reference output device of the underlying EditEngine/Outliner
262 @return the OutputDevice used from the EditEngine/Outliner to
263 format the text. It should be used when performing e.g. font
264 calculations, since this is usually a printer with fonts and
265 resolution different from the screen.
267 virtual OutputDevice* GetRefDevice() const = 0;
269 /** Query paragraph and character index of the character at the
270 given point. Returns sal_True on success, sal_False otherwise
272 @param rPoint
273 Point to query text position of. Is interpreted in logical
274 coordinates, relative to the upper left corner of the text, and
275 in the map mode given by GetMapMode()
277 @param rPara[0 .. n-1]
278 Index of paragraph the point is within
280 @param rIndex[0 .. m-1]
281 Index of character the point is over
283 @return true, if the point is over any text and both rPara and rIndex are valid
286 virtual bool GetIndexAtPoint( const Point& rPoint, sal_Int32& rPara, sal_Int32& rIndex ) const = 0;
288 /** Get the start and the end index of the word at the given index
290 An index value on a word leads from the first character of
291 that word up to and including the last space before the next
292 word. The index values returned do not contain any leading or
293 trailing white-space. If the input indices are invalid,
294 sal_False is returned.
296 @param nPara[0 .. n-1]
297 Index of paragraph to start the search in
299 @param nIndex[0 .. m-1]
300 Index of character to query the search on
302 @param rStart
303 Start index (in the same paragraph)
305 @param rEnd
306 End index (in the same paragraph), this point to the last
307 character still contained in the query
309 @return true, if the result is non-empty
311 virtual bool GetWordIndices( sal_Int32 nPara, sal_Int32 nIndex, sal_Int32& rStart, sal_Int32& rEnd ) const = 0;
313 /** Query range of similar attributes
315 Please note that the range returned is half-open: [nStartIndex,nEndIndex)
317 @param nStartIndex
318 Herein, the start index of the range of similar attributes is returned
320 @param nEndIndex
321 Herein, the end index (exclusive) of the range of similar attributes is returned
323 @param nIndex
324 The character index from which the range of similar attributed characters is requested
326 @return true, if the range has been successfully determined
328 virtual bool GetAttributeRun( sal_Int32& nStartIndex, sal_Int32& nEndIndex, sal_Int32 nPara, sal_Int32 nIndex, bool bInCell = false ) const = 0;
330 /** Query number of lines in the formatted paragraph
332 @param nPara[0 .. n-1]
333 Index of paragraph to query number of lines in
335 @return number of lines in given paragraph
338 virtual sal_Int32 GetLineCount( sal_Int32 nPara ) const = 0;
340 /** Query line length
342 @param nPara[0 .. n-1]
343 Index of paragraph to query line length in
345 @param nLine[0 .. m-1]
346 Index of line in paragraph to query line length of
349 virtual sal_Int32 GetLineLen( sal_Int32 nPara, sal_Int32 nLine ) const = 0;
351 /** Query bounds of line in paragraph
353 @param rStart [output param; 0 .. text_len]
354 The index in the paragraph text that belongs to the chara at the start of the line
356 @param rEnd [output param; 0 .. text_len]
357 The index in the paragraph text that follows the last chara in the line
359 @param nParagraph[0 .. n-1]
360 Index of paragraph to query line length in
362 @param nLine[0 .. m-1]
363 Index of line in paragraph to query line length of
366 virtual void GetLineBoundaries( /*out*/sal_Int32 &rStart, /*out*/sal_Int32 &rEnd, sal_Int32 nParagraph, sal_Int32 nLine ) const = 0;
368 /** Query the line number for an index in the paragraphs text
370 @param nPara[0 .. n-1]
371 Index of paragraph to query line length in
373 @param nIndex[0 .. m-1]
374 Index of the char in the paragraph text
376 @returns [0 .. k-1]
377 The line number of the char in the paragraph
379 virtual sal_Int32 GetLineNumberAtIndex( sal_Int32 nPara, sal_Int32 nIndex ) const = 0;
381 /** Delete given text range and reformat text
383 @param rSelection
384 The text range to be deleted
386 @return true if text has been successfully deleted
388 virtual bool Delete( const ESelection& rSelection ) = 0;
390 /** Insert/Replace given text in given range and reformat text
392 @param rText
393 Text to insert/replace
395 @param rSel
396 Selection where text should be replaced. The empty selection inserts
398 @return true if text has been successfully inserted
400 virtual bool InsertText( const OUString& rText, const ESelection& rSel ) = 0;
402 /** Updates the formatting
404 @see EditEngine::QuickFormatDoc() for details
406 @return true if text have been successfully reformatted
408 virtual bool QuickFormatDoc( bool bFull = false ) = 0;
410 /** Get the outline depth of given paragraph
412 @param nPara
413 Index of the paragraph to query the depth of
415 @return the outline level of the given paragraph. The range is
416 [0,n), where n is the maximal outline level.
418 virtual sal_Int16 GetDepth( sal_Int32 nPara ) const = 0;
420 /** Set the outline depth of given paragraph
422 @param nPara
423 Index of the paragraph to set the depth of
425 @param nNewDepth
426 The depth to set on the given paragraph. The range is
427 [0,n), where n is the maximal outline level.
429 @return true, if depth could be successfully set. Reasons for
430 failure are e.g. the text does not support outline level
431 (EditEngine), or the depth range is exceeded.
433 virtual bool SetDepth( sal_Int32 nPara, sal_Int16 nNewDepth ) = 0;
435 virtual sal_Int32 GetNumberingStartValue( sal_Int32 nPara );
436 virtual void SetNumberingStartValue( sal_Int32 nPara, sal_Int32 nNumberingStartValue );
438 virtual bool IsParaIsNumberingRestart( sal_Int32 nPara );
439 virtual void SetParaIsNumberingRestart( sal_Int32 nPara, bool bParaIsNumberingRestart );
442 /** Encapsulates the document view for the purpose of unified
443 EditEngine/Outliner access.
445 This one has to be different from the SvxEditViewForwarder, since
446 the latter is only valid in edit mode.
448 class EDITENG_DLLPUBLIC SvxViewForwarder
450 public:
451 virtual ~SvxViewForwarder();
453 /** Query state of forwarder
455 @return sal_False, if no longer valid
457 virtual bool IsValid() const = 0;
459 /** Convert from logical, EditEngine-relative coordinates to screen coordinates
461 @param rPoint
462 Point in logical, EditEngine-relative coordinates.
464 @param rMapMode
465 The map mode to interpret the coordinates in.
467 @return the point in screen coordinates
469 virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const = 0;
471 /** Convert from screen to logical, EditEngine-relative coordinates
473 @param rPoint
474 Point in screen coordinates
476 @param rMapMode
477 The map mode to interpret the coordinates in.
479 @return the point in logical coordinates.
481 virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const = 0;
486 /** Encapsulates EditView and OutlinerView for the purpose of unified
487 EditEngine/Outliner access
489 class SvxEditViewForwarder : public SvxViewForwarder
491 public:
493 /** Query current selection.
495 @param rSelection
496 Contains the current selection after method call
498 @return false, if there is no view or no selection (the empty selection _is_ a selection)
501 virtual bool GetSelection( ESelection& rSelection ) const = 0;
503 /** Set selection in view.
505 @param rSelection
506 The selection to set
508 @return false, if there is no view or selection is invalid
510 virtual bool SetSelection( const ESelection& rSelection ) = 0;
512 /** Copy current selection to clipboard.
514 @return false if no selection or no view (the empty selection _is_ a selection)
516 virtual bool Copy() = 0;
518 /** Cut current selection to clipboard.
520 @return false if no selection or no view (the empty selection _is_ a selection)
522 virtual bool Cut() = 0;
524 /** Paste clipboard into current selection.
526 @return false if no view or no selection (the empty selection _is_ a selection)
528 virtual bool Paste() = 0;
532 #endif
534 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */