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 <qregexp.h> 00034 #include <qdict.h> 00035 #include <qintdict.h> 00036 #include <qmap.h> 00037 #include <qobject.h> 00038 #include <qstringlist.h> 00039 #include <qguardedptr.h> 00040 #include <qdatetime.h> 00041 00042 class KateHlContext; 00043 class KateHlItem; 00044 class KateHlItemData; 00045 class KateHlData; 00046 class KateEmbeddedHlInfo; 00047 class KateHlIncludeRule; 00048 class KateSyntaxDocument; 00049 class KateTextLine; 00050 class KateSyntaxModeListItem; 00051 class KateSyntaxContextData; 00052 00053 class QPopupMenu; 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<signed char> *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 00165 enum commentData { Start, End, SingleLine }; 00166 00171 QString getCommentString( int which, int attrib ) const; 00172 00177 QString getCommentStart( int attrib=0 ) const; 00178 00183 QString getCommentEnd( int attrib=0 ) const; 00184 00189 QString getCommentSingleLineStart( int attrib=0 ) const; 00190 00191 void clearAttributeArrays (); 00192 00193 QMemArray<KateAttribute> *attributes (uint schema); 00194 00195 inline bool noHighlighting () const { return noHl; }; 00196 00197 // be carefull: all documents hl should be invalidated after calling this method! 00198 void dropDynamicContexts(); 00199 00200 private: 00201 // make this private, nobody should play with the internal data pointers 00202 void getKateHlItemDataList(uint schema, KateHlItemDataList &); 00203 00204 void init(); 00205 void done(); 00206 void makeContextList (); 00207 int makeDynamicContext(KateHlContext *model, const QStringList *args); 00208 void handleKateHlIncludeRules (); 00209 void handleKateHlIncludeRulesRecursive(KateHlIncludeRules::iterator it, KateHlIncludeRules *list); 00210 int addToContextList(const QString &ident, int ctx0); 00211 void addToKateHlItemDataList(); 00212 void createKateHlItemData (KateHlItemDataList &list); 00213 QString readGlobalKeywordConfig(); 00214 QString readWordWrapConfig(); 00215 QStringList readCommentConfig(); 00216 void readFoldingConfig (); 00217 00218 // manipulates the ctxs array directly ;) 00219 void generateContextStack(int *ctxNum, int ctx, QMemArray<short> *ctxs, int *posPrevLine,bool lineContinue=false); 00220 00221 KateHlItem *createKateHlItem(struct KateSyntaxContextData *data, KateHlItemDataList &iDl, QStringList *RegionList, QStringList *ContextList); 00222 int lookupAttrName(const QString& name, KateHlItemDataList &iDl); 00223 00224 void createContextNameList(QStringList *ContextNameList, int ctx0); 00225 int getIdFromString(QStringList *ContextNameList, QString tmpLineEndContext,/*NO CONST*/ QString &unres); 00226 00230 int hlKeyForAttrib( int attrib ) const; 00231 00232 KateHlItemDataList internalIDList; 00233 00234 QIntDict<KateHlContext> contextList; 00235 inline KateHlContext *contextNum (uint n) { return contextList[n]; } 00236 00237 QMap< QPair<KateHlContext *, QString>, short> dynamicCtxs; 00238 00239 // make them pointers perhaps 00240 KateEmbeddedHlInfos embeddedHls; 00241 KateHlUnresolvedCtxRefs unresolvedContextReferences; 00242 QStringList RegionList; 00243 QStringList ContextNameList; 00244 00245 bool noHl; 00246 bool folding; 00247 bool casesensitive; 00248 QString weakDeliminator; 00249 QString deliminator; 00250 00251 QString iName; 00252 QString iNameTranslated; 00253 QString iSection; 00254 bool iHidden; 00255 QString iWildcards; 00256 QString iMimetypes; 00257 QString identifier; 00258 QString iVersion; 00259 QString iAuthor; 00260 QString iLicense; 00261 int m_priority; 00262 int refCount; 00263 int startctx, base_startctx; 00264 00265 QString errorsAndWarnings; 00266 QString buildIdentifier; 00267 QString buildPrefix; 00268 bool building; 00269 uint itemData0; 00270 uint buildContext0Offset; 00271 KateHlIncludeRules includeRules; 00272 QValueList<int> contextsIncludingSomething; //### unused, can i remove it? 00273 bool m_foldingIndentationSensitive; 00274 00275 QIntDict< QMemArray<KateAttribute> > m_attributeArrays; 00276 00284 QMap<int, QStringList> m_additionalData; 00285 00289 IntList m_hlIndex; 00290 00291 QString extensionSource; 00292 QValueList<QRegExp> regexpExtensions; 00293 QStringList plainExtensions; 00294 00295 public: 00296 inline bool foldingIndentationSensitive () { return m_foldingIndentationSensitive; } 00297 inline bool allowsFolding(){return folding;} 00298 }; 00299 00300 class KateHlManager : public QObject 00301 { 00302 Q_OBJECT 00303 00304 private: 00305 KateHlManager(); 00306 00307 public: 00308 ~KateHlManager(); 00309 00310 static KateHlManager *self(); 00311 00312 inline KConfig *getKConfig() { return &m_config; }; 00313 00314 KateHighlighting *getHl(int n); 00315 int nameFind(const QString &name); 00316 00317 int detectHighlighting (class KateDocument *doc); 00318 00319 int findHl(KateHighlighting *h) {return hlList.find(h);} 00320 QString identifierForName(const QString&); 00321 00322 // methodes to get the default style count + names 00323 static uint defaultStyles(); 00324 static QString defaultStyleName(int n); 00325 00326 void getDefaults(uint schema, KateAttributeList &); 00327 void setDefaults(uint schema, KateAttributeList &); 00328 00329 int highlights(); 00330 QString hlName(int n); 00331 QString hlNameTranslated (int n); 00332 QString hlSection(int n); 00333 bool hlHidden(int n); 00334 00335 void incDynamicCtxs() { ++dynamicCtxsCount; }; 00336 uint countDynamicCtxs() { return dynamicCtxsCount; }; 00337 void setForceNoDCReset(bool b) { forceNoDCReset = b; }; 00338 00339 // be carefull: all documents hl should be invalidated after having successfully called this method! 00340 bool resetDynamicCtxs(); 00341 00342 signals: 00343 void changed(); 00344 00345 private: 00346 int wildcardFind(const QString &fileName); 00347 int mimeFind(KateDocument *); 00348 int realWildcardFind(const QString &fileName); 00349 00350 private: 00351 friend class KateHighlighting; 00352 00353 QPtrList<KateHighlighting> hlList; 00354 QDict<KateHighlighting> hlDict; 00355 00356 static KateHlManager *s_self; 00357 00358 KConfig m_config; 00359 QStringList commonSuffixes; 00360 00361 KateSyntaxDocument *syntax; 00362 00363 uint dynamicCtxsCount; 00364 QTime lastCtxsReset; 00365 bool forceNoDCReset; 00366 }; 00367 00368 class KateViewHighlightAction: public Kate::ActionMenu 00369 { 00370 Q_OBJECT 00371 00372 public: 00373 KateViewHighlightAction(const QString& text, QObject* parent = 0, const char* name = 0) 00374 : Kate::ActionMenu(text, parent, name) { init(); }; 00375 00376 ~KateViewHighlightAction(){;}; 00377 00378 void updateMenu (Kate::Document *doc); 00379 00380 private: 00381 void init(); 00382 00383 QGuardedPtr<Kate::Document> m_doc; 00384 QStringList subMenusName; 00385 QStringList names; 00386 QPtrList<QPopupMenu> subMenus; 00387 00388 public slots: 00389 void slotAboutToShow(); 00390 00391 private slots: 00392 void setHl (int mode); 00393 }; 00394 00395 #endif 00396 00397 // 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.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Sep 29 09:45:08 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003