diff --git a/dw/table.cc b/dw/table.cc index 0c15cbe..85e5d25 100644 --- a/dw/table.cc +++ b/dw/table.cc @@ -52,7 +52,6 @@ Table::Table(bool limitTextWidth) colExtremes = new misc::SimpleVector (8); colWidthSpecified = new misc::SimpleVector (8); colWidthPercentage = new misc::SimpleVector (8); - colWidths = new misc::SimpleVector (8); cumHeight = new misc::SimpleVector (8); rowSpanCells = new misc::SimpleVector (8); baseline = new misc::SimpleVector (8); @@ -93,7 +92,6 @@ Table::~Table() delete colExtremes; delete colWidthSpecified; delete colWidthPercentage; - delete colWidths; delete cumHeight; delete rowSpanCells; delete baseline; @@ -114,7 +112,7 @@ void Table::sizeRequestSimpl (core::Requisition *requisition) requisition->width = boxDiffWidth () + (numCols + 1) * getStyle()->hBorderSpacing; for (int col = 0; col < numCols; col++) - requisition->width += colWidths->get (col); + requisition->width += colWidths.at (col); requisition->ascent = boxDiffHeight () + cumHeight->get (numRows) + getStyle()->vBorderSpacing; @@ -186,7 +184,7 @@ void Table::sizeAllocateImpl (core::Allocation *allocation) int width = (children->get(n)->cell.colspanEff - 1) * getStyle()->hBorderSpacing; for (int i = 0; i < children->get(n)->cell.colspanEff; i++) - width += colWidths->get (col + i); + width += colWidths.at (col + i); core::Allocation childAllocation; core::Requisition childRequisition; @@ -205,7 +203,7 @@ void Table::sizeAllocateImpl (core::Allocation *allocation) } } - x += colWidths->get (col) + getStyle()->hBorderSpacing; + x += colWidths.at (col) + getStyle()->hBorderSpacing; } sizeAllocateEnd (); @@ -295,7 +293,7 @@ int Table::calcAvailWidthForDescendant (Widget *child) int width = (colspanEff - 1) * getStyle()->hBorderSpacing; for (int i = 0; i < colspanEff; i++) - width += colWidths->get (col + i); + width += colWidths.at (col + i); width = std::max (width, 0); if (child != actualChild) { @@ -806,12 +804,12 @@ void Table::reallocChildren (int newNumCols, int newNumRows) // defined available width for the children before the column // widths are actually calculated. - colWidths->setSize (numCols, 100); + colWidths.resize( numCols, 100 ); DBG_IF_RTFL { - DBG_OBJ_SET_NUM ("colWidths.size", colWidths->size ()); - for (int i = 0; i < colWidths->size (); i++) - DBG_OBJ_ARRSET_NUM ("colWidths", i, colWidths->get (i)); + DBG_OBJ_SET_NUM ("colWidths.size", colWidths.size ()); + for (int i = 0; i < colWidths.size(); i++) + DBG_OBJ_ARRSET_NUM ("colWidths", i, colWidths.at (i)); } DBG_OBJ_SET_NUM ("numCols", numCols); @@ -846,17 +844,15 @@ void Table::forceCalcCellSizes (bool calcHeights) // correction is necessary. The old values are temporary preserved // ... - lout::misc::SimpleVector oldColWidths (8); - oldColWidths.setSize (colWidths->size ()); - colWidths->copyTo (&oldColWidths); + std::vector oldColWidths= colWidths; actuallyCalcCellSizes (calcHeights); // ... and then compared to the new ones. In case of a difference, // the cell is told about this. - for (int col = 0; col < colWidths->size (); col++) { - if (oldColWidths.get (col) != colWidths->get (col)) { + for (int col = 0; col < colWidths.size (); col++) { + if (oldColWidths.at (col) != colWidths.at (col)) { for (int row = 0; row < numRows; row++) { int n = row * numCols + col, col2; Child *child = children->get(n); @@ -923,14 +919,14 @@ void Table::actuallyCalcCellSizes (bool calcHeights) availWidth, corrWidth, numCols, getStyle()->hBorderSpacing, boxDiffWidth (), totalWidth); - assert (colWidths->size () == numCols); // This is set in addCell. + assert (colWidths.size () == numCols); // This is set in addCell. cumHeight->setSize (numRows + 1, 0); rowSpanCells->setSize (0); baseline->setSize (numRows); - misc::SimpleVector *oldColWidths = colWidths; - colWidths = new misc::SimpleVector (8); - colWidths->setSize (numCols); + std::vector< int > oldColWidths = colWidths; + colWidths.clear(); + colWidths.resize( numCols ); int minWidth = 0, minWidthIntrinsic = 0, maxWidth = 0; for (int col = 0; col < colExtremes->size(); col++) { @@ -998,7 +994,7 @@ void Table::actuallyCalcCellSizes (bool calcHeights) DBG_OBJ_MSG ("resize", 1, "case 1a: simple apportioning"); apportion2 (totalWidth, 0, colExtremes->size() - 1, MIN_MIN, MAX_MIN, - NULL, colWidths, 0); + NULL, &colWidths, 0); } else { DBG_OBJ_MSG ("resize", 1, "case 1b: treat percentages specially"); @@ -1033,7 +1029,7 @@ void Table::actuallyCalcCellSizes (bool calcHeights) if (colWidth > widthPartPer - minWidthIntrinsicPer) colWidth = widthPartPer - minWidthIntrinsicPer; - colWidths->set (col, colWidth); + colWidths[ col ]= colWidth; widthPartPer -= colWidth; DBG_OBJ_MSGF ("resize", 1, @@ -1042,8 +1038,7 @@ void Table::actuallyCalcCellSizes (bool calcHeights) col, colWidth, widthPartPer, minWidthIntrinsicPer); } else - colWidths->set (col, - colExtremes->getRef(col)->minWidthIntrinsic); + colWidths[ col ]= colExtremes->getRef(col)->minWidthIntrinsic; } } else if (totalWidthSpecified && totalWidth > maxWidth) { @@ -1069,7 +1064,7 @@ void Table::actuallyCalcCellSizes (bool calcHeights) DBG_OBJ_MSG ("resize", 1, "subcase 2a: no or all columns with specified width"); apportion2 (totalWidth, 0, colExtremes->size() - 1, MAX, MAX, NULL, - colWidths, 0); + &colWidths, 0); } else { DBG_OBJ_MSGF ("resize", 1, "subcase 2b: %d column(s) with specified width", @@ -1082,7 +1077,7 @@ void Table::actuallyCalcCellSizes (bool calcHeights) misc::SimpleVector widthsNotSpecified (numNotSpecified); widthsNotSpecified.setSize (numNotSpecified); - misc::SimpleVector apportionDest (numNotSpecified); + std::vector< int > apportionDest( numNotSpecified ); int totalWidthNotSpecified = totalWidth, indexNotSpecified = 0; for (int col = 0; col < colExtremes->size(); col++) @@ -1129,13 +1124,13 @@ void Table::actuallyCalcCellSizes (bool calcHeights) if (colWidthSpecified->get (col)) { DBG_OBJ_MSGF ("resize", 1, "#%d: specified, gets maximum %d", col, colExtremes->getRef(col)->maxWidth); - colWidths->set (col, colExtremes->getRef(col)->maxWidth); + colWidths[ col ]= colExtremes->getRef(col)->maxWidth; } else { DBG_OBJ_MSGF ("resize", 1, "#%d: not specified, gets value %d " "at position %d from temporary list", - col, apportionDest.get (indexNotSpecified), + col, apportionDest.at (indexNotSpecified), indexNotSpecified); - colWidths->set (col, apportionDest.get (indexNotSpecified)); + colWidths[ col ]= apportionDest.at (indexNotSpecified); indexNotSpecified++; } @@ -1146,7 +1141,7 @@ void Table::actuallyCalcCellSizes (bool calcHeights) int width = totalWidthSpecified ? totalWidth : std::min (totalWidth, maxWidth); DBG_OBJ_MSGF ("resize", 1, "case 3: else; width = %d", width); - apportion2 (width, 0, colExtremes->size() - 1, MIN, MAX, NULL, colWidths, + apportion2 (width, 0, colExtremes->size() - 1, MIN, MAX, NULL, &colWidths, 0); } @@ -1154,13 +1149,13 @@ void Table::actuallyCalcCellSizes (bool calcHeights) // this anyway correct (col width is is not x)? And does the // performance gain actually play a role? for (int col = 0; col < colExtremes->size(); col++) { - if (colWidths->get (col) != oldColWidths->get (col)) - redrawX = std::min (redrawX, colWidths->get (col)); + if (colWidths.at (col) != oldColWidths.at (col)) + redrawX = std::min (redrawX, colWidths.at (col)); } DBG_IF_RTFL { DBG_OBJ_SET_NUM ("colWidths.size", colWidths->size ()); - for (int i = 0; i < colWidths->size (); i++) + for (int i = 0; i < colWidths.size (); i++) DBG_OBJ_ARRSET_NUM ("colWidths", i, colWidths->get (i)); } @@ -1169,8 +1164,8 @@ void Table::actuallyCalcCellSizes (bool calcHeights) colWidthsUpToDateWidthColExtremes); for (int col = 0; col < numCols; col++) { - if (col >= oldColWidths->size () || col >= colWidths->size () || - oldColWidths->get (col) != colWidths->get (col)) { + if (col >= oldColWidths.size () || col >= colWidths.size () || + oldColWidths.at (col) != colWidths.at (col)) { // Column width has changed, tell children about this. for (int row = 0; row < numRows; row++) { int n = row * numCols + col; @@ -1182,7 +1177,8 @@ void Table::actuallyCalcCellSizes (bool calcHeights) } } - delete oldColWidths; + oldColWidths.clear(); + oldColWidths.shrink_to_fit(); if (calcHeights) { setCumHeight (0, 0); @@ -1473,7 +1469,8 @@ void Table::calcExtremesSpanMultiCols (int col, int cs, bool changeMax = cellMax > maxSumCols; if (changeMin || changeMax) { // TODO This differs from the documentation? Should work, anyway. - misc::SimpleVector newMin, newMax; + std::vector< int > newMin; + std::vector< int > newMax; if (changeMin) apportion2 (cellMin, col, col + cs - 1, MIN, MAX, NULL, &newMin, 0); if (changeMax) @@ -1481,9 +1478,9 @@ void Table::calcExtremesSpanMultiCols (int col, int cs, for (int j = 0; j < cs; j++) { if (changeMin) - setColExtreme (col + j, minExtrMod, extrData, newMin.get (j)); + setColExtreme (col + j, minExtrMod, extrData, newMin.at (j)); if (changeMax) - setColExtreme (col + j, maxExtrMod, extrData, newMax.get (j)); + setColExtreme (col + j, maxExtrMod, extrData, newMax.at (j)); // For cases where min and max are somewhat confused: setColExtreme (col + j, maxExtrMod, extrData, @@ -1508,12 +1505,12 @@ void Table::calcAdjustmentWidthSpanMultiCols (int col, int cs, sumAdjustmentWidth += colExtremes->getRef(col + j)->adjustmentWidth; if (cellExtremes->adjustmentWidth > sumAdjustmentWidth) { - misc::SimpleVector newAdjustmentWidth; + std::vector< int > newAdjustmentWidth; apportion2 (cellExtremes->adjustmentWidth, col, col + cs - 1, MIN, MAX, NULL, &newAdjustmentWidth, 0); for (int j = 0; j < cs; j++) colExtremes->getRef(col + j)->adjustmentWidth = - newAdjustmentWidth.get (j); + newAdjustmentWidth.at (j); } DBG_OBJ_LEAVE (); @@ -1524,14 +1521,14 @@ void Table::calcAdjustmentWidthSpanMultiCols (int col, int cs, */ void Table::apportion2 (int totalWidth, int firstCol, int lastCol, ExtrMod minExtrMod, ExtrMod maxExtrMod, void *extrData, - misc::SimpleVector *dest, int destOffset) + std::vector *dest, int destOffset) { DBG_OBJ_ENTER ("resize", 0, "apportion2", "%d, %d, %d, %s, %s, ..., %d", totalWidth, firstCol, lastCol, getExtrModName (minExtrMod), getExtrModName (maxExtrMod), destOffset); if (lastCol >= firstCol) { - dest->setSize (destOffset + lastCol - firstCol + 1, 0); + dest->resize( destOffset + lastCol - firstCol + 1, 0 ); int totalMin = 0, totalMax = 0; for (int col = firstCol; col <= lastCol; col++) { @@ -1602,7 +1599,7 @@ void Table::apportion2 (int totalWidth, int firstCol, int lastCol, (cumDiffExtr * totalDiffWidth) / totalDiffExtr - cumDiffWidth; cumDiffWidth += diffWidth; - dest->set (destOffset - firstCol + col, diffWidth + min); + dest->at( destOffset - firstCol + col )= diffWidth + min; } } else if (totalMin != 0) { // Special case. Again, same algorithm, with @@ -1621,7 +1618,7 @@ void Table::apportion2 (int totalWidth, int firstCol, int lastCol, int width = (cumMin * totalWidth) / totalMin - cumWidth; cumWidth += width; - dest->set (destOffset - firstCol + col, width); + dest->at( destOffset - firstCol + col )= width; } } else { // if (totalMin == 0) // Last special case. Same algorithm, with @@ -1639,7 +1636,7 @@ void Table::apportion2 (int totalWidth, int firstCol, int lastCol, int width = (i * totalWidth) / n - cumWidth; cumWidth += width; - dest->set (destOffset - firstCol + col, width); + dest->at( destOffset - firstCol + col )= width; } } } diff --git a/dw/table.hh b/dw/table.hh index 4c4f3bb..85c2724 100644 --- a/dw/table.hh +++ b/dw/table.hh @@ -402,7 +402,7 @@ private: /** * \brief The widths of all columns. */ - lout::misc::SimpleVector *colWidths; + std::vector< int > colWidths; /** * Row cumulative height array: cumHeight->size() is numRows + 1, @@ -453,7 +453,7 @@ private: void apportion2 (int totalWidth, int firstCol, int lastCol, ExtrMod minExtrMod, ExtrMod maxExtrMod, void *extrData, - lout::misc::SimpleVector *dest, int destOffset); + std::vector< int > *dest, int destOffset); void setCumHeight (int row, int value) {