Files
libreoffice/sw/source/core/ole/ndole.cxx

1003 lines
32 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patches contributed by Oliver-Rainer Wittmann sw34bf06: #i117783# - Writer's implementation of XPagePrintable - apply print settings to new printing routines http://svn.apache.org/viewvc?view=revision&revision=1172115 sw34bf06: #o12311627# use <rtl_random> methods to create unique ids for list styles and list ids http://svn.apache.org/viewvc?view=revision&revision=1172112 sw34bf06 #i114725#,#i115828# - method <SwDoc::ClearDoc()> - clear list structures completely http://svn.apache.org/viewvc?view=revision&revision=1172122 i#118572 - remove ui string and help content regarding usage of Java Mail in Writer's Mail Merge as Java Mail is not used. http://svn.apache.org/viewvc?view=revision&revision=1197035 Patches contributed by Mathias Bauer cws mba34issues01: #i117718#: provide filter name in case storage of medium does not allow to detect one http://svn.apache.org/viewvc?view=revision&revision=1172350 cws mba34issues01: #i117721#: directly provide parameters retrieved from SfxMedium http://svn.apache.org/viewvc?view=revision&revision=1172353 gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 cws mba34issues01: #i117723#: convert assertion into trace http://svn.apache.org/viewvc?view=revision&revision=1172355 cws mba34issues01: #i117699#: keep layout alive until swdoc dies http://svn.apache.org/viewvc?view=revision&revision=1172362 cws mba34issues01: #i117943#: missing color attributes in RTF clipboard http://svn.apache.org/viewvc?view=revision&revision=1172363 Patch contributed by Henning Brinkmann imported patch i#103878 http://svn.apache.org/viewvc?view=revision&revision=1172109 Patches contributed by Michael Stahl sw34bf06: #i117955#: WW8 export: disable storing of section breaks in endnotes http://svn.apache.org/viewvc?view=revision&revision=1172119 Patch contributed by imacat Fixed the Asian language work count. http://svn.apache.org/viewvc?view=revision&revision=1241345 Patch contributed by Pedro Giffuni i#20878 - Add comment with BZ issue for reference. http://svn.apache.org/viewvc?view=revision&revision=1244517 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 add writerperfect dependency.
2011-03-31 10:05:04 +02:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/embed/XEmbedPersist.hpp>
#include <com/sun/star/embed/XLinkageSupport.hpp>
#include <com/sun/star/embed/Aspects.hpp>
#include <com/sun/star/embed/EmbedMisc.hpp>
#include <com/sun/star/embed/EmbedStates.hpp>
#include <com/sun/star/util/XCloseable.hpp>
#include <com/sun/star/util/XModifiable.hpp>
#include <com/sun/star/document/XEventBroadcaster.hpp>
#include <com/sun/star/chart2/XChartDocument.hpp>
#include <cppuhelper/implbase.hxx>
#include <toolkit/helper/vclunohelper.hxx>
2000-09-18 23:08:29 +00:00
#include <hintids.hxx>
#include <sfx2/docfile.hxx>
#include <sfx2/app.hxx>
2010-01-13 22:25:07 +01:00
#include <sfx2/linkmgr.hxx>
#include <unotools/configitem.hxx>
2001-07-05 09:34:53 +00:00
#include <vcl/outdev.hxx>
2000-09-18 23:08:29 +00:00
#include <fmtanchr.hxx>
#include <frmfmt.hxx>
#include <doc.hxx>
#include <docsh.hxx>
2000-09-18 23:08:29 +00:00
#include <pam.hxx>
#include <section.hxx>
#include <cntfrm.hxx>
#include <frmatr.hxx>
#include <ndole.hxx>
#include <DocumentSettingManager.hxx>
#include <IDocumentLinksAdministration.hxx>
#include <comphelper/classids.hxx>
#include <vcl/graph.hxx>
#include <sot/formats.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <vcl/graphicfilter.hxx>
#include <comcore.hrc>
2000-09-18 23:08:29 +00:00
#include <deque>
using namespace utl;
using namespace com::sun::star::uno;
using namespace com::sun::star;
2000-09-18 23:08:29 +00:00
class SwOLELRUCache
: private utl::ConfigItem
2000-09-18 23:08:29 +00:00
{
private:
typedef std::deque<SwOLEObj *> OleObjects_t;
OleObjects_t m_OleObjects;
sal_Int32 m_nLRU_InitSize;
static uno::Sequence< OUString > GetPropertyNames();
virtual void ImplCommit() SAL_OVERRIDE;
2000-09-18 23:08:29 +00:00
public:
SwOLELRUCache();
virtual void Notify( const uno::Sequence<
OUString>& aPropertyNames ) SAL_OVERRIDE;
void Load();
2000-09-18 23:08:29 +00:00
void InsertObj( SwOLEObj& rObj );
void RemoveObj( SwOLEObj& rObj );
2000-09-18 23:08:29 +00:00
};
SwOLELRUCache* pOLELRU_Cache = 0;
class SwOLEListener_Impl : public ::cppu::WeakImplHelper< embed::XStateChangeListener >
{
SwOLEObj* mpObj;
public:
explicit SwOLEListener_Impl( SwOLEObj* pObj );
void Release();
virtual void SAL_CALL changingState( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (embed::WrongStateException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual void SAL_CALL stateChanged( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
};
SwOLEListener_Impl::SwOLEListener_Impl( SwOLEObj* pObj )
: mpObj( pObj )
{
if ( mpObj->IsOleRef() && mpObj->GetOleRef()->getCurrentState() == embed::EmbedStates::RUNNING )
{
pOLELRU_Cache->InsertObj( *mpObj );
}
}
void SAL_CALL SwOLEListener_Impl::changingState( const lang::EventObject&, ::sal_Int32 , ::sal_Int32 ) throw (embed::WrongStateException, uno::RuntimeException, std::exception)
{
}
void SAL_CALL SwOLEListener_Impl::stateChanged( const lang::EventObject&, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (uno::RuntimeException, std::exception)
{
if ( mpObj && nOldState == embed::EmbedStates::LOADED && nNewState == embed::EmbedStates::RUNNING )
{
if( !pOLELRU_Cache )
pOLELRU_Cache = new SwOLELRUCache;
pOLELRU_Cache->InsertObj( *mpObj );
}
else if ( mpObj && nNewState == embed::EmbedStates::LOADED && nOldState == embed::EmbedStates::RUNNING )
{
if ( pOLELRU_Cache )
pOLELRU_Cache->RemoveObj( *mpObj );
}
}
void SwOLEListener_Impl::Release()
{
if ( mpObj && pOLELRU_Cache )
pOLELRU_Cache->RemoveObj( *mpObj );
mpObj=0;
release();
}
void SAL_CALL SwOLEListener_Impl::disposing( const lang::EventObject& ) throw (uno::RuntimeException, std::exception)
{
if ( mpObj && pOLELRU_Cache )
pOLELRU_Cache->RemoveObj( *mpObj );
}
2000-09-18 23:08:29 +00:00
// TODO/LATER: actually SwEmbedObjectLink should be used here, but because different objects are used to control
// embedded object different link objects with the same functionality had to be implemented
class SwEmbedObjectLink : public sfx2::SvBaseLink
{
SwOLENode* pOleNode;
public:
explicit SwEmbedObjectLink(SwOLENode* pNode);
virtual ~SwEmbedObjectLink();
virtual void Closed() SAL_OVERRIDE;
2011-05-25 14:58:03 -04:00
virtual ::sfx2::SvBaseLink::UpdateResult DataChanged(
const OUString& rMimeType, const ::com::sun::star::uno::Any & rValue ) SAL_OVERRIDE;
bool Connect() { return GetRealObject() != NULL; }
};
SwEmbedObjectLink::SwEmbedObjectLink(SwOLENode* pNode):
::sfx2::SvBaseLink( ::SfxLinkUpdateMode::ONCALL, SotClipboardFormatId::SVXB ),
pOleNode(pNode)
{
SetSynchron( false );
}
SwEmbedObjectLink::~SwEmbedObjectLink()
{
}
2011-05-25 14:58:03 -04:00
::sfx2::SvBaseLink::UpdateResult SwEmbedObjectLink::DataChanged(
const OUString&, const uno::Any& )
{
if ( !pOleNode->UpdateLinkURL_Impl() )
{
// the link URL was not changed
uno::Reference< embed::XEmbeddedObject > xObject = pOleNode->GetOLEObj().GetOleRef();
OSL_ENSURE( xObject.is(), "The object must exist always!\n" );
if ( xObject.is() )
{
// let the object reload the link
// TODO/LATER: reload call could be used for this case
try
{
sal_Int32 nState = xObject->getCurrentState();
if ( nState != embed::EmbedStates::LOADED )
{
// in some cases the linked file probably is not locked so it could be changed
xObject->changeState( embed::EmbedStates::LOADED );
xObject->changeState( nState );
}
}
catch ( uno::Exception& )
{
}
}
}
pOleNode->GetNewReplacement();
2011-05-25 14:58:03 -04:00
return SUCCESS;
}
void SwEmbedObjectLink::Closed()
{
pOleNode->BreakFileLink_Impl();
SvBaseLink::Closed();
}
2000-09-18 23:08:29 +00:00
SwOLENode::SwOLENode( const SwNodeIndex &rWhere,
const svt::EmbeddedObjectRef& xObj,
SwGrfFormatColl *pGrfColl,
2000-09-18 23:08:29 +00:00
SwAttrSet* pAutoAttr ) :
SwNoTextNode( rWhere, ND_OLENODE, pGrfColl, pAutoAttr ),
aOLEObj( xObj ),
bOLESizeInvalid( false ),
mpObjectLink( NULL )
2000-09-18 23:08:29 +00:00
{
aOLEObj.SetNode( this );
}
SwOLENode::SwOLENode( const SwNodeIndex &rWhere,
const OUString &rString,
sal_Int64 nAspect,
SwGrfFormatColl *pGrfColl,
2000-09-18 23:08:29 +00:00
SwAttrSet* pAutoAttr ) :
SwNoTextNode( rWhere, ND_OLENODE, pGrfColl, pAutoAttr ),
aOLEObj( rString, nAspect ),
bOLESizeInvalid( false ),
mpObjectLink( NULL )
2000-09-18 23:08:29 +00:00
{
aOLEObj.SetNode( this );
}
SwOLENode::~SwOLENode()
{
DisconnectFileLink_Impl();
}
const Graphic* SwOLENode::GetGraphic()
{
if ( aOLEObj.GetOleRef().is() )
return aOLEObj.xOLERef.GetGraphic();
return 0;
}
SwContentNode *SwOLENode::SplitContentNode( const SwPosition & )
2000-09-18 23:08:29 +00:00
{
// Multiply OLE objects?
OSL_FAIL( "OleNode: can't split." );
2000-09-18 23:08:29 +00:00
return this;
}
/**
* Loading a OLE object that has been moved to the Undo Area
*/
bool SwOLENode::RestorePersistentData()
2000-09-18 23:08:29 +00:00
{
OSL_ENSURE( aOLEObj.GetOleRef().is(), "No object to restore!" );
if ( aOLEObj.xOLERef.is() )
2000-09-18 23:08:29 +00:00
{
// If a SvPersist instance already exists, we use it
SfxObjectShell* p = GetDoc()->GetPersist();
if( !p )
{
// TODO/LATER: Isn't a EmbeddedObjectContainer sufficient here?
// What happens to this document?
OSL_ENSURE( false, "Why are we creating a DocShell here?" );
p = new SwDocShell( GetDoc(), SfxObjectCreateMode::INTERNAL );
p->DoInitNew( NULL );
}
uno::Reference < container::XChild > xChild( aOLEObj.xOLERef.GetObject(), uno::UNO_QUERY );
if ( xChild.is() )
xChild->setParent( p->GetModel() );
OSL_ENSURE( !aOLEObj.aName.isEmpty(), "No object name!" );
OUString aObjName;
if ( !p->GetEmbeddedObjectContainer().InsertEmbeddedObject( aOLEObj.xOLERef.GetObject(), aObjName ) )
{
if ( xChild.is() )
xChild->setParent( 0 );
2011-03-01 19:09:12 +01:00
OSL_FAIL( "InsertObject failed" );
}
else
2000-09-18 23:08:29 +00:00
{
aOLEObj.aName = aObjName;
aOLEObj.xOLERef.AssignToContainer( &p->GetEmbeddedObjectContainer(), aObjName );
CheckFileLink_Impl();
2000-09-18 23:08:29 +00:00
}
}
return true;
2000-09-18 23:08:29 +00:00
}
/**
* OLE object is transported into UNDO area
*/
bool SwOLENode::SavePersistentData()
2000-09-18 23:08:29 +00:00
{
if( aOLEObj.xOLERef.is() )
2000-09-18 23:08:29 +00:00
{
comphelper::EmbeddedObjectContainer* pCnt = aOLEObj.xOLERef.GetContainer();
#if OSL_DEBUG_LEVEL > 0
SfxObjectShell* p = GetDoc()->GetPersist();
OSL_ENSURE( p, "No document!" );
if( p )
{
comphelper::EmbeddedObjectContainer& rCnt = p->GetEmbeddedObjectContainer();
OSL_ENSURE( !pCnt || &rCnt == pCnt, "The helper is assigned to unexpected container!\n" );
}
#endif
if ( pCnt && pCnt->HasEmbeddedObject( aOLEObj.aName ) )
2000-09-18 23:08:29 +00:00
{
uno::Reference < container::XChild > xChild( aOLEObj.xOLERef.GetObject(), uno::UNO_QUERY );
if ( xChild.is() )
xChild->setParent( 0 );
/*
#i119941
When cut or move the chart, SwUndoFlyBase::DelFly will call SaveSection
to store the content to storage. In this step, chart filter functions
will be called. And chart filter will call chart core functions to create
the chart again. Then chart core function will call the class
ExplicitCategoryProvider to create data source. In this step, when SW data
source provider create the data source, an UnoActionRemoveContext
will mess with the layout and create a new SwFlyFrm.
But later in SwUndoFlyBase::DelFly, it will clear anchor related attributes
of SwFlyFrm. Then finally null pointer occur.
Resolution:
In pCnt->RemoveEmbeddedObject in SaveSection process of table chart,
only remove the object from the object container, without removing it's
storage and graphic stream. The chart already removed from formatter.
*/
bool bKeepObjectToTempStorage = true;
uno::Reference < embed::XEmbeddedObject > xIP = GetOLEObj().GetOleRef();
if (IsChart() && !sChartTableName.isEmpty()
&& svt::EmbeddedObjectRef::TryRunningState(xIP))
{
uno::Reference< chart2::XChartDocument > xChart( xIP->getComponent(), UNO_QUERY );
if (xChart.is() && !xChart->hasInternalDataProvider())
{
bKeepObjectToTempStorage = false;
}
}
pCnt->RemoveEmbeddedObject( aOLEObj.aName, false, bKeepObjectToTempStorage );
// TODO/LATER: aOLEObj.aName has no meaning here, since the undo container contains the object
// by different name, in future it might makes sense that the name is transported here.
aOLEObj.xOLERef.AssignToContainer( 0, aOLEObj.aName );
try
{
// "unload" object
aOLEObj.xOLERef->changeState( embed::EmbedStates::LOADED );
}
catch ( uno::Exception& )
{
}
2000-09-18 23:08:29 +00:00
}
}
DisconnectFileLink_Impl();
return true;
2000-09-18 23:08:29 +00:00
}
SwOLENode * SwNodes::MakeOLENode( const SwNodeIndex & rWhere,
const svt::EmbeddedObjectRef& xObj,
SwGrfFormatColl* pGrfColl,
2000-09-18 23:08:29 +00:00
SwAttrSet* pAutoAttr )
{
OSL_ENSURE( pGrfColl,"SwNodes::MakeOLENode: Formatpointer is 0." );
2000-09-18 23:08:29 +00:00
SwOLENode *pNode =
new SwOLENode( rWhere, xObj, pGrfColl, pAutoAttr );
// set parent if XChild is supported
//!! needed to supply Math objects with a valid reference device
uno::Reference< container::XChild > xChild( pNode->GetOLEObj().GetObject().GetObject(), UNO_QUERY );
if (xChild.is())
{
SwDocShell *pDocSh = GetDoc()->GetDocShell();
if (pDocSh)
xChild->setParent( pDocSh->GetModel() );
}
2000-09-18 23:08:29 +00:00
return pNode;
}
SwOLENode * SwNodes::MakeOLENode( const SwNodeIndex & rWhere,
const OUString &rName, sal_Int64 nAspect, SwGrfFormatColl* pGrfColl, SwAttrSet* pAutoAttr )
2000-09-18 23:08:29 +00:00
{
OSL_ENSURE( pGrfColl,"SwNodes::MakeOLENode: Formatpointer is 0." );
2000-09-18 23:08:29 +00:00
SwOLENode *pNode =
new SwOLENode( rWhere, rName, nAspect, pGrfColl, pAutoAttr );
// set parent if XChild is supported
//!! needed to supply Math objects with a valid reference device
uno::Reference< container::XChild > xChild( pNode->GetOLEObj().GetObject().GetObject(), UNO_QUERY );
if (xChild.is())
{
SwDocShell *pDocSh= GetDoc()->GetDocShell();
if (pDocSh)
xChild->setParent( pDocSh->GetModel() );
}
2000-09-18 23:08:29 +00:00
return pNode;
}
Size SwOLENode::GetTwipSize() const
{
MapMode aMapMode( MAP_TWIP );
return const_cast<SwOLENode*>(this)->aOLEObj.GetObject().GetSize( &aMapMode );
2000-09-18 23:08:29 +00:00
}
SwContentNode* SwOLENode::MakeCopy( SwDoc* pDoc, const SwNodeIndex& rIdx ) const
2000-09-18 23:08:29 +00:00
{
// If there's already a SvPersist instance, we use it
SfxObjectShell* pPersistShell = pDoc->GetPersist();
if( !pPersistShell )
2000-09-18 23:08:29 +00:00
{
// TODO/LATER: is EmbeddedObjectContainer not enough?
// the created document will be closed by pDoc ( should use SfxObjectShellLock )
pPersistShell = new SwDocShell( pDoc, SfxObjectCreateMode::INTERNAL );
2011-03-15 13:50:53 +00:00
pDoc->SetTmpDocShell( pPersistShell );
pPersistShell->DoInitNew( NULL );
2000-09-18 23:08:29 +00:00
}
// We insert it at SvPersist level
// TODO/LATER: check if using the same naming scheme for all apps works here
OUString aNewName/*( Sw3Io::UniqueName( p->GetStorage(), "Obj" ) )*/;
SfxObjectShell* pSrc = GetDoc()->GetPersist();
pPersistShell->GetEmbeddedObjectContainer().CopyAndGetEmbeddedObject(
pSrc->GetEmbeddedObjectContainer(),
pSrc->GetEmbeddedObjectContainer().GetEmbeddedObject( aOLEObj.aName ),
aNewName,
OUString(),
OUString());
SwOLENode* pOLENd = pDoc->GetNodes().MakeOLENode( rIdx, aNewName, GetAspect(),
pDoc->GetDfltGrfFormatColl(),
const_cast<SwAttrSet*>(GetpSwAttrSet()) );
2000-09-18 23:08:29 +00:00
pOLENd->SetChartTableName( GetChartTableName() );
CWS-TOOLING: integrate CWS sw32a11y01 2009-08-27 10:11:46 +0200 hde r275457 : new testcase i103265 2009-08-27 08:24:31 +0200 hde r275454 : new testcase i103265 2009-08-27 08:23:05 +0200 hde r275453 : new document for testcase i103265 2009-08-26 13:43:33 +0200 hde r275421 : added new autotest 2009-08-26 13:36:28 +0200 hde r275420 : added new autotest 2009-08-18 15:41:18 +0200 od r275113 : #i104300# method <SwEditWin::RequestHelp(..)> - improve help tip for hyperlinks to cross-reference bookmarks. 2009-08-10 15:18:41 +0200 od r274816 : #i73249# method <SwFrameShell::Execute(..)> - no update of fly frame manager on dialog "Title and Description" 2009-08-10 14:24:15 +0200 od r274813 : #i92125# correction of end of file - missing newline end 2009-08-10 14:10:14 +0200 od r274811 : #i92125# correction of end of file - newline missing 2009-08-10 14:00:30 +0200 od r274808 : #i92125# - correct end of file - new line missing 2009-08-10 09:12:30 +0200 od r274794 : CWS-TOOLING: rebase CWS sw32a11y01 to trunk@274622 (milestone: DEV300:m54) 2009-08-07 15:52:59 +0200 od r274775 : #i73249# minor adjustment due to compiler warning 2009-08-07 15:40:38 +0200 od r274774 : #i92125# method <MarkManager::deleteMarks(..)> - do not delete cross-reference bookmark, if deletion occurs inside a certain node 2009-08-06 12:53:05 +0200 od r274717 : #i92125# method <MarkManager::deleteMarks(..) - no move of position for cross-reference bookmark, if move occurs inside certain node. 2009-08-06 12:50:27 +0200 od r274716 : #i92125# method <SwUndoSaveCntnt::DelCntntIndex(..)> - keep cross-reference bookmarks, if deletion occurs inside a certain node. 2009-08-06 09:53:29 +0200 od r274705 : #i103265# method <SwTOXPara::GetURL()> - For outline and template entries create link to bookmark. The bookmark of type CROSSREF_HEADING_BOOKMARK is created, if needed 2009-07-22 13:57:04 +0200 od r274236 : #i73249# adjustment for export of svg:title and svg:description 2009-07-22 13:51:58 +0200 od r274234 : #i73249# adjust and enhance import/export of svg:title and svg:description for Writer's text frames, graphics and embedded objects 2009-07-21 10:26:27 +0200 od r274168 : #i73249# implement support for attributes Title and Description for text frames, graphics and embedded objects in Writer - core, UNO-API, undo/redo and UI 2009-07-21 10:05:15 +0200 od r274164 : #i73249# new optional properties Title and Description as basis frame properties in text documents 2009-07-13 12:19:54 +0200 od r273928 : #i73249# Implementation of Undo/Redo of drawing object's name, title and description
2009-08-27 11:59:20 +00:00
pOLENd->SetTitle( GetTitle() );
pOLENd->SetDescription( GetDescription() );
pOLENd->SetContour( HasContour(), HasAutomaticContour() );
pOLENd->SetAspect( GetAspect() ); // the replacement image must be already copied
2000-09-18 23:08:29 +00:00
pOLENd->SetOLESizeInvalid( true );
2000-09-18 23:08:29 +00:00
pDoc->SetOLEPrtNotifyPending();
return pOLENd;
}
bool SwOLENode::IsInGlobalDocSection() const
2000-09-18 23:08:29 +00:00
{
// Find the "Body Anchor"
sal_uLong nEndExtraIdx = GetNodes().GetEndOfExtras().GetIndex();
2000-09-18 23:08:29 +00:00
const SwNode* pAnchorNd = this;
do {
SwFrameFormat* pFlyFormat = pAnchorNd->GetFlyFormat();
if( !pFlyFormat )
return false;
2000-09-18 23:08:29 +00:00
const SwFormatAnchor& rAnchor = pFlyFormat->GetAnchor();
if( !rAnchor.GetContentAnchor() )
return false;
2000-09-18 23:08:29 +00:00
pAnchorNd = &rAnchor.GetContentAnchor()->nNode.GetNode();
2000-09-18 23:08:29 +00:00
} while( pAnchorNd->GetIndex() < nEndExtraIdx );
const SwSectionNode* pSectNd = pAnchorNd->FindSectionNode();
if( !pSectNd )
return false;
2000-09-18 23:08:29 +00:00
while( pSectNd )
{
pAnchorNd = pSectNd;
pSectNd = pAnchorNd->StartOfSectionNode()->FindSectionNode();
2000-09-18 23:08:29 +00:00
}
// pAnchorNd contains the most recently found Section Node, which
// now must fulfill the prerequesites for the GlobalDoc
pSectNd = static_cast<const SwSectionNode*>(pAnchorNd);
2000-09-18 23:08:29 +00:00
return FILE_LINK_SECTION == pSectNd->GetSection().GetType() &&
pSectNd->GetIndex() > nEndExtraIdx;
}
bool SwOLENode::IsOLEObjectDeleted() const
2000-09-18 23:08:29 +00:00
{
bool bRet = false;
if( aOLEObj.xOLERef.is() )
2000-09-18 23:08:29 +00:00
{
SfxObjectShell* p = GetDoc()->GetPersist();
if( p ) // Must be there
2000-09-18 23:08:29 +00:00
{
return !p->GetEmbeddedObjectContainer().HasEmbeddedObject( aOLEObj.aName );
2000-09-18 23:08:29 +00:00
}
}
return bRet;
}
void SwOLENode::GetNewReplacement()
{
if ( aOLEObj.xOLERef.is() )
aOLEObj.xOLERef.UpdateReplacement();
}
bool SwOLENode::UpdateLinkURL_Impl()
{
bool bResult = false;
if ( mpObjectLink )
{
OUString aNewLinkURL;
sfx2::LinkManager::GetDisplayNames( mpObjectLink, 0, &aNewLinkURL, 0, 0 );
if ( !aNewLinkURL.equalsIgnoreAsciiCase( maLinkURL ) )
{
if ( !aOLEObj.xOLERef.is() )
aOLEObj.GetOleRef();
uno::Reference< embed::XEmbeddedObject > xObj = aOLEObj.xOLERef.GetObject();
uno::Reference< embed::XCommonEmbedPersist > xPersObj( xObj, uno::UNO_QUERY );
OSL_ENSURE( xPersObj.is(), "The object must exist!\n" );
if ( xPersObj.is() )
{
try
{
sal_Int32 nCurState = xObj->getCurrentState();
if ( nCurState != embed::EmbedStates::LOADED )
xObj->changeState( embed::EmbedStates::LOADED );
// TODO/LATER: there should be possible to get current mediadescriptor settings from the object
uno::Sequence< beans::PropertyValue > aArgs( 1 );
aArgs[0].Name = "URL";
aArgs[0].Value <<= aNewLinkURL;
xPersObj->reload( aArgs, uno::Sequence< beans::PropertyValue >() );
maLinkURL = aNewLinkURL;
bResult = true;
if ( nCurState != embed::EmbedStates::LOADED )
xObj->changeState( nCurState );
}
catch( uno::Exception& )
{}
}
if ( !bResult )
{
// TODO/LATER: return the old name to the link manager, is it possible?
}
}
}
return bResult;
}
void SwOLENode::BreakFileLink_Impl()
{
SfxObjectShell* pPers = GetDoc()->GetPersist();
if ( pPers )
{
uno::Reference< embed::XStorage > xStorage = pPers->GetStorage();
if ( xStorage.is() )
{
try
{
uno::Reference< embed::XLinkageSupport > xLinkSupport( aOLEObj.GetOleRef(), uno::UNO_QUERY_THROW );
xLinkSupport->breakLink( xStorage, aOLEObj.GetCurrentPersistName() );
DisconnectFileLink_Impl();
maLinkURL.clear();
}
catch( uno::Exception& )
{
}
}
}
}
void SwOLENode::DisconnectFileLink_Impl()
{
if ( mpObjectLink )
{
GetDoc()->getIDocumentLinksAdministration().GetLinkManager().Remove( mpObjectLink );
mpObjectLink = NULL;
}
}
void SwOLENode::CheckFileLink_Impl()
{
if ( aOLEObj.xOLERef.GetObject().is() && !mpObjectLink )
{
try
{
uno::Reference< embed::XLinkageSupport > xLinkSupport( aOLEObj.xOLERef.GetObject(), uno::UNO_QUERY_THROW );
if ( xLinkSupport->isLink() )
{
const OUString aLinkURL = xLinkSupport->getLinkURL();
if ( !aLinkURL.isEmpty() )
{
// this is a file link so the model link manager should handle it
mpObjectLink = new SwEmbedObjectLink( this );
maLinkURL = aLinkURL;
GetDoc()->getIDocumentLinksAdministration().GetLinkManager().InsertFileLink( *mpObjectLink, OBJECT_CLIENT_OLE, aLinkURL, NULL, NULL );
mpObjectLink->Connect();
}
}
}
catch( uno::Exception& )
{
}
}
}
// #i99665#
bool SwOLENode::IsChart() const
{
bool bIsChart( false );
const uno::Reference< embed::XEmbeddedObject > xEmbObj =
const_cast<SwOLEObj&>(GetOLEObj()).GetOleRef();
if ( xEmbObj.is() )
{
SvGlobalName aClassID( xEmbObj->getClassID() );
bIsChart = SotExchange::IsChart( aClassID );
}
return bIsChart;
}
SwOLEObj::SwOLEObj( const svt::EmbeddedObjectRef& xObj ) :
pOLENd( 0 ),
pListener( 0 ),
xOLERef( xObj )
2000-09-18 23:08:29 +00:00
{
xOLERef.Lock( true );
if ( xObj.is() )
{
pListener = new SwOLEListener_Impl( this );
pListener->acquire();
xObj->addStateChangeListener( pListener );
}
2000-09-18 23:08:29 +00:00
}
SwOLEObj::SwOLEObj( const OUString &rString, sal_Int64 nAspect ) :
2000-09-18 23:08:29 +00:00
pOLENd( 0 ),
pListener( 0 ),
aName( rString )
2000-09-18 23:08:29 +00:00
{
xOLERef.Lock( true );
xOLERef.SetViewAspect( nAspect );
2000-09-18 23:08:29 +00:00
}
SwOLEObj::~SwOLEObj()
{
if( pListener )
{
if ( xOLERef.is() )
xOLERef->removeStateChangeListener( pListener );
pListener->Release();
}
if( pOLENd && !pOLENd->GetDoc()->IsInDtor() )
2000-09-18 23:08:29 +00:00
{
// if the model is not currently in destruction it means that this object should be removed from the model
comphelper::EmbeddedObjectContainer* pCnt = xOLERef.GetContainer();
#if OSL_DEBUG_LEVEL > 0
SfxObjectShell* p = pOLENd->GetDoc()->GetPersist();
OSL_ENSURE( p, "No document!" );
if( p )
{
comphelper::EmbeddedObjectContainer& rCnt = p->GetEmbeddedObjectContainer();
OSL_ENSURE( !pCnt || &rCnt == pCnt, "The helper is assigned to unexpected container!\n" );
}
#endif
if ( pCnt && pCnt->HasEmbeddedObject( aName ) )
{
uno::Reference < container::XChild > xChild( xOLERef.GetObject(), uno::UNO_QUERY );
if ( xChild.is() )
xChild->setParent( 0 );
// not already removed by deleting the object
xOLERef.AssignToContainer( 0, aName );
// unlock object so that object can be closed in RemoveEmbeddedObject
// successful closing of the object will automatically clear the reference then
xOLERef.Lock(false);
// Always remove object from container it is connected to
try
{
// remove object from container but don't close it
pCnt->RemoveEmbeddedObject( aName, false);
}
catch ( uno::Exception& )
{
}
}
2000-09-18 23:08:29 +00:00
}
if ( xOLERef.is() )
// in case the object wasn't closed: release it
// in case the object was not in the container: it's still locked, try to close
xOLERef.Clear();
2000-09-18 23:08:29 +00:00
}
void SwOLEObj::SetNode( SwOLENode* pNode )
{
pOLENd = pNode;
if ( aName.isEmpty() )
2000-09-18 23:08:29 +00:00
{
SwDoc* pDoc = pNode->GetDoc();
// If there's already a SvPersist instance, we use it
SfxObjectShell* p = pDoc->GetPersist();
2000-09-18 23:08:29 +00:00
if( !p )
{
// TODO/LATER: Isn't a EmbeddedObjectContainer sufficient here?
// What happens to the document?
OSL_ENSURE( false, "Why are we creating a DocShell here??" );
p = new SwDocShell( pDoc, SfxObjectCreateMode::INTERNAL );
2000-09-18 23:08:29 +00:00
p->DoInitNew( NULL );
}
OUString aObjName;
uno::Reference < container::XChild > xChild( xOLERef.GetObject(), uno::UNO_QUERY );
if ( xChild.is() && xChild->getParent() != p->GetModel() )
// it is possible that the parent was set already
xChild->setParent( p->GetModel() );
if (!p->GetEmbeddedObjectContainer().InsertEmbeddedObject( xOLERef.GetObject(), aObjName ) )
{
2011-03-01 19:09:12 +01:00
OSL_FAIL( "InsertObject failed" );
if ( xChild.is() )
xChild->setParent( 0 );
}
else
xOLERef.AssignToContainer( &p->GetEmbeddedObjectContainer(), aObjName );
const_cast<SwOLENode*>(pOLENd)->CheckFileLink_Impl(); // for this notification nonconst access is required
aName = aObjName;
2000-09-18 23:08:29 +00:00
}
}
OUString SwOLEObj::GetStyleString()
{
OUString strStyle;
if (xOLERef.is() && xOLERef.IsChart())
strStyle = xOLERef.GetChartType();
return strStyle;
}
bool SwOLEObj::IsOleRef() const
2000-09-18 23:08:29 +00:00
{
return xOLERef.is();
2000-09-18 23:08:29 +00:00
}
const uno::Reference < embed::XEmbeddedObject > SwOLEObj::GetOleRef()
2000-09-18 23:08:29 +00:00
{
if( !xOLERef.is() )
2000-09-18 23:08:29 +00:00
{
SfxObjectShell* p = pOLENd->GetDoc()->GetPersist();
OSL_ENSURE( p, "No SvPersist present" );
2000-09-18 23:08:29 +00:00
uno::Reference < embed::XEmbeddedObject > xObj = p->GetEmbeddedObjectContainer().GetEmbeddedObject( aName );
OSL_ENSURE( !xOLERef.is(), "Calling GetOleRef() recursively is not permitted" );
2000-09-18 23:08:29 +00:00
if ( !xObj.is() )
2000-09-18 23:08:29 +00:00
{
// We could not load this part (probably broken)
2000-09-18 23:08:29 +00:00
Rectangle aArea;
SwFrm *pFrm = pOLENd->getLayoutFrm(0);
2000-09-18 23:08:29 +00:00
if ( pFrm )
{
Size aSz( pFrm->Frm().SSize() );
const MapMode aSrc ( MAP_TWIP );
const MapMode aDest( MAP_100TH_MM );
aSz = OutputDevice::LogicToLogic( aSz, aSrc, aDest );
aArea.SetSize( aSz );
}
else
aArea.SetSize( Size( 5000, 5000 ) );
// TODO/LATER: set replacement graphic for dead object
// It looks as if it should work even without the object, because the replace will be generated automatically
OUString aTmpName;
xObj = p->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_DUMMY_CLASSID ).GetByteSequence(), aTmpName );
2000-09-18 23:08:29 +00:00
}
// else
{
xOLERef.Assign( xObj, xOLERef.GetViewAspect() );
xOLERef.AssignToContainer( &p->GetEmbeddedObjectContainer(), aName );
pListener = new SwOLEListener_Impl( this );
pListener->acquire();
xObj->addStateChangeListener( pListener );
}
const_cast<SwOLENode*>(pOLENd)->CheckFileLink_Impl(); // for this notification nonconst access is required
2000-09-18 23:08:29 +00:00
}
else if ( xOLERef->getCurrentState() == embed::EmbedStates::RUNNING )
{
// move object to first position in cache
if( !pOLELRU_Cache )
pOLELRU_Cache = new SwOLELRUCache;
pOLELRU_Cache->InsertObj( *this );
}
2000-09-18 23:08:29 +00:00
return xOLERef.GetObject();
2000-09-18 23:08:29 +00:00
}
svt::EmbeddedObjectRef& SwOLEObj::GetObject()
{
GetOleRef();
return xOLERef;
}
bool SwOLEObj::UnloadObject()
2000-09-18 23:08:29 +00:00
{
bool bRet = true;
if ( pOLENd )
{
const SwDoc* pDoc = pOLENd->GetDoc();
bRet = UnloadObject( xOLERef.GetObject(), pDoc, xOLERef.GetViewAspect() );
}
return bRet;
}
bool SwOLEObj::UnloadObject( uno::Reference< embed::XEmbeddedObject > xObj, const SwDoc* pDoc, sal_Int64 nAspect )
{
if ( !pDoc )
return false;
bool bRet = true;
sal_Int32 nState = xObj.is() ? xObj->getCurrentState() : embed::EmbedStates::LOADED;
bool bIsActive = ( nState != embed::EmbedStates::LOADED && nState != embed::EmbedStates::RUNNING );
sal_Int64 nMiscStatus = xObj->getStatus( nAspect );
if( nState != embed::EmbedStates::LOADED && !pDoc->IsInDtor() && !bIsActive &&
embed::EmbedMisc::MS_EMBED_ALWAYSRUN != ( nMiscStatus & embed::EmbedMisc::MS_EMBED_ALWAYSRUN ) &&
embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY != ( nMiscStatus & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) )
2000-09-18 23:08:29 +00:00
{
SfxObjectShell* p = pDoc->GetPersist();
2000-09-18 23:08:29 +00:00
if( p )
{
if( pDoc->GetDocumentSettingManager().get(DocumentSettingId::PURGE_OLE) )
2000-09-18 23:08:29 +00:00
{
try
2000-09-18 23:08:29 +00:00
{
uno::Reference < util::XModifiable > xMod( xObj->getComponent(), uno::UNO_QUERY );
if( xMod.is() && xMod->isModified() )
{
uno::Reference < embed::XEmbedPersist > xPers( xObj, uno::UNO_QUERY );
if ( xPers.is() )
xPers->storeOwn();
else {
2014-03-29 18:15:35 +01:00
OSL_FAIL("Modified object without persistence in cache!");
}
}
2000-09-18 23:08:29 +00:00
// setting object to loaded state will remove it from cache
xObj->changeState( embed::EmbedStates::LOADED );
}
catch ( uno::Exception& )
{
bRet = false;
}
2000-09-18 23:08:29 +00:00
}
else
bRet = false;
2000-09-18 23:08:29 +00:00
}
}
2000-09-18 23:08:29 +00:00
return bRet;
}
OUString SwOLEObj::GetDescription()
{
uno::Reference< embed::XEmbeddedObject > xEmbObj = GetOleRef();
if ( !xEmbObj.is() )
return OUString();
SvGlobalName aClassID( xEmbObj->getClassID() );
if ( SotExchange::IsMath( aClassID ) )
return SW_RESSTR(STR_MATH_FORMULA);
if ( SotExchange::IsChart( aClassID ) )
return SW_RESSTR(STR_CHART);
return SW_RESSTR(STR_OLE);
}
SwOLELRUCache::SwOLELRUCache()
: utl::ConfigItem(OUString("Office.Common/Cache"))
, m_nLRU_InitSize( 20 )
{
EnableNotification( GetPropertyNames() );
Load();
}
uno::Sequence< OUString > SwOLELRUCache::GetPropertyNames()
{
Sequence< OUString > aNames( 1 );
OUString* pNames = aNames.getArray();
pNames[0] = "Writer/OLE_Objects";
return aNames;
}
void SwOLELRUCache::Notify( const uno::Sequence< OUString>& )
{
Load();
}
void SwOLELRUCache::ImplCommit()
{
}
void SwOLELRUCache::Load()
{
Sequence< OUString > aNames( GetPropertyNames() );
Sequence< Any > aValues = GetProperties( aNames );
const Any* pValues = aValues.getConstArray();
OSL_ENSURE( aValues.getLength() == aNames.getLength(), "GetProperties failed" );
if( aValues.getLength() == aNames.getLength() && pValues->hasValue() )
{
sal_Int32 nVal = 0;
*pValues >>= nVal;
{
if (nVal < m_nLRU_InitSize)
{
// size of cache has been changed
sal_Int32 nCount = m_OleObjects.size();
sal_Int32 nPos = nCount;
// try to remove the last entries until new maximum size is reached
while( nCount > nVal )
{
SwOLEObj *const pObj = m_OleObjects[ --nPos ];
if ( pObj->UnloadObject() )
nCount--;
if ( !nPos )
break;
}
}
}
m_nLRU_InitSize = nVal;
}
}
2000-09-18 23:08:29 +00:00
void SwOLELRUCache::InsertObj( SwOLEObj& rObj )
2000-09-18 23:08:29 +00:00
{
SwOLEObj* pObj = &rObj;
OleObjects_t::iterator it =
std::find(m_OleObjects.begin(), m_OleObjects.end(), pObj);
if (it != m_OleObjects.end() && it != m_OleObjects.begin())
2000-09-18 23:08:29 +00:00
{
// object in cache but is currently not the first in cache
m_OleObjects.erase(it);
it = m_OleObjects.end();
}
if (it == m_OleObjects.end())
{
// try to remove objects if necessary
sal_Int32 nCount = m_OleObjects.size();
sal_Int32 nPos = nCount-1;
while (nPos >= 0 && nCount >= m_nLRU_InitSize)
{
pObj = m_OleObjects[ nPos-- ];
if ( pObj->UnloadObject() )
nCount--;
2000-09-18 23:08:29 +00:00
}
m_OleObjects.push_front(&rObj);
2000-09-18 23:08:29 +00:00
}
}
void SwOLELRUCache::RemoveObj( SwOLEObj& rObj )
2000-09-18 23:08:29 +00:00
{
OleObjects_t::iterator const it =
std::find(m_OleObjects.begin(), m_OleObjects.end(), &rObj);
if (it != m_OleObjects.end())
{
m_OleObjects.erase(it);
}
if (m_OleObjects.empty())
{
DELETEZ( pOLELRU_Cache );
}
2000-09-18 23:08:29 +00:00
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */