[Libreoffice-commits] core.git: sw/source
Tamás Zolnai (via logerrit)
logerrit at kemper.freedesktop.org
Fri Jul 12 04:12:06 UTC 2019
sw/source/core/crsr/DateFormFieldButton.cxx | 14 +---
sw/source/core/text/itrform2.cxx | 26 +++-----
sw/source/filter/ww8/docxattributeoutput.cxx | 85 ++++++++++++---------------
sw/source/ui/fldui/DateFormFieldDialog.cxx | 8 --
4 files changed, 61 insertions(+), 72 deletions(-)
New commits:
commit 9e007eb2b0ab44b436da9d00559150cc4fa37dc5
Author: Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Wed Jul 3 14:43:12 2019 +0200
Commit: Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Fri Jul 12 06:10:34 2019 +0200
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 at collabora.com>
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)
{
More information about the Libreoffice-commits
mailing list