kate Library API Documentation

katebuffer.h

00001 /* This file is part of the KDE libraries
00002    Copyright (c) 2000 Waldo Bastian <bastian@kde.org>
00003    Copyright (C) 2002-2004 Christoph Cullmann <cullmann@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #ifndef __KATE_BUFFER_H__
00021 #define __KATE_BUFFER_H__
00022 
00023 #include "katetextline.h"
00024 #include "katecodefoldinghelpers.h"
00025 
00026 #include <kvmallocator.h>
00027 
00028 #include <qptrlist.h>
00029 #include <qobject.h>
00030 #include <qtimer.h>
00031 #include <qvaluevector.h>
00032 
00033 class KateLineInfo;
00034 class KateDocument;
00035 class KateHighlighting;
00036 class KateBufBlockList;
00037 class KateBuffer;
00038 class KateFileLoader;
00039 
00040 class QTextCodec;
00041 
00049 class KateBufBlock
00050 {
00051   friend class KateBufBlockList;
00052 
00053   public:
00061     KateBufBlock ( KateBuffer *parent, KateBufBlock *prev = 0, KateBufBlock *next = 0,
00062                    KateFileLoader *stream = 0 );
00063     
00067     ~KateBufBlock ();
00068     
00069   private:
00074     void fillBlock (KateFileLoader *stream);
00075     
00076   public:
00080     enum State
00081     {
00082       stateSwapped = 0,
00083       stateClean = 1,
00084       stateDirty = 2
00085     };
00086     
00091     State state () const { return m_state; }
00092     
00093   public:
00101     KateTextLine::Ptr line(uint i);
00102     
00109     void insertLine(uint i, KateTextLine::Ptr line);
00110     
00116     void removeLine(uint i);
00117     
00122     void markDirty ();
00123   
00124   public:
00129     inline uint startLine () const { return m_startLine; };
00130     
00135     inline void setStartLine (uint line) { m_startLine = line; }
00136     
00141     inline uint endLine () const { return m_startLine + m_lines; }
00142     
00147     inline uint lines () const { return m_lines; }
00148 
00153     inline KateBufBlock *prev () { return m_prev; }
00154     
00159     inline KateBufBlock *next () { return m_next; }
00160   
00164   private:
00168     void swapIn ();
00169 
00173     void swapOut ();
00174             
00175   private:
00180     KateBufBlock::State m_state;
00181     
00185     uint m_startLine;
00186     
00190     uint m_lines;
00191 
00195     KVMAllocator::Block *m_vmblock;
00196     
00200     uint m_vmblockSize;
00201 
00205     QValueVector<KateTextLine::Ptr> m_stringList;
00206 
00210     KateBuffer* m_parent;
00211 
00215     KateBufBlock *m_prev;
00216     
00220     KateBufBlock *m_next;
00221     
00222   private:
00227     KateBufBlockList *list;
00228     
00232     KateBufBlock *listPrev;
00233     
00237     KateBufBlock *listNext;
00238 };
00239 
00248 class KateBufBlockList
00249 {
00250   public:
00254     KateBufBlockList ();
00255     
00256   public:
00261     inline uint count() const { return m_count; }
00262   
00267     inline KateBufBlock *first () { return m_first; };
00268     
00273     inline KateBufBlock *last () { return m_last; };
00274 
00280     inline bool isFirst (KateBufBlock *buf) { return m_first == buf; };
00281     
00287     inline bool isLast (KateBufBlock *buf) { return m_last == buf; };
00288         
00294     void append (KateBufBlock *buf);
00295     
00300     inline static void remove (KateBufBlock *buf)
00301     {
00302       if (buf->list)
00303         buf->list->removeInternal (buf);
00304     }
00305     
00306   private:
00311     void removeInternal (KateBufBlock *buf);
00312     
00313   private:
00317     uint m_count;
00318     
00322     KateBufBlock *m_first;
00323     
00327     KateBufBlock *m_last;
00328 };
00329 
00341 class KateBuffer : public QObject
00342 {
00343   Q_OBJECT
00344   
00345   friend class KateBufBlock;
00346   
00347   public:
00352     inline static uint maxLoadedBlocks () { return m_maxLoadedBlocks; }
00353     
00358     static void setMaxLoadedBlocks (uint count);
00359     
00360   private:
00364     static uint m_maxLoadedBlocks;
00365 
00366   public:
00371     KateBuffer (KateDocument *doc);
00372 
00376     ~KateBuffer ();
00377     
00378   public:
00382     void editStart ();
00383     
00387     void editEnd ();
00388     
00389   private:
00394     void editTagLine (uint line);
00395     
00400     void editRemoveTagLine (uint line);
00401     
00406     void editInsertTagLine (uint line);
00407   
00408   private:
00412     uint editSessionNumber;
00413     
00417     bool editIsRunning;
00418     
00422     uint editTagLineStart;
00423     
00427     uint editTagLineEnd;
00428     
00429   public:
00433     void clear();
00434   
00440     bool openFile (const QString &m_file);
00441     
00447     bool loadingBorked () const { return m_loadingBorked; }
00448 
00453     bool canEncode ();
00454 
00460     bool saveFile (const QString &m_file);
00461     
00462   public:
00466     inline KateTextLine::Ptr line(uint i)
00467     {
00468       KateBufBlock *buf = findBlock(i);
00469       if (!buf)
00470         return 0;
00471         
00472       if (i < m_lineHighlighted)
00473         return buf->line (i - buf->startLine());
00474       
00475       return line_internal (buf, i);
00476     }
00477     
00478   private:
00482      KateTextLine::Ptr line_internal (KateBufBlock *buf, uint i);
00483 
00484   public:
00488     inline KateTextLine::Ptr plainLine(uint i)
00489     {
00490       KateBufBlock *buf = findBlock(i);
00491       if (!buf)
00492         return 0;
00493     
00494       return buf->line(i - buf->startLine());
00495     }
00496     
00500     inline uint count() const { return m_lines; }
00501     
00502   private:
00508     KateBufBlock *findBlock (uint i, uint *index = 0)
00509     {
00510       // out of range !
00511       if (i >= m_lines)
00512         return 0;
00513         
00514       if ((m_blocks[m_lastFoundBlock]->startLine() <= i) && (m_blocks[m_lastFoundBlock]->endLine() > i))
00515       {
00516         if (index)
00517           (*index) = m_lastFoundBlock;
00518           
00519         return m_blocks[m_lastFoundBlock];
00520       }
00521       
00522       return findBlock_internal (i, index);
00523     }
00524     
00525     KateBufBlock *findBlock_internal (uint i, uint *index = 0);
00526     
00527   public:
00531     void changeLine(uint i);
00532   
00536     void insertLine(uint i, KateTextLine::Ptr line);
00537 
00541     void removeLine(uint i);
00542     
00543   public:
00544     inline uint countVisible () { return m_lines - m_regionTree.getHiddenLinesCount(m_lines); }
00545     
00546     inline uint lineNumber (uint visibleLine) { return m_regionTree.getRealLine (visibleLine); }
00547     
00548     inline uint lineVisibleNumber (uint line) { return m_regionTree.getVirtualLine (line); }
00549     
00550     inline void lineInfo (KateLineInfo *info, unsigned int line) { m_regionTree.getLineInfo(info,line); }
00551 
00552     inline uint tabWidth () const { return m_tabWidth; }
00553     
00554     inline KVMAllocator *vm () { return &m_vm; }
00555     
00556   public:
00557     void setTabWidth (uint w);  
00558 
00565     void setHighlight (KateHighlighting *highlight);
00566 
00567     KateHighlighting *highlight () { return m_highlight; };
00568     
00572     void invalidateHighlighting();
00573     
00574     KateCodeFoldingTree *foldingTree () { return &m_regionTree; };
00575     
00576   public slots:
00580     void setLineVisible (unsigned int lineNr, bool visible);
00581   
00582   private:
00595     bool doHighlight (KateBufBlock *buf, uint from, uint to, bool invalidate);
00596     
00597   signals:
00601     void codeFoldingUpdated();
00602 
00607     void tagLines(int start, int end);
00608 
00609   private:
00613     KateDocument *m_doc;
00614   
00618     uint m_lines;
00619     
00624     QValueVector<KateBufBlock*> m_blocks;
00625     
00629     uint m_lastInSyncBlock;
00630     
00634     uint m_lastFoundBlock;
00635 
00639     KVMAllocator m_vm;
00640 
00645     bool m_cacheReadError;
00646     bool m_cacheWriteError;
00647     
00651     bool m_loadingBorked;
00652 
00656   private:
00660     KateHighlighting *m_highlight;
00661     
00665     KateCodeFoldingTree m_regionTree;
00666     
00667     // for the scrapty indent sensitive langs
00668     uint m_tabWidth;
00669         
00670     uint m_lineHighlightedMax;
00671     uint m_lineHighlighted;
00672   
00676     uint m_maxDynamicContexts;
00677 
00681   private:
00685     KateBufBlockList m_loadedBlocks;
00686 };
00687 
00688 #endif
00689 
00690 // 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.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Feb 18 15:11:55 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003