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

kate

  • kate
  • part
katecursor.h
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 #ifndef kate_cursor_h
23 #define kate_cursor_h
24 
25 #include "../interfaces/document.h"
26 #include <kdebug.h>
27 
28 class KateDocument;
29 
33 class KateTextCursor
34 {
35  public:
36  KateTextCursor() : m_line(0), m_col(0) {};
37  KateTextCursor(int line, int col) : m_line(line), m_col(col) {};
38  virtual ~KateTextCursor () {};
39 
40  friend bool operator==(const KateTextCursor& c1, const KateTextCursor& c2)
41  { return c1.m_line == c2.m_line && c1.m_col == c2.m_col; }
42 
43  friend bool operator!=(const KateTextCursor& c1, const KateTextCursor& c2)
44  { return !(c1 == c2); }
45 
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); }
48 
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); }
51 
52  friend bool operator<(const KateTextCursor& c1, const KateTextCursor& c2)
53  { return !(c1 >= c2); }
54 
55  friend bool operator<=(const KateTextCursor& c1, const KateTextCursor& c2)
56  { return !(c1 > c2); }
57 
58  friend kdbgstream& operator<<(kdbgstream& stream, const KateTextCursor& c) {
59  stream << c.m_line << "," << c.m_col;
60  return stream;
61  }
62 
63 #ifndef Q_WS_WIN //not needed
64  friend void tqSwap(KateTextCursor & c1, KateTextCursor & c2) {
65  KateTextCursor tmp = c1;
66  c1 = c2;
67  c2 = tmp;
68  }
69 #endif
70 
71  inline void pos(int *pline, int *pcol) const {
72  if(pline) *pline = m_line;
73  if(pcol) *pcol = m_col;
74  }
75 
76  inline int line() const { return m_line; };
77  inline int col() const { return m_col; };
78 
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; };
83 
84  protected:
85  int m_line;
86  int m_col;
87 };
88 
92 class KateDocCursor : public KateTextCursor
93 {
94  public:
95  KateDocCursor(KateDocument *doc);
96  KateDocCursor(int line, int col, KateDocument *doc);
97  virtual ~KateDocCursor() {};
98 
99  bool validPosition(uint line, uint col);
100  bool validPosition();
101 
102  bool gotoNextLine();
103  bool gotoPreviousLine();
104  bool gotoEndOfNextLine();
105  bool gotoEndOfPreviousLine();
106 
107  int nbCharsOnLineAfter();
108  bool moveForward(uint nbChar);
109  bool moveBackward(uint nbChar);
110 
111  // KTextEditor::Cursor interface
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;
117 
118  uchar currentAttrib() const;
119 
128  bool nextNonSpaceChar();
129 
138  bool previousNonSpaceChar();
139 
140  protected:
141  KateDocument *m_doc;
142 };
143 
144 class KateRange
145 {
146  public:
147  KateRange () {};
148  virtual ~KateRange () {};
149 
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;
155 };
156 
157 class KateTextRange : public KateRange
158 {
159  public:
160  KateTextRange()
161  : m_valid(false)
162  {
163  };
164 
165  KateTextRange(int startline, int startcol, int endline, int endcol)
166  : m_start(startline, startcol)
167  , m_end(endline, endcol)
168  , m_valid(true)
169  {
170  normalize();
171  };
172 
173  KateTextRange(const KateTextCursor& start, const KateTextCursor& end)
174  : m_start(start)
175  , m_end(end)
176  , m_valid(true)
177  {
178  normalize();
179  };
180 
181  virtual ~KateTextRange () {};
182 
183  virtual bool isValid() const { return m_valid; };
184  void setValid(bool valid) {
185  m_valid = valid;
186  if( valid )
187  normalize();
188  };
189 
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; };
194 
195  /* if range is not valid, the result is undefined
196  if cursor is before start -1 is returned, if cursor is within range 0 is returned if cursor is after end 1 is returned*/
197  inline int cursorInRange(const KateTextCursor &cursor) const {
198  return ((cursor<m_start)?(-1):((cursor>m_end)?1:0));
199  }
200 
201  inline void normalize() {
202  if( m_start > m_end )
203  tqSwap(m_start, m_end);
204  }
205 
206  protected:
207  KateTextCursor m_start, m_end;
208  bool m_valid;
209 };
210 
211 
212 class KateBracketRange : public KateTextRange
213 {
214  public:
215  KateBracketRange()
216  : KateTextRange()
217  , m_minIndent(0)
218  {
219  };
220 
221  KateBracketRange(int startline, int startcol, int endline, int endcol, int minIndent)
222  : KateTextRange(startline, startcol, endline, endcol)
223  , m_minIndent(minIndent)
224  {
225  };
226 
227  KateBracketRange(const KateTextCursor& start, const KateTextCursor& end, int minIndent)
228  : KateTextRange(start, end)
229  , m_minIndent(minIndent)
230  {
231  };
232 
233  int getMinIndent() const
234  {
235  return m_minIndent;
236  }
237 
238  void setIndentMin(int m)
239  {
240  m_minIndent = m;
241  }
242 
243  protected:
244  int m_minIndent;
245 };
246 
247 
248 #endif
KateTextCursor
Simple cursor class with no document pointer.
Definition: katecursor.h:33
KateDocCursor
Cursor class with a pointer to its document.
Definition: katecursor.h:92
kdbgstream
KateDocCursor::nextNonSpaceChar
bool nextNonSpaceChar()
Find the position (line and col) of the next char that is not a space.
Definition: katecursor.cpp:165
TDEStdAccel::end
const TDEShortcut & end()
KateDocCursor::previousNonSpaceChar
bool previousNonSpaceChar()
Find the position (line and col) of the previous char that is not a space.
Definition: katecursor.cpp:178

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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kate by doxygen 1.8.8
This website is maintained by Timothy Pearson.