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 <comphelper/errcode.hxx>
30 #include <vcl/vclptr.hxx>
31 #include <editeng/editstat.hxx>
32 #include <editeng/flditem.hxx>
33 #include <svl/languageoptions.hxx>
34 #include <editeng/editdata.hxx>
35 #include <com/sun/star/uno/Reference.h>
36 #include <editeng/editengdllapi.h>
43 class OutlinerViewShell
;
46 namespace vcl
{ class Window
; }
47 namespace weld
{ class Widget
; }
52 class SvKeyValueIterator
;
55 namespace vcl
{ class Cursor
; }
56 namespace vcl
{ class Font
; }
60 enum class TransliterationFlags
;
61 enum class PointerStyle
;
66 namespace datatransfer
{
75 namespace linguistic2
{
77 class XLanguageGuessing
;
81 template <typename Arg
, typename Ret
> class Link
;
83 enum class ScrollRangeCheck
85 NoNegative
= 1, // No negative VisArea when scrolling
86 PaperWidthTextSize
= 2, // VisArea must be within paper width, Text Size
89 // Helper class that allows to set a callback at the EditView. When
90 // set, Invalidates and repaints are suppressed at the EditView, but
91 // EditViewInvalidate() will be triggered to allow the consumer to
92 // react itself as needed.
93 // Also Selection visualization is suppressed and EditViewSelectionChange
94 // is triggered when Selection changes and needs reaction.
95 class EDITENG_DLLPUBLIC EditViewCallbacks
98 virtual ~EditViewCallbacks();
100 // call this when text visualization changed in any way. It
101 // will also update selection, so no need to call this self
102 // additionally (but will also do no harm)
103 virtual void EditViewInvalidate(const tools::Rectangle
& rRect
) = 0;
105 // call this when only selection is changed. Text change will
106 // then *not* be checked and not be reacted on. Still, when
107 // only the selection is changed, this is useful and faster
108 virtual void EditViewSelectionChange() = 0;
110 // return the OutputDevice that the EditView will draw to
111 virtual OutputDevice
& EditViewOutputDevice() const = 0;
113 virtual weld::Widget
* EditViewPopupParent() const
118 // return the Mouse Position
119 virtual Point
EditViewPointerPosPixel() const = 0;
121 // Triggered to update InputEngine context information
122 virtual void EditViewInputContext(const InputContext
& rInputContext
) = 0;
124 // Triggered to update InputEngine cursor position
125 virtual void EditViewCursorRect(const tools::Rectangle
& rRect
, int nExtTextInputWidth
) = 0;
127 // Triggered if scroll bar state should change
128 virtual void EditViewScrollStateChange()
132 // Access to clipboard
133 virtual css::uno::Reference
<css::datatransfer::clipboard::XClipboard
> GetClipboard() const = 0;
135 // implemented if drag and drop support is wanted
136 virtual css::uno::Reference
<css::datatransfer::dnd::XDropTarget
> GetDropTarget()
142 class EDITENG_DLLPUBLIC EditView final
144 friend class EditEngine
;
145 friend class ImpEditEngine
;
146 friend class EditSelFunctionSet
;
149 typedef std::vector
<VclPtr
<vcl::Window
>> OutWindowSet
;
151 public: // Needed for Undo
152 ImpEditView
* GetImpEditView() const { return pImpEditView
.get(); }
153 ImpEditEngine
* GetImpEditEngine() const;
156 std::unique_ptr
<ImpEditView
>
158 OUString aDicNameSingle
;
160 EditView( const EditView
& ) = delete;
161 EditView
& operator=( const EditView
& ) = delete;
163 // counts how many characters take unfolded fields
164 // bCanOverflow - count field length without trim to the selected pos
165 sal_Int32
countFieldsOffsetSum(sal_Int32 nPara
, sal_Int32 nPo
, bool bCanOverflow
) const;
168 EditView( EditEngine
* pEng
, vcl::Window
* pWindow
);
171 // set EditViewCallbacks for external handling of Repaints/Visualization
172 void setEditViewCallbacks(EditViewCallbacks
* pEditViewCallbacks
);
173 EditViewCallbacks
* getEditViewCallbacks() const;
175 void SetEditEngine( EditEngine
* pEditEngine
);
176 EditEngine
* GetEditEngine() const;
178 void SetWindow( vcl::Window
* pWin
);
179 vcl::Window
* GetWindow() const;
180 OutputDevice
& GetOutputDevice() const;
182 LanguageType
GetInputLanguage() const;
184 bool HasOtherViewWindow( vcl::Window
* pWin
);
185 bool AddOtherViewWindow( vcl::Window
* pWin
);
186 bool RemoveOtherViewWindow( vcl::Window
* pWin
);
188 void Paint( const tools::Rectangle
& rRect
, OutputDevice
* pTargetDevice
= nullptr );
189 tools::Rectangle
GetInvalidateRect() const;
190 void InvalidateWindow(const tools::Rectangle
& rClipRect
);
191 void InvalidateOtherViewWindows( const tools::Rectangle
& rInvRect
);
193 ::Pair
Scroll( tools::Long nHorzScroll
, tools::Long nVertScroll
, ScrollRangeCheck nRangeCheck
= ScrollRangeCheck::NoNegative
);
195 void SetBroadcastLOKViewCursor(bool bSet
);
196 tools::Rectangle
GetEditCursor() const;
197 void ShowCursor( bool bGotoCursor
= true, bool bForceVisCursor
= true, bool bActivate
= false );
198 void HideCursor( bool bDeactivate
= false );
200 void SetSelectionMode( EESelectionMode eMode
);
202 void SetReadOnly( bool bReadOnly
);
203 bool IsReadOnly() const;
205 bool HasSelection() const;
206 ESelection
GetSelection() const;
207 void SetSelection( const ESelection
& rNewSel
);
208 bool IsSelectionAtPoint(const Point
& rPointPixel
);
209 void SelectCurrentWord( sal_Int16 nWordType
= css::i18n::WordType::ANYWORD_IGNOREWHITESPACES
);
210 /// Returns the rectangles of the current selection in TWIPs.
211 void GetSelectionRectangles(std::vector
<tools::Rectangle
>& rLogicRects
) const;
213 bool IsInsertMode() const;
214 void SetInsertMode( bool bInsert
);
216 OUString
GetSelected() const;
217 void DeleteSelected();
219 SvtScriptType
GetSelectedScriptType() const;
221 // VisArea position of the Output window.
222 // A size change also affects the VisArea
223 void SetOutputArea( const tools::Rectangle
& rRect
);
224 const tools::Rectangle
& GetOutputArea() const;
226 // Document position.
227 // A size change also affects the VisArea
228 void SetVisArea( const tools::Rectangle
& rRect
);
229 tools::Rectangle
GetVisArea() const;
231 PointerStyle
GetPointer() const;
233 vcl::Cursor
* GetCursor() const;
235 void InsertText( const OUString
& rNew
, bool bSelect
= false , bool bLOKShowSelect
= true);
236 void InsertParaBreak();
238 bool PostKeyEvent( const KeyEvent
& rKeyEvent
, vcl::Window
const * pFrameWin
= nullptr );
240 bool MouseButtonUp( const MouseEvent
& rMouseEvent
);
241 bool MouseButtonDown( const MouseEvent
& rMouseEvent
);
243 bool MouseMove( const MouseEvent
& rMouseEvent
);
244 bool Command(const CommandEvent
& rCEvt
);
254 // especially for Oliver Specht
255 Point
GetWindowPosTopLeft( sal_Int32 nParagraph
);
256 void MoveParagraphs( Range aParagraphs
, sal_Int32 nNewPos
);
257 void MoveParagraphs( tools::Long nDiff
);
259 const SfxItemSet
& GetEmptyItemSet() const;
260 SfxItemSet
GetAttribs();
261 void SetAttribs( const SfxItemSet
& rSet
);
262 void RemoveAttribs( bool bRemoveParaAttribs
= false, sal_uInt16 nWhich
= 0 );
263 void RemoveAttribs( EERemoveParaAttribsMode eMode
, sal_uInt16 nWhich
);
264 void RemoveCharAttribs( sal_Int32 nPara
, sal_uInt16 nWhich
);
265 void RemoveAttribsKeepLanguages( bool bRemoveParaAttribs
);
267 ErrCode
Read( SvStream
& rInput
, EETextFormat eFormat
, SvKeyValueIterator
* pHTTPHeaderAttrs
);
269 void SetBackgroundColor( const Color
& rColor
);
270 Color
const & GetBackgroundColor() const;
272 /// Informs this edit view about which view shell contains it.
273 void RegisterViewShell(OutlinerViewShell
* pViewShell
);
274 /// Informs this edit view about which other shell listens to it.
275 void RegisterOtherShell(OutlinerViewShell
* pOtherShell
);
277 void SetControlWord( EVControlBits nWord
);
278 EVControlBits
GetControlWord() const;
280 std::unique_ptr
<EditTextObject
> CreateTextObject();
281 void InsertText( const EditTextObject
& rTextObject
);
282 void InsertText( css::uno::Reference
< css::datatransfer::XTransferable
> const & xDataObj
, const OUString
& rBaseURL
, bool bUseSpecial
);
284 css::uno::Reference
<css::datatransfer::clipboard::XClipboard
> GetClipboard() const;
285 css::uno::Reference
<css::datatransfer::XTransferable
> GetTransferable() const;
287 // An EditView, so that when TRUE the update will be free from flickering:
288 // @return the previous bUpdateLayout state
289 bool SetEditEngineUpdateLayout( bool bUpdate
);
290 void ForceLayoutCalculation();
292 const SfxStyleSheet
* GetStyleSheet() const;
293 SfxStyleSheet
* GetStyleSheet();
295 void SetAnchorMode( EEAnchorMode eMode
);
296 EEAnchorMode
GetAnchorMode() const;
298 void CompleteAutoCorrect( vcl::Window
const * pFrameWin
= nullptr );
300 EESpellState
StartSpeller(weld::Widget
* pDialogParent
, bool bMultipleDoc
= false);
301 EESpellState
StartThesaurus(weld::Widget
* pDialogParent
);
302 sal_Int32
StartSearchAndReplace( const SvxSearchItem
& rSearchItem
);
304 // for text conversion
305 void StartTextConversion(weld::Widget
* pDialogParent
, LanguageType nSrcLang
, LanguageType nDestLang
, const vcl::Font
*pDestFont
, sal_Int32 nOptions
, bool bIsInteractive
, bool bMultipleDoc
);
307 void TransliterateText( TransliterationFlags nTransliterationMode
);
309 bool IsCursorAtWrongSpelledWord();
310 bool IsWrongSpelledWordAtPos( const Point
& rPosPixel
, bool bMarkIfWrong
= false );
311 bool ExecuteSpellPopup(const Point
& rPosPixel
, const Link
<SpellCallbackInfo
&,void>& rCallBack
);
312 OUString
SpellIgnoreWord();
314 void InsertField( const SvxFieldItem
& rFld
);
315 const SvxFieldItem
* GetFieldUnderMousePointer() const;
316 const SvxFieldItem
* GetFieldUnderMousePointer( sal_Int32
& nPara
, sal_Int32
& nPos
) const;
317 const SvxFieldItem
* GetField( const Point
& rPos
, sal_Int32
* pnPara
= nullptr, sal_Int32
* pnPos
= nullptr ) const;
319 const SvxFieldItem
* GetFieldAtSelection() const;
320 /// Select and return the field at the current cursor position
321 const SvxFieldData
* GetFieldAtCursor() const;
322 void SelectFieldAtCursor();
323 /// Converts position in paragraph to logical position without unfolding fields
324 sal_Int32
GetPosNoField(sal_Int32 nPara
, sal_Int32 nPos
) const;
325 /// Converts logical position in paragraph to position with unfolded fields
326 sal_Int32
GetPosWithField(sal_Int32 nPara
, sal_Int32 nPos
) const;
328 void SetInvalidateMore( sal_uInt16 nPixel
);
329 sal_uInt16
GetInvalidateMore() const;
331 // grows or shrinks the font height for the current selection
332 void ChangeFontSize( bool bGrow
, const FontList
* pList
);
334 static bool ChangeFontSize( bool bGrow
, SfxItemSet
& rSet
, const FontList
* pFontList
);
336 OUString
GetSurroundingText() const;
337 Selection
GetSurroundingTextSelection() const;
338 bool DeleteSurroundingText(const Selection
& rRange
);
340 /** Tries to determine the language of 'rText', returning a matching known
341 locale if possible, or a fallback, or LANGUAGE_NONE if nothing found or
345 If TRUE, rText is a paragraph and the language is obtained by
346 passing the text to xLangGuess.
347 IF FALSE, a language match is tried for, in order,
348 1. the default document language (non-CTL, non-CJK, aka LATIN)
349 2. the UI language (Tools->Options->LanguageSettings->Languages User Interface)
350 3. the locale (Tools->Options->LanguageSettings->Languages Locale)
352 If nothing matched, LANGUAGE_NONE is returned.
354 static LanguageType
CheckLanguage(
355 const OUString
&rText
,
356 const css::uno::Reference
< css::linguistic2::XSpellChecker1
>& xSpell
,
357 const css::uno::Reference
< css::linguistic2::XLanguageGuessing
>& xLangGuess
,
359 /// Allows adjusting the point or mark of the selection to a document coordinate.
360 void SetCursorLogicPosition(const Point
& rPosition
, bool bPoint
, bool bClearMark
);
361 /// Trigger selection drawing callback in pOtherShell based on our shell's selection state.
362 void DrawSelectionXOR(OutlinerViewShell
* pOtherShell
);
365 * This is meant for Calc(LOK), but there may be other use-cases.
366 * In Calc, all logical positions are computed by
367 * doing independent pixel-alignment for each cell's size. The *LOKSpecial* methods
368 * can be used to set/get the output-area and visible-area in real logical
369 * units. This enables EditView to send cursor/selection messages in
370 * real logical units like it is done for Writer.
372 void InitLOKSpecialPositioning(MapUnit eUnit
, const tools::Rectangle
& rOutputArea
,
373 const Point
& rVisDocStartPos
);
374 void SetLOKSpecialOutputArea(const tools::Rectangle
& rOutputArea
);
375 const tools::Rectangle
& GetLOKSpecialOutputArea() const;
376 void SetLOKSpecialVisArea(const tools::Rectangle
& rVisArea
);
377 tools::Rectangle
GetLOKSpecialVisArea() const;
378 bool HasLOKSpecialPositioning() const;
380 void SuppressLOKMessages(bool bSet
);
381 bool IsSuppressLOKMessages() const;
383 /// To inform editeng that negated x document coordinates are in use.
384 void SetNegativeX(bool bSet
);
385 bool IsNegativeX() const;
388 #endif // INCLUDED_EDITENG_EDITVIEW_HXX
390 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */