add support for table border width attribute (closes #10610)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60363 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -323,6 +323,10 @@ Major new features in this release
|
|||||||
2.9.1:
|
2.9.1:
|
||||||
------
|
------
|
||||||
|
|
||||||
|
All:
|
||||||
|
|
||||||
|
- wxHTML: add support for table borders width (Laurent Humbertclaude).
|
||||||
|
|
||||||
i18n:
|
i18n:
|
||||||
|
|
||||||
- Korean translations added (Sungkee Jung).
|
- Korean translations added (Sungkee Jung).
|
||||||
|
@@ -470,7 +470,7 @@ public:
|
|||||||
// returns background colour (of wxNullColour if none set), so that widgets can
|
// returns background colour (of wxNullColour if none set), so that widgets can
|
||||||
// adapt to it:
|
// adapt to it:
|
||||||
wxColour GetBackgroundColour();
|
wxColour GetBackgroundColour();
|
||||||
void SetBorder(const wxColour& clr1, const wxColour& clr2) {m_UseBorder = true; m_BorderColour1 = clr1, m_BorderColour2 = clr2;}
|
void SetBorder(const wxColour& clr1, const wxColour& clr2, int border = 1) {m_Border = border; m_BorderColour1 = clr1, m_BorderColour2 = clr2;}
|
||||||
virtual wxHtmlLinkInfo* GetLink(int x = 0, int y = 0) const;
|
virtual wxHtmlLinkInfo* GetLink(int x = 0, int y = 0) const;
|
||||||
virtual const wxHtmlCell* Find(int condition, const void* param) const;
|
virtual const wxHtmlCell* Find(int condition, const void* param) const;
|
||||||
|
|
||||||
@@ -529,7 +529,8 @@ protected:
|
|||||||
bool m_UseBkColour;
|
bool m_UseBkColour;
|
||||||
wxColour m_BkColour;
|
wxColour m_BkColour;
|
||||||
// background color of this container
|
// background color of this container
|
||||||
bool m_UseBorder;
|
int m_Border;
|
||||||
|
// border size. Draw only if m_Border > 0
|
||||||
wxColour m_BorderColour1, m_BorderColour2;
|
wxColour m_BorderColour1, m_BorderColour2;
|
||||||
// borders color of this container
|
// borders color of this container
|
||||||
int m_LastLayout;
|
int m_LastLayout;
|
||||||
|
@@ -413,8 +413,10 @@ public:
|
|||||||
Colour of top and left lines
|
Colour of top and left lines
|
||||||
@param clr2
|
@param clr2
|
||||||
Colour of bottom and right lines
|
Colour of bottom and right lines
|
||||||
|
@param border
|
||||||
|
Size of the border in pixels
|
||||||
*/
|
*/
|
||||||
void SetBorder(const wxColour& clr1, const wxColour& clr2);
|
void SetBorder(const wxColour& clr1, const wxColour& clr2, int border = 1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Sets the indentation (free space between borders of container and subcells).
|
Sets the indentation (free space between borders of container and subcells).
|
||||||
|
@@ -193,3 +193,63 @@ kjhkj hkj hkj lkh kjh kjlh kj</TD>
|
|||||||
<td>Really, a test!</td>
|
<td>Really, a test!</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
<TABLE BORDER="50">
|
||||||
|
<TR>
|
||||||
|
<TD>1</TD>
|
||||||
|
<TD>2</TD>
|
||||||
|
</TR>
|
||||||
|
<TR>
|
||||||
|
<TD>3</TD>
|
||||||
|
<TD>4</TD>
|
||||||
|
</TR>
|
||||||
|
</TABLE>
|
||||||
|
|
||||||
|
<TABLE BORDER="50" width="50%">
|
||||||
|
<TR>
|
||||||
|
<TD>50%</TD>
|
||||||
|
<TD>2</TD>
|
||||||
|
</TR>
|
||||||
|
<TR>
|
||||||
|
<TD>3</TD>
|
||||||
|
<TD>4</TD>
|
||||||
|
</TR>
|
||||||
|
</TABLE>
|
||||||
|
|
||||||
|
<TABLE BORDER="50" width="100%">
|
||||||
|
<TR>
|
||||||
|
<TD>100%</TD>
|
||||||
|
<TD>2</TD>
|
||||||
|
</TR>
|
||||||
|
<TR>
|
||||||
|
<TD>3</TD>
|
||||||
|
<TD>4</TD>
|
||||||
|
</TR>
|
||||||
|
</TABLE>
|
||||||
|
|
||||||
|
|
||||||
|
<TABLE BORDER="50" width="5%">
|
||||||
|
<TR>
|
||||||
|
<TD>5%</TD>
|
||||||
|
<TD>2</TD>
|
||||||
|
</TR>
|
||||||
|
<TR>
|
||||||
|
<TD>3</TD>
|
||||||
|
<TD>4</TD>
|
||||||
|
</TR>
|
||||||
|
</TABLE>
|
||||||
|
|
||||||
|
<TABLE BORDER="50" width="300">
|
||||||
|
<TR>
|
||||||
|
<TD>300pix</TD>
|
||||||
|
<TD>2</TD>
|
||||||
|
</TR>
|
||||||
|
<TR>
|
||||||
|
<TD>3</TD>
|
||||||
|
<TD>4</TD>
|
||||||
|
</TR>
|
||||||
|
</TABLE><TABLE BORDER="1" width="300">
|
||||||
|
<TR>
|
||||||
|
<TD>300pix</TD>
|
||||||
|
<TD>2</TD>
|
||||||
|
</TR>
|
||||||
|
</TABLE>
|
||||||
|
@@ -735,7 +735,7 @@ wxHtmlContainerCell::wxHtmlContainerCell(wxHtmlContainerCell *parent) : wxHtmlCe
|
|||||||
m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0;
|
m_IndentLeft = m_IndentRight = m_IndentTop = m_IndentBottom = 0;
|
||||||
m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT;
|
m_WidthFloat = 100; m_WidthFloatUnits = wxHTML_UNITS_PERCENT;
|
||||||
m_UseBkColour = false;
|
m_UseBkColour = false;
|
||||||
m_UseBorder = false;
|
m_Border = 0;
|
||||||
m_MinHeight = 0;
|
m_MinHeight = 0;
|
||||||
m_MinHeightAlign = wxHTML_ALIGN_TOP;
|
m_MinHeightAlign = wxHTML_ALIGN_TOP;
|
||||||
m_LastLayout = -1;
|
m_LastLayout = -1;
|
||||||
@@ -1124,8 +1124,9 @@ void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
|
|||||||
dc.DrawRectangle(xlocal, real_y1, m_Width, real_y2 - real_y1 + 1);
|
dc.DrawRectangle(xlocal, real_y1, m_Width, real_y2 - real_y1 + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_UseBorder)
|
if (m_Border == 1)
|
||||||
{
|
{
|
||||||
|
// draw thin border using lines
|
||||||
wxPen mypen1(m_BorderColour1, 1, wxPENSTYLE_SOLID);
|
wxPen mypen1(m_BorderColour1, 1, wxPENSTYLE_SOLID);
|
||||||
wxPen mypen2(m_BorderColour2, 1, wxPENSTYLE_SOLID);
|
wxPen mypen2(m_BorderColour2, 1, wxPENSTYLE_SOLID);
|
||||||
|
|
||||||
@@ -1136,7 +1137,56 @@ void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
|
|||||||
dc.DrawLine(xlocal + m_Width - 1, ylocal, xlocal + m_Width - 1, ylocal + m_Height - 1);
|
dc.DrawLine(xlocal + m_Width - 1, ylocal, xlocal + m_Width - 1, ylocal + m_Height - 1);
|
||||||
dc.DrawLine(xlocal, ylocal + m_Height - 1, xlocal + m_Width, ylocal + m_Height - 1);
|
dc.DrawLine(xlocal, ylocal + m_Height - 1, xlocal + m_Width, ylocal + m_Height - 1);
|
||||||
}
|
}
|
||||||
|
else if (m_Border> 0)
|
||||||
|
{
|
||||||
|
wxBrush mybrush1(m_BorderColour1, wxBRUSHSTYLE_SOLID);
|
||||||
|
wxBrush mybrush2(m_BorderColour2, wxBRUSHSTYLE_SOLID);
|
||||||
|
|
||||||
|
// draw upper left corner
|
||||||
|
// 0---------------5
|
||||||
|
// | /
|
||||||
|
// | 3-----------4
|
||||||
|
// | |
|
||||||
|
// | 2
|
||||||
|
// |/
|
||||||
|
// 1
|
||||||
|
|
||||||
|
wxPoint poly[6];
|
||||||
|
poly[0].x =m_PosX; poly[0].y = m_PosY ;
|
||||||
|
poly[1].x =m_PosX; poly[1].y = m_PosY + m_Height;
|
||||||
|
poly[2].x =m_PosX + m_Border; poly[2].y = poly[1].y - m_Border;
|
||||||
|
poly[3].x =poly[2].x ; poly[3].y = m_PosY + m_Border;
|
||||||
|
poly[4].x =m_PosX + m_Width - m_Border; poly[4].y = poly[3].y;
|
||||||
|
poly[5].x =m_PosX + m_Width; poly[5].y = m_PosY;
|
||||||
|
|
||||||
|
dc.SetBrush(mybrush1);
|
||||||
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||||
|
dc.DrawPolygon(6, poly, x, y);
|
||||||
|
|
||||||
|
// draw lower right corner reusing point 1,2,4 and 5
|
||||||
|
// 5
|
||||||
|
// /|
|
||||||
|
// 4 |
|
||||||
|
// | |
|
||||||
|
// 2-----------3 |
|
||||||
|
// / |
|
||||||
|
// 1---------------0
|
||||||
|
dc.SetBrush(mybrush2);
|
||||||
|
poly[0].x = poly[5].x; poly[0].y = poly[1].y;
|
||||||
|
poly[3].x = poly[4].x; poly[3].y = poly[2].y;
|
||||||
|
dc.DrawPolygon(6, poly, x, y);
|
||||||
|
|
||||||
|
// smooth color transition like firefox
|
||||||
|
wxColour borderMediumColour(
|
||||||
|
(m_BorderColour1.Red() + m_BorderColour2.Red()) /2 ,
|
||||||
|
(m_BorderColour1.Green() + m_BorderColour2.Green()) /2 ,
|
||||||
|
(m_BorderColour1.Blue() + m_BorderColour2.Blue()) /2
|
||||||
|
);
|
||||||
|
wxPen mypen3(borderMediumColour, 1, wxPENSTYLE_SOLID);
|
||||||
|
dc.SetPen(mypen3);
|
||||||
|
dc.DrawLines(2, &poly[1], x, y - 1); // between 1 and 2
|
||||||
|
dc.DrawLines(2, &poly[4], x, y - 1); // between 4 and 5
|
||||||
|
}
|
||||||
if (m_Cells)
|
if (m_Cells)
|
||||||
{
|
{
|
||||||
// draw container's contents:
|
// draw container's contents:
|
||||||
|
@@ -71,8 +71,6 @@ class wxHtmlTableCell : public wxHtmlContainerCell
|
|||||||
protected:
|
protected:
|
||||||
/* These are real attributes: */
|
/* These are real attributes: */
|
||||||
|
|
||||||
// should we draw borders or not?
|
|
||||||
bool m_HasBorders;
|
|
||||||
// number of columns; rows
|
// number of columns; rows
|
||||||
int m_NumCols, m_NumRows;
|
int m_NumCols, m_NumRows;
|
||||||
// array of column information
|
// array of column information
|
||||||
@@ -128,8 +126,6 @@ wxHtmlTableCell::wxHtmlTableCell(wxHtmlContainerCell *parent, const wxHtmlTag& t
|
|||||||
: wxHtmlContainerCell(parent)
|
: wxHtmlContainerCell(parent)
|
||||||
{
|
{
|
||||||
m_PixelScale = pixel_scale;
|
m_PixelScale = pixel_scale;
|
||||||
m_HasBorders =
|
|
||||||
(tag.HasParam(wxT("BORDER")) && tag.GetParam(wxT("BORDER")) != wxT("0"));
|
|
||||||
m_ColsInfo = NULL;
|
m_ColsInfo = NULL;
|
||||||
m_NumCols = m_NumRows = 0;
|
m_NumCols = m_NumRows = 0;
|
||||||
m_CellInfo = NULL;
|
m_CellInfo = NULL;
|
||||||
@@ -153,8 +149,20 @@ wxHtmlTableCell::wxHtmlTableCell(wxHtmlContainerCell *parent, const wxHtmlTag& t
|
|||||||
m_Spacing = (int)(m_PixelScale * (double)m_Spacing);
|
m_Spacing = (int)(m_PixelScale * (double)m_Spacing);
|
||||||
m_Padding = (int)(m_PixelScale * (double)m_Padding);
|
m_Padding = (int)(m_PixelScale * (double)m_Padding);
|
||||||
|
|
||||||
if (m_HasBorders)
|
if(tag.HasParam(wxT("BORDER")))
|
||||||
SetBorder(TABLE_BORDER_CLR_1, TABLE_BORDER_CLR_2);
|
{
|
||||||
|
if(tag.GetParam("BORDER").IsEmpty())
|
||||||
|
m_Border = 1;
|
||||||
|
else
|
||||||
|
tag.GetParamAsInt(wxT("BORDER"), &m_Border);
|
||||||
|
}
|
||||||
|
if (m_Border == 1)
|
||||||
|
SetBorder(TABLE_BORDER_CLR_1, TABLE_BORDER_CLR_2, m_Border); // special case see wxHtmlContainerCell::Draw
|
||||||
|
else if (m_Border> 0)
|
||||||
|
SetBorder(TABLE_BORDER_CLR_1, TABLE_BORDER_CLR_2, (int)(m_PixelScale * (double)m_Border));
|
||||||
|
else
|
||||||
|
m_Border = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -339,7 +347,7 @@ void wxHtmlTableCell::AddCell(wxHtmlContainerCell *cell, const wxHtmlTag& tag)
|
|||||||
if (bk.Ok())
|
if (bk.Ok())
|
||||||
cell->SetBackgroundColour(bk);
|
cell->SetBackgroundColour(bk);
|
||||||
}
|
}
|
||||||
if (m_HasBorders)
|
if (m_Border > 0)
|
||||||
cell->SetBorder(TABLE_BORDER_CLR_2, TABLE_BORDER_CLR_1);
|
cell->SetBorder(TABLE_BORDER_CLR_2, TABLE_BORDER_CLR_1);
|
||||||
|
|
||||||
// vertical alignment:
|
// vertical alignment:
|
||||||
@@ -413,7 +421,7 @@ void wxHtmlTableCell::ComputeMinMaxWidths()
|
|||||||
else
|
else
|
||||||
m_MaxTotalWidth = m_MaxTotalWidth * 100 / (100 - percentage);
|
m_MaxTotalWidth = m_MaxTotalWidth * 100 / (100 - percentage);
|
||||||
|
|
||||||
m_MaxTotalWidth += (m_NumCols + 1) * m_Spacing;
|
m_MaxTotalWidth += (m_NumCols + 1) * m_Spacing + 2 * m_Border;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxHtmlTableCell::Layout(int w)
|
void wxHtmlTableCell::Layout(int w)
|
||||||
@@ -461,7 +469,7 @@ void wxHtmlTableCell::Layout(int w)
|
|||||||
The algorithm tries to keep the table size less than w if possible.
|
The algorithm tries to keep the table size less than w if possible.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
int wpix = m_Width - (m_NumCols + 1) * m_Spacing;
|
int wpix = m_Width - (m_NumCols + 1) * m_Spacing - 2 * m_Border; // Available space for cell content
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
// 1a. setup fixed-width columns:
|
// 1a. setup fixed-width columns:
|
||||||
@@ -500,7 +508,7 @@ void wxHtmlTableCell::Layout(int w)
|
|||||||
else
|
else
|
||||||
newWidth = newWidth * 100 / (100 - percentage);
|
newWidth = newWidth * 100 / (100 - percentage);
|
||||||
|
|
||||||
newWidth = wxMin(newWidth, w - (m_NumCols + 1) * m_Spacing);
|
newWidth = wxMin(newWidth, w - (m_NumCols + 1) * m_Spacing - 2 * m_Border);
|
||||||
wpix -= m_Width - newWidth;
|
wpix -= m_Width - newWidth;
|
||||||
m_Width = newWidth;
|
m_Width = newWidth;
|
||||||
}
|
}
|
||||||
@@ -514,7 +522,7 @@ void wxHtmlTableCell::Layout(int w)
|
|||||||
m_ColsInfo[i].pixwidth = wxMin(m_ColsInfo[i].width, 100) * wpix / 100;
|
m_ColsInfo[i].pixwidth = wxMin(m_ColsInfo[i].width, 100) * wpix / 100;
|
||||||
|
|
||||||
// Make sure to leave enough space for the other columns
|
// Make sure to leave enough space for the other columns
|
||||||
int minRequired = 0;
|
int minRequired = m_Border;
|
||||||
for (j = 0; j < m_NumCols; j++)
|
for (j = 0; j < m_NumCols; j++)
|
||||||
{
|
{
|
||||||
if ((m_ColsInfo[j].units == wxHTML_UNITS_PERCENT && j > i) ||
|
if ((m_ColsInfo[j].units == wxHTML_UNITS_PERCENT && j > i) ||
|
||||||
@@ -525,7 +533,7 @@ void wxHtmlTableCell::Layout(int w)
|
|||||||
|
|
||||||
wtemp -= m_ColsInfo[i].pixwidth;
|
wtemp -= m_ColsInfo[i].pixwidth;
|
||||||
}
|
}
|
||||||
wpix = wtemp;
|
wpix = wtemp; // minimum cells width
|
||||||
|
|
||||||
// 1d. setup default columns (no width specification supplied):
|
// 1d. setup default columns (no width specification supplied):
|
||||||
// The algorithm assigns calculates the maximum possible width if line
|
// The algorithm assigns calculates the maximum possible width if line
|
||||||
@@ -536,8 +544,8 @@ void wxHtmlTableCell::Layout(int w)
|
|||||||
|
|
||||||
for (i = j = 0; i < m_NumCols; i++)
|
for (i = j = 0; i < m_NumCols; i++)
|
||||||
if (m_ColsInfo[i].width == 0) j++;
|
if (m_ColsInfo[i].width == 0) j++;
|
||||||
if (wpix < 0)
|
if (wpix < m_Border)
|
||||||
wpix = 0;
|
wpix = m_Border;
|
||||||
|
|
||||||
// Assign widths
|
// Assign widths
|
||||||
for (i = 0; i < m_NumCols; i++)
|
for (i = 0; i < m_NumCols; i++)
|
||||||
@@ -575,7 +583,7 @@ void wxHtmlTableCell::Layout(int w)
|
|||||||
|
|
||||||
/* 2. compute positions of columns: */
|
/* 2. compute positions of columns: */
|
||||||
{
|
{
|
||||||
int wpos = m_Spacing;
|
int wpos = m_Spacing + m_Border;
|
||||||
for (int i = 0; i < m_NumCols; i++)
|
for (int i = 0; i < m_NumCols; i++)
|
||||||
{
|
{
|
||||||
m_ColsInfo[i].leftpos = wpos;
|
m_ColsInfo[i].leftpos = wpos;
|
||||||
@@ -583,8 +591,8 @@ void wxHtmlTableCell::Layout(int w)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add the remaining space to the last column
|
// add the remaining space to the last column
|
||||||
if (m_NumCols > 0 && wpos < m_Width)
|
if (m_NumCols > 0 && wpos < m_Width - m_Border)
|
||||||
m_ColsInfo[m_NumCols-1].pixwidth += m_Width - wpos;
|
m_ColsInfo[m_NumCols-1].pixwidth += m_Width - wpos - m_Border;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 3. sub-layout all cells: */
|
/* 3. sub-layout all cells: */
|
||||||
@@ -595,7 +603,7 @@ void wxHtmlTableCell::Layout(int w)
|
|||||||
int fullwid;
|
int fullwid;
|
||||||
wxHtmlContainerCell *actcell;
|
wxHtmlContainerCell *actcell;
|
||||||
|
|
||||||
ypos[0] = m_Spacing;
|
ypos[0] = m_Spacing + m_Border;
|
||||||
for (actrow = 1; actrow <= m_NumRows; actrow++) ypos[actrow] = -1;
|
for (actrow = 1; actrow <= m_NumRows; actrow++) ypos[actrow] = -1;
|
||||||
for (actrow = 0; actrow < m_NumRows; actrow++)
|
for (actrow = 0; actrow < m_NumRows; actrow++)
|
||||||
{
|
{
|
||||||
@@ -637,7 +645,7 @@ void wxHtmlTableCell::Layout(int w)
|
|||||||
actcell->SetPos(m_ColsInfo[actcol].leftpos, ypos[actrow]);
|
actcell->SetPos(m_ColsInfo[actcol].leftpos, ypos[actrow]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_Height = ypos[m_NumRows];
|
m_Height = ypos[m_NumRows] + m_Border;
|
||||||
delete[] ypos;
|
delete[] ypos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -645,7 +653,7 @@ void wxHtmlTableCell::Layout(int w)
|
|||||||
if (m_NumCols > 0)
|
if (m_NumCols > 0)
|
||||||
{
|
{
|
||||||
int twidth = m_ColsInfo[m_NumCols-1].leftpos +
|
int twidth = m_ColsInfo[m_NumCols-1].leftpos +
|
||||||
m_ColsInfo[m_NumCols-1].pixwidth + m_Spacing;
|
m_ColsInfo[m_NumCols-1].pixwidth + m_Spacing + m_Border;
|
||||||
if (twidth > m_Width)
|
if (twidth > m_Width)
|
||||||
m_Width = twidth;
|
m_Width = twidth;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user