Fix for UBSan build
[platform/upstream/doxygen.git] / src / layout.cpp
1 /******************************************************************************
2  *
3  * $Id: layout.cpp,v 1.2 2001/03/19 19:27:41 root Exp $
4  *
5  *
6  * Copyright (C) 1997-2012 by Dimitri van Heesch.
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation under the terms of the GNU General Public License is hereby 
10  * granted. No representations are made about the suitability of this software 
11  * for any purpose. It is provided "as is" without express or implied warranty.
12  * See the GNU General Public License for more details.
13  *
14  * Documents produced by Doxygen are derivative works derived from the
15  * input used in their production; they are not affected by this license.
16  *
17  */
18
19 #include "layout.h"
20 #include "message.h"
21 #include "language.h"
22 #include "vhdldocgen.h"
23 #include "util.h"
24 #include "doxygen.h"
25
26 #include <assert.h>
27 #include <qxml.h>
28 #include <qfile.h>
29 #include <qstring.h>
30 #include <qfileinfo.h>
31 #include <qtextstream.h>
32
33 static const char layout_default[] =
34 #include "layout_default.h"
35 ;
36
37 #define ADD_OPTION(langId,text) "|"+QCString().setNum(langId)+"="+text
38
39 #define COMPILE_FOR_1_OPTION(def,langId1,text1) \
40   def+ADD_OPTION(langId1,text1)
41
42 #define COMPILE_FOR_2_OPTIONS(def,langId1,text1,langId2,text2) \
43   COMPILE_FOR_1_OPTION(def,langId1,text1)+ADD_OPTION(langId2,text2)
44
45 #define COMPILE_FOR_3_OPTIONS(def,langId1,text1,langId2,text2,langId3,text3) \
46   COMPILE_FOR_2_OPTIONS(def,langId1,text1,langId2,text2)+ADD_OPTION(langId3,text3)
47
48 #define COMPILE_FOR_4_OPTIONS(def,langId1,text1,langId2,text2,langId3,text3,langId4,text4) \
49   COMPILE_FOR_3_OPTIONS(def,langId1,text1,langId2,text2,langId3,text3)+ADD_OPTION(langId4,text4)
50
51 static bool elemIsVisible(const QXmlAttributes &attrib,bool defVal=TRUE)
52 {
53   QCString visible = convertToQCString(attrib.value("visible"));
54   if (visible.isEmpty()) return defVal;
55   if (visible.at(0)=='$' && visible.length()>1)
56   {
57     QCString id = visible.mid(1);
58     ConfigOption *opt = Config::instance()->get(id);
59     if (opt && opt->kind()==ConfigOption::O_Bool)
60     {
61       return *((ConfigBool *)opt)->valueRef();
62     }
63     else if (!opt)
64     {
65       err("error: found unsupported value %s for visible attribute in layout file\n",
66           visible.data());
67     }
68   }
69   return visible!="no" && visible!="0";
70 }
71
72 //---------------------------------------------------------------------------------
73
74 LayoutNavEntry *LayoutNavEntry::find(LayoutNavEntry::Kind kind,
75     const char *file) const
76 {
77   LayoutNavEntry *result=0;
78   QListIterator<LayoutNavEntry> li(m_children);
79   LayoutNavEntry *entry;
80   for (li.toFirst();(entry=li.current());++li)
81   {
82     // depth first search, needed to find the entry furthest from the 
83     // root in case an entry is in the tree twice
84     result = entry->find(kind,file);
85     if (result) return result;
86     if (entry->kind()==kind && (file==0 || entry->baseFile()==file))
87     {
88       return entry;
89     }
90   }
91   return result;
92 }
93
94 QCString LayoutNavEntry::url() const
95 {
96   QCString url = baseFile().stripWhiteSpace();
97   if (kind()!=LayoutNavEntry::User)
98   {
99     url+=Doxygen::htmlFileExtension;
100   }
101   else if (url.left(5)=="@ref " || url.left(5)=="\\ref ")
102   {
103     Definition *d;
104     QCString anchor;
105     bool found=FALSE;
106     if (resolveLink(0,url.mid(5).stripWhiteSpace(),TRUE,&d,anchor))
107     {
108       if (d && d->isLinkable()) 
109       {
110         url=d->getOutputFileBase()+Doxygen::htmlFileExtension;
111         if (!anchor.isEmpty())
112         {
113           url+="#"+anchor;
114         }
115         found=TRUE;
116       }
117     }
118     if (!found)
119     {
120       msg("warning: explicit link request to '%s' in layout file '%s' could not be resolved\n",qPrint(url.mid(5)),qPrint(Config_getString("LAYOUT_FILE")));
121     }
122   }
123   //printf("LayoutNavEntry::url()=%s\n",url.data());
124   return url;
125 }
126
127 //---------------------------------------------------------------------------------
128
129 class LayoutParser : public QXmlDefaultHandler
130 {
131   private:
132     class StartElementHandler
133     {
134         typedef void (LayoutParser::*Handler)(const QXmlAttributes &attrib); 
135       public:
136         StartElementHandler(LayoutParser *parent, Handler h) 
137           : m_parent(parent), m_handler(h) {}
138         virtual ~StartElementHandler() {}
139         virtual void operator()(const QXmlAttributes &attrib) 
140         { 
141           (m_parent->*m_handler)(attrib); 
142         }
143       protected:
144         StartElementHandler() : m_parent(0), m_handler(0) {}
145       private:
146         LayoutParser *m_parent;
147         Handler m_handler;
148     };
149
150     class StartElementHandlerKind : public StartElementHandler
151     {
152         typedef void (LayoutParser::*Handler)(LayoutDocEntry::Kind kind,
153                                               const QXmlAttributes &attrib); 
154       public:
155         StartElementHandlerKind(LayoutParser *parent, LayoutDocEntry::Kind k,Handler h) 
156           : m_parent(parent), m_kind(k), m_handler(h) {}
157         void operator()(const QXmlAttributes &attrib) 
158         { 
159           (m_parent->*m_handler)(m_kind,attrib); 
160         }
161       private:
162         LayoutParser *m_parent;
163         LayoutDocEntry::Kind m_kind;
164         Handler m_handler;
165     };
166
167     class StartElementHandlerSection : public StartElementHandler
168     {
169         typedef void (LayoutParser::*Handler)(LayoutDocEntry::Kind kind,
170                                               const QXmlAttributes &attrib,
171                                               const QCString &title); 
172       public:
173         StartElementHandlerSection(LayoutParser *parent, LayoutDocEntry::Kind k,Handler h,
174                                 const QCString &title) 
175           : m_parent(parent), m_kind(k), m_handler(h), m_title(title) {}
176         void operator()(const QXmlAttributes &attrib) 
177         { 
178           (m_parent->*m_handler)(m_kind,attrib,m_title); 
179         }
180       private:
181         LayoutParser *m_parent;
182         LayoutDocEntry::Kind m_kind;
183         Handler m_handler;
184         QCString m_title;
185     };
186
187     class StartElementHandlerMember : public StartElementHandler
188     {
189         typedef void (LayoutParser::*Handler)(const QXmlAttributes &attrib,
190                                               MemberList::ListType type,
191                                               const QCString &title,
192                                               const QCString &subtitle); 
193       public:
194         StartElementHandlerMember(LayoutParser *parent, 
195                                   Handler h,
196                                   MemberList::ListType type,
197                                   const QCString &tl,
198                                   const QCString &ss = QCString()
199                                  ) 
200           : m_parent(parent), m_handler(h), m_type(type),
201             m_title(tl), m_subscript(ss) {}
202         void operator()(const QXmlAttributes &attrib) 
203         { 
204           (m_parent->*m_handler)(attrib,m_type,m_title,m_subscript); 
205         }
206       private:
207         LayoutParser *m_parent;
208         Handler m_handler;
209         MemberList::ListType m_type;
210         QCString m_title;
211         QCString m_subscript;
212     };
213
214     class StartElementHandlerNavEntry : public StartElementHandler
215     {
216         typedef void (LayoutParser::*Handler)(LayoutNavEntry::Kind kind,
217                                               const QXmlAttributes &attrib,
218                                               const QCString &title); 
219       public:
220         StartElementHandlerNavEntry(LayoutParser *parent,
221                                LayoutNavEntry::Kind kind, 
222                                Handler h,
223                                const QCString &tl
224                               ) 
225           : m_parent(parent), m_kind(kind), m_handler(h), m_title(tl) {}
226         void operator()(const QXmlAttributes &attrib) 
227         { 
228           (m_parent->*m_handler)(m_kind,attrib,m_title); 
229         }
230       private:
231         LayoutParser *m_parent;
232         LayoutNavEntry::Kind m_kind;
233         Handler m_handler;
234         QCString m_title;
235     };
236
237     class EndElementHandler
238     {
239         typedef void (LayoutParser::*Handler)(); 
240       public:
241         EndElementHandler(LayoutParser *parent, Handler h) : m_parent(parent), m_handler(h) {}
242         void operator()() { (m_parent->*m_handler)(); }
243       private:
244         LayoutParser *m_parent;
245         Handler m_handler;
246     };
247
248
249   public:
250     static LayoutParser &instance()
251     {
252       static LayoutParser *theInstance = new LayoutParser;
253       return *theInstance;
254     }
255     void init()
256     {
257       m_sHandler.setAutoDelete(TRUE);
258       m_eHandler.setAutoDelete(TRUE);
259       m_part = -1; // invalid
260       m_rootNav = 0;
261
262       //bool fortranOpt = Config_getBool("OPTIMIZE_FOR_FORTRAN");
263       //bool vhdlOpt    = Config_getBool("OPTIMIZE_OUTPUT_VHDL");  
264       //bool javaOpt    = Config_getBool("OPTIMIZE_OUTPUT_JAVA");
265
266       // start & end handlers
267       m_sHandler.insert("doxygenlayout", 
268           new StartElementHandler(this,&LayoutParser::startLayout));
269       m_eHandler.insert("doxygenlayout", 
270           new EndElementHandler(this,&LayoutParser::endLayout));
271
272       // class layout handlers
273       m_sHandler.insert("navindex", 
274           new StartElementHandler(this,&LayoutParser::startNavIndex));
275       m_sHandler.insert("navindex/tab", 
276           new StartElementHandler(this,&LayoutParser::startNavEntry));
277       m_eHandler.insert("navindex/tab", 
278           new EndElementHandler(this,&LayoutParser::endNavEntry));
279       m_eHandler.insert("navindex", 
280           new EndElementHandler(this,&LayoutParser::endNavIndex));
281
282       // class layout handlers
283       m_sHandler.insert("class", 
284           new StartElementHandler(this,&LayoutParser::startClass));
285       m_sHandler.insert("class/briefdescription", 
286           new StartElementHandlerKind(this,LayoutDocEntry::BriefDesc,&LayoutParser::startSimpleEntry));
287       m_sHandler.insert("class/detaileddescription", 
288           new StartElementHandlerSection(this,LayoutDocEntry::DetailedDesc,&LayoutParser::startSectionEntry,
289                                          theTranslator->trDetailedDescription()));
290       m_sHandler.insert("class/authorsection", 
291           new StartElementHandlerKind(this,LayoutDocEntry::AuthorSection,&LayoutParser::startSimpleEntry));
292       m_sHandler.insert("class/includes", 
293           new StartElementHandlerKind(this,LayoutDocEntry::ClassIncludes,&LayoutParser::startSimpleEntry));
294       m_sHandler.insert("class/inheritancegraph", 
295           new StartElementHandlerKind(this,LayoutDocEntry::ClassInheritanceGraph,&LayoutParser::startSimpleEntry));
296       m_sHandler.insert("class/collaborationgraph", 
297           new StartElementHandlerKind(this,LayoutDocEntry::ClassCollaborationGraph,&LayoutParser::startSimpleEntry));
298       m_sHandler.insert("class/allmemberslink", 
299           new StartElementHandlerKind(this,LayoutDocEntry::ClassAllMembersLink,&LayoutParser::startSimpleEntry));
300       m_sHandler.insert("class/usedfiles", 
301           new StartElementHandlerKind(this,LayoutDocEntry::ClassUsedFiles,&LayoutParser::startSimpleEntry));
302       m_sHandler.insert("class/memberdecl", 
303           new StartElementHandler(this,&LayoutParser::startMemberDecl));
304       m_sHandler.insert("class/memberdecl/membergroups", 
305           new StartElementHandlerKind(this,LayoutDocEntry::MemberGroups,&LayoutParser::startSimpleEntry));
306       m_sHandler.insert("class/memberdecl/nestedclasses", 
307           new StartElementHandlerSection(this,LayoutDocEntry::ClassNestedClasses,&LayoutParser::startSectionEntry,
308                                          COMPILE_FOR_2_OPTIONS(
309                                            theTranslator->trCompounds(),
310                                            SrcLangExt_VHDL,VhdlDocGen::trVhdlType(VhdlDocGen::ENTITY,FALSE),
311                                            SrcLangExt_Fortran,theTranslator->trDataTypes()
312                                          )));
313       m_sHandler.insert("class/memberdecl/publictypes", 
314           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
315                                         MemberList::pubTypes,theTranslator->trPublicTypes()));
316       m_sHandler.insert("class/memberdecl/publicslots", 
317           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
318                                         MemberList::pubSlots,theTranslator->trPublicSlots())); 
319       m_sHandler.insert("class/memberdecl/signals", 
320           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
321                                         MemberList::signals,theTranslator->trSignals())); 
322       m_sHandler.insert("class/memberdecl/publicmethods", 
323           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
324                                         MemberList::pubMethods,
325                                         COMPILE_FOR_1_OPTION(
326                                           theTranslator->trPublicMembers(),
327                                           SrcLangExt_ObjC,theTranslator->trInstanceMethods()
328                                         ))); 
329       m_sHandler.insert("class/memberdecl/publicstaticmethods", 
330           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
331                                         MemberList::pubStaticMethods,
332                                         COMPILE_FOR_1_OPTION(
333                                           theTranslator->trStaticPublicMembers(),
334                                           SrcLangExt_ObjC,theTranslator->trClassMethods()
335                                         ))); 
336       m_sHandler.insert("class/memberdecl/publicattributes", 
337           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
338                                         MemberList::pubAttribs,theTranslator->trPublicAttribs())); 
339       m_sHandler.insert("class/memberdecl/publicstaticattributes", 
340           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
341                                         MemberList::pubStaticAttribs,theTranslator->trStaticPublicAttribs())); 
342       m_sHandler.insert("class/memberdecl/protectedtypes", 
343           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
344                                         MemberList::proTypes,theTranslator->trProtectedTypes())); 
345       m_sHandler.insert("class/memberdecl/protectedslots", 
346           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
347                                         MemberList::proSlots,theTranslator->trProtectedSlots())); 
348       m_sHandler.insert("class/memberdecl/protectedmethods", 
349           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
350                                         MemberList::proMethods,theTranslator->trProtectedMembers())); 
351       m_sHandler.insert("class/memberdecl/protectedstaticmethods", 
352           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
353                                         MemberList::proStaticMethods,theTranslator->trStaticProtectedMembers()));
354       m_sHandler.insert("class/memberdecl/protectedattributes", 
355           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
356                                         MemberList::proAttribs,theTranslator->trProtectedAttribs())); 
357       m_sHandler.insert("class/memberdecl/protectedstaticattributes", 
358           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
359                                         MemberList::proStaticAttribs,theTranslator->trStaticProtectedAttribs())); 
360       m_sHandler.insert("class/memberdecl/packagetypes", 
361           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
362                                         MemberList::pacTypes,theTranslator->trPackageTypes())); 
363       m_sHandler.insert("class/memberdecl/packagemethods", 
364           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
365                                         MemberList::pacMethods,theTranslator->trPackageMembers())); 
366       m_sHandler.insert("class/memberdecl/packagestaticmethods", 
367           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
368                                         MemberList::pacStaticMethods,theTranslator->trStaticPackageMembers())); 
369       m_sHandler.insert("class/memberdecl/packageattributes", 
370           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
371                                         MemberList::pacAttribs,theTranslator->trPackageAttribs())); 
372       m_sHandler.insert("class/memberdecl/packagestaticattributes", 
373           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
374                                         MemberList::pacStaticAttribs,theTranslator->trStaticPackageAttribs())); 
375       m_sHandler.insert("class/memberdecl/properties", 
376           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
377                                         MemberList::properties,theTranslator->trProperties())); 
378       m_sHandler.insert("class/memberdecl/events", 
379           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
380                                         MemberList::events,theTranslator->trEvents())); 
381       m_sHandler.insert("class/memberdecl/privatetypes", 
382           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
383                                         MemberList::priTypes,theTranslator->trPrivateTypes())); 
384       m_sHandler.insert("class/memberdecl/privateslots", 
385           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
386                                         MemberList::priSlots,theTranslator->trPrivateSlots())); 
387       m_sHandler.insert("class/memberdecl/privatemethods", 
388           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
389                                         MemberList::priMethods,theTranslator->trPrivateMembers())); 
390       m_sHandler.insert("class/memberdecl/privatestaticmethods", 
391           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
392                                         MemberList::priStaticMethods,theTranslator->trStaticPrivateMembers())); 
393       m_sHandler.insert("class/memberdecl/privateattributes", 
394           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
395                                         MemberList::priAttribs,theTranslator->trPrivateAttribs())); 
396       m_sHandler.insert("class/memberdecl/privatestaticattributes", 
397           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
398                                         MemberList::priStaticAttribs,theTranslator->trStaticPrivateAttribs())); 
399       m_sHandler.insert("class/memberdecl/friends", 
400           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
401                                         MemberList::friends,theTranslator->trFriends()));
402       m_sHandler.insert("class/memberdecl/related", 
403           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
404                                         MemberList::related,theTranslator->trRelatedFunctions(),
405                                         theTranslator->trRelatedSubscript())); 
406       m_eHandler.insert("class/memberdecl", 
407           new EndElementHandler(this,&LayoutParser::endMemberDecl));
408       m_sHandler.insert("class/memberdef", 
409           new StartElementHandler(this,&LayoutParser::startMemberDef));
410       m_sHandler.insert("class/memberdef/inlineclasses", 
411           new StartElementHandlerSection(this,LayoutDocEntry::ClassInlineClasses,&LayoutParser::startSectionEntry,
412                                          COMPILE_FOR_1_OPTION(
413                                            theTranslator->trClassDocumentation(),
414                                            SrcLangExt_Fortran,theTranslator->trTypeDocumentation()
415                                          )));
416       m_sHandler.insert("class/memberdef/typedefs", 
417           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
418                                         MemberList::typedefMembers,theTranslator->trMemberTypedefDocumentation()));
419       m_sHandler.insert("class/memberdef/enums", 
420           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
421                                         MemberList::enumMembers,theTranslator->trMemberEnumerationDocumentation()));
422       m_sHandler.insert("class/memberdef/constructors", 
423           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
424                                         MemberList::constructors,theTranslator->trConstructorDocumentation()));
425       m_sHandler.insert("class/memberdef/functions", 
426           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
427                                         MemberList::functionMembers,
428                                         COMPILE_FOR_2_OPTIONS(
429                                           theTranslator->trMemberFunctionDocumentation(),
430                                           SrcLangExt_ObjC,theTranslator->trMethodDocumentation(),
431                                           SrcLangExt_Fortran,theTranslator->trMemberFunctionDocumentationFortran()
432                                         )));
433       m_sHandler.insert("class/memberdef/related", 
434           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
435                                         MemberList::relatedMembers,theTranslator->trRelatedFunctionDocumentation()));
436       m_sHandler.insert("class/memberdef/variables", 
437           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
438                                         MemberList::variableMembers,theTranslator->trMemberDataDocumentation()));
439       m_sHandler.insert("class/memberdef/properties", 
440           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
441                                         MemberList::propertyMembers,theTranslator->trPropertyDocumentation()));
442       m_sHandler.insert("class/memberdef/events", 
443           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
444                                         MemberList::eventMembers,theTranslator->trEventDocumentation()));
445       m_eHandler.insert("class/memberdef", 
446           new EndElementHandler(this,&LayoutParser::endMemberDef));
447       m_eHandler.insert("class", 
448           new EndElementHandler(this,&LayoutParser::endClass));
449
450
451       // namespace layout handlers
452       m_sHandler.insert("namespace", 
453           new StartElementHandler(this,&LayoutParser::startNamespace));
454       m_sHandler.insert("namespace/briefdescription", 
455           new StartElementHandlerKind(this,LayoutDocEntry::BriefDesc,&LayoutParser::startSimpleEntry));
456       m_sHandler.insert("namespace/detaileddescription", 
457           new StartElementHandlerSection(this,LayoutDocEntry::DetailedDesc,&LayoutParser::startSectionEntry,
458                                          theTranslator->trDetailedDescription()));
459       m_sHandler.insert("namespace/authorsection", 
460           new StartElementHandlerKind(this,LayoutDocEntry::AuthorSection,&LayoutParser::startSimpleEntry));
461       m_sHandler.insert("namespace/memberdecl", 
462           new StartElementHandler(this,&LayoutParser::startMemberDecl));
463       m_sHandler.insert("namespace/memberdecl/nestednamespaces", 
464           new StartElementHandlerSection(this,LayoutDocEntry::NamespaceNestedNamespaces,&LayoutParser::startSectionEntry,
465                                          COMPILE_FOR_3_OPTIONS(
466                                            theTranslator->trNamespaces(),
467                                            SrcLangExt_Java,theTranslator->trPackages(),
468                                            SrcLangExt_VHDL,theTranslator->trPackages(),
469                                            SrcLangExt_Fortran,theTranslator->trModules()
470                                          )));
471       m_sHandler.insert("namespace/memberdecl/classes", 
472           new StartElementHandlerSection(this,LayoutDocEntry::NamespaceClasses,&LayoutParser::startSectionEntry,
473                                          COMPILE_FOR_2_OPTIONS(
474                                            theTranslator->trCompounds(),
475                                            SrcLangExt_VHDL,VhdlDocGen::trVhdlType(VhdlDocGen::ENTITY,FALSE),
476                                            SrcLangExt_Fortran,theTranslator->trDataTypes()
477                                          )));
478       m_sHandler.insert("namespace/memberdecl/membergroups", 
479           new StartElementHandlerKind(this,LayoutDocEntry::MemberGroups,&LayoutParser::startSimpleEntry));
480       m_sHandler.insert("namespace/memberdecl/typedefs", 
481           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
482                                         MemberList::decTypedefMembers,theTranslator->trTypedefs()));
483       m_sHandler.insert("namespace/memberdecl/enums", 
484           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
485                                         MemberList::decEnumMembers,theTranslator->trEnumerations()));
486       m_sHandler.insert("namespace/memberdecl/functions", 
487           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
488                                         MemberList::decFuncMembers,
489                                         COMPILE_FOR_2_OPTIONS(
490                                           theTranslator->trFunctions(),
491                                           SrcLangExt_Fortran,theTranslator->trSubprograms(),
492                                           SrcLangExt_VHDL,VhdlDocGen::trFunctionAndProc()
493                                         )));
494       m_sHandler.insert("namespace/memberdecl/variables", 
495           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
496                                         MemberList::decVarMembers,theTranslator->trVariables()));
497       m_eHandler.insert("namespace/memberdecl", 
498           new EndElementHandler(this,&LayoutParser::endMemberDecl));
499       m_sHandler.insert("namespace/memberdef", 
500           new StartElementHandler(this,&LayoutParser::startMemberDef));
501       m_sHandler.insert("namespace/memberdef/inlineclasses", 
502           new StartElementHandlerSection(this,LayoutDocEntry::NamespaceInlineClasses,&LayoutParser::startSectionEntry,
503                                          COMPILE_FOR_1_OPTION(
504                                            theTranslator->trClassDocumentation(),
505                                            SrcLangExt_Fortran,theTranslator->trTypeDocumentation()
506                                          )));
507       m_sHandler.insert("namespace/memberdef/typedefs", 
508           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
509                                         MemberList::docTypedefMembers,theTranslator->trTypedefDocumentation()));
510       m_sHandler.insert("namespace/memberdef/enums", 
511           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
512                                         MemberList::docEnumMembers,theTranslator->trEnumerationTypeDocumentation()));
513       m_sHandler.insert("namespace/memberdef/functions", 
514           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
515                                         MemberList::docFuncMembers,
516                                         COMPILE_FOR_1_OPTION(
517                                           theTranslator->trFunctionDocumentation(),
518                                           SrcLangExt_Fortran,theTranslator->trSubprogramDocumentation()
519                                         )));
520       m_sHandler.insert("namespace/memberdef/variables", 
521           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
522                                         MemberList::docVarMembers,theTranslator->trVariableDocumentation()));
523       m_eHandler.insert("namespace/memberdef", 
524           new EndElementHandler(this,&LayoutParser::endMemberDef));
525       m_eHandler.insert("namespace", 
526           new EndElementHandler(this,&LayoutParser::endNamespace));
527
528       // file layout handlers
529       m_sHandler.insert("file", 
530           new StartElementHandler(this,&LayoutParser::startFile));
531       m_sHandler.insert("file/briefdescription", 
532           new StartElementHandlerKind(this,LayoutDocEntry::BriefDesc,&LayoutParser::startSimpleEntry));
533       m_sHandler.insert("file/detaileddescription", 
534           new StartElementHandlerSection(this,LayoutDocEntry::DetailedDesc,&LayoutParser::startSectionEntry,
535                                          theTranslator->trDetailedDescription()));
536       m_sHandler.insert("file/authorsection", 
537           new StartElementHandlerKind(this,LayoutDocEntry::AuthorSection,&LayoutParser::startSimpleEntry));
538       m_sHandler.insert("file/includes", 
539           new StartElementHandlerKind(this,LayoutDocEntry::FileIncludes,&LayoutParser::startSimpleEntry));
540       m_sHandler.insert("file/includegraph", 
541           new StartElementHandlerKind(this,LayoutDocEntry::FileIncludeGraph,&LayoutParser::startSimpleEntry));
542       m_sHandler.insert("file/includedbygraph", 
543           new StartElementHandlerKind(this,LayoutDocEntry::FileIncludedByGraph,&LayoutParser::startSimpleEntry));
544       m_sHandler.insert("file/sourcelink", 
545           new StartElementHandlerKind(this,LayoutDocEntry::FileSourceLink,&LayoutParser::startSimpleEntry));
546       m_sHandler.insert("file/memberdecl/membergroups", 
547           new StartElementHandlerKind(this,LayoutDocEntry::MemberGroups,&LayoutParser::startSimpleEntry));
548       m_sHandler.insert("file/memberdecl", 
549           new StartElementHandler(this,&LayoutParser::startMemberDecl));
550       m_sHandler.insert("file/memberdecl/classes", 
551           new StartElementHandlerSection(this,LayoutDocEntry::FileClasses,&LayoutParser::startSectionEntry,
552                                          COMPILE_FOR_2_OPTIONS(
553                                            theTranslator->trCompounds(),
554                                            SrcLangExt_VHDL,VhdlDocGen::trVhdlType(VhdlDocGen::ENTITY,FALSE),
555                                            SrcLangExt_Fortran,theTranslator->trDataTypes()
556                                          )));
557       m_sHandler.insert("file/memberdecl/namespaces", 
558           new StartElementHandlerSection(this,LayoutDocEntry::FileNamespaces,&LayoutParser::startSectionEntry,
559                                          COMPILE_FOR_2_OPTIONS(
560                                            theTranslator->trNamespaces(),
561                                            SrcLangExt_Java,theTranslator->trPackages(),
562                                            SrcLangExt_Fortran,theTranslator->trModules()
563                                          )));
564       m_sHandler.insert("file/memberdecl/defines", 
565           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
566                                         MemberList::decDefineMembers,theTranslator->trDefines()));
567       m_sHandler.insert("file/memberdecl/typedefs", 
568           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
569                                         MemberList::decTypedefMembers,theTranslator->trTypedefs()));
570       m_sHandler.insert("file/memberdecl/enums", 
571           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
572                                         MemberList::decEnumMembers,theTranslator->trEnumerations()));
573       m_sHandler.insert("file/memberdecl/functions", 
574           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
575                                         MemberList::decFuncMembers,
576                                         COMPILE_FOR_2_OPTIONS(
577                                           theTranslator->trFunctions(),
578                                           SrcLangExt_Fortran,theTranslator->trSubprograms(),
579                                           SrcLangExt_VHDL,VhdlDocGen::trFunctionAndProc()
580                                         )));
581       m_sHandler.insert("file/memberdecl/variables", 
582           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
583                                         MemberList::decVarMembers,theTranslator->trVariables()));
584
585       m_eHandler.insert("file/memberdecl", 
586           new EndElementHandler(this,&LayoutParser::endMemberDecl));
587       m_sHandler.insert("file/memberdef", 
588           new StartElementHandler(this,&LayoutParser::startMemberDef));
589       m_sHandler.insert("file/memberdef/inlineclasses", 
590           new StartElementHandlerSection(this,LayoutDocEntry::FileInlineClasses,&LayoutParser::startSectionEntry,
591                                          COMPILE_FOR_1_OPTION(
592                                            theTranslator->trClassDocumentation(),
593                                            SrcLangExt_Fortran,theTranslator->trTypeDocumentation()
594                                          )));
595       m_sHandler.insert("file/memberdef/defines", 
596           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
597                                         MemberList::docDefineMembers,theTranslator->trDefineDocumentation()));
598       m_sHandler.insert("file/memberdef/typedefs", 
599           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
600                                         MemberList::docTypedefMembers,theTranslator->trTypedefDocumentation()));
601       m_sHandler.insert("file/memberdef/enums", 
602           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
603                                         MemberList::docEnumMembers,
604                                         theTranslator->trEnumerationTypeDocumentation()));
605       m_sHandler.insert("file/memberdef/functions", 
606           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
607                                         MemberList::docFuncMembers,
608                                         COMPILE_FOR_1_OPTION(
609                                           theTranslator->trFunctionDocumentation(),
610                                           SrcLangExt_Fortran,theTranslator->trSubprogramDocumentation()
611                                         )));
612       m_sHandler.insert("file/memberdef/variables", 
613           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
614                                         MemberList::docVarMembers,theTranslator->trVariableDocumentation()));
615       m_eHandler.insert("file/memberdef", 
616           new EndElementHandler(this,&LayoutParser::endMemberDef));
617       m_eHandler.insert("file", 
618           new EndElementHandler(this,&LayoutParser::endFile));
619
620       // group layout handlers
621       m_sHandler.insert("group", 
622           new StartElementHandler(this,&LayoutParser::startGroup));
623       m_sHandler.insert("group/briefdescription", 
624           new StartElementHandlerKind(this,LayoutDocEntry::BriefDesc,&LayoutParser::startSimpleEntry));
625       m_sHandler.insert("group/detaileddescription", 
626           new StartElementHandlerSection(this,LayoutDocEntry::DetailedDesc,&LayoutParser::startSectionEntry,
627                                          theTranslator->trDetailedDescription()));
628       m_sHandler.insert("group/authorsection", 
629           new StartElementHandlerKind(this,LayoutDocEntry::AuthorSection,&LayoutParser::startSimpleEntry));
630       m_sHandler.insert("group/groupgraph", 
631           new StartElementHandlerKind(this,LayoutDocEntry::GroupGraph,&LayoutParser::startSimpleEntry));
632       m_sHandler.insert("group/memberdecl/membergroups", 
633           new StartElementHandlerKind(this,LayoutDocEntry::MemberGroups,&LayoutParser::startSimpleEntry));
634       m_sHandler.insert("group/memberdecl", 
635           new StartElementHandler(this,&LayoutParser::startMemberDecl));
636       m_sHandler.insert("group/memberdecl/classes", 
637           new StartElementHandlerSection(this,LayoutDocEntry::GroupClasses,&LayoutParser::startSectionEntry,
638                                          COMPILE_FOR_2_OPTIONS(
639                                            theTranslator->trCompounds(),
640                                            SrcLangExt_VHDL,VhdlDocGen::trVhdlType(VhdlDocGen::ENTITY,FALSE),
641                                            SrcLangExt_Fortran,theTranslator->trDataTypes()
642                                          )));
643       m_sHandler.insert("group/memberdecl/namespaces", 
644           new StartElementHandlerSection(this,LayoutDocEntry::GroupNamespaces,&LayoutParser::startSectionEntry,
645                                          COMPILE_FOR_2_OPTIONS(
646                                            theTranslator->trNamespaces(),
647                                            SrcLangExt_Java,theTranslator->trPackages(),
648                                            SrcLangExt_Fortran,theTranslator->trModules()
649                                          )));
650       m_sHandler.insert("group/memberdecl/dirs", 
651           new StartElementHandlerSection(this,LayoutDocEntry::GroupDirs,&LayoutParser::startSectionEntry,
652                                          theTranslator->trDirectories()
653                                          ));
654       m_sHandler.insert("group/memberdecl/nestedgroups", 
655           new StartElementHandlerSection(this,LayoutDocEntry::GroupNestedGroups,&LayoutParser::startSectionEntry,
656                                          theTranslator->trModules()
657                                          ));
658       m_sHandler.insert("group/memberdecl/files", 
659           new StartElementHandlerSection(this,LayoutDocEntry::GroupFiles,&LayoutParser::startSectionEntry,
660                                          theTranslator->trFile(TRUE,FALSE)
661                                          ));
662
663       m_sHandler.insert("group/memberdecl/defines", 
664           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
665                                         MemberList::decDefineMembers,theTranslator->trDefines()));
666       m_sHandler.insert("group/memberdecl/typedefs", 
667           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
668                                         MemberList::decTypedefMembers,theTranslator->trTypedefs()));
669       m_sHandler.insert("group/memberdecl/enums", 
670           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
671                                         MemberList::decEnumMembers,theTranslator->trEnumerations()));
672       m_sHandler.insert("group/memberdecl/enumvalues", 
673           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
674                                         MemberList::decEnumValMembers,theTranslator->trEnumerationValues()));
675       m_sHandler.insert("group/memberdecl/functions", 
676           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
677                                         MemberList::decFuncMembers,
678                                         COMPILE_FOR_2_OPTIONS(
679                                           theTranslator->trFunctions(),
680                                           SrcLangExt_Fortran,theTranslator->trSubprograms(),
681                                           SrcLangExt_VHDL,VhdlDocGen::trFunctionAndProc()
682                                         )));
683       m_sHandler.insert("group/memberdecl/variables", 
684           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
685                                         MemberList::decVarMembers,theTranslator->trVariables()));
686       m_sHandler.insert("group/memberdecl/signals", 
687           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
688                                         MemberList::decSignalMembers,theTranslator->trSignals()));
689       m_sHandler.insert("group/memberdecl/publicslots", 
690           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
691                                         MemberList::decPubSlotMembers,theTranslator->trPublicSlots()));
692       m_sHandler.insert("group/memberdecl/protectedslots", 
693           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
694                                         MemberList::decProSlotMembers,theTranslator->trProtectedSlots()));
695       m_sHandler.insert("group/memberdecl/privateslots", 
696           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
697                                         MemberList::decPriSlotMembers,theTranslator->trPrivateSlots()));
698       m_sHandler.insert("group/memberdecl/events", 
699           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
700                                         MemberList::decEventMembers,theTranslator->trEvents()));
701       m_sHandler.insert("group/memberdecl/properties", 
702           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
703                                         MemberList::decPropMembers,theTranslator->trProperties()));
704       m_sHandler.insert("group/memberdecl/friends", 
705           new StartElementHandlerMember(this,&LayoutParser::startMemberDeclEntry,
706                                         MemberList::decFriendMembers,theTranslator->trFriends()));
707       m_eHandler.insert("group/memberdecl", 
708           new EndElementHandler(this,&LayoutParser::endMemberDecl));
709       m_sHandler.insert("group/memberdef", 
710           new StartElementHandler(this,&LayoutParser::startMemberDef));
711       m_sHandler.insert("group/memberdef/pagedocs", 
712           new StartElementHandlerKind(this,LayoutDocEntry::GroupPageDocs,&LayoutParser::startSimpleEntry));
713       m_sHandler.insert("group/memberdef/inlineclasses", 
714           new StartElementHandlerSection(this,LayoutDocEntry::GroupInlineClasses,&LayoutParser::startSectionEntry,
715                                          COMPILE_FOR_1_OPTION(
716                                            theTranslator->trClassDocumentation(),
717                                            SrcLangExt_Fortran,theTranslator->trTypeDocumentation()
718                                          )));
719       m_sHandler.insert("group/memberdef/defines", 
720           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
721                                         MemberList::docDefineMembers,theTranslator->trDefineDocumentation()));
722       m_sHandler.insert("group/memberdef/typedefs", 
723           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
724                                         MemberList::docTypedefMembers,theTranslator->trTypedefDocumentation()));
725       m_sHandler.insert("group/memberdef/enums", 
726           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
727                                         MemberList::docEnumMembers,theTranslator->trEnumerationTypeDocumentation()));
728       m_sHandler.insert("group/memberdef/enumvalues", 
729           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
730                                         MemberList::docEnumValMembers,theTranslator->trEnumerationValueDocumentation()));
731       m_sHandler.insert("group/memberdef/functions", 
732           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
733                                         MemberList::docFuncMembers,
734                                         COMPILE_FOR_1_OPTION(
735                                           theTranslator->trFunctionDocumentation(),
736                                           SrcLangExt_Fortran,theTranslator->trSubprogramDocumentation()
737                                        )));
738       m_sHandler.insert("group/memberdef/variables", 
739           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
740                                         MemberList::docVarMembers,theTranslator->trVariableDocumentation()));
741       m_sHandler.insert("group/memberdef/signals", 
742           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
743                                         MemberList::docSignalMembers,theTranslator->trSignals())); 
744       m_sHandler.insert("group/memberdef/publicslots", 
745           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
746                                         MemberList::docPubSlotMembers,theTranslator->trPublicSlots()));
747       m_sHandler.insert("group/memberdef/protectedslots", 
748           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
749                                         MemberList::docProSlotMembers,theTranslator->trProtectedSlots()));
750       m_sHandler.insert("group/memberdef/privateslots", 
751           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
752                                         MemberList::docPriSlotMembers,theTranslator->trPrivateSlots()));
753       m_sHandler.insert("group/memberdef/events", 
754           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
755                                         MemberList::docEventMembers,theTranslator->trEvents()));
756       m_sHandler.insert("group/memberdef/properties", 
757           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
758                                         MemberList::docPropMembers,theTranslator->trProperties()));
759       m_sHandler.insert("group/memberdef/friends", 
760           new StartElementHandlerMember(this,&LayoutParser::startMemberDefEntry,
761                                         MemberList::docFriendMembers,theTranslator->trFriends()));
762       m_eHandler.insert("group/memberdef", 
763           new EndElementHandler(this,&LayoutParser::endMemberDef));
764       m_eHandler.insert("group", 
765           new EndElementHandler(this,&LayoutParser::endGroup));
766
767       // directory layout handlers
768       m_sHandler.insert("directory", 
769           new StartElementHandler(this,&LayoutParser::startDirectory));
770       m_sHandler.insert("directory/briefdescription", 
771           new StartElementHandlerKind(this,LayoutDocEntry::BriefDesc,&LayoutParser::startSimpleEntry));
772       m_sHandler.insert("directory/detaileddescription", 
773           new StartElementHandlerSection(this,LayoutDocEntry::DetailedDesc,&LayoutParser::startSectionEntry,
774                                          theTranslator->trDetailedDescription()));
775       m_sHandler.insert("directory/directorygraph", 
776           new StartElementHandlerKind(this,LayoutDocEntry::DirGraph,&LayoutParser::startSimpleEntry));
777       m_sHandler.insert("directory/memberdecl", 
778           new StartElementHandler(this,&LayoutParser::startMemberDecl));
779       m_sHandler.insert("directory/memberdecl/dirs", 
780           new StartElementHandlerKind(this,LayoutDocEntry::DirSubDirs,&LayoutParser::startSimpleEntry));
781       m_sHandler.insert("directory/memberdecl/files", 
782           new StartElementHandlerKind(this,LayoutDocEntry::DirFiles,&LayoutParser::startSimpleEntry));
783       m_eHandler.insert("directory/memberdecl", 
784           new EndElementHandler(this,&LayoutParser::endMemberDecl));
785       m_eHandler.insert("directory", 
786           new EndElementHandler(this,&LayoutParser::endDirectory));
787     }
788
789     void startSimpleEntry(LayoutDocEntry::Kind k,const QXmlAttributes &attrib)
790     {
791       bool isVisible = elemIsVisible(attrib);
792       if (m_part!=-1 && isVisible)
793       {
794         LayoutDocManager::instance().addEntry((LayoutDocManager::LayoutPart)m_part,
795                                               new LayoutDocEntrySimple(k));
796       }
797     }
798
799     void startSectionEntry(LayoutDocEntry::Kind k,const QXmlAttributes &attrib,
800                            const QCString &title)
801     {
802       bool isVisible = elemIsVisible(attrib);
803       QCString userTitle = convertToQCString(attrib.value("title"));
804       //printf("startSectionEntry: title='%s' userTitle='%s'\n",
805       //    title.data(),userTitle.data());
806       if (userTitle.isEmpty())  userTitle = title;
807       if (m_part!=-1 && isVisible)
808       {
809         LayoutDocManager::instance().addEntry((LayoutDocManager::LayoutPart)m_part,
810                                               new LayoutDocEntrySection(k,userTitle));
811       }
812     }
813
814
815     void startMemberDeclEntry(const QXmlAttributes &attrib,MemberList::ListType type,
816                               const QCString &title,const QCString &subscript)
817     {
818       //QCString visible = convertToQCString(attrib.value("visible"));
819       //bool isVisible = visible.isEmpty() || (visible!="no" && visible!="0");
820       QCString userTitle     = convertToQCString(attrib.value("title"));
821       QCString userSubscript = convertToQCString(attrib.value("subtitle"));
822       if (userTitle.isEmpty())     userTitle     = title;
823       if (userSubscript.isEmpty()) userSubscript = subscript;
824       //printf("memberdecl: %s\n",userTitle.data());
825       if (m_part!=-1 /*&& isVisible*/)
826       {
827         LayoutDocManager::instance().addEntry((LayoutDocManager::LayoutPart)m_part,
828                                               new LayoutDocEntryMemberDecl(type,userTitle,userSubscript));
829       }
830     }
831
832     void startMemberDefEntry(const QXmlAttributes &attrib,MemberList::ListType type,
833                              const QCString &title,const QCString &)
834     {
835       QCString userTitle = convertToQCString(attrib.value("title"));
836       if (userTitle.isEmpty()) userTitle = title;
837       //printf("memberdef: %s\n",userTitle.data());
838       if (m_part!=-1 /*&& isVisible*/)
839       {
840         LayoutDocManager::instance().addEntry((LayoutDocManager::LayoutPart)m_part,
841                                               new LayoutDocEntryMemberDef(type,userTitle));
842       }
843     }
844
845     void startLayout(const QXmlAttributes &)
846     {
847     }
848
849     void endLayout()
850     {
851     }
852
853     void startNavIndex(const QXmlAttributes &)
854     {
855       m_scope="navindex/";
856       m_rootNav = LayoutDocManager::instance().rootNavEntry();
857       if (m_rootNav) m_rootNav->clear();
858     }
859
860     void endNavIndex()
861     {
862       m_scope="";
863       if (m_rootNav && !m_rootNav->find(LayoutNavEntry::MainPage))
864       {
865         // no MainPage node... add one as the first item of the root node...
866         new LayoutNavEntry(m_rootNav,LayoutNavEntry::MainPage, TRUE, 
867             /*Config_getBool("GENERATE_TREEVIEW") ? "main" :*/ "index",
868             theTranslator->trMainPage(),TRUE);
869       }
870     }
871
872     void startNavEntry(const QXmlAttributes &attrib)
873     {
874       static bool javaOpt    = Config_getBool("OPTIMIZE_OUTPUT_JAVA");
875       static bool fortranOpt = Config_getBool("OPTIMIZE_FOR_FORTRAN");
876       static bool vhdlOpt    = Config_getBool("OPTIMIZE_OUTPUT_VHDL");  
877       static bool hasGraphicalHierarchy = Config_getBool("HAVE_DOT") &&
878                                           Config_getBool("GRAPHICAL_HIERARCHY");
879       static bool extractAll = Config_getBool("EXTRACT_ALL");
880       static struct NavEntryMap
881       {
882         const char *typeStr;       // type attribute name in the XML file
883         LayoutNavEntry::Kind kind; // corresponding enum name
884         QCString mainName;         // default title for an item if it has children
885         QCString subName;          // optional name for an item if it is rendered as a child
886         QCString intro;            // introduction text to be put on the index page
887         QCString baseFile;         // base name of the file containing the index page
888       } mapping[] =
889       {
890         { "mainpage",
891           LayoutNavEntry::MainPage,
892           theTranslator->trMainPage(),
893           QCString(),
894           QCString(),
895           "index"
896         },
897         { "pages",
898           LayoutNavEntry::Pages,
899           theTranslator->trRelatedPages(),
900           QCString(),
901           theTranslator->trRelatedPagesDescription(),
902           "pages"
903         },
904         { "modules",
905           LayoutNavEntry::Modules,
906           theTranslator->trModules(),
907           QCString(),
908           theTranslator->trModulesDescription(),
909           "modules"
910         },
911         { "namespaces",
912           LayoutNavEntry::Namespaces,
913           javaOpt || vhdlOpt   ? theTranslator->trPackages() : fortranOpt ? theTranslator->trModules() : theTranslator->trNamespaces(),
914           javaOpt || vhdlOpt   ? theTranslator->trPackages() : fortranOpt ? theTranslator->trModulesList() : theTranslator->trNamespaceList(),
915           javaOpt || vhdlOpt   ? theTranslator->trPackageListDescription() : fortranOpt ? theTranslator->trModulesListDescription(extractAll) : theTranslator->trNamespaceListDescription(extractAll),
916           "namespaces"
917         },
918         { "namespacelist",
919           LayoutNavEntry::NamespaceList,
920           javaOpt || vhdlOpt   ? theTranslator->trPackages() : fortranOpt ? theTranslator->trModulesList() : theTranslator->trNamespaceList(),
921           QCString(),
922           javaOpt || vhdlOpt   ? theTranslator->trPackageListDescription() : fortranOpt ? theTranslator->trModulesListDescription(extractAll) : theTranslator->trNamespaceListDescription(extractAll),
923           "namespaces"
924         },
925         { "namespacemembers",
926           LayoutNavEntry::NamespaceMembers,
927           javaOpt || vhdlOpt   ? theTranslator->trPackageMembers() : fortranOpt ? theTranslator->trModulesMembers() : theTranslator->trNamespaceMembers(),
928           QCString(),
929           fortranOpt ? theTranslator->trModulesMemberDescription(extractAll) : theTranslator->trNamespaceMemberDescription(extractAll),
930           "namespacemembers"
931         },
932         { "classindex",
933           LayoutNavEntry::ClassIndex,
934           fortranOpt ? theTranslator->trDataTypes() : vhdlOpt ? VhdlDocGen::trDesignUnits() : theTranslator->trCompoundIndex(),
935           QCString(),
936           QCString(),
937           "classes"
938         },
939         { "classes",
940           LayoutNavEntry::Classes,
941           fortranOpt ? theTranslator->trCompoundListFortran() : vhdlOpt ? VhdlDocGen::trDesignUnitList() : theTranslator->trClasses(),
942           theTranslator->trCompoundList(),
943           fortranOpt ? theTranslator->trCompoundListDescriptionFortran() : vhdlOpt ? VhdlDocGen::trDesignUnitListDescription() : theTranslator->trCompoundListDescription(),
944           "annotated"
945         },
946         { "classlist",
947           LayoutNavEntry::ClassList,
948           fortranOpt ? theTranslator->trCompoundListFortran() : vhdlOpt ? VhdlDocGen::trDesignUnitList() : theTranslator->trCompoundList(),
949           QCString(),
950           fortranOpt ? theTranslator->trCompoundListDescriptionFortran() : vhdlOpt ? VhdlDocGen::trDesignUnitListDescription() : theTranslator->trCompoundListDescription(),
951           "annotated"
952         },
953         { "hierarchy",
954           LayoutNavEntry::ClassHierarchy,
955           vhdlOpt    ? VhdlDocGen::trDesignUnitHierarchy() : theTranslator->trClassHierarchy(),
956           QCString(),
957           theTranslator->trClassHierarchyDescription(),
958           hasGraphicalHierarchy ? "inherits" : "hierarchy"
959         },
960         { "classmembers",
961           LayoutNavEntry::ClassMembers,
962           fortranOpt ? theTranslator->trCompoundMembersFortran() : vhdlOpt ? VhdlDocGen::trDesignUnitMembers() : theTranslator->trCompoundMembers(),
963           QCString(),
964           fortranOpt ? theTranslator->trCompoundMembersDescriptionFortran(extractAll) : theTranslator->trCompoundMembersDescription(extractAll),
965           "functions"
966         },
967         { "files",
968           LayoutNavEntry::Files,
969           theTranslator->trFile(TRUE,FALSE),
970           theTranslator->trFileList(),
971           theTranslator->trFileListDescription(extractAll),
972           "files"
973         },
974         { "filelist",
975           LayoutNavEntry::FileList,
976           theTranslator->trFileList(),
977           QCString(),
978           theTranslator->trFileListDescription(extractAll),
979           "files"
980         },
981         { "globals",
982           LayoutNavEntry::FileGlobals,
983           theTranslator->trFileMembers(),
984           QCString(),
985           theTranslator->trFileMembersDescription(extractAll),
986           "globals"
987         },
988         //{ "dirs",
989         //  LayoutNavEntry::Dirs,
990         //  theTranslator->trDirectories(),
991         //  QCString(),
992         //  theTranslator->trDirDescription(),
993         //  "dirs"
994         //},
995         { "examples",
996           LayoutNavEntry::Examples,
997           theTranslator->trExamples(),
998           QCString(),
999           theTranslator->trExamplesDescription(),
1000           "examples"
1001         },
1002         { "user",
1003           LayoutNavEntry::User,
1004           QCString(),
1005           QCString(),
1006           QCString(),
1007           "user"
1008         },
1009         { "usergroup",
1010           LayoutNavEntry::UserGroup,
1011           QCString(),
1012           QCString(),
1013           QCString(),
1014           "usergroup"
1015         },
1016         { 0, // end of list
1017           (LayoutNavEntry::Kind)0,
1018           QCString(),
1019           QCString(),
1020           QCString(),
1021           QCString()
1022         }
1023       };
1024       LayoutNavEntry::Kind kind;
1025       // find type in the table
1026       int i=0;
1027       QString type = attrib.value("type");
1028       while (mapping[i].typeStr)
1029       {
1030         if (mapping[i].typeStr==type)
1031         {
1032           kind = mapping[i].kind;
1033           break;
1034         }
1035         i++;
1036       }
1037       if (mapping[i].typeStr==0) 
1038       {
1039         if (type.isEmpty())
1040         {
1041           err("error: an entry tag within a navindex has no type attribute! Check your layout file!\n");
1042         }
1043         else
1044         {
1045           err("error: the type '%s' is not supported for the entry tag within a navindex! Check your layout file!\n",type.data());
1046         }
1047         m_invalidEntry=TRUE;
1048         return;
1049       }
1050       QCString baseFile = mapping[i].baseFile;
1051       QCString title = convertToQCString(attrib.value("title"));
1052       bool isVisible = elemIsVisible(attrib);
1053       if (title.isEmpty()) // use default title
1054       { 
1055         title = mapping[i].mainName; // use title for main row
1056         if (m_rootNav!=LayoutDocManager::instance().rootNavEntry() && !mapping[i].subName.isEmpty())
1057         {
1058           title = mapping[i].subName; // if this is a child of another row, use the subName if available
1059                                       // this is mainly done to get compatible naming with older versions.
1060         }
1061       }
1062       QCString intro = convertToQCString(attrib.value("intro"));
1063       if (intro.isEmpty()) // use default intro text
1064       {
1065         intro = mapping[i].intro;
1066       }
1067       QCString url = convertToQCString(attrib.value("url"));
1068       if (mapping[i].kind==LayoutNavEntry::User && !url.isEmpty())
1069       {
1070         baseFile=url;
1071       }
1072       else if (kind==LayoutNavEntry::UserGroup)
1073       {
1074         baseFile+=QCString().sprintf("%d",m_userGroupCount++);
1075       }
1076       // create new item and make it the new root
1077       m_rootNav = new LayoutNavEntry(m_rootNav,kind,kind==LayoutNavEntry::MainPage?TRUE:isVisible,baseFile,title,intro);
1078     }
1079
1080     void endNavEntry()
1081     {
1082       // set the root back to the parent
1083       if (m_rootNav && !m_invalidEntry) m_rootNav = m_rootNav->parent();
1084       m_invalidEntry=FALSE;
1085     }
1086
1087     void startClass(const QXmlAttributes &)
1088     {
1089       LayoutDocManager::instance().clear(LayoutDocManager::Class);
1090       m_scope="class/";
1091       m_part = (int)LayoutDocManager::Class;
1092     }
1093
1094     void endClass()
1095     {
1096       m_scope="";
1097       m_part = -1;
1098     }
1099
1100     void startNamespace(const QXmlAttributes &)
1101     {
1102       LayoutDocManager::instance().clear(LayoutDocManager::Namespace);
1103       m_scope="namespace/";
1104       m_part = (int)LayoutDocManager::Namespace;
1105     }
1106
1107     void endNamespace()
1108     {
1109       m_scope="";
1110       m_part = -1;
1111     }
1112
1113     void startFile(const QXmlAttributes &)
1114     {
1115       LayoutDocManager::instance().clear(LayoutDocManager::File);
1116       m_scope="file/";
1117       m_part = (int)LayoutDocManager::File;
1118     }
1119
1120     void endFile()
1121     {
1122       m_scope="";
1123       m_part = -1;
1124     }
1125
1126     void startGroup(const QXmlAttributes &)
1127     {
1128       LayoutDocManager::instance().clear(LayoutDocManager::Group);
1129       m_scope="group/";
1130       m_part = (int)LayoutDocManager::Group;
1131     }
1132
1133     void endGroup()
1134     {
1135       m_scope="";
1136       m_part = -1;
1137     }
1138
1139     void startDirectory(const QXmlAttributes &)
1140     {
1141       LayoutDocManager::instance().clear(LayoutDocManager::Directory);
1142       m_scope="directory/";
1143       m_part = (int)LayoutDocManager::Directory;
1144     }
1145
1146     void endDirectory()
1147     {
1148       m_scope="";
1149       m_part = -1;
1150     }
1151
1152     void startMemberDef(const QXmlAttributes &)
1153     {
1154       m_scope+="memberdef/";
1155       if (m_part!=-1)
1156       {
1157         LayoutDocManager::instance().addEntry((LayoutDocManager::LayoutPart)m_part,
1158                                               new LayoutDocEntrySimple(LayoutDocEntry::MemberDefStart));
1159       }
1160     }
1161
1162     void endMemberDef()
1163     {
1164       int i=m_scope.findRev("memberdef/");
1165       if (i!=-1)
1166       {
1167         m_scope=m_scope.left(i);
1168         if (m_part!=-1)
1169         {
1170           LayoutDocManager::instance().addEntry((LayoutDocManager::LayoutPart)m_part,
1171                                               new LayoutDocEntrySimple(LayoutDocEntry::MemberDefEnd));
1172         }
1173       }
1174     }
1175
1176     void startMemberDecl(const QXmlAttributes &)
1177     {
1178       m_scope+="memberdecl/";
1179       if (m_part!=-1)
1180       {
1181         LayoutDocManager::instance().addEntry((LayoutDocManager::LayoutPart)m_part,
1182                                               new LayoutDocEntrySimple(LayoutDocEntry::MemberDeclStart));
1183       }
1184     }
1185
1186     void endMemberDecl()
1187     {
1188       int i=m_scope.findRev("memberdecl/");
1189       if (i!=-1)
1190       {
1191         m_scope=m_scope.left(i);
1192         if (m_part!=-1)
1193         {
1194           LayoutDocManager::instance().addEntry((LayoutDocManager::LayoutPart)m_part,
1195                                               new LayoutDocEntrySimple(LayoutDocEntry::MemberDeclEnd));
1196         }
1197       }
1198     }
1199
1200     // reimplemented from QXmlDefaultHandler
1201     bool startElement( const QString&, const QString&, 
1202                        const QString& name, const QXmlAttributes& attrib )
1203     {
1204       //printf("startElement [%s]::[%s]\n",m_scope.data(),name.data());
1205       StartElementHandler *handler = m_sHandler[m_scope+name.utf8()];
1206       if (handler)
1207       {
1208         (*handler)(attrib);
1209       }
1210       else
1211       {
1212         err("error: Unexpected start tag `%s' found in scope='%s'!\n",
1213             name.data(),m_scope.data());
1214       }
1215       return TRUE;
1216     }
1217     bool endElement( const QString&, const QString&, const QString& name )
1218     {
1219       //printf("endElement [%s]::[%s]\n",m_scope.data(),name.data());
1220       EndElementHandler *handler;
1221       if (!m_scope.isEmpty() && m_scope.right(name.length()+1)==name.utf8()+"/")
1222       { // element ends current scope
1223         handler = m_eHandler[m_scope.left(m_scope.length()-1)];
1224       }
1225       else // continue with current scope
1226       {
1227         handler = m_eHandler[m_scope+name.utf8()];
1228       }
1229       if (handler)
1230       {
1231         (*handler)();
1232       }
1233       return TRUE;
1234     }
1235     bool startDocument()
1236     {
1237       return TRUE;
1238     }
1239
1240   private:
1241     LayoutParser() : m_sHandler(163), m_eHandler(17), m_invalidEntry(FALSE) { }
1242
1243     QDict<StartElementHandler> m_sHandler;
1244     QDict<EndElementHandler>   m_eHandler;
1245     QCString m_scope;
1246     int m_part;
1247     LayoutNavEntry *m_rootNav;
1248     bool m_invalidEntry;
1249     static int m_userGroupCount;
1250 };
1251
1252 int LayoutParser::m_userGroupCount=0;
1253
1254 //---------------------------------------------------------------------------------
1255
1256 class LayoutErrorHandler : public QXmlErrorHandler
1257 {
1258   public:
1259     LayoutErrorHandler(const char *fn) : fileName(fn) {}
1260     bool warning( const QXmlParseException &exception )
1261     {
1262       err("warning: at line %d column %d of %s: %s\n",
1263           exception.lineNumber(),exception.columnNumber(),fileName.data(),
1264           exception.message().data());
1265       return FALSE;
1266     }
1267     bool error( const QXmlParseException &exception )
1268     {
1269       err("error: at line %d column %d of %s: %s\n",
1270           exception.lineNumber(),exception.columnNumber(),fileName.data(),
1271           exception.message().data());
1272       return FALSE;
1273     }
1274     bool fatalError( const QXmlParseException &exception )
1275     {
1276       err("fatal error: at line %d column %d of %s: %s\n",
1277           exception.lineNumber(),exception.columnNumber(),fileName.data(),
1278           exception.message().data());
1279       return FALSE;
1280     }
1281     QString errorString() { return ""; }
1282
1283   private:
1284     QString errorMsg;
1285     QString fileName;
1286 };
1287
1288 //---------------------------------------------------------------------------------
1289
1290 class LayoutDocManager::Private
1291 {
1292   public:
1293     QList<LayoutDocEntry> docEntries[LayoutDocManager::NrParts];
1294     LayoutNavEntry *rootNav;
1295 };
1296
1297 LayoutDocManager::LayoutDocManager()
1298 {
1299   d = new Private;
1300   int i;
1301   for (i=0;i<LayoutDocManager::NrParts;i++)
1302   {
1303     d->docEntries[i].setAutoDelete(TRUE);
1304   }
1305   d->rootNav = new LayoutNavEntry;
1306   LayoutParser::instance().init();
1307 }
1308
1309
1310 void LayoutDocManager::init()
1311 {
1312   // parse the default layout
1313   LayoutErrorHandler errorHandler( "layout_default.xml" );
1314   QXmlInputSource source;
1315   source.setData( layout_default );
1316   QXmlSimpleReader reader;
1317   reader.setContentHandler( &LayoutParser::instance() );
1318   reader.setErrorHandler( &errorHandler );
1319   reader.parse( source );
1320 }
1321
1322 LayoutDocManager::~LayoutDocManager()
1323 {
1324   delete d->rootNav;
1325   delete d;
1326 }
1327
1328 LayoutDocManager & LayoutDocManager::instance()
1329 {
1330   static LayoutDocManager *theInstance = new LayoutDocManager;
1331   return *theInstance;
1332 }
1333
1334 const QList<LayoutDocEntry> &LayoutDocManager::docEntries(LayoutDocManager::LayoutPart part) const
1335 {
1336   return d->docEntries[(int)part];
1337 }
1338
1339 LayoutNavEntry* LayoutDocManager::rootNavEntry() const
1340 {
1341   return d->rootNav;
1342 }
1343
1344 void LayoutDocManager::addEntry(LayoutDocManager::LayoutPart p,LayoutDocEntry *e)
1345 {
1346   d->docEntries[(int)p].append(e);
1347 }
1348
1349 void LayoutDocManager::clear(LayoutDocManager::LayoutPart p)
1350 {
1351   d->docEntries[(int)p].clear();
1352 }
1353
1354 void LayoutDocManager::parse(QTextStream &t,const char *fileName)
1355 {
1356   LayoutErrorHandler errorHandler(fileName);
1357   QXmlInputSource source( t );
1358   QXmlSimpleReader reader;
1359   reader.setContentHandler( &LayoutParser::instance() );
1360   reader.setErrorHandler( &errorHandler );
1361   reader.parse( source );
1362 }
1363
1364 //---------------------------------------------------------------------------------
1365
1366 void writeDefaultLayoutFile(const char *fileName)
1367 {
1368   QFile f(fileName);
1369   if (!f.open(IO_WriteOnly))
1370   {
1371     err("Failed to open file %s for writing!\n",fileName);
1372     return;
1373   }
1374   QTextStream t(&f);
1375   t << layout_default;
1376 }
1377
1378 //----------------------------------------------------------------------------------
1379
1380 // Convert input to a title.
1381 // The format of input can be a simple title "A title" or in case there are different 
1382 // titles for some programming languages they can take the following form:
1383 // "A title|16=Another title|8=Yet Another title"
1384 // where the number is a value of SrcLangExt in decimal notation (i.e. 16=Java, 8=IDL).
1385 QCString extractLanguageSpecificTitle(const QCString &input,SrcLangExt lang)
1386 {
1387   int i,s=0,e=input.find('|');
1388   if (e==-1) return input; // simple title case
1389   int e1=e;
1390   while (e!=-1) // look for 'number=title' pattern separated by '|'
1391   {
1392     s=e+1;
1393     e=input.find('|',s);
1394     i=input.find('=',s);
1395     assert(i>s);
1396     int key=input.mid(s,i-s).toInt();
1397     if (key==(int)lang) // found matching key
1398     {
1399       if (e==-1) e=input.length();
1400       return input.mid(i+1,e-i-1);
1401     }
1402   }
1403   return input.left(e1); // fallback, no explicit language key found
1404 }
1405
1406 //----------------------------------------------------------------------------------
1407
1408 QCString LayoutDocEntrySection::title(SrcLangExt lang) const
1409 {
1410   return extractLanguageSpecificTitle(m_title,lang);
1411 }
1412
1413 //----------------------------------------------------------------------------------
1414
1415 QCString LayoutDocEntryMemberDecl::title(SrcLangExt lang) const
1416 {
1417   return extractLanguageSpecificTitle(m_title,lang);
1418 }
1419
1420 QCString LayoutDocEntryMemberDecl::subtitle(SrcLangExt lang) const
1421 {
1422   return extractLanguageSpecificTitle(m_subscript,lang);
1423 }
1424
1425 //----------------------------------------------------------------------------------
1426
1427 QCString LayoutDocEntryMemberDef::title(SrcLangExt lang) const
1428 {
1429   return extractLanguageSpecificTitle(m_title,lang);
1430 }
1431
1432
1433
1434