diff options
-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() {} |