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 : :
30 : : #include <sfx2/objsh.hxx>
31 : : #include <vcl/svapp.hxx>
32 : :
33 : : #include "addinlis.hxx"
34 : : #include "miscuno.hxx" // SC_IMPL_SERVICE_INFO
35 : : #include "document.hxx"
36 : : #include "brdcst.hxx"
37 : : #include "sc.hrc"
38 : :
39 : : using namespace com::sun::star;
40 : :
41 [ # # ]: 0 : SC_SIMPLE_SERVICE_INFO( ScAddInListener, "ScAddInListener", "stardiv.one.sheet.AddInListener" )
42 : :
43 : 51 : ::std::list<ScAddInListener*> ScAddInListener::aAllListeners;
44 : :
45 : 0 : ScAddInListener* ScAddInListener::CreateListener(
46 : : uno::Reference<sheet::XVolatileResult> xVR, ScDocument* pDoc )
47 : : {
48 [ # # ]: 0 : ScAddInListener* pNew = new ScAddInListener( xVR, pDoc );
49 : :
50 : 0 : pNew->acquire(); // for aAllListeners
51 [ # # ]: 0 : aAllListeners.push_back( pNew );
52 : :
53 [ # # ]: 0 : if ( xVR.is() )
54 [ # # ][ # # ]: 0 : xVR->addResultListener( pNew ); // after at least 1 ref exists!
[ # # ][ # # ]
55 : :
56 : 0 : return pNew;
57 : : }
58 : :
59 : 0 : ScAddInListener::ScAddInListener( uno::Reference<sheet::XVolatileResult> xVR, ScDocument* pDoc ) :
60 [ # # ]: 0 : xVolRes( xVR )
61 : : {
62 [ # # ][ # # ]: 0 : pDocs = new ScAddInDocs();
63 [ # # ]: 0 : pDocs->insert( pDoc );
64 : 0 : }
65 : :
66 [ # # ]: 0 : ScAddInListener::~ScAddInListener()
67 : : {
68 [ # # ]: 0 : delete pDocs;
69 [ # # ]: 0 : }
70 : :
71 : 0 : ScAddInListener* ScAddInListener::Get( uno::Reference<sheet::XVolatileResult> xVR )
72 : : {
73 : 0 : ScAddInListener* pLst = NULL;
74 : 0 : sheet::XVolatileResult* pComp = xVR.get();
75 : :
76 [ # # ]: 0 : for(::std::list<ScAddInListener*>::iterator iter = aAllListeners.begin(); iter != aAllListeners.end(); ++iter)
77 : : {
78 [ # # ][ # # ]: 0 : if ( pComp == (sheet::XVolatileResult*)(*iter)->xVolRes.get() )
79 : : {
80 : 0 : pLst = *iter;
81 : 0 : break;
82 : : }
83 : : }
84 : 0 : return pLst;
85 : : }
86 : :
87 : : //! move to some container object?
88 : 1611 : void ScAddInListener::RemoveDocument( ScDocument* pDocumentP )
89 : : {
90 : 1611 : ::std::list<ScAddInListener*>::iterator iter = aAllListeners.begin();
91 [ - + ]: 1611 : while(iter != aAllListeners.end())
92 : : {
93 : 0 : ScAddInDocs* p = (*iter)->pDocs;
94 [ # # ]: 0 : ScAddInDocs::iterator iter2 = p->find( pDocumentP );
95 [ # # ]: 0 : if( iter2 != p->end() )
96 : : {
97 [ # # ]: 0 : p->erase( iter2 );
98 [ # # ]: 0 : if ( p->empty() )
99 : : {
100 [ # # ]: 0 : if ( (*iter)->xVolRes.is() )
101 [ # # ][ # # ]: 0 : (*iter)->xVolRes->removeResultListener( *iter );
[ # # ][ # # ]
102 : :
103 : 0 : (*iter)->release(); // Ref for aAllListeners - pLst may be deleted here
104 : :
105 : : // this AddIn is no longer used
106 : : // dont delete, just remove the ref for the list
107 : :
108 [ # # ]: 0 : iter = aAllListeners.erase( iter );
109 : 0 : continue;
110 : : }
111 : : }
112 : 0 : ++iter;
113 : : }
114 : 1611 : }
115 : :
116 : : // XResultListener
117 : :
118 : 0 : void SAL_CALL ScAddInListener::modified( const ::com::sun::star::sheet::ResultEvent& aEvent )
119 : : throw(::com::sun::star::uno::RuntimeException)
120 : : {
121 [ # # ]: 0 : SolarMutexGuard aGuard; //! or generate a UserEvent
122 : :
123 : 0 : aResult = aEvent.Value; // store result
124 : :
125 : : // notify document of changes
126 : :
127 [ # # ][ # # ]: 0 : Broadcast( ScHint( SC_HINT_DATACHANGED, ScAddress(), NULL ) );
[ # # ]
128 : :
129 [ # # ]: 0 : for ( ScAddInDocs::iterator it = pDocs->begin(); it != pDocs->end(); ++it )
130 : : {
131 : 0 : ScDocument* pDoc = *it;
132 [ # # ]: 0 : pDoc->TrackFormulas();
133 [ # # ][ # # ]: 0 : pDoc->GetDocumentShell()->Broadcast( SfxSimpleHint( FID_DATACHANGED ) );
[ # # ]
134 [ # # ]: 0 : }
135 : 0 : }
136 : :
137 : : // XEventListener
138 : :
139 : 0 : void SAL_CALL ScAddInListener::disposing( const ::com::sun::star::lang::EventObject& /* Source */ )
140 : : throw(::com::sun::star::uno::RuntimeException)
141 : : {
142 : : // hold a ref so this is not deleted at removeResultListener
143 [ # # ]: 0 : uno::Reference<sheet::XResultListener> xRef( this );
144 : :
145 [ # # ]: 0 : if ( xVolRes.is() )
146 : : {
147 [ # # ][ # # ]: 0 : xVolRes->removeResultListener( this );
[ # # ]
148 [ # # ]: 0 : xVolRes = NULL;
149 : 0 : }
150 [ + - ][ + - ]: 153 : }
151 : :
152 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|