[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - 2 commits - sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Wed Mar 20 16:43:51 PDT 2013


 sc/source/core/tool/stringutil.cxx |    1 
 sc/source/ui/unoobj/cellsuno.cxx   |   81 +++++++++++++++++++++++--------------
 2 files changed, 53 insertions(+), 29 deletions(-)

New commits:
commit d9570aef923b30f8bffa0000d24efd39a50f9fe9
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 20 19:41:42 2013 -0400

    Reduce indentation levels by early bail-out.
    
    Change-Id: Ief345d48750250150836097af2072fb030aa4505

diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 184c859..dde15a6 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -6342,66 +6342,65 @@ void ScCellObj::InputEnglishString( const ::rtl::OUString& rText )
     // but all parsing is in English.
 
     ScDocShell* pDocSh = GetDocShell();
-    if ( pDocSh )
+    if (!pDocSh)
+        return;
+
+    String aString(rText);
+    ScDocument* pDoc = pDocSh->GetDocument();
+    SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
+    sal_uInt32 nOldFormat = pDoc->GetNumberFormat( aCellPos );
+    if (pFormatter->GetType(nOldFormat) == NUMBERFORMAT_TEXT)
     {
-        String aString(rText);
-        ScDocument* pDoc = pDocSh->GetDocument();
-        SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
-        sal_uInt32 nOldFormat = pDoc->GetNumberFormat( aCellPos );
-        if ( pFormatter->GetType( nOldFormat ) == NUMBERFORMAT_TEXT )
-        {
-            SetString_Impl(aString, false, false);      // text cell
-        }
-        else
-        {
-            ScDocFunc &rFunc = pDocSh->GetDocFunc();
+        SetString_Impl(aString, false, false);      // text cell
+        return;
+    }
+
+    ScDocFunc &rFunc = pDocSh->GetDocFunc();
 
-            ScInputStringType aRes =
-                ScStringUtil::parseInputString(*pFormatter, aString, LANGUAGE_ENGLISH_US);
+    ScInputStringType aRes =
+        ScStringUtil::parseInputString(*pFormatter, aString, LANGUAGE_ENGLISH_US);
 
-            if (aRes.meType != ScInputStringType::Unknown)
+    if (aRes.meType != ScInputStringType::Unknown)
+    {
+        if ((nOldFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 && aRes.mnFormatType)
+        {
+            // apply a format for the recognized type and the old format's language
+            sal_uInt32 nNewFormat = ScGlobal::GetStandardFormat(*pFormatter, nOldFormat, aRes.mnFormatType);
+            if (nNewFormat != nOldFormat)
             {
-                if ((nOldFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 && aRes.mnFormatType)
-                {
-                    // apply a format for the recognized type and the old format's language
-                    sal_uInt32 nNewFormat = ScGlobal::GetStandardFormat(*pFormatter, nOldFormat, aRes.mnFormatType);
-                    if (nNewFormat != nOldFormat)
-                    {
-                        ScPatternAttr aPattern( pDoc->GetPool() );
-                        aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) );
-                        // ATTR_LANGUAGE_FORMAT remains unchanged
-                        rFunc.ApplyAttributes( *GetMarkData(), aPattern, true, true );
-                    }
-                }
+                ScPatternAttr aPattern( pDoc->GetPool() );
+                aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) );
+                // ATTR_LANGUAGE_FORMAT remains unchanged
+                rFunc.ApplyAttributes( *GetMarkData(), aPattern, true, true );
             }
-            switch (aRes.meType)
+        }
+    }
+    switch (aRes.meType)
+    {
+        case ScInputStringType::Formula:
+            rFunc.SetFormulaCell(
+                aCellPos,
+                new ScFormulaCell(pDoc, aCellPos, aRes.maText, formula::FormulaGrammar::GRAM_PODF_A1),
+                false);
+        break;
+        case ScInputStringType::Number:
+            rFunc.SetValueCell(aCellPos, aRes.mfValue, false);
+        break;
+        case ScInputStringType::Text:
+        {
+            if (ScStringUtil::isMultiline(aRes.maText))
             {
-                case ScInputStringType::Formula:
-                    rFunc.SetFormulaCell(
-                        aCellPos,
-                        new ScFormulaCell(pDoc, aCellPos, aRes.maText, formula::FormulaGrammar::GRAM_PODF_A1),
-                        false);
-                break;
-                case ScInputStringType::Number:
-                    rFunc.SetValueCell(aCellPos, aRes.mfValue, false);
-                break;
-                case ScInputStringType::Text:
-                {
-                    if (ScStringUtil::isMultiline(aRes.maText))
-                    {
-                        ScFieldEditEngine& rEngine = pDoc->GetEditEngine();
-                        rEngine.SetText(aRes.maText);
-                        boost::scoped_ptr<EditTextObject> pEditText(rEngine.CreateTextObject());
-                        rFunc.SetEditCell(aCellPos, *pEditText, false);
-                    }
-                    else
-                        rFunc.SetStringCell(aCellPos, aRes.maText, false);
-                }
-                break;
-                default:
-                    SetString_Impl(aString, false, false); // probably empty string
+                ScFieldEditEngine& rEngine = pDoc->GetEditEngine();
+                rEngine.SetText(aRes.maText);
+                boost::scoped_ptr<EditTextObject> pEditText(rEngine.CreateTextObject());
+                rFunc.SetEditCell(aCellPos, *pEditText, false);
             }
+            else
+                rFunc.SetStringCell(aCellPos, aRes.maText, false);
         }
+        break;
+        default:
+            SetString_Impl(aString, false, false); // probably empty string
     }
 }
 
