summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-11-09 15:50:01 +0100
committerMiklos Vajna <vmiklos@collabora.com>2022-11-10 17:12:22 +0100
commit295ae0ab150d8e9ea5da39c518906bdb5cb3aead (patch)
treea0804d185b4bbf4d89a670703d228f3b78347fb3 /sw
parent53b2132137f526106a3d57ffc6a9cb088a221e17 (diff)
sw content controls: allow no list items in a dropdown
- Replace SwContentControl::HasListItems(), which assumed that the type is dropdown if we have list items. This is not valid, it's OK to have a dropdown with no list items. Add a GetDropDown() instead to check for the type, explicitly. - UNO API sets the dropdown bit when list items are set and the type is not expilcitly combo box or drop down, to keep backwards compatibility with existing documents. - No change to the edit shell, SwDropDownContentControlButton already checked if items are empty and used STR_DROP_DOWN_EMPTY_LIST in that case, but that was dead code previously. - ODT & DOCX filters are now updated, ODF has a new <loext:content-control loext:dropdown="..."> attribute to specify that the type is a dropdown, explicitly. (cherry picked from commit 56db6406b0b63a2d2d99024e7c311ebd874f3893) Conflicts: xmloff/qa/unit/text.cxx Change-Id: Id577ba9639151549a8f953aab31685a73a898504 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142544 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/formatcontentcontrol.hxx9
-rw-r--r--sw/inc/unoprnms.hxx1
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport17.cxx1
-rw-r--r--sw/source/core/crsr/viscrs.cxx4
-rw-r--r--sw/source/core/txtnode/attrcontentcontrol.cxx17
-rw-r--r--sw/source/core/unocore/unocontentcontrol.cxx40
-rw-r--r--sw/source/core/unocore/unomap1.cxx1
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx2
-rw-r--r--sw/source/ui/misc/contentcontroldlg.cxx2
-rw-r--r--sw/source/uibase/uno/unotxdoc.cxx2
-rw-r--r--sw/source/uibase/wrtsh/wrtsh1.cxx13
11 files changed, 77 insertions, 15 deletions
diff --git a/sw/inc/formatcontentcontrol.hxx b/sw/inc/formatcontentcontrol.hxx
index 86bc8a0c62b7..a44c8b9b5a44 100644
--- a/sw/inc/formatcontentcontrol.hxx
+++ b/sw/inc/formatcontentcontrol.hxx
@@ -151,6 +151,9 @@ class SW_DLLPUBLIC SwContentControl : public sw::BroadcastingModify
/// Same as drop-down, but free-form input is also accepted.
bool m_bComboBox = false;
+ /// Same as combo box, but free-form input is not accepted.
+ bool m_bDropDown = false;
+
/// The placeholder's doc part: just remembered.
OUString m_aPlaceholderDocPart;
@@ -236,8 +239,6 @@ public:
std::vector<SwContentControlListItem> GetListItems() const { return m_aListItems; }
- bool HasListItems() const { return !m_aListItems.empty(); }
-
void SetListItems(const std::vector<SwContentControlListItem>& rListItems)
{
m_aListItems = rListItems;
@@ -280,6 +281,10 @@ public:
bool GetComboBox() const { return m_bComboBox; }
+ void SetDropDown(bool bDropDown) { m_bDropDown = bDropDown; }
+
+ bool GetDropDown() const { return m_bDropDown; }
+
void SetPlaceholderDocPart(const OUString& rPlaceholderDocPart)
{
m_aPlaceholderDocPart = rPlaceholderDocPart;
diff --git a/sw/inc/unoprnms.hxx b/sw/inc/unoprnms.hxx
index 64fe359f7ac7..37069b07925f 100644
--- a/sw/inc/unoprnms.hxx
+++ b/sw/inc/unoprnms.hxx
@@ -882,6 +882,7 @@
#define UNO_NAME_CURRENT_DATE "CurrentDate"
#define UNO_NAME_PLAIN_TEXT "PlainText"
#define UNO_NAME_COMBO_BOX "ComboBox"
+#define UNO_NAME_DROP_DOWN "DropDown"
#define UNO_NAME_PLACEHOLDER_DOC_PART "PlaceholderDocPart"
#define UNO_NAME_DATA_BINDING_PREFIX_MAPPINGS "DataBindingPrefixMappings"
#define UNO_NAME_DATA_BINDING_XPATH "DataBindingXpath"
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index d7f85c501b47..8ccd9f1f6540 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -202,6 +202,7 @@ CPPUNIT_TEST_FIXTURE(Test, testDropdownContentControlExport)
xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY);
{
+ xContentControlProps->setPropertyValue("DropDown", uno::Any(true));
uno::Sequence<beans::PropertyValues> aListItems = {
{
comphelper::makePropertyValue("DisplayText", uno::Any(OUString("red"))),
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index ec07f4353881..0e73555c0c94 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -697,7 +697,7 @@ void SwSelPaintRects::HighlightContentControl()
aJson.put("action", "show");
aJson.put("rectangles", aPayload);
- if (pContentControl && pContentControl->HasListItems())
+ if (pContentControl && (pContentControl->GetComboBox() || pContentControl->GetDropDown()))
{
tools::ScopedJsonWriterArray aItems = aJson.startArray("items");
for (const auto& rItem : pContentControl->GetListItems())
@@ -742,7 +742,7 @@ void SwSelPaintRects::HighlightContentControl()
}
}
- if (pContentControl && pContentControl->HasListItems())
+ if (pContentControl && (pContentControl->GetComboBox() || pContentControl->GetDropDown()))
{
if (pWrtShell)
{
diff --git a/sw/source/core/txtnode/attrcontentcontrol.cxx b/sw/source/core/txtnode/attrcontentcontrol.cxx
index 263b64a2da8f..7300ecfdf265 100644
--- a/sw/source/core/txtnode/attrcontentcontrol.cxx
+++ b/sw/source/core/txtnode/attrcontentcontrol.cxx
@@ -334,10 +334,17 @@ bool SwContentControl::IsInteractingCharacter(sal_Unicode cCh)
bool SwContentControl::ShouldOpenPopup(const vcl::KeyCode& rKeyCode)
{
- if (HasListItems() || GetDate())
+ switch (GetType())
{
- // Alt-down opens the popup.
- return rKeyCode.IsMod2() && rKeyCode.GetCode() == KEY_DOWN;
+ case SwContentControlType::DROP_DOWN_LIST:
+ case SwContentControlType::COMBO_BOX:
+ case SwContentControlType::DATE:
+ {
+ // Alt-down opens the popup.
+ return rKeyCode.IsMod2() && rKeyCode.GetCode() == KEY_DOWN;
+ }
+ default:
+ break;
}
return false;
@@ -355,7 +362,7 @@ SwContentControlType SwContentControl::GetType() const
return SwContentControlType::COMBO_BOX;
}
- if (!m_aListItems.empty())
+ if (m_bDropDown)
{
return SwContentControlType::DROP_DOWN_LIST;
}
@@ -407,6 +414,8 @@ void SwContentControl::dumpAsXml(xmlTextWriterPtr pWriter) const
BAD_CAST(OString::boolean(m_bPlainText).getStr()));
(void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("combo-box"),
BAD_CAST(OString::boolean(m_bComboBox).getStr()));
+ (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("drop-down"),
+ BAD_CAST(OString::boolean(m_bDropDown).getStr()));
(void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("placeholder-doc-part"),
BAD_CAST(m_aPlaceholderDocPart.toUtf8().getStr()));
(void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("data-binding-prefix-mappings"),
diff --git a/sw/source/core/unocore/unocontentcontrol.cxx b/sw/source/core/unocore/unocontentcontrol.cxx
index bae19e9b6edd..c67dc8193de9 100644
--- a/sw/source/core/unocore/unocontentcontrol.cxx
+++ b/sw/source/core/unocore/unocontentcontrol.cxx
@@ -169,6 +169,7 @@ public:
OUString m_aCurrentDate;
bool m_bPlainText;
bool m_bComboBox;
+ bool m_bDropDown;
OUString m_aPlaceholderDocPart;
OUString m_aDataBindingPrefixMappings;
OUString m_aDataBindingXpath;
@@ -193,6 +194,7 @@ public:
, m_bDate(false)
, m_bPlainText(false)
, m_bComboBox(false)
+ , m_bDropDown(false)
{
if (m_pContentControl)
{
@@ -543,6 +545,7 @@ void SwXContentControl::AttachImpl(const uno::Reference<text::XTextRange>& xText
pContentControl->SetCurrentDate(m_pImpl->m_aCurrentDate);
pContentControl->SetPlainText(m_pImpl->m_bPlainText);
pContentControl->SetComboBox(m_pImpl->m_bComboBox);
+ pContentControl->SetDropDown(m_pImpl->m_bDropDown);
pContentControl->SetPlaceholderDocPart(m_pImpl->m_aPlaceholderDocPart);
pContentControl->SetDataBindingPrefixMappings(m_pImpl->m_aDataBindingPrefixMappings);
pContentControl->SetDataBindingXpath(m_pImpl->m_aDataBindingXpath);
@@ -783,10 +786,21 @@ void SAL_CALL SwXContentControl::setPropertyValue(const OUString& rPropertyName,
if (m_pImpl->m_bIsDescriptor)
{
m_pImpl->m_aListItems = aItems;
+
+ if (!m_pImpl->m_bComboBox && !m_pImpl->m_bDropDown)
+ {
+ m_pImpl->m_bDropDown = true;
+ }
}
else
{
m_pImpl->m_pContentControl->SetListItems(aItems);
+
+ if (!m_pImpl->m_pContentControl->GetComboBox()
+ && !m_pImpl->m_pContentControl->GetDropDown())
+ {
+ m_pImpl->m_pContentControl->SetDropDown(true);
+ }
}
}
else if (rPropertyName == UNO_NAME_PICTURE)
@@ -894,6 +908,21 @@ void SAL_CALL SwXContentControl::setPropertyValue(const OUString& rPropertyName,
}
}
}
+ else if (rPropertyName == UNO_NAME_DROP_DOWN)
+ {
+ bool bValue;
+ if (rValue >>= bValue)
+ {
+ if (m_pImpl->m_bIsDescriptor)
+ {
+ m_pImpl->m_bDropDown = bValue;
+ }
+ else
+ {
+ m_pImpl->m_pContentControl->SetDropDown(bValue);
+ }
+ }
+ }
else if (rPropertyName == UNO_NAME_PLACEHOLDER_DOC_PART)
{
OUString aValue;
@@ -1155,6 +1184,17 @@ uno::Any SAL_CALL SwXContentControl::getPropertyValue(const OUString& rPropertyN
aRet <<= m_pImpl->m_pContentControl->GetComboBox();
}
}
+ else if (rPropertyName == UNO_NAME_DROP_DOWN)
+ {
+ if (m_pImpl->m_bIsDescriptor)
+ {
+ aRet <<= m_pImpl->m_bDropDown;
+ }
+ else
+ {
+ aRet <<= m_pImpl->m_pContentControl->GetDropDown();
+ }
+ }
else if (rPropertyName == UNO_NAME_PLACEHOLDER_DOC_PART)
{
if (m_pImpl->m_bIsDescriptor)
diff --git a/sw/source/core/unocore/unomap1.cxx b/sw/source/core/unocore/unomap1.cxx
index 05563ca34116..a584d1f59952 100644
--- a/sw/source/core/unocore/unomap1.cxx
+++ b/sw/source/core/unocore/unomap1.cxx
@@ -1039,6 +1039,7 @@ const SfxItemPropertyMapEntry* SwUnoPropertyMapProvider::GetContentControlProper
{ u"" UNO_NAME_CURRENT_DATE, 0, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
{ u"" UNO_NAME_PLAIN_TEXT, 0, cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },
{ u"" UNO_NAME_COMBO_BOX, 0, cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },
+ { u"" UNO_NAME_DROP_DOWN, 0, cppu::UnoType<bool>::get(), PROPERTY_NONE, 0 },
{ u"" UNO_NAME_PLACEHOLDER_DOC_PART, 0, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
{ u"" UNO_NAME_DATA_BINDING_PREFIX_MAPPINGS, 0, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
{ u"" UNO_NAME_DATA_BINDING_XPATH, 0, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 0d54ef129784..1fc10fdbd332 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2405,7 +2405,7 @@ void DocxAttributeOutput::WriteContentControlStart()
m_pSerializer->endElementNS(XML_w14, XML_checkbox);
}
- if (m_pContentControl->HasListItems())
+ if (m_pContentControl->GetComboBox() || m_pContentControl->GetDropDown())
{
if (m_pContentControl->GetComboBox())
{
diff --git a/sw/source/ui/misc/contentcontroldlg.cxx b/sw/source/ui/misc/contentcontroldlg.cxx
index 5770bf1bd6bd..fadb4c1739fe 100644
--- a/sw/source/ui/misc/contentcontroldlg.cxx
+++ b/sw/source/ui/misc/contentcontroldlg.cxx
@@ -120,7 +120,7 @@ SwContentControlDlg::SwContentControlDlg(weld::Window* pParent, SwWrtShell& rWrt
m_xCheckboxFrame->set_visible(false);
}
- if (m_pContentControl->HasListItems())
+ if (m_pContentControl->GetComboBox() || m_pContentControl->GetDropDown())
{
for (const auto& rListItem : m_pContentControl->GetListItems())
{
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index f3f1911d3ee2..696529b61ab0 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3417,7 +3417,7 @@ void SwXTextDocument::executeContentControlEvent(const StringMap& rArguments)
auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr);
const SwFormatContentControl& rFormatContentControl = pTextContentControl->GetContentControl();
std::shared_ptr<SwContentControl> pContentControl = rFormatContentControl.GetContentControl();
- if (!pContentControl->HasListItems())
+ if (!pContentControl->GetComboBox() && !pContentControl->GetDropDown())
{
return;
}
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx
index 52558d1963a6..4983bb3dc30f 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -1058,12 +1058,17 @@ void SwWrtShell::InsertContentControl(SwContentControlType eType)
break;
}
case SwContentControlType::COMBO_BOX:
- {
- pContentControl->SetComboBox(true);
- [[fallthrough]];
- }
case SwContentControlType::DROP_DOWN_LIST:
{
+ if (eType == SwContentControlType::COMBO_BOX)
+ {
+ pContentControl->SetComboBox(true);
+ }
+ else if (eType == SwContentControlType::DROP_DOWN_LIST)
+ {
+ pContentControl->SetDropDown(true);
+ }
+
pContentControl->SetShowingPlaceHolder(true);
if (!HasSelection())
{