Related: tdf#111522 svx: fix crash with view1 doing textedit and resize/rotate

The two actually affected functions are SdrEditView::RotateMarkedObj()
and SdrDragObjOwn::EndSdrDrag(), but it looks like the other functions
in SdrEditView are safe to be changed the same way.

I expect IsUndoEnabled() can't be changed, though: that would mean there
would be no undo for the text edit itself, either.

If other actions still crash, the pattern is the same: put a breakpoint
on the SdrUndoAction constructor and see the backtrace to find the
function that calls IsUndoEnabled() without calling CanDoSdrUndo() at
the same time.

Change-Id: If9324e311ec6e9f68a951559e903e14bb72ea31c
Reviewed-on: https://gerrit.libreoffice.org/73669
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
diff --git a/sd/qa/unit/uiimpress.cxx b/sd/qa/unit/uiimpress.cxx
index 910f4a9..2d3710f 100644
--- a/sd/qa/unit/uiimpress.cxx
+++ b/sd/qa/unit/uiimpress.cxx
@@ -93,6 +93,13 @@ CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf111522)
    // Without the accompanying fix in place, this test would have failed with an assertion failure
    // in SdrObjEditView::SdrEndTextEdit() as mpOldTextEditUndoManager was not nullptr.
    pViewShell2->GetViewFrame()->GetDispatcher()->Execute(SID_UNDO, SfxCallMode::SYNCHRON);

    // Rotate the shape in window 2 & undo.
    pView2->MarkObj(pShape2, pView2->GetSdrPageView());
    pView2->RotateMarkedObj(pShape2->GetLastBoundRect().Center(), /*nAngle=*/45);
    // Without the accompanying fix in place, this test would have failed with an assertion failure
    // in SdrObjEditView::SdrEndTextEdit() as mpOldTextEditUndoManager was not nullptr.
    pViewShell2->GetViewFrame()->GetDispatcher()->Execute(SID_UNDO, SfxCallMode::SYNCHRON);
}

CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/svx/source/svdraw/svddrgmt.cxx b/svx/source/svdraw/svddrgmt.cxx
index 05d44ce..f41a799 100644
--- a/svx/source/svdraw/svddrgmt.cxx
+++ b/svx/source/svdraw/svddrgmt.cxx
@@ -1366,7 +1366,7 @@ bool SdrDragObjOwn::EndSdrDrag(bool /*bCopy*/)
    {
        std::unique_ptr<SdrUndoAction> pUndo;
        std::unique_ptr<SdrUndoAction> pUndo2;
        const bool bUndo = getSdrDragView().IsUndoEnabled();
        const bool bUndo = getSdrDragView().IsUndoEnabled() && getSdrDragView().CanDoSdrUndo();

        if( bUndo )
        {
diff --git a/svx/source/svdraw/svdedtv1.cxx b/svx/source/svdraw/svdedtv1.cxx
index 66bc4c15..47e05a0 100644
--- a/svx/source/svdraw/svdedtv1.cxx
+++ b/svx/source/svdraw/svdedtv1.cxx
@@ -88,7 +88,7 @@ void SdrEditView::SetMarkedObjRect(const tools::Rectangle& rRect)
    long w1=rRect.Right()-x1;
    long h1=rRect.Bottom()-y1;

    const bool bUndo = IsUndoEnabled();
    const bool bUndo = IsUndoEnabled() && CanDoSdrUndo();
    if( bUndo )
        BegUndo(ImpGetDescriptionString(STR_EditPosSize));

@@ -208,7 +208,7 @@ void SdrEditView::MoveMarkedObj(const Size& rSiz, bool bCopy)

void SdrEditView::ResizeMarkedObj(const Point& rRef, const Fraction& xFact, const Fraction& yFact, bool bCopy)
{
    const bool bUndo = IsUndoEnabled();
    const bool bUndo = IsUndoEnabled() && CanDoSdrUndo();
    if( bUndo )
    {
        OUString aStr {ImpGetDescriptionString(STR_EditResize)};
@@ -242,7 +242,7 @@ void SdrEditView::ResizeMultMarkedObj(const Point& rRef,
    const bool bWdh,
    const bool bHgt)
{
    const bool bUndo = IsUndoEnabled();
    const bool bUndo = IsUndoEnabled() && CanDoSdrUndo();
    if( bUndo )
    {
        BegUndo(ImpGetDescriptionString(STR_EditResize));
@@ -302,7 +302,7 @@ long SdrEditView::GetMarkedObjRotate() const

void SdrEditView::RotateMarkedObj(const Point& rRef, long nAngle, bool bCopy)
{
    const bool bUndo = IsUndoEnabled();
    const bool bUndo = IsUndoEnabled() && CanDoSdrUndo();
    if( bUndo )
    {
        OUString aStr {ImpGetDescriptionString(STR_EditRotate)};
@@ -357,7 +357,7 @@ void SdrEditView::RotateMarkedObj(const Point& rRef, long nAngle, bool bCopy)

void SdrEditView::MirrorMarkedObj(const Point& rRef1, const Point& rRef2, bool bCopy)
{
    const bool bUndo = IsUndoEnabled();
    const bool bUndo = IsUndoEnabled() && CanDoSdrUndo();

    if( bUndo )
    {
@@ -456,7 +456,7 @@ long SdrEditView::GetMarkedObjShear() const

void SdrEditView::ShearMarkedObj(const Point& rRef, long nAngle, bool bVShear, bool bCopy)
{
    const bool bUndo = IsUndoEnabled();
    const bool bUndo = IsUndoEnabled() && CanDoSdrUndo();

    if( bUndo )
    {
@@ -569,7 +569,7 @@ void SdrEditView::CrookMarkedObj(const Point& rRef, const Point& rRad, SdrCrookM
    bool bVertical, bool bNoContortion, bool bCopy)
{
    tools::Rectangle aMarkRect(GetMarkedObjRect());
    const bool bUndo = IsUndoEnabled();
    const bool bUndo = IsUndoEnabled() && CanDoSdrUndo();

    bool bRotate=bNoContortion && eMode==SdrCrookMode::Rotate && IsRotateAllowed();

@@ -644,7 +644,7 @@ void SdrEditView::ImpDistortObj(SdrObject* pO, const tools::Rectangle& rRef, con

void SdrEditView::DistortMarkedObj(const tools::Rectangle& rRef, const XPolygon& rDistortedRect, bool bNoContortion, bool bCopy)
{
    const bool bUndo = IsUndoEnabled();
    const bool bUndo = IsUndoEnabled() && CanDoSdrUndo();

    if( bUndo )
    {
@@ -753,7 +753,7 @@ void SdrEditView::SetNotPersistAttrToMarked(const SfxItemSet& rAttr)
        ShearMarkedObj(aAllSnapRect.Center(),nAngle,true);
    }

    const bool bUndo = IsUndoEnabled();
    const bool bUndo = IsUndoEnabled() && CanDoSdrUndo();

    // TODO: check if WhichRange is necessary.
    const size_t nMarkCount=GetMarkedObjectCount();
@@ -1001,7 +1001,7 @@ void SdrEditView::SetAttrToMarked(const SfxItemSet& rAttr, bool bReplaceAll)
        nWhich = aIter.NextWhich();
    }

    const bool bUndo = IsUndoEnabled();
    const bool bUndo = IsUndoEnabled() && CanDoSdrUndo();
    if( bUndo )
    {
        BegUndo(ImpGetDescriptionString(STR_EditSetAttributes));
@@ -1179,7 +1179,7 @@ void SdrEditView::SetStyleSheetToMarked(SfxStyleSheet* pStyleSheet, bool bDontRe
{
    if (AreObjectsMarked())
    {
        const bool bUndo = IsUndoEnabled();
        const bool bUndo = IsUndoEnabled() && CanDoSdrUndo();

        if( bUndo )
        {
@@ -1741,7 +1741,7 @@ void SdrEditView::AlignMarkedObjects(SdrHorAlign eHor, SdrVertAlign eVert)
    if (!GetMarkedObjectCount())
        return;

    const bool bUndo = IsUndoEnabled();
    const bool bUndo = IsUndoEnabled() && CanDoSdrUndo();
    if( bUndo )
    {
        OUString aStr(GetDescriptionOfMarkedObjects());