// 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
/////////////////////////////////////////////////////////////////////////////
#ifndef WX_PRECOMP
#include "wx/wxcrtvararg.h"
+ #include "wx/brush.h"
#endif
#include "wx/html/forcelnk.h"
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
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))
// 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;
}
/* 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;
}
}
}
//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);
}
// 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"))
}
// 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);
}
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;
// 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);
}
}
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);
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
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();
new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
}
- ParseInner(tag);
+ wxColour bgCol;
+ if ( !tag.GetParamAsColour(wxT("BGCOLOR"), &bgCol) )
+ bgCol = m_Table->GetRowDefaultBackgroundColour();
+
+ CallParseInnerWithBg(tag, bgCol);
if ( isHeader )
{