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
.GetParamAsColour(wxT("BGCOLOR"), &m_tBkg
))
138 SetBackgroundColour(m_tBkg
);
139 m_tValign
= tag
.GetParam(wxT("VALIGN"));
140 if (!tag
.GetParamAsInt(wxT("CELLSPACING"), &m_Spacing
))
142 if (!tag
.GetParamAsInt(wxT("CELLPADDING"), &m_Padding
))
144 m_Spacing
= (int)(m_PixelScale
* (double)m_Spacing
);
145 m_Padding
= (int)(m_PixelScale
* (double)m_Padding
);
147 if(tag
.HasParam(wxT("BORDER")))
149 if(tag
.GetParam("BORDER").IsEmpty())
152 tag
.GetParamAsInt(wxT("BORDER"), &m_Border
);
155 SetBorder(TABLE_BORDER_CLR_1
, TABLE_BORDER_CLR_2
, m_Border
); // special case see wxHtmlContainerCell::Draw
156 else if (m_Border
> 0)
157 SetBorder(TABLE_BORDER_CLR_1
, TABLE_BORDER_CLR_2
, (int)(m_PixelScale
* (double)m_Border
));
165 wxHtmlTableCell::~wxHtmlTableCell()
167 if (m_ColsInfo
) free(m_ColsInfo
);
170 for (int i
= 0; i
< m_NumRows
; i
++)
177 void wxHtmlTableCell::RemoveExtraSpacing(bool WXUNUSED(top
),
178 bool WXUNUSED(bottom
))
180 // Don't remove any spacing in the table -- it's always desirable,
181 // because it's part of table's definition.
182 // (If wxHtmlContainerCell::RemoveExtraSpacing() was applied to tables,
183 // then upper left cell of a table would be positioned above other cells
184 // if the table was the first element on the page.)
187 void wxHtmlTableCell::ReallocCols(int cols
)
191 for (i
= 0; i
< m_NumRows
; i
++)
193 m_CellInfo
[i
] = (cellStruct
*) realloc(m_CellInfo
[i
], sizeof(cellStruct
) * cols
);
194 for (j
= m_NumCols
; j
< cols
; j
++)
195 m_CellInfo
[i
][j
].flag
= cellFree
;
198 m_ColsInfo
= (colStruct
*) realloc(m_ColsInfo
, sizeof(colStruct
) * cols
);
199 for (j
= m_NumCols
; j
< cols
; j
++)
201 m_ColsInfo
[j
].width
= 0;
202 m_ColsInfo
[j
].units
= wxHTML_UNITS_PERCENT
;
203 m_ColsInfo
[j
].minWidth
= m_ColsInfo
[j
].maxWidth
= -1;
211 void wxHtmlTableCell::ReallocRows(int rows
)
213 m_CellInfo
= (cellStruct
**) realloc(m_CellInfo
, sizeof(cellStruct
*) * rows
);
214 for (int row
= m_NumRows
; row
< rows
; row
++)
217 m_CellInfo
[row
] = NULL
;
220 m_CellInfo
[row
] = (cellStruct
*) malloc(sizeof(cellStruct
) * m_NumCols
);
221 for (int col
= 0; col
< m_NumCols
; col
++)
222 m_CellInfo
[row
][col
].flag
= cellFree
;
229 void wxHtmlTableCell::AddRow(const wxHtmlTag
& tag
)
232 // VS: real allocation of row entry is done in AddCell in order
233 // to correctly handle empty rows (i.e. "<tr></tr>")
234 // m_ActualCol == -1 indicates that AddCell has to allocate new row.
238 tag
.GetParamAsColour(wxT("BGCOLOR"), &m_rBkg
);
239 if (!tag
.GetParamAsString(wxT("VALIGN"), &m_rValign
))
240 m_rValign
= m_tValign
;
245 void wxHtmlTableCell::AddCell(wxHtmlContainerCell
*cell
, const wxHtmlTag
& tag
)
247 // Is this cell in new row?
248 // VS: we can't do it in AddRow, see my comment there
249 if (m_ActualCol
== -1)
251 if (m_ActualRow
+ 1 > m_NumRows
- 1)
252 ReallocRows(m_ActualRow
+ 2);
260 } while ((m_ActualCol
< m_NumCols
) &&
261 (m_CellInfo
[m_ActualRow
][m_ActualCol
].flag
!= cellFree
));
263 if (m_ActualCol
> m_NumCols
- 1)
264 ReallocCols(m_ActualCol
+ 1);
266 int r
= m_ActualRow
, c
= m_ActualCol
;
268 m_CellInfo
[r
][c
].cont
= cell
;
269 m_CellInfo
[r
][c
].colspan
= 1;
270 m_CellInfo
[r
][c
].rowspan
= 1;
271 m_CellInfo
[r
][c
].flag
= cellUsed
;
272 m_CellInfo
[r
][c
].minheight
= 0;
273 m_CellInfo
[r
][c
].valign
= wxHTML_ALIGN_TOP
;
275 /* scan for parameters: */
279 if (tag
.GetParamAsString(wxT("ID"), &idvalue
))
281 cell
->SetId(idvalue
);
287 bool wpercent
= false;
288 if (tag
.GetParamAsIntOrPercent(wxT("WIDTH"), &width
, wpercent
))
292 m_ColsInfo
[c
].width
= width
;
293 m_ColsInfo
[c
].units
= wxHTML_UNITS_PERCENT
;
297 m_ColsInfo
[c
].width
= (int)(m_PixelScale
* (double)width
);
298 m_ColsInfo
[c
].units
= wxHTML_UNITS_PIXELS
;
306 tag
.GetParamAsInt(wxT("COLSPAN"), &m_CellInfo
[r
][c
].colspan
);
307 tag
.GetParamAsInt(wxT("ROWSPAN"), &m_CellInfo
[r
][c
].rowspan
);
309 // VS: the standard says this about col/rowspan:
310 // "This attribute specifies the number of rows spanned by the
311 // current cell. The default value of this attribute is one ("1").
312 // The value zero ("0") means that the cell spans all rows from the
313 // current row to the last row of the table." All mainstream
314 // browsers act as if 0==1, though, and so does wxHTML.
315 if (m_CellInfo
[r
][c
].colspan
< 1)
316 m_CellInfo
[r
][c
].colspan
= 1;
317 if (m_CellInfo
[r
][c
].rowspan
< 1)
318 m_CellInfo
[r
][c
].rowspan
= 1;
320 if ((m_CellInfo
[r
][c
].colspan
> 1) || (m_CellInfo
[r
][c
].rowspan
> 1))
324 if (r
+ m_CellInfo
[r
][c
].rowspan
> m_NumRows
)
325 ReallocRows(r
+ m_CellInfo
[r
][c
].rowspan
);
326 if (c
+ m_CellInfo
[r
][c
].colspan
> m_NumCols
)
327 ReallocCols(c
+ m_CellInfo
[r
][c
].colspan
);
328 for (i
= r
; i
< r
+ m_CellInfo
[r
][c
].rowspan
; i
++)
329 for (j
= c
; j
< c
+ m_CellInfo
[r
][c
].colspan
; j
++)
330 m_CellInfo
[i
][j
].flag
= cellSpan
;
331 m_CellInfo
[r
][c
].flag
= cellUsed
;
337 wxColour bk
= m_rBkg
;
338 tag
.GetParamAsColour(wxT("BGCOLOR"), &bk
);
340 cell
->SetBackgroundColour(bk
);
343 cell
->SetBorder(TABLE_BORDER_CLR_2
, TABLE_BORDER_CLR_1
);
345 // vertical alignment:
348 if (!tag
.GetParamAsString(wxT("VALIGN"), &valign
))
351 if (valign
== wxT("TOP"))
352 m_CellInfo
[r
][c
].valign
= wxHTML_ALIGN_TOP
;
353 else if (valign
== wxT("BOTTOM"))
354 m_CellInfo
[r
][c
].valign
= wxHTML_ALIGN_BOTTOM
;
355 else m_CellInfo
[r
][c
].valign
= wxHTML_ALIGN_CENTER
;
359 m_CellInfo
[r
][c
].nowrap
= tag
.HasParam(wxT("NOWRAP"));
361 cell
->SetIndent(m_Padding
, wxHTML_INDENT_ALL
, wxHTML_UNITS_PIXELS
);
364 void wxHtmlTableCell::ComputeMinMaxWidths()
366 if (m_NumCols
== 0 || m_ColsInfo
[0].minWidth
!= wxDefaultCoord
) return;
370 for (int c
= 0; c
< m_NumCols
; c
++)
372 for (int r
= 0; r
< m_NumRows
; r
++)
374 cellStruct
& cell
= m_CellInfo
[r
][c
];
375 if (cell
.flag
== cellUsed
)
377 cell
.cont
->Layout(2*m_Padding
+ 1);
378 int maxWidth
= cell
.cont
->GetMaxTotalWidth();
379 int width
= cell
.nowrap
?maxWidth
:cell
.cont
->GetWidth();
380 width
-= (cell
.colspan
-1) * m_Spacing
;
381 maxWidth
-= (cell
.colspan
-1) * m_Spacing
;
382 // HTML 4.0 says it is acceptable to distribute min/max
383 width
/= cell
.colspan
;
384 maxWidth
/= cell
.colspan
;
385 for (int j
= 0; j
< cell
.colspan
; j
++) {
386 if (width
> m_ColsInfo
[c
+j
].minWidth
)
387 m_ColsInfo
[c
+j
].minWidth
= width
;
388 if (maxWidth
> m_ColsInfo
[c
+j
].maxWidth
)
389 m_ColsInfo
[c
+j
].maxWidth
= maxWidth
;
393 // Calculate maximum table width, required for nested tables
394 if (m_ColsInfo
[c
].units
== wxHTML_UNITS_PIXELS
)
395 m_MaxTotalWidth
+= wxMax(m_ColsInfo
[c
].width
, m_ColsInfo
[c
].minWidth
);
396 else if ((m_ColsInfo
[c
].units
== wxHTML_UNITS_PERCENT
) && (m_ColsInfo
[c
].width
!= 0))
397 percentage
+= m_ColsInfo
[c
].width
;
399 m_MaxTotalWidth
+= m_ColsInfo
[c
].maxWidth
;
402 if (percentage
>= 100)
404 // Table would have infinite length
405 // Make it ridiculous large
406 m_MaxTotalWidth
= 0xFFFFFF;
409 m_MaxTotalWidth
= m_MaxTotalWidth
* 100 / (100 - percentage
);
411 m_MaxTotalWidth
+= (m_NumCols
+ 1) * m_Spacing
+ 2 * m_Border
;
414 void wxHtmlTableCell::Layout(int w
)
416 ComputeMinMaxWidths();
418 wxHtmlCell::Layout(w
);
426 if (m_WidthFloatUnits
== wxHTML_UNITS_PERCENT
)
428 if (m_WidthFloat
< 0)
430 if (m_WidthFloat
< -100)
432 m_Width
= (100 + m_WidthFloat
) * w
/ 100;
436 if (m_WidthFloat
> 100)
438 m_Width
= m_WidthFloat
* w
/ 100;
443 if (m_WidthFloat
< 0) m_Width
= w
+ m_WidthFloat
;
444 else m_Width
= m_WidthFloat
;
454 /* 1. setup columns widths:
456 The algorithm tries to keep the table size less than w if possible.
459 int wpix
= m_Width
- (m_NumCols
+ 1) * m_Spacing
- 2 * m_Border
; // Available space for cell content
462 // 1a. setup fixed-width columns:
463 for (i
= 0; i
< m_NumCols
; i
++)
464 if (m_ColsInfo
[i
].units
== wxHTML_UNITS_PIXELS
)
466 m_ColsInfo
[i
].pixwidth
= wxMax(m_ColsInfo
[i
].width
,
467 m_ColsInfo
[i
].minWidth
);
468 wpix
-= m_ColsInfo
[i
].pixwidth
;
471 // 1b. Calculate maximum possible width if line wrapping would be disabled
472 // Recalculate total width if m_WidthFloat is zero to keep tables as small
475 for (i
= 0; i
< m_NumCols
; i
++)
476 if (m_ColsInfo
[i
].width
== 0)
478 maxWidth
+= m_ColsInfo
[i
].maxWidth
;
483 // Recalculate table width since no table width was initially given
484 int newWidth
= m_Width
- wpix
+ maxWidth
;
486 // Make sure that floating-width columns will have the right size.
487 // Calculate sum of all floating-width columns
489 for (i
= 0; i
< m_NumCols
; i
++)
490 if ((m_ColsInfo
[i
].units
== wxHTML_UNITS_PERCENT
) && (m_ColsInfo
[i
].width
!= 0))
491 percentage
+= m_ColsInfo
[i
].width
;
493 if (percentage
>= 100)
496 newWidth
= newWidth
* 100 / (100 - percentage
);
498 newWidth
= wxMin(newWidth
, w
- (m_NumCols
+ 1) * m_Spacing
- 2 * m_Border
);
499 wpix
-= m_Width
- newWidth
;
504 // 1c. setup floating-width columns:
506 for (i
= 0; i
< m_NumCols
; i
++)
507 if ((m_ColsInfo
[i
].units
== wxHTML_UNITS_PERCENT
) && (m_ColsInfo
[i
].width
!= 0))
509 m_ColsInfo
[i
].pixwidth
= wxMin(m_ColsInfo
[i
].width
, 100) * wpix
/ 100;
511 // Make sure to leave enough space for the other columns
512 int minRequired
= m_Border
;
513 for (j
= 0; j
< m_NumCols
; j
++)
515 if ((m_ColsInfo
[j
].units
== wxHTML_UNITS_PERCENT
&& j
> i
) ||
516 !m_ColsInfo
[j
].width
)
517 minRequired
+= m_ColsInfo
[j
].minWidth
;
519 m_ColsInfo
[i
].pixwidth
= wxMax(wxMin(wtemp
- minRequired
, m_ColsInfo
[i
].pixwidth
), m_ColsInfo
[i
].minWidth
);
521 wtemp
-= m_ColsInfo
[i
].pixwidth
;
523 wpix
= wtemp
; // minimum cells width
525 // 1d. setup default columns (no width specification supplied):
526 // The algorithm assigns calculates the maximum possible width if line
527 // wrapping would be disabled and assigns column width as a fraction
528 // based upon the maximum width of a column
529 // FIXME: I'm not sure if this algorithm is conform to HTML standard,
530 // though it seems to be much better than the old one
532 for (i
= j
= 0; i
< m_NumCols
; i
++)
533 if (m_ColsInfo
[i
].width
== 0) j
++;
538 for (i
= 0; i
< m_NumCols
; i
++)
539 if (m_ColsInfo
[i
].width
== 0)
541 // Assign with, make sure not to drop below minWidth
543 m_ColsInfo
[i
].pixwidth
= (int)(wpix
* (m_ColsInfo
[i
].maxWidth
/ (float)maxWidth
) + 0.5);
545 m_ColsInfo
[i
].pixwidth
= wpix
/ j
;
547 // Make sure to leave enough space for the other columns
550 for (r
= i
+ 1; r
< m_NumCols
; r
++)
552 if (!m_ColsInfo
[r
].width
)
553 minRequired
+= m_ColsInfo
[r
].minWidth
;
555 m_ColsInfo
[i
].pixwidth
= wxMax(wxMin(wpix
- minRequired
, m_ColsInfo
[i
].pixwidth
), m_ColsInfo
[i
].minWidth
);
559 if (m_ColsInfo
[i
].pixwidth
> (wpix
* (m_ColsInfo
[i
].maxWidth
/ (float)maxWidth
) + 0.5))
561 int diff
= (int)(m_ColsInfo
[i
].pixwidth
- (wpix
* m_ColsInfo
[i
].maxWidth
/ (float)maxWidth
+ 0.5));
562 maxWidth
+= diff
- m_ColsInfo
[i
].maxWidth
;
565 maxWidth
-= m_ColsInfo
[i
].maxWidth
;
567 wpix
-= m_ColsInfo
[i
].pixwidth
;
571 /* 2. compute positions of columns: */
573 int wpos
= m_Spacing
+ m_Border
;
574 for (int i
= 0; i
< m_NumCols
; i
++)
576 m_ColsInfo
[i
].leftpos
= wpos
;
577 wpos
+= m_ColsInfo
[i
].pixwidth
+ m_Spacing
;
580 // add the remaining space to the last column
581 if (m_NumCols
> 0 && wpos
< m_Width
- m_Border
)
582 m_ColsInfo
[m_NumCols
-1].pixwidth
+= m_Width
- wpos
- m_Border
;
585 /* 3. sub-layout all cells: */
587 int *ypos
= new int[m_NumRows
+ 1];
591 wxHtmlContainerCell
*actcell
;
593 ypos
[0] = m_Spacing
+ m_Border
;
594 for (actrow
= 1; actrow
<= m_NumRows
; actrow
++) ypos
[actrow
] = -1;
595 for (actrow
= 0; actrow
< m_NumRows
; actrow
++)
597 if (ypos
[actrow
] == -1) ypos
[actrow
] = ypos
[actrow
-1];
598 // 3a. sub-layout and detect max height:
600 for (actcol
= 0; actcol
< m_NumCols
; actcol
++) {
601 if (m_CellInfo
[actrow
][actcol
].flag
!= cellUsed
) continue;
602 actcell
= m_CellInfo
[actrow
][actcol
].cont
;
604 for (int i
= actcol
; i
< m_CellInfo
[actrow
][actcol
].colspan
+ actcol
; i
++)
605 fullwid
+= m_ColsInfo
[i
].pixwidth
;
606 fullwid
+= (m_CellInfo
[actrow
][actcol
].colspan
- 1) * m_Spacing
;
607 actcell
->SetMinHeight(m_CellInfo
[actrow
][actcol
].minheight
, m_CellInfo
[actrow
][actcol
].valign
);
608 actcell
->Layout(fullwid
);
610 if (ypos
[actrow
] + actcell
->GetHeight() + m_CellInfo
[actrow
][actcol
].rowspan
* m_Spacing
> ypos
[actrow
+ m_CellInfo
[actrow
][actcol
].rowspan
])
611 ypos
[actrow
+ m_CellInfo
[actrow
][actcol
].rowspan
] =
612 ypos
[actrow
] + actcell
->GetHeight() + m_CellInfo
[actrow
][actcol
].rowspan
* m_Spacing
;
616 for (actrow
= 0; actrow
< m_NumRows
; actrow
++)
618 // 3b. place cells in row & let'em all have same height:
620 for (actcol
= 0; actcol
< m_NumCols
; actcol
++)
622 if (m_CellInfo
[actrow
][actcol
].flag
!= cellUsed
) continue;
623 actcell
= m_CellInfo
[actrow
][actcol
].cont
;
624 actcell
->SetMinHeight(
625 ypos
[actrow
+ m_CellInfo
[actrow
][actcol
].rowspan
] - ypos
[actrow
] - m_Spacing
,
626 m_CellInfo
[actrow
][actcol
].valign
);
628 for (int i
= actcol
; i
< m_CellInfo
[actrow
][actcol
].colspan
+ actcol
; i
++)
629 fullwid
+= m_ColsInfo
[i
].pixwidth
;
630 fullwid
+= (m_CellInfo
[actrow
][actcol
].colspan
- 1) * m_Spacing
;
631 actcell
->Layout(fullwid
);
632 actcell
->SetPos(m_ColsInfo
[actcol
].leftpos
, ypos
[actrow
]);
635 m_Height
= ypos
[m_NumRows
] + m_Border
;
639 /* 4. adjust table's width if it was too small: */
642 int twidth
= m_ColsInfo
[m_NumCols
-1].leftpos
+
643 m_ColsInfo
[m_NumCols
-1].pixwidth
+ m_Spacing
+ m_Border
;
644 if (twidth
> m_Width
)
654 //-----------------------------------------------------------------------------
655 // The tables handler:
656 //-----------------------------------------------------------------------------
659 TAG_HANDLER_BEGIN(TABLE
, "TABLE,TR,TD,TH")
662 wxHtmlTableCell
* m_Table
;
663 wxString m_tAlign
, m_rAlign
;
664 wxHtmlContainerCell
*m_enclosingContainer
;
666 // Call ParseInner() preserving background colour and mode after any
667 // changes done by it.
668 void CallParseInnerWithBg(const wxHtmlTag
& tag
, const wxColour
& colBg
)
670 const wxColour oldbackclr
= m_WParser
->GetActualBackgroundColor();
671 const int oldbackmode
= m_WParser
->GetActualBackgroundMode();
674 m_WParser
->SetActualBackgroundColor(colBg
);
675 m_WParser
->SetActualBackgroundMode(wxBRUSHSTYLE_SOLID
);
676 m_WParser
->GetContainer()->InsertCell(
677 new wxHtmlColourCell(colBg
, wxHTML_CLR_BACKGROUND
)
683 if ( oldbackmode
!= m_WParser
->GetActualBackgroundMode() ||
684 oldbackclr
!= m_WParser
->GetActualBackgroundColor() )
686 m_WParser
->SetActualBackgroundMode(oldbackmode
);
687 m_WParser
->SetActualBackgroundColor(oldbackclr
);
688 m_WParser
->GetContainer()->InsertCell(
689 new wxHtmlColourCell(oldbackclr
,
690 oldbackmode
== wxBRUSHSTYLE_TRANSPARENT
691 ? wxHTML_CLR_TRANSPARENT_BACKGROUND
692 : wxHTML_CLR_BACKGROUND
)
697 TAG_HANDLER_CONSTR(TABLE
)
700 m_enclosingContainer
= NULL
;
701 m_tAlign
= m_rAlign
= wxEmptyString
;
705 TAG_HANDLER_PROC(tag
)
707 wxHtmlContainerCell
*c
;
709 // new table started, backup upper-level table (if any) and create new:
710 if (tag
.GetName() == wxT("TABLE"))
712 wxHtmlTableCell
*oldt
= m_Table
;
714 wxHtmlContainerCell
*oldEnclosing
= m_enclosingContainer
;
715 m_enclosingContainer
= c
= m_WParser
->OpenContainer();
717 m_Table
= new wxHtmlTableCell(c
, tag
, m_WParser
->GetPixelScale());
722 bool wpercent
= false;
723 if (tag
.GetParamAsIntOrPercent(wxT("WIDTH"), &width
, wpercent
))
727 m_Table
->SetWidthFloat(width
, wxHTML_UNITS_PERCENT
);
731 m_Table
->SetWidthFloat((int)(m_WParser
->GetPixelScale() * width
), wxHTML_UNITS_PIXELS
);
735 m_Table
->SetWidthFloat(0, wxHTML_UNITS_PIXELS
);
737 int oldAlign
= m_WParser
->GetAlign();
738 if (!tag
.GetParamAsString(wxT("ALIGN"), &m_tAlign
))
741 CallParseInnerWithBg(tag
, m_Table
->GetBackgroundColour());
743 m_WParser
->SetAlign(oldAlign
);
744 m_WParser
->SetContainer(m_enclosingContainer
);
745 m_WParser
->CloseContainer();
748 m_enclosingContainer
= oldEnclosing
;
750 return true; // ParseInner() called
757 if (tag
.GetName() == wxT("TR"))
759 m_Table
->AddRow(tag
);
760 if (!tag
.GetParamAsString(wxT("ALIGN"), &m_rAlign
))
767 c
= m_WParser
->SetContainer(new wxHtmlContainerCell(m_Table
));
768 m_Table
->AddCell(c
, tag
);
770 m_WParser
->OpenContainer();
772 const bool isHeader
= tag
.GetName() == wxT("TH");
775 if (!tag
.GetParamAsString(wxT("ALIGN"), &als
))
779 if (als
== wxT("RIGHT"))
780 m_WParser
->SetAlign(wxHTML_ALIGN_RIGHT
);
781 else if (als
== wxT("LEFT"))
782 m_WParser
->SetAlign(wxHTML_ALIGN_LEFT
);
783 else if (als
== wxT("CENTER"))
784 m_WParser
->SetAlign(wxHTML_ALIGN_CENTER
);
785 else // use default alignment
786 m_WParser
->SetAlign(isHeader
? wxHTML_ALIGN_CENTER
787 : wxHTML_ALIGN_LEFT
);
789 m_WParser
->OpenContainer();
791 // the header should be rendered in bold by default
795 boldOld
= m_WParser
->GetFontBold();
796 m_WParser
->SetFontBold(true);
797 m_WParser
->GetContainer()->InsertCell(
798 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
802 if ( !tag
.GetParamAsColour(wxT("BGCOLOR"), &bgCol
) )
803 bgCol
= m_Table
->GetRowDefaultBackgroundColour();
805 CallParseInnerWithBg(tag
, bgCol
);
809 m_WParser
->SetFontBold(boldOld
);
810 m_WParser
->GetContainer()->InsertCell(
811 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
814 // set the current container back to the enclosing one so that
815 // text outside of <th> and <td> isn't included in any cell
816 // (this happens often enough in practice because it's common
817 // to use whitespace between </td> and the next <td>):
818 m_WParser
->SetContainer(m_enclosingContainer
);
820 return true; // ParseInner() called
827 TAG_HANDLER_END(TABLE
)
833 TAGS_MODULE_BEGIN(Tables
)
835 TAGS_MODULE_ADD(TABLE
)
837 TAGS_MODULE_END(Tables
)