/src/libreoffice/include/vcl/textview.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 | | |
20 | | #ifndef INCLUDED_VCL_TEXTVIEW_HXX |
21 | | #define INCLUDED_VCL_TEXTVIEW_HXX |
22 | | |
23 | | #include <config_options.h> |
24 | | #include <o3tl/deleter.hxx> |
25 | | #include <tools/gen.hxx> |
26 | | #include <tools/lineend.hxx> |
27 | | #include <tools/stream.hxx> |
28 | | #include <vcl/cursor.hxx> |
29 | | #include <vcl/dllapi.h> |
30 | | #include <vcl/dndhelp.hxx> |
31 | | #include <vcl/seleng.hxx> |
32 | | #include <vcl/textdata.hxx> |
33 | | #include <vcl/outdev.hxx> |
34 | | #include <memory> |
35 | | |
36 | | class TextEngine; |
37 | | |
38 | | class KeyEvent; |
39 | | class MouseEvent; |
40 | | class CommandEvent; |
41 | | namespace vcl { class Window; } |
42 | | |
43 | | namespace com::sun::star::datatransfer::clipboard { |
44 | | class XClipboard; |
45 | | } |
46 | | namespace i18nutil { |
47 | | struct SearchOptions2; |
48 | | } |
49 | | |
50 | | class ExtTextEngine; |
51 | | class TextSelFunctionSet; |
52 | | struct TextDDInfo; |
53 | | |
54 | | class UNLESS_MERGELIBS(VCL_DLLPUBLIC) TETextDataObject final : public css::datatransfer::XTransferable, |
55 | | public ::cppu::OWeakObject |
56 | | |
57 | | { |
58 | | private: |
59 | | OUString maText; |
60 | | SvMemoryStream maHTMLStream; |
61 | | |
62 | | public: |
63 | | explicit TETextDataObject( OUString aText ); |
64 | | |
65 | 0 | SvMemoryStream& GetHTMLStream() { return maHTMLStream; } |
66 | | |
67 | | // css::uno::XInterface |
68 | | css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; |
69 | 0 | void SAL_CALL acquire() noexcept override { OWeakObject::acquire(); } |
70 | 0 | void SAL_CALL release() noexcept override { OWeakObject::release(); } |
71 | | |
72 | | // css::datatransfer::XTransferable |
73 | | css::uno::Any SAL_CALL getTransferData( const css::datatransfer::DataFlavor& aFlavor ) override; |
74 | | css::uno::Sequence< css::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors( ) override; |
75 | | sal_Bool SAL_CALL isDataFlavorSupported( const css::datatransfer::DataFlavor& aFlavor ) override; |
76 | | }; |
77 | | |
78 | | |
79 | | class VCL_DLLPUBLIC TextView final : public vcl::unohelper::DragAndDropClient |
80 | | { |
81 | | friend class TextEngine; |
82 | | friend class TextUndo; |
83 | | friend class TextUndoManager; |
84 | | friend class TextSelFunctionSet; |
85 | | |
86 | | ExtTextEngine* mpTextEngine; |
87 | | |
88 | | VclPtr<vcl::Window> mpWindow; |
89 | | TextSelection maSelection; |
90 | | Point maStartDocPos; |
91 | | |
92 | | std::unique_ptr<vcl::Cursor, o3tl::default_delete<vcl::Cursor>> mpCursor; |
93 | | |
94 | | std::unique_ptr<TextDDInfo, o3tl::default_delete<TextDDInfo>> mpDDInfo; |
95 | | |
96 | | std::unique_ptr<SelectionEngine> mpSelEngine; |
97 | | std::unique_ptr<TextSelFunctionSet> mpSelFuncSet; |
98 | | |
99 | | rtl::Reference<vcl::unohelper::DragAndDropWrapper> mxDnDListener; |
100 | | |
101 | | sal_uInt16 mnTravelXPos; |
102 | | |
103 | | bool mbAutoScroll : 1; |
104 | | bool mbInsertMode : 1; |
105 | | bool mbReadOnly : 1; |
106 | | bool mbPaintSelection : 1; |
107 | | bool mbAutoIndent : 1; |
108 | | bool mbCursorEnabled : 1; |
109 | | bool mbClickedInSelection : 1; |
110 | | bool mbCursorAtEndOfLine; |
111 | | |
112 | | TextView(const TextView&) = delete; |
113 | | TextView& operator=( const TextView& ) = delete; |
114 | | |
115 | | SAL_DLLPRIVATE bool ImpIndentBlock( bool bRight ); |
116 | | SAL_DLLPRIVATE void ShowSelection(); |
117 | | SAL_DLLPRIVATE void HideSelection(); |
118 | | SAL_DLLPRIVATE void ShowSelection( const TextSelection& rSel ); |
119 | | SAL_DLLPRIVATE void ImpShowHideSelection( const TextSelection* pRange = nullptr ); |
120 | | |
121 | | SAL_DLLPRIVATE TextSelection const & ImpMoveCursor( const KeyEvent& rKeyEvent ); |
122 | | SAL_DLLPRIVATE TextPaM ImpDelete( sal_uInt8 nMode, sal_uInt8 nDelMode ); |
123 | | SAL_DLLPRIVATE bool IsInSelection( const TextPaM& rPaM ) const; |
124 | | |
125 | | SAL_DLLPRIVATE void ImpPaint(vcl::RenderContext& rRenderContext, const Point& rStartPos, tools::Rectangle const* pPaintArea, TextSelection const* pSelection); |
126 | | SAL_DLLPRIVATE void ImpPaint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect); |
127 | | SAL_DLLPRIVATE void ImpShowCursor( bool bGotoCursor, bool bForceVisCursor, bool bEndKey ); |
128 | | SAL_DLLPRIVATE void ImpSetSelection( const TextSelection& rSelection ); |
129 | | SAL_DLLPRIVATE Point ImpGetOutputStartPos( const Point& rStartDocPos ) const; |
130 | | |
131 | | SAL_DLLPRIVATE void ImpHideDDCursor(); |
132 | | SAL_DLLPRIVATE void ImpShowDDCursor(); |
133 | | |
134 | | SAL_DLLPRIVATE bool ImplTruncateNewText( OUString& rNewText ) const; |
135 | | SAL_DLLPRIVATE bool ImplCheckTextLen( std::u16string_view rNewText ) const; |
136 | | |
137 | | // DragAndDropClient |
138 | | SAL_DLLPRIVATE virtual void dragGestureRecognized( const css::datatransfer::dnd::DragGestureEvent& dge ) override; |
139 | | SAL_DLLPRIVATE virtual void dragDropEnd( const css::datatransfer::dnd::DragSourceDropEvent& dsde ) override; |
140 | | SAL_DLLPRIVATE virtual void drop( const css::datatransfer::dnd::DropTargetDropEvent& dtde ) override; |
141 | | SAL_DLLPRIVATE virtual void dragEnter( const css::datatransfer::dnd::DropTargetDragEnterEvent& dtdee ) override; |
142 | | SAL_DLLPRIVATE virtual void dragExit( const css::datatransfer::dnd::DropTargetEvent& dte ) override; |
143 | | SAL_DLLPRIVATE virtual void dragOver( const css::datatransfer::dnd::DropTargetDragEvent& dtde ) override; |
144 | | |
145 | | using DragAndDropClient::dragEnter; |
146 | | using DragAndDropClient::dragExit; |
147 | | using DragAndDropClient::dragOver; |
148 | | |
149 | | public: |
150 | | TextView( ExtTextEngine* pEng, vcl::Window* pWindow ); |
151 | | virtual ~TextView() override; |
152 | | |
153 | | TextEngine* GetTextEngine() const; |
154 | | vcl::Window* GetWindow() const; |
155 | | |
156 | | SAL_DLLPRIVATE void Invalidate(); |
157 | | void Scroll( tools::Long nHorzScroll, tools::Long nVertScroll ); |
158 | | |
159 | | void ShowCursor( bool bGotoCursor = true, bool bForceVisCursor = true ); |
160 | | void HideCursor(); |
161 | | |
162 | | SAL_DLLPRIVATE void EnableCursor( bool bEnable ); |
163 | | SAL_DLLPRIVATE bool IsCursorEnabled() const; |
164 | | |
165 | | SAL_DLLPRIVATE const TextSelection& GetSelection() const; |
166 | | TextSelection& GetSelection(); |
167 | | void SetSelection( const TextSelection& rNewSel ); |
168 | | SAL_DLLPRIVATE void SetSelection( const TextSelection& rNewSel, bool bGotoCursor ); |
169 | | bool HasSelection() const; |
170 | | |
171 | | OUString GetSelected() const; |
172 | | SAL_DLLPRIVATE OUString GetSelected( LineEnd aSeparator ) const; |
173 | | void DeleteSelected(); |
174 | | |
175 | | void InsertText( const OUString& rNew ); |
176 | | |
177 | | bool KeyInput( const KeyEvent& rKeyEvent ); |
178 | | void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect); |
179 | | void MouseButtonUp( const MouseEvent& rMouseEvent ); |
180 | | void MouseButtonDown( const MouseEvent& rMouseEvent ); |
181 | | void MouseMove( const MouseEvent& rMouseEvent ); |
182 | | void Command( const CommandEvent& rCEvt ); |
183 | | |
184 | | void Cut(); |
185 | | void Copy(); |
186 | | void Paste(); |
187 | | |
188 | | SAL_DLLPRIVATE void Copy( css::uno::Reference< css::datatransfer::clipboard::XClipboard > const & rxClipboard ); |
189 | | SAL_DLLPRIVATE void Paste( css::uno::Reference< css::datatransfer::clipboard::XClipboard > const & rxClipboard ); |
190 | | |
191 | | void Undo(); |
192 | | void Redo(); |
193 | | |
194 | | void Read( SvStream& rInput ); |
195 | | |
196 | | void SetStartDocPos( const Point& rPos ); |
197 | | const Point& GetStartDocPos() const; |
198 | | |
199 | | Point GetDocPos( const Point& rWindowPos ) const; |
200 | | Point GetWindowPos( const Point& rDocPos ) const; |
201 | | |
202 | | SAL_DLLPRIVATE void SetInsertMode( bool bInsert ); |
203 | | bool IsInsertMode() const; |
204 | | |
205 | | void SetAutoIndentMode( bool bAutoIndent ); |
206 | | |
207 | | void SetReadOnly( bool bReadOnly ); |
208 | | bool IsReadOnly() const; |
209 | | |
210 | | void SetAutoScroll( bool bAutoScroll ); |
211 | | SAL_DLLPRIVATE bool IsAutoScroll() const; |
212 | | |
213 | | SAL_DLLPRIVATE void SetCursorAtPoint( const Point& rPointPixel ); |
214 | | SAL_DLLPRIVATE bool IsSelectionAtPoint( const Point& rPointPixel ); |
215 | | |
216 | | SAL_DLLPRIVATE void SetPaintSelection( bool bPaint); |
217 | | |
218 | | // Moved in here from the protected part. |
219 | | // For 'SvtXECTextCursor' (TL). Possibly needs to be solved again differently. |
220 | | SAL_DLLPRIVATE TextPaM PageUp( const TextPaM& rPaM ); |
221 | | SAL_DLLPRIVATE TextPaM PageDown( const TextPaM& rPaM ); |
222 | | SAL_DLLPRIVATE TextPaM CursorUp( const TextPaM& rPaM ); |
223 | | SAL_DLLPRIVATE TextPaM CursorDown( const TextPaM& rPaM ); |
224 | | SAL_DLLPRIVATE TextPaM CursorLeft( const TextPaM& rPaM, sal_uInt16 nCharacterIteratorMode ); |
225 | | SAL_DLLPRIVATE TextPaM CursorRight( const TextPaM& rPaM, sal_uInt16 nCharacterIteratorMode ); |
226 | | SAL_DLLPRIVATE TextPaM CursorFirstWord( const TextPaM& rPaM ); |
227 | | SAL_DLLPRIVATE TextPaM CursorWordLeft( const TextPaM& rPaM ); |
228 | | SAL_DLLPRIVATE TextPaM CursorWordRight( const TextPaM& rPaM ); |
229 | | SAL_DLLPRIVATE TextPaM CursorStartOfLine( const TextPaM& rPaM ); |
230 | | TextPaM CursorEndOfLine( const TextPaM& rPaM ); |
231 | | SAL_DLLPRIVATE static TextPaM CursorStartOfParagraph( const TextPaM& rPaM ); |
232 | | SAL_DLLPRIVATE TextPaM CursorEndOfParagraph( const TextPaM& rPaM ); |
233 | | SAL_DLLPRIVATE static TextPaM CursorStartOfDoc(); |
234 | | SAL_DLLPRIVATE TextPaM CursorEndOfDoc(); |
235 | | |
236 | | /** |
237 | | Returns the number in paragraph of the line in which the cursor is blinking |
238 | | if enabled, -1 otherwise. |
239 | | */ |
240 | | sal_Int32 GetLineNumberOfCursorInSelection() const; |
241 | | |
242 | | void MatchGroup(); |
243 | | |
244 | | // tdf#49482: Moves the start of the PaM to the center of the textview |
245 | | SAL_DLLPRIVATE void CenterPaM( const TextPaM& rPaM ); |
246 | | |
247 | | bool Search( const i18nutil::SearchOptions2& rSearchOptions, bool bForward ); |
248 | | sal_uInt16 Replace( const i18nutil::SearchOptions2& rSearchOptions, bool bAll, bool bForward ); |
249 | | |
250 | | bool IndentBlock(); |
251 | | bool UnindentBlock(); |
252 | | |
253 | | // Used in the Basic IDE to toggle comment on a block of code |
254 | | void ToggleComment(); |
255 | | }; |
256 | | |
257 | | #endif |
258 | | |
259 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |