tdf#103706: tdf#142857: sd: context aware paste for clone format

Change-Id: I37e7197580c2b8da333ada1a60408f40f85d7ef5
diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx
index 72e9aec..32f8ad2 100644
--- a/editeng/source/editeng/editview.cxx
+++ b/editeng/source/editeng/editview.cxx
@@ -316,6 +316,34 @@ bool EditView::HasSelection() const
    return pImpEditView->HasSelection();
}

bool EditView::IsSelectionFullPara() const
{
    sal_Int32 nSelectionStartPara = pImpEditView->pEditEngine->GetEditDoc().GetPos(
        pImpEditView->GetEditSelection().Min().GetNode());
    sal_Int32 nSelectionEndPara = pImpEditView->pEditEngine->GetEditDoc().GetPos(
        pImpEditView->GetEditSelection().Max().GetNode());

    if (nSelectionStartPara != nSelectionEndPara)
        return false;

    sal_Int32 nSelectionStartPos = pImpEditView->GetEditSelection().Min().GetIndex();
    sal_Int32 nSelectionEndPos = pImpEditView->GetEditSelection().Max().GetIndex();

    if (nSelectionStartPos > nSelectionEndPos)
        std::swap(nSelectionStartPos, nSelectionEndPos);

    if (nSelectionStartPos != 0)
        return false;

    const ContentNode* pNode
        = pImpEditView->pEditEngine->GetEditDoc().GetObject(nSelectionStartPara);

    if (pNode->Len() != nSelectionEndPos)
        return false;

    return true;
}

bool EditView::IsSelectionAtPoint(const Point& rPointPixel)
{
    return pImpEditView->IsSelectionAtPoint(rPointPixel);
diff --git a/include/editeng/editview.hxx b/include/editeng/editview.hxx
index 1ea777e..e6188f2 100644
--- a/include/editeng/editview.hxx
+++ b/include/editeng/editview.hxx
@@ -219,6 +219,7 @@ public:
    void            SelectCurrentWord( sal_Int16 nWordType = css::i18n::WordType::ANYWORD_IGNOREWHITESPACES );
    /// Returns the rectangles of the current selection in TWIPs.
    void GetSelectionRectangles(std::vector<tools::Rectangle>& rLogicRects) const;
    bool IsSelectionFullPara() const;

    bool            IsInsertMode() const;
    void            SetInsertMode( bool bInsert );
diff --git a/sd/source/ui/func/fuformatpaintbrush.cxx b/sd/source/ui/func/fuformatpaintbrush.cxx
index 26c2d2c..62b2efa 100644
--- a/sd/source/ui/func/fuformatpaintbrush.cxx
+++ b/sd/source/ui/func/fuformatpaintbrush.cxx
@@ -167,8 +167,18 @@ bool FuFormatPaintBrush::MouseButtonUp(const MouseEvent& rMEvt)
{
    if( mxItemSet && mpView && mpView->AreObjectsMarked() )
    {
        bool bIsCloneFormatDirectOnly
            = SD_MOD()->GetSdOptions(mpDoc->GetDocumentType())->IsCloneFormatDirectOnly();
        OutlinerView* pOLV = mpView->GetTextEditOutlinerView();

        bool bIsCloneFormatDirectOnly = true;
        // Paste paragraph properties if the whole paragraph is selected or
        // there was no selection at all (i.e. just a left click)
        if (!pOLV || (pOLV
                      && (!pOLV->GetEditView().HasSelection() || pOLV->GetEditView().IsSelectionFullPara())))
        {
            bIsCloneFormatDirectOnly
                = SD_MOD()->GetSdOptions(mpDoc->GetDocumentType())->IsCloneFormatDirectOnly();
        }

        bool bNoCharacterFormats = false;
        bool bNoParagraphFormats = bIsCloneFormatDirectOnly ? true : false;
        {
@@ -178,7 +188,6 @@ bool FuFormatPaintBrush::MouseButtonUp(const MouseEvent& rMEvt)
                bNoParagraphFormats = bIsCloneFormatDirectOnly ? false : true;
        }

        OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
        if( pOLV )
            pOLV->MouseButtonUp(rMEvt);