00001 #ifndef __DW_TABLE_HH__
00002 #define __DW_TABLE_HH__
00003
00004 #include "core.hh"
00005 #include "tablecell.hh"
00006 #include "../lout/misc.hh"
00007
00008 namespace dw {
00009
00334 class Table: public core::Widget
00335 {
00336 private:
00337
00338 struct Child
00339 {
00340 enum {
00341 CELL,
00342 SPAN_SPACE
00343 } type;
00344 union {
00345 struct {
00346 core::Widget *widget;
00347 int colspanOrig, colspanEff, rowspan;
00348 } cell;
00349 struct {
00350 int startCol, startRow;
00351 } spanSpace;
00352 };
00353 };
00354
00355 class TableIterator: public core::Iterator
00356 {
00357 private:
00358 int index;
00359
00360 public:
00361 TableIterator (Table *table, core::Content::Type mask, bool atEnd);
00362 TableIterator (Table *table, core::Content::Type mask, int index);
00363
00364 lout::object::Object *clone();
00365 int compareTo(lout::misc::Comparable *other);
00366
00367 bool next ();
00368 bool prev ();
00369 void highlight (int start, int end, core::HighlightLayer layer);
00370 void unhighlight (int direction, core::HighlightLayer layer);
00371 void getAllocation (int start, int end, core::Allocation *allocation);
00372 };
00373
00374 friend class TableIterator;
00375
00376 bool limitTextWidth, rowClosed;
00377 int availWidth, availAscent, availDescent;
00378
00379 int numRows, numCols, curRow, curCol;
00380 lout::misc::SimpleVector<Child*> *children;
00381
00382 int redrawX, redrawY;
00383
00387 lout::misc::SimpleVector<core::Extremes> *colExtremes;
00388
00392 lout::misc::SimpleVector<int> *colWidths;
00393
00399 lout::misc::SimpleVector<int> *cumHeight;
00403 lout::misc::SimpleVector<int> *rowSpanCells;
00407 lout::misc::SimpleVector<int> *colSpanCells;
00408 lout::misc::SimpleVector<int> *baseline;
00409
00410 lout::misc::SimpleVector<core::style::Style*> *rowStyle;
00411
00416 enum { LEN_AUTO = -1, LEN_ABS = -2};
00417 int hasColPercent;
00418 lout::misc::SimpleVector<float> *colPercents;
00419
00420 inline bool childDefined(int n)
00421 {
00422 return n < children->size() && children->get(n) != NULL &&
00423 children->get(n)->type != Child::SPAN_SPACE;
00424 }
00425
00426 void reallocChildren (int newNumCols, int newNumRows);
00427
00428 void calcCellSizes ();
00429 void forceCalcCellSizes ();
00430 void apportionRowSpan ();
00431
00432 void calcColumnExtremes ();
00433 void forceCalcColumnExtremes ();
00434
00435 void apportion2 (int totalWidth, int forceTotalWidth);
00436 void apportion_percentages2 (int totalWidth, int forceTotalWidth);
00437
00438 void setCumHeight (int row, int value)
00439 {
00440 if (value != cumHeight->get (row)) {
00441 redrawY = lout::misc::min ( redrawY, value );
00442 cumHeight->set (row, value);
00443 }
00444 }
00445
00446 inline void setColWidth (int col, int value)
00447 {
00448 if (value != colWidths->get (col)) {
00449 redrawX = lout::misc::min (redrawX, value);
00450 colWidths->set (col, value);
00451 }
00452 }
00453
00454 protected:
00455 void sizeRequestImpl (core::Requisition *requisition);
00456 void getExtremesImpl (core::Extremes *extremes);
00457 void sizeAllocateImpl (core::Allocation *allocation);
00458 void resizeDrawImpl ();
00459
00460 void setWidth (int width);
00461 void setAscent (int ascent);
00462 void setDescent (int descent);
00463 void draw (core::View *view, core::Rectangle *area);
00464
00465
00466
00467
00468
00469 void removeChild (Widget *child);
00470
00471 public:
00472 static int CLASS_ID;
00473
00474 Table(bool limitTextWidth);
00475 ~Table();
00476
00477 core::Iterator *iterator (core::Content::Type mask, bool atEnd);
00478
00479 void addCell (Widget *widget, int colspan, int rowspan);
00480 void addRow (core::style::Style *style);
00481 TableCell *getCellRef ();
00482 };
00483
00484 }
00485
00486 #endif // __DW_TABLE_HH__