• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Kate

katehighlight.h

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, 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 #include <qpopupmenu.h>
00043 
00044 class KateHlContext;
00045 class KateHlItem;
00046 class KateHlItemData;
00047 class KateHlData;
00048 class KateEmbeddedHlInfo;
00049 class KateHlIncludeRule;
00050 class KateSyntaxDocument;
00051 class KateTextLine;
00052 class KateSyntaxModeListItem;
00053 class KateSyntaxContextData;
00054 
00055 // some typedefs
00056 typedef QPtrList<KateAttribute> KateAttributeList;
00057 typedef QValueList<KateHlIncludeRule*> KateHlIncludeRules;
00058 typedef QPtrList<KateHlItemData> KateHlItemDataList;
00059 typedef QPtrList<KateHlData> KateHlDataList;
00060 typedef QMap<QString,KateEmbeddedHlInfo> KateEmbeddedHlInfos;
00061 typedef QMap<int*,QString> KateHlUnresolvedCtxRefs;
00062 typedef QValueList<int> IntList;
00063 
00064 //Item Properties: name, Item Style, Item Font
00065 class KateHlItemData : public KateAttribute
00066 {
00067   public:
00068     KateHlItemData(const QString  name, int defStyleNum);
00069 
00070     enum ItemStyles {
00071       dsNormal,
00072       dsKeyword,
00073       dsDataType,
00074       dsDecVal,
00075       dsBaseN,
00076       dsFloat,
00077       dsChar,
00078       dsString,
00079       dsComment,
00080       dsOthers,
00081       dsAlert,
00082       dsFunction,
00083       dsRegionMarker,
00084       dsError };
00085 
00086   public:
00087     const QString name;
00088     int defStyleNum;
00089 };
00090 
00091 class KateHlData
00092 {
00093   public:
00094     KateHlData(const QString &wildcards, const QString &mimetypes,const QString &identifier, int priority);
00095 
00096   public:
00097     QString wildcards;
00098     QString mimetypes;
00099     QString identifier;
00100     int priority;
00101 };
00102 
00103 class KateHighlighting
00104 {
00105   public:
00106     KateHighlighting(const KateSyntaxModeListItem *def);
00107     ~KateHighlighting();
00108 
00109   public:
00110     void doHighlight ( KateTextLine *prevLine,
00111                        KateTextLine *textLine,
00112                        QMemArray<uint> *foldingList,
00113                        bool *ctxChanged );
00114 
00115     void loadWildcards();
00116     QValueList<QRegExp>& getRegexpExtensions();
00117     QStringList& getPlainExtensions();
00118 
00119     QString getMimetypes();
00120 
00121     // this pointer needs to be deleted !!!!!!!!!!
00122     KateHlData *getData();
00123     void setData(KateHlData *);
00124 
00125     void setKateHlItemDataList(uint schema, KateHlItemDataList &);
00126 
00127     // both methodes return hard copies of the internal lists
00128     // the lists are cleared first + autodelete is set !
00129     // keep track that you delete them, or mem will be lost
00130     void getKateHlItemDataListCopy (uint schema, KateHlItemDataList &);
00131 
00132     const QString &name() const {return iName;}
00133     const QString &nameTranslated() const {return iNameTranslated;}
00134     const QString &section() const {return iSection;}
00135     bool hidden() const {return iHidden;}
00136     const QString &version() const {return iVersion;}
00137     const QString &author () const { return iAuthor; }
00138     const QString &license () const { return iLicense; }
00139     int priority();
00140     const QString &getIdentifier() const {return identifier;}
00141     void use();
00142     void release();
00143 
00148     bool isInWord( QChar c, int attrib=0 ) const;
00149 
00154     bool canBreakAt( QChar c, int attrib=0 ) const;
00155 
00160     bool canComment( int startAttr, int endAttr ) const;
00161 
00166     signed char commentRegion(int attr) const;
00167 
00172     QString getCommentStart( int attrib=0 ) const;
00173 
00178     QString getCommentEnd( int attrib=0 ) const;
00179 
00184     QString getCommentSingleLineStart( int attrib=0 ) const;
00185 
00186 
00190     enum CSLPos { CSLPosColumn0=0,CSLPosAfterWhitespace=1};
00191 
00196     CSLPos getCommentSingleLinePosition( int attrib=0 ) const;
00197 
00201     int attribute( int context ) const;
00202 
00207     QString hlKeyForAttrib( int attrib ) const;
00208 
00209 
00210     void clearAttributeArrays ();
00211 
00212     QMemArray<KateAttribute> *attributes (uint schema);
00213 
00214     inline bool noHighlighting () const { return noHl; };
00215 
00216     // be carefull: all documents hl should be invalidated after calling this method!
00217     void dropDynamicContexts();
00218 
00219     QString indentation () { return m_indentation; }
00220 
00221   private:
00222     // make this private, nobody should play with the internal data pointers
00223     void getKateHlItemDataList(uint schema, KateHlItemDataList &);
00224 
00225     void init();
00226     void done();
00227     void makeContextList ();
00228     int makeDynamicContext(KateHlContext *model, const QStringList *args);
00229     void handleKateHlIncludeRules ();
00230     void handleKateHlIncludeRulesRecursive(KateHlIncludeRules::iterator it, KateHlIncludeRules *list);
00231     int addToContextList(const QString &ident, int ctx0);
00232     void addToKateHlItemDataList();
00233     void createKateHlItemData (KateHlItemDataList &list);
00234     void readGlobalKeywordConfig();
00235     void readWordWrapConfig();
00236     void readCommentConfig();
00237     void readIndentationConfig ();
00238     void readFoldingConfig ();
00239 
00240     // manipulates the ctxs array directly ;)
00241     void generateContextStack(int *ctxNum, int ctx, QMemArray<short> *ctxs, int *posPrevLine);
00242 
00243     KateHlItem *createKateHlItem(KateSyntaxContextData *data, KateHlItemDataList &iDl, QStringList *RegionList, QStringList *ContextList);
00244     int lookupAttrName(const QString& name, KateHlItemDataList &iDl);
00245 
00246     void createContextNameList(QStringList *ContextNameList, int ctx0);
00247     int getIdFromString(QStringList *ContextNameList, QString tmpLineEndContext,/*NO CONST*/ QString &unres);
00248 
00249     KateHlItemDataList internalIDList;
00250 
00251     QValueVector<KateHlContext*> m_contexts;
00252     inline KateHlContext *contextNum (uint n) { if (n < m_contexts.size()) return m_contexts[n]; return 0; }
00253 
00254     QMap< QPair<KateHlContext *, QString>, short> dynamicCtxs;
00255 
00256     // make them pointers perhaps
00257     KateEmbeddedHlInfos embeddedHls;
00258     KateHlUnresolvedCtxRefs unresolvedContextReferences;
00259     QStringList RegionList;
00260     QStringList ContextNameList;
00261 
00262     bool noHl;
00263     bool folding;
00264     bool casesensitive;
00265     QString weakDeliminator;
00266     QString deliminator;
00267 
00268     QString iName;
00269     QString iNameTranslated;
00270     QString iSection;
00271     bool iHidden;
00272     QString iWildcards;
00273     QString iMimetypes;
00274     QString identifier;
00275     QString iVersion;
00276     QString iAuthor;
00277     QString iLicense;
00278     QString m_indentation;
00279     int m_priority;
00280     int refCount;
00281     int startctx, base_startctx;
00282 
00283     QString errorsAndWarnings;
00284     QString buildIdentifier;
00285     QString buildPrefix;
00286     bool building;
00287     uint itemData0;
00288     uint buildContext0Offset;
00289     KateHlIncludeRules includeRules;
00290     bool m_foldingIndentationSensitive;
00291 
00292     QIntDict< QMemArray<KateAttribute> > m_attributeArrays;
00293 
00294 
00307     class HighlightPropertyBag {
00308       public:
00309         QString singleLineCommentMarker;
00310         QString multiLineCommentStart;
00311         QString multiLineCommentEnd;
00312         QString multiLineRegion;
00313         CSLPos  singleLineCommentPosition;
00314         QString deliminator;
00315         QString wordWrapDeliminator;
00316     };
00317 
00322     QDict<HighlightPropertyBag> m_additionalData;
00323 
00329     QMap<int, QString> m_hlIndex;
00330 
00331 
00332     QString extensionSource;
00333     QValueList<QRegExp> regexpExtensions;
00334     QStringList plainExtensions;
00335 
00336   public:
00337     inline bool foldingIndentationSensitive () { return m_foldingIndentationSensitive; }
00338     inline bool allowsFolding(){return folding;}
00339 };
00340 
00341 class KateHlManager : public QObject
00342 {
00343   Q_OBJECT
00344 
00345   private:
00346     KateHlManager();
00347 
00348   public:
00349     ~KateHlManager();
00350 
00351     static KateHlManager *self();
00352 
00353     inline KConfig *getKConfig() { return &m_config; };
00354 
00355     KateHighlighting *getHl(int n);
00356     int nameFind(const QString &name);
00357 
00358     int detectHighlighting (class KateDocument *doc);
00359 
00360     int findHl(KateHighlighting *h) {return hlList.find(h);}
00361     QString identifierForName(const QString&);
00362 
00363     // methodes to get the default style count + names
00364     static uint defaultStyles();
00365     static QString defaultStyleName(int n, bool translateNames = false);
00366 
00367     void getDefaults(uint schema, KateAttributeList &);
00368     void setDefaults(uint schema, KateAttributeList &);
00369 
00370     int highlights();
00371     QString hlName(int n);
00372     QString hlNameTranslated (int n);
00373     QString hlSection(int n);
00374     bool hlHidden(int n);
00375 
00376     void incDynamicCtxs() { ++dynamicCtxsCount; };
00377     uint countDynamicCtxs() { return dynamicCtxsCount; };
00378     void setForceNoDCReset(bool b) { forceNoDCReset = b; };
00379 
00380     // be carefull: all documents hl should be invalidated after having successfully called this method!
00381     bool resetDynamicCtxs();
00382 
00383   signals:
00384     void changed();
00385 
00386   private:
00387     int wildcardFind(const QString &fileName);
00388     int mimeFind(KateDocument *);
00389     int realWildcardFind(const QString &fileName);
00390 
00391   private:
00392     friend class KateHighlighting;
00393 
00394     QPtrList<KateHighlighting> hlList;
00395     QDict<KateHighlighting> hlDict;
00396 
00397     static KateHlManager *s_self;
00398 
00399     KConfig m_config;
00400     QStringList commonSuffixes;
00401 
00402     KateSyntaxDocument *syntax;
00403 
00404     uint dynamicCtxsCount;
00405     QTime lastCtxsReset;
00406     bool forceNoDCReset;
00407 };
00408 
00409 class KateViewHighlightAction: public Kate::ActionMenu
00410 {
00411   Q_OBJECT
00412 
00413   public:
00414     KateViewHighlightAction(const QString& text, QObject* parent = 0, const char* name = 0)
00415        : Kate::ActionMenu(text, parent, name) { init(); };
00416 
00417     ~KateViewHighlightAction(){;};
00418 
00419     void updateMenu (Kate::Document *doc);
00420 
00421   private:
00422     void init();
00423 
00424     QGuardedPtr<Kate::Document> m_doc;
00425     QStringList subMenusName;
00426     QStringList names;
00427     QPtrList<QPopupMenu> subMenus;
00428 
00429   public  slots:
00430     void slotAboutToShow();
00431 
00432   private slots:
00433     void setHl (int mode);
00434 };
00435 
00436 #endif
00437 
00438 // kate: space-indent on; indent-width 2; replace-tabs on;

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal