tdf#149141 - Writer - Added default object creation when drag size too low

Patch in case consistency is required for suggested Draw/Impress change here : https://gerrit.libreoffice.org/c/core/+/134499

Change-Id: If4f51109633338620cfe836695214df20c3ec577
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134682
Tested-by: Jenkins
Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
diff --git a/sw/source/uibase/inc/concustomshape.hxx b/sw/source/uibase/inc/concustomshape.hxx
index 1ebb77c..cc2358c 100644
--- a/sw/source/uibase/inc/concustomshape.hxx
+++ b/sw/source/uibase/inc/concustomshape.hxx
@@ -47,6 +47,7 @@ class ConstCustomShape final : public SwDrawBase
    static OUString GetShapeTypeFromRequest( SfxRequest const & rReq );

    virtual void CreateDefaultObject() override;
    virtual void CreateDefaultObjectAtPosWithSize(Point aPos, Size aSize) override;

    // #i33136#
    virtual bool doConstructOrthogonal() const override;
diff --git a/sw/source/uibase/inc/drawbase.hxx b/sw/source/uibase/inc/drawbase.hxx
index 6aeb445..ccc045c 100644
--- a/sw/source/uibase/inc/drawbase.hxx
+++ b/sw/source/uibase/inc/drawbase.hxx
@@ -63,6 +63,7 @@ public:
    virtual void Deactivate();                      // deactivate function

    virtual void CreateDefaultObject();
    virtual void CreateDefaultObjectAtPosWithSize(Point aPos, Size aSize);

    // #i33136#
    virtual bool doConstructOrthogonal() const;
diff --git a/sw/source/uibase/ribbar/concustomshape.cxx b/sw/source/uibase/ribbar/concustomshape.cxx
index e830a44..56030fc 100644
--- a/sw/source/uibase/ribbar/concustomshape.cxx
+++ b/sw/source/uibase/ribbar/concustomshape.cxx
@@ -171,6 +171,22 @@ void ConstCustomShape::CreateDefaultObject()
    }
}

void ConstCustomShape::CreateDefaultObjectAtPosWithSize(Point aPos, Size aSize)
{
    SwDrawBase::CreateDefaultObjectAtPosWithSize(aPos, aSize);
    SdrView *pSdrView = m_pSh->GetDrawView();
    if ( pSdrView )
    {
        const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
        if ( rMarkList.GetMarkCount() == 1 )
        {
            SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
            if ( dynamic_cast< const SdrObjCustomShape *>( pObj ) )
                SetAttributes( pObj );
        }
    }
}

// #i33136#
bool ConstCustomShape::doConstructOrthogonal() const
{
diff --git a/sw/source/uibase/ribbar/drawbase.cxx b/sw/source/uibase/ribbar/drawbase.cxx
index b88c964..36a0085 100644
--- a/sw/source/uibase/ribbar/drawbase.cxx
+++ b/sw/source/uibase/ribbar/drawbase.cxx
@@ -254,7 +254,7 @@ bool SwDrawBase::MouseButtonUp(const MouseEvent& rMEvt)
                           SdrObjKind::PathFill == nDrawMode ||
                           SdrObjKind::FreehandLine == nDrawMode ||
                           SdrObjKind::FreehandFill == nDrawMode;
        if(rMEvt.IsRight() || (aPnt == m_aStartPos && !bMultiPoint))
        if(rMEvt.IsRight())
        {
            m_pSh->BreakCreate();
            m_pView->LeaveDrawCreate();
@@ -269,7 +269,12 @@ bool SwDrawBase::MouseButtonUp(const MouseEvent& rMEvt)
                m_pSh->StartUndo(SwUndoId::INSERT, &aRewriter);
            }

            m_pSh->EndCreate(SdrCreateCmd::ForceEnd);
            bool didCreate = m_pSh->EndCreate(SdrCreateCmd::ForceEnd);
            if(!didCreate && !bMultiPoint)
            {
                CreateDefaultObjectAtPosWithSize(aPnt, Size(1000, 1000));
            }

            if (SdrObjKind::NONE == nDrawMode)   // Text border inserted
            {
                uno::Reference< frame::XDispatchRecorder > xRecorder =
@@ -523,6 +528,21 @@ void SwDrawBase::CreateDefaultObject()
    m_pSh->CreateDefaultShape(m_pWin->GetSdrDrawMode(), aRect, m_nSlotId);
}

void SwDrawBase::CreateDefaultObjectAtPosWithSize(Point aPos, Size aSize)
{
    aPos.AdjustX(-sal_Int32(aSize.getWidth() / 2));
    aPos.AdjustY(-sal_Int32(aSize.getHeight() / 2));

    SdrView* sdrView =  m_pView->GetDrawView();
    SdrPageView *pPV = sdrView->GetSdrPageView();

    if(sdrView->IsSnapEnabled())
        aPos = sdrView->GetSnapPos(aPos, pPV);

    ::tools::Rectangle aNewObjectRectangle(aPos, aSize);
    m_pSh->CreateDefaultShape(m_pWin->GetSdrDrawMode(), aNewObjectRectangle, m_nSlotId);
}

Point  SwDrawBase::GetDefaultCenterPos() const
{
    Size aDocSz(m_pSh->GetDocSize());