summaryrefslogtreecommitdiff
path: root/patches/vba/calc-vba-volatile-user-func.diff
diff options
context:
space:
mode:
Diffstat (limited to 'patches/vba/calc-vba-volatile-user-func.diff')
-rw-r--r--patches/vba/calc-vba-volatile-user-func.diff908
1 files changed, 0 insertions, 908 deletions
diff --git a/patches/vba/calc-vba-volatile-user-func.diff b/patches/vba/calc-vba-volatile-user-func.diff
deleted file mode 100644
index 5e3d38038..000000000
--- a/patches/vba/calc-vba-volatile-user-func.diff
+++ /dev/null
@@ -1,908 +0,0 @@
-diff --git formula/inc/formula/FormulaCompiler.hxx formula/inc/formula/FormulaCompiler.hxx
-index d5c3410..a388926 100644
---- formula/inc/formula/FormulaCompiler.hxx
-+++ formula/inc/formula/FormulaCompiler.hxx
-@@ -219,6 +219,8 @@ public:
- */
- OpCode GetEnglishOpCode( const String& rName ) const;
-
-+ static bool IsOpCodeVolatile( OpCode eOp );
-+
- static BOOL DeQuote( String& rStr );
-
- static const String& GetNativeSymbol( OpCode eOp );
-diff --git formula/source/core/api/FormulaCompiler.cxx formula/source/core/api/FormulaCompiler.cxx
-index a0a1c1a..72e6409 100644
---- formula/source/core/api/FormulaCompiler.cxx
-+++ formula/source/core/api/FormulaCompiler.cxx
-@@ -744,6 +744,30 @@ OpCode FormulaCompiler::GetEnglishOpCode( const String& rName ) const
- return bFound ? (*iLook).second : OpCode(ocNone);
- }
-
-+bool FormulaCompiler::IsOpCodeVolatile( OpCode eOp )
-+{
-+ switch (eOp)
-+ {
-+ // no parameters:
-+ case ocRandom:
-+ case ocGetActDate:
-+ case ocGetActTime:
-+ // one parameter:
-+ case ocFormula:
-+ case ocInfo:
-+ // more than one parameters:
-+ // ocIndirect/ocIndirectXL otherwise would have to do
-+ // StopListening and StartListening on a reference for every
-+ // interpreted value.
-+ case ocIndirect:
-+ case ocIndirectXL:
-+ // ocOffset results in indirect references.
-+ case ocOffset:
-+ return true;
-+ }
-+ return false;
-+}
-+
- // Remove quotes, escaped quotes are unescaped.
- BOOL FormulaCompiler::DeQuote( String& rStr )
- {
-@@ -960,44 +984,32 @@ void FormulaCompiler::Factor()
- {
- if( nNumFmt == NUMBERFORMAT_UNDEFINED )
- nNumFmt = lcl_GetRetFormat( eOp );
-- // Functions that have to be always recalculated
-- switch( eOp )
-+
-+ if ( IsOpCodeVolatile(eOp) )
-+ pArr->SetRecalcModeAlways();
-+ else
- {
-- // no parameters:
-- case ocRandom:
-- case ocGetActDate:
-- case ocGetActTime:
-- // one parameter:
-- case ocFormula:
-- case ocInfo:
-- // more than one parameters:
-- // ocIndirect/ocIndirectXL otherwise would have to do
-- // StopListening and StartListening on a reference for every
-- // interpreted value.
-- case ocIndirect:
-- case ocIndirectXL:
-- // ocOffset results in indirect references.
-- case ocOffset:
-- pArr->SetRecalcModeAlways();
-- break;
-- // Functions recalculated on every document load.
-- // Don't use SetRecalcModeOnLoad() which would override
-- // ModeAlways.
-- case ocConvert :
-- pArr->AddRecalcMode( RECALCMODE_ONLOAD );
-- break;
-- // If the referred cell is moved the value changes.
-- case ocColumn :
-- case ocRow :
-- // ocCell needs recalc on move for some possible type values.
-- case ocCell :
-- pArr->SetRecalcModeOnRefMove();
-- break;
-- case ocHyperLink :
-- pArr->SetHyperLink(TRUE);
-- break;
-- default:
-- ; // nothing
-+ switch( eOp )
-+ {
-+ // Functions recalculated on every document load.
-+ // Don't use SetRecalcModeOnLoad() which would override
-+ // ModeAlways.
-+ case ocConvert :
-+ pArr->AddRecalcMode( RECALCMODE_ONLOAD );
-+ break;
-+ // If the referred cell is moved the value changes.
-+ case ocColumn :
-+ case ocRow :
-+ // ocCell needs recalc on move for some possible type values.
-+ case ocCell :
-+ pArr->SetRecalcModeOnRefMove();
-+ break;
-+ case ocHyperLink :
-+ pArr->SetHyperLink(TRUE);
-+ break;
-+ default:
-+ ; // nothing
-+ }
- }
- if (SC_OPCODE_START_NO_PAR <= eOp && eOp < SC_OPCODE_STOP_NO_PAR)
- {
---- sc/inc/document.hxx
-+++ sc/inc/document.hxx
-@@ -96,6 +96,7 @@ class ScDrawLayer;
- class ScExtDocOptions;
- class ScExternalRefManager;
- class ScFormulaCell;
-+class ScMacroManager;
- class ScMarkData;
- class ScOutlineTable;
- class ScPatternAttr;
-@@ -294,6 +295,8 @@ private:
- ::std::auto_ptr<ScClipParam> mpClipParam;
-
- ::std::auto_ptr<ScExternalRefManager> pExternalRefMgr;
-+ ::std::auto_ptr<ScMacroManager> mpMacroMgr;
-+
-
- // mutable for lazy construction
- mutable ::std::auto_ptr< ScFormulaParserPool >
-@@ -1510,6 +1513,7 @@ public:
- SC_DLLPUBLIC ScLkUpdMode GetLinkMode() const { return eLinkMode ;}
- void SetLinkMode( ScLkUpdMode nSet ) { eLinkMode = nSet;}
-
-+ SC_DLLPUBLIC ScMacroManager* GetMacroManager();
-
- private:
- ScDocument(const ScDocument& r); // disabled with no definition
-diff --git sc/inc/macromgr.hxx sc/inc/macromgr.hxx
-new file mode 100644
-index 0000000..35a3b2d
---- /dev/null
-+++ sc/inc/macromgr.hxx
-@@ -0,0 +1,70 @@
-+/*************************************************************************
-+ *
-+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-+ *
-+ * Copyright 2008 by Sun Microsystems, Inc.
-+ *
-+ * OpenOffice.org - a multi-platform office productivity suite
-+ *
-+ * $RCSfile: document.hxx,v $
-+ * $Revision: 1.115.36.9 $
-+ *
-+ * This file is part of OpenOffice.org.
-+ *
-+ * OpenOffice.org is free software: you can redistribute it and/or modify
-+ * it under the terms of the GNU Lesser General Public License version 3
-+ * only, as published by the Free Software Foundation.
-+ *
-+ * OpenOffice.org is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU Lesser General Public License version 3 for more details
-+ * (a copy is included in the LICENSE file that accompanied this code).
-+ *
-+ * You should have received a copy of the GNU Lesser General Public License
-+ * version 3 along with OpenOffice.org. If not, see
-+ * <http://www.openoffice.org/license.html>
-+ * for a copy of the LGPLv3 License.
-+ *
-+ ************************************************************************/
-+
-+#ifndef SC_MACROMGR_HXX
-+#define SC_MACROMGR_HXX
-+
-+#include <com/sun/star/container/XContainerListener.hpp>
-+
-+#include "rtl/ustring.hxx"
-+#include "scdllapi.h"
-+
-+#include <hash_map>
-+#include <memory>
-+
-+class ScDocument;
-+class ScFormulaCell;
-+class ScUserMacroDepTracker;
-+
-+class ScMacroManager
-+{
-+public:
-+ explicit ScMacroManager(ScDocument* pDoc);
-+ ~ScMacroManager();
-+
-+ SC_DLLPUBLIC void InitUserFuncData();
-+ SC_DLLPUBLIC void SetUserFuncVolatile( const rtl::OUString& sName, bool isVolatile );
-+ SC_DLLPUBLIC bool GetUserFuncVolatile( const rtl::OUString& sName );
-+
-+ void AddDependentCell(const ::rtl::OUString& aModuleName, ScFormulaCell* pCell);
-+ void RemoveDependentCell(ScFormulaCell* pCell);
-+ void BroadcastModuleUpdate(const ::rtl::OUString& aModuleName);
-+
-+private:
-+ typedef std::hash_map< ::rtl::OUString, bool, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > NameBoolMap;
-+ NameBoolMap mhFuncToVolatile;
-+ com::sun::star::uno::Reference< com::sun::star::container::XContainerListener > mxContainerListener;
-+
-+ ::std::auto_ptr<ScUserMacroDepTracker> mpDepTracker;
-+ ScDocument* mpDoc;
-+};
-+
-+#endif
-+
---- sc/source/core/data/cell.cxx
-+++ sc/source/core/data/cell.cxx
-@@ -54,6 +54,7 @@
- #include "recursionhelper.hxx"
- #include "postit.hxx"
- #include "externalrefmgr.hxx"
-+#include "macromgr.hxx"
- #include <svx/editobj.hxx>
- #include <svtools/intitem.hxx>
- #include <svx/flditem.hxx>
-@@ -855,6 +856,9 @@ ScFormulaCell::ScFormulaCell( const ScFormulaCell& rCell, ScDocument& rDoc, cons
- ScFormulaCell::~ScFormulaCell()
- {
- pDocument->RemoveFromFormulaTree( this );
-+ if (pCode->HasOpCode(ocMacro))
-+ pDocument->GetMacroManager()->RemoveDependentCell(this);
-+
- delete pCode;
- #ifdef DBG_UTIL
- eCellType = CELLTYPE_DESTROYED;
-@@ -1721,6 +1725,36 @@ void ScFormulaCell::InterpretTail( ScInterpretTailParameter eTailParam )
- // Reschedule verlangsamt das ganze erheblich, nur bei Prozentaenderung ausfuehren
- ScProgress::GetInterpretProgress()->SetStateCountDownOnPercent(
- pDocument->GetFormulaCodeInTree()/MIN_NO_CODES_PER_PROGRESS_UPDATE );
-+
-+ switch (p->GetVolatileType())
-+ {
-+ case ScInterpreter::VOLATILE:
-+ // Volatile via built-in volatile functions. No actions needed.
-+ break;
-+ case ScInterpreter::VOLATILE_MACRO:
-+ // The formula contains a volatile macro.
-+ pCode->SetRecalcModeAlways();
-+ pDocument->PutInFormulaTree(this);
-+ StartListeningTo(pDocument);
-+ break;
-+ case ScInterpreter::NOT_VOLATILE:
-+ if (pCode->IsRecalcModeAlways())
-+ {
-+ // The formula was previously volatile, but no more.
-+ EndListeningTo(pDocument);
-+ pCode->SetRecalcModeNormal();
-+ }
-+ else
-+ {
-+ // non-volatile formula. End listening to the area in case
-+ // it's listening due to macro module change.
-+ pDocument->EndListeningArea(BCA_LISTEN_ALWAYS, this);
-+ }
-+ pDocument->RemoveFromFormulaTree(this);
-+ break;
-+ default:
-+ ;
-+ }
- }
- else
- {
---- sc/source/core/data/documen2.cxx
-+++ sc/source/core/data/documen2.cxx
-@@ -96,6 +96,7 @@
- #include "externalrefmgr.hxx"
- #include "tabprotection.hxx"
- #include "formulaparserpool.hxx"
- #include "clipparam.hxx"
-+#include "macromgr.hxx"
- #include <com/sun/star/document/XVbaEventsHelper.hpp>
-
-@@ -157,7 +158,8 @@ ScDocument::ScDocument( ScDocumentMode eMode,
- pCacheFieldEditEngine( NULL ),
- pDocProtection( NULL ),
- mpClipParam( NULL),
-+ mpMacroMgr( NULL ),
- pExternalRefMgr( NULL ),
- pViewOptions( NULL ),
- pDocOptions( NULL ),
- pExtDocOptions( NULL ),
-diff --git sc/source/core/data/documen8.cxx sc/source/core/data/documen8.cxx
-index 077b6fa..f1b608c 100644
---- sc/source/core/data/documen8.cxx
-+++ sc/source/core/data/documen8.cxx
-@@ -96,7 +96,8 @@
- #include "globstr.hrc"
- #include "sc.hrc"
- #include "charthelper.hxx"
- #include "dpobject.hxx"
-+#include "macromgr.hxx"
-
- #define GET_SCALEVALUE(set,id) ((const SfxUInt16Item&)(set.Get( id ))).GetValue()
-
-@@ -427,6 +428,13 @@ BYTE ScDocument::GetEditTextDirection(SCTAB nTab) const
- return sal::static_int_cast<BYTE>(eRet);
- }
-
-+ScMacroManager* ScDocument::GetMacroManager()
-+{
-+ if (!mpMacroMgr.get())
-+ mpMacroMgr.reset(new ScMacroManager(this));
-+ return mpMacroMgr.get();
-+}
-+
- //------------------------------------------------------------------------
-
- void ScDocument::InvalidateTextWidth( const ScAddress* pAdrFrom, const ScAddress* pAdrTo,
-diff --git sc/source/core/data/document.cxx sc/source/core/data/document.cxx
-index 11af993..676883e 100644
---- sc/source/core/data/document.cxx
-+++ sc/source/core/data/document.cxx
-@@ -95,10 +95,14 @@
- #include "externalrefmgr.hxx"
- #include "tabprotection.hxx"
- #include "clipparam.hxx"
-+#include <basic/basmgr.hxx>
-+#include <com/sun/star/container/XContainer.hpp>
-
- #include <map>
- #include <limits>
-
-+using namespace ::com::sun::star;
-+
- namespace WritingMode2 = ::com::sun::star::text::WritingMode2;
- using ::com::sun::star::uno::Sequence;
- using ::com::sun::star::sheet::TablePageBreakData;
-diff --git sc/source/core/inc/interpre.hxx sc/source/core/inc/interpre.hxx
-index a72775d..3a45be6 100644
---- sc/source/core/inc/interpre.hxx
-+++ sc/source/core/inc/interpre.hxx
-@@ -128,6 +128,15 @@ public:
- static inline double div( const double& fNumerator, const double& fDenominator );
-
- ScMatrixRef GetNewMat(SCSIZE nC, SCSIZE nR);
-+
-+ enum VolatileType {
-+ VOLATILE,
-+ VOLATILE_MACRO,
-+ NOT_VOLATILE
-+ };
-+
-+ VolatileType GetVolatileType() const;
-+
- private:
- static ScTokenStack* pGlobalStack;
- static BOOL bGlobalStackInUse;
-@@ -161,6 +170,8 @@ private:
- BOOL bCalcAsShown; // precision as shown
- BOOL bMatrixFormula; // formula cell is a matrix formula
-
-+ VolatileType meVolaileType;
-+
- //---------------------------------Funktionen in interpre.cxx---------
- // nMust <= nAct <= nMax ? ok : PushError
- inline BOOL MustHaveParamCount( short nAct, short nMust );
-diff --git sc/source/core/tool/interpr4.cxx sc/source/core/tool/interpr4.cxx
-index baa5152..7fccd66 100644
---- sc/source/core/tool/interpr4.cxx
-+++ sc/source/core/tool/interpr4.cxx
-@@ -41,6 +41,7 @@
- #include <basic/sbmod.hxx>
- #include <basic/sbstar.hxx>
- #include <basic/sbx.hxx>
-+#include <basic/sbxobj.hxx>
- #include <basic/sbuno.hxx>
- #include <svtools/zforlist.hxx>
- #include <tools/urlobj.hxx>
-@@ -71,7 +72,9 @@
- #include "jumpmatrix.hxx"
- #include "parclass.hxx"
- #include "externalrefmgr.hxx"
- #include "doubleref.hxx"
-+#include "formula/FormulaCompiler.hxx"
-+#include "macromgr.hxx"
-
- #include <math.h>
- #include <float.h>
-@@ -78,6 +81,7 @@
- #include <algorithm>
- #include <functional>
- #include <vbahelper/vbahelper.hxx>
-+#include <basic/basmgr.hxx>
-
- using namespace com::sun::star;
- using namespace formula;
-@@ -2751,7 +2755,9 @@ void ScInterpreter::ScMacro()
- return;
- }
-
-+ bool bVolatileMacro = false;
- SbMethod* pMethod = (SbMethod*)pVar;
-+
- SbModule* pModule = pMethod->GetModule();
- bool bUseVBAObjects = pModule->IsVBACompat();
- SbxObject* pObject = pModule->GetParent();
-@@ -2891,6 +2897,13 @@ void ScInterpreter::ScMacro()
- pDok->DecMacroInterpretLevel();
- pDok->UnlockTable( aPos.Tab() );
-
-+ ScMacroManager* pMacroMgr = pDok->GetMacroManager();
-+ if (pMacroMgr)
-+ {
-+ bVolatileMacro = pMacroMgr->GetUserFuncVolatile( pMethod->GetName() );
-+ pMacroMgr->AddDependentCell(pModule->GetName(), pMyFormulaCell);
-+ }
-+
- SbxDataType eResType = refRes->GetType();
- if( pVar->GetError() )
- SetError( errNoValue);
-@@ -2962,6 +2975,9 @@ void ScInterpreter::ScMacro()
- }
-
- pSfxApp->LeaveBasicCall();
-+
-+ if (bVolatileMacro && meVolaileType == NOT_VOLATILE)
-+ meVolaileType = VOLATILE_MACRO;
- }
-
-
-@@ -3619,7 +3635,8 @@ ScInterpreter::ScInterpreter( ScFormulaCell* pCell, ScDocument* pDoc,
- pTokenMatrixMap( NULL ),
- pMyFormulaCell( pCell ),
- pFormatter( pDoc->GetFormatTable() ),
-- bCalcAsShown( pDoc->GetDocOptions().IsCalcAsShown() )
-+ bCalcAsShown( pDoc->GetDocOptions().IsCalcAsShown() ),
-+ meVolaileType(NOT_VOLATILE)
- {
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "Eike.Rathke@sun.com", "ScInterpreter::ScTTT" );
- // pStack = new ScToken*[ MAXSTACK ];
-@@ -4060,6 +4077,9 @@ StackVar ScInterpreter::Interpret()
- default : PushError( errUnknownOpCode); break;
- }
-
-+ if (FormulaCompiler::IsOpCodeVolatile(eOp))
-+ meVolaileType = VOLATILE;
-+
- // Remember result matrix in case it could be reused.
- if (pTokenMatrixMap && sp && GetStackType() == svMatrix)
- pTokenMatrixMap->insert( ScTokenMatrixMap::value_type( pCur,
-diff --git sc/source/core/tool/interpr5.cxx sc/source/core/tool/interpr5.cxx
-index c5b4770..854c25d 100644
---- sc/source/core/tool/interpr5.cxx
-+++ sc/source/core/tool/interpr5.cxx
-@@ -324,6 +324,11 @@ ScMatrixRef ScInterpreter::GetNewMat(SCSIZE nC, SCSIZE nR)
- return pMat;
- }
-
-+ScInterpreter::VolatileType ScInterpreter::GetVolatileType() const
-+{
-+ return meVolaileType;
-+}
-+
- ScMatrixRef ScInterpreter::CreateMatrixFromDoubleRef( const FormulaToken* pToken,
- SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
- SCCOL nCol2, SCROW nRow2, SCTAB nTab2 )
-diff --git sc/source/filter/excel/excimp8.cxx sc/source/filter/excel/excimp8.cxx
-index 60c2f6d..846682b 100644
---- sc/source/filter/excel/excimp8.cxx
-+++ sc/source/filter/excel/excimp8.cxx
-@@ -99,6 +99,7 @@
- #include "stlpool.hxx"
- #include "stlsheet.hxx"
- #include "detfunc.hxx"
-+#include "macromgr.hxx"
-
- #include <com/sun/star/document/XDocumentProperties.hpp>
- #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
-@@ -107,6 +108,7 @@
- #include <cppuhelper/component_context.hxx>
-
- #include <com/sun/star/container/XNameContainer.hpp>
-+#include <sfx2/app.hxx>
-
- using namespace com::sun::star;
-
-@@ -279,7 +281,24 @@ void ImportExcel8::ReadBasic( void )
- SvxImportMSVBasic aBasicImport( *pShell, *xRootStrg, bLoadCode, bLoadStrg );
- bool bAsComment = !bLoadExecutable || !aGlobs.hasValue();
- aBasicImport.Import( EXC_STORAGE_VBA_PROJECT, EXC_STORAGE_VBA, bAsComment );
-- GetObjectManager().SetOleNameOverrideInfo( aBasicImport.ControlNameForObjectId() );
-+ if ( !bAsComment )
-+ {
-+ GetObjectManager().SetOleNameOverrideInfo( aBasicImport.ControlNameForObjectId() );
-+ ScDocument& rDoc = GetDoc();
-+ rDoc.GetMacroManager()->InitUserFuncData();
-+ // Fake ThisComponent being setup by Activate ( which is a view
-+ // related thing ),
-+ // a) if another document is opened then in theory ThisComponent
-+ // will be reset as before,
-+ // b) when this document is 'really' Activated then ThisComponent
-+ // again will be set as before
-+ // The only wrinkle seems if this document is loaded 'InVisible'
-+ // but.. I don't see that this is possible from the vba API
-+ // I could be wrong though
-+ BasicManager* pAppMgr = SFX_APP()->GetBasicManager();
-+ if ( pAppMgr )
-+ pAppMgr->SetGlobalUNOConstant( "ThisComponent", makeAny( pShell->GetModel() ) );
-+ }
- }
- }
- }
-diff --git sc/source/ui/docshell/macromgr.cxx sc/source/ui/docshell/macromgr.cxx
-new file mode 100644
-index 0000000..97623f3
---- /dev/null
-+++ sc/source/ui/docshell/macromgr.cxx
-@@ -0,0 +1,217 @@
-+/*************************************************************************
-+ *
-+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-+ *
-+ * Copyright 2008 by Sun Microsystems, Inc.
-+ *
-+ * OpenOffice.org - a multi-platform office productivity suite
-+ *
-+ * $RCSfile: document.hxx,v $
-+ * $Revision: 1.115.36.9 $
-+ *
-+ * This file is part of OpenOffice.org.
-+ *
-+ * OpenOffice.org is free software: you can redistribute it and/or modify
-+ * it under the terms of the GNU Lesser General Public License version 3
-+ * only, as published by the Free Software Foundation.
-+ *
-+ * OpenOffice.org is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU Lesser General Public License version 3 for more details
-+ * (a copy is included in the LICENSE file that accompanied this code).
-+ *
-+ * You should have received a copy of the GNU Lesser General Public License
-+ * version 3 along with OpenOffice.org. If not, see
-+ * <http://www.openoffice.org/license.html>
-+ * for a copy of the LGPLv3 License.
-+ *
-+ ************************************************************************/
-+
-+// MARKER(update_precomp.py): autogen include statement, do not remove
-+#include "precompiled_sc.hxx"
-+
-+// INCLUDE ---------------------------------------------------------------
-+
-+#include "macromgr.hxx"
-+#include "document.hxx"
-+
-+#include "basic/basmgr.hxx"
-+#include "cppuhelper/implbase1.hxx"
-+#include "sfx2/objsh.hxx"
-+#include "cell.hxx"
-+#include <com/sun/star/container/XContainer.hpp>
-+
-+#include <list>
-+
-+using namespace ::com::sun::star;
-+using ::com::sun::star::uno::RuntimeException;
-+using ::com::sun::star::uno::Reference;
-+using ::rtl::OUString;
-+using ::rtl::OUStringHash;
-+using ::std::hash_map;
-+using ::std::list;
-+using ::std::for_each;
-+using ::std::pair;
-+
-+// ============================================================================
-+
-+/**
-+ * A simple container to keep track of cells that depend on basic modules
-+ * changes. We don't check for duplicates at insertion time; instead, we
-+ * remove duplicates at query time.
-+ */
-+class ScUserMacroDepTracker
-+{
-+public:
-+ void addCell(const OUString& rModuleName, ScFormulaCell* pCell)
-+ {
-+ ModuleCellMap::iterator itr = maCells.find(rModuleName);
-+ if (itr == maCells.end())
-+ {
-+ pair<ModuleCellMap::iterator, bool> r = maCells.insert(
-+ ModuleCellMap::value_type(rModuleName, list<ScFormulaCell*>()));
-+
-+ if (!r.second)
-+ // insertion failed.
-+ return;
-+
-+ itr = r.first;
-+ }
-+ itr->second.push_back(pCell);
-+ }
-+
-+ void removeCell(ScFormulaCell* pCell)
-+ {
-+ ModuleCellMap::iterator itr = maCells.begin(), itrEnd = maCells.end();
-+ for (; itr != itrEnd; ++itr)
-+ itr->second.remove(pCell);
-+ }
-+
-+ void getCellsByModule(const OUString& rModuleName, list<ScFormulaCell*>& rCells)
-+ {
-+ ModuleCellMap::iterator itr = maCells.find(rModuleName);
-+ if (itr == maCells.end())
-+ return;
-+
-+ list<ScFormulaCell*>& rCellList = itr->second;
-+
-+ // Remove duplicates.
-+ rCellList.sort();
-+ rCellList.unique();
-+ // exception safe copy
-+ list<ScFormulaCell*> temp(rCellList);
-+ rCells.swap(temp);
-+ }
-+
-+private:
-+ typedef hash_map<OUString, list<ScFormulaCell*>, OUStringHash> ModuleCellMap;
-+ ModuleCellMap maCells;
-+};
-+
-+
-+// ============================================================================
-+
-+ScMacroManager::ScMacroManager(ScDocument* pDoc) :
-+ mpDepTracker(new ScUserMacroDepTracker),
-+ mpDoc(pDoc)
-+{
-+}
-+
-+ScMacroManager::~ScMacroManager()
-+{
-+}
-+
-+typedef ::cppu::WeakImplHelper1< ::com::sun::star::container::XContainerListener > ContainerListenerHelper;
-+
-+class VBAProjectListener : public ContainerListenerHelper
-+{
-+ ScMacroManager* mpMacroMgr;
-+public:
-+ VBAProjectListener( ScMacroManager* pMacroMgr ) : mpMacroMgr( pMacroMgr ) {}
-+ // XEventListener
-+ virtual void SAL_CALL disposing( const lang::EventObject& /*Source*/ ) throw(RuntimeException) {}
-+
-+ // XContainerListener
-+ virtual void SAL_CALL elementInserted( const container::ContainerEvent& /*Event*/ ) throw(RuntimeException){}
-+ virtual void SAL_CALL elementReplaced( const container::ContainerEvent& Event ) throw(RuntimeException)
-+ {
-+ rtl::OUString sModuleName;
-+ Event.Accessor >>= sModuleName;
-+ OSL_TRACE("VBAProjectListener::elementReplaced(%s)", rtl::OUStringToOString( sModuleName, RTL_TEXTENCODING_UTF8 ).getStr() );
-+ mpMacroMgr->InitUserFuncData();
-+ mpMacroMgr->BroadcastModuleUpdate(sModuleName);
-+ }
-+ virtual void SAL_CALL elementRemoved( const container::ContainerEvent& /*Event*/ ) throw(RuntimeException){}
-+
-+};
-+
-+void ScMacroManager::InitUserFuncData()
-+{
-+ // Clear hash_map
-+ mhFuncToVolatile.clear();
-+ String sProjectName( RTL_CONSTASCII_USTRINGPARAM("Standard") );
-+
-+ Reference< container::XContainer > xModuleContainer;
-+ SfxObjectShell* pShell = mpDoc->GetDocumentShell();
-+ if ( pShell && pShell->GetBasicManager()->GetName().Len() > 0 )
-+ sProjectName = pShell->GetBasicManager()->GetName();
-+ try
-+ {
-+ Reference< script::XLibraryContainer > xLibraries( pShell->GetBasicContainer(), uno::UNO_QUERY_THROW );
-+ xModuleContainer.set( xLibraries->getByName( sProjectName ), uno::UNO_QUERY_THROW );
-+
-+ if ( xModuleContainer.is() )
-+ {
-+ // remove old listener ( if there was one )
-+ if ( mxContainerListener.is() )
-+ xModuleContainer->removeContainerListener( mxContainerListener );
-+ // Create listener
-+ mxContainerListener = new VBAProjectListener( this );
-+ xModuleContainer->addContainerListener( mxContainerListener );
-+ }
-+ }
-+ catch( uno::Exception& )
-+ {
-+ }
-+}
-+
-+void ScMacroManager::SetUserFuncVolatile( const OUString& sName, bool isVolatile )
-+{
-+ mhFuncToVolatile[ sName ] = isVolatile;
-+}
-+
-+bool ScMacroManager::GetUserFuncVolatile( const OUString& sName )
-+{
-+ NameBoolMap::iterator it = mhFuncToVolatile.find( sName );
-+ if ( it == mhFuncToVolatile.end() )
-+ return false;
-+ return it->second;
-+}
-+
-+void ScMacroManager::AddDependentCell(const OUString& aModuleName, ScFormulaCell* pCell)
-+{
-+ mpDepTracker->addCell(aModuleName, pCell);
-+}
-+
-+void ScMacroManager::RemoveDependentCell(ScFormulaCell* pCell)
-+{
-+ mpDepTracker->removeCell(pCell);
-+}
-+
-+void ScMacroManager::BroadcastModuleUpdate(const OUString& aModuleName)
-+{
-+ list<ScFormulaCell*> aCells;
-+ mpDepTracker->getCellsByModule(aModuleName, aCells);
-+ list<ScFormulaCell*>::iterator itr = aCells.begin(), itrEnd = aCells.end();
-+ for (; itr != itrEnd; ++itr)
-+ {
-+ ScFormulaCell* pCell = *itr;
-+ mpDoc->PutInFormulaTree(pCell); // for F9 recalc
-+
-+ // for recalc on cell value change. If the cell is not volatile, the
-+ // cell stops listening right away after it gets re-interpreted.
-+ mpDoc->StartListeningArea(BCA_LISTEN_ALWAYS, pCell);
-+ }
-+}
-+
-diff --git sc/source/ui/docshell/makefile.mk sc/source/ui/docshell/makefile.mk
-index b48627e..e96d750 100644
---- sc/source/ui/docshell/makefile.mk
-+++ sc/source/ui/docshell/makefile.mk
-@@ -95,7 +95,8 @@ SLOFILES = \
- $(SLO)$/hiranges.obj \
- $(SLO)$/pntlock.obj \
- $(SLO)$/sizedev.obj \
-- $(SLO)$/editable.obj
-+ $(SLO)$/editable.obj \
-+ $(SLO)$/macromgr.obj
-
-
- EXCEPTIONSFILES= \
-@@ -105,7 +106,8 @@ EXCEPTIONSFILES= \
- $(SLO)$/docsh8.obj \
- $(SLO)$/externalrefmgr.obj \
- $(SLO)$/dbdocimp.obj \
-- $(SLO)$/docfunc.obj
-+ $(SLO)$/docfunc.obj \
-+ $(SLO)$/macromgr.obj
-
- SRS1NAME=$(TARGET)
- SRC1FILES = tpstat.src
-@@ -135,7 +137,8 @@ LIB1OBJFILES = \
- $(SLO)$/hiranges.obj \
- $(SLO)$/pntlock.obj \
- $(SLO)$/sizedev.obj \
-- $(SLO)$/editable.obj
-+ $(SLO)$/editable.obj \
-+ $(SLO)$/macromgr.obj
-
- # --- Tagets -------------------------------------------------------
-
-diff --git sc/source/ui/vba/vbaapplication.cxx sc/source/ui/vba/vbaapplication.cxx
-index 69121a0..c26a61d 100644
---- sc/source/ui/vba/vbaapplication.cxx
-+++ sc/source/ui/vba/vbaapplication.cxx
-@@ -61,6 +61,7 @@
- #include "vbatextboxshape.hxx"
- #include "vbaassistant.hxx"
- #include "sc.hrc"
-+#include "macromgr.hxx"
-
- #include <osl/file.hxx>
-
-@@ -87,7 +88,12 @@
- #include "unonames.hxx"
- #include "docsh.hxx"
- #include <vbahelper/helperdecl.hxx>
--
-+#include <basic/sbmeth.hxx>
-+#include <basic/sbmod.hxx>
-+#include <basic/sbstar.hxx>
-+#include <basic/sbx.hxx>
-+#include <basic/sbxobj.hxx>
-+#include <basic/sbuno.hxx>
- using namespace ::ooo::vba;
- using namespace ::com::sun::star;
- using ::com::sun::star::uno::Reference;
-@@ -1111,6 +1117,16 @@ ScVbaApplication::Volatile( const uno::Any& aVolatile ) throw ( uno::RuntimeExc
- {
- sal_Bool bVolatile = sal_True;
- aVolatile >>= bVolatile;
-+ SbMethod* pMeth = StarBASIC::GetActiveMethod();
-+ if ( pMeth )
-+ {
-+ OSL_TRACE("ScVbaApplication::Volatile() In method ->%s<-", rtl::OUStringToOString( pMeth->GetName(), RTL_TEXTENCODING_UTF8 ).getStr() );
-+ uno::Reference< frame::XModel > xModel( getCurrentDocument() );
-+ ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument();
-+ pDoc->GetMacroManager()->SetUserFuncVolatile( pMeth->GetName(), bVolatile);
-+ }
-+
-+// this is bound to break when loading the document
- return;
- /*
- if ( bVolatile )
-diff --git sc/source/ui/vba/vbadialog.cxx sc/source/ui/vba/vbadialog.cxx
-index 7383f5d..abfa6d3 100644
---- sc/source/ui/vba/vbadialog.cxx
-+++ sc/source/ui/vba/vbadialog.cxx
-@@ -47,6 +47,7 @@ void
- ScVbaDialog::Show() throw(uno::RuntimeException)
- {
- rtl::OUString aURL;
-+ // #FIXME - should this really use the current document?
- uno::Reference< frame::XModel > xModel = getCurrentDocument();
- if ( xModel.is() )
- {
-diff --git sc/source/ui/vba/vbarange.cxx sc/source/ui/vba/vbarange.cxx
-index 7a31267..5f62736 100644
---- sc/source/ui/vba/vbarange.cxx
-+++ sc/source/ui/vba/vbarange.cxx
-@@ -1976,6 +1976,7 @@ ScVbaRange::Select() throw (uno::RuntimeException)
- // ThisComponent.CurrentController.Frame.getContainerWindow.SetFocus
- try
- {
-+ // #FIXME don't use current document
- uno::Reference< frame::XController > xController( getCurrentDocument()->getCurrentController(), uno::UNO_QUERY_THROW );
- uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_QUERY_THROW );
- uno::Reference< awt::XWindow > xWin( xFrame->getContainerWindow(), uno::UNO_QUERY_THROW );
-@@ -2026,8 +2027,10 @@ ScVbaRange::Activate() throw (uno::RuntimeException)
- table::CellRangeAddress thisRangeAddress = xThisRangeAddress->getRangeAddress();
-
- // get current selection
-+ // #FIXME don't use getCurrentDocument
- uno::Reference< sheet::XCellRangeAddressable > xRange( getCurrentDocument()->getCurrentSelection(), ::uno::UNO_QUERY);
-
-+ // #FIXME don't use getCurrentDocument
- uno::Reference< sheet::XSheetCellRanges > xRanges( getCurrentDocument()->getCurrentSelection(), ::uno::UNO_QUERY);
-
- if ( xRanges.is() )
-@@ -2541,8 +2544,10 @@ ScVbaRange::PasteSpecial( const uno::Any& Paste, const uno::Any& Operation, cons
- {
- if ( m_Areas->getCount() > 1 )
- throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("That command cannot be used on multiple selections" ) ), uno::Reference< uno::XInterface >() );
-+ // #FIXME doen't use current document
- uno::Reference< view::XSelectionSupplier > xSelection( getCurrentDocument()->getCurrentController(), uno::UNO_QUERY_THROW );
- // save old selection
-+ // #FIXME doen't use current document
- uno::Reference< uno::XInterface > xSel( getCurrentDocument()->getCurrentSelection() );
- // select this range
- xSelection->select( uno::makeAny( mxRange ) );
-@@ -3900,6 +3905,7 @@ ScVbaRange::ApplicationRange( const uno::Reference< uno::XComponentContext >& xC
- }
- }
- }
-+ // #FIXME don't use current document
- uno::Reference< sheet::XSpreadsheetView > xView( getCurrentDocument()->getCurrentController(), uno::UNO_QUERY );
- uno::Reference< table::XCellRange > xSheetRange( xView->getActiveSheet(), uno::UNO_QUERY_THROW );
- ScVbaRange* pRange = new ScVbaRange( uno::Reference< XHelperInterface >(), xContext, xSheetRange );
-diff --git sc/source/ui/vba/vbashape.cxx sc/source/ui/vba/vbashape.cxx
-index a8d9e82..a231cad 100644
---- sc/source/ui/vba/vbashape.cxx
-+++ sc/source/ui/vba/vbashape.cxx
-@@ -431,6 +431,7 @@ ScVbaShape::ScaleWidth( double Factor, sal_Bool /*RelativeToOriginalSize*/, sal_
- void SAL_CALL
- ScVbaShape::Select( const uno::Any& /*Replace*/ ) throw ( uno::RuntimeException )
- {
-+ // #FIXME don't use getCurrentDocument
- uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
- uno::Reference< view::XSelectionSupplier > xSelectSupp( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
- xSelectSupp->select( uno::makeAny( m_xShape ) );
-diff --git sc/source/ui/vba/vbashaperange.cxx sc/source/ui/vba/vbashaperange.cxx
-index 8aebaea..5890e43 100644
---- sc/source/ui/vba/vbashaperange.cxx
-+++ sc/source/ui/vba/vbashaperange.cxx
-@@ -66,6 +66,7 @@ ScVbaShapeRange::ScVbaShapeRange( const uno::Reference< XHelperInterface >& xPar
- void SAL_CALL
- ScVbaShapeRange::Select( ) throw (uno::RuntimeException)
- {
-+ // #FIXME don't use getCurrentDocument
- uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
- uno::Reference< view::XSelectionSupplier > xSelectSupp( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
- xSelectSupp->select( uno::makeAny( getShapes() ) );
-diff --git sc/source/ui/vba/vbashapes.cxx sc/source/ui/vba/vbashapes.cxx
-index 80c1e8f..c1013ba 100644
---- sc/source/ui/vba/vbashapes.cxx
-+++ sc/source/ui/vba/vbashapes.cxx
-@@ -219,6 +219,7 @@ ScVbaShapes::SelectAll() throw (uno::RuntimeException)
- uno::Reference< drawing::XShape >
- ScVbaShapes::createShape( rtl::OUString service ) throw (css::uno::RuntimeException)
- {
-+ // #FIXME don't use getCurrentDocument
- uno::Reference< lang::XMultiServiceFactory > xMSF( getCurrentDocument(), uno::UNO_QUERY_THROW );
- uno::Reference< drawing::XShape > xShape( xMSF->createInstance( service ), uno::UNO_QUERY_THROW );
- return xShape;