00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
#ifndef kate_cursor_h
00023
#define kate_cursor_h
00024
00025
#include "../interfaces/document.h"
00026
00027
class KateDocument;
00028
00032 class KateTextCursor
00033 {
00034
public:
00035
KateTextCursor() : m_line(0), m_col(0) {};
00036
KateTextCursor(
int line,
int col) : m_line(line), m_col(col) {};
00037
virtual ~
KateTextCursor () {};
00038
00039
friend bool operator==(
const KateTextCursor& c1,
const KateTextCursor& c2)
00040 {
return c1.
m_line == c2.
m_line && c1.
m_col == c2.
m_col; }
00041
00042
friend bool operator!=(
const KateTextCursor& c1,
const KateTextCursor& c2)
00043 {
return !(c1 == c2); }
00044
00045
friend bool operator>(
const KateTextCursor& c1,
const KateTextCursor& c2)
00046 {
return c1.
m_line > c2.
m_line || (c1.
m_line == c2.
m_line && c1.
m_col > c2.
m_col); }
00047
00048
friend bool operator>=(
const KateTextCursor& c1,
const KateTextCursor& c2)
00049 {
return c1.
m_line > c2.
m_line || (c1.
m_line == c2.
m_line && c1.
m_col >= c2.
m_col); }
00050
00051
friend bool operator<(
const KateTextCursor& c1,
const KateTextCursor& c2)
00052 {
return !(c1 >= c2); }
00053
00054
friend bool operator<=(
const KateTextCursor& c1,
const KateTextCursor& c2)
00055 {
return !(c1 > c2); }
00056
00057
inline void pos(
int *pline,
int *pcol)
const {
00058
if(pline) *pline = m_line;
00059
if(pcol) *pcol = m_col;
00060 }
00061
00062
inline int line()
const {
return m_line; };
00063
inline int col()
const {
return m_col; };
00064
00065
virtual void setLine(
int line) { m_line = line; };
00066
virtual void setCol(
int col) { m_col = col; };
00067
virtual void setPos(
const KateTextCursor& pos) { m_line = pos.
line(); m_col = pos.
col(); };
00068
virtual void setPos(
int line,
int col) { m_line = line; m_col = col; };
00069
00070
protected:
00071
int m_line;
00072
int m_col;
00073 };
00074
00078 class KateDocCursor :
public KateTextCursor
00079 {
00080
public:
00081
KateDocCursor(KateDocument *doc);
00082
KateDocCursor(
int line,
int col, KateDocument *doc);
00083
virtual ~
KateDocCursor() {};
00084
00085
bool validPosition(uint line, uint col);
00086
bool validPosition();
00087
00088
bool gotoNextLine();
00089
bool gotoPreviousLine();
00090
bool gotoEndOfNextLine();
00091
bool gotoEndOfPreviousLine();
00092
00093
int nbCharsOnLineAfter();
00094
bool moveForward(uint nbChar);
00095
bool moveBackward(uint nbChar);
00096
00097
00098
void position(uint *line, uint *col)
const;
00099
bool setPosition(uint line, uint col);
00100
bool insertText(
const QString& text);
00101
bool removeText(uint numberOfCharacters);
00102
QChar currentChar()
const;
00103
00112
bool nextNonSpaceChar();
00113
00122
bool previousNonSpaceChar();
00123
00124
protected:
00125 KateDocument *m_doc;
00126 };
00127
00128
class KateRange
00129 {
00130
public:
00131 KateRange () {};
00132
virtual ~KateRange () {};
00133
00134
virtual bool isValid() const = 0;
00135 virtual
KateTextCursor& start() = 0;
00136 virtual
KateTextCursor& end() = 0;
00137 virtual const
KateTextCursor& start() const = 0;
00138 virtual const
KateTextCursor& end() const = 0;
00139 };
00140
00141 class KateTextRange : public KateRange
00142 {
00143
public:
00144 KateTextRange()
00145 : m_valid(false)
00146 {
00147 };
00148
00149 KateTextRange(
int startline,
int startcol,
int endline,
int endcol)
00150 : m_start(startline, startcol)
00151 , m_end(endline, endcol)
00152 , m_valid(true)
00153 {
00154 };
00155
00156 KateTextRange(
const KateTextCursor& start,
const KateTextCursor& end)
00157 : m_start(start)
00158 , m_end(
end)
00159 , m_valid(true)
00160 {
00161 };
00162
00163
virtual ~KateTextRange () {};
00164
00165
virtual bool isValid()
const {
return m_valid; };
00166
void setValid(
bool valid) { m_valid = valid; };
00167
00168
virtual KateTextCursor& start() {
return m_start; };
00169
virtual KateTextCursor&
end() {
return m_end; };
00170
virtual const KateTextCursor& start()
const {
return m_start; };
00171
virtual const KateTextCursor&
end()
const {
return m_end; };
00172
00173
protected:
00174
KateTextCursor m_start, m_end;
00175
bool m_valid;
00176 };
00177
00178
#endif