• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

KTextEditor

  • kde-4.14
  • applications
  • kate
  • ktexteditor
cursor.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  Copyright (C) 2003-2005 Hamish Rodda <rodda@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "cursor.h"
21 
22 #include "range.h"
23 
24 using namespace KTextEditor;
25 
26 Cursor::Cursor( )
27  : m_line(0)
28  , m_column(0)
29  , m_range(0L)
30 {
31 }
32 
33 Cursor::Cursor( int _line, int _column )
34  : m_line(_line)
35  , m_column(_column)
36  , m_range(0L)
37 {
38 }
39 
40 Cursor::Cursor(const Cursor& copy)
41  : m_line(copy.line())
42  , m_column(copy.column())
43  , m_range(0L)
44 {
45 }
46 
47 bool Cursor::isValid() const
48 {
49  return m_line >= 0 && m_column >= 0;
50 }
51 
52 Cursor Cursor::invalid( )
53 {
54  return Cursor (-1,-1);
55 }
56 
57 Cursor Cursor::start()
58 {
59  return Cursor (0, 0);
60 }
61 
62 int Cursor::line() const
63 {
64  return m_line;
65 }
66 
67 void Cursor::setLine( int line )
68 {
69  if (line == this->line())
70  return;
71 
72  Cursor old = *this;
73 
74  m_line = line;
75 
76  cursorChangedDirectly(old);
77 }
78 
79 int Cursor::column() const
80 {
81  return m_column;
82 }
83 
84 void Cursor::setColumn( int column )
85 {
86  if (column == this->column())
87  return;
88 
89  Cursor old = *this;
90 
91  m_column = column;
92 
93  cursorChangedDirectly(old);
94 }
95 
96 void Cursor::setPosition( const Cursor & pos )
97 {
98  if (pos == *this)
99  return;
100 
101  Cursor old = *this;
102 
103  m_line = pos.line();
104  m_column = pos.column();
105 
106  cursorChangedDirectly(old);
107 }
108 
109 bool Cursor::isSmartCursor( ) const
110 {
111  return false;
112 }
113 
114 void Cursor::setPosition(int line, int column)
115 {
116  setPosition(Cursor(line, column));
117 }
118 
119 void Cursor::position (int &_line, int &_column) const
120 {
121  _line = line(); _column = column();
122 }
123 
124 Range* Cursor::range() const
125 {
126  return m_range;
127 }
128 
129 Cursor::~ Cursor( )
130 {
131 }
132 
133 void Cursor::setRange( Range * range )
134 {
135  m_range = range;
136 }
137 
138 void KTextEditor::Cursor::cursorChangedDirectly(const Cursor& from)
139 {
140  if (m_range) {
141  if (this == &m_range->start())
142  m_range->rangeChanged(this, Range(from, m_range->end()));
143  else
144  m_range->rangeChanged(this, Range(m_range->start(), from));
145  }
146 }
147 
148 bool KTextEditor::Cursor::atStartOfLine( ) const
149 {
150  return m_column == 0;
151 }
152 
153 bool KTextEditor::Cursor::atStartOfDocument( ) const
154 {
155  return line() == 0 && m_column == 0;
156 }
157 
158 SmartCursor * KTextEditor::Cursor::toSmartCursor( ) const
159 {
160  return 0L;
161 }
162 
163 // kate: space-indent on; indent-width 2; replace-tabs on;
KTextEditor::Cursor::atStartOfDocument
bool atStartOfDocument() const
Determine if this cursor is located at the start of a document.
Definition: cursor.cpp:153
KTextEditor::Cursor::m_range
Range * m_range
Definition: cursor.h:349
KTextEditor::Cursor::invalid
static Cursor invalid()
Returns an invalid cursor.
Definition: cursor.cpp:52
KTextEditor::Cursor::position
void position(int &line, int &column) const
Get both the line and column of the cursor position.
Definition: cursor.cpp:119
cursor.h
KTextEditor::Cursor::m_line
int m_line
Definition: cursor.h:334
KTextEditor::Cursor::start
static Cursor start()
Returns a cursor representing the start of any document - i.e., line 0, column 0. ...
Definition: cursor.cpp:57
KTextEditor::Cursor::setRange
virtual void setRange(Range *range)
Definition: cursor.cpp:133
KTextEditor::Cursor
An object which represents a position in a Document.
Definition: cursor.h:55
KTextEditor::Cursor::isSmartCursor
virtual bool isSmartCursor() const
Returns whether this cursor is a SmartCursor.
Definition: cursor.cpp:109
KTextEditor::Cursor::cursorChangedDirectly
void cursorChangedDirectly(const Cursor &from)
Definition: cursor.cpp:138
KTextEditor::Cursor::isValid
virtual bool isValid() const
Returns whether the current position of this cursor is a valid position (line + column must both be >...
Definition: cursor.cpp:47
KTextEditor::Cursor::range
Range * range() const
Returns the range that this cursor belongs to, if any.
Definition: cursor.cpp:124
range.h
KTextEditor::SmartCursor
A Cursor which is bound to a specific Document, and maintains its position.
Definition: smartcursor.h:65
KTextEditor::Cursor::~Cursor
virtual ~Cursor()
Virtual destructor.
Definition: cursor.cpp:129
KTextEditor::Range
An object representing a section of text, from one Cursor to another.
Definition: range.h:54
KTextEditor::Cursor::line
virtual int line() const
Retrieve the line on which this cursor is situated.
Definition: cursor.cpp:62
KTextEditor::Cursor::setLine
virtual void setLine(int line)
Set the cursor line to line.
Definition: cursor.cpp:67
KTextEditor::Cursor::setPosition
virtual void setPosition(const Cursor &position)
Set the current cursor position to position.
Definition: cursor.cpp:96
KTextEditor::Cursor::toSmartCursor
virtual SmartCursor * toSmartCursor() const
Returns this cursor as a SmartCursor, if it is one.
Definition: cursor.cpp:158
KTextEditor::Cursor::Cursor
Cursor()
The default constructor creates a cursor at position (0,0).
Definition: cursor.cpp:26
KTextEditor::Cursor::setColumn
virtual void setColumn(int column)
Set the cursor column to column.
Definition: cursor.cpp:84
KTextEditor::Cursor::column
int column() const
Retrieve the column on which this cursor is situated.
Definition: cursor.cpp:79
KTextEditor::Cursor::m_column
int m_column
Definition: cursor.h:341
KTextEditor::Cursor::atStartOfLine
bool atStartOfLine() const
Determine if this cursor is located at the start of a line.
Definition: cursor.cpp:148
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:48 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KTextEditor

Skip menu "KTextEditor"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal