1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr> 4 ** 5 ** This file is part of the Edyuk project <http://edyuk.org> 6 ** 7 ** This file may be used under the terms of the GNU General Public License 8 ** version 3 as published by the Free Software Foundation and appearing in the 9 ** file GPL.txt included in the packaging of this file. 10 ** 11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 ** 14 ****************************************************************************/ 15 16 #ifndef Header_QDocument_Cursor_P 17 #define Header_QDocument_Cursor_P 18 19 #include "qce-config.h" 20 21 /*! 22 \file qdocumentcursor_p.h 23 \brief Definition of QDocumentCursorHandle 24 */ 25 26 #include "qdocumentcursor.h" 27 28 #include <QStack> 29 30 #include <QAtomicInt> 31 32 class QPoint; 33 class QPolygon; 34 35 class QDocument; 36 class QDocumentLine; 37 class QDocumentPrivate; 38 class QDocumentCommand; 39 class QDocumentCommandBlock; 40 41 class QCE_EXPORT QDocumentCursorHandle 42 { 43 friend class QDocumentCursor; 44 friend class QDocumentPrivate; 45 friend class QDocumentCommand; 46 47 public: 48 enum Flags 49 { 50 Silent = 1, 51 ColumnMemory = 2, 52 MoveWithinWrapped = 4, 53 AutoErasable = 0x100, 54 AutoUpdated = 0x200, 55 AutoUpdateKeepBegin = 0x400, 56 AutoUpdateKeepEnd = 0x800 57 }; 58 59 QDocument* document() const; 60 61 bool atEnd() const; 62 bool atStart() const; 63 64 bool atBlockEnd() const; 65 bool atBlockStart() const; 66 67 bool atLineEnd() const; 68 bool atLineStart() const; 69 70 bool hasSelection() const; 71 bool isForwardSelection() const; 72 73 bool isSilent() const; 74 void setSilent(bool y); 75 76 bool isAutoUpdated() const; 77 void setAutoUpdated(bool y); 78 79 bool isAutoErasable() const; 80 void setAutoErasable(bool y); 81 82 83 QDocumentLine line() const; 84 QDocumentLine anchorLine() const; 85 86 int lineNumber() const; 87 int columnNumber() const; 88 89 int anchorLineNumber() const; 90 int anchorColumnNumber() const; 91 92 int startLineNumber() const; 93 int startColumnNumber() const; 94 95 int endLineNumber() const; 96 int endColumnNumber() const; 97 98 int visualColumnNumber() const; 99 100 void setLineNumber(int l, int m = QDocumentCursor::MoveAnchor); 101 void setColumnNumber(int c, int m = QDocumentCursor::MoveAnchor); 102 void setAnchorLineNumber(int l); 103 void setAnchorColumnNumber(int c); 104 105 QPointF documentPosition() const; 106 QPointF anchorDocumentPosition() const; 107 108 QPolygonF documentRegion() const; 109 110 void shift(int offset); 111 void setPosition(int pos, int m); 112 bool movePosition(int offset, int op, const QDocumentCursor::MoveMode& m); 113 114 void insertText(const QString& s, bool keepAnchor = false); 115 116 QChar nextChar() const; 117 QChar previousChar() const; 118 119 void eraseLine(); 120 void deleteChar(); 121 void deletePreviousChar(); 122 123 QDocumentCursor selectionStart() const; 124 QDocumentCursor selectionEnd() const; 125 QDocumentCursor anchorCursor() const; 126 127 bool eq(const QDocumentCursorHandle *h); 128 bool lt(const QDocumentCursorHandle *h); 129 bool gt(const QDocumentCursorHandle *h); 130 131 QString selectedText() const; 132 133 void clearSelection(); 134 void flipSelection(); 135 void removeSelectedText(bool keepAnchor = false); 136 void replaceSelectedText(const QString& text); 137 138 void select(QDocumentCursor::SelectionType t); 139 void expandSelect(QDocumentCursor::SelectionType t); 140 void setSelectionBoundary(const QDocumentCursor& c); 141 void select(int line, int column, int lineTo = -1, int columnTo = -1); 142 143 bool isWithinSelection(const QDocumentCursor& c) const; 144 QDocumentCursor intersect(const QDocumentCursor& c) const; 145 146 void beginBoundary(int& begline, int& begcol) const; 147 void endBoundary(int& endline, int& endcol) const; 148 void substractBoundaries(int lbeg, int cbeg, int lend, int cend); 149 void boundaries(int& begline, int& begcol, int& endline, int& endcol) const; 150 void intersectBoundaries(int& lbeg, int& cbeg, int& lend, int& cend) const; 151 void intersectBoundaries(QDocumentCursorHandle *h, int& lbeg, int& cbeg, int& lend, int& cend) const; 152 bool equalBoundaries(const QDocumentCursorHandle* c); 153 bool equal(const QDocumentCursorHandle* c); 154 155 156 void getMatchingPair(QDocumentCursor& from, QDocumentCursor& to, bool maximal) const; 157 158 void beginEditBlock(); 159 void endEditBlock(); 160 161 void moveTo(int line, int column, const QDocumentCursor::MoveMode& m = QDocumentCursor::MoveAnchor); 162 void moveTo(const QDocumentCursor &c, const QDocumentCursor::MoveMode& m ); 163 164 void copy(const QDocumentCursorHandle *c); 165 166 void refreshColumnMemory(); 167 bool hasColumnMemory() const; 168 void setColumnMemory(bool y); 169 170 bool isRTL() const; 171 172 virtual void execute(QDocumentCommand *c); 173 ref()174 inline void ref() { m_ref.ref(); } deref()175 inline void deref() { if ( !m_ref.deref() ) delete this; } 176 hasFlag(int f)177 inline bool hasFlag(int f) const { return m_flags & f; } setFlag(int f)178 inline void setFlag(int f) { m_flags |= f; } clearFlag(int f)179 inline void clearFlag(int f) { m_flags &= ~f; } 180 protected: 181 QDocumentCursorHandle(QDocument *d, int line = 0); 182 QDocumentCursorHandle(QDocument *d, int line, int column, int lineTo = -1, int columnTo = -1); 183 virtual ~QDocumentCursorHandle(); 184 185 QDocumentCursorHandle* clone(bool cloneAutoUpdatedFlag) const; 186 187 private: 188 int m_flags; 189 QDocument *m_doc; 190 191 QAtomicInt m_ref; 192 193 int m_begOffset, m_endOffset, m_savedX, m_begLine, m_endLine; //beg: cursor position, end: anchor position 194 QStack<QDocumentCommandBlock*> m_blocks; 195 }; 196 197 Q_DECLARE_TYPEINFO(QDocumentCursorHandle*, Q_PRIMITIVE_TYPE); 198 199 #endif // !_QDOCUMENT_CURSOR_P_H_ 200