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 .
20 #ifndef INCLUDED_VCL_TEXTVIEW_HXX
21 #define INCLUDED_VCL_TEXTVIEW_HXX
23 #include <config_options.h>
24 #include <tools/gen.hxx>
25 #include <tools/lineend.hxx>
26 #include <tools/stream.hxx>
27 #include <vcl/dllapi.h>
28 #include <vcl/dndhelp.hxx>
29 #include <vcl/textdata.hxx>
30 #include <vcl/outdev.hxx>
38 namespace vcl
{ class Window
; }
40 namespace com::sun::star::datatransfer::clipboard
{
44 struct SearchOptions2
;
51 class UNLESS_MERGELIBS(VCL_DLLPUBLIC
) TETextDataObject final
: public css::datatransfer::XTransferable
,
52 public ::cppu::OWeakObject
57 SvMemoryStream maHTMLStream
;
60 explicit TETextDataObject( OUString aText
);
62 SvMemoryStream
& GetHTMLStream() { return maHTMLStream
; }
64 // css::uno::XInterface
65 css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
66 void SAL_CALL
acquire() noexcept override
{ OWeakObject::acquire(); }
67 void SAL_CALL
release() noexcept override
{ OWeakObject::release(); }
69 // css::datatransfer::XTransferable
70 css::uno::Any SAL_CALL
getTransferData( const css::datatransfer::DataFlavor
& aFlavor
) override
;
71 css::uno::Sequence
< css::datatransfer::DataFlavor
> SAL_CALL
getTransferDataFlavors( ) override
;
72 sal_Bool SAL_CALL
isDataFlavorSupported( const css::datatransfer::DataFlavor
& aFlavor
) override
;
76 class VCL_DLLPUBLIC TextView final
: public vcl::unohelper::DragAndDropClient
78 friend class TextEngine
;
79 friend class TextUndo
;
80 friend class TextUndoManager
;
81 friend class TextSelFunctionSet
;
83 std::unique_ptr
<ImpTextView
> mpImpl
;
85 TextView( const TextView
& ) = delete;
86 TextView
& operator=( const TextView
& ) = delete;
88 SAL_DLLPRIVATE
bool ImpIndentBlock( bool bRight
);
89 SAL_DLLPRIVATE
void ShowSelection();
90 SAL_DLLPRIVATE
void HideSelection();
91 SAL_DLLPRIVATE
void ShowSelection( const TextSelection
& rSel
);
92 SAL_DLLPRIVATE
void ImpShowHideSelection( const TextSelection
* pRange
= nullptr );
94 SAL_DLLPRIVATE TextSelection
const & ImpMoveCursor( const KeyEvent
& rKeyEvent
);
95 SAL_DLLPRIVATE TextPaM
ImpDelete( sal_uInt8 nMode
, sal_uInt8 nDelMode
);
96 SAL_DLLPRIVATE
bool IsInSelection( const TextPaM
& rPaM
) const;
98 SAL_DLLPRIVATE
void ImpPaint(vcl::RenderContext
& rRenderContext
, const Point
& rStartPos
, tools::Rectangle
const* pPaintArea
, TextSelection
const* pSelection
);
99 SAL_DLLPRIVATE
void ImpPaint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
);
100 SAL_DLLPRIVATE
void ImpShowCursor( bool bGotoCursor
, bool bForceVisCursor
, bool bEndKey
);
101 SAL_DLLPRIVATE
void ImpSetSelection( const TextSelection
& rSelection
);
102 SAL_DLLPRIVATE Point
ImpGetOutputStartPos( const Point
& rStartDocPos
) const;
104 SAL_DLLPRIVATE
void ImpHideDDCursor();
105 SAL_DLLPRIVATE
void ImpShowDDCursor();
107 SAL_DLLPRIVATE
bool ImplTruncateNewText( OUString
& rNewText
) const;
108 SAL_DLLPRIVATE
bool ImplCheckTextLen( std::u16string_view rNewText
) const;
111 SAL_DLLPRIVATE
virtual void dragGestureRecognized( const css::datatransfer::dnd::DragGestureEvent
& dge
) override
;
112 SAL_DLLPRIVATE
virtual void dragDropEnd( const css::datatransfer::dnd::DragSourceDropEvent
& dsde
) override
;
113 SAL_DLLPRIVATE
virtual void drop( const css::datatransfer::dnd::DropTargetDropEvent
& dtde
) override
;
114 SAL_DLLPRIVATE
virtual void dragEnter( const css::datatransfer::dnd::DropTargetDragEnterEvent
& dtdee
) override
;
115 SAL_DLLPRIVATE
virtual void dragExit( const css::datatransfer::dnd::DropTargetEvent
& dte
) override
;
116 SAL_DLLPRIVATE
virtual void dragOver( const css::datatransfer::dnd::DropTargetDragEvent
& dtde
) override
;
118 using DragAndDropClient::dragEnter
;
119 using DragAndDropClient::dragExit
;
120 using DragAndDropClient::dragOver
;
123 TextView( ExtTextEngine
* pEng
, vcl::Window
* pWindow
);
124 virtual ~TextView() override
;
126 TextEngine
* GetTextEngine() const;
127 vcl::Window
* GetWindow() const;
129 SAL_DLLPRIVATE
void Invalidate();
130 void Scroll( tools::Long nHorzScroll
, tools::Long nVertScroll
);
132 void ShowCursor( bool bGotoCursor
= true, bool bForceVisCursor
= true );
135 SAL_DLLPRIVATE
void EnableCursor( bool bEnable
);
136 SAL_DLLPRIVATE
bool IsCursorEnabled() const;
138 SAL_DLLPRIVATE
const TextSelection
& GetSelection() const;
139 TextSelection
& GetSelection();
140 void SetSelection( const TextSelection
& rNewSel
);
141 SAL_DLLPRIVATE
void SetSelection( const TextSelection
& rNewSel
, bool bGotoCursor
);
142 bool HasSelection() const;
144 OUString
GetSelected() const;
145 SAL_DLLPRIVATE OUString
GetSelected( LineEnd aSeparator
) const;
146 void DeleteSelected();
148 void InsertText( const OUString
& rNew
);
150 bool KeyInput( const KeyEvent
& rKeyEvent
);
151 void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
);
152 void MouseButtonUp( const MouseEvent
& rMouseEvent
);
153 void MouseButtonDown( const MouseEvent
& rMouseEvent
);
154 void MouseMove( const MouseEvent
& rMouseEvent
);
155 void Command( const CommandEvent
& rCEvt
);
161 SAL_DLLPRIVATE
void Copy( css::uno::Reference
< css::datatransfer::clipboard::XClipboard
> const & rxClipboard
);
162 SAL_DLLPRIVATE
void Paste( css::uno::Reference
< css::datatransfer::clipboard::XClipboard
> const & rxClipboard
);
167 void Read( SvStream
& rInput
);
169 void SetStartDocPos( const Point
& rPos
);
170 const Point
& GetStartDocPos() const;
172 Point
GetDocPos( const Point
& rWindowPos
) const;
173 Point
GetWindowPos( const Point
& rDocPos
) const;
175 SAL_DLLPRIVATE
void SetInsertMode( bool bInsert
);
176 bool IsInsertMode() const;
178 void SetAutoIndentMode( bool bAutoIndent
);
180 void SetReadOnly( bool bReadOnly
);
181 bool IsReadOnly() const;
183 void SetAutoScroll( bool bAutoScroll
);
184 SAL_DLLPRIVATE
bool IsAutoScroll() const;
186 SAL_DLLPRIVATE
void SetCursorAtPoint( const Point
& rPointPixel
);
187 SAL_DLLPRIVATE
bool IsSelectionAtPoint( const Point
& rPointPixel
);
189 SAL_DLLPRIVATE
void SetPaintSelection( bool bPaint
);
191 // Moved in here from the protected part.
192 // For 'SvtXECTextCursor' (TL). Possibly needs to be solved again differently.
193 SAL_DLLPRIVATE TextPaM
PageUp( const TextPaM
& rPaM
);
194 SAL_DLLPRIVATE TextPaM
PageDown( const TextPaM
& rPaM
);
195 SAL_DLLPRIVATE TextPaM
CursorUp( const TextPaM
& rPaM
);
196 SAL_DLLPRIVATE TextPaM
CursorDown( const TextPaM
& rPaM
);
197 SAL_DLLPRIVATE TextPaM
CursorLeft( const TextPaM
& rPaM
, sal_uInt16 nCharacterIteratorMode
);
198 SAL_DLLPRIVATE TextPaM
CursorRight( const TextPaM
& rPaM
, sal_uInt16 nCharacterIteratorMode
);
199 SAL_DLLPRIVATE TextPaM
CursorFirstWord( const TextPaM
& rPaM
);
200 SAL_DLLPRIVATE TextPaM
CursorWordLeft( const TextPaM
& rPaM
);
201 SAL_DLLPRIVATE TextPaM
CursorWordRight( const TextPaM
& rPaM
);
202 SAL_DLLPRIVATE TextPaM
CursorStartOfLine( const TextPaM
& rPaM
);
203 TextPaM
CursorEndOfLine( const TextPaM
& rPaM
);
204 SAL_DLLPRIVATE
static TextPaM
CursorStartOfParagraph( const TextPaM
& rPaM
);
205 SAL_DLLPRIVATE TextPaM
CursorEndOfParagraph( const TextPaM
& rPaM
);
206 SAL_DLLPRIVATE
static TextPaM
CursorStartOfDoc();
207 SAL_DLLPRIVATE TextPaM
CursorEndOfDoc();
210 Returns the number in paragraph of the line in which the cursor is blinking
211 if enabled, -1 otherwise.
213 sal_Int32
GetLineNumberOfCursorInSelection() const;
217 // tdf#49482: Moves the start of the PaM to the center of the textview
218 SAL_DLLPRIVATE
void CenterPaM( const TextPaM
& rPaM
);
220 bool Search( const i18nutil::SearchOptions2
& rSearchOptions
, bool bForward
);
221 sal_uInt16
Replace( const i18nutil::SearchOptions2
& rSearchOptions
, bool bAll
, bool bForward
);
224 bool UnindentBlock();
226 // Used in the Basic IDE to toggle comment on a block of code
227 void ToggleComment();
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */