1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <sfx2/objsh.hxx>
22 #include <vcl/svapp.hxx>
24 #include "addinlis.hxx"
25 #include "miscuno.hxx"
26 #include "document.hxx"
30 using namespace com::sun::star
;
32 SC_SIMPLE_SERVICE_INFO( ScAddInListener
, "ScAddInListener", "stardiv.one.sheet.AddInListener" )
34 ::std::list
<ScAddInListener
*> ScAddInListener::aAllListeners
;
36 ScAddInListener
* ScAddInListener::CreateListener(
37 uno::Reference
<sheet::XVolatileResult
> xVR
, ScDocument
* pDoc
)
39 ScAddInListener
* pNew
= new ScAddInListener( xVR
, pDoc
);
41 pNew
->acquire(); // for aAllListeners
42 aAllListeners
.push_back( pNew
);
45 xVR
->addResultListener( pNew
); // after at least 1 ref exists!
50 ScAddInListener::ScAddInListener( uno::Reference
<sheet::XVolatileResult
> xVR
, ScDocument
* pDoc
) :
53 pDocs
= new ScAddInDocs();
54 pDocs
->insert( pDoc
);
57 ScAddInListener::~ScAddInListener()
62 ScAddInListener
* ScAddInListener::Get( uno::Reference
<sheet::XVolatileResult
> xVR
)
64 ScAddInListener
* pLst
= NULL
;
65 sheet::XVolatileResult
* pComp
= xVR
.get();
67 for(::std::list
<ScAddInListener
*>::iterator iter
= aAllListeners
.begin(); iter
!= aAllListeners
.end(); ++iter
)
69 if ( pComp
== (sheet::XVolatileResult
*)(*iter
)->xVolRes
.get() )
78 //! move to some container object?
79 void ScAddInListener::RemoveDocument( ScDocument
* pDocumentP
)
81 ::std::list
<ScAddInListener
*>::iterator iter
= aAllListeners
.begin();
82 while(iter
!= aAllListeners
.end())
84 ScAddInDocs
* p
= (*iter
)->pDocs
;
85 ScAddInDocs::iterator iter2
= p
->find( pDocumentP
);
86 if( iter2
!= p
->end() )
91 if ( (*iter
)->xVolRes
.is() )
92 (*iter
)->xVolRes
->removeResultListener( *iter
);
94 (*iter
)->release(); // Ref for aAllListeners - pLst may be deleted here
96 // this AddIn is no longer used
97 // dont delete, just remove the ref for the list
99 iter
= aAllListeners
.erase( iter
);
109 void SAL_CALL
ScAddInListener::modified( const ::com::sun::star::sheet::ResultEvent
& aEvent
)
110 throw(::com::sun::star::uno::RuntimeException
)
112 SolarMutexGuard aGuard
; //! or generate a UserEvent
114 aResult
= aEvent
.Value
; // store result
116 // notify document of changes
118 Broadcast( ScHint(SC_HINT_DATACHANGED
, ScAddress()) );
120 for ( ScAddInDocs::iterator it
= pDocs
->begin(); it
!= pDocs
->end(); ++it
)
122 ScDocument
* pDoc
= *it
;
123 pDoc
->TrackFormulas();
124 pDoc
->GetDocumentShell()->Broadcast( SfxSimpleHint( FID_DATACHANGED
) );
130 void SAL_CALL
ScAddInListener::disposing( const ::com::sun::star::lang::EventObject
& /* Source */ )
131 throw(::com::sun::star::uno::RuntimeException
)
133 // hold a ref so this is not deleted at removeResultListener
134 uno::Reference
<sheet::XResultListener
> xRef( this );
138 xVolRes
->removeResultListener( this );
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */