My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
HtmlCodeGenerator Class Reference

#include <htmlgen.h>

Inheritance diagram for HtmlCodeGenerator:
CodeOutputInterface

Public Member Functions

 HtmlCodeGenerator (FTextStream &t, const QCString &relPath)
 
 HtmlCodeGenerator ()
 
void setTextStream (FTextStream &t)
 
void setRelativePath (const QCString &path)
 
void codify (const char *text)
 
void writeCodeLink (const char *ref, const char *file, const char *anchor, const char *name, const char *tooltip)
 
void writeTooltip (const char *id, const DocLinkInfo &docInfo, const char *decl, const char *desc, const SourceLinkInfo &defInfo, const SourceLinkInfo &declInfo)
 
void writeLineNumber (const char *, const char *, const char *, int)
 
void startCodeLine (bool)
 
void endCodeLine ()
 
void startFontClass (const char *s)
 
void endFontClass ()
 
void writeCodeAnchor (const char *anchor)
 
void setCurrentDoc (Definition *, const char *, bool)
 
void addWord (const char *, bool)
 
- Public Member Functions inherited from CodeOutputInterface
virtual ~CodeOutputInterface ()
 

Private Member Functions

void _writeCodeLink (const char *className, const char *ref, const char *file, const char *anchor, const char *name, const char *tooltip)
 
void docify (const char *str)
 

Private Attributes

bool m_streamSet
 
FTextStream m_t
 
int m_col
 
QCString m_relPath
 

Detailed Description

Definition at line 31 of file htmlgen.h.

Constructor & Destructor Documentation

HtmlCodeGenerator::HtmlCodeGenerator ( FTextStream t,
const QCString &  relPath 
)

Definition at line 415 of file htmlgen.cpp.

References setTextStream().

: m_col(0), m_relPath(relPath)
{
}
HtmlCodeGenerator::HtmlCodeGenerator ( )

Definition at line 410 of file htmlgen.cpp.

: m_streamSet(FALSE), m_col(0)
{
}

Member Function Documentation

void HtmlCodeGenerator::_writeCodeLink ( const char *  className,
const char *  ref,
const char *  file,
const char *  anchor,
const char *  name,
const char *  tooltip 
)
private

Definition at line 542 of file htmlgen.cpp.

References convertToHtml(), docify(), externalLinkTarget(), externalRef(), Doxygen::htmlFileExtension, m_col, m_relPath, and m_t.

Referenced by writeCodeLink(), and writeLineNumber().

{
if (ref)
{
m_t << "<a class=\"" << className << "Ref\" ";
}
else
{
m_t << "<a class=\"" << className << "\" ";
}
m_t << "href=\"";
m_t << externalRef(m_relPath,ref,TRUE);
if (anchor) m_t << "#" << anchor;
m_t << "\"";
if (tooltip) m_t << " title=\"" << convertToHtml(tooltip) << "\"";
m_t << ">";
docify(name);
m_t << "</a>";
m_col+=qstrlen(name);
}
void HtmlCodeGenerator::addWord ( const char *  ,
bool   
)
inlinevirtual

Implements CodeOutputInterface.

Definition at line 56 of file htmlgen.h.

{}
void HtmlCodeGenerator::codify ( const char *  s)
virtual

Writes an code fragment to the output. This function should keep spaces visible, should break lines at a newline and should convert tabs to the right number of spaces.

Implements CodeOutputInterface.

Definition at line 432 of file htmlgen.cpp.

References Config_getInt, m_col, m_streamSet, m_t, Doxygen::spaces, and writeUtf8Char().

Referenced by HtmlGenerator::codify(), and writeLineNumber().

{
static int tabSize = Config_getInt(TAB_SIZE);
if (str && m_streamSet)
{
const char *p=str;
char c;
int spacesToNextTabStop;
while (*p)
{
c=*p++;
switch(c)
{
case '\t': spacesToNextTabStop =
tabSize - (m_col%tabSize);
m_t << Doxygen::spaces.left(spacesToNextTabStop);
m_col+=spacesToNextTabStop;
break;
case '\n': m_t << "\n"; m_col=0;
break;
case '\r': break;
case '<': m_t << "&lt;"; m_col++;
break;
case '>': m_t << "&gt;"; m_col++;
break;
case '&': m_t << "&amp;"; m_col++;
break;
case '\'': m_t << "&#39;"; m_col++; // &apos; is not valid XHTML
break;
case '"': m_t << "&quot;"; m_col++;
break;
case '\\':
if (*p=='<')
{ m_t << "&lt;"; p++; }
else if (*p=='>')
{ m_t << "&gt;"; p++; }
else
m_t << "\\";
m_col++;
break;
default: p=writeUtf8Char(m_t,p-1);
m_col++;
break;
}
}
}
}
void HtmlCodeGenerator::docify ( const char *  str)
private

Definition at line 480 of file htmlgen.cpp.

References m_streamSet, and m_t.

Referenced by _writeCodeLink(), and writeTooltip().

{
if (str && m_streamSet)
{
const char *p=str;
char c;
while (*p)
{
c=*p++;
switch(c)
{
case '<': m_t << "&lt;"; break;
case '>': m_t << "&gt;"; break;
case '&': m_t << "&amp;"; break;
case '"': m_t << "&quot;"; break;
case '\\':
if (*p=='<')
{ m_t << "&lt;"; p++; }
else if (*p=='>')
{ m_t << "&gt;"; p++; }
else
m_t << "\\";
break;
default: m_t << c;
}
}
}
}
void HtmlCodeGenerator::endCodeLine ( )
virtual

Ends a line of code started with startCodeLine()

Implements CodeOutputInterface.

Definition at line 659 of file htmlgen.cpp.

References m_streamSet, and m_t.

Referenced by HtmlGenerator::endCodeLine().

{
if (m_streamSet) m_t << "</div>";
}
void HtmlCodeGenerator::endFontClass ( )
virtual

Ends a block started with startFontClass()

Implements CodeOutputInterface.

Definition at line 669 of file htmlgen.cpp.

References m_streamSet, and m_t.

Referenced by HtmlGenerator::endFontClass().

{
if (m_streamSet) m_t << "</span>";
}
void HtmlCodeGenerator::setCurrentDoc ( Definition ,
const char *  ,
bool   
)
inlinevirtual

Implements CodeOutputInterface.

Definition at line 55 of file htmlgen.h.

{}
void HtmlCodeGenerator::setRelativePath ( const QCString &  path)

Definition at line 427 of file htmlgen.cpp.

References m_relPath.

Referenced by HtmlGenerator::startFile().

{
m_relPath = path;
}
void HtmlCodeGenerator::setTextStream ( FTextStream t)
void HtmlCodeGenerator::startCodeLine ( bool  hasLineNumbers)
virtual

Implements CodeOutputInterface.

Definition at line 650 of file htmlgen.cpp.

References m_col, m_streamSet, and m_t.

Referenced by HtmlGenerator::startCodeLine().

{
{
if (!hasLineNumbers) m_t << "<div class=\"line\">";
m_col=0;
}
}
void HtmlCodeGenerator::startFontClass ( const char *  clsName)
virtual

Starts a block with a certain meaning. Used for syntax highlighting, which elements of the same type are rendered using the same 'font class'.

Parameters
clsNameThe category name.

Implements CodeOutputInterface.

Definition at line 664 of file htmlgen.cpp.

References m_streamSet, and m_t.

Referenced by HtmlGenerator::startFontClass().

{
if (m_streamSet) m_t << "<span class=\"" << s << "\">";
}
void HtmlCodeGenerator::writeCodeAnchor ( const char *  name)
virtual

Write an anchor to a source listing.

Parameters
nameThe name of the anchor.

Implements CodeOutputInterface.

Definition at line 674 of file htmlgen.cpp.

References m_streamSet, and m_t.

Referenced by HtmlGenerator::writeCodeAnchor().

{
if (m_streamSet) m_t << "<a name=\"" << anchor << "\"></a>";
}
void HtmlCodeGenerator::writeCodeLink ( const char *  ref,
const char *  file,
const char *  anchor,
const char *  name,
const char *  tooltip 
)
virtual

Writes a link to an object in a code fragment.

Parameters
refIf this is non-zero, the object is to be found in an external documentation file.
fileThe file in which the object is located.
anchorThe anchor uniquely identifying the object within the file.
nameThe text to display as a placeholder for the link.
tooltipThe tooltip to display when the mouse is on the link.

Implements CodeOutputInterface.

Definition at line 533 of file htmlgen.cpp.

References _writeCodeLink(), and m_streamSet.

Referenced by HtmlGenerator::writeCodeLink().

{
if (!m_streamSet) return;
//printf("writeCodeLink(ref=%s,f=%s,anchor=%s,name=%s,tooltip=%s)\n",ref,f,anchor,name,tooltip);
_writeCodeLink("code",ref,f,anchor,name,tooltip);
}
void HtmlCodeGenerator::writeLineNumber ( const char *  ref,
const char *  file,
const char *  anchor,
int  lineNumber 
)
virtual

Writes the line number of a source listing

Parameters
refExternal reference (when imported from a tag file)
fileThe file part of the URL pointing to the docs.
anchorThe anchor part of the URL pointing to the docs.
lineNumberThe line number to write

Implements CodeOutputInterface.

Definition at line 509 of file htmlgen.cpp.

References _writeCodeLink(), codify(), m_streamSet, and m_t.

Referenced by HtmlGenerator::writeLineNumber().

{
if (!m_streamSet) return;
const int maxLineNrStr = 10;
char lineNumber[maxLineNrStr];
char lineAnchor[maxLineNrStr];
qsnprintf(lineNumber,maxLineNrStr,"%5d",l);
qsnprintf(lineAnchor,maxLineNrStr,"l%05d",l);
m_t << "<div class=\"line\">";
m_t << "<a name=\"" << lineAnchor << "\"></a><span class=\"lineno\">";
if (filename)
{
_writeCodeLink("line",ref,filename,anchor,lineNumber,0);
}
else
{
codify(lineNumber);
}
m_t << "</span>";
m_t << "&#160;";
}
void HtmlCodeGenerator::writeTooltip ( const char *  id,
const DocLinkInfo docInfo,
const char *  decl,
const char *  desc,
const SourceLinkInfo defInfo,
const SourceLinkInfo declInfo 
)
virtual

Writes a tool tip definition

Parameters
idunique identifier for the tooltip
docInfoInfo about the symbol's documentation.
declfull declaration of the symbol (for functions)
descbrief description for the symbol
defInfoInfo about the symbol's definition in the source code
declInfoInfo about the symbol's declaration in the source code

Implements CodeOutputInterface.

Definition at line 568 of file htmlgen.cpp.

References DocLinkInfo::anchor, SourceLinkInfo::anchor, docify(), endl(), externalRef(), SourceLinkInfo::file, Doxygen::htmlFileExtension, SourceLinkInfo::line, m_relPath, m_t, DocLinkInfo::name, DocLinkInfo::ref, SourceLinkInfo::ref, DocLinkInfo::url, and SourceLinkInfo::url.

Referenced by HtmlGenerator::writeTooltip().

{
m_t << "<div class=\"ttc\" id=\"" << id << "\">";
m_t << "<div class=\"ttname\">";
if (!docInfo.url.isEmpty())
{
m_t << "<a href=\"";
m_t << externalRef(m_relPath,docInfo.ref,TRUE);
if (!docInfo.anchor.isEmpty())
{
m_t << "#" << docInfo.anchor;
}
m_t << "\">";
}
docify(docInfo.name);
if (!docInfo.url.isEmpty())
{
m_t << "</a>";
}
m_t << "</div>";
if (decl)
{
m_t << "<div class=\"ttdeci\">";
docify(decl);
m_t << "</div>";
}
if (desc)
{
m_t << "<div class=\"ttdoc\">";
docify(desc); // desc is already HTML escaped; but there are still < and > signs
m_t << "</div>";
}
if (!defInfo.file.isEmpty())
{
m_t << "<div class=\"ttdef\"><b>Definition:</b> ";
if (!defInfo.url.isEmpty())
{
m_t << "<a href=\"";
m_t << externalRef(m_relPath,defInfo.ref,TRUE);
if (!defInfo.anchor.isEmpty())
{
m_t << "#" << defInfo.anchor;
}
m_t << "\">";
}
m_t << defInfo.file << ":" << defInfo.line;
if (!defInfo.url.isEmpty())
{
m_t << "</a>";
}
m_t << "</div>";
}
if (!declInfo.file.isEmpty())
{
m_t << "<div class=\"ttdecl\"><b>Declaration:</b> ";
if (!declInfo.url.isEmpty())
{
m_t << "<a href=\"";
m_t << externalRef(m_relPath,declInfo.ref,TRUE);
if (!declInfo.anchor.isEmpty())
{
m_t << "#" << declInfo.anchor;
}
m_t << "\">";
}
m_t << declInfo.file << ":" << declInfo.line;
if (!declInfo.url.isEmpty())
{
m_t << "</a>";
}
m_t << "</div>";
}
m_t << "</div>" << endl;
}

Member Data Documentation

int HtmlCodeGenerator::m_col
private

Definition at line 66 of file htmlgen.h.

Referenced by _writeCodeLink(), codify(), and startCodeLine().

QCString HtmlCodeGenerator::m_relPath
private

Definition at line 67 of file htmlgen.h.

Referenced by _writeCodeLink(), setRelativePath(), and writeTooltip().

bool HtmlCodeGenerator::m_streamSet
private
FTextStream HtmlCodeGenerator::m_t
private

The documentation for this class was generated from the following files: