2517942ab1157c1af70c13c1afef205edf0abc62
[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_showToc = 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::RTF);
191   ol.disable(OutputGenerator::Man);
192   if (!title().isEmpty() && !name().isEmpty() && si!=0)
193   {
194     //ol.startSection(si->label,si->title,si->type);
195     startTitle(ol,getOutputFileBase(),this);
196     ol.generateDoc(docFile(),docLine(),this,0,si->title,TRUE,FALSE,0,TRUE,FALSE);
197     //stringToSearchIndex(getOutputFileBase(),
198     //                    theTranslator->trPage(TRUE,TRUE)+" "+si->title,
199     //                    si->title);
200     //ol.endSection(si->label,si->type);
201     endTitle(ol,getOutputFileBase(),name());
202   }
203   ol.startContents();
204   ol.popGeneratorState();
205   //2.}
206
207   if (m_showToc && hasSections())
208   {
209     writeToc(ol);
210   }
211
212   writePageDocumentation(ol);
213
214   if (generateTreeView && getOuterScope()!=Doxygen::globalScope && !Config_getBool(DISABLE_INDEX))
215   {
216     ol.endContents();
217     endFileWithNavPath(getOuterScope(),ol);
218   }
219   else
220   {
221     endFile(ol);
222   }
223
224   ol.popGeneratorState();
225   //1.}
226
227   Doxygen::indexList->addIndexItem(this,0,0,filterTitle(title()));
228 }
229
230 void PageDef::writePageDocumentation(OutputList &ol)
231 {
232
233   bool markdownEnabled = Doxygen::markdownSupport;
234   if (getLanguage()==SrcLangExt_Markdown)
235   {
236     Doxygen::markdownSupport = TRUE;
237   }
238
239   ol.startTextBlock();
240   QCString docStr = documentation()+inbodyDocumentation();
241   if (hasBriefDescription() && !Doxygen::sectionDict->find(name()))
242   {
243     ol.pushGeneratorState();
244     ol.disableAllBut(OutputGenerator::Man);
245     ol.writeString(" - ");
246     ol.popGeneratorState();
247   }
248   ol.generateDoc(
249       docFile(),           // fileName
250       docLine(),           // startLine
251       this,                // context
252       0,                   // memberdef
253       docStr,              // docStr
254       TRUE,                // index words
255       FALSE                // not an example
256       );
257   ol.endTextBlock();
258
259   Doxygen::markdownSupport = markdownEnabled;
260
261   if (hasSubPages())
262   {
263     // for printed documentation we write subpages as section's of the
264     // parent page.
265     ol.pushGeneratorState();
266     ol.disableAll();
267     ol.enable(OutputGenerator::Latex);
268     ol.enable(OutputGenerator::RTF);
269
270     PageSDict::Iterator pdi(*m_subPageDict);
271     PageDef *subPage=pdi.toFirst();
272     for (pdi.toFirst();(subPage=pdi.current());++pdi)
273     {
274       SectionInfo::SectionType sectionType = SectionInfo::Paragraph;
275       switch (m_nestingLevel)
276       {
277         case  0: sectionType = SectionInfo::Page;          break;
278         case  1: sectionType = SectionInfo::Section;       break;
279         case  2: sectionType = SectionInfo::Subsection;    break;
280         case  3: sectionType = SectionInfo::Subsubsection; break;
281         default: sectionType = SectionInfo::Paragraph;     break;
282       }
283       QCString title = subPage->title();
284       if (title.isEmpty()) title = subPage->name();
285       ol.startSection(subPage->name(),title,sectionType);
286       ol.parseText(title);
287       ol.endSection(subPage->name(),sectionType);
288       Doxygen::subpageNestingLevel++;
289       subPage->writePageDocumentation(ol);
290       Doxygen::subpageNestingLevel--;
291     }
292
293     ol.popGeneratorState();
294   }
295 }
296
297 bool PageDef::visibleInIndex() const
298 {
299   static bool externalPages = Config_getBool(EXTERNAL_PAGES);
300   return // not part of a group
301          !getGroupDef() && 
302          // not an externally defined page
303          (!isReference() || externalPages) 
304          ;
305 }
306
307 bool PageDef::documentedPage() const
308 {
309    return // not part of a group
310           !getGroupDef() && 
311           // not an externally defined page
312           !isReference();
313 }
314
315 bool PageDef::hasSubPages() const
316 {
317   return m_subPageDict->count()>0;
318 }
319
320 void PageDef::setNestingLevel(int l)
321 {
322   m_nestingLevel = l;
323 }
324
325 void PageDef::setShowToc(bool b)
326 {
327   m_showToc |= b;
328 }
329