kate Library API Documentation

katehighlight.h

00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2001,2002 Joseph Wenninger <jowenn@kde.org>
00003    Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
00004    Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License version 2 as published by the Free Software Foundation.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #ifndef __KATE_HIGHLIGHT_H__
00022 #define __KATE_HIGHLIGHT_H__
00023 
00024 #include "katetextline.h"
00025 #include "kateattribute.h"
00026 
00027 #include "../interfaces/document.h"
00028 
00029 #include <kconfig.h>
00030 
00031 #include <qptrlist.h>
00032 #include <qvaluelist.h>
00033 #include <qvaluevector.h>
00034 #include <qregexp.h>
00035 #include <qdict.h>
00036 #include <qintdict.h>
00037 #include <qmap.h>
00038 #include <qobject.h>
00039 #include <qstringlist.h>
00040 #include <qguardedptr.h>
00041 #include <qdatetime.h>
00042 
00043 class KateHlContext;
00044 class KateHlItem;
00045 class KateHlItemData;
00046 class KateHlData;
00047 class KateEmbeddedHlInfo;
00048 class KateHlIncludeRule;
00049 class KateSyntaxDocument;
00050 class KateTextLine;
00051 class KateSyntaxModeListItem;
00052 class KateSyntaxContextData;
00053 
00054 class QPopupMenu;
00055 
00056 // some typedefs
00057 typedef QPtrList<KateAttribute> KateAttributeList;
00058 typedef QValueList<KateHlIncludeRule*> KateHlIncludeRules;
00059 typedef QPtrList<KateHlItemData> KateHlItemDataList;
00060 typedef QPtrList<KateHlData> KateHlDataList;
00061 typedef QMap<QString,KateEmbeddedHlInfo> KateEmbeddedHlInfos;
00062 typedef QMap<int*,QString> KateHlUnresolvedCtxRefs;
00063 typedef QValueList<int> IntList;
00064 
00065 //Item Properties: name, Item Style, Item Font
00066 class KateHlItemData : public KateAttribute
00067 {
00068   public:
00069     KateHlItemData(const QString  name, int defStyleNum);
00070 
00071     enum ItemStyles {
00072       dsNormal,
00073       dsKeyword,
00074       dsDataType,
00075       dsDecVal,
00076       dsBaseN,
00077       dsFloat,
00078       dsChar,
00079       dsString,
00080       dsComment,
00081       dsOthers,
00082       dsAlert,
00083       dsFunction,
00084       dsRegionMarker,
00085       dsError };
00086 
00087   public:
00088     const QString name;
00089     int defStyleNum;
00090 };
00091 
00092 class KateHlData
00093 {
00094   public:
00095     KateHlData(const QString &wildcards, const QString &mimetypes,const QString &identifier, int priority);
00096 
00097   public:
00098     QString wildcards;
00099     QString mimetypes;
00100     QString identifier;
00101     int priority;
00102 };
00103 
00104 class KateHighlighting
00105 {
00106   public:
00107     KateHighlighting(const KateSyntaxModeListItem *def);
00108     ~KateHighlighting();
00109 
00110   public:
00111     void doHighlight ( KateTextLine *prevLine,
00112                        KateTextLine *textLine,
00113                        QMemArray<uint> *foldingList,
00114                        bool *ctxChanged );
00115 
00116     void loadWildcards();
00117     QValueList<QRegExp>& getRegexpExtensions();
00118     QStringList& getPlainExtensions();
00119 
00120     QString getMimetypes();
00121 
00122     // this pointer needs to be deleted !!!!!!!!!!
00123     KateHlData *getData();
00124     void setData(KateHlData *);
00125 
00126     void setKateHlItemDataList(uint schema, KateHlItemDataList &);
00127 
00128     // both methodes return hard copies of the internal lists
00129     // the lists are cleared first + autodelete is set !
00130     // keep track that you delete them, or mem will be lost
00131     void getKateHlItemDataListCopy (uint schema, KateHlItemDataList &);
00132 
00133     const QString &name() const {return iName;}
00134     const QString &nameTranslated() const {return iNameTranslated;}
00135     const QString &section() const {return iSection;}
00136     bool hidden() const {return iHidden;}
00137     const QString &version() const {return iVersion;}
00138     const QString &author () const { return iAuthor; }
00139     const QString &license () const { return iLicense; }
00140     int priority();
00141     const QString &getIdentifier() const {return identifier;}
00142     void use();
00143     void release();
00144 
00149     bool isInWord( QChar c, int attrib=0 ) const;
00150 
00155     bool canBreakAt( QChar c, int attrib=0 ) const;
00156 
00161     bool canComment( int startAttr, int endAttr ) const;
00162 
00167     signed char commentRegion(int attr) const;
00168 
00173     QString getCommentStart( int attrib=0 ) const;
00174 
00179     QString getCommentEnd( int attrib=0 ) const;
00180 
00185     QString getCommentSingleLineStart( int attrib=0 ) const;
00186 
00190     int attribute( int context ) const;
00191 
00192     void clearAttributeArrays ();
00193 
00194     QMemArray<KateAttribute> *attributes (uint schema);
00195 
00196     inline bool noHighlighting () const { return noHl; };
00197 
00198     // be carefull: all documents hl should be invalidated after calling this method!
00199     void dropDynamicContexts();
00200 
00201     QString indentation () { return m_indentation; }
00202 
00203   private:
00204     // make this private, nobody should play with the internal data pointers
00205     void getKateHlItemDataList(uint schema, KateHlItemDataList &);
00206 
00207     void init();
00208     void done();
00209     void makeContextList ();
00210     int makeDynamicContext(KateHlContext *model, const QStringList *args);
00211     void handleKateHlIncludeRules ();
00212     void handleKateHlIncludeRulesRecursive(KateHlIncludeRules::iterator it, KateHlIncludeRules *list);
00213     int addToContextList(const QString &ident, int ctx0);
00214     void addToKateHlItemDataList();
00215     void createKateHlItemData (KateHlItemDataList &list);
00216     void readGlobalKeywordConfig();
00217     void readWordWrapConfig();
00218     void readCommentConfig();
00219     void readIndentationConfig ();
00220     void readFoldingConfig ();
00221 
00222     // manipulates the ctxs array directly ;)
00223     void generateContextStack(int *ctxNum, int ctx, QMemArray<short> *ctxs, int *posPrevLine);
00224 
00225     KateHlItem *createKateHlItem(KateSyntaxContextData *data, KateHlItemDataList &iDl, QStringList *RegionList, QStringList *ContextList);
00226     int lookupAttrName(const QString& name, KateHlItemDataList &iDl);
00227 
00228     void createContextNameList(QStringList *ContextNameList, int ctx0);
00229     int getIdFromString(QStringList *ContextNameList, QString tmpLineEndContext,/*NO CONST*/ QString &unres);
00230 
00234     QString hlKeyForAttrib( int attrib ) const;
00235 
00236     KateHlItemDataList internalIDList;
00237 
00238     QValueVector<KateHlContext*> m_contexts;
00239     inline KateHlContext *contextNum (uint n) { if (n < m_contexts.size()) return m_contexts[n]; return 0; }
00240 
00241     QMap< QPair<KateHlContext *, QString>, short> dynamicCtxs;
00242 
00243     // make them pointers perhaps
00244     KateEmbeddedHlInfos embeddedHls;
00245     KateHlUnresolvedCtxRefs unresolvedContextReferences;
00246     QStringList RegionList;
00247     QStringList ContextNameList;
00248 
00249     bool noHl;
00250     bool folding;
00251     bool casesensitive;
00252     QString weakDeliminator;
00253     QString deliminator;
00254 
00255     QString iName;
00256     QString iNameTranslated;
00257     QString iSection;
00258     bool iHidden;
00259     QString iWildcards;
00260     QString iMimetypes;
00261     QString identifier;
00262     QString iVersion;
00263     QString iAuthor;
00264     QString iLicense;
00265     QString m_indentation;
00266     int m_priority;
00267     int refCount;
00268     int startctx, base_startctx;
00269 
00270     QString errorsAndWarnings;
00271     QString buildIdentifier;
00272     QString buildPrefix;
00273     bool building;
00274     uint itemData0;
00275     uint buildContext0Offset;
00276     KateHlIncludeRules includeRules;
00277     bool m_foldingIndentationSensitive;
00278 
00279     QIntDict< QMemArray<KateAttribute> > m_attributeArrays;
00280 
00293     class HighlightPropertyBag {
00294       public:
00295         QString singleLineCommentMarker;
00296         QString multiLineCommentStart;
00297         QString multiLineCommentEnd;
00298         QString multiLineRegion;
00299         QString deliminator;
00300         QString wordWrapDeliminator;
00301     };
00302 
00307     QDict<HighlightPropertyBag> m_additionalData;
00308 
00314     QMap<int, QString> m_hlIndex;
00315 
00316 
00317     QString extensionSource;
00318     QValueList<QRegExp> regexpExtensions;
00319     QStringList plainExtensions;
00320 
00321   public:
00322     inline bool foldingIndentationSensitive () { return m_foldingIndentationSensitive; }
00323     inline bool allowsFolding(){return folding;}
00324 };
00325 
00326 class KateHlManager : public QObject
00327 {
00328   Q_OBJECT
00329 
00330   private:
00331     KateHlManager();
00332 
00333   public:
00334     ~KateHlManager();
00335 
00336     static KateHlManager *self();
00337 
00338     inline KConfig *getKConfig() { return &m_config; };
00339 
00340     KateHighlighting *getHl(int n);
00341     int nameFind(const QString &name);
00342 
00343     int detectHighlighting (class KateDocument *doc);
00344 
00345     int findHl(KateHighlighting *h) {return hlList.find(h);}
00346     QString identifierForName(const QString&);
00347 
00348     // methodes to get the default style count + names
00349     static uint defaultStyles();
00350     static QString defaultStyleName(int n, bool translateNames = false);
00351 
00352     void getDefaults(uint schema, KateAttributeList &);
00353     void setDefaults(uint schema, KateAttributeList &);
00354 
00355     int highlights();
00356     QString hlName(int n);
00357     QString hlNameTranslated (int n);
00358     QString hlSection(int n);
00359     bool hlHidden(int n);
00360 
00361     void incDynamicCtxs() { ++dynamicCtxsCount; };
00362     uint countDynamicCtxs() { return dynamicCtxsCount; };
00363     void setForceNoDCReset(bool b) { forceNoDCReset = b; };
00364 
00365     // be carefull: all documents hl should be invalidated after having successfully called this method!
00366     bool resetDynamicCtxs();
00367 
00368   signals:
00369     void changed();
00370 
00371   private:
00372     int wildcardFind(const QString &fileName);
00373     int mimeFind(KateDocument *);
00374     int realWildcardFind(const QString &fileName);
00375 
00376   private:
00377     friend class KateHighlighting;
00378 
00379     QPtrList<KateHighlighting> hlList;
00380     QDict<KateHighlighting> hlDict;
00381 
00382     static KateHlManager *s_self;
00383 
00384     KConfig m_config;
00385     QStringList commonSuffixes;
00386 
00387     KateSyntaxDocument *syntax;
00388 
00389     uint dynamicCtxsCount;
00390     QTime lastCtxsReset;
00391     bool forceNoDCReset;
00392 };
00393 
00394 class KateViewHighlightAction: public Kate::ActionMenu
00395 {
00396   Q_OBJECT
00397 
00398   public:
00399     KateViewHighlightAction(const QString& text, QObject* parent = 0, const char* name = 0)
00400        : Kate::ActionMenu(text, parent, name) { init(); };
00401 
00402     ~KateViewHighlightAction(){;};
00403 
00404     void updateMenu (Kate::Document *doc);
00405 
00406   private:
00407     void init();
00408 
00409     QGuardedPtr<Kate::Document> m_doc;
00410     QStringList subMenusName;
00411     QStringList names;
00412     QPtrList<QPopupMenu> subMenus;
00413 
00414   public  slots:
00415     void slotAboutToShow();
00416 
00417   private slots:
00418     void setHl (int mode);
00419 };
00420 
00421 #endif
00422 
00423 // 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.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Sep 15 11:18:57 2005 by doxygen 1.4.4 written by Dimitri van Heesch, © 1997-2003