Kaydet (Commit) 9c3420d1 authored tarafından Lionel Elie Mamane's avatar Lionel Elie Mamane

svtools FormattedField: don't reparse value from text after ReFormat

If our format is lossy / not a bijection
(as is e.g. our default date format, because of 2-digit year),
then reparsing the string that came from the format
leads to data loss (the value is changed to something else).

The existing code tried to do that, by calling Modify()
and then setting m_bValueDirty to false.
However, this fails because listeners are called
while m_bValueDirty is true. If any of them calls
e.g. GetValue(), the reparse happens.

Change-Id: I272f377927f83c71ede1eb80eafbc689f36fb17a
üst 35fdbea1
...@@ -236,6 +236,7 @@ public: ...@@ -236,6 +236,7 @@ public:
protected: protected:
virtual long Notify(NotifyEvent& rNEvt); virtual long Notify(NotifyEvent& rNEvt);
void impl_Modify(bool makeValueDirty = true);
virtual void Modify(); virtual void Modify();
// CheckText ueberschreiben fuer Ueberpruefung zur Eingabezeit // CheckText ueberschreiben fuer Ueberpruefung zur Eingabezeit
......
...@@ -487,13 +487,14 @@ void FormattedField::SetAutoColor(sal_Bool _bAutomatic) ...@@ -487,13 +487,14 @@ void FormattedField::SetAutoColor(sal_Bool _bAutomatic)
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void FormattedField::Modify() void FormattedField::impl_Modify(bool makeValueDirty)
{ {
DBG_CHKTHIS(FormattedField, NULL); DBG_CHKTHIS(FormattedField, NULL);
if (!IsStrictFormat()) if (!IsStrictFormat())
{ {
m_bValueDirty = sal_True; if(makeValueDirty)
m_bValueDirty = sal_True;
SpinField::Modify(); SpinField::Modify();
return; return;
} }
...@@ -503,7 +504,8 @@ void FormattedField::Modify() ...@@ -503,7 +504,8 @@ void FormattedField::Modify()
{ {
m_sLastValidText = sCheck; m_sLastValidText = sCheck;
m_aLastSelection = GetSelection(); m_aLastSelection = GetSelection();
m_bValueDirty = sal_True; if(makeValueDirty)
m_bValueDirty = sal_True;
} }
else else
{ {
...@@ -513,6 +515,14 @@ void FormattedField::Modify() ...@@ -513,6 +515,14 @@ void FormattedField::Modify()
SpinField::Modify(); SpinField::Modify();
} }
//------------------------------------------------------------------------------
void FormattedField::Modify()
{
DBG_CHKTHIS(FormattedField, NULL);
impl_Modify();
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void FormattedField::ImplSetTextImpl(const OUString& rNew, Selection* pNewSel) void FormattedField::ImplSetTextImpl(const OUString& rNew, Selection* pNewSel)
{ {
...@@ -789,10 +799,12 @@ void FormattedField::Commit() ...@@ -789,10 +799,12 @@ void FormattedField::Commit()
// did the text change? // did the text change?
if ( GetText() != sOld ) if ( GetText() != sOld )
{ // consider the field as modified { // consider the field as modified,
Modify(); // but we already have the most recent value;
// but we have the most recent value now // don't reparse it from the text
m_bValueDirty = sal_False; // (can lead to data loss when the format is lossy,
// as is e.g. our default date format: 2-digit year!)
impl_Modify(false);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment