sc/inc/dpsave.hxx | 2 + sc/qa/unit/ucalc.cxx | 29 ++++++++++++++++++++++++++ sc/source/core/data/dpobject.cxx | 12 +++++++++- sc/source/core/data/dpsave.cxx | 37 +++++++++++++++++++++++++++++++++ sc/source/ui/inc/gridwin.hxx | 4 ++- sc/source/ui/view/dbfunc3.cxx | 43 ++++++--------------------------------- sc/source/ui/view/gridwin.cxx | 39 ++++++++++++++++++++--------------- 7 files changed, 112 insertions(+), 54 deletions(-)
New commits: commit 28daebdf085844b8e611a90ece376ac3b19b8b9b Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Thu Dec 6 00:32:22 2012 -0500 Avoid activating window pane when launching popup window. Else, activating another window pane where the cursor is not would cause the pivot table field popup to immediately get dismissed after launch because ClickExtern() gets called from ActivatePart(). For example, imagine a field popup button is on C2, the cell cursor is on E5, and the window is frozen between rows 2 and 3. Clicking the popup button in C2 would launch it for a brief second and dismiss it immediately afterward. Conceptually, launching a popup in another pane shouldn't activate that pane anyway. So it makes sense not to activate it for that scenario. Change-Id: Ib970cb898fb9c79d254411e2519cfce74c60b72f diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx index 8a64de9..4f84d43 100644 --- a/sc/source/ui/inc/gridwin.hxx +++ b/sc/source/ui/inc/gridwin.hxx @@ -115,6 +115,8 @@ private: boost::scoped_ptr<Rectangle> mpAutoFillRect; + struct MouseEventState; + /** * Stores current visible column and row ranges, used to avoid expensive * operations on objects that are outside visible area. @@ -250,7 +252,7 @@ private: sal_Int8 DropTransferObj( ScTransferObj* pTransObj, SCCOL nDestPosX, SCROW nDestPosY, const Point& rLogicPos, sal_Int8 nDndAction ); - void HandleMouseButtonDown( const MouseEvent& rMEvt ); + void HandleMouseButtonDown( const MouseEvent& rMEvt, MouseEventState& rState ); bool DrawMouseButtonDown(const MouseEvent& rMEvt); bool DrawMouseButtonUp(const MouseEvent& rMEvt); diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index 64555e6..e7f82b8 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -167,6 +167,13 @@ extern SfxViewShell* pScActiveViewShell; // global.cxx extern sal_uInt16 nScClickMouseModifier; // global.cxx extern sal_uInt16 nScFillModeMouseModifier; // global.cxx +struct ScGridWindow::MouseEventState +{ + bool mbActivatePart; + + MouseEventState() : mbActivatePart(false) {} +}; + #define SC_FILTERLISTBOX_LINES 12 // ============================================================================ @@ -1734,7 +1741,10 @@ void ScGridWindow::MouseButtonDown( const MouseEvent& rMEvt ) { nNestedButtonState = SC_NESTEDBUTTON_DOWN; - HandleMouseButtonDown( rMEvt ); + MouseEventState aState; + HandleMouseButtonDown(rMEvt, aState); + if (aState.mbActivatePart) + pViewData->GetView()->ActivatePart(eWhich); if ( nNestedButtonState == SC_NESTEDBUTTON_UP ) { @@ -1751,7 +1761,7 @@ void ScGridWindow::MouseButtonDown( const MouseEvent& rMEvt ) nNestedButtonState = SC_NESTEDBUTTON_NONE; } -void ScGridWindow::HandleMouseButtonDown( const MouseEvent& rMEvt ) +void ScGridWindow::HandleMouseButtonDown( const MouseEvent& rMEvt, MouseEventState& rState ) { // We have to check if a context menu is shown and we have an UI // active inplace client. In that case we have to ignore the event. @@ -1835,12 +1845,9 @@ void ScGridWindow::HandleMouseButtonDown( const MouseEvent& rMEvt ) if (!bDouble) nMouseStatus = SC_GM_NONE; - if (!bFormulaMode) - { - if ( pViewData->GetActivePart() != eWhich ) - pViewData->GetView()->ActivatePart( eWhich ); - } - else + rState.mbActivatePart = !bFormulaMode; // Don't activate when in formula mode. + + if (bFormulaMode) { ScViewSelectionEngine* pSelEng = pViewData->GetView()->GetSelEngine(); pSelEng->SetWindow(this); @@ -1896,9 +1903,7 @@ void ScGridWindow::HandleMouseButtonDown( const MouseEvent& rMEvt ) { bRFMouse = true; // die anderen Variablen sind oben initialisiert - if ( pViewData->GetActivePart() != eWhich ) - pViewData->GetView()->ActivatePart( eWhich ); //! schon oben immer ??? - + rState.mbActivatePart = true; // always activate ? StartTracking(); return; } @@ -1909,7 +1914,7 @@ void ScGridWindow::HandleMouseButtonDown( const MouseEvent& rMEvt ) if ( bDouble ) pViewData->GetView()->FillCrossDblClick(); else - pScMod->InputEnterHandler(); // Autofill etc. + pScMod->InputEnterHandler(); // Autofill etc. } if ( !bCrossPointer ) @@ -1944,10 +1949,7 @@ void ScGridWindow::HandleMouseButtonDown( const MouseEvent& rMEvt ) SCTAB nTab = pViewData->GetTabNo(); ScDocument* pDoc = pViewData->GetDocument(); - - // - // AutoFilter buttons - // + // Auto filter / pivot table / data select popup. This shouldn't activate the part. if ( !bDouble && !bFormulaMode && rMEvt.IsLeft() ) { @@ -1956,11 +1958,15 @@ void ScGridWindow::HandleMouseButtonDown( const MouseEvent& rMEvt ) if (pAttr->HasAutoFilter()) { if (DoAutoFilterButton(nPosX, nPosY, rMEvt)) + { + rState.mbActivatePart = false; return; + } } if (pAttr->HasButton()) { DoPushButton( nPosX, nPosY, rMEvt ); // setzt evtl. bPivotMouse / bDPMouse + rState.mbActivatePart = false; return; } @@ -1975,6 +1981,7 @@ void ScGridWindow::HandleMouseButtonDown( const MouseEvent& rMEvt ) nMouseStatus = SC_GM_FILTER; // not set in DoAutoFilterMenue for bDataSelect CaptureMouse(); + rState.mbActivatePart = false; return; } } commit 7c1ed71c22f120279c07bb3aa60b1022ed4391d1 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Wed Dec 5 12:53:03 2012 -0500 fdo#57497: Remove group table data when all group dimensions are gone. Otherwise ungrouping date grouped dimension may crash, or produce incorrect results. Change-Id: I3634e3c0bf8336fc1221f5d234cb7e01eb1f07c6 diff --git a/sc/inc/dpsave.hxx b/sc/inc/dpsave.hxx index 14a0032..4225d1b 100644 --- a/sc/inc/dpsave.hxx +++ b/sc/inc/dpsave.hxx @@ -345,6 +345,8 @@ public: const ScDPDimensionSaveData* GetExistingDimensionData() const { return pDimensionData; } + void RemoveAllGroupDimensions( const rtl::OUString& rSrcDimName, std::vector<rtl::OUString>* pDeletedNames = NULL ); + SC_DLLPUBLIC ScDPDimensionSaveData* GetDimensionData(); // create if not there void SetDimensionData( const ScDPDimensionSaveData* pNew ); // copied void BuildAllDimensionMembers(ScDPTableData* pData); diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index cab47a6..795bea3 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -2688,6 +2688,35 @@ void Test::testPivotTableDateGrouping() CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess); } + // Remove all date grouping. The source dimension "Date" has two + // external dimensions ("Years" and "Quarters") and one internal ("Date" + // the same name but different hierarchy). Remove all of them. + pSaveData = pDPObj->GetSaveData(); + pSaveData->RemoveAllGroupDimensions(aBaseDimName); + pDPObj->SetSaveData(*pSaveData); + pDPObj->ReloadGroupTableData(); + pDPObj->InvalidateData(); + + aOutRange = refresh(pDPObj); + { + // Expected output table content. 0 = empty cell + const char* aOutputCheck[][2] = { + { "Date", 0 }, + { "2011-01-01", "1" }, + { "2011-03-02", "2" }, + { "2011-09-03", "7" }, + { "2012-01-04", "3" }, + { "2012-02-23", "4" }, + { "2012-02-24", "5" }, + { "2012-03-15", "6" }, + { "2012-12-25", "8" }, + { "Total Result", "36" } + }; + + bSuccess = checkDPTableOutput<2>(m_pDoc, aOutRange, aOutputCheck, "Remove all date grouping."); + CPPUNIT_ASSERT_MESSAGE("Table output check failed", bSuccess); + } + pDPs->FreeTable(pDPObj); CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be no more tables.", pDPs->GetCount(), static_cast<size_t>(0)); CPPUNIT_ASSERT_EQUAL_MESSAGE("There shouldn't be any more cache stored.", diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx index ebdbc35..2175d09 100644 --- a/sc/source/core/data/dpobject.cxx +++ b/sc/source/core/data/dpobject.cxx @@ -567,8 +567,18 @@ void ScDPObject::ReloadGroupTableData() const ScDPDimensionSaveData* pDimData = pSaveData->GetExistingDimensionData(); if (!pDimData || !pDimData->HasGroupDimensions()) - // No group dimensions exist. + { + // No group dimensions exist. Check if it currently has group + // dimensions, and if so, remove all of them. + ScDPGroupTableData* pData = dynamic_cast<ScDPGroupTableData*>(mpTableData.get()); + if (pData) + { + // Replace the existing group table data with the source data. + shared_ptr<ScDPTableData> pSource = pData->GetSourceTableData(); + mpTableData = pSource; + } return; + } ScDPGroupTableData* pData = dynamic_cast<ScDPGroupTableData*>(mpTableData.get()); if (pData) diff --git a/sc/source/core/data/dpsave.cxx b/sc/source/core/data/dpsave.cxx index 5c987da..f86dce4 100644 --- a/sc/source/core/data/dpsave.cxx +++ b/sc/source/core/data/dpsave.cxx @@ -1221,6 +1221,43 @@ bool ScDPSaveData::IsEmpty() const return true; // no entries that are not hidden } +void ScDPSaveData::RemoveAllGroupDimensions( const OUString& rSrcDimName, std::vector<OUString>* pDeletedNames ) +{ + if (!pDimensionData) + // No group dimensions exist. Nothing to do. + return; + + // Remove numeric group dimension (exists once at most). No need to delete + // anything in save data (grouping was done inplace in an existing base + // dimension). + pDimensionData->RemoveNumGroupDimension(rSrcDimName); + + // Remove named group dimension(s). Dimensions have to be removed from + // dimension save data and from save data too. + const ScDPSaveGroupDimension* pExistingGroup = pDimensionData->GetGroupDimForBase(rSrcDimName); + while ( pExistingGroup ) + { + rtl::OUString aGroupDimName = pExistingGroup->GetGroupDimName(); + pDimensionData->RemoveGroupDimension(aGroupDimName); // pExistingGroup is deleted + + // also remove SaveData settings for the dimension that no longer exists + RemoveDimensionByName(aGroupDimName); + + if (pDeletedNames) + pDeletedNames->push_back(aGroupDimName); + + // see if there are more group dimensions + pExistingGroup = pDimensionData->GetGroupDimForBase(rSrcDimName); + + if ( pExistingGroup && pExistingGroup->GetGroupDimName() == aGroupDimName ) + { + // still get the same group dimension? + OSL_FAIL("couldn't remove group dimension"); + pExistingGroup = NULL; // avoid endless loop + } + } +} + ScDPDimensionSaveData* ScDPSaveData::GetDimensionData() { if (!pDimensionData) diff --git a/sc/source/ui/view/dbfunc3.cxx b/sc/source/ui/view/dbfunc3.cxx index bd3fa19..3f3992a 100644 --- a/sc/source/ui/view/dbfunc3.cxx +++ b/sc/source/ui/view/dbfunc3.cxx @@ -973,52 +973,23 @@ void ScDBFunc::DateGroupDataPilot( const ScDPNumGroupInfo& rInfo, sal_Int32 nPar if (aEntries.empty()) return; + std::vector<rtl::OUString> aDeletedNames; bool bIsDataLayout; OUString aDimName = pDPObj->GetDimName( nSelectDimension, bIsDataLayout ); ScDPSaveData aData( *pDPObj->GetSaveData() ); ScDPDimensionSaveData* pDimData = aData.GetDimensionData(); // created if not there - // find original base + // find the source dimension name. rtl::OUString aBaseDimName = aDimName; if( const ScDPSaveGroupDimension* pBaseGroupDim = pDimData->GetNamedGroupDim( aDimName ) ) aBaseDimName = pBaseGroupDim->GetSourceDimName(); - // remove all existing parts (the grouping is built completely new) - - /* Remove numeric group dimension (exists once at most). No need - to delete anything in save data (grouping was done inplace in - an existing base dimension). */ - pDimData->RemoveNumGroupDimension( aBaseDimName ); - - /* Remove named group dimension(s). Collect deleted dimension - names which may be reused while recreating the groups. - Dimensions have to be removed from dimension save data and from - save data too. */ - std::vector<rtl::OUString> aDeletedNames; - const ScDPSaveGroupDimension* pExistingGroup = pDimData->GetGroupDimForBase( aBaseDimName ); - while ( pExistingGroup ) - { - rtl::OUString aGroupDimName = pExistingGroup->GetGroupDimName(); - pDimData->RemoveGroupDimension( aGroupDimName ); // pExistingGroup is deleted - - // also remove SaveData settings for the dimension that no longer exists - aData.RemoveDimensionByName( aGroupDimName ); - - /* The name can be used for the new group dimensions, although - it is still in use with the DataPilotSource. */ - aDeletedNames.push_back( aGroupDimName ); - - // see if there are more group dimensions - pExistingGroup = pDimData->GetGroupDimForBase( aBaseDimName ); - - if ( pExistingGroup && pExistingGroup->GetGroupDimName() == aGroupDimName ) - { - // still get the same group dimension? - OSL_FAIL("couldn't remove group dimension"); - pExistingGroup = NULL; // avoid endless loop - } - } + // Remove all group dimensions associated with this source dimension. For + // date grouping, we need to remove all existing groups for the affected + // source dimension and build new one(s) from scratch. Keep the deleted + // names so that they can be reused during re-construction. + aData.RemoveAllGroupDimensions(aBaseDimName, &aDeletedNames); if ( nParts ) { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits