xref: /AOO41X/main/sc/workben/result.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 #ifdef _MSC_VER
29 #pragma hdrstop
30 #endif
31 
32 #include <tools/debug.hxx>
33 #include <usr/ustring.hxx>
34 
35 #include "result.hxx"
36 
37 using namespace com::sun::star;
38 
39 //------------------------------------------------------------------------
40 
41 SV_IMPL_PTRARR( XResultListenerArr_Impl, XResultListenerPtr );
42 
43 //SMART_UNO_IMPLEMENTATION( ScAddInResult, UsrObject );
44 
45 //------------------------------------------------------------------------
46 
47 ScAddInResult::ScAddInResult(const String& rStr) :
48     aArg( rStr ),
49     nTickCount( 0 )
50 {
51     aTimer.SetTimeout( 1000 );
52     aTimer.SetTimeoutHdl( LINK( this, ScAddInResult, TimeoutHdl ) );
53     aTimer.Start();
54 }
55 
56 void ScAddInResult::NewValue()
57 {
58     ++nTickCount;
59 
60     uno::Any aAny;
61     if ( TRUE /* nTickCount % 4 */ )
62     {
63         String aRet = aArg;
64         aRet += nTickCount;
65         rtl::OUString aUStr = StringToOUString( aRet, CHARSET_SYSTEM );
66         aAny <<= aUStr;
67     }
68     // else void
69 
70 //  sheet::ResultEvent aEvent( (UsrObject*)this, aAny );
71     sheet::ResultEvent aEvent( (cppu::OWeakObject*)this, aAny );
72 
73     for ( USHORT n=0; n<aListeners.Count(); n++ )
74         (*aListeners[n])->modified( aEvent );
75 }
76 
77 IMPL_LINK_INLINE_START( ScAddInResult, TimeoutHdl, Timer*, pT )
78 {
79     NewValue();
80     pT->Start();
81     return 0;
82 }
83 IMPL_LINK_INLINE_END( ScAddInResult, TimeoutHdl, Timer*, pT )
84 
85 ScAddInResult::~ScAddInResult()
86 {
87 }
88 
89 // XVolatileResult
90 
91 void SAL_CALL ScAddInResult::addResultListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XResultListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
92 {
93     uno::Reference<sheet::XResultListener> *pObj = new uno::Reference<sheet::XResultListener>( aListener );
94     aListeners.Insert( pObj, aListeners.Count() );
95 
96     if ( aListeners.Count() == 1 )
97     {
98         acquire();                      // one Ref for all listeners
99 
100         NewValue(); //! Test
101     }
102 }
103 
104 void SAL_CALL ScAddInResult::removeResultListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XResultListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
105 {
106     acquire();
107 
108     USHORT nCount = aListeners.Count();
109     for ( USHORT n=nCount; n--; )
110     {
111         uno::Reference<sheet::XResultListener> *pObj = aListeners[n];
112         if ( *pObj == aListener )
113         {
114             aListeners.DeleteAndDestroy( n );
115 
116             if ( aListeners.Count() == 0 )
117             {
118                 nTickCount = 0; //! Test
119 
120                 release();                  // release listener Ref
121             }
122 
123             break;
124         }
125     }
126 
127     release();
128 }
129 
130 //------------------------------------------------------------------------
131 
132 
133 
134