summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamás Zolnai <tamas.zolnai@collabora.com>2019-07-01 13:45:09 +0200
committerTamás Zolnai <tamas.zolnai@collabora.com>2019-07-12 05:53:28 +0200
commit1e6b8e5c2a42b2ca35c963bbbe83f3e2e817ff50 (patch)
tree93b350785ba2912662c547804383c6e1e95e2276
parent70ae581d103b599a321f513baba1158eeb2887f2 (diff)
MSForms: date field converions: better error handling
Change-Id: Ia518c7c50079e443ddf135f1c32c5c39d2c85552 Reviewed-on: https://gerrit.libreoffice.org/75449 Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com> Tested-by: Tamás Zolnai <tamas.zolnai@collabora.com>
-rw-r--r--sw/source/core/crsr/DateFormFieldButton.cxx39
-rw-r--r--sw/source/core/text/itrform2.cxx42
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx39
-rw-r--r--sw/source/ui/fldui/DateFormFieldDialog.cxx25
4 files changed, 88 insertions, 57 deletions
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);
}
}
}