/*! * This method sets the sensitivity of the radio buttons to above/below/left/right merges * Because we can't merge to the left of column zero for example. * * Call this right after contructing the widget and before dropping into the main loop. */ void AP_Dialog_SplitCells::setAllSensitivities(void) { FV_View * pView = 0; if (XAP_Frame * pFrame = getApp()->getLastFocussedFrame()) { pView = static_cast<FV_View *>(pFrame->getCurrentView()); } if (!pView) { setSensitivity(vert_above, false); setSensitivity(vert_mid, false); setSensitivity(vert_below, false); setSensitivity(hori_left, false); setSensitivity(hori_mid, false); setSensitivity(hori_right, false); return; } if (!pView->isInTable()) { setSensitivity(vert_above, false); setSensitivity(vert_mid, false); setSensitivity(vert_below, false); setSensitivity(hori_left, false); setSensitivity(hori_mid, false); setSensitivity(hori_right, false); return; } PT_DocPosition iCurPos = pView->getPoint(); m_iCellSource = iCurPos; pView->getCellParams(iCurPos,&m_iLeft,&m_iRight,&m_iTop,&m_iBot); // // Now find the number of rows and columns inthis table. This is easiest to // get from the table container // fl_BlockLayout * pBL = pView->getLayout()->findBlockAtPosition(iCurPos); fp_Run * pRun; UT_sint32 xPoint,yPoint,xPoint2,yPoint2,iPointHeight; bool bDirection; pRun = pBL->findPointCoords(iCurPos, false, xPoint, yPoint, xPoint2, yPoint2, iPointHeight, bDirection); UT_return_if_fail(pRun); fp_Line * pLine = pRun->getLine(); UT_return_if_fail(pLine); fp_Container * pCon = pLine->getContainer(); UT_return_if_fail(pCon); fp_TableContainer * pTab = static_cast<fp_TableContainer *>(pCon->getContainer()); UT_return_if_fail(pTab); UT_return_if_fail(pTab->getContainerType() == FP_CONTAINER_TABLE); m_pTab = pTab; m_iNumRows = pTab->getNumRows(); m_iNumCols = pTab->getNumCols(); if(m_iBot > m_iTop+2) { setSensitivity(vert_above,true); setSensitivity(vert_below,true); } else { setSensitivity(vert_above,false); setSensitivity(vert_below,false); } UT_sint32 diff = m_iBot - m_iTop; if((m_iBot - m_iTop == 1) || (2*(diff/2) == diff)) { setSensitivity(vert_mid,true); } else { setSensitivity(vert_mid,false); } if(m_iRight > m_iLeft+2) { setSensitivity(hori_left,true); setSensitivity(hori_right,true); } else { setSensitivity(hori_left,false); setSensitivity(hori_right,false); } diff = m_iRight - m_iLeft; if((m_iRight - m_iLeft == 1) || (2*(diff/2) == diff)) { setSensitivity(hori_mid,true); } else { setSensitivity(hori_mid,false); } }
bool fp_FieldTableSumCols::calculateValue(void) { FV_View * pView = _getView(); pf_Frag_Strux* tableSDH= NULL; UT_sint32 numRows =0; UT_sint32 numCols = 0; bUseCurrency = false; cCurrency = '$'; pf_Frag_Strux* sdh = getBlock()->getStruxDocHandle(); PD_Document * pDoc = getBlock()->getDocument(); if(pDoc->isPieceTableChanging()) { return false; } if(getLine() == NULL) { return false; } fp_Container * pCol = getLine()->getColumn(); if(pCol == NULL) { return false; } fp_ShadowContainer * pShad =NULL; fl_HdrFtrShadow * pShadL = NULL; if(pCol->getContainerType() == FP_CONTAINER_COLUMN_SHADOW) { pShad = static_cast<fp_ShadowContainer *>(pCol); pShadL = pShad->getShadow(); } PT_DocPosition pos = pDoc->getStruxPosition(sdh)+1; pDoc->getStruxOfTypeFromPosition(pos,PTX_SectionTable,&tableSDH); pDoc-> getRowsColsFromTableSDH(tableSDH, pView->isShowRevisions(), pView->getRevisionLevel(), &numRows, &numCols); UT_UTF8String sValF; if(!pView->isInTable(pos)) { sValF = "???"; return _setValue(sValF.ucs4_str().ucs4_str()); } fl_CellLayout * pCell = NULL; UT_sint32 myLeft,myRight,myTop,myBot; pView->getCellParams(pos,&myLeft,&myRight,&myTop,&myBot); UT_sint32 col = 0; UT_sint32 row = myTop; UT_sint32 lastCol = -1; double dSum = 0.0; for(col = 0; col < numCols; col++) { pf_Frag_Strux* sdhCell = pDoc->getCellSDHFromRowCol(tableSDH,true,99999,row,col); UT_sint32 i = getBlock()->getDocLayout()->getLID(); fl_ContainerLayout* fmtCell = pDoc->getNthFmtHandle(sdhCell,i); pCell = static_cast<fl_CellLayout *>(fmtCell); if(pCell->getLeftAttach() == lastCol) { continue; } if((pCell->getTopAttach() == myTop) && (pCell->getLeftAttach() == myLeft)) { continue; } UT_GrowBuf grText; pCell->appendTextToBuf(grText); if(grText.getLength() == 0) { fl_ContainerLayout * pC = pCell->getFirstLayout(); while(pC) { if(pC->getContainerType() == FL_CONTAINER_BLOCK) { fl_BlockLayout * pBL = static_cast<fl_BlockLayout *>(pC); if(pShadL) { pBL = static_cast<fl_BlockLayout *>(pShadL->findMatchingContainer(pBL)); } if(pBL == NULL) { continue; } fp_Run * pRun = pBL->getFirstRun(); while(pRun) { if(pRun->getType() == FPRUN_FIELD) { fp_FieldRun * pFRun = static_cast<fp_FieldRun *>(pRun); const UT_UCS4Char * szVal = pFRun->getValue(); sValF.clear(); sValF.appendUCS4(szVal); dSum += dGetVal(sValF.utf8_str()); pRun = NULL; pC = NULL; break; } pRun = pRun->getNextRun(); } } if(pC) { pC = pC->getNext(); } } } else { sValF.clear(); sValF.appendUCS4(reinterpret_cast<const UT_UCS4Char *>(grText.getPointer(0)),grText.getLength()); dSum += dGetVal(sValF.utf8_str()); } lastCol = col; } sFormatDouble(sValF,dSum); return _setValue(sValF.ucs4_str().ucs4_str()); }