--- source/ui/view/viewfun2.cxx.old 2007-03-31 21:40:23.000000000 +0200 +++ source/ui/view/viewfun2.cxx 2007-03-31 23:54:42.000000000 +0200 @@ -397,31 +397,47 @@ void ScViewFunc::EnterAutoSum(const ScRangeList& rRangeList, sal_Bool bSubTotal) // Block mit Summen fuellen { 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 )