--- sc/source/ui/view/viewfun2.cxx.old 2007-03-31 21:40:23.000000000 +0200 +++ sc/source/ui/view/viewfun2.cxx 2007-04-01 14:36:21.000000000 +0200 @@ -393,35 +393,51 @@ //---------------------------------------------------------------------------- - -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(); + SCCOL nEndCol = range.aEnd.Col(); + SCROW nEndRow = range.aEnd.Row(); + + PutInOrder( nStartCol, nEndCol ); + PutInOrder( nStartRow, nEndRow ); + + // Insert formula for the selected range String aRef; - rRangeList.Format( aRef, SCA_VALID, pDoc ); + range.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 ); + const ScFuncDesc* pDesc = pFuncMgr->Get( SC_OPCODE_SUM ); if ( pDesc && pDesc->pFuncName ) { aFormula += *pDesc->pFuncName; - if (bSubTotal) - aFormula.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "(9;" )); - else - aFormula += '('; - aFormula += aRef; - aFormula += ')'; - } - - EnterBlock( aFormula, NULL ); + aFormula += '('; + aFormula += aRef; + aFormula += ')'; + } + // try to put the sum in the good intuitive place. + SCCOL nSumCol = ((nEndCol - nStartCol == 0) ? nEndCol : nEndCol + 1); + SCROW nSumRow = ((nEndRow - nStartRow == 0) ? nEndRow : nEndRow + 1); + if (nStartCol != nEndCol && nStartRow != nEndRow) + nSumCol = nEndCol; + + GetViewData()->SetCurX(nSumCol); + GetViewData()->SetCurY(nSumRow); + EnterDataAtCursor( aFormula ); } + //---------------------------------------------------------------------------- void ScViewFunc::EnterBlock( const String& rString, const EditTextObject* pData ) --- 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 );