]> git.saurik.com Git - wxWidgets.git/commitdiff
Add support for background-color style to span element in wxHTML.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 30 Sep 2012 22:20:58 +0000 (22:20 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 30 Sep 2012 22:20:58 +0000 (22:20 +0000)
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

docs/changes.txt
include/wx/html/htmlcell.h
include/wx/html/htmldefs.h
include/wx/html/winpars.h
samples/html/test/test.htm
src/html/htmlcell.cpp
src/html/m_span.cpp
src/html/winpars.cpp

index c2ed7071b705ce63f357938611f9391305be915c..5db8756baa0ce4da7477f46fdd3351e9709c783e 100644 (file)
@@ -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 <font> XRC tag (Steffen Olszewski, Gero Meßsysteme GmbH).
 
 wxGTK:
index a474030726a0ad1b3fbf12d525db1d0e1ff93342..328aefce8a4b79adb16c0c6f97c9b501c00c41dd 100644 (file)
@@ -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;
 };
 
 
index 4b9d54e9ec1c2c0b8de05ab14bb8790b98714f67..ec7348f85af48e080c0b023239b1789972804b9e 100644 (file)
@@ -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
 
 
 
index 1e268512a1d3a99ccb30f9a77ab3ec33f7e9f3bb..bdb16749cf4d597bc8ae885eb7d1acebc8dc9bbe 100644 (file)
@@ -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
index 64cc34ac20d8d009571756cfd23955ee2922d22f..135c7abbbd66628ffe3bc10b98219ffd744074df 100644 (file)
@@ -10,7 +10,7 @@
   <table border="0" cellspacing="0" cellpadding="5" style="width:100%; background:#C0C0C0;">
    <tr style="vertical-align:middle">
     <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 style="text-align:right">
index d0f433f17b421bc261681ecdeae21ae0563b8974..9966a16c091560b0f8bb334b79cea1c6414a65ea 100644 (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);
     }
 }
 
index 025593e19e559fe80cab896d5c2d268a60efa07e..50660bd4f18e63eb42da6c7c80cab5497ea9aef3 100644 (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;
     }
 
index d7047133c397e91a6538c05d4625e4209bb6693a..adb15c8328cdaae36f47b37ece69b39da07944f8 100644 (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
                        )
                   );