]>
Commit | Line | Data |
---|---|---|
5526e819 | 1 | ///////////////////////////////////////////////////////////////////////////// |
c88293a4 | 2 | // Name: m_tables.cpp |
5526e819 VS |
3 | // Purpose: wxHtml module for tables |
4 | // Author: Vaclav Slavik | |
69941f05 | 5 | // RCS-ID: $Id$ |
5526e819 VS |
6 | // Copyright: (c) 1999 Vaclav Slavik |
7 | // Licence: wxWindows Licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
3364ab79 RS |
10 | #ifdef __GNUG__ |
11 | #pragma implementation | |
12 | #endif | |
13 | ||
3096bd2f | 14 | #include "wx/wxprec.h" |
3364ab79 | 15 | |
314260fb | 16 | #include "wx/defs.h" |
f6bcfd97 | 17 | #if wxUSE_HTML && wxUSE_STREAMS |
2b5f62a0 | 18 | #ifdef __BORLANDC__ |
3364ab79 RS |
19 | #pragma hdrstop |
20 | #endif | |
21 | ||
22 | #ifndef WXPRECOMP | |
3364ab79 RS |
23 | #endif |
24 | ||
5526e819 VS |
25 | |
26 | /* | |
27 | REMARKS: | |
c88293a4 | 28 | 1. This version of m_tables doesn't support auto-layout algorithm. |
5526e819 VS |
29 | This means that all columns are of same width unless explicitly specified. |
30 | */ | |
31 | ||
32 | ||
69941f05 VS |
33 | #include "wx/html/forcelnk.h" |
34 | #include "wx/html/m_templ.h" | |
5526e819 | 35 | |
69941f05 | 36 | #include "wx/html/htmlcell.h" |
5526e819 | 37 | |
c88293a4 | 38 | FORCE_LINK_ME(m_tables) |
5526e819 VS |
39 | |
40 | ||
41 | #define TABLE_BORDER_CLR_1 wxColour(0xC5, 0xC2, 0xC5) | |
42 | #define TABLE_BORDER_CLR_2 wxColour(0x62, 0x61, 0x62) | |
43 | ||
44 | ||
45 | //----------------------------------------------------------------------------- | |
46 | // wxHtmlTableCell | |
47 | //----------------------------------------------------------------------------- | |
48 | ||
49 | ||
79d6c018 VS |
50 | struct colStruct |
51 | { | |
52 | int width, units; | |
53 | // width of the column either in pixels or percents | |
54 | // ('width' is the number, 'units' determines its meaning) | |
55 | int minWidth, maxWidth; | |
56 | // minimal/maximal column width. This is needed by HTML 4.0 | |
57 | // layouting algorithm and can be determined by trying to | |
58 | // layout table cells with width=1 and width=infinity | |
59 | int leftpos, pixwidth, maxrealwidth; | |
60 | // temporary (depends on actual width of table) | |
61 | }; | |
62 | ||
63 | enum cellState | |
64 | { | |
65 | cellSpan, | |
66 | cellUsed, | |
67 | cellFree | |
68 | }; | |
69 | ||
70 | struct cellStruct | |
71 | { | |
72 | wxHtmlContainerCell *cont; | |
73 | int colspan, rowspan; | |
74 | int minheight, valign; | |
75 | cellState flag; | |
76 | }; | |
5526e819 VS |
77 | |
78 | ||
79 | class wxHtmlTableCell : public wxHtmlContainerCell | |
80 | { | |
79d6c018 VS |
81 | protected: |
82 | /* These are real attributes: */ | |
83 | ||
84 | // should we draw borders or not? | |
85 | bool m_HasBorders; | |
86 | // number of columns; rows | |
87 | int m_NumCols, m_NumRows; | |
88 | // array of column information | |
89 | colStruct *m_ColsInfo; | |
90 | // 2D array of all cells in the table : m_CellInfo[row][column] | |
91 | cellStruct **m_CellInfo; | |
92 | // spaces between cells | |
93 | int m_Spacing; | |
94 | // cells internal indentation | |
95 | int m_Padding; | |
96 | ||
97 | private: | |
98 | /* ...and these are valid only when parsing the table: */ | |
99 | ||
100 | // number of actual column (ranging from 0..m_NumCols) | |
101 | int m_ActualCol, m_ActualRow; | |
102 | ||
103 | // default values (for table and row): | |
104 | wxColour m_tBkg, m_rBkg; | |
105 | wxString m_tValign, m_rValign; | |
106 | ||
107 | double m_PixelScale; | |
108 | ||
109 | ||
110 | public: | |
111 | wxHtmlTableCell(wxHtmlContainerCell *parent, const wxHtmlTag& tag, double pixel_scale = 1.0); | |
112 | ~wxHtmlTableCell(); | |
113 | virtual void Layout(int w); | |
114 | ||
115 | void AddRow(const wxHtmlTag& tag); | |
116 | void AddCell(wxHtmlContainerCell *cell, const wxHtmlTag& tag); | |
117 | ||
118 | private: | |
119 | // Reallocates memory to given number of cols/rows | |
120 | // and changes m_NumCols/m_NumRows value to reflect this change | |
121 | // NOTE! You CAN'T change m_NumCols/m_NumRows before calling this!! | |
122 | void ReallocCols(int cols); | |
123 | void ReallocRows(int rows); | |
124 | ||
125 | // Computes minimal and maximal widths of columns. Needs to be called | |
126 | // only once, before first Layout(). | |
127 | void ComputeMinMaxWidths(); | |
5526e819 VS |
128 | }; |
129 | ||
130 | ||
131 | ||
edbd0635 | 132 | wxHtmlTableCell::wxHtmlTableCell(wxHtmlContainerCell *parent, const wxHtmlTag& tag, double pixel_scale) |
5526e819 VS |
133 | : wxHtmlContainerCell(parent) |
134 | { | |
edbd0635 | 135 | m_PixelScale = pixel_scale; |
b0bdbbfe VS |
136 | m_HasBorders = |
137 | (tag.HasParam(wxT("BORDER")) && tag.GetParam(wxT("BORDER")) != wxT("0")); | |
5526e819 VS |
138 | m_ColsInfo = NULL; |
139 | m_NumCols = m_NumRows = 0; | |
140 | m_CellInfo = NULL; | |
141 | m_ActualCol = m_ActualRow = -1; | |
142 | ||
143 | /* scan params: */ | |
04dbb646 | 144 | if (tag.HasParam(wxT("BGCOLOR"))) |
8bd72d90 | 145 | tag.GetParamAsColour(wxT("BGCOLOR"), &m_tBkg); |
04dbb646 VZ |
146 | if (tag.HasParam(wxT("VALIGN"))) |
147 | m_tValign = tag.GetParam(wxT("VALIGN")); | |
148 | else | |
8bd72d90 VS |
149 | m_tValign = wxEmptyString; |
150 | if (!tag.GetParamAsInt(wxT("CELLSPACING"), &m_Spacing)) | |
151 | m_Spacing = 2; | |
152 | if (!tag.GetParamAsInt(wxT("CELLPADDING"), &m_Padding)) | |
153 | m_Padding = 3; | |
edbd0635 VS |
154 | m_Spacing = (int)(m_PixelScale * (double)m_Spacing); |
155 | m_Padding = (int)(m_PixelScale * (double)m_Padding); | |
5526e819 VS |
156 | |
157 | if (m_HasBorders) | |
158 | SetBorder(TABLE_BORDER_CLR_1, TABLE_BORDER_CLR_2); | |
159 | } | |
160 | ||
161 | ||
162 | ||
163 | wxHtmlTableCell::~wxHtmlTableCell() | |
164 | { | |
165 | if (m_ColsInfo) free(m_ColsInfo); | |
04dbb646 | 166 | if (m_CellInfo) |
4f9297b0 | 167 | { |
5526e819 VS |
168 | for (int i = 0; i < m_NumRows; i++) |
169 | free(m_CellInfo[i]); | |
170 | free(m_CellInfo); | |
171 | } | |
172 | } | |
173 | ||
174 | ||
175 | ||
176 | void wxHtmlTableCell::ReallocCols(int cols) | |
177 | { | |
178 | int i,j; | |
179 | ||
04dbb646 | 180 | for (i = 0; i < m_NumRows; i++) |
4f9297b0 | 181 | { |
5526e819 VS |
182 | m_CellInfo[i] = (cellStruct*) realloc(m_CellInfo[i], sizeof(cellStruct) * cols); |
183 | for (j = m_NumCols; j < cols; j++) | |
184 | m_CellInfo[i][j].flag = cellFree; | |
185 | } | |
186 | ||
187 | m_ColsInfo = (colStruct*) realloc(m_ColsInfo, sizeof(colStruct) * cols); | |
04dbb646 | 188 | for (j = m_NumCols; j < cols; j++) |
4f9297b0 | 189 | { |
5526e819 | 190 | m_ColsInfo[j].width = 0; |
efba2b89 | 191 | m_ColsInfo[j].units = wxHTML_UNITS_PERCENT; |
79d6c018 | 192 | m_ColsInfo[j].minWidth = m_ColsInfo[j].maxWidth = -1; |
5526e819 VS |
193 | } |
194 | ||
195 | m_NumCols = cols; | |
196 | } | |
197 | ||
198 | ||
199 | ||
200 | void wxHtmlTableCell::ReallocRows(int rows) | |
201 | { | |
202 | m_CellInfo = (cellStruct**) realloc(m_CellInfo, sizeof(cellStruct*) * rows); | |
04dbb646 | 203 | for (int row = m_NumRows; row < rows ; row++) |
80eab469 | 204 | { |
04dbb646 | 205 | if (m_NumCols == 0) |
80eab469 | 206 | m_CellInfo[row] = NULL; |
04dbb646 | 207 | else |
80eab469 VS |
208 | { |
209 | m_CellInfo[row] = (cellStruct*) malloc(sizeof(cellStruct) * m_NumCols); | |
210 | for (int col = 0; col < m_NumCols; col++) | |
211 | m_CellInfo[row][col].flag = cellFree; | |
212 | } | |
5526e819 | 213 | } |
5526e819 VS |
214 | m_NumRows = rows; |
215 | } | |
216 | ||
217 | ||
5526e819 VS |
218 | void wxHtmlTableCell::AddRow(const wxHtmlTag& tag) |
219 | { | |
5526e819 | 220 | m_ActualCol = -1; |
d361bbff VS |
221 | // VS: real allocation of row entry is done in AddCell in order |
222 | // to correctly handle empty rows (i.e. "<tr></tr>") | |
223 | // m_ActualCol == -1 indicates that AddCell has to allocate new row. | |
5526e819 | 224 | |
d361bbff | 225 | // scan params: |
5526e819 | 226 | m_rBkg = m_tBkg; |
04dbb646 | 227 | if (tag.HasParam(wxT("BGCOLOR"))) |
8bd72d90 | 228 | tag.GetParamAsColour(wxT("BGCOLOR"), &m_rBkg); |
04dbb646 VZ |
229 | if (tag.HasParam(wxT("VALIGN"))) |
230 | m_rValign = tag.GetParam(wxT("VALIGN")); | |
231 | else | |
d361bbff | 232 | m_rValign = m_tValign; |
5526e819 VS |
233 | } |
234 | ||
235 | ||
236 | ||
237 | void wxHtmlTableCell::AddCell(wxHtmlContainerCell *cell, const wxHtmlTag& tag) | |
238 | { | |
d361bbff VS |
239 | // Is this cell in new row? |
240 | // VS: we can't do it in AddRow, see my comment there | |
241 | if (m_ActualCol == -1) | |
242 | { | |
243 | if (m_ActualRow + 1 > m_NumRows - 1) | |
244 | ReallocRows(m_ActualRow + 2); | |
245 | m_ActualRow++; | |
246 | } | |
247 | ||
248 | // cells & columns: | |
04dbb646 | 249 | do |
4f9297b0 | 250 | { |
5526e819 | 251 | m_ActualCol++; |
04dbb646 | 252 | } while ((m_ActualCol < m_NumCols) && |
8bd72d90 | 253 | (m_CellInfo[m_ActualRow][m_ActualCol].flag != cellFree)); |
04dbb646 | 254 | |
5526e819 VS |
255 | if (m_ActualCol > m_NumCols - 1) |
256 | ReallocCols(m_ActualCol + 1); | |
257 | ||
258 | int r = m_ActualRow, c = m_ActualCol; | |
259 | ||
260 | m_CellInfo[r][c].cont = cell; | |
261 | m_CellInfo[r][c].colspan = 1; | |
262 | m_CellInfo[r][c].rowspan = 1; | |
263 | m_CellInfo[r][c].flag = cellUsed; | |
264 | m_CellInfo[r][c].minheight = 0; | |
efba2b89 | 265 | m_CellInfo[r][c].valign = wxHTML_ALIGN_TOP; |
5526e819 VS |
266 | |
267 | /* scan for parameters: */ | |
268 | ||
269 | // width: | |
270 | { | |
8bd72d90 | 271 | if (tag.HasParam(wxT("WIDTH"))) |
2fa3b707 | 272 | { |
8bd72d90 | 273 | wxString wd = tag.GetParam(wxT("WIDTH")); |
5526e819 | 274 | |
8bd72d90 | 275 | if (wd[wd.Length()-1] == wxT('%')) |
2fa3b707 | 276 | { |
66a77a74 | 277 | wxSscanf(wd.c_str(), wxT("%i%%"), &m_ColsInfo[c].width); |
efba2b89 | 278 | m_ColsInfo[c].units = wxHTML_UNITS_PERCENT; |
5526e819 | 279 | } |
04dbb646 | 280 | else |
2fa3b707 | 281 | { |
66a77a74 | 282 | wxSscanf(wd.c_str(), wxT("%i"), &m_ColsInfo[c].width); |
edbd0635 | 283 | m_ColsInfo[c].width = (int)(m_PixelScale * (double)m_ColsInfo[c].width); |
efba2b89 | 284 | m_ColsInfo[c].units = wxHTML_UNITS_PIXELS; |
5526e819 VS |
285 | } |
286 | } | |
287 | } | |
288 | ||
289 | ||
290 | // spanning: | |
291 | { | |
8bd72d90 VS |
292 | tag.GetParamAsInt(wxT("COLSPAN"), &m_CellInfo[r][c].colspan); |
293 | tag.GetParamAsInt(wxT("ROWSPAN"), &m_CellInfo[r][c].rowspan); | |
fbe77cea VS |
294 | |
295 | // VS: the standard says this about col/rowspan: | |
296 | // "This attribute specifies the number of rows spanned by the | |
297 | // current cell. The default value of this attribute is one ("1"). | |
298 | // The value zero ("0") means that the cell spans all rows from the | |
299 | // current row to the last row of the table." All mainstream | |
300 | // browsers act as if 0==1, though, and so does wxHTML. | |
301 | if (m_CellInfo[r][c].colspan < 1) | |
302 | m_CellInfo[r][c].colspan = 1; | |
303 | if (m_CellInfo[r][c].rowspan < 1) | |
304 | m_CellInfo[r][c].rowspan = 1; | |
305 | ||
306 | if ((m_CellInfo[r][c].colspan > 1) || (m_CellInfo[r][c].rowspan > 1)) | |
2fa3b707 | 307 | { |
5526e819 VS |
308 | int i, j; |
309 | ||
04dbb646 | 310 | if (r + m_CellInfo[r][c].rowspan > m_NumRows) |
8bd72d90 | 311 | ReallocRows(r + m_CellInfo[r][c].rowspan); |
04dbb646 | 312 | if (c + m_CellInfo[r][c].colspan > m_NumCols) |
8bd72d90 | 313 | ReallocCols(c + m_CellInfo[r][c].colspan); |
5526e819 VS |
314 | for (i = r; i < r + m_CellInfo[r][c].rowspan; i++) |
315 | for (j = c; j < c + m_CellInfo[r][c].colspan; j++) | |
316 | m_CellInfo[i][j].flag = cellSpan; | |
317 | m_CellInfo[r][c].flag = cellUsed; | |
318 | } | |
319 | } | |
320 | ||
321 | //background color: | |
322 | { | |
8bd72d90 | 323 | wxColour bk = m_rBkg; |
04dbb646 | 324 | if (tag.HasParam(wxT("BGCOLOR"))) |
8bd72d90 VS |
325 | tag.GetParamAsColour(wxT("BGCOLOR"), &bk); |
326 | if (bk.Ok()) | |
327 | cell->SetBackgroundColour(bk); | |
5526e819 VS |
328 | } |
329 | if (m_HasBorders) | |
4f9297b0 | 330 | cell->SetBorder(TABLE_BORDER_CLR_2, TABLE_BORDER_CLR_1); |
5526e819 VS |
331 | |
332 | // vertical alignment: | |
333 | { | |
334 | wxString valign; | |
04dbb646 VZ |
335 | if (tag.HasParam(wxT("VALIGN"))) |
336 | valign = tag.GetParam(wxT("VALIGN")); | |
337 | else | |
8bd72d90 | 338 | valign = m_tValign; |
5526e819 | 339 | valign.MakeUpper(); |
04dbb646 | 340 | if (valign == wxT("TOP")) |
8bd72d90 | 341 | m_CellInfo[r][c].valign = wxHTML_ALIGN_TOP; |
04dbb646 | 342 | else if (valign == wxT("BOTTOM")) |
8bd72d90 | 343 | m_CellInfo[r][c].valign = wxHTML_ALIGN_BOTTOM; |
efba2b89 | 344 | else m_CellInfo[r][c].valign = wxHTML_ALIGN_CENTER; |
5526e819 VS |
345 | } |
346 | ||
4f9297b0 | 347 | cell->SetIndent(m_Padding, wxHTML_INDENT_ALL, wxHTML_UNITS_PIXELS); |
5526e819 VS |
348 | } |
349 | ||
79d6c018 VS |
350 | void wxHtmlTableCell::ComputeMinMaxWidths() |
351 | { | |
352 | if (m_NumCols == 0 || m_ColsInfo[0].minWidth != -1) return; | |
353 | ||
354 | int left, right, width; | |
355 | ||
79d6c018 VS |
356 | for (int c = 0; c < m_NumCols; c++) |
357 | { | |
358 | for (int r = 0; r < m_NumRows; r++) | |
359 | { | |
360 | cellStruct& cell = m_CellInfo[r][c]; | |
361 | if (cell.flag == cellUsed) | |
362 | { | |
026d1fac | 363 | cell.cont->Layout(2*m_Padding + 1); |
79d6c018 | 364 | cell.cont->GetHorizontalConstraints(&left, &right); |
026d1fac VS |
365 | width = right - left; |
366 | width -= (cell.colspan-1) * m_Spacing; | |
79d6c018 VS |
367 | // HTML 4.0 says it is acceptable to distribute min/max |
368 | // width of spanning cells evently | |
369 | width /= cell.colspan; | |
79d6c018 VS |
370 | for (int j = 0; j < cell.colspan; j++) |
371 | if (width > m_ColsInfo[c+j].minWidth) | |
372 | m_ColsInfo[c+j].minWidth = width; | |
373 | } | |
374 | } | |
375 | } | |
376 | ||
377 | // FIXME -- compute maxWidth as well. Not needed yet, so there's no | |
378 | // point in computing it. | |
379 | } | |
5526e819 VS |
380 | |
381 | ||
382 | void wxHtmlTableCell::Layout(int w) | |
383 | { | |
79d6c018 | 384 | ComputeMinMaxWidths(); |
026d1fac VS |
385 | |
386 | wxHtmlCell::Layout(w); | |
79d6c018 | 387 | |
5526e819 VS |
388 | /* |
389 | ||
390 | WIDTH ADJUSTING : | |
391 | ||
392 | */ | |
393 | ||
04dbb646 | 394 | if (m_WidthFloatUnits == wxHTML_UNITS_PERCENT) |
4f9297b0 | 395 | { |
5526e819 VS |
396 | if (m_WidthFloat < 0) m_Width = (100 + m_WidthFloat) * w / 100; |
397 | else m_Width = m_WidthFloat * w / 100; | |
398 | } | |
04dbb646 | 399 | else |
4f9297b0 | 400 | { |
5526e819 VS |
401 | if (m_WidthFloat < 0) m_Width = w + m_WidthFloat; |
402 | else m_Width = m_WidthFloat; | |
403 | } | |
404 | ||
405 | ||
406 | /* | |
407 | ||
408 | LAYOUTING : | |
409 | ||
410 | */ | |
411 | ||
412 | /* 1. setup columns widths: */ | |
413 | { | |
414 | int wpix = m_Width - (m_NumCols + 1) * m_Spacing; | |
415 | int i, j; | |
5526e819 VS |
416 | |
417 | // 1a. setup fixed-width columns: | |
418 | for (i = 0; i < m_NumCols; i++) | |
efba2b89 | 419 | if (m_ColsInfo[i].units == wxHTML_UNITS_PIXELS) |
79d6c018 VS |
420 | { |
421 | m_ColsInfo[i].pixwidth = wxMax(m_ColsInfo[i].width, | |
422 | m_ColsInfo[i].minWidth); | |
423 | wpix -= m_ColsInfo[i].pixwidth; | |
424 | } | |
5526e819 VS |
425 | |
426 | // 1b. setup floating-width columns: | |
79d6c018 | 427 | int wtemp = 0; |
5526e819 | 428 | for (i = 0; i < m_NumCols; i++) |
efba2b89 | 429 | if ((m_ColsInfo[i].units == wxHTML_UNITS_PERCENT) && (m_ColsInfo[i].width != 0)) |
79d6c018 VS |
430 | { |
431 | m_ColsInfo[i].pixwidth = wxMax(m_ColsInfo[i].width * wpix / 100, | |
432 | m_ColsInfo[i].minWidth); | |
433 | wtemp += m_ColsInfo[i].pixwidth; | |
434 | } | |
5526e819 VS |
435 | wpix -= wtemp; |
436 | ||
437 | // 1c. setup defalut columns (no width specification supplied): | |
438 | // NOTE! This algorithm doesn't conform to HTML standard : it assigns equal widths | |
439 | // instead of optimal | |
440 | for (i = j = 0; i < m_NumCols; i++) | |
441 | if (m_ColsInfo[i].width == 0) j++; | |
442 | for (i = 0; i < m_NumCols; i++) | |
443 | if (m_ColsInfo[i].width == 0) | |
444 | m_ColsInfo[i].pixwidth = wpix / j; | |
445 | } | |
446 | ||
447 | /* 2. compute positions of columns: */ | |
448 | { | |
449 | int wpos = m_Spacing; | |
04dbb646 | 450 | for (int i = 0; i < m_NumCols; i++) |
2fa3b707 | 451 | { |
5526e819 VS |
452 | m_ColsInfo[i].leftpos = wpos; |
453 | wpos += m_ColsInfo[i].pixwidth + m_Spacing; | |
454 | } | |
455 | } | |
456 | ||
457 | /* 3. sub-layout all cells: */ | |
458 | { | |
2776d7c3 | 459 | int *ypos = new int[m_NumRows + 1]; |
5526e819 VS |
460 | |
461 | int actcol, actrow; | |
462 | int fullwid; | |
463 | wxHtmlContainerCell *actcell; | |
464 | ||
2fa3b707 VS |
465 | ypos[0] = m_Spacing; |
466 | for (actrow = 1; actrow <= m_NumRows; actrow++) ypos[actrow] = -1; | |
04dbb646 | 467 | for (actrow = 0; actrow < m_NumRows; actrow++) |
2fa3b707 VS |
468 | { |
469 | if (ypos[actrow] == -1) ypos[actrow] = ypos[actrow-1]; | |
5526e819 VS |
470 | // 3a. sub-layout and detect max height: |
471 | ||
472 | for (actcol = 0; actcol < m_NumCols; actcol++) { | |
473 | if (m_CellInfo[actrow][actcol].flag != cellUsed) continue; | |
474 | actcell = m_CellInfo[actrow][actcol].cont; | |
475 | fullwid = 0; | |
476 | for (int i = actcol; i < m_CellInfo[actrow][actcol].colspan + actcol; i++) | |
477 | fullwid += m_ColsInfo[i].pixwidth; | |
a97a264f | 478 | fullwid += (m_CellInfo[actrow][actcol].colspan - 1) * m_Spacing; |
4f9297b0 VS |
479 | actcell->SetMinHeight(m_CellInfo[actrow][actcol].minheight, m_CellInfo[actrow][actcol].valign); |
480 | actcell->Layout(fullwid); | |
5526e819 | 481 | |
4f9297b0 | 482 | if (ypos[actrow] + actcell->GetHeight() + m_CellInfo[actrow][actcol].rowspan * m_Spacing > ypos[actrow + m_CellInfo[actrow][actcol].rowspan]) |
5526e819 | 483 | ypos[actrow + m_CellInfo[actrow][actcol].rowspan] = |
4f9297b0 | 484 | ypos[actrow] + actcell->GetHeight() + m_CellInfo[actrow][actcol].rowspan * m_Spacing; |
5526e819 VS |
485 | } |
486 | } | |
487 | ||
04dbb646 | 488 | for (actrow = 0; actrow < m_NumRows; actrow++) |
2fa3b707 | 489 | { |
5526e819 VS |
490 | // 3b. place cells in row & let'em all have same height: |
491 | ||
04dbb646 | 492 | for (actcol = 0; actcol < m_NumCols; actcol++) |
2fa3b707 | 493 | { |
5526e819 VS |
494 | if (m_CellInfo[actrow][actcol].flag != cellUsed) continue; |
495 | actcell = m_CellInfo[actrow][actcol].cont; | |
4f9297b0 | 496 | actcell->SetMinHeight( |
a97a264f | 497 | ypos[actrow + m_CellInfo[actrow][actcol].rowspan] - ypos[actrow] - m_Spacing, |
5526e819 VS |
498 | m_CellInfo[actrow][actcol].valign); |
499 | fullwid = 0; | |
500 | for (int i = actcol; i < m_CellInfo[actrow][actcol].colspan + actcol; i++) | |
501 | fullwid += m_ColsInfo[i].pixwidth; | |
a97a264f | 502 | fullwid += (m_CellInfo[actrow][actcol].colspan - 1) * m_Spacing; |
4f9297b0 VS |
503 | actcell->Layout(fullwid); |
504 | actcell->SetPos(m_ColsInfo[actcol].leftpos, ypos[actrow]); | |
5526e819 | 505 | } |
5526e819 VS |
506 | } |
507 | m_Height = ypos[m_NumRows]; | |
2776d7c3 | 508 | delete[] ypos; |
5526e819 VS |
509 | } |
510 | } | |
511 | ||
512 | ||
513 | ||
514 | ||
515 | ||
516 | ||
517 | //----------------------------------------------------------------------------- | |
518 | // The tables handler: | |
519 | //----------------------------------------------------------------------------- | |
520 | ||
521 | ||
522 | TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH") | |
523 | ||
524 | TAG_HANDLER_VARS | |
525 | wxHtmlTableCell* m_Table; | |
526 | wxString m_tAlign, m_rAlign; | |
5526e819 VS |
527 | |
528 | TAG_HANDLER_CONSTR(TABLE) | |
529 | { | |
530 | m_Table = NULL; | |
01325161 | 531 | m_tAlign = m_rAlign = wxEmptyString; |
5526e819 VS |
532 | } |
533 | ||
534 | ||
535 | TAG_HANDLER_PROC(tag) | |
536 | { | |
537 | wxHtmlContainerCell *c; | |
538 | ||
539 | // new table started, backup upper-level table (if any) and create new: | |
04dbb646 | 540 | if (tag.GetName() == wxT("TABLE")) |
2fa3b707 | 541 | { |
5526e819 VS |
542 | wxHtmlTableCell *oldt = m_Table; |
543 | wxHtmlContainerCell *oldcont; | |
5526e819 | 544 | |
4f9297b0 | 545 | oldcont = c = m_WParser->OpenContainer(); |
5526e819 | 546 | |
4f9297b0 VS |
547 | c->SetWidthFloat(tag, m_WParser->GetPixelScale()); |
548 | m_Table = new wxHtmlTableCell(c, tag, m_WParser->GetPixelScale()); | |
2755d437 | 549 | int oldAlign = m_WParser->GetAlign(); |
5526e819 | 550 | m_tAlign = wxEmptyString; |
8bd72d90 VS |
551 | if (tag.HasParam(wxT("ALIGN"))) |
552 | m_tAlign = tag.GetParam(wxT("ALIGN")); | |
5526e819 VS |
553 | |
554 | ParseInner(tag); | |
555 | ||
2755d437 | 556 | m_WParser->SetAlign(oldAlign); |
4f9297b0 VS |
557 | m_WParser->SetContainer(oldcont); |
558 | m_WParser->CloseContainer(); | |
fbe77cea | 559 | |
5526e819 VS |
560 | m_Table = oldt; |
561 | return TRUE; | |
562 | } | |
563 | ||
564 | ||
211dfedd | 565 | else if (m_Table) |
2fa3b707 | 566 | { |
5526e819 | 567 | // new row in table |
04dbb646 | 568 | if (tag.GetName() == wxT("TR")) |
2fa3b707 | 569 | { |
4f9297b0 | 570 | m_Table->AddRow(tag); |
5526e819 | 571 | m_rAlign = m_tAlign; |
04dbb646 | 572 | if (tag.HasParam(wxT("ALIGN"))) |
8bd72d90 | 573 | m_rAlign = tag.GetParam(wxT("ALIGN")); |
5526e819 VS |
574 | } |
575 | ||
576 | // new cell | |
04dbb646 | 577 | else |
2fa3b707 | 578 | { |
4f9297b0 VS |
579 | c = m_WParser->SetContainer(new wxHtmlContainerCell(m_Table)); |
580 | m_Table->AddCell(c, tag); | |
5526e819 | 581 | |
4f9297b0 | 582 | m_WParser->OpenContainer(); |
5526e819 | 583 | |
04dbb646 | 584 | if (tag.GetName() == wxT("TH")) /*header style*/ |
4f9297b0 | 585 | m_WParser->SetAlign(wxHTML_ALIGN_CENTER); |
2755d437 VS |
586 | else |
587 | m_WParser->SetAlign(wxHTML_ALIGN_LEFT); | |
588 | ||
589 | wxString als; | |
590 | ||
591 | als = m_rAlign; | |
592 | if (tag.HasParam(wxT("ALIGN"))) | |
593 | als = tag.GetParam(wxT("ALIGN")); | |
594 | als.MakeUpper(); | |
595 | if (als == wxT("RIGHT")) | |
596 | m_WParser->SetAlign(wxHTML_ALIGN_RIGHT); | |
597 | else if (als == wxT("LEFT")) | |
598 | m_WParser->SetAlign(wxHTML_ALIGN_LEFT); | |
599 | else if (als == wxT("CENTER")) | |
600 | m_WParser->SetAlign(wxHTML_ALIGN_CENTER); | |
601 | ||
4f9297b0 | 602 | m_WParser->OpenContainer(); |
5526e819 VS |
603 | } |
604 | } | |
605 | return FALSE; | |
606 | } | |
607 | ||
608 | TAG_HANDLER_END(TABLE) | |
609 | ||
610 | ||
611 | ||
612 | ||
613 | ||
614 | TAGS_MODULE_BEGIN(Tables) | |
615 | ||
616 | TAGS_MODULE_ADD(TABLE) | |
617 | ||
618 | TAGS_MODULE_END(Tables) | |
619 | ||
620 | ||
621 | #endif |