bump product version to 4.1.6.2
[LibreOffice.git] / sc / workben / result.cxx
blobc11d74b6d106790b815a3376b842a0cebd0d394d
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 #ifdef _MSC_VER
21 #pragma hdrstop
22 #endif
24 #include <usr/ustring.hxx>
26 #include "result.hxx"
28 using namespace com::sun::star;
30 //------------------------------------------------------------------------
32 SV_IMPL_PTRARR( XResultListenerArr_Impl, XResultListenerPtr );
34 //------------------------------------------------------------------------
36 ScAddInResult::ScAddInResult(const String& rStr) :
37 aArg( rStr ),
38 nTickCount( 0 )
40 aTimer.SetTimeout( 1000 );
41 aTimer.SetTimeoutHdl( LINK( this, ScAddInResult, TimeoutHdl ) );
42 aTimer.Start();
45 void ScAddInResult::NewValue()
47 ++nTickCount;
49 uno::Any aAny;
50 String aRet = aArg;
51 aRet += nTickCount;
52 OUString aUStr = StringToOUString( aRet, CHARSET_SYSTEM );
53 aAny <<= aUStr;
55 sheet::ResultEvent aEvent( (cppu::OWeakObject*)this, aAny );
57 for ( sal_uInt16 n=0; n<aListeners.Count(); n++ )
58 (*aListeners[n])->modified( aEvent );
61 IMPL_LINK_INLINE_START( ScAddInResult, TimeoutHdl, Timer*, pT )
63 NewValue();
64 pT->Start();
65 return 0;
67 IMPL_LINK_INLINE_END( ScAddInResult, TimeoutHdl, Timer*, pT )
69 ScAddInResult::~ScAddInResult()
73 // XVolatileResult
75 void SAL_CALL ScAddInResult::addResultListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XResultListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
77 uno::Reference<sheet::XResultListener> *pObj = new uno::Reference<sheet::XResultListener>( aListener );
78 aListeners.Insert( pObj, aListeners.Count() );
80 if ( aListeners.Count() == 1 )
82 acquire(); // one Ref for all listeners
84 NewValue(); //! Test
88 void SAL_CALL ScAddInResult::removeResultListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XResultListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
90 acquire();
92 sal_uInt16 nCount = aListeners.Count();
93 for ( sal_uInt16 n=nCount; n--; )
95 uno::Reference<sheet::XResultListener> *pObj = aListeners[n];
96 if ( *pObj == aListener )
98 aListeners.DeleteAndDestroy( n );
100 if ( aListeners.Count() == 0 )
102 nTickCount = 0; //! Test
104 release(); // release listener Ref
107 break;
111 release();
114 //------------------------------------------------------------------------
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */