]>
git.saurik.com Git - wxWidgets.git/blob - src/html/m_tables.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/m_tables.cpp
3 // Purpose: wxHtml module for tables
4 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #include "wx/wxprec.h"
16 #if wxUSE_HTML && wxUSE_STREAMS
19 #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 // layouting 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
);
110 // Reallocates memory to given number of cols/rows
111 // and changes m_NumCols/m_NumRows value to reflect this change
112 // NOTE! You CAN'T change m_NumCols/m_NumRows before calling this!!
113 void ReallocCols(int cols
);
114 void ReallocRows(int rows
);
116 // Computes minimal and maximal widths of columns. Needs to be called
117 // only once, before first Layout().
118 void ComputeMinMaxWidths();
120 wxDECLARE_NO_COPY_CLASS(wxHtmlTableCell
);
125 wxHtmlTableCell::wxHtmlTableCell(wxHtmlContainerCell
*parent
, const wxHtmlTag
& tag
, double pixel_scale
)
126 : wxHtmlContainerCell(parent
)
128 m_PixelScale
= pixel_scale
;
130 m_NumCols
= m_NumRows
= 0;
132 m_ActualCol
= m_ActualRow
= -1;
135 if (tag
.HasParam(wxT("BGCOLOR")))
137 tag
.GetParamAsColour(wxT("BGCOLOR"), &m_tBkg
);
139 SetBackgroundColour(m_tBkg
);
141 if (tag
.HasParam(wxT("VALIGN")))
142 m_tValign
= tag
.GetParam(wxT("VALIGN"));
144 m_tValign
= wxEmptyString
;
145 if (!tag
.GetParamAsInt(wxT("CELLSPACING"), &m_Spacing
))
147 if (!tag
.GetParamAsInt(wxT("CELLPADDING"), &m_Padding
))
149 m_Spacing
= (int)(m_PixelScale
* (double)m_Spacing
);
150 m_Padding
= (int)(m_PixelScale
* (double)m_Padding
);
152 if(tag
.HasParam(wxT("BORDER")))
154 if(tag
.GetParam("BORDER").IsEmpty())
157 tag
.GetParamAsInt(wxT("BORDER"), &m_Border
);
160 SetBorder(TABLE_BORDER_CLR_1
, TABLE_BORDER_CLR_2
, m_Border
); // special case see wxHtmlContainerCell::Draw
161 else if (m_Border
> 0)
162 SetBorder(TABLE_BORDER_CLR_1
, TABLE_BORDER_CLR_2
, (int)(m_PixelScale
* (double)m_Border
));
170 wxHtmlTableCell::~wxHtmlTableCell()
172 if (m_ColsInfo
) free(m_ColsInfo
);
175 for (int i
= 0; i
< m_NumRows
; i
++)
182 void wxHtmlTableCell::RemoveExtraSpacing(bool WXUNUSED(top
),
183 bool WXUNUSED(bottom
))
185 // Don't remove any spacing in the table -- it's always desirable,
186 // because it's part of table's definition.
187 // (If wxHtmlContainerCell::RemoveExtraSpacing() was applied to tables,
188 // then upper left cell of a table would be positioned above other cells
189 // if the table was the first element on the page.)
192 void wxHtmlTableCell::ReallocCols(int cols
)
196 for (i
= 0; i
< m_NumRows
; i
++)
198 m_CellInfo
[i
] = (cellStruct
*) realloc(m_CellInfo
[i
], sizeof(cellStruct
) * cols
);
199 for (j
= m_NumCols
; j
< cols
; j
++)
200 m_CellInfo
[i
][j
].flag
= cellFree
;
203 m_ColsInfo
= (colStruct
*) realloc(m_ColsInfo
, sizeof(colStruct
) * cols
);
204 for (j
= m_NumCols
; j
< cols
; j
++)
206 m_ColsInfo
[j
].width
= 0;
207 m_ColsInfo
[j
].units
= wxHTML_UNITS_PERCENT
;
208 m_ColsInfo
[j
].minWidth
= m_ColsInfo
[j
].maxWidth
= -1;
216 void wxHtmlTableCell::ReallocRows(int rows
)
218 m_CellInfo
= (cellStruct
**) realloc(m_CellInfo
, sizeof(cellStruct
*) * rows
);
219 for (int row
= m_NumRows
; row
< rows
; row
++)
222 m_CellInfo
[row
] = NULL
;
225 m_CellInfo
[row
] = (cellStruct
*) malloc(sizeof(cellStruct
) * m_NumCols
);
226 for (int col
= 0; col
< m_NumCols
; col
++)
227 m_CellInfo
[row
][col
].flag
= cellFree
;
234 void wxHtmlTableCell::AddRow(const wxHtmlTag
& tag
)
237 // VS: real allocation of row entry is done in AddCell in order
238 // to correctly handle empty rows (i.e. "<tr></tr>")
239 // m_ActualCol == -1 indicates that AddCell has to allocate new row.
243 if (tag
.HasParam(wxT("BGCOLOR")))
244 tag
.GetParamAsColour(wxT("BGCOLOR"), &m_rBkg
);
245 if (tag
.HasParam(wxT("VALIGN")))
246 m_rValign
= tag
.GetParam(wxT("VALIGN"));
248 m_rValign
= m_tValign
;
253 void wxHtmlTableCell::AddCell(wxHtmlContainerCell
*cell
, const wxHtmlTag
& tag
)
255 // Is this cell in new row?
256 // VS: we can't do it in AddRow, see my comment there
257 if (m_ActualCol
== -1)
259 if (m_ActualRow
+ 1 > m_NumRows
- 1)
260 ReallocRows(m_ActualRow
+ 2);
268 } while ((m_ActualCol
< m_NumCols
) &&
269 (m_CellInfo
[m_ActualRow
][m_ActualCol
].flag
!= cellFree
));
271 if (m_ActualCol
> m_NumCols
- 1)
272 ReallocCols(m_ActualCol
+ 1);
274 int r
= m_ActualRow
, c
= m_ActualCol
;
276 m_CellInfo
[r
][c
].cont
= cell
;
277 m_CellInfo
[r
][c
].colspan
= 1;
278 m_CellInfo
[r
][c
].rowspan
= 1;
279 m_CellInfo
[r
][c
].flag
= cellUsed
;
280 m_CellInfo
[r
][c
].minheight
= 0;
281 m_CellInfo
[r
][c
].valign
= wxHTML_ALIGN_TOP
;
283 /* scan for parameters: */
287 if (tag
.HasParam(wxT("WIDTH")))
289 wxString wd
= tag
.GetParam(wxT("WIDTH"));
291 if (wd
[wd
.length()-1] == wxT('%'))
293 if ( wxSscanf(wd
.c_str(), wxT("%i%%"), &m_ColsInfo
[c
].width
) == 1 )
295 m_ColsInfo
[c
].units
= wxHTML_UNITS_PERCENT
;
301 if ( wd
.ToLong(&width
) )
303 m_ColsInfo
[c
].width
= (int)(m_PixelScale
* (double)width
);
304 m_ColsInfo
[c
].units
= wxHTML_UNITS_PIXELS
;
313 tag
.GetParamAsInt(wxT("COLSPAN"), &m_CellInfo
[r
][c
].colspan
);
314 tag
.GetParamAsInt(wxT("ROWSPAN"), &m_CellInfo
[r
][c
].rowspan
);
316 // VS: the standard says this about col/rowspan:
317 // "This attribute specifies the number of rows spanned by the
318 // current cell. The default value of this attribute is one ("1").
319 // The value zero ("0") means that the cell spans all rows from the
320 // current row to the last row of the table." All mainstream
321 // browsers act as if 0==1, though, and so does wxHTML.
322 if (m_CellInfo
[r
][c
].colspan
< 1)
323 m_CellInfo
[r
][c
].colspan
= 1;
324 if (m_CellInfo
[r
][c
].rowspan
< 1)
325 m_CellInfo
[r
][c
].rowspan
= 1;
327 if ((m_CellInfo
[r
][c
].colspan
> 1) || (m_CellInfo
[r
][c
].rowspan
> 1))
331 if (r
+ m_CellInfo
[r
][c
].rowspan
> m_NumRows
)
332 ReallocRows(r
+ m_CellInfo
[r
][c
].rowspan
);
333 if (c
+ m_CellInfo
[r
][c
].colspan
> m_NumCols
)
334 ReallocCols(c
+ m_CellInfo
[r
][c
].colspan
);
335 for (i
= r
; i
< r
+ m_CellInfo
[r
][c
].rowspan
; i
++)
336 for (j
= c
; j
< c
+ m_CellInfo
[r
][c
].colspan
; j
++)
337 m_CellInfo
[i
][j
].flag
= cellSpan
;
338 m_CellInfo
[r
][c
].flag
= cellUsed
;
344 wxColour bk
= m_rBkg
;
345 if (tag
.HasParam(wxT("BGCOLOR")))
346 tag
.GetParamAsColour(wxT("BGCOLOR"), &bk
);
348 cell
->SetBackgroundColour(bk
);
351 cell
->SetBorder(TABLE_BORDER_CLR_2
, TABLE_BORDER_CLR_1
);
353 // vertical alignment:
356 if (tag
.HasParam(wxT("VALIGN")))
357 valign
= tag
.GetParam(wxT("VALIGN"));
361 if (valign
== wxT("TOP"))
362 m_CellInfo
[r
][c
].valign
= wxHTML_ALIGN_TOP
;
363 else if (valign
== wxT("BOTTOM"))
364 m_CellInfo
[r
][c
].valign
= wxHTML_ALIGN_BOTTOM
;
365 else m_CellInfo
[r
][c
].valign
= wxHTML_ALIGN_CENTER
;
369 if (tag
.HasParam(wxT("NOWRAP")))
370 m_CellInfo
[r
][c
].nowrap
= true;
372 m_CellInfo
[r
][c
].nowrap
= false;
374 cell
->SetIndent(m_Padding
, wxHTML_INDENT_ALL
, wxHTML_UNITS_PIXELS
);
377 void wxHtmlTableCell::ComputeMinMaxWidths()
379 if (m_NumCols
== 0 || m_ColsInfo
[0].minWidth
!= wxDefaultCoord
) return;
383 for (int c
= 0; c
< m_NumCols
; c
++)
385 for (int r
= 0; r
< m_NumRows
; r
++)
387 cellStruct
& cell
= m_CellInfo
[r
][c
];
388 if (cell
.flag
== cellUsed
)
390 cell
.cont
->Layout(2*m_Padding
+ 1);
391 int maxWidth
= cell
.cont
->GetMaxTotalWidth();
392 int width
= cell
.nowrap
?maxWidth
:cell
.cont
->GetWidth();
393 width
-= (cell
.colspan
-1) * m_Spacing
;
394 maxWidth
-= (cell
.colspan
-1) * m_Spacing
;
395 // HTML 4.0 says it is acceptable to distribute min/max
396 width
/= cell
.colspan
;
397 maxWidth
/= cell
.colspan
;
398 for (int j
= 0; j
< cell
.colspan
; j
++) {
399 if (width
> m_ColsInfo
[c
+j
].minWidth
)
400 m_ColsInfo
[c
+j
].minWidth
= width
;
401 if (maxWidth
> m_ColsInfo
[c
+j
].maxWidth
)
402 m_ColsInfo
[c
+j
].maxWidth
= maxWidth
;
406 // Calculate maximum table width, required for nested tables
407 if (m_ColsInfo
[c
].units
== wxHTML_UNITS_PIXELS
)
408 m_MaxTotalWidth
+= wxMax(m_ColsInfo
[c
].width
, m_ColsInfo
[c
].minWidth
);
409 else if ((m_ColsInfo
[c
].units
== wxHTML_UNITS_PERCENT
) && (m_ColsInfo
[c
].width
!= 0))
410 percentage
+= m_ColsInfo
[c
].width
;
412 m_MaxTotalWidth
+= m_ColsInfo
[c
].maxWidth
;
415 if (percentage
>= 100)
417 // Table would have infinite length
418 // Make it ridiculous large
419 m_MaxTotalWidth
= 0xFFFFFF;
422 m_MaxTotalWidth
= m_MaxTotalWidth
* 100 / (100 - percentage
);
424 m_MaxTotalWidth
+= (m_NumCols
+ 1) * m_Spacing
+ 2 * m_Border
;
427 void wxHtmlTableCell::Layout(int w
)
429 ComputeMinMaxWidths();
431 wxHtmlCell::Layout(w
);
439 if (m_WidthFloatUnits
== wxHTML_UNITS_PERCENT
)
441 if (m_WidthFloat
< 0)
443 if (m_WidthFloat
< -100)
445 m_Width
= (100 + m_WidthFloat
) * w
/ 100;
449 if (m_WidthFloat
> 100)
451 m_Width
= m_WidthFloat
* w
/ 100;
456 if (m_WidthFloat
< 0) m_Width
= w
+ m_WidthFloat
;
457 else m_Width
= m_WidthFloat
;
467 /* 1. setup columns widths:
469 The algorithm tries to keep the table size less than w if possible.
472 int wpix
= m_Width
- (m_NumCols
+ 1) * m_Spacing
- 2 * m_Border
; // Available space for cell content
475 // 1a. setup fixed-width columns:
476 for (i
= 0; i
< m_NumCols
; i
++)
477 if (m_ColsInfo
[i
].units
== wxHTML_UNITS_PIXELS
)
479 m_ColsInfo
[i
].pixwidth
= wxMax(m_ColsInfo
[i
].width
,
480 m_ColsInfo
[i
].minWidth
);
481 wpix
-= m_ColsInfo
[i
].pixwidth
;
484 // 1b. Calculate maximum possible width if line wrapping would be disabled
485 // Recalculate total width if m_WidthFloat is zero to keep tables as small
488 for (i
= 0; i
< m_NumCols
; i
++)
489 if (m_ColsInfo
[i
].width
== 0)
491 maxWidth
+= m_ColsInfo
[i
].maxWidth
;
496 // Recalculate table width since no table width was initially given
497 int newWidth
= m_Width
- wpix
+ maxWidth
;
499 // Make sure that floating-width columns will have the right size.
500 // Calculate sum of all floating-width columns
502 for (i
= 0; i
< m_NumCols
; i
++)
503 if ((m_ColsInfo
[i
].units
== wxHTML_UNITS_PERCENT
) && (m_ColsInfo
[i
].width
!= 0))
504 percentage
+= m_ColsInfo
[i
].width
;
506 if (percentage
>= 100)
509 newWidth
= newWidth
* 100 / (100 - percentage
);
511 newWidth
= wxMin(newWidth
, w
- (m_NumCols
+ 1) * m_Spacing
- 2 * m_Border
);
512 wpix
-= m_Width
- newWidth
;
517 // 1c. setup floating-width columns:
519 for (i
= 0; i
< m_NumCols
; i
++)
520 if ((m_ColsInfo
[i
].units
== wxHTML_UNITS_PERCENT
) && (m_ColsInfo
[i
].width
!= 0))
522 m_ColsInfo
[i
].pixwidth
= wxMin(m_ColsInfo
[i
].width
, 100) * wpix
/ 100;
524 // Make sure to leave enough space for the other columns
525 int minRequired
= m_Border
;
526 for (j
= 0; j
< m_NumCols
; j
++)
528 if ((m_ColsInfo
[j
].units
== wxHTML_UNITS_PERCENT
&& j
> i
) ||
529 !m_ColsInfo
[j
].width
)
530 minRequired
+= m_ColsInfo
[j
].minWidth
;
532 m_ColsInfo
[i
].pixwidth
= wxMax(wxMin(wtemp
- minRequired
, m_ColsInfo
[i
].pixwidth
), m_ColsInfo
[i
].minWidth
);
534 wtemp
-= m_ColsInfo
[i
].pixwidth
;
536 wpix
= wtemp
; // minimum cells width
538 // 1d. setup default columns (no width specification supplied):
539 // The algorithm assigns calculates the maximum possible width if line
540 // wrapping would be disabled and assigns column width as a fraction
541 // based upon the maximum width of a column
542 // FIXME: I'm not sure if this algorithm is conform to HTML standard,
543 // though it seems to be much better than the old one
545 for (i
= j
= 0; i
< m_NumCols
; i
++)
546 if (m_ColsInfo
[i
].width
== 0) j
++;
551 for (i
= 0; i
< m_NumCols
; i
++)
552 if (m_ColsInfo
[i
].width
== 0)
554 // Assign with, make sure not to drop below minWidth
556 m_ColsInfo
[i
].pixwidth
= (int)(wpix
* (m_ColsInfo
[i
].maxWidth
/ (float)maxWidth
) + 0.5);
558 m_ColsInfo
[i
].pixwidth
= wpix
/ j
;
560 // Make sure to leave enough space for the other columns
563 for (r
= i
+ 1; r
< m_NumCols
; r
++)
565 if (!m_ColsInfo
[r
].width
)
566 minRequired
+= m_ColsInfo
[r
].minWidth
;
568 m_ColsInfo
[i
].pixwidth
= wxMax(wxMin(wpix
- minRequired
, m_ColsInfo
[i
].pixwidth
), m_ColsInfo
[i
].minWidth
);
572 if (m_ColsInfo
[i
].pixwidth
> (wpix
* (m_ColsInfo
[i
].maxWidth
/ (float)maxWidth
) + 0.5))
574 int diff
= (int)(m_ColsInfo
[i
].pixwidth
- (wpix
* m_ColsInfo
[i
].maxWidth
/ (float)maxWidth
+ 0.5));
575 maxWidth
+= diff
- m_ColsInfo
[i
].maxWidth
;
578 maxWidth
-= m_ColsInfo
[i
].maxWidth
;
580 wpix
-= m_ColsInfo
[i
].pixwidth
;
584 /* 2. compute positions of columns: */
586 int wpos
= m_Spacing
+ m_Border
;
587 for (int i
= 0; i
< m_NumCols
; i
++)
589 m_ColsInfo
[i
].leftpos
= wpos
;
590 wpos
+= m_ColsInfo
[i
].pixwidth
+ m_Spacing
;
593 // add the remaining space to the last column
594 if (m_NumCols
> 0 && wpos
< m_Width
- m_Border
)
595 m_ColsInfo
[m_NumCols
-1].pixwidth
+= m_Width
- wpos
- m_Border
;
598 /* 3. sub-layout all cells: */
600 int *ypos
= new int[m_NumRows
+ 1];
604 wxHtmlContainerCell
*actcell
;
606 ypos
[0] = m_Spacing
+ m_Border
;
607 for (actrow
= 1; actrow
<= m_NumRows
; actrow
++) ypos
[actrow
] = -1;
608 for (actrow
= 0; actrow
< m_NumRows
; actrow
++)
610 if (ypos
[actrow
] == -1) ypos
[actrow
] = ypos
[actrow
-1];
611 // 3a. sub-layout and detect max height:
613 for (actcol
= 0; actcol
< m_NumCols
; actcol
++) {
614 if (m_CellInfo
[actrow
][actcol
].flag
!= cellUsed
) continue;
615 actcell
= m_CellInfo
[actrow
][actcol
].cont
;
617 for (int i
= actcol
; i
< m_CellInfo
[actrow
][actcol
].colspan
+ actcol
; i
++)
618 fullwid
+= m_ColsInfo
[i
].pixwidth
;
619 fullwid
+= (m_CellInfo
[actrow
][actcol
].colspan
- 1) * m_Spacing
;
620 actcell
->SetMinHeight(m_CellInfo
[actrow
][actcol
].minheight
, m_CellInfo
[actrow
][actcol
].valign
);
621 actcell
->Layout(fullwid
);
623 if (ypos
[actrow
] + actcell
->GetHeight() + m_CellInfo
[actrow
][actcol
].rowspan
* m_Spacing
> ypos
[actrow
+ m_CellInfo
[actrow
][actcol
].rowspan
])
624 ypos
[actrow
+ m_CellInfo
[actrow
][actcol
].rowspan
] =
625 ypos
[actrow
] + actcell
->GetHeight() + m_CellInfo
[actrow
][actcol
].rowspan
* m_Spacing
;
629 for (actrow
= 0; actrow
< m_NumRows
; actrow
++)
631 // 3b. place cells in row & let'em all have same height:
633 for (actcol
= 0; actcol
< m_NumCols
; actcol
++)
635 if (m_CellInfo
[actrow
][actcol
].flag
!= cellUsed
) continue;
636 actcell
= m_CellInfo
[actrow
][actcol
].cont
;
637 actcell
->SetMinHeight(
638 ypos
[actrow
+ m_CellInfo
[actrow
][actcol
].rowspan
] - ypos
[actrow
] - m_Spacing
,
639 m_CellInfo
[actrow
][actcol
].valign
);
641 for (int i
= actcol
; i
< m_CellInfo
[actrow
][actcol
].colspan
+ actcol
; i
++)
642 fullwid
+= m_ColsInfo
[i
].pixwidth
;
643 fullwid
+= (m_CellInfo
[actrow
][actcol
].colspan
- 1) * m_Spacing
;
644 actcell
->Layout(fullwid
);
645 actcell
->SetPos(m_ColsInfo
[actcol
].leftpos
, ypos
[actrow
]);
648 m_Height
= ypos
[m_NumRows
] + m_Border
;
652 /* 4. adjust table's width if it was too small: */
655 int twidth
= m_ColsInfo
[m_NumCols
-1].leftpos
+
656 m_ColsInfo
[m_NumCols
-1].pixwidth
+ m_Spacing
+ m_Border
;
657 if (twidth
> m_Width
)
667 //-----------------------------------------------------------------------------
668 // The tables handler:
669 //-----------------------------------------------------------------------------
672 TAG_HANDLER_BEGIN(TABLE
, "TABLE,TR,TD,TH")
675 wxHtmlTableCell
* m_Table
;
676 wxString m_tAlign
, m_rAlign
;
677 wxHtmlContainerCell
*m_enclosingContainer
;
679 TAG_HANDLER_CONSTR(TABLE
)
682 m_enclosingContainer
= NULL
;
683 m_tAlign
= m_rAlign
= wxEmptyString
;
687 TAG_HANDLER_PROC(tag
)
689 wxHtmlContainerCell
*c
;
691 // new table started, backup upper-level table (if any) and create new:
692 if (tag
.GetName() == wxT("TABLE"))
694 wxHtmlTableCell
*oldt
= m_Table
;
696 wxHtmlContainerCell
*oldEnclosing
= m_enclosingContainer
;
697 m_enclosingContainer
= c
= m_WParser
->OpenContainer();
699 m_Table
= new wxHtmlTableCell(c
, tag
, m_WParser
->GetPixelScale());
703 if (tag
.HasParam(wxT("WIDTH")))
705 wxString wd
= tag
.GetParam(wxT("WIDTH"));
707 if (wd
[wd
.length()-1] == wxT('%'))
710 wxSscanf(wd
.c_str(), wxT("%i%%"), &width
);
711 m_Table
->SetWidthFloat(width
, wxHTML_UNITS_PERCENT
);
716 wxSscanf(wd
.c_str(), wxT("%i"), &width
);
717 m_Table
->SetWidthFloat((int)(m_WParser
->GetPixelScale() * width
), wxHTML_UNITS_PIXELS
);
721 m_Table
->SetWidthFloat(0, wxHTML_UNITS_PIXELS
);
723 int oldAlign
= m_WParser
->GetAlign();
724 m_tAlign
= wxEmptyString
;
725 if (tag
.HasParam(wxT("ALIGN")))
726 m_tAlign
= tag
.GetParam(wxT("ALIGN"));
730 m_WParser
->SetAlign(oldAlign
);
731 m_WParser
->SetContainer(m_enclosingContainer
);
732 m_WParser
->CloseContainer();
735 m_enclosingContainer
= oldEnclosing
;
737 return true; // ParseInner() called
744 if (tag
.GetName() == wxT("TR"))
746 m_Table
->AddRow(tag
);
748 if (tag
.HasParam(wxT("ALIGN")))
749 m_rAlign
= tag
.GetParam(wxT("ALIGN"));
755 c
= m_WParser
->SetContainer(new wxHtmlContainerCell(m_Table
));
756 m_Table
->AddCell(c
, tag
);
758 m_WParser
->OpenContainer();
760 const bool isHeader
= tag
.GetName() == wxT("TH");
763 if (tag
.HasParam(wxT("ALIGN")))
764 als
= tag
.GetParam(wxT("ALIGN"));
769 if (als
== wxT("RIGHT"))
770 m_WParser
->SetAlign(wxHTML_ALIGN_RIGHT
);
771 else if (als
== wxT("LEFT"))
772 m_WParser
->SetAlign(wxHTML_ALIGN_LEFT
);
773 else if (als
== wxT("CENTER"))
774 m_WParser
->SetAlign(wxHTML_ALIGN_CENTER
);
775 else // use default alignment
776 m_WParser
->SetAlign(isHeader
? wxHTML_ALIGN_CENTER
777 : wxHTML_ALIGN_LEFT
);
779 m_WParser
->OpenContainer();
781 // the header should be rendered in bold by default
785 boldOld
= m_WParser
->GetFontBold();
786 m_WParser
->SetFontBold(true);
787 m_WParser
->GetContainer()->InsertCell(
788 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
795 m_WParser
->SetFontBold(boldOld
);
796 m_WParser
->GetContainer()->InsertCell(
797 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
800 // set the current container back to the enclosing one so that
801 // text outside of <th> and <td> isn't included in any cell
802 // (this happens often enough in practice because it's common
803 // to use whitespace between </td> and the next <td>):
804 m_WParser
->SetContainer(m_enclosingContainer
);
806 return true; // ParseInner() called
813 TAG_HANDLER_END(TABLE
)
819 TAGS_MODULE_BEGIN(Tables
)
821 TAGS_MODULE_ADD(TABLE
)
823 TAGS_MODULE_END(Tables
)