]> git.saurik.com Git - wxWidgets.git/blobdiff - src/html/m_tables.cpp
Fix wrong references to wxImageList description in XRC format docs.
[wxWidgets.git] / src / html / m_tables.cpp
index 7bca5a4c3feed94d941de7c45e252715053f6658..25f3f96b7c7982fdab178d1822550250b6336d50 100644 (file)
@@ -2,7 +2,6 @@
 // Name:        src/html/m_tables.cpp
 // Purpose:     wxHtml module for tables
 // Author:      Vaclav Slavik
-// RCS-ID:      $Id$
 // Copyright:   (c) 1999 Vaclav Slavik
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
@@ -17,6 +16,7 @@
 
 #ifndef WX_PRECOMP
     #include "wx/wxcrtvararg.h"
+    #include "wx/brush.h"
 #endif
 
 #include "wx/html/forcelnk.h"
@@ -106,6 +106,8 @@ public:
     void AddRow(const wxHtmlTag& tag);
     void AddCell(wxHtmlContainerCell *cell, const wxHtmlTag& tag);
 
+    const wxColour& GetRowDefaultBackgroundColour() const { return m_rBkg; }
+
 private:
     // Reallocates memory to given number of cols/rows
     // and changes m_NumCols/m_NumRows value to reflect this change
@@ -132,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())
-            SetBackgroundColour(m_tBkg);
-    }
-    if (tag.HasParam(wxT("VALIGN")))
-        m_tValign = tag.GetParam(wxT("VALIGN"));
-    else
-        m_tValign = wxEmptyString;
+    if (tag.GetParamAsColour(wxT("BGCOLOR"), &m_tBkg))
+        SetBackgroundColour(m_tBkg);
+    m_tValign = tag.GetParam(wxT("VALIGN"));
     if (!tag.GetParamAsInt(wxT("CELLSPACING"), &m_Spacing))
         m_Spacing = 2;
     if (!tag.GetParamAsInt(wxT("CELLPADDING"), &m_Padding))
@@ -240,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
+    tag.GetParamAsColour(wxT("BGCOLOR"), &m_rBkg);
+    if (!tag.GetParamAsString(wxT("VALIGN"), &m_rValign))
         m_rValign = m_tValign;
 }
 
@@ -282,27 +274,28 @@ void wxHtmlTableCell::AddCell(wxHtmlContainerCell *cell, const wxHtmlTag& tag)
 
     /* scan for parameters: */
 
+    // id:
+    wxString idvalue;
+    if (tag.GetParamAsString(wxT("ID"), &idvalue))
+    {
+        cell->SetId(idvalue);
+    }
+
     // 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[wd.length()-1] == wxT('%'))
+            if (wpercent)
             {
-                if ( wxSscanf(wd.c_str(), wxT("%i%%"), &m_ColsInfo[c].width) == 1 )
-                {
-                    m_ColsInfo[c].units = wxHTML_UNITS_PERCENT;
-                }
+                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;
-                }
+                m_ColsInfo[c].width = (int)(m_PixelScale * (double)width);
+                m_ColsInfo[c].units = wxHTML_UNITS_PIXELS;
             }
         }
     }
@@ -342,8 +335,7 @@ void wxHtmlTableCell::AddCell(wxHtmlContainerCell *cell, const wxHtmlTag& tag)
     //background color:
     {
         wxColour bk = m_rBkg;
-        if (tag.HasParam(wxT("BGCOLOR")))
-            tag.GetParamAsColour(wxT("BGCOLOR"), &bk);
+        tag.GetParamAsColour(wxT("BGCOLOR"), &bk);
         if (bk.IsOk())
             cell->SetBackgroundColour(bk);
     }
@@ -353,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"))
@@ -366,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);
 }
@@ -676,6 +663,37 @@ TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH")
         wxString m_tAlign, m_rAlign;
         wxHtmlContainerCell *m_enclosingContainer;
 
+        // Call ParseInner() preserving background colour and mode after any
+        // changes done by it.
+        void CallParseInnerWithBg(const wxHtmlTag& tag, const wxColour& colBg)
+        {
+            const wxColour oldbackclr = m_WParser->GetActualBackgroundColor();
+            const int oldbackmode = m_WParser->GetActualBackgroundMode();
+            if ( colBg.IsOk() )
+            {
+                m_WParser->SetActualBackgroundColor(colBg);
+                m_WParser->SetActualBackgroundMode(wxBRUSHSTYLE_SOLID);
+                m_WParser->GetContainer()->InsertCell(
+                        new wxHtmlColourCell(colBg, wxHTML_CLR_BACKGROUND)
+                    );
+            }
+
+            ParseInner(tag);
+
+            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)
+                );
+            }
+        }
+
     TAG_HANDLER_CONSTR(TABLE)
     {
         m_Table = NULL;
@@ -700,20 +718,16 @@ TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH")
 
             // 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[wd.length()-1] == wxT('%'))
+                    if (wpercent)
                     {
-                        int width = 0;
-                        wxSscanf(wd.c_str(), wxT("%i%%"), &width);
                         m_Table->SetWidthFloat(width, wxHTML_UNITS_PERCENT);
                     }
                     else
                     {
-                        int width = 0;
-                        wxSscanf(wd.c_str(), wxT("%i"), &width);
                         m_Table->SetWidthFloat((int)(m_WParser->GetPixelScale() * width), wxHTML_UNITS_PIXELS);
                     }
                 }
@@ -721,11 +735,10 @@ TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH")
                     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();
 
-            ParseInner(tag);
+            CallParseInnerWithBg(tag, m_Table->GetBackgroundColour());
 
             m_WParser->SetAlign(oldAlign);
             m_WParser->SetContainer(m_enclosingContainer);
@@ -744,9 +757,8 @@ TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH")
             if (tag.GetName() == wxT("TR"))
             {
                 m_Table->AddRow(tag);
-                m_rAlign = m_tAlign;
-                if (tag.HasParam(wxT("ALIGN")))
-                    m_rAlign = tag.GetParam(wxT("ALIGN"));
+                if (!tag.GetParamAsString(wxT("ALIGN"), &m_rAlign))
+                    m_rAlign = m_tAlign;
             }
 
             // new cell
@@ -760,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();
 
@@ -788,7 +798,11 @@ TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH")
                         new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
                 }
 
-                ParseInner(tag);
+                wxColour bgCol;
+                if ( !tag.GetParamAsColour(wxT("BGCOLOR"), &bgCol) )
+                    bgCol = m_Table->GetRowDefaultBackgroundColour();
+
+                CallParseInnerWithBg(tag, bgCol);
 
                 if ( isHeader )
                 {