tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / include / editeng / editview.hxx
blob9672506dc9a42fb71ff58c806a06916ea9cd7f06
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 <sot/formats.hxx>
28 #include <tools/color.hxx>
29 #include <tools/gen.hxx>
30 #include <comphelper/errcode.hxx>
31 #include <vcl/vclptr.hxx>
32 #include <editeng/editstat.hxx>
33 #include <editeng/flditem.hxx>
34 #include <svl/languageoptions.hxx>
35 #include <editeng/editdata.hxx>
36 #include <com/sun/star/uno/Reference.h>
37 #include <editeng/editengdllapi.h>
40 class EditTextObject;
41 class EditEngine;
42 class ImpEditEngine;
43 class ImpEditView;
44 class OutlinerViewShell;
45 class SvxSearchItem;
46 class SvxFieldItem;
47 namespace vcl { class Window; }
48 namespace weld { class Widget; }
49 class KeyEvent;
50 class MouseEvent;
51 class CommandEvent;
52 class SvStream;
53 class SvKeyValueIterator;
54 class SfxStyleSheet;
55 class SfxItemSet;
56 namespace vcl { class Cursor; }
57 namespace vcl { class Font; }
58 class FontList;
59 class InputContext;
60 class OutputDevice;
61 enum class TransliterationFlags;
62 enum class PointerStyle;
64 namespace com {
65 namespace sun {
66 namespace star {
67 namespace datatransfer {
68 class XTransferable;
69 namespace clipboard {
70 class XClipboard;
72 namespace dnd {
73 class XDropTarget;
76 namespace linguistic2 {
77 class XSpellChecker1;
78 class XLanguageGuessing;
80 }}}
82 template <typename Arg, typename Ret> class Link;
84 enum class ScrollRangeCheck
86 NoNegative = 1, // No negative VisArea when scrolling
87 PaperWidthTextSize = 2, // VisArea must be within paper width, Text Size
90 enum class LOKSpecialFlags {
91 NONE = 0x0000,
92 LayoutRTL = 0x0001,
95 namespace o3tl
97 template<> struct typed_flags<LOKSpecialFlags> : is_typed_flags<LOKSpecialFlags, 0x77> {};
100 // Helper class that allows to set a callback at the EditView. When
101 // set, Invalidates and repaints are suppressed at the EditView, but
102 // EditViewInvalidate() will be triggered to allow the consumer to
103 // react itself as needed.
104 // Also Selection visualization is suppressed and EditViewSelectionChange
105 // is triggered when Selection changes and needs reaction.
106 class EDITENG_DLLPUBLIC EditViewCallbacks
108 public:
109 virtual ~EditViewCallbacks();
111 // call this when text visualization changed in any way. It
112 // will also update selection, so no need to call this self
113 // additionally (but will also do no harm)
114 virtual void EditViewInvalidate(const tools::Rectangle& rRect) = 0;
116 // call this when only selection is changed. Text change will
117 // then *not* be checked and not be reacted on. Still, when
118 // only the selection is changed, this is useful and faster
119 virtual void EditViewSelectionChange() = 0;
121 // return the OutputDevice that the EditView will draw to
122 virtual OutputDevice& EditViewOutputDevice() const = 0;
124 virtual weld::Widget* EditViewPopupParent() const
126 return nullptr;
129 // return the Mouse Position
130 virtual Point EditViewPointerPosPixel() const = 0;
132 // Triggered to update InputEngine context information
133 virtual void EditViewInputContext(const InputContext& rInputContext) = 0;
135 // Triggered to update InputEngine cursor position
136 virtual void EditViewCursorRect(const tools::Rectangle& rRect, int nExtTextInputWidth) = 0;
138 // Triggered if scroll bar state should change
139 virtual void EditViewScrollStateChange()
143 // Access to clipboard
144 virtual css::uno::Reference<css::datatransfer::clipboard::XClipboard> GetClipboard() const = 0;
146 // implemented if drag and drop support is wanted
147 virtual css::uno::Reference<css::datatransfer::dnd::XDropTarget> GetDropTarget()
149 return nullptr;
153 class EDITENG_DLLPUBLIC EditView final
155 friend class EditEngine;
156 friend class ImpEditEngine;
157 friend class EditSelFunctionSet;
159 public:
160 typedef std::vector<VclPtr<vcl::Window>> OutWindowSet;
162 ImpEditView& getImpl() const { return *mpImpEditView; }
163 SAL_DLLPRIVATE ImpEditEngine& getImpEditEngine() const;
165 void setEditEngine(EditEngine* pEditEngine);
166 EditEngine& getEditEngine() const;
168 private:
169 std::unique_ptr<ImpEditView> mpImpEditView;
170 OUString aDicNameSingle;
172 EditView( const EditView& ) = delete;
173 EditView& operator=( const EditView& ) = delete;
175 // counts how many characters take unfolded fields
176 // bCanOverflow - count field length without trim to the selected pos
177 SAL_DLLPRIVATE sal_Int32 countFieldsOffsetSum(sal_Int32 nPara, sal_Int32 nPo, bool bCanOverflow) const;
179 public:
180 EditView( EditEngine* pEng, vcl::Window* pWindow );
181 ~EditView();
183 // set EditViewCallbacks for external handling of Repaints/Visualization
184 void setEditViewCallbacks(EditViewCallbacks* pEditViewCallbacks);
185 EditViewCallbacks* getEditViewCallbacks() const;
187 void SetWindow( vcl::Window* pWin );
188 vcl::Window* GetWindow() const;
189 OutputDevice& GetOutputDevice() const;
191 LanguageType GetInputLanguage() const;
193 SAL_DLLPRIVATE bool HasOtherViewWindow( vcl::Window* pWin );
194 bool AddOtherViewWindow( vcl::Window* pWin );
195 bool RemoveOtherViewWindow( vcl::Window* pWin );
197 void Paint( const tools::Rectangle& rRect, OutputDevice* pTargetDevice = nullptr );
198 tools::Rectangle GetInvalidateRect() const;
199 SAL_DLLPRIVATE void InvalidateWindow(const tools::Rectangle& rClipRect);
200 void InvalidateOtherViewWindows( const tools::Rectangle& rInvRect );
201 void Invalidate();
202 ::Pair Scroll( tools::Long nHorzScroll, tools::Long nVertScroll, ScrollRangeCheck nRangeCheck = ScrollRangeCheck::NoNegative );
204 void SetBroadcastLOKViewCursor(bool bSet);
205 tools::Rectangle GetEditCursor() const;
206 void ShowCursor( bool bGotoCursor = true, bool bForceVisCursor = true, bool bActivate = false );
207 void HideCursor( bool bDeactivate = false );
208 bool IsCursorVisible() const;
210 void SetSelectionMode( EESelectionMode eMode );
212 void SetReadOnly( bool bReadOnly );
213 bool IsReadOnly() const;
215 bool HasSelection() const;
216 ESelection GetSelection() const;
217 void SetSelection( const ESelection& rNewSel );
218 bool IsSelectionAtPoint(const Point& rPointPixel);
219 void SelectCurrentWord( sal_Int16 nWordType = css::i18n::WordType::ANYWORD_IGNOREWHITESPACES );
220 /// Returns the rectangles of the current selection in TWIPs.
221 void GetSelectionRectangles(std::vector<tools::Rectangle>& rLogicRects) const;
222 bool IsSelectionFullPara() const;
223 bool IsSelectionWithinSinglePara() const;
225 bool IsInsertMode() const;
226 void SetInsertMode( bool bInsert );
228 OUString GetSelected() const;
229 void DeleteSelected();
231 SvtScriptType GetSelectedScriptType() const;
233 // VisArea position of the Output window.
234 // A size change also affects the VisArea
235 void SetOutputArea( const tools::Rectangle& rRect );
236 const tools::Rectangle& GetOutputArea() const;
238 // Document position.
239 // A size change also affects the VisArea
240 void SetVisArea( const tools::Rectangle& rRect );
241 tools::Rectangle GetVisArea() const;
243 PointerStyle GetPointer() const;
245 vcl::Cursor* GetCursor() const;
247 void InsertText( const OUString& rNew, bool bSelect = false , bool bLOKShowSelect = true);
248 void InsertParaBreak();
250 bool PostKeyEvent( const KeyEvent& rKeyEvent, vcl::Window const * pFrameWin = nullptr );
252 bool MouseButtonUp( const MouseEvent& rMouseEvent );
253 bool MouseButtonDown( const MouseEvent& rMouseEvent );
254 SAL_DLLPRIVATE void ReleaseMouse();
255 bool MouseMove( const MouseEvent& rMouseEvent );
256 bool Command(const CommandEvent& rCEvt);
258 void Cut();
259 void Copy();
260 void Paste();
261 void PasteSpecial(SotClipboardFormatId format = SotClipboardFormatId::NONE);
263 void Undo();
264 void Redo();
266 // especially for Oliver Specht
267 Point GetWindowPosTopLeft( sal_Int32 nParagraph );
268 SAL_DLLPRIVATE void MoveParagraphs( Range aParagraphs, sal_Int32 nNewPos );
269 SAL_DLLPRIVATE void MoveParagraphs( tools::Long nDiff );
271 const SfxItemSet& GetEmptyItemSet() const;
272 SfxItemSet GetAttribs();
273 void SetAttribs( const SfxItemSet& rSet );
274 void RemoveAttribs( bool bRemoveParaAttribs = false, sal_uInt16 nWhich = 0 );
275 SAL_DLLPRIVATE void RemoveAttribs( EERemoveParaAttribsMode eMode, sal_uInt16 nWhich );
276 void RemoveCharAttribs( sal_Int32 nPara, sal_uInt16 nWhich );
277 void RemoveAttribsKeepLanguages( bool bRemoveParaAttribs );
279 SAL_DLLPRIVATE ErrCode Read( SvStream& rInput, EETextFormat eFormat, SvKeyValueIterator* pHTTPHeaderAttrs );
280 OString GetSimpleHtml() const;
282 void SetBackgroundColor( const Color& rColor );
283 Color const & GetBackgroundColor() const;
285 /// Informs this edit view about which view shell contains it.
286 void RegisterViewShell(OutlinerViewShell* pViewShell);
287 /// Informs this edit view about which other shell listens to it.
288 void RegisterOtherShell(OutlinerViewShell* pOtherShell);
290 void SetControlWord( EVControlBits nWord );
291 EVControlBits GetControlWord() const;
293 std::unique_ptr<EditTextObject> CreateTextObject();
294 void InsertText( const EditTextObject& rTextObject );
295 void InsertText( css::uno::Reference< css::datatransfer::XTransferable > const & xDataObj, const OUString& rBaseURL, bool bUseSpecial );
297 css::uno::Reference<css::datatransfer::clipboard::XClipboard> GetClipboard() const;
298 css::uno::Reference<css::datatransfer::XTransferable> GetTransferable() const;
300 // An EditView, so that when TRUE the update will be free from flickering:
301 // @return the previous bUpdateLayout state
302 bool SetEditEngineUpdateLayout( bool bUpdate );
303 void ForceLayoutCalculation();
305 SAL_DLLPRIVATE const SfxStyleSheet* GetStyleSheet() const;
306 SAL_DLLPRIVATE SfxStyleSheet* GetStyleSheet();
308 SAL_DLLPRIVATE void SetAnchorMode( EEAnchorMode eMode );
309 SAL_DLLPRIVATE EEAnchorMode GetAnchorMode() const;
311 void CompleteAutoCorrect( vcl::Window const * pFrameWin = nullptr );
313 EESpellState StartSpeller(weld::Widget* pDialogParent, bool bMultipleDoc = false);
314 EESpellState StartThesaurus(weld::Widget* pDialogParent);
315 SAL_DLLPRIVATE sal_Int32 StartSearchAndReplace( const SvxSearchItem& rSearchItem );
317 // for text conversion
318 void StartTextConversion(weld::Widget* pDialogParent, LanguageType nSrcLang, LanguageType nDestLang, const vcl::Font *pDestFont, sal_Int32 nOptions, bool bIsInteractive, bool bMultipleDoc);
320 void TransliterateText( TransliterationFlags nTransliterationMode );
322 SAL_DLLPRIVATE bool IsCursorAtWrongSpelledWord();
323 bool IsWrongSpelledWordAtPos( const Point& rPosPixel, bool bMarkIfWrong = false );
324 bool ExecuteSpellPopup(const Point& rPosPixel, const Link<SpellCallbackInfo&,void>& rCallBack);
325 OUString SpellIgnoreWord();
327 void InsertField( const SvxFieldItem& rFld );
328 const SvxFieldItem* GetFieldUnderMousePointer() const;
329 SAL_DLLPRIVATE const SvxFieldItem* GetFieldUnderMousePointer( sal_Int32& nPara, sal_Int32& nPos ) const;
330 const SvxFieldItem* GetField( const Point& rPos, sal_Int32* pnPara = nullptr, sal_Int32* pnPos = nullptr ) const;
332 /// return the selected field or the field immediately after (or before) the current cursor
333 const SvxFieldItem* GetFieldAtSelection(bool bAlsoCheckBeforeCursor = false) const;
334 SAL_DLLPRIVATE const SvxFieldItem* GetFieldAtSelection(bool* pIsBeforeCursor) const;
336 /// return field under mouse, at selection, or immediately after (or before) the current cursor
337 const SvxFieldData* GetFieldUnderMouseOrInSelectionOrAtCursor(bool bAlsoCheckBeforeCursor = false) const;
338 /// if no selection, select the field immediately after or before the current cursor
339 void SelectFieldAtCursor();
340 /// Converts position in paragraph to logical position without unfolding fields
341 sal_Int32 GetPosNoField(sal_Int32 nPara, sal_Int32 nPos) const;
342 /// Converts logical position in paragraph to position with unfolded fields
343 sal_Int32 GetPosWithField(sal_Int32 nPara, sal_Int32 nPos) const;
345 SAL_DLLPRIVATE void SetInvalidateMore( sal_uInt16 nPixel );
346 SAL_DLLPRIVATE sal_uInt16 GetInvalidateMore() const;
348 // grows or shrinks the font height for the current selection
349 void ChangeFontSize( bool bGrow, const FontList* pList );
351 static bool ChangeFontSize( bool bGrow, SfxItemSet& rSet, const FontList* pFontList );
353 OUString GetSurroundingText() const;
354 Selection GetSurroundingTextSelection() const;
355 bool DeleteSurroundingText(const Selection& rRange);
357 /** Tries to determine the language of 'rText', returning a matching known
358 locale if possible, or a fallback, or LANGUAGE_NONE if nothing found or
359 matched.
361 @param bIsParaText
362 If TRUE, rText is a paragraph and the language is obtained by
363 passing the text to xLangGuess.
364 IF FALSE, a language match is tried for, in order,
365 1. the default document language (non-CTL, non-CJK, aka LATIN)
366 2. the UI language (Tools->Options->LanguageSettings->Languages User Interface)
367 3. the locale (Tools->Options->LanguageSettings->Languages Locale)
368 4. en-US
369 If nothing matched, LANGUAGE_NONE is returned.
371 static LanguageType CheckLanguage(
372 const OUString &rText,
373 const css::uno::Reference< css::linguistic2::XSpellChecker1 >& xSpell,
374 const css::uno::Reference< css::linguistic2::XLanguageGuessing >& xLangGuess,
375 bool bIsParaText );
376 /// Allows adjusting the point or mark of the selection to a document coordinate.
377 void SetCursorLogicPosition(const Point& rPosition, bool bPoint, bool bClearMark);
378 /// Trigger selection drawing callback in pOtherShell based on our shell's selection state.
379 void DrawSelectionXOR(OutlinerViewShell* pOtherShell);
382 * This is meant for Calc(LOK), but there may be other use-cases.
383 * In Calc, all logical positions are computed by
384 * doing independent pixel-alignment for each cell's size. The *LOKSpecial* methods
385 * can be used to set/get the output-area and visible-area in real logical
386 * units. This enables EditView to send cursor/selection messages in
387 * real logical units like it is done for Writer.
389 void InitLOKSpecialPositioning(MapUnit eUnit, const tools::Rectangle& rOutputArea,
390 const Point& rVisDocStartPos);
391 void SetLOKSpecialOutputArea(const tools::Rectangle& rOutputArea);
392 const tools::Rectangle & GetLOKSpecialOutputArea() const;
393 void SetLOKSpecialVisArea(const tools::Rectangle& rVisArea);
394 tools::Rectangle GetLOKSpecialVisArea() const;
395 bool HasLOKSpecialPositioning() const;
397 void SetLOKSpecialFlags(LOKSpecialFlags eFlags);
399 void SuppressLOKMessages(bool bSet);
400 bool IsSuppressLOKMessages() const;
402 /// To inform editeng that negated x document coordinates are in use.
403 void SetNegativeX(bool bSet);
404 bool IsNegativeX() const;
407 #endif // INCLUDED_EDITENG_EDITVIEW_HXX
409 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */