update dev300-m57
[ooovba.git] / sc / workben / result.cxx
blob33b3d75747c2fff1c176f9d869782c291533c7c7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: result.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifdef _MSC_VER
32 #pragma hdrstop
33 #endif
35 #include <tools/debug.hxx>
36 #include <usr/ustring.hxx>
38 #include "result.hxx"
40 using namespace com::sun::star;
42 //------------------------------------------------------------------------
44 SV_IMPL_PTRARR( XResultListenerArr_Impl, XResultListenerPtr );
46 //SMART_UNO_IMPLEMENTATION( ScAddInResult, UsrObject );
48 //------------------------------------------------------------------------
50 ScAddInResult::ScAddInResult(const String& rStr) :
51 aArg( rStr ),
52 nTickCount( 0 )
54 aTimer.SetTimeout( 1000 );
55 aTimer.SetTimeoutHdl( LINK( this, ScAddInResult, TimeoutHdl ) );
56 aTimer.Start();
59 void ScAddInResult::NewValue()
61 ++nTickCount;
63 uno::Any aAny;
64 if ( TRUE /* nTickCount % 4 */ )
66 String aRet = aArg;
67 aRet += nTickCount;
68 rtl::OUString aUStr = StringToOUString( aRet, CHARSET_SYSTEM );
69 aAny <<= aUStr;
71 // else void
73 // sheet::ResultEvent aEvent( (UsrObject*)this, aAny );
74 sheet::ResultEvent aEvent( (cppu::OWeakObject*)this, aAny );
76 for ( USHORT n=0; n<aListeners.Count(); n++ )
77 (*aListeners[n])->modified( aEvent );
80 IMPL_LINK_INLINE_START( ScAddInResult, TimeoutHdl, Timer*, pT )
82 NewValue();
83 pT->Start();
84 return 0;
86 IMPL_LINK_INLINE_END( ScAddInResult, TimeoutHdl, Timer*, pT )
88 ScAddInResult::~ScAddInResult()
92 // XVolatileResult
94 void SAL_CALL ScAddInResult::addResultListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XResultListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
96 uno::Reference<sheet::XResultListener> *pObj = new uno::Reference<sheet::XResultListener>( aListener );
97 aListeners.Insert( pObj, aListeners.Count() );
99 if ( aListeners.Count() == 1 )
101 acquire(); // one Ref for all listeners
103 NewValue(); //! Test
107 void SAL_CALL ScAddInResult::removeResultListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XResultListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
109 acquire();
111 USHORT nCount = aListeners.Count();
112 for ( USHORT n=nCount; n--; )
114 uno::Reference<sheet::XResultListener> *pObj = aListeners[n];
115 if ( *pObj == aListener )
117 aListeners.DeleteAndDestroy( n );
119 if ( aListeners.Count() == 0 )
121 nTickCount = 0; //! Test
123 release(); // release listener Ref
126 break;
130 release();
133 //------------------------------------------------------------------------