Imported Upstream version 1.8.15
[platform/upstream/doxygen.git] / src / pagedef.cpp
1 /******************************************************************************
2  *
3  * Copyright (C) 1997-2015 by Dimitri van Heesch.
4  *
5  * Permission to use, copy, modify, and distribute this software and its
6  * documentation under the terms of the GNU General Public License is hereby 
7  * granted. No representations are made about the suitability of this software 
8  * for any purpose. It is provided "as is" without express or implied warranty.
9  * See the GNU General Public License for more details.
10  *
11  * Documents produced by Doxygen are derivative works derived from the
12  * input used in their production; they are not affected by this license.
13  *
14  */
15
16 #include <qregexp.h>
17
18 #include "pagedef.h"
19 #include "groupdef.h"
20 #include "docparser.h"
21 #include "config.h"
22 #include "util.h"
23 #include "outputlist.h"
24 #include "doxygen.h"
25 #include "language.h"
26 #include "namespacedef.h"
27 #include "reflist.h"
28
29 PageDef::PageDef(const char *f,int l,const char *n,
30                  const char *d,const char *t)
31  : Definition(f,l,1,n), m_title(t)
32 {
33   setDocumentation(d,f,l);
34   m_subPageDict = new PageSDict(7);
35   m_pageScope = 0;
36   m_nestingLevel = 0;
37   m_fileName = ::convertNameToFile(n,FALSE,TRUE);
38   m_showLineNo = FALSE;
39 }
40
41 PageDef::~PageDef()
42 {
43   delete m_subPageDict;
44 }
45
46 void PageDef::findSectionsInDocumentation()
47 {
48   docFindSections(documentation(),this,0,docFile());
49 }
50
51 GroupDef *PageDef::getGroupDef() const 
52
53   GroupList *groups = partOfGroups();
54   return groups!=0 ? groups->getFirst() : 0; 
55 }
56
57 QCString PageDef::getOutputFileBase() const 
58
59   if (getGroupDef()) 
60     return getGroupDef()->getOutputFileBase();
61   else 
62     return m_fileName; 
63 }
64
65 void PageDef::setFileName(const char *name)
66 {
67   m_fileName = name;
68 }
69
70 void PageDef::addInnerCompound(Definition *def)
71 {
72   if (def->definitionType()==Definition::TypePage)
73   {
74     PageDef *pd = (PageDef*)def;
75     m_subPageDict->append(pd->name(),pd);
76     def->setOuterScope(this);
77     if (this==Doxygen::mainPage)
78     {
79       pd->setNestingLevel(m_nestingLevel);
80     }
81     else
82     {
83       pd->setNestingLevel(m_nestingLevel+1);
84     }
85   }
86 }
87
88 bool PageDef::hasParentPage() const
89 {
90   return getOuterScope() && 
91          getOuterScope()->definitionType()==Definition::TypePage;
92 }
93
94 void PageDef::writeTagFile(FTextStream &tagFile)
95 {
96   bool found = name()=="citelist";
97   QDictIterator<RefList> rli(*Doxygen::xrefLists);
98   RefList *rl;
99   for (rli.toFirst();(rl=rli.current()) && !found;++rli)
100   {
101     if (rl->listName()==name())
102     {
103       found=TRUE;
104       break;
105     }
106   }
107   if (!found) // not one of the generated related pages
108   {
109     tagFile << "  <compound kind=\"page\">" << endl;
110     tagFile << "    <name>" << name() << "</name>" << endl;
111     tagFile << "    <title>" << convertToXML(title()) << "</title>" << endl;
112     tagFile << "    <filename>" << convertToXML(getOutputFileBase()) << "</filename>" << endl;
113     writeDocAnchorsToTagFile(tagFile);
114     tagFile << "  </compound>" << endl;
115   }
116 }
117
118 void PageDef::writeDocumentation(OutputList &ol)
119 {
120   static bool generateTreeView = Config_getBool(GENERATE_TREEVIEW);
121
122   //outputList->disable(OutputGenerator::Man);
123   QCString pageName,manPageName;
124   pageName    = escapeCharsInString(name(),FALSE,TRUE);
125   manPageName = escapeCharsInString(name(),TRUE,TRUE);
126
127   //printf("PageDef::writeDocumentation: %s\n",getOutputFileBase().data());
128
129   ol.pushGeneratorState();
130   //1.{ 
131
132   if (m_nestingLevel>0 
133       //&& // a sub page
134       //(Doxygen::mainPage==0 || getOuterScope()!=Doxygen::mainPage) // and not a subpage of the mainpage
135      )
136   {
137     // do not generate sub page output for RTF and LaTeX, as these are
138     // part of their parent page
139     ol.disableAll();
140     ol.enable(OutputGenerator::Man);
141     ol.enable(OutputGenerator::Html);
142   }
143
144   ol.pushGeneratorState();
145   //2.{ 
146   ol.disableAllBut(OutputGenerator::Man);
147   startFile(ol,getOutputFileBase(),manPageName,title(),HLI_Pages,!generateTreeView);
148   ol.enableAll();
149   ol.disable(OutputGenerator::Man);
150   startFile(ol,getOutputFileBase(),pageName,title(),HLI_Pages,!generateTreeView);
151   ol.popGeneratorState();
152   //2.} 
153
154   if (!generateTreeView)
155   {
156     if (getOuterScope()!=Doxygen::globalScope && !Config_getBool(DISABLE_INDEX))
157     {
158       getOuterScope()->writeNavigationPath(ol);
159     }
160     ol.endQuickIndices();
161   }
162   SectionInfo *si=Doxygen::sectionDict->find(name());
163
164   // save old generator state and write title only to Man generator
165   ol.pushGeneratorState();
166   //2.{
167   ol.disableAllBut(OutputGenerator::Man);
168   ol.startTitleHead(manPageName);
169   ol.endTitleHead(manPageName, manPageName);
170   if (si)
171   {
172     ol.pushGeneratorState();
173     ol.disableAllBut(OutputGenerator::Man);
174     ol.writeString(" - ");
175     ol.popGeneratorState();
176
177     if (si->title != manPageName)
178     {
179       ol.generateDoc(docFile(),docLine(),this,0,si->title,TRUE,FALSE,0,TRUE,FALSE);
180       ol.endSection(si->label,si->type);
181     }
182   }
183   ol.popGeneratorState();
184   //2.}
185
186   // for Latex the section is already generated as a chapter in the index!
187   ol.pushGeneratorState();
188   //2.{
189   ol.disable(OutputGenerator::Latex);
190   ol.disable(OutputGenerator::Docbook);
191   ol.disable(OutputGenerator::RTF);
192   ol.disable(OutputGenerator::Man);
193   if (!title().isEmpty() && !name().isEmpty() && si!=0)
194   {
195     ol.startPageDoc(si->title);
196     //ol.startSection(si->label,si->title,si->type);
197     startTitle(ol,getOutputFileBase(),this);
198     ol.generateDoc(docFile(),docLine(),this,0,si->title,TRUE,FALSE,0,TRUE,FALSE);
199     //stringToSearchIndex(getOutputFileBase(),
200     //                    theTranslator->trPage(TRUE,TRUE)+" "+si->title,
201     //                    si->title);
202     //ol.endSection(si->label,si->type);
203     endTitle(ol,getOutputFileBase(),name());
204   }
205   else
206     ol.startPageDoc("");
207   ol.startContents();
208   ol.popGeneratorState();
209   //2.}
210
211   if ((m_localToc.isHtmlEnabled() || m_localToc.isLatexEnabled() || m_localToc.isDocbookEnabled()) && hasSections())
212   {
213     writeToc(ol, m_localToc);
214   }
215
216   writePageDocumentation(ol);
217   ol.endPageDoc();
218
219   if (generateTreeView && getOuterScope()!=Doxygen::globalScope && !Config_getBool(DISABLE_INDEX))
220   {
221     ol.endContents();
222     endFileWithNavPath(getOuterScope(),ol);
223   }
224   else
225   {
226     endFile(ol);
227   }
228
229   ol.popGeneratorState();
230   //1.}
231
232   Doxygen::indexList->addIndexItem(this,0,0,filterTitle(title()));
233 }
234
235 void PageDef::writePageDocumentation(OutputList &ol)
236 {
237
238   bool markdownEnabled = Doxygen::markdownSupport;
239   if (getLanguage()==SrcLangExt_Markdown)
240   {
241     Doxygen::markdownSupport = TRUE;
242   }
243
244   ol.startTextBlock();
245   QCString docStr = documentation()+inbodyDocumentation();
246   if (hasBriefDescription() && !Doxygen::sectionDict->find(name()))
247   {
248     ol.pushGeneratorState();
249     ol.disableAllBut(OutputGenerator::Man);
250     ol.writeString(" - ");
251     ol.popGeneratorState();
252   }
253   ol.generateDoc(
254       docFile(),           // fileName
255       docLine(),           // startLine
256       this,                // context
257       0,                   // memberdef
258       docStr,              // docStr
259       TRUE,                // index words
260       FALSE                // not an example
261       );
262   ol.endTextBlock();
263
264   Doxygen::markdownSupport = markdownEnabled;
265
266   if (hasSubPages())
267   {
268     // for printed documentation we write subpages as section's of the
269     // parent page.
270     ol.pushGeneratorState();
271     ol.disableAll();
272     ol.enable(OutputGenerator::Latex);
273     ol.enable(OutputGenerator::Docbook);
274     ol.enable(OutputGenerator::RTF);
275
276     PageSDict::Iterator pdi(*m_subPageDict);
277     PageDef *subPage=pdi.toFirst();
278     for (pdi.toFirst();(subPage=pdi.current());++pdi)
279     {
280       SectionInfo::SectionType sectionType = SectionInfo::Paragraph;
281       switch (m_nestingLevel)
282       {
283         case  0: sectionType = SectionInfo::Page;          break;
284         case  1: sectionType = SectionInfo::Section;       break;
285         case  2: sectionType = SectionInfo::Subsection;    break;
286         case  3: sectionType = SectionInfo::Subsubsection; break;
287         default: sectionType = SectionInfo::Paragraph;     break;
288       }
289       QCString title = subPage->title();
290       if (title.isEmpty()) title = subPage->name();
291       ol.startSection(subPage->name(),title,sectionType);
292       ol.parseText(title);
293       ol.endSection(subPage->name(),sectionType);
294       Doxygen::subpageNestingLevel++;
295       subPage->writePageDocumentation(ol);
296       Doxygen::subpageNestingLevel--;
297     }
298
299     ol.popGeneratorState();
300   }
301 }
302
303 bool PageDef::visibleInIndex() const
304 {
305   static bool externalPages = Config_getBool(EXTERNAL_PAGES);
306   return // not part of a group
307          !getGroupDef() && 
308          // not an externally defined page
309          (!isReference() || externalPages) 
310          ;
311 }
312
313 bool PageDef::documentedPage() const
314 {
315    return // not part of a group
316           !getGroupDef() && 
317           // not an externally defined page
318           !isReference();
319 }
320
321 bool PageDef::hasSubPages() const
322 {
323   return m_subPageDict->count()>0;
324 }
325
326 void PageDef::setNestingLevel(int l)
327 {
328   m_nestingLevel = l;
329 }
330
331 void PageDef::setLocalToc(const LocalToc &lt)
332 {
333   m_localToc = lt;
334 }
335
336 void PageDef::setShowLineNo(bool b)
337 {
338   m_showLineNo = b;
339 }
340
341 bool PageDef::showLineNo() const
342 {
343   return m_showLineNo;
344 }