Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
30 : : #include <com/sun/star/container/XChild.hpp>
31 : : #include <com/sun/star/embed/XEmbedPersist.hpp>
32 : : #include <com/sun/star/embed/XLinkageSupport.hpp>
33 : : #include <com/sun/star/embed/Aspects.hpp>
34 : : #include <com/sun/star/embed/EmbedMisc.hpp>
35 : : #include <com/sun/star/embed/EmbedStates.hpp>
36 : : #include <com/sun/star/util/XCloseable.hpp>
37 : : #include <com/sun/star/util/XModifiable.hpp>
38 : : #include <com/sun/star/document/XEventBroadcaster.hpp>
39 : : #include <cppuhelper/implbase1.hxx>
40 : :
41 : : #include <cppuhelper/implbase2.hxx>
42 : : #include <toolkit/helper/vclunohelper.hxx>
43 : : #include <hintids.hxx>
44 : : #include <sfx2/docfile.hxx>
45 : : #include <sfx2/app.hxx>
46 : : #include <sfx2/linkmgr.hxx>
47 : : #include <unotools/configitem.hxx>
48 : : #include <vcl/outdev.hxx>
49 : : #include <fmtanchr.hxx>
50 : : #include <frmfmt.hxx>
51 : : #include <doc.hxx>
52 : : #include <docsh.hxx>
53 : : #include <pam.hxx>
54 : : #include <section.hxx>
55 : : #include <cntfrm.hxx>
56 : : #include <frmatr.hxx>
57 : : #include <ndole.hxx>
58 : :
59 : : #include <comphelper/classids.hxx>
60 : : #include <vcl/graph.hxx>
61 : : #include <sot/formats.hxx>
62 : : #include <unotools/ucbstreamhelper.hxx>
63 : : #include <svtools/filter.hxx>
64 : : #include <comcore.hrc>
65 : :
66 : : using rtl::OUString;
67 : : using namespace utl;
68 : : using namespace com::sun::star::uno;
69 : : using namespace com::sun::star;
70 : :
71 [ - + ]: 180 : class SwOLELRUCache
72 : : : private utl::ConfigItem
73 : : {
74 : : private:
75 : : typedef std::deque<SwOLEObj *> OleObjects_t;
76 : : OleObjects_t m_OleObjects;
77 : : sal_Int32 m_nLRU_InitSize;
78 : : uno::Sequence< rtl::OUString > GetPropertyNames();
79 : :
80 : : public:
81 : : SwOLELRUCache();
82 : :
83 : : virtual void Notify( const uno::Sequence<
84 : : rtl::OUString>& aPropertyNames );
85 : : virtual void Commit();
86 : : void Load();
87 : :
88 : : void InsertObj( SwOLEObj& rObj );
89 : : void RemoveObj( SwOLEObj& rObj );
90 : :
91 : : void RemovePtr( SwOLEObj* pObj )
92 : : {
93 : : OleObjects_t::iterator const it =
94 : : std::find(m_OleObjects.begin(), m_OleObjects.end(), pObj);
95 : : if (it != m_OleObjects.end())
96 : : {
97 : : m_OleObjects.erase(it);
98 : : }
99 : : }
100 : : };
101 : :
102 : : SwOLELRUCache* pOLELRU_Cache = 0;
103 : :
104 [ - + ]: 694 : class SwOLEListener_Impl : public ::cppu::WeakImplHelper1< embed::XStateChangeListener >
105 : : {
106 : : SwOLEObj* mpObj;
107 : : public:
108 : : SwOLEListener_Impl( SwOLEObj* pObj );
109 : : void Release();
110 : : virtual void SAL_CALL changingState( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (embed::WrongStateException, uno::RuntimeException);
111 : : virtual void SAL_CALL stateChanged( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (uno::RuntimeException);
112 : : virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) throw (uno::RuntimeException);
113 : : };
114 : :
115 : 434 : SwOLEListener_Impl::SwOLEListener_Impl( SwOLEObj* pObj )
116 : 434 : : mpObj( pObj )
117 : : {
118 [ + - ][ + - ]: 434 : if ( mpObj->IsOleRef() && mpObj->GetOleRef()->getCurrentState() == embed::EmbedStates::RUNNING )
[ + - ][ + - ]
[ + + ][ + - ]
[ + + # # ]
[ + - ]
119 : : {
120 [ + - ]: 432 : pOLELRU_Cache->InsertObj( *mpObj );
121 : : }
122 : 434 : }
123 : :
124 : 42 : void SAL_CALL SwOLEListener_Impl::changingState( const lang::EventObject&, ::sal_Int32 , ::sal_Int32 ) throw (embed::WrongStateException, uno::RuntimeException)
125 : : {
126 : 42 : }
127 : :
128 : 42 : void SAL_CALL SwOLEListener_Impl::stateChanged( const lang::EventObject&, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (uno::RuntimeException)
129 : : {
130 [ + - ][ - + ]: 42 : if ( mpObj && nOldState == embed::EmbedStates::LOADED && nNewState == embed::EmbedStates::RUNNING )
[ # # ]
131 : : {
132 [ # # ]: 0 : if( !pOLELRU_Cache )
133 [ # # ]: 0 : pOLELRU_Cache = new SwOLELRUCache;
134 : 0 : pOLELRU_Cache->InsertObj( *mpObj );
135 : : }
136 [ + - ][ + + ]: 42 : else if ( mpObj && nNewState == embed::EmbedStates::LOADED && nOldState == embed::EmbedStates::RUNNING )
[ + - ]
137 : : {
138 [ + - ]: 38 : if ( pOLELRU_Cache )
139 : 38 : pOLELRU_Cache->RemoveObj( *mpObj );
140 : : }
141 : 42 : }
142 : :
143 : 347 : void SwOLEListener_Impl::Release()
144 : : {
145 [ + - ][ + + ]: 347 : if ( mpObj && pOLELRU_Cache )
146 : 343 : pOLELRU_Cache->RemoveObj( *mpObj );
147 : 347 : mpObj=0;
148 : 347 : release();
149 : 347 : }
150 : :
151 : 0 : void SAL_CALL SwOLEListener_Impl::disposing( const lang::EventObject& ) throw (uno::RuntimeException)
152 : : {
153 [ # # ][ # # ]: 0 : if ( mpObj && pOLELRU_Cache )
154 : 0 : pOLELRU_Cache->RemoveObj( *mpObj );
155 : 0 : }
156 : :
157 : : // --------------------
158 : : // SwEmbedObjectLink
159 : : // --------------------
160 : : // TODO/LATER: actually SwEmbedObjectLink should be used here, but because different objects are used to control
161 : : // embedded object different link objects with the same functionality had to be implemented
162 : :
163 : : class SwEmbedObjectLink : public sfx2::SvBaseLink
164 : : {
165 : : SwOLENode* pOleNode;
166 : :
167 : : public:
168 : : SwEmbedObjectLink(SwOLENode* pNode);
169 : : virtual ~SwEmbedObjectLink();
170 : :
171 : : virtual void Closed();
172 : : virtual ::sfx2::SvBaseLink::UpdateResult DataChanged(
173 : : const String& rMimeType, const ::com::sun::star::uno::Any & rValue );
174 : :
175 : 0 : sal_Bool Connect() { return GetRealObject() != NULL; }
176 : : };
177 : :
178 : : // -----------------------------------------------------------------------------
179 : :
180 : 0 : SwEmbedObjectLink::SwEmbedObjectLink(SwOLENode* pNode):
181 : : ::sfx2::SvBaseLink( ::sfx2::LINKUPDATE_ONCALL, SOT_FORMATSTR_ID_SVXB ),
182 : 0 : pOleNode(pNode)
183 : : {
184 : 0 : SetSynchron( sal_False );
185 : 0 : }
186 : :
187 : : // -----------------------------------------------------------------------------
188 : :
189 : 0 : SwEmbedObjectLink::~SwEmbedObjectLink()
190 : : {
191 [ # # ]: 0 : }
192 : :
193 : : // -----------------------------------------------------------------------------
194 : :
195 : 0 : ::sfx2::SvBaseLink::UpdateResult SwEmbedObjectLink::DataChanged(
196 : : const String&, const uno::Any& )
197 : : {
198 [ # # ]: 0 : if ( !pOleNode->UpdateLinkURL_Impl() )
199 : : {
200 : : // the link URL was not changed
201 [ # # ]: 0 : uno::Reference< embed::XEmbeddedObject > xObject = pOleNode->GetOLEObj().GetOleRef();
202 : : OSL_ENSURE( xObject.is(), "The object must exist always!\n" );
203 [ # # ]: 0 : if ( xObject.is() )
204 : : {
205 : : // let the object reload the link
206 : : // TODO/LATER: reload call could be used for this case
207 : :
208 : : try
209 : : {
210 [ # # ][ # # ]: 0 : sal_Int32 nState = xObject->getCurrentState();
211 [ # # ]: 0 : if ( nState != embed::EmbedStates::LOADED )
212 : : {
213 : : // in some cases the linked file probably is not locked so it could be changed
214 [ # # ][ # # ]: 0 : xObject->changeState( embed::EmbedStates::LOADED );
215 [ # # ][ # # ]: 0 : xObject->changeState( nState );
216 : : }
217 : : }
218 [ # # ]: 0 : catch ( uno::Exception& )
219 : : {
220 : : }
221 : 0 : }
222 : : }
223 : :
224 : 0 : pOleNode->GetNewReplacement();
225 [ # # ]: 0 : return SUCCESS;
226 : : }
227 : :
228 : : // -----------------------------------------------------------------------------
229 : :
230 : 0 : void SwEmbedObjectLink::Closed()
231 : : {
232 : 0 : pOleNode->BreakFileLink_Impl();
233 : 0 : SvBaseLink::Closed();
234 : 0 : }
235 : :
236 : :
237 : : // --------------------
238 : : // SwOLENode
239 : : // --------------------
240 : :
241 : 432 : SwOLENode::SwOLENode( const SwNodeIndex &rWhere,
242 : : const svt::EmbeddedObjectRef& xObj,
243 : : SwGrfFmtColl *pGrfColl,
244 : : SwAttrSet* pAutoAttr ) :
245 : : SwNoTxtNode( rWhere, ND_OLENODE, pGrfColl, pAutoAttr ),
246 : : aOLEObj( xObj ),
247 : : pGraphic(0),
248 : : bOLESizeInvalid( sal_False ),
249 [ + - ][ + - ]: 432 : mpObjectLink( NULL )
[ + - ]
250 : : {
251 [ + - ]: 432 : aOLEObj.SetNode( this );
252 : 432 : }
253 : :
254 : 2 : SwOLENode::SwOLENode( const SwNodeIndex &rWhere,
255 : : const String &rString,
256 : : sal_Int64 nAspect,
257 : : SwGrfFmtColl *pGrfColl,
258 : : SwAttrSet* pAutoAttr ) :
259 : : SwNoTxtNode( rWhere, ND_OLENODE, pGrfColl, pAutoAttr ),
260 : : aOLEObj( rString, nAspect ),
261 : : pGraphic(0),
262 : : bOLESizeInvalid( sal_False ),
263 [ + - ][ + - ]: 2 : mpObjectLink( NULL )
[ + - ]
264 : : {
265 [ + - ]: 2 : aOLEObj.SetNode( this );
266 : 2 : }
267 : :
268 [ + - ][ + - ]: 347 : SwOLENode::~SwOLENode()
[ + - ]
269 : : {
270 [ + - ]: 347 : DisconnectFileLink_Impl();
271 [ - + ][ # # ]: 347 : delete pGraphic;
272 [ - + ]: 694 : }
273 : :
274 : 290 : Graphic* SwOLENode::GetGraphic()
275 : : {
276 [ + - ]: 290 : if ( aOLEObj.GetOleRef().is() )
277 : 290 : return aOLEObj.xOLERef.GetGraphic();
278 : 290 : return pGraphic;
279 : : }
280 : :
281 : 0 : SwCntntNode *SwOLENode::SplitCntntNode( const SwPosition & )
282 : : {
283 : : // OLE-Objecte vervielfaeltigen ??
284 : : OSL_FAIL( "OleNode: can't split." );
285 : 0 : return this;
286 : : }
287 : :
288 : : // Laden eines in den Undo-Bereich verschobenen OLE-Objekts
289 : :
290 : 0 : sal_Bool SwOLENode::RestorePersistentData()
291 : : {
292 : : OSL_ENSURE( aOLEObj.GetOleRef().is(), "No object to restore!" );
293 [ # # ]: 0 : if ( aOLEObj.xOLERef.is() )
294 : : {
295 : : // Falls bereits eine SvPersist-Instanz existiert, nehmen wir diese
296 [ # # ]: 0 : SfxObjectShell* p = GetDoc()->GetPersist();
297 [ # # ]: 0 : if( !p )
298 : : {
299 : : // TODO/LATER: reicht hier nicht ein EmbeddedObjectContainer? Was passiert mit
300 : : // diesem Dokument?
301 : : OSL_ENSURE( !this, "warum wird hier eine DocShell angelegt?" );
302 [ # # ][ # # ]: 0 : p = new SwDocShell( GetDoc(), SFX_CREATE_MODE_INTERNAL );
303 [ # # ]: 0 : p->DoInitNew( NULL );
304 : : }
305 : :
306 [ # # ]: 0 : uno::Reference < container::XChild > xChild( aOLEObj.xOLERef.GetObject(), uno::UNO_QUERY );
307 [ # # ]: 0 : if ( xChild.is() )
308 [ # # ][ # # ]: 0 : xChild->setParent( p->GetModel() );
[ # # ]
309 : :
310 : : OSL_ENSURE( aOLEObj.aName.Len(), "No object name!" );
311 : 0 : ::rtl::OUString aObjName;
312 [ # # ][ # # ]: 0 : if ( !p->GetEmbeddedObjectContainer().InsertEmbeddedObject( aOLEObj.xOLERef.GetObject(), aObjName ) )
[ # # ]
313 : : {
314 [ # # ]: 0 : if ( xChild.is() )
315 [ # # ][ # # ]: 0 : xChild->setParent( 0 );
[ # # ]
316 : : OSL_FAIL( "InsertObject failed" );
317 : : }
318 : : else
319 : : {
320 [ # # ]: 0 : aOLEObj.aName = aObjName;
321 [ # # ][ # # ]: 0 : aOLEObj.xOLERef.AssignToContainer( &p->GetEmbeddedObjectContainer(), aObjName );
322 [ # # ]: 0 : CheckFileLink_Impl();
323 : 0 : }
324 : : }
325 : :
326 : 0 : return sal_True;
327 : : }
328 : :
329 : : // OLE object is transported into UNDO area
330 : 2 : sal_Bool SwOLENode::SavePersistentData()
331 : : {
332 [ + - ]: 2 : if( aOLEObj.xOLERef.is() )
333 : : {
334 : 2 : comphelper::EmbeddedObjectContainer* pCnt = aOLEObj.xOLERef.GetContainer();
335 : :
336 : : #if OSL_DEBUG_LEVEL > 0
337 : : SfxObjectShell* p = GetDoc()->GetPersist();
338 : : OSL_ENSURE( p, "No document!" );
339 : : if( p )
340 : : {
341 : : comphelper::EmbeddedObjectContainer& rCnt = p->GetEmbeddedObjectContainer();
342 : : OSL_ENSURE( !pCnt || &rCnt == pCnt, "The helper is assigned to unexpected container!\n" );
343 : : }
344 : : #endif
345 : :
346 [ + - ][ + - ]: 2 : if ( pCnt && pCnt->HasEmbeddedObject( aOLEObj.aName ) )
[ + - ][ + - ]
[ + - # # ]
[ + - ]
347 : : {
348 [ + - ]: 2 : uno::Reference < container::XChild > xChild( aOLEObj.xOLERef.GetObject(), uno::UNO_QUERY );
349 [ + - ]: 2 : if ( xChild.is() )
350 [ + - ][ + - ]: 2 : xChild->setParent( 0 );
[ + - ]
351 : :
352 [ + - ][ + - ]: 2 : pCnt->RemoveEmbeddedObject( aOLEObj.aName, sal_False );
353 : :
354 : : // TODO/LATER: aOLEObj.aName has no meaning here, since the undo container contains the object
355 : : // by different name, in future it might makes sence that the name is transported here.
356 [ + - ][ # # ]: 2 : aOLEObj.xOLERef.AssignToContainer( 0, aOLEObj.aName );
[ + - ]
357 : : try
358 : : {
359 : : // "unload" object
360 [ + - ][ + - ]: 2 : aOLEObj.xOLERef->changeState( embed::EmbedStates::LOADED );
361 : : }
362 [ # # ]: 0 : catch ( uno::Exception& )
363 : : {
364 : 2 : }
365 : : }
366 : : }
367 : :
368 : 2 : DisconnectFileLink_Impl();
369 : :
370 : 2 : return sal_True;
371 : : }
372 : :
373 : :
374 : 432 : SwOLENode * SwNodes::MakeOLENode( const SwNodeIndex & rWhere,
375 : : const svt::EmbeddedObjectRef& xObj,
376 : : SwGrfFmtColl* pGrfColl,
377 : : SwAttrSet* pAutoAttr )
378 : : {
379 : : OSL_ENSURE( pGrfColl,"SwNodes::MakeOLENode: Formatpointer ist 0." );
380 : :
381 : : SwOLENode *pNode =
382 [ + - ][ + - ]: 432 : new SwOLENode( rWhere, xObj, pGrfColl, pAutoAttr );
383 : :
384 : : // set parent if XChild is supported
385 : : //!! needed to supply Math objects with a valid reference device
386 [ + - ][ + - ]: 432 : uno::Reference< container::XChild > xChild( pNode->GetOLEObj().GetObject().GetObject(), UNO_QUERY );
387 [ + - ]: 432 : if (xChild.is())
388 : : {
389 : 432 : SwDocShell *pDocSh = GetDoc()->GetDocShell();
390 [ + - ]: 432 : if (pDocSh)
391 [ + - ][ + - ]: 432 : xChild->setParent( pDocSh->GetModel() );
[ + - ]
392 : : }
393 : :
394 : 432 : return pNode;
395 : : }
396 : :
397 : :
398 : 2 : SwOLENode * SwNodes::MakeOLENode( const SwNodeIndex & rWhere,
399 : : const String &rName, sal_Int64 nAspect, SwGrfFmtColl* pGrfColl, SwAttrSet* pAutoAttr )
400 : : {
401 : : OSL_ENSURE( pGrfColl,"SwNodes::MakeOLENode: Formatpointer ist 0." );
402 : :
403 : : SwOLENode *pNode =
404 [ + - ][ + - ]: 2 : new SwOLENode( rWhere, rName, nAspect, pGrfColl, pAutoAttr );
405 : :
406 : : // set parent if XChild is supported
407 : : //!! needed to supply Math objects with a valid reference device
408 [ + - ][ + - ]: 2 : uno::Reference< container::XChild > xChild( pNode->GetOLEObj().GetObject().GetObject(), UNO_QUERY );
409 [ + - ]: 2 : if (xChild.is())
410 : : {
411 : 2 : SwDocShell *pDocSh= GetDoc()->GetDocShell();
412 [ + - ]: 2 : if (pDocSh)
413 [ + - ][ + - ]: 2 : xChild->setParent( pDocSh->GetModel() );
[ + - ]
414 : : }
415 : :
416 : 2 : return pNode;
417 : : }
418 : :
419 : 300 : Size SwOLENode::GetTwipSize() const
420 : : {
421 [ + - ]: 300 : MapMode aMapMode( MAP_TWIP );
422 [ + - ][ + - ]: 300 : return ((SwOLENode*)this)->aOLEObj.GetObject().GetSize( &aMapMode );
[ + - ]
423 : : }
424 : :
425 : 0 : SwCntntNode* SwOLENode::MakeCopy( SwDoc* pDoc, const SwNodeIndex& rIdx ) const
426 : : {
427 : : // Falls bereits eine SvPersist-Instanz existiert, nehmen wir diese
428 [ # # ]: 0 : SfxObjectShell* pPersistShell = pDoc->GetPersist();
429 [ # # ]: 0 : if( !pPersistShell )
430 : : {
431 : : // TODO/LATER: is EmbeddedObjectContainer not enough?
432 : : // the created document will be closed by pDoc ( should use SfxObjectShellLock )
433 [ # # ][ # # ]: 0 : pPersistShell = new SwDocShell( pDoc, SFX_CREATE_MODE_INTERNAL );
434 [ # # ][ # # ]: 0 : pDoc->SetTmpDocShell( pPersistShell );
[ # # ]
435 [ # # ]: 0 : pPersistShell->DoInitNew( NULL );
436 : : }
437 : :
438 : : // Wir hauen das Ding auf SvPersist-Ebene rein
439 : : // TODO/LATER: check if using the same naming scheme for all apps works here
440 : 0 : ::rtl::OUString aNewName/*( Sw3Io::UniqueName( p->GetStorage(), "Obj" ) )*/;
441 [ # # ]: 0 : SfxObjectShell* pSrc = GetDoc()->GetPersist();
442 : :
443 [ # # ]: 0 : pPersistShell->GetEmbeddedObjectContainer().CopyAndGetEmbeddedObject(
444 [ # # ]: 0 : pSrc->GetEmbeddedObjectContainer(),
445 [ # # ]: 0 : pSrc->GetEmbeddedObjectContainer().GetEmbeddedObject( aOLEObj.aName ),
446 [ # # ][ # # ]: 0 : aNewName );
[ # # ]
447 : :
448 [ # # ]: 0 : SwOLENode* pOLENd = pDoc->GetNodes().MakeOLENode( rIdx, aNewName, GetAspect(),
449 : 0 : (SwGrfFmtColl*)pDoc->GetDfltGrfFmtColl(),
450 [ # # ][ # # ]: 0 : (SwAttrSet*)GetpSwAttrSet() );
[ # # ]
[ # # # # ]
451 : :
452 [ # # ]: 0 : pOLENd->SetChartTblName( GetChartTblName() );
453 [ # # ][ # # ]: 0 : pOLENd->SetTitle( GetTitle() );
[ # # ]
454 [ # # ][ # # ]: 0 : pOLENd->SetDescription( GetDescription() );
[ # # ]
455 [ # # ][ # # ]: 0 : pOLENd->SetContour( HasContour(), HasAutomaticContour() );
456 [ # # ][ # # ]: 0 : pOLENd->SetAspect( GetAspect() ); // the replacement image must be already copied
457 : :
458 : 0 : pOLENd->SetOLESizeInvalid( sal_True );
459 : 0 : pDoc->SetOLEPrtNotifyPending();
460 : :
461 : 0 : return pOLENd;
462 : : }
463 : :
464 : 0 : sal_Bool SwOLENode::IsInGlobalDocSection() const
465 : : {
466 : : // suche den "Body Anchor"
467 : 0 : sal_uLong nEndExtraIdx = GetNodes().GetEndOfExtras().GetIndex();
468 : 0 : const SwNode* pAnchorNd = this;
469 [ # # ]: 0 : do {
470 : 0 : SwFrmFmt* pFlyFmt = pAnchorNd->GetFlyFmt();
471 [ # # ]: 0 : if( !pFlyFmt )
472 : 0 : return sal_False;
473 : :
474 : 0 : const SwFmtAnchor& rAnchor = pFlyFmt->GetAnchor();
475 [ # # ]: 0 : if( !rAnchor.GetCntntAnchor() )
476 : 0 : return sal_False;
477 : :
478 : 0 : pAnchorNd = &rAnchor.GetCntntAnchor()->nNode.GetNode();
479 : 0 : } while( pAnchorNd->GetIndex() < nEndExtraIdx );
480 : :
481 : 0 : const SwSectionNode* pSectNd = pAnchorNd->FindSectionNode();
482 [ # # ]: 0 : if( !pSectNd )
483 : 0 : return sal_False;
484 : :
485 [ # # ]: 0 : while( pSectNd )
486 : : {
487 : 0 : pAnchorNd = pSectNd;
488 : 0 : pSectNd = pAnchorNd->StartOfSectionNode()->FindSectionNode();
489 : : }
490 : :
491 : : // in pAnchorNd steht der zuletzt gefundene Section Node. Der muss
492 : : // jetzt die Bedingung fuers GlobalDoc erfuellen.
493 : 0 : pSectNd = (SwSectionNode*)pAnchorNd;
494 : 0 : return FILE_LINK_SECTION == pSectNd->GetSection().GetType() &&
495 [ # # ][ # # ]: 0 : pSectNd->GetIndex() > nEndExtraIdx;
496 : : }
497 : :
498 : 0 : sal_Bool SwOLENode::IsOLEObjectDeleted() const
499 : : {
500 : 0 : sal_Bool bRet = sal_False;
501 [ # # ]: 0 : if( aOLEObj.xOLERef.is() )
502 : : {
503 : 0 : SfxObjectShell* p = GetDoc()->GetPersist();
504 [ # # ]: 0 : if( p ) // muss da sein
505 : : {
506 [ # # ][ # # ]: 0 : return !p->GetEmbeddedObjectContainer().HasEmbeddedObject( aOLEObj.aName );
507 : : }
508 : : }
509 : 0 : return bRet;
510 : : }
511 : :
512 : 0 : void SwOLENode::GetNewReplacement()
513 : : {
514 [ # # ]: 0 : if ( aOLEObj.xOLERef.is() )
515 : 0 : aOLEObj.xOLERef.UpdateReplacement();
516 : 0 : }
517 : :
518 : 0 : sal_Bool SwOLENode::UpdateLinkURL_Impl()
519 : : {
520 : 0 : sal_Bool bResult = sal_False;
521 : :
522 [ # # ]: 0 : if ( mpObjectLink )
523 : : {
524 [ # # ]: 0 : String aNewLinkURL;
525 [ # # ][ # # ]: 0 : GetDoc()->GetLinkManager().GetDisplayNames( mpObjectLink, 0, &aNewLinkURL, 0, 0 );
526 [ # # ][ # # ]: 0 : if ( !aNewLinkURL.EqualsIgnoreCaseAscii( maLinkURL ) )
527 : : {
528 [ # # ]: 0 : if ( !aOLEObj.xOLERef.is() )
529 [ # # ]: 0 : aOLEObj.GetOleRef();
530 : :
531 : 0 : uno::Reference< embed::XEmbeddedObject > xObj = aOLEObj.xOLERef.GetObject();
532 [ # # ]: 0 : uno::Reference< embed::XCommonEmbedPersist > xPersObj( xObj, uno::UNO_QUERY );
533 : : OSL_ENSURE( xPersObj.is(), "The object must exist!\n" );
534 [ # # ]: 0 : if ( xPersObj.is() )
535 : : {
536 : : try
537 : : {
538 [ # # ][ # # ]: 0 : sal_Int32 nCurState = xObj->getCurrentState();
539 [ # # ]: 0 : if ( nCurState != embed::EmbedStates::LOADED )
540 [ # # ][ # # ]: 0 : xObj->changeState( embed::EmbedStates::LOADED );
541 : :
542 : : // TODO/LATER: there should be possible to get current mediadescriptor settings from the object
543 [ # # ]: 0 : uno::Sequence< beans::PropertyValue > aArgs( 1 );
544 [ # # ][ # # ]: 0 : aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
545 [ # # ][ # # ]: 0 : aArgs[0].Value <<= ::rtl::OUString( aNewLinkURL );
[ # # ]
546 [ # # ][ # # ]: 0 : xPersObj->reload( aArgs, uno::Sequence< beans::PropertyValue >() );
[ # # ][ # # ]
547 : :
548 [ # # ]: 0 : maLinkURL = aNewLinkURL;
549 : 0 : bResult = sal_True;
550 : :
551 [ # # ]: 0 : if ( nCurState != embed::EmbedStates::LOADED )
552 [ # # ][ # # ]: 0 : xObj->changeState( nCurState );
[ # # ][ # # ]
553 : : }
554 [ # # ]: 0 : catch( uno::Exception& )
555 : : {}
556 : : }
557 : :
558 : : if ( !bResult )
559 : : {
560 : : // TODO/LATER: return the old name to the link manager, is it possible?
561 : 0 : }
562 [ # # ]: 0 : }
563 : : }
564 : :
565 : 0 : return bResult;
566 : : }
567 : :
568 : 0 : void SwOLENode::BreakFileLink_Impl()
569 : : {
570 : 0 : SfxObjectShell* pPers = GetDoc()->GetPersist();
571 : :
572 [ # # ]: 0 : if ( pPers )
573 : : {
574 [ # # ]: 0 : uno::Reference< embed::XStorage > xStorage = pPers->GetStorage();
575 [ # # ]: 0 : if ( xStorage.is() )
576 : : {
577 : : try
578 : : {
579 [ # # ][ # # ]: 0 : uno::Reference< embed::XLinkageSupport > xLinkSupport( aOLEObj.GetOleRef(), uno::UNO_QUERY_THROW );
580 [ # # ][ # # ]: 0 : xLinkSupport->breakLink( xStorage, aOLEObj.GetCurrentPersistName() );
[ # # ]
581 [ # # ]: 0 : DisconnectFileLink_Impl();
582 [ # # ][ # # ]: 0 : maLinkURL = String();
[ # # ][ # # ]
583 : : }
584 [ # # ]: 0 : catch( uno::Exception& )
585 : : {
586 : : }
587 : 0 : }
588 : : }
589 : 0 : }
590 : :
591 : 349 : void SwOLENode::DisconnectFileLink_Impl()
592 : : {
593 [ - + ]: 349 : if ( mpObjectLink )
594 : : {
595 : 0 : GetDoc()->GetLinkManager().Remove( mpObjectLink );
596 : 0 : mpObjectLink = NULL;
597 : : }
598 : 349 : }
599 : :
600 : 434 : void SwOLENode::CheckFileLink_Impl()
601 : : {
602 [ + - ][ + - ]: 434 : if ( aOLEObj.xOLERef.GetObject().is() && !mpObjectLink )
[ + - ]
603 : : {
604 : : try
605 : : {
606 [ + - ]: 434 : uno::Reference< embed::XLinkageSupport > xLinkSupport( aOLEObj.xOLERef.GetObject(), uno::UNO_QUERY_THROW );
607 [ + - ][ + - ]: 434 : if ( xLinkSupport->isLink() )
[ - + ]
608 : : {
609 [ # # ][ # # ]: 0 : String aLinkURL = xLinkSupport->getLinkURL();
[ # # ]
610 [ # # ]: 0 : if ( aLinkURL.Len() )
611 : : {
612 : : // this is a file link so the model link manager should handle it
613 [ # # ][ # # ]: 0 : mpObjectLink = new SwEmbedObjectLink( this );
614 [ # # ]: 0 : maLinkURL = aLinkURL;
615 [ # # ][ # # ]: 0 : GetDoc()->GetLinkManager().InsertFileLink( *mpObjectLink, OBJECT_CLIENT_OLE, aLinkURL, NULL, NULL );
616 [ # # ]: 0 : mpObjectLink->Connect();
617 [ # # ]: 0 : }
618 [ # # ]: 434 : }
619 : : }
620 : 0 : catch( uno::Exception& )
621 : : {
622 : : }
623 : : }
624 : 434 : }
625 : :
626 : : // #i99665#
627 : 0 : bool SwOLENode::IsChart() const
628 : : {
629 : 0 : bool bIsChart( false );
630 : :
631 : : const uno::Reference< embed::XEmbeddedObject > xEmbObj =
632 [ # # ]: 0 : const_cast<SwOLEObj&>(GetOLEObj()).GetOleRef();
633 [ # # ]: 0 : if ( xEmbObj.is() )
634 : : {
635 [ # # ][ # # ]: 0 : SvGlobalName aClassID( xEmbObj->getClassID() );
[ # # ][ # # ]
636 [ # # ][ # # ]: 0 : bIsChart = SotExchange::IsChart( aClassID );
637 : : }
638 : :
639 : 0 : return bIsChart;
640 : : }
641 : :
642 : 432 : SwOLEObj::SwOLEObj( const svt::EmbeddedObjectRef& xObj ) :
643 : : pOLENd( 0 ),
644 : : pListener( 0 ),
645 [ + - ]: 432 : xOLERef( xObj )
646 : : {
647 [ + - ]: 432 : xOLERef.Lock( sal_True );
648 [ + - ]: 432 : if ( xObj.is() )
649 : : {
650 [ + - ]: 432 : pListener = new SwOLEListener_Impl( this );
651 : 432 : pListener->acquire();
652 [ + - ][ + - ]: 432 : xObj->addStateChangeListener( pListener );
[ + - ][ + - ]
653 : : }
654 : 432 : }
655 : :
656 : :
657 : 2 : SwOLEObj::SwOLEObj( const String &rString, sal_Int64 nAspect ) :
658 : : pOLENd( 0 ),
659 : : pListener( 0 ),
660 [ + - ]: 2 : aName( rString )
661 : : {
662 [ + - ]: 2 : xOLERef.Lock( sal_True );
663 [ + - ]: 2 : xOLERef.SetViewAspect( nAspect );
664 : 2 : }
665 : :
666 : :
667 [ + - ]: 347 : SwOLEObj::~SwOLEObj()
668 : : {
669 [ + - ]: 347 : if( pListener )
670 : : {
671 [ + - ]: 347 : if ( xOLERef.is() )
672 [ + - ][ + - ]: 347 : xOLERef->removeStateChangeListener( pListener );
[ + - ][ + - ]
673 [ + - ]: 347 : pListener->Release();
674 : : }
675 : :
676 [ + - ][ - + ]: 347 : if( pOLENd && !pOLENd->GetDoc()->IsInDtor() )
[ - + ]
677 : : {
678 : : // if the model is not currently in destruction it means that this object should be removed from the model
679 [ # # ]: 0 : comphelper::EmbeddedObjectContainer* pCnt = xOLERef.GetContainer();
680 : :
681 : : #if OSL_DEBUG_LEVEL > 0
682 : : SfxObjectShell* p = pOLENd->GetDoc()->GetPersist();
683 : : OSL_ENSURE( p, "No document!" );
684 : : if( p )
685 : : {
686 : : comphelper::EmbeddedObjectContainer& rCnt = p->GetEmbeddedObjectContainer();
687 : : OSL_ENSURE( !pCnt || &rCnt == pCnt, "The helper is assigned to unexpected container!\n" );
688 : : }
689 : : #endif
690 : :
691 [ # # ][ # # ]: 0 : if ( pCnt && pCnt->HasEmbeddedObject( aName ) )
[ # # ][ # # ]
[ # # ]
[ # # # # ]
692 : : {
693 [ # # ]: 0 : uno::Reference < container::XChild > xChild( xOLERef.GetObject(), uno::UNO_QUERY );
694 [ # # ]: 0 : if ( xChild.is() )
695 [ # # ][ # # ]: 0 : xChild->setParent( 0 );
[ # # ]
696 : :
697 : : // not already removed by deleting the object
698 [ # # ][ # # ]: 0 : xOLERef.AssignToContainer( 0, aName );
699 : :
700 : : // unlock object so that object can be closed in RemoveEmbeddedObject
701 : : // successful closing of the object will automatically clear the reference then
702 [ # # ]: 0 : xOLERef.Lock(sal_False);
703 : :
704 : : // Always remove object from conteiner it is connected to
705 : : try
706 : : {
707 [ # # ][ # # ]: 0 : pCnt->RemoveEmbeddedObject( aName );
[ # # ]
708 : : }
709 [ # # ]: 0 : catch ( uno::Exception& )
710 : : {
711 : 0 : }
712 : : }
713 : :
714 : : }
715 : :
716 [ + - ]: 347 : if ( xOLERef.is() )
717 : : // in case the object wasn't closed: release it
718 : : // in case the object was not in the container: it's still locked, try to close
719 [ + - ]: 347 : xOLERef.Clear();
720 : 347 : }
721 : :
722 : :
723 : 434 : void SwOLEObj::SetNode( SwOLENode* pNode )
724 : : {
725 : 434 : pOLENd = pNode;
726 [ + + ]: 434 : if ( !aName.Len() )
727 : : {
728 : 432 : SwDoc* pDoc = pNode->GetDoc();
729 : :
730 : : // Falls bereits eine SvPersist-Instanz existiert, nehmen wir diese
731 [ + - ]: 432 : SfxObjectShell* p = pDoc->GetPersist();
732 [ - + ]: 432 : if( !p )
733 : : {
734 : : // TODO/LATER: reicht hier nicht ein EmbeddedObjectContainer? Was passiert mit
735 : : // diesem Dokument?
736 : : OSL_ENSURE( !this, "warum wird hier eine DocShell angelegt?" );
737 [ # # ][ # # ]: 0 : p = new SwDocShell( pDoc, SFX_CREATE_MODE_INTERNAL );
738 [ # # ]: 0 : p->DoInitNew( NULL );
739 : : }
740 : :
741 : 432 : ::rtl::OUString aObjName;
742 [ + - ]: 432 : uno::Reference < container::XChild > xChild( xOLERef.GetObject(), uno::UNO_QUERY );
743 [ + - ][ + - ]: 432 : if ( xChild.is() && xChild->getParent() != p->GetModel() )
[ + - ][ + - ]
[ + - ][ + + ]
[ + - ][ + - ]
[ + + # #
# # ]
744 : : // it is possible that the parent was set already
745 [ + - ][ + - ]: 2 : xChild->setParent( p->GetModel() );
[ + - ]
746 [ + - ][ + - ]: 432 : if (!p->GetEmbeddedObjectContainer().InsertEmbeddedObject( xOLERef.GetObject(), aObjName ) )
[ - + ]
747 : : {
748 : : OSL_FAIL( "InsertObject failed" );
749 [ # # ]: 0 : if ( xChild.is() )
750 [ # # ][ # # ]: 0 : xChild->setParent( 0 );
[ # # ]
751 : : }
752 : : else
753 [ + - ][ + - ]: 432 : xOLERef.AssignToContainer( &p->GetEmbeddedObjectContainer(), aObjName );
754 : :
755 [ + - ]: 432 : ( (SwOLENode*)pOLENd )->CheckFileLink_Impl(); // for this notification nonconst access is required
756 : :
757 [ + - ]: 432 : aName = aObjName;
758 : : }
759 : 434 : }
760 : :
761 : 1299 : sal_Bool SwOLEObj::IsOleRef() const
762 : : {
763 : 1299 : return xOLERef.is();
764 : : }
765 : :
766 : 4249 : const uno::Reference < embed::XEmbeddedObject > SwOLEObj::GetOleRef()
767 : : {
768 [ + + ]: 4249 : if( !xOLERef.is() )
769 : : {
770 [ + - ]: 2 : SfxObjectShell* p = pOLENd->GetDoc()->GetPersist();
771 : : OSL_ENSURE( p, "kein SvPersist vorhanden" );
772 : :
773 [ + - ][ + - ]: 2 : uno::Reference < embed::XEmbeddedObject > xObj = p->GetEmbeddedObjectContainer().GetEmbeddedObject( aName );
[ + - ]
774 : : OSL_ENSURE( !xOLERef.is(), "rekursiver Aufruf von GetOleRef() ist nicht erlaubt" );
775 : :
776 [ - + ]: 2 : if ( !xObj.is() )
777 : : {
778 : : //Das Teil konnte nicht geladen werden (wahrsch. Kaputt).
779 [ # # ]: 0 : Rectangle aArea;
780 [ # # ]: 0 : SwFrm *pFrm = pOLENd->getLayoutFrm(0);
781 [ # # ]: 0 : if ( pFrm )
782 : : {
783 : 0 : Size aSz( pFrm->Frm().SSize() );
784 [ # # ]: 0 : const MapMode aSrc ( MAP_TWIP );
785 [ # # ]: 0 : const MapMode aDest( MAP_100TH_MM );
786 [ # # ]: 0 : aSz = OutputDevice::LogicToLogic( aSz, aSrc, aDest );
787 [ # # ][ # # ]: 0 : aArea.SetSize( aSz );
[ # # ]
788 : : }
789 : : else
790 [ # # ]: 0 : aArea.SetSize( Size( 5000, 5000 ) );
791 : : // TODO/LATER: set replacement graphic for dead object
792 : : // It looks as if it should work even without the object, because the replace will be generated automatically
793 : 0 : ::rtl::OUString aTmpName;
794 [ # # ][ # # ]: 0 : xObj = p->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_DUMMY_CLASSID ).GetByteSequence(), aTmpName );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
795 : : }
796 : : // else
797 : : {
798 [ + - ][ + - ]: 2 : xOLERef.Assign( xObj, xOLERef.GetViewAspect() );
799 [ + - ][ + - ]: 2 : xOLERef.AssignToContainer( &p->GetEmbeddedObjectContainer(), aName );
[ + - ]
800 [ + - ]: 2 : pListener = new SwOLEListener_Impl( this );
801 : 2 : pListener->acquire();
802 [ + - ][ + - ]: 2 : xObj->addStateChangeListener( pListener );
[ + - ][ + - ]
803 : : }
804 : :
805 [ + - ]: 2 : ( (SwOLENode*)pOLENd )->CheckFileLink_Impl(); // for this notification nonconst access is required
806 : : }
807 [ + + ]: 4247 : else if ( xOLERef->getCurrentState() == embed::EmbedStates::RUNNING )
808 : : {
809 : : // move object to first position in cache
810 [ + + ]: 4183 : if( !pOLELRU_Cache )
811 [ + - ]: 93 : pOLELRU_Cache = new SwOLELRUCache;
812 : 4183 : pOLELRU_Cache->InsertObj( *this );
813 : : }
814 : :
815 : 4249 : return xOLERef.GetObject();
816 : : }
817 : :
818 : 2423 : svt::EmbeddedObjectRef& SwOLEObj::GetObject()
819 : : {
820 : 2423 : GetOleRef();
821 : 2423 : return xOLERef;
822 : : }
823 : :
824 : 36 : sal_Bool SwOLEObj::UnloadObject()
825 : : {
826 : 36 : sal_Bool bRet = sal_True;
827 [ + - ]: 36 : if ( pOLENd )
828 : : {
829 : 36 : const SwDoc* pDoc = pOLENd->GetDoc();
830 [ + - ]: 36 : bRet = UnloadObject( xOLERef.GetObject(), pDoc, xOLERef.GetViewAspect() );
831 : : }
832 : :
833 : 36 : return bRet;
834 : : }
835 : :
836 : 36 : sal_Bool SwOLEObj::UnloadObject( uno::Reference< embed::XEmbeddedObject > xObj, const SwDoc* pDoc, sal_Int64 nAspect )
837 : : {
838 [ - + ]: 36 : if ( !pDoc )
839 : 0 : return sal_False;
840 : :
841 : 36 : sal_Bool bRet = sal_True;
842 [ + - ]: 36 : sal_Int32 nState = xObj.is() ? xObj->getCurrentState() : embed::EmbedStates::LOADED;
843 [ + - ][ - + ]: 36 : sal_Bool bIsActive = ( nState != embed::EmbedStates::LOADED && nState != embed::EmbedStates::RUNNING );
844 : 36 : sal_Int64 nMiscStatus = xObj->getStatus( nAspect );
845 : :
846 [ + - ][ + - ]: 36 : if( nState != embed::EmbedStates::LOADED && !pDoc->IsInDtor() && !bIsActive &&
[ + - ][ + - ]
[ + - ][ + - ]
847 : : embed::EmbedMisc::MS_EMBED_ALWAYSRUN != ( nMiscStatus & embed::EmbedMisc::MS_EMBED_ALWAYSRUN ) &&
848 : : embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY != ( nMiscStatus & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) )
849 : : {
850 : 36 : SfxObjectShell* p = pDoc->GetPersist();
851 [ + - ]: 36 : if( p )
852 : : {
853 [ + - ]: 36 : if( pDoc->get(IDocumentSettingAccess::PURGE_OLE) )
854 : : {
855 : : try
856 : : {
857 [ + - ][ + - ]: 36 : uno::Reference < util::XModifiable > xMod( xObj->getComponent(), uno::UNO_QUERY );
[ + - ]
858 [ + - ][ + - ]: 36 : if( xMod.is() && xMod->isModified() )
[ - + ][ - + ]
[ + - ]
859 : : {
860 [ # # ]: 0 : uno::Reference < embed::XEmbedPersist > xPers( xObj, uno::UNO_QUERY );
861 [ # # ]: 0 : if ( xPers.is() )
862 [ # # ][ # # ]: 0 : xPers->storeOwn();
863 : : else {
864 : : OSL_FAIL("Modified object without persistance in cache!");
865 : 0 : }
866 : : }
867 : :
868 : : // setting object to loaded state will remove it from cache
869 [ + - ][ + - ]: 36 : xObj->changeState( embed::EmbedStates::LOADED );
[ # # ]
870 : : }
871 : 0 : catch ( uno::Exception& )
872 : : {
873 : 0 : bRet = sal_False;
874 : : }
875 : : }
876 : : else
877 : 0 : bRet = sal_False;
878 : : }
879 : : }
880 : :
881 : 36 : return bRet;
882 : : }
883 : :
884 : 2 : String SwOLEObj::GetDescription()
885 : : {
886 [ + - ]: 2 : String aResult;
887 [ + - ]: 2 : uno::Reference< embed::XEmbeddedObject > xEmbObj = GetOleRef();
888 [ + - ]: 2 : if ( xEmbObj.is() )
889 : : {
890 [ + - ][ + - ]: 2 : SvGlobalName aClassID( xEmbObj->getClassID() );
[ + - ][ + - ]
891 [ + - ][ - + ]: 2 : if ( SotExchange::IsMath( aClassID ) )
892 [ # # ][ # # ]: 0 : aResult = SW_RESSTR(STR_MATH_FORMULA);
893 [ + - ][ + - ]: 2 : else if ( SotExchange::IsChart( aClassID ) )
894 [ + - ][ + - ]: 2 : aResult = SW_RESSTR(STR_CHART);
895 : : else
896 [ # # ][ # # ]: 2 : aResult = SW_RESSTR(STR_OLE);
[ + - ]
897 : : }
898 : :
899 : 2 : return aResult;
900 : : }
901 : :
902 : :
903 : 93 : SwOLELRUCache::SwOLELRUCache()
904 : : : utl::ConfigItem(OUString("Office.Common/Cache"))
905 [ + - ][ + - ]: 93 : , m_nLRU_InitSize( 20 )
906 : : {
907 [ + - ][ + - ]: 93 : EnableNotification( GetPropertyNames() );
[ + - ]
908 [ + - ]: 93 : Load();
909 : 93 : }
910 : :
911 : 186 : uno::Sequence< rtl::OUString > SwOLELRUCache::GetPropertyNames()
912 : : {
913 : 186 : Sequence< OUString > aNames( 1 );
914 [ + - ]: 186 : OUString* pNames = aNames.getArray();
915 [ + - ]: 186 : pNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("Writer/OLE_Objects"));
916 : 186 : return aNames;
917 : : }
918 : :
919 : 0 : void SwOLELRUCache::Notify( const uno::Sequence< rtl::OUString>& )
920 : : {
921 : 0 : Load();
922 : 0 : }
923 : :
924 : 0 : void SwOLELRUCache::Commit()
925 : : {
926 : 0 : }
927 : :
928 : 93 : void SwOLELRUCache::Load()
929 : : {
930 [ + - ]: 93 : Sequence< OUString > aNames( GetPropertyNames() );
931 [ + - ]: 93 : Sequence< Any > aValues = GetProperties( aNames );
932 : 93 : const Any* pValues = aValues.getConstArray();
933 : : OSL_ENSURE( aValues.getLength() == aNames.getLength(), "GetProperties failed" );
934 [ + - ][ + - ]: 93 : if( aValues.getLength() == aNames.getLength() && pValues->hasValue() )
[ + - ]
935 : : {
936 : 93 : sal_Int32 nVal = 0;
937 : 93 : *pValues >>= nVal;
938 : :
939 : : {
940 [ - + ]: 93 : if (nVal < m_nLRU_InitSize)
941 : : {
942 : : // size of cache has been changed
943 : 0 : sal_Int32 nCount = m_OleObjects.size();
944 : 0 : sal_Int32 nPos = nCount;
945 : :
946 : : // try to remove the last entries until new maximum size is reached
947 [ # # ]: 0 : while( nCount > nVal )
948 : : {
949 [ # # ]: 0 : SwOLEObj *const pObj = m_OleObjects[ --nPos ];
950 [ # # ][ # # ]: 0 : if ( pObj->UnloadObject() )
951 : 0 : nCount--;
952 [ # # ]: 0 : if ( !nPos )
953 : 0 : break;
954 : : }
955 : : }
956 : : }
957 : :
958 : 93 : m_nLRU_InitSize = nVal;
959 [ + - ][ + - ]: 93 : }
960 : 93 : }
961 : :
962 : 4615 : void SwOLELRUCache::InsertObj( SwOLEObj& rObj )
963 : : {
964 : 4615 : SwOLEObj* pObj = &rObj;
965 : : OleObjects_t::iterator it =
966 [ + - ]: 4615 : std::find(m_OleObjects.begin(), m_OleObjects.end(), pObj);
967 [ + - ][ + + ]: 4615 : if (it != m_OleObjects.end() && it != m_OleObjects.begin())
[ + - ][ + + ]
[ + + ][ + - ]
[ + + # #
# # ]
968 : : {
969 : : // object in cache but is currently not the first in cache
970 [ + - ][ + - ]: 984 : m_OleObjects.erase(it);
971 : 984 : it = m_OleObjects.end();
972 : : }
973 [ + - ][ + + ]: 4615 : if (it == m_OleObjects.end())
974 : : {
975 [ + - ]: 1416 : m_OleObjects.push_front( pObj );
976 : :
977 : : // try to remove objects if necessary
978 : : // (of course not the freshly inserted one at nPos=0)
979 : 1416 : sal_Int32 nCount = m_OleObjects.size();
980 : 1416 : sal_Int32 nPos = nCount-1;
981 [ + + ][ + + ]: 1452 : while (nPos && nCount > m_nLRU_InitSize)
[ + + ]
982 : : {
983 [ + - ]: 36 : pObj = m_OleObjects[ nPos-- ];
984 [ + - ][ + - ]: 36 : if ( pObj->UnloadObject() )
985 : 36 : nCount--;
986 : : }
987 : : }
988 : 4615 : }
989 : :
990 : 381 : void SwOLELRUCache::RemoveObj( SwOLEObj& rObj )
991 : : {
992 : : OleObjects_t::iterator const it =
993 [ + - ]: 381 : std::find(m_OleObjects.begin(), m_OleObjects.end(), &rObj);
994 [ + - ][ + - ]: 381 : if (it != m_OleObjects.end())
995 : : {
996 [ + - ][ + - ]: 381 : m_OleObjects.erase(it);
997 : : }
998 [ + + ]: 381 : if (m_OleObjects.empty())
999 : : {
1000 [ + - ][ + - ]: 90 : DELETEZ( pOLELRU_Cache );
1001 : : }
1002 : 381 : }
1003 : :
1004 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|