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

@@ -557,6 +557,7 @@ All (GUI):
- Fix text origin and extent computations in wxSVGFileDC (Neil Chittenden). - Fix text origin and extent computations in wxSVGFileDC (Neil Chittenden).
- Show tooltips for the too long items in generic wxTreeCtrl (Steven Houchins). - Show tooltips for the too long items in generic wxTreeCtrl (Steven Houchins).
- Add wxStyledTextCtrl::AnnotationClearLine() (sentieshar). - Add wxStyledTextCtrl::AnnotationClearLine() (sentieshar).
- Add support for background-color style to span element in wxHTML (gevorg).
- Add "inherit" to <font> XRC tag (Steffen Olszewski, Gero Meßsysteme GmbH). - Add "inherit" to <font> XRC tag (Steffen Olszewski, Gero Meßsysteme GmbH).
wxGTK: wxGTK:

View File

@@ -91,10 +91,13 @@ public:
const wxColour& GetFgColour() const { return m_fgColour; } const wxColour& GetFgColour() const { return m_fgColour; }
void SetBgColour(const wxColour& c) { m_bgColour = c; } void SetBgColour(const wxColour& c) { m_bgColour = c; }
const wxColour& GetBgColour() const { return m_bgColour; } const wxColour& GetBgColour() const { return m_bgColour; }
void SetBgMode(int m) { m_bgMode = m; }
int GetBgMode() const { return m_bgMode; }
private: private:
wxHtmlSelectionState m_selState; wxHtmlSelectionState m_selState;
wxColour m_fgColour, m_bgColour; wxColour m_fgColour, m_bgColour;
int m_bgMode;
}; };

View File

@@ -38,6 +38,7 @@
#define wxHTML_CLR_FOREGROUND 0x0001 #define wxHTML_CLR_FOREGROUND 0x0001
#define wxHTML_CLR_BACKGROUND 0x0002 #define wxHTML_CLR_BACKGROUND 0x0002
#define wxHTML_CLR_TRANSPARENT_BACKGROUND 0x0004

View File

@@ -132,6 +132,10 @@ public:
void SetLinkColor(const wxColour& clr) { m_LinkColor = clr; } void SetLinkColor(const wxColour& clr) { m_LinkColor = clr; }
const wxColour& GetActualColor() const { return m_ActualColor; } const wxColour& GetActualColor() const { return m_ActualColor; }
void SetActualColor(const wxColour& clr) { m_ActualColor = clr ;} void SetActualColor(const wxColour& clr) { m_ActualColor = clr ;}
const wxColour& GetActualBackgroundColor() const { return m_ActualBackgroundColor; }
void SetActualBackgroundColor(const wxColour& clr) { m_ActualBackgroundColor = clr;}
int GetActualBackgroundMode() const { return m_ActualBackgroundMode; }
void SetActualBackgroundMode(int mode) { m_ActualBackgroundMode = mode;}
const wxHtmlLinkInfo& GetLink() const { return m_Link; } const wxHtmlLinkInfo& GetLink() const { return m_Link; }
void SetLink(const wxHtmlLinkInfo& link); void SetLink(const wxHtmlLinkInfo& link);
@@ -193,6 +197,8 @@ private:
int m_FontSize; // From 1 (smallest) to 7, default is 3. int m_FontSize; // From 1 (smallest) to 7, default is 3.
wxColour m_LinkColor; wxColour m_LinkColor;
wxColour m_ActualColor; wxColour m_ActualColor;
wxColour m_ActualBackgroundColor;
int m_ActualBackgroundMode;
// basic font parameters. // basic font parameters.
wxHtmlLinkInfo m_Link; wxHtmlLinkInfo m_Link;
// actual hypertext link or empty string // actual hypertext link or empty string

View File

@@ -10,7 +10,7 @@
<table border="0" cellspacing="0" cellpadding="5" style="width:100%; background:#C0C0C0;"> <table border="0" cellspacing="0" cellpadding="5" style="width:100%; background:#C0C0C0;">
<tr style="vertical-align:middle"> <tr style="vertical-align:middle">
<td style="text-align:left"> <td style="text-align:left">
<span style="font-size: 24pt; font-weight: bold;">Header using styles</span> <span style="font-size: 24pt; font-weight: bold; background-color: #00BF00;">Header using styles</span>
</td> </td>
<td style="text-align:right"> <td style="text-align:right">

View File

@@ -504,10 +504,12 @@ static void SwitchSelState(wxDC& dc, wxHtmlRenderingInfo& info,
} }
else else
{ {
dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); const int mode = info.GetState().GetBgMode();
dc.SetBackgroundMode(mode);
dc.SetTextForeground(fg); dc.SetTextForeground(fg);
dc.SetTextBackground(bg); 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(); wxHtmlSelectionState selstate = info.GetState().GetSelectionState();
// Not changing selection state, draw the word in single mode: // Not changing selection state, draw the word in single mode:
if ( selstate != wxHTML_SEL_OUT && SwitchSelState(dc, info, 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);
}
dc.DrawText(m_Word, x + m_PosX, y + m_PosY); dc.DrawText(m_Word, x + m_PosX, y + m_PosY);
drawSelectionAfterCell = (selstate != wxHTML_SEL_OUT); drawSelectionAfterCell = (selstate != wxHTML_SEL_OUT);
} }
@@ -1552,17 +1545,23 @@ void wxHtmlColourCell::DrawInvisible(wxDC& dc,
if (m_Flags & wxHTML_CLR_BACKGROUND) if (m_Flags & wxHTML_CLR_BACKGROUND)
{ {
state.SetBgColour(m_Colour); state.SetBgColour(m_Colour);
if (state.GetSelectionState() != wxHTML_SEL_IN) state.SetBgMode(wxSOLID);
{ const wxColour c = state.GetSelectionState() == wxHTML_SEL_IN
dc.SetTextBackground(m_Colour); ? info.GetStyle().GetSelectedTextBgColour(m_Colour)
dc.SetBackground(wxBrush(m_Colour, wxBRUSHSTYLE_SOLID)); : m_Colour;
}
else
{
wxColour c = info.GetStyle().GetSelectedTextBgColour(m_Colour);
dc.SetTextBackground(c); dc.SetTextBackground(c);
dc.SetBackground(wxBrush(c, wxBRUSHSTYLE_SOLID)); 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) TAG_HANDLER_PROC(tag)
{ {
wxColour oldclr = m_WParser->GetActualColor(); wxColour oldclr = m_WParser->GetActualColor();
wxColour oldbackclr = m_WParser->GetActualBackgroundColor();
int oldbackmode = m_WParser->GetActualBackgroundMode();
int oldsize = m_WParser->GetFontSize(); int oldsize = m_WParser->GetFontSize();
int oldbold = m_WParser->GetFontBold(); int oldbold = m_WParser->GetFontBold();
int olditalic = m_WParser->GetFontItalic(); 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")); str = styleParams.GetParam(wxS("font-size"));
if ( !str.empty() ) if ( !str.empty() )
{ {
@@ -151,6 +165,15 @@ TAG_HANDLER_BEGIN(SPAN, "SPAN" )
new wxHtmlColourCell(oldclr)); 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; return true;
} }

View File

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