Index: sc/inc/sccommands.h =================================================================== --- sc/inc/sccommands.h (revision 1348444) +++ sc/inc/sccommands.h (working copy) @@ -328,5 +328,6 @@ #define CMD_FID_TAB_EVENTS ".uno:TableEvents" #define CMD_FID_TAB_MENU_SET_TAB_BG_COLOR ".uno:SetTabBgColor" #define CMD_FID_TAB_SET_TAB_BG_COLOR ".uno:TabBgColor" +#define CMD_SID_INPUT_SUM ".uno:AutoSum" #endif Index: sc/sdi/tabvwsh.sdi =================================================================== --- sc/sdi/tabvwsh.sdi (revision 1348444) +++ sc/sdi/tabvwsh.sdi (working copy) @@ -217,6 +217,8 @@ SID_OPT_LOCALE_CHANGED [ ExecMethod = Execute; ] SID_READONLY_MODE [ StateMethod = GetState; ] + + SID_INPUT_SUM [ ExecMethod = Execute; ] } Index: sc/sdi/scalc.sdi =================================================================== --- sc/sdi/scalc.sdi (revision 1348444) +++ sc/sdi/scalc.sdi (working copy) @@ -7822,3 +7822,28 @@ GroupId = GID_FORMAT; ] +//-------------------------------------------------------------------------- +SfxVoidItem AutoSum SID_INPUT_SUM + +[ + /* flags: */ + AutoUpdate = FALSE, + Cachable = Cachable, + FastCall = FALSE, + HasCoreId = FALSE, + HasDialog = FALSE, + ReadOnlyDoc = FALSE, + Toggle = FALSE, + Container = FALSE, + RecordAbsolute = FALSE, + RecordPerSet; + Synchron; + + /* config: */ + AccelConfig = TRUE, + MenuConfig = TRUE, + StatusBarConfig = FALSE, + ToolBoxConfig = FALSE, + GroupId = GID_EDIT; +] + Index: sc/source/ui/inc/inputwin.hxx =================================================================== --- sc/source/ui/inc/inputwin.hxx (revision 1348444) +++ sc/source/ui/inc/inputwin.hxx (working copy) @@ -192,7 +192,6 @@ virtual void SetText( const String& rString ); virtual String GetText() const; - sal_Bool UseSubTotal( ScRangeList* pRangeList ) const; private: ScPosWnd aWndPos; Index: sc/source/ui/inc/tabvwsh.hxx =================================================================== --- sc/source/ui/inc/tabvwsh.hxx (revision 1348444) +++ sc/source/ui/inc/tabvwsh.hxx (working copy) @@ -422,6 +422,8 @@ bool ExecuteRetypePassDlg(ScPasswordHash eDesiredHash); + void InputAutoSum( bool bFromInputWindow = false ); + using ScTabView::ShowCursor; }; Index: sc/source/ui/view/tabvwshg.cxx =================================================================== --- sc/source/ui/view/tabvwshg.cxx (revision 1348444) +++ sc/source/ui/view/tabvwshg.cxx (working copy) @@ -48,6 +48,11 @@ #include "drawview.hxx" #include "globstr.hrc" #include +#include "scmod.hxx" +#include "dbcolect.hxx" +#include "inputhdl.hxx" +#include +#include "inputwin.hxx" //------------------------------------------------------------------------ @@ -131,6 +136,174 @@ pDrView->InsertObjectSafe( pObj, *pDrView->GetSdrPageView() ); } +//------------------------------------------------------------------------ +sal_Bool lcl_UseSubTotal(ScTabViewShell* pViewSh, ScRangeList* pRangeList) +{ + sal_Bool bSubTotal(sal_False); + + ScDocument* pDoc = pViewSh->GetViewData()->GetDocument(); + sal_Int32 nRangeCount (pRangeList->Count()); + sal_Int32 nRangeIndex (0); + while (!bSubTotal && nRangeIndex < nRangeCount) + { + const ScRange* pRange = pRangeList->GetObject( nRangeIndex ); + if( pRange ) + { + SCTAB nTabEnd(pRange->aEnd.Tab()); + SCTAB nTab(pRange->aStart.Tab()); + while (!bSubTotal && nTab <= nTabEnd) + { + SCROW nRowEnd(pRange->aEnd.Row()); + SCROW nRow(pRange->aStart.Row()); + while (!bSubTotal && nRow <= nRowEnd) + { + if (pDoc->RowFiltered(nRow, nTab)) + bSubTotal = sal_True; + else + ++nRow; + } + ++nTab; + } + } + ++nRangeIndex; + } + ScDBCollection* pDBCollection = pDoc->GetDBCollection(); + sal_uInt16 nDBCount (pDBCollection->GetCount()); + sal_uInt16 nDBIndex (0); + while (!bSubTotal && nDBIndex < nDBCount) + { + ScDBData* pDB = (*pDBCollection)[nDBIndex]; + if (pDB && pDB->HasAutoFilter()) + { + nRangeIndex = 0; + while (!bSubTotal && nRangeIndex < nRangeCount) + { + const ScRange* pRange = pRangeList->GetObject( nRangeIndex ); + if( pRange ) + { + ScRange aDBArea; + pDB->GetArea(aDBArea); + if (aDBArea.Intersects(*pRange)) + bSubTotal = sal_True; + } + ++nRangeIndex; + } + } + ++nDBIndex; + } + + return bSubTotal; +} +//---------------------------------------------------------------------------- + +void ScTabViewShell::InputAutoSum( bool bFromInputWindow ) +{ + const ScMarkData& rMark = GetViewData()->GetMarkData(); + if ( rMark.IsMarked() || rMark.IsMultiMarked() ) + { + ScRangeList aMarkRangeList; + rMark.FillRangeListWithMarks( &aMarkRangeList, sal_False ); + ScDocument* pDoc = GetViewData()->GetDocument(); + + // check if one of the marked ranges is empty + bool bEmpty = false; + const sal_uLong nCount = aMarkRangeList.Count(); + for ( sal_uLong i = 0; i < nCount; ++i ) + { + const ScRange aRange( *aMarkRangeList.GetObject( i ) ); + if ( pDoc->IsBlockEmpty( aRange.aStart.Tab(), + aRange.aStart.Col(), aRange.aStart.Row(), + aRange.aEnd.Col(), aRange.aEnd.Row() ) ) + { + bEmpty = true; + break; + } + } + + if ( bEmpty ) + { + ScRangeList aRangeList; + const sal_Bool bDataFound = GetAutoSumArea( aRangeList ); + if ( bDataFound ) + { + const sal_Bool bSubTotal( lcl_UseSubTotal( this, &aRangeList ) ); + EnterAutoSum( aRangeList, bSubTotal ); // Block mit Summen fuellen + } + } + else + { + const sal_Bool bSubTotal( lcl_UseSubTotal( this, &aMarkRangeList ) ); + for ( sal_uLong i = 0; i < nCount; ++i ) + { + const ScRange aRange( *aMarkRangeList.GetObject( i ) ); + const bool bSetCursor = ( i == nCount - 1 ? true : false ); + const bool bContinue = ( i != 0 ? true : false ); + if ( !AutoSum( aRange, bSubTotal, bSetCursor, bContinue ) ) + { + MarkRange( aRange, sal_False, sal_False ); + SetCursor( aRange.aEnd.Col(), aRange.aEnd.Row() ); + ScInputHandler* pHdl = GetInputHandler(); + if ( pHdl ) + { + const ScRangeList aRangeList; + const String aFormula = GetAutoSumFormula( aRangeList, bSubTotal ); + ScInputWindow *pInputWin = pHdl->GetInputWindow(); + if ( pInputWin ) + pInputWin->SetFuncString( aFormula ); + else if ( !bFromInputWindow ) + EnterData( GetViewData()->GetCurX(), GetViewData()->GetCurY(), + GetViewData()->GetTabNo(), aFormula ); + } + break; + } + } + } + } + else + { + ScRangeList aRangeList; + const sal_Bool bDataFound = GetAutoSumArea( aRangeList ); + const sal_Bool bSubTotal( lcl_UseSubTotal( this, &aRangeList ) ); + const String aFormula = GetAutoSumFormula( aRangeList, bSubTotal ); + ScInputHandler* pHdl = GetInputHandler(); + + if ( pHdl ) + { + ScInputWindow *pInputWin = pHdl->GetInputWindow(); + if ( pInputWin ) + pInputWin->SetFuncString( aFormula ); + else if ( !bFromInputWindow ) + EnterData( GetViewData()->GetCurX(), GetViewData()->GetCurY(), + GetViewData()->GetTabNo(), aFormula ); + } + + if ( bDataFound ) + { + if ( pHdl && SC_MOD()->IsEditMode() ) + { + pHdl->InitRangeFinder( aFormula ); + + //! SetSelection am InputHandler ??? + //! bSelIsRef setzen ??? + const xub_StrLen nOpen = aFormula.Search('('); + const xub_StrLen nLen = aFormula.Len(); + if ( nOpen != STRING_NOTFOUND && nLen > nOpen ) + { + sal_uInt8 nAdd(1); + if (bSubTotal) + nAdd = 3; + ESelection aSel(0,nOpen+nAdd,0,nLen-1); + EditView* pTableView = pHdl->GetTableView(); + if (pTableView) + pTableView->SetSelection(aSel); + EditView* pTopView = pHdl->GetTopView(); + if (pTopView) + pTopView->SetSelection(aSel); + } + } + } + } +} Index: sc/source/ui/view/tabvwsh3.cxx =================================================================== --- sc/source/ui/view/tabvwsh3.cxx (revision 1348444) +++ sc/source/ui/view/tabvwsh3.cxx (working copy) @@ -1219,6 +1219,11 @@ rReq.Done(); } break; + + case SID_INPUT_SUM : + InputAutoSum(); + rReq.Done(); + break; default: DBG_ERROR("Unbekannter Slot bei ScTabViewShell::Execute"); Index: sc/source/ui/app/inputwin.cxx =================================================================== --- sc/source/ui/app/inputwin.cxx (revision 1348444) +++ sc/source/ui/app/inputwin.cxx (working copy) @@ -264,67 +264,6 @@ } } -sal_Bool ScInputWindow::UseSubTotal(ScRangeList* pRangeList) const -{ - sal_Bool bSubTotal(sal_False); - ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() ); - if ( pViewSh ) - { - ScDocument* pDoc = pViewSh->GetViewData()->GetDocument(); - sal_Int32 nRangeCount (pRangeList->Count()); - sal_Int32 nRangeIndex (0); - while (!bSubTotal && nRangeIndex < nRangeCount) - { - const ScRange* pRange = pRangeList->GetObject( nRangeIndex ); - if( pRange ) - { - SCTAB nTabEnd(pRange->aEnd.Tab()); - SCTAB nTab(pRange->aStart.Tab()); - while (!bSubTotal && nTab <= nTabEnd) - { - SCROW nRowEnd(pRange->aEnd.Row()); - SCROW nRow(pRange->aStart.Row()); - while (!bSubTotal && nRow <= nRowEnd) - { - if (pDoc->RowFiltered(nRow, nTab)) - bSubTotal = sal_True; - else - ++nRow; - } - ++nTab; - } - } - ++nRangeIndex; - } - - ScDBCollection* pDBCollection = pDoc->GetDBCollection(); - sal_uInt16 nDBCount (pDBCollection->GetCount()); - sal_uInt16 nDBIndex (0); - while (!bSubTotal && nDBIndex < nDBCount) - { - ScDBData* pDB = (*pDBCollection)[nDBIndex]; - if (pDB && pDB->HasAutoFilter()) - { - nRangeIndex = 0; - while (!bSubTotal && nRangeIndex < nRangeCount) - { - const ScRange* pRange = pRangeList->GetObject( nRangeIndex ); - if( pRange ) - { - ScRange aDBArea; - pDB->GetArea(aDBArea); - if (aDBArea.Intersects(*pRange)) - bSubTotal = sal_True; - } - ++nRangeIndex; - } - } - ++nDBIndex; - } - } - return bSubTotal; -} - void __EXPORT ScInputWindow::Select() { ScModule* pScMod = SC_MOD(); @@ -364,93 +303,7 @@ ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() ); if ( pViewSh ) { - const ScMarkData& rMark = pViewSh->GetViewData()->GetMarkData(); - if ( rMark.IsMarked() || rMark.IsMultiMarked() ) - { - ScRangeList aMarkRangeList; - rMark.FillRangeListWithMarks( &aMarkRangeList, sal_False ); - ScDocument* pDoc = pViewSh->GetViewData()->GetDocument(); - - // check if one of the marked ranges is empty - bool bEmpty = false; - const sal_uLong nCount = aMarkRangeList.Count(); - for ( sal_uLong i = 0; i < nCount; ++i ) - { - const ScRange aRange( *aMarkRangeList.GetObject( i ) ); - if ( pDoc->IsBlockEmpty( aRange.aStart.Tab(), - aRange.aStart.Col(), aRange.aStart.Row(), - aRange.aEnd.Col(), aRange.aEnd.Row() ) ) - { - bEmpty = true; - break; - } - } - - if ( bEmpty ) - { - ScRangeList aRangeList; - const sal_Bool bDataFound = pViewSh->GetAutoSumArea( aRangeList ); - if ( bDataFound ) - { - const sal_Bool bSubTotal( UseSubTotal( &aRangeList ) ); - pViewSh->EnterAutoSum( aRangeList, bSubTotal ); // Block mit Summen fuellen - } - } - else - { - const sal_Bool bSubTotal( UseSubTotal( &aMarkRangeList ) ); - for ( sal_uLong i = 0; i < nCount; ++i ) - { - const ScRange aRange( *aMarkRangeList.GetObject( i ) ); - const bool bSetCursor = ( i == nCount - 1 ? true : false ); - const bool bContinue = ( i != 0 ? true : false ); - if ( !pViewSh->AutoSum( aRange, bSubTotal, bSetCursor, bContinue ) ) - { - pViewSh->MarkRange( aRange, sal_False, sal_False ); - pViewSh->SetCursor( aRange.aEnd.Col(), aRange.aEnd.Row() ); - const ScRangeList aRangeList; - const String aFormula = pViewSh->GetAutoSumFormula( aRangeList, bSubTotal ); - SetFuncString( aFormula ); - break; - } - } - } - } - else // nur in Eingabezeile einfuegen - { - ScRangeList aRangeList; - const sal_Bool bDataFound = pViewSh->GetAutoSumArea( aRangeList ); - const sal_Bool bSubTotal( UseSubTotal( &aRangeList ) ); - const String aFormula = pViewSh->GetAutoSumFormula( aRangeList, bSubTotal ); - SetFuncString( aFormula ); - - if ( bDataFound && pScMod->IsEditMode() ) - { - ScInputHandler* pHdl = pScMod->GetInputHdl( pViewSh ); - if ( pHdl ) - { - pHdl->InitRangeFinder( aFormula ); - - //! SetSelection am InputHandler ??? - //! bSelIsRef setzen ??? - const xub_StrLen nOpen = aFormula.Search('('); - const xub_StrLen nLen = aFormula.Len(); - if ( nOpen != STRING_NOTFOUND && nLen > nOpen ) - { - sal_uInt8 nAdd(1); - if (bSubTotal) - nAdd = 3; - ESelection aSel(0,nOpen+nAdd,0,nLen-1); - EditView* pTableView = pHdl->GetTableView(); - if (pTableView) - pTableView->SetSelection(aSel); - EditView* pTopView = pHdl->GetTopView(); - if (pTopView) - pTopView->SetSelection(aSel); - } - } - } - } + pViewSh->InputAutoSum( true ); } } break; Index: officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu =================================================================== --- officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu (revision 1348444) +++ officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu (working copy) @@ -1622,6 +1622,14 @@ Assign Macro... + + + Sum + + + 1 + +