| # kate Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# katecursor.h

    00001 /* This file is part of the KDE libraries
    00002    Copyright (C) 2002 Christian Couder <christian@kdevelop.org>
    00003    Copyright (C) 2001, 2003 Christoph Cullmann <cullmann@kde.org>
    00004    Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
    00005    Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
    00006
    00007    This library is free software; you can redistribute it and/or
    00008    modify it under the terms of the GNU Library General Public
    00009    License version 2 as published by the Free Software Foundation.
    00010
    00011    This library is distributed in the hope that it will be useful,
    00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014    Library General Public License for more details.
    00015
    00016    You should have received a copy of the GNU Library General Public License
    00017    along with this library; see the file COPYING.LIB.  If not, write to
    00018    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00019    Boston, MA 02111-1307, USA.
    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     // KTextEditor::Cursor interface
    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
    00104     uchar currentAttrib() const;
    00105
    00114     bool nextNonSpaceChar();
    00115
    00124     bool previousNonSpaceChar();
    00125
    00126   protected:
    00127     KateDocument *m_doc;
    00128 };
    00129
    00130 class KateRange
    00131 {
    00132   public:
    00133     KateRange () {};
    00134     virtual ~KateRange () {};
    00135
    00136     virtual bool isValid() const = 0;
    00137     virtual KateTextCursor& start() = 0;
    00138     virtual KateTextCursor& end() = 0;
    00139     virtual const KateTextCursor& start() const = 0;
    00140     virtual const KateTextCursor& end() const = 0;
    00141 };
    00142
    00143 class KateTextRange : public KateRange
    00144 {
    00145   public:
    00146     KateTextRange()
    00147       : m_valid(false)
    00148     {
    00149     };
    00150
    00151     KateTextRange(int startline, int startcol, int endline, int endcol)
    00152       : m_start(startline, startcol)
    00153       , m_end(endline, endcol)
    00154       , m_valid(true)
    00155     {
    00156     };
    00157
    00158     KateTextRange(const KateTextCursor& start, const KateTextCursor& end)
    00159       : m_start(start)
    00160       , m_end(end)
    00161       , m_valid(true)
    00162     {
    00163     };
    00164
    00165     virtual ~KateTextRange () {};
    00166
    00167     virtual bool isValid() const { return m_valid; };
    00168     void setValid(bool valid) { m_valid = valid; };
    00169
    00170     virtual KateTextCursor& start() { return m_start; };
    00171     virtual KateTextCursor& end() { return m_end; };
    00172     virtual const KateTextCursor& start() const { return m_start; };
    00173     virtual const KateTextCursor& end() const { return m_end; };
    00174     /* if range is not valid, the result is undefined
    00175       if cursor is before start -1 is returned, if cursor is within range 0 is returned if cursor is after end 1 is returned*/
    00176     inline int cursorInRange(const KateTextCursor &cursor) const {
    00177       return ((cursor<m_start)?(-1):((cursor>m_end)?1:0));
    00178     }
    00179   protected:
    00180     KateTextCursor m_start, m_end;
    00181     bool m_valid;
    00182 };
    00183
    00184 #endif
    00185
    00186 // kate: space-indent on; indent-width 2; replace-tabs on;

This file is part of the documentation for kate Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:36:30 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003