[Libreoffice-commits] core.git: 11 commits - include/sfx2 sc/inc sc/source sfx2/source

Kohei Yoshida kohei.yoshida at collabora.com
Wed May 21 10:26:39 PDT 2014


 include/sfx2/sfxmodelfactory.hxx         |   12 
 sc/inc/compiler.hxx                      |    2 
 sc/inc/document.hxx                      |    3 
 sc/inc/externalrefmgr.hxx                |   35 ++
 sc/inc/sc.hrc                            |    3 
 sc/inc/scopetools.hxx                    |    9 
 sc/inc/unonames.hxx                      |    3 
 sc/inc/xmlwrap.hxx                       |   23 +
 sc/source/core/data/documen2.cxx         |    1 
 sc/source/core/data/documen8.cxx         |   59 ++-
 sc/source/core/data/documen9.cxx         |    5 
 sc/source/core/tool/compiler.cxx         |  106 ++-----
 sc/source/core/tool/scopetools.cxx       |   14 
 sc/source/filter/xml/xmlimprt.cxx        |   40 ++
 sc/source/filter/xml/xmlimprt.hxx        |    7 
 sc/source/filter/xml/xmlwrap.cxx         |  464 +++++++++++++++----------------
 sc/source/ui/docshell/docsh.cxx          |   18 -
 sc/source/ui/docshell/externalrefmgr.cxx |  290 ++++++++++++++++---
 sc/source/ui/src/scstring.src            |    5 
 sfx2/source/doc/objxtor.cxx              |    6 
 20 files changed, 698 insertions(+), 407 deletions(-)

New commits:
commit 27a84e96005c502e5d1f4164cd7befbb6230d666
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Wed May 21 11:14:44 2014 -0400

    Avoid unnecessary cloning of ScRawToken during token check.
    
    Change-Id: Ia980054437394ef48f7df655411f81d20b9cfa32

diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx
index 8b5158c..6100835 100644
--- a/sc/inc/compiler.hxx
+++ b/sc/inc/compiler.hxx
@@ -317,7 +317,7 @@ private:
     sal_Unicode cSymbol[MAXSTRLEN];                 // current Symbol
     OUString    aFormula;                           // formula source code
     sal_Int32   nSrcPos;                            // tokenizer position (source code)
-    mutable ScRawTokenRef pRawToken;
+    mutable ScRawToken maRawToken;
 
     const CharClass*    pCharClass;         // which character classification is used for parseAnyToken
     sal_uInt16      mnPredetectedReference;     // reference when reading ODF, 0 (none), 1 (single) or 2 (double)
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 6f6b89d..0af9ad3 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -2344,7 +2344,6 @@ bool ScCompiler::IsOpCode( const OUString& rName, bool bInArray )
     bool bFound = (iLook != mxSymbols->getHashMap()->end());
     if (bFound)
     {
-        ScRawToken aToken;
         OpCode eOp = iLook->second;
         if (bInArray)
         {
@@ -2353,8 +2352,7 @@ bool ScCompiler::IsOpCode( const OUString& rName, bool bInArray )
             else if (rName.equals(mxSymbols->getSymbol(ocArrayRowSep)))
                 eOp = ocArrayRowSep;
         }
-        aToken.SetOpCode(eOp);
-        pRawToken = aToken.Clone();
+        maRawToken.SetOpCode(eOp);
     }
     else if (mxSymbols->isODFF())
     {
@@ -2382,9 +2380,7 @@ bool ScCompiler::IsOpCode( const OUString& rName, bool bInArray )
         {
             if (rName.equalsIgnoreAsciiCaseAscii( aOdffAliases[i].pName))
             {
-                ScRawToken aToken;
-                aToken.SetOpCode( aOdffAliases[i].eOp);
-                pRawToken = aToken.Clone();
+                maRawToken.SetOpCode( aOdffAliases[i].eOp);
                 bFound = true;
                 break;  // for
             }
@@ -2417,9 +2413,7 @@ bool ScCompiler::IsOpCode( const OUString& rName, bool bInArray )
             // Old (deprecated) addins first for legacy.
             if (ScGlobal::GetFuncCollection()->findByName(cSymbol))
             {
-                ScRawToken aToken;
-                aToken.SetExternal( cSymbol );
-                pRawToken = aToken.Clone();
+                maRawToken.SetExternal( cSymbol );
             }
             else
                 // bLocalFirst=false for (English) upper full original name
@@ -2429,14 +2423,12 @@ bool ScCompiler::IsOpCode( const OUString& rName, bool bInArray )
         }
         if (!aIntName.isEmpty())
         {
-            ScRawToken aToken;
-            aToken.SetExternal( aIntName.getStr() );     // international name
-            pRawToken = aToken.Clone();
+            maRawToken.SetExternal( aIntName.getStr() );     // international name
             bFound = true;
         }
     }
     OpCode eOp;
-    if (bFound && ((eOp = pRawToken->GetOpCode()) == ocSub || eOp == ocNegSub))
+    if (bFound && ((eOp = maRawToken.GetOpCode()) == ocSub || eOp == ocNegSub))
     {
         bool bShouldBeNegSub =
             (eLastOp == ocOpen || eLastOp == ocSep || eLastOp == ocNegSub ||
@@ -2444,10 +2436,10 @@ bool ScCompiler::IsOpCode( const OUString& rName, bool bInArray )
              eLastOp == ocArrayOpen ||
              eLastOp == ocArrayColSep || eLastOp == ocArrayRowSep);
         if (bShouldBeNegSub && eOp == ocSub)
-            pRawToken->NewOpCode( ocNegSub );
+            maRawToken.NewOpCode( ocNegSub );
             //! if ocNegSub had ForceArray we'd have to set it here
         else if (!bShouldBeNegSub && eOp == ocNegSub)
-            pRawToken->NewOpCode( ocSub );
+            maRawToken.NewOpCode( ocSub );
     }
     return bFound;
 }
@@ -2462,9 +2454,7 @@ bool ScCompiler::IsOpCode2( const OUString& rName )
 
     if (bFound)
     {
-        ScRawToken aToken;
-        aToken.SetOpCode( (OpCode) --i );
-        pRawToken = aToken.Clone();
+        maRawToken.SetOpCode( (OpCode) --i );
     }
     return bFound;
 }
@@ -2499,9 +2489,7 @@ bool ScCompiler::IsValue( const OUString& rSym )
     if( nType == NUMBERFORMAT_TEXT )
         // HACK: number too big!
         SetError( errIllegalArgument );
-    ScRawToken aToken;
-    aToken.SetDouble( fVal );
-    pRawToken = aToken.Clone();
+    maRawToken.SetDouble( fVal );
     return true;
 }
 
@@ -2520,11 +2508,9 @@ bool ScCompiler::IsString()
     if ( bQuote )
     {
         cSymbol[nLen] = '\0';
-        ScRawToken aToken;
         const sal_Unicode* pStr = cSymbol+1;
         svl::SharedString aSS = pDoc->GetSharedStringPool().intern(OUString(pStr));
-        aToken.SetString(aSS.getData(), aSS.getDataIgnoreCase());
-        pRawToken = aToken.Clone();
+        maRawToken.SetString(aSS.getData(), aSS.getDataIgnoreCase());
         return true;
     }
     return false;
@@ -2595,7 +2581,6 @@ bool ScCompiler::IsDoubleReference( const OUString& rName )
     sal_uInt16 nFlags = aRange.Parse( rName, pDoc, aDetails, &aExtInfo, &maExternalLinks );
     if( nFlags & SCA_VALID )
     {
-        ScRawToken aToken;
         ScComplexRefData aRef;
         aRef.InitRange( aRange );
         aRef.Ref1.SetColRel( (nFlags & SCA_COL_ABSOLUTE) == 0 );
@@ -2615,15 +2600,14 @@ bool ScCompiler::IsDoubleReference( const OUString& rName )
         {
             ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager();
             const OUString* pRealTab = pRefMgr->getRealTableName(aExtInfo.mnFileId, aExtInfo.maTabName);
-            aToken.SetExternalDoubleRef(
+            maRawToken.SetExternalDoubleRef(
                 aExtInfo.mnFileId, pRealTab ? *pRealTab : aExtInfo.maTabName, aRef);
             maExternalFiles.push_back(aExtInfo.mnFileId);
         }
         else
         {
-            aToken.SetDoubleReference(aRef);
+            maRawToken.SetDoubleReference(aRef);
         }
-        pRawToken = aToken.Clone();
     }
 
     return ( nFlags & SCA_VALID ) != 0;
@@ -2639,7 +2623,6 @@ bool ScCompiler::IsSingleReference( const OUString& rName )
     // as a (wrong) reference.
     if( nFlags & ( SCA_VALID_COL|SCA_VALID_ROW|SCA_VALID_TAB ) )
     {
-        ScRawToken aToken;
         ScSingleRefData aRef;
         aRef.InitAddress( aAddr );
         aRef.SetColRel( (nFlags & SCA_COL_ABSOLUTE) == 0 );
@@ -2663,13 +2646,12 @@ bool ScCompiler::IsSingleReference( const OUString& rName )
         {
             ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager();
             const OUString* pRealTab = pRefMgr->getRealTableName(aExtInfo.mnFileId, aExtInfo.maTabName);
-            aToken.SetExternalSingleRef(
+            maRawToken.SetExternalSingleRef(
                 aExtInfo.mnFileId, pRealTab ? *pRealTab : aExtInfo.maTabName, aRef);
             maExternalFiles.push_back(aExtInfo.mnFileId);
         }
         else
-            aToken.SetSingleReference(aRef);
-        pRawToken = aToken.Clone();
+            maRawToken.SetSingleReference(aRef);
     }
 
     return ( nFlags & SCA_VALID ) != 0;
@@ -2827,10 +2809,8 @@ bool ScCompiler::IsMacro( const OUString& rName )
         rSolarMutex.release();
         return false;
     }
-    ScRawToken aToken;
-    aToken.SetExternal( aName.getStr() );
-    aToken.eOp = ocMacro;
-    pRawToken = aToken.Clone();
+    maRawToken.SetExternal( aName.getStr() );
+    maRawToken.eOp = ocMacro;
     rSolarMutex.release();
     return true;
 #endif
@@ -2857,9 +2837,7 @@ bool ScCompiler::IsNamedRange( const OUString& rUpperName )
 
     if (pData)
     {
-        ScRawToken aToken;
-        aToken.SetName(bGlobal, pData->GetIndex());
-        pRawToken = aToken.Clone();
+        maRawToken.SetName(bGlobal, pData->GetIndex());
         return true;
     }
     else
@@ -2881,7 +2859,6 @@ bool ScCompiler::IsExternalNamedRange( const OUString& rSymbol )
     if (!pConv->parseExternalName( rSymbol, aFile, aName, pDoc, &maExternalLinks))
         return false;
 
-    ScRawToken aToken;
     if (aFile.getLength() > MAXSTRLEN || aName.getLength() > MAXSTRLEN)
         return false;
 
@@ -2895,8 +2872,7 @@ bool ScCompiler::IsExternalNamedRange( const OUString& rSymbol )
         return false;
 
     const OUString* pRealName = pRefMgr->getRealRangeName(nFileId, aName);
-    aToken.SetExternalName(nFileId, pRealName ? *pRealName : OUString(aTmp));
-    pRawToken = aToken.Clone();
+    maRawToken.SetExternalName(nFileId, pRealName ? *pRealName : OUString(aTmp));
     maExternalFiles.push_back(nFileId);
     return true;
 }
@@ -2905,13 +2881,11 @@ bool ScCompiler::IsDBRange( const OUString& rName )
 {
     if (rName.equalsAscii("[]"))
     {
-        if (pRawToken && pRawToken->GetOpCode() == ocDBArea)
+        if (maRawToken.GetOpCode() == ocDBArea)
         {
             // In OOXML, a database range is named Table1[], Table2[] etc.
             // Skip the [] part if the previous token is a valid db range.
-            ScRawToken aToken;
-            aToken.eOp = ocSkip;
-            pRawToken = aToken.Clone();
+            maRawToken.eOp = ocSkip;
             return true;
         }
     }
@@ -2920,10 +2894,8 @@ bool ScCompiler::IsDBRange( const OUString& rName )
     if (!p)
         return false;
 
-    ScRawToken aToken;
-    aToken.SetName(true, p->GetIndex()); // DB range is always global.
-    aToken.eOp = ocDBArea;
-    pRawToken = aToken.Clone();
+    maRawToken.SetName(true, p->GetIndex()); // DB range is always global.
+    maRawToken.eOp = ocDBArea;
     return true;
 }
 
@@ -3169,10 +3141,8 @@ bool ScCompiler::IsColRowName( const OUString& rName )
     }
     if ( bFound )
     {
-        ScRawToken aToken;
-        aToken.SetSingleReference( aRef );
-        aToken.eOp = ocColRowName;
-        pRawToken = aToken.Clone();
+        maRawToken.SetSingleReference( aRef );
+        maRawToken.eOp = ocColRowName;
         return true;
     }
     else
@@ -3186,9 +3156,7 @@ bool ScCompiler::IsBoolean( const OUString& rName )
         ((*iLook).second == ocTrue ||
          (*iLook).second == ocFalse) )
     {
-        ScRawToken aToken;
-        aToken.SetOpCode( (*iLook).second );
-        pRawToken = aToken.Clone();
+        maRawToken.SetOpCode( (*iLook).second );
         return true;
     }
     else
@@ -3200,9 +3168,7 @@ bool ScCompiler::IsErrorConstant( const OUString& rName ) const
     sal_uInt16 nError = GetErrorConstant( rName);
     if (nError)
     {
-        ScRawToken aToken;
-        aToken.SetErrorConstant( nError);
-        pRawToken = aToken.Clone();
+        maRawToken.SetErrorConstant( nError);
         return true;
     }
     else
