From 97f0fbe5830a5d2119fe9f5e8142fe45b255c2ac Mon Sep 17 00:00:00 2001 From: Henry Castro Date: Mon, 24 Oct 2016 22:15:45 -0400 Subject: tdf#103409: No selection outline displayed when SUM button is clicked Change-Id: I8a1bb22bd0be9717a56a90732b17c4ed8f230bf3 Reviewed-on: https://gerrit.libreoffice.org/30254 Tested-by: Jenkins Reviewed-by: Henry Castro --- sc/source/ui/app/inputwin.cxx | 27 ++++++++++++++++++++++++++- sc/source/ui/inc/tabvwsh.hxx | 2 +- sc/source/ui/view/cellsh1.cxx | 28 ++++++++++++++++++---------- sc/source/ui/view/tabvwshc.cxx | 37 +++++-------------------------------- 4 files changed, 50 insertions(+), 44 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx index e0d961bc98ec..352483105ffc 100644 --- a/sc/source/ui/app/inputwin.cxx +++ b/sc/source/ui/app/inputwin.cxx @@ -331,10 +331,35 @@ void ScInputWindow::Select() ScTabViewShell* pViewSh = dynamic_cast( SfxViewShell::Current() ); if ( pViewSh ) { - const OUString aFormula = pViewSh->DoAutoSum(); + bool bSubTotal = false; + bool bRangeFinder = false; + const OUString aFormula = pViewSh->DoAutoSum(bRangeFinder, bSubTotal); if (!aFormula.isEmpty()) { SetFuncString( aFormula ); + if (bRangeFinder && pScMod->IsEditMode()) + { + ScInputHandler* pHdl = pScMod->GetInputHdl( pViewSh ); + if ( pHdl ) + { + pHdl->InitRangeFinder( aFormula ); + + //! SetSelection at the InputHandler? + //! Set bSelIsRef? + const sal_Int32 nOpen = aFormula.indexOf('('); + const sal_Int32 nLen = aFormula.getLength(); + if ( nOpen != -1 && nLen > nOpen ) + { + ESelection aSel( 0, nOpen + (bSubTotal ? 3 : 1), 0, nLen-1 ); + EditView* pTableView = pHdl->GetTableView(); + if ( pTableView ) + pTableView->SetSelection( aSel ); + EditView* pTopView = pHdl->GetTopView(); + if ( pTopView ) + pTopView->SetSelection( aSel ); + } + } + } } } } diff --git a/sc/source/ui/inc/tabvwsh.hxx b/sc/source/ui/inc/tabvwsh.hxx index 7e29d9c8152c..5b4dc42bf29d 100644 --- a/sc/source/ui/inc/tabvwsh.hxx +++ b/sc/source/ui/inc/tabvwsh.hxx @@ -383,7 +383,7 @@ public: bool IsActive() const { return bIsActive; } OUString GetFormula(ScAddress& rAddress); bool UseSubTotal(ScRangeList* pRangeList); - const OUString DoAutoSum(); + const OUString DoAutoSum(bool& rRangeFinder, bool& rSubTotal); // ugly hack to call Define Names from Manage Names void SwitchBetweenRefDialogs(SfxModelessDialog* pDialog); diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index 03983b8ebcea..e5c3fc206f0e 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -2546,19 +2546,24 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) case SID_AUTO_SUM: { - const OUString aFormula = pTabViewShell->DoAutoSum(); - if (!aFormula.isEmpty()) + bool bSubTotal = false; + bool bRangeFinder = false; + const OUString aFormula = pTabViewShell->DoAutoSum( bRangeFinder, bSubTotal ); + if ( !aFormula.isEmpty() ) { - ScInputHandler* pHdl = pScMod->GetInputHdl(pTabViewShell); - if (pHdl) + const sal_Int32 nPar = aFormula.indexOf( '(' ); + const sal_Int32 nLen = aFormula.getLength(); + ScInputHandler* pHdl = pScMod->GetInputHdl( pTabViewShell ); + + if ( pHdl && nPar != -1 ) { - if (!pScMod->IsEditMode()) + if ( !pScMod->IsEditMode() ) { - pScMod->SetInputMode(SC_INPUT_TABLE); + pScMod->SetInputMode( SC_INPUT_TABLE ); } EditView *pEditView=pHdl->GetActiveView(); - if (pEditView) + if ( pEditView ) { ESelection aTextSel = pEditView->GetSelection(); aTextSel.nStartPos = 0; @@ -2566,10 +2571,13 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) pHdl->DataChanging(); pEditView->SetSelection(aTextSel); pEditView->InsertText(aFormula); - aTextSel.nStartPos = aFormula.getLength() - 1; - aTextSel.nEndPos = aFormula.getLength() - 1; - pEditView->SetSelection(aTextSel); + pEditView->SetSelection( bRangeFinder ? ESelection( 0, nPar + ( bSubTotal ? 3 : 1 ), 0, nLen - 1 ) : ESelection( 0, nLen - 1, 0, nLen - 1 ) ); pHdl->DataChanged(); + + if ( bRangeFinder ) + { + pHdl->InitRangeFinder( aFormula ); + } } } } diff --git a/sc/source/ui/view/tabvwshc.cxx b/sc/source/ui/view/tabvwshc.cxx index 8cdfcac650a3..cdc2ee864676 100644 --- a/sc/source/ui/view/tabvwshc.cxx +++ b/sc/source/ui/view/tabvwshc.cxx @@ -598,14 +598,14 @@ bool ScTabViewShell::UseSubTotal(ScRangeList* pRangeList) return bSubTotal; } -const OUString ScTabViewShell::DoAutoSum() +const OUString ScTabViewShell::DoAutoSum(bool& rRangeFinder, bool& rSubTotal) { OUString aFormula; - ScModule* pScMod = SC_MOD(); const ScMarkData& rMark = GetViewData().GetMarkData(); if ( rMark.IsMarked() || rMark.IsMultiMarked() ) { ScRangeList aMarkRangeList; + rRangeFinder = rSubTotal = false; rMark.FillRangeListWithMarks( &aMarkRangeList, false ); ScDocument* pDoc = GetViewData().GetDocument(); @@ -660,37 +660,10 @@ const OUString ScTabViewShell::DoAutoSum() else // Only insert into input row { ScRangeList aRangeList; - const bool bDataFound = GetAutoSumArea( aRangeList ); - const bool bSubTotal( UseSubTotal( &aRangeList ) ); + rRangeFinder = GetAutoSumArea( aRangeList ); + rSubTotal = UseSubTotal( &aRangeList ); ScAddress aAddr = GetViewData().GetCurPos(); - aFormula = GetAutoSumFormula( aRangeList, bSubTotal, aAddr ); - - if ( bDataFound && pScMod->IsEditMode() ) - { - ScInputHandler* pHdl = pScMod->GetInputHdl( this ); - if ( pHdl ) - { - pHdl->InitRangeFinder( aFormula ); - - //! SetSelection at the InputHandler? - //! Set bSelIsRef? - const sal_Int32 nOpen = aFormula.indexOf('('); - const sal_Int32 nLen = aFormula.getLength(); - if ( nOpen != -1 && 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); - } - } - } + aFormula = GetAutoSumFormula( aRangeList, rSubTotal, aAddr ); } return aFormula; } -- cgit