xref: /AOO41X/main/sc/workben/addin.cxx (revision b3f79822e811ac3493b185030a72c3c5a51f32d8)
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 <usr/factoryhlp.hxx>
29 #include <usr/macros.hxx>
30 #include <usr/reflserv.hxx>
31 #include <vos/mutex.hxx>
32 #include <vcl/svapp.hxx>
33 #include <tools/debug.hxx>
34 #include <tools/date.hxx>
35 #include <svl/itemprop.hxx>
36 #include <usr/proptypehlp.hxx>
37 #include <cppuhelper/factory.hxx>
38 #include <uno/lbnames.h>
39 #include <osl/diagnose.h>
40 
41 #include <com/sun/star/util/date.hpp>
42 
43 #include "addin.hxx"
44 #include "result.hxx"
45 
46 using namespace com::sun::star;
47 
48 //------------------------------------------------------------------------
49 
50 
51 //------------------------------------------------------------------------
52 
53 SMART_UNO_IMPLEMENTATION( ScTestAddIn, UsrObject );
54 
55 #define SCADDIN_SERVICE         L"com.sun.star.sheet.AddIn"
56 #define SCTESTADDIN_SERVICE     L"stardiv.one.sheet.DemoAddIn"
57 
58 //------------------------------------------------------------------------
59 
60 extern "C" {
61 
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment ** ppEnv)62 void SAL_CALL component_getImplementationEnvironment(
63     const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
64 {
65     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
66 }
67 
component_writeInfo(void * pServiceManager,registry::XRegistryKey * pRegistryKey)68 sal_Bool SAL_CALL component_writeInfo(
69     void * pServiceManager, registry::XRegistryKey * pRegistryKey )
70 {
71     if (pRegistryKey)
72     {
73         try
74         {
75             UString aImpl = L"/";
76             aImpl += ScTestAddIn::getImplementationName_Static();
77             aImpl += L"/UNO/SERVICES";
78 
79             uno::Reference<registry::XRegistryKey> xNewKey(
80                 reinterpret_cast<registry::XRegistryKey*>(pRegistryKey)->createKey(aImpl) );
81 
82             uno::Sequence <rtl::OUString> aSequ = ScTestAddIn::getSupportedServiceNames_Static();
83             const rtl::OUString * pArray = aSequ.getConstArray();
84             for( INT32 i = 0; i < aSequ.getLength(); i++ )
85                 xNewKey->createKey( pArray[i] );
86 
87             return sal_True;
88         }
89         catch (registry::InvalidRegistryException&)
90         {
91             OSL_ENSHURE( sal_False, "### InvalidRegistryException!" );
92         }
93     }
94     return sal_False;
95 }
96 
component_getFactory(const sal_Char * pImplName,void * pServiceManager,void * pRegistryKey)97 void * SAL_CALL component_getFactory(
98     const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
99 {
100     void* pRet = 0;
101 
102     if ( pServiceManager && UString(pImplName) == ScTestAddIn::getImplementationName_Static() )
103     {
104         uno::Reference<lang::XSingleServiceFactory> xFactory( cppu::createOneInstanceFactory(
105                 reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
106                 ScTestAddIn::getImplementationName_Static(),
107                 ScTestAddIn_CreateInstance,
108                 ScTestAddIn::getSupportedServiceNames_Static() ) );
109 
110         if (xFactory.is())
111         {
112             xFactory->acquire();
113             pRet = xFactory.get();
114         }
115     }
116 
117     return pRet;
118 }
119 
120 }   // extern C
121 
122 //------------------------------------------------------------------------
123 
ScTestAddIn()124 ScTestAddIn::ScTestAddIn()
125 {
126 }
127 
~ScTestAddIn()128 ScTestAddIn::~ScTestAddIn()
129 {
130 }
131 
getImplementationName_Static()132 UString ScTestAddIn::getImplementationName_Static()
133 {
134     return L"stardiv.StarCalc.ScTestAddIn";
135 }
136 
getSupportedServiceNames_Static()137 ::com::sun::star::uno::Sequence< ::rtl::OUString > ScTestAddIn::getSupportedServiceNames_Static()
138 {
139     uno::Sequence< rtl::OUString > aRet(2);
140     rtl::OUString* pArray = aRet.getArray();
141     pArray[0] = SCADDIN_SERVICE;
142     pArray[1] = SCTESTADDIN_SERVICE;
143     return aRet;
144 }
145 
ScTestAddIn_CreateInstance(const uno::Reference<lang::XMultiServiceFactory> &)146 uno::Reference<uno::XInterface> ScTestAddIn_CreateInstance(
147         const uno::Reference<lang::XMultiServiceFactory>& )
148 {
149     static uno::Reference<uno::XInterface> xInst = (cppu::OWeakObject*)new ScTestAddIn();
150     return xInst;
151 }
152 
153 
154 // XAddIn
155 
getProgrammaticFuntionName(const UString & aDisplayName)156 UString ScTestAddIn::getProgrammaticFuntionName(const UString& aDisplayName)
157                                 THROWS( (UsrSystemException) )
158 {
159     //!...
160     return UString();
161 }
162 
getDisplayFunctionName(const UString & aProgrammaticName)163 UString ScTestAddIn::getDisplayFunctionName(const UString& aProgrammaticName)
164                                 THROWS( (UsrSystemException) )
165 {
166     //  return translated strings
167 
168     UString aRet;
169     if ( aProgrammaticName == L"countParams" )        aRet = L"ParamAnzahl";
170     else if ( aProgrammaticName == L"addOne" )        aRet = L"PlusEins";
171     else if ( aProgrammaticName == L"repeatStr" )     aRet = L"WiederholeString";
172     else if ( aProgrammaticName == L"getDateString" ) aRet = L"Datumsstring";
173     else if ( aProgrammaticName == L"getColorValue" ) aRet = L"Farbwert";
174     else if ( aProgrammaticName == L"transpose" )     aRet = L"Transponieren";
175     else if ( aProgrammaticName == L"transposeInt" )  aRet = L"IntegerTransponieren";
176     else if ( aProgrammaticName == L"repeatMultiple" )aRet = L"Mehrfach";
177     else if ( aProgrammaticName == L"getStrOrVal" )   aRet = L"StringOderWert";
178     else if ( aProgrammaticName == L"callAsync" )     aRet = L"Asynchron";
179     return aRet;
180 }
181 
getFunctionDescription(const UString & aProgrammaticName)182 UString ScTestAddIn::getFunctionDescription(const UString& aProgrammaticName)
183                                 THROWS( (UsrSystemException) )
184 {
185     //  return translated strings
186 
187     UString aRet;
188     if ( aProgrammaticName == L"countParams" )        aRet = L"Gibt die Anzahl der Parameter zurueck.";
189     else if ( aProgrammaticName == L"addOne" )        aRet = L"Addiert 1 zur uebergebenen Zahl.";
190     else if ( aProgrammaticName == L"repeatStr" )     aRet = L"Wiederholt eine Zeichenkette.";
191     else if ( aProgrammaticName == L"getDateString" ) aRet = L"Wandelt ein Datum in eine Zeichenkette.";
192     else if ( aProgrammaticName == L"getColorValue" ) aRet = L"Gibt den Farbwert eines Zellbereichs zurueck. Bei transparentem Hintergrund wird -1 zurueckgegeben";
193     else if ( aProgrammaticName == L"transpose" )     aRet = L"Transponiert eine Matrix.";
194     else if ( aProgrammaticName == L"transposeInt" )  aRet = L"Transponiert eine Matrix mit Ganzzahlen.";
195     else if ( aProgrammaticName == L"repeatMultiple" )aRet = L"Wiederholt mehrere Bestandteile.";
196     else if ( aProgrammaticName == L"getStrOrVal" )   aRet = L"Gibt einen String oder einen Wert zurueck.";
197     else if ( aProgrammaticName == L"callAsync" )     aRet = L"Test fuer asynchrone Funktion.";
198     return aRet;
199 }
200 
getDisplayArgumentName(const UString & aProgrammaticFunctionName,INT32 nArgument)201 UString ScTestAddIn::getDisplayArgumentName(const UString& aProgrammaticFunctionName,
202                                 INT32 nArgument) THROWS( (UsrSystemException) )
203 {
204     //  return translated strings
205 
206     UString aRet;
207     if ( aProgrammaticFunctionName == L"countParams" )
208     {
209         if ( nArgument == 0 )       aRet = L"Parameter";
210     }
211     else if ( aProgrammaticFunctionName == L"addOne" )
212     {
213         if ( nArgument == 0 )       aRet = L"Wert";
214     }
215     else if ( aProgrammaticFunctionName == L"repeatStr" )
216     {
217         if ( nArgument == 0 )       aRet = L"String";
218         else if ( nArgument == 1 )  aRet = L"Anzahl";
219     }
220     else if ( aProgrammaticFunctionName == L"getDateString" )
221     {
222         if ( nArgument == 0 )       aRet = L"Dokument";
223         else if ( nArgument == 1 )  aRet = L"Wert";
224     }
225     else if ( aProgrammaticFunctionName == L"getColorValue" )
226     {
227         if ( nArgument == 0 )       aRet = L"Bereich";
228     }
229     else if ( aProgrammaticFunctionName == L"transpose" )
230     {
231         if ( nArgument == 0 )       aRet = L"Matrix";
232     }
233     else if ( aProgrammaticFunctionName == L"transposeInt" )
234     {
235         if ( nArgument == 0 )       aRet = L"Matrix";
236     }
237     else if ( aProgrammaticFunctionName == L"repeatMultiple" )
238     {
239         if ( nArgument == 0 )       aRet = L"Anzahl";
240         else if ( nArgument == 1 )  aRet = L"Trenner";
241         else if ( nArgument == 2 )  aRet = L"Inhalt";
242     }
243     else if ( aProgrammaticFunctionName == L"getStrOrVal" )
244     {
245         if ( nArgument == 0 )       aRet = L"Flag";
246     }
247     else if ( aProgrammaticFunctionName == L"callAsync" )
248     {
249         if ( nArgument == 0 )       aRet = L"Name";
250     }
251     return aRet;
252 }
253 
getArgumentDescription(const UString & aProgrammaticFunctionName,INT32 nArgument)254 UString ScTestAddIn::getArgumentDescription(const UString& aProgrammaticFunctionName,
255                                 INT32 nArgument) THROWS( (UsrSystemException) )
256 {
257     //  return translated strings
258 
259     UString aRet;
260     if ( aProgrammaticFunctionName == L"countParams" )
261     {
262         if ( nArgument == 0 )       aRet = L"Beliebiger Parameter";
263     }
264     else if ( aProgrammaticFunctionName == L"addOne" )
265     {
266         if ( nArgument == 0 )       aRet = L"Der Wert, zu dem 1 addiert wird";
267     }
268     else if ( aProgrammaticFunctionName == L"repeatStr" )
269     {
270         if ( nArgument == 0 )       aRet = L"Der Text, der wiederholt wird";
271         else if ( nArgument == 1 )  aRet = L"Die Anzahl der Wiederholungen";
272     }
273     else if ( aProgrammaticFunctionName == L"getDateString" )
274     {
275         if ( nArgument == 0 )       aRet = L"(intern)";
276         else if ( nArgument == 1 )  aRet = L"Der Wert, der als Datum formatiert wird";
277     }
278     else if ( aProgrammaticFunctionName == L"getColorValue" )
279     {
280         if ( nArgument == 0 )       aRet = L"Der Bereich, dessen Hintergrundfarbe abgefragt wird";
281     }
282     else if ( aProgrammaticFunctionName == L"transpose" )
283     {
284         if ( nArgument == 0 )       aRet = L"Die Matrix, die transponiert werden soll";
285     }
286     else if ( aProgrammaticFunctionName == L"transposeInt" )
287     {
288         if ( nArgument == 0 )       aRet = L"Die Matrix, die transponiert werden soll";
289     }
290     else if ( aProgrammaticFunctionName == L"repeatMultiple" )
291     {
292         if ( nArgument == 0 )       aRet = L"Anzahl der Wiederholungen";
293         else if ( nArgument == 1 )  aRet = L"Text, der zwischen den Inhalten erscheint";
294         else if ( nArgument == 2 )  aRet = L"Mehrere Inhalte";
295     }
296     else if ( aProgrammaticFunctionName == L"getStrOrVal" )
297     {
298         if ( nArgument == 0 )       aRet = L"Wenn Flag 0 ist, wird ein Wert zurueckgegeben, sonst ein String.";
299     }
300     else if ( aProgrammaticFunctionName == L"callAsync" )
301     {
302         if ( nArgument == 0 )       aRet = L"Ein String";
303     }
304     return aRet;
305 }
306 
getProgrammaticCategoryName(const UString & aProgrammaticFunctionName)307 UString ScTestAddIn::getProgrammaticCategoryName(const UString& aProgrammaticFunctionName)
308                                 THROWS( (UsrSystemException) )
309 {
310     //  return non-translated strings
311 
312     UString aRet;
313     if ( aProgrammaticFunctionName == L"countParams" )        aRet = L"Information";
314     else if ( aProgrammaticFunctionName == L"addOne" )        aRet = L"Mathematical";
315     else if ( aProgrammaticFunctionName == L"repeatStr" )     aRet = L"Text";
316     else if ( aProgrammaticFunctionName == L"getDateString" ) aRet = L"Date&Time";
317     else if ( aProgrammaticFunctionName == L"getColorValue" ) aRet = L"Spreadsheet";
318     else if ( aProgrammaticFunctionName == L"transpose" )     aRet = L"Matrix";
319     else if ( aProgrammaticFunctionName == L"transposeInt" )  aRet = L"Matrix";
320     else if ( aProgrammaticFunctionName == L"repeatMultiple" )aRet = L"Text";
321     else if ( aProgrammaticFunctionName == L"getStrOrVal" )   aRet = L"Add-In";
322     else if ( aProgrammaticFunctionName == L"callAsync" )     aRet = L"Realtime";       // new group
323     return aRet;
324 }
325 
getDisplayCategoryName(const UString & aProgrammaticFunctionName)326 UString ScTestAddIn::getDisplayCategoryName(const UString& aProgrammaticFunctionName)
327                                 THROWS( (UsrSystemException) )
328 {
329     //  return translated strings
330 
331     return L"irgendwas";    // not used for predefined categories
332 }
333 
334 // XLocalizable
335 
setLocale(const lang::Locale & eLocale)336 void ScTestAddIn::setLocale(const lang::Locale& eLocale) THROWS( (UsrSystemException) )
337 {
338     aFuncLoc = eLocale;
339 //  DBG_ERROR( UStringToString(aFuncLoc.Language, CHARSET_SYSTEM) + String("-") +
340 //             UStringToString(aFuncLoc.Country, CHARSET_SYSTEM) );
341 }
342 
getLocale()343 ::com::sun::star::lang::Locale SAL_CALL ScTestAddIn::getLocale(  ) throw(::com::sun::star::uno::RuntimeException)
344 {
345     return aFuncLoc;
346 }
347 
348 // XTestAddIn
349 
countParams(const::com::sun::star::uno::Sequence<::com::sun::star::uno::Any> & aArgs)350 sal_Int32 SAL_CALL ScTestAddIn::countParams( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArgs ) throw(::com::sun::star::uno::RuntimeException)
351 {
352     return aArgs.getLength();
353 }
354 
addOne(double fValue)355 double SAL_CALL ScTestAddIn::addOne( double fValue ) throw(::com::sun::star::uno::RuntimeException)
356 {
357     return fValue + 1.0;
358 }
359 
repeatStr(const::rtl::OUString & aStr,sal_Int32 nCount)360 ::rtl::OUString SAL_CALL ScTestAddIn::repeatStr( const ::rtl::OUString& aStr, sal_Int32 nCount ) throw(::com::sun::star::uno::RuntimeException)
361 {
362     String aRet;
363     String aStrStr = OUStringToString( aStr, CHARSET_SYSTEM );
364     for (long i=0; i<nCount; i++)
365         aRet += aStrStr;
366 
367     return StringToOUString( aRet, CHARSET_SYSTEM );
368 }
369 
getDateString(const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertySet> & xCaller,double fValue)370 ::rtl::OUString SAL_CALL ScTestAddIn::getDateString( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xCaller, double fValue ) throw(::com::sun::star::uno::RuntimeException)
371 {
372     uno::Any aDateAny = xCaller->getPropertyValue( L"NullDate" );
373 //! if ( aDateAny.getReflection()->equals( *Date_getReflection() ) )
374     {
375         util::Date aDate;
376         aDateAny >>= aDate;
377         //const Date* pDate = (const Date*)aDateAny.get();
378         //if (pDate)
379         {
380             //Date aNewDate = *pDate;
381             Date aNewDate( aDate.Day, aDate.Month, aDate.Year );
382 
383             aNewDate += (long)(fValue+0.5);
384 
385             String aRet;
386             aRet += aNewDate.GetDay();
387             aRet += '.';
388             aRet += aNewDate.GetMonth();
389             aRet += '.';
390             aRet += aNewDate.GetYear();
391             return StringToOUString( aRet, CHARSET_SYSTEM );
392         }
393     }
394 
395     return L"**ERROR**";
396 }
397 
getColorValue(const::com::sun::star::uno::Reference<::com::sun::star::table::XCellRange> & xRange)398 sal_Int32 SAL_CALL ScTestAddIn::getColorValue( const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange >& xRange ) throw(::com::sun::star::uno::RuntimeException)
399 {
400     uno::Reference<beans::XPropertySet> xProp( xRange, uno::UNO_QUERY );
401     if (xProp.is())
402     {
403         long nRet = -1;
404         uno::Any aTrans = xProp->getPropertyValue( L"IsCellBackgroundTransparent" );
405         BOOL bIsTrans;
406         aTrans >>= bIsTrans;        //! dont use >>= for BOOL
407         if (!bIsTrans)
408         {
409             uno::Any aCol = xProp->getPropertyValue( L"CellBackColor" );
410             //nRet = NAMESPACE_USR(OPropertyTypeConversion)::toINT32( aCol );
411             aCol >>= nRet;
412         }
413         return nRet;
414     }
415     return 0;
416 }
417 
lcl_GetDoubleElement(const uno::Sequence<uno::Sequence<double>> & aMatrix,long nCol,long nRow)418 double lcl_GetDoubleElement( const uno::Sequence< uno::Sequence<double> >& aMatrix, long nCol, long nRow )
419 {
420     if ( nRow < aMatrix.getLength() )
421     {
422         const uno::Sequence<double>& rRowSeq = aMatrix.getConstArray()[nRow];
423         if ( nCol < rRowSeq.getLength() )
424             return rRowSeq.getConstArray()[nCol];
425     }
426     return 0.0;     // error
427 }
428 
lcl_GetLongElement(const uno::Sequence<uno::Sequence<INT32>> & aMatrix,long nCol,long nRow)429 INT32 lcl_GetLongElement( const uno::Sequence< uno::Sequence<INT32> >& aMatrix, long nCol, long nRow )
430 {
431     if ( nRow < aMatrix.getLength() )
432     {
433         const uno::Sequence<INT32>& rRowSeq = aMatrix.getConstArray()[nRow];
434         if ( nCol < rRowSeq.getLength() )
435             return rRowSeq.getConstArray()[nCol];
436     }
437     return 0.0;     // error
438 }
439 
transpose(const::com::sun::star::uno::Sequence<::com::sun::star::uno::Sequence<double>> & aMatrix)440 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > > SAL_CALL ScTestAddIn::transpose( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& aMatrix ) throw(::com::sun::star::uno::RuntimeException)
441 {
442     long nRowCount = aMatrix.getLength();
443     long nColCount = 0;
444     if ( nRowCount )
445         nColCount = aMatrix.getConstArray()[0].getLength();
446 
447     uno::Sequence< uno::Sequence<double> > aRet( nColCount );
448     for (long nCol=0; nCol<nColCount; nCol++)
449     {
450         uno::Sequence<double> aSubSeq(nRowCount);
451         for (long nRow=0; nRow<nRowCount; nRow++)
452             aSubSeq.getArray()[nRow] = lcl_GetDoubleElement( aMatrix, nCol, nRow );
453 
454         aRet.getArray()[nCol] = aSubSeq;
455     }
456 
457     return aRet;
458 }
459 
transposeInt(const::com::sun::star::uno::Sequence<::com::sun::star::uno::Sequence<sal_Int32>> & aMatrix)460 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< sal_Int32 > > SAL_CALL ScTestAddIn::transposeInt( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< sal_Int32 > >& aMatrix ) throw(::com::sun::star::uno::RuntimeException)
461 {
462     long nRowCount = aMatrix.getLength();
463     long nColCount = 0;
464     if ( nRowCount )
465         nColCount = aMatrix.getConstArray()[0].getLength();
466 
467     uno::Sequence< uno::Sequence<INT32> > aRet( nColCount );
468     for (long nCol=0; nCol<nColCount; nCol++)
469     {
470         uno::Sequence<INT32> aSubSeq(nRowCount);
471         for (long nRow=0; nRow<nRowCount; nRow++)
472             aSubSeq.getArray()[nRow] = lcl_GetLongElement( aMatrix, nCol, nRow );
473 
474         aRet.getArray()[nCol] = aSubSeq;
475     }
476 
477     return aRet;
478 }
479 
repeatMultiple(sal_Int32 nCount,const::com::sun::star::uno::Any & aFirst,const::com::sun::star::uno::Sequence<::com::sun::star::uno::Any> & aFollow)480 ::rtl::OUString SAL_CALL ScTestAddIn::repeatMultiple( sal_Int32 nCount, const ::com::sun::star::uno::Any& aFirst, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aFollow ) throw(::com::sun::star::uno::RuntimeException)
481 {
482     String aSeparator;
483     if ( !aFirst.hasValue() )   // not specified
484         aSeparator = ';';
485     else
486     {
487         rtl::OUString aUStr;
488         aFirst >>= aUStr;
489         aSeparator = OUStringToString( aUStr, CHARSET_SYSTEM );
490     }
491 
492     String aContent;
493     long nContCount = aFollow.getLength();
494     const uno::Any* pArr = aFollow.getConstArray();
495     for (long nPos=0; nPos<nContCount; nPos++)
496     {
497         if ( nPos > 0 )
498             aContent += ' ';
499         rtl::OUString aUStr;
500         pArr[nPos] >>= aUStr;
501         aContent += OUStringToString( aUStr, CHARSET_SYSTEM );
502     }
503 
504     String aRet;
505 
506     for (long i=0; i<nCount; i++)
507     {
508         if (i>0)
509             aRet += aSeparator;
510         aRet += aContent;
511     }
512 
513     return StringToOUString(aRet, CHARSET_SYSTEM);
514 }
515 
getStrOrVal(sal_Int32 nFlag)516 ::com::sun::star::uno::Any SAL_CALL ScTestAddIn::getStrOrVal( sal_Int32 nFlag ) throw(::com::sun::star::uno::RuntimeException)
517 {
518     uno::Any aRet;
519 
520     //! Test
521     if ( nFlag == 42 )
522     {
523         uno::Sequence<rtl::OUString> aInner(3);
524         aInner.getArray()[0] = L"Bla";
525         aInner.getArray()[1] = L"Fasel";
526         aInner.getArray()[2] = L"Suelz";
527         uno::Sequence< uno::Sequence<rtl::OUString> > aOuter( &aInner, 1 );
528 
529         //return uno::Any( &aOuter, Sequence< Sequence<UString> >::getReflection() );
530 
531         aRet <<= aOuter;
532         return aRet;
533     }
534     //! Test
535 
536     if ( nFlag )
537         aRet <<= UString(L"This is a string.");
538     else
539         aRet <<= (INT32)42;
540 
541     return aRet;
542 }
543 
callAsync(const::rtl::OUString & aString)544 ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XVolatileResult > SAL_CALL ScTestAddIn::callAsync( const ::rtl::OUString& aString ) throw(::com::sun::star::uno::RuntimeException)
545 {
546     String aStr = OUStringToString( aString, CHARSET_SYSTEM );
547     char c = (char) aStr;
548     if ( c >= '0' && c <= '9' )
549     {
550         if (!xNumResult.is())
551             xNumResult = new ScAddInResult( "Num" );
552         return xNumResult;
553     }
554     else
555     {
556         if (!xAlphaResult.is())
557             xAlphaResult = new ScAddInResult( "Str" );
558         return xAlphaResult;
559     }
560 }
561 
562 
563 // XServiceName
564 
getServiceName()565 ::rtl::OUString SAL_CALL ScTestAddIn::getServiceName(  ) throw(::com::sun::star::uno::RuntimeException)
566 {
567     return SCTESTADDIN_SERVICE;     // name of specific AddIn service
568 }
569 
570 // XServiceInfo
571 
getImplementationName()572 ::rtl::OUString SAL_CALL ScTestAddIn::getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException)
573 {
574     return getImplementationName_Static();
575 }
576 
supportsService(const::rtl::OUString & ServiceName)577 sal_Bool SAL_CALL ScTestAddIn::supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException)
578 {
579     return ServiceName == SCADDIN_SERVICE ||
580             ServiceName == SCTESTADDIN_SERVICE;
581 }
582 
getSupportedServiceNames()583 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL ScTestAddIn::getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException)
584 {
585     return getSupportedServiceNames_Static();
586 }
587 
588 //------------------------------------------------------------------------
589 
590 
591 
592