kate Library API Documentation

katecodefoldinghelpers.h

00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00016    Boston, MA 02111-1307, USA.
00017 */
00018 
00019 #ifndef _KATE_CODEFOLDING_HELPERS_
00020 #define _KATE_CODEFOLDING_HELPERS_
00021 
00022 //BEGIN INCLUDES + FORWARDS
00023 #include <qptrlist.h>
00024 #include <qvaluelist.h>
00025 #include <qobject.h>
00026 #include <qintdict.h>
00027 
00028 class KateBuffer;
00029 
00030 class QString;
00031 //END
00032 
00033 class KateHiddenLineBlock
00034 {
00035   public:
00036     unsigned int start;
00037     unsigned int length;
00038 };
00039 
00040 class KateLineInfo
00041 {
00042   public:
00043     bool topLevel;
00044     bool startsVisibleBlock;
00045     bool startsInVisibleBlock;
00046     bool endsBlock;
00047     bool invalidBlockEnd;
00048 };
00049 
00050 class KateCodeFoldingNode
00051 {
00052   public:
00053     KateCodeFoldingNode();
00054     KateCodeFoldingNode(KateCodeFoldingNode *par, signed char typ, unsigned int sLRel);
00055     ~KateCodeFoldingNode();
00056 
00057     inline QPtrList<KateCodeFoldingNode> *childnodes ()
00058     {
00059       if (!m_childnodes)
00060       {
00061         m_childnodes = new QPtrList<KateCodeFoldingNode>;
00062         m_childnodes->setAutoDelete (true);
00063       }
00064 
00065       return m_childnodes;
00066     }
00067 
00068     inline bool hasChildNodes ()
00069     {
00070       if (!m_childnodes)
00071         return false;
00072 
00073       return !m_childnodes->isEmpty ();
00074     }
00075 
00076     // temporary public to avoid friend an be able to disallow the access of m_childnodes directly ;)
00077     KateCodeFoldingNode                *parentNode;
00078     unsigned int startLineRel;
00079     unsigned int endLineRel;
00080 
00081     bool startLineValid;
00082     bool endLineValid;
00083 
00084     signed char type;                // 0 -> toplevel / invalid
00085     bool visible;
00086     bool deleteOpening;
00087     bool deleteEnding;
00088 
00089   protected:
00090     QPtrList<KateCodeFoldingNode>    *m_childnodes;
00091 };
00092 
00093 
00094 class KateCodeFoldingTree : public QObject, public KateCodeFoldingNode
00095 {
00096   Q_OBJECT
00097 
00098   public:
00099     KateCodeFoldingTree (KateBuffer *buffer);
00100     ~KateCodeFoldingTree ();
00101 
00102     KateCodeFoldingNode *findNodeForLine (unsigned int line);
00103 
00104     unsigned int getRealLine         (unsigned int virtualLine);
00105     unsigned int getVirtualLine      (unsigned int realLine);
00106     unsigned int getHiddenLinesCount (unsigned int docLine);
00107 
00108     bool isTopLevel (unsigned int line);
00109 
00110     void lineHasBeenInserted (unsigned int line);
00111     void lineHasBeenRemoved  (unsigned int line);
00112     void debugDump ();
00113     void getLineInfo (KateLineInfo *info,unsigned int line);
00114 
00115     unsigned int getStartLine (KateCodeFoldingNode *node);
00116 
00117     void fixRoot (int endLRel);
00118     void clear ();
00119 
00120   private:
00121     KateBuffer *m_buffer;
00122 
00123     QIntDict<unsigned int> lineMapping;
00124     QIntDict<bool>         dontIgnoreUnchangedLines;
00125 
00126     QPtrList<KateCodeFoldingNode> markedForDeleting;
00127     QPtrList<KateCodeFoldingNode> nodesForLine;
00128     QValueList<KateHiddenLineBlock>   hiddenLines;
00129 
00130     unsigned int hiddenLinesCountCache;
00131     bool         something_changed;
00132     bool         hiddenLinesCountCacheValid;
00133 
00134     static bool trueVal;
00135 
00136     KateCodeFoldingNode *findNodeForLineDescending (KateCodeFoldingNode *, unsigned int, unsigned int, bool oneStepOnly=false);
00137 
00138     bool correctEndings (signed char data, KateCodeFoldingNode *node, unsigned int line, int insertPos);
00139 
00140     void dumpNode    (KateCodeFoldingNode *node,QString prefix);
00141     void addOpening  (KateCodeFoldingNode *node, signed char nType,QMemArray<signed char>* list, unsigned int line);
00142     void addOpening_further_iterations (KateCodeFoldingNode *node,signed char nType, QMemArray<signed char>*
00143                                         list,unsigned int line,int current,unsigned int startLine);
00144 
00145     void incrementBy1 (KateCodeFoldingNode *node, KateCodeFoldingNode *after);
00146     void decrementBy1 (KateCodeFoldingNode *node, KateCodeFoldingNode *after);
00147 
00148     void cleanupUnneededNodes (unsigned int line);
00149 
00153     bool removeEnding (KateCodeFoldingNode *node,unsigned int line);
00154 
00158     bool removeOpening (KateCodeFoldingNode *node,unsigned int line);
00159 
00160     void findAndMarkAllNodesforRemovalOpenedOrClosedAt (unsigned int line);
00161     void findAllNodesOpenedOrClosedAt (unsigned int line);
00162 
00163     void addNodeToFoundList  (KateCodeFoldingNode *node,unsigned int line,int childpos);
00164     void addNodeToRemoveList (KateCodeFoldingNode *node,unsigned int line);
00165     void addHiddenLineBlock  (KateCodeFoldingNode *node,unsigned int line);
00166 
00167     bool existsOpeningAtLineAfter(unsigned int line, KateCodeFoldingNode *node);
00168 
00169     void dontDeleteEnding  (KateCodeFoldingNode*);
00170     void dontDeleteOpening (KateCodeFoldingNode*);
00171 
00172     void updateHiddenSubNodes (KateCodeFoldingNode *node);
00173     void moveSubNodesUp (KateCodeFoldingNode *node);
00174 
00175   public slots:
00176     void updateLine (unsigned int line,QMemArray<signed char>* regionChanges, bool *updated, bool changed);
00177     void toggleRegionVisibility (unsigned int);
00178     void collapseToplevelNodes ();
00179     void expandToplevelNodes (int numLines);
00180     int collapseOne (int realLine);
00181     void expandOne  (int realLine, int numLines);
00185     void ensureVisible( uint line );
00186 
00187   signals:
00188     void setLineVisible (unsigned int, bool);
00189     void regionVisibilityChangedAt  (unsigned int);
00190     void regionBeginEndAddedRemoved (unsigned int);
00191 };
00192 
00193 #endif
00194 
00195 // 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.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Jan 15 13:35:02 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003