diff -u text/fmt/xp/old/fp_ContainerObject.cpp text/fmt/xp/fp_ContainerObject.cpp --- text/fmt/xp/old/fp_ContainerObject.cpp Thu Oct 02 15:39:33 2003 +++ text/fmt/xp/fp_ContainerObject.cpp Thu Oct 02 22:39:47 2003 @@ -81,7 +81,7 @@ m_pContainer(NULL), m_pNext(NULL), m_pPrev(NULL), - m_pMyBrokenContainer(NULL) + m_pMyBrokenContainer(NULL), m_cBrokenContainers(0) { m_vecContainers.clear(); } @@ -114,6 +114,13 @@ void fp_Container::setMyBrokenContainer(fp_Container * pMyBroken) { m_pMyBrokenContainer = pMyBroken; + fp_Container * pc = this; + + while (NULL != pc) + { + pc->incBrokenCount(); + pc = pc->getContainer(); + } } /*! @@ -122,16 +129,30 @@ void fp_Container::clearBrokenContainers(void) { if (m_pMyBrokenContainer) + { + fp_Container * pc = this; + + while (NULL != pc) + { + pc->decBrokenCount(); + pc = pc->getContainer(); + } m_pMyBrokenContainer = NULL; + } - UT_uint32 i =0; - for(i=0;i(getNthCon(i)); - if(pCon) + UT_uint32 i =0; + + for(i=0;(iclearBrokenContainers(); + fp_Container * pCon = static_cast(getNthCon(i)); + if (pCon && (0 != pCon->getBrokenCount())) + { + pCon->clearBrokenContainers(); + } } + m_cBrokenContainers = 0; } } @@ -295,3 +316,9 @@ } +UT_uint32 fp_Container::binarysearchCons(void * key, int (*compar)(const void *, const void *)) +{ + UT_uint32 u = m_vecContainers.binarysearch(key, compar); + + return u; +} diff -u text/fmt/xp/old/fp_ContainerObject.h text/fmt/xp/fp_ContainerObject.h --- text/fmt/xp/old/fp_ContainerObject.h Thu Oct 02 15:39:36 2003 +++ text/fmt/xp/fp_ContainerObject.h Thu Oct 02 22:38:40 2003 @@ -218,12 +218,19 @@ fp_Container * getMyBrokenContainer(void) const; void setMyBrokenContainer(fp_Container * pMyBroken); void clearBrokenContainers(void); + + UT_uint32 binarysearchCons(void *key, int (*compar)(const void *, const void *)); + UT_uint32 getBrokenCount(void) { return m_cBrokenContainers; } + void incBrokenCount(void) { m_cBrokenContainers += 1; } + void decBrokenCount(void) { if (m_cBrokenContainers > 0) { m_cBrokenContainers -= 1; }} + private: fp_Container* m_pContainer; fp_ContainerObject * m_pNext; fp_ContainerObject * m_pPrev; UT_Vector m_vecContainers; fp_Container * m_pMyBrokenContainer; + UT_uint32 m_cBrokenContainers; }; #endif /* CONTAINEROBJECT_H */ diff -u text/fmt/xp/old/fp_TableContainer.cpp text/fmt/xp/fp_TableContainer.cpp --- text/fmt/xp/old/fp_TableContainer.cpp Thu Oct 02 15:39:47 2003 +++ text/fmt/xp/fp_TableContainer.cpp Thu Oct 02 22:55:09 2003 @@ -2333,44 +2333,57 @@ } /*! + * This static function is used to compare cells' position for the + * UT_Vector::binarysearch +\param vX1 pointer to a Point value. +\param vX2 pointer to a fp_CellContainer object +*/ +static UT_sint32 compareCellPosBinary(const void * vX1, const void * vX2) +{ + const UT_Point *pt = static_cast(vX1); + const fp_ContainerObject *pc = *(fp_ContainerObject **)(vX2); + const fp_CellContainer *pCell = static_cast(pc); + + // compare cell's top and bottom first + if (pCell->getTopAttach() > pt->y) + { + return -1; + } + if (pCell->getBottomAttach() <= pt->y) + { + return 1; + } + // then compare cell's left and right next + if (pCell->getLeftAttach() > pt->x) + { + return -1; + } + if (pCell->getRightAttach() <= pt->x) + { + return 1; + } + + return 0; +} + + +/*! * Return the cell container at the specified row and column */ fp_CellContainer * fp_TableContainer::getCellAtRowColumn(UT_sint32 row, UT_sint32 col) { - UT_sint32 count = static_cast(countCons()); - UT_sint32 i =0; - fp_CellContainer * pCell = NULL; fp_CellContainer * pSmall = NULL; - bool bFound = false; - for(i=0; i < count && !bFound; i++) - { - pCell = static_cast(getNthCon(i)); - xxx_UT_DEBUGMSG(("getCellAtRowColumn: left %d ,right %d, top %d, bot %d \n",pCell->getLeftAttach(),pCell->getRightAttach(),pCell->getTopAttach(),pCell->getBottomAttach())); - if(pCell->getLeftAttach() <= col && pCell->getRightAttach() > col && - pCell->getTopAttach() <= row && pCell->getBottomAttach() > row) - { - bFound = true; - if(pSmall == NULL) - { - pSmall = pCell; - } -#if 0 - else - { - if((pSmall->getLeftAttach() > pCell->getLeftAttach()) && - (pSmall->getTopAttach() > pCell->getTopAttach())) - { - pSmall = pCell; - } - } -#endif - } - } - if(bFound) + UT_Point pt; + pt.x = col; + pt.y = row; + + UT_sint32 u = binarysearchCons(&pt, compareCellPosBinary); + if (u != -1) { - return pSmall; + pSmall = static_cast(getNthCon(u)); } - return NULL; + + return pSmall; } /* @@ -2602,13 +2615,15 @@ for(i=0; i< m_iRows; i++) { m_vecRows.addItem(static_cast(new fp_TableRowColumn())); - getNthRow(i)->requisition = 0; - getNthRow(i)->allocation = 0; - getNthRow(i)->spacing = m_iRowSpacing; - getNthRow(i)->need_expand = 0; - getNthRow(i)->need_shrink = 0; - getNthRow(i)->expand = 0; - getNthRow(i)->shrink = 0; + + fp_TableRowColumn *prow = getNthRow(i); + prow->requisition = 0; + prow->allocation = 0; + prow->spacing = m_iRowSpacing; + prow->need_expand = 0; + prow->need_shrink = 0; + prow->expand = 0; + prow->shrink = 0; } } @@ -2623,13 +2638,16 @@ for(i=0; i< m_iCols; i++) { m_vecColumns.addItem(static_cast(new fp_TableRowColumn())); - getNthCol(i)->requisition = 0; - getNthCol(i)->allocation = 0; - getNthCol(i)->spacing = m_iColSpacing; - getNthCol(i)->need_expand = 0; - getNthCol(i)->need_shrink = 0; - getNthCol(i)->expand = 0; - getNthCol(i)->shrink = 0; + + fp_TableRowColumn *pcol = getNthCol(i); + + pcol->requisition = 0; + pcol->allocation = 0; + pcol->spacing = m_iColSpacing; + pcol->need_expand = 0; + pcol->need_shrink = 0; + pcol->expand = 0; + pcol->shrink = 0; } } } @@ -4037,21 +4055,25 @@ m_iCols = m_vecColumns.getItemCount(); for (col = 0; col < m_iCols; col++) { - getNthCol(col)->allocation = getNthCol(col)->requisition; - getNthCol(col)->need_expand = false; - getNthCol(col)->need_shrink = true; - getNthCol(col)->expand = false; - getNthCol(col)->shrink = true; - getNthCol(col)->empty = true; + fp_TableRowColumn *pcol = getNthCol(col); + + pcol->allocation = pcol->requisition; + pcol->need_expand = false; + pcol->need_shrink = true; + pcol->expand = false; + pcol->shrink = true; + pcol->empty = true; } for (row = 0; row < m_iRows; row++) { - getNthRow(row)->allocation = getNthRow(row)->requisition; - getNthRow(row)->need_expand = false; - getNthRow(row)->need_shrink = true; - getNthRow(row)->expand = false; - getNthRow(row)->shrink = true; - getNthRow(row)->empty = true; + fp_TableRowColumn *prow = getNthRow(row); + + prow->allocation = prow->requisition; + prow->need_expand = false; + prow->need_shrink = true; + prow->expand = false; + prow->shrink = true; + prow->empty = true; } /* Loop over all the children and adjust the row and col values @@ -4064,28 +4086,30 @@ { if (child->getLeftAttach() == (child->getRightAttach() - 1)) { + fp_TableRowColumn *pcol = getNthCol(child->getLeftAttach()); if (child->getXexpand()) { - getNthCol(child->getLeftAttach())->expand = true; + pcol->expand = true; } if (!child->getXshrink()) { - getNthCol(child->getLeftAttach())->shrink = false; + pcol->shrink = false; } - getNthCol(child->getLeftAttach())->empty = false; + pcol->empty = false; } if (child->getTopAttach() == (child->getBottomAttach() - 1)) { + fp_TableRowColumn *prow = getNthRow(child->getTopAttach()); if (child->getYshrink()) { - getNthRow(child->getTopAttach())->expand = true; + prow->expand = true; } if (!child->getYshrink()) { - getNthRow(child->getTopAttach())->shrink = false; + prow->shrink = false; } - getNthRow(child->getTopAttach())->empty = false; + prow->empty = false; } child = static_cast(child->getNext()); } @@ -4199,20 +4223,22 @@ m_iCols = m_vecColumns.getItemCount(); for (col = 0; col < m_iCols; col++) { - if (getNthCol(col)->empty) + fp_TableRowColumn *pcol = getNthCol(col); + + if (pcol->empty) { - getNthCol(col)->expand = false; - getNthCol(col)->shrink = false; + pcol->expand = false; + pcol->shrink = false; } else { - if (getNthCol(col)->need_expand) + if (pcol->need_expand) { - getNthCol(col)->expand = true; + pcol->expand = true; } - if (!getNthCol(col)->need_shrink) + if (!pcol->need_shrink) { - getNthCol(col)->shrink = false; + pcol->shrink = false; } } } @@ -4222,20 +4248,22 @@ */ for (row = 0; row < m_iRows; row++) { - if (getNthRow(row)->empty) + fp_TableRowColumn *prow = getNthRow(row); + + if (prow->empty) { - getNthRow(row)->expand = false; - getNthRow(row)->shrink = false; + prow->expand = false; + prow->shrink = false; } else { - if (getNthRow(row)->need_expand) + if (prow->need_expand) { - getNthRow(row)->expand = true; + prow->expand = true; } - if (!getNthRow(row)->need_shrink) + if (!prow->need_shrink) { - getNthRow(row)->shrink = false; + prow->shrink = false; } } } @@ -4302,12 +4330,13 @@ m_iCols = m_vecColumns.getItemCount(); for (col = 0; col < m_iCols; col++) { - width += getNthCol(col)->requisition; - if (getNthCol(col)->expand) + fp_TableRowColumn *pcol = getNthCol(col); + width += pcol->requisition; + if (pcol->expand) { nexpand += 1; } - if (getNthCol(col)->shrink) + if (pcol->shrink) { nshrink += 1; } @@ -4348,16 +4377,17 @@ m_iCols = m_vecColumns.getItemCount(); for (col = 0; col < m_iCols; col++) { - if (getNthCol(col)->shrink) + fp_TableRowColumn *pcol = getNthCol(col); + if (pcol->shrink) { - UT_sint32 allocation = getNthCol(col)->allocation; - getNthCol(col)->allocation = UT_MAX (1, static_cast(getNthCol(col)->allocation) - extra / nshrink); - extra -= allocation - getNthCol(col)->allocation; + UT_sint32 allocation = pcol->allocation; + pcol->allocation = UT_MAX (1, static_cast(pcol->allocation) - extra / nshrink); + extra -= allocation - pcol->allocation; nshrink -= 1; - if (getNthCol(col)->allocation < 2) + if (pcol->allocation < 2) { total_nshrink -= 1; - getNthCol(col)->shrink = false; + pcol->shrink = false; } } } @@ -4402,12 +4432,13 @@ nshrink = 0; for (row = 0; row < m_iRows; row++) { - height += getNthRow(row)->requisition; - if (getNthRow(row)->expand) + fp_TableRowColumn *prow = getNthRow(row); + height += prow->requisition; + if (prow->expand) { nexpand += 1; } - if (getNthRow(row)->shrink) + if (prow->shrink) { nshrink += 1; } @@ -4423,10 +4454,11 @@ height = real_height - height; for (row = 0; row < m_iRows; row++) { - if (getNthRow(row)->expand) + fp_TableRowColumn *prow = getNthRow(row); + if (prow->expand) { extra = height / nexpand; - getNthRow(row)->allocation += extra; + prow->allocation += extra; height -= extra; nexpand -= 1; } @@ -4445,17 +4477,18 @@ nshrink = total_nshrink; for (row = 0; row < m_iRows; row++) { - if (getNthRow(row)->shrink) + fp_TableRowColumn *prow = getNthRow(row); + if (prow->shrink) { - UT_sint32 allocation = getNthRow(row)->allocation; + UT_sint32 allocation = prow->allocation; - getNthRow(row)->allocation = UT_MAX (1, static_cast(getNthRow(row)->allocation) - extra / nshrink); - extra -= allocation - getNthRow(row)->allocation; + prow->allocation = UT_MAX (1, static_cast(prow->allocation) - extra / nshrink); + extra -= allocation - prow->allocation; nshrink -= 1; - if (getNthRow(row)->allocation < 2) + if (prow->allocation < 2) { total_nshrink -= 1; - getNthRow(row)->shrink = false; + prow->shrink = false; } } } @@ -4479,10 +4512,11 @@ for (col = 0; (col < static_cast(pVecColProps->getItemCount())) && (col (pVecColProps->getNthItem(col)); - getNthCol(col)->allocation = pColProp->m_iColWidth - getNthCol(col)->spacing; + fp_TableRowColumn *pcol = getNthCol(col); + pcol->allocation = pColProp->m_iColWidth - pcol->spacing; if(col == (getNumCols() - 1) ) { - getNthCol(col)->allocation += 2 * getNthCol(col)->spacing; + pcol->allocation += 2 * pcol->spacing; } xxx_UT_DEBUGMSG(("Sevior: table %x column %d set to width %d spacing %d pColProp width %d \n",this,col,getNthCol(col)->allocation,getNthCol(col)->spacing,pColProp->m_iColWidth)); } @@ -4507,40 +4541,44 @@ for (col = 0; col < child->getLeftAttach(); col++) { - x += getNthCol(col)->allocation; - x += getNthCol(col)->spacing; + fp_TableRowColumn *pcol = getNthCol(col); + x += pcol->allocation; + x += pcol->spacing; } for (col = child->getLeftAttach(); col < child->getRightAttach(); col++) { - max_width += getNthCol(col)->allocation; + fp_TableRowColumn *pcol = getNthCol(col); + max_width += pcol->allocation; if ((col + 1) < child->getRightAttach()) { - max_width += getNthCol(col)->spacing; + max_width += pcol->spacing; } } for (row = 0; row < child->getTopAttach(); row++) { - UT_sint32 iOldAlloc = getNthRow(row)->allocation; + fp_TableRowColumn *prow = getNthRow(row); + UT_sint32 iOldAlloc = prow->allocation; UT_sint32 iNewAlloc = getRowHeight(row,iOldAlloc); if(iNewAlloc > iOldAlloc) { - iNewAlloc -= getNthRow(row)->spacing; + iNewAlloc -= prow->spacing; } - getNthRow(row)->allocation = iNewAlloc; - y += getNthRow(row)->allocation; - y += getNthRow(row)->spacing; + prow->allocation = iNewAlloc; + y += prow->allocation; + y += prow->spacing; xxx_UT_DEBUGMSG(("SEVIOR: Adding Height %d spacing is %d \n", getNthRow(row)->allocation,getNthRow(row)->spacing)); } xxx_UT_DEBUGMSG(("SEVIOR: 2 next y %d for top-attach %d \n",y,child->getTopAttach())); for (row = child->getTopAttach(); row < child->getBottomAttach(); row++) { - max_height += getNthRow(row)->allocation; + fp_TableRowColumn *prow = getNthRow(row); + max_height += prow->allocation; if ((row + 1) < child->getBottomAttach()) { - max_height += getNthRow(row)->spacing; + max_height += prow->spacing; } } @@ -4621,14 +4659,15 @@ // for (row = 0; row + 1 < m_iRows; row++) for (row = 0; row < m_iRows; row++) { - UT_sint32 iOldReq = getNthRow(row)->requisition; + fp_TableRowColumn *prow = getNthRow(row); + UT_sint32 iOldReq = prow->requisition; UT_sint32 iNewReq = getRowHeight(row,iOldReq); if(iNewReq > iOldReq) { - iNewReq -= getNthRow(row)->spacing; + iNewReq -= prow->spacing; } - getNthRow(row)->requisition = iNewReq; - pRequisition->height += getNthRow(row)->spacing; + prow->requisition = iNewReq; + pRequisition->height += prow->spacing; xxx_UT_DEBUGMSG(("SEVIOR: requisition spacing 2 is %d \n", getNthRow(row)->spacing)); xxx_UT_DEBUGMSG(("SEVIOR: requisition height 2 is %d \n", pRequisition->height));