KTextEditor
cursor.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "cursor.h"
00020
00021 #include "range.h"
00022
00023 using namespace KTextEditor;
00024
00025 Cursor::Cursor( )
00026 : m_line(0)
00027 , m_column(0)
00028 , m_range(0L)
00029 {
00030 }
00031
00032 Cursor::Cursor( int _line, int _column )
00033 : m_line(_line)
00034 , m_column(_column)
00035 , m_range(0L)
00036 {
00037 }
00038
00039 Cursor::Cursor(const Cursor& copy)
00040 : m_line(copy.line())
00041 , m_column(copy.column())
00042 , m_range(0L)
00043 {
00044 }
00045
00046 bool Cursor::isValid() const
00047 {
00048 return m_line >= 0 && m_column >= 0;
00049 }
00050
00051 Cursor Cursor::invalid( )
00052 {
00053 return Cursor (-1,-1);
00054 }
00055
00056 Cursor Cursor::start()
00057 {
00058 return Cursor (0, 0);
00059 }
00060
00061 int Cursor::line() const
00062 {
00063 return m_line;
00064 }
00065
00066 void Cursor::setLine( int line )
00067 {
00068 if (line == this->line())
00069 return;
00070
00071 Cursor old = *this;
00072
00073 m_line = line;
00074
00075 cursorChangedDirectly(old);
00076 }
00077
00078 int Cursor::column() const
00079 {
00080 return m_column;
00081 }
00082
00083 void Cursor::setColumn( int column )
00084 {
00085 if (column == this->column())
00086 return;
00087
00088 Cursor old = *this;
00089
00090 m_column = column;
00091
00092 cursorChangedDirectly(old);
00093 }
00094
00095 void Cursor::setPosition( const Cursor & pos )
00096 {
00097 if (pos == *this)
00098 return;
00099
00100 Cursor old = *this;
00101
00102 m_line = pos.line();
00103 m_column = pos.column();
00104
00105 cursorChangedDirectly(old);
00106 }
00107
00108 bool Cursor::isSmartCursor( ) const
00109 {
00110 return false;
00111 }
00112
00113 void Cursor::setPosition(int line, int column)
00114 {
00115 setPosition(Cursor(line, column));
00116 }
00117
00118 void Cursor::position (int &_line, int &_column) const
00119 {
00120 _line = line(); _column = column();
00121 }
00122
00123 Range* Cursor::range() const
00124 {
00125 return m_range;
00126 }
00127
00128 Cursor::~ Cursor( )
00129 {
00130 }
00131
00132 void Cursor::setRange( Range * range )
00133 {
00134 m_range = range;
00135 }
00136
00137 void KTextEditor::Cursor::cursorChangedDirectly(const Cursor& from)
00138 {
00139 if (m_range) {
00140 if (this == &m_range->start())
00141 m_range->rangeChanged(this, Range(from, m_range->end()));
00142 else
00143 m_range->rangeChanged(this, Range(m_range->start(), from));
00144 }
00145 }
00146
00147 bool KTextEditor::Cursor::atStartOfLine( ) const
00148 {
00149 return m_column == 0;
00150 }
00151
00152 bool KTextEditor::Cursor::atStartOfDocument( ) const
00153 {
00154 return m_line == 0 && m_column == 0;
00155 }
00156
00157 SmartCursor * KTextEditor::Cursor::toSmartCursor( ) const
00158 {
00159 return 0L;
00160 }
00161
00162