KTextEditor
cursor.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 Copyright (C) 2003-2005 Hamish Rodda <rodda@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "cursor.h" 00021 00022 #include "range.h" 00023 00024 using namespace KTextEditor; 00025 00026 Cursor::Cursor( ) 00027 : m_line(0) 00028 , m_column(0) 00029 , m_range(0L) 00030 { 00031 } 00032 00033 Cursor::Cursor( int _line, int _column ) 00034 : m_line(_line) 00035 , m_column(_column) 00036 , m_range(0L) 00037 { 00038 } 00039 00040 Cursor::Cursor(const Cursor& copy) 00041 : m_line(copy.line()) 00042 , m_column(copy.column()) 00043 , m_range(0L) 00044 { 00045 } 00046 00047 bool Cursor::isValid() const 00048 { 00049 return m_line >= 0 && m_column >= 0; 00050 } 00051 00052 Cursor Cursor::invalid( ) 00053 { 00054 return Cursor (-1,-1); 00055 } 00056 00057 Cursor Cursor::start() 00058 { 00059 return Cursor (0, 0); 00060 } 00061 00062 int Cursor::line() const 00063 { 00064 return m_line; 00065 } 00066 00067 void Cursor::setLine( int line ) 00068 { 00069 if (line == this->line()) 00070 return; 00071 00072 Cursor old = *this; 00073 00074 m_line = line; 00075 00076 cursorChangedDirectly(old); 00077 } 00078 00079 int Cursor::column() const 00080 { 00081 return m_column; 00082 } 00083 00084 void Cursor::setColumn( int column ) 00085 { 00086 if (column == this->column()) 00087 return; 00088 00089 Cursor old = *this; 00090 00091 m_column = column; 00092 00093 cursorChangedDirectly(old); 00094 } 00095 00096 void Cursor::setPosition( const Cursor & pos ) 00097 { 00098 if (pos == *this) 00099 return; 00100 00101 Cursor old = *this; 00102 00103 m_line = pos.line(); 00104 m_column = pos.column(); 00105 00106 cursorChangedDirectly(old); 00107 } 00108 00109 bool Cursor::isSmartCursor( ) const 00110 { 00111 return false; 00112 } 00113 00114 void Cursor::setPosition(int line, int column) 00115 { 00116 setPosition(Cursor(line, column)); 00117 } 00118 00119 void Cursor::position (int &_line, int &_column) const 00120 { 00121 _line = line(); _column = column(); 00122 } 00123 00124 Range* Cursor::range() const 00125 { 00126 return m_range; 00127 } 00128 00129 Cursor::~ Cursor( ) 00130 { 00131 } 00132 00133 void Cursor::setRange( Range * range ) 00134 { 00135 m_range = range; 00136 } 00137 00138 void KTextEditor::Cursor::cursorChangedDirectly(const Cursor& from) 00139 { 00140 if (m_range) { 00141 if (this == &m_range->start()) 00142 m_range->rangeChanged(this, Range(from, m_range->end())); 00143 else 00144 m_range->rangeChanged(this, Range(m_range->start(), from)); 00145 } 00146 } 00147 00148 bool KTextEditor::Cursor::atStartOfLine( ) const 00149 { 00150 return m_column == 0; 00151 } 00152 00153 bool KTextEditor::Cursor::atStartOfDocument( ) const 00154 { 00155 return line() == 0 && m_column == 0; 00156 } 00157 00158 SmartCursor * KTextEditor::Cursor::toSmartCursor( ) const 00159 { 00160 return 0L; 00161 } 00162 00163 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference