xref: /trunk/main/sc/workben/result.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifdef _MSC_VER
25cdf0e10cSrcweir #pragma hdrstop
26cdf0e10cSrcweir #endif
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <tools/debug.hxx>
29cdf0e10cSrcweir #include <usr/ustring.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "result.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using namespace com::sun::star;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //------------------------------------------------------------------------
36cdf0e10cSrcweir 
37cdf0e10cSrcweir SV_IMPL_PTRARR( XResultListenerArr_Impl, XResultListenerPtr );
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //SMART_UNO_IMPLEMENTATION( ScAddInResult, UsrObject );
40cdf0e10cSrcweir 
41cdf0e10cSrcweir //------------------------------------------------------------------------
42cdf0e10cSrcweir 
ScAddInResult(const String & rStr)43cdf0e10cSrcweir ScAddInResult::ScAddInResult(const String& rStr) :
44cdf0e10cSrcweir     aArg( rStr ),
45cdf0e10cSrcweir     nTickCount( 0 )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir     aTimer.SetTimeout( 1000 );
48cdf0e10cSrcweir     aTimer.SetTimeoutHdl( LINK( this, ScAddInResult, TimeoutHdl ) );
49cdf0e10cSrcweir     aTimer.Start();
50cdf0e10cSrcweir }
51cdf0e10cSrcweir 
NewValue()52cdf0e10cSrcweir void ScAddInResult::NewValue()
53cdf0e10cSrcweir {
54cdf0e10cSrcweir     ++nTickCount;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     uno::Any aAny;
57cdf0e10cSrcweir     if ( TRUE /* nTickCount % 4 */ )
58cdf0e10cSrcweir     {
59cdf0e10cSrcweir         String aRet = aArg;
60cdf0e10cSrcweir         aRet += nTickCount;
61cdf0e10cSrcweir         rtl::OUString aUStr = StringToOUString( aRet, CHARSET_SYSTEM );
62cdf0e10cSrcweir         aAny <<= aUStr;
63cdf0e10cSrcweir     }
64cdf0e10cSrcweir     // else void
65cdf0e10cSrcweir 
66cdf0e10cSrcweir //  sheet::ResultEvent aEvent( (UsrObject*)this, aAny );
67cdf0e10cSrcweir     sheet::ResultEvent aEvent( (cppu::OWeakObject*)this, aAny );
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     for ( USHORT n=0; n<aListeners.Count(); n++ )
70cdf0e10cSrcweir         (*aListeners[n])->modified( aEvent );
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
IMPL_LINK_INLINE_START(ScAddInResult,TimeoutHdl,Timer *,pT)73cdf0e10cSrcweir IMPL_LINK_INLINE_START( ScAddInResult, TimeoutHdl, Timer*, pT )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     NewValue();
76cdf0e10cSrcweir     pT->Start();
77cdf0e10cSrcweir     return 0;
78cdf0e10cSrcweir }
IMPL_LINK_INLINE_END(ScAddInResult,TimeoutHdl,Timer *,pT)79cdf0e10cSrcweir IMPL_LINK_INLINE_END( ScAddInResult, TimeoutHdl, Timer*, pT )
80cdf0e10cSrcweir 
81cdf0e10cSrcweir ScAddInResult::~ScAddInResult()
82cdf0e10cSrcweir {
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir // XVolatileResult
86cdf0e10cSrcweir 
addResultListener(const::com::sun::star::uno::Reference<::com::sun::star::sheet::XResultListener> & aListener)87cdf0e10cSrcweir void SAL_CALL ScAddInResult::addResultListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XResultListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
88cdf0e10cSrcweir {
89cdf0e10cSrcweir     uno::Reference<sheet::XResultListener> *pObj = new uno::Reference<sheet::XResultListener>( aListener );
90cdf0e10cSrcweir     aListeners.Insert( pObj, aListeners.Count() );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     if ( aListeners.Count() == 1 )
93cdf0e10cSrcweir     {
94cdf0e10cSrcweir         acquire();                      // one Ref for all listeners
95cdf0e10cSrcweir 
96cdf0e10cSrcweir         NewValue(); //! Test
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
removeResultListener(const::com::sun::star::uno::Reference<::com::sun::star::sheet::XResultListener> & aListener)100cdf0e10cSrcweir void SAL_CALL ScAddInResult::removeResultListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XResultListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
101cdf0e10cSrcweir {
102cdf0e10cSrcweir     acquire();
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     USHORT nCount = aListeners.Count();
105cdf0e10cSrcweir     for ( USHORT n=nCount; n--; )
106cdf0e10cSrcweir     {
107cdf0e10cSrcweir         uno::Reference<sheet::XResultListener> *pObj = aListeners[n];
108cdf0e10cSrcweir         if ( *pObj == aListener )
109cdf0e10cSrcweir         {
110cdf0e10cSrcweir             aListeners.DeleteAndDestroy( n );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir             if ( aListeners.Count() == 0 )
113cdf0e10cSrcweir             {
114cdf0e10cSrcweir                 nTickCount = 0; //! Test
115cdf0e10cSrcweir 
116cdf0e10cSrcweir                 release();                  // release listener Ref
117cdf0e10cSrcweir             }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir             break;
120cdf0e10cSrcweir         }
121cdf0e10cSrcweir     }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     release();
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir //------------------------------------------------------------------------
127