sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx | 4 +- sw/source/core/crsr/DateFormFieldButton.cxx | 39 ++++++++++++++---------- sw/source/core/text/itrform2.cxx | 42 ++++++++++++++++---------- sw/source/filter/ww8/docxattributeoutput.cxx | 39 ++++++++++++++---------- sw/source/ui/fldui/DateFormFieldDialog.cxx | 25 ++++++++------- 5 files changed, 90 insertions(+), 59 deletions(-)
New commits: commit 1e6b8e5c2a42b2ca35c963bbbe83f3e2e817ff50 Author: Tamás Zolnai <[email protected]> AuthorDate: Mon Jul 1 13:45:09 2019 +0200 Commit: Tamás Zolnai <[email protected]> CommitDate: Fri Jul 12 05:53:28 2019 +0200 MSForms: date field converions: better error handling Change-Id: Ia518c7c50079e443ddf135f1c32c5c39d2c85552 Reviewed-on: https://gerrit.libreoffice.org/75449 Reviewed-by: Tamás Zolnai <[email protected]> Tested-by: Tamás Zolnai <[email protected]> diff --git a/sw/source/core/crsr/DateFormFieldButton.cxx b/sw/source/core/crsr/DateFormFieldButton.cxx index 19dceb971bcc..5927d6a3c5e8 100644 --- a/sw/source/core/crsr/DateFormFieldButton.cxx +++ b/sw/source/core/crsr/DateFormFieldButton.cxx @@ -57,22 +57,26 @@ SwDatePickerDialog::SwDatePickerDialog(SwEditWin* parent, sw::mark::IFieldmark* OUString sDateString; pResult->second >>= sDateString; - double dCurrentDate = 0; sal_uInt32 nFormat = m_pNumberFormatter->GetEntryKey(ODF_FORMDATE_CURRENTDATE_FORMAT, ODF_FORMDATE_CURRENTDATE_LANGUAGE); + bool bValidFormat = nFormat != NUMBERFORMAT_ENTRY_NOT_FOUND; if (nFormat == NUMBERFORMAT_ENTRY_NOT_FOUND) { sal_Int32 nCheckPos = 0; SvNumFormatType nType; OUString sFormat = ODF_FORMDATE_CURRENTDATE_FORMAT; - m_pNumberFormatter->PutEntry(sFormat, nCheckPos, nType, nFormat, - ODF_FORMDATE_CURRENTDATE_LANGUAGE); + bValidFormat = m_pNumberFormatter->PutEntry(sFormat, nCheckPos, nType, nFormat, + ODF_FORMDATE_CURRENTDATE_LANGUAGE); } - m_pNumberFormatter->IsNumberFormat(sDateString, nFormat, dCurrentDate); + if (bValidFormat) + { + double dCurrentDate = 0; + m_pNumberFormatter->IsNumberFormat(sDateString, nFormat, dCurrentDate); - const Date& rNullDate = m_pNumberFormatter->GetNullDate(); - m_pCalendar->SetCurDate(rNullDate + sal_Int32(dCurrentDate)); + const Date& rNullDate = m_pNumberFormatter->GetNullDate(); + m_pCalendar->SetCurDate(rNullDate + sal_Int32(dCurrentDate)); + } } } m_pCalendar->SetSelectHdl(LINK(this, SwDatePickerDialog, ImplSelectHdl)); @@ -95,26 +99,31 @@ IMPL_LINK(SwDatePickerDialog, ImplSelectHdl, Calendar*, pCalendar, void) { if (m_pFieldmark != nullptr) { - Color* pCol = nullptr; - OUString sOutput; sal_uInt32 nFormat = m_pNumberFormatter->GetEntryKey(ODF_FORMDATE_CURRENTDATE_FORMAT, ODF_FORMDATE_CURRENTDATE_LANGUAGE); + bool bValidFormat = nFormat != NUMBERFORMAT_ENTRY_NOT_FOUND; if (nFormat == NUMBERFORMAT_ENTRY_NOT_FOUND) { sal_Int32 nCheckPos = 0; SvNumFormatType nType; OUString sFormat = ODF_FORMDATE_CURRENTDATE_FORMAT; - m_pNumberFormatter->PutEntry(sFormat, nCheckPos, nType, nFormat, - ODF_FORMDATE_CURRENTDATE_LANGUAGE); + bValidFormat = m_pNumberFormatter->PutEntry(sFormat, nCheckPos, nType, nFormat, + ODF_FORMDATE_CURRENTDATE_LANGUAGE); } - const Date& rNullDate = m_pNumberFormatter->GetNullDate(); - double dDate = pCalendar->GetFirstSelectedDate() - rNullDate; + if (bValidFormat) + { + Color* pCol = nullptr; + OUString sOutput; - m_pNumberFormatter->GetOutputString(dDate, nFormat, sOutput, &pCol, false); + const Date& rNullDate = m_pNumberFormatter->GetNullDate(); + double dDate = pCalendar->GetFirstSelectedDate() - rNullDate; - sw::mark::IFieldmark::parameter_map_t* pParameters = m_pFieldmark->GetParameters(); - (*pParameters)[ODF_FORMDATE_CURRENTDATE] <<= sOutput; + m_pNumberFormatter->GetOutputString(dDate, nFormat, sOutput, &pCol, false); + + sw::mark::IFieldmark::parameter_map_t* pParameters = m_pFieldmark->GetParameters(); + (*pParameters)[ODF_FORMDATE_CURRENTDATE] <<= sOutput; + } } EndPopupMode(); } diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx index 143922fade66..ce88fb01bbb5 100644 --- a/sw/source/core/text/itrform2.cxx +++ b/sw/source/core/text/itrform2.cxx @@ -890,38 +890,48 @@ namespace sw { namespace mark { OUString sFormattedDate; pResult->second >>= sFormattedDate; - sal_uInt32 nFormat = pFormatter->GetEntryKey(ODF_FORMDATE_CURRENTDATE_FORMAT, ODF_FORMDATE_CURRENTDATE_LANGUAGE); if (nFormat == NUMBERFORMAT_ENTRY_NOT_FOUND) + sal_uInt32 nFormat = pFormatter->GetEntryKey(ODF_FORMDATE_CURRENTDATE_FORMAT, ODF_FORMDATE_CURRENTDATE_LANGUAGE); + bool bValidFormat = nFormat != NUMBERFORMAT_ENTRY_NOT_FOUND; if (nFormat == NUMBERFORMAT_ENTRY_NOT_FOUND) { sal_Int32 nCheckPos = 0; SvNumFormatType nType; OUString sFormat = ODF_FORMDATE_CURRENTDATE_FORMAT; - pFormatter->PutEntry(sFormat, - nCheckPos, - nType, - nFormat, - ODF_FORMDATE_CURRENTDATE_LANGUAGE); + bValidFormat = pFormatter->PutEntry(sFormat, + nCheckPos, + nType, + nFormat, + ODF_FORMDATE_CURRENTDATE_LANGUAGE); + } + + if (bValidFormat) + { + pFormatter->IsNumberFormat(sFormattedDate, nFormat, dCurrentDate); + bHasCurrentDate = true; } - pFormatter->IsNumberFormat(sFormattedDate, nFormat, dCurrentDate); - bHasCurrentDate = true; } - Color* pCol = nullptr; if (!sDateFormat.isEmpty() && !sLang.isEmpty() && bHasCurrentDate) { - OUString sOutput; sal_uInt32 nFormat = pFormatter->GetEntryKey(sDateFormat, LanguageTag(sLang).getLanguageType()); + bool bValidFormat = nFormat != NUMBERFORMAT_ENTRY_NOT_FOUND; if (nFormat == NUMBERFORMAT_ENTRY_NOT_FOUND) { sal_Int32 nCheckPos = 0; SvNumFormatType nType; - pFormatter->PutEntry(sDateFormat, - nCheckPos, - nType, - nFormat, - LanguageTag(sLang).getLanguageType()); + bValidFormat = pFormatter->PutEntry(sDateFormat, + nCheckPos, + nType, + nFormat, + LanguageTag(sLang).getLanguageType()); + } + + OUString sOutput; + if (bValidFormat) + { + Color* pCol = nullptr; + pFormatter->GetOutputString(dCurrentDate, nFormat, sOutput, &pCol, false); } - pFormatter->GetOutputString(dCurrentDate, nFormat, sOutput, &pCol, false); return sOutput; } diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index d225576534b5..17362b72e243 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -1915,36 +1915,45 @@ void DocxAttributeOutput::WriteFormDate(const OUString& sCurrentDate, const OUSt double dCurrentDate = 0.0; // First get the date internal double representation - sal_uInt32 nFormat = pFormatter->GetEntryKey(ODF_FORMDATE_CURRENTDATE_FORMAT, ODF_FORMDATE_CURRENTDATE_LANGUAGE); if (nFormat == NUMBERFORMAT_ENTRY_NOT_FOUND) + sal_uInt32 nFormat = pFormatter->GetEntryKey(ODF_FORMDATE_CURRENTDATE_FORMAT, ODF_FORMDATE_CURRENTDATE_LANGUAGE); + bool bValidFormat = nFormat != NUMBERFORMAT_ENTRY_NOT_FOUND; if (nFormat == NUMBERFORMAT_ENTRY_NOT_FOUND) { sal_Int32 nCheckPos = 0; SvNumFormatType nType; OUString sFormat = ODF_FORMDATE_CURRENTDATE_FORMAT; - pFormatter->PutEntry(sFormat, - nCheckPos, - nType, - nFormat, - ODF_FORMDATE_CURRENTDATE_LANGUAGE); + bValidFormat = pFormatter->PutEntry(sFormat, + nCheckPos, + nType, + nFormat, + ODF_FORMDATE_CURRENTDATE_LANGUAGE); + } + if (bValidFormat) + { + pFormatter->IsNumberFormat(sCurrentDate, nFormat, dCurrentDate); } - pFormatter->IsNumberFormat(sCurrentDate, nFormat, dCurrentDate); // Then convert the date to a fromatter string - OUString sOutput; - Color* pCol = nullptr; nFormat = pFormatter->GetEntryKey(sDateFormat, LanguageTag(sLang).getLanguageType()); + bValidFormat = nFormat != NUMBERFORMAT_ENTRY_NOT_FOUND; if (nFormat == NUMBERFORMAT_ENTRY_NOT_FOUND) { sal_Int32 nCheckPos = 0; SvNumFormatType nType; OUString sNonConstDateFormat = sDateFormat; - pFormatter->PutEntry(sNonConstDateFormat, - nCheckPos, - nType, - nFormat, - LanguageTag(sLang).getLanguageType()); + bValidFormat = pFormatter->PutEntry(sNonConstDateFormat, + nCheckPos, + nType, + nFormat, + LanguageTag(sLang).getLanguageType()); + } + + OUString sOutput; + if (bValidFormat) + { + Color* pCol = nullptr; + pFormatter->GetOutputString(dCurrentDate, nFormat, sOutput, &pCol, false); } - pFormatter->GetOutputString(dCurrentDate, nFormat, sOutput, &pCol, false); RunText(sOutput); } diff --git a/sw/source/ui/fldui/DateFormFieldDialog.cxx b/sw/source/ui/fldui/DateFormFieldDialog.cxx index fef0d92cea3d..bfc3aa3e3aa0 100644 --- a/sw/source/ui/fldui/DateFormFieldDialog.cxx +++ b/sw/source/ui/fldui/DateFormFieldDialog.cxx @@ -78,20 +78,23 @@ void DateFormFieldDialog::InitControls() LanguageType aLangType = LanguageTag(sLang).getLanguageType(); sal_uInt32 nFormatKey = m_pNumberFormatter->GetEntryKey(sFormatString, aLangType); - if (m_xFormatLB->GetCurLanguage() == aLangType) + if (aLangType != LANGUAGE_DONTKNOW && nFormatKey != NUMBERFORMAT_ENTRY_NOT_FOUND) { - m_xFormatLB->SetAutomaticLanguage(true); - } - else - { - m_xFormatLB->SetAutomaticLanguage(false); - m_xFormatLB->SetLanguage(aLangType); + if (m_xFormatLB->GetCurLanguage() == aLangType) + { + m_xFormatLB->SetAutomaticLanguage(true); + } + else + { + m_xFormatLB->SetAutomaticLanguage(false); + m_xFormatLB->SetLanguage(aLangType); - // Change format and change back for regenerating the list - m_xFormatLB->SetFormatType(SvNumFormatType::ALL); - m_xFormatLB->SetFormatType(SvNumFormatType::DATE); + // Change format and change back for regenerating the list + m_xFormatLB->SetFormatType(SvNumFormatType::ALL); + m_xFormatLB->SetFormatType(SvNumFormatType::DATE); + } + m_xFormatLB->SetDefFormat(nFormatKey); } - m_xFormatLB->SetDefFormat(nFormatKey); } } } commit 70ae581d103b599a321f513baba1158eeb2887f2 Author: Tamás Zolnai <[email protected]> AuthorDate: Mon Jul 1 13:27:31 2019 +0200 Commit: Tamás Zolnai <[email protected]> CommitDate: Fri Jul 12 05:52:48 2019 +0200 MSForms: DOCX filter: reenable passing test Change-Id: Ic82e2edddce7e46740f74f7b20bb849b6735a3b8 Reviewed-on: https://gerrit.libreoffice.org/75448 Tested-by: Jenkins Reviewed-by: Tamás Zolnai <[email protected]> diff --git a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx index 3b7f928facdb..3d3c528ef41a 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx @@ -510,14 +510,14 @@ DECLARE_OOXMLEXPORT_TEST(testTableStart2Sdt, "table-start-2-sdt.docx") } } -/*DECLARE_OOXMLEXPORT_TEST(testSdtDateDuplicate, "sdt-date-duplicate.docx") +DECLARE_OOXMLEXPORT_TEST(testSdtDateDuplicate, "sdt-date-duplicate.docx") { if (xmlDocPtr pXmlDoc = parseExport()) { // Single <w:sdt> was exported as 2 <w:sdt> elements. assertXPath(pXmlDoc, "//w:sdt", 1); } -}*/ +} DECLARE_OOXMLEXPORT_TEST(testFdo81492, "fdo81492.docx") { _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
