25#include "../interfaces/document.h"
36 KateTextCursor() : m_line(0), m_col(0) {};
37 KateTextCursor(
int line,
int col) : m_line(line), m_col(col) {};
38 virtual ~KateTextCursor () {};
40 friend bool operator==(
const KateTextCursor& c1,
const KateTextCursor& c2)
41 {
return c1.m_line == c2.m_line && c1.m_col == c2.m_col; }
43 friend bool operator!=(
const KateTextCursor& c1,
const KateTextCursor& c2)
44 {
return !(c1 == c2); }
46 friend bool operator>(
const KateTextCursor& c1,
const KateTextCursor& c2)
47 {
return c1.m_line > c2.m_line || (c1.m_line == c2.m_line && c1.m_col > c2.m_col); }
49 friend bool operator>=(
const KateTextCursor& c1,
const KateTextCursor& c2)
50 {
return c1.m_line > c2.m_line || (c1.m_line == c2.m_line && c1.m_col >= c2.m_col); }
52 friend bool operator<(
const KateTextCursor& c1,
const KateTextCursor& c2)
53 {
return !(c1 >= c2); }
55 friend bool operator<=(
const KateTextCursor& c1,
const KateTextCursor& c2)
56 {
return !(c1 > c2); }
59 stream << c.m_line <<
"," << c.m_col;
64 friend void tqSwap(KateTextCursor & c1, KateTextCursor & c2) {
65 KateTextCursor tmp = c1;
71 inline void pos(
int *pline,
int *pcol)
const {
72 if(pline) *pline = m_line;
73 if(pcol) *pcol = m_col;
76 inline int line()
const {
return m_line; };
77 inline int col()
const {
return m_col; };
79 virtual void setLine(
int line) { m_line = line; };
80 virtual void setCol(
int col) { m_col = col; };
81 virtual void setPos(
const KateTextCursor& pos) { m_line = pos.line(); m_col = pos.col(); };
82 virtual void setPos(
int line,
int col) { m_line = line; m_col = col; };
92class KateDocCursor :
public KateTextCursor
95 KateDocCursor(KateDocument *doc);
96 KateDocCursor(
int line,
int col, KateDocument *doc);
97 virtual ~KateDocCursor() {};
99 bool validPosition(uint line, uint col);
100 bool validPosition();
103 bool gotoPreviousLine();
104 bool gotoEndOfNextLine();
105 bool gotoEndOfPreviousLine();
107 int nbCharsOnLineAfter();
108 bool moveForward(uint nbChar);
109 bool moveBackward(uint nbChar);
112 void position(uint *line, uint *col)
const;
113 bool setPosition(uint line, uint col);
114 bool insertText(
const TQString& text);
115 bool removeText(uint numberOfCharacters);
116 TQChar currentChar()
const;
118 uchar currentAttrib()
const;
148 virtual ~KateRange () {};
150 virtual bool isValid()
const = 0;
151 virtual KateTextCursor& start() = 0;
152 virtual KateTextCursor& end() = 0;
153 virtual const KateTextCursor& start()
const = 0;
154 virtual const KateTextCursor& end()
const = 0;
157class KateTextRange :
public KateRange
165 KateTextRange(
int startline,
int startcol,
int endline,
int endcol)
166 : m_start(startline, startcol)
167 , m_end(endline, endcol)
173 KateTextRange(
const KateTextCursor& start,
const KateTextCursor& end)
181 virtual ~KateTextRange () {};
183 virtual bool isValid()
const {
return m_valid; };
184 void setValid(
bool valid) {
190 virtual KateTextCursor& start() {
return m_start; };
191 virtual KateTextCursor& end() {
return m_end; };
192 virtual const KateTextCursor& start()
const {
return m_start; };
193 virtual const KateTextCursor& end()
const {
return m_end; };
197 inline int cursorInRange(
const KateTextCursor &cursor)
const {
198 return ((cursor<m_start)?(-1):((cursor>m_end)?1:0));
201 inline void normalize() {
202 if( m_start > m_end )
203 tqSwap(m_start, m_end);
207 KateTextCursor m_start, m_end;
212class KateBracketRange :
public KateTextRange
221 KateBracketRange(
int startline,
int startcol,
int endline,
int endcol,
int minIndent)
222 : KateTextRange(startline, startcol, endline, endcol)
223 , m_minIndent(minIndent)
227 KateBracketRange(
const KateTextCursor& start,
const KateTextCursor& end,
int minIndent)
228 : KateTextRange(start, end)
229 , m_minIndent(minIndent)
233 int getMinIndent()
const
238 void setIndentMin(
int m)
bool previousNonSpaceChar()
Find the position (line and col) of the previous char that is not a space.
bool nextNonSpaceChar()
Find the position (line and col) of the next char that is not a space.