Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / editeng / editview.hxx
blob73d4c23f49a95da3aed6359db9bb87ef28821fc5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
23 #include <memory>
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>
39 class EditTextObject;
40 class EditEngine;
41 class ImpEditEngine;
42 class ImpEditView;
43 class OutlinerViewShell;
44 class SvxSearchItem;
45 class SvxFieldItem;
46 namespace vcl { class Window; }
47 namespace weld { class Widget; }
48 class KeyEvent;
49 class MouseEvent;
50 class CommandEvent;
51 class SvStream;
52 class SvKeyValueIterator;
53 class SfxStyleSheet;
54 class SfxItemSet;
55 namespace vcl { class Cursor; }
56 namespace vcl { class Font; }
57 class FontList;
58 class InputContext;
59 class OutputDevice;
60 enum class TransliterationFlags;
61 enum class PointerStyle;
63 namespace com {
64 namespace sun {
65 namespace star {
66 namespace datatransfer {
67 class XTransferable;
68 namespace clipboard {
69 class XClipboard;
71 namespace dnd {
72 class XDropTarget;
75 namespace linguistic2 {
76 class XSpellChecker1;
77 class XLanguageGuessing;
79 }}}
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
97 public:
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
115 return nullptr;
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()
138 return nullptr;
142 class EDITENG_DLLPUBLIC EditView final
144 friend class EditEngine;
145 friend class ImpEditEngine;
146 friend class EditSelFunctionSet;
148 public:
149 typedef std::vector<VclPtr<vcl::Window>> OutWindowSet;
151 public: // Needed for Undo
152 ImpEditView* GetImpEditView() const { return pImpEditView.get(); }
153 ImpEditEngine* GetImpEditEngine() const;
155 private:
156 std::unique_ptr<ImpEditView>
157 pImpEditView;
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;
167 public:
168 EditView( EditEngine* pEng, vcl::Window* pWindow );
169 ~EditView();
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 );
192 void Invalidate();
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 );
242 void ReleaseMouse();
243 bool MouseMove( const MouseEvent& rMouseEvent );
244 bool Command(const CommandEvent& rCEvt);
246 void Cut();
247 void Copy();
248 void Paste();
249 void PasteSpecial();
251 void Undo();
252 void Redo();
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
342 matched.
344 @param bIsParaText
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)
351 4. en-US
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,
358 bool bIsParaText );
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: */