@@ -3448,11 +3414,9 @@ bool ScCompiler::NextNewToken( bool bInArray )
              * original string containing partial valid address
              * information if not ODFF (in that case it was already handled).
              * */
-            ScRawToken aToken;
             svl::SharedString aSS = pDoc->GetSharedStringPool().intern(aStr);
-            aToken.SetString(aSS.getData(), aSS.getDataIgnoreCase());
-            aToken.NewOpCode( ocBad );
-            pRawToken = aToken.Clone();
+            maRawToken.SetString(aSS.getData(), aSS.getDataIgnoreCase());
+            maRawToken.NewOpCode( ocBad );
         }
         return true;
     }
@@ -3545,7 +3509,7 @@ bool ScCompiler::NextNewToken( bool bInArray )
             // If a syntactically correct reference was recognized but invalid
             // e.g. because of non-existing sheet name => entire reference
             // ocBad to preserve input instead of #REF!.A1
-            if (!pRawToken->IsValidReference())
+            if (!maRawToken.IsValidReference())
             {
                 aUpper = aOrg;          // ensure for ocBad
                 break;                  // do; create ocBad token or set error.
@@ -3598,11 +3562,9 @@ bool ScCompiler::NextNewToken( bool bInArray )
     // would prematurely end compilation. Simple unknown names are handled by
     // the interpreter.
     aUpper = ScGlobal::pCharClass->lowercase( aUpper );
-    ScRawToken aToken;
     svl::SharedString aSS = pDoc->GetSharedStringPool().intern(aUpper);
-    aToken.SetString(aSS.getData(), aSS.getDataIgnoreCase());
-    aToken.NewOpCode( ocBad );
-    pRawToken = aToken.Clone();
+    maRawToken.SetString(aSS.getData(), aSS.getDataIgnoreCase());
+    maRawToken.NewOpCode( ocBad );
     if ( bAutoCorrect )
         AutoCorrectParsedSymbol();
     return true;
@@ -3694,7 +3656,7 @@ ScTokenArray* ScCompiler::CompileString( const OUString& rFormula )
     eLastOp = ocOpen;
     while( NextNewToken( bInArray ) )
     {
-        const OpCode eOp = pRawToken->GetOpCode();
+        const OpCode eOp = maRawToken.GetOpCode();
         if (eOp == ocSkip)
             continue;
 
@@ -3824,7 +3786,7 @@ ScTokenArray* ScCompiler::CompileString( const OUString& rFormula )
                 ++pFunctionStack[ nFunction ].nSep;
             }
         }
-        FormulaToken* pNewToken = static_cast<ScTokenArray*>(pArr)->Add( pRawToken->CreateToken());
+        FormulaToken* pNewToken = static_cast<ScTokenArray*>(pArr)->Add( maRawToken.CreateToken());
         if (!pNewToken)
         {
             SetError(errCodeOverflow); break;
@@ -3832,7 +3794,7 @@ ScTokenArray* ScCompiler::CompileString( const OUString& rFormula )
         else if (eLastOp == ocRange && pNewToken->GetOpCode() == ocPush &&
                 pNewToken->GetType() == svSingleRef)
             static_cast<ScTokenArray*>(pArr)->MergeRangeReference( aPos);
-        eLastOp = pRawToken->GetOpCode();
+        eLastOp = maRawToken.GetOpCode();
         if ( bAutoCorrect )
             aCorrectedFormula += aCorrectedSymbol;
     }
commit 50454f382215d63855684402b4258183be8d0e4c
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Wed May 21 00:00:57 2014 -0400

    cp#1000072: Skip styles import for external link cache documents.
    
    This reduces external link update time by 10%.
    
    Change-Id: Ic14d9ea7530818f839330a2004f6aa67ef1e831e

diff --git a/include/sfx2/sfxmodelfactory.hxx b/include/sfx2/sfxmodelfactory.hxx
index 7f7b05f..2067fbf 100644
--- a/include/sfx2/sfxmodelfactory.hxx
+++ b/include/sfx2/sfxmodelfactory.hxx
@@ -25,16 +25,14 @@
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
 
