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