1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/m_tables.cpp
3 // Purpose: wxHtml module for tables
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
15 #if wxUSE_HTML && wxUSE_STREAMS
18 #include "wx/wxcrtvararg.h"
22 #include "wx/html/forcelnk.h"
23 #include "wx/html/m_templ.h"
25 #include "wx/html/htmlcell.h"
27 FORCE_LINK_ME(m_tables
)
30 #define TABLE_BORDER_CLR_1 wxColour(0xC5, 0xC2, 0xC5)
31 #define TABLE_BORDER_CLR_2 wxColour(0x62, 0x61, 0x62)
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
42 // width of the column either in pixels or percents
43 // ('width' is the number, 'units' determines its meaning)
44 int minWidth
, maxWidth
;
45 // minimal/maximal column width. This is needed by HTML 4.0
46 // layout algorithm and can be determined by trying to
47 // layout table cells with width=1 and width=infinity
48 int leftpos
, pixwidth
, maxrealwidth
;
49 // temporary (depends on actual width of table)
61 wxHtmlContainerCell
*cont
;
63 int minheight
, valign
;
69 class wxHtmlTableCell
: public wxHtmlContainerCell
72 /* These are real attributes: */
74 // number of columns; rows
75 int m_NumCols
, m_NumRows
;
76 // array of column information
77 colStruct
*m_ColsInfo
;
78 // 2D array of all cells in the table : m_CellInfo[row][column]
79 cellStruct
**m_CellInfo
;
80 // spaces between cells
82 // cells internal indentation
86 /* ...and these are valid only when parsing the table: */
88 // number of actual column (ranging from 0..m_NumCols)
89 int m_ActualCol
, m_ActualRow
;
91 // default values (for table and row):
92 wxColour m_tBkg
, m_rBkg
;
93 wxString m_tValign
, m_rValign
;
99 wxHtmlTableCell(wxHtmlContainerCell
*parent
, const wxHtmlTag
& tag
, double pixel_scale
= 1.0);
100 virtual ~wxHtmlTableCell();
102 virtual void RemoveExtraSpacing(bool top
, bool bottom
);
104 virtual void Layout(int w
);
106 void AddRow(const wxHtmlTag
& tag
);
107 void AddCell(wxHtmlContainerCell
*cell
, const wxHtmlTag
& tag
);
109 const wxColour
& GetRowDefaultBackgroundColour() const { return m_rBkg
; }
112 // Reallocates memory to given number of cols/rows
113 // and changes m_NumCols/m_NumRows value to reflect this change
114 // NOTE! You CAN'T change m_NumCols/m_NumRows before calling this!!
115 void ReallocCols(int cols
);
116 void ReallocRows(int rows
);
118 // Computes minimal and maximal widths of columns. Needs to be called
119 // only once, before first Layout().
120 void ComputeMinMaxWidths();
122 wxDECLARE_NO_COPY_CLASS(wxHtmlTableCell
);
127 wxHtmlTableCell::wxHtmlTableCell(wxHtmlContainerCell
*parent
, const wxHtmlTag
& tag
, double pixel_scale
)
128 : wxHtmlContainerCell(parent
)
130 m_PixelScale
= pixel_scale
;
132 m_NumCols
= m_NumRows
= 0;
134 m_ActualCol
= m_ActualRow
= -1;
137 if (tag
.HasParam(wxT("BGCOLOR")))
139 tag
.GetParamAsColour(wxT("BGCOLOR"), &m_tBkg
);
141 SetBackgroundColour(m_tBkg
);
143 if (tag
.HasParam(wxT("VALIGN")))
144 m_tValign
= tag
.GetParam(wxT("VALIGN"));
146 m_tValign
= wxEmptyString
;
147 if (!tag
.GetParamAsInt(wxT("CELLSPACING"), &m_Spacing
))
149 if (!tag
.GetParamAsInt(wxT("CELLPADDING"), &m_Padding
))
151 m_Spacing
= (int)(m_PixelScale
* (double)m_Spacing
);
152 m_Padding
= (int)(m_PixelScale
* (double)m_Padding
);
154 if(tag
.HasParam(wxT("BORDER")))
156 if(tag
.GetParam("BORDER").IsEmpty())
159 tag
.GetParamAsInt(wxT("BORDER"), &m_Border
);
162 SetBorder(TABLE_BORDER_CLR_1
, TABLE_BORDER_CLR_2
, m_Border
); // special case see wxHtmlContainerCell::Draw
163 else if (m_Border
> 0)
164 SetBorder(TABLE_BORDER_CLR_1
, TABLE_BORDER_CLR_2
, (int)(m_PixelScale
* (double)m_Border
));
172 wxHtmlTableCell::~wxHtmlTableCell()
174 if (m_ColsInfo
) free(m_ColsInfo
);
177 for (int i
= 0; i
< m_NumRows
; i
++)
184 void wxHtmlTableCell::RemoveExtraSpacing(bool WXUNUSED(top
),
185 bool WXUNUSED(bottom
))
187 // Don't remove any spacing in the table -- it's always desirable,
188 // because it's part of table's definition.
189 // (If wxHtmlContainerCell::RemoveExtraSpacing() was applied to tables,
190 // then upper left cell of a table would be positioned above other cells
191 // if the table was the first element on the page.)
194 void wxHtmlTableCell::ReallocCols(int cols
)
198 for (i
= 0; i
< m_NumRows
; i
++)
200 m_CellInfo
[i
] = (cellStruct
*) realloc(m_CellInfo
[i
], sizeof(cellStruct
) * cols
);
201 for (j
= m_NumCols
; j
< cols
; j
++)
202 m_CellInfo
[i
][j
].flag
= cellFree
;
205 m_ColsInfo
= (colStruct
*) realloc(m_ColsInfo
, sizeof(colStruct
) * cols
);
206 for (j
= m_NumCols
; j
< cols
; j
++)
208 m_ColsInfo
[j
].width
= 0;
209 m_ColsInfo
[j
].units
= wxHTML_UNITS_PERCENT
;
210 m_ColsInfo
[j
].minWidth
= m_ColsInfo
[j
].maxWidth
= -1;
218 void wxHtmlTableCell::ReallocRows(int rows
)
220 m_CellInfo
= (cellStruct
**) realloc(m_CellInfo
, sizeof(cellStruct
*) * rows
);
221 for (int row
= m_NumRows
; row
< rows
; row
++)
224 m_CellInfo
[row
] = NULL
;
227 m_CellInfo
[row
] = (cellStruct
*) malloc(sizeof(cellStruct
) * m_NumCols
);
228 for (int col
= 0; col
< m_NumCols
; col
++)
229 m_CellInfo
[row
][col
].flag
= cellFree
;
236 void wxHtmlTableCell::AddRow(const wxHtmlTag
& tag
)
239 // VS: real allocation of row entry is done in AddCell in order
240 // to correctly handle empty rows (i.e. "<tr></tr>")
241 // m_ActualCol == -1 indicates that AddCell has to allocate new row.
245 if (tag
.HasParam(wxT("BGCOLOR")))
246 tag
.GetParamAsColour(wxT("BGCOLOR"), &m_rBkg
);
247 if (tag
.HasParam(wxT("VALIGN")))
248 m_rValign
= tag
.GetParam(wxT("VALIGN"));
250 m_rValign
= m_tValign
;
255 void wxHtmlTableCell::AddCell(wxHtmlContainerCell
*cell
, const wxHtmlTag
& tag
)
257 // Is this cell in new row?
258 // VS: we can't do it in AddRow, see my comment there
259 if (m_ActualCol
== -1)
261 if (m_ActualRow
+ 1 > m_NumRows
- 1)
262 ReallocRows(m_ActualRow
+ 2);
270 } while ((m_ActualCol
< m_NumCols
) &&
271 (m_CellInfo
[m_ActualRow
][m_ActualCol
].flag
!= cellFree
));
273 if (m_ActualCol
> m_NumCols
- 1)
274 ReallocCols(m_ActualCol
+ 1);
276 int r
= m_ActualRow
, c
= m_ActualCol
;
278 m_CellInfo
[r
][c
].cont
= cell
;
279 m_CellInfo
[r
][c
].colspan
= 1;
280 m_CellInfo
[r
][c
].rowspan
= 1;
281 m_CellInfo
[r
][c
].flag
= cellUsed
;
282 m_CellInfo
[r
][c
].minheight
= 0;
283 m_CellInfo
[r
][c
].valign
= wxHTML_ALIGN_TOP
;
285 /* scan for parameters: */
289 if (tag
.HasParam(wxT("WIDTH")))
291 wxString wd
= tag
.GetParam(wxT("WIDTH"));
293 if (!wd
.empty() && wd
[wd
.length()-1] == wxT('%'))
295 if ( wxSscanf(wd
.c_str(), wxT("%i%%"), &m_ColsInfo
[c
].width
) == 1 )
297 m_ColsInfo
[c
].units
= wxHTML_UNITS_PERCENT
;
303 if ( wd
.ToLong(&width
) )
305 m_ColsInfo
[c
].width
= (int)(m_PixelScale
* (double)width
);
306 m_ColsInfo
[c
].units
= wxHTML_UNITS_PIXELS
;
315 tag
.GetParamAsInt(wxT("COLSPAN"), &m_CellInfo
[r
][c
].colspan
);
316 tag
.GetParamAsInt(wxT("ROWSPAN"), &m_CellInfo
[r
][c
].rowspan
);
318 // VS: the standard says this about col/rowspan:
319 // "This attribute specifies the number of rows spanned by the
320 // current cell. The default value of this attribute is one ("1").
321 // The value zero ("0") means that the cell spans all rows from the
322 // current row to the last row of the table." All mainstream
323 // browsers act as if 0==1, though, and so does wxHTML.
324 if (m_CellInfo
[r
][c
].colspan
< 1)
325 m_CellInfo
[r
][c
].colspan
= 1;
326 if (m_CellInfo
[r
][c
].rowspan
< 1)
327 m_CellInfo
[r
][c
].rowspan
= 1;
329 if ((m_CellInfo
[r
][c
].colspan
> 1) || (m_CellInfo
[r
][c
].rowspan
> 1))
333 if (r
+ m_CellInfo
[r
][c
].rowspan
> m_NumRows
)
334 ReallocRows(r
+ m_CellInfo
[r
][c
].rowspan
);
335 if (c
+ m_CellInfo
[r
][c
].colspan
> m_NumCols
)
336 ReallocCols(c
+ m_CellInfo
[r
][c
].colspan
);
337 for (i
= r
; i
< r
+ m_CellInfo
[r
][c
].rowspan
; i
++)
338 for (j
= c
; j
< c
+ m_CellInfo
[r
][c
].colspan
; j
++)
339 m_CellInfo
[i
][j
].flag
= cellSpan
;
340 m_CellInfo
[r
][c
].flag
= cellUsed
;
346 wxColour bk
= m_rBkg
;
347 if (tag
.HasParam(wxT("BGCOLOR")))
348 tag
.GetParamAsColour(wxT("BGCOLOR"), &bk
);
350 cell
->SetBackgroundColour(bk
);
353 cell
->SetBorder(TABLE_BORDER_CLR_2
, TABLE_BORDER_CLR_1
);
355 // vertical alignment:
358 if (tag
.HasParam(wxT("VALIGN")))
359 valign
= tag
.GetParam(wxT("VALIGN"));
363 if (valign
== wxT("TOP"))
364 m_CellInfo
[r
][c
].valign
= wxHTML_ALIGN_TOP
;
365 else if (valign
== wxT("BOTTOM"))
366 m_CellInfo
[r
][c
].valign
= wxHTML_ALIGN_BOTTOM
;
367 else m_CellInfo
[r
][c
].valign
= wxHTML_ALIGN_CENTER
;
371 if (tag
.HasParam(wxT("NOWRAP")))
372 m_CellInfo
[r
][c
].nowrap
= true;
374 m_CellInfo
[r
][c
].nowrap
= false;
376 cell
->SetIndent(m_Padding
, wxHTML_INDENT_ALL
, wxHTML_UNITS_PIXELS
);
379 void wxHtmlTableCell::ComputeMinMaxWidths()
381 if (m_NumCols
== 0 || m_ColsInfo
[0].minWidth
!= wxDefaultCoord
) return;
385 for (int c
= 0; c
< m_NumCols
; c
++)
387 for (int r
= 0; r
< m_NumRows
; r
++)
389 cellStruct
& cell
= m_CellInfo
[r
][c
];
390 if (cell
.flag
== cellUsed
)
392 cell
.cont
->Layout(2*m_Padding
+ 1);
393 int maxWidth
= cell
.cont
->GetMaxTotalWidth();
394 int width
= cell
.nowrap
?maxWidth
:cell
.cont
->GetWidth();
395 width
-= (cell
.colspan
-1) * m_Spacing
;
396 maxWidth
-= (cell
.colspan
-1) * m_Spacing
;
397 // HTML 4.0 says it is acceptable to distribute min/max
398 width
/= cell
.colspan
;
399 maxWidth
/= cell
.colspan
;
400 for (int j
= 0; j
< cell
.colspan
; j
++) {
401 if (width
> m_ColsInfo
[c
+j
].minWidth
)
402 m_ColsInfo
[c
+j
].minWidth
= width
;
403 if (maxWidth
> m_ColsInfo
[c
+j
].maxWidth
)
404 m_ColsInfo
[c
+j
].maxWidth
= maxWidth
;
408 // Calculate maximum table width, required for nested tables
409 if (m_ColsInfo
[c
].units
== wxHTML_UNITS_PIXELS
)
410 m_MaxTotalWidth
+= wxMax(m_ColsInfo
[c
].width
, m_ColsInfo
[c
].minWidth
);
411 else if ((m_ColsInfo
[c
].units
== wxHTML_UNITS_PERCENT
) && (m_ColsInfo
[c
].width
!= 0))
412 percentage
+= m_ColsInfo
[c
].width
;
414 m_MaxTotalWidth
+= m_ColsInfo
[c
].maxWidth
;
417 if (percentage
>= 100)
419 // Table would have infinite length
420 // Make it ridiculous large
421 m_MaxTotalWidth
= 0xFFFFFF;
424 m_MaxTotalWidth
= m_MaxTotalWidth
* 100 / (100 - percentage
);
426 m_MaxTotalWidth
+= (m_NumCols
+ 1) * m_Spacing
+ 2 * m_Border
;
429 void wxHtmlTableCell::Layout(int w
)
431 ComputeMinMaxWidths();
433 wxHtmlCell::Layout(w
);
441 if (m_WidthFloatUnits
== wxHTML_UNITS_PERCENT
)
443 if (m_WidthFloat
< 0)
445 if (m_WidthFloat
< -100)
447 m_Width
= (100 + m_WidthFloat
) * w
/ 100;
451 if (m_WidthFloat
> 100)
453 m_Width
= m_WidthFloat
* w
/ 100;
458 if (m_WidthFloat
< 0) m_Width
= w
+ m_WidthFloat
;
459 else m_Width
= m_WidthFloat
;
469 /* 1. setup columns widths:
471 The algorithm tries to keep the table size less than w if possible.
474 int wpix
= m_Width
- (m_NumCols
+ 1) * m_Spacing
- 2 * m_Border
; // Available space for cell content
477 // 1a. setup fixed-width columns:
478 for (i
= 0; i
< m_NumCols
; i
++)
479 if (m_ColsInfo
[i
].units
== wxHTML_UNITS_PIXELS
)
481 m_ColsInfo
[i
].pixwidth
= wxMax(m_ColsInfo
[i
].width
,
482 m_ColsInfo
[i
].minWidth
);
483 wpix
-= m_ColsInfo
[i
].pixwidth
;
486 // 1b. Calculate maximum possible width if line wrapping would be disabled
487 // Recalculate total width if m_WidthFloat is zero to keep tables as small
490 for (i
= 0; i
< m_NumCols
; i
++)
491 if (m_ColsInfo
[i
].width
== 0)
493 maxWidth
+= m_ColsInfo
[i
].maxWidth
;
498 // Recalculate table width since no table width was initially given
499 int newWidth
= m_Width
- wpix
+ maxWidth
;
501 // Make sure that floating-width columns will have the right size.
502 // Calculate sum of all floating-width columns
504 for (i
= 0; i
< m_NumCols
; i
++)
505 if ((m_ColsInfo
[i
].units
== wxHTML_UNITS_PERCENT
) && (m_ColsInfo
[i
].width
!= 0))
506 percentage
+= m_ColsInfo
[i
].width
;
508 if (percentage
>= 100)
511 newWidth
= newWidth
* 100 / (100 - percentage
);
513 newWidth
= wxMin(newWidth
, w
- (m_NumCols
+ 1) * m_Spacing
- 2 * m_Border
);
514 wpix
-= m_Width
- newWidth
;
519 // 1c. setup floating-width columns:
521 for (i
= 0; i
< m_NumCols
; i
++)
522 if ((m_ColsInfo
[i
].units
== wxHTML_UNITS_PERCENT
) && (m_ColsInfo
[i
].width
!= 0))
524 m_ColsInfo
[i
].pixwidth
= wxMin(m_ColsInfo
[i
].width
, 100) * wpix
/ 100;
526 // Make sure to leave enough space for the other columns
527 int minRequired
= m_Border
;
528 for (j
= 0; j
< m_NumCols
; j
++)
530 if ((m_ColsInfo
[j
].units
== wxHTML_UNITS_PERCENT
&& j
> i
) ||
531 !m_ColsInfo
[j
].width
)
532 minRequired
+= m_ColsInfo
[j
].minWidth
;
534 m_ColsInfo
[i
].pixwidth
= wxMax(wxMin(wtemp
- minRequired
, m_ColsInfo
[i
].pixwidth
), m_ColsInfo
[i
].minWidth
);
536 wtemp
-= m_ColsInfo
[i
].pixwidth
;
538 wpix
= wtemp
; // minimum cells width
540 // 1d. setup default columns (no width specification supplied):
541 // The algorithm assigns calculates the maximum possible width if line
542 // wrapping would be disabled and assigns column width as a fraction
543 // based upon the maximum width of a column
544 // FIXME: I'm not sure if this algorithm is conform to HTML standard,
545 // though it seems to be much better than the old one
547 for (i
= j
= 0; i
< m_NumCols
; i
++)
548 if (m_ColsInfo
[i
].width
== 0) j
++;
553 for (i
= 0; i
< m_NumCols
; i
++)
554 if (m_ColsInfo
[i
].width
== 0)
556 // Assign with, make sure not to drop below minWidth
558 m_ColsInfo
[i
].pixwidth
= (int)(wpix
* (m_ColsInfo
[i
].maxWidth
/ (float)maxWidth
) + 0.5);
560 m_ColsInfo
[i
].pixwidth
= wpix
/ j
;
562 // Make sure to leave enough space for the other columns
565 for (r
= i
+ 1; r
< m_NumCols
; r
++)
567 if (!m_ColsInfo
[r
].width
)
568 minRequired
+= m_ColsInfo
[r
].minWidth
;
570 m_ColsInfo
[i
].pixwidth
= wxMax(wxMin(wpix
- minRequired
, m_ColsInfo
[i
].pixwidth
), m_ColsInfo
[i
].minWidth
);
574 if (m_ColsInfo
[i
].pixwidth
> (wpix
* (m_ColsInfo
[i
].maxWidth
/ (float)maxWidth
) + 0.5))
576 int diff
= (int)(m_ColsInfo
[i
].pixwidth
- (wpix
* m_ColsInfo
[i
].maxWidth
/ (float)maxWidth
+ 0.5));
577 maxWidth
+= diff
- m_ColsInfo
[i
].maxWidth
;
580 maxWidth
-= m_ColsInfo
[i
].maxWidth
;
582 wpix
-= m_ColsInfo
[i
].pixwidth
;
586 /* 2. compute positions of columns: */
588 int wpos
= m_Spacing
+ m_Border
;
589 for (int i
= 0; i
< m_NumCols
; i
++)
591 m_ColsInfo
[i
].leftpos
= wpos
;
592 wpos
+= m_ColsInfo
[i
].pixwidth
+ m_Spacing
;
595 // add the remaining space to the last column
596 if (m_NumCols
> 0 && wpos
< m_Width
- m_Border
)
597 m_ColsInfo
[m_NumCols
-1].pixwidth
+= m_Width
- wpos
- m_Border
;
600 /* 3. sub-layout all cells: */
602 int *ypos
= new int[m_NumRows
+ 1];
606 wxHtmlContainerCell
*actcell
;
608 ypos
[0] = m_Spacing
+ m_Border
;
609 for (actrow
= 1; actrow
<= m_NumRows
; actrow
++) ypos
[actrow
] = -1;
610 for (actrow
= 0; actrow
< m_NumRows
; actrow
++)
612 if (ypos
[actrow
] == -1) ypos
[actrow
] = ypos
[actrow
-1];
613 // 3a. sub-layout and detect max height:
615 for (actcol
= 0; actcol
< m_NumCols
; actcol
++) {
616 if (m_CellInfo
[actrow
][actcol
].flag
!= cellUsed
) continue;
617 actcell
= m_CellInfo
[actrow
][actcol
].cont
;
619 for (int i
= actcol
; i
< m_CellInfo
[actrow
][actcol
].colspan
+ actcol
; i
++)
620 fullwid
+= m_ColsInfo
[i
].pixwidth
;
621 fullwid
+= (m_CellInfo
[actrow
][actcol
].colspan
- 1) * m_Spacing
;
622 actcell
->SetMinHeight(m_CellInfo
[actrow
][actcol
].minheight
, m_CellInfo
[actrow
][actcol
].valign
);
623 actcell
->Layout(fullwid
);
625 if (ypos
[actrow
] + actcell
->GetHeight() + m_CellInfo
[actrow
][actcol
].rowspan
* m_Spacing
> ypos
[actrow
+ m_CellInfo
[actrow
][actcol
].rowspan
])
626 ypos
[actrow
+ m_CellInfo
[actrow
][actcol
].rowspan
] =
627 ypos
[actrow
] + actcell
->GetHeight() + m_CellInfo
[actrow
][actcol
].rowspan
* m_Spacing
;
631 for (actrow
= 0; actrow
< m_NumRows
; actrow
++)
633 // 3b. place cells in row & let'em all have same height:
635 for (actcol
= 0; actcol
< m_NumCols
; actcol
++)
637 if (m_CellInfo
[actrow
][actcol
].flag
!= cellUsed
) continue;
638 actcell
= m_CellInfo
[actrow
][actcol
].cont
;
639 actcell
->SetMinHeight(
640 ypos
[actrow
+ m_CellInfo
[actrow
][actcol
].rowspan
] - ypos
[actrow
] - m_Spacing
,
641 m_CellInfo
[actrow
][actcol
].valign
);
643 for (int i
= actcol
; i
< m_CellInfo
[actrow
][actcol
].colspan
+ actcol
; i
++)
644 fullwid
+= m_ColsInfo
[i
].pixwidth
;
645 fullwid
+= (m_CellInfo
[actrow
][actcol
].colspan
- 1) * m_Spacing
;
646 actcell
->Layout(fullwid
);
647 actcell
->SetPos(m_ColsInfo
[actcol
].leftpos
, ypos
[actrow
]);
650 m_Height
= ypos
[m_NumRows
] + m_Border
;
654 /* 4. adjust table's width if it was too small: */
657 int twidth
= m_ColsInfo
[m_NumCols
-1].leftpos
+
658 m_ColsInfo
[m_NumCols
-1].pixwidth
+ m_Spacing
+ m_Border
;
659 if (twidth
> m_Width
)
669 //-----------------------------------------------------------------------------
670 // The tables handler:
671 //-----------------------------------------------------------------------------
674 TAG_HANDLER_BEGIN(TABLE
, "TABLE,TR,TD,TH")
677 wxHtmlTableCell
* m_Table
;
678 wxString m_tAlign
, m_rAlign
;
679 wxHtmlContainerCell
*m_enclosingContainer
;
681 // Call ParseInner() preserving background colour and mode after any
682 // changes done by it.
683 void CallParseInnerWithBg(const wxHtmlTag
& tag
, const wxColour
& colBg
)
685 const wxColour oldbackclr
= m_WParser
->GetActualBackgroundColor();
686 const int oldbackmode
= m_WParser
->GetActualBackgroundMode();
689 m_WParser
->SetActualBackgroundColor(colBg
);
690 m_WParser
->SetActualBackgroundMode(wxBRUSHSTYLE_SOLID
);
691 m_WParser
->GetContainer()->InsertCell(
692 new wxHtmlColourCell(colBg
, wxHTML_CLR_BACKGROUND
)
698 if ( oldbackmode
!= m_WParser
->GetActualBackgroundMode() ||
699 oldbackclr
!= m_WParser
->GetActualBackgroundColor() )
701 m_WParser
->SetActualBackgroundMode(oldbackmode
);
702 m_WParser
->SetActualBackgroundColor(oldbackclr
);
703 m_WParser
->GetContainer()->InsertCell(
704 new wxHtmlColourCell(oldbackclr
,
705 oldbackmode
== wxBRUSHSTYLE_TRANSPARENT
706 ? wxHTML_CLR_TRANSPARENT_BACKGROUND
707 : wxHTML_CLR_BACKGROUND
)
712 TAG_HANDLER_CONSTR(TABLE
)
715 m_enclosingContainer
= NULL
;
716 m_tAlign
= m_rAlign
= wxEmptyString
;
720 TAG_HANDLER_PROC(tag
)
722 wxHtmlContainerCell
*c
;
724 // new table started, backup upper-level table (if any) and create new:
725 if (tag
.GetName() == wxT("TABLE"))
727 wxHtmlTableCell
*oldt
= m_Table
;
729 wxHtmlContainerCell
*oldEnclosing
= m_enclosingContainer
;
730 m_enclosingContainer
= c
= m_WParser
->OpenContainer();
732 m_Table
= new wxHtmlTableCell(c
, tag
, m_WParser
->GetPixelScale());
736 if (tag
.HasParam(wxT("WIDTH")))
739 bool wpercent
= false;
740 if (tag
.GetParamAsIntOrPercent(wxT("WIDTH"), &width
, wpercent
))
744 m_Table
->SetWidthFloat(width
, wxHTML_UNITS_PERCENT
);
748 m_Table
->SetWidthFloat((int)(m_WParser
->GetPixelScale() * width
), wxHTML_UNITS_PIXELS
);
753 m_Table
->SetWidthFloat(0, wxHTML_UNITS_PIXELS
);
755 int oldAlign
= m_WParser
->GetAlign();
756 m_tAlign
= wxEmptyString
;
757 if (tag
.HasParam(wxT("ALIGN")))
758 m_tAlign
= tag
.GetParam(wxT("ALIGN"));
760 CallParseInnerWithBg(tag
, m_Table
->GetBackgroundColour());
762 m_WParser
->SetAlign(oldAlign
);
763 m_WParser
->SetContainer(m_enclosingContainer
);
764 m_WParser
->CloseContainer();
767 m_enclosingContainer
= oldEnclosing
;
769 return true; // ParseInner() called
776 if (tag
.GetName() == wxT("TR"))
778 m_Table
->AddRow(tag
);
780 if (tag
.HasParam(wxT("ALIGN")))
781 m_rAlign
= tag
.GetParam(wxT("ALIGN"));
787 c
= m_WParser
->SetContainer(new wxHtmlContainerCell(m_Table
));
788 m_Table
->AddCell(c
, tag
);
790 m_WParser
->OpenContainer();
792 const bool isHeader
= tag
.GetName() == wxT("TH");
795 if (tag
.HasParam(wxT("ALIGN")))
796 als
= tag
.GetParam(wxT("ALIGN"));
801 if (als
== wxT("RIGHT"))
802 m_WParser
->SetAlign(wxHTML_ALIGN_RIGHT
);
803 else if (als
== wxT("LEFT"))
804 m_WParser
->SetAlign(wxHTML_ALIGN_LEFT
);
805 else if (als
== wxT("CENTER"))
806 m_WParser
->SetAlign(wxHTML_ALIGN_CENTER
);
807 else // use default alignment
808 m_WParser
->SetAlign(isHeader
? wxHTML_ALIGN_CENTER
809 : wxHTML_ALIGN_LEFT
);
811 m_WParser
->OpenContainer();
813 // the header should be rendered in bold by default
817 boldOld
= m_WParser
->GetFontBold();
818 m_WParser
->SetFontBold(true);
819 m_WParser
->GetContainer()->InsertCell(
820 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
824 if ( !tag
.GetParamAsColour(wxT("BGCOLOR"), &bgCol
) )
825 bgCol
= m_Table
->GetRowDefaultBackgroundColour();
827 CallParseInnerWithBg(tag
, bgCol
);
831 m_WParser
->SetFontBold(boldOld
);
832 m_WParser
->GetContainer()->InsertCell(
833 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
836 // set the current container back to the enclosing one so that
837 // text outside of <th> and <td> isn't included in any cell
838 // (this happens often enough in practice because it's common
839 // to use whitespace between </td> and the next <td>):
840 m_WParser
->SetContainer(m_enclosingContainer
);
842 return true; // ParseInner() called
849 TAG_HANDLER_END(TABLE
)
855 TAGS_MODULE_BEGIN(Tables
)
857 TAGS_MODULE_ADD(TABLE
)
859 TAGS_MODULE_END(Tables
)