--- sc/source/ui/app/inputwin.cxx.old 2007-04-01 13:58:47.000000000 +0200 +++ sc/source/ui/app/inputwin.cxx 2007-04-01 14:24:46.000000000 +0200 @@ -397,9 +397,9 @@ sal_Bool bSubTotal(UseSubTotal(pRangeList)); - if ((rMark.IsMarked() || rMark.IsMultiMarked()) && bDataFound) + if (rMark.IsMarked() || rMark.IsMarkNegative() || (rMark.IsMultiMarked() && bDataFound)) { - pViewSh->EnterAutoSum( *pRangeList, bSubTotal ); // Block mit Summen fuellen + pViewSh->EnterAutoSum(); // Block mit Summen fuellen } else // nur in Eingabezeile einfuegen { --- sc/source/ui/inc/viewfunc.hxx.old 2007-04-01 14:35:38.000000000 +0200 +++ sc/source/ui/inc/viewfunc.hxx 2007-04-01 14:35:46.000000000 +0200 @@ -104,7 +104,7 @@ BYTE GetSelectionScriptType(); BOOL GetAutoSumArea(ScRangeList& rRangeList); - void EnterAutoSum(const ScRangeList& rRangeList, sal_Bool bSubTotal); + void EnterAutoSum(); void EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab, const String& rString, BOOL bRecord = TRUE ); --- sc/source/ui/view/viewfun2.cxx.old 2007-03-31 21:40:23.000000000 +0200 +++ sc/source/ui/view/viewfun2.cxx 2007-04-08 11:53:29.000000000 +0200 @@ -393,35 +393,72 @@ //---------------------------------------------------------------------------- - -void ScViewFunc::EnterAutoSum(const ScRangeList& rRangeList, sal_Bool bSubTotal) // Block mit Summen fuellen +/** Compute the formula sum for the selected range */ +void ScViewFunc::EnterAutoSum() { ScDocument* pDoc = GetViewData()->GetDocument(); + ScMarkData& rMark = GetViewData()->GetMarkData(); + ScRange range; + + //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 ); + + // Insert formula for the selected range + ScFunctionMgr* pFuncMgr = ScGlobal::GetStarCalcFunctionMgr(); + const ScFuncDesc* pDesc = pFuncMgr->Get( SC_OPCODE_SUM ); + if ( !pDesc || !pDesc->pFuncName ) { + return; + } String aRef; - rRangeList.Format( aRef, SCA_VALID, pDoc ); - 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 ) - { + // Special case : line sum + // TODO : this is not DRY, put a method to do this thing + if ((nEndRow - nStartRow == 0) && (nEndCol - nStartCol != 0)) { + range.Format( aRef, SCA_VALID, pDoc ); + + String aFormula = '='; + aFormula += *pDesc->pFuncName; + aFormula += '('; + aFormula += aRef; + aFormula += ')'; + + GetViewData()->SetCurX( nEndCol + 1); + GetViewData()->SetCurY( nEndRow ); + EnterDataAtCursor( aFormula ); + return; + } + + // common case : table sum, one for each row + for (SCCOL nCurCol = nStartCol; nCurCol <= nEndCol; nCurCol++) { + ScRange sumRange( nCurCol, nStartRow, nStartTab, nCurCol, nEndRow, nEndTab ); + + sumRange.Format( aRef, SCA_VALID, pDoc ); + + String aFormula = '='; aFormula += *pDesc->pFuncName; - if (bSubTotal) - aFormula.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "(9;" )); - else - aFormula += '('; + aFormula += '('; aFormula += aRef; aFormula += ')'; + + GetViewData()->SetCurX( nCurCol ); + GetViewData()->SetCurY( nEndRow + 1 ); + EnterDataAtCursor( aFormula ); } - - EnterBlock( aFormula, NULL ); } + //---------------------------------------------------------------------------- void ScViewFunc::EnterBlock( const String& rString, const EditTextObject* pData )