19 #include "katesupercursor.h" 20 #include "katesupercursor.moc" 22 #include "katedocument.h" 26 #include <tqobjectlist.h> 29 : TQObject(parent, name)
34 m_moveOnInsert =
false;
35 m_lineRemoved =
false;
36 m_privateCursor = privateC;
38 m_doc->addSuperCursor (
this, privateC);
42 : TQObject(parent, name)
47 m_moveOnInsert =
false;
48 m_lineRemoved =
false;
49 m_privateCursor = privateC;
51 m_doc->addSuperCursor (
this, privateC);
54 KateSuperCursor::~KateSuperCursor ()
56 m_doc->removeSuperCursor (
this, m_privateCursor);
59 void KateSuperCursor::position(uint *pline, uint *pcol)
const 61 KateDocCursor::position(pline, pcol);
64 bool KateSuperCursor::setPosition(uint line, uint col)
66 if (line == uint(-2) && col == uint(-2)) {
delete this;
return true; }
67 return KateDocCursor::setPosition(line, col);
70 bool KateSuperCursor::insertText(
const TQString& s)
72 return KateDocCursor::insertText(s);
75 bool KateSuperCursor::removeText(uint nbChar)
77 return KateDocCursor::removeText(nbChar);
80 TQChar KateSuperCursor::currentChar()
const 82 return KateDocCursor::currentChar();
92 return col() >= (int)m_doc->kateTextLine(line())->length();
97 return m_moveOnInsert;
105 void KateSuperCursor::setLine(
int lineNum)
107 int tempLine = line(), tempcol = col();
108 KateDocCursor::setLine(lineNum);
110 if (tempLine != line() || tempcol != col())
114 void KateSuperCursor::setCol(
int colNum)
116 KateDocCursor::setCol(colNum);
121 KateDocCursor::setPos(pos);
124 void KateSuperCursor::setPos(
int lineNum,
int colNum)
126 KateDocCursor::setPos(lineNum, colNum);
129 void KateSuperCursor::editTextInserted(uint line, uint col, uint len)
131 if (m_line ==
int(line))
133 if ((m_col >
int(col)) || (m_moveOnInsert && (m_col ==
int(col))))
135 bool insertedAt = m_col == int(col);
150 void KateSuperCursor::editTextRemoved(uint line, uint col, uint len)
152 if (m_line ==
int(line))
154 if (m_col >
int(col))
156 if (m_col >
int(col + len))
162 bool prevCharDeleted = m_col == int(col + len);
176 else if (m_col ==
int(col))
185 void KateSuperCursor::editLineWrapped(uint line, uint col,
bool newLine)
189 if (m_line >
int(line) || (m_line ==
int(line) && m_col >=
int(col)))
191 if(m_line ==
int(line))
199 else if ( (m_line ==
int(line)) && (m_col >
int(col)) || (m_moveOnInsert && (m_col ==
int(col))) )
211 void KateSuperCursor::editLineUnWrapped(uint line, uint col,
bool removeLine, uint length)
213 if (removeLine && (m_line >
int(line+1)))
220 else if ( (m_line ==
int(line+1)) && (removeLine || (m_col <
int(length))) )
228 else if ( (m_line ==
int(line+1)) && (m_col >=
int(length)) )
239 void KateSuperCursor::editLineInserted (uint line)
241 if (m_line >=
int(line))
252 void KateSuperCursor::editLineRemoved(uint line)
254 if (m_line >
int(line))
261 else if (m_line ==
int(line))
263 m_line = (line <= m_doc->lastLine()) ? line : (line - 1);
275 KateSuperCursor::operator TQString()
277 return TQString(
"[%1,%1]").arg(line()).arg(col());
281 : TQObject(parent, name)
285 , m_startChanged(false)
286 , m_endChanged(false)
287 , m_deleteCursors(false)
288 , m_allowZeroLength(false)
294 : TQObject(parent, name)
298 , m_startChanged(
false)
299 , m_endChanged(
false)
300 , m_deleteCursors(
true)
301 , m_allowZeroLength(
false)
307 : TQObject(parent, name)
311 , m_startChanged(
false)
312 , m_endChanged(
false)
313 , m_deleteCursors(
true)
314 , m_allowZeroLength(
false)
319 void KateSuperRange::init()
325 insertChild(m_start);
331 connect(m_start, TQT_SIGNAL(positionDirectlyChanged()), TQT_SIGNAL(
contentsChanged()));
332 connect(m_end, TQT_SIGNAL(positionDirectlyChanged()), TQT_SIGNAL(
contentsChanged()));
334 connect(m_start, TQT_SIGNAL(
positionChanged()), TQT_SLOT(slotEvaluateChanged()));
335 connect(m_end, TQT_SIGNAL(
positionChanged()), TQT_SLOT(slotEvaluateChanged()));
336 connect(m_start, TQT_SIGNAL(
positionUnChanged()), TQT_SLOT(slotEvaluateUnChanged()));
337 connect(m_end, TQT_SIGNAL(
positionUnChanged()), TQT_SLOT(slotEvaluateUnChanged()));
338 connect(m_start, TQT_SIGNAL(positionDeleted()), TQT_SIGNAL(
boundaryDeleted()));
339 connect(m_end, TQT_SIGNAL(positionDeleted()), TQT_SIGNAL(
boundaryDeleted()));
342 KateSuperRange::~KateSuperRange()
411 if (!
includes(cursor))
return false;
413 if (!childrenListObject().isEmpty())
414 for (TQObjectListIt it(childrenListObject()); *it; ++it)
415 if ((*it)->inherits(
"KateSuperRange"))
416 if (static_cast<KateSuperRange*>(*it)->owns(cursor))
447 void KateSuperRange::slotEvaluateChanged()
449 if (sender() == static_cast<TQObject*>(m_start)) {
453 evaluateEliminated();
457 evaluatePositionChanged();
458 m_endChanged =
false;
462 m_startChanged =
true;
467 if (!m_startChanged) {
469 evaluateEliminated();
473 evaluatePositionChanged();
474 m_startChanged =
false;
482 m_evaluate = !m_evaluate;
485 void KateSuperRange::slotEvaluateUnChanged()
487 if (sender() == static_cast<TQObject*>(m_start)) {
491 evaluateEliminated();
492 m_endChanged =
false;
502 if (m_startChanged) {
504 evaluateEliminated();
505 m_startChanged =
false;
514 m_evaluate = !m_evaluate;
517 void KateSuperRange::slotTagRange()
522 void KateSuperRange::evaluateEliminated()
531 void KateSuperRange::evaluatePositionChanged()
539 int KateSuperCursorList::compareItems(TQPtrCollection::Item item1, TQPtrCollection::Item item2)
541 if (*(static_cast<KateSuperCursor*>(item1)) == *(static_cast<KateSuperCursor*>(item2)))
547 KateSuperRangeList::KateSuperRangeList(
bool autoManage, TQObject* parent,
const char* name)
548 : TQObject(parent, name)
549 , m_autoManage(autoManage)
551 , m_trackingBoundaries(
false)
553 setAutoManage(autoManage);
556 KateSuperRangeList::KateSuperRangeList(
const TQPtrList<KateSuperRange>& rangeList, TQObject* parent,
const char* name)
557 : TQObject(parent, name)
558 , m_autoManage(
false)
560 , m_trackingBoundaries(
false)
562 appendList(rangeList);
565 void KateSuperRangeList::appendList(
const TQPtrList<KateSuperRange>& rangeList)
567 for (TQPtrListIterator<KateSuperRange> it = rangeList; *it; ++it)
571 void KateSuperRangeList::clear()
574 emit rangeEliminated(range);
576 TQPtrList<KateSuperRange>::clear();
579 void KateSuperRangeList::connectAll()
584 connect(range, TQT_SIGNAL(destroyed(TQObject*)), TQT_SLOT(slotDeleted(TQObject*)));
585 connect(range, TQT_SIGNAL(
eliminated()), TQT_SLOT(slotEliminated()));
590 bool KateSuperRangeList::autoManage()
const 595 void KateSuperRangeList::setAutoManage(
bool autoManage)
597 m_autoManage = autoManage;
598 setAutoDelete(m_autoManage);
601 TQPtrList<KateSuperRange> KateSuperRangeList::rangesIncluding(
const KateTextCursor& cursor)
605 TQPtrList<KateSuperRange> ret;
608 if (r->includes(cursor))
614 TQPtrList<KateSuperRange> KateSuperRangeList::rangesIncluding(uint line)
618 TQPtrList<KateSuperRange> ret;
621 if (r->includes(line))
627 bool KateSuperRangeList::rangesInclude(
const KateTextCursor& cursor)
630 if (r->includes(cursor))
636 void KateSuperRangeList::slotEliminated()
640 emit rangeEliminated(range);
642 if (m_trackingBoundaries) {
643 m_columnBoundaries.removeRef(range->m_start);
644 m_columnBoundaries.removeRef(range->m_end);
655 void KateSuperRangeList::slotDeleted(TQObject* range)
660 if (m_trackingBoundaries) {
661 m_columnBoundaries.removeRef(r->m_start);
662 m_columnBoundaries.removeRef(r->m_end);
665 int index = findRef(r);
676 if (!m_trackingBoundaries) {
677 m_trackingBoundaries =
true;
680 m_columnBoundaries.append(&(r->superStart()));
681 m_columnBoundaries.append(&(r->superEnd()));
685 m_columnBoundaries.sort();
689 for (
KateSuperCursor* c = m_columnBoundaries.first(); c; c = m_columnBoundaries.next())
693 return m_columnBoundaries.current();
702 while (m_columnBoundaries.next())
703 if (*(m_columnBoundaries.current()) != *current)
706 return m_columnBoundaries.current();
711 return m_columnBoundaries.current();
714 int KateSuperRangeList::compareItems(TQPtrCollection::Item item1, TQPtrCollection::Item item2)
716 if (static_cast<KateSuperRange*>(item1)->
superStart() == static_cast<KateSuperRange*>(item2)->
superStart()) {
717 if (static_cast<KateSuperRange*>(item1)->
superEnd() == static_cast<KateSuperRange*>(item2)->
superEnd()) {
727 TQPtrCollection::Item KateSuperRangeList::newItem(TQPtrCollection::Item d)
730 connect(static_cast<KateSuperRange*>(d), TQT_SIGNAL(destroyed(TQObject*)), TQT_SLOT(slotDeleted(TQObject*)));
731 connect(static_cast<KateSuperRange*>(d), TQT_SIGNAL(
eliminated()), TQT_SLOT(slotEliminated()));
738 if (m_trackingBoundaries) {
739 m_columnBoundaries.append(&(static_cast<KateSuperRange*>(d)->
superStart()));
740 m_columnBoundaries.append(&(static_cast<KateSuperRange*>(d)->
superEnd()));
743 return TQPtrList<KateSuperRange>::newItem(d);
Simple cursor class with no document pointer.
Cursor class with a pointer to its document.
virtual bool isValid() const
Start and end must be valid and start <= end.
Represents a range of text, from the start() to the end().
KateSuperCursor(KateDocument *doc, bool privateC, const KateTextCursor &cursor, TQObject *parent=0L, const char *name=0L)
bool privateC says: if private, than don't show to apps using the cursorinterface in the list...
Expand to encapsulate new characters to the right of the range.
kdbgstream kdDebug(int area=0)
void charDeletedBefore()
The character immediately before the cursor was deleted.
bool includesWholeLine(uint lineNum) const
Returns true if the range totally encompasses line.
Don't expand to encapsulate new characters in either direction. This is the default.
void boundaryDeleted()
Either cursor's surrounding characters were both deleted.
bool boundaryOn(uint lineNum) const
Returns whether there is a boundary of this range on line.
void positionUnChanged()
Athough an edit took place, the cursor's position was unchanged.
void positionChanged()
The cursor's position was changed.
void contentsChanged()
The contents of the range changed.
int behaviour() const
Returns how this range reacts to characters inserted immediately outside the range.
KateSuperCursor & superEnd()
Returns the super end cursor.
void positionUnChanged()
The range's position was unchanged.
void positionDirectlyChanged()
The cursor's position was directly changed by the program.
void charDeletedAfter()
The character immediately after the cursor was deleted.
void positionChanged()
More interesting signals that aren't worth implementing here: firstCharDeleted: start()::charDeleted(...
Possible additional features:
void charInsertedAt()
A character was inserted immediately before the cursor.
Expand to encapsulate new characters to the left of the range.
bool owns(const KateTextCursor &cursor) const
This is for use where the ranges are used in a heirachy, ie.
void positionDeleted()
The cursor's surrounding characters were both deleted simultaneously.
kndbgstream & endl(kndbgstream &s)
bool atStartOfLine() const
bool boundaryAt(const KateTextCursor &cursor) const
Returns whether cursor is the site of a boundary of this range.
KateSuperCursor & superStart()
Returns the super start cursor.
Kate namespace All classes in this namespace must stay BC during one major release series (e...
void tagRange(KateSuperRange *range)
Indicates the region needs re-drawing.
void setMoveOnInsert(bool moveOnInsert)
Change the behavior of the cursor when text is inserted at the cursor.
bool includes(const KateTextCursor &cursor) const
Returns true if the range includes cursor 's character.
KateSuperRange(KateSuperCursor *start, KateSuperCursor *end, TQObject *parent=0L, const char *name=0L)
Constructor.
void eliminated()
The range now contains no characters (ie.
void setBehaviour(int behaviour)
Determine how the range should react to characters inserted immediately outside the range...
bool moveOnInsert() const
Returns how this cursor behaves when text is inserted at the cursor.