summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2010-03-09 14:51:15 -0500
committerKohei Yoshida <kyoshida@novell.com>2010-03-09 14:51:15 -0500
commit5f94a5e44621da1ca3cf59df7d6cbace46606995 (patch)
treec0484cfa5a9108b132d0eae9e995a64e66cbb04c
parentae6f4b5f20abc753f6d065e007c56a80b4925f6b (diff)
koheiextref01: #i108404# Disable interaction handler when interpreting formula strings via UNO API.
-rw-r--r--sc/inc/externalrefmgr.hxx25
-rw-r--r--sc/source/ui/docshell/docfunc.cxx9
-rw-r--r--sc/source/ui/docshell/externalrefmgr.cxx25
-rw-r--r--sc/source/ui/unoobj/cellsuno.cxx3
-rw-r--r--sc/source/ui/unoobj/tokenuno.cxx5
5 files changed, 60 insertions, 7 deletions
diff --git a/sc/inc/externalrefmgr.hxx b/sc/inc/externalrefmgr.hxx
index f251875b35ea..3f368d9a3189 100644
--- a/sc/inc/externalrefmgr.hxx
+++ b/sc/inc/externalrefmgr.hxx
@@ -386,6 +386,21 @@ public:
};
};
+ /**
+ * Use this guard when performing something from the API that might query
+ * values from external references. Interpreting formula strings is one
+ * such example.
+ */
+ class ApiGuard
+ {
+ public:
+ ApiGuard(ScExternalRefManager* pMgr);
+ ~ApiGuard();
+ private:
+ ScExternalRefManager* mpMgr;
+ bool mbOldInteractionEnabled;
+ };
+
private:
/** Shell instance for a source document. */
struct SrcShell
@@ -512,7 +527,7 @@ public:
* @returns <TRUE/> if setAllCacheTableReferencedStati(false) was called,
* <FALSE/> if setAllCacheTableReferencedStati(true) was called.
*/
- bool isInReferenceMarking() const { return bInReferenceMarking; }
+ bool isInReferenceMarking() const { return mbInReferenceMarking; }
void storeRangeNameTokens(sal_uInt16 nFileId, const String& rName, const ScTokenArray& rArray);
@@ -716,7 +731,13 @@ private:
::std::vector<SrcFileData> maSrcFiles;
/** Status whether in reference marking state. See isInReferenceMarking(). */
- bool bInReferenceMarking;
+ bool mbInReferenceMarking:1;
+
+ /**
+ * Controls whether or not to allow user interaction. We don't want any
+ * user interaction when calling from the API.
+ */
+ bool mbUserInteractionEnabled:1;
AutoTimer maSrcDocTimer;
DECL_LINK(TimeOutHdl, AutoTimer*);
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index cd28daa99401..176ce4b2694a 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -92,8 +92,10 @@
#include "scui_def.hxx" //CHINA001
#include "tabprotection.hxx"
#include "clipparam.hxx"
+#include "externalrefmgr.hxx"
#include <memory>
+#include <boost/scoped_ptr.hpp>
using namespace com::sun::star;
using ::com::sun::star::uno::Sequence;
@@ -1035,6 +1037,13 @@ BOOL ScDocFunc::SetCellText( const ScAddress& rPos, const String& rText,
{
if ( bEnglish )
{
+ ::boost::scoped_ptr<ScExternalRefManager::ApiGuard> pExtRefGuard;
+ if (bApi)
+ {
+ ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager();
+ pExtRefGuard.reset(new ScExternalRefManager::ApiGuard(pRefMgr));
+ }
+
// code moved to own method InterpretEnglishString because it is also used in
// ScCellRangeObj::setFormulaArray
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index b071cdb3a6a6..2a96561bb303 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -1449,7 +1449,8 @@ static ScTokenArray* lcl_fillEmptyMatrix(const ScRange& rRange)
ScExternalRefManager::ScExternalRefManager(ScDocument* pDoc) :
mpDoc(pDoc),
- bInReferenceMarking(false)
+ mbInReferenceMarking(false),
+ mbUserInteractionEnabled(true)
{
maSrcDocTimer.SetTimeoutHdl( LINK(this, ScExternalRefManager, TimeOutHdl) );
maSrcDocTimer.SetTimeout(SRCDOC_SCAN_INTERVAL);
@@ -1487,6 +1488,22 @@ ScExternalRefManager::LinkListener::~LinkListener()
// ----------------------------------------------------------------------------
+ScExternalRefManager::ApiGuard::ApiGuard(ScExternalRefManager* pMgr) :
+ mpMgr(pMgr),
+ mbOldInteractionEnabled(pMgr->mbUserInteractionEnabled)
+{
+ // We don't want user interaction handled in the API.
+ mpMgr->mbUserInteractionEnabled = false;
+}
+
+ScExternalRefManager::ApiGuard::~ApiGuard()
+{
+ // Restore old value.
+ mpMgr->mbUserInteractionEnabled = mbOldInteractionEnabled;
+}
+
+// ----------------------------------------------------------------------------
+
void ScExternalRefManager::getAllCachedTableNames(sal_uInt16 nFileId, vector<String>& rTabNames) const
{
maRefCache.getAllTableNames(nFileId, rTabNames);
@@ -1567,7 +1584,7 @@ void ScExternalRefManager::setCacheTableReferencedPermanently( sal_uInt16 nFileI
void ScExternalRefManager::setAllCacheTableReferencedStati( bool bReferenced )
{
- bInReferenceMarking = !bReferenced;
+ mbInReferenceMarking = !bReferenced;
maRefCache.setAllCacheTableReferencedStati( bReferenced );
}
@@ -1978,8 +1995,8 @@ SfxObjectShellRef ScExternalRefManager::loadSrcDocument(sal_uInt16 nFileId, Stri
if (pMedium->GetError() != ERRCODE_NONE)
return NULL;
- // We need this to load encrypted documents with password.
- pMedium->UseInteractionHandler(true);
+ // To load encrypted documents with password, user interaction needs to be enabled.
+ pMedium->UseInteractionHandler(mbUserInteractionEnabled);
ScDocShell* pNewShell = new ScDocShell(SFX_CREATE_MODE_INTERNAL);
SfxObjectShellRef aRef = pNewShell;
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index c61a6443af99..34718880a9b4 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -5264,6 +5264,9 @@ void SAL_CALL ScCellRangeObj::setFormulaArray(
ScDocShell* pDocSh = GetDocShell();
if (pDocSh)
{
+ ScExternalRefManager* pRefMgr = pDocSh->GetDocument()->GetExternalRefManager();
+ ScExternalRefManager::ApiGuard aExtRefGuard(pRefMgr);
+
// GRAM_PODF_A1 for API compatibility.
bDone = lcl_PutFormulaArray( *pDocSh, aRange, aArray, EMPTY_STRING, formula::FormulaGrammar::GRAM_PODF_A1 );
}
diff --git a/sc/source/ui/unoobj/tokenuno.cxx b/sc/source/ui/unoobj/tokenuno.cxx
index fc14b53a6372..6c2f00c809f0 100644
--- a/sc/source/ui/unoobj/tokenuno.cxx
+++ b/sc/source/ui/unoobj/tokenuno.cxx
@@ -140,9 +140,12 @@ uno::Sequence<sheet::FormulaToken> SAL_CALL ScFormulaParserObj::parseFormula(
if (mpDocShell)
{
+ ScDocument* pDoc = mpDocShell->GetDocument();
+ ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager();
+ ScExternalRefManager::ApiGuard aExtRefGuard(pRefMgr);
+
ScAddress aRefPos( ScAddress::UNINITIALIZED );
ScUnoConversion::FillScAddress( aRefPos, rReferencePos );
- ScDocument* pDoc = mpDocShell->GetDocument();
ScCompiler aCompiler( pDoc, aRefPos);
aCompiler.SetGrammar(pDoc->GetGrammar());
SetCompilerFlags( aCompiler );