/src/libreoffice/include/editeng/unoedsrc.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #ifndef INCLUDED_EDITENG_UNOEDSRC_HXX |
21 | | #define INCLUDED_EDITENG_UNOEDSRC_HXX |
22 | | |
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> |
31 | | |
32 | | #include <vector> |
33 | | |
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; |
46 | | |
47 | | typedef std::vector< SvxUnoTextRangeBase* > SvxUnoTextRangeBaseVec; |
48 | | |
49 | | /** Wrapper class for unified EditEngine/Outliner access |
50 | | |
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. |
54 | | */ |
55 | | class EDITENG_DLLPUBLIC SvxEditSource |
56 | | { |
57 | | public: |
58 | 1.24M | SvxEditSource() = default; |
59 | 2.53k | SvxEditSource(SvxEditSource const &) = default; |
60 | | SvxEditSource(SvxEditSource &&) = default; |
61 | | SvxEditSource & operator =(SvxEditSource const &) = default; |
62 | | SvxEditSource & operator =(SvxEditSource &&) = default; |
63 | | |
64 | | virtual ~SvxEditSource(); |
65 | | |
66 | | /// Returns a new reference to the same object. This is a shallow copy |
67 | | virtual std::unique_ptr<SvxEditSource> Clone() const = 0; |
68 | | |
69 | | /** Query the text forwarder |
70 | | |
71 | | @return the text forwarder, or NULL if the underlying object is dead |
72 | | */ |
73 | | virtual SvxTextForwarder* GetTextForwarder() = 0; |
74 | | |
75 | | /** Query the view forwarder |
76 | | |
77 | | @return the view forwarder, or NULL if the underlying object |
78 | | is dead, or if no view is available |
79 | | |
80 | | @derive default implementation provided, overriding is optional |
81 | | */ |
82 | | virtual SvxViewForwarder* GetViewForwarder(); |
83 | | |
84 | | /** Query the edit view forwarder |
85 | | |
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. |
91 | | |
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) |
96 | | |
97 | | @derive default implementation provided, overriding is optional |
98 | | |
99 | | @attention If this method is called with bCreate equal to |
100 | | sal_True, all previously returned text forwarder can become |
101 | | invalid |
102 | | */ |
103 | | virtual SvxEditViewForwarder* GetEditViewForwarder( bool bCreate = false ); |
104 | | |
105 | | /// Write back data to model |
106 | | virtual void UpdateData() = 0; |
107 | | |
108 | | /** Returns broadcaster the underlying edit engine's events are sent from |
109 | | |
110 | | @derive default implementation provided, overriding is optional |
111 | | */ |
112 | | virtual SfxBroadcaster& GetBroadcaster() const; |
113 | | |
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 ); |
121 | | |
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 ); |
127 | | |
128 | | /** returns a const list of all text ranges that are registered |
129 | | for the underlying text object. */ |
130 | | virtual const SvxUnoTextRangeBaseVec& getRanges() const; |
131 | | }; |
132 | | |
133 | | |
134 | | /** Contains an EditEngine or an Outliner and unifies access to them. |
135 | | |
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. |
140 | | */ |
141 | | class EDITENG_DLLPUBLIC SvxTextForwarder |
142 | | { |
143 | | public: |
144 | | virtual ~SvxTextForwarder(); |
145 | | |
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; |
154 | | |
155 | | virtual OUString GetStyleSheet(sal_Int32 nPara) const = 0; |
156 | | virtual void SetStyleSheet(sal_Int32 nPara, const OUString& rStyleName) = 0; |
157 | | |
158 | | virtual SfxItemState GetItemState( const ESelection& rSel, sal_uInt16 nWhich ) const = 0; |
159 | | virtual SfxItemState GetItemState( sal_Int32 nPara, sal_uInt16 nWhich ) const = 0; |
160 | | |
161 | | virtual void QuickInsertText( const OUString& rText, const ESelection& rSel ) = 0; |
162 | | virtual void QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel ) = 0; |
163 | | virtual void QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel ) = 0; |
164 | | virtual void QuickInsertLineBreak( const ESelection& rSel ) = 0; |
165 | | |
166 | | 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; |
167 | | virtual void FieldClicked( const SvxFieldItem& rField ) = 0; |
168 | | |
169 | | virtual SfxItemPool* GetPool() const = 0; |
170 | | |
171 | | virtual const SfxItemSet* GetEmptyItemSetPtr() = 0; |
172 | | |
173 | | // implementation functions for XParagraphAppend and XTextPortionAppend |
174 | | virtual void AppendParagraph() = 0; |
175 | | virtual sal_Int32 AppendTextPortion( sal_Int32 nPara, const OUString &rText, const SfxItemSet &rSet ) = 0; |
176 | | |
177 | | // XTextCopy |
178 | | virtual void CopyText(const SvxTextForwarder& rSource) = 0; |
179 | | |
180 | | /** Query state of forwarder |
181 | | |
182 | | @return false, if no longer valid |
183 | | */ |
184 | | virtual bool IsValid() const = 0; |
185 | | |
186 | | /** Query language of character at given position on the underlying edit engine |
187 | | |
188 | | @param nPara[0 .. n-1] |
189 | | Index of paragraph to query language in |
190 | | |
191 | | @param nIndex[0 .. m-1] |
192 | | Index of character to query language of |
193 | | */ |
194 | | virtual LanguageType GetLanguage( sal_Int32 nPara, sal_Int32 nIndex ) const = 0; |
195 | | |
196 | | /** Query information for fields in the underlying edit engine |
197 | | |
198 | | @param nPara[0 .. n-1] |
199 | | Index of paragraph to query field info in |
200 | | */ |
201 | | virtual std::vector<EFieldInfo> GetFieldInfo( sal_Int32 nPara ) const = 0; |
202 | | |
203 | | /** Query information regarding bullets for given paragraph on the underlying edit engine |
204 | | |
205 | | @param nPara[0 .. n-1] |
206 | | Index of paragraph to query bullet info on |
207 | | */ |
208 | | virtual EBulletInfo GetBulletInfo( sal_Int32 nPara ) const = 0; |
209 | | |
210 | | /** Query the bounding rectangle of the given character |
211 | | |
212 | | @param nPara[0 .. n] |
213 | | Index of paragraph to query the bounds in. <p>The virtual |
214 | | character after the last character of the represented text, |
215 | | i.e. the one at position n is a special case. Because it does |
216 | | not represent an existing character its bounding box is |
217 | | defined in relation to preceding characters. It should be |
218 | | roughly equivalent to the bounding box of some character when |
219 | | inserted at the end of the text. Its height typically being |
220 | | the maximal height of all the characters in the text or the |
221 | | height of the preceding character, its width being at least |
222 | | one pixel so that the bounding box is not degenerate.<br> |
223 | | |
224 | | @param nIndex[0 .. m-1] |
225 | | Index of character to query the bounds of |
226 | | |
227 | | @return rectangle in logical coordinates, relative to upper |
228 | | left corner of text. The coordinates returned here are to be |
229 | | interpreted in the map mode given by GetMapMode(). |
230 | | */ |
231 | | virtual tools::Rectangle GetCharBounds( sal_Int32 nPara, sal_Int32 nIndex ) const = 0; |
232 | | |
233 | | /** Query the bounding rectangle of the given paragraph |
234 | | |
235 | | @param nPara[0 .. n-1] |
236 | | Index of paragraph to query the bounds of |
237 | | |
238 | | @return rectangle in logical coordinates, relative to upper |
239 | | left corner of text. The coordinates returned here are to be |
240 | | interpreted in the map mode given by GetMapMode(). |
241 | | */ |
242 | | virtual tools::Rectangle GetParaBounds( sal_Int32 nPara ) const = 0; |
243 | | |
244 | | /** Query the map mode of the underlying EditEngine/Outliner |
245 | | |
246 | | @return the map mode used on the EditEngine/Outliner. The |
247 | | values returned by GetParaBounds() and GetCharBounds() are to |
248 | | be interpreted in this map mode, the point given to |
249 | | GetIndexAtPoint() is interpreted in this map mode. |
250 | | */ |
251 | | virtual MapMode GetMapMode() const = 0; |
252 | | |
253 | | /** Query the reference output device of the underlying EditEngine/Outliner |
254 | | |
255 | | @return the OutputDevice used from the EditEngine/Outliner to |
256 | | format the text. It should be used when performing e.g. font |
257 | | calculations, since this is usually a printer with fonts and |
258 | | resolution different from the screen. |
259 | | */ |
260 | | virtual OutputDevice* GetRefDevice() const = 0; |
261 | | |
262 | | /** Query paragraph and character index of the character at the |
263 | | given point. Returns sal_True on success, sal_False otherwise |
264 | | |
265 | | @param rPoint |
266 | | Point to query text position of. Is interpreted in logical |
267 | | coordinates, relative to the upper left corner of the text, and |
268 | | in the map mode given by GetMapMode() |
269 | | |
270 | | @param rPara[0 .. n-1] |
271 | | Index of paragraph the point is within |
272 | | |
273 | | @param rIndex[0 .. m-1] |
274 | | Index of character the point is over |
275 | | |
276 | | @return true, if the point is over any text and both rPara and rIndex are valid |
277 | | |
278 | | */ |
279 | | virtual bool GetIndexAtPoint( const Point& rPoint, sal_Int32& rPara, sal_Int32& rIndex ) const = 0; |
280 | | |
281 | | /** Get the start and the end index of the word at the given index |
282 | | |
283 | | An index value on a word leads from the first character of |
284 | | that word up to and including the last space before the next |
285 | | word. The index values returned do not contain any leading or |
286 | | trailing white-space. If the input indices are invalid, |
287 | | sal_False is returned. |
288 | | |
289 | | @param nPara[0 .. n-1] |
290 | | Index of paragraph to start the search in |
291 | | |
292 | | @param nIndex[0 .. m-1] |
293 | | Index of character to query the search on |
294 | | |
295 | | @param rStart |
296 | | Start index (in the same paragraph) |
297 | | |
298 | | @param rEnd |
299 | | End index (in the same paragraph), this point to the last |
300 | | character still contained in the query |
301 | | |
302 | | @return true, if the result is non-empty |
303 | | */ |
304 | | virtual bool GetWordIndices( sal_Int32 nPara, sal_Int32 nIndex, sal_Int32& rStart, sal_Int32& rEnd ) const = 0; |
305 | | |
306 | | /** Query range of similar attributes |
307 | | |
308 | | Please note that the range returned is half-open: [nStartIndex,nEndIndex) |
309 | | |
310 | | @param nStartIndex |
311 | | Herein, the start index of the range of similar attributes is returned |
312 | | |
313 | | @param nEndIndex |
314 | | Herein, the end index (exclusive) of the range of similar attributes is returned |
315 | | |
316 | | @param nIndex |
317 | | The character index from which the range of similar attributed characters is requested |
318 | | |
319 | | @return true, if the range has been successfully determined |
320 | | */ |
321 | | virtual bool GetAttributeRun( sal_Int32& nStartIndex, sal_Int32& nEndIndex, sal_Int32 nPara, sal_Int32 nIndex, bool bInCell = false ) const = 0; |
322 | | |
323 | | /** Query number of lines in the formatted paragraph |
324 | | |
325 | | @param nPara[0 .. n-1] |
326 | | Index of paragraph to query number of lines in |
327 | | |
328 | | @return number of lines in given paragraph |
329 | | |
330 | | */ |
331 | | virtual sal_Int32 GetLineCount( sal_Int32 nPara ) const = 0; |
332 | | |
333 | | /** Query line length |
334 | | |
335 | | @param nPara[0 .. n-1] |
336 | | Index of paragraph to query line length in |
337 | | |
338 | | @param nLine[0 .. m-1] |
339 | | Index of line in paragraph to query line length of |
340 | | |
341 | | */ |
342 | | virtual sal_Int32 GetLineLen( sal_Int32 nPara, sal_Int32 nLine ) const = 0; |
343 | | |
344 | | /** Query bounds of line in paragraph |
345 | | |
346 | | @param rStart [output param; 0 .. text_len] |
347 | | The index in the paragraph text that belongs to the chara at the start of the line |
348 | | |
349 | | @param rEnd [output param; 0 .. text_len] |
350 | | The index in the paragraph text that follows the last chara in the line |
351 | | |
352 | | @param nParagraph[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 void GetLineBoundaries( /*out*/sal_Int32 &rStart, /*out*/sal_Int32 &rEnd, sal_Int32 nParagraph, sal_Int32 nLine ) const = 0; |
360 | | |
361 | | /** Query the line number for an index in the paragraphs text |
362 | | |
363 | | @param nPara[0 .. n-1] |
364 | | Index of paragraph to query line length in |
365 | | |
366 | | @param nIndex[0 .. m-1] |
367 | | Index of the char in the paragraph text |
368 | | |
369 | | @returns [0 .. k-1] |
370 | | The line number of the char in the paragraph |
371 | | */ |
372 | | virtual sal_Int32 GetLineNumberAtIndex( sal_Int32 nPara, sal_Int32 nIndex ) const = 0; |
373 | | |
374 | | /** Delete given text range and reformat text |
375 | | |
376 | | @param rSelection |
377 | | The text range to be deleted |
378 | | |
379 | | @return true if text has been successfully deleted |
380 | | */ |
381 | | virtual bool Delete( const ESelection& rSelection ) = 0; |
382 | | |
383 | | /** Insert/Replace given text in given range and reformat text |
384 | | |
385 | | @param rText |
386 | | Text to insert/replace |
387 | | |
388 | | @param rSel |
389 | | Selection where text should be replaced. The empty selection inserts |
390 | | |
391 | | @return true if text has been successfully inserted |
392 | | */ |
393 | | virtual bool InsertText( const OUString& rText, const ESelection& rSel ) = 0; |
394 | | |
395 | | /** Updates the formatting |
396 | | |
397 | | @see EditEngine::QuickFormatDoc() for details |
398 | | |
399 | | @return true if text have been successfully reformatted |
400 | | */ |
401 | | virtual bool QuickFormatDoc( bool bFull = false ) = 0; |
402 | | |
403 | | // Is able to use Outline depth functions (GetDepth and SetDepth) meaningfully |
404 | | virtual bool SupportsOutlineDepth() const = 0; |
405 | | |
406 | | /** Get the outline depth of given paragraph |
407 | | |
408 | | @param nPara |
409 | | Index of the paragraph to query the depth of |
410 | | |
411 | | @return the outline level of the given paragraph. The range is |
412 | | [0,n), where n is the maximal outline level. |
413 | | */ |
414 | | virtual sal_Int16 GetDepth( sal_Int32 nPara ) const = 0; |
415 | | |
416 | | /** Set the outline depth of given paragraph |
417 | | |
418 | | @param nPara |
419 | | Index of the paragraph to set the depth of |
420 | | |
421 | | @param nNewDepth |
422 | | The depth to set on the given paragraph. The range is |
423 | | [0,n), where n is the maximal outline level. |
424 | | |
425 | | @return true, if depth could be successfully set. Reasons for |
426 | | failure are e.g. the text does not support outline level |
427 | | (EditEngine), or the depth range is exceeded. |
428 | | */ |
429 | | virtual bool SetDepth( sal_Int32 nPara, sal_Int16 nNewDepth ) = 0; |
430 | | |
431 | | virtual sal_Int32 GetNumberingStartValue( sal_Int32 nPara ); |
432 | | virtual void SetNumberingStartValue( sal_Int32 nPara, sal_Int32 nNumberingStartValue ); |
433 | | |
434 | | virtual bool IsParaIsNumberingRestart( sal_Int32 nPara ); |
435 | | virtual void SetParaIsNumberingRestart( sal_Int32 nPara, bool bParaIsNumberingRestart ); |
436 | | }; |
437 | | |
438 | | /** Encapsulates the document view for the purpose of unified |
439 | | EditEngine/Outliner access. |
440 | | |
441 | | This one has to be different from the SvxEditViewForwarder, since |
442 | | the latter is only valid in edit mode. |
443 | | */ |
444 | | class EDITENG_DLLPUBLIC SvxViewForwarder |
445 | | { |
446 | | public: |
447 | | virtual ~SvxViewForwarder(); |
448 | | |
449 | | /** Query state of forwarder |
450 | | |
451 | | @return sal_False, if no longer valid |
452 | | */ |
453 | | virtual bool IsValid() const = 0; |
454 | | |
455 | | /** Convert from logical, EditEngine-relative coordinates to screen coordinates |
456 | | |
457 | | @param rPoint |
458 | | Point in logical, EditEngine-relative coordinates. |
459 | | |
460 | | @param rMapMode |
461 | | The map mode to interpret the coordinates in. |
462 | | |
463 | | @return the point in screen coordinates |
464 | | */ |
465 | | virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const = 0; |
466 | | |
467 | | /** Convert from screen to logical, EditEngine-relative coordinates |
468 | | |
469 | | @param rPoint |
470 | | Point in screen coordinates |
471 | | |
472 | | @param rMapMode |
473 | | The map mode to interpret the coordinates in. |
474 | | |
475 | | @return the point in logical coordinates. |
476 | | */ |
477 | | virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const = 0; |
478 | | |
479 | | }; |
480 | | |
481 | | |
482 | | /** Encapsulates EditView and OutlinerView for the purpose of unified |
483 | | EditEngine/Outliner access |
484 | | */ |
485 | | class SvxEditViewForwarder : public SvxViewForwarder |
486 | | { |
487 | | public: |
488 | | |
489 | | /** Query current selection. |
490 | | |
491 | | @param rSelection |
492 | | Contains the current selection after method call |
493 | | |
494 | | @return false, if there is no view or no selection (the empty selection _is_ a selection) |
495 | | |
496 | | */ |
497 | | virtual bool GetSelection( ESelection& rSelection ) const = 0; |
498 | | |
499 | | /** Set selection in view. |
500 | | |
501 | | @param rSelection |
502 | | The selection to set |
503 | | |
504 | | @return false, if there is no view or selection is invalid |
505 | | */ |
506 | | virtual bool SetSelection( const ESelection& rSelection ) = 0; |
507 | | |
508 | | /** Copy current selection to clipboard. |
509 | | |
510 | | @return false if no selection or no view (the empty selection _is_ a selection) |
511 | | */ |
512 | | virtual bool Copy() = 0; |
513 | | |
514 | | /** Cut current selection to clipboard. |
515 | | |
516 | | @return false if no selection or no view (the empty selection _is_ a selection) |
517 | | */ |
518 | | virtual bool Cut() = 0; |
519 | | |
520 | | /** Paste clipboard into current selection. |
521 | | |
522 | | @return false if no view or no selection (the empty selection _is_ a selection) |
523 | | */ |
524 | | virtual bool Paste() = 0; |
525 | | |
526 | | }; |
527 | | |
528 | | #endif |
529 | | |
530 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |