1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 // MyEDITVIEW, due to exported EditView
20 #ifndef INCLUDED_EDITENG_EDITVIEW_HXX
21 #define INCLUDED_EDITENG_EDITVIEW_HXX
24 #include <com/sun/star/i18n/WordType.hpp>
26 #include <i18nlangtag/lang.h>
27 #include <tools/color.hxx>
28 #include <tools/gen.hxx>
29 #include <vcl/errcode.hxx>
30 #include <vcl/vclptr.hxx>
31 #include <editeng/editstat.hxx>
32 #include <svl/languageoptions.hxx>
33 #include <editeng/editdata.hxx>
34 #include <com/sun/star/uno/Reference.h>
35 #include <editeng/editengdllapi.h>
42 class OutlinerViewShell
;
45 namespace vcl
{ class Window
; }
50 class SvKeyValueIterator
;
53 namespace vcl
{ class Cursor
; }
54 namespace vcl
{ class Font
; }
57 enum class TransliterationFlags
;
58 enum class PointerStyle
;
63 namespace datatransfer
{
66 namespace linguistic2
{
68 class XLanguageGuessing
;
72 template <typename Arg
, typename Ret
> class Link
;
74 enum class ScrollRangeCheck
76 NoNegative
= 1, // No negative VisArea when scrolling
77 PaperWidthTextSize
= 2, // VisArea must be within paper width, Text Size
80 // Helper class that allows to set a callback at the EditView. When
81 // set, Invalidates and repaints are suppressed at the EditView, but
82 // EditViewInvalidate() will be triggered to allow the consumer to
83 // react itself as needed.
84 // Also Selection visualization is suppressed and EditViewSelectionChange
85 // is triggered when Selection changes and needs reaction.
86 class EDITENG_DLLPUBLIC EditViewCallbacks
89 EditViewCallbacks() {}
90 virtual ~EditViewCallbacks();
92 // call this when text visualization changed in any way. It
93 // will also update selection, so no need to call this self
94 // additionally (but will also do no harm)
95 virtual void EditViewInvalidate(const tools::Rectangle
& rRect
) const = 0;
97 // call this when only selection is changed. Text change will
98 // then *not* be checked and not be reacted on. Still, when
99 // only the selection is changed, this is useful and faster
100 virtual void EditViewSelectionChange() const = 0;
102 // return the OutputDevice that the EditView will draw to
103 virtual OutputDevice
& EditViewOutputDevice() const = 0;
106 class EDITENG_DLLPUBLIC EditView final
108 friend class EditEngine
;
109 friend class ImpEditEngine
;
110 friend class EditSelFunctionSet
;
113 typedef std::vector
<VclPtr
<vcl::Window
>> OutWindowSet
;
115 public: // Needed for Undo
116 ImpEditView
* GetImpEditView() const { return pImpEditView
.get(); }
117 ImpEditEngine
* GetImpEditEngine() const;
120 std::unique_ptr
<ImpEditView
>
122 OUString aDicNameSingle
;
124 EditView( const EditView
& ) = delete;
125 EditView
& operator=( const EditView
& ) = delete;
128 EditView( EditEngine
* pEng
, vcl::Window
* pWindow
);
131 // set EditViewCallbacks for external handling of Repaints/Visualization
132 void setEditViewCallbacks(const EditViewCallbacks
* pEditViewCallbacks
);
133 const EditViewCallbacks
* getEditViewCallbacks() const;
135 void SetEditEngine( EditEngine
* pEditEngine
);
136 EditEngine
* GetEditEngine() const;
138 void SetWindow( vcl::Window
* pWin
);
139 vcl::Window
* GetWindow() const;
141 bool HasOtherViewWindow( vcl::Window
* pWin
);
142 bool AddOtherViewWindow( vcl::Window
* pWin
);
143 bool RemoveOtherViewWindow( vcl::Window
* pWin
);
145 void Paint( const tools::Rectangle
& rRect
, OutputDevice
* pTargetDevice
= nullptr );
146 tools::Rectangle
GetInvalidateRect() const;
147 void InvalidateWindow(const tools::Rectangle
& rClipRect
);
148 void InvalidateOtherViewWindows( const tools::Rectangle
& rInvRect
);
150 Pair
Scroll( long nHorzScroll
, long nVertScroll
, ScrollRangeCheck nRangeCheck
= ScrollRangeCheck::NoNegative
);
152 void ShowCursor( bool bGotoCursor
= true, bool bForceVisCursor
= true, bool bActivate
= false );
153 void HideCursor( bool bDeactivate
= false );
155 void SetSelectionMode( EESelectionMode eMode
);
157 void SetReadOnly( bool bReadOnly
);
158 bool IsReadOnly() const;
160 bool HasSelection() const;
161 ESelection
GetSelection() const;
162 void SetSelection( const ESelection
& rNewSel
);
163 void SelectCurrentWord( sal_Int16 nWordType
= css::i18n::WordType::ANYWORD_IGNOREWHITESPACES
);
164 /// Returns the rectangles of the current selection in TWIPs.
165 void GetSelectionRectangles(std::vector
<tools::Rectangle
>& rLogicRects
) const;
167 bool IsInsertMode() const;
168 void SetInsertMode( bool bInsert
);
170 OUString
GetSelected();
171 void DeleteSelected();
173 SvtScriptType
GetSelectedScriptType() const;
175 // VisArea position of the Output window.
176 // A size change also affects the VisArea
177 void SetOutputArea( const tools::Rectangle
& rRect
);
178 const tools::Rectangle
& GetOutputArea() const;
180 // Document position.
181 // A size change also affects the VisArea
182 void SetVisArea( const tools::Rectangle
& rRect
);
183 const tools::Rectangle
& GetVisArea() const;
185 PointerStyle
GetPointer() const;
187 vcl::Cursor
* GetCursor() const;
189 void InsertText( const OUString
& rNew
, bool bSelect
= false );
190 void InsertParaBreak();
192 bool PostKeyEvent( const KeyEvent
& rKeyEvent
, vcl::Window
const * pFrameWin
= nullptr );
194 bool MouseButtonUp( const MouseEvent
& rMouseEvent
);
195 bool MouseButtonDown( const MouseEvent
& rMouseEvent
);
197 bool MouseMove( const MouseEvent
& rMouseEvent
);
198 void Command( const CommandEvent
& rCEvt
);
208 // especially for Oliver Specht
209 Point
GetWindowPosTopLeft( sal_Int32 nParagraph
);
210 void MoveParagraphs( Range aParagraphs
, sal_Int32 nNewPos
);
211 void MoveParagraphs( long nDiff
);
213 const SfxItemSet
& GetEmptyItemSet();
214 SfxItemSet
GetAttribs();
215 void SetAttribs( const SfxItemSet
& rSet
);
216 void RemoveAttribs( bool bRemoveParaAttribs
= false, sal_uInt16 nWhich
= 0 );
217 void RemoveCharAttribs( sal_Int32 nPara
, sal_uInt16 nWhich
);
218 void RemoveAttribsKeepLanguages( bool bRemoveParaAttribs
);
220 ErrCode
Read( SvStream
& rInput
, EETextFormat eFormat
, SvKeyValueIterator
* pHTTPHeaderAttrs
);
222 void SetBackgroundColor( const Color
& rColor
);
223 Color
const & GetBackgroundColor() const;
225 /// Informs this edit view about which view shell contains it.
226 void RegisterViewShell(OutlinerViewShell
* pViewShell
);
227 /// Informs this edit view about which other shell listens to it.
228 void RegisterOtherShell(OutlinerViewShell
* pOtherShell
);
230 void SetControlWord( EVControlBits nWord
);
231 EVControlBits
GetControlWord() const;
233 std::unique_ptr
<EditTextObject
> CreateTextObject();
234 void InsertText( const EditTextObject
& rTextObject
);
235 void InsertText( css::uno::Reference
< css::datatransfer::XTransferable
> const & xDataObj
, const OUString
& rBaseURL
, bool bUseSpecial
);
237 css::uno::Reference
< css::datatransfer::XTransferable
> GetTransferable();
239 // An EditView, so that when TRUE the update will be free from flickering:
240 void SetEditEngineUpdateMode( bool bUpdate
);
243 const SfxStyleSheet
* GetStyleSheet() const;
244 SfxStyleSheet
* GetStyleSheet();
246 void SetAnchorMode( EEAnchorMode eMode
);
247 EEAnchorMode
GetAnchorMode() const;
249 void CompleteAutoCorrect( vcl::Window
const * pFrameWin
= nullptr );
251 EESpellState
StartSpeller( bool bMultipleDoc
= false );
252 EESpellState
StartThesaurus();
253 sal_Int32
StartSearchAndReplace( const SvxSearchItem
& rSearchItem
);
255 // for text conversion
256 void StartTextConversion( LanguageType nSrcLang
, LanguageType nDestLang
, const vcl::Font
*pDestFont
, sal_Int32 nOptions
, bool bIsInteractive
, bool bMultipleDoc
);
258 void TransliterateText( TransliterationFlags nTransliterationMode
);
260 bool IsCursorAtWrongSpelledWord();
261 bool IsWrongSpelledWordAtPos( const Point
& rPosPixel
, bool bMarkIfWrong
= false );
262 void ExecuteSpellPopup( const Point
& rPosPixel
, Link
<SpellCallbackInfo
&,void> const * pCallBack
);
264 void InsertField( const SvxFieldItem
& rFld
);
265 const SvxFieldItem
* GetFieldUnderMousePointer() const;
266 const SvxFieldItem
* GetFieldUnderMousePointer( sal_Int32
& nPara
, sal_Int32
& nPos
) const;
267 const SvxFieldItem
* GetField( const Point
& rPos
, sal_Int32
* pnPara
= nullptr, sal_Int32
* pnPos
= nullptr ) const;
269 const SvxFieldItem
* GetFieldAtSelection() const;
271 void SetInvalidateMore( sal_uInt16 nPixel
);
272 sal_uInt16
GetInvalidateMore() const;
274 // grows or shrinks the font height for the current selection
275 void ChangeFontSize( bool bGrow
, const FontList
* pList
);
277 static bool ChangeFontSize( bool bGrow
, SfxItemSet
& rSet
, const FontList
* pFontList
);
279 OUString
GetSurroundingText() const;
280 Selection
GetSurroundingTextSelection() const;
282 /** Tries to determine the language of 'rText', returning a matching known
283 locale if possible, or a fallback, or LANGUAGE_NONE if nothing found or
287 If TRUE, rText is a paragraph and the language is obtained by
288 passing the text to xLangGuess.
289 IF FALSE, a language match is tried for, in order,
290 1. the default document language (non-CTL, non-CJK, aka LATIN)
291 2. the UI language (Tools->Options->LanguageSettings->Languages User Interface)
292 3. the locale (Tools->Options->LanguageSettings->Languages Locale)
294 If nothing matched, LANGUAGE_NONE is returned.
296 static LanguageType
CheckLanguage(
297 const OUString
&rText
,
298 const css::uno::Reference
< css::linguistic2::XSpellChecker1
>& xSpell
,
299 const css::uno::Reference
< css::linguistic2::XLanguageGuessing
>& xLangGuess
,
301 /// Allows adjusting the point or mark of the selection to a document coordinate.
302 void SetCursorLogicPosition(const Point
& rPosition
, bool bPoint
, bool bClearMark
);
303 /// Trigger selection drawing callback in pOtherShell based on our shell's selection state.
304 void DrawSelectionXOR(OutlinerViewShell
* pOtherShell
);
307 #endif // INCLUDED_EDITENG_EDITVIEW_HXX
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */