• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kate

katecursor.cpp

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "katecursor.h"
00023 
00024 #include "katedocument.h"
00025 #include "katetextline.h"
00026 #include "katesmartrange.h"
00027 
00028 #include <ktexteditor/attribute.h>
00029 
00030 //
00031 // KateDocCursor implementation
00032 //
00033 
00034 KateDocCursor::KateDocCursor(KateDocument *doc) : KTextEditor::Cursor(), m_doc(doc)
00035 {
00036 }
00037 
00038 KateDocCursor::KateDocCursor(const KTextEditor::Cursor &position, KateDocument *doc)
00039   : KTextEditor::Cursor(position), m_doc(doc)
00040 {
00041 }
00042 
00043 KateDocCursor::KateDocCursor(int line, int col, KateDocument *doc)
00044   : KTextEditor::Cursor(line, col), m_doc(doc)
00045 {
00046 }
00047 
00048 bool KateDocCursor::validPosition(int line, int col)
00049 {
00050   return line >= 0 && col >= 0 && line < m_doc->lines() && col <= m_doc->lineLength(line);
00051 }
00052 
00053 bool KateDocCursor::validPosition()
00054 {
00055   return validPosition(line(), column());
00056 }
00057 
00058 bool KateDocCursor::gotoNextLine()
00059 {
00060   bool ok = (line() + 1 < m_doc->lines());
00061 
00062   if (ok) {
00063     m_line++;
00064     m_column = 0;
00065   }
00066 
00067   return ok;
00068 }
00069 
00070 bool KateDocCursor::gotoPreviousLine()
00071 {
00072   bool ok = (line() > 0);
00073 
00074   if (ok) {
00075     m_line--;
00076     m_column = 0;
00077   }
00078 
00079   return ok;
00080 }
00081 
00082 bool KateDocCursor::gotoEndOfNextLine()
00083 {
00084   bool ok = gotoNextLine();
00085   if(ok)
00086     m_column = m_doc->lineLength(line());
00087 
00088   return ok;
00089 }
00090 
00091 bool KateDocCursor::gotoEndOfPreviousLine()
00092 {
00093   bool ok = gotoPreviousLine();
00094   if(ok)
00095     m_column = m_doc->lineLength(line());
00096 
00097   return ok;
00098 }
00099 
00100 int KateDocCursor::nbCharsOnLineAfter()
00101 {
00102   return ((int)m_doc->lineLength(line()) - column());
00103 }
00104 
00105 bool KateDocCursor::moveForward(uint nbChar)
00106 {
00107   int nbCharLeft = nbChar - nbCharsOnLineAfter();
00108 
00109   if(nbCharLeft > 0) {
00110     return gotoNextLine() && moveForward((uint)nbCharLeft - 1);
00111   } else {
00112     m_column += nbChar;
00113     return true;
00114   }
00115 }
00116 
00117 bool KateDocCursor::moveBackward(uint nbChar)
00118 {
00119   int nbCharLeft = nbChar - m_column;
00120   if(nbCharLeft > 0) {
00121     return gotoEndOfPreviousLine() && moveBackward((uint)nbCharLeft - 1);
00122   } else {
00123     m_column -= nbChar;
00124     return true;
00125   }
00126 }
00127 
00128 bool KateDocCursor::insertText(const QString& s)
00129 {
00130   return m_doc->insertText(*this, s);
00131 }
00132 
00133 bool KateDocCursor::removeText(uint nbChar)
00134 {
00135   // Get a cursor at the end of the removed area
00136   KateDocCursor endCursor = *this;
00137   endCursor.moveForward(nbChar);
00138 
00139   // Remove the text
00140   return m_doc->removeText(KTextEditor::Range(*this, endCursor));
00141 }
00142 
00143 QChar KateDocCursor::currentChar() const
00144 {
00145   return m_doc->plainKateTextLine(line())->at(column());
00146 }
00147 
00148 uchar KateDocCursor::currentAttrib() const
00149 {
00150   return m_doc->plainKateTextLine(line())->attribute(column());
00151 }
00152 
00153 bool KateDocCursor::nextNonSpaceChar()
00154 {
00155   for(; m_line < m_doc->lines(); ++m_line) {
00156     m_column = m_doc->plainKateTextLine(line())->nextNonSpaceChar(column());
00157     if(m_column != -1)
00158       return true; // Next non-space char found
00159     m_column = 0;
00160   }
00161   // No non-space char found
00162   setPosition(-1, -1);
00163   return false;
00164 }
00165 
00166 bool KateDocCursor::previousNonSpaceChar()
00167 {
00168   while (true) {
00169     m_column = m_doc->plainKateTextLine(line())->previousNonSpaceChar(column());
00170     if(m_column != -1) return true; // Previous non-space char found
00171     if(m_line == 0) return false;
00172     --m_line;
00173     m_column = m_doc->plainKateTextLine(m_line)->length();
00174   }
00175   // No non-space char found
00176   setPosition(-1, -1);
00177   return false;
00178 }
00179 
00180 // kate: space-indent on; indent-width 2; replace-tabs on;

Kate

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal