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., 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 <tqptrlist.h> 00032 #include <tqvaluelist.h> 00033 #include <tqvaluevector.h> 00034 #include <tqregexp.h> 00035 #include <tqdict.h> 00036 #include <tqintdict.h> 00037 #include <tqmap.h> 00038 #include <tqobject.h> 00039 #include <tqstringlist.h> 00040 #include <tqguardedptr.h> 00041 #include <tqdatetime.h> 00042 #include <tqpopupmenu.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 TQPtrList<KateAttribute> KateAttributeList; 00057 typedef TQValueList<KateHlIncludeRule*> KateHlIncludeRules; 00058 typedef TQPtrList<KateHlItemData> KateHlItemDataList; 00059 typedef TQPtrList<KateHlData> KateHlDataList; 00060 typedef TQMap<TQString,KateEmbeddedHlInfo> KateEmbeddedHlInfos; 00061 typedef TQMap<int*,TQString> KateHlUnresolvedCtxRefs; 00062 typedef TQValueList<int> IntList; 00063 00064 //Item Properties: name, Item Style, Item Font 00065 class KateHlItemData : public KateAttribute 00066 { 00067 public: 00068 KateHlItemData(const TQString 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 TQString name; 00088 int defStyleNum; 00089 }; 00090 00091 class KateHlData 00092 { 00093 public: 00094 KateHlData(const TQString &wildcards, const TQString &mimetypes,const TQString &identifier, int priority); 00095 00096 public: 00097 TQString wildcards; 00098 TQString mimetypes; 00099 TQString 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 TQMemArray<uint> *foldingList, 00113 bool *ctxChanged ); 00114 00115 void loadWildcards(); 00116 TQValueList<TQRegExp>& getRegexpExtensions(); 00117 TQStringList& getPlainExtensions(); 00118 00119 TQString 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 TQString &name() const {return iName;} 00133 const TQString &nameTranslated() const {return iNameTranslated;} 00134 const TQString §ion() const {return iSection;} 00135 bool hidden() const {return iHidden;} 00136 const TQString &version() const {return iVersion;} 00137 const TQString &author () const { return iAuthor; } 00138 const TQString &license () const { return iLicense; } 00139 int priority(); 00140 const TQString &getIdentifier() const {return identifier;} 00141 void use(); 00142 void release(); 00143 00148 bool isInWord( TQChar c, int attrib=0 ) const; 00149 00154 bool canBreakAt( TQChar c, int attrib=0 ) const; 00155 00160 bool canComment( int startAttr, int endAttr ) const; 00161 00166 signed char commentRegion(int attr) const; 00167 00172 TQString getCommentStart( int attrib=0 ) const; 00173 00178 TQString getCommentEnd( int attrib=0 ) const; 00179 00184 TQString 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 TQString hlKeyForAttrib( int attrib ) const; 00208 00209 00210 void clearAttributeArrays (); 00211 00212 TQMemArray<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 TQString 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 TQStringList *args); 00229 void handleKateHlIncludeRules (); 00230 void handleKateHlIncludeRulesRecursive(KateHlIncludeRules::iterator it, KateHlIncludeRules *list); 00231 int addToContextList(const TQString &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, TQMemArray<short> *ctxs, int *posPrevLine); 00242 00243 KateHlItem *createKateHlItem(KateSyntaxContextData *data, KateHlItemDataList &iDl, TQStringList *RegionList, TQStringList *ContextList); 00244 int lookupAttrName(const TQString& name, KateHlItemDataList &iDl); 00245 00246 void createContextNameList(TQStringList *ContextNameList, int ctx0); 00247 int getIdFromString(TQStringList *ContextNameList, TQString tmpLineEndContext,/*NO CONST*/ TQString &unres); 00248 00249 KateHlItemDataList internalIDList; 00250 00251 TQValueVector<KateHlContext*> m_contexts; 00252 inline KateHlContext *contextNum (uint n) { if (n < m_contexts.size()) return m_contexts[n]; return 0; } 00253 00254 TQMap< QPair<KateHlContext *, TQString>, short> dynamicCtxs; 00255 00256 // make them pointers perhaps 00257 KateEmbeddedHlInfos embeddedHls; 00258 KateHlUnresolvedCtxRefs unresolvedContextReferences; 00259 TQStringList RegionList; 00260 TQStringList ContextNameList; 00261 00262 bool noHl; 00263 bool folding; 00264 bool casesensitive; 00265 TQString weakDeliminator; 00266 TQString deliminator; 00267 00268 TQString iName; 00269 TQString iNameTranslated; 00270 TQString iSection; 00271 bool iHidden; 00272 TQString iWildcards; 00273 TQString iMimetypes; 00274 TQString identifier; 00275 TQString iVersion; 00276 TQString iAuthor; 00277 TQString iLicense; 00278 TQString m_indentation; 00279 int m_priority; 00280 int refCount; 00281 int startctx, base_startctx; 00282 00283 TQString errorsAndWarnings; 00284 TQString buildIdentifier; 00285 TQString buildPrefix; 00286 bool building; 00287 uint itemData0; 00288 uint buildContext0Offset; 00289 KateHlIncludeRules includeRules; 00290 bool m_foldingIndentationSensitive; 00291 00292 TQIntDict< TQMemArray<KateAttribute> > m_attributeArrays; 00293 00294 00307 class HighlightPropertyBag { 00308 public: 00309 TQString singleLineCommentMarker; 00310 TQString multiLineCommentStart; 00311 TQString multiLineCommentEnd; 00312 TQString multiLineRegion; 00313 CSLPos singleLineCommentPosition; 00314 TQString deliminator; 00315 TQString wordWrapDeliminator; 00316 }; 00317 00322 TQDict<HighlightPropertyBag> m_additionalData; 00323 00329 TQMap<int, TQString> m_hlIndex; 00330 00331 00332 TQString extensionSource; 00333 TQValueList<TQRegExp> regexpExtensions; 00334 TQStringList plainExtensions; 00335 00336 public: 00337 inline bool foldingIndentationSensitive () { return m_foldingIndentationSensitive; } 00338 inline bool allowsFolding(){return folding;} 00339 }; 00340 00341 class KateHlManager : public TQObject 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 TQString &name); 00357 00358 int detectHighlighting (class KateDocument *doc); 00359 00360 int findHl(KateHighlighting *h) {return hlList.find(h);} 00361 TQString identifierForName(const TQString&); 00362 00363 // methodes to get the default style count + names 00364 static uint defaultStyles(); 00365 static TQString defaultStyleName(int n, bool translateNames = false); 00366 00367 void getDefaults(uint schema, KateAttributeList &); 00368 void setDefaults(uint schema, KateAttributeList &); 00369 00370 int highlights(); 00371 TQString hlName(int n); 00372 TQString hlNameTranslated (int n); 00373 TQString 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 TQString &fileName); 00388 int mimeFind(KateDocument *); 00389 int realWildcardFind(const TQString &fileName); 00390 00391 private: 00392 friend class KateHighlighting; 00393 00394 TQPtrList<KateHighlighting> hlList; 00395 TQDict<KateHighlighting> hlDict; 00396 00397 static KateHlManager *s_self; 00398 00399 KConfig m_config; 00400 TQStringList commonSuffixes; 00401 00402 KateSyntaxDocument *syntax; 00403 00404 uint dynamicCtxsCount; 00405 TQTime lastCtxsReset; 00406 bool forceNoDCReset; 00407 }; 00408 00409 class KateViewHighlightAction: public Kate::ActionMenu 00410 { 00411 Q_OBJECT 00412 00413 public: 00414 KateViewHighlightAction(const TQString& text, TQObject* 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 TQGuardedPtr<Kate::Document> m_doc; 00425 TQStringList subMenusName; 00426 TQStringList names; 00427 TQPtrList<TQPopupMenu> 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;