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

Kohei Yoshida kohei.yoshida at gmail.com
Wed Mar 27 14:39:15 PDT 2013


 sc/source/ui/unoobj/cellsuno.cxx |  111 ++++++++++++++++++---------------------
 1 file changed, 53 insertions(+), 58 deletions(-)

New commits:
commit dd47fc6b2d3ed79868721826ad77d6ad415ca4ac
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 27 17:38:51 2013 -0400

    Remove a bit more use of ScEditCell and ScBaseCell.
    
    Change-Id: Ib01eaef7e3a612048d2ed3f714ed178f4076e689

diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index df8d3ce..e74f249 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -1394,18 +1394,18 @@ static OUString lcl_GetInputString( ScDocument* pDoc, const ScAddress& rPos, sal
     if (!pDoc)
         return EMPTY_OUSTRING;
 
-
-    ScBaseCell* pCell = pDoc->GetCell(rPos);
-    if (!pCell || pCell->GetCellType() == CELLTYPE_NOTE)
+    ScRefCellValue aCell;
+    aCell.assign(*pDoc, rPos);
+    if (aCell.isEmpty())
         return EMPTY_OUSTRING;
 
     OUString aVal;
 
-    CellType eType = pCell->GetCellType();
+    CellType eType = aCell.meType;
     if (eType == CELLTYPE_FORMULA)
     {
-        ScFormulaCell* pForm = (ScFormulaCell*)pCell;
-        pForm->GetFormula( aVal,formula::FormulaGrammar::mapAPItoGrammar( bEnglish, false));
+        ScFormulaCell* pForm = aCell.mpFormula;
+        pForm->GetFormula( aVal, formula::FormulaGrammar::mapAPItoGrammar( bEnglish, false));
         return aVal;
     }
 
@@ -1416,24 +1416,20 @@ static OUString lcl_GetInputString( ScDocument* pDoc, const ScAddress& rPos, sal
     // we don't have to query.
     sal_uInt32 nNumFmt = bEnglish ? 0 : pDoc->GetNumberFormat(rPos);
 
-    if ( eType == CELLTYPE_EDIT )
+    if (eType == CELLTYPE_EDIT)
     {
         //  GetString an der EditCell macht Leerzeichen aus Umbruechen,
         //  hier werden die Umbrueche aber gebraucht
-        const EditTextObject* pData = ((ScEditCell*)pCell)->GetData();
+        const EditTextObject* pData = aCell.mpEditText;
         if (pData)
         {
             EditEngine& rEngine = pDoc->GetEditEngine();
-            rEngine.SetText( *pData );
-            aVal = rEngine.GetText( LINEEND_LF );
+            rEngine.SetText(*pData);
+            aVal = rEngine.GetText(LINEEND_LF);
         }
     }
     else
-    {
-        ScRefCellValue aCell;
-        aCell.assign(*pCell);
         ScCellFormat::GetInputString(aCell, nNumFmt, aVal, *pFormatter);
-    }
 
     //  ggf. ein ' davorhaengen wie in ScTabViewShell::UpdateInputHandler
     if ( eType == CELLTYPE_STRING || eType == CELLTYPE_EDIT )
commit 9c72cc05735d3e2dc16c6ef4f8765cb34ce5bfbc
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 27 17:34:02 2013 -0400

    Reduce indentation by early bail-out.
    
    Change-Id: I5965a38fdd4e80e22136905881a39eb38ffb7798

diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 45e41da..df8d3ce 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -1389,69 +1389,68 @@ static sal_Bool lcl_PutFormulaArray( ScDocShell& rDocShell, const ScRange& rRang
 }
 
 //  used in ScCellRangeObj::getFormulaArray and ScCellObj::GetInputString_Impl
-static String lcl_GetInputString( ScDocument* pDoc, const ScAddress& rPosition, sal_Bool bEnglish )
+static OUString lcl_GetInputString( ScDocument* pDoc, const ScAddress& rPos, sal_Bool bEnglish )
 {
-    rtl::OUString aVal;
-    if ( pDoc )
+    if (!pDoc)
+        return EMPTY_OUSTRING;
+
+
+    ScBaseCell* pCell = pDoc->GetCell(rPos);
+    if (!pCell || pCell->GetCellType() == CELLTYPE_NOTE)
+        return EMPTY_OUSTRING;
+
+    OUString aVal;
+
+    CellType eType = pCell->GetCellType();
+    if (eType == CELLTYPE_FORMULA)
     {
-        ScBaseCell* pCell = pDoc->GetCell( rPosition );
-        if ( pCell && pCell->GetCellType() != CELLTYPE_NOTE )
+        ScFormulaCell* pForm = (ScFormulaCell*)pCell;
+        pForm->GetFormula( aVal,formula::FormulaGrammar::mapAPItoGrammar( bEnglish, false));
+        return aVal;
+    }
+
+    SvNumberFormatter* pFormatter = bEnglish ? ScGlobal::GetEnglishFormatter() :
+                                                pDoc->GetFormatTable();
+    // Since the English formatter was constructed with
+    // LANGUAGE_ENGLISH_US the "General" format has index key 0,
+    // we don't have to query.
+    sal_uInt32 nNumFmt = bEnglish ? 0 : pDoc->GetNumberFormat(rPos);
+
+    if ( eType == CELLTYPE_EDIT )
+    {
+        //  GetString an der EditCell macht Leerzeichen aus Umbruechen,
+        //  hier werden die Umbrueche aber gebraucht
+        const EditTextObject* pData = ((ScEditCell*)pCell)->GetData();
+        if (pData)
         {
-            CellType eType = pCell->GetCellType();
-            if ( eType == CELLTYPE_FORMULA )
-            {
-                ScFormulaCell* pForm = (ScFormulaCell*)pCell;
-                pForm->GetFormula( aVal,formula::FormulaGrammar::mapAPItoGrammar( bEnglish, false));
-            }
-            else
-            {
-                SvNumberFormatter* pFormatter = bEnglish ? ScGlobal::GetEnglishFormatter() :
-                                                            pDoc->GetFormatTable();
-                // Since the English formatter was constructed with
-                // LANGUAGE_ENGLISH_US the "General" format has index key 0,
-                // we don't have to query.
-                sal_uInt32 nNumFmt = bEnglish ?
-                        0 :
-                        pDoc->GetNumberFormat( rPosition );
-
-                if ( eType == CELLTYPE_EDIT )
-                {
-                    //  GetString an der EditCell macht Leerzeichen aus Umbruechen,
-                    //  hier werden die Umbrueche aber gebraucht
-                    const EditTextObject* pData = ((ScEditCell*)pCell)->GetData();
-                    if (pData)
-                    {
-                        EditEngine& rEngine = pDoc->GetEditEngine();
-                        rEngine.SetText( *pData );
-                        aVal = rEngine.GetText( LINEEND_LF );
-                    }
-                }
-                else
-                {
-                    ScRefCellValue aCell;
-                    aCell.assign(*pCell);
-                    ScCellFormat::GetInputString(aCell, nNumFmt, aVal, *pFormatter);
-                }
+            EditEngine& rEngine = pDoc->GetEditEngine();
+            rEngine.SetText( *pData );
+            aVal = rEngine.GetText( LINEEND_LF );
+        }
+    }
+    else
+    {
+        ScRefCellValue aCell;
+        aCell.assign(*pCell);
+        ScCellFormat::GetInputString(aCell, nNumFmt, aVal, *pFormatter);
+    }
 
-                //  ggf. ein ' davorhaengen wie in ScTabViewShell::UpdateInputHandler
-                if ( eType == CELLTYPE_STRING || eType == CELLTYPE_EDIT )
-                {
-                    double fDummy;
-                    String aTempString = aVal;
-                    sal_Bool bIsNumberFormat(pFormatter->IsNumberFormat(aTempString, nNumFmt, fDummy));
-                    if ( bIsNumberFormat )
-                        aTempString.Insert('\'',0);
-                    else if ( aTempString.Len() && aTempString.GetChar(0) == '\'' )
-                    {
-                        //  if the string starts with a "'", add another one because setFormula
-                        //  strips one (like text input, except for "text" number formats)
-                        if ( bEnglish || ( pFormatter->GetType(nNumFmt) != NUMBERFORMAT_TEXT ) )
-                            aTempString.Insert('\'',0);
-                    }
-                    aVal = aTempString;
-                }
-            }
+    //  ggf. ein ' davorhaengen wie in ScTabViewShell::UpdateInputHandler
+    if ( eType == CELLTYPE_STRING || eType == CELLTYPE_EDIT )
+    {
+        double fDummy;
+        String aTempString = aVal;
+        sal_Bool bIsNumberFormat(pFormatter->IsNumberFormat(aTempString, nNumFmt, fDummy));
+        if ( bIsNumberFormat )
+            aTempString.Insert('\'',0);
+        else if ( aTempString.Len() && aTempString.GetChar(0) == '\'' )
+        {
+            //  if the string starts with a "'", add another one because setFormula
+            //  strips one (like text input, except for "text" number formats)
+            if ( bEnglish || ( pFormatter->GetType(nNumFmt) != NUMBERFORMAT_TEXT ) )
+                aTempString.Insert('\'',0);
         }
+        aVal = aTempString;
     }
     return aVal;
 }


More information about the Libreoffice-commits mailing list