void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag)
{
- if (tag.HasParam(wxT("ALIGN")))
+ wxString alg;
+ if (tag.GetParamAsString(wxT("ALIGN"), &alg))
{
- wxString alg = tag.GetParam(wxT("ALIGN"));
alg.MakeUpper();
if (alg == wxT("CENTER"))
SetAlignHor(wxHTML_ALIGN_CENTER);
void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale)
{
- if (tag.HasParam(wxT("WIDTH")))
+ int wdi;
+ bool wpercent;
+ if (tag.GetParamAsIntOrPercent(wxT("WIDTH"), &wdi, wpercent))
{
- int wdi;
- wxString wd = tag.GetParam(wxT("WIDTH"));
-
- if (wd[wd.length()-1] == wxT('%'))
+ if (wpercent)
{
- wxSscanf(wd.c_str(), wxT("%i%%"), &wdi);
SetWidthFloat(wdi, wxHTML_UNITS_PERCENT);
}
else
{
- wxSscanf(wd.c_str(), wxT("%i"), &wdi);
SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS);
}
m_LastLayout = -1;
return false;
}
- if (tag.HasParam(wxT("HTTP-EQUIV")) &&
- tag.GetParam(wxT("HTTP-EQUIV")).IsSameAs(wxT("Content-Type"), false) &&
- tag.HasParam(wxT("CONTENT")))
+ wxString httpEquiv,
+ content;
+ if (tag.GetParamAsString(wxT("HTTP-EQUIV"), &httpEquiv) &&
+ httpEquiv.IsSameAs(wxT("Content-Type"), false) &&
+ tag.GetParamAsString(wxT("CONTENT"), &content))
{
- wxString content = tag.GetParam(wxT("CONTENT")).Lower();
+ content.MakeLower();
if (content.Left(19) == wxT("text/html; charset="))
{
*m_retval = content.Mid(19);
int oldsize = m_WParser->GetFontSize();
wxString oldface = m_WParser->GetFontFace();
- if (tag.HasParam(wxT("COLOR")))
{
wxColour clr;
if (tag.GetParamAsColour(wxT("COLOR"), &clr))
}
}
- if (tag.HasParam(wxT("SIZE")))
{
long tmp = 0;
- const wxString sizeStr = tag.GetParam(wxT("SIZE"));
- if (sizeStr.ToLong(&tmp))
+ wxString sizeStr;
+ if (tag.GetParamAsString(wxT("SIZE"), &sizeStr) && sizeStr.ToLong(&tmp))
{
wxChar c = sizeStr[0];
if (c == wxT('+') || c == wxT('-'))
}
}
- if (tag.HasParam(wxT("FACE")))
+ wxString faces;
+ if (tag.GetParamAsString(wxT("FACE"), &faces))
{
if (m_Faces.GetCount() == 0)
m_Faces = wxFontEnumerator::GetFacenames();
- wxStringTokenizer tk(tag.GetParam(wxT("FACE")), wxT(","));
+ wxStringTokenizer tk(faces, wxT(","));
int index;
while (tk.HasMoreTokens())
{
if (tag.GetName() == wxT("IMG"))
{
- if (tag.HasParam(wxT("SRC")))
+ wxString tmp;
+ if (tag.GetParamAsString(wxT("SRC"), &tmp))
{
int w = wxDefaultCoord, h = wxDefaultCoord;
bool wpercent = false;
bool hpresent = false;
int al;
wxFSFile *str;
- wxString tmp = tag.GetParam(wxT("SRC"));
- wxString mn = wxEmptyString;
+ wxString mn;
str = m_WParser->OpenURL(wxHTML_URL_IMAGE, tmp);
- if (tag.HasParam(wxT("WIDTH")))
+ if (tag.GetParamAsIntOrPercent(wxT("WIDTH"), &w, wpercent))
{
- if (tag.GetParamAsIntOrPercent(wxT("WIDTH"), &w, wpercent))
+ if (wpercent)
{
- if (wpercent)
- {
- if (w < 0)
- w = 0;
- else if (w > 100)
- w = 100;
- }
+ if (w < 0)
+ w = 0;
+ else if (w > 100)
+ w = 100;
}
}
- if (tag.HasParam(wxT("HEIGHT")))
+ if (tag.GetParamAsInt(wxT("HEIGHT"), &h))
{
- tag.GetParamAsInt(wxT("HEIGHT"), &h);
hpresent = true;
}
al = wxHTML_ALIGN_BOTTOM;
- if (tag.HasParam(wxT("ALIGN")))
+ wxString alstr;
+ if (tag.GetParamAsString(wxT("ALIGN"), &alstr))
{
- 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 (tag.HasParam(wxT("USEMAP")))
+ if (tag.GetParamAsString(wxT("USEMAP"), &mn))
{
- mn = tag.GetParam( wxT("USEMAP") );
if ( !mn.empty() && *mn.begin() == '#' )
{
mn = mn.Mid( 1 );
{
m_WParser->CloseContainer();
m_WParser->OpenContainer();
- if (tag.HasParam(wxT("NAME")))
+ wxString tmp;
+ if (tag.GetParamAsString(wxT("NAME"), &tmp))
{
- wxString tmp = tag.GetParam(wxT("NAME"));
wxHtmlImageMapCell *cel = new wxHtmlImageMapCell( tmp );
m_WParser->GetContainer()->InsertCell( cel );
}
}
if (tag.GetName() == wxT("AREA"))
{
- if (tag.HasParam(wxT("SHAPE")))
+ wxString tmp;
+ if (tag.GetParamAsString(wxT("SHAPE"), &tmp))
{
- wxString tmp = tag.GetParam(wxT("SHAPE"));
- wxString coords = wxEmptyString;
+ wxString coords = tag.GetParam(wxT("COORDS"));
tmp.MakeUpper();
wxHtmlImageMapAreaCell *cel = NULL;
- if (tag.HasParam(wxT("COORDS")))
- {
- coords = tag.GetParam(wxT("COORDS"));
- }
if (tmp == wxT("POLY"))
{
cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::POLY, coords, m_WParser->GetPixelScale() );
{
cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::RECT, coords, m_WParser->GetPixelScale() );
}
- if (cel != NULL && tag.HasParam(wxT("HREF")))
- {
- wxString target;
- if (tag.HasParam(wxT("TARGET")))
- target = tag.GetParam(wxT("TARGET"));
- cel->SetLink(wxHtmlLinkInfo(tag.GetParam(wxT("HREF")), target));
- }
+ wxString href;
+ if (cel != NULL && tag.GetParamAsString(wxT("HREF"), &href))
+ cel->SetLink(wxHtmlLinkInfo(href, tag.GetParam(wxT("TARGET"))));
if (cel != NULL)
m_WParser->GetContainer()->InsertCell( cel );
}
TAG_HANDLER_PROC(tag)
{
- if(tag.HasParam(wxT("STYLE")))
+ wxString style;
+ if(tag.GetParamAsString(wxT("STYLE"), &style))
{
- if(tag.GetParam(wxT("STYLE")).IsSameAs(wxT("PAGE-BREAK-BEFORE:ALWAYS"), false))
+ if(style.IsSameAs(wxT("PAGE-BREAK-BEFORE:ALWAYS"), false))
{
m_WParser->CloseContainer();
m_WParser->OpenContainer()->InsertCell(new wxHtmlPageBreakCell);
if ( !winIface )
return false;
- if (tag.HasParam(wxT("BACKGROUND")))
+ wxString bg;
+ if (tag.GetParamAsString(wxT("BACKGROUND"), &bg))
{
- wxFSFile *fileBgImage = m_WParser->OpenURL
- (
- wxHTML_URL_IMAGE,
- tag.GetParam(wxT("BACKGROUND"))
- );
+ wxFSFile *fileBgImage = m_WParser->OpenURL(wxHTML_URL_IMAGE, bg);
if ( fileBgImage )
{
wxInputStream *is = fileBgImage->GetStream();
TAG_HANDLER_PROC(tag)
{
- if (tag.HasParam( wxT("NAME") ))
+ wxString name;
+ if (tag.GetParamAsString(wxT("NAME"), &name))
{
- m_WParser->GetContainer()->InsertCell(new wxHtmlAnchorCell(tag.GetParam( wxT("NAME") )));
+ m_WParser->GetContainer()->InsertCell(new wxHtmlAnchorCell(name));
}
- if (tag.HasParam( wxT("HREF") ))
+ wxString href;
+ if (tag.GetParamAsString(wxT("HREF"), &href))
{
wxHtmlLinkInfo oldlnk = m_WParser->GetLink();
wxColour oldclr = m_WParser->GetActualColor();
int olditalic = m_WParser->GetFontItalic();
int oldund = m_WParser->GetFontUnderlined();
wxString oldfontface = m_WParser->GetFontFace();
- wxString name(tag.GetParam( wxT("HREF") )), target;
-
- if (tag.HasParam( wxT("TARGET") )) target = tag.GetParam( wxT("TARGET") );
+ wxString target = tag.GetParam( wxT("TARGET") );
// set default styles, might get overridden by ApplyStyle
m_WParser->SetActualColor(m_WParser->GetLinkColor());
m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(m_WParser->GetLinkColor()));
m_WParser->SetFontUnderlined(true);
m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
- m_WParser->SetLink(wxHtmlLinkInfo(name, target));
+ m_WParser->SetLink(wxHtmlLinkInfo(href, target));
// Load any style parameters
wxHtmlStyleParams styleParams(tag);
m_ActualCol = m_ActualRow = -1;
/* scan params: */
- if (tag.HasParam(wxT("BGCOLOR")))
- {
- tag.GetParamAsColour(wxT("BGCOLOR"), &m_tBkg);
- if (m_tBkg.IsOk())
- SetBackgroundColour(m_tBkg);
- }
- if (tag.HasParam(wxT("VALIGN")))
- m_tValign = tag.GetParam(wxT("VALIGN"));
- else
- m_tValign = wxEmptyString;
+ if (tag.GetParamAsColour(wxT("BGCOLOR"), &m_tBkg))
+ SetBackgroundColour(m_tBkg);
+ m_tValign = tag.GetParam(wxT("VALIGN"));
if (!tag.GetParamAsInt(wxT("CELLSPACING"), &m_Spacing))
m_Spacing = 2;
if (!tag.GetParamAsInt(wxT("CELLPADDING"), &m_Padding))
// scan params:
m_rBkg = m_tBkg;
- if (tag.HasParam(wxT("BGCOLOR")))
- tag.GetParamAsColour(wxT("BGCOLOR"), &m_rBkg);
- if (tag.HasParam(wxT("VALIGN")))
- m_rValign = tag.GetParam(wxT("VALIGN"));
- else
+ tag.GetParamAsColour(wxT("BGCOLOR"), &m_rBkg);
+ if (!tag.GetParamAsString(wxT("VALIGN"), &m_rValign))
m_rValign = m_tValign;
}
// width:
{
- if (tag.HasParam(wxT("WIDTH")))
+ int width = 0;
+ bool wpercent = false;
+ if (tag.GetParamAsIntOrPercent(wxT("WIDTH"), &width, wpercent))
{
- wxString wd = tag.GetParam(wxT("WIDTH"));
-
- if (!wd.empty() && wd[wd.length()-1] == wxT('%'))
+ if (wpercent)
{
- if ( wxSscanf(wd.c_str(), wxT("%i%%"), &m_ColsInfo[c].width) == 1 )
- {
- m_ColsInfo[c].units = wxHTML_UNITS_PERCENT;
- }
+ m_ColsInfo[c].width = width;
+ m_ColsInfo[c].units = wxHTML_UNITS_PERCENT;
}
else
{
- long width;
- if ( wd.ToLong(&width) )
- {
- m_ColsInfo[c].width = (int)(m_PixelScale * (double)width);
- m_ColsInfo[c].units = wxHTML_UNITS_PIXELS;
- }
+ m_ColsInfo[c].width = (int)(m_PixelScale * (double)width);
+ m_ColsInfo[c].units = wxHTML_UNITS_PIXELS;
}
}
}
//background color:
{
wxColour bk = m_rBkg;
- if (tag.HasParam(wxT("BGCOLOR")))
- tag.GetParamAsColour(wxT("BGCOLOR"), &bk);
+ tag.GetParamAsColour(wxT("BGCOLOR"), &bk);
if (bk.IsOk())
cell->SetBackgroundColour(bk);
}
// vertical alignment:
{
wxString valign;
- if (tag.HasParam(wxT("VALIGN")))
- valign = tag.GetParam(wxT("VALIGN"));
- else
+ if (!tag.GetParamAsString(wxT("VALIGN"), &valign))
valign = m_tValign;
valign.MakeUpper();
if (valign == wxT("TOP"))
}
// nowrap
- if (tag.HasParam(wxT("NOWRAP")))
- m_CellInfo[r][c].nowrap = true;
- else
- m_CellInfo[r][c].nowrap = false;
+ m_CellInfo[r][c].nowrap = tag.HasParam(wxT("NOWRAP"));
cell->SetIndent(m_Padding, wxHTML_INDENT_ALL, wxHTML_UNITS_PIXELS);
}
// width:
{
- if (tag.HasParam(wxT("WIDTH")))
+ int width = 0;
+ bool wpercent = false;
+ if (tag.GetParamAsIntOrPercent(wxT("WIDTH"), &width, wpercent))
{
- int width = 0;
- bool wpercent = false;
- if (tag.GetParamAsIntOrPercent(wxT("WIDTH"), &width, wpercent))
+ if (wpercent)
{
- if (wpercent)
- {
- m_Table->SetWidthFloat(width, wxHTML_UNITS_PERCENT);
- }
- else
- {
- m_Table->SetWidthFloat((int)(m_WParser->GetPixelScale() * width), wxHTML_UNITS_PIXELS);
- }
+ m_Table->SetWidthFloat(width, wxHTML_UNITS_PERCENT);
+ }
+ else
+ {
+ m_Table->SetWidthFloat((int)(m_WParser->GetPixelScale() * width), wxHTML_UNITS_PIXELS);
}
}
else
m_Table->SetWidthFloat(0, wxHTML_UNITS_PIXELS);
}
int oldAlign = m_WParser->GetAlign();
- m_tAlign = wxEmptyString;
- if (tag.HasParam(wxT("ALIGN")))
- m_tAlign = tag.GetParam(wxT("ALIGN"));
+ if (!tag.GetParamAsString(wxT("ALIGN"), &m_tAlign))
+ m_tAlign.clear();
CallParseInnerWithBg(tag, m_Table->GetBackgroundColour());
if (tag.GetName() == wxT("TR"))
{
m_Table->AddRow(tag);
- m_rAlign = m_tAlign;
- if (tag.HasParam(wxT("ALIGN")))
- m_rAlign = tag.GetParam(wxT("ALIGN"));
+ if (!tag.GetParamAsString(wxT("ALIGN"), &m_rAlign))
+ m_rAlign = m_tAlign;
}
// new cell
const bool isHeader = tag.GetName() == wxT("TH");
wxString als;
- if (tag.HasParam(wxT("ALIGN")))
- als = tag.GetParam(wxT("ALIGN"));
- else
+ if (!tag.GetParamAsString(wxT("ALIGN"), &als))
als = m_rAlign;
als.MakeUpper();