QCodeEdit 2.2
|
00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr> 00004 ** 00005 ** This file is part of the Edyuk project <http://edyuk.org> 00006 ** 00007 ** This file may be used under the terms of the GNU General Public License 00008 ** version 3 as published by the Free Software Foundation and appearing in the 00009 ** file GPL.txt included in the packaging of this file. 00010 ** 00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00013 ** 00014 ****************************************************************************/ 00015 00016 #ifndef _QDOCUMENT_CURSOR_P_H_ 00017 #define _QDOCUMENT_CURSOR_P_H_ 00018 00019 #include "qce-config.h" 00020 00026 #include "qdocumentcursor.h" 00027 00028 #include <QStack> 00029 00030 #if QT_VERSION < 0x040400 00031 #include <QAtomic> 00032 #else 00033 #include <QAtomicInt> 00034 #endif 00035 00036 class QPoint; 00037 class QPolygon; 00038 00039 class QDocument; 00040 class QDocumentLine; 00041 class QDocumentPrivate; 00042 class QDocumentCommand; 00043 class QDocumentCommandBlock; 00044 00045 class QCE_EXPORT QDocumentCursorHandle 00046 { 00047 friend class QDocumentCursor; 00048 friend class QDocumentPrivate; 00049 friend class QDocumentCommand; 00050 00051 public: 00052 enum Flags 00053 { 00054 Silent = 1, 00055 ColumnMemory = 2, 00056 MoveWithinWrapped = 4 00057 }; 00058 00059 QDocument* document() const; 00060 00061 bool atEnd() const; 00062 bool atStart() const; 00063 00064 bool atBlockEnd() const; 00065 bool atBlockStart() const; 00066 00067 bool atLineEnd() const; 00068 bool atLineStart() const; 00069 00070 bool hasSelection() const; 00071 00072 bool isSilent() const; 00073 void setSilent(bool y); 00074 00075 bool isAutoUpdated() const; 00076 void setAutoUpdated(bool y); 00077 00078 QDocumentLine line() const; 00079 QDocumentLine anchorLine() const; 00080 00081 int lineNumber() const; 00082 int columnNumber() const; 00083 00084 int anchorLineNumber() const; 00085 int anchorColumnNumber() const; 00086 00087 int visualColumnNumber() const; 00088 00089 void setColumnNumber(int c, int m = QDocumentCursor::MoveAnchor); 00090 00091 QPoint documentPosition() const; 00092 QPoint anchorDocumentPosition() const; 00093 00094 QPolygon documentRegion() const; 00095 00096 int position() const; 00097 00098 void shift(int offset); 00099 void setPosition(int pos, int m); 00100 bool movePosition(int offset, int op, int m); 00101 00102 void insertText(const QString& s, bool keepAnchor = false); 00103 00104 QChar nextChar() const; 00105 QChar previousChar() const; 00106 00107 void eraseLine(); 00108 void deleteChar(); 00109 void deletePreviousChar(); 00110 00111 QDocumentCursor selectionStart() const; 00112 QDocumentCursor selectionEnd() const; 00113 00114 bool eq(const QDocumentCursorHandle *h); 00115 bool lt(const QDocumentCursorHandle *h); 00116 bool gt(const QDocumentCursorHandle *h); 00117 00118 QString selectedText() const; 00119 00120 void clearSelection(); 00121 void removeSelectedText(bool keepAnchor = false); 00122 void replaceSelectedText(const QString& text); 00123 00124 void select(QDocumentCursor::SelectionType t); 00125 void setSelectionBoundary(const QDocumentCursor& c); 00126 00127 bool isWithinSelection(const QDocumentCursor& c) const; 00128 QDocumentCursor intersect(const QDocumentCursor& c) const; 00129 00130 void beginBoundary(int& begline, int& begcol) const; 00131 void endBoundary(int& endline, int& endcol) const; 00132 void substractBoundaries(int lbeg, int cbeg, int lend, int cend); 00133 void boundaries(int& begline, int& begcol, int& endline, int& endcol) const; 00134 void intersectBoundaries(int& lbeg, int& cbeg, int& lend, int& cend) const; 00135 void intersectBoundaries(QDocumentCursorHandle *h, int& lbeg, int& cbeg, int& lend, int& cend) const; 00136 00137 void beginEditBlock(); 00138 void endEditBlock(); 00139 00140 void moveTo(int line, int column); 00141 void moveTo(const QDocumentCursor &c); 00142 00143 void copy(const QDocumentCursorHandle *c); 00144 00145 void refreshColumnMemory(); 00146 bool hasColumnMemory() const; 00147 void setColumnMemory(bool y); 00148 00149 virtual void execute(QDocumentCommand *c); 00150 00151 inline void ref() { m_ref.ref(); } 00152 inline void deref() { if ( m_ref ) m_ref.deref(); if ( !m_ref ) delete this; } 00153 00154 inline bool hasFlag(int f) const { return m_flags & f; } 00155 inline void setFlag(int f) { m_flags |= f; } 00156 inline void clearFlag(int f) { m_flags &= ~f; } 00157 00158 protected: 00159 QDocumentCursorHandle(QDocument *d, int line = 0); 00160 virtual ~QDocumentCursorHandle(); 00161 00162 QDocumentCursorHandle* clone() const; 00163 00164 private: 00165 int m_flags; 00166 QDocument *m_doc; 00167 #if QT_VERSION < 0x040400 00168 QBasicAtomic m_ref; 00169 #else 00170 QAtomicInt m_ref; 00171 #endif 00172 int m_begOffset, m_endOffset, m_max, m_begLine, m_endLine; 00173 QStack<QDocumentCommandBlock*> m_blocks; 00174 }; 00175 00176 Q_DECLARE_TYPEINFO(QDocumentCursorHandle*, Q_PRIMITIVE_TYPE); 00177 00178 #endif // !_QDOCUMENT_CURSOR_P_H_