diff options
author | Tamás Zolnai <tamas.zolnai@collabora.com> | 2019-07-03 14:43:12 +0200 |
---|---|---|
committer | Tamás Zolnai <tamas.zolnai@collabora.com> | 2019-07-12 06:10:34 +0200 |
commit | 9e007eb2b0ab44b436da9d00559150cc4fa37dc5 (patch) | |
tree | 3025d4f798a8dd9649e5205f6d30e5dfa1fd2f96 | |
parent | 52205f85582aaaee04fcfffd1c1729454f512400 (diff) |
MSForms: date format: better searching of date format entries
* GetEntryKey and PutEntry methods are not consistent.
* It can happen that GetEntryKey does not found the format
we are searching for, however the PutEntry() method finds
it among the entries and so returns with failure.
* Let's check the nFormat instead, PutEntry returns the found
entry key if the entry exists.
Change-Id: Ia7e8702b03999950adfa649d1adc3a839dc5a178
Reviewed-on: https://gerrit.libreoffice.org/75453
Tested-by: Jenkins
Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
-rw-r--r-- | sw/source/core/crsr/DateFormFieldButton.cxx | 14 | ||||
-rw-r--r-- | sw/source/core/text/itrform2.cxx | 26 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 85 | ||||
-rw-r--r-- | sw/source/ui/fldui/DateFormFieldDialog.cxx | 8 |
4 files changed, 61 insertions, 72 deletions
diff --git a/sw/source/core/crsr/DateFormFieldButton.cxx b/sw/source/core/crsr/DateFormFieldButton.cxx index 5927d6a3c5e8..04fee37f1fb3 100644 --- a/sw/source/core/crsr/DateFormFieldButton.cxx +++ b/sw/source/core/crsr/DateFormFieldButton.cxx @@ -59,17 +59,16 @@ SwDatePickerDialog::SwDatePickerDialog(SwEditWin* parent, sw::mark::IFieldmark* 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; - bValidFormat = m_pNumberFormatter->PutEntry(sFormat, nCheckPos, nType, nFormat, - ODF_FORMDATE_CURRENTDATE_LANGUAGE); + m_pNumberFormatter->PutEntry(sFormat, nCheckPos, nType, nFormat, + ODF_FORMDATE_CURRENTDATE_LANGUAGE); } - if (bValidFormat) + if (nFormat != NUMBERFORMAT_ENTRY_NOT_FOUND) { double dCurrentDate = 0; m_pNumberFormatter->IsNumberFormat(sDateString, nFormat, dCurrentDate); @@ -101,17 +100,16 @@ IMPL_LINK(SwDatePickerDialog, ImplSelectHdl, Calendar*, pCalendar, void) { 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; - bValidFormat = m_pNumberFormatter->PutEntry(sFormat, nCheckPos, nType, nFormat, - ODF_FORMDATE_CURRENTDATE_LANGUAGE); + m_pNumberFormatter->PutEntry(sFormat, nCheckPos, nType, nFormat, + ODF_FORMDATE_CURRENTDATE_LANGUAGE); } - if (bValidFormat) + if (nFormat != NUMBERFORMAT_ENTRY_NOT_FOUND) { Color* pCol = nullptr; OUString sOutput; diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx index ce88fb01bbb5..313c6d22102f 100644 --- a/sw/source/core/text/itrform2.cxx +++ b/sw/source/core/text/itrform2.cxx @@ -891,20 +891,19 @@ namespace sw { namespace mark { pResult->second >>= sFormattedDate; 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; - bValidFormat = pFormatter->PutEntry(sFormat, - nCheckPos, - nType, - nFormat, - ODF_FORMDATE_CURRENTDATE_LANGUAGE); + pFormatter->PutEntry(sFormat, + nCheckPos, + nType, + nFormat, + ODF_FORMDATE_CURRENTDATE_LANGUAGE); } - if (bValidFormat) + if (nFormat != NUMBERFORMAT_ENTRY_NOT_FOUND) { pFormatter->IsNumberFormat(sFormattedDate, nFormat, dCurrentDate); bHasCurrentDate = true; @@ -914,20 +913,19 @@ namespace sw { namespace mark { if (!sDateFormat.isEmpty() && !sLang.isEmpty() && bHasCurrentDate) { 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; - bValidFormat = pFormatter->PutEntry(sDateFormat, - nCheckPos, - nType, - nFormat, - LanguageTag(sLang).getLanguageType()); + pFormatter->PutEntry(sDateFormat, + nCheckPos, + nType, + nFormat, + LanguageTag(sLang).getLanguageType()); } OUString sOutput; - if (bValidFormat) + if (nFormat != NUMBERFORMAT_ENTRY_NOT_FOUND) { Color* pCol = nullptr; pFormatter->GetOutputString(dCurrentDate, nFormat, sOutput, &pCol, false); diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 17362b72e243..82c5c30896ea 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -1906,57 +1906,52 @@ void DocxAttributeOutput::WriteFormDate(const OUString& sCurrentDate, const OUSt m_pSerializer->startElementNS(XML_w, XML_sdtContent); m_pSerializer->startElementNS(XML_w, XML_r); + // Convert the current date to the right format if (!sCurrentDate.isEmpty()) { - // Convert the current date to the right format - if (!sCurrentDate.isEmpty()) - { - SvNumberFormatter* pFormatter = m_rExport.m_pDoc->GetNumberFormatter(); + SvNumberFormatter* pFormatter = m_rExport.m_pDoc->GetNumberFormatter(); - double dCurrentDate = 0.0; - // First get the date internal double representation - 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; - bValidFormat = pFormatter->PutEntry(sFormat, - nCheckPos, - nType, - nFormat, - ODF_FORMDATE_CURRENTDATE_LANGUAGE); - } - if (bValidFormat) - { - pFormatter->IsNumberFormat(sCurrentDate, nFormat, dCurrentDate); - } - - // Then convert the date to a fromatter string - 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; - bValidFormat = pFormatter->PutEntry(sNonConstDateFormat, - nCheckPos, - nType, - nFormat, - LanguageTag(sLang).getLanguageType()); - } + 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_Int32 nCheckPos = 0; + SvNumFormatType nType; + OUString sFormat = ODF_FORMDATE_CURRENTDATE_FORMAT; + pFormatter->PutEntry(sFormat, + nCheckPos, + nType, + nFormat, + ODF_FORMDATE_CURRENTDATE_LANGUAGE); + } + if (nFormat != NUMBERFORMAT_ENTRY_NOT_FOUND) + { + pFormatter->IsNumberFormat(sCurrentDate, nFormat, dCurrentDate); + } - OUString sOutput; - if (bValidFormat) - { - Color* pCol = nullptr; - pFormatter->GetOutputString(dCurrentDate, nFormat, sOutput, &pCol, false); - } + // Then convert the date to a fromatter string + nFormat = pFormatter->GetEntryKey(sDateFormat, LanguageTag(sLang).getLanguageType()); + if (nFormat == NUMBERFORMAT_ENTRY_NOT_FOUND) + { + sal_Int32 nCheckPos = 0; + SvNumFormatType nType; + OUString sNonConstDateFormat = sDateFormat; + pFormatter->PutEntry(sNonConstDateFormat, + nCheckPos, + nType, + nFormat, + LanguageTag(sLang).getLanguageType()); + } - RunText(sOutput); + OUString sOutput; + if (nFormat != NUMBERFORMAT_ENTRY_NOT_FOUND) + { + Color* pCol = nullptr; + pFormatter->GetOutputString(dCurrentDate, nFormat, sOutput, &pCol, false); } + + RunText(sOutput); } m_pSerializer->endElementNS(XML_w, XML_r); diff --git a/sw/source/ui/fldui/DateFormFieldDialog.cxx b/sw/source/ui/fldui/DateFormFieldDialog.cxx index ad511dff7ddf..b82c7711f0df 100644 --- a/sw/source/ui/fldui/DateFormFieldDialog.cxx +++ b/sw/source/ui/fldui/DateFormFieldDialog.cxx @@ -77,17 +77,15 @@ void DateFormFieldDialog::InitControls() { LanguageType aLangType = LanguageTag(sLang).getLanguageType(); sal_uInt32 nFormatKey = m_pNumberFormatter->GetEntryKey(sFormatString, aLangType); - bool bValidFormat = nFormatKey != NUMBERFORMAT_ENTRY_NOT_FOUND; if (nFormatKey == NUMBERFORMAT_ENTRY_NOT_FOUND) { sal_Int32 nCheckPos = 0; SvNumFormatType nType; - bValidFormat - = m_pNumberFormatter->PutEntry(sFormatString, nCheckPos, nType, nFormatKey, - LanguageTag(sLang).getLanguageType()); + m_pNumberFormatter->PutEntry(sFormatString, nCheckPos, nType, nFormatKey, + LanguageTag(sLang).getLanguageType()); } - if (aLangType != LANGUAGE_DONTKNOW && bValidFormat) + if (aLangType != LANGUAGE_DONTKNOW && nFormatKey != NUMBERFORMAT_ENTRY_NOT_FOUND) { if (m_xFormatLB->GetCurLanguage() == aLangType) { |