19#include "katesupercursor.h"
20#include "katesupercursor.moc"
22#include "katedocument.h"
26#include <tqobjectlist.h>
29 : TQObject(parent, name)
30 , KateDocCursor(cursor.line(), cursor.col(), doc)
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);
54KateSuperCursor::~KateSuperCursor ()
56 m_doc->removeSuperCursor (
this, m_privateCursor);
59void KateSuperCursor::position(uint *pline, uint *pcol)
const
61 KateDocCursor::position(pline, pcol);
64bool KateSuperCursor::setPosition(uint line, uint col)
66 if (line == uint(-2) && col == uint(-2)) {
delete this;
return true; }
67 return KateDocCursor::setPosition(line, col);
70bool KateSuperCursor::insertText(
const TQString& s)
72 return KateDocCursor::insertText(s);
75bool KateSuperCursor::removeText(uint nbChar)
77 return KateDocCursor::removeText(nbChar);
80TQChar KateSuperCursor::currentChar()
const
82 return KateDocCursor::currentChar();
92 return col() >= (int)m_doc->kateTextLine(line())->length();
97 return m_moveOnInsert;
105void KateSuperCursor::setLine(
int lineNum)
107 int tempLine = line(), tempcol = col();
108 KateDocCursor::setLine(lineNum);
110 if (tempLine != line() || tempcol != col())
114void KateSuperCursor::setCol(
int colNum)
116 KateDocCursor::setCol(colNum);
121 KateDocCursor::setPos(pos);
124void KateSuperCursor::setPos(
int lineNum,
int colNum)
126 KateDocCursor::setPos(lineNum, colNum);
129void 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);
150void 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))
185void 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))) )
211void 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)) )
239void KateSuperCursor::editLineInserted (uint line)
241 if (m_line >=
int(line))
252void 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);
275KateSuperCursor::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)
319void KateSuperRange::init()
325 insertChild(m_start);
331 connect(m_start, TQ_SIGNAL(positionDirectlyChanged()), TQ_SIGNAL(
contentsChanged()));
332 connect(m_end, TQ_SIGNAL(positionDirectlyChanged()), TQ_SIGNAL(
contentsChanged()));
334 connect(m_start, TQ_SIGNAL(
positionChanged()), TQ_SLOT(slotEvaluateChanged()));
335 connect(m_end, TQ_SIGNAL(
positionChanged()), TQ_SLOT(slotEvaluateChanged()));
336 connect(m_start, TQ_SIGNAL(
positionUnChanged()), TQ_SLOT(slotEvaluateUnChanged()));
337 connect(m_end, TQ_SIGNAL(
positionUnChanged()), TQ_SLOT(slotEvaluateUnChanged()));
338 connect(m_start, TQ_SIGNAL(positionDeleted()), TQ_SIGNAL(
boundaryDeleted()));
339 connect(m_end, TQ_SIGNAL(positionDeleted()), TQ_SIGNAL(
boundaryDeleted()));
342KateSuperRange::~KateSuperRange()
411 if (!
includes(cursor))
return false;
413 if (!childrenListObject().isEmpty())
414 for (TQObjectListIt it(childrenListObject()); *it; ++it)
415 if ((*it)->inherits(
"KateSuperRange"))
447void KateSuperRange::slotEvaluateChanged()
449 if (sender() == 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;
485void KateSuperRange::slotEvaluateUnChanged()
487 if (sender() == m_start) {
491 evaluateEliminated();
492 m_endChanged =
false;
502 if (m_startChanged) {
504 evaluateEliminated();
505 m_startChanged =
false;
514 m_evaluate = !m_evaluate;
517void KateSuperRange::slotTagRange()
522void KateSuperRange::evaluateEliminated()
531void KateSuperRange::evaluatePositionChanged()
539int KateSuperCursorList::compareItems(TQPtrCollection::Item item1, TQPtrCollection::Item item2)
541 if (*(
static_cast<KateSuperCursor*
>(item1)) == *(
static_cast<KateSuperCursor*
>(item2)))
544 return *(
static_cast<KateSuperCursor*
>(item1)) < *(
static_cast<KateSuperCursor*
>(item2)) ? -1 : 1;
547KateSuperRangeList::KateSuperRangeList(
bool autoManage, TQObject* parent,
const char* name)
548 : TQObject(parent,
name)
549 , m_autoManage(autoManage)
551 , m_trackingBoundaries(false)
553 setAutoManage(autoManage);
556KateSuperRangeList::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);
565void KateSuperRangeList::appendList(
const TQPtrList<KateSuperRange>& rangeList)
567 for (TQPtrListIterator<KateSuperRange> it = rangeList; *it; ++it)
571void KateSuperRangeList::clear()
573 for (KateSuperRange* range = first(); range; range =
next())
574 emit rangeEliminated(range);
576 TQPtrList<KateSuperRange>::clear();
579void KateSuperRangeList::connectAll()
583 for (KateSuperRange* range = first(); range; range =
next()) {
584 connect(range, TQ_SIGNAL(destroyed(TQObject*)), TQ_SLOT(slotDeleted(TQObject*)));
585 connect(range, TQ_SIGNAL(eliminated()), TQ_SLOT(slotEliminated()));
590bool KateSuperRangeList::autoManage()
const
595void KateSuperRangeList::setAutoManage(
bool autoManage)
597 m_autoManage = autoManage;
598 setAutoDelete(m_autoManage);
601TQPtrList<KateSuperRange> KateSuperRangeList::rangesIncluding(
const KateTextCursor& cursor)
605 TQPtrList<KateSuperRange> ret;
607 for (KateSuperRange* r = first(); r; r =
next())
608 if (r->includes(cursor))
614TQPtrList<KateSuperRange> KateSuperRangeList::rangesIncluding(uint line)
618 TQPtrList<KateSuperRange> ret;
620 for (KateSuperRange* r = first(); r; r =
next())
621 if (r->includes(line))
627bool KateSuperRangeList::rangesInclude(
const KateTextCursor& cursor)
629 for (KateSuperRange* r = first(); r; r =
next())
630 if (r->includes(cursor))
636void KateSuperRangeList::slotEliminated()
639 KateSuperRange* range =
static_cast<KateSuperRange*
>(
const_cast<TQObject*
>(sender()));
640 emit rangeEliminated(range);
642 if (m_trackingBoundaries) {
643 m_columnBoundaries.removeRef(range->m_start);
644 m_columnBoundaries.removeRef(range->m_end);
655void KateSuperRangeList::slotDeleted(TQObject* range)
658 KateSuperRange* r =
static_cast<KateSuperRange*
>(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;
679 for (KateSuperRange* r = first(); r; r =
next()) {
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();
698 KateSuperCursor* current = m_columnBoundaries.current();
702 while (m_columnBoundaries.next())
703 if (*(m_columnBoundaries.current()) != *current)
706 return m_columnBoundaries.current();
711 return m_columnBoundaries.current();
714int 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()) {
720 return static_cast<KateSuperRange*
>(item1)->superEnd() <
static_cast<KateSuperRange*
>(item2)->superEnd() ? -1 : 1;
724 return static_cast<KateSuperRange*
>(item1)->superStart() <
static_cast<KateSuperRange*
>(item2)->superStart() ? -1 : 1;
727TQPtrCollection::Item KateSuperRangeList::newItem(TQPtrCollection::Item d)
730 connect(
static_cast<KateSuperRange*
>(d), TQ_SIGNAL(destroyed(TQObject*)), TQ_SLOT(slotDeleted(TQObject*)));
731 connect(
static_cast<KateSuperRange*
>(d), TQ_SIGNAL(eliminated()), TQ_SLOT(slotEliminated()));
732 connect(
static_cast<KateSuperRange*
>(d), TQ_SIGNAL(tagRange(KateSuperRange*)), TQ_SIGNAL(tagRange(KateSuperRange*)));
735 static_cast<KateSuperRange*
>(d)->slotTagRange();
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);
Cursor class with a pointer to its document.
Possible additional features:
void setMoveOnInsert(bool moveOnInsert)
Change the behavior of the cursor when text is inserted at the cursor.
void charDeletedAfter()
The character immediately after the cursor was deleted.
void charInsertedAt()
A character was inserted immediately before the cursor.
void positionDeleted()
The cursor's surrounding characters were both deleted simultaneously.
void positionDirectlyChanged()
The cursor's position was directly changed by the program.
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,...
void positionChanged()
The cursor's position was changed.
bool atStartOfLine() const
void charDeletedBefore()
The character immediately before the cursor was deleted.
bool moveOnInsert() const
Returns how this cursor behaves when text is inserted at the cursor.
void positionUnChanged()
Athough an edit took place, the cursor's position was unchanged.
virtual bool isValid() const
Start and end must be valid and start <= end.
KateSuperCursor & superEnd()
Returns the super end cursor.
bool boundaryOn(uint lineNum) const
Returns whether there is a boundary of this range on line.
void contentsChanged()
The contents of the range changed.
void eliminated()
The range now contains no characters (ie.
KateSuperRange(KateSuperCursor *start, KateSuperCursor *end, TQObject *parent=0L, const char *name=0L)
Constructor.
bool includes(const KateTextCursor &cursor) const
Returns true if the range includes cursor 's character.
int behaviour() const
Returns how this range reacts to characters inserted immediately outside the range.
KateSuperCursor & superStart()
Returns the super start cursor.
bool includesWholeLine(uint lineNum) const
Returns true if the range totally encompasses line.
@ DoNotExpand
Don't expand to encapsulate new characters in either direction. This is the default.
@ ExpandRight
Expand to encapsulate new characters to the right of the range.
@ ExpandLeft
Expand to encapsulate new characters to the left of the range.
void positionChanged()
More interesting signals that aren't worth implementing here: firstCharDeleted: start()charDeleted() ...
void boundaryDeleted()
Either cursor's surrounding characters were both deleted.
void tagRange(KateSuperRange *range)
Indicates the region needs re-drawing.
void positionUnChanged()
The range's position was unchanged.
bool owns(const KateTextCursor &cursor) const
This is for use where the ranges are used in a heirachy, ie.
bool boundaryAt(const KateTextCursor &cursor) const
Returns whether cursor is the site of a boundary of this range.
void setBehaviour(int behaviour)
Determine how the range should react to characters inserted immediately outside the range.
Simple cursor class with no document pointer.
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)
Kate namespace All classes in this namespace must stay BC during one major release series (e....
const TDEShortcut & next()
TQString name(StdAccel id)
const TDEShortcut & end()