Commits

Anonymous committed 3285a6a

#i10000#: fix merge conflicts (CWS frmdlg)

Comments (0)

Files changed (36)

sc/inc/address.hxx

     inline void GetVars( SCCOL& nColP, SCROW& nRowP, SCTAB& nTabP ) const
     { nColP = nCol; nRowP = nRow; nTabP = nTab; }
 
-    USC_DLLPUBLIC USHORT Parse( const String&, ScDocument* = NULL, 
+    SC_DLLPUBLIC USHORT Parse( const String&, ScDocument* = NULL, 
                   const Details& rDetails = detailsOOOa1,
                   ExternalInfo* pExtInfo = NULL,
                   const ::com::sun::star::uno::Sequence<

sc/inc/compiler.hxx

             The previous grammar that was active before SetFormulaLanguage().
      */
     void            SetGrammarAndRefConvention(
-                        const ScGrammar::Grammar eNewGrammar,
-                        const ScGrammar::Grammar eOldGrammar );
+                        const formula::FormulaGrammar::Grammar eNewGrammar,
+                        const formula::FormulaGrammar::Grammar eOldGrammar );
 public:
 
     /// Set external link info for ScAddress::CONV_XL_OOX.
     virtual BOOL HandleDbData();
 
     virtual formula::FormulaTokenRef ExtendRangeReference( formula::FormulaToken & rTok1, formula::FormulaToken & rTok2, bool bReuseDoubleRef );
-	virtual void CreateStringFromExternal(rtl::OUStringBuffer& rBuffer, FormulaToken* pTokenP)
+	virtual void CreateStringFromExternal(rtl::OUStringBuffer& rBuffer, formula::FormulaToken* pTokenP);
     virtual void CreateStringFromSingleRef(rtl::OUStringBuffer& rBuffer,formula::FormulaToken* _pTokenP);
     virtual void CreateStringFromDoubleRef(rtl::OUStringBuffer& rBuffer,formula::FormulaToken* _pTokenP);
     virtual void CreateStringFromMatrix( rtl::OUStringBuffer& rBuffer, formula::FormulaToken* _pTokenP);

sc/inc/externalrefmgr.hxx

 #include <boost/shared_ptr.hpp>
 #include <vector>
 #include <list>
+#include <formula/ExternalReferenceHelper.hxx>
 
 class ScDocument;
+namespace formula
+{
+    class FormulaToken;
+}
 class ScToken;
 class ScMatrix;
 class ScTokenArray;
 class ScExternalRefCache
 {
 public:
-    typedef ::boost::shared_ptr<ScToken>            TokenRef;
-    typedef ::boost::shared_ptr<ScTokenArray>       TokenArrayRef;
+    typedef ::boost::shared_ptr< formula::FormulaToken>     TokenRef;
+    typedef ::boost::shared_ptr<ScTokenArray>               TokenArrayRef;
 
     struct TableName
     {
 
 // ============================================================================
 
-class ScExternalRefManager
+class ScExternalRefManager : public formula::ExternalReferenceHelper
 {
 public:
 
     explicit ScExternalRefManager(ScDocument* pDoc);
     ~ScExternalRefManager();
 
-    String getCacheTableName(sal_uInt16 nFileId, size_t nTabIndex) const;
+    virtual String getCacheTableName(sal_uInt16 nFileId, size_t nTabIndex) const;
 
     /**
      * Get a cache table instance for specified table and table index.  Unlike
     virtual const String&           GetString() const;
     virtual const ScSingleRefData&  GetSingleRef() const;
     virtual ScSingleRefData&          GetSingleRef();
-    virtual BOOL                    operator==( const ScToken& rToken ) const;
+    virtual BOOL                operator==( const formula::FormulaToken& rToken ) const;
 };
 
 
     virtual ScSingleRefData&       GetSingleRef2();
     virtual const ScComplexRefData&    GetDoubleRef() const;
     virtual ScComplexRefData&      GetDoubleRef();
-    virtual BOOL                   operator==( const ScToken& rToken ) const;
+    virtual BOOL                operator==( const formula::FormulaToken& rToken ) const;
 };
 
 
     virtual                     ~ScExternalNameToken();
     virtual USHORT              GetIndex() const;
     virtual const String&       GetString() const;
-    virtual BOOL                operator==( const ScToken& rToken ) const;
+    virtual BOOL                operator==( const formula::FormulaToken& rToken ) const;
 };
 
 

sc/inc/tokenarray.hxx

 struct ScComplexRefData;
 class ScMatrix;
 
-class ScTokenArray : public formula::FormulaTokenArray
-{
-    bool    mbODFF;     /// TRUE: ODFF, FALSE: PODF
-public:
-        explicit    ScMissingConvention( bool bODFF ) : mbODFF(bODFF) {}
-    // Implementation and usage only in token.cxx
-    inline  bool    isRewriteNeeded( OpCode eOp ) const;
-    inline  bool    isODFF() const { return mbODFF; }
-};
-
-class SC_DLLPUBLIC ScTokenArray
+class SC_DLLPUBLIC ScTokenArray : public formula::FormulaTokenArray
 {
     friend class ScCompiler;
     BOOL                    ImplGetReference( ScRange& rRange, BOOL bValidOnly ) const;
                                 const ScAddress& rPos, ScDirection );
 
     formula::FormulaToken* AddRawToken( const ScRawToken& );
-    virtual bool AddFormulaToken(const com::sun::star::sheet::FormulaToken& _aToken);
+    virtual bool AddFormulaToken(const com::sun::star::sheet::FormulaToken& _aToken,formula::ExternalReferenceHelper* _pRef);
     virtual formula::FormulaToken* AddOpCode( OpCode eCode );
     /** ScSingleRefToken with ocPush. */
     formula::FormulaToken* AddSingleReference( const ScSingleRefData& rRef );

sc/inc/tokenuno.hxx

 {
 public:
     static bool ConvertToTokenArray(
+                        ScDocument& rDoc,
                         ScTokenArray& rTokenArray,
                         const com::sun::star::uno::Sequence< com::sun::star::sheet::FormulaToken >& rSequence );
     static bool ConvertToTokenSequence(
+                        ScDocument& rDoc,
                         com::sun::star::uno::Sequence< com::sun::star::sheet::FormulaToken >& rSequence,
                         const ScTokenArray& rTokenArray );
 };
 {
 private:
     ::com::sun::star::uno::Sequence< const ::com::sun::star::sheet::FormulaOpCodeMapEntry > maOpCodeMapping;
+    ::com::sun::star::uno::Sequence< const ::com::sun::star::sheet::ExternalLinkInfo > maExternalLinks;
     ScCompiler::OpCodeMapPtr    mxOpCodeMap;
     ScDocShell*         mpDocShell;
     ScAddress           maRefPos;

sc/inc/unonames.hxx

 #define SC_UNO_IGNORELEADING        "IgnoreLeadingSpaces"
 #define SC_UNO_OPCODEMAP            "OpCodeMap"
 #define SC_UNO_EXTERNALLINKS        "ExternalLinks"
+#define SC_UNO_COMPILEFAP           "CompileFAP"
 
 // Chart2
 #define SC_UNONAME_ISHIDDEN         "IsHidden"

sc/source/core/data/cell2.cxx

     }
 
     pCode->Reset();
-    for ( ScToken* t = pCode->GetNextReferenceOrName(); t; t = pCode->GetNextReferenceOrName() )
+    for ( formula::FormulaToken* t = pCode->GetNextReferenceOrName(); t; t = pCode->GetNextReferenceOrName() )
     {
         StackVar sv = t->GetType();
         if (sv == svExternalSingleRef || sv == svExternalDoubleRef || sv == svExternalName)

sc/source/core/tool/address.cxx

         }
 
     case formula::FormulaGrammar::CONV_XL_A1:
-    case ScAddress::CONV_XL_OOX:
+    case formula::FormulaGrammar::CONV_XL_OOX:
         {
             ScRange r = rAddr;
             USHORT nFlags = lcl_ScRange_Parse_XL_A1( r, p, pDoc, true, pExtInfo,
-                    (rDetails.eConv == ScAddress::CONV_XL_OOX ? pExternalLinks : NULL) );
+                    (rDetails.eConv == formula::FormulaGrammar::CONV_XL_OOX ? pExternalLinks : NULL) );
             rAddr = r.aStart;
             return nFlags;
         }
         return lcl_ScRange_Parse_OOo( *this, r, pDoc, pExtInfo );
 
     case formula::FormulaGrammar::CONV_XL_A1:
-    case ScAddress::CONV_XL_OOX:
+    case formula::FormulaGrammar::CONV_XL_OOX:
         return lcl_ScRange_Parse_XL_A1( *this, r.GetBuffer(), pDoc, false, pExtInfo,
-                (rDetails.eConv == ScAddress::CONV_XL_OOX ? pExternalLinks : NULL) );
+                (rDetails.eConv == formula::FormulaGrammar::CONV_XL_OOX ? pExternalLinks : NULL) );
 
     case formula::FormulaGrammar::CONV_XL_R1C1:
         return lcl_ScRange_Parse_XL_R1C1( *this, r.GetBuffer(), pDoc, rDetails, false, pExtInfo );
     default :
     case formula::FormulaGrammar::CONV_OOO: // No full col refs in OOO yet, assume XL notation
     case formula::FormulaGrammar::CONV_XL_A1:
-    case ScAddress::CONV_XL_OOX:
+    case formula::FormulaGrammar::CONV_XL_OOX:
         if (NULL != (p = lcl_a1_get_col( p, &aStart, &ignored ) ) )
         {
             if( p[0] == ':')
     default :
     case formula::FormulaGrammar::CONV_OOO: // No full row refs in OOO yet, assume XL notation
     case formula::FormulaGrammar::CONV_XL_A1:
-    case ScAddress::CONV_XL_OOX:
+    case formula::FormulaGrammar::CONV_XL_OOX:
         if (NULL != (p = lcl_a1_get_row( p, &aStart, &ignored ) ) )
         {
             if( p[0] == ':')
 
             case formula::FormulaGrammar::CONV_XL_A1:
             case formula::FormulaGrammar::CONV_XL_R1C1:
-            case CONV_XL_OOX:
+            case formula::FormulaGrammar::CONV_XL_OOX:
                 if (aDocName.Len() > 0)
                 {
                     r += '[';
     default :
     case formula::FormulaGrammar::CONV_OOO:
     case formula::FormulaGrammar::CONV_XL_A1:
-    case CONV_XL_OOX:
+    case formula::FormulaGrammar::CONV_XL_OOX:
         if( nFlags & SCA_VALID_COL )
             lcl_a1_append_c ( r, nCol, nFlags & SCA_COL_ABSOLUTE );
         if( nFlags & SCA_VALID_ROW )
     break;
 
     case formula::FormulaGrammar::CONV_XL_A1:
-    case ScAddress::CONV_XL_OOX:
+    case formula::FormulaGrammar::CONV_XL_OOX:
         lcl_ScRange_Format_XL_Header( r, *this, nFlags, pDoc, rDetails );
         if( aStart.Col() == 0 && aEnd.Col() >= MAXCOL )
         {
     default :
     case formula::FormulaGrammar::CONV_OOO:
     case formula::FormulaGrammar::CONV_XL_A1:
-    case ScAddress::CONV_XL_OOX:
+    case formula::FormulaGrammar::CONV_XL_OOX:
     if (bAbsolute)
         aString.Append( '$' );
 

sc/source/core/tool/compiler.cxx

 
 
 void ScCompiler::SetGrammarAndRefConvention(
-        const ScGrammar::Grammar eNewGrammar, const ScGrammar::Grammar eOldGrammar )
+        const FormulaGrammar::Grammar eNewGrammar, const FormulaGrammar::Grammar eOldGrammar )
 {
     meGrammar = eNewGrammar;    //! SetRefConvention needs the new grammar set!
     FormulaGrammar::AddressConvention eConv = FormulaGrammar::extractRefConvention( meGrammar);
 /* " */     t[34] = SC_COMPILER_C_CHAR_STRING | SC_COMPILER_C_STRING_SEP;
 /* # */     t[35] = SC_COMPILER_C_WORD_SEP;
 /* $ */     t[36] = SC_COMPILER_C_CHAR_WORD | SC_COMPILER_C_WORD | SC_COMPILER_C_CHAR_IDENT | SC_COMPILER_C_IDENT;
-    if (ScAddress::CONV_ODF == meConv)
+    if (FormulaGrammar::CONV_ODF == meConv)
 /* $ */     t[36] |= SC_COMPILER_C_ODF_NAME_MARKER;
 /* % */     t[37] = SC_COMPILER_C_VALUE;
 /* & */     t[38] = SC_COMPILER_C_CHAR | SC_COMPILER_C_WORD_SEP | SC_COMPILER_C_VALUE_SEP;
 /* [ */     t[91] |= SC_COMPILER_C_IDENT;
 /* ] */     t[93] |= SC_COMPILER_C_IDENT;
         }
-        if( ScAddress::CONV_XL_OOX == meConv )
+        if( FormulaGrammar::CONV_XL_OOX == meConv )
         {
 /* [ */     t[91] |= SC_COMPILER_C_CHAR_IDENT;
 /* ] */     t[93] |= SC_COMPILER_C_IDENT;
 struct ConventionXL_A1 : public Convention_A1, public ConventionXL
 {
     ConventionXL_A1() : Convention_A1( FormulaGrammar::CONV_XL_A1 ) { }
-    ConventionXL_A1( ScAddress::Convention eConv ) : Convention_A1( eConv ) { }
+    ConventionXL_A1( FormulaGrammar::AddressConvention eConv ) : Convention_A1( eConv ) { }
 
     void makeSingleCellStr( ::rtl::OUStringBuffer& rBuf, const ScSingleRefData& rRef ) const
     {
 
 struct ConventionXL_OOX : public ConventionXL_A1
 {
-    ConventionXL_OOX() : ConventionXL_A1( ScAddress::CONV_XL_OOX ) { }
+    ConventionXL_OOX() : ConventionXL_A1( FormulaGrammar::CONV_XL_OOX ) { }
 };
 
 static const ConventionXL_OOX ConvXL_OOX;
         case FormulaGrammar::CONV_OOO :
         case FormulaGrammar::CONV_XL_A1 :
         case FormulaGrammar::CONV_XL_R1C1 :
-        case ScAddress::CONV_XL_OOX :
+        case FormulaGrammar::CONV_XL_OOX :
             if( bNeedsQuote )
             {
                 static const String one_quote = static_cast<sal_Unicode>( '\'' );
         case FormulaGrammar::CONV_ODF :      SetRefConvention( pConvOOO_A1_ODF ); break;
         case FormulaGrammar::CONV_XL_A1 :    SetRefConvention( pConvXL_A1 );  break;
         case FormulaGrammar::CONV_XL_R1C1 :  SetRefConvention( pConvXL_R1C1 ); break;
-        case ScAddress::CONV_XL_OOX :   SetRefConvention( pConvXL_OOX ); break;
+        case FormulaGrammar::CONV_XL_OOX :   SetRefConvention( pConvXL_OOX ); break;
     }
 }
 
             BOOL bAddPair = !(bBorder1 && bBorder2);
             if ( bAddPair )
             {
-                pNew = new ScTokenArray;
+                pNew = new ScTokenArray();
                 pNew->AddOpCode( ocClose );
                 PushTokenArray( pNew, TRUE );
                 pNew->Reset();
             pNew->Reset();
             if ( bAddPair )
             {
-                pNew = new ScTokenArray;
+                pNew = new ScTokenArray();
                 pNew->AddOpCode( ocOpen );
                 PushTokenArray( pNew, TRUE );
                 pNew->Reset();
     {
         case svExternalSingleRef:
         case svExternalDoubleRef:
-            pArr->nRefs++;
+            pArr->IncrementRefs();
         break;
         case svExternalName:
         {
             return GetToken();
         }
 		default:
-			DBG_ERRROR("Wrong type for external reference!");
+			DBG_ERROR("Wrong type for external reference!");
 			return FALSE;
     }
     return TRUE;
 void ScCompiler::CreateStringFromExternal(rtl::OUStringBuffer& rBuffer, FormulaToken* pTokenP)
 {
     FormulaToken* t = pTokenP;
-    OpCode eOp = t->GetOpCode();
     ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager();
     switch (t->GetType())
     {
         break;
         case svExternalSingleRef:
             pConv->makeExternalRefStr(
-                   rBuffer, *this, t->GetIndex(), t->GetString(), t->GetSingleRef(), pRefMgr);
+                   rBuffer, *this, t->GetIndex(), t->GetString(), static_cast<ScToken*>(t)->GetSingleRef(), pRefMgr);
         break;
         case svExternalDoubleRef:
             pConv->makeExternalRefStr(
-                        rBuffer, *this, t->GetIndex(), t->GetString(), t->GetDoubleRef(), pRefMgr);
+                        rBuffer, *this, t->GetIndex(), t->GetString(), static_cast<ScToken*>(t)->GetDoubleRef(), pRefMgr);
    		break;
         default:
             // warning, not error, otherwise we may end up with a never
     rtl::OUStringBuffer aBuffer;
     switch ( eOp )
     {
-        case ocName:
-        {
-            String aStr( rStr );
-            aStr.SearchAndReplaceAll( '"', String( RTL_CONSTASCII_USTRINGPARAM( "\"\"")));
-        }
-        break;
         case ocDBArea:
         {
             ScDBData* pDBData = pDoc->GetDBCollection()->FindIndex(_pTokenP->GetIndex());
             SetError(errNoRef);
         else if ( !bCompileForFAP )
         {
-            ScTokenArray* pNew = new ScTokenArray;
+            ScTokenArray* pNew = new ScTokenArray();
             if ( bSingle )
             {
                 ScSingleRefData aRefData;
             }
             else
             {
-                ScScComplexRefData aRefData;
+                ScComplexRefData aRefData;
                 aRefData.InitRange( aRange );
                 if ( bColName )
                 {
                             (SCROW&) aRefData.Ref2.nRow);
         aRefData.Ref2.nTab    = aRefData.Ref1.nTab;
         aRefData.CalcRelFromAbs( aPos );
-        ScTokenArray* pNew = new ScTokenArray;
+        ScTokenArray* pNew = new ScTokenArray();
         pNew->AddDoubleReference( aRefData );
         PushTokenArray( pNew, TRUE );
         pNew->Reset();

sc/source/core/tool/interpr4.cxx

 void ScInterpreter::ScColRowNameAuto()
 {
     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "Eike.Rathke@sun.com", "ScInterpreter::ScColRowNameAuto" );
-    ScComplexRefData aRefData( pCur->GetDoubleRef() );
+    ScComplexRefData aRefData( static_cast<const ScToken*>(pCur)->GetDoubleRef() );
     aRefData.CalcAbsIfRel( aPos );
     if ( aRefData.Valid() )
     {
     {
         case svExternalSingleRef:
         {
-            ScSingleRefData aData(pCur->GetSingleRef());
+            ScSingleRefData aData(static_cast<const ScToken*>(pCur)->GetSingleRef());
             if (aData.IsTabRel())
             {
                 DBG_ERROR("ScCompiler::GetToken: external single reference must have an absolute table reference!");
         //break;    // unreachable, prevent compiler warning
         case svExternalDoubleRef:
         {
-            ScComplexRefData aData(pCur->GetDoubleRef());
+            ScComplexRefData aData(static_cast<const ScToken*>(pCur)->GetDoubleRef());
             if (aData.Ref1.IsTabRel() || aData.Ref2.IsTabRel())
             {
                 DBG_ERROR("ScCompiler::GetToken: external double reference must have an absolute table reference!");
             if (!xNew)
                 break;
 
-            ScToken* p = xNew->First();
+            ScToken* p = static_cast<ScToken*>(xNew->First());
             if (p->GetType() != svMatrix)
                 break;
 

sc/source/core/tool/rangenam.cxx

         // Copy ctor default-constructs pCode if it was NULL, so it's initialized here, too,
         // to ensure same behavior if unnecessary copying is left out.
 
-        pCode = new ScTokenArray;
+        pCode = new ScTokenArray();
     }
 }
 
 						  const ScAddress& rTarget ) :
 				aName		( rName ),
                 aUpperName  ( ScGlobal::pCharClass->upper( rName ) ),
-				pCode		( new ScTokenArray ),
+				pCode		( new ScTokenArray() ),
 				aPos		( rTarget ),
 				eType		( RT_NAME ),
 				pDoc		( pDok ),
     ScDataObject(),
 	aName 	(rScRangeData.aName),
     aUpperName  (rScRangeData.aUpperName),
-	pCode		(rScRangeData.pCode ? rScRangeData.pCode->Clone() : new ScTokenArray),		// echte Kopie erzeugen (nicht copy-ctor)
+	pCode		(rScRangeData.pCode ? rScRangeData.pCode->Clone() : new ScTokenArray()),		// echte Kopie erzeugen (nicht copy-ctor)
 	aPos		(rScRangeData.aPos),
 	eType		(rScRangeData.eType),
 	pDoc		(rScRangeData.pDoc),

sc/source/core/tool/token.cxx

 #include "parclass.hxx"
 #include "jumpmatrix.hxx"
 #include "rangeseq.hxx"
+#include "externalrefmgr.hxx"
+#include "document.hxx"
 
 using ::std::vector;
 
 #include <com/sun/star/sheet/ComplexReference.hpp>
+#include <com/sun/star/sheet/ExternalReference.hpp>
 #include <com/sun/star/sheet/ReferenceFlags.hpp>
 
 using namespace formula;
         rRef.SetFlag3D(     ( rAPI.Flags & sheet::ReferenceFlags::SHEET_3D        ) != 0 );
         rRef.SetRelName(    ( rAPI.Flags & sheet::ReferenceFlags::RELATIVE_NAME   ) != 0 );
     }
+    
+    void lcl_ExternalRefToCalc( ScSingleRefData& rRef, const sheet::SingleReference& rAPI )
+    {
+        rRef.InitFlags();
+
+        rRef.nCol    = static_cast<SCsCOL>(rAPI.Column);
+        rRef.nRow    = static_cast<SCsROW>(rAPI.Row);
+        rRef.nTab    = 0;
+        rRef.nRelCol = static_cast<SCsCOL>(rAPI.RelativeColumn);
+        rRef.nRelRow = static_cast<SCsROW>(rAPI.RelativeRow);
+        rRef.nRelTab = 0;
+
+        rRef.SetColRel(     ( rAPI.Flags & sheet::ReferenceFlags::COLUMN_RELATIVE ) != 0 );
+        rRef.SetRowRel(     ( rAPI.Flags & sheet::ReferenceFlags::ROW_RELATIVE    ) != 0 );
+        rRef.SetTabRel(     false );    // sheet index must be absolute for external refs
+        rRef.SetColDeleted( ( rAPI.Flags & sheet::ReferenceFlags::COLUMN_DELETED  ) != 0 );
+        rRef.SetRowDeleted( ( rAPI.Flags & sheet::ReferenceFlags::ROW_DELETED     ) != 0 );
+        rRef.SetTabDeleted( false );    // sheet must not be deleted for external refs
+        rRef.SetFlag3D(     ( rAPI.Flags & sheet::ReferenceFlags::SHEET_3D        ) != 0 );
+        rRef.SetRelName(    false );
+    }
 //
 } // namespace
 // 
     return maSingleRef;
 }
 
-BOOL ScExternalSingleRefToken::operator ==( const ScToken& r ) const
+BOOL ScExternalSingleRefToken::operator ==( const FormulaToken& r ) const
 {
-    if (!ScToken::operator==(r))
+    if (!FormulaToken::operator==(r))
         return false;
 
     if (mnFileId != r.GetIndex())
     if (maTabName != r.GetString())
         return false;
 
-    return maSingleRef == r.GetSingleRef();
+    return maSingleRef == static_cast<const ScToken&>(r).GetSingleRef();
 }
 
 // ============================================================================
     return maDoubleRef;
 }
 
-BOOL ScExternalDoubleRefToken::operator ==( const ScToken& r ) const
+BOOL ScExternalDoubleRefToken::operator ==( const FormulaToken& r ) const
 {
     if (!ScToken::operator==(r))
         return false;
     if (maTabName != r.GetString())
         return false;
 
-    return maDoubleRef == r.GetDoubleRef();
+    return maDoubleRef == static_cast<const ScToken&>(r).GetDoubleRef();
 }
 
 // ============================================================================
     return maName;
 }
 
-BOOL ScExternalNameToken::operator==( const ScToken& r ) const
+BOOL ScExternalNameToken::operator==( const FormulaToken& r ) const
 {
-    if ( !ScToken::operator==(r) )
+    if ( !FormulaToken::operator==(r) )
         return false;
 
     if (mnFileId != r.GetIndex())
 
 //////////////////////////////////////////////////////////////////////////
 
-bool ScTokenArray::AddFormulaToken(const com::sun::star::sheet::FormulaToken& _aToken)
+bool ScTokenArray::AddFormulaToken(const com::sun::star::sheet::FormulaToken& _aToken,formula::ExternalReferenceHelper* _pRef)
 {
-    bool bError = FormulaTokenArray::AddFormulaToken(_aToken);
+    bool bError = FormulaTokenArray::AddFormulaToken(_aToken,_pRef);
     if ( bError )
     {
         bError = false;
                     else if ( aType.equals( cppu::UnoType<sheet::ExternalReference>::get() ) )
                     {
                         sheet::ExternalReference aApiExtRef;
-                        if( (eOpCode == ocPush) && (rAPI.Data >>= aApiExtRef) && (0 <= aApiExtRef.Index) && (aApiExtRef.Index <= SAL_MAX_UINT16) )
+                        if( (eOpCode == ocPush) && (_aToken.Data >>= aApiExtRef) && (0 <= aApiExtRef.Index) && (aApiExtRef.Index <= SAL_MAX_UINT16) )
                         {
                             sal_uInt16 nFileId = static_cast< sal_uInt16 >( aApiExtRef.Index );
                             sheet::SingleReference aApiSRef;
                             {
                                 // try to resolve cache index to sheet name
                                 size_t nCacheId = static_cast< size_t >( aApiSRef.Sheet );
-                                String aTabName = rDoc.GetExternalRefManager()->getCacheTableName( nFileId, nCacheId );
+                                String aTabName = _pRef->getCacheTableName( nFileId, nCacheId );
                                 if( aTabName.Len() > 0 )
                                 {
                                     ScSingleRefData aSingleRef;
                             {
                                 // try to resolve cache index to sheet name.
                                 size_t nCacheId = static_cast< size_t >( aApiCRef.Reference1.Sheet );
-                                String aTabName = rDoc.GetExternalRefManager()->getCacheTableName( nFileId, nCacheId );
+                                String aTabName = _pRef->getCacheTableName( nFileId, nCacheId );
                                 if( aTabName.Len() > 0 )
                                 {
                                     ScComplexRefData aComplRef;
 
 ////////////////////////////////////////////////////////////////////////////
 
-ScTokenArray::ScTokenArray()
+ScTokenArray::ScTokenArray() 
 {
 }
 
 
 ScTokenArray* ScTokenArray::Clone() const
 {
-    ScTokenArray* p = new ScTokenArray;
+    ScTokenArray* p = new ScTokenArray();
     p->nLen = nLen;
     p->nRPN = nRPN;
     p->nRefs = nRefs;
     return Add( new ScSingleRefToken( rRef, ocMatRef ) );
 }
 
-FormulaToken* ScTokenArray::AddDoubleReference( const ScScComplexRefData& rRef )
+FormulaToken* ScTokenArray::AddDoubleReference( const ScComplexRefData& rRef )
 {
     return Add( new ScDoubleRefToken( rRef ) );
 }
                         break;
                         case svDoubleRef :
                         {
-                            ScScComplexRefData& rRef = static_cast<ScToken*>(p)->GetDoubleRef();
+                            ScComplexRefData& rRef = static_cast<ScToken*>(p)->GetDoubleRef();
                             rRef.CalcAbsIfRel( rPos );
                             switch ( eDir )
                             {
                 ScSingleRefData& rRef1 = static_cast<ScToken*>(pCode[j])->GetSingleRef();
                     rRef1.CalcAbsIfRel( rOldPos );
                     rRef1.CalcRelFromAbs( rNewPos );
-                }
             }
             break;
             default:

sc/source/filter/excel/makefile.mk

 		$(SLO)$/xepage.obj					\
 		$(SLO)$/xepivot.obj					\
 		$(SLO)$/xechart.obj					\
+		$(SLO)$/xestream.obj				\
 		$(SLO)$/xestring.obj				\
 		$(SLO)$/xestyle.obj					\
 		$(SLO)$/xetable.obj					\

sc/source/filter/excel/xecontent.cxx

 #include <sfx2/objsh.hxx>
 #include <tools/urlobj.hxx>
 #include <svtools/itemset.hxx>
+#include <formula/grammar.hxx>
 #include "scitems.hxx"
 #include <svx/eeitem.hxx>
 #include <svx/flditem.hxx>
         for( USHORT nIndex = 0, nCount = rCondFormat.Count(); nIndex < nCount; ++nIndex )
             if( const ScCondFormatEntry* pEntry = rCondFormat.GetEntry( nIndex ) )
                 maCFList.AppendNewRecord( new XclExpCF( GetRoot(), *pEntry ) );
-        aScRanges.Format( msSeqRef, SCA_VALID, NULL, ScAddress::CONV_XL_A1 );
+        aScRanges.Format( msSeqRef, SCA_VALID, NULL, formula::FormulaGrammar::CONV_XL_A1 );
     }
 }
 

sc/source/filter/excel/xeformula.cxx

                 AppendErrorToken(EXC_ERR_REF, rTokData.mnSpaces);
                 break;
             }
-            ScSingleRefData aRef(rTokData.mpScToken->GetSingleRef());
+            ScSingleRefData aRef(static_cast<const ScToken*>(rTokData.mpScToken)->GetSingleRef());
             aRef.CalcAbsIfRel(*mpScBasePos);
             const String& rTabName = rTokData.mpScToken->GetString();
             ScExternalRefCache::TokenRef p = pRefMgr->getSingleRefToken(nFileId, rTabName, ScAddress(aRef.nCol, aRef.nRow, aRef.nTab), NULL, NULL);
                 AppendErrorToken(XclTools::GetXclErrorCode(errNoRef), rTokData.mnSpaces);
                 break;
             }
-            ScComplexRefData aRef(rTokData.mpScToken->GetDoubleRef());
+            ScComplexRefData aRef(static_cast<const ScToken*>(rTokData.mpScToken)->GetDoubleRef());
             aRef.CalcAbsIfRel(*mpScBasePos);
             const String& rTabName = rTokData.mpScToken->GetString();
             const ScSingleRefData& r1 = aRef.Ref1;
 
             // Go through all these tokens to store the external cell/range 
             // references for CRN records.
-            for (ScToken* p = pArray->First(); p; p = pArray->Next())
+            for (formula::FormulaToken* p = pArray->First(); p; p = pArray->Next())
             {
                 if (p->GetOpCode() == ocExternalRef)
                 {
                     if (p->GetType() == svExternalSingleRef)
                     {
-                        ScSingleRefData aData(p->GetSingleRef());
+                        ScSingleRefData aData(static_cast<ScToken*>(p)->GetSingleRef());
                         aData.CalcAbsIfRel(*mpScBasePos);
                         mpLinkMgr->StoreCell(nFileId, p->GetString(), aData);
                     }
                     else if (p->GetType() == svExternalDoubleRef)
                     {
-                        ScComplexRefData aData(p->GetDoubleRef());
+                        ScComplexRefData aData(static_cast<ScToken*>(p)->GetDoubleRef());
                         aData.CalcAbsIfRel(*mpScBasePos);
                         mpLinkMgr->StoreCellRange(nFileId, p->GetString(), aData);
                     }

sc/source/filter/excel/xelink.cxx

 using ::std::auto_ptr;
 using ::std::find_if;
 using ::std::vector;
+using namespace formula;
 
 // ============================================================================
 // *** Helper classes ***
     /** Stores all cells in the given range in the CRN list. */
     void                StoreCellRange( const XclExpRoot& rRoot, const ScRange& rRange );
 
-    void                StoreCell( const XclExpRoot& rRoot, const ScAddress& rCell, const ScToken& rToken );
-    void                StoreCellRange( const XclExpRoot& rRoot, const ScRange& rRange, const ScToken& rToken );
+    void                StoreCell( const XclExpRoot& rRoot, const ScAddress& rCell, const formula::FormulaToken& rToken );
+    void                StoreCellRange( const XclExpRoot& rRoot, const ScRange& rRange, const formula::FormulaToken& rToken );
 
     /** Writes the XCT and all CRN records. */
     virtual void        Save( XclExpStream& rStrm );
     /** Stores all cells in the given range in the CRN list of the specified SUPBOOK sheet. */
     void                StoreCellRange( const ScRange& rRange, sal_uInt16 nSBTab );
 
-    void                StoreCell( sal_uInt16 nSBTab, const ScAddress& rCell, const ScToken& rToken );
-    void                StoreCellRange( sal_uInt16 nSBTab, const ScRange& rRange, const ScToken& rToken );
+    void                StoreCell( sal_uInt16 nSBTab, const ScAddress& rCell, const formula::FormulaToken& rToken );
+    void                StoreCellRange( sal_uInt16 nSBTab, const ScRange& rRange, const formula::FormulaToken& rToken );
 
     sal_uInt16          GetTabIndex( const String& rTabName ) const;
     sal_uInt16          GetTabCount() const;
         if (mpArray->GetLen() != 1)
             break;
 
-        const ScToken* p = mpArray->First();
+        const ScToken* p = static_cast<const ScToken*>(mpArray->First());
         if (p->GetOpCode() != ocExternalRef)
             break;
 
     maUsedCells.SetMultiMarkArea( rRange );
 }
 
-void XclExpXct::StoreCell( const XclExpRoot& /*rRoot*/, const ScAddress& rCell, const ScToken& rToken )
+void XclExpXct::StoreCell( const XclExpRoot& /*rRoot*/, const ScAddress& rCell, const formula::FormulaToken& rToken )
 {
     switch (rToken.GetType())
     {
     }
 }
 
-void XclExpXct::StoreCellRange( const XclExpRoot& /*rRoot*/, const ScRange& rRange, const ScToken& rToken )
+void XclExpXct::StoreCellRange( const XclExpRoot& /*rRoot*/, const ScRange& rRange, const formula::FormulaToken& rToken )
 {
     if (rToken.GetType() != svMatrix)
         return;
         // multi-table range is not supported here.
         return;
 
-    const ScMatrix* pMtx = rToken.GetMatrix();
+    const ScMatrix* pMtx = static_cast<const ScToken*>(&rToken)->GetMatrix();
     if (!pMtx)
         return;
 
         xXct->StoreCellRange( GetRoot(), rRange );
 }
 
-void XclExpSupbook::StoreCell( sal_uInt16 nSBTab, const ScAddress& rCell, const ScToken& rToken )
+void XclExpSupbook::StoreCell( sal_uInt16 nSBTab, const ScAddress& rCell, const formula::FormulaToken& rToken )
 {
     XclExpXctRef xXct = maXctList.GetRecord(nSBTab);
     if (!xXct.is())
     xXct->StoreCell(GetRoot(), rCell, rToken);
 }
 
-void XclExpSupbook::StoreCellRange( sal_uInt16 nSBTab, const ScRange& rRange, const ScToken& rToken )
+void XclExpSupbook::StoreCellRange( sal_uInt16 nSBTab, const ScRange& rRange, const formula::FormulaToken& rToken )
 {
     if (rRange.aStart.Tab() != rRange.aEnd.Tab())
         // multi-table range is not allowed!
     SCTAB nTabCount = rRange.aEnd.Tab() - rRange.aStart.Tab() + 1;
 
     // If this is a multi-table range, get token for each table.
-    vector<ScToken*> aMatrixList;
+    vector<FormulaToken*> aMatrixList;
     aMatrixList.reserve(nTabCount);
 
     // This is a new'ed instance, so we must manage its life cycle here.
     if (!pArray.get())
         return;
 
-    for (ScToken* p = pArray->First(); p; p = pArray->Next())
+    for (FormulaToken* p = pArray->First(); p; p = pArray->Next())
     {
         if (p->GetType() == svMatrix)
             aMatrixList.push_back(p);

sc/source/filter/excel/xename.cxx

 #include "excrecds.hxx"
 
 #include <oox/core/tokens.hxx>
+#include <formula/grammar.hxx>
 
 using ::rtl::OString;
 
         xName->SetTokenArray( xTokArr );
 
         String sSymbol;
-        rRangeData.GetSymbol( sSymbol, ScGrammar::GRAM_NATIVE_XL_A1 );
+        rRangeData.GetSymbol( sSymbol, formula::FormulaGrammar::GRAM_NATIVE_XL_A1 );
         xName->SetSymbol( sSymbol );
 
         /*  Try to replace by existing built-in name - complete token array is

sc/source/filter/excel/xestream.cxx

 #include "compiler.hxx"
 
 #include <oox/core/tokens.hxx>
+#include <formula/grammar.hxx>
 
 using ::com::sun::star::beans::PropertyValue;
 using ::com::sun::star::io::XOutputStream;
 using ::rtl::OString;
 using ::rtl::OUString;
 using ::utl::OStreamWrapper;
-
+using namespace formula;
 // ============================================================================
 
 XclExpStream::XclExpStream( SvStream& rOutStrm, const XclExpRoot& rRoot, sal_uInt16 nMaxRecSize ) :
 rtl::OString XclXmlUtils::ToOString( const ScAddress& rAddress )
 {
     String sAddress;
-    rAddress.Format( sAddress, SCA_VALID, NULL, ScAddress::Details( ScAddress::CONV_XL_A1 ) );
+    rAddress.Format( sAddress, SCA_VALID, NULL, ScAddress::Details( FormulaGrammar::CONV_XL_A1 ) );
     return ToOString( sAddress );
 }
 
 rtl::OString XclXmlUtils::ToOString( const ScRange& rRange )
 {
     String sRange;
-    rRange.Format( sRange, SCA_VALID, NULL, ScAddress::Details( ScAddress::CONV_XL_A1 ) );
+    rRange.Format( sRange, SCA_VALID, NULL, ScAddress::Details( FormulaGrammar::CONV_XL_A1 ) );
     return ToOString( sRange );
 }
 
 rtl::OString XclXmlUtils::ToOString( const ScRangeList& rRangeList )
 {
     String s;
-    rRangeList.Format( s, SCA_VALID, NULL, ScAddress::CONV_XL_A1, ' ' );
+    rRangeList.Format( s, SCA_VALID, NULL, FormulaGrammar::CONV_XL_A1, ' ' );
     return ToOString( s );
 }
 
 
 rtl::OUString XclXmlUtils::ToOUString( ScDocument& rDocument, const ScAddress& rAddress, ScTokenArray* pTokenArray )
 {
-    ScCompiler aCompiler( &rDocument, rAddress, *pTokenArray, ScGrammar::GRAM_NATIVE_XL_A1 );
+    ScCompiler aCompiler( &rDocument, rAddress, *pTokenArray);
+    aCompiler.SetGrammar(FormulaGrammar::GRAM_NATIVE_XL_A1);
     String s;
     aCompiler.CreateStringFromTokenArray( s );
     return ToOUString( s );

sc/source/filter/excel/xetable.cxx

     }
 }
 
-XclExpDimensions* XclExpRowBuffer::GetDimensions()
+XclExpDimensions* XclExpRowBuffer::GetDimensions() 
 {
     return &maDimensions;
 }
     mxDefrowheight->SetDefaultData( aDefRowData );
 }
 
-XclExpRecordRef XclExpCellTable::CreateRecord( sal_uInt16 nRecId ) const
+XclExpRecordRef XclExpCellTable::CreateRecord( sal_uInt16 nRecId ) const 
 {
     XclExpRecordRef xRec;
     switch( nRecId )
     {
-        case EXC_ID3_DIMENSIONS:    xRec.reset( new XclExpDelegatingRecord( maRowBfr.GetDimensions() ) );   break;
+        case EXC_ID3_DIMENSIONS:    xRec.reset( new XclExpDelegatingRecord( const_cast<XclExpRowBuffer*>(&maRowBfr)->GetDimensions() ) );   break;
         case EXC_ID2_DEFROWHEIGHT:  xRec = mxDefrowheight;  break;
         case EXC_ID_GUTS:           xRec = mxGuts;          break;
         case EXC_ID_NOTE:           xRec = mxNoteList;      break;

sc/source/filter/excel/xeview.cxx

 {
     switch( nActivePane )
     {
-        case EXC_PANE_TOPLEFT:      return "topLeft";       break;
-        case EXC_PANE_TOPRIGHT:     return "topRight";      break;
-        case EXC_PANE_BOTTOMLEFT:   return "bottomLeft";    break;
-        case EXC_PANE_BOTTOMRIGHT:  return "bottomRight";   break;
+        case EXC_PANE_TOPLEFT:      return "topLeft";       //break;
+        case EXC_PANE_TOPRIGHT:     return "topRight";      //break;
+        case EXC_PANE_BOTTOMLEFT:   return "bottomLeft";    //break;
+        case EXC_PANE_BOTTOMRIGHT:  return "bottomRight";   //break;
     }
     return "**error: lcl_GetActivePane";
 }

sc/source/filter/excel/xilink.cxx

             case EXC_CACHEDVAL_DOUBLE:
             {
                 double f = p->GetValue();
-                ScExternalRefCache::TokenRef pToken(new ScDoubleToken(f));
+                ScExternalRefCache::TokenRef pToken(new formula::FormulaDoubleToken(f));
                 pCacheTable->setCell(rAddr.mnCol, rAddr.mnRow, pToken);
             }
             break;
             case EXC_CACHEDVAL_STRING:
             {
                 const String& rStr = p->GetString();
-                ScExternalRefCache::TokenRef pToken(new ScStringToken(rStr));
+                ScExternalRefCache::TokenRef pToken(new formula::FormulaStringToken(rStr));
                 pCacheTable->setCell(rAddr.mnCol, rAddr.mnRow, pToken);
             }
             break;

sc/source/filter/excel/xlformula.cxx

 
 // MARKER(update_precomp.py): autogen include statement, do not remove
 #include "precompiled_sc.hxx"
+#include "xestream.hxx"
 #include "xlformula.hxx"
 #include "compiler.hxx"
 #include "rangenam.hxx"
 #include "xlroot.hxx"
 #include "xistream.hxx"
-#include "xestream.hxx"
 #include "token.hxx"
 #include "tokenarray.hxx"
 

sc/source/filter/inc/xetable.hxx

         @param nRecId  The record identifier that specifies which record is
             returned. Possible values are: EXC_ID_DEFROWHEIGHT, EXC_ID_NOTE,
             EXC_ID_MERGEDCELLS, EXC_ID_HLINK, EXC_ID_DVAL. */
-    XclExpRecordRef     CreateRecord( sal_uInt16 nRecId );
+    XclExpRecordRef     CreateRecord( sal_uInt16 nRecId ) const;
     /** Saves the entire cell table. */
     virtual void        Save( XclExpStream& rStrm );
     virtual void        SaveXml( XclExpXmlStream& rStrm );

sc/source/filter/xml/XMLTrackedChangesContext.cxx

 #include <com/sun/star/text/XTextCursor.hpp>
 #include <com/sun/star/text/ControlCharacter.hpp>
 
+using rtl::OUString;
 using namespace com::sun::star;
 using namespace xmloff::token;
 

sc/source/filter/xml/xmlbodyi.cxx

-<<<<<<< .working
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #include <sal/types.h>
 #include <tools/debug.hxx>
 
+using rtl::OUString;
 using namespace com::sun::star;
 using namespace xmloff::token;
 

sc/source/filter/xml/xmlexprt.cxx

 #define SC_SHOW_CHANGES_BY_RANGES_LIST				12
 
 using namespace rtl;
+using namespace formula;
 using namespace com::sun::star;
 using namespace xmloff::token;
 using ::std::vector;

sc/source/filter/xml/xmlexternaltabi.cxx

 
         ScExternalRefCache::TokenRef aToken;
         if (mbIsNumeric)
-            aToken.reset(new ScDoubleToken(mfCellValue));
+            aToken.reset(new formula::FormulaDoubleToken(mfCellValue));
         else
-            aToken.reset(new ScStringToken(maCellString));
+            aToken.reset(new formula::FormulaStringToken(maCellString));
 
         sal_uInt32 nNumFmt = mnNumberFormat >= 0 ? static_cast<sal_uInt32>(mnNumberFormat) : 0;
         mrExternalRefInfo.mpCacheTable->setCell(

sc/source/filter/xml/xmlstyli.hxx

   	void AddProperty(sal_Int16 nContextID, const com::sun::star::uno::Any& aValue);
     XMLPropertyState* FindProperty(const sal_Int16 nContextID);
 
-	sal_Int32 GetNumberFormat() { return nNumberFormat; }
+	sal_Int32 GetNumberFormat();// { return nNumberFormat; }
 
 private:
     using XMLPropStyleContext::SetStyle;

sc/source/ui/app/inputhdl.cxx

 #include <vcl/help.hxx>
 #include <vcl/cursor.hxx>
 #include <tools/urlobj.hxx>
+#include <formula/formulahelper.hxx>
 
 #include "inputwin.hxx"
 #include "tabvwsh.hxx"
 //	max. Ranges im RangeFinder
 #define RANGEFIND_MAX	32
 
+using namespace formula;
+
 // STATIC DATA -----------------------------------------------------------
 
 BOOL ScInputHandler::bOptLoaded = FALSE;			// App-Optionen ausgewertet
             const ScFuncDesc* pDesc = pFuncList->GetFunction( i );
             if ( pDesc->pFuncName )
             {
-                pDesc->InitArgumentInfo();
+                pDesc->initArgumentInfo();
                 String aEntry = pDesc->GetSignature();
                 TypedStrData* pData = new TypedStrData( aEntry, 0.0, SC_STRTYPE_FUNCTIONS );
                 if (!pFormulaDataPara->Insert(pData))
             xub_StrLen  nNextFStart = 0;
             xub_StrLen  nNextFEnd = 0;
             xub_StrLen  nArgPos = 0;
-            const ScFuncDesc* ppFDesc;
-            String**    pppArgs;
+            const IFunctionDescription* ppFDesc;
+            ::std::vector< ::rtl::OUString> aArgs;
             USHORT	    nArgs;
             BOOL  bFound = FALSE;
+            FormulaHelper aHelper(ScGlobal::GetStarCalcFunctionMgr());
 
             while( !bFound )
             {
                     sal_Unicode c = aSelText.GetChar( nLeftParentPos-1 );
                     if( !(c >= 'A' && c<= 'Z' || c>= 'a' && c<= 'z' ) )
                         continue;
-                    nNextFStart = ScFormulaUtil::GetFunctionStart( aSelText, nLeftParentPos, TRUE);
-                    if( ScFormulaUtil::GetNextFunc( aSelText, FALSE, nNextFStart, &nNextFEnd, &ppFDesc, &pppArgs ) )
+                    nNextFStart = aHelper.GetFunctionStart( aSelText, nLeftParentPos, TRUE);
+                    if( aHelper.GetNextFunc( aSelText, FALSE, nNextFStart, &nNextFEnd, &ppFDesc, &aArgs ) )
                     {
-                        if( ppFDesc->pFuncName )
+                        if( ppFDesc->getFunctionName().getLength() )
                         {
-                            nArgPos = ScFormulaUtil::GetArgStart( aSelText, nNextFStart, 0 );
-                            nArgs = ppFDesc->nArgCount;
+                            nArgPos = aHelper.GetArgStart( aSelText, nNextFStart, 0 );
+                            nArgs = ppFDesc->getParameterCount();
 
                             USHORT nActive = 0;
                             USHORT nCount = 0;
                             BOOL   bFlag = FALSE;
                             String aNew;
                             USHORT nParAutoPos = SCPOS_INVALID;
-                            if( pFormulaDataPara->FindText( *(ppFDesc->pFuncName), aNew, nParAutoPos, FALSE ) )
+                            if( pFormulaDataPara->FindText( ppFDesc->getFunctionName(), aNew, nParAutoPos, FALSE ) )
                             {
                                 for( USHORT i=0; i < nArgs; i++ )
                                 {
-                                    xub_StrLen nLength=(pppArgs[i])->Len();
+                                    xub_StrLen nLength=aArgs[i].getLength();
                                     if( nArgPos <= aSelText.Len()-1 )
                                     {
                                         nActive = i+1;
             xub_StrLen  nNextFStart = 0;
             xub_StrLen  nNextFEnd = 0;
             xub_StrLen  nArgPos = 0;
-            const ScFuncDesc* ppFDesc;
-            String**    pppArgs;
+            const IFunctionDescription* ppFDesc;
+            ::std::vector< ::rtl::OUString> aArgs;
             USHORT	    nArgs;
             BOOL  bFound = FALSE;
 
                     aAutoSearch = aText;
                 }
             }
+            FormulaHelper aHelper(ScGlobal::GetStarCalcFunctionMgr());
 
             while( !bFound )
             {
                 sal_Unicode c = aFormula.GetChar( nLeftParentPos-1 );
                 if( !(c >= 'A' && c<= 'Z' || c>= 'a' && c<= 'z' ) )
                     continue;
-                nNextFStart = ScFormulaUtil::GetFunctionStart( aFormula, nLeftParentPos, TRUE);
-                if( ScFormulaUtil::GetNextFunc( aFormula, FALSE, nNextFStart, &nNextFEnd, &ppFDesc, &pppArgs ) )
+                nNextFStart = aHelper.GetFunctionStart( aFormula, nLeftParentPos, TRUE);
+                if( aHelper.GetNextFunc( aFormula, FALSE, nNextFStart, &nNextFEnd, &ppFDesc, &aArgs ) )
                 {
-                    if( ppFDesc->pFuncName )
                     {
-                        nArgPos = ScFormulaUtil::GetArgStart( aFormula, nNextFStart, 0 );
-                        nArgs = ppFDesc->nArgCount;
+                        nArgPos = aHelper.GetArgStart( aFormula, nNextFStart, 0 );
+                        nArgs = ppFDesc->getParameterCount();
 
                         USHORT nActive = 0;
                         USHORT nCount = 0;
                         BOOL   bFlag = FALSE;
                         String aNew;
                         USHORT nParAutoPos = SCPOS_INVALID;
-                        if( pFormulaDataPara->FindText( *(ppFDesc->pFuncName), aNew, nParAutoPos, FALSE ) )
+                        if( pFormulaDataPara->FindText( ppFDesc->getFunctionName(), aNew, nParAutoPos, FALSE ) )
                         {
                             for( USHORT i=0; i < nArgs; i++ )
                             {
-                                xub_StrLen nLength=(pppArgs[i])->Len();
+                                xub_StrLen nLength=aArgs[i].getLength();
                                 if( nArgPos <= aFormula.Len()-1 )
                                 {
                                     nActive = i+1;

sc/source/ui/docshell/externalrefmgr.cxx

 using ::std::distance;
 using ::std::pair;
 using ::std::list;
+using namespace formula;
 
 #define SRCDOC_LIFE_SPAN     6000       // 1 minute (in 100th of a sec)
 #define SRCDOC_SCAN_INTERVAL 1000*5     // every 5 seconds (in msec)
         {
             for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
             {
-                ScToken* pToken = pTab->getCell(nCol, nRow).get();
+                FormulaToken* pToken = pTab->getCell(nCol, nRow).get();
                 if (!pToken)
                     return TokenArrayRef();
 
                 TokenRef pToken;
                 const ScMatrixRef& pMat = itrData->mpRangeData;
                 if (pMat->IsValue(nC, nR))
-                    pToken.reset(new ScDoubleToken(pMat->GetDouble(nC, nR)));
+                    pToken.reset(new formula::FormulaDoubleToken(pMat->GetDouble(nC, nR)));
                 else if (pMat->IsString(nC, nR))
-                    pToken.reset(new ScStringToken(pMat->GetString(nC, nR)));
+                    pToken.reset(new formula::FormulaStringToken(pMat->GetString(nC, nR)));
                 else
                     pToken.reset(new ScEmptyCellToken(false, false));
 
 
 // ============================================================================
 
-static ScToken* lcl_convertToToken(ScBaseCell* pCell)
+static FormulaToken* lcl_convertToToken(ScBaseCell* pCell)
 {
     if (!pCell || pCell->HasEmptyData())
     {
         {
             String aStr;
             static_cast<ScEditCell*>(pCell)->GetString(aStr);
-            return new ScStringToken(aStr);
+            return new formula::FormulaStringToken(aStr);
         }
         //break;
         case CELLTYPE_STRING:
         {
             String aStr;
             static_cast<ScStringCell*>(pCell)->GetString(aStr);
-            return new ScStringToken(aStr);
+            return new formula::FormulaStringToken(aStr);
         }
         //break;
         case CELLTYPE_VALUE:
         {
             double fVal = static_cast<ScValueCell*>(pCell)->GetValue();
-            return new ScDoubleToken(fVal);
+            return new formula::FormulaDoubleToken(fVal);
         }
         //break;
         case CELLTYPE_FORMULA:
             ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell);
             USHORT nError = pFCell->GetErrCode();
             if (nError)
-                return new ScErrorToken( nError);
+                return new FormulaErrorToken( nError);
             else if (pFCell->IsValue())
             {
                 double fVal = pFCell->GetValue();
-                return new ScDoubleToken(fVal);
+                return new formula::FormulaDoubleToken(fVal);
             }
             else
             {
                 String aStr;
                 pFCell->GetString(aStr);
-                return new ScStringToken(aStr);
+                return new formula::FormulaStringToken(aStr);
             }
         }
         //break;
     if (!pTok.get())
     {
         // Generate an error for unresolvable cells.
-        pTok.reset( new ScErrorToken( errNoValue));
+        pTok.reset( new FormulaErrorToken( errNoValue));
     }
 
     // Now, insert the token into cache table.
     ScExternalRefCache::TokenArrayRef pNew(new ScTokenArray);
 
     ScTokenArray* pCode = pRangeData->GetCode();
-    for (ScToken* pToken = pCode->First(); pToken; pToken = pCode->Next())
+    for (FormulaToken* pToken = pCode->First(); pToken; pToken = pCode->Next())
     {
         bool bTokenAdded = false;
         switch (pToken->GetType())
         {
             case svSingleRef:
             {
-                const ScSingleRefData& rRef = pToken->GetSingleRef();
+                const ScSingleRefData& rRef = static_cast<ScToken*>(pToken)->GetSingleRef();
                 String aTabName;
                 pSrcDoc->GetName(rRef.nTab, aTabName);
-                ScExternalSingleRefToken aNewToken(nFileId, aTabName, pToken->GetSingleRef());
+                ScExternalSingleRefToken aNewToken(nFileId, aTabName, static_cast<ScToken*>(pToken)->GetSingleRef());
                 pNew->AddToken(aNewToken);
                 bTokenAdded = true;
             }
             break;
             case svDoubleRef:
             {
-                const ScSingleRefData& rRef = pToken->GetSingleRef();
+                const ScSingleRefData& rRef = static_cast<ScToken*>(pToken)->GetSingleRef();
                 String aTabName;
                 pSrcDoc->GetName(rRef.nTab, aTabName);
-                ScExternalDoubleRefToken aNewToken(nFileId, aTabName, pToken->GetDoubleRef());
+                ScExternalDoubleRefToken aNewToken(nFileId, aTabName, static_cast<ScToken*>(pToken)->GetDoubleRef());
                 pNew->AddToken(aNewToken);
                 bTokenAdded = true;
             }

sc/source/ui/docshell/impex.cxx

     virtual FltError ScExportRTF( SvStream&, ScDocument*, const ScRange&, const CharSet ) RETURN_ERROR
 };
 
-extern "C" { static void SAL_CALL thisModule() {} };
+extern "C" { static void SAL_CALL thisModule() {} }
 typedef ScFormatFilterPlugin * (*FilterFn)(void);
 ScFormatFilterPlugin &ScFormatFilter::Get()
 {

sc/source/ui/inc/inputhdl.hxx

 
 	TypedScStrCollection*		pColumnData;
 	TypedScStrCollection*		pFormulaData;
-    TypedStrCollection*		pFormulaDataPara;
+    TypedScStrCollection*		pFormulaDataPara;
 	ULONG					nTipVisible;
     ULONG                   nTipVisibleSec;
 	String					aManualTip;

sc/source/ui/unoobj/linkuno.cxx

 #include <climits>
 
 using namespace com::sun::star;
+using namespace formula;
 using ::com::sun::star::uno::Any;
 using ::com::sun::star::uno::Reference;
 using ::com::sun::star::uno::Sequence;
     double fVal = 0.0;
     OUString aVal;
     if (rValue >>= fVal)
-        pToken.reset(new ScDoubleToken(fVal));
+        pToken.reset(new FormulaDoubleToken(fVal));
     else if (rValue >>= aVal)
-        pToken.reset(new ScStringToken(aVal));
+        pToken.reset(new FormulaStringToken(aVal));
     else
         // unidentified value type.
         return;
     if (nRow < 0 || nCol < 0)
         throw IllegalArgumentException();
 
-    ScToken* pToken = mpTable->getCell(static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow)).get();
+    FormulaToken* pToken = mpTable->getCell(static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow)).get();
     if (!pToken)
         throw IllegalArgumentException();
 

sc/source/ui/unoobj/tokenuno.cxx

     ScUnoGuard aGuard;
     uno::Any aRet;
     String aString(aPropertyName);
-    } // if ( aString.EqualsAscii( SC_UNO_REFERENCEPOS ) )
-    else if ( aString.EqualsAscii( SC_UNO_COMPILEFAP ) )
-    {
-        aRet <<= mbCompileFAP;
     if ( aString.EqualsAscii( SC_UNO_REFERENCEPOS ) )
     {
         table::CellAddress aAddress;
         ScUnoConversion::FillApiAddress( aAddress, maRefPos );
         aRet <<= aAddress;
     }
+    else if ( aString.EqualsAscii( SC_UNO_COMPILEFAP ) )
+    {
+        aRet <<= mbCompileFAP;
+    }
     else if ( aString.EqualsAscii( SC_UNO_COMPILEENGLISH ) )
     {
         aRet <<= mbEnglish;
 
 //------------------------------------------------------------------------
 
-void lcl_ExternalRefToCalc( ScSingleRefData& rRef, const sheet::SingleReference& rAPI )
-{
-    rRef.InitFlags();
-
-    rRef.nCol    = static_cast<SCsCOL>(rAPI.Column);
-    rRef.nRow    = static_cast<SCsROW>(rAPI.Row);
-    rRef.nTab    = 0;
-    rRef.nRelCol = static_cast<SCsCOL>(rAPI.RelativeColumn);
-    rRef.nRelRow = static_cast<SCsROW>(rAPI.RelativeRow);
-    rRef.nRelTab = 0;
-
-    rRef.SetColRel(     ( rAPI.Flags & sheet::ReferenceFlags::COLUMN_RELATIVE ) != 0 );
-    rRef.SetRowRel(     ( rAPI.Flags & sheet::ReferenceFlags::ROW_RELATIVE    ) != 0 );
-    rRef.SetTabRel(     false );    // sheet index must be absolute for external refs
-    rRef.SetColDeleted( ( rAPI.Flags & sheet::ReferenceFlags::COLUMN_DELETED  ) != 0 );
-    rRef.SetRowDeleted( ( rAPI.Flags & sheet::ReferenceFlags::ROW_DELETED     ) != 0 );
-    rRef.SetTabDeleted( false );    // sheet must not be deleted for external refs
-    rRef.SetFlag3D(     ( rAPI.Flags & sheet::ReferenceFlags::SHEET_3D        ) != 0 );
-    rRef.SetRelName(    false );
-}
-
 void lcl_ExternalRefToApi( sheet::SingleReference& rAPI, const ScSingleRefData& rRef )
 {
     rAPI.Column         = rRef.nCol;
 bool ScTokenConversion::ConvertToTokenArray( ScDocument& rDoc,
         ScTokenArray& rTokenArray, const uno::Sequence<sheet::FormulaToken>& rSequence )
 {
-    return rTokenArray.Fill(rSequence);
+    return rTokenArray.Fill(rSequence,rDoc.GetExternalRefManager());
 }
 
 // static

sc/source/ui/view/tabcont.cxx

 				}
 			}
 		}
-                }
 	}
 	SetCurPageId( static_cast<sal_uInt16>(pViewData->GetTabNo()) + 1 );