Index: embeddedobj/source/commonembedding/persistence.cxx
===================================================================
RCS file: /cvs/framework/embeddedobj/source/commonembedding/persistence.cxx,v
retrieving revision 1.32
retrieving revision 1.32.6.1
diff -u -p -u -p -r1.32 -r1.32.6.1
--- embeddedobj/source/commonembedding/persistence.cxx	2 Aug 2007 17:05:11 -0000	1.32
+++ embeddedobj/source/commonembedding/persistence.cxx	8 Oct 2007 11:09:08 -0000	1.32.6.1
@@ -459,17 +459,6 @@ uno::Reference< util::XCloseable > OComm
 
     uno::Reference< util::XCloseable >  xDocument( m_xFactory->createInstance( GetDocumentServiceName() ), uno::UNO_QUERY );
 
-    try
-    {
-        uno::Reference < container::XChild > xChild( xDocument, uno::UNO_QUERY );
-        if ( xChild.is() )
-            xChild->setParent( m_xParent );
-    }
-    catch( const lang::NoSupportException & )
-    {
-        OSL_ENSURE( false, "Cannot set parent at document" );
-    }
-
     uno::Reference< frame::XLoadable > xLoadable( xDocument, uno::UNO_QUERY );
     uno::Reference< document::XStorageBasedDocument > xDoc
 #ifdef USE_STORAGEBASED_DOCUMENT
