From 70f0b3917688e7c462917d97d39443d6e75502fb Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Wed, 11 Feb 2015 11:36:58 +0000 Subject: Resolves: tdf#70062 avoid crash on ungrouping "ac char" group If you can't group a char-anchored thing with something else, then you can't ungroup a selection that contains a char-anchored group. You can group together non-char anchored things, then change the anchor type to get a char-anchored group to get into this situation. Change-Id: Id627bd11e2c749ad08fb902bf88f937ff5f06a12 --- sw/inc/fesh.hxx | 1 + sw/source/core/frmedt/feshview.cxx | 49 ++++++++++++++++++++++++++---------- sw/source/uibase/shells/drwbassh.cxx | 4 +-- 3 files changed, 39 insertions(+), 15 deletions(-) (limited to 'sw') diff --git a/sw/inc/fesh.hxx b/sw/inc/fesh.hxx index 821323a9dd47..55ef44beb866 100644 --- a/sw/inc/fesh.hxx +++ b/sw/inc/fesh.hxx @@ -506,6 +506,7 @@ public: it is possible that there are groups included. */ bool IsGroupAllowed() const; + bool IsUnGroupAllowed() const; void MirrorSelection( bool bHorizontal ); ///< Vertical if FALSE. diff --git a/sw/source/core/frmedt/feshview.cxx b/sw/source/core/frmedt/feshview.cxx index b75bdae064c0..f092a6c289e5 100644 --- a/sw/source/core/frmedt/feshview.cxx +++ b/sw/source/core/frmedt/feshview.cxx @@ -2073,6 +2073,25 @@ bool SwFEShell::IsGroupSelected() return false; } +namespace +{ + bool HasSuitableGroupingAnchor(const SdrObject* pObj) + { + bool bSuitable = true; + SwFrmFmt* pFrmFmt(::FindFrmFmt(const_cast(pObj))); + if (!pFrmFmt) + { + OSL_FAIL( " - missing frame format" ); + bSuitable = false; + } + else if (FLY_AS_CHAR == pFrmFmt->GetAnchor().GetAnchorId()) + { + bSuitable = false; + } + return bSuitable; + } +} + // Change return type. // Adjustments for drawing objects in header/footer: // allow group, only if all selected objects are in the same header/footer @@ -2095,18 +2114,7 @@ bool SwFEShell::IsGroupAllowed() const pUpGroup = pObj->GetUpGroup(); if ( bIsGroupAllowed ) - { - SwFrmFmt* pFrmFmt( ::FindFrmFmt( const_cast(pObj) ) ); - if ( !pFrmFmt ) - { - OSL_FAIL( " - missing frame format" ); - bIsGroupAllowed = false; - } - else if ( FLY_AS_CHAR == pFrmFmt->GetAnchor().GetAnchorId() ) - { - bIsGroupAllowed = false; - } - } + bIsGroupAllowed = HasSuitableGroupingAnchor(pObj); // check, if all selected objects are in the // same header/footer or not in header/footer. @@ -2143,13 +2151,28 @@ bool SwFEShell::IsGroupAllowed() const } } } - } } return bIsGroupAllowed; } +bool SwFEShell::IsUnGroupAllowed() const +{ + bool bIsUnGroupAllowed = false; + + const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList(); + for (size_t i = 0; i < rMrkList.GetMarkCount(); ++i) + { + const SdrObject* pObj = rMrkList.GetMark(i)->GetMarkedSdrObj(); + bIsUnGroupAllowed = HasSuitableGroupingAnchor(pObj); + if (!bIsUnGroupAllowed) + break; + } + + return bIsUnGroupAllowed; +} + // The group gets the anchor and the contactobject of the first in the selection void SwFEShell::GroupSelection() { diff --git a/sw/source/uibase/shells/drwbassh.cxx b/sw/source/uibase/shells/drwbassh.cxx index 75f4c6ad4132..348fff2b8c79 100644 --- a/sw/source/uibase/shells/drwbassh.cxx +++ b/sw/source/uibase/shells/drwbassh.cxx @@ -400,7 +400,7 @@ void SwDrawBaseShell::Execute(SfxRequest &rReq) break; case SID_UNGROUP: - if (pSh->IsGroupSelected()) + if (pSh->IsGroupSelected() && pSh->IsUnGroupAllowed()) { pSh->UnGroupSelection(); rBind.Invalidate(SID_GROUP); @@ -652,7 +652,7 @@ void SwDrawBaseShell::GetState(SfxItemSet& rSet) rSet.DisableItem( nWhich ); break; case SID_UNGROUP: - if ( !rSh.IsGroupSelected() || bProtected ) + if ( !rSh.IsGroupSelected() || bProtected || !rSh.IsUnGroupAllowed() ) rSet.DisableItem( nWhich ); break; case SID_ENTER_GROUP: -- cgit