#include "wx/defs.h"
#if wxUSE_HTML
+class WXDLLEXPORT wxHtmlEntitiesParser;
+
//-----------------------------------------------------------------------------
// wxHtmlTagsCache
// - internal wxHTML class, do not use!
// constructs wxHtmlTag object based on HTML tag.
// The tag begins (with '<' character) at position pos in source
// end_pos is position where parsing ends (usually end of document)
- wxHtmlTag(const wxString& source, int pos, int end_pos, wxHtmlTagsCache* cache);
+ wxHtmlTag(const wxString& source, int pos, int end_pos,
+ wxHtmlTagsCache *cache,
+ wxHtmlEntitiesParser *entParser = NULL);
// Returns tag's name in uppercase.
inline wxString GetName() const {return m_Name;}
// (or ("WhaT.jpg") if with_commas == TRUE)
wxString GetParam(const wxString& par, bool with_commas = FALSE) const;
- // Scans param like scanf() functions family do.
+ // Convenience functions:
+ bool GetParamAsColour(const wxString& par, wxColour *clr) const;
+ bool GetParamAsInt(const wxString& par, int *clr) const;
+
+ // Scans param like scanf() functions family does.
// Example : ScanParam("COLOR", "\"#%X\"", &clr);
// This is always with with_commas=FALSE
// Returns number of scanned values
int ScanParam(const wxString& par, wxChar *format, void *param) const;
// Returns string containing all params.
- inline const wxString& GetAllParams() const {return m_Params;}
+ wxString GetAllParams() const;
// return TRUE if this is ending tag (</something>) or FALSE
// if it isn't (<something>)
inline int GetEndPos2() const {return m_End2;}
private:
- wxString m_Name, m_Params;
+ wxString m_Name;
int m_Begin, m_End1, m_End2;
bool m_Ending;
+ wxArrayString m_ParamNames, m_ParamValues;
};
if (tag.GetParam(wxT("NAME")) == wxT("Local"))
m_Page = tag.GetParam(wxT("VALUE"));
if (tag.GetParam(wxT("NAME")) == wxT("ID"))
- tag.ScanParam(wxT("VALUE"), wxT("%i"), &m_ID);
+ tag.GetParamAsInt(wxT("VALUE"), &m_ID);
return FALSE;
}
}
return wxSscanf(parval, format, param);
}
+bool wxHtmlTag::GetParamAsColour(const wxString& par, wxColour *clr) const
+{
+ wxString str = GetParam(par);
+
+ if (str.IsEmpty()) return FALSE;
+ if (str.GetChar(0) == wxT('#'))
+ {
+ unsigned long tmp;
+ if (ScanParam(par, wxT("#%lX"), &tmp) != 1)
+ return FALSE;
+ *clr = wxColour((unsigned char)((tmp & 0xFF0000) >> 16),
+ (unsigned char)((tmp & 0x00FF00) >> 8),
+ (unsigned char)(tmp & 0x0000FF));
+ return TRUE;
+ }
+ else
+ {
+ // Handle colours defined in HTML 4.0:
+ #define HTML_COLOUR(name,r,g,b) \
+ if (str.IsSameAs(wxT(name), FALSE)) \
+ { *clr = wxColour(r,g,b); return TRUE; }
+ HTML_COLOUR("black", 0x00,0x00,0x00)
+ HTML_COLOUR("silver", 0xC0,0xC0,0xC0)
+ HTML_COLOUR("gray", 0x80,0x80,0x80)
+ HTML_COLOUR("white", 0xFF,0xFF,0xFF)
+ HTML_COLOUR("maroon", 0x80,0x00,0x00)
+ HTML_COLOUR("red", 0xFF,0x00,0x00)
+ HTML_COLOUR("purple", 0x80,0x00,0x80)
+ HTML_COLOUR("fuchsia", 0xFF,0x00,0xFF)
+ HTML_COLOUR("green", 0x00,0x80,0x00)
+ HTML_COLOUR("lime", 0x00,0xFF,0x00)
+ HTML_COLOUR("olive", 0x80,0x80,0x00)
+ HTML_COLOUR("yellow", 0xFF,0xFF,0x00)
+ HTML_COLOUR("navy", 0x00,0x00,0x80)
+ HTML_COLOUR("blue", 0x00,0x00,0xFF)
+ HTML_COLOUR("teal", 0x00,0x80,0x80)
+ HTML_COLOUR("aqua", 0x00,0xFF,0xFF)
+ #undef HTML_COLOUR
+ return FALSE;
+ }
+}
+
+bool wxHtmlTag::GetParamAsInt(const wxString& par, int *clr) const
+{
+ if (!HasParam(par)) return FALSE;
+ long i;
+ bool succ = GetParam(par).ToLong(&i);
+ *clr = (int)i;
+ return succ;
+}
+
wxString wxHtmlTag::GetAllParams() const
{
// VS: this function is for backward compatiblity only,
if (tag.HasParam(wxT("COLOR")))
{
- unsigned long tmp = 0;
wxColour clr;
- if (tag.ScanParam(wxT("COLOR"), wxT("#%lX"), &tmp) == 1)
+ if (tag.GetParamAsColour(wxT("COLOR"), &clr))
{
- clr = wxColour((unsigned char)((tmp & 0xFF0000) >> 16),
- (unsigned char)((tmp & 0x00FF00) >> 8),
- (unsigned char)(tmp & 0x0000FF));
m_WParser->SetActualColor(clr);
m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr));
}
if (tag.HasParam(wxT("SIZE")))
{
- long tmp = 0;
- wxChar c = tag.GetParam(wxT("SIZE"))[(unsigned int) 0];
- if (tag.ScanParam(wxT("SIZE"), wxT("%li"), &tmp) == 1)
+ int tmp = 0;
+ wxChar c = tag.GetParam(wxT("SIZE")).GetChar(0);
+ if (tag.GetParamAsInt(wxT("SIZE"), &tmp))
{
- if (c == '+' || c == '-')
+ if (c == wxT('+') || c == wxT('-'))
m_WParser->SetFontSize(oldsize+tmp);
else
m_WParser->SetFontSize(tmp);
- m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
+ m_WParser->GetContainer()->InsertCell(
+ new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
}
}
enu.EnumerateFacenames();
m_Faces = *enu.GetFacenames();
}
- wxStringTokenizer tk(tag.GetParam(wxT("FACE")), ",");
+ wxStringTokenizer tk(tag.GetParam(wxT("FACE")), wxT(","));
int index;
while (tk.HasMoreTokens())
int underlined = m_WParser->GetFontUnderlined();
m_WParser->SetFontUnderlined(TRUE);
- m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
+ m_WParser->GetContainer()->InsertCell(
+ new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
ParseInner(tag);
m_WParser->SetFontUnderlined(underlined);
- m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
+ m_WParser->GetContainer()->InsertCell(
+ new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
return TRUE;
}
int bold = m_WParser->GetFontBold();
m_WParser->SetFontBold(TRUE);
- m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
+ m_WParser->GetContainer()->InsertCell(
+ new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
ParseInner(tag);
m_WParser->SetFontBold(bold);
- m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
+ m_WParser->GetContainer()->InsertCell(
+ new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
return TRUE;
}
int italic = m_WParser->GetFontItalic();
m_WParser->SetFontItalic(TRUE);
- m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
+ m_WParser->GetContainer()->InsertCell(
+ new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
ParseInner(tag);
m_WParser->SetFontItalic(italic);
- m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
+ m_WParser->GetContainer()->InsertCell(
+ new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
return TRUE;
}
int fixed = m_WParser->GetFontFixed();
m_WParser->SetFontFixed(TRUE);
- m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
+ m_WParser->GetContainer()->InsertCell(
+ new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
ParseInner(tag);
m_WParser->SetFontFixed(fixed);
- m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
+ m_WParser->GetContainer()->InsertCell(
+ new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
return TRUE;
}
m_WParser->SetFontFixed(old_f);
m_WParser->SetAlign(old_al);
- m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
+ m_WParser->GetContainer()->InsertCell(
+ new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
m_WParser->CloseContainer();
m_WParser->OpenContainer();
c = m_WParser->GetContainer();
int sz = (tag.GetName() == wxT("BIG")) ? +1 : -1;
m_WParser->SetFontSize(sz);
- m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
+ m_WParser->GetContainer()->InsertCell(
+ new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
ParseInner(tag);
m_WParser->SetFontSize(oldsize);
- m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
+ m_WParser->GetContainer()->InsertCell(
+ new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
return TRUE;
}
c->SetAlign(tag);
c->SetWidthFloat(tag);
sz = 1;
- if (tag.HasParam(wxT("SIZE")) && tag.ScanParam(wxT("SIZE"), wxT("%i"), &sz) == 1) {}
+ tag.GetParamAsInt(wxT("SIZE"), &sz);
c->InsertCell(new wxHtmlLineCell((int)((double)sz * m_WParser->GetPixelScale())));
m_WParser->CloseContainer();
wxString mn = wxEmptyString;
str = m_WParser->GetFS()->OpenFile(tmp);
- if (tag.HasParam(wxT("WIDTH"))) tag.ScanParam(wxT("WIDTH"), wxT("%i"), &w);
- if (tag.HasParam(wxT("HEIGHT"))) tag.ScanParam(wxT("HEIGHT"), wxT("%i"), &h);
+ if (tag.HasParam(wxT("WIDTH")))
+ tag.GetParamAsInt(wxT("WIDTH"), &w);
+ if (tag.HasParam(wxT("HEIGHT")))
+ tag.GetParamAsInt(wxT("HEIGHT"), &h);
al = wxHTML_ALIGN_BOTTOM;
if (tag.HasParam(wxT("ALIGN")))
{
wxString alstr = tag.GetParam(wxT("ALIGN"));
alstr.MakeUpper(); // for the case alignment was in ".."
- if (alstr == wxT("TEXTTOP")) al = wxHTML_ALIGN_TOP;
- else if ((alstr == wxT("CENTER")) || (alstr == wxT("ABSCENTER"))) al = wxHTML_ALIGN_CENTER;
+ if (alstr == wxT("TEXTTOP"))
+ al = wxHTML_ALIGN_TOP;
+ else if ((alstr == wxT("CENTER")) || (alstr == wxT("ABSCENTER")))
+ al = wxHTML_ALIGN_CENTER;
}
if (tag.HasParam(wxT("USEMAP")))
{
mn = tag.GetParam( wxT("USEMAP") );
- if (mn[ (unsigned int) 0 ] == wxT('#'))
+ if (mn.GetChar(0) == wxT('#'))
{
mn = mn.Mid( 1 );
}
TAG_HANDLER_PROC(tag)
{
- unsigned long tmp;
wxColour clr;
- if (tag.HasParam(wxT("TEXT")))
+ if (tag.GetParamAsColour(wxT("TEXT"), &clr))
{
- if (tag.ScanParam(wxT("TEXT"), wxT("#%lX"), &tmp) == 1)
- {
- clr = wxColour((unsigned char)((tmp & 0xFF0000) >> 16),
- (unsigned char)((tmp & 0x00FF00) >> 8),
- (unsigned char)(tmp & 0x0000FF));
- m_WParser->SetActualColor(clr);
- m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr));
- }
- }
-
- if (tag.HasParam(wxT("LINK")))
- {
- if (tag.ScanParam(wxT("LINK"), wxT("#%lX"), &tmp) == 1)
- {
- clr = wxColour((unsigned char)((tmp & 0xFF0000) >> 16),
- (unsigned char)((tmp & 0x00FF00) >> 8),
- (unsigned char)(tmp & 0x0000FF));
- m_WParser->SetLinkColor(clr);
- }
+ m_WParser->SetActualColor(clr);
+ m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr));
}
- if (tag.HasParam(wxT("BGCOLOR")))
+ if (tag.GetParamAsColour(wxT("LINK"), &clr))
+ m_WParser->SetLinkColor(clr);
+
+ if (tag.GetParamAsColour(wxT("BGCOLOR"), &clr))
{
- if (tag.ScanParam(wxT("BGCOLOR"), wxT("#%lX"), &tmp) == 1)
- {
- clr = wxColour((unsigned char)((tmp & 0xFF0000) >> 16),
- (unsigned char)((tmp & 0x00FF00) >> 8),
- (unsigned char)(tmp & 0x0000FF));
- m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr, wxHTML_CLR_BACKGROUND));
- if (m_WParser->GetWindow() != NULL)
- m_WParser->GetWindow()->SetBackgroundColour(clr);
- }
+ m_WParser->GetContainer()->InsertCell(
+ new wxHtmlColourCell(clr, wxHTML_CLR_BACKGROUND));
+ if (m_WParser->GetWindow() != NULL)
+ m_WParser->GetWindow()->SetBackgroundColour(clr);
}
return FALSE;
}
typedef struct {
- int width, units; // universal
- int leftpos, pixwidth, maxrealwidth; // temporary (depends on width of table)
+ int width, units;
+ // universal
+ int leftpos, pixwidth, maxrealwidth;
+ // temporary (depends on width of table)
} colStruct;
typedef enum {
// number of actual column (ranging from 0..m_NumCols)
// default values (for table and row):
- int m_tBkg, m_rBkg;
+ wxColour m_tBkg, m_rBkg;
wxString m_tValign, m_rValign;
double m_PixelScale;
: wxHtmlContainerCell(parent)
{
m_PixelScale = pixel_scale;
- m_HasBorders = (tag.HasParam(wxT("BORDER")) && tag.GetParam(wxT("BORDER")) != wxT("0"));
+ m_HasBorders = (tag.GetParam(wxT("BORDER")) != wxT("0"));
m_ColsInfo = NULL;
m_NumCols = m_NumRows = 0;
m_CellInfo = NULL;
m_ActualCol = m_ActualRow = -1;
/* scan params: */
- m_tBkg = m_rBkg = -1;
- if (tag.HasParam(wxT("BGCOLOR"))) tag.ScanParam(wxT("BGCOLOR"), wxT("#%lX"), &m_tBkg);
- if (tag.HasParam(wxT("VALIGN"))) m_tValign = tag.GetParam(wxT("VALIGN")); else m_tValign = wxEmptyString;
- if (tag.HasParam(wxT("CELLSPACING")) && tag.ScanParam(wxT("CELLSPACING"), wxT("%i"), &m_Spacing) == 1) {} else m_Spacing = 2;
- if (tag.HasParam(wxT("CELLPADDING")) && tag.ScanParam(wxT("CELLPADDING"), wxT("%i"), &m_Padding) == 1) {} else m_Padding = 3;
+ if (tag.HasParam(wxT("BGCOLOR")))
+ tag.GetParamAsColour(wxT("BGCOLOR"), &m_tBkg);
+ if (tag.HasParam(wxT("VALIGN")))
+ m_tValign = tag.GetParam(wxT("VALIGN"));
+ else
+ m_tValign = wxEmptyString;
+ if (!tag.GetParamAsInt(wxT("CELLSPACING"), &m_Spacing))
+ m_Spacing = 2;
+ if (!tag.GetParamAsInt(wxT("CELLPADDING"), &m_Padding))
+ m_Padding = 3;
m_Spacing = (int)(m_PixelScale * (double)m_Spacing);
m_Padding = (int)(m_PixelScale * (double)m_Padding);
// scan params:
m_rBkg = m_tBkg;
if (tag.HasParam(wxT("BGCOLOR")))
- tag.ScanParam(wxT("BGCOLOR"), wxT("#%lX"), &m_rBkg);
+ tag.GetParamAsColour(wxT("BGCOLOR"), &m_rBkg);
if (tag.HasParam(wxT("VALIGN")))
m_rValign = tag.GetParam(wxT("VALIGN"));
else
do
{
m_ActualCol++;
- } while ((m_ActualCol < m_NumCols) && (m_CellInfo[m_ActualRow][m_ActualCol].flag != cellFree));
+ } while ((m_ActualCol < m_NumCols) &&
+ (m_CellInfo[m_ActualRow][m_ActualCol].flag != cellFree));
if (m_ActualCol > m_NumCols - 1)
ReallocCols(m_ActualCol + 1);
// width:
{
- if (tag.HasParam("WIDTH"))
+ if (tag.HasParam(wxT("WIDTH")))
{
- wxString wd = tag.GetParam("WIDTH");
+ wxString wd = tag.GetParam(wxT("WIDTH"));
- if (wd[wd.Length()-1] == '%')
+ if (wd[wd.Length()-1] == wxT('%'))
{
wxSscanf(wd.c_str(), wxT("%i%%"), &m_ColsInfo[c].width);
m_ColsInfo[c].units = wxHTML_UNITS_PERCENT;
// spanning:
{
- if (tag.HasParam(wxT("COLSPAN"))) tag.ScanParam(wxT("COLSPAN"), wxT("%i"), &m_CellInfo[r][c].colspan);
- if (tag.HasParam(wxT("ROWSPAN"))) tag.ScanParam(wxT("ROWSPAN"), wxT("%i"), &m_CellInfo[r][c].rowspan);
+ tag.GetParamAsInt(wxT("COLSPAN"), &m_CellInfo[r][c].colspan);
+ tag.GetParamAsInt(wxT("ROWSPAN"), &m_CellInfo[r][c].rowspan);
if ((m_CellInfo[r][c].colspan != 1) || (m_CellInfo[r][c].rowspan != 1))
{
int i, j;
- if (r + m_CellInfo[r][c].rowspan > m_NumRows) ReallocRows(r + m_CellInfo[r][c].rowspan);
- if (c + m_CellInfo[r][c].colspan > m_NumCols) ReallocCols(c + m_CellInfo[r][c].colspan);
+ if (r + m_CellInfo[r][c].rowspan > m_NumRows)
+ ReallocRows(r + m_CellInfo[r][c].rowspan);
+ if (c + m_CellInfo[r][c].colspan > m_NumCols)
+ ReallocCols(c + m_CellInfo[r][c].colspan);
for (i = r; i < r + m_CellInfo[r][c].rowspan; i++)
for (j = c; j < c + m_CellInfo[r][c].colspan; j++)
m_CellInfo[i][j].flag = cellSpan;
//background color:
{
- int bk = m_rBkg;
- if (tag.HasParam(wxT("BGCOLOR"))) tag.ScanParam(wxT("BGCOLOR"), wxT("#%lX"), &bk);
- if (bk != -1)
- {
- wxColour clr = wxColour((bk & 0xFF0000) >> 16 , (bk & 0x00FF00) >> 8, (bk & 0x0000FF));
- cell->SetBackgroundColour(clr);
- }
+ wxColour bk = m_rBkg;
+ if (tag.HasParam(wxT("BGCOLOR")))
+ tag.GetParamAsColour(wxT("BGCOLOR"), &bk);
+ if (bk.Ok())
+ cell->SetBackgroundColour(bk);
}
if (m_HasBorders)
cell->SetBorder(TABLE_BORDER_CLR_2, TABLE_BORDER_CLR_1);
// vertical alignment:
{
wxString valign;
- if (tag.HasParam(wxT("VALIGN"))) valign = tag.GetParam(wxT("VALIGN")); else valign = m_tValign;
+ if (tag.HasParam(wxT("VALIGN")))
+ valign = tag.GetParam(wxT("VALIGN"));
+ else
+ valign = m_tValign;
valign.MakeUpper();
- if (valign == wxT("TOP")) m_CellInfo[r][c].valign = wxHTML_ALIGN_TOP;
- else if (valign == wxT("BOTTOM")) m_CellInfo[r][c].valign = wxHTML_ALIGN_BOTTOM;
+ if (valign == wxT("TOP"))
+ m_CellInfo[r][c].valign = wxHTML_ALIGN_TOP;
+ else if (valign == wxT("BOTTOM"))
+ m_CellInfo[r][c].valign = wxHTML_ALIGN_BOTTOM;
else m_CellInfo[r][c].valign = wxHTML_ALIGN_CENTER;
}
m_Table = new wxHtmlTableCell(c, tag, m_WParser->GetPixelScale());
m_OldAlign = m_WParser->GetAlign();
m_tAlign = wxEmptyString;
- if (tag.HasParam(wxT("ALIGN"))) m_tAlign = tag.GetParam(wxT("ALIGN"));
+ if (tag.HasParam(wxT("ALIGN")))
+ m_tAlign = tag.GetParam(wxT("ALIGN"));
ParseInner(tag);
{
m_Table->AddRow(tag);
m_rAlign = m_tAlign;
- if (tag.HasParam(wxT("ALIGN"))) m_rAlign = tag.GetParam(wxT("ALIGN"));
+ if (tag.HasParam(wxT("ALIGN")))
+ m_rAlign = tag.GetParam(wxT("ALIGN"));
}
// new cell
wxString als;
als = m_rAlign;
- if (tag.HasParam(wxT("ALIGN"))) als = tag.GetParam(wxT("ALIGN"));
+ if (tag.HasParam(wxT("ALIGN")))
+ als = tag.GetParam(wxT("ALIGN"));
als.MakeUpper();
- if (als == wxT("RIGHT")) m_WParser->SetAlign(wxHTML_ALIGN_RIGHT);
- else if (als == wxT("CENTER")) m_WParser->SetAlign(wxHTML_ALIGN_CENTER);
+ if (als == wxT("RIGHT"))
+ m_WParser->SetAlign(wxHTML_ALIGN_RIGHT);
+ else if (als == wxT("CENTER"))
+ m_WParser->SetAlign(wxHTML_ALIGN_CENTER);
}
m_WParser->OpenContainer();
}