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