+#define SFXMODEL_STANDARD                   (sal_uInt64)(0x0000)
+#define SFXMODEL_EMBEDDED_OBJECT            (sal_uInt64)(0x0001)
+#define SFXMODEL_EXTERNAL_LINK              (sal_uInt64)(0x0002)
+#define SFXMODEL_DISABLE_EMBEDDED_SCRIPTS   (sal_uInt64)(0x0004)
+#define SFXMODEL_DISABLE_DOCUMENT_RECOVERY  (sal_uInt64)(0x0008)
 
 namespace sfx2
 {
-
-
-    #define SFXMODEL_STANDARD                   (sal_uInt64)(0x0000)
-    #define SFXMODEL_EMBEDDED_OBJECT            (sal_uInt64)(0x0001)
-    #define SFXMODEL_DISABLE_EMBEDDED_SCRIPTS   (sal_uInt64)(0x0002)
-    #define SFXMODEL_DISABLE_DOCUMENT_RECOVERY  (sal_uInt64)(0x0004)
-
     typedef ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > ( SAL_CALL * SfxModelFactoryFunc ) (
         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory,
         const sal_uInt64 _nCreationFlags
diff --git a/sc/inc/unonames.hxx b/sc/inc/unonames.hxx
index 689dcea..ca7a28c 100644
--- a/sc/inc/unonames.hxx
+++ b/sc/inc/unonames.hxx
@@ -668,7 +668,8 @@
 
 #define SC_UNO_EMBED_FONTS     "EmbedFonts"
 
-#define SC_UNO_ODS_LOCK_SOLAR_MUTEX "LockSolarMutex"
+#define SC_UNO_ODS_LOCK_SOLAR_MUTEX "ODSLockSolarMutex"
+#define SC_UNO_ODS_IMPORT_STYLES    "ODSImportStyles"
 
 #endif
 
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index 813190d..9128026 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -2104,6 +2104,7 @@ ScXMLImport::ScXMLImport(
     bNullDateSetted(false),
     bSelfImportingXMLSet(false),
     mbLockSolarMutex(true),
+    mbImportStyles(true),
     mbHasNewCondFormatData(false)
 {
     pStylesImportHelper = new ScMyStylesImportHelper(*this);
@@ -2256,6 +2257,9 @@ void ScXMLImport::initialize( const css::uno::Sequence<css::uno::Any>& aArgument
 
     if (xInfoSetInfo->hasPropertyByName(SC_UNO_ODS_LOCK_SOLAR_MUTEX))
         xInfoSet->getPropertyValue(SC_UNO_ODS_LOCK_SOLAR_MUTEX) >>= mbLockSolarMutex;
+
+    if (xInfoSetInfo->hasPropertyByName(SC_UNO_ODS_IMPORT_STYLES))
+        xInfoSet->getPropertyValue(SC_UNO_ODS_IMPORT_STYLES) >>= mbImportStyles;
 }
 
 SvXMLImportContext *ScXMLImport::CreateFontDeclsContext(const sal_uInt16 nPrefix, const OUString& rLocalName,
@@ -2765,6 +2769,9 @@ void ScXMLImport::SetType(uno::Reference <beans::XPropertySet>& rProperties,
                           const sal_Int16 nCellType,
                           const OUString& rCurrency)
 {
+    if (!mbImportStyles)
+        return;
+
     if ((nCellType != util::NumberFormat::TEXT) && (nCellType != util::NumberFormat::UNDEFINED))
     {
         if (rNumberFormat == -1)
@@ -2832,6 +2839,9 @@ void ScXMLImport::SetType(uno::Reference <beans::XPropertySet>& rProperties,
 
 void ScXMLImport::AddStyleRange(const table::CellRangeAddress& rCellRange)
 {
+    if (!mbImportStyles)
+        return;
+
     if (!xSheetCellRanges.is() && GetModel().is())
     {
         uno::Reference <lang::XMultiServiceFactory> xMultiServiceFactory(GetModel(), uno::UNO_QUERY);
@@ -2845,6 +2855,9 @@ void ScXMLImport::AddStyleRange(const table::CellRangeAddress& rCellRange)
 
 void ScXMLImport::SetStyleToRanges()
 {
+    if (!mbImportStyles)
+        return;
+
     if (!sPrevStyleName.isEmpty())
     {
         uno::Reference <beans::XPropertySet> xProperties (xSheetCellRanges, uno::UNO_QUERY);
@@ -2901,6 +2914,9 @@ void ScXMLImport::SetStyleToRanges()
 void ScXMLImport::SetStyleToRange(const ScRange& rRange, const OUString* pStyleName,
                                   const sal_Int16 nCellType, const OUString* pCurrency)
 {
+    if (!mbImportStyles)
+        return;
+
     if (sPrevStyleName.isEmpty())
     {
         nPrevCellType = nCellType;
diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx
index 660f3bd..1f44982 100644
--- a/sc/source/filter/xml/xmlimprt.hxx
+++ b/sc/source/filter/xml/xmlimprt.hxx
@@ -965,6 +965,7 @@ class ScXMLImport: public SvXMLImport, boost::noncopyable
     bool                    bNullDateSetted;
     bool                    bSelfImportingXMLSet;
     bool mbLockSolarMutex;
+    bool mbImportStyles;
     bool mbHasNewCondFormatData;
 
 
diff --git a/sc/source/filter/xml/xmlwrap.cxx b/sc/source/filter/xml/xmlwrap.cxx
index 159c3d8..640890b 100644
--- a/sc/source/filter/xml/xmlwrap.cxx
+++ b/sc/source/filter/xml/xmlwrap.cxx
@@ -345,6 +345,7 @@ bool ScXMLImportWrapper::Import( sal_uInt8 nMode, ErrCode& rError )
             ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
         { OUString("SourceStorage"), 0, cppu::UnoType<embed::XStorage>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
         { OUString(SC_UNO_ODS_LOCK_SOLAR_MUTEX), 0, getBooleanCppuType(), css::beans::PropertyAttribute::MAYBEVOID, 0 },
+        { OUString(SC_UNO_ODS_IMPORT_STYLES), 0, getBooleanCppuType(), css::beans::PropertyAttribute::MAYBEVOID, 0 },
         { OUString(), 0, css::uno::Type(), 0, 0 }
     };
     uno::Reference< beans::XPropertySet > xInfoSet( comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aImportInfoMap ) ) );
@@ -520,6 +521,10 @@ bool ScXMLImportWrapper::Import( sal_uInt8 nMode, ErrCode& rError )
     sal_uInt32 nDocRetval(0);
     if ((nMode & CONTENT) == CONTENT)
     {
+        if (mrDocShell.GetCreateMode() == SFX_CREATE_MODE_INTERNAL)
+            // We only need to import content for external link cache document.
+            xInfoSet->setPropertyValue(SC_UNO_ODS_IMPORT_STYLES, uno::makeAny(false));
+
         uno::Sequence<uno::Any> aDocArgs(4);
         uno::Any* pDocArgs = aDocArgs.getArray();
         pDocArgs[0] <<= xInfoSet;
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index a2a569e..38f900b 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -2372,7 +2372,7 @@ SfxObjectShellRef ScExternalRefManager::loadSrcDocument(sal_uInt16 nFileId, OUSt
     // To load encrypted documents with password, user interaction needs to be enabled.
     pMedium->UseInteractionHandler(mbUserInteractionEnabled);
 
-    ScDocShell* pNewShell = new ScDocShell(SFX_CREATE_MODE_INTERNAL);
+    ScDocShell* pNewShell = new ScDocShell(SFXMODEL_EXTERNAL_LINK);
     SfxObjectShellRef aRef = pNewShell;
 
     // increment the recursive link count of the source document.
diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx
index c97cb4a..29fe983 100644
--- a/sfx2/source/doc/objxtor.cxx
+++ b/sfx2/source/doc/objxtor.cxx
@@ -285,10 +285,14 @@ SfxObjectShell::SfxObjectShell( const sal_uInt64 i_nCreationFlags )
     :   pImp( new SfxObjectShell_Impl( *this ) )
     ,   pMedium(0)
     ,   pStyleSheetPool(0)
-    ,   eCreateMode( ( i_nCreationFlags & SFXMODEL_EMBEDDED_OBJECT ) ? SFX_CREATE_MODE_EMBEDDED : SFX_CREATE_MODE_STANDARD )
+    ,   eCreateMode(SFX_CREATE_MODE_STANDARD)
     ,   bHasName( false )
     ,   bIsInGenerateThumbnail ( false )
 {
+    if (i_nCreationFlags & SFXMODEL_EMBEDDED_OBJECT)
+        eCreateMode = SFX_CREATE_MODE_EMBEDDED;
+    else if (i_nCreationFlags & SFXMODEL_EXTERNAL_LINK)
+        eCreateMode = SFX_CREATE_MODE_INTERNAL;
 
     const bool bScriptSupport = ( i_nCreationFlags & SFXMODEL_DISABLE_EMBEDDED_SCRIPTS ) == 0;
     if ( !bScriptSupport )
commit 713c2f197b46cefe3d46f0658536af3be1c3842e
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue May 20 22:32:43 2014 -0400

    Finer grained ODS import mode selection.
    
    Change-Id: I18520837f8d25103bf8482a0204b8a7b7740feb1

diff --git a/sc/inc/xmlwrap.hxx b/sc/inc/xmlwrap.hxx
index e74c01a..b7ec5cd 100644
--- a/sc/inc/xmlwrap.hxx
+++ b/sc/inc/xmlwrap.hxx
@@ -72,10 +72,17 @@ class ScXMLImportWrapper
         ScMySharedData*& pSharedData);
 
 public:
+
+    static const sal_uInt8 STYLES   = 0x01;
+    static const sal_uInt8 CONTENT  = 0x02;
+    static const sal_uInt8 METADATA = 0x04;
+    static const sal_uInt8 SETTINGS = 0x08;
+    static const sal_uInt8 ALL      = STYLES | CONTENT | METADATA | SETTINGS;
+
     ScXMLImportWrapper(
         ScDocShell& rDocSh, SfxMedium* pM, const css::uno::Reference<css::embed::XStorage>& xStor );
 
-    bool Import(bool bStylesOnly, ErrCode& );
+    bool Import( sal_uInt8 nMode, ErrCode& rError );
     bool Export(bool bStylesOnly);
 
     const sc::ImportPostProcessData& GetImportPostProcessData() const;
diff --git a/sc/source/filter/xml/xmlwrap.cxx b/sc/source/filter/xml/xmlwrap.cxx
index cc1cbff..159c3d8 100644
--- a/sc/source/filter/xml/xmlwrap.cxx
+++ b/sc/source/filter/xml/xmlwrap.cxx
@@ -309,7 +309,7 @@ sal_uInt32 ScXMLImportWrapper::ImportFromComponent(const uno::Reference<uno::XCo
     return nReturn;
 }
 
-bool ScXMLImportWrapper::Import(bool bStylesOnly, ErrCode& nError)
+bool ScXMLImportWrapper::Import( sal_uInt8 nMode, ErrCode& rError )
 {
     uno::Reference<uno::XComponentContext> xContext = comphelper::getProcessComponentContext();
 
@@ -349,6 +349,7 @@ bool ScXMLImportWrapper::Import(bool bStylesOnly, ErrCode& nError)
     };
     uno::Reference< beans::XPropertySet > xInfoSet( comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aImportInfoMap ) ) );
 
+    // No need to lock solar mutex when calling from the wrapper.
     xInfoSet->setPropertyValue(SC_UNO_ODS_LOCK_SOLAR_MUTEX, uno::makeAny(false));
 
     // ---- get BuildId from parent container if available
@@ -403,14 +404,14 @@ bool ScXMLImportWrapper::Import(bool bStylesOnly, ErrCode& nError)
         }
     }
 
-    if (bStylesOnly)
-        xInfoSet->setPropertyValue("OrganizerMode", uno::makeAny(sal_True));
+    if (mrDocShell.GetCreateMode() == SFX_CREATE_MODE_ORGANIZER)
+        xInfoSet->setPropertyValue("OrganizerMode", uno::makeAny(true));
 
     xInfoSet->setPropertyValue( "SourceStorage", uno::Any( xStorage ) );
 
     bool bOasis = ( SotStorage::GetVersion( xStorage ) > SOFFICE_FILEFORMAT_60 );
 
-    if (!bStylesOnly && bOasis)
+    if ((nMode & METADATA) == METADATA && bOasis)
     {
         // RDF metadata: ODF >= 1.2
         try
@@ -428,34 +429,37 @@ bool ScXMLImportWrapper::Import(bool bStylesOnly, ErrCode& nError)
             ucb::InteractiveAugmentedIOException iaioe;
             if ( e.TargetException >>= iaioe )
             {
-                nError = SCERR_IMPORT_UNKNOWN;
+                rError = SCERR_IMPORT_UNKNOWN;
             }
             else
             {
-                nError = SCWARN_IMPORT_FEATURES_LOST;
+                rError = SCWARN_IMPORT_FEATURES_LOST;
             }
         }
         catch ( const uno::Exception &)
         {
-            nError = SCWARN_IMPORT_FEATURES_LOST;
+            rError = SCWARN_IMPORT_FEATURES_LOST;
         }
     }
 
     // #i103539#: always read meta.xml for generator
     sal_uInt32 nMetaRetval(0);
-    uno::Sequence<uno::Any> aMetaArgs(1);
-    uno::Any* pMetaArgs = aMetaArgs.getArray();
-    pMetaArgs[0] <<= xInfoSet;
+    if ((nMode & METADATA) == METADATA)
+    {
+        uno::Sequence<uno::Any> aMetaArgs(1);
+        uno::Any* pMetaArgs = aMetaArgs.getArray();
+        pMetaArgs[0] <<= xInfoSet;
 
-    SAL_INFO( "sc.filter", "meta import start" );
+        SAL_INFO( "sc.filter", "meta import start" );
 
-    nMetaRetval = ImportFromComponent(
-                            xContext, xModel, xXMLParser, aParserInput,
-                            bOasis ? OUString("com.sun.star.comp.Calc.XMLOasisMetaImporter")
-                            : OUString("com.sun.star.comp.Calc.XMLMetaImporter"),
-                            "meta.xml", "Meta.xml", aMetaArgs, false);
+        nMetaRetval = ImportFromComponent(
+                                xContext, xModel, xXMLParser, aParserInput,
+                                bOasis ? OUString("com.sun.star.comp.Calc.XMLOasisMetaImporter")
+                                : OUString("com.sun.star.comp.Calc.XMLMetaImporter"),
+                                "meta.xml", "Meta.xml", aMetaArgs, false);
 
-    SAL_INFO( "sc.filter", "meta import end" );
+        SAL_INFO( "sc.filter", "meta import end" );
+    }
 
     SvXMLGraphicHelper* pGraphicHelper = NULL;
     uno::Reference< document::XGraphicObjectResolver > xGrfContainer;
@@ -479,7 +483,7 @@ bool ScXMLImportWrapper::Import(bool bStylesOnly, ErrCode& nError)
     pStylesArgs[3] <<= xObjectResolver;
 
     sal_uInt32 nSettingsRetval(0);
-    if (!bStylesOnly)
+    if ((nMode & SETTINGS) == SETTINGS)
     {
         //  Settings must be loaded first because of the printer setting,
         //  which is needed in the page styles (paper tray).
@@ -500,6 +504,7 @@ bool ScXMLImportWrapper::Import(bool bStylesOnly, ErrCode& nError)
     }
 
     sal_uInt32 nStylesRetval(0);
+    if ((nMode & STYLES) == STYLES)
     {
         SAL_INFO( "sc.filter", "styles import start" );
 
@@ -513,7 +518,7 @@ bool ScXMLImportWrapper::Import(bool bStylesOnly, ErrCode& nError)
     }
 
     sal_uInt32 nDocRetval(0);
-    if (!bStylesOnly)
+    if ((nMode & CONTENT) == CONTENT)
     {
         uno::Sequence<uno::Any> aDocArgs(4);
         uno::Any* pDocArgs = aDocArgs.getArray();
@@ -542,34 +547,24 @@ bool ScXMLImportWrapper::Import(bool bStylesOnly, ErrCode& nError)
     if (xStatusIndicator.is())
         xStatusIndicator->end();
 
-    bool bRet(false);
-    if (bStylesOnly)
+    bool bRet = false;
+    if (nDocRetval)
     {
-        if (nStylesRetval)
-            nError = nStylesRetval;
-        else
+        rError = nDocRetval;
+        if (nDocRetval == SCWARN_IMPORT_RANGE_OVERFLOW ||
+            nDocRetval == SCWARN_IMPORT_ROW_OVERFLOW ||
+            nDocRetval == SCWARN_IMPORT_COLUMN_OVERFLOW ||
+            nDocRetval == SCWARN_IMPORT_SHEET_OVERFLOW)
             bRet = true;
     }
+    else if (nStylesRetval)
+        rError = nStylesRetval;
+    else if (nMetaRetval)
+        rError = nMetaRetval;
+    else if (nSettingsRetval)
+        rError = nSettingsRetval;
     else
-    {
-        if (nDocRetval)
-        {
-            nError = nDocRetval;
-            if (nDocRetval == SCWARN_IMPORT_RANGE_OVERFLOW ||
-                nDocRetval == SCWARN_IMPORT_ROW_OVERFLOW ||
-                nDocRetval == SCWARN_IMPORT_COLUMN_OVERFLOW ||
-                nDocRetval == SCWARN_IMPORT_SHEET_OVERFLOW)
-                bRet = true;
-        }
-        else if (nStylesRetval)
-            nError = nStylesRetval;
-        else if (nMetaRetval)
-            nError = nMetaRetval;
-        else if (nSettingsRetval)
-            nError = nSettingsRetval;
-        else
-            bRet = true;
-    }
+        bRet = true;
 
     // set BuildId on XModel for later OLE object loading
     if( xInfoSet.is() )
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index e85008d..7ed1836 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -441,13 +441,13 @@ bool ScDocShell::LoadXML( SfxMedium* pLoadMedium, const ::com::sun::star::uno::R
 
     ScXMLImportWrapper aImport(*this, pLoadMedium, xStor);
 
-    bool bRet(false);
+    bool bRet = false;
     ErrCode nError = ERRCODE_NONE;
     aDocument.EnableAdjustHeight(false);
-    if (GetCreateMode() != SFX_CREATE_MODE_ORGANIZER)
-        bRet = aImport.Import(false, nError);
+    if (GetCreateMode() == SFX_CREATE_MODE_ORGANIZER)
+        bRet = aImport.Import(ScXMLImportWrapper::STYLES, nError);
     else
-        bRet = aImport.Import(true, nError);
+        bRet = aImport.Import(ScXMLImportWrapper::ALL, nError);
 
     if ( nError )
         pLoadMedium->SetError( nError, OUString( OSL_LOG_PREFIX ) );
commit 34789dbff7cc51473bca407afa5bddaf1505975c
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue May 20 21:09:41 2014 -0400

    Let's use constant uno name for these.
    
    Change-Id: I5e34f4d7561ef7f4f7b8b3b4d7d06cca072831c7

diff --git a/sc/inc/unonames.hxx b/sc/inc/unonames.hxx
index 1cc71a9..689dcea 100644
--- a/sc/inc/unonames.hxx
+++ b/sc/inc/unonames.hxx
@@ -668,6 +668,8 @@
 
 #define SC_UNO_EMBED_FONTS     "EmbedFonts"
 
+#define SC_UNO_ODS_LOCK_SOLAR_MUTEX "LockSolarMutex"
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index 2aa6c14..813190d 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -69,6 +69,7 @@
 #include "editattributemap.hxx"
 #include "documentimport.hxx"
 #include "pivotsource.hxx"
+#include <unonames.hxx>
 
 #include <comphelper/extract.hxx>
 
@@ -2253,8 +2254,8 @@ void ScXMLImport::initialize( const css::uno::Sequence<css::uno::Any>& aArgument
     if (!xInfoSetInfo.is())
         return;
 
-    if (xInfoSetInfo->hasPropertyByName("LockSolarMutex"))
-        xInfoSet->getPropertyValue("LockSolarMutex") >>= mbLockSolarMutex;
+    if (xInfoSetInfo->hasPropertyByName(SC_UNO_ODS_LOCK_SOLAR_MUTEX))
+        xInfoSet->getPropertyValue(SC_UNO_ODS_LOCK_SOLAR_MUTEX) >>= mbLockSolarMutex;
 }
 
 SvXMLImportContext *ScXMLImport::CreateFontDeclsContext(const sal_uInt16 nPrefix, const OUString& rLocalName,
diff --git a/sc/source/filter/xml/xmlwrap.cxx b/sc/source/filter/xml/xmlwrap.cxx
index 6282b9f..cc1cbff 100644
--- a/sc/source/filter/xml/xmlwrap.cxx
+++ b/sc/source/filter/xml/xmlwrap.cxx
@@ -71,6 +71,7 @@
 #include "sheetdata.hxx"
 #include "XMLCodeNameProvider.hxx"
 #include <docsh.hxx>
+#include <unonames.hxx>
 
 using namespace com::sun::star;
 
@@ -343,12 +344,12 @@ bool ScXMLImportWrapper::Import(bool bStylesOnly, ErrCode& nError)
         { OUString("OrganizerMode"), 0, ::getBooleanCppuType(),
             ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
         { OUString("SourceStorage"), 0, cppu::UnoType<embed::XStorage>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
-        { OUString("LockSolarMutex"), 0, getBooleanCppuType(), css::beans::PropertyAttribute::MAYBEVOID, 0 },
+        { OUString(SC_UNO_ODS_LOCK_SOLAR_MUTEX), 0, getBooleanCppuType(), css::beans::PropertyAttribute::MAYBEVOID, 0 },
         { OUString(), 0, css::uno::Type(), 0, 0 }
     };
     uno::Reference< beans::XPropertySet > xInfoSet( comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aImportInfoMap ) ) );
 
-    xInfoSet->setPropertyValue("LockSolarMutex", uno::makeAny(false));
+    xInfoSet->setPropertyValue(SC_UNO_ODS_LOCK_SOLAR_MUTEX, uno::makeAny(false));
 
     // ---- get BuildId from parent container if available
 
commit 84db495da003ce9c4a93decd22ff220543586023
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue May 20 21:01:46 2014 -0400

    Let's not use ScDocument as a convenient "anything goes" storage place.
    
    Change-Id: I0ae2f44b89b0db915e78a9b07835000e843d016f

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 08f1ca4..e1aabf4 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -400,7 +400,6 @@ private:
     bool                bInsertingFromOtherDoc;
     bool                bLoadingMedium;
     bool                bImportingXML;      // special handling of formula text
-    bool                bXMLFromWrapper;    // distinguish ScXMLImportWrapper from external component
     bool                bCalcingAfterLoad;              // in CalcAfterLoad TRUE
     // don't construct/destruct listeners temporarily
     bool                bNoListening;
@@ -1754,8 +1753,6 @@ public:
     void            SetLoadingMedium( bool bVal );
     void            SetImportingXML( bool bVal );
     bool            IsImportingXML() const { return bImportingXML; }
-    void            SetXMLFromWrapper( bool bVal );
-    bool            IsXMLFromWrapper() const { return bXMLFromWrapper; }
     void            SetCalcingAfterLoad( bool bVal ) { bCalcingAfterLoad = bVal; }
     bool            IsCalcingAfterLoad() const { return bCalcingAfterLoad; }
     void            SetNoListening( bool bVal ) { bNoListening = bVal; }
diff --git a/sc/inc/xmlwrap.hxx b/sc/inc/xmlwrap.hxx
index 8bb78af..e74c01a 100644
--- a/sc/inc/xmlwrap.hxx
+++ b/sc/inc/xmlwrap.hxx
@@ -26,10 +26,6 @@
 #include "importfilterdata.hxx"
 #include <sal/types.h>
 
-class ScDocument;
-class SfxMedium;
-class ScMySharedData;
-
 #include <tools/errcode.hxx>
 
 namespace com { namespace sun { namespace star {
@@ -43,10 +39,16 @@ namespace com { namespace sun { namespace star {
         namespace sax { struct InputSource; class XParser; class XWriter; } }
 } } }
 
+class ScDocument;
+class SfxMedium;
+class ScMySharedData;
+class ScDocShell;
+
 class ScXMLImportWrapper
 {
     sc::ImportPostProcessData maPostProcessData;
 
+    ScDocShell& mrDocShell;
     ScDocument&     rDoc;
     SfxMedium*      pMedium;
     ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > xStorage;
@@ -70,7 +72,9 @@ class ScXMLImportWrapper
         ScMySharedData*& pSharedData);
 
 public:
-    ScXMLImportWrapper(ScDocument& rD, SfxMedium* pM, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >&);
+    ScXMLImportWrapper(
+        ScDocShell& rDocSh, SfxMedium* pM, const css::uno::Reference<css::embed::XStorage>& xStor );
+
     bool Import(bool bStylesOnly, ErrCode& );
     bool Export(bool bStylesOnly);
 
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index e0ed474..d65c42c 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -194,7 +194,6 @@ ScDocument::ScDocument( ScDocumentMode eMode, SfxObjectShell* pDocShell ) :
         bInsertingFromOtherDoc( false ),
         bLoadingMedium( false ),
         bImportingXML( false ),
-        bXMLFromWrapper( false ),
         bCalcingAfterLoad( false ),
         bNoListening( false ),
         mbIdleEnabled(true),
diff --git a/sc/source/core/data/documen9.cxx b/sc/source/core/data/documen9.cxx
index 4d7920e..c9fe85b 100644
--- a/sc/source/core/data/documen9.cxx
+++ b/sc/source/core/data/documen9.cxx
@@ -620,11 +620,6 @@ void ScDocument::SetImportingXML( bool bVal )
     SetLoadingMedium(bVal);
 }
 
-void ScDocument::SetXMLFromWrapper( bool bVal )
-{
-    bXMLFromWrapper = bVal;
-}
-
 rtl::Reference<SvxForbiddenCharactersTable> ScDocument::GetForbiddenCharacters()
 {
     return xForbiddenCharacters;
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index f95b2aa..2aa6c14 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -2102,7 +2102,7 @@ ScXMLImport::ScXMLImport(
     bRemoveLastChar(false),
     bNullDateSetted(false),
     bSelfImportingXMLSet(false),
-    bFromWrapper(false),
+    mbLockSolarMutex(true),
     mbHasNewCondFormatData(false)
 {
     pStylesImportHelper = new ScMyStylesImportHelper(*this);
@@ -2240,6 +2240,23 @@ ScXMLImport::~ScXMLImport() throw()
     delete pDetectiveOpArray;
 }
 
+void ScXMLImport::initialize( const css::uno::Sequence<css::uno::Any>& aArguments )
+        throw (css::uno::Exception, css::uno::RuntimeException, std::exception)
+{
+    SvXMLImport::initialize(aArguments);
+
+    uno::Reference<beans::XPropertySet> xInfoSet = getImportInfo();
+    if (!xInfoSet.is())
+        return;
+
+    uno::Reference<beans::XPropertySetInfo> xInfoSetInfo = xInfoSet->getPropertySetInfo();
+    if (!xInfoSetInfo.is())
+        return;
+
+    if (xInfoSetInfo->hasPropertyByName("LockSolarMutex"))
+        xInfoSet->getPropertyValue("LockSolarMutex") >>= mbLockSolarMutex;
+}
+
 SvXMLImportContext *ScXMLImport::CreateFontDeclsContext(const sal_uInt16 nPrefix, const OUString& rLocalName,
                                                         const uno::Reference<xml::sax::XAttributeList>& xAttrList)
 {
@@ -2964,8 +2981,6 @@ throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::R
     mpComp.reset(new ScCompiler(pDoc, ScAddress()));
     mpComp->SetGrammar(formula::FormulaGrammar::GRAM_ODFF);
 
-    bFromWrapper = pDoc->IsXMLFromWrapper();    // UnlockSolarMutex below still works normally
-
     uno::Reference<document::XActionLockable> xActionLockable(xDoc, uno::UNO_QUERY);
     if (xActionLockable.is())
         xActionLockable->addActionLock();
@@ -3284,7 +3299,7 @@ void ScXMLImport::LockSolarMutex()
 {
     // #i62677# When called from DocShell/Wrapper, the SolarMutex is already locked,
     // so there's no need to allocate (and later delete) the SolarMutexGuard.
-    if (bFromWrapper)
+    if (!mbLockSolarMutex)
     {
         DBG_TESTSOLARMUTEX();
         return;
diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx
index 97c4a5c..660f3bd 100644
--- a/sc/source/filter/xml/xmlimprt.hxx
+++ b/sc/source/filter/xml/xmlimprt.hxx
@@ -964,7 +964,7 @@ class ScXMLImport: public SvXMLImport, boost::noncopyable
     bool                    bRemoveLastChar;
     bool                    bNullDateSetted;
     bool                    bSelfImportingXMLSet;
-    bool                    bFromWrapper;           // called from ScDocShell / ScXMLImportWrapper?
+    bool mbLockSolarMutex;
     bool mbHasNewCondFormatData;
 
 
@@ -986,6 +986,10 @@ public:
 
     virtual ~ScXMLImport() throw();
 
+    // XInitialization
+    virtual void SAL_CALL initialize( const css::uno::Sequence<css::uno::Any>& aArguments )
+        throw (css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
+
     // namespace office
     // NB: in contrast to other CreateFooContexts, this particular one handles
     //     the root element (i.e. office:document-meta)
diff --git a/sc/source/filter/xml/xmlwrap.cxx b/sc/source/filter/xml/xmlwrap.cxx
index e99fcdb..6282b9f 100644
--- a/sc/source/filter/xml/xmlwrap.cxx
+++ b/sc/source/filter/xml/xmlwrap.cxx
@@ -70,12 +70,14 @@
 #include "docuno.hxx"
 #include "sheetdata.hxx"
 #include "XMLCodeNameProvider.hxx"
+#include <docsh.hxx>
 
 using namespace com::sun::star;
 
 
-ScXMLImportWrapper::ScXMLImportWrapper(ScDocument& rD, SfxMedium* pM, const uno::Reference < embed::XStorage >& xStor ) :
-    rDoc(rD),
+ScXMLImportWrapper::ScXMLImportWrapper( ScDocShell& rDocSh, SfxMedium* pM, const uno::Reference < embed::XStorage >& xStor ) :
+    mrDocShell(rDocSh),
+    rDoc(*rDocSh.GetDocument()),
     pMedium(pM),
     xStorage(xStor)
 {
@@ -321,303 +323,294 @@ bool ScXMLImportWrapper::Import(bool bStylesOnly, ErrCode& nError)
     uno::Reference<xml::sax::XParser> xXMLParser = xml::sax::Parser::create(xContext);
 
     // get filter
-    SfxObjectShell* pObjSh = rDoc.GetDocumentShell();
-    if ( pObjSh )
+    OUString sEmpty;
+    uno::Reference<frame::XModel> xModel = mrDocShell.GetModel();
+
+    /** property map for export info set */
+    comphelper::PropertyMapEntry const aImportInfoMap[] =
     {
-        OUString sEmpty;
-        uno::Reference<frame::XModel> xModel(pObjSh->GetModel());
+        { OUString("ProgressRange"), 0, ::cppu::UnoType<sal_Int32>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
+        { OUString("ProgressMax"), 0, ::cppu::UnoType<sal_Int32>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
+        { OUString("ProgressCurrent"), 0, ::cppu::UnoType<sal_Int32>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
+        { OUString("NumberStyles"), 0, cppu::UnoType<container::XNameAccess>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
+        { OUString("PrivateData"), 0, cppu::UnoType<uno::XInterface>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
+        { OUString("BaseURI"), 0, ::cppu::UnoType<OUString>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
+        { OUString("StreamRelPath"), 0, ::cppu::UnoType<OUString>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
+        { OUString("StreamName"), 0, ::cppu::UnoType<OUString>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
+        { OUString("BuildId"), 0, ::cppu::UnoType<OUString>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
+        { OUString("VBACompatibilityMode"), 0, ::getBooleanCppuType(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
+        { OUString("ScriptConfiguration"), 0, cppu::UnoType<container::XNameAccess>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
+        { OUString("OrganizerMode"), 0, ::getBooleanCppuType(),
+            ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
+        { OUString("SourceStorage"), 0, cppu::UnoType<embed::XStorage>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
+        { OUString("LockSolarMutex"), 0, getBooleanCppuType(), css::beans::PropertyAttribute::MAYBEVOID, 0 },
+        { OUString(), 0, css::uno::Type(), 0, 0 }
+    };
+    uno::Reference< beans::XPropertySet > xInfoSet( comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aImportInfoMap ) ) );
 
-        /** property map for export info set */
-        comphelper::PropertyMapEntry const aImportInfoMap[] =
-        {
-            { OUString("ProgressRange"), 0, ::cppu::UnoType<sal_Int32>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
-            { OUString("ProgressMax"), 0, ::cppu::UnoType<sal_Int32>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
-            { OUString("ProgressCurrent"), 0, ::cppu::UnoType<sal_Int32>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
-            { OUString("NumberStyles"), 0, cppu::UnoType<container::XNameAccess>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
-            { OUString("PrivateData"), 0, cppu::UnoType<uno::XInterface>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
-            { OUString("BaseURI"), 0, ::cppu::UnoType<OUString>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
-            { OUString("StreamRelPath"), 0, ::cppu::UnoType<OUString>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
-            { OUString("StreamName"), 0, ::cppu::UnoType<OUString>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
-            { OUString("BuildId"), 0, ::cppu::UnoType<OUString>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
-            { OUString("VBACompatibilityMode"), 0, ::getBooleanCppuType(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
-            { OUString("ScriptConfiguration"), 0, cppu::UnoType<container::XNameAccess>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
-            { OUString("OrganizerMode"), 0, ::getBooleanCppuType(),
-                ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
-            { OUString("SourceStorage"), 0, cppu::UnoType<embed::XStorage>::get(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
-            { OUString(), 0, css::uno::Type(), 0, 0 }
-        };
-        uno::Reference< beans::XPropertySet > xInfoSet( comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aImportInfoMap ) ) );
-
-        // ---- get BuildId from parent container if available
-
-        uno::Reference< container::XChild > xChild( xModel, uno::UNO_QUERY );
-        if( xChild.is() )
+    xInfoSet->setPropertyValue("LockSolarMutex", uno::makeAny(false));
+
+    // ---- get BuildId from parent container if available
+
+    uno::Reference< container::XChild > xChild( xModel, uno::UNO_QUERY );
+    if( xChild.is() )
+    {
+        uno::Reference< beans::XPropertySet > xParentSet( xChild->getParent(), uno::UNO_QUERY );
+        if( xParentSet.is() )
         {
-            uno::Reference< beans::XPropertySet > xParentSet( xChild->getParent(), uno::UNO_QUERY );
-            if( xParentSet.is() )
+            uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xParentSet->getPropertySetInfo() );
+            OUString sPropName("BuildId" );
+            if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName(sPropName) )
             {
-                uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xParentSet->getPropertySetInfo() );
-                OUString sPropName("BuildId" );
-                if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName(sPropName) )
-                {
-                    xInfoSet->setPropertyValue( sPropName, xParentSet->getPropertyValue(sPropName) );
-                }
+                xInfoSet->setPropertyValue( sPropName, xParentSet->getPropertyValue(sPropName) );
             }
         }
+    }
 
-        uno::Reference<task::XStatusIndicator> xStatusIndicator(GetStatusIndicator());
-        if (xStatusIndicator.is())
-        {
-            sal_Int32 nProgressRange(1000000);
-            xStatusIndicator->start(ScGlobal::GetRscString(STR_LOAD_DOC), nProgressRange);
-            xInfoSet->setPropertyValue("ProgressRange", uno::makeAny(nProgressRange));
-        }
+    uno::Reference<task::XStatusIndicator> xStatusIndicator = GetStatusIndicator();
+    if (xStatusIndicator.is())
+    {
+        sal_Int32 nProgressRange(1000000);
+        xStatusIndicator->start(ScGlobal::GetRscString(STR_LOAD_DOC), nProgressRange);
+        xInfoSet->setPropertyValue("ProgressRange", uno::makeAny(nProgressRange));
+    }
 
-        // Set base URI
-        OSL_ENSURE( pMedium, "There is no medium to get MediaDescriptor from!\n" );
-        OUString aBaseURL = pMedium ? pMedium->GetBaseURL() : OUString();
-        OUString sPropName("BaseURI");
-        xInfoSet->setPropertyValue( sPropName, uno::makeAny( aBaseURL ) );
+    // Set base URI
+    OSL_ENSURE( pMedium, "There is no medium to get MediaDescriptor from!\n" );
+    OUString aBaseURL = pMedium ? pMedium->GetBaseURL() : OUString();
+    OUString sPropName("BaseURI");
+    xInfoSet->setPropertyValue( sPropName, uno::makeAny( aBaseURL ) );
 
-        // TODO/LATER: do not do it for embedded links
-        OUString aName;
-        if( SFX_CREATE_MODE_EMBEDDED == pObjSh->GetCreateMode() )
+    // TODO/LATER: do not do it for embedded links
+    OUString aName;
+    if (SFX_CREATE_MODE_EMBEDDED == mrDocShell.GetCreateMode())
+    {
+        if ( pMedium && pMedium->GetItemSet() )
         {
-            if ( pMedium && pMedium->GetItemSet() )
-            {
-                const SfxStringItem* pDocHierarchItem = static_cast<const SfxStringItem*>(
-                    pMedium->GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) );
-                if ( pDocHierarchItem )
-                    aName = pDocHierarchItem->GetValue();
-            }
-            else
-                aName = "dummyObjectName";
-
-            if( !aName.isEmpty() )
-            {
-                sPropName = "StreamRelPath";
-                xInfoSet->setPropertyValue( sPropName, uno::makeAny( aName ) );
-            }
+            const SfxStringItem* pDocHierarchItem = static_cast<const SfxStringItem*>(
+                pMedium->GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) );
+            if ( pDocHierarchItem )
+                aName = pDocHierarchItem->GetValue();
         }
+        else
+            aName = "dummyObjectName";
 
-        if (bStylesOnly)
+        if( !aName.isEmpty() )
         {
-            OUString const sOrganizerMode(
-                "OrganizerMode");
-            xInfoSet->setPropertyValue(sOrganizerMode, uno::makeAny(sal_True));
+            sPropName = "StreamRelPath";
+            xInfoSet->setPropertyValue( sPropName, uno::makeAny( aName ) );
         }
+    }
 
-        xInfoSet->setPropertyValue( "SourceStorage", uno::Any( xStorage ) );
+    if (bStylesOnly)
+        xInfoSet->setPropertyValue("OrganizerMode", uno::makeAny(sal_True));
 
-        bool bOasis = ( SotStorage::GetVersion( xStorage ) > SOFFICE_FILEFORMAT_60 );
+    xInfoSet->setPropertyValue( "SourceStorage", uno::Any( xStorage ) );
+
+    bool bOasis = ( SotStorage::GetVersion( xStorage ) > SOFFICE_FILEFORMAT_60 );
 
-        if (!bStylesOnly && bOasis)
+    if (!bStylesOnly && bOasis)
+    {
+        // RDF metadata: ODF >= 1.2
+        try
         {
-            // RDF metadata: ODF >= 1.2
-            try
+            const uno::Reference< rdf::XDocumentMetadataAccess > xDMA(
+                xModel, uno::UNO_QUERY_THROW );
+            const uno::Reference< rdf::XURI > xBaseURI(
+                ::sfx2::createBaseURI( xContext, xStorage, aBaseURL, aName ) );
+            uno::Reference<task::XInteractionHandler> xHandler =
+                mrDocShell.GetMedium()->GetInteractionHandler();
+            xDMA->loadMetadataFromStorage( xStorage, xBaseURI, xHandler );
+        }
+        catch ( const lang::WrappedTargetException & e)
+        {
+            ucb::InteractiveAugmentedIOException iaioe;
+            if ( e.TargetException >>= iaioe )
             {
-                const uno::Reference< rdf::XDocumentMetadataAccess > xDMA(
-                    xModel, uno::UNO_QUERY_THROW );
-                const uno::Reference< rdf::XURI > xBaseURI(
-                    ::sfx2::createBaseURI( xContext, xStorage, aBaseURL, aName ) );
-                const uno::Reference< task::XInteractionHandler > xHandler(
-                    pObjSh->GetMedium()->GetInteractionHandler() );
-                xDMA->loadMetadataFromStorage( xStorage, xBaseURI, xHandler );
+                nError = SCERR_IMPORT_UNKNOWN;
             }
-            catch ( const lang::WrappedTargetException & e)
-            {
-                ucb::InteractiveAugmentedIOException iaioe;
-                if ( e.TargetException >>= iaioe )
-                {
-                    nError = SCERR_IMPORT_UNKNOWN;
-                }
-                else
-                {
-                    nError = SCWARN_IMPORT_FEATURES_LOST;
-                }
-            }
-            catch ( const uno::Exception &)
+            else
             {
                 nError = SCWARN_IMPORT_FEATURES_LOST;
             }
         }
+        catch ( const uno::Exception &)
+        {
+            nError = SCWARN_IMPORT_FEATURES_LOST;
+        }
+    }
 
-        // #i103539#: always read meta.xml for generator
-        sal_uInt32 nMetaRetval(0);
-        uno::Sequence<uno::Any> aMetaArgs(1);
-        uno::Any* pMetaArgs = aMetaArgs.getArray();
-        pMetaArgs[0] <<= xInfoSet;
-
-        SAL_INFO( "sc.filter", "meta import start" );
-
-        nMetaRetval = ImportFromComponent(
-                                xContext, xModel, xXMLParser, aParserInput,
-                                bOasis ? OUString("com.sun.star.comp.Calc.XMLOasisMetaImporter")
-                                : OUString("com.sun.star.comp.Calc.XMLMetaImporter"),
-                                "meta.xml", "Meta.xml", aMetaArgs, false);
-
-        SAL_INFO( "sc.filter", "meta import end" );
+    // #i103539#: always read meta.xml for generator
+    sal_uInt32 nMetaRetval(0);
+    uno::Sequence<uno::Any> aMetaArgs(1);
+    uno::Any* pMetaArgs = aMetaArgs.getArray();
+    pMetaArgs[0] <<= xInfoSet;
 
-        SvXMLGraphicHelper* pGraphicHelper = NULL;
-        uno::Reference< document::XGraphicObjectResolver > xGrfContainer;
+    SAL_INFO( "sc.filter", "meta import start" );
 
-        uno::Reference< document::XEmbeddedObjectResolver > xObjectResolver;
-        SvXMLEmbeddedObjectHelper *pObjectHelper = NULL;
+    nMetaRetval = ImportFromComponent(
+                            xContext, xModel, xXMLParser, aParserInput,
+                            bOasis ? OUString("com.sun.star.comp.Calc.XMLOasisMetaImporter")
+                            : OUString("com.sun.star.comp.Calc.XMLMetaImporter"),
+                            "meta.xml", "Meta.xml", aMetaArgs, false);
 
-        if( xStorage.is() )
-        {
-            pGraphicHelper = SvXMLGraphicHelper::Create( xStorage, GRAPHICHELPER_MODE_READ );
-            xGrfContainer = pGraphicHelper;
+    SAL_INFO( "sc.filter", "meta import end" );
 
-            if( pObjSh )
-            {
-                pObjectHelper = SvXMLEmbeddedObjectHelper::Create(xStorage, *pObjSh, EMBEDDEDOBJECTHELPER_MODE_READ, false );
-                xObjectResolver = pObjectHelper;
-            }
-        }
-        uno::Sequence<uno::Any> aStylesArgs(4);
-        uno::Any* pStylesArgs = aStylesArgs.getArray();
-        pStylesArgs[0] <<= xInfoSet;
-        pStylesArgs[1] <<= xGrfContainer;
-        pStylesArgs[2] <<= xStatusIndicator;
-        pStylesArgs[3] <<= xObjectResolver;
-
-        sal_uInt32 nSettingsRetval(0);
-        if (!bStylesOnly)
-        {
-            //  Settings must be loaded first because of the printer setting,
-            //  which is needed in the page styles (paper tray).
+    SvXMLGraphicHelper* pGraphicHelper = NULL;
+    uno::Reference< document::XGraphicObjectResolver > xGrfContainer;
 
-            uno::Sequence<uno::Any> aSettingsArgs(1);
-            uno::Any* pSettingsArgs = aSettingsArgs.getArray();
-            pSettingsArgs[0] <<= xInfoSet;
+    uno::Reference< document::XEmbeddedObjectResolver > xObjectResolver;
+    SvXMLEmbeddedObjectHelper *pObjectHelper = NULL;
 
-            SAL_INFO( "sc.filter", "settings import start" );
+    if( xStorage.is() )
+    {
+        pGraphicHelper = SvXMLGraphicHelper::Create( xStorage, GRAPHICHELPER_MODE_READ );
+        xGrfContainer = pGraphicHelper;
 
-            nSettingsRetval = ImportFromComponent(
-                                xContext, xModel, xXMLParser, aParserInput,
-                                bOasis ? OUString("com.sun.star.comp.Calc.XMLOasisSettingsImporter")
-                                       : OUString("com.sun.star.comp.Calc.XMLSettingsImporter"),
-                                "settings.xml", sEmpty, aSettingsArgs, false);
+        pObjectHelper = SvXMLEmbeddedObjectHelper::Create(xStorage, mrDocShell, EMBEDDEDOBJECTHELPER_MODE_READ, false);
+        xObjectResolver = pObjectHelper;
+    }
+    uno::Sequence<uno::Any> aStylesArgs(4);
+    uno::Any* pStylesArgs = aStylesArgs.getArray();
+    pStylesArgs[0] <<= xInfoSet;
+    pStylesArgs[1] <<= xGrfContainer;
+    pStylesArgs[2] <<= xStatusIndicator;
+    pStylesArgs[3] <<= xObjectResolver;
+
+    sal_uInt32 nSettingsRetval(0);
+    if (!bStylesOnly)
+    {
+        //  Settings must be loaded first because of the printer setting,
+        //  which is needed in the page styles (paper tray).
 
-            SAL_INFO( "sc.filter", "settings import end" );
-        }
+        uno::Sequence<uno::Any> aSettingsArgs(1);
+        uno::Any* pSettingsArgs = aSettingsArgs.getArray();
+        pSettingsArgs[0] <<= xInfoSet;
 
-        sal_uInt32 nStylesRetval(0);
-        {
-            SAL_INFO( "sc.filter", "styles import start" );
+        SAL_INFO( "sc.filter", "settings import start" );
 
-            nStylesRetval = ImportFromComponent(xContext, xModel, xXMLParser, aParserInput,
-                bOasis ? OUString("com.sun.star.comp.Calc.XMLOasisStylesImporter")
-                       : OUString("com.sun.star.comp.Calc.XMLStylesImporter"),
-                OUString("styles.xml"),
-                sEmpty, aStylesArgs, true);
+        nSettingsRetval = ImportFromComponent(
+                            xContext, xModel, xXMLParser, aParserInput,
+                            bOasis ? OUString("com.sun.star.comp.Calc.XMLOasisSettingsImporter")
+                                   : OUString("com.sun.star.comp.Calc.XMLSettingsImporter"),
+                            "settings.xml", sEmpty, aSettingsArgs, false);
 
-            SAL_INFO( "sc.filter", "styles import end" );
-        }
+        SAL_INFO( "sc.filter", "settings import end" );
+    }
 
-        sal_uInt32 nDocRetval(0);
-        if (!bStylesOnly)
-        {
-            uno::Sequence<uno::Any> aDocArgs(4);
-            uno::Any* pDocArgs = aDocArgs.getArray();
-            pDocArgs[0] <<= xInfoSet;
-            pDocArgs[1] <<= xGrfContainer;
-            pDocArgs[2] <<= xStatusIndicator;
-            pDocArgs[3] <<= xObjectResolver;
+    sal_uInt32 nStylesRetval(0);
+    {
+        SAL_INFO( "sc.filter", "styles import start" );
 
-            SAL_INFO( "sc.filter", "content import start" );
+        nStylesRetval = ImportFromComponent(xContext, xModel, xXMLParser, aParserInput,
+            bOasis ? OUString("com.sun.star.comp.Calc.XMLOasisStylesImporter")
+                   : OUString("com.sun.star.comp.Calc.XMLStylesImporter"),
+            OUString("styles.xml"),
+            sEmpty, aStylesArgs, true);
 
-            nDocRetval = ImportFromComponent(xContext, xModel, xXMLParser, aParserInput,
-                bOasis ? OUString("com.sun.star.comp.Calc.XMLOasisContentImporter")
-                       : OUString("com.sun.star.comp.Calc.XMLContentImporter"),
-                OUString("content.xml"),
-                OUString("Content.xml"), aDocArgs,
-                true);
+        SAL_INFO( "sc.filter", "styles import end" );
+    }
 
-            SAL_INFO( "sc.filter", "content import end" );
-        }
-        if( pGraphicHelper )
-            SvXMLGraphicHelper::Destroy( pGraphicHelper );
+    sal_uInt32 nDocRetval(0);
+    if (!bStylesOnly)
+    {
+        uno::Sequence<uno::Any> aDocArgs(4);
+        uno::Any* pDocArgs = aDocArgs.getArray();
+        pDocArgs[0] <<= xInfoSet;
+        pDocArgs[1] <<= xGrfContainer;
+        pDocArgs[2] <<= xStatusIndicator;
+        pDocArgs[3] <<= xObjectResolver;
+
+        SAL_INFO( "sc.filter", "content import start" );
+
+        nDocRetval = ImportFromComponent(xContext, xModel, xXMLParser, aParserInput,
+            bOasis ? OUString("com.sun.star.comp.Calc.XMLOasisContentImporter")
+                   : OUString("com.sun.star.comp.Calc.XMLContentImporter"),
+            OUString("content.xml"),
+            OUString("Content.xml"), aDocArgs,
+            true);
+
+        SAL_INFO( "sc.filter", "content import end" );
+    }
+    if( pGraphicHelper )
+        SvXMLGraphicHelper::Destroy( pGraphicHelper );
 
-        if( pObjectHelper )
-            SvXMLEmbeddedObjectHelper::Destroy( pObjectHelper );
+    if( pObjectHelper )
+        SvXMLEmbeddedObjectHelper::Destroy( pObjectHelper );
 
-        if (xStatusIndicator.is())
-            xStatusIndicator->end();
+    if (xStatusIndicator.is())
+        xStatusIndicator->end();
 
-        bool bRet(false);
-        if (bStylesOnly)
+    bool bRet(false);
+    if (bStylesOnly)
+    {
+        if (nStylesRetval)
+            nError = nStylesRetval;
+        else
+            bRet = true;
+    }
+    else
+    {
+        if (nDocRetval)
         {
-            if (nStylesRetval)
-                nError = nStylesRetval;
-            else
+            nError = nDocRetval;
+            if (nDocRetval == SCWARN_IMPORT_RANGE_OVERFLOW ||
+                nDocRetval == SCWARN_IMPORT_ROW_OVERFLOW ||
+                nDocRetval == SCWARN_IMPORT_COLUMN_OVERFLOW ||
+                nDocRetval == SCWARN_IMPORT_SHEET_OVERFLOW)
                 bRet = true;
         }
+        else if (nStylesRetval)
+            nError = nStylesRetval;
+        else if (nMetaRetval)
+            nError = nMetaRetval;
+        else if (nSettingsRetval)
+            nError = nSettingsRetval;
         else
+            bRet = true;
+    }
+
+    // set BuildId on XModel for later OLE object loading
+    if( xInfoSet.is() )
+    {
+        uno::Reference< beans::XPropertySet > xModelSet( xModel, uno::UNO_QUERY );
+        if( xModelSet.is() )
         {
-            if (nDocRetval)
+            uno::Reference< beans::XPropertySetInfo > xModelSetInfo( xModelSet->getPropertySetInfo() );
+            OUString sBuildPropName("BuildId" );
+            if( xModelSetInfo.is() && xModelSetInfo->hasPropertyByName(sBuildPropName) )
             {
-                nError = nDocRetval;
-                if (nDocRetval == SCWARN_IMPORT_RANGE_OVERFLOW ||
-                    nDocRetval == SCWARN_IMPORT_ROW_OVERFLOW ||
-                    nDocRetval == SCWARN_IMPORT_COLUMN_OVERFLOW ||
-                    nDocRetval == SCWARN_IMPORT_SHEET_OVERFLOW)
-                    bRet = true;
+                xModelSet->setPropertyValue( sBuildPropName, xInfoSet->getPropertyValue(sBuildPropName) );
             }
-            else if (nStylesRetval)
-                nError = nStylesRetval;
-            else if (nMetaRetval)
-                nError = nMetaRetval;
-            else if (nSettingsRetval)
-                nError = nSettingsRetval;
-            else
-                bRet = true;
         }
 
-        // set BuildId on XModel for later OLE object loading
-        if( xInfoSet.is() )
+        // Set Code Names
+        uno::Any aAny = xInfoSet->getPropertyValue("ScriptConfiguration");
+        uno::Reference <container::XNameAccess> xCodeNameAccess;
+        if( aAny >>= xCodeNameAccess )
+            XMLCodeNameProvider::set( xCodeNameAccess, &rDoc );
+
+        // VBA compatibility
+        bool bVBACompat = false;
+        if ( (xInfoSet->getPropertyValue("VBACompatibilityMode") >>= bVBACompat) && bVBACompat )
         {
-            uno::Reference< beans::XPropertySet > xModelSet( xModel, uno::UNO_QUERY );
-            if( xModelSet.is() )
+            /*  Set library container to VBA compatibility mode, this
+                forces loading the Basic project, which in turn creates the
+                VBA Globals object and does all related initialization. */
+            if ( xModelSet.is() ) try
             {
-                uno::Reference< beans::XPropertySetInfo > xModelSetInfo( xModelSet->getPropertySetInfo() );
-                OUString sBuildPropName("BuildId" );
-                if( xModelSetInfo.is() && xModelSetInfo->hasPropertyByName(sBuildPropName) )
-                {
-                    xModelSet->setPropertyValue( sBuildPropName, xInfoSet->getPropertyValue(sBuildPropName) );
-                }
+                uno::Reference< script::vba::XVBACompatibility > xVBACompat( xModelSet->getPropertyValue(
+                    OUString( "BasicLibraries" ) ), uno::UNO_QUERY_THROW );
+                xVBACompat->setVBACompatibilityMode( sal_True );
             }
-
-            // Set Code Names
-            uno::Any aAny = xInfoSet->getPropertyValue("ScriptConfiguration");
-            uno::Reference <container::XNameAccess> xCodeNameAccess;
-            if( aAny >>= xCodeNameAccess )
-                XMLCodeNameProvider::set( xCodeNameAccess, &rDoc );
-
-            // VBA compatibility
-            bool bVBACompat = false;
-            if ( (xInfoSet->getPropertyValue("VBACompatibilityMode") >>= bVBACompat) && bVBACompat )
+            catch( const uno::Exception& )
             {
-                /*  Set library container to VBA compatibility mode, this
-                    forces loading the Basic project, which in turn creates the
-                    VBA Globals object and does all related initialization. */
-                if ( xModelSet.is() ) try
-                {
-                    uno::Reference< script::vba::XVBACompatibility > xVBACompat( xModelSet->getPropertyValue(
-                        OUString( "BasicLibraries" ) ), uno::UNO_QUERY_THROW );
-                    xVBACompat->setVBACompatibilityMode( sal_True );
-                }
-                catch( const uno::Exception& )
-                {
-                }
             }
         }
-
-        // Don't test bStylesRetval and bMetaRetval, because it could be an older file which not contain such streams
-        return bRet;//!bStylesOnly ? bDocRetval : bStylesRetval;
     }
-    return false;
+
+    // Don't test bStylesRetval and bMetaRetval, because it could be an older file which not contain such streams
+    return bRet;//!bStylesOnly ? bDocRetval : bStylesRetval;
 }
 
 static bool lcl_HasValidStream(ScDocument& rDoc)
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 2cc729e..e85008d 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -439,12 +439,7 @@ bool ScDocShell::LoadXML( SfxMedium* pLoadMedium, const ::com::sun::star::uno::R
 
     BeforeXMLLoading();
 
-    // #i62677# BeforeXMLLoading is also called from ScXMLImport::startDocument when invoked
-    // from an external component. The XMLFromWrapper flag is only set here, when called
-    // through ScDocShell.
-    aDocument.SetXMLFromWrapper( true );
-
-    ScXMLImportWrapper aImport( aDocument, pLoadMedium, xStor );
+    ScXMLImportWrapper aImport(*this, pLoadMedium, xStor);
 
     bool bRet(false);
     ErrCode nError = ERRCODE_NONE;
@@ -508,7 +503,6 @@ bool ScDocShell::LoadXML( SfxMedium* pLoadMedium, const ::com::sun::star::uno::R
         aDocument.Broadcast(ScHint(SC_HINT_DATACHANGED, BCA_BRDCST_ALWAYS));
     }
 
-    aDocument.SetXMLFromWrapper( false );
     AfterXMLLoading(bRet);
 
     aDocument.EnableAdjustHeight(true);
@@ -519,7 +513,7 @@ bool ScDocShell::SaveXML( SfxMedium* pSaveMedium, const ::com::sun::star::uno::R
 {
     aDocument.EnableIdle(false);
 
-    ScXMLImportWrapper aImport( aDocument, pSaveMedium, xStor );
+    ScXMLImportWrapper aImport(*this, pSaveMedium, xStor);
     bool bRet(false);
     if (GetCreateMode() != SFX_CREATE_MODE_ORGANIZER)
         bRet = aImport.Export(false);
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index 9f6b657..a2a569e 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -1921,7 +1921,6 @@ ScExternalRefCache::TokenArrayRef ScExternalRefManager::getDoubleRefTokens(
 
         // Put the data into cache.
         putRangeDataIntoCache(maRefCache, pArray, nFileId, rTabName, aCacheData, rRange, aDataRange);
-        fprintf(stdout, "ScExternalRefManager::getDoubleRefTokens:   in memory!\n");
         return pArray;
     }
 
@@ -1929,11 +1928,8 @@ ScExternalRefCache::TokenArrayRef ScExternalRefManager::getDoubleRefTokens(
     ScExternalRefCache::TokenArrayRef pArray =
         maRefCache.getCellRangeData(nFileId, rTabName, rRange);
     if (pArray)
-    {
         // Cache hit !
-        fprintf(stdout, "ScExternalRefManager::getDoubleRefTokens:   cached!\n");
         return pArray;
-    }
 
     pSrcDoc = getSrcDocument(nFileId);
     if (!pSrcDoc)
commit 1df232139353d166014d7f73ea2423e6930ad348
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue May 20 14:24:44 2014 -0400

    Turn the mouse cursor to the "wait hand" during the external link update.
    
    Change-Id: I983127828b28c72dd12d4778b88051964e9bceaa

diff --git a/sc/inc/scopetools.hxx b/sc/inc/scopetools.hxx
index 443ceaf..785fd70 100644
--- a/sc/inc/scopetools.hxx
+++ b/sc/inc/scopetools.hxx
@@ -13,6 +13,7 @@
 #include "scdllapi.h"
 
 class ScDocument;
+class Window;
 
 namespace sc {
 
@@ -55,6 +56,14 @@ public:
     ~IdleSwitch();
 };
 
+class WaitPointerSwitch
+{
+    Window* mpFrameWin;
+public:
+    WaitPointerSwitch(Window* pWin);
+    ~WaitPointerSwitch();
+};
+
 }
 
 #endif
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index e8ce20c..1247563 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -87,6 +87,7 @@
 #include "globalnames.hxx"
 #include "stringutil.hxx"
 #include <documentlinkmgr.hxx>
+#include <scopetools.hxx>
 
 #include <boost/scoped_ptr.hpp>
 
@@ -802,6 +803,8 @@ void ScDocument::UpdateExternalRefLinks(Window* pWin)
             aRefLinks.push_back(pRefLink);
     }
 
+    sc::WaitPointerSwitch aWaitSwitch(pWin);
+
     pExternalRefMgr->enableDocTimer(false);
     ScProgress aProgress(GetDocumentShell(), ScResId(SCSTR_UPDATE_EXTDOCS).toString(), aRefLinks.size());
     for (size_t i = 0, n = aRefLinks.size(); i < n; ++i)
diff --git a/sc/source/core/tool/scopetools.cxx b/sc/source/core/tool/scopetools.cxx
index 96f4458..0664219 100644
--- a/sc/source/core/tool/scopetools.cxx
+++ b/sc/source/core/tool/scopetools.cxx
@@ -9,6 +9,7 @@
 
 #include "scopetools.hxx"
 #include "document.hxx"
+#include <vcl/window.hxx>
 
 namespace sc {
 
@@ -56,6 +57,19 @@ IdleSwitch::~IdleSwitch()
     mrDoc.EnableIdle(mbOldValue);
 }
 
+WaitPointerSwitch::WaitPointerSwitch(Window* pWin) :
+    mpFrameWin(pWin)
+{
+    if (mpFrameWin)
+        mpFrameWin->EnterWait();
+}
+
+WaitPointerSwitch::~WaitPointerSwitch()
+{
+    if (mpFrameWin)
+        mpFrameWin->LeaveWait();
+}
+
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 8d5d877dc94ba5edfc7587b957ca5a00725d434b
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue May 20 13:57:13 2014 -0400

    cp#1000072: Populate cache tables when updating all external links.
    
    This way, even after the loaded doc shells get purged due to timeout,
    we won't reload those external documents from disk again.  One caveat
    is that we currently don't pre-populate empty cells even if they are
    referenced by the host document.
    
    Change-Id: I1de2987836bf2fc5d9d7044b406fb99faa534164

diff --git a/sc/inc/externalrefmgr.hxx b/sc/inc/externalrefmgr.hxx
index bbb3094..9bcc64d 100644
--- a/sc/inc/externalrefmgr.hxx
+++ b/sc/inc/externalrefmgr.hxx
@@ -55,6 +55,12 @@ class SharedStringPool;
 
 }
 
+namespace sc {
+
+class ColumnSpanSet;
+
+}
+
 class ScExternalRefLink : public ::sfx2::SvBaseLink
 {
 public:
@@ -145,6 +151,8 @@ public:
         Table();
         ~Table();
 
+        void clear();
+
         /**
          * Add cell value to the cache.
          *
@@ -268,6 +276,13 @@ public:
     void setAllCacheTableReferencedStati( bool bReferenced );
     bool areAllCacheTablesReferenced() const;
 
+    /**
+     * Collect all cached non-empty cell positions, inferred directly from the
+     * cached data, not the cached range metadata stored separately in the
+     * Table.
+     */
+    void getAllCachedDataSpans( sal_uInt16 nFileId, sc::ColumnSpanSet& rSet ) const;
+
 private:
     struct ReferencedStatus
     {
@@ -295,8 +310,17 @@ public:
     ScExternalRefCache::TableTypeRef getCacheTable(sal_uInt16 nFileId, size_t nTabIndex) const;
     ScExternalRefCache::TableTypeRef getCacheTable(sal_uInt16 nFileId, const OUString& rTabName, bool bCreateNew, size_t* pnIndex);
 
+    /**
+     * Clear all caches including the cache tables.
+     */
     void clearCache(sal_uInt16 nFileId);
 
+    /**
+     * Clear all caches but keep the tables.  All cache tables will be empty
+     * after the call, but the tables will not be removed.
+     */
+    void clearCacheTables(sal_uInt16 nFileId);
+
 private:
     struct RangeHash
     {
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index 525bbce..9f6b657 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -53,6 +53,8 @@
 #include <vcl/msgbox.hxx>
 #include "stringutil.hxx"
 #include "scmatrix.hxx"
+#include <columnspanset.hxx>
+#include <column.hxx>
 
 #include <memory>
 #include <algorithm>
@@ -254,6 +256,13 @@ ScExternalRefCache::Table::~Table()
 {
 }
 
+void ScExternalRefCache::Table::clear()
+{
+    maRows.clear();
+    maCachedRanges.RemoveAll();
+    meReferenced = REFERENCED_MARKED;
+}
+
 void ScExternalRefCache::Table::setReferencedFlag( ScExternalRefCache::Table::ReferencedFlag eFlag )
 {
     meReferenced = eFlag;
@@ -445,9 +454,6 @@ void ScExternalRefCache::Table::setCachedCellRange(SCCOL nCol1, SCROW nRow1, SCC
         maCachedRanges.Append(aRange);
     else
         maCachedRanges.Join(aRange);
-
-    OUString aStr;
-    maCachedRanges.Format(aStr, SCA_VALID);
 }
 
 void ScExternalRefCache::Table::setWholeTableCached()
@@ -1106,6 +1112,35 @@ bool ScExternalRefCache::areAllCacheTablesReferenced() const
     return maReferenced.mbAllReferenced;
 }
 
+void ScExternalRefCache::getAllCachedDataSpans( sal_uInt16 nFileId, sc::ColumnSpanSet& rSet ) const
+{
+    const DocItem* pDocItem = getDocItem(nFileId);
+    if (!pDocItem)
+        // This document is not cached.
+        return;
+
+    const std::vector<TableTypeRef>& rTables = pDocItem->maTables;
+    for (size_t nTab = 0, nTabCount = rTables.size(); nTab < nTabCount; ++nTab)
+    {
+        const Table& rTable = *rTables[nTab];
+        std::vector<SCROW> aRows;
+        rTable.getAllRows(aRows);
+        std::vector<SCROW>::const_iterator itRow = aRows.begin(), itRowEnd = aRows.end();
+        for (; itRow != itRowEnd; ++itRow)
+        {
+            SCROW nRow = *itRow;
+            std::vector<SCCOL> aCols;
+            rTable.getAllCols(nRow, aCols);
+            std::vector<SCCOL>::const_iterator itCol = aCols.begin(), itColEnd = aCols.end();
+            for (; itCol != itColEnd; ++itCol)
+            {
+                SCCOL nCol = *itCol;
+                rSet.set(nTab, nCol, nRow, true);
+            }
+        }
+    }
+}
+
 ScExternalRefCache::ReferencedStatus::ReferencedStatus() :
     mbAllReferenced(false)
 {
@@ -1199,6 +1234,28 @@ void ScExternalRefCache::clearCache(sal_uInt16 nFileId)
     maDocs.erase(nFileId);
 }
 
+void ScExternalRefCache::clearCacheTables(sal_uInt16 nFileId)
+{
+    osl::MutexGuard aGuard(&maMtxDocs);
+    DocItem* pDocItem = getDocItem(nFileId);
+    if (!pDocItem)
+        // This document is not cached at all.
+        return;
+
+    // Clear all cache table content, but keep the tables.
+    std::vector<TableTypeRef>& rTabs = pDocItem->maTables;
+    for (size_t i = 0, n = rTabs.size(); i < n; ++i)
+    {
+        Table& rTab = *rTabs[i];
+        rTab.clear();
+    }
+
+    // Clear the external range name caches.
+    pDocItem->maRangeNames.clear();
+    pDocItem->maRangeArrays.clear();
+    pDocItem->maRealRangeNameMap.clear();
+}
+
 ScExternalRefCache::DocItem* ScExternalRefCache::getDocItem(sal_uInt16 nFileId) const
 {
     osl::MutexGuard aGuard(&maMtxDocs);
@@ -1864,6 +1921,7 @@ ScExternalRefCache::TokenArrayRef ScExternalRefManager::getDoubleRefTokens(
 
         // Put the data into cache.
         putRangeDataIntoCache(maRefCache, pArray, nFileId, rTabName, aCacheData, rRange, aDataRange);
+        fprintf(stdout, "ScExternalRefManager::getDoubleRefTokens:   in memory!\n");
         return pArray;
     }
 
@@ -1871,8 +1929,11 @@ ScExternalRefCache::TokenArrayRef ScExternalRefManager::getDoubleRefTokens(
     ScExternalRefCache::TokenArrayRef pArray =
         maRefCache.getCellRangeData(nFileId, rTabName, rRange);
     if (pArray)
+    {
         // Cache hit !
+        fprintf(stdout, "ScExternalRefManager::getDoubleRefTokens:   cached!\n");
         return pArray;
+    }
 
     pSrcDoc = getSrcDocument(nFileId);
     if (!pSrcDoc)
@@ -2580,8 +2641,100 @@ void ScExternalRefManager::clearCache(sal_uInt16 nFileId)
     maRefCache.clearCache(nFileId);
 }
 
+namespace {
+
+class RefCacheFiller : public sc::ColumnSpanSet::ColumnAction
+{
+    svl::SharedStringPool& mrStrPool;
+
+    ScExternalRefCache& mrRefCache;
+    ScExternalRefCache::TableTypeRef mpRefTab;
+    sal_uInt16 mnFileId;
+    ScColumn* mpCurCol;
+    sc::ColumnBlockConstPosition maBlockPos;
+
+public:
+    RefCacheFiller( svl::SharedStringPool& rStrPool, ScExternalRefCache& rRefCache, sal_uInt16 nFileId ) :
+        mrStrPool(rStrPool), mrRefCache(rRefCache), mnFileId(nFileId), mpCurCol(NULL) {}
+
+    virtual void startColumn( ScColumn* pCol )
+    {
+        mpCurCol = pCol;
+        if (!mpCurCol)
+            return;
+
+        mpCurCol->InitBlockPosition(maBlockPos);
+        mpRefTab = mrRefCache.getCacheTable(mnFileId, mpCurCol->GetTab());
+    }
+
+    virtual void execute( SCROW nRow1, SCROW nRow2, bool bVal )
+    {
+        if (!mpCurCol || !bVal)
+            return;
+
+        if (!mpRefTab)
+            return;
+
+        for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
+        {
+            ScExternalRefCache::TokenRef pTok;
+            ScRefCellValue aCell = mpCurCol->GetCellValue(maBlockPos, nRow);
+            switch (aCell.meType)
+            {
+                case CELLTYPE_STRING:
+                case CELLTYPE_EDIT:
+                {
+                    OUString aStr = aCell.getString(&mpCurCol->GetDoc());
+                    svl::SharedString aSS = mrStrPool.intern(aStr);
+                    pTok.reset(new formula::FormulaStringToken(aSS));
+                }
+                break;
+                case CELLTYPE_VALUE:
+                    pTok.reset(new formula::FormulaDoubleToken(aCell.mfValue));
+                break;
+                case CELLTYPE_FORMULA:
+                {
+                    sc::FormulaResultValue aRes = aCell.mpFormula->GetResult();
+                    switch (aRes.meType)
+                    {
+                        case sc::FormulaResultValue::Value:
+                            pTok.reset(new formula::FormulaDoubleToken(aRes.mfValue));
+                        break;
+                        case sc::FormulaResultValue::String:
+                        {
+                            // Re-intern the string to the host document pool.
+                            svl::SharedString aInterned = mrStrPool.intern(aRes.maString.getString());
+                            pTok.reset(new formula::FormulaStringToken(aInterned));
+                        }
+                        break;
+                        case sc::FormulaResultValue::Error:
+                        case sc::FormulaResultValue::Invalid:
+                        default:
+                            pTok.reset(new FormulaErrorToken(errNoValue));
+                    }
+                }
+                break;
+                default:
+                    pTok.reset(new FormulaErrorToken(errNoValue));
+            }
+
+            if (pTok)
+            {
+                // Cache this cell.
+                mpRefTab->setCell(mpCurCol->GetCol(), nRow, pTok, mpCurCol->GetNumberFormat(nRow));
+                mpRefTab->setCachedCell(mpCurCol->GetCol(), nRow);
+            }
+        }
+    };
+};
+
+}
+
 bool ScExternalRefManager::refreshSrcDocument(sal_uInt16 nFileId)
 {
+    sc::ColumnSpanSet aCachedArea(false);
+    maRefCache.getAllCachedDataSpans(nFileId, aCachedArea);
+
     OUString aFilter;
     SfxObjectShellRef xDocShell;
     try
@@ -2594,8 +2747,15 @@ bool ScExternalRefManager::refreshSrcDocument(sal_uInt16 nFileId)
         // Failed to load the document.  Bail out.
         return false;
 
-    // Clear the existing cache, and store the loaded doc shell until it expires.
-    clearCache(nFileId);
+    ScDocShell& rDocSh = static_cast<ScDocShell&>(*xDocShell);
+    ScDocument* pSrcDoc = rDocSh.GetDocument();
+
+    // Clear the existing cache, and refill it.  Make sure we keep the
+    // existing cache table instances here.
+    maRefCache.clearCacheTables(nFileId);
+    RefCacheFiller aAction(mpDoc->GetSharedStringPool(), maRefCache, nFileId);
+    aCachedArea.executeColumnAction(*pSrcDoc, aAction);
+
     DocShellMap::iterator it = maDocShells.find(nFileId);
     if (it != maDocShells.end())
     {
commit 516bd94247ea24586885254ac716f4a5f90e5c73
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue May 20 10:41:03 2014 -0400

    Localize this string.
    
    Change-Id: I88b205d36eede5e63af46f8581896d980b6aa27d

diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc
index d350aad..2253aac 100644
--- a/sc/inc/sc.hrc
+++ b/sc/inc/sc.hrc
@@ -983,7 +983,8 @@
 #define STR_MID                 (STR_START + 431)
 #define STR_SOUTH               (STR_START + 432)
 #define STR_SUM                 (STR_START + 433)
-#define STR_END                 (STR_SUM)
+#define SCSTR_UPDATE_EXTDOCS    (STR_START + 434)
+#define STR_END                 (SCSTR_UPDATE_EXTDOCS)
 
 #define BMP_START               (STR_END)
 
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 6b2f028..e8ce20c 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -803,7 +803,7 @@ void ScDocument::UpdateExternalRefLinks(Window* pWin)
     }
 
     pExternalRefMgr->enableDocTimer(false);
-    ScProgress aProgress(GetDocumentShell(), "Updating external links", aRefLinks.size());
+    ScProgress aProgress(GetDocumentShell(), ScResId(SCSTR_UPDATE_EXTDOCS).toString(), aRefLinks.size());
     for (size_t i = 0, n = aRefLinks.size(); i < n; ++i)
     {
         aProgress.SetState(i+1);
diff --git a/sc/source/ui/src/scstring.src b/sc/source/ui/src/scstring.src
index 78d9541..b083fff 100644
--- a/sc/source/ui/src/scstring.src
+++ b/sc/source/ui/src/scstring.src
@@ -811,6 +811,11 @@ String SCSTR_EXTDOC_NOT_LOADED
     Text [ en-US ] = "The following external file could not be loaded. Data linked from this file did not get updated." ;
 };
 
+String SCSTR_UPDATE_EXTDOCS
+{
+    Text [ en-US ] = "Updating external links.";
+};
+
 String SCSTR_FORMULA_SYNTAX_CALC_A1
 {
     Text [ en-US ] = "Calc A1";
commit 65d026f39cff52c96be95871e16a3d6714203d2e
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue May 20 10:19:25 2014 -0400

    cp#1000072: Purge one document shell at a time, to avoid freeze.
    
    Import especially when we have a whole bunch of large-ish documents open
    in the background.
    
    Change-Id: I614e6daab3481c09dae47c8407497d77aec40480

diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 4563b02..6b2f028 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -806,7 +806,7 @@ void ScDocument::UpdateExternalRefLinks(Window* pWin)
     ScProgress aProgress(GetDocumentShell(), "Updating external links", aRefLinks.size());
     for (size_t i = 0, n = aRefLinks.size(); i < n; ++i)
     {
-        aProgress.SetState(i);
+        aProgress.SetState(i+1);
 
         ScExternalRefLink* pRefLink = aRefLinks[i];
         if (pRefLink->Update())
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index ded749f..525bbce 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -2796,19 +2796,20 @@ void ScExternalRefManager::notifyAllLinkListeners(sal_uInt16 nFileId, LinkUpdate
 
 void ScExternalRefManager::purgeStaleSrcDocument(sal_Int32 nTimeOut)
 {
-    DocShellMap aNewDocShells;
+    // To avoid potentially freezing Calc, we close one stale document at a time.
     DocShellMap::iterator itr = maDocShells.begin(), itrEnd = maDocShells.end();
     for (; itr != itrEnd; ++itr)
     {
         // in 100th of a second.
         sal_Int32 nSinceLastAccess = (Time( Time::SYSTEM ) - itr->second.maLastAccess).GetTime();
-        if (nSinceLastAccess < nTimeOut)
-            aNewDocShells.insert(*itr);
-        else
-            // Timed out.  Let's close this.
+        if (nSinceLastAccess >= nTimeOut)
+        {
+            // Timed out.  Let's close this, and exit the loop.
             itr->second.maShell->DoClose();
+            maDocShells.erase(itr);
+            break;
+        }
     }
-    maDocShells.swap(aNewDocShells);
 
     if (maDocShells.empty())
         maSrcDocTimer.Stop();
commit c28aadc7fcb1858acc2e59a875e0a4c9071681ed
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue May 20 00:59:29 2014 -0400

    cp#1000072: Stop the external doc shell timer while mass-updating.
    
    To prevent collision with the timer wanting to purge the doc cache
    while updating external links.
    
    Also, show progress bar, and make the timer interval and the document
    cache life span longer.
    
    Change-Id: I325984c8fa68425a2621cf8f9c016463291afc89

diff --git a/sc/inc/externalrefmgr.hxx b/sc/inc/externalrefmgr.hxx
index 1c7fcc1..bbb3094 100644
--- a/sc/inc/externalrefmgr.hxx
+++ b/sc/inc/externalrefmgr.hxx
@@ -689,6 +689,8 @@ public:
 
     void insertRefCell(sal_uInt16 nFileId, const ScAddress& rCell);
 
+    void enableDocTimer( bool bEnable );
+
 private:
     ScExternalRefManager();
     ScExternalRefManager(const ScExternalRefManager&);
@@ -822,6 +824,8 @@ private:
      */
     bool mbUserInteractionEnabled:1;
 
+    bool mbDocTimerEnabled:1;
+
     AutoTimer maSrcDocTimer;
     DECL_LINK(TimeOutHdl, AutoTimer*);
 };
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 316738a..4563b02 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -780,6 +780,9 @@ bool ScDocument::IsInLinkUpdate() const
 
 void ScDocument::UpdateExternalRefLinks(Window* pWin)
 {
+    if (!pExternalRefMgr.get())
+        return;
+
     sfx2::LinkManager* pMgr = GetDocLinkManager().getLinkManager(bAutoCalc);
     if (!pMgr)
         return;
@@ -788,33 +791,48 @@ void ScDocument::UpdateExternalRefLinks(Window* pWin)
     sal_uInt16 nCount = rLinks.size();
 
     bool bAny = false;
+
+    // Collect all the external ref links first.
+    std::vector<ScExternalRefLink*> aRefLinks;
     for (sal_uInt16 i = 0; i < nCount; ++i)
     {
         ::sfx2::SvBaseLink* pBase = *rLinks[i];
         ScExternalRefLink* pRefLink = dynamic_cast<ScExternalRefLink*>(pBase);
         if (pRefLink)
+            aRefLinks.push_back(pRefLink);
+    }
+
+    pExternalRefMgr->enableDocTimer(false);
+    ScProgress aProgress(GetDocumentShell(), "Updating external links", aRefLinks.size());
+    for (size_t i = 0, n = aRefLinks.size(); i < n; ++i)
+    {
+        aProgress.SetState(i);
+
+        ScExternalRefLink* pRefLink = aRefLinks[i];
+        if (pRefLink->Update())
         {
-            if (pRefLink->Update())
-                bAny = true;
-            else
-            {
-                // Update failed.  Notify the user.
-
-                OUString aFile;
-                pMgr->GetDisplayNames(pRefLink, NULL, &aFile, NULL, NULL);
-                // Decode encoded URL for display friendliness.
-                INetURLObject aUrl(aFile,INetURLObject::WAS_ENCODED);
-                aFile = aUrl.GetMainURL(INetURLObject::DECODE_UNAMBIGUOUS);
-
-                OUStringBuffer aBuf;
-                aBuf.append(OUString(ScResId(SCSTR_EXTDOC_NOT_LOADED)));
-                aBuf.appendAscii("\n\n");
-                aBuf.append(aFile);
-                ErrorBox aBox(pWin, WB_OK, aBuf.makeStringAndClear());
-                aBox.Execute();
-            }
+            bAny = true;
+            continue;
         }
+
+        // Update failed.  Notify the user.
+
+        OUString aFile;
+        pMgr->GetDisplayNames(pRefLink, NULL, &aFile, NULL, NULL);
+        // Decode encoded URL for display friendliness.
+        INetURLObject aUrl(aFile,INetURLObject::WAS_ENCODED);
+        aFile = aUrl.GetMainURL(INetURLObject::DECODE_UNAMBIGUOUS);
+
+        OUStringBuffer aBuf;
+        aBuf.append(OUString(ScResId(SCSTR_EXTDOC_NOT_LOADED)));
+        aBuf.appendAscii("\n\n");
+        aBuf.append(aFile);
+        ErrorBox aBox(pWin, WB_OK, aBuf.makeStringAndClear());
+        aBox.Execute();
     }
+
+    pExternalRefMgr->enableDocTimer(true);
+
     if (bAny)
     {
         TrackFormulas();
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index 549549a..ded749f 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -71,8 +71,8 @@ using ::std::list;
 using ::std::unary_function;
 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)
+#define SRCDOC_LIFE_SPAN     30000      // 5 minutes (in 100th of a sec)
+#define SRCDOC_SCAN_INTERVAL 1000*30    // every 30 seconds (in msec)
 
 namespace {
 
@@ -1537,7 +1537,8 @@ static ScTokenArray* lcl_fillEmptyMatrix(const ScRange& rRange)
 ScExternalRefManager::ScExternalRefManager(ScDocument* pDoc) :
     mpDoc(pDoc),
     mbInReferenceMarking(false),
-    mbUserInteractionEnabled(true)
+    mbUserInteractionEnabled(true),
+    mbDocTimerEnabled(true)
 {
     maSrcDocTimer.SetTimeoutHdl( LINK(this, ScExternalRefManager, TimeOutHdl) );
     maSrcDocTimer.SetTimeout(SRCDOC_SCAN_INTERVAL);
@@ -2009,6 +2010,27 @@ void ScExternalRefManager::insertRefCell(sal_uInt16 nFileId, const ScAddress& rC
         itr->second.insert(pCell);
 }
 
+void ScExternalRefManager::enableDocTimer( bool bEnable )
+{
+    if (mbDocTimerEnabled == bEnable)
+        return;
+
+    mbDocTimerEnabled = bEnable;
+    if (mbDocTimerEnabled)
+    {
+        if (!maDocShells.empty())
+        {
+            DocShellMap::iterator it = maDocShells.begin(), itEnd = maDocShells.end();
+            for (; it != itEnd; ++it)
+                it->second.maLastAccess = Time(Time::SYSTEM);
+
+            maSrcDocTimer.Start();
+        }
+    }
+    else
+        maSrcDocTimer.Stop();
+}
+
 void ScExternalRefManager::fillCellFormat(sal_uLong nFmtIndex, ScExternalRefCache::CellFormat* pFmt) const
 {
     if (!pFmt)
@@ -2331,7 +2353,7 @@ SfxObjectShellRef ScExternalRefManager::loadSrcDocument(sal_uInt16 nFileId, OUSt
 
 ScDocument* ScExternalRefManager::cacheNewDocShell( sal_uInt16 nFileId, SrcShell& rSrcShell )
 {
-    if (maDocShells.empty())
+    if (mbDocTimerEnabled && maDocShells.empty())
         // If this is the first source document insertion, start up the timer.
         maSrcDocTimer.Start();
 
commit 1b243b14e9715b7b7da6359b5b752ee6d8278731
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Mon May 19 23:42:05 2014 -0400

    cp#1000072: Load external documents when refreshing caches.
    
    Rather than just clearing the existing caches and loading the external
    documents on demand as the formula cells gets re-calculated.  This has two
    advantages: 1) when the loading itself fails, we can keep the existing cache
    rather than turning all affected cells to error cells, and 2) this prevents
    on-demand loading after the external linkes get refreshed, which can make
    scrolling very slow & painful.
    
    Change-Id: Ie8243f6f94c5e477964413ab83f6b4b746fe3220

diff --git a/sc/inc/externalrefmgr.hxx b/sc/inc/externalrefmgr.hxx
index 00b968d..1c7fcc1 100644
--- a/sc/inc/externalrefmgr.hxx
+++ b/sc/inc/externalrefmgr.hxx
@@ -599,7 +599,7 @@ public:
     const OUString* getRealTableName(sal_uInt16 nFileId, const OUString& rTabName) const;
     const OUString* getRealRangeName(sal_uInt16 nFileId, const OUString& rRangeName) const;
     void clearCache(sal_uInt16 nFileId);
-    void refreshNames(sal_uInt16 nFileId);
+    bool refreshSrcDocument(sal_uInt16 nFileId);
     void breakLink(sal_uInt16 nFileId);
     void switchSrcFile(sal_uInt16 nFileId, const OUString& rNewFile, const OUString& rNewFilter);
 
@@ -738,6 +738,11 @@ private:
     ScDocument* getSrcDocument(sal_uInt16 nFileId);
     SfxObjectShellRef loadSrcDocument(sal_uInt16 nFileId, OUString& rFilter);
 
+    /**
+     * Caller must ensure that the passed shell is not already stored.
+     */
+    ScDocument* cacheNewDocShell( sal_uInt16 nFileId, SrcShell& rSrcShell );
+
     void maybeLinkExternalFile(sal_uInt16 nFileId);
 
     /**
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index 25dfe63..549549a 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -136,17 +136,18 @@ struct UpdateFormulaCell : public unary_function<ScFormulaCell*, void>
         // Check to make sure the cell really contains ocExternalRef.
         // External names, external cell and range references all have a
         // ocExternalRef token.
-        const ScTokenArray* pCode = pCell->GetCode();
+        ScTokenArray* pCode = pCell->GetCode();
         if (!pCode->HasExternalRef())
             return;
 
-        ScTokenArray* pArray = pCell->GetCode();
-        if (pArray)
+        if (pCode->GetCodeError())
+        {
             // Clear the error code, or a cell with error won't get re-compiled.
-            pArray->SetCodeError(0);
+            pCode->SetCodeError(0);
+            pCell->SetCompile(true);
+            pCell->CompileTokenArray();
+        }
 
-        pCell->SetCompile(true);
-        pCell->CompileTokenArray();
         pCell->SetDirty();
     }
 };
@@ -1258,7 +1259,8 @@ void ScExternalRefLink::Closed()
     if (pCurFile->equals(aFile))
     {
         // Refresh the current source document.
-        pMgr->refreshNames(mnFileId);
+        if (!pMgr->refreshSrcDocument(mnFileId))
+            return ERROR_GENERAL;
     }
     else
     {
@@ -2234,17 +2236,7 @@ ScDocument* ScExternalRefManager::getSrcDocument(sal_uInt16 nFileId)
         return NULL;
     }
 
-    if (maDocShells.empty())
-    {
-        // If this is the first source document insertion, start up the timer.
-        maSrcDocTimer.Start();
-    }
-
-    maDocShells.insert(DocShellMap::value_type(nFileId, aSrcDoc));
-    SfxObjectShell* p = aSrcDoc.maShell;
-    ScDocument* pSrcDoc = static_cast<ScDocShell*>(p)->GetDocument();
-    initDocInCache(maRefCache, pSrcDoc, nFileId);
-    return pSrcDoc;
+    return cacheNewDocShell(nFileId, aSrcDoc);
 }
 
 SfxObjectShellRef ScExternalRefManager::loadSrcDocument(sal_uInt16 nFileId, OUString& rFilter)
@@ -2321,7 +2313,12 @@ SfxObjectShellRef ScExternalRefManager::loadSrcDocument(sal_uInt16 nFileId, OUSt
     }
     pExtOptNew->GetDocSettings().mnLinkCnt = nLinkCount + 1;
 
-    pNewShell->DoLoad(pMedium.release());
+    if (!pNewShell->DoLoad(pMedium.release()))
+    {
+        aRef->DoClose();
+        aRef.Clear();
+        return aRef;
+    }
 
     // with UseInteractionHandler, options may be set by dialog during DoLoad
     OUString aNew = ScDocumentLoader::GetOptions(*pNewShell->GetMedium());
@@ -2332,6 +2329,19 @@ SfxObjectShellRef ScExternalRefManager::loadSrcDocument(sal_uInt16 nFileId, OUSt
     return aRef;
 }
 
+ScDocument* ScExternalRefManager::cacheNewDocShell( sal_uInt16 nFileId, SrcShell& rSrcShell )
+{
+    if (maDocShells.empty())
+        // If this is the first source document insertion, start up the timer.
+        maSrcDocTimer.Start();
+
+    maDocShells.insert(DocShellMap::value_type(nFileId, rSrcShell));
+    SfxObjectShell& rShell = *rSrcShell.maShell;
+    ScDocument* pSrcDoc = static_cast<ScDocShell&>(rShell).GetDocument();
+    initDocInCache(maRefCache, pSrcDoc, nFileId);
+    return pSrcDoc;
+}
+
 bool ScExternalRefManager::isFileLoadable(const OUString& rFile) const
 {
     if (rFile.isEmpty())
@@ -2548,18 +2558,43 @@ void ScExternalRefManager::clearCache(sal_uInt16 nFileId)
     maRefCache.clearCache(nFileId);
 }
 
-void ScExternalRefManager::refreshNames(sal_uInt16 nFileId)
+bool ScExternalRefManager::refreshSrcDocument(sal_uInt16 nFileId)
 {
-    clearCache(nFileId);
-    lcl_removeByFileId(nFileId, maDocShells);
+    OUString aFilter;
+    SfxObjectShellRef xDocShell;
+    try
+    {
+        xDocShell = loadSrcDocument(nFileId, aFilter);
+    }
+    catch ( const css::uno::Exception& ) {}
 
-    if (maDocShells.empty())
-        maSrcDocTimer.Stop();
+    if (!xDocShell.Is())
+        // Failed to load the document.  Bail out.
+        return false;
+
+    // Clear the existing cache, and store the loaded doc shell until it expires.
+    clearCache(nFileId);
+    DocShellMap::iterator it = maDocShells.find(nFileId);
+    if (it != maDocShells.end())
+    {
+        it->second.maShell->DoClose();
+        it->second.maShell = xDocShell;
+        it->second.maLastAccess = Time(Time::SYSTEM);
+    }
+    else
+    {
+        SrcShell aSrcDoc;
+        aSrcDoc.maShell = xDocShell;
+        aSrcDoc.maLastAccess = Time(Time::SYSTEM);
+        cacheNewDocShell(nFileId, aSrcDoc);
+    }
 
     // Update all cells containing names from this source document.
     refreshAllRefCells(nFileId);
 
     notifyAllLinkListeners(nFileId, LINK_MODIFIED);
+
+    return true;
 }
 
 void ScExternalRefManager::breakLink(sal_uInt16 nFileId)
@@ -2615,7 +2650,7 @@ void ScExternalRefManager::switchSrcFile(sal_uInt16 nFileId, const OUString& rNe
         maSrcFiles[nFileId].maFilterName = rNewFilter;
         maSrcFiles[nFileId].maFilterOptions = OUString();
     }
-    refreshNames(nFileId);
+    refreshSrcDocument(nFileId);
 }
 
 void ScExternalRefManager::setRelativeFileName(sal_uInt16 nFileId, const OUString& rRelUrl)


More information about the Libreoffice-commits mailing list