diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2023-03-10 13:36:37 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-03-14 12:53:04 +0000 |
commit | 20d7735c21eeee208536f98c641ca6ba8da95606 (patch) | |
tree | 386952e0a356ad509dbc7c30e1205b1d5abf0a69 | |
parent | 1dd68786a927a23e5465589025abd90b8c9f4e7b (diff) |
sw content control: fix lost properties on copy&paste
cp-22.05.11-1
E.g. a checkbox content control was turned into a rich text one on
copy&paste, so toggling didn't work on the copied content control.
(cherry picked from commit c804c5354855188b5a37219cfe11dc079dc235f4)
Change-Id: Ia7262e0b88dff12a2f87acd7b0e6cc3fbde3c3a8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148836
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Tested-by: Justin Luth <jluth@mail.com>
Reviewed-by: Justin Luth <jluth@mail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r-- | sw/qa/core/txtnode/txtnode.cxx | 30 | ||||
-rw-r--r-- | sw/source/core/txtnode/attrcontentcontrol.cxx | 36 |
2 files changed, 66 insertions, 0 deletions
diff --git a/sw/qa/core/txtnode/txtnode.cxx b/sw/qa/core/txtnode/txtnode.cxx index bd9bcd66d6fc..5a88a2225846 100644 --- a/sw/qa/core/txtnode/txtnode.cxx +++ b/sw/qa/core/txtnode/txtnode.cxx @@ -30,6 +30,7 @@ #include <txatbase.hxx> #include <ndtxt.hxx> #include <textcontentcontrol.hxx> +#include <swdtflvr.hxx> constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/txtnode/data/"; @@ -318,6 +319,35 @@ CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testDateContentControlKeyboard) CPPUNIT_ASSERT(bShouldOpen); } +CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testContentControlCopy) +{ + // Given a document with a content control: + SwDoc* pDoc = createSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(SwContentControlType::CHECKBOX); + + // When copying that content control: + pWrtShell->SelAll(); + rtl::Reference<SwTransferable> xTransfer = new SwTransferable(*pWrtShell); + xTransfer->Copy(); + // Kill the selection, go to the end of the document: + pWrtShell->EndOfSection(); + TransferableDataHelper aHelper(xTransfer); + SwTransferable::Paste(*pWrtShell, aHelper); + + // Then make sure that the copy is also a checkbox: + SwContentControlManager& rManager = pDoc->GetContentControlManager(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rManager.GetCount()); + const SwFormatContentControl& rFormat1 = rManager.Get(0)->GetContentControl(); + CPPUNIT_ASSERT_EQUAL(SwContentControlType::CHECKBOX, rFormat1.GetContentControl()->GetType()); + const SwFormatContentControl& rFormat2 = rManager.Get(1)->GetContentControl(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 (CHECKBOX) + // - Actual : 0 (RICH_TEXT) + // i.e. properties were not copied from the source to the destination content control. + CPPUNIT_ASSERT_EQUAL(SwContentControlType::CHECKBOX, rFormat2.GetContentControl()->GetType()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/txtnode/attrcontentcontrol.cxx b/sw/source/core/txtnode/attrcontentcontrol.cxx index 07e7afceb027..2b96ddda53ed 100644 --- a/sw/source/core/txtnode/attrcontentcontrol.cxx +++ b/sw/source/core/txtnode/attrcontentcontrol.cxx @@ -182,6 +182,42 @@ SwContentControl::SwContentControl(SwFormatContentControl* pFormat) , m_pFormat(pFormat) , m_pTextNode(nullptr) { + if (!pFormat) + { + return; + } + + const std::shared_ptr<SwContentControl>& pOther = pFormat->GetContentControl(); + if (!pOther) + { + return; + } + + SetShowingPlaceHolder(pOther->m_bShowingPlaceHolder); + SetCheckbox(pOther->m_bCheckbox); + SetChecked(pOther->m_bChecked); + SetCheckedState(pOther->m_aCheckedState); + SetUncheckedState(pOther->m_aUncheckedState); + SetListItems(pOther->m_aListItems); + SetPicture(pOther->m_bPicture); + SetDate(pOther->m_bDate); + SetDateFormat(pOther->m_aDateFormat); + SetDateLanguage(pOther->m_aDateLanguage); + SetCurrentDate(pOther->m_aCurrentDate); + SetPlainText(pOther->m_bPlainText); + SetComboBox(pOther->m_bComboBox); + SetDropDown(pOther->m_bDropDown); + SetPlaceholderDocPart(pOther->m_aPlaceholderDocPart); + SetDataBindingPrefixMappings(pOther->m_aDataBindingPrefixMappings); + SetDataBindingXpath(pOther->m_aDataBindingXpath); + SetDataBindingStoreItemID(pOther->m_aDataBindingStoreItemID); + SetColor(pOther->m_aColor); + SetAppearance(pOther->m_aAppearance); + SetAlias(pOther->m_aAlias); + SetTag(pOther->m_aTag); + SetId(pOther->m_nId); + SetTabIndex(pOther->m_nTabIndex); + SetLock(pOther->m_aLock); } SwContentControl::~SwContentControl() {} |