summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasily Melenchuk <vasily.melenchuk@cib.de>2021-11-18 15:04:00 +0300
committerVasily Melenchuk <vasily.melenchuk@cib.de>2021-12-01 13:33:15 +0100
commitfe1da0ce2e097e5b8db6be9c141f2615b45ea8e7 (patch)
treee815709661de82c8c5374aa734b6d4f5eeed7af0
parent4437071c3f7c0b51881b0b1a5d5a68bdd100328b (diff)
writerfilter: extend SdtHelper for better support control types
There is much more different controls which must be supprorted in future. So approach with isInsideDropDownControl() and validateDateFormat() is not sufficient. Use enum to determine and store control type. Change-Id: Ibea7fde117c059053195be213a3ae821644f277c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125471 Tested-by: Jenkins Reviewed-by: Vasily Melenchuk <vasily.melenchuk@cib.de>
-rw-r--r--writerfilter/source/dmapper/DomainMapper.cxx91
-rw-r--r--writerfilter/source/dmapper/SdtHelper.cxx13
-rw-r--r--writerfilter/source/dmapper/SdtHelper.hxx18
3 files changed, 63 insertions, 59 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 0383abb708aa..ea16e51e0f9f 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -1078,10 +1078,17 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
else
m_pImpl->setSdtEndDeferred(true);
- if (m_pImpl->m_pSdtHelper->isInsideDropDownControl())
- m_pImpl->m_pSdtHelper->createDropDownControl();
- else if (m_pImpl->m_pSdtHelper->validateDateFormat())
- m_pImpl->m_pSdtHelper->createDateContentControl();
+ switch (m_pImpl->m_pSdtHelper->getControlType())
+ {
+ case SdtControlType::dropDown:
+ m_pImpl->m_pSdtHelper->createDropDownControl();
+ break;
+ case SdtControlType::datePicker:
+ m_pImpl->m_pSdtHelper->createDateContentControl();
+ break;
+ case SdtControlType::unknown:
+ default:;
+ }
break;
case NS_ooxml::LN_CT_SdtListItem_displayText:
// TODO handle when this is != value
@@ -2638,7 +2645,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext )
case NS_ooxml::LN_CT_SdtPr_dropDownList:
case NS_ooxml::LN_CT_SdtPr_comboBox:
{
- m_pImpl->m_pSdtHelper->setInsideDropDownControl(true);
+ m_pImpl->m_pSdtHelper->setControlType(SdtControlType::dropDown);
writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
if (pProperties)
pProperties->resolve(*this);
@@ -2661,6 +2668,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext )
break;
case NS_ooxml::LN_CT_SdtPr_date:
{
+ m_pImpl->m_pSdtHelper->setControlType(SdtControlType::datePicker);
resolveSprmProps(*this, rSprm);
m_pImpl->m_pSdtHelper->setDateFieldStartRange(GetCurrentTextRange()->getEnd());
}
@@ -3518,7 +3526,7 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
}
bool bNewLine = len == 1 && (sText[0] == 0x0d || sText[0] == 0x07);
- if (m_pImpl->m_pSdtHelper->isInsideDropDownControl())
+ if (m_pImpl->m_pSdtHelper->getControlType() == SdtControlType::dropDown)
{
if (bNewLine)
// Dropdown control has single-line texts, so in case of newline, create the control.
@@ -3529,43 +3537,47 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
return;
}
}
+ else if (m_pImpl->m_pSdtHelper->getControlType() == SdtControlType::datePicker)
+ {
+ if (!m_pImpl->m_pSdtHelper->isInteropGrabBagEmpty())
+ {
+ m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear();
+ }
+ else if (IsInHeaderFooter() && m_pImpl->IsDiscardHeaderFooter())
+ {
+ m_pImpl->m_pSdtHelper->getDateFormat().truncate();
+ m_pImpl->m_pSdtHelper->getLocale().truncate();
+ return;
+ }
+ }
else if (!m_pImpl->m_pSdtHelper->isInteropGrabBagEmpty())
{
- // Ignore grabbag when we have a date field, it can conflict during export
- if(m_pImpl->m_pSdtHelper->validateDateFormat())
+ // there are unsupported SDT properties in the document
+ // save them in the paragraph interop grab bag
+ if (m_pImpl->IsDiscardHeaderFooter())
{
+ // Unless we're supposed to ignore this header/footer.
m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear();
+ return;
}
- else
+ if((m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_checkbox") ||
+ m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_text") ||
+ m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_dataBinding") ||
+ m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_citation") ||
+ (m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_id") &&
+ m_pImpl->m_pSdtHelper->getInteropGrabBagSize() == 1)) && !m_pImpl->m_pSdtHelper->isOutsideAParagraph())
{
+ PropertyMapPtr pContext = m_pImpl->GetTopContextOfType(CONTEXT_CHARACTER);
- // there are unsupported SDT properties in the document
- // save them in the paragraph interop grab bag
- if (m_pImpl->IsDiscardHeaderFooter())
- {
- // Unless we're supposed to ignore this header/footer.
- m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear();
- return;
- }
- if((m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_checkbox") ||
- m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_text") ||
- m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_dataBinding") ||
- m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_citation") ||
- (m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_id") &&
- m_pImpl->m_pSdtHelper->getInteropGrabBagSize() == 1)) && !m_pImpl->m_pSdtHelper->isOutsideAParagraph())
- {
- PropertyMapPtr pContext = m_pImpl->GetTopContextOfType(CONTEXT_CHARACTER);
-
- if (m_pImpl->IsOpenField())
- // We have a field, insert the SDT properties to the field's grab-bag, so they won't be lost.
- pContext = m_pImpl->GetTopFieldContext()->getProperties();
+ if (m_pImpl->IsOpenField())
+ // We have a field, insert the SDT properties to the field's grab-bag, so they won't be lost.
+ pContext = m_pImpl->GetTopFieldContext()->getProperties();
- pContext->Insert(PROP_SDTPR, uno::makeAny(m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear()), true, CHAR_GRAB_BAG);
- }
- else
- m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH)->Insert(PROP_SDTPR,
- uno::makeAny(m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear()), true, PARA_GRAB_BAG);
+ pContext->Insert(PROP_SDTPR, uno::makeAny(m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear()), true, CHAR_GRAB_BAG);
}
+ else
+ m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH)->Insert(PROP_SDTPR,
+ uno::makeAny(m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear()), true, PARA_GRAB_BAG);
}
else if (len == 1 && sText[0] == 0x03)
{
@@ -3591,15 +3603,6 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
return;
}
}
- else if (m_pImpl->m_pSdtHelper->validateDateFormat())
- {
- if(IsInHeaderFooter() && m_pImpl->IsDiscardHeaderFooter())
- {
- m_pImpl->m_pSdtHelper->getDateFormat().truncate();
- m_pImpl->m_pSdtHelper->getLocale().truncate();
- return;
- }
- }
if (!m_pImpl->hasTableManager())
return;
@@ -4186,7 +4189,7 @@ void DomainMapper::HandleRedline( Sprm& rSprm )
void DomainMapper::finishParagraph(const bool bRemove, const bool bNoNumbering)
{
- if (m_pImpl->m_pSdtHelper->validateDateFormat())
+ if (m_pImpl->m_pSdtHelper->getControlType() == SdtControlType::datePicker)
m_pImpl->m_pSdtHelper->createDateContentControl();
m_pImpl->finishParagraph(m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH), bRemove, bNoNumbering);
}
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx
index 7bf233446ee5..46f834280404 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -67,7 +67,7 @@ static awt::Size lcl_getOptimalWidth(const StyleSheetTablePtr& pStyleSheet,
SdtHelper::SdtHelper(DomainMapper_Impl& rDM_Impl)
: m_rDM_Impl(rDM_Impl)
- , m_bInsideDropDownControl(false)
+ , m_aControlType(SdtControlType::unknown)
, m_bHasElements(false)
, m_bOutsideAParagraph(false)
{
@@ -77,7 +77,7 @@ SdtHelper::~SdtHelper() = default;
void SdtHelper::createDropDownControl()
{
- assert(m_bInsideDropDownControl);
+ assert(getControlType() == SdtControlType::dropDown);
const bool bDropDown
= officecfg::Office::Writer::Filter::Import::DOCX::ImportComboBoxAsDropDown::get();
@@ -132,12 +132,7 @@ void SdtHelper::createDropDownControl()
// clean up
m_aDropDownItems.clear();
- m_bInsideDropDownControl = false;
-}
-
-bool SdtHelper::validateDateFormat()
-{
- return !m_sDateFormat.toString().isEmpty() && !m_sLocale.toString().isEmpty();
+ setControlType(SdtControlType::unknown);
}
void SdtHelper::createDateContentControl()
@@ -199,6 +194,8 @@ void SdtHelper::createDateContentControl()
sFullDate = sFullDate.copy(0, nTimeSep);
xNameCont->insertByName(ODF_FORMDATE_CURRENTDATE, uno::makeAny(sFullDate));
}
+
+ setControlType(SdtControlType::unknown);
}
void SdtHelper::createControlShape(awt::Size aSize,
diff --git a/writerfilter/source/dmapper/SdtHelper.hxx b/writerfilter/source/dmapper/SdtHelper.hxx
index 13859aab0f2c..5a39177c4a56 100644
--- a/writerfilter/source/dmapper/SdtHelper.hxx
+++ b/writerfilter/source/dmapper/SdtHelper.hxx
@@ -27,6 +27,13 @@ namespace writerfilter::dmapper
{
class DomainMapper_Impl;
+enum class SdtControlType
+{
+ datePicker,
+ dropDown,
+ unknown
+};
+
/**
* Helper to create form controls from w:sdt tokens.
*
@@ -39,8 +46,8 @@ class SdtHelper final : public virtual SvRefBase
/// Items of the drop-down control.
std::vector<OUString> m_aDropDownItems;
- /// Indicator of a drop-down control
- bool m_bInsideDropDownControl;
+ /// Type of sdt control
+ SdtControlType m_aControlType;
/// Pieces of the default text -- currently used only by the dropdown control.
OUStringBuffer m_aSdtTexts;
/// Date ISO string contained in the w:date element, used by the date control.
@@ -79,9 +86,6 @@ public:
m_xDateFieldStartRange = xStartRange;
}
- /// Decides if we have enough information to create a date control.
- bool validateDateFormat();
-
OUStringBuffer& getLocale() { return m_sLocale; }
/// If createControlShape() was ever called.
bool hasElements() const { return m_bHasElements; }
@@ -93,8 +97,8 @@ public:
bool isOutsideAParagraph() const { return m_bOutsideAParagraph; }
- bool isInsideDropDownControl() const { return m_bInsideDropDownControl; }
- void setInsideDropDownControl(bool bInside) { m_bInsideDropDownControl = bInside; }
+ SdtControlType getControlType() { return m_aControlType; }
+ void setControlType(SdtControlType aType) { m_aControlType = aType; }
/// Create drop-down control from w:sdt's w:dropDownList.
void createDropDownControl();