diff options
author | Sarper Akdemir <sarper.akdemir.extern@allotropia.de> | 2023-07-31 17:11:04 +0300 |
---|---|---|
committer | Thorsten Behrens <thorsten.behrens@allotropia.de> | 2024-02-22 13:13:28 +0100 |
commit | 170860775de552f255a48a1f1b37c9b3460c033d (patch) | |
tree | 7e9be8cf01907a7a2188d15819a8e59c77219bb6 | |
parent | ecc98d3fa0827f4c078610c9f43faebd62452387 (diff) |
tdf#103706: tdf#142857: sd: context aware paste for clone format
Introduces selection aware pasting for Impress/Draw's Clone
Format where paragraph properties are applied when the selection
contains a whole paragraph or there's no selection at all (i.e.
clone format applied with just a left click - without drag).
Change-Id: I37e7197580c2b8da333ada1a60408f40f85d7ef5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155108
Tested-by: Jenkins
Reviewed-by: Sarper Akdemir <sarper.akdemir.extern@allotropia.de>
-rw-r--r-- | editeng/source/editeng/editview.cxx | 10 | ||||
-rw-r--r-- | editeng/source/editeng/impedit.cxx | 23 | ||||
-rw-r--r-- | editeng/source/editeng/impedit.hxx | 2 | ||||
-rw-r--r-- | include/editeng/editview.hxx | 2 | ||||
-rw-r--r-- | sd/source/ui/func/fuformatpaintbrush.cxx | 36 |
5 files changed, 67 insertions, 6 deletions
diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx index 0e3985c49459..72bdd4d18f1c 100644 --- a/editeng/source/editeng/editview.cxx +++ b/editeng/source/editeng/editview.cxx @@ -316,6 +316,16 @@ bool EditView::HasSelection() const return pImpEditView->HasSelection(); } +bool EditView::IsSelectionFullPara() const +{ + return pImpEditView->IsSelectionFullPara(); +} + +bool EditView::IsSelectionWithinSinglePara() const +{ + return pImpEditView->IsSelectionInSinglePara(); +} + bool EditView::IsSelectionAtPoint(const Point& rPointPixel) { return pImpEditView->IsSelectionAtPoint(rPointPixel); diff --git a/editeng/source/editeng/impedit.cxx b/editeng/source/editeng/impedit.cxx index 92af0e24b848..d03a2185a929 100644 --- a/editeng/source/editeng/impedit.cxx +++ b/editeng/source/editeng/impedit.cxx @@ -2047,6 +2047,29 @@ bool ImpEditView::IsInSelection( const EditPaM& rPaM ) return false; } +bool ImpEditView::IsSelectionFullPara() const +{ + if (!IsSelectionInSinglePara()) + return false; + + sal_Int32 nSelectionStartPos = GetEditSelection().Min().GetIndex(); + sal_Int32 nSelectionEndPos = GetEditSelection().Max().GetIndex(); + + if (nSelectionStartPos > nSelectionEndPos) + std::swap(nSelectionStartPos, nSelectionEndPos); + + if (nSelectionStartPos != 0) + return false; + + const ContentNode* pNode = GetEditSelection().Min().GetNode(); + return pNode->Len() == nSelectionEndPos; +} + +bool ImpEditView::IsSelectionInSinglePara() const +{ + return GetEditSelection().Min().GetNode() == GetEditSelection().Max().GetNode(); +} + void ImpEditView::CreateAnchor() { pEditEngine->SetInSelectionMode(true); diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx index 5ff09c67257a..503e79bde400 100644 --- a/editeng/source/editeng/impedit.hxx +++ b/editeng/source/editeng/impedit.hxx @@ -416,6 +416,8 @@ public: bool IsSelectionAtPoint( const Point& rPosPixel ); bool IsInSelection( const EditPaM& rPaM ); + bool IsSelectionFullPara() const; + bool IsSelectionInSinglePara() const; void SetAnchorMode( EEAnchorMode eMode ); EEAnchorMode GetAnchorMode() const { return eAnchorMode; } diff --git a/include/editeng/editview.hxx b/include/editeng/editview.hxx index f014e3abfeb9..ce0407c36530 100644 --- a/include/editeng/editview.hxx +++ b/include/editeng/editview.hxx @@ -210,6 +210,8 @@ 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 IsSelectionWithinSinglePara() 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 ae8f2f79ab74..9bbd30939d53 100644 --- a/sd/source/ui/func/fuformatpaintbrush.cxx +++ b/sd/source/ui/func/fuformatpaintbrush.cxx @@ -37,6 +37,25 @@ #include <Window.hxx> +namespace +{ +// Paragraph properties are pasted if the selection contains a whole paragraph +// or there was no selection at all (i.e. just a left click) +bool ShouldPasteParaFormatPerSelection(const OutlinerView* pOLV) +{ + if(!pOLV) + return true; + + if(!pOLV->GetEditView().HasSelection()) + return true; + + if(!pOLV->GetEditView().IsSelectionWithinSinglePara()) + return true; + + return pOLV->GetEditView().IsSelectionFullPara(); +} +} + namespace sd { @@ -166,16 +185,21 @@ bool FuFormatPaintBrush::MouseButtonUp(const MouseEvent& rMEvt) { if( mxItemSet && mpView && mpView->AreObjectsMarked() ) { + OutlinerView* pOLV = mpView->GetTextEditOutlinerView(); + bool bNoCharacterFormats = false; - bool bNoParagraphFormats = false; + bool bNoParagraphFormats = !ShouldPasteParaFormatPerSelection(pOLV); + + if ((rMEvt.GetModifier() & KEY_MOD1) && (rMEvt.GetModifier() & KEY_SHIFT)) + { + bNoCharacterFormats = true; + bNoParagraphFormats = false; + } + else if (rMEvt.GetModifier() & KEY_MOD1) { - if( (rMEvt.GetModifier()&KEY_MOD1) && (rMEvt.GetModifier()&KEY_SHIFT) ) - bNoCharacterFormats = true; - else if( rMEvt.GetModifier() & KEY_MOD1 ) - bNoParagraphFormats = true; + bNoParagraphFormats = true; } - OutlinerView* pOLV = mpView->GetTextEditOutlinerView(); if( pOLV ) pOLV->MouseButtonUp(rMEvt); |