merged tag ooo/OOO330_m14
[LibreOffice.git] / sc / workben / result.cxx
blob9198692357e6277b2ab08b55155f23100b521586
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifdef _MSC_VER
29 #pragma hdrstop
30 #endif
32 #include <tools/debug.hxx>
33 #include <usr/ustring.hxx>
35 #include "result.hxx"
37 using namespace com::sun::star;
39 //------------------------------------------------------------------------
41 SV_IMPL_PTRARR( XResultListenerArr_Impl, XResultListenerPtr );
43 //SMART_UNO_IMPLEMENTATION( ScAddInResult, UsrObject );
45 //------------------------------------------------------------------------
47 ScAddInResult::ScAddInResult(const String& rStr) :
48 aArg( rStr ),
49 nTickCount( 0 )
51 aTimer.SetTimeout( 1000 );
52 aTimer.SetTimeoutHdl( LINK( this, ScAddInResult, TimeoutHdl ) );
53 aTimer.Start();
56 void ScAddInResult::NewValue()
58 ++nTickCount;
60 uno::Any aAny;
61 if ( TRUE /* nTickCount % 4 */ )
63 String aRet = aArg;
64 aRet += nTickCount;
65 rtl::OUString aUStr = StringToOUString( aRet, CHARSET_SYSTEM );
66 aAny <<= aUStr;
68 // else void
70 // sheet::ResultEvent aEvent( (UsrObject*)this, aAny );
71 sheet::ResultEvent aEvent( (cppu::OWeakObject*)this, aAny );
73 for ( USHORT n=0; n<aListeners.Count(); n++ )
74 (*aListeners[n])->modified( aEvent );
77 IMPL_LINK_INLINE_START( ScAddInResult, TimeoutHdl, Timer*, pT )
79 NewValue();
80 pT->Start();
81 return 0;
83 IMPL_LINK_INLINE_END( ScAddInResult, TimeoutHdl, Timer*, pT )
85 ScAddInResult::~ScAddInResult()
89 // XVolatileResult
91 void SAL_CALL ScAddInResult::addResultListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XResultListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
93 uno::Reference<sheet::XResultListener> *pObj = new uno::Reference<sheet::XResultListener>( aListener );
94 aListeners.Insert( pObj, aListeners.Count() );
96 if ( aListeners.Count() == 1 )
98 acquire(); // one Ref for all listeners
100 NewValue(); //! Test
104 void SAL_CALL ScAddInResult::removeResultListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XResultListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
106 acquire();
108 USHORT nCount = aListeners.Count();
109 for ( USHORT n=nCount; n--; )
111 uno::Reference<sheet::XResultListener> *pObj = aListeners[n];
112 if ( *pObj == aListener )
114 aListeners.DeleteAndDestroy( n );
116 if ( aListeners.Count() == 0 )
118 nTickCount = 0; //! Test
120 release(); // release listener Ref
123 break;
127 release();
130 //------------------------------------------------------------------------