Avoid using wxHtmlTag::HasParam() unnecessarily.
Use GetParamAsXXX() accessors instead as they combine the calls to HasParam() and GetParam() and make the code shorter and avoid the duplication of the tag name. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74881 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
6d2190fcb4
commit
534f87c6c4
@ -1264,9 +1264,9 @@ void wxHtmlContainerCell::InsertCell(wxHtmlCell *f)
|
||||
|
||||
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);
|
||||
@ -1283,20 +1283,17 @@ void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag)
|
||||
|
||||
|
||||
void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale)
|
||||
{
|
||||
if (tag.HasParam(wxT("WIDTH")))
|
||||
{
|
||||
int wdi;
|
||||
wxString wd = tag.GetParam(wxT("WIDTH"));
|
||||
|
||||
if (wd[wd.length()-1] == wxT('%'))
|
||||
bool wpercent;
|
||||
if (tag.GetParamAsIntOrPercent(wxT("WIDTH"), &wdi, wpercent))
|
||||
{
|
||||
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;
|
||||
|
@ -918,11 +918,13 @@ bool wxMetaTagHandler::HandleTag(const wxHtmlTag& tag)
|
||||
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);
|
||||
|
@ -38,7 +38,6 @@ TAG_HANDLER_BEGIN(FONT, "FONT" )
|
||||
int oldsize = m_WParser->GetFontSize();
|
||||
wxString oldface = m_WParser->GetFontFace();
|
||||
|
||||
if (tag.HasParam(wxT("COLOR")))
|
||||
{
|
||||
wxColour clr;
|
||||
if (tag.GetParamAsColour(wxT("COLOR"), &clr))
|
||||
@ -48,11 +47,10 @@ TAG_HANDLER_BEGIN(FONT, "FONT" )
|
||||
}
|
||||
}
|
||||
|
||||
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('-'))
|
||||
@ -64,12 +62,13 @@ TAG_HANDLER_BEGIN(FONT, "FONT" )
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
|
@ -661,20 +661,18 @@ TAG_HANDLER_BEGIN(IMG, "IMG,MAP,AREA")
|
||||
{
|
||||
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 (wpercent)
|
||||
@ -685,27 +683,24 @@ TAG_HANDLER_BEGIN(IMG, "IMG,MAP,AREA")
|
||||
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 );
|
||||
@ -729,9 +724,9 @@ TAG_HANDLER_BEGIN(IMG, "IMG,MAP,AREA")
|
||||
{
|
||||
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 );
|
||||
}
|
||||
@ -741,16 +736,12 @@ TAG_HANDLER_BEGIN(IMG, "IMG,MAP,AREA")
|
||||
}
|
||||
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() );
|
||||
@ -763,13 +754,9 @@ TAG_HANDLER_BEGIN(IMG, "IMG,MAP,AREA")
|
||||
{
|
||||
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 );
|
||||
}
|
||||
|
@ -212,9 +212,10 @@ TAG_HANDLER_BEGIN(DIV, "DIV")
|
||||
|
||||
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);
|
||||
@ -330,13 +331,10 @@ TAG_HANDLER_BEGIN(BODY, "BODY")
|
||||
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();
|
||||
|
@ -61,12 +61,14 @@ TAG_HANDLER_BEGIN(A, "A")
|
||||
|
||||
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();
|
||||
@ -77,16 +79,14 @@ TAG_HANDLER_BEGIN(A, "A")
|
||||
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);
|
||||
|
@ -134,16 +134,9 @@ wxHtmlTableCell::wxHtmlTableCell(wxHtmlContainerCell *parent, const wxHtmlTag& t
|
||||
m_ActualCol = m_ActualRow = -1;
|
||||
|
||||
/* scan params: */
|
||||
if (tag.HasParam(wxT("BGCOLOR")))
|
||||
{
|
||||
tag.GetParamAsColour(wxT("BGCOLOR"), &m_tBkg);
|
||||
if (m_tBkg.IsOk())
|
||||
if (tag.GetParamAsColour(wxT("BGCOLOR"), &m_tBkg))
|
||||
SetBackgroundColour(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))
|
||||
@ -242,11 +235,8 @@ void wxHtmlTableCell::AddRow(const wxHtmlTag& tag)
|
||||
|
||||
// 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
|
||||
if (!tag.GetParamAsString(wxT("VALIGN"), &m_rValign))
|
||||
m_rValign = m_tValign;
|
||||
}
|
||||
|
||||
@ -293,28 +283,22 @@ void wxHtmlTableCell::AddCell(wxHtmlContainerCell *cell, const wxHtmlTag& tag)
|
||||
|
||||
// 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 ( wxSscanf(wd.c_str(), wxT("%i%%"), &m_ColsInfo[c].width) == 1 )
|
||||
if (wpercent)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// spanning:
|
||||
@ -351,7 +335,6 @@ void wxHtmlTableCell::AddCell(wxHtmlContainerCell *cell, const wxHtmlTag& tag)
|
||||
//background color:
|
||||
{
|
||||
wxColour bk = m_rBkg;
|
||||
if (tag.HasParam(wxT("BGCOLOR")))
|
||||
tag.GetParamAsColour(wxT("BGCOLOR"), &bk);
|
||||
if (bk.IsOk())
|
||||
cell->SetBackgroundColour(bk);
|
||||
@ -362,9 +345,7 @@ void wxHtmlTableCell::AddCell(wxHtmlContainerCell *cell, const wxHtmlTag& tag)
|
||||
// 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"))
|
||||
@ -375,10 +356,7 @@ void wxHtmlTableCell::AddCell(wxHtmlContainerCell *cell, const wxHtmlTag& tag)
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
@ -739,8 +717,6 @@ TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH")
|
||||
m_Table = new wxHtmlTableCell(c, tag, m_WParser->GetPixelScale());
|
||||
|
||||
// width:
|
||||
{
|
||||
if (tag.HasParam(wxT("WIDTH")))
|
||||
{
|
||||
int width = 0;
|
||||
bool wpercent = false;
|
||||
@ -755,14 +731,12 @@ TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH")
|
||||
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());
|
||||
|
||||
@ -783,9 +757,8 @@ TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH")
|
||||
if (tag.GetName() == wxT("TR"))
|
||||
{
|
||||
m_Table->AddRow(tag);
|
||||
if (!tag.GetParamAsString(wxT("ALIGN"), &m_rAlign))
|
||||
m_rAlign = m_tAlign;
|
||||
if (tag.HasParam(wxT("ALIGN")))
|
||||
m_rAlign = tag.GetParam(wxT("ALIGN"));
|
||||
}
|
||||
|
||||
// new cell
|
||||
@ -799,9 +772,7 @@ TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH")
|
||||
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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user