commit bd686325bb4e8b3c0ab7d4cab1ccd2a8b72fa388
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 20 19:40:29 2013 -0400

    Another removal of PutCell().
    
    Change-Id: I1519ed62f623770f690385cb725e5d1e9a636e48

diff --git a/sc/source/core/tool/stringutil.cxx b/sc/source/core/tool/stringutil.cxx
index 82dfc69..7753bdf 100644
--- a/sc/source/core/tool/stringutil.cxx
+++ b/sc/source/core/tool/stringutil.cxx
@@ -338,6 +338,7 @@ ScInputStringType ScStringUtil::parseInputString(
     SvNumberFormatter& rFormatter, const OUString& rStr, LanguageType eLang )
 {
     ScInputStringType aRet;
+    aRet.mnFormatType = 0;
     aRet.meType = ScInputStringType::Unknown;
     aRet.maText = rStr;
 
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 0e3994c..184c859 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -27,6 +27,7 @@
 #include <editeng/editeng.hxx>
 #include <editeng/flditem.hxx>
 #include <editeng/justifyitem.hxx>
+#include "editeng/editobj.hxx"
 #include <svx/fmdpage.hxx>
 #include <editeng/langitem.hxx>
 #include <sfx2/linkmgr.hxx>
@@ -6354,29 +6355,52 @@ void ScCellObj::InputEnglishString( const ::rtl::OUString& rText )
         else
         {
             ScDocFunc &rFunc = pDocSh->GetDocFunc();
-            short nFormatType = 0;
-            ScBaseCell* pNewCell = rFunc.InterpretEnglishString( aCellPos, aString,
-                                    EMPTY_STRING, formula::FormulaGrammar::GRAM_PODF_A1, &nFormatType );
-            if (pNewCell)
+
+            ScInputStringType aRes =
+                ScStringUtil::parseInputString(*pFormatter, aString, LANGUAGE_ENGLISH_US);
+
+            if (aRes.meType != ScInputStringType::Unknown)
             {
-                if ( ( nOldFormat % SV_COUNTRY_LANGUAGE_OFFSET ) == 0 && nFormatType != 0 )
+                if ((nOldFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 && aRes.mnFormatType)
                 {
                     // apply a format for the recognized type and the old format's language
-                    sal_uInt32 nNewFormat = ScGlobal::GetStandardFormat( *pFormatter, nOldFormat, nFormatType );
-                    if ( nNewFormat != nOldFormat )
+                    sal_uInt32 nNewFormat = ScGlobal::GetStandardFormat(*pFormatter, nOldFormat, aRes.mnFormatType);
+                    if (nNewFormat != nOldFormat)
                     {
                         ScPatternAttr aPattern( pDoc->GetPool() );
                         aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) );
                         // ATTR_LANGUAGE_FORMAT remains unchanged
-                        rFunc.ApplyAttributes( *GetMarkData(), aPattern, sal_True, sal_True );
+                        rFunc.ApplyAttributes( *GetMarkData(), aPattern, true, true );
                     }
                 }
-                // put the cell into the document
-                // (after applying the format, so possible formula recalculation already uses the new format)
-                (void)rFunc.PutCell( aCellPos, pNewCell, sal_True );
             }
-            else
-                SetString_Impl(aString, false, false);      // no cell from InterpretEnglishString, probably empty string
+            switch (aRes.meType)
+            {
+                case ScInputStringType::Formula:
+                    rFunc.SetFormulaCell(
+                        aCellPos,
+                        new ScFormulaCell(pDoc, aCellPos, aRes.maText, formula::FormulaGrammar::GRAM_PODF_A1),
+                        false);
+                break;
+                case ScInputStringType::Number:
+                    rFunc.SetValueCell(aCellPos, aRes.mfValue, false);
+                break;
+                case ScInputStringType::Text:
+                {
+                    if (ScStringUtil::isMultiline(aRes.maText))
+                    {
+                        ScFieldEditEngine& rEngine = pDoc->GetEditEngine();
+                        rEngine.SetText(aRes.maText);
+                        boost::scoped_ptr<EditTextObject> pEditText(rEngine.CreateTextObject());
+                        rFunc.SetEditCell(aCellPos, *pEditText, false);
+                    }
+                    else
+                        rFunc.SetStringCell(aCellPos, aRes.maText, false);
+                }
+                break;
+                default:
+                    SetString_Impl(aString, false, false); // probably empty string
+            }
         }
     }
 }


More information about the Libreoffice-commits mailing list