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 #ifndef INCLUDED_EDITENG_SOURCE_EDITENG_IMPEDIT_HXX
20 #define INCLUDED_EDITENG_SOURCE_EDITENG_IMPEDIT_HXX
21 
22 #include <eerdll2.hxx>
23 #include <editdoc.hxx>
24 #include "editsel.hxx"
25 #include "editundo.hxx"
26 #include "editobj2.hxx"
27 #include "editstt2.hxx"
28 #include <editeng/editdata.hxx>
29 #include <editeng/svxacorr.hxx>
30 #include <editeng/SpellPortions.hxx>
31 #include <editeng/eedata.hxx>
32 #include <editeng/editeng.hxx>
33 #include <editeng/editview.hxx>
34 #include <svtools/colorcfg.hxx>
35 #include <vcl/virdev.hxx>
36 #include <vcl/gdimtf.hxx>
37 #include <vcl/cursor.hxx>
38 #include <vcl/vclptr.hxx>
39 #include <tools/fract.hxx>
40 #include <vcl/idle.hxx>
41 #include <vcl/commandevent.hxx>
42 #include <vcl/ptrstyle.hxx>
43 
44 #include <vcl/dndhelp.hxx>
45 #include <svl/ondemand.hxx>
46 #include <svl/languageoptions.hxx>
47 #include <com/sun/star/linguistic2/XSpellAlternatives.hpp>
48 #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
49 #include <com/sun/star/linguistic2/XHyphenator.hpp>
50 #include <com/sun/star/lang/Locale.hpp>
51 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
52 #include <com/sun/star/i18n/XBreakIterator.hpp>
53 #include <com/sun/star/i18n/CharacterIteratorMode.hpp>
54 #include <com/sun/star/i18n/WordType.hpp>
55 #include <com/sun/star/i18n/XExtendedInputSequenceChecker.hpp>
56 #include <com/sun/star/uno/Sequence.hxx>
57 
58 #include <i18nlangtag/lang.h>
59 #include <rtl/ref.hxx>
60 #include <LibreOfficeKit/LibreOfficeKitTypes.h>
61 #include <o3tl/deleter.hxx>
62 #include <o3tl/typed_flags_set.hxx>
63 
64 #include <boost/optional.hpp>
65 #include <memory>
66 #include <vector>
67 
68 class EditView;
69 class EditEngine;
70 class OutlinerSearchable;
71 
72 class SvxSearchItem;
73 class SvxLRSpaceItem;
74 class TextRanger;
75 class SvKeyValueIterator;
76 class SvxForbiddenCharactersTable;
77 class SvtCTLOptions;
78 namespace vcl { class Window; }
79 class SvxNumberFormat;
80 
81 
82 namespace com {
83 namespace sun {
84 namespace star {
85 namespace datatransfer {
86 namespace clipboard {
87     class XClipboard;
88 }}}}}
89 
90 namespace editeng {
91     struct MisspellRanges;
92 }
93 
94 #define DEL_LEFT    1
95 #define DEL_RIGHT   2
96 #define TRAVEL_X_DONTKNOW           0xFFFFFFFF
97 #define CURSOR_BIDILEVEL_DONTKNOW   0xFFFF
98 #define MAXCHARSINPARA              0x3FFF-CHARPOSGROW  // Max 16K, because WYSIWYG array
99 #define LINE_SEP    '\x0A'
100 
101 #define ATTRSPECIAL_WHOLEWORD   1
102 #define ATTRSPECIAL_EDGE        2
103 
104 enum class GetCursorFlags {
105     NONE                = 0x0000,
106     TextOnly            = 0x0001,
107     StartOfLine         = 0x0002,
108     EndOfLine           = 0x0004,
109     PreferPortionStart  = 0x0008,
110 };
111 namespace o3tl {
112     template<> struct typed_flags<GetCursorFlags> : is_typed_flags<GetCursorFlags, 0x0f> {};
113 }
114 
115 
116 struct DragAndDropInfo
117 {
118     tools::Rectangle           aCurCursor;
119     tools::Rectangle           aCurSavedCursor;
120     sal_uInt16          nSensibleRange;
121     sal_uInt16          nCursorWidth;
122     ESelection          aBeginDragSel;
123     EditPaM             aDropDest;
124     sal_Int32           nOutlinerDropDest;
125     ESelection          aDropSel;
126     VclPtr<VirtualDevice> pBackground;
127     const SvxFieldItem* pField;
128     bool            bVisCursor              : 1;
129     bool            bDroppedInMe            : 1;
130     bool            bStarterOfDD            : 1;
131     bool            bHasValidData           : 1;
132     bool            bUndoAction             : 1;
133     bool            bOutlinerMode           : 1;
134     bool            bDragAccepted           : 1;
135 
DragAndDropInfoDragAndDropInfo136     DragAndDropInfo()
137     {
138             pBackground = nullptr; bVisCursor = false; bDroppedInMe = false; bStarterOfDD = false;
139             bHasValidData = false; bUndoAction = false; bOutlinerMode = false;
140             nSensibleRange = 0; nCursorWidth = 0; pField = nullptr; nOutlinerDropDest = 0; bDragAccepted = false;
141     }
~DragAndDropInfoDragAndDropInfo142     ~DragAndDropInfo()
143     {
144             pBackground.disposeAndClear();
145     }
146 };
147 
148 struct ImplIMEInfos
149 {
150     OUString    aOldTextAfterStartPos;
151     std::unique_ptr<ExtTextInputAttr[]> pAttribs;
152     EditPaM     aPos;
153     sal_Int32   nLen;
154     bool        bWasCursorOverwrite;
155 
156             ImplIMEInfos( const EditPaM& rPos, const OUString& rOldTextAfterStartPos );
157             ~ImplIMEInfos();
158 
159     void    CopyAttribs( const ExtTextInputAttr* pA, sal_uInt16 nL );
160     void    DestroyAttribs();
161 };
162 
163 // #i18881# to be able to identify the positions of changed words
164 // the positions of each portion need to be saved
165 typedef std::vector<EditSelection>  SpellContentSelections;
166 
167 struct SpellInfo
168 {
169     EESpellState    eState;
170     EPaM            aSpellStart;
171     EPaM            aSpellTo;
172     EditPaM         aCurSentenceStart;
173     bool        bSpellToEnd;
174     bool        bMultipleDoc;
175     svx::SpellPortions    aLastSpellPortions;
176     SpellContentSelections  aLastSpellContentSelections;
SpellInfoSpellInfo177     SpellInfo()
178         { bSpellToEnd = true; eState = EESpellState::Ok; bMultipleDoc = false; }
179 };
180 
181 // used for text conversion
182 struct ConvInfo
183 {
184     EPaM            aConvStart;
185     EPaM            aConvTo;
186     EPaM            aConvContinue;    // position to start search for next text portion (word) with
187     bool            bConvToEnd;
188     bool            bMultipleDoc;
189 
ConvInfoConvInfo190     ConvInfo() : bConvToEnd(true), bMultipleDoc(false) {}
191 };
192 
193 struct FormatterFontMetric
194 {
195     sal_uInt16 nMaxAscent;
196     sal_uInt16 nMaxDescent;
197 
FormatterFontMetricFormatterFontMetric198     FormatterFontMetric()               { nMaxAscent = 0; nMaxDescent = 0; /* nMinLeading = 0xFFFF; */ }
GetHeightFormatterFontMetric199     sal_uInt16  GetHeight() const       { return nMaxAscent+nMaxDescent; }
200 };
201 
202 class IdleFormattter : public Idle
203 {
204 private:
205     EditView*   pView;
206     int         nRestarts;
207 
208 public:
209                 IdleFormattter();
210                 virtual ~IdleFormattter() override;
211 
212     void        DoIdleFormat( EditView* pV );
213     void        ForceTimeout();
ResetRestarts()214     void        ResetRestarts() { nRestarts = 0; }
GetView()215     EditView*   GetView()       { return pView; }
216 };
217 
218 
219 //  class ImpEditView
220 
221 class ImpEditView : public vcl::unohelper::DragAndDropClient
222 {
223     friend class EditView;
224     friend class EditEngine;
225     friend class ImpEditEngine;
226     using vcl::unohelper::DragAndDropClient::dragEnter;
227     using vcl::unohelper::DragAndDropClient::dragExit;
228     using vcl::unohelper::DragAndDropClient::dragOver;
229 
230 private:
231     EditView*                 pEditView;
232     std::unique_ptr<vcl::Cursor, o3tl::default_delete<vcl::Cursor>>  pCursor;
233     std::unique_ptr<Color>    pBackgroundColor;
234     /// Containing view shell, if any.
235     OutlinerViewShell*        mpViewShell;
236     /// Another shell, just listening to our state, if any.
237     OutlinerViewShell*        mpOtherShell;
238     EditEngine*               pEditEngine;
239     VclPtr<vcl::Window>       pOutWin;
240     EditView::OutWindowSet    aOutWindowSet;
241     boost::optional<PointerStyle>  mxPointer;
242     std::unique_ptr<DragAndDropInfo>  pDragAndDropInfo;
243 
244     css::uno::Reference< css::datatransfer::dnd::XDragSourceListener > mxDnDListener;
245 
246 
247     long                nInvMore;
248     EVControlBits       nControl;
249     sal_uInt32          nTravelXPos;
250     GetCursorFlags      nExtraCursorFlags;
251     sal_uInt16          nCursorBidiLevel;
252     sal_uInt16          nScrollDiffX;
253     bool                bReadOnly;
254     bool                bClickedInSelection;
255     bool                bActiveDragAndDropListener;
256 
257     Point               aAnchorPoint;
258     tools::Rectangle           aOutArea;
259     Point               aVisDocStartPos;
260     EESelectionMode     eSelectionMode;
261     EditSelection       aEditSelection;
262     EEAnchorMode        eAnchorMode;
263 
264     /// mechanism to change from the classic refresh mode that simply
265     // invalidates the area where text was changed. When set, the invalidate
266     // and the direct repaint of the Window-plugged EditView will be suppressed.
267     // Instead, a consumer that has registered using an EditViewCallbacks
268     // incarnation has to handle that. Used e.g. to represent the edited text
269     // in Draw/Impress in an OverlayObject which avoids evtl. expensive full
270     // repaints of the EditView(s)
271     const EditViewCallbacks* mpEditViewCallbacks;
272 
getEditViewCallbacks() const273     const EditViewCallbacks* getEditViewCallbacks() const
274     {
275         return mpEditViewCallbacks;
276     }
277 
setEditViewCallbacks(const EditViewCallbacks * pEditViewCallbacks)278     void setEditViewCallbacks(const EditViewCallbacks* pEditViewCallbacks)
279     {
280         mpEditViewCallbacks = pEditViewCallbacks;
281     }
282 
283     void InvalidateAtWindow(const tools::Rectangle& rRect);
284 
285     css::uno::Reference<css::datatransfer::clipboard::XClipboard> GetClipboard() const;
286     css::uno::Reference<css::datatransfer::clipboard::XClipboard> GetSelection() const;
287 
288 protected:
289 
290     // DragAndDropClient
291     void dragGestureRecognized(const css::datatransfer::dnd::DragGestureEvent& dge) override;
292     void dragDropEnd( const css::datatransfer::dnd::DragSourceDropEvent& dsde ) override;
293     void drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde) override;
294     void dragEnter( const css::datatransfer::dnd::DropTargetDragEnterEvent& dtdee ) override;
295     void dragExit( const css::datatransfer::dnd::DropTargetEvent& dte ) override;
296     void dragOver(const css::datatransfer::dnd::DropTargetDragEvent& dtde) override;
297 
298     void ShowDDCursor( const tools::Rectangle& rRect );
299     void HideDDCursor();
300 
301     void ImplDrawHighlightRect( OutputDevice* _pTarget, const Point& rDocPosTopLeft, const Point& rDocPosBottomRight, tools::PolyPolygon* pPolyPoly );
302 
303 public:
304                     ImpEditView( EditView* pView, EditEngine* pEng, vcl::Window* pWindow );
305                     virtual ~ImpEditView() override;
306 
GetEditViewPtr()307     EditView*       GetEditViewPtr() { return pEditView; }
308 
GetScrollDiffX() const309     sal_uInt16      GetScrollDiffX() const          { return nScrollDiffX; }
SetScrollDiffX(sal_uInt16 n)310     void            SetScrollDiffX( sal_uInt16 n )  { nScrollDiffX = n; }
311 
GetCursorBidiLevel() const312     sal_uInt16      GetCursorBidiLevel() const      { return nCursorBidiLevel; }
SetCursorBidiLevel(sal_uInt16 n)313     void            SetCursorBidiLevel( sal_uInt16 n ) { nCursorBidiLevel = n; }
314 
315     Point           GetDocPos( const Point& rWindowPos ) const;
316     Point           GetWindowPos( const Point& rDocPos ) const;
317     tools::Rectangle       GetWindowPos( const tools::Rectangle& rDocPos ) const;
318 
319     void                SetOutputArea( const tools::Rectangle& rRect );
320     void                ResetOutputArea( const tools::Rectangle& rRect );
GetOutputArea() const321     const tools::Rectangle&    GetOutputArea() const   { return aOutArea; }
322 
323     bool            IsVertical() const;
324     bool            IsTopToBottom() const;
325 
326     bool            PostKeyEvent( const KeyEvent& rKeyEvent, vcl::Window const * pFrameWin );
327 
328     bool            MouseButtonUp( const MouseEvent& rMouseEvent );
329     bool            MouseButtonDown( const MouseEvent& rMouseEvent );
330     void            ReleaseMouse();
331     bool            MouseMove( const MouseEvent& rMouseEvent );
332     void            Command( const CommandEvent& rCEvt );
333 
334     void            CutCopy( css::uno::Reference< css::datatransfer::clipboard::XClipboard > const & rxClipboard, bool bCut );
335     void            Paste( css::uno::Reference< css::datatransfer::clipboard::XClipboard > const & rxClipboard, bool bUseSpecial = false );
336 
SetVisDocStartPos(const Point & rPos)337     void            SetVisDocStartPos( const Point& rPos ) { aVisDocStartPos = rPos; }
338 
GetVisDocLeft() const339     long            GetVisDocLeft() const { return aVisDocStartPos.X(); }
GetVisDocTop() const340     long            GetVisDocTop() const { return aVisDocStartPos.Y(); }
GetVisDocRight() const341     long            GetVisDocRight() const { return aVisDocStartPos.X() + ( !IsVertical() ? aOutArea.GetWidth() : aOutArea.GetHeight() ); }
GetVisDocBottom() const342     long            GetVisDocBottom() const { return aVisDocStartPos.Y() + ( !IsVertical() ? aOutArea.GetHeight() : aOutArea.GetWidth() ); }
343     tools::Rectangle       GetVisDocArea() const;
344 
GetEditSelection() const345     const EditSelection&  GetEditSelection() const { return aEditSelection; }
346     void            SetEditSelection( const EditSelection& rEditSelection );
HasSelection() const347     bool            HasSelection() const { return aEditSelection.HasRange(); }
348 
349     void SelectionChanged();
DrawSelectionXOR()350     void            DrawSelectionXOR() { DrawSelectionXOR( aEditSelection ); }
351     void            DrawSelectionXOR( EditSelection, vcl::Region* pRegion = nullptr, OutputDevice* pTargetDevice = nullptr );
352     void GetSelectionRectangles(EditSelection aTmpSel, std::vector<tools::Rectangle>& rLogicRects);
353 
GetWindow() const354     vcl::Window*    GetWindow() const           { return pOutWin; }
355 
356     void            SetSelectionMode( EESelectionMode eMode );
357 
358     inline PointerStyle GetPointer();
359 
360     inline vcl::Cursor*     GetCursor();
361 
362     void            AddDragAndDropListeners();
363     void            RemoveDragAndDropListeners();
364 
365     bool            IsBulletArea( const Point& rPos, sal_Int32* pPara );
366 
367 //  For the Selection Engine...
368     void            CreateAnchor();
369     void            DeselectAll();
370     bool            SetCursorAtPoint( const Point& rPointPixel );
371     bool            IsSelectionAtPoint( const Point& rPosPixel );
372     bool            IsInSelection( const EditPaM& rPaM );
373 
374 
375     void            SetAnchorMode( EEAnchorMode eMode );
GetAnchorMode() const376     EEAnchorMode    GetAnchorMode() const           { return eAnchorMode; }
377     void            CalcAnchorPoint();
378     void            RecalcOutputArea();
379 
380     void            ShowCursor( bool bGotoCursor, bool bForceVisCursor );
381     Pair            Scroll( long ndX, long ndY, ScrollRangeCheck nRangeCheck = ScrollRangeCheck::NoNegative );
382 
383     void        SetInsertMode( bool bInsert );
IsInsertMode() const384     bool        IsInsertMode() const            { return !( nControl & EVControlBits::OVERWRITE ); }
385 
IsPasteEnabled() const386     bool        IsPasteEnabled() const          { return bool( nControl & EVControlBits::ENABLEPASTE ); }
387 
DoSingleLinePaste() const388     bool        DoSingleLinePaste() const       { return bool( nControl & EVControlBits::SINGLELINEPASTE ); }
DoAutoScroll() const389     bool        DoAutoScroll() const            { return bool( nControl & EVControlBits::AUTOSCROLL ); }
DoAutoSize() const390     bool        DoAutoSize() const              { return bool( nControl & EVControlBits::AUTOSIZE ); }
DoAutoWidth() const391     bool        DoAutoWidth() const             { return bool( nControl & EVControlBits::AUTOSIZEX); }
DoAutoHeight() const392     bool        DoAutoHeight() const            { return bool( nControl & EVControlBits::AUTOSIZEY); }
DoInvalidateMore() const393     bool        DoInvalidateMore() const        { return bool( nControl & EVControlBits::INVONEMORE ); }
394 
395     void            SetBackgroundColor( const Color& rColor );
GetBackgroundColor() const396     const Color&    GetBackgroundColor() const {
397                         return ( pBackgroundColor ? *pBackgroundColor : pOutWin->GetBackground().GetColor() ); }
398 
399     /// Informs this edit view about which view shell contains it.
400     void RegisterViewShell(OutlinerViewShell* pViewShell);
401     const OutlinerViewShell* GetViewShell() const;
402     /// Informs this edit view about which other shell listens to it.
403     void RegisterOtherShell(OutlinerViewShell* pViewShell);
404 
405     bool            IsWrongSpelledWord( const EditPaM& rPaM, bool bMarkIfWrong );
406     OUString        SpellIgnoreWord();
407 
408     const SvxFieldItem* GetField( const Point& rPos, sal_Int32* pPara, sal_Int32* pPos ) const;
409     void            DeleteSelected();
410 
411     //  If possible invalidate more than OutputArea, for the DrawingEngine text frame
SetInvalidateMore(sal_uInt16 nPixel)412     void            SetInvalidateMore( sal_uInt16 nPixel ) { nInvMore = nPixel; }
GetInvalidateMore() const413     sal_uInt16      GetInvalidateMore() const { return static_cast<sal_uInt16>(nInvMore); }
414 };
415 
416 
417 //  ImpEditEngine
418 
419 
420 class ImpEditEngine : public SfxListener
421 {
422     friend class EditEngine;
423     friend class EditDbg;
424 
425     typedef EditEngine::ViewsType ViewsType;
426 
427 private:
428     std::shared_ptr<editeng::SharedVclResources> pSharedVCL;
429 
430 
431     // Data ...
432 
433 
434     // Document Specific data ...
435     ParaPortionList     aParaPortionList;       // Formatting
436     Size                aPaperSize;             // Layout
437     Size                aMinAutoPaperSize;      // Layout ?
438     Size                aMaxAutoPaperSize;      // Layout ?
439     EditDoc             aEditDoc;               // Document content
440 
441     // Engine Specific data ...
442     EditEngine*         pEditEngine;
443     ViewsType           aEditViews;
444     EditView*           pActiveView;
445     std::unique_ptr<TextRanger> pTextRanger;
446 
447     SfxStyleSheetPool*  pStylePool;
448     SfxItemPool*        pTextObjectPool;
449 
450     VclPtr< VirtualDevice> pVirtDev;
451     VclPtr< OutputDevice > pRefDev;
452     VclPtr<VirtualDevice> mpOwnDev;
453 
454     svtools::ColorConfig maColorConfig;
455     mutable std::unique_ptr<SvtCTLOptions> pCTLOptions;
456 
457     std::unique_ptr<SfxItemSet> pEmptyItemSet;
458     EditUndoManager*    pUndoManager;
459     std::unique_ptr<ESelection> pUndoMarkSelection;
460 
461     std::unique_ptr<ImplIMEInfos> mpIMEInfos;
462 
463     OUString            aWordDelimiters;
464 
465     EditSelFunctionSet  aSelFuncSet;
466     EditSelectionEngine aSelEngine;
467 
468     Color               maBackgroundColor;
469 
470     sal_uInt16          nStretchX;
471     sal_uInt16          nStretchY;
472 
473     CharCompressType    nAsianCompressionMode;
474 
475     EEHorizontalTextDirection eDefaultHorizontalTextDirection;
476 
477     sal_Int32          nBigTextObjectStart;
478     css::uno::Reference< css::linguistic2::XSpellChecker1 > xSpeller;
479     css::uno::Reference< css::linguistic2::XHyphenator >    xHyphenator;
480     std::unique_ptr<SpellInfo> pSpellInfo;
481     mutable css::uno::Reference < css::i18n::XBreakIterator > xBI;
482     mutable css::uno::Reference < css::i18n::XExtendedInputSequenceChecker > xISC;
483 
484     std::unique_ptr<ConvInfo> pConvInfo;
485 
486     OUString            aAutoCompleteText;
487 
488     InternalEditStatus  aStatus;
489 
490     LanguageType        eDefLanguage;
491 
492     OnDemandLocaleDataWrapper       xLocaleDataWrapper;
493     OnDemandTransliterationWrapper  xTransliterationWrapper;
494 
495     // For Formatting / Update...
496     std::vector<std::unique_ptr<DeletedNodeInfo> > aDeletedNodes;
497     tools::Rectangle           aInvalidRect;
498     sal_uInt32          nCurTextHeight;
499     sal_uInt32          nCurTextHeightNTP;  // without trailing empty paragraphs
500     sal_uInt16          nOnePixelInRef;
501 
502     IdleFormattter      aIdleFormatter;
503 
504     Timer               aOnlineSpellTimer;
505 
506     // For Chaining
507     sal_Int32 mnOverflowingPara = -1;
508     sal_Int32 mnOverflowingLine = -1;
509     bool mbNeedsChainingHandling = false;
510 
511     // If it is detected at one point that the StatusHdl has to be called, but
512     // this should not happen immediately (critical section):
513     Timer               aStatusTimer;
514     Link<EditStatus&,void>         aStatusHdlLink;
515     Link<EENotify&,void>           aNotifyHdl;
516     Link<HtmlImportInfo&,void>     aHtmlImportHdl;
517     Link<RtfImportInfo&,void>      aRtfImportHdl;
518     Link<MoveParagraphsInfo&,void> aBeginMovingParagraphsHdl;
519     Link<MoveParagraphsInfo&,void> aEndMovingParagraphsHdl;
520     Link<PasteOrDropInfos&,void>   aBeginPasteOrDropHdl;
521     Link<PasteOrDropInfos&,void>   aEndPasteOrDropHdl;
522     Link<LinkParamNone*,void>      aModifyHdl;
523     Link<EditView*,void>           maBeginDropHdl;
524     Link<EditView*,void>           maEndDropHdl;
525 
526     bool            bKernAsianPunctuation:1;
527     bool            bAddExtLeading:1;
528     bool            bIsFormatting:1;
529     bool            bFormatted:1;
530     bool            bInSelection:1;
531     bool            bIsInUndo:1;
532     bool            bUpdate:1;
533     bool            bUndoEnabled:1;
534     bool            bDowning:1;
535     bool            bUseAutoColor:1;
536     bool            bForceAutoColor:1;
537     bool            bCallParaInsertedOrDeleted:1;
538     bool            bFirstWordCapitalization:1;   // specifies if auto-correction should capitalize the first word or not
539     bool            mbLastTryMerge:1;
540     bool            mbReplaceLeadingSingleQuotationMark:1;
541 
542     bool            mbNbspRunNext;  // can't be a bitfield as it is passed as bool&
543 
544 
545     // Methods...
546 
547 
548     void                CursorMoved( const ContentNode* pPrevNode );
549     void                ParaAttribsChanged( ContentNode const * pNode, bool bIgnoreUndoCheck = false );
550     void                TextModified();
551     void                CalcHeight( ParaPortion* pPortion );
552 
553     void                InsertUndo( std::unique_ptr<EditUndo> pUndo, bool bTryMerge = false );
554     void                ResetUndoManager();
HasUndoManager() const555     bool            HasUndoManager() const  { return pUndoManager != nullptr; }
556 
557     std::unique_ptr<EditUndoSetAttribs> CreateAttribUndo( EditSelection aSel, const SfxItemSet& rSet );
558 
559     std::unique_ptr<EditTextObject> GetEmptyTextObject();
560 
561     EditPaM             GetPaM( Point aDocPos, bool bSmart = true );
562     EditPaM             GetPaM( ParaPortion* pPortion, Point aPos, bool bSmart );
563     long GetXPos(const ParaPortion* pParaPortion, const EditLine* pLine, sal_Int32 nIndex, bool bPreferPortionStart = false) const;
564     long GetPortionXOffset(const ParaPortion* pParaPortion, const EditLine* pLine, sal_Int32 nTextPortion) const;
565     sal_Int32 GetChar(const ParaPortion* pParaPortion, const EditLine* pLine, long nX, bool bSmart = true);
566     Range               GetInvalidYOffsets( ParaPortion* pPortion );
567     Range GetLineXPosStartEnd( const ParaPortion* pParaPortion, const EditLine* pLine ) const;
568 
569     void                ParaAttribsToCharAttribs( ContentNode* pNode );
570     void                GetCharAttribs( sal_Int32 nPara, std::vector<EECharAttrib>& rLst ) const;
571 
572     std::unique_ptr<EditTextObject>
573                         CreateTextObject(EditSelection aSelection, SfxItemPool*, bool bAllowBigObjects = false, sal_Int32 nBigObjStart = 0);
574     EditSelection       InsertTextObject( const EditTextObject&, EditPaM aPaM );
575     EditSelection       PasteText( css::uno::Reference< css::datatransfer::XTransferable > const & rxDataObj, const OUString& rBaseURL, const EditPaM& rPaM, bool bUseSpecial );
576 
577     void                CheckPageOverflow();
578 
579     void                Clear();
580     EditPaM             RemoveText();
581     bool                CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY );
582     void                CreateAndInsertEmptyLine( ParaPortion* pParaPortion );
583     bool                FinishCreateLines( ParaPortion* pParaPortion );
584     void                CreateTextPortions( ParaPortion* pParaPortion, sal_Int32& rStartPos /*, sal_Bool bCreateBlockPortions */ );
585     void                RecalcTextPortion( ParaPortion* pParaPortion, sal_Int32 nStartPos, sal_Int32 nNewChars );
586     sal_Int32           SplitTextPortion( ParaPortion* pParaPortion, sal_Int32 nPos,  EditLine* pCurLine = nullptr );
587     void                SeekCursor( ContentNode* pNode, sal_Int32 nPos, SvxFont& rFont, OutputDevice* pOut = nullptr );
588     void                RecalcFormatterFontMetrics( FormatterFontMetric& rCurMetrics, SvxFont& rFont );
589     void                CheckAutoPageSize();
590 
591     void                ImpBreakLine( ParaPortion* pParaPortion, EditLine* pLine, TextPortion const * pPortion, sal_Int32 nPortionStart, long nRemainingWidth, bool bCanHyphenate );
592     void                ImpAdjustBlocks( ParaPortion* pParaPortion, EditLine* pLine, long nRemainingSpace );
593     EditPaM             ImpConnectParagraphs( ContentNode* pLeft, ContentNode* pRight, bool bBackward = false );
594     EditPaM             ImpDeleteSelection(const EditSelection& rCurSel);
595     EditPaM             ImpInsertParaBreak( EditPaM& rPaM, bool bKeepEndingAttribs = true );
596     EditPaM             ImpInsertParaBreak( const EditSelection& rEditSelection );
597     EditPaM             ImpInsertText(const EditSelection& aCurEditSelection, const OUString& rStr);
598     EditPaM             ImpInsertFeature(const EditSelection& rCurSel, const SfxPoolItem& rItem);
599     void                ImpRemoveChars( const EditPaM& rPaM, sal_Int32 nChars );
600     void                ImpRemoveParagraph( sal_Int32 nPara );
601     EditSelection       ImpMoveParagraphs( Range aParagraphs, sal_Int32 nNewPos );
602 
603     EditPaM             ImpFastInsertText( EditPaM aPaM, const OUString& rStr );
604     EditPaM             ImpFastInsertParagraph( sal_Int32 nPara );
605 
606     bool                ImpCheckRefMapMode();
607 
608     bool                ImplHasText() const;
609 
610     void                ImpFindKashidas( ContentNode* pNode, sal_Int32 nStart, sal_Int32 nEnd, std::vector<sal_Int32>& rArray );
611 
612     void                InsertContent( ContentNode* pNode, sal_Int32 nPos );
613     EditPaM             SplitContent( sal_Int32 nNode, sal_Int32 nSepPos );
614     EditPaM             ConnectContents( sal_Int32 nLeftNode, bool bBackward );
615 
616     void                ShowParagraph( sal_Int32 nParagraph, bool bShow );
617 
618     EditPaM             PageUp( const EditPaM& rPaM, EditView const * pView);
619     EditPaM             PageDown( const EditPaM& rPaM, EditView const * pView);
620     EditPaM             CursorUp( const EditPaM& rPaM, EditView const * pEditView );
621     EditPaM             CursorDown( const EditPaM& rPaM, EditView const * pEditView );
622     EditPaM             CursorLeft( const EditPaM& rPaM, sal_uInt16 nCharacterIteratorMode = css::i18n::CharacterIteratorMode::SKIPCELL );
623     EditPaM             CursorRight( const EditPaM& rPaM, sal_uInt16 nCharacterIteratorMode = css::i18n::CharacterIteratorMode::SKIPCELL );
624     EditPaM             CursorStartOfLine( const EditPaM& rPaM );
625     EditPaM             CursorEndOfLine( const EditPaM& rPaM );
626     static EditPaM      CursorStartOfParagraph( const EditPaM& rPaM );
627     static EditPaM      CursorEndOfParagraph( const EditPaM& rPaM );
628     EditPaM             CursorStartOfDoc();
629     EditPaM             CursorEndOfDoc();
630     EditPaM             WordLeft( const EditPaM& rPaM );
631     EditPaM             WordRight( const EditPaM& rPaM, sal_Int16 nWordType = css::i18n::WordType::ANYWORD_IGNOREWHITESPACES );
632     EditPaM             StartOfWord( const EditPaM& rPaM );
633     EditPaM             EndOfWord( const EditPaM& rPaM );
634     EditSelection       SelectWord( const EditSelection& rCurSelection, sal_Int16 nWordType = css::i18n::WordType::ANYWORD_IGNOREWHITESPACES, bool bAcceptStartOfWord = true );
635     EditSelection       SelectSentence( const EditSelection& rCurSel ) const;
636     EditPaM             CursorVisualLeftRight( EditView const * pEditView, const EditPaM& rPaM, sal_uInt16 nCharacterIteratorMode, bool bToLeft );
637     EditPaM             CursorVisualStartEnd( EditView const * pEditView, const EditPaM& rPaM, bool bStart );
638 
639 
640     void                InitScriptTypes( sal_Int32 nPara );
641     sal_uInt16          GetI18NScriptType( const EditPaM& rPaM, sal_Int32* pEndPos = nullptr ) const;
642     SvtScriptType       GetItemScriptType( const EditSelection& rSel ) const;
643     bool                IsScriptChange( const EditPaM& rPaM ) const;
644     bool                HasScriptType( sal_Int32 nPara, sal_uInt16 nType ) const;
645 
646     bool                ImplCalcAsianCompression( ContentNode* pNode, TextPortion* pTextPortion, sal_Int32 nStartPos,
647                                                   long* pDXArray, sal_uInt16 n100thPercentFromMax, bool bManipulateDXArray );
648     void                ImplExpandCompressedPortions( EditLine* pLine, ParaPortion* pParaPortion, long nRemainingWidth );
649 
650     void                ImplInitLayoutMode( OutputDevice* pOutDev, sal_Int32 nPara, sal_Int32 nIndex );
651     LanguageType        ImplCalcDigitLang(LanguageType eCurLang) const;
652     void                ImplInitDigitMode(OutputDevice* pOutDev, LanguageType eLang);
653     static OUString     convertDigits(const OUString &rString, sal_Int32 nStt, sal_Int32 nLen, LanguageType eDigitLang);
654 
655     EditPaM             ReadText( SvStream& rInput, EditSelection aSel );
656     EditPaM             ReadRTF( SvStream& rInput, EditSelection aSel );
657     EditPaM             ReadXML( SvStream& rInput, EditSelection aSel );
658     EditPaM             ReadHTML( SvStream& rInput, const OUString& rBaseURL, EditSelection aSel, SvKeyValueIterator* pHTTPHeaderAttrs );
659     ErrCode             WriteText( SvStream& rOutput, EditSelection aSel );
660     ErrCode             WriteRTF( SvStream& rOutput, EditSelection aSel );
661     void                WriteXML(SvStream& rOutput, const EditSelection& rSel);
662 
663     void                WriteItemAsRTF( const SfxPoolItem& rItem, SvStream& rOutput, sal_Int32 nPara, sal_Int32 nPos,
664                             std::vector<std::unique_ptr<SvxFontItem>>& rFontTable, SvxColorList& rColorList );
665     bool                WriteItemListAsRTF( ItemList& rLst, SvStream& rOutput, sal_Int32 nPara, sal_Int32 nPos,
666                             std::vector<std::unique_ptr<SvxFontItem>>& rFontTable, SvxColorList& rColorList );
667     sal_Int32           LogicToTwips( sal_Int32 n );
668 
669     inline short        GetXValue( short nXValue ) const;
670     inline long         GetXValue( long nXValue ) const;
671 
672     inline short        GetYValue( short nYValue ) const;
673     inline sal_uInt16   GetYValue( sal_uInt16 nYValue ) const;
674 
675     ContentNode*        GetPrevVisNode( ContentNode const * pCurNode );
676     ContentNode*        GetNextVisNode( ContentNode const * pCurNode );
677 
678     const ParaPortion*  GetPrevVisPortion( const ParaPortion* pCurPortion ) const;
679     const ParaPortion*  GetNextVisPortion( const ParaPortion* pCurPortion ) const;
680 
SetBackgroundColor(const Color & rColor)681     void                SetBackgroundColor( const Color& rColor ) { maBackgroundColor = rColor; }
GetBackgroundColor() const682     const Color&        GetBackgroundColor() const { return maBackgroundColor; }
683 
684     long                CalcVertLineSpacing(Point& rStartPos) const;
685 
686     Color               GetAutoColor() const;
EnableAutoColor(bool b)687     void                EnableAutoColor( bool b ) { bUseAutoColor = b; }
IsAutoColorEnabled() const688     bool                IsAutoColorEnabled() const { return bUseAutoColor; }
ForceAutoColor(bool b)689     void                ForceAutoColor( bool b ) { bForceAutoColor = b; }
IsForceAutoColor() const690     bool                IsForceAutoColor() const { return bForceAutoColor; }
691 
692     inline VirtualDevice*   GetVirtualDevice( const MapMode& rMapMode, DrawModeFlags nDrawMode );
EraseVirtualDevice()693     void             EraseVirtualDevice() { pVirtDev.disposeAndClear(); }
694 
695     DECL_LINK( StatusTimerHdl, Timer *, void);
696     DECL_LINK( IdleFormatHdl, Timer *, void);
697     DECL_LINK( OnlineSpellHdl, Timer *, void);
698     DECL_LINK( DocModified, LinkParamNone*, void );
699 
700     void                CheckIdleFormatter();
701 
702     inline const ParaPortion* FindParaPortion( const ContentNode* pNode ) const;
703     inline ParaPortion* FindParaPortion( ContentNode const * pNode );
704 
705     css::uno::Reference< css::datatransfer::XTransferable > CreateTransferable( const EditSelection& rSelection );
706 
707     void                SetValidPaperSize( const Size& rSz );
708 
709     css::uno::Reference < css::i18n::XBreakIterator > const & ImplGetBreakIterator() const;
710     css::uno::Reference < css::i18n::XExtendedInputSequenceChecker > const & ImplGetInputSequenceChecker() const;
711 
712     void ImplUpdateOverflowingParaNum( sal_uInt32 );
713     void ImplUpdateOverflowingLineNum( sal_uInt32, sal_uInt32, sal_uInt32 );
714 
715     void CreateSpellInfo( bool bMultipleDocs );
716     /// Obtains a view shell ID from the active EditView.
717     ViewShellId CreateViewShellId();
718 
719     ImpEditEngine(EditEngine* pEditEngine, SfxItemPool* pPool);
720     void InitDoc(bool bKeepParaAttribs);
GetEditDoc()721     EditDoc&                GetEditDoc()            { return aEditDoc; }
GetEditDoc() const722     const EditDoc&          GetEditDoc() const      { return aEditDoc; }
723 
GetParaPortions() const724     const ParaPortionList&  GetParaPortions() const { return aParaPortionList; }
GetParaPortions()725     ParaPortionList&        GetParaPortions()       { return aParaPortionList; }
726 
727 protected:
728     virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
729 
730 public:
731                             virtual ~ImpEditEngine() override;
732                             ImpEditEngine(const ImpEditEngine&) = delete;
733     ImpEditEngine&          operator=(const ImpEditEngine&) = delete;
734 
735     inline EditUndoManager& GetUndoManager();
736     inline SfxUndoManager* SetUndoManager(SfxUndoManager* pNew);
737 
738     void                    SetUpdateMode( bool bUp, EditView* pCurView = nullptr, bool bForceUpdate = false );
GetUpdateMode() const739     bool                    GetUpdateMode() const   { return bUpdate; }
740 
GetEditViews()741     ViewsType& GetEditViews() { return aEditViews; }
GetEditViews() const742     const ViewsType& GetEditViews() const { return aEditViews; }
743 
GetPaperSize() const744     const Size&             GetPaperSize() const                    { return aPaperSize; }
SetPaperSize(const Size & rSz)745     void                    SetPaperSize( const Size& rSz )         { aPaperSize = rSz; }
746 
747     void                    SetVertical( bool bVertical, bool bTopToBottom);
IsVertical() const748     bool                    IsVertical() const                      { return GetEditDoc().IsVertical(); }
IsTopToBottom() const749     bool                    IsTopToBottom() const                   { return GetEditDoc().IsTopToBottom(); }
750 
751     bool IsPageOverflow( ) const;
752 
753     void                    SetFixedCellHeight( bool bUseFixedCellHeight );
IsFixedCellHeight() const754     bool                    IsFixedCellHeight() const { return GetEditDoc().IsFixedCellHeight(); }
755 
SetDefaultHorizontalTextDirection(EEHorizontalTextDirection eHTextDir)756     void                        SetDefaultHorizontalTextDirection( EEHorizontalTextDirection eHTextDir ) { eDefaultHorizontalTextDirection = eHTextDir; }
GetDefaultHorizontalTextDirection() const757     EEHorizontalTextDirection   GetDefaultHorizontalTextDirection() const { return eDefaultHorizontalTextDirection; }
758 
759 
760     void                    InitWritingDirections( sal_Int32 nPara );
761     bool                    IsRightToLeft( sal_Int32 nPara ) const;
762     sal_uInt8               GetRightToLeft( sal_Int32 nPara, sal_Int32 nChar, sal_Int32* pStart = nullptr, sal_Int32* pEnd = nullptr );
763     bool                    HasDifferentRTLLevels( const ContentNode* pNode );
764 
765     void                    SetTextRanger( std::unique_ptr<TextRanger> pRanger );
GetTextRanger() const766     TextRanger*             GetTextRanger() const { return pTextRanger.get(); }
767 
GetMinAutoPaperSize() const768     const Size&             GetMinAutoPaperSize() const             { return aMinAutoPaperSize; }
SetMinAutoPaperSize(const Size & rSz)769     void                    SetMinAutoPaperSize( const Size& rSz )  { aMinAutoPaperSize = rSz; }
770 
GetMaxAutoPaperSize() const771     const Size&             GetMaxAutoPaperSize() const             { return aMaxAutoPaperSize; }
SetMaxAutoPaperSize(const Size & rSz)772     void                    SetMaxAutoPaperSize( const Size& rSz )  { aMaxAutoPaperSize = rSz; }
773 
774     void                    FormatDoc();
775     void                    FormatFullDoc();
776     void                    UpdateViews( EditView* pCurView = nullptr );
777     void                    Paint( ImpEditView* pView, const tools::Rectangle& rRect, OutputDevice* pTargetDevice );
778     void                    Paint( OutputDevice* pOutDev, tools::Rectangle aClipRect, Point aStartPos, bool bStripOnly = false, short nOrientation = 0 );
779 
780     bool                MouseButtonUp( const MouseEvent& rMouseEvent, EditView* pView );
781     bool                MouseButtonDown( const MouseEvent& rMouseEvent, EditView* pView );
782     void                ReleaseMouse();
783     bool                MouseMove( const MouseEvent& rMouseEvent, EditView* pView );
784     void                    Command( const CommandEvent& rCEvt, EditView* pView );
785 
GetSelEngine()786     EditSelectionEngine&    GetSelEngine() { return aSelEngine; }
787     OUString                GetSelected( const EditSelection& rSel ) const;
788 
789     const SfxItemSet&       GetEmptyItemSet();
790 
791     void                    UpdateSelections();
792 
793     void                EnableUndo( bool bEnable );
IsUndoEnabled() const794     bool                IsUndoEnabled() const   { return bUndoEnabled; }
SetUndoMode(bool b)795     void                SetUndoMode( bool b )   { bIsInUndo = b; }
IsInUndo() const796     bool                IsInUndo() const        { return bIsInUndo; }
797 
SetCallParaInsertedOrDeleted(bool b)798     void                SetCallParaInsertedOrDeleted( bool b ) { bCallParaInsertedOrDeleted = b; }
IsCallParaInsertedOrDeleted() const799     bool                IsCallParaInsertedOrDeleted() const { return bCallParaInsertedOrDeleted; }
800 
IsFormatted() const801     bool                IsFormatted() const { return bFormatted; }
IsFormatting() const802     bool                IsFormatting() const { return bIsFormatting; }
803 
804     void            SetText(const OUString& rText);
805     EditPaM         DeleteSelected(const EditSelection& rEditSelection);
806     EditPaM         InsertTextUserInput( const EditSelection& rCurEditSelection, sal_Unicode c, bool bOverwrite );
807     EditPaM         InsertText(const EditSelection& aCurEditSelection, const OUString& rStr);
808     EditPaM         AutoCorrect( const EditSelection& rCurEditSelection, sal_Unicode c, bool bOverwrite, vcl::Window const * pFrameWin = nullptr );
809     EditPaM         DeleteLeftOrRight( const EditSelection& rEditSelection, sal_uInt8 nMode, DeleteMode nDelMode );
810     EditPaM         InsertParaBreak(const EditSelection& rEditSelection);
811     EditPaM         InsertLineBreak(const EditSelection& aEditSelection);
812     EditPaM         InsertTab(const EditSelection& rEditSelection);
813     EditPaM         InsertField(const EditSelection& rCurSel, const SvxFieldItem& rFld);
814     bool            UpdateFields();
815 
816     EditPaM         Read(SvStream& rInput, const OUString& rBaseURL, EETextFormat eFormat, const EditSelection& rSel, SvKeyValueIterator* pHTTPHeaderAttrs = nullptr);
817     void            Write(SvStream& rOutput, EETextFormat eFormat, const EditSelection& rSel);
818 
819     std::unique_ptr<EditTextObject> CreateTextObject();
820     std::unique_ptr<EditTextObject> CreateTextObject(const EditSelection& rSel);
821     void            SetText( const EditTextObject& rTextObject );
822     EditSelection   InsertText( const EditTextObject& rTextObject, EditSelection aSel );
823 
824     EditSelection const & MoveCursor( const KeyEvent& rKeyEvent, EditView* pEditView );
825 
826     EditSelection   MoveParagraphs( Range aParagraphs, sal_Int32 nNewPos, EditView* pCurView );
827 
828     sal_uInt32      CalcTextHeight( sal_uInt32* pHeightNTP );
829     sal_uInt32      GetTextHeight() const;
830     sal_uInt32      GetTextHeightNTP() const;
831     sal_uInt32      CalcTextWidth( bool bIgnoreExtraSpace);
832     sal_uInt32      CalcParaWidth( sal_Int32 nParagraph, bool bIgnoreExtraSpace );
833     sal_uInt32      CalcLineWidth( ParaPortion* pPortion, EditLine* pLine, bool bIgnoreExtraSpace);
834     sal_Int32       GetLineCount( sal_Int32 nParagraph ) const;
835     sal_Int32       GetLineLen( sal_Int32 nParagraph, sal_Int32 nLine ) const;
836     void            GetLineBoundaries( /*out*/sal_Int32& rStart, /*out*/sal_Int32& rEnd, sal_Int32 nParagraph, sal_Int32 nLine ) const;
837     sal_Int32       GetLineNumberAtIndex( sal_Int32 nPara, sal_Int32 nIndex ) const;
838     sal_uInt16      GetLineHeight( sal_Int32 nParagraph, sal_Int32 nLine );
839     sal_uInt32      GetParaHeight( sal_Int32 nParagraph );
840 
841     SfxItemSet      GetAttribs( sal_Int32 nPara, sal_Int32 nStart, sal_Int32 nEnd, GetAttribsFlags nFlags = GetAttribsFlags::ALL ) const;
842     SfxItemSet      GetAttribs( EditSelection aSel, EditEngineAttribs nOnlyHardAttrib = EditEngineAttribs::All  );
843     void            SetAttribs( EditSelection aSel, const SfxItemSet& rSet, SetAttribsMode nSpecial = SetAttribsMode::NONE );
844     void            RemoveCharAttribs( EditSelection aSel, bool bRemoveParaAttribs, sal_uInt16 nWhich );
845     void            RemoveCharAttribs( sal_Int32 nPara, sal_uInt16 nWhich = 0, bool bRemoveFeatures = false );
846     void            SetFlatMode( bool bFlat );
847 
848     void                SetParaAttribs( sal_Int32 nPara, const SfxItemSet& rSet );
849     const SfxItemSet&   GetParaAttribs( sal_Int32 nPara ) const;
850 
851     bool            HasParaAttrib( sal_Int32 nPara, sal_uInt16 nWhich ) const;
852     const SfxPoolItem&  GetParaAttrib( sal_Int32 nPara, sal_uInt16 nWhich ) const;
853     template<class T>
GetParaAttrib(sal_Int32 nPara,TypedWhichId<T> nWhich) const854     const T&            GetParaAttrib( sal_Int32 nPara, TypedWhichId<T> nWhich ) const
855     {
856         return static_cast<const T&>(GetParaAttrib(nPara, sal_uInt16(nWhich)));
857     }
858 
859     tools::Rectangle       PaMtoEditCursor( EditPaM aPaM, GetCursorFlags nFlags = GetCursorFlags::NONE );
860     tools::Rectangle       GetEditCursor( ParaPortion* pPortion, sal_Int32 nIndex, GetCursorFlags nFlags = GetCursorFlags::NONE );
861 
IsModified() const862     bool            IsModified() const      { return aEditDoc.IsModified(); }
SetModifyFlag(bool b)863     void            SetModifyFlag( bool b ) { aEditDoc.SetModified( b ); }
SetModifyHdl(const Link<LinkParamNone *,void> & rLink)864     void            SetModifyHdl( const Link<LinkParamNone*,void>& rLink ) { aModifyHdl = rLink; }
GetModifyHdl() const865     const Link<LinkParamNone*,void>& GetModifyHdl() const { return aModifyHdl; }
866 
IsInSelectionMode() const867     bool            IsInSelectionMode() const { return bInSelection; }
868 
869 //  For Undo/Redo
870     void            Undo( EditView* pView );
871     void            Redo( EditView* pView );
872 
873 //  OV-Special
874     void            InvalidateFromParagraph( sal_Int32 nFirstInvPara );
875     EditPaM         InsertParagraph( sal_Int32 nPara );
876     std::unique_ptr<EditSelection> SelectParagraph( sal_Int32 nPara );
877 
SetStatusEventHdl(const Link<EditStatus &,void> & rLink)878     void            SetStatusEventHdl( const Link<EditStatus&, void>& rLink ) { aStatusHdlLink = rLink; }
GetStatusEventHdl() const879     const Link<EditStatus&,void>& GetStatusEventHdl() const               { return aStatusHdlLink; }
880 
SetNotifyHdl(const Link<EENotify &,void> & rLink)881     void            SetNotifyHdl( const Link<EENotify&,void>& rLink )     { aNotifyHdl = rLink; }
GetNotifyHdl() const882     const Link<EENotify&,void>&   GetNotifyHdl() const            { return aNotifyHdl; }
883 
884     void            FormatAndUpdate( EditView* pCurView = nullptr, bool bCalledFromUndo = false );
885     inline void     IdleFormatAndUpdate( EditView* pCurView );
886 
GetColorConfig() const887     const svtools::ColorConfig& GetColorConfig() const { return maColorConfig; }
888     bool            IsVisualCursorTravelingEnabled();
889     bool            DoVisualCursorTraveling();
890 
891     EditSelection         ConvertSelection( sal_Int32 nStartPara, sal_Int32 nStartPos, sal_Int32 nEndPara, sal_Int32 nEndPos );
892     inline EPaM           CreateEPaM( const EditPaM& rPaM );
893     inline EditPaM        CreateEditPaM( const EPaM& rEPaM );
894     inline ESelection     CreateESel( const EditSelection& rSel );
895     inline EditSelection  CreateSel( const ESelection& rSel );
896 
897     void                SetStyleSheetPool( SfxStyleSheetPool* pSPool );
GetStyleSheetPool() const898     SfxStyleSheetPool*  GetStyleSheetPool() const { return pStylePool; }
899 
900     void                SetStyleSheet( EditSelection aSel, SfxStyleSheet* pStyle );
901     void                SetStyleSheet( sal_Int32 nPara, SfxStyleSheet* pStyle );
902     const SfxStyleSheet* GetStyleSheet( sal_Int32 nPara ) const;
903     SfxStyleSheet*      GetStyleSheet( sal_Int32 nPara );
904 
905     void                UpdateParagraphsWithStyleSheet( SfxStyleSheet* pStyle );
906     void                RemoveStyleFromParagraphs( SfxStyleSheet const * pStyle );
907 
GetRefDevice() const908     OutputDevice*       GetRefDevice() const { return pRefDev.get(); }
909     void                SetRefDevice( OutputDevice* pRefDef );
910 
GetRefMapMode() const911     const MapMode&      GetRefMapMode() const { return pRefDev->GetMapMode(); }
912     void                SetRefMapMode( const MapMode& rMapMode );
913 
GetStatus()914     InternalEditStatus& GetStatus() { return aStatus; }
915     void                CallStatusHdl();
DelayedCallStatusHdl()916     void                DelayedCallStatusHdl()  { aStatusTimer.Start(); }
917 
918     void                UndoActionStart( sal_uInt16 nId );
919     void                UndoActionStart( sal_uInt16 nId, const ESelection& rSel );
920     void                UndoActionEnd();
921 
GetActiveView() const922     EditView*           GetActiveView() const   { return pActiveView; }
923     void                SetActiveView( EditView* pView );
924 
925     css::uno::Reference< css::linguistic2::XSpellChecker1 > const &
926                         GetSpeller();
SetSpeller(css::uno::Reference<css::linguistic2::XSpellChecker1> const & xSpl)927     void                SetSpeller( css::uno::Reference< css::linguistic2::XSpellChecker1 > const &xSpl )
928                             { xSpeller = xSpl; }
929     const css::uno::Reference< css::linguistic2::XHyphenator >&
GetHyphenator() const930                         GetHyphenator() const { return xHyphenator; }
SetHyphenator(css::uno::Reference<css::linguistic2::XHyphenator> const & xHyph)931     void                SetHyphenator( css::uno::Reference< css::linguistic2::XHyphenator > const &xHyph )
932                             { xHyphenator = xHyph; }
933 
934     void GetAllMisspellRanges( std::vector<editeng::MisspellRanges>& rRanges ) const;
935     void SetAllMisspellRanges( const std::vector<editeng::MisspellRanges>& rRanges );
936 
GetSpellInfo() const937     SpellInfo*          GetSpellInfo() const { return pSpellInfo.get(); }
938 
SetDefaultLanguage(LanguageType eLang)939     void                SetDefaultLanguage( LanguageType eLang ) { eDefLanguage = eLang; }
GetDefaultLanguage() const940     LanguageType        GetDefaultLanguage() const { return eDefLanguage; }
941 
942     LanguageType        GetLanguage( const EditPaM& rPaM, sal_Int32* pEndPos = nullptr ) const;
943     css::lang::Locale   GetLocale( const EditPaM& rPaM ) const;
944 
945     void DoOnlineSpelling( ContentNode* pThisNodeOnly = nullptr, bool bSpellAtCursorPos = false, bool bInterruptible = true );
946     EESpellState        Spell( EditView* pEditView, bool bMultipleDoc );
947     EESpellState        HasSpellErrors();
948     void                ClearSpellErrors();
949     EESpellState        StartThesaurus( EditView* pEditView );
950     css::uno::Reference< css::linguistic2::XSpellAlternatives >
951                         ImpSpell( EditView* pEditView );
952 
953     // text conversion functions
954     void                Convert( EditView* pEditView, LanguageType nSrcLang, LanguageType nDestLang, const vcl::Font *pDestFont, sal_Int32 nOptions, bool bIsInteractive, bool bMultipleDoc );
955     void                ImpConvert( OUString &rConvTxt, LanguageType &rConvTxtLang, EditView* pEditView, LanguageType nSrcLang, const ESelection &rConvRange,
956                                     bool bAllowImplicitChangesForNotConvertibleText, LanguageType nTargetLang, const vcl::Font *pTargetFont );
GetConvInfo() const957     ConvInfo *          GetConvInfo() const { return pConvInfo.get(); }
958     bool                HasConvertibleTextPortion( LanguageType nLang );
959     void                SetLanguageAndFont( const ESelection &rESel,
960                                 LanguageType nLang, sal_uInt16 nLangWhichId,
961                                 const vcl::Font *pFont,  sal_uInt16 nFontWhichId );
962 
963     // returns true if input sequence checking should be applied
964     bool                IsInputSequenceCheckingRequired( sal_Unicode nChar, const EditSelection& rCurSel ) const;
965 
966     //find the next error within the given selection - forward only!
967     css::uno::Reference< css::linguistic2::XSpellAlternatives >
968                         ImpFindNextError(EditSelection& rSelection);
969     //spell and return a sentence
970     bool                SpellSentence(EditView const & rView, svx::SpellPortions& rToFill );
971     //put spelling back to start of current sentence - needed after switch of grammar support
972     void                PutSpellingToSentenceStart( EditView const & rEditView );
973     //applies a changed sentence
974     void                ApplyChangedSentence(EditView const & rEditView, const svx::SpellPortions& rNewPortions, bool bRecheck );
975     //adds one or more portions of text to the SpellPortions depending on language changes
976     void                AddPortionIterated(
977                           EditView const & rEditView,
978                           const EditSelection &rSel,
979                           const css::uno::Reference< css::linguistic2::XSpellAlternatives >& xAlt,
980                           svx::SpellPortions& rToFill);
981     //adds one portion to the SpellPortions
982     void                AddPortion(
983                             const EditSelection &rSel,
984                             const css::uno::Reference< css::linguistic2::XSpellAlternatives >& xAlt,
985                             svx::SpellPortions& rToFill,
986                             bool bIsField );
987 
988     bool                    Search( const SvxSearchItem& rSearchItem, EditView* pView );
989     bool                    ImpSearch( const SvxSearchItem& rSearchItem, const EditSelection& rSearchSelection, const EditPaM& rStartPos, EditSelection& rFoundSel );
990     sal_Int32               StartSearchAndReplace( EditView* pEditView, const SvxSearchItem& rSearchItem );
991     bool                    HasText( const SvxSearchItem& rSearchItem );
992 
SetEditTextObjectPool(SfxItemPool * pP)993     void                    SetEditTextObjectPool( SfxItemPool* pP )    { pTextObjectPool = pP; }
GetEditTextObjectPool() const994     SfxItemPool*            GetEditTextObjectPool() const               { return pTextObjectPool; }
995 
996     const SvxNumberFormat * GetNumberFormat( const ContentNode* pNode ) const;
997     sal_Int32               GetSpaceBeforeAndMinLabelWidth( const ContentNode *pNode, sal_Int32 *pnSpaceBefore = nullptr, sal_Int32 *pnMinLabelWidth = nullptr ) const;
998 
999     const SvxLRSpaceItem&   GetLRSpaceItem( ContentNode* pNode );
1000     SvxAdjust               GetJustification( sal_Int32 nPara ) const;
1001     SvxCellJustifyMethod    GetJustifyMethod( sal_Int32 nPara ) const;
1002     SvxCellVerJustify       GetVerJustification( sal_Int32 nPara ) const;
1003 
1004     void                SetCharStretching( sal_uInt16 nX, sal_uInt16 nY );
1005     inline void         GetCharStretching( sal_uInt16& rX, sal_uInt16& rY ) const;
1006 
GetBigTextObjectStart() const1007     sal_Int32           GetBigTextObjectStart() const                               { return nBigTextObjectStart; }
1008 
GetEditEnginePtr() const1009     EditEngine*  GetEditEnginePtr() const    { return pEditEngine; }
1010 
StartOnlineSpellTimer()1011     void                StartOnlineSpellTimer()     { aOnlineSpellTimer.Start(); }
StopOnlineSpellTimer()1012     void                StopOnlineSpellTimer()      { aOnlineSpellTimer.Stop(); }
1013 
GetAutoCompleteText() const1014     const OUString&     GetAutoCompleteText() const { return aAutoCompleteText; }
1015     void                SetAutoCompleteText(const OUString& rStr, bool bUpdateTipWindow);
1016 
1017     EditSelection       TransliterateText( const EditSelection& rSelection, TransliterationFlags nTransliterationMode );
1018     short               ReplaceTextOnly( ContentNode* pNode, sal_Int32 nCurrentStart, const OUString& rText, const css::uno::Sequence< sal_Int32 >& rOffsets );
1019 
1020     void                SetAsianCompressionMode( CharCompressType n );
GetAsianCompressionMode() const1021     CharCompressType    GetAsianCompressionMode() const { return nAsianCompressionMode; }
1022 
1023     void                SetKernAsianPunctuation( bool b );
IsKernAsianPunctuation() const1024     bool                IsKernAsianPunctuation() const { return bKernAsianPunctuation; }
1025 
GetOverflowingParaNum() const1026     sal_Int32 GetOverflowingParaNum() const { return mnOverflowingPara; }
GetOverflowingLineNum() const1027     sal_Int32 GetOverflowingLineNum() const { return mnOverflowingLine; }
ClearOverflowingParaNum()1028     void ClearOverflowingParaNum() { mnOverflowingPara = -1; }
1029 
1030 
1031     void                SetAddExtLeading( bool b );
IsAddExtLeading() const1032     bool                IsAddExtLeading() const { return bAddExtLeading; }
1033 
1034     static std::shared_ptr<SvxForbiddenCharactersTable> const & GetForbiddenCharsTable();
1035     static void         SetForbiddenCharsTable( const std::shared_ptr<SvxForbiddenCharactersTable>& xForbiddenChars );
1036 
1037     /** sets a link that is called at the beginning of a drag operation at an edit view */
SetBeginDropHdl(const Link<EditView *,void> & rLink)1038     void                SetBeginDropHdl( const Link<EditView*,void>& rLink ) { maBeginDropHdl = rLink; }
GetBeginDropHdl() const1039     const Link<EditView*,void>&  GetBeginDropHdl() const { return maBeginDropHdl; }
1040 
1041     /** sets a link that is called at the end of a drag operation at an edit view */
SetEndDropHdl(const Link<EditView *,void> & rLink)1042     void            SetEndDropHdl( const Link<EditView*,void>& rLink ) { maEndDropHdl = rLink; }
GetEndDropHdl() const1043     const Link<EditView*,void>&  GetEndDropHdl() const { return maEndDropHdl; }
1044 
1045     /// specifies if auto-correction should capitalize the first word or not (default is on)
SetFirstWordCapitalization(bool bCapitalize)1046     void            SetFirstWordCapitalization( bool bCapitalize )  { bFirstWordCapitalization = bCapitalize; }
IsFirstWordCapitalization() const1047     bool            IsFirstWordCapitalization() const   { return bFirstWordCapitalization; }
1048 
1049     /** specifies if auto-correction should replace a leading single quotation
1050         mark (apostrophe) or not (default is on) */
SetReplaceLeadingSingleQuotationMark(bool bReplace)1051     void            SetReplaceLeadingSingleQuotationMark( bool bReplace ) { mbReplaceLeadingSingleQuotationMark = bReplace; }
IsReplaceLeadingSingleQuotationMark() const1052     bool            IsReplaceLeadingSingleQuotationMark() const { return mbReplaceLeadingSingleQuotationMark; }
1053 
1054     /** Whether last AutoCorrect inserted a NO-BREAK SPACE that may need to be removed again. */
IsNbspRunNext() const1055     bool            IsNbspRunNext() const { return mbNbspRunNext; }
1056 
1057     void Dispose();
1058 };
1059 
CreateEPaM(const EditPaM & rPaM)1060 inline EPaM ImpEditEngine::CreateEPaM( const EditPaM& rPaM )
1061 {
1062     const ContentNode* pNode = rPaM.GetNode();
1063     return EPaM( aEditDoc.GetPos( pNode ), rPaM.GetIndex() );
1064 }
1065 
CreateEditPaM(const EPaM & rEPaM)1066 inline EditPaM ImpEditEngine::CreateEditPaM( const EPaM& rEPaM )
1067 {
1068     DBG_ASSERT( rEPaM.nPara < aEditDoc.Count(), "CreateEditPaM: invalid paragraph" );
1069     DBG_ASSERT( aEditDoc[ rEPaM.nPara ]->Len() >= rEPaM.nIndex, "CreateEditPaM: invalid Index" );
1070     return EditPaM( aEditDoc[ rEPaM.nPara], rEPaM.nIndex );
1071 }
1072 
CreateESel(const EditSelection & rSel)1073 inline ESelection ImpEditEngine::CreateESel( const EditSelection& rSel )
1074 {
1075     const ContentNode* pStartNode = rSel.Min().GetNode();
1076     const ContentNode* pEndNode = rSel.Max().GetNode();
1077     ESelection aESel;
1078     aESel.nStartPara = aEditDoc.GetPos( pStartNode );
1079     aESel.nStartPos = rSel.Min().GetIndex();
1080     aESel.nEndPara = aEditDoc.GetPos( pEndNode );
1081     aESel.nEndPos = rSel.Max().GetIndex();
1082     return aESel;
1083 }
1084 
CreateSel(const ESelection & rSel)1085 inline EditSelection ImpEditEngine::CreateSel( const ESelection& rSel )
1086 {
1087     DBG_ASSERT( rSel.nStartPara < aEditDoc.Count(), "CreateSel: invalid start paragraph" );
1088     DBG_ASSERT( rSel.nEndPara < aEditDoc.Count(), "CreateSel: invalid end paragraph" );
1089     EditSelection aSel;
1090     aSel.Min().SetNode( aEditDoc[ rSel.nStartPara ] );
1091     aSel.Min().SetIndex( rSel.nStartPos );
1092     aSel.Max().SetNode( aEditDoc[ rSel.nEndPara ] );
1093     aSel.Max().SetIndex( rSel.nEndPos );
1094     DBG_ASSERT( !aSel.DbgIsBuggy( aEditDoc ), "CreateSel: incorrect selection!" );
1095     return aSel;
1096 }
1097 
GetVirtualDevice(const MapMode & rMapMode,DrawModeFlags nDrawMode)1098 inline VirtualDevice* ImpEditEngine::GetVirtualDevice( const MapMode& rMapMode, DrawModeFlags nDrawMode )
1099 {
1100     if ( !pVirtDev )
1101         pVirtDev = VclPtr<VirtualDevice>::Create();
1102 
1103     if ( ( pVirtDev->GetMapMode().GetMapUnit() != rMapMode.GetMapUnit() ) ||
1104          ( pVirtDev->GetMapMode().GetScaleX() != rMapMode.GetScaleX() ) ||
1105          ( pVirtDev->GetMapMode().GetScaleY() != rMapMode.GetScaleY() ) )
1106     {
1107         MapMode aMapMode( rMapMode );
1108         aMapMode.SetOrigin( Point( 0, 0 ) );
1109         pVirtDev->SetMapMode( aMapMode );
1110     }
1111 
1112     pVirtDev->SetDrawMode( nDrawMode );
1113 
1114     return pVirtDev;
1115 }
1116 
IdleFormatAndUpdate(EditView * pCurView)1117 inline void ImpEditEngine::IdleFormatAndUpdate( EditView* pCurView )
1118 {
1119     aIdleFormatter.DoIdleFormat( pCurView );
1120 }
1121 
GetUndoManager()1122 inline EditUndoManager& ImpEditEngine::GetUndoManager()
1123 {
1124     if ( !pUndoManager )
1125     {
1126         pUndoManager = new EditUndoManager();
1127         pUndoManager->SetEditEngine(pEditEngine);
1128     }
1129     return *pUndoManager;
1130 }
1131 
SetUndoManager(SfxUndoManager * pNew)1132 inline SfxUndoManager* ImpEditEngine::SetUndoManager(SfxUndoManager* pNew)
1133 {
1134     SfxUndoManager* pRetval = pUndoManager;
1135 
1136     if(pUndoManager)
1137     {
1138         pUndoManager->SetEditEngine(nullptr);
1139     }
1140 
1141     pUndoManager = dynamic_cast< EditUndoManager* >(pNew);
1142 
1143     if(pUndoManager)
1144     {
1145         pUndoManager->SetEditEngine(pEditEngine);
1146     }
1147 
1148     return pRetval;
1149 }
1150 
FindParaPortion(const ContentNode * pNode) const1151 inline const ParaPortion* ImpEditEngine::FindParaPortion( const ContentNode* pNode ) const
1152 {
1153     sal_Int32 nPos = aEditDoc.GetPos( pNode );
1154     DBG_ASSERT( nPos < GetParaPortions().Count(), "Portionloser Node?" );
1155     return GetParaPortions()[ nPos ];
1156 }
1157 
FindParaPortion(ContentNode const * pNode)1158 inline ParaPortion* ImpEditEngine::FindParaPortion( ContentNode const * pNode )
1159 {
1160     sal_Int32 nPos = aEditDoc.GetPos( pNode );
1161     DBG_ASSERT( nPos < GetParaPortions().Count(), "Portionloser Node?" );
1162     return GetParaPortions()[ nPos ];
1163 }
1164 
GetCharStretching(sal_uInt16 & rX,sal_uInt16 & rY) const1165 inline void ImpEditEngine::GetCharStretching( sal_uInt16& rX, sal_uInt16& rY ) const
1166 {
1167     rX = nStretchX;
1168     rY = nStretchY;
1169 }
1170 
GetXValue(short nXValue) const1171 inline short ImpEditEngine::GetXValue( short nXValue ) const
1172 {
1173     if ( !aStatus.DoStretch() || ( nStretchX == 100 ) )
1174         return nXValue;
1175 
1176     return static_cast<short>(static_cast<long>(nXValue)*nStretchX/100);
1177 }
1178 
1179 
GetXValue(long nXValue) const1180 inline long ImpEditEngine::GetXValue( long nXValue ) const
1181 {
1182     if ( !aStatus.DoStretch() || ( nStretchX == 100 ) )
1183         return nXValue;
1184 
1185     return nXValue*nStretchX/100;
1186 }
1187 
GetYValue(short nYValue) const1188 inline short ImpEditEngine::GetYValue( short nYValue ) const
1189 {
1190     if ( !aStatus.DoStretch() || ( nStretchY == 100 ) )
1191         return nYValue;
1192 
1193     return static_cast<short>(static_cast<long>(nYValue)*nStretchY/100);
1194 }
1195 
GetYValue(sal_uInt16 nYValue) const1196 inline sal_uInt16 ImpEditEngine::GetYValue( sal_uInt16 nYValue ) const
1197 {
1198     if ( !aStatus.DoStretch() || ( nStretchY == 100 ) )
1199         return nYValue;
1200 
1201     return static_cast<sal_uInt16>(static_cast<long>(nYValue)*nStretchY/100);
1202 }
1203 
GetPointer()1204 inline PointerStyle ImpEditView::GetPointer()
1205 {
1206     if ( !mxPointer )
1207     {
1208         mxPointer = IsVertical() ? PointerStyle::TextVertical : PointerStyle::Text;
1209         return *mxPointer;
1210     }
1211 
1212     if(PointerStyle::Text == *mxPointer && IsVertical())
1213     {
1214         mxPointer = PointerStyle::TextVertical;
1215     }
1216     else if(PointerStyle::TextVertical == *mxPointer && !IsVertical())
1217     {
1218         mxPointer = PointerStyle::Text;
1219     }
1220 
1221     return *mxPointer;
1222 }
1223 
GetCursor()1224 inline vcl::Cursor* ImpEditView::GetCursor()
1225 {
1226     if ( !pCursor )
1227         pCursor.reset( new vcl::Cursor );
1228     return pCursor.get();
1229 }
1230 
1231 void ConvertItem( std::unique_ptr<SfxPoolItem>& rPoolItem, MapUnit eSourceUnit, MapUnit eDestUnit );
1232 void ConvertAndPutItems( SfxItemSet& rDest, const SfxItemSet& rSource, const MapUnit* pSourceUnit = nullptr, const MapUnit* pDestUnit = nullptr );
1233 AsianCompressionFlags GetCharTypeForCompression( sal_Unicode cChar );
1234 Point Rotate( const Point& rPoint, short nOrientation, const Point& rOrigin );
1235 
1236 #endif // INCLUDED_EDITENG_SOURCE_EDITENG_IMPEDIT_HXX
1237 
1238 
1239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1240