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