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 .
20 #include <sfx2/objsh.hxx>
21 #include <vcl/svapp.hxx>
23 #include "addinlis.hxx"
24 #include "miscuno.hxx"
25 #include "document.hxx"
29 using namespace com::sun::star
;
31 SC_SIMPLE_SERVICE_INFO( ScAddInListener
, "ScAddInListener", "stardiv.one.sheet.AddInListener" )
33 ::std::list
<ScAddInListener
*> ScAddInListener::aAllListeners
;
35 ScAddInListener
* ScAddInListener::CreateListener(
36 uno::Reference
<sheet::XVolatileResult
> xVR
, ScDocument
* pDoc
)
38 ScAddInListener
* pNew
= new ScAddInListener( xVR
, pDoc
);
40 pNew
->acquire(); // for aAllListeners
41 aAllListeners
.push_back( pNew
);
44 xVR
->addResultListener( pNew
); // after at least 1 ref exists!
49 ScAddInListener::ScAddInListener( uno::Reference
<sheet::XVolatileResult
> xVR
, ScDocument
* pDoc
) :
52 pDocs
= new ScAddInDocs();
53 pDocs
->insert( pDoc
);
56 ScAddInListener::~ScAddInListener()
61 ScAddInListener
* ScAddInListener::Get( uno::Reference
<sheet::XVolatileResult
> xVR
)
63 ScAddInListener
* pLst
= NULL
;
64 sheet::XVolatileResult
* pComp
= xVR
.get();
66 for(::std::list
<ScAddInListener
*>::iterator iter
= aAllListeners
.begin(); iter
!= aAllListeners
.end(); ++iter
)
68 if ( pComp
== (sheet::XVolatileResult
*)(*iter
)->xVolRes
.get() )
77 //TODO: move to some container object?
78 void ScAddInListener::RemoveDocument( ScDocument
* pDocumentP
)
80 ::std::list
<ScAddInListener
*>::iterator iter
= aAllListeners
.begin();
81 while(iter
!= aAllListeners
.end())
83 ScAddInDocs
* p
= (*iter
)->pDocs
;
84 ScAddInDocs::iterator iter2
= p
->find( pDocumentP
);
85 if( iter2
!= p
->end() )
90 if ( (*iter
)->xVolRes
.is() )
91 (*iter
)->xVolRes
->removeResultListener( *iter
);
93 (*iter
)->release(); // Ref for aAllListeners - pLst may be deleted here
95 // this AddIn is no longer used
96 // dont delete, just remove the ref for the list
98 iter
= aAllListeners
.erase( iter
);
108 void SAL_CALL
ScAddInListener::modified( const ::com::sun::star::sheet::ResultEvent
& aEvent
)
109 throw(::com::sun::star::uno::RuntimeException
, std::exception
)
111 SolarMutexGuard aGuard
; //TODO: or generate a UserEvent
113 aResult
= aEvent
.Value
; // store result
115 // notify document of changes
117 Broadcast( ScHint(SC_HINT_DATACHANGED
, ScAddress()) );
119 for ( ScAddInDocs::iterator it
= pDocs
->begin(); it
!= pDocs
->end(); ++it
)
121 ScDocument
* pDoc
= *it
;
122 pDoc
->TrackFormulas();
123 pDoc
->GetDocumentShell()->Broadcast( SfxSimpleHint( FID_DATACHANGED
) );
129 void SAL_CALL
ScAddInListener::disposing( const ::com::sun::star::lang::EventObject
& /* Source */ )
130 throw(::com::sun::star::uno::RuntimeException
, std::exception
)
132 // hold a ref so this is not deleted at removeResultListener
133 uno::Reference
<sheet::XResultListener
> xRef( this );
137 xVolRes
->removeResultListener( this );
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */