summaryrefslogtreecommitdiff
path: root/sw/source/ui/fldui/DateFormFieldDialog.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sw/source/ui/fldui/DateFormFieldDialog.cxx')
-rw-r--r--sw/source/ui/fldui/DateFormFieldDialog.cxx34
1 files changed, 25 insertions, 9 deletions
diff --git a/sw/source/ui/fldui/DateFormFieldDialog.cxx b/sw/source/ui/fldui/DateFormFieldDialog.cxx
index 45c607b0084c..c0c3dbe59199 100644
--- a/sw/source/ui/fldui/DateFormFieldDialog.cxx
+++ b/sw/source/ui/fldui/DateFormFieldDialog.cxx
@@ -18,7 +18,7 @@
namespace sw
{
-DateFormFieldDialog::DateFormFieldDialog(vcl::Window* pParent, mark::IFieldmark* pDateField,
+DateFormFieldDialog::DateFormFieldDialog(vcl::Window* pParent, mark::IDateFieldmark* pDateField,
SwDoc* pDoc)
: SvxStandardDialog(pParent, "DateFormFieldDialog", "modules/swriter/ui/dateformfielddialog.ui")
, m_pDateField(pDateField)
@@ -46,12 +46,28 @@ void DateFormFieldDialog::Apply()
{
if (m_pDateField != nullptr)
{
- const SvNumberformat* pFormat = m_pNumberFormatter->GetEntry(m_xFormatLB->GetFormat());
+ // Try to find out the current date value and replace the content
+ // with the right formatted date string
sw::mark::IFieldmark::parameter_map_t* pParameters = m_pDateField->GetParameters();
+ const SvNumberformat* pFormat = m_pNumberFormatter->GetEntry(m_xFormatLB->GetFormat());
+
+ // Get date value first
+ std::pair<bool, double> aResult = m_pDateField->GetCurrentDate();
+
+ // Then set the date format
(*pParameters)[ODF_FORMDATE_DATEFORMAT] <<= pFormat->GetFormatstring();
+ (*pParameters)[ODF_FORMDATE_DATEFORMAT_LANGUAGE]
+ <<= LanguageTag(pFormat->GetLanguage()).getBcp47();
- LanguageType aLang = pFormat->GetLanguage();
- (*pParameters)[ODF_FORMDATE_DATEFORMAT_LANGUAGE] <<= LanguageTag(aLang).getBcp47();
+ // Update current date
+ if (aResult.first)
+ {
+ m_pDateField->SetCurrentDate(aResult.second);
+ }
+ else
+ {
+ (*pParameters)[ODF_FORMDATE_CURRENTDATE] <<= OUString();
+ }
}
}
@@ -78,16 +94,16 @@ void DateFormFieldDialog::InitControls()
if (!sFormatString.isEmpty() && !sLang.isEmpty())
{
LanguageType aLangType = LanguageTag(sLang).getLanguageType();
- sal_uInt32 nFormatKey = m_pNumberFormatter->GetEntryKey(sFormatString, aLangType);
- if (nFormatKey == NUMBERFORMAT_ENTRY_NOT_FOUND)
+ sal_uInt32 nFormat = m_pNumberFormatter->GetEntryKey(sFormatString, aLangType);
+ if (nFormat == NUMBERFORMAT_ENTRY_NOT_FOUND)
{
sal_Int32 nCheckPos = 0;
short nType;
- m_pNumberFormatter->PutEntry(sFormatString, nCheckPos, nType, nFormatKey,
+ m_pNumberFormatter->PutEntry(sFormatString, nCheckPos, nType, nFormat,
LanguageTag(sLang).getLanguageType());
}
- if (aLangType != LANGUAGE_DONTKNOW && nFormatKey != NUMBERFORMAT_ENTRY_NOT_FOUND)
+ if (aLangType != LANGUAGE_DONTKNOW && nFormat != NUMBERFORMAT_ENTRY_NOT_FOUND)
{
if (m_xFormatLB->GetCurLanguage() == aLangType)
{
@@ -102,7 +118,7 @@ void DateFormFieldDialog::InitControls()
m_xFormatLB->SetFormatType(css::util::NumberFormat::ALL);
m_xFormatLB->SetFormatType(css::util::NumberFormat::DATE);
}
- m_xFormatLB->SetDefFormat(nFormatKey);
+ m_xFormatLB->SetDefFormat(nFormat);
}
}
}