f085be
From 9ba9d810d9e17a7e3a3e0885235924f4c480c3b0 Mon Sep 17 00:00:00 2001
f085be
From: Kohei Yoshida <kohei.yoshida@collabora.com>
f085be
Date: Fri, 11 Jul 2014 10:50:29 -0400
f085be
Subject: [PATCH 043/137] bnc#883684: Better fix for this.
f085be
f085be
Instead of making all chart objects exempt from unloading, check each OLE
f085be
object on whether or not it already has its persistent storage created.
f085be
If not, don't unload it else it would have nothing to load back from once
f085be
unloaded.
f085be
f085be
(cherry picked from commit a0bd5587a5ac62974bdb10731d3fd21584521a72)
f085be
f085be
Conflicts:
f085be
	svx/source/svdraw/svdetc.cxx
f085be
	embeddedobj/source/commonembedding/miscobj.cxx
f085be
	embeddedobj/source/commonembedding/persistence.cxx
f085be
	include/svx/svdoole2.hxx
f085be
	svx/source/svdraw/svdoole2.cxx
f085be
f085be
Change-Id: I2312e86c9376d3699ef4aa1e0cf2f4c04f706c1e
f085be
---
f085be
 embeddedobj/source/commonembedding/miscobj.cxx     |  8 +++++-
f085be
 embeddedobj/source/commonembedding/persistence.cxx | 10 +++++++-
f085be
 embeddedobj/source/inc/commonembobj.hxx            |  8 ++++--
f085be
 include/svx/svdoole2.hxx                           |  7 -----
f085be
 offapi/UnoApi_offapi.mk                            |  1 +
f085be
 offapi/com/sun/star/embed/XEmbedPersist2.idl       | 30 ++++++++++++++++++++++
f085be
 svx/source/svdraw/svdetc.cxx                       |  4 ---
f085be
 svx/source/svdraw/svdoole2.cxx                     | 16 +++++++-----
f085be
 8 files changed, 62 insertions(+), 22 deletions(-)
f085be
 create mode 100644 offapi/com/sun/star/embed/XEmbedPersist2.idl
f085be
f085be
diff --git a/embeddedobj/source/commonembedding/miscobj.cxx b/embeddedobj/source/commonembedding/miscobj.cxx
f085be
index 70b8696..8ce2f84 100644
f085be
--- a/embeddedobj/source/commonembedding/miscobj.cxx
f085be
+++ b/embeddedobj/source/commonembedding/miscobj.cxx
f085be
@@ -363,6 +363,11 @@ uno::Any SAL_CALL OCommonEmbeddedObject::queryInterface( const uno::Type& rType
f085be
         void * p = static_cast< embed::XEmbeddedObject * >( this );
f085be
         return uno::Any( &p, rType );
f085be
     }
f085be
+    else if (rType == ::getCppuType( (uno::Reference<embed::XEmbedPersist2> const *)0 ))
f085be
+    {
f085be
+        void* p = static_cast<embed::XEmbedPersist2*>(this);
f085be
+        return uno::Any(&p, rType);
f085be
+    }
f085be
     else
f085be
         aReturn <<= ::cppu::queryInterface(
f085be
                     rType,
f085be
@@ -431,7 +436,8 @@ uno::Sequence< uno::Type > SAL_CALL OCommonEmbeddedObject::getTypes()
f085be
                                             ::getCppuType( (const uno::Reference< embed::XInplaceObject >*)NULL ),
f085be
                                             ::getCppuType( (const uno::Reference< embed::XCommonEmbedPersist >*)NULL ),
f085be
                                             ::getCppuType( (const uno::Reference< container::XChild >*)NULL ),
f085be
-                                            ::getCppuType( (const uno::Reference< embed::XEmbedPersist >*)NULL ) );
f085be
+                                            ::getCppuType( (const uno::Reference< embed::XEmbedPersist >*)NULL ),
f085be
+                                            ::getCppuType( (const uno::Reference< embed::XEmbedPersist2 >*)NULL ) );
f085be
 
f085be
                 pTypeCollection = &aTypeCollection ;
f085be
             }
f085be
diff --git a/embeddedobj/source/commonembedding/persistence.cxx b/embeddedobj/source/commonembedding/persistence.cxx
f085be
index 4891656..44b4e30 100644
f085be
--- a/embeddedobj/source/commonembedding/persistence.cxx
f085be
+++ b/embeddedobj/source/commonembedding/persistence.cxx
f085be
@@ -1799,7 +1799,15 @@ void SAL_CALL OCommonEmbeddedObject::reload(
f085be
     }
f085be
 }
f085be
 
f085be
-//------------------------------------------------------
f085be
+sal_Bool SAL_CALL OCommonEmbeddedObject::isStored() throw (css::uno::RuntimeException, std::exception)
f085be
+{
f085be
+    uno::Reference<container::XNameAccess> xNA(m_xObjectStorage, uno::UNO_QUERY);
f085be
+    if (!xNA.is())
f085be
+        return false;
f085be
+
f085be
+    return xNA->getElementNames().getLength() > 0;
f085be
+}
f085be
+
f085be
 void SAL_CALL OCommonEmbeddedObject::breakLink( const uno::Reference< embed::XStorage >& xStorage,
f085be
                                                 const OUString& sEntName )
f085be
         throw ( lang::IllegalArgumentException,
f085be
diff --git a/embeddedobj/source/inc/commonembobj.hxx b/embeddedobj/source/inc/commonembobj.hxx
f085be
index 83e4445..4c23325 100644
f085be
--- a/embeddedobj/source/inc/commonembobj.hxx
f085be
+++ b/embeddedobj/source/inc/commonembobj.hxx
f085be
@@ -27,7 +27,7 @@
f085be
 #include <com/sun/star/document/XStorageBasedDocument.hpp>
f085be
 #include <com/sun/star/embed/XEmbeddedObject.hpp>
f085be
 #include <com/sun/star/embed/XVisualObject.hpp>
f085be
-#include <com/sun/star/embed/XEmbedPersist.hpp>
f085be
+#include <com/sun/star/embed/XEmbedPersist2.hpp>
f085be
 #include <com/sun/star/embed/XLinkageSupport.hpp>
f085be
 #include <com/sun/star/embed/XClassifiedObject.hpp>
f085be
 #include <com/sun/star/embed/XComponentSupplier.hpp>
f085be
@@ -72,7 +72,7 @@ namespace comphelper {
f085be
 class Interceptor;
f085be
 
f085be
 class OCommonEmbeddedObject : public ::com::sun::star::embed::XEmbeddedObject
f085be
-                            , public ::com::sun::star::embed::XEmbedPersist
f085be
+                            , public ::com::sun::star::embed::XEmbedPersist2
f085be
                             , public ::com::sun::star::embed::XLinkageSupport
f085be
                             , public ::com::sun::star::embed::XInplaceObject
f085be
                             , public ::com::sun::star::container::XChild
f085be
@@ -431,6 +431,10 @@ public:
f085be
                 ::com::sun::star::uno::Exception,
f085be
                 ::com::sun::star::uno::RuntimeException );
f085be
 
f085be
+// XEmbedPersist2
f085be
+
f085be
+    virtual sal_Bool SAL_CALL isStored()
f085be
+        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
f085be
 
f085be
 // XInplaceObject
f085be
 
f085be
diff --git a/include/svx/svdoole2.hxx b/include/svx/svdoole2.hxx
f085be
index 149dc61..c2cad4b 100644
f085be
--- a/include/svx/svdoole2.hxx
f085be
+++ b/include/svx/svdoole2.hxx
f085be
@@ -170,13 +170,6 @@ public:
f085be
     sal_Bool IsChart() const;
f085be
     sal_Bool IsCalc() const;
f085be
 
f085be
-    /**
f085be
-     * Unloadable OLE objects are subject to automatic unloading per memory
f085be
-     * setting.  The "Number of objects" setting in the Memory option controls
f085be
-     * how many OLE objects can be loaded at any given moment.
f085be
-     */
f085be
-    bool IsUnloadable() const;
f085be
-
f085be
     sal_Bool UpdateLinkURL_Impl();
f085be
     void BreakFileLink_Impl();
f085be
     void DisconnectFileLink_Impl();
f085be
diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
f085be
index 3c1d92e..22d84d2 100755
f085be
--- a/offapi/UnoApi_offapi.mk
f085be
+++ b/offapi/UnoApi_offapi.mk
f085be
@@ -2411,6 +2411,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/embed,\
f085be
     XEmbeddedObjectCreator \
f085be
 	XEmbedObjectFactory \
f085be
 	XEmbedPersist \
f085be
+	XEmbedPersist2 \
f085be
 	XEmbeddedClient \
f085be
 	XEmbeddedObject \
f085be
 	XEncryptionProtectedSource \
f085be
diff --git a/offapi/com/sun/star/embed/XEmbedPersist2.idl b/offapi/com/sun/star/embed/XEmbedPersist2.idl
f085be
new file mode 100644
f085be
index 0000000..205b902
f085be
--- /dev/null
f085be
+++ b/offapi/com/sun/star/embed/XEmbedPersist2.idl
f085be
@@ -0,0 +1,30 @@
f085be
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
f085be
+/*
f085be
+ * This file is part of the LibreOffice project.
f085be
+ *
f085be
+ * This Source Code Form is subject to the terms of the Mozilla Public
f085be
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
f085be
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
f085be
+ */
f085be
+
f085be
+#ifndef __com_sun_star_XEmbedPersist2_idl__
f085be
+#define __com_sun_star_XEmbedPersist2_idl__
f085be
+
f085be
+#include <com/sun/star/embed/XEmbedPersist.idl>
f085be
+
f085be
+module com {  module sun {  module star { module embed {
f085be
+
f085be
+interface XEmbedPersist2 : XEmbedPersist
f085be
+{
f085be
+    /**
f085be
+     * Checks whether or not the object has created its persistent
f085be
+     * representation counterpart of its in-memory model.
f085be
+     */
f085be
+    boolean isStored();
f085be
+};
f085be
+
f085be
+}; }; }; };
f085be
+
f085be
+#endif
f085be
+
f085be
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
f085be
diff --git a/svx/source/svdraw/svdetc.cxx b/svx/source/svdraw/svdetc.cxx
f085be
index afcc792..4caca94 100644
f085be
--- a/svx/source/svdraw/svdetc.cxx
f085be
+++ b/svx/source/svdraw/svdetc.cxx
f085be
@@ -165,10 +165,6 @@ void OLEObjCache::UnloadOnDemand()
f085be
 
f085be
 void OLEObjCache::InsertObj(SdrOle2Obj* pObj)
f085be
 {
f085be
-    if (!pObj->IsUnloadable())
f085be
-        // This OLE object is exempt from automatic unloading.
f085be
-        return;
f085be
-
f085be
     if ( !empty() )
f085be
     {
f085be
         SdrOle2Obj* pExistingObj = front();
f085be
diff --git a/svx/source/svdraw/svdoole2.cxx b/svx/source/svdraw/svdoole2.cxx
f085be
index f68f5d7..f1f27a83 100644
f085be
--- a/svx/source/svdraw/svdoole2.cxx
f085be
+++ b/svx/source/svdraw/svdoole2.cxx
f085be
@@ -25,6 +25,7 @@
f085be
 #include <com/sun/star/embed/ElementModes.hpp>
f085be
 #include <com/sun/star/embed/EmbedMisc.hpp>
f085be
 #include <com/sun/star/embed/Aspects.hpp>
f085be
+#include <com/sun/star/embed/XEmbedPersist2.hpp>
f085be
 #include <com/sun/star/embed/XInplaceClient.hpp>
f085be
 #include <com/sun/star/embed/XInplaceObject.hpp>
f085be
 #include <com/sun/star/embed/XLinkageSupport.hpp>
f085be
@@ -1926,6 +1927,14 @@ void SdrOle2Obj::NbcMove(const Size& rSize)
f085be
 
f085be
 sal_Bool SdrOle2Obj::CanUnloadRunningObj( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
f085be
 {
f085be
+    uno::Reference<embed::XEmbedPersist2> xPersist(xObj, uno::UNO_QUERY);
f085be
+    if (xPersist.is())
f085be
+    {
f085be
+        if (!xPersist->isStored())
f085be
+            // It doesn't have persistent storage.  We can't unload this.
f085be
+            return false;
f085be
+    }
f085be
+
f085be
     sal_Bool bResult = sal_False;
f085be
 
f085be
     sal_Int32 nState = xObj->getCurrentState();
f085be
@@ -2159,13 +2168,6 @@ sal_Bool SdrOle2Obj::IsCalc() const
f085be
     return sal_False;
f085be
 }
f085be
 
f085be
-bool SdrOle2Obj::IsUnloadable() const
f085be
-{
f085be
-    // Right now, chart OLE objects are the only ones exempt from automatic
f085be
-    // unloading.
f085be
-    return !IsChart();
f085be
-}
f085be
-
f085be
 uno::Reference< frame::XModel > SdrOle2Obj::GetParentXModel() const
f085be
 {
f085be
     uno::Reference< frame::XModel > xDoc;
f085be
-- 
f085be
1.9.3
f085be