KTextEditor

katetextcursor.h
1 /* SPDX-License-Identifier: LGPL-2.0-or-later
2 
3  Copyright (C) 2010 Christoph Cullmann <[email protected]>
4 
5  Based on code of the SmartCursor/Range by:
6  Copyright (C) 2003-2005 Hamish Rodda <[email protected]>
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 */
23 
24 #ifndef KATE_TEXTCURSOR_H
25 #define KATE_TEXTCURSOR_H
26 
27 #include <ktexteditor/movingcursor.h>
28 
29 #include "katetextblock.h"
30 #include <ktexteditor_export.h>
31 
32 namespace Kate
33 {
34 class TextBuffer;
35 class TextBlock;
36 class TextRange;
37 
43 class KTEXTEDITOR_EXPORT TextCursor : public KTextEditor::MovingCursor
44 {
45  // range wants direct access to some internals
46  friend class TextRange;
47 
48  // this is a friend, because this is needed to efficiently transfer cursors from on to an other block
49  friend class TextBlock;
50 
51 private:
59  TextCursor(TextBuffer &buffer, TextRange *range, const KTextEditor::Cursor &position, InsertBehavior insertBehavior);
60 
61 public:
68  TextCursor(TextBuffer &buffer, const KTextEditor::Cursor &position, InsertBehavior insertBehavior);
69 
73  ~TextCursor() override;
74 
79  void setInsertBehavior(InsertBehavior insertBehavior) override
80  {
81  m_moveOnInsert = insertBehavior == MoveOnInsert;
82  }
83 
88  InsertBehavior insertBehavior() const override
89  {
90  return m_moveOnInsert ? MoveOnInsert : StayOnInsert;
91  }
92 
97  KTextEditor::Document *document() const override;
98 
104  void setPosition(const TextCursor &position);
105 
111  void setPosition(const KTextEditor::Cursor &position) override;
112 
121  void setPosition(int line, int column)
122  {
124  }
125 
130  int line() const override;
131 
137  int lineInternal() const
138  {
139  // invalid cursor have no block
140  if (!m_block) {
141  return -1;
142  }
143 
144  // else, calculate real line
145  return m_block->startLine() + m_line;
146  }
147 
152  int column() const override
153  {
154  return m_column;
155  }
156 
161  int columnInternal() const
162  {
163  return m_column;
164  }
165 
170  KTextEditor::MovingRange *range() const override;
171 
177  {
178  return m_range;
179  }
180 
185  TextBlock *block() const
186  {
187  return m_block;
188  }
189 
194  int lineInBlock() const
195  {
196  if (m_block) {
197  return m_line;
198  }
199  return -1;
200  }
201 
202 private:
206  TextCursor(const TextCursor &);
207 
211  TextCursor &operator=(const TextCursor &);
212 
221  void setPosition(const KTextEditor::Cursor &position, bool init);
222 
223 private:
228  TextBuffer &m_buffer;
229 
235  TextRange *const m_range;
236 
240  TextBlock *m_block;
241 
245  int m_line;
246 
250  int m_column;
251 
255  bool m_moveOnInsert;
256 };
257 
258 }
259 
260 #endif
void setPosition(int line, int column)
This is an overloaded member function, provided for convenience. It differs from the above function o...
TextBlock * block() const
Get block this cursor belongs to, if any.
A Cursor which is bound to a specific Document, and maintains its position.
Definition: movingcursor.h:68
A range that is bound to a specific Document, and maintains its position.
Definition: movingrange.h:157
int lineInternal() const
Non-virtual version of line(), which is faster.
The Cursor represents a position in a Document.
Definition: cursor.h:85
InsertBehavior
Insert behavior of this cursor, should it stay if text is insert at its position or should it move...
Definition: movingcursor.h:78
A KParts derived class representing a text document.
Definition: document.h:199
int lineInBlock() const
Get offset into block this cursor belongs to, if any.
InsertBehavior insertBehavior() const override
Get current insert behavior.
QCA_EXPORT void init()
Kate::TextRange * kateRange() const
Get range this cursor belongs to, if any.
Class representing a &#39;clever&#39; text cursor.
int column() const override
Retrieve the column on which this cursor is situated.
void setInsertBehavior(InsertBehavior insertBehavior) override
Set insert behavior.
Class representing a text buffer.
virtual void setPosition(const KTextEditor::Cursor &position)=0
Set the current cursor position to position.
int columnInternal() const
Non-virtual version of column(), which is faster.
Class representing a &#39;clever&#39; text range.
Definition: katetextrange.h:46
Class representing a text block.
Definition: katetextblock.h:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Aug 9 2020 23:00:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.