From: Vadim Zeitlin Date: Sun, 30 Sep 2012 22:20:58 +0000 (+0000) Subject: Add support for background-color style to span element in wxHTML. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/f5413b878c19eafae19edb48455d0d79b37b0ffc 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 --- diff --git a/docs/changes.txt b/docs/changes.txt index c2ed7071b7..5db8756baa 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -557,6 +557,7 @@ All (GUI): - Fix text origin and extent computations in wxSVGFileDC (Neil Chittenden). - Show tooltips for the too long items in generic wxTreeCtrl (Steven Houchins). - Add wxStyledTextCtrl::AnnotationClearLine() (sentieshar). +- Add support for background-color style to span element in wxHTML (gevorg). - Add "inherit" to XRC tag (Steffen Olszewski, Gero Meßsysteme GmbH). wxGTK: diff --git a/include/wx/html/htmlcell.h b/include/wx/html/htmlcell.h index a474030726..328aefce8a 100644 --- a/include/wx/html/htmlcell.h +++ b/include/wx/html/htmlcell.h @@ -91,10 +91,13 @@ public: const wxColour& GetFgColour() const { return m_fgColour; } void SetBgColour(const wxColour& c) { m_bgColour = c; } const wxColour& GetBgColour() const { return m_bgColour; } + void SetBgMode(int m) { m_bgMode = m; } + int GetBgMode() const { return m_bgMode; } private: wxHtmlSelectionState m_selState; wxColour m_fgColour, m_bgColour; + int m_bgMode; }; diff --git a/include/wx/html/htmldefs.h b/include/wx/html/htmldefs.h index 4b9d54e9ec..ec7348f85a 100644 --- a/include/wx/html/htmldefs.h +++ b/include/wx/html/htmldefs.h @@ -36,8 +36,9 @@ // Used by wxHtmlColourCell to determine clr of what is changing //-------------------------------------------------------------------------------- -#define wxHTML_CLR_FOREGROUND 0x0001 -#define wxHTML_CLR_BACKGROUND 0x0002 +#define wxHTML_CLR_FOREGROUND 0x0001 +#define wxHTML_CLR_BACKGROUND 0x0002 +#define wxHTML_CLR_TRANSPARENT_BACKGROUND 0x0004 diff --git a/include/wx/html/winpars.h b/include/wx/html/winpars.h index 1e268512a1..bdb16749cf 100644 --- a/include/wx/html/winpars.h +++ b/include/wx/html/winpars.h @@ -132,6 +132,10 @@ public: void SetLinkColor(const wxColour& clr) { m_LinkColor = clr; } const wxColour& GetActualColor() const { return m_ActualColor; } 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; } void SetLink(const wxHtmlLinkInfo& link); @@ -193,6 +197,8 @@ private: int m_FontSize; // From 1 (smallest) to 7, default is 3. wxColour m_LinkColor; wxColour m_ActualColor; + wxColour m_ActualBackgroundColor; + int m_ActualBackgroundMode; // basic font parameters. wxHtmlLinkInfo m_Link; // actual hypertext link or empty string diff --git a/samples/html/test/test.htm b/samples/html/test/test.htm index 64cc34ac20..135c7abbbd 100644 --- a/samples/html/test/test.htm +++ b/samples/html/test/test.htm @@ -10,7 +10,7 @@
- Header using styles + Header using styles diff --git a/src/html/htmlcell.cpp b/src/html/htmlcell.cpp index d0f433f17b..9966a16c09 100644 --- a/src/html/htmlcell.cpp +++ b/src/html/htmlcell.cpp @@ -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); } } diff --git a/src/html/m_span.cpp b/src/html/m_span.cpp index 025593e19e..50660bd4f1 100644 --- a/src/html/m_span.cpp +++ b/src/html/m_span.cpp @@ -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; } diff --git a/src/html/winpars.cpp b/src/html/winpars.cpp index d7047133c3..adb15c8328 100644 --- a/src/html/winpars.cpp +++ b/src/html/winpars.cpp @@ -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 ) );