@@ -543,8 +532,20 @@ uno::Reference< util::XCloseable > OComm
 
 	try
 	{
-		// set the document mode to embedded
+		// set the document mode to embedded as the first step!!!
         SetDocToEmbedded( uno::Reference < frame::XModel >( xDocument, uno::UNO_QUERY ), m_aModuleName );
+
+        try
+        {
+            uno::Reference < container::XChild > xChild( xDocument, uno::UNO_QUERY );
+            if ( xChild.is() )
+                xChild->setParent( m_xParent );
+        }
+        catch( const lang::NoSupportException & )
+        {
+            OSL_ENSURE( false, "Cannot set parent at document" );
+        }
+
         if ( xDoc.is() )
             xDoc->loadFromStorage( xStorage, aArgs );
         else
Index: sw/source/ui/wrtsh/wrtsh1.cxx
===================================================================
RCS file: /cvs/sw/sw/source/ui/wrtsh/wrtsh1.cxx,v
retrieving revision 1.62
retrieving revision 1.62.36.1
diff -u -p -u -p -r1.62 -r1.62.36.1
--- sw/source/ui/wrtsh/wrtsh1.cxx	5 Jul 2007 13:14:40 -0000	1.62
+++ sw/source/ui/wrtsh/wrtsh1.cxx	5 Oct 2007 15:12:00 -0000	1.62.36.1
@@ -51,6 +51,9 @@
 #ifndef _COM_SUN_STAR_EMBED_NOVISUALAREASIZEEXCEPTION_HPP_
 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
 #endif
+#ifndef _COM_SUN_STAR_CHART2_XCHARTDOCUMENT_HPP_
+#include <com/sun/star/chart2/XChartDocument.hpp>
+#endif
 
 #if STLPORT_VERSION>=321
 #include <math.h>	// prevent conflict between exception and std::exception
@@ -778,77 +781,106 @@ void SwWrtShell::CalcAndSetScale( svt::E
     ASSERT( xObj.is(), "ObjectRef not  valid" );
 
     sal_Int64 nAspect = xObj.GetViewAspect();
-	if ( nAspect == embed::Aspects::MSOLE_ICON )
-		return; // the replacement image is completely controlled by container in this case
+    if ( nAspect == embed::Aspects::MSOLE_ICON )
+        return; // the replacement image is completely controlled by container in this case
 
-    sal_Int64 nMisc = xObj->getStatus( nAspect );
+    sal_Int64 nMisc = 0;
+    sal_Bool bLinkingChart = sal_False;
 
-    //Das kann ja wohl nur ein nicht aktives Objekt sein. Diese bekommen
-    //auf Wunsch die neue Groesse als VisArea gesetzt (StarChart)
-    if( embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE & nMisc )
+    try
     {
-        // TODO/MBA: testing
-        SwRect aRect( pFlyPrtRect ? *pFlyPrtRect
-                    : GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, xObj.GetObject() ));
-        if( !aRect.IsEmpty() )
+        nMisc = xObj->getStatus( nAspect );
+
+        //Das kann ja wohl nur ein nicht aktives Objekt sein. Diese bekommen
+        //auf Wunsch die neue Groesse als VisArea gesetzt (StarChart)
+        if( embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE & nMisc )
         {
-            // TODO/LEAN: getMapUnit can switch object to running state
-            // xObj.TryRunningState();
+            // TODO/MBA: testing
+            SwRect aRect( pFlyPrtRect ? *pFlyPrtRect
+                        : GetAnyCurRect( RECT_FLY_PRT_EMBEDDED, 0, xObj.GetObject() ));
+            if( !aRect.IsEmpty() )
+            {
+                // TODO/LEAN: getMapUnit can switch object to running state
+                // xObj.TryRunningState();
 
-            MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
+                MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
 
-            // TODO/LATER: needs complete VisArea?!
-            Size aSize( OutputDevice::LogicToLogic( aRect.SVRect(), MAP_TWIP, aUnit ).GetSize() );
-            awt::Size aSz;
-            aSz.Width = aSize.Width();
-            aSz.Height = aSize.Height();
-            xObj->setVisualAreaSize( nAspect, aSz );
-            // --> OD 2005-05-02 #i48419# - action 'UpdateReplacement' doesn't
-            // have to change the modified state of the document.
-            // This is only a workaround for the defect, that this action
-            // modifies a document after load, because unnecessarily the
-            // replacement graphic is updated, in spite of the fact that
-            // nothing has been changed.
-            // If the replacement graphic changes by this action, the document
-            // will be already modified via other mechanisms.
-            {
-                bool bResetEnableSetModified(false);
-                if ( GetDoc()->GetDocShell()->IsEnableSetModified() )
+                // TODO/LATER: needs complete VisArea?!
+                Size aSize( OutputDevice::LogicToLogic( aRect.SVRect(), MAP_TWIP, aUnit ).GetSize() );
+                awt::Size aSz;
+                aSz.Width = aSize.Width();
+                aSz.Height = aSize.Height();
+                xObj->setVisualAreaSize( nAspect, aSz );
+                // --> OD 2005-05-02 #i48419# - action 'UpdateReplacement' doesn't
+                // have to change the modified state of the document.
+                // This is only a workaround for the defect, that this action
+                // modifies a document after load, because unnecessarily the
+                // replacement graphic is updated, in spite of the fact that
+                // nothing has been changed.
+                // If the replacement graphic changes by this action, the document
+                // will be already modified via other mechanisms.
                 {
-                    GetDoc()->GetDocShell()->EnableSetModified( FALSE );
-                    bResetEnableSetModified = true;
-                }
+                    bool bResetEnableSetModified(false);
+                    if ( GetDoc()->GetDocShell()->IsEnableSetModified() )
+                    {
+                        GetDoc()->GetDocShell()->EnableSetModified( FALSE );
+                        bResetEnableSetModified = true;
+                    }
 
-                xObj.UpdateReplacement();
+                    xObj.UpdateReplacement();
 
-                if ( bResetEnableSetModified )
-                {
-                    GetDoc()->GetDocShell()->EnableSetModified( TRUE );
+                    if ( bResetEnableSetModified )
+                    {
+                        GetDoc()->GetDocShell()->EnableSetModified( TRUE );
+                    }
                 }
+                // <--
             }
-            // <--
+
+            // TODO/LATER: this is only a workaround, 
+            uno::Reference< chart2::XChartDocument > xChartDocument( xObj->getComponent(), uno::UNO_QUERY );
+            bLinkingChart = ( xChartDocument.is() && !xChartDocument->hasInternalDataProvider() );
         }
     }
+    catch ( uno::Exception& )
+    {
+        // TODO/LATER: handle the error
+        return;
+    }
 
     SfxInPlaceClient* pCli = GetView().FindIPClient( xObj.GetObject(), &GetView().GetEditWin() );
     if ( !pCli )
-	{
-        pCli = new SwOleClient( &GetView(), &GetView().GetEditWin(), xObj );
-	}
+    {
+        if ( (embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY & nMisc) || bLinkingChart
+            // TODO/LATER: ResizeOnPrinterChange
+             //|| SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & xObj->GetMiscStatus()
+             )
+        {
+            pCli = new SwOleClient( &GetView(), &GetView().GetEditWin(), xObj );
+        }
+        else
+            return;
+    }
 
     // TODO/LEAN: getMapUnit can switch object to running state
     // xObj.TryRunningState();
 
     awt::Size aSize;
-	try
-	{
-		aSize = xObj->getVisualAreaSize( nAspect );
-	}
-	catch( embed::NoVisualAreaSizeException& )
-	{
-		DBG_ERROR( "Can't get visual area size!\n" );
-		// the scaling will not be done
-	}
+    try
+    {
+        aSize = xObj->getVisualAreaSize( nAspect );
+    }
+    catch( embed::NoVisualAreaSizeException& )
+    {
+        DBG_ERROR( "Can't get visual area size!\n" );
+        // the scaling will not be done
+    }
+    catch( uno::Exception& )
+    {
+        // TODO/LATER: handle the error
+        DBG_ERROR( "Can't get visual area size!\n" );
+        return;
+    }
 
     Size aVisArea( aSize.Width, aSize.Height );
 
