kate Library API Documentation

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., 59 Temple Place - Suite 330,
00020    Boston, MA 02111-1307, 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 
00040 class KateTextLine : public KShared
00041 {
00042   public:
00046     typedef KSharedPtr<KateTextLine> Ptr;
00047 
00048   public:
00052     enum Flags
00053     {
00054       flagNoOtherData = 0x1, // ONLY INTERNAL USE, NEVER EVER SET THAT !!!!
00055       flagHlContinue = 0x2,
00056       flagAutoWrapped = 0x4,
00057       flagFoldingColumnsOutdated=0x8
00058     };
00059 
00060   public:
00066     KateTextLine ();
00067 
00071     ~KateTextLine ();
00072 
00076   public:
00080     inline void setFoldingColumnsOutdated(bool set) { if (set) m_flags |= KateTextLine::flagFoldingColumnsOutdated; else m_flags&=
00081                                                       (~KateTextLine::flagFoldingColumnsOutdated);}
00082 
00087      inline bool foldingColumnsOutdated() { return m_flags & KateTextLine::flagFoldingColumnsOutdated; }
00088 
00089 
00094     inline uint length() const { return m_text.length(); }
00095 
00100     inline bool hlLineContinue () const { return m_flags & KateTextLine::flagHlContinue; }
00101 
00106     inline bool isAutoWrapped () const { return m_flags & KateTextLine::flagAutoWrapped; }
00107 
00112     int firstChar() const;
00113 
00118     int lastChar() const;
00119 
00126     int nextNonSpaceChar(uint pos) const;
00127 
00134     int previousNonSpaceChar(uint pos) const;
00135 
00142     inline QChar getChar (uint pos) const { return m_text[pos]; }
00143 
00148     inline const QChar *text() const { return m_text.unicode(); }
00149 
00164     inline uchar *attributes () const { return m_attributes.data(); }
00165 
00170     inline const QString& string() const { return m_text; }
00171 
00178     inline QString string(uint startCol, uint length) const
00179     { return m_text.mid(startCol, length); }
00180 
00193     void stringAsHtml(uint startCol, uint length, KateRenderer *renderer, QTextStream *outputStream) const;
00194 
00204     void stringAsHtml(KateRenderer *renderer, QTextStream *outputStream) const
00205     { stringAsHtml(0,m_text.length(),renderer, outputStream);}
00206     
00211     const QChar *firstNonSpace() const;
00212 
00218     uint indentDepth (uint tabwidth) const;
00219 
00227     int cursorX(uint pos, uint tabChars) const;
00228 
00234     uint lengthWithTabs (uint tabChars) const;
00235 
00242     bool stringAtPos(uint pos, const QString& match) const;
00243 
00249     bool startingWith(const QString& match) const;
00250 
00256     bool endingWith(const QString& match) const;
00257 
00268     bool searchText (uint startCol, const QString &text,
00269                      uint *foundAtCol, uint *matchLen,
00270                      bool casesensitive = true,
00271                      bool backwards = false);
00272 
00282     bool searchText (uint startCol, const QRegExp &regexp,
00283                      uint *foundAtCol, uint *matchLen,
00284                      bool backwards = false);
00285 
00294     inline uchar attribute (uint pos) const
00295     {
00296       if (pos < m_attributes.size()) return m_attributes[pos];
00297       return 0;
00298     }
00299 
00304     inline const QMemArray<short> &ctxArray () const { return m_ctx; };
00305 
00310     inline const QMemArray<uint> &foldingListArray () const { return m_foldingList; };
00311 
00316     inline const QMemArray<unsigned short> &indentationDepthArray () const { return m_indentationDepth; };
00317 
00325     void insertText (uint pos, uint insLen, const QChar *insText, uchar *insAttribs = 0);
00326 
00332     void removeText (uint pos, uint delLen);
00333 
00338     void truncate(uint newLen);
00339 
00344     inline void setHlLineContinue (bool cont)
00345     {
00346       if (cont) m_flags = m_flags | KateTextLine::flagHlContinue;
00347       else m_flags = m_flags & ~ KateTextLine::flagHlContinue;
00348     }
00349 
00354     inline void setAutoWrapped (bool wrapped)
00355     {
00356       if (wrapped) m_flags = m_flags | KateTextLine::flagAutoWrapped;
00357       else m_flags = m_flags & ~ KateTextLine::flagAutoWrapped;
00358     }
00359 
00364     inline void setContext (QMemArray<short> &val) { m_ctx.assign (val); }
00365 
00370     inline void setFoldingList (QMemArray<uint> &val) { m_foldingList.assign (val); m_foldingList.detach(); }
00371 
00376     inline void setIndentationDepth (QMemArray<unsigned short> &val) { m_indentationDepth.assign (val); }
00377 
00381   public:
00387     inline uint dumpSize (bool withHighlighting) const
00388     {
00389       return ( 1
00390                + sizeof(uint)
00391                + (m_text.length() * sizeof(QChar))
00392                + ( withHighlighting ?
00393                      ( (3 * sizeof(uint))
00394                        + (m_text.length() * sizeof(uchar))
00395                        + (m_ctx.size() * sizeof(short))
00396                        + (m_foldingList.size() * sizeof(uint))
00397                        + (m_indentationDepth.size() * sizeof(unsigned short))
00398                      ) : 0
00399                  )
00400              );
00401     }
00402 
00410     char *dump (char *buf, bool withHighlighting) const;
00411 
00418     char *restore (char *buf);
00419 
00423   private:
00427     QString m_text;
00428 
00434     QMemArray<uchar> m_attributes;
00435 
00439     QMemArray<short> m_ctx;
00440 
00444     QMemArray<uint> m_foldingList;
00445 
00449     QMemArray<unsigned short> m_indentationDepth;
00450 
00454     uchar m_flags;
00455 };
00456 
00457 #endif
00458 
00459 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE Logo
This file is part of the documentation for kate Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Apr 28 01:42:34 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003