You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by le...@apache.org on 2012/09/21 08:40:24 UTC

svn commit: r1388342 - in /incubator/ooo/trunk/main/sc: inc/cell.hxx source/core/data/cell.cxx source/core/inc/interpre.hxx source/core/tool/interpr4.cxx source/ui/unoobj/chart2uno.cxx

Author: leiw
Date: Fri Sep 21 06:40:24 2012
New Revision: 1388342

URL: http://svn.apache.org/viewvc?rev=1388342&view=rev
Log:
#i120962 Chart data lost if the source data refers to a range name which is defined as a reference formula

          Patch by: Clarence GUO
          Review by: Wang Lei

Modified:
    incubator/ooo/trunk/main/sc/inc/cell.hxx
    incubator/ooo/trunk/main/sc/source/core/data/cell.cxx
    incubator/ooo/trunk/main/sc/source/core/inc/interpre.hxx
    incubator/ooo/trunk/main/sc/source/core/tool/interpr4.cxx
    incubator/ooo/trunk/main/sc/source/ui/unoobj/chart2uno.cxx

Modified: incubator/ooo/trunk/main/sc/inc/cell.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/inc/cell.hxx?rev=1388342&r1=1388341&r2=1388342&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/inc/cell.hxx (original)
+++ incubator/ooo/trunk/main/sc/inc/cell.hxx Fri Sep 21 06:40:24 2012
@@ -19,8 +19,6 @@
  * 
  *************************************************************/
 
-
-
 #ifndef SC_CELL_HXX
 #define SC_CELL_HXX
 
@@ -309,6 +307,7 @@ private:
     sal_Bool            bInChangeTrack : 1; // Cell is in ChangeTrack
     sal_Bool            bTableOpDirty  : 1; // Dirty flag for TableOp
     sal_Bool            bNeedListening : 1; // Listeners need to be re-established after UpdateReference
+    ScToken*            pValidRefToken; // i120962, get the valid reference token if the cell was applied a reference formula
 
                     enum ScInterpretTailParameter
                     {
@@ -485,6 +484,7 @@ public:
 
     /** Determines whether or not the result string contains more than one paragraph */
     bool            IsMultilineResult();
+    ScToken*        GetValidRefToken() { return pValidRefToken; }   // i120962
 };
 
 //			Iterator fuer Referenzen in einer Formelzelle

Modified: incubator/ooo/trunk/main/sc/source/core/data/cell.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/core/data/cell.cxx?rev=1388342&r1=1388341&r2=1388342&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/core/data/cell.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/core/data/cell.cxx Fri Sep 21 06:40:24 2012
@@ -19,8 +19,6 @@
  * 
  *************************************************************/
 
-
-
 // MARKER(update_precomp.py): autogen include statement, do not remove
 #include "precompiled_sc.hxx"
 
@@ -644,7 +642,8 @@ ScFormulaCell::ScFormulaCell() :
 	bInChangeTrack( sal_False ),
 	bTableOpDirty( sal_False ),
 	bNeedListening( sal_False ),
-	aPos(0,0,0)
+	aPos(0,0,0),
+	pValidRefToken( NULL )
 {
 }
 
@@ -673,7 +672,8 @@ ScFormulaCell::ScFormulaCell( ScDocument
 	bInChangeTrack( sal_False ),
 	bTableOpDirty( sal_False ),
 	bNeedListening( sal_False ),
-	aPos( rPos )
+	aPos( rPos ),
+	pValidRefToken( NULL )
 {
     Compile( rFormula, sal_True, eGrammar );    // bNoListening, Insert does that
 }
@@ -704,7 +704,8 @@ ScFormulaCell::ScFormulaCell( ScDocument
 	bInChangeTrack( sal_False ),
 	bTableOpDirty( sal_False ),
 	bNeedListening( sal_False ),
-	aPos( rPos )
+	aPos( rPos ),
+	pValidRefToken( NULL )
 {
 	// UPN-Array erzeugen
 	if( pCode->GetLen() && !pCode->GetCodeError() && !pCode->GetCodeLen() )
@@ -745,7 +746,8 @@ ScFormulaCell::ScFormulaCell( const ScFo
 	bInChangeTrack( sal_False ),
 	bTableOpDirty( sal_False ),
 	bNeedListening( sal_False ),
-	aPos( rPos )
+	aPos( rPos ),
+	pValidRefToken( rCell.pValidRefToken )
 {
 	pCode = (rCell.pCode) ? rCell.pCode->Clone() : NULL;
 
@@ -823,6 +825,7 @@ ScFormulaCell::~ScFormulaCell()
 #ifdef DBG_UTIL
 	eCellType = CELLTYPE_DESTROYED;
 #endif
+    DELETEZ(pValidRefToken);
 }
 
 void ScFormulaCell::GetFormula( rtl::OUStringBuffer& rBuffer,
@@ -1556,6 +1559,12 @@ void ScFormulaCell::InterpretTail( ScInt
             return;
         }
         bRunning = bOldRunning;
+//-> i120962: If the cell was applied reference formula, get the valid token
+        if (pValidRefToken)
+            DELETEZ(pValidRefToken);
+        if (p->IsReferenceFunc() && p->GetLastStackRefToken())
+            pValidRefToken = static_cast<ScToken*>(p->GetLastStackRefToken()->Clone());
+//<- i120962
 
         // #i102616# For single-sheet saving consider only content changes, not format type,
         // because format type isn't set on loading (might be changed later)

Modified: incubator/ooo/trunk/main/sc/source/core/inc/interpre.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/core/inc/interpre.hxx?rev=1388342&r1=1388341&r2=1388342&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/core/inc/interpre.hxx (original)
+++ incubator/ooo/trunk/main/sc/source/core/inc/interpre.hxx Fri Sep 21 06:40:24 2012
@@ -19,8 +19,6 @@
  * 
  *************************************************************/
 
-
-
 #ifndef SC_INTERPRE_HXX
 #define SC_INTERPRE_HXX
 
@@ -146,7 +144,7 @@ public:
     ScMatrixRef GetNewMat(SCSIZE nC, SCSIZE nR);
 private:
     static ScTokenStack*    pGlobalStack;
-    static sal_Bool             bGlobalStackInUse;
+    static sal_Bool         bGlobalStackInUse;
 
     formula::FormulaTokenIterator aCode;
     ScAddress   aPos;
@@ -160,6 +158,8 @@ private:
 
     const formula::FormulaToken* 
                 pCur;                // current token
+    ScToken*    pLastStackRefToken;     // i120962: current valid reference token
+    bool        bRefFunc;               // i120962: is a reference function
     String      aTempStr;               // for GetString()
     ScTokenStack* pStackObj;            // contains the stacks
     formula::FormulaToken**   pStack;                 // the current stack
@@ -812,14 +812,16 @@ public:
     void SetError(sal_uInt16 nError)
             { if (nError && !nGlobalError) nGlobalError = nError; }
 
-    sal_uInt16 GetError()                               const   { return nGlobalError; }
+    sal_uInt16 GetError()                           const   { return nGlobalError; }
     formula::StackVar  GetResultType()              const   { return xResult->GetType(); }
     const String&   GetStringResult()               const   { return xResult->GetString(); }
     double          GetNumResult()                  const   { return xResult->GetDouble(); }
     formula::FormulaTokenRef 
                     GetResultToken()                const   { return xResult; }
     short           GetRetFormatType()              const   { return nRetFmtType; }
-    sal_uLong           GetRetFormatIndex()             const   { return nRetFmtIndex; }
+    sal_uLong       GetRetFormatIndex()             const   { return nRetFmtIndex; }
+    ScToken*        GetLastStackRefToken() { return pLastStackRefToken; }
+    bool            IsReferenceFunc() { return bRefFunc; }
 };
 
 

Modified: incubator/ooo/trunk/main/sc/source/core/tool/interpr4.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/core/tool/interpr4.cxx?rev=1388342&r1=1388341&r2=1388342&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/core/tool/interpr4.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/core/tool/interpr4.cxx Fri Sep 21 06:40:24 2012
@@ -19,8 +19,6 @@
  * 
  *************************************************************/
 
-
-
 // MARKER(update_precomp.py): autogen include statement, do not remove
 #include "precompiled_sc.hxx"
 // INCLUDE ---------------------------------------------------------------
@@ -62,6 +60,7 @@
 #include "parclass.hxx"
 #include "externalrefmgr.hxx"
 #include "doubleref.hxx"
+#include "token.hxx"
 
 #include <math.h>
 #include <float.h>
@@ -1170,6 +1169,9 @@ void ScInterpreter::PopSingleRef(SCCOL& 
                 SingleRefToVars( static_cast<ScToken*>(p)->GetSingleRef(), rCol, rRow, rTab);
                 if ( pDok->aTableOpList.Count() > 0 )
                     ReplaceCell( rCol, rRow, rTab );
+                DELETEZ(pLastStackRefToken);
+                pLastStackRefToken = static_cast<ScToken*>(p->Clone());
+                ((ScSingleRefToken*)pLastStackRefToken)->GetSingleRef().SetFlag3D(sal_True);
                 break;
             default:
                 SetError( errIllegalParameter);
@@ -1201,6 +1203,9 @@ void ScInterpreter::PopSingleRef( ScAddr
                     rAdr.Set( nCol, nRow, nTab );
                     if ( pDok->aTableOpList.Count() > 0 )
                         ReplaceCell( rAdr );
+                    DELETEZ(pLastStackRefToken);
+                    pLastStackRefToken = static_cast<ScToken*>(p->Clone());
+                    ((ScSingleRefToken*)pLastStackRefToken)->GetSingleRef().SetFlag3D(sal_True);
                 }
                 break;
             default:
@@ -1283,6 +1288,9 @@ void ScInterpreter::PopDoubleRef(SCCOL& 
             case svDoubleRef:
                 DoubleRefToVars( static_cast<ScToken*>(p), rCol1, rRow1, rTab1, rCol2, rRow2, rTab2,
                         bDontCheckForTableOp);
+                DELETEZ(pLastStackRefToken);
+                pLastStackRefToken = static_cast<ScToken*>(p->Clone());
+                ((ScDoubleRefToken*)pLastStackRefToken)->GetSingleRef().SetFlag3D(sal_True);
                 break;
             default:
                 SetError( errIllegalParameter);
@@ -1327,6 +1335,9 @@ void ScInterpreter::PopDoubleRef( ScRang
             case svDoubleRef:
                 --sp;
                 DoubleRefToRange( p->GetDoubleRef(), rRange);
+                DELETEZ(pLastStackRefToken);
+                pLastStackRefToken = static_cast<ScToken*>(p->Clone());
+                ((ScDoubleRefToken*)pLastStackRefToken)->GetSingleRef().SetFlag3D(sal_True);
                 break;
             case svRefList:
                 {
@@ -1373,6 +1384,9 @@ void ScInterpreter::PopDoubleRef( ScRang
                 break;
             case svDoubleRef:
                 DoubleRefToRange( static_cast<ScToken*>(p)->GetDoubleRef(), rRange, bDontCheckForTableOp);
+                DELETEZ(pLastStackRefToken);
+                pLastStackRefToken = static_cast<ScToken*>(p->Clone());
+                ((ScDoubleRefToken*)pLastStackRefToken)->GetSingleRef().SetFlag3D(sal_True);
                 break;
             default:
                 SetError( errIllegalParameter);
@@ -3286,6 +3300,8 @@ ScInterpreter::ScInterpreter( ScFormulaC
     pMyFormulaCell( pCell ),
     pFormatter( pDoc->GetFormatTable() ),
     mnStringNoValueError( errNoValue),
+    pLastStackRefToken( NULL ),
+    bRefFunc( false ),
     bCalcAsShown( pDoc->GetDocOptions().IsCalcAsShown() )
 {
     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::ScTTT" );
@@ -3317,6 +3333,7 @@ ScInterpreter::~ScInterpreter()
         delete pStackObj;
     if (pTokenMatrixMap)
         delete pTokenMatrixMap;
+    DELETEZ(pLastStackRefToken);
 }
 
 
@@ -3865,6 +3882,7 @@ StackVar ScInterpreter::Interpret()
 
     // End: obtain result
 
+    bRefFunc = false;
     if( sp )
     {
         pCur = pStack[ sp-1 ];
@@ -3891,6 +3909,7 @@ StackVar ScInterpreter::Interpret()
                 break;
                 case svSingleRef :
                 {
+                    bRefFunc = true;
                     ScAddress aAdr;
                     PopSingleRef( aAdr );
                     if( !nGlobalError )
@@ -3911,6 +3930,7 @@ StackVar ScInterpreter::Interpret()
                     }
                     else
                     {
+                        bRefFunc = true;
                         ScRange aRange;
                         PopDoubleRef( aRange );
                         ScAddress aAdr;

Modified: incubator/ooo/trunk/main/sc/source/ui/unoobj/chart2uno.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/sc/source/ui/unoobj/chart2uno.cxx?rev=1388342&r1=1388341&r2=1388342&view=diff
==============================================================================
--- incubator/ooo/trunk/main/sc/source/ui/unoobj/chart2uno.cxx (original)
+++ incubator/ooo/trunk/main/sc/source/ui/unoobj/chart2uno.cxx Fri Sep 21 06:40:24 2012
@@ -19,8 +19,6 @@
  * 
  *************************************************************/
 
-
-
 // MARKER(update_precomp.py): autogen include statement, do not remove
 #include "precompiled_sc.hxx"
 
@@ -39,6 +37,7 @@
 #include "compiler.hxx"
 #include "reftokenhelper.hxx"
 #include "chartlis.hxx"
+#include "rangenam.hxx"
 
 #include <sfx2/objsh.hxx>
 #include <tools/table.hxx>
@@ -2035,6 +2034,53 @@ uno::Reference< chart2::data::XDataSeque
 
     vector<ScSharedTokenRef> aRefTokens;
     ScRefTokenHelper::compileRangeRepresentation(aRefTokens, aRangeRepresentation, m_pDocument);
+	if (aRefTokens.empty())	// i120962: If haven't get reference, that means aRangeRepresentation is not a simple address, then try formulas
+	{
+		ScRangeName	aLocalRangeName(*(m_pDocument->GetRangeName()));
+		sal_uInt16	nCurPos = 0;
+		sal_Bool	bFindName = aLocalRangeName.SearchName(aRangeRepresentation, nCurPos);	// Find global name first
+
+		for (SCTAB Scope = 0; Scope < MAXTABCOUNT && !bFindName; Scope++ )	// Find name in sheet scope
+			bFindName = aLocalRangeName.SearchName(aRangeRepresentation, nCurPos, Scope);
+
+		if (bFindName)
+		{
+			ScRangeData*	pData =(ScRangeData*)(aLocalRangeName.At(nCurPos));
+			ScTokenArray*	pArray = pData->GetCode();
+			sal_uInt16 nLen = pArray->GetLen();
+			if (!nLen)
+				;
+			else if (nLen == 1)	// range names
+			{
+				pArray->Reset();
+				const FormulaToken* p = pArray->GetNextReference();
+				if (p)
+					aRefTokens.push_back(
+							ScSharedTokenRef(static_cast<ScToken*>(p->Clone())));
+			}
+			else	// formulas
+			{
+				String	aSymbol;
+				pData->GetSymbol(aSymbol, FormulaGrammar::GRAM_ENGLISH);
+
+				String	aFormulaStr('=');
+				aFormulaStr += aSymbol;
+
+				ScAddress	aAddr;
+				ScFormulaCell*	pCell = new ScFormulaCell(m_pDocument, aAddr, aFormulaStr, FormulaGrammar::GRAM_ENGLISH);
+				pCell->Interpret();
+
+				if (pCell->GetValidRefToken())
+				{
+					aRefTokens.push_back(
+						ScSharedTokenRef(static_cast<ScToken*>(pCell->GetValidRefToken()->Clone())));
+				}
+
+				DELETEZ( pCell );
+			}
+		}
+	}
+
     if (aRefTokens.empty())
         return xResult;