summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-11-09 15:50:01 +0100
committerMiklos Vajna <vmiklos@collabora.com>2022-11-09 17:00:00 +0100
commit56db6406b0b63a2d2d99024e7c311ebd874f3893 (patch)
treeb7096b526b5bfd5f5a474f467761f7065f8e81c2 /sw/source
parentcb8a05bfccf77d5217f4f2e20b5898d6a24f990d (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. Change-Id: Id577ba9639151549a8f953aab31685a73a898504 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142491 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw/source')
-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
8 files changed, 68 insertions, 13 deletions
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index b112ead80317..4d34e9b89d35 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -696,7 +696,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())
@@ -741,7 +741,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 3807ee9f2dba..965c6adf8476 100644
--- a/sw/source/core/txtnode/attrcontentcontrol.cxx
+++ b/sw/source/core/txtnode/attrcontentcontrol.cxx
@@ -340,10 +340,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;
@@ -361,7 +368,7 @@ SwContentControlType SwContentControl::GetType() const
return SwContentControlType::COMBO_BOX;
}
- if (!m_aListItems.empty())
+ if (m_bDropDown)
{
return SwContentControlType::DROP_DOWN_LIST;
}
@@ -413,6 +420,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 62e93d33d68e..fbded5b45baf 100644
--- a/sw/source/core/unocore/unocontentcontrol.cxx
+++ b/sw/source/core/unocore/unocontentcontrol.cxx
@@ -170,6 +170,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)
{
@@ -480,6 +482,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);
@@ -720,10 +723,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)
@@ -831,6 +845,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;
@@ -1092,6 +1121,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 a860f2900754..92f41e52b7a2 100644
--- a/sw/source/core/unocore/unomap1.cxx
+++ b/sw/source/core/unocore/unomap1.cxx
@@ -1004,6 +1004,7 @@ o3tl::span<const SfxItemPropertyMapEntry> SwUnoPropertyMapProvider::GetContentCo
{ 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 a88049e31c09..4a0e4325d580 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2403,7 +2403,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 c530795458a0..ec45e87066c4 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 e74c490f2098..08746303cecf 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3415,7 +3415,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 9ca81b72b4cd..8cfc57a7cea1 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -1059,12 +1059,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())
{