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 
00038 class KateTextLine : public KShared
00039 {
00040   public:
00044     typedef KSharedPtr<KateTextLine> Ptr;
00045 
00046   public:
00050     enum Flags
00051     {
00052       flagNoOtherData = 0x1, // ONLY INTERNAL USE, NEVER EVER SET THAT !!!!
00053       flagHlContinue = 0x2,
00054       flagVisible = 0x4,
00055       flagAutoWrapped = 0x8
00056     };
00057 
00058   public:
00064     KateTextLine ();
00065 
00069     ~KateTextLine ();
00070 
00074   public:
00079     inline uint length() const { return m_text.length(); }
00080 
00085     inline bool hlLineContinue () const { return m_flags & KateTextLine::flagHlContinue; }
00086 
00091     inline bool isVisible () const { return m_flags & KateTextLine::flagVisible; }
00092 
00097     inline bool isAutoWrapped () const { return m_flags & KateTextLine::flagAutoWrapped; }
00098 
00103     int firstChar() const;
00104 
00109     int lastChar() const;
00110 
00117     int nextNonSpaceChar(uint pos) const;
00118 
00125     int previousNonSpaceChar(uint pos) const;
00126 
00133     inline QChar getChar (uint pos) const { return m_text[pos]; }
00134 
00139     inline const QChar *text() const { return m_text.unicode(); }
00140 
00145     inline uchar *attributes () const { return m_attributes.data(); }
00146 
00151     inline const QString& string() const { return m_text; }
00152 
00159     inline QString string(uint startCol, uint length) const
00160     { return m_text.mid(startCol, length); }
00161 
00166     const QChar *firstNonSpace() const;
00167 
00173     uint indentDepth (uint tabwidth) const;
00174 
00182     int cursorX(uint pos, uint tabChars) const;
00183 
00189     uint lengthWithTabs (uint tabChars) const;
00190 
00197     bool stringAtPos(uint pos, const QString& match) const;
00198 
00204     bool startingWith(const QString& match) const;
00205 
00211     bool endingWith(const QString& match) const;
00212 
00223     bool searchText (uint startCol, const QString &text,
00224                      uint *foundAtCol, uint *matchLen,
00225                      bool casesensitive = true,
00226                      bool backwards = false);
00227 
00237     bool searchText (uint startCol, const QRegExp &regexp,
00238                      uint *foundAtCol, uint *matchLen,
00239                      bool backwards = false);
00240 
00246     inline uchar attribute (uint pos) const
00247     {
00248       if (pos < m_attributes.size()) return m_attributes[pos];
00249       return 0;
00250     }
00251 
00256     inline const QMemArray<short> &ctxArray () const { return m_ctx; };
00257 
00262     inline const QMemArray<signed char> &foldingListArray () const { return m_foldingList; };
00263 
00268     inline const QMemArray<unsigned short> &indentationDepthArray () const { return m_indentationDepth; };
00269 
00277     void insertText (uint pos, uint insLen, const QChar *insText, uchar *insAttribs = 0);
00278 
00284     void removeText (uint pos, uint delLen);
00285 
00290     void truncate(uint newLen);
00291 
00296     inline void setHlLineContinue (bool cont)
00297     {
00298       if (cont) m_flags = m_flags | KateTextLine::flagHlContinue;
00299       else m_flags = m_flags & ~ KateTextLine::flagHlContinue;
00300     }
00301 
00306     inline void setVisible(bool val)
00307     {
00308       if (val) m_flags = m_flags | KateTextLine::flagVisible;
00309       else m_flags = m_flags & ~ KateTextLine::flagVisible;
00310     }
00311 
00316     inline void setAutoWrapped (bool wrapped)
00317     {
00318       if (wrapped) m_flags = m_flags | KateTextLine::flagAutoWrapped;
00319       else m_flags = m_flags & ~ KateTextLine::flagAutoWrapped;
00320     }
00321 
00328     void setAttribs(uchar attribute, uint start, uint end);
00329 
00334     inline void setContext (QMemArray<short> &val) { m_ctx.assign (val); }
00335 
00340     inline void setFoldingList (QMemArray<signed char> &val) { m_foldingList.assign (val); m_foldingList.detach(); }
00341 
00346     inline void setIndentationDepth (QMemArray<unsigned short> &val) { m_indentationDepth.assign (val); }
00347 
00351   public:
00357     inline uint dumpSize (bool withHighlighting) const
00358     {
00359       return ( 1
00360                + sizeof(uint)
00361                + (m_text.length() * sizeof(QChar))
00362                + ( withHighlighting ?
00363                      ( (3 * sizeof(uint))
00364                        + (m_text.length() * sizeof(uchar))
00365                        + (m_ctx.size() * sizeof(short))
00366                        + (m_foldingList.size() * sizeof(signed char))
00367                        + (m_indentationDepth.size() * sizeof(unsigned short))
00368                      ) : 0
00369                  )
00370              );
00371     }
00372 
00380     char *dump (char *buf, bool withHighlighting) const;
00381 
00388     char *restore (char *buf);
00389 
00393   private:
00397     QString m_text;
00398 
00402     QMemArray<uchar> m_attributes;
00403 
00407     QMemArray<short> m_ctx;
00408 
00412     QMemArray<signed char> m_foldingList;
00413 
00417     QMemArray<unsigned short> m_indentationDepth;
00418 
00422     uchar m_flags;
00423 };
00424 
00425 #endif
00426 
00427 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE Logo
This file is part of the documentation for kate Library Version 3.3.90.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 30 10:24:44 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003