fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / core / tool / addinlis.cxx
bloba6797798ebcd2599af4d9ae5daebb06982ea9741
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
26 #include "brdcst.hxx"
27 #include "sc.hrc"
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 );
43 if ( xVR.is() )
44 xVR->addResultListener( pNew ); // after at least 1 ref exists!
46 return pNew;
49 ScAddInListener::ScAddInListener( uno::Reference<sheet::XVolatileResult> xVR, ScDocument* pDoc ) :
50 xVolRes( xVR )
52 pDocs = new ScAddInDocs();
53 pDocs->insert( pDoc );
56 ScAddInListener::~ScAddInListener()
58 delete pDocs;
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() )
70 pLst = *iter;
71 break;
74 return pLst;
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() )
87 p->erase( iter2 );
88 if ( p->empty() )
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 );
99 continue;
102 ++iter;
106 // XResultListener
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 ) );
127 // XEventListener
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 );
135 if ( xVolRes.is() )
137 xVolRes->removeResultListener( this );
138 xVolRes = NULL;
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */