pagedef.cpp 8.34 KB
Newer Older
1 2
/******************************************************************************
 *
Dimitri van Heesch's avatar
Dimitri van Heesch committed
3
 * Copyright (C) 1997-2013 by Dimitri van Heesch.
4 5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby 
 * granted. No representations are made about the suitability of this software 
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
 * Documents produced by Doxygen are derivative works derived from the
 * input used in their production; they are not affected by this license.
 *
 */

#include <qregexp.h>

18
#include "pagedef.h"
19 20
#include "groupdef.h"
#include "docparser.h"
21 22 23 24
#include "config.h"
#include "util.h"
#include "outputlist.h"
#include "doxygen.h"
25
#include "language.h"
26 27
#include "namespacedef.h"
#include "reflist.h"
28 29 30

PageDef::PageDef(const char *f,int l,const char *n,
                 const char *d,const char *t)
31
 : Definition(f,l,1,n), m_title(t)
32 33
{
  setDocumentation(d,f,l);
34 35 36
  m_subPageDict = new PageSDict(7);
  m_pageScope = 0;
  m_nestingLevel = 0;
37
  m_showToc = FALSE;
38 39 40 41
}

PageDef::~PageDef()
{
42
  delete m_subPageDict;
43
}
44 45 46 47 48 49 50 51

void PageDef::findSectionsInDocumentation()
{
  docFindSections(documentation(),this,0,docFile());
}

GroupDef *PageDef::getGroupDef() const 
{ 
52
  GroupList *groups = partOfGroups();
53
  return groups!=0 ? groups->getFirst() : 0; 
54 55
}

56 57 58 59 60 61 62 63
QCString PageDef::getOutputFileBase() const 
{ 
  if (getGroupDef()) 
    return getGroupDef()->getOutputFileBase();
  else 
    return m_fileName; 
}

64 65 66 67 68 69 70 71 72 73 74 75 76 77
void PageDef::setFileName(const char *name) 
{ 
  static bool shortNames = Config_getBool("SHORT_NAMES");
  if (shortNames)
  {
    m_fileName = convertNameToFile(name);
  }
  else
  {
    m_fileName = name; 
  }
}


78 79 80 81 82
void PageDef::addInnerCompound(Definition *def)
{
  if (def->definitionType()==Definition::TypePage)
  {
    PageDef *pd = (PageDef*)def;
83
    m_subPageDict->append(pd->name(),pd);
84
    def->setOuterScope(this);
85 86 87 88 89 90 91 92
    if (this==Doxygen::mainPage)
    {
      pd->setNestingLevel(m_nestingLevel);
    }
    else
    {
      pd->setNestingLevel(m_nestingLevel+1);
    }
93 94 95
  }
}

96 97 98 99 100 101
bool PageDef::hasParentPage() const
{
  return getOuterScope() && 
         getOuterScope()->definitionType()==Definition::TypePage;
}

102 103
void PageDef::writeDocumentation(OutputList &ol)
{
104 105
  static bool generateTreeView = Config_getBool("GENERATE_TREEVIEW");

106
  //outputList->disable(OutputGenerator::Man);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
107 108 109
  QCString pageName,manPageName;
  pageName    = escapeCharsInString(name(),FALSE,TRUE);
  manPageName = escapeCharsInString(name(),TRUE,TRUE);
110

111 112
  //printf("PageDef::writeDocumentation: %s\n",getOutputFileBase().data());

113
  ol.pushGeneratorState();
114
  //1.{ 
115

116 117 118 119
  if (m_nestingLevel>0 
      //&& // a sub page
      //(Doxygen::mainPage==0 || getOuterScope()!=Doxygen::mainPage) // and not a subpage of the mainpage
     )
120 121 122 123 124 125 126 127
  {
    // do not generate sub page output for RTF and LaTeX, as these are
    // part of their parent page
    ol.disableAll();
    ol.enable(OutputGenerator::Man);
    ol.enable(OutputGenerator::Html);
  }

Dimitri van Heesch's avatar
Dimitri van Heesch committed
128 129 130 131 132 133
  ol.pushGeneratorState();
  //2.{ 
  ol.disableAllBut(OutputGenerator::Man);
  startFile(ol,getOutputFileBase(),manPageName,title(),HLI_Pages,!generateTreeView);
  ol.enableAll();
  ol.disable(OutputGenerator::Man);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
134
  startFile(ol,getOutputFileBase(),pageName,title(),HLI_Pages,!generateTreeView);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
135 136
  ol.popGeneratorState();
  //2.} 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
137

138
  if (!generateTreeView)
139
  {
140 141
    if (getOuterScope()!=Doxygen::globalScope && !Config_getBool("DISABLE_INDEX"))
    {
142
      getOuterScope()->writeNavigationPath(ol);
143 144
    }
    ol.endQuickIndices();
145
  }
146
  SectionInfo *si=Doxygen::sectionDict->find(name());
147 148 149

  // save old generator state and write title only to Man generator
  ol.pushGeneratorState();
150
  //2.{
151
  ol.disableAllBut(OutputGenerator::Man);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
152 153
  ol.startTitleHead(manPageName);
  ol.endTitleHead(manPageName, manPageName);
154 155
  if (si)
  {
156
    ol.generateDoc(docFile(),docLine(),this,0,si->title,TRUE,FALSE,0,TRUE,FALSE);
157 158
    ol.endSection(si->label,si->type);
  }
159
  ol.popGeneratorState();
160
  //2.}
161

162 163
  // for Latex the section is already generated as a chapter in the index!
  ol.pushGeneratorState();
164
  //2.{
165
  ol.disable(OutputGenerator::Latex);
166
  ol.disable(OutputGenerator::RTF);
167 168
  ol.disable(OutputGenerator::Man);
  if (!title().isEmpty() && !name().isEmpty() && si!=0)
169
  {
170 171
    //ol.startSection(si->label,si->title,si->type);
    startTitle(ol,getOutputFileBase(),this);
172
    ol.generateDoc(docFile(),docLine(),this,0,si->title,TRUE,FALSE,0,TRUE,FALSE);
173 174 175
    //stringToSearchIndex(getOutputFileBase(),
    //                    theTranslator->trPage(TRUE,TRUE)+" "+si->title,
    //                    si->title);
176 177
    //ol.endSection(si->label,si->type);
    endTitle(ol,getOutputFileBase(),name());
178
  }
179
  ol.startContents();
180
  ol.popGeneratorState();
181
  //2.}
182

183 184 185 186 187
  if (m_showToc && hasSections())
  {
    writeToc(ol);
  }

188 189
  writePageDocumentation(ol);

190 191 192
  if (generateTreeView && getOuterScope()!=Doxygen::globalScope && !Config_getBool("DISABLE_INDEX"))
  {
    ol.endContents();
193
    endFileWithNavPath(getOuterScope(),ol);
194 195 196 197 198
  }
  else
  {
    endFile(ol);
  }
199

Dimitri van Heesch's avatar
Dimitri van Heesch committed
200 201 202
  ol.popGeneratorState();
  //1.}

203 204
  if (!Config_getString("GENERATE_TAGFILE").isEmpty())
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
205
    bool found = name()=="citelist";
206 207
    QDictIterator<RefList> rli(*Doxygen::xrefLists);
    RefList *rl;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
208
    for (rli.toFirst();(rl=rli.current()) && !found;++rli)
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
    {
      if (rl->listName()==name())
      {
        found=TRUE;
        break;
      }
    }
    if (!found) // not one of the generated related pages
    {
      Doxygen::tagFile << "  <compound kind=\"page\">" << endl;
      Doxygen::tagFile << "    <name>" << name() << "</name>" << endl;
      Doxygen::tagFile << "    <title>" << convertToXML(title()) << "</title>" << endl;
      Doxygen::tagFile << "    <filename>" << getOutputFileBase() << "</filename>" << endl;
      writeDocAnchorsToTagFile();
      Doxygen::tagFile << "  </compound>" << endl;
    }
  }
226

227
  Doxygen::indexList->addIndexItem(this,0,0,filterTitle(title()));
228 229
}

230 231
void PageDef::writePageDocumentation(OutputList &ol)
{
232 233 234 235 236 237 238

  bool markdownEnabled = Doxygen::markdownSupport;
  if (getLanguage()==SrcLangExt_Markdown)
  {
    Doxygen::markdownSupport = TRUE;
  }

239
  ol.startTextBlock();
240
  ol.generateDoc(
241
      docFile(),           // fileName
242 243 244
      docLine(),           // startLine
      this,                // context
      0,                   // memberdef
245
      documentation()+inbodyDocumentation(), // docStr
246 247 248 249 250
      TRUE,                // index words
      FALSE                // not an example
      );
  ol.endTextBlock();

251 252
  Doxygen::markdownSupport = markdownEnabled;

253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
  if (hasSubPages())
  {
    // for printed documentation we write subpages as section's of the
    // parent page.
    ol.pushGeneratorState();
    ol.disableAll();
    ol.enable(OutputGenerator::Latex);
    ol.enable(OutputGenerator::RTF);

    PageSDict::Iterator pdi(*m_subPageDict);
    PageDef *subPage=pdi.toFirst();
    for (pdi.toFirst();(subPage=pdi.current());++pdi)
    {
      SectionInfo::SectionType sectionType = SectionInfo::Paragraph;
      switch (m_nestingLevel)
      {
        case  0: sectionType = SectionInfo::Page;          break;
        case  1: sectionType = SectionInfo::Section;       break;
        case  2: sectionType = SectionInfo::Subsection;    break;
        case  3: sectionType = SectionInfo::Subsubsection; break;
        default: sectionType = SectionInfo::Paragraph;     break;
      }
      QCString title = subPage->title();
      if (title.isEmpty()) title = subPage->name();
      ol.startSection(subPage->name(),title,sectionType);
      ol.parseText(title);
      ol.endSection(subPage->name(),sectionType);
280
      Doxygen::subpageNestingLevel++;
281
      subPage->writePageDocumentation(ol);
282
      Doxygen::subpageNestingLevel--;
283 284 285 286 287 288
    }

    ol.popGeneratorState();
  }
}

289 290
bool PageDef::visibleInIndex() const
{
291
  static bool externalPages = Config_getBool("EXTERNAL_PAGES");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
292 293 294
  return // not part of a group
         !getGroupDef() && 
         // not an externally defined page
295
         (!isReference() || externalPages) 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
296
         ;
297 298 299 300 301 302 303 304 305 306 307 308
}

bool PageDef::documentedPage() const
{
   return // not part of a group
          !getGroupDef() && 
          // not an externally defined page
          !isReference();
}

bool PageDef::hasSubPages() const
{
309
  return m_subPageDict->count()>0;
310 311
}

312 313 314 315
void PageDef::setNestingLevel(int l)
{
  m_nestingLevel = l;
}
316

317 318 319 320 321
void PageDef::setShowToc(bool b)
{
  m_showToc = b;
}