Line data Source code
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 <com/sun/star/accessibility/TextSegment.hpp>
24 :
25 : #include <i18nlangtag/lang.h>
26 : #include <rtl/ustring.hxx>
27 : #include <tools/gen.hxx>
28 : #include <vcl/mapmod.hxx>
29 : #include <tools/color.hxx>
30 : #include <svl/poolitem.hxx>
31 : #include <svl/itempool.hxx>
32 : #include <editeng/editengdllapi.h>
33 : #include <editeng/editeng.hxx>
34 :
35 : #include <list>
36 :
37 : struct ESelection;
38 : struct EFieldInfo;
39 : struct EBulletInfo;
40 : class OutputDevice;
41 : class SfxItemSet;
42 : class SvxTextForwarder;
43 : class SvxViewForwarder;
44 : class SvxEditViewForwarder;
45 : class SvxFieldItem;
46 : class SfxBroadcaster;
47 : class SvxUnoTextRangeBase;
48 :
49 : typedef std::list< SvxUnoTextRangeBase* > SvxUnoTextRangeBaseList;
50 :
51 : /** Wrapper class for unified EditEngine/Outliner access
52 :
53 : This class wraps a textual object, which might or might not
54 : contain an EditEngine/Outliner. Is used e.g. for filling an
55 : EditEngine with the content of a cell, note page or page template.
56 : */
57 0 : class EDITENG_DLLPUBLIC SvxEditSource
58 : {
59 : public:
60 : virtual ~SvxEditSource();
61 :
62 : /// Returns a new reference to the same object. This is a shallow copy
63 : virtual SvxEditSource* Clone() const = 0;
64 :
65 : /** Query the text forwarder
66 :
67 : @return the text forwarder, or NULL if the underlying object is dead
68 : */
69 : virtual SvxTextForwarder* GetTextForwarder() = 0;
70 :
71 : /** Query the view forwarder
72 :
73 : @return the view forwarder, or NULL if the underlying object
74 : is dead, or if no view is available
75 :
76 : @derive default implementation provided, overriding is optional
77 : */
78 : virtual SvxViewForwarder* GetViewForwarder();
79 :
80 : /** Query the edit view forwarder
81 :
82 : @param bCreate
83 : Determines whether an EditView should be created, if there is
84 : none active. If set to sal_True, and the underlying object is
85 : not in EditMode, the text forwarder changes and the object is
86 : set to EditMode.
87 :
88 : @return the edit view forwarder, or NULL if the underlying
89 : object is dead, or if no view is available (if bCreate is
90 : sal_False, NULL is also returned if the object is not in
91 : EditMode)
92 :
93 : @derive default implementation provided, overriding is optional
94 :
95 : @attention If this method is called with bCreate equal to
96 : sal_True, all previously returned text forwarder can become
97 : invalid
98 : */
99 : virtual SvxEditViewForwarder* GetEditViewForwarder( bool bCreate = false );
100 :
101 : /// Write back data to model
102 : virtual void UpdateData() = 0;
103 :
104 : /** Returns broadcaster the underlying edit engine's events are sent from
105 :
106 : @derive default implementation provided, overriding is optional
107 : */
108 : virtual SfxBroadcaster& GetBroadcaster() const;
109 :
110 : /** adds the given SvxUnoTextRangeBase to the text object
111 : capsulated by this SvxEditSource. This allows the text
112 : object to inform all created text ranges about changes
113 : and also allows to re use already created instances.
114 : All SvxUnoTextRangeBase must remove itself with
115 : removeRange() before theire deleted. */
116 : virtual void addRange( SvxUnoTextRangeBase* pNewRange );
117 :
118 : /** removes the given SvxUnoTextRangeBase from the text
119 : object capsulated by this SvxEditSource. This text range
120 : will not be informed any longer of changes on the underlying
121 : text and will also not re used anymore. */
122 : virtual void removeRange( SvxUnoTextRangeBase* pOldRange );
123 :
124 : /** returns a const list of all text ranges that are registered
125 : for the underlying text object. */
126 : virtual const SvxUnoTextRangeBaseList& getRanges() const;
127 : };
128 :
129 :
130 : /** Contains an EditEngine or an Outliner and unifies access to them.
131 :
132 : The EditEngine-UNO objects use this class only. To reflect changes
133 : not only in the EditEngine, but also in the model data, call
134 : SvxEditSource::UpdateData(). This copies back the data to the model's
135 : EditTextObject/OutlinerParaObject.
136 : */
137 0 : class EDITENG_DLLPUBLIC SvxTextForwarder
138 : {
139 : public:
140 : virtual ~SvxTextForwarder();
141 :
142 : virtual sal_Int32 GetParagraphCount() const = 0;
143 : virtual sal_Int32 GetTextLen( sal_Int32 nParagraph ) const = 0;
144 : virtual OUString GetText( const ESelection& rSel ) const = 0;
145 : virtual SfxItemSet GetAttribs( const ESelection& rSel, EditEngineAttribs nOnlyHardAttrib = EditEngineAttribs_All ) const = 0;
146 : virtual SfxItemSet GetParaAttribs( sal_Int32 nPara ) const = 0;
147 : virtual void SetParaAttribs( sal_Int32 nPara, const SfxItemSet& rSet ) = 0;
148 : virtual void RemoveAttribs( const ESelection& rSelection, bool bRemoveParaAttribs, sal_uInt16 nWhich ) = 0;
149 : virtual void GetPortions( sal_Int32 nPara, std::vector<sal_Int32>& rList ) const = 0;
150 :
151 : virtual sal_uInt16 GetItemState( const ESelection& rSel, sal_uInt16 nWhich ) const = 0;
152 : virtual sal_uInt16 GetItemState( sal_Int32 nPara, sal_uInt16 nWhich ) const = 0;
153 :
154 : virtual void QuickInsertText( const OUString& rText, const ESelection& rSel ) = 0;
155 : virtual void QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel ) = 0;
156 : virtual void QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel ) = 0;
157 : virtual void QuickInsertLineBreak( const ESelection& rSel ) = 0;
158 :
159 : virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rpTxtColor, Color*& rpFldColor ) = 0;
160 : virtual void FieldClicked( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos ) = 0;
161 :
162 : virtual SfxItemPool* GetPool() const = 0;
163 :
164 : virtual const SfxItemSet* GetEmptyItemSetPtr() = 0;
165 :
166 : // implementation functions for XParagraphAppend and XTextPortionAppend
167 : virtual void AppendParagraph() = 0;
168 : virtual sal_Int32 AppendTextPortion( sal_Int32 nPara, const OUString &rText, const SfxItemSet &rSet ) = 0;
169 :
170 : // XTextCopy
171 : virtual void CopyText(const SvxTextForwarder& rSource) = 0;
172 :
173 : /** Query state of forwarder
174 :
175 : @return false, if no longer valid
176 : */
177 : virtual bool IsValid() const = 0;
178 :
179 : /** Query language of character at given position on the underlying edit engine
180 :
181 : @param nPara[0 .. n-1]
182 : Index of paragraph to query language in
183 :
184 : @param nIndex[0 .. m-1]
185 : Index of character to query language of
186 : */
187 : virtual LanguageType GetLanguage( sal_Int32 nPara, sal_Int32 nIndex ) const = 0;
188 :
189 : /** Query number of fields in the underlying edit engine
190 :
191 : @param nPara[0 .. n-1]
192 : Index of paragraph to query field number in
193 : */
194 : virtual sal_Int32 GetFieldCount( sal_Int32 nPara ) const = 0;
195 :
196 : /** Query information for given field number in the underlying edit engine
197 :
198 : @param nPara[0 .. n-1]
199 : Index of paragraph to query field info in
200 :
201 : @param nField[0 .. m-1]
202 : Index of field to query information of
203 : */
204 : virtual EFieldInfo GetFieldInfo( sal_Int32 nPara, sal_uInt16 nField ) const = 0;
205 :
206 : /** Query information regarding bullets for given paragraph on the underlying edit engine
207 :
208 : @param nPara[0 .. n-1]
209 : Index of paragraph to query bullet info on
210 : */
211 : virtual EBulletInfo GetBulletInfo( sal_Int32 nPara ) const = 0;
212 :
213 0 : virtual OUString GetNumStr(sal_uInt16) const { return OUString(); }
214 0 : virtual void SetUpdateModeForAcc(bool) {}
215 0 : virtual bool GetUpdateModeForAcc() const { return true; }
216 :
217 : /** Query the bounding rectangle of the given character
218 :
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 : rougly 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>
230 :
231 : @param nIndex[0 .. m-1]
232 : Index of character to query the bounds of
233 :
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().
237 : */
238 : virtual Rectangle GetCharBounds( sal_Int32 nPara, sal_Int32 nIndex ) const = 0;
239 :
240 : /** Query the bounding rectangle of the given paragraph
241 :
242 : @param nPara[0 .. n-1]
243 : Index of paragraph to query the bounds of
244 :
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().
248 : */
249 : virtual Rectangle GetParaBounds( sal_Int32 nPara ) const = 0;
250 :
251 : /** Query the map mode of the underlying EditEngine/Outliner
252 :
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.
257 : */
258 : virtual MapMode GetMapMode() const = 0;
259 :
260 : /** Query the reference output device of the underlying EditEngine/Outliner
261 :
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.
266 : */
267 : virtual OutputDevice* GetRefDevice() const = 0;
268 :
269 : /** Query paragraph and character index of the character at the
270 : given point. Returns sal_True on success, sal_False otherwise
271 :
272 : @param rPoint
273 : Point to query text position of. Is interpreted in logical
274 : coordinates, relativ to the upper left corner of the text, and
275 : in the map mode given by GetMapMode()
276 :
277 : @param rPara[0 .. n-1]
278 : Index of paragraph the point is within
279 :
280 : @param rIndex[0 .. m-1]
281 : Index of character the point is over
282 :
283 : @return true, if the point is over any text and both rPara and rIndex are valid
284 :
285 : */
286 : virtual bool GetIndexAtPoint( const Point& rPoint, sal_Int32& rPara, sal_Int32& rIndex ) const = 0;
287 :
288 : /** Get the start and the end index of the word at the given index
289 :
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.
295 :
296 : @param nPara[0 .. n-1]
297 : Index of paragraph to start the search in
298 :
299 : @param nIndex[0 .. m-1]
300 : Index of character to query the search on
301 :
302 : @param rStart
303 : Start index (in the same paragraph)
304 :
305 : @param rEnd
306 : End index (in the same paragraph), this point to the last
307 : character still contained in the query
308 :
309 : @return true, if the result is non-empty
310 : */
311 : virtual bool GetWordIndices( sal_Int32 nPara, sal_Int32 nIndex, sal_Int32& rStart, sal_Int32& rEnd ) const = 0;
312 :
313 : /** Query range of similar attributes
314 :
315 : Please note that the range returned is half-open: [nStartIndex,nEndIndex)
316 :
317 : @param nStartIndex
318 : Herein, the start index of the range of similar attributes is returned
319 :
320 : @param nEndIndex
321 : Herein, the end index (exclusive) of the range of similar attributes is returned
322 :
323 : @param nIndex
324 : The character index from which the range of similar attributed characters is requested
325 :
326 : @return true, if the range has been successfully determined
327 : */
328 : virtual bool GetAttributeRun( sal_Int32& nStartIndex, sal_Int32& nEndIndex, sal_Int32 nPara, sal_Int32 nIndex, bool bInCell = false ) const = 0;
329 :
330 : /** Query number of lines in the formatted paragraph
331 :
332 : @param nPara[0 .. n-1]
333 : Index of paragraph to query number of lines in
334 :
335 : @return number of lines in given paragraph
336 :
337 : */
338 : virtual sal_Int32 GetLineCount( sal_Int32 nPara ) const = 0;
339 :
340 : /** Query line length
341 :
342 : @param nPara[0 .. n-1]
343 : Index of paragraph to query line length in
344 :
345 : @param nLine[0 .. m-1]
346 : Index of line in paragraph to query line length of
347 :
348 : */
349 : virtual sal_Int32 GetLineLen( sal_Int32 nPara, sal_Int32 nLine ) const = 0;
350 :
351 : /** Query bounds of line in paragraph
352 :
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
355 :
356 : @param rEnd [output param; 0 .. text_len]
357 : The index in the paragraph text that follows the last chara in the line
358 :
359 : @param nParagraph[0 .. n-1]
360 : Index of paragraph to query line length in
361 :
362 : @param nLine[0 .. m-1]
363 : Index of line in paragraph to query line length of
364 :
365 : */
366 : virtual void GetLineBoundaries( /*out*/sal_Int32 &rStart, /*out*/sal_Int32 &rEnd, sal_Int32 nParagraph, sal_Int32 nLine ) const = 0;
367 :
368 : /** Query the line number for a index in the paragraphs text
369 :
370 : @param nPara[0 .. n-1]
371 : Index of paragraph to query line length in
372 :
373 : @param nIndex[0 .. m-1]
374 : Index of of the chara in the paragraph text
375 :
376 : @returns [0 .. k-1]
377 : The line number of the chara in the paragraph
378 : */
379 : virtual sal_Int32 GetLineNumberAtIndex( sal_Int32 nPara, sal_Int32 nIndex ) const = 0;
380 :
381 : /** Delete given text range and reformat text
382 :
383 : @param rSelection
384 : The text range to be deleted
385 :
386 : @return true if text has been successfully deleted
387 : */
388 : virtual bool Delete( const ESelection& rSelection ) = 0;
389 :
390 : /** Insert/Replace given text in given range and reformat text
391 :
392 : @param rText
393 : Text to insert/replace
394 :
395 : @param rSel
396 : Selection where text should be replaced. The empty selection inserts
397 :
398 : @return true if text has been successfully inserted
399 : */
400 : virtual bool InsertText( const OUString& rText, const ESelection& rSel ) = 0;
401 :
402 : /** Updates the formatting
403 :
404 : @see EditEngine::QuickFormatDoc() for details
405 :
406 : @return true if text have been successfully reformatted
407 : */
408 : virtual bool QuickFormatDoc( bool bFull = false ) = 0;
409 :
410 : /** Get the outline depth of given paragraph
411 :
412 : @param nPara
413 : Index of the paragraph to query the depth of
414 :
415 : @return the outline level of the given paragraph. The range is
416 : [0,n), where n is the maximal outline level.
417 : */
418 : virtual sal_Int16 GetDepth( sal_Int32 nPara ) const = 0;
419 :
420 : /** Set the outline depth of given paragraph
421 :
422 : @param nPara
423 : Index of the paragraph to set the depth of
424 :
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.
428 :
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.
432 : */
433 : virtual bool SetDepth( sal_Int32 nPara, sal_Int16 nNewDepth ) = 0;
434 :
435 : virtual sal_Int32 GetNumberingStartValue( sal_Int32 nPara );
436 : virtual void SetNumberingStartValue( sal_Int32 nPara, sal_Int32 nNumberingStartValue );
437 :
438 : virtual bool IsParaIsNumberingRestart( sal_Int32 nPara );
439 : virtual void SetParaIsNumberingRestart( sal_Int32 nPara, bool bParaIsNumberingRestart );
440 : };
441 :
442 : /** Encapsulates the document view for the purpose of unified
443 : EditEngine/Outliner access.
444 :
445 : This one has to be different from the SvxEditViewForwarder, since
446 : the latter is only valid in edit mode.
447 : */
448 0 : class EDITENG_DLLPUBLIC SvxViewForwarder
449 : {
450 : public:
451 : virtual ~SvxViewForwarder();
452 :
453 : /** Query state of forwarder
454 :
455 : @return sal_False, if no longer valid
456 : */
457 : virtual bool IsValid() const = 0;
458 :
459 : /** Query visible area of the view containing the text
460 :
461 : @return the visible rectangle of the text, i.e. the part of
462 : the EditEngine or Outliner that is currently on screen. The
463 : values are already in screen coordinates (pixel), and have to
464 : be relative to the EditEngine/Outliner's upper left corner.
465 : */
466 : virtual Rectangle GetVisArea() const = 0;
467 :
468 : /** Convert from logical, EditEngine-relative coordinates to screen coordinates
469 :
470 : @param rPoint
471 : Point in logical, EditEngine-relative coordinates.
472 :
473 : @param rMapMode
474 : The map mode to interpret the coordinates in.
475 :
476 : @return the point in screen coordinates
477 : */
478 : virtual Point LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const = 0;
479 :
480 : /** Convert from screen to logical, EditEngine-relative coordinates
481 :
482 : @param rPoint
483 : Point in screen coordinates
484 :
485 : @param rMapMode
486 : The map mode to interpret the coordinates in.
487 :
488 : @return the point in logical coordinates.
489 : */
490 : virtual Point PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const = 0;
491 :
492 : };
493 :
494 :
495 : /** Encapsulates EditView and OutlinerView for the purpose of unified
496 : EditEngine/Outliner access
497 : */
498 0 : class SvxEditViewForwarder : public SvxViewForwarder
499 : {
500 : public:
501 :
502 : /** Query current selection.
503 :
504 : @param rSelection
505 : Contains the current selection after method call
506 :
507 : @return false, if there is no view or no selection (the empty selection _is_ a selection)
508 :
509 : */
510 : virtual bool GetSelection( ESelection& rSelection ) const = 0;
511 :
512 : /** Set selection in view.
513 :
514 : @param rSelection
515 : The selection to set
516 :
517 : @return false, if there is no view or selection is invalid
518 : */
519 : virtual bool SetSelection( const ESelection& rSelection ) = 0;
520 :
521 : /** Copy current selection to clipboard.
522 :
523 : @return false if no selection or no view (the empty selection _is_ a selection)
524 : */
525 : virtual bool Copy() = 0;
526 :
527 : /** Cut current selection to clipboard.
528 :
529 : @eturn balse if no selection or no view (the empty selection _is_ a selection)
530 : */
531 : virtual bool Cut() = 0;
532 :
533 : /** Paste clipboard into current selection.
534 :
535 : @return false if no view or no selection (the empty selection _is_ a selection)
536 : */
537 : virtual bool Paste() = 0;
538 :
539 0 : virtual bool IsWrongSpelledWordAtPos( sal_Int32, sal_Int32 ) { return false; };
540 0 : virtual bool IsShapeParaFocusable( ) { return true; };
541 0 : virtual bool BreakParaWrongList(sal_Int32, sal_Int32&, sal_Int32&, sal_Int32){ return false; };
542 : };
543 :
544 : #endif
545 :
546 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|