--- sc/source/ui/view/viewfun2.cxx.old 2007-03-25 21:36:54.000000000 +0200 +++ sc/source/ui/view/viewfun2.cxx 2007-03-25 23:45:22.000000000 +0200 @@ -394,30 +394,47 @@ //---------------------------------------------------------------------------- +// TODO : change params, none of them is needed void ScViewFunc::EnterAutoSum(const ScRangeList& rRangeList, sal_Bool bSubTotal) // Block mit Summen fuellen { ScDocument* pDoc = GetViewData()->GetDocument(); - String aRef; - rRangeList.Format( aRef, SCA_VALID, pDoc ); + ScMarkData& rMark = GetViewData()->GetMarkData(); - String aFormula = '='; - ScFunctionMgr* pFuncMgr = ScGlobal::GetStarCalcFunctionMgr(); - const ScFuncDesc* pDesc = NULL; - if (!bSubTotal) - pDesc = pFuncMgr->Get( SC_OPCODE_SUM ); - else - pDesc = pFuncMgr->Get( SC_OPCODE_SUB_TOTAL ); - if ( pDesc && pDesc->pFuncName ) - { - aFormula += *pDesc->pFuncName; - if (bSubTotal) - aFormula.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "(9;" )); - else - aFormula += '('; - aFormula += aRef; - aFormula += ')'; - } - EnterBlock( aFormula, NULL ); + ScRange range; + ScBaseCell* pCell = NULL; + CellType eType; + + //get the selected range + rMark.GetMarkArea( range ); + // and all the stuff needed :/ + SCCOL nStartCol = range.aStart.Col(); + SCROW nStartRow = range.aStart.Row(); + SCTAB nStartTab = range.aStart.Tab(); + SCCOL nEndCol = range.aEnd.Col(); + SCROW nEndRow = range.aEnd.Row(); + SCTAB nEndTab = range.aEnd.Tab(); + + PutInOrder( nStartCol, nEndCol ); + PutInOrder( nStartRow, nEndRow ); + PutInOrder( nStartTab, nEndTab ); + + // iterating over all cells I can find + // TODO : check if iterating on Tab is needed. + // My guess is no, but i am really not sure of it + double sum = 0; + for ( SCTAB nTab = nStartTab; nTab <= nEndTab; nTab++ ) + for ( SCCOL nCol = nStartCol; nCol <= nEndCol; nCol++ ) + for ( SCROW nRow = nStartRow; nRow <= nEndRow; nRow++ ) { + pDoc->GetCell( nCol, nRow, nTab, pCell ); + if (pCell && pCell->HasValueData()) { + eType = pCell->GetCellType(); + if (eType == CELLTYPE_FORMULA) + sum += ((ScFormulaCell*) pCell)->GetValueAlways(); + else + sum += ((ScValueCell*) pCell)->GetValue(); + } + } + EnterBlock( rtl::OUString::valueOf(sum).getStr(), NULL ); }