Add support for background-color style to span element in wxHTML.

Add code for setting/restoring background mode and use it to implement support
for changing the text background colour.

Closes #14443.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72589 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-09-30 22:20:58 +00:00
parent a0393f9725
commit f5413b878c
8 changed files with 66 additions and 31 deletions

View File

@@ -504,10 +504,12 @@ static void SwitchSelState(wxDC& dc, wxHtmlRenderingInfo& info,
}
else
{
dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
const int mode = info.GetState().GetBgMode();
dc.SetBackgroundMode(mode);
dc.SetTextForeground(fg);
dc.SetTextBackground(bg);
dc.SetBackground(wxBrush(bg, wxBRUSHSTYLE_SOLID));
if ( mode != wxTRANSPARENT )
dc.SetBackground(wxBrush(bg, mode));
}
}
@@ -572,16 +574,7 @@ void wxHtmlWordCell::Draw(wxDC& dc, int x, int y,
{
wxHtmlSelectionState selstate = info.GetState().GetSelectionState();
// Not changing selection state, draw the word in single mode:
if ( selstate != wxHTML_SEL_OUT &&
dc.GetBackgroundMode() != wxBRUSHSTYLE_SOLID )
{
SwitchSelState(dc, info, true);
}
else if ( selstate == wxHTML_SEL_OUT &&
dc.GetBackgroundMode() == wxBRUSHSTYLE_SOLID )
{
SwitchSelState(dc, info, false);
}
SwitchSelState(dc, info, selstate != wxHTML_SEL_OUT);
dc.DrawText(m_Word, x + m_PosX, y + m_PosY);
drawSelectionAfterCell = (selstate != wxHTML_SEL_OUT);
}
@@ -1552,17 +1545,23 @@ void wxHtmlColourCell::DrawInvisible(wxDC& dc,
if (m_Flags & wxHTML_CLR_BACKGROUND)
{
state.SetBgColour(m_Colour);
if (state.GetSelectionState() != wxHTML_SEL_IN)
{
dc.SetTextBackground(m_Colour);
dc.SetBackground(wxBrush(m_Colour, wxBRUSHSTYLE_SOLID));
}
else
{
wxColour c = info.GetStyle().GetSelectedTextBgColour(m_Colour);
dc.SetTextBackground(c);
dc.SetBackground(wxBrush(c, wxBRUSHSTYLE_SOLID));
}
state.SetBgMode(wxSOLID);
const wxColour c = state.GetSelectionState() == wxHTML_SEL_IN
? info.GetStyle().GetSelectedTextBgColour(m_Colour)
: m_Colour;
dc.SetTextBackground(c);
dc.SetBackground(c);
dc.SetBackgroundMode(wxSOLID);
}
if (m_Flags & wxHTML_CLR_TRANSPARENT_BACKGROUND)
{
state.SetBgColour(m_Colour);
state.SetBgMode(wxTRANSPARENT);
const wxColour c = state.GetSelectionState() == wxHTML_SEL_IN
? info.GetStyle().GetSelectedTextBgColour(m_Colour)
: m_Colour;
dc.SetTextBackground(c);
dc.SetBackgroundMode(wxTRANSPARENT);
}
}

View File

@@ -34,6 +34,8 @@ TAG_HANDLER_BEGIN(SPAN, "SPAN" )
TAG_HANDLER_PROC(tag)
{
wxColour oldclr = m_WParser->GetActualColor();
wxColour oldbackclr = m_WParser->GetActualBackgroundColor();
int oldbackmode = m_WParser->GetActualBackgroundMode();
int oldsize = m_WParser->GetFontSize();
int oldbold = m_WParser->GetFontBold();
int olditalic = m_WParser->GetFontItalic();
@@ -56,6 +58,18 @@ TAG_HANDLER_BEGIN(SPAN, "SPAN" )
}
}
str = styleParams.GetParam(wxS("background-color"));
if ( !str.empty() )
{
wxColour clr;
if ( wxHtmlTag::ParseAsColour(str, &clr) )
{
m_WParser->SetActualBackgroundColor(clr);
m_WParser->SetActualBackgroundMode(wxBRUSHSTYLE_SOLID);
m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr, wxHTML_CLR_BACKGROUND));
}
}
str = styleParams.GetParam(wxS("font-size"));
if ( !str.empty() )
{
@@ -151,6 +165,15 @@ TAG_HANDLER_BEGIN(SPAN, "SPAN" )
new wxHtmlColourCell(oldclr));
}
if (oldbackmode != m_WParser->GetActualBackgroundMode() ||
oldbackclr != m_WParser->GetActualBackgroundColor())
{
m_WParser->SetActualBackgroundMode(oldbackmode);
m_WParser->SetActualBackgroundColor(oldbackclr);
m_WParser->GetContainer()->InsertCell(
new wxHtmlColourCell(oldbackclr, oldbackmode == wxBRUSHSTYLE_TRANSPARENT ? wxHTML_CLR_TRANSPARENT_BACKGROUND : wxHTML_CLR_BACKGROUND));
}
return true;
}

View File

@@ -214,6 +214,11 @@ void wxHtmlWinParser::InitParser(const wxString& source)
m_Link = wxHtmlLinkInfo( wxEmptyString );
m_LinkColor.Set(0, 0, 0xFF);
m_ActualColor.Set(0, 0, 0);
const wxColour windowColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ;
m_ActualBackgroundColor = m_windowInterface
? m_windowInterface->GetHTMLBackgroundColour()
: windowColour;
m_ActualBackgroundMode = wxBRUSHSTYLE_TRANSPARENT;
m_Align = wxHTML_ALIGN_LEFT;
m_ScriptMode = wxHTML_SCRIPT_NORMAL;
m_ScriptBaseline = 0;
@@ -238,16 +243,13 @@ void wxHtmlWinParser::InitParser(const wxString& source)
#endif
m_Container->InsertCell(new wxHtmlColourCell(m_ActualColor));
wxColour windowColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ;
m_Container->InsertCell
(
new wxHtmlColourCell
(
m_windowInterface
? m_windowInterface->GetHTMLBackgroundColour()
: windowColour,
wxHTML_CLR_BACKGROUND
m_ActualBackgroundColor,
m_ActualBackgroundMode == wxBRUSHSTYLE_TRANSPARENT ? wxHTML_CLR_TRANSPARENT_BACKGROUND : wxHTML_CLR_BACKGROUND
)
);