• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kate
 

kate

  • kate
  • part
katecursor.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 2002 Christian Couder <christian@kdevelop.org>
3 Copyright (C) 2001, 2003 Christoph Cullmann <cullmann@kde.org>
4 Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
5 Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License version 2 as published by the Free Software Foundation.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#include "katecursor.h"
23
24#include "katedocument.h"
25#include "katetextline.h"
26
27//
28// KateDocCursor implementation
29//
30
31KateDocCursor::KateDocCursor(KateDocument *doc) : KateTextCursor(), m_doc(doc)
32{
33}
34
35KateDocCursor::KateDocCursor(int line, int col, KateDocument *doc)
36 : KateTextCursor(line, col), m_doc(doc)
37{
38}
39
40bool KateDocCursor::validPosition(uint line, uint col)
41{
42 return line < m_doc->numLines() && (int)col <= m_doc->lineLength(line);
43}
44
45bool KateDocCursor::validPosition()
46{
47 return validPosition(line(), col());
48}
49
50void KateDocCursor::position(uint *pline, uint *pcol) const
51{
52 if (pline)
53 *pline = (uint)line();
54
55 if (pcol)
56 *pcol = (uint)col();
57}
58
59bool KateDocCursor::setPosition(uint line, uint col)
60{
61 bool ok = validPosition(line, col);
62
63 if(ok)
64 setPos(line, col);
65
66 return ok;
67}
68
69bool KateDocCursor::gotoNextLine()
70{
71 bool ok = (line() + 1 < (int)m_doc->numLines());
72
73 if (ok) {
74 m_line++;
75 m_col = 0;
76 }
77
78 return ok;
79}
80
81bool KateDocCursor::gotoPreviousLine()
82{
83 bool ok = (line() > 0);
84
85 if (ok) {
86 m_line--;
87 m_col = 0;
88 }
89
90 return ok;
91}
92
93bool KateDocCursor::gotoEndOfNextLine()
94{
95 bool ok = gotoNextLine();
96 if(ok)
97 m_col = m_doc->lineLength(line());
98
99 return ok;
100}
101
102bool KateDocCursor::gotoEndOfPreviousLine()
103{
104 bool ok = gotoPreviousLine();
105 if(ok)
106 m_col = m_doc->lineLength(line());
107
108 return ok;
109}
110
111int KateDocCursor::nbCharsOnLineAfter()
112{
113 return ((int)m_doc->lineLength(line()) - col());
114}
115
116bool KateDocCursor::moveForward(uint nbChar)
117{
118 int nbCharLeft = nbChar - nbCharsOnLineAfter();
119
120 if(nbCharLeft > 0) {
121 return gotoNextLine() && moveForward((uint)nbCharLeft);
122 } else {
123 m_col += nbChar;
124 return true;
125 }
126}
127
128bool KateDocCursor::moveBackward(uint nbChar)
129{
130 int nbCharLeft = nbChar - m_col;
131 if(nbCharLeft > 0) {
132 return gotoEndOfPreviousLine() && moveBackward((uint)nbCharLeft);
133 } else {
134 m_col -= nbChar;
135 return true;
136 }
137}
138
139bool KateDocCursor::insertText(const TQString& s)
140{
141 return m_doc->insertText(line(), col(), s);
142}
143
144bool KateDocCursor::removeText(uint nbChar)
145{
146 // Get a cursor at the end of the removed area
147 KateDocCursor endCursor = *this;
148 endCursor.moveForward(nbChar);
149
150 // Remove the text
151 return m_doc->removeText((uint)line(), (uint)col(),
152 (uint)endCursor.line(), (uint)endCursor.col());
153}
154
155TQChar KateDocCursor::currentChar() const
156{
157 return m_doc->plainKateTextLine(line())->getChar(col());
158}
159
160uchar KateDocCursor::currentAttrib() const
161{
162 return m_doc->plainKateTextLine(line())->attribute(col());
163}
164
165bool KateDocCursor::nextNonSpaceChar()
166{
167 for(; m_line < (int)m_doc->numLines(); m_line++) {
168 m_col = m_doc->plainKateTextLine(line())->nextNonSpaceChar(col());
169 if(m_col != -1)
170 return true; // Next non-space char found
171 m_col = 0;
172 }
173 // No non-space char found
174 setPos(-1, -1);
175 return false;
176}
177
178bool KateDocCursor::previousNonSpaceChar()
179{
180 while (true) {
181 m_col = m_doc->plainKateTextLine(line())->previousNonSpaceChar(col());
182 if(m_col != -1) return true; // Previous non-space char found
183 if(m_line == 0) return false;
184 --m_line;
185 m_col = m_doc->plainKateTextLine(m_line)->length();
186 }
187 // No non-space char found
188 setPos(-1, -1);
189 return false;
190}
KateDocCursor
Cursor class with a pointer to its document.
Definition: katecursor.h:93
KateDocCursor::previousNonSpaceChar
bool previousNonSpaceChar()
Find the position (line and col) of the previous char that is not a space.
Definition: katecursor.cpp:178
KateDocCursor::nextNonSpaceChar
bool nextNonSpaceChar()
Find the position (line and col) of the next char that is not a space.
Definition: katecursor.cpp:165
KateTextCursor
Simple cursor class with no document pointer.
Definition: katecursor.h:34

kate

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

kate

Skip menu "kate"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kate by doxygen 1.9.4
This website is maintained by Timothy Pearson.