[Libreoffice-commits] core.git: 2 commits - sw/source

Jan Holesovsky kendy at suse.cz
Wed Apr 3 06:24:23 PDT 2013


 sw/source/core/docnode/ndtbl.cxx |   57 +++++++++++++++++++--------------------
 1 file changed, 29 insertions(+), 28 deletions(-)

New commits:
commit f8be3d02573c4d6d753b5e0c1a449e932f94bd81
Author: Jan Holesovsky <kendy at suse.cz>
Date:   Wed Apr 3 11:49:38 2013 +0200

    fdo#32082: Do not reset number format in table cells on edit.
    
    When we changed the default to _not_ to recognize the number formats in table
    cells (commit 334c34e4ec803c65e43abf20edbc6faf7fa95e76), it caused that any
    edit of a number formatted cell had reset it to text on edit.
    
    This was quite unexpected, because when eg. there was a number that contributed
    to a sum, and it changed to text, the sum changed as if there was a '0' there.
    
    To solve this, try hard to retain the number format regardless of the
    'Recognize Number Formats' setting when there was a number formatting assigned
    to the cell.
    
    Change-Id: Ib43e0877420d90cdac7a0357d1ef3a549c866fb7

diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 4fd72a8..398dd6a 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -4028,31 +4028,35 @@ void SwDoc::ChkBoxNumFmt( SwTableBox& rBox, sal_Bool bCallUpdate )
             SwTableBoxFmt* pBoxFmt = (SwTableBoxFmt*)rBox.GetFrmFmt();
             SfxItemSet aBoxSet( GetAttrPool(), RES_BOXATR_FORMAT, RES_BOXATR_VALUE );
 
-            sal_Bool bSetNumFmt = IsInsTblFormatNum();
             sal_Bool bLockModify = sal_True;
+            sal_Bool bSetNumFmt = sal_False;
+            const bool bForceNumberFormat = IsInsTblFormatNum() && IsInsTblChangeNumFormat();
 
-            if( bSetNumFmt && !IsInsTblChangeNumFormat() )
+            // if the user forced a number format in this cell previously,
+            // keep it, unless the user set that she wants the full number
+            // format recognition
+            if( pNumFmtItem && !bForceNumberFormat )
             {
-                if( !pNumFmtItem )
-                    bSetNumFmt = sal_False;
+                sal_uLong nOldNumFmt = ((SwTblBoxNumFormat*)pNumFmtItem)->GetValue();
+                SvNumberFormatter* pNumFmtr = GetNumberFormatter();
+
+                short nFmtType = pNumFmtr->GetType( nFmtIdx );
+                if( nFmtType == pNumFmtr->GetType( nOldNumFmt ) || NUMBERFORMAT_NUMBER == nFmtType )
+                {
+                    // Current and specified NumFormat match
+                    // -> keep old Format
+                    nFmtIdx = nOldNumFmt;
+                    bSetNumFmt = sal_True;
+                }
                 else
                 {
-                    sal_uLong nOldNumFmt = ((SwTblBoxNumFormat*)pNumFmtItem)->GetValue();
-                    SvNumberFormatter* pNumFmtr = GetNumberFormatter();
-
-                    short nFmtType = pNumFmtr->GetType( nFmtIdx );
-                    if( nFmtType == pNumFmtr->GetType( nOldNumFmt ) || NUMBERFORMAT_NUMBER == nFmtType )
-                        // Current and specified NumFormat match
-                        // -> keep old Format
-                        nFmtIdx = nOldNumFmt;
-                    else
-                        // Current and specified NumFormat do not match
-                        // -> insert as Text
-                        bLockModify = bSetNumFmt = sal_False;
+                    // Current and specified NumFormat do not match
+                    // -> insert as Text
+                    bLockModify = bSetNumFmt = sal_False;
                 }
             }
 
-            if( bSetNumFmt )
+            if( bSetNumFmt || bForceNumberFormat )
             {
                 pBoxFmt = (SwTableBoxFmt*)rBox.ClaimFrmFmt();
 
commit c44a06a122d916a18bbede0126bb1e4614f244dc
Author: Jan Holesovsky <kendy at suse.cz>
Date:   Wed Apr 3 11:44:28 2013 +0200

    Keep semantics, but improve readibility.
    
    Change-Id: I32c18cb7b080f4847118a2d7e8d77dcd2bbce308

diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 882ff1b..4fd72a8 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -4028,39 +4028,36 @@ void SwDoc::ChkBoxNumFmt( SwTableBox& rBox, sal_Bool bCallUpdate )
             SwTableBoxFmt* pBoxFmt = (SwTableBoxFmt*)rBox.GetFrmFmt();
             SfxItemSet aBoxSet( GetAttrPool(), RES_BOXATR_FORMAT, RES_BOXATR_VALUE );
 
-            sal_Bool bSetNumFmt = IsInsTblFormatNum(), bLockModify = sal_True;
-            if( bSetNumFmt )
+            sal_Bool bSetNumFmt = IsInsTblFormatNum();
+            sal_Bool bLockModify = sal_True;
+
+            if( bSetNumFmt && !IsInsTblChangeNumFormat() )
             {
-                if( !IsInsTblChangeNumFormat() )
+                if( !pNumFmtItem )
+                    bSetNumFmt = sal_False;
+                else
                 {
-                    if( !pNumFmtItem )
-                        bSetNumFmt = sal_False;
+                    sal_uLong nOldNumFmt = ((SwTblBoxNumFormat*)pNumFmtItem)->GetValue();
+                    SvNumberFormatter* pNumFmtr = GetNumberFormatter();
+
+                    short nFmtType = pNumFmtr->GetType( nFmtIdx );
+                    if( nFmtType == pNumFmtr->GetType( nOldNumFmt ) || NUMBERFORMAT_NUMBER == nFmtType )
+                        // Current and specified NumFormat match
+                        // -> keep old Format
+                        nFmtIdx = nOldNumFmt;
                     else
-                    {
-                        sal_uLong nOldNumFmt = ((SwTblBoxNumFormat*)pNumFmtItem)->
-                                            GetValue();
-                        SvNumberFormatter* pNumFmtr = GetNumberFormatter();
-
-                        short nFmtType = pNumFmtr->GetType( nFmtIdx );
-                        if( nFmtType == pNumFmtr->GetType( nOldNumFmt ) ||
-                            NUMBERFORMAT_NUMBER == nFmtType )
-                            // Current and specified NumFormat match
-                            // -> keep old Format
-                            nFmtIdx = nOldNumFmt;
-                        else
-                            // Current and specified NumFormat do not match
-                            // -> insert as Text
-                            bLockModify = bSetNumFmt = sal_False;
-                    }
+                        // Current and specified NumFormat do not match
+                        // -> insert as Text
+                        bLockModify = bSetNumFmt = sal_False;
                 }
+            }
 
-                if( bSetNumFmt )
-                {
-                    pBoxFmt = (SwTableBoxFmt*)rBox.ClaimFrmFmt();
+            if( bSetNumFmt )
+            {
+                pBoxFmt = (SwTableBoxFmt*)rBox.ClaimFrmFmt();
 
-                    aBoxSet.Put( SwTblBoxValue( fNumber ));
-                    aBoxSet.Put( SwTblBoxNumFormat( nFmtIdx ));
-                }
+                aBoxSet.Put( SwTblBoxValue( fNumber ));
+                aBoxSet.Put( SwTblBoxNumFormat( nFmtIdx ));
             }
 
             // It's not enough to only reset the Formula.


More information about the Libreoffice-commits mailing list