katetextline.h
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2001-2003 Christoph Cullmann <cullmann@kde.org> 00003 Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org> 00004 00005 Based on: 00006 KateTextLine : Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de> 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Library General Public 00010 License version 2 as published by the Free Software Foundation. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef __KATE_TEXTLINE_H__ 00024 #define __KATE_TEXTLINE_H__ 00025 00026 #include <ksharedptr.h> 00027 00028 #include <qmemarray.h> 00029 #include <qstring.h> 00030 00031 class KateRenderer; 00032 class QTextStream; 00033 00041 class KateTextLine : public KShared 00042 { 00043 public: 00047 typedef KSharedPtr<KateTextLine> Ptr; 00048 00049 public: 00053 enum Flags 00054 { 00055 flagNoOtherData = 1, // ONLY INTERNAL USE, NEVER EVER SET THAT !!!! 00056 flagHlContinue = 2, 00057 flagAutoWrapped = 4, 00058 flagFoldingColumnsOutdated = 8, 00059 flagNoIndentationBasedFolding = 16, 00060 flagNoIndentationBasedFoldingAtStart = 32 00061 }; 00062 00063 public: 00069 KateTextLine (); 00070 00074 ~KateTextLine (); 00075 00079 public: 00083 inline void setFoldingColumnsOutdated(bool set) { if (set) m_flags |= KateTextLine::flagFoldingColumnsOutdated; else m_flags&= 00084 (~KateTextLine::flagFoldingColumnsOutdated);} 00085 00090 inline bool foldingColumnsOutdated() { return m_flags & KateTextLine::flagFoldingColumnsOutdated; } 00091 00092 00097 inline uint length() const { return m_text.length(); } 00098 00103 inline bool hlLineContinue () const { return m_flags & KateTextLine::flagHlContinue; } 00104 00109 inline bool isAutoWrapped () const { return m_flags & KateTextLine::flagAutoWrapped; } 00110 00115 int firstChar() const; 00116 00121 int lastChar() const; 00122 00129 int nextNonSpaceChar(uint pos) const; 00130 00137 int previousNonSpaceChar(uint pos) const; 00138 00145 inline QChar getChar (uint pos) const { return m_text[pos]; } 00146 00151 inline const QChar *text() const { return m_text.unicode(); } 00152 00167 inline uchar *attributes () const { return m_attributes.data(); } 00168 00173 inline const QString& string() const { return m_text; } 00174 00181 inline QString string(uint startCol, uint length) const 00182 { return m_text.mid(startCol, length); } 00183 00188 const QChar *firstNonSpace() const; 00189 00195 uint indentDepth (uint tabwidth) const; 00196 00204 int cursorX(uint pos, uint tabChars) const; 00205 00211 uint lengthWithTabs (uint tabChars) const; 00212 00219 bool stringAtPos(uint pos, const QString& match) const; 00220 00226 bool startingWith(const QString& match) const; 00227 00233 bool endingWith(const QString& match) const; 00234 00245 bool searchText (uint startCol, const QString &text, 00246 uint *foundAtCol, uint *matchLen, 00247 bool casesensitive = true, 00248 bool backwards = false); 00249 00259 bool searchText (uint startCol, const QRegExp ®exp, 00260 uint *foundAtCol, uint *matchLen, 00261 bool backwards = false); 00262 00271 inline uchar attribute (uint pos) const 00272 { 00273 if (pos < m_attributes.size()) return m_attributes[pos]; 00274 return 0; 00275 } 00276 00281 inline const QMemArray<short> &ctxArray () const { return m_ctx; }; 00282 00286 inline const bool noIndentBasedFolding() const { return m_flags & KateTextLine::flagNoIndentationBasedFolding; }; 00287 inline const bool noIndentBasedFoldingAtStart() const { return m_flags & KateTextLine::flagNoIndentationBasedFoldingAtStart; }; 00292 inline const QMemArray<uint> &foldingListArray () const { return m_foldingList; }; 00293 00298 inline const QMemArray<unsigned short> &indentationDepthArray () const { return m_indentationDepth; }; 00299 00307 void insertText (uint pos, uint insLen, const QChar *insText, uchar *insAttribs = 0); 00308 00314 void removeText (uint pos, uint delLen); 00315 00320 void truncate(uint newLen); 00321 00326 inline void setHlLineContinue (bool cont) 00327 { 00328 if (cont) m_flags = m_flags | KateTextLine::flagHlContinue; 00329 else m_flags = m_flags & ~ KateTextLine::flagHlContinue; 00330 } 00331 00336 inline void setAutoWrapped (bool wrapped) 00337 { 00338 if (wrapped) m_flags = m_flags | KateTextLine::flagAutoWrapped; 00339 else m_flags = m_flags & ~ KateTextLine::flagAutoWrapped; 00340 } 00341 00346 inline void setContext (QMemArray<short> &val) { m_ctx.assign (val); } 00347 00351 inline void setNoIndentBasedFolding(bool val) 00352 { 00353 if (val) m_flags = m_flags | KateTextLine::flagNoIndentationBasedFolding; 00354 else m_flags = m_flags & ~ KateTextLine::flagNoIndentationBasedFolding; 00355 } 00356 00357 inline void setNoIndentBasedFoldingAtStart(bool val) 00358 { 00359 if (val) m_flags = m_flags | KateTextLine::flagNoIndentationBasedFoldingAtStart; 00360 else m_flags = m_flags & ~ KateTextLine::flagNoIndentationBasedFoldingAtStart; 00361 } 00362 00367 inline void setFoldingList (QMemArray<uint> &val) { m_foldingList.assign (val); m_foldingList.detach(); } 00368 00373 inline void setIndentationDepth (QMemArray<unsigned short> &val) { m_indentationDepth.assign (val); } 00374 00378 public: 00384 inline uint dumpSize (bool withHighlighting) const 00385 { 00386 return ( 1 00387 + sizeof(uint) 00388 + (m_text.length() * sizeof(QChar)) 00389 + ( withHighlighting ? 00390 ( (3 * sizeof(uint)) 00391 + (m_text.length() * sizeof(uchar)) 00392 + (m_ctx.size() * sizeof(short)) 00393 + (m_foldingList.size() * sizeof(uint)) 00394 + (m_indentationDepth.size() * sizeof(unsigned short)) 00395 ) : 0 00396 ) 00397 ); 00398 } 00399 00407 char *dump (char *buf, bool withHighlighting) const; 00408 00415 char *restore (char *buf); 00416 00420 private: 00424 QString m_text; 00425 00431 QMemArray<uchar> m_attributes; 00432 00436 QMemArray<short> m_ctx; 00437 00441 QMemArray<uint> m_foldingList; 00442 00446 QMemArray<unsigned short> m_indentationDepth; 00447 00451 uchar m_flags; 00452 }; 00453 00454 #endif 00455 00456 // kate: space-indent on; indent-width 2; replace-tabs on;