summaryrefslogtreecommitdiff
path: root/sc/source/ui/unoobj/fmtuno.cxx
blob: bfc666f4970c191421a6204640e3d602976664f1 (plain)
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
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: fmtuno.cxx,v $
 *
 *  $Revision: 1.13 $
 *
 *  last change: $Author: kz $ $Date: 2006-07-21 14:39:29 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library 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 for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sc.hxx"



#include <tools/debug.hxx>
#include <rtl/uuid.h>

#include <com/sun/star/sheet/ValidationAlertStyle.hpp>
#include <com/sun/star/sheet/ValidationType.hpp>
#include <com/sun/star/sheet/TableValidationVisibility.hpp>

#include "fmtuno.hxx"
#include "miscuno.hxx"
#include "conditio.hxx"
#include "validat.hxx"
#include "document.hxx"
#include "unoguard.hxx"
#include "unonames.hxx"
#include "styleuno.hxx"		// ScStyleNameConversion

using namespace com::sun::star;

//------------------------------------------------------------------------

//	Map nur fuer PropertySetInfo

const SfxItemPropertyMap* lcl_GetValidatePropertyMap()
{
    static SfxItemPropertyMap aValidatePropertyMap_Impl[] =
    {
        {MAP_CHAR_LEN(SC_UNONAME_ERRALSTY),	0,	&getCppuType((sheet::ValidationAlertStyle*)0),	0},
        {MAP_CHAR_LEN(SC_UNONAME_ERRMESS),	0,	&getCppuType((rtl::OUString*)0),				0},
        {MAP_CHAR_LEN(SC_UNONAME_ERRTITLE),	0,	&getCppuType((rtl::OUString*)0),				0},
        {MAP_CHAR_LEN(SC_UNONAME_IGNOREBL),	0,	&getBooleanCppuType(),							0},
        {MAP_CHAR_LEN(SC_UNONAME_INPMESS),	0,	&getCppuType((rtl::OUString*)0),				0},
        {MAP_CHAR_LEN(SC_UNONAME_INPTITLE),	0,	&getCppuType((rtl::OUString*)0),				0},
        {MAP_CHAR_LEN(SC_UNONAME_SHOWERR),	0,	&getBooleanCppuType(),							0},
        {MAP_CHAR_LEN(SC_UNONAME_SHOWINP),	0,	&getBooleanCppuType(),							0},
        {MAP_CHAR_LEN(SC_UNONAME_SHOWLIST),	0,	&getCppuType((sal_Int16*)0),    				0},
        {MAP_CHAR_LEN(SC_UNONAME_TYPE),		0,	&getCppuType((sheet::ValidationType*)0),		0},
        {0,0,0,0}
    };
    return aValidatePropertyMap_Impl;
}

//------------------------------------------------------------------------

SC_SIMPLE_SERVICE_INFO( ScTableConditionalEntry, "ScTableConditionalEntry", "com.sun.star.sheet.TableConditionalEntry" )
SC_SIMPLE_SERVICE_INFO( ScTableConditionalFormat, "ScTableConditionalFormat", "com.sun.star.sheet.TableConditionalFormat" )
SC_SIMPLE_SERVICE_INFO( ScTableValidationObj, "ScTableValidationObj", "com.sun.star.sheet.TableValidation" )

//------------------------------------------------------------------------

sheet::ConditionOperator lcl_ConditionModeToOperator( ScConditionMode eMode )
{
    sheet::ConditionOperator eOper = sheet::ConditionOperator_NONE;
    switch (eMode)
    {
        case SC_COND_EQUAL:		 eOper = sheet::ConditionOperator_EQUAL;		 break;
        case SC_COND_LESS:		 eOper = sheet::ConditionOperator_LESS;			 break;
        case SC_COND_GREATER:	 eOper = sheet::ConditionOperator_GREATER;		 break;
        case SC_COND_EQLESS:	 eOper = sheet::ConditionOperator_LESS_EQUAL;	 break;
        case SC_COND_EQGREATER:	 eOper = sheet::ConditionOperator_GREATER_EQUAL; break;
        case SC_COND_NOTEQUAL:	 eOper = sheet::ConditionOperator_NOT_EQUAL;	 break;
        case SC_COND_BETWEEN:	 eOper = sheet::ConditionOperator_BETWEEN;		 break;
        case SC_COND_NOTBETWEEN: eOper = sheet::ConditionOperator_NOT_BETWEEN;	 break;
        case SC_COND_DIRECT:	 eOper = sheet::ConditionOperator_FORMULA;		 break;
    }
    return eOper;
}

ScConditionMode lcl_ConditionOperatorToMode( sheet::ConditionOperator eOper )
{
    ScConditionMode eMode = SC_COND_NONE;
    switch (eOper)
    {
        case sheet::ConditionOperator_EQUAL:		 eMode = SC_COND_EQUAL;		 break;
        case sheet::ConditionOperator_LESS:			 eMode = SC_COND_LESS;		 break;
        case sheet::ConditionOperator_GREATER:		 eMode = SC_COND_GREATER;	 break;
        case sheet::ConditionOperator_LESS_EQUAL:	 eMode = SC_COND_EQLESS;	 break;
        case sheet::ConditionOperator_GREATER_EQUAL: eMode = SC_COND_EQGREATER;  break;
        case sheet::ConditionOperator_NOT_EQUAL:	 eMode = SC_COND_NOTEQUAL;	 break;
        case sheet::ConditionOperator_BETWEEN:		 eMode = SC_COND_BETWEEN;	 break;
        case sheet::ConditionOperator_NOT_BETWEEN:	 eMode = SC_COND_NOTBETWEEN; break;
        case sheet::ConditionOperator_FORMULA:		 eMode = SC_COND_DIRECT;	 break;
    }
    return eMode;
}

//------------------------------------------------------------------------

ScTableConditionalFormat::ScTableConditionalFormat()
{
}

ScTableConditionalFormat::ScTableConditionalFormat(ScDocument* pDoc, ULONG nKey,
                                                    BOOL bEnglish, BOOL bCompileXML)
{
    //	Eintrag aus dem Dokument lesen...

    if ( pDoc && nKey )
    {
        ScConditionalFormatList* pList = pDoc->GetCondFormList();
        if (pList)
        {
            const ScConditionalFormat* pFormat = pList->GetFormat( nKey );
            if (pFormat)
            {
                USHORT nEntryCount = pFormat->Count();
                for (USHORT i=0; i<nEntryCount; i++)
                {
                    const ScCondFormatEntry* pFormatEntry = pFormat->GetEntry(i);
                    ScConditionMode eMode = pFormatEntry->GetOperation();
                    ScAddress aPos(pFormatEntry->GetValidSrcPos());    // #b4974740# valid pos for expressions
                    String aExpr1(pFormatEntry->GetExpression( aPos, 0, 0, bEnglish, bCompileXML ));
                    String aExpr2(pFormatEntry->GetExpression( aPos, 1, 0, bEnglish, bCompileXML ));
                    String aStyle(pFormatEntry->GetStyle());

                    AddEntry_Impl( eMode, aExpr1, aExpr2, aPos, EMPTY_STRING, aStyle );
                }
            }
        }
    }
}

void ScTableConditionalFormat::FillFormat( ScConditionalFormat& rFormat,
                                            ScDocument* pDoc, BOOL bEnglish, BOOL bCompileXML ) const
{
    //	ScConditionalFormat = Core-Struktur, muss leer sein

    DBG_ASSERT( rFormat.IsEmpty(), "FillFormat: Format nicht leer" );
    USHORT nCount = (USHORT)aEntries.Count();
    for (USHORT i=0; i<nCount; i++)
    {
        ScTableConditionalEntry* pEntry = (ScTableConditionalEntry*)aEntries.GetObject(i);
        if (pEntry)
        {
            USHORT nMode;
            String aExpr1, aExpr2, aStyle, aPosStr;
            ScAddress aPos;
            pEntry->GetData( nMode, aExpr1, aExpr2, aPos, aPosStr, aStyle );
            ScCondFormatEntry aCoreEntry( (ScConditionMode)nMode,
                                aExpr1, aExpr2, pDoc, aPos, aStyle, bEnglish, bCompileXML );
            if ( aPosStr.Len() )
                aCoreEntry.SetSrcString( aPosStr );
            rFormat.AddEntry( aCoreEntry );
        }
    }
}

ScTableConditionalFormat::~ScTableConditionalFormat()
{
    ScTableConditionalEntry* pEntry;
    aEntries.First();
    while ( pEntry = (ScTableConditionalEntry*)aEntries.Remove() )
        pEntry->release();
}

void ScTableConditionalFormat::AddEntry_Impl( USHORT nMode,
                        const String& rExpr1, const String& rExpr2,
                        const ScAddress& rPos, const String& rPosStr, const String& rStyle )
{
    ScTableConditionalEntry* pNew = new ScTableConditionalEntry(
                                        this, nMode, rExpr1, rExpr2, rPos, rPosStr, rStyle );
    pNew->acquire();
    aEntries.Insert( pNew, LIST_APPEND );
}

void ScTableConditionalFormat::DataChanged()
{
    //	wenn's mal das "lebende Objekt" ist, muss hier was passieren...
}

// XSheetConditionalFormat

ScTableConditionalEntry* ScTableConditionalFormat::GetObjectByIndex_Impl(USHORT nIndex) const
{
    return (ScTableConditionalEntry*)aEntries.GetObject(nIndex);
}

void SAL_CALL ScTableConditionalFormat::addNew(
                    const uno::Sequence<beans::PropertyValue >& aConditionalEntry )
                    throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    ScConditionMode eMode = SC_COND_NONE;
    String aExpr1;
    String aExpr2;
    ScAddress aPos;
    String aPosStr;
    String aStyle;

    const beans::PropertyValue* pPropArray = aConditionalEntry.getConstArray();
    long nPropCount = aConditionalEntry.getLength();
    for (long i = 0; i < nPropCount; i++)
    {
        const beans::PropertyValue& rProp = pPropArray[i];
        String aPropName(rProp.Name);

        if ( aPropName.EqualsAscii( SC_UNONAME_OPERATOR ) )
        {
            sheet::ConditionOperator eOper = (sheet::ConditionOperator)
                            ScUnoHelpFunctions::GetEnumFromAny( rProp.Value );
            eMode = lcl_ConditionOperatorToMode( eOper );
        }
        else if ( aPropName.EqualsAscii( SC_UNONAME_FORMULA1 ) )
        {
            rtl::OUString aStrVal;
            if ( rProp.Value >>= aStrVal )
                aExpr1 = String( aStrVal );
        }
        else if ( aPropName.EqualsAscii( SC_UNONAME_FORMULA2 ) )
        {
            rtl::OUString aStrVal;
            if ( rProp.Value >>= aStrVal )
                aExpr2 = String( aStrVal );
        }
        else if ( aPropName.EqualsAscii( SC_UNONAME_SOURCEPOS ) )
        {
            table::CellAddress aAddress;
            if ( rProp.Value >>= aAddress )
                aPos = ScAddress( (SCCOL)aAddress.Column, (SCROW)aAddress.Row, aAddress.Sheet );
        }
        else if ( aPropName.EqualsAscii( SC_UNONAME_SOURCESTR ) )
        {
            rtl::OUString aStrVal;
            if ( rProp.Value >>= aStrVal )
                aPosStr = String( aStrVal );
        }
        else if ( aPropName.EqualsAscii( SC_UNONAME_STYLENAME ) )
        {
            rtl::OUString aStrVal;
            if ( rProp.Value >>= aStrVal )
                aStyle = ScStyleNameConversion::ProgrammaticToDisplayName(
                                                aStrVal, SFX_STYLE_FAMILY_PARA );
        }
        else
        {
            DBG_ERROR("falsche Property");
            //!	Exception...
        }
    }

    AddEntry_Impl( eMode, aExpr1, aExpr2, aPos, aPosStr, aStyle );
    DataChanged();
}

void SAL_CALL ScTableConditionalFormat::removeByIndex( sal_Int32 nIndex )
                                                throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    ScTableConditionalEntry* pEntry = (ScTableConditionalEntry*)aEntries.GetObject(nIndex);
    if (pEntry)
    {
        aEntries.Remove(pEntry);
        pEntry->release();
        DataChanged();
    }
}

void SAL_CALL ScTableConditionalFormat::clear() throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    ScTableConditionalEntry* pEntry;
    aEntries.First();
    while ( pEntry = (ScTableConditionalEntry*)aEntries.Remove() )
        pEntry->release();

    DataChanged();
}

// XEnumerationAccess

uno::Reference<container::XEnumeration> SAL_CALL ScTableConditionalFormat::createEnumeration()
                                                    throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.TableConditionalEntryEnumeration")));
}

// XIndexAccess

sal_Int32 SAL_CALL ScTableConditionalFormat::getCount() throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    return aEntries.Count();
}

uno::Any SAL_CALL ScTableConditionalFormat::getByIndex( sal_Int32 nIndex )
                            throw(lang::IndexOutOfBoundsException,
                                    lang::WrappedTargetException, uno::RuntimeException)
{
    ScUnoGuard aGuard;
    uno::Reference<sheet::XSheetConditionalEntry> xEntry(GetObjectByIndex_Impl((USHORT)nIndex));
    if (xEntry.is())
        return uno::makeAny(xEntry);
    else
        throw lang::IndexOutOfBoundsException();
    return uno::Any();
}

uno::Type SAL_CALL ScTableConditionalFormat::getElementType() throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    return getCppuType((uno::Reference<sheet::XSheetConditionalEntry>*)0);
}

sal_Bool SAL_CALL ScTableConditionalFormat::hasElements() throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    return ( getCount() != 0 );
}

//	conditional format entries have no real names
//	-> generate name from index

rtl::OUString lcl_GetEntryNameFromIndex( sal_Int32 nIndex )
{
    rtl::OUString aRet( RTL_CONSTASCII_USTRINGPARAM( "Entry" ) );
    aRet += rtl::OUString::valueOf( nIndex );
    return aRet;
}

uno::Any SAL_CALL ScTableConditionalFormat::getByName( const rtl::OUString& aName )
            throw(container::NoSuchElementException,
                    lang::WrappedTargetException, uno::RuntimeException)
{
    ScUnoGuard aGuard;

    uno::Reference<sheet::XSheetConditionalEntry> xEntry;
    long nCount = aEntries.Count();
    for (long i=0; i<nCount; i++)
        if ( aName == lcl_GetEntryNameFromIndex(i) )
        {
            xEntry.set(GetObjectByIndex_Impl((USHORT)i));
            break;
        }

    if (xEntry.is())
        return uno::makeAny(xEntry);
    else
        throw container::NoSuchElementException();
    return uno::Any();
}

uno::Sequence<rtl::OUString> SAL_CALL ScTableConditionalFormat::getElementNames()
                                                    throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;

    long nCount = aEntries.Count();
    uno::Sequence<rtl::OUString> aNames(nCount);
    rtl::OUString* pArray = aNames.getArray();
    for (long i=0; i<nCount; i++)
        pArray[i] = lcl_GetEntryNameFromIndex(i);

    return aNames;
}

sal_Bool SAL_CALL ScTableConditionalFormat::hasByName( const rtl::OUString& aName )
                                                    throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;

    long nCount = aEntries.Count();
    for (long i=0; i<nCount; i++)
        if ( aName == lcl_GetEntryNameFromIndex(i) )
            return TRUE;

    return FALSE;
}

// XUnoTunnel

sal_Int64 SAL_CALL ScTableConditionalFormat::getSomething(
                const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
{
    if ( rId.getLength() == 16 &&
          0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
                                    rId.getConstArray(), 16 ) )
    {
        return (sal_Int64)this;
    }
    return 0;
}

// static
const uno::Sequence<sal_Int8>& ScTableConditionalFormat::getUnoTunnelId()
{
    static uno::Sequence<sal_Int8> * pSeq = 0;
    if( !pSeq )
    {
        osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
        if( !pSeq )
        {
            static uno::Sequence< sal_Int8 > aSeq( 16 );
            rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
            pSeq = &aSeq;
        }
    }
    return *pSeq;
}

// static
ScTableConditionalFormat* ScTableConditionalFormat::getImplementation(
                                const uno::Reference<sheet::XSheetConditionalEntries> xObj )
{
    ScTableConditionalFormat* pRet = NULL;
    uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
    if (xUT.is())
        pRet = (ScTableConditionalFormat*) xUT->getSomething( getUnoTunnelId() );
    return pRet;
}

//------------------------------------------------------------------------

ScTableConditionalEntry::ScTableConditionalEntry() :
    pParent( NULL )
{
}

ScTableConditionalEntry::ScTableConditionalEntry( ScTableConditionalFormat* pPar,
                             USHORT nM, const String& rEx1, const String& rEx2,
                             const ScAddress& rPos, const String& rPosStr, const String& rSt ) :
    pParent( pPar ),
    nMode( nM ),
    aExpr1( rEx1 ),
    aExpr2( rEx2 ),
    aSrcPos( rPos ),
    aPosString( rPosStr ),
    aStyle( rSt )
{
    if (pParent)
        pParent->acquire();
}

ScTableConditionalEntry::~ScTableConditionalEntry()
{
    if (pParent)
        pParent->release();
}

void ScTableConditionalEntry::GetData( USHORT& rM, String& rEx1, String& rEx2,
                                        ScAddress& rPos, String& rPosStr, String& rSt ) const
{
    rM	 = nMode;
    rEx1 = aExpr1;
    rEx2 = aExpr2;
    rPos = aSrcPos;
    rPosStr = aPosString;
    rSt  = aStyle;
}

// XSheetCondition

sheet::ConditionOperator SAL_CALL ScTableConditionalEntry::getOperator()
                                                throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    return lcl_ConditionModeToOperator( (ScConditionMode)nMode );
}

void SAL_CALL ScTableConditionalEntry::setOperator( sheet::ConditionOperator nOperator )
                                                throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    nMode = lcl_ConditionOperatorToMode( nOperator );
    if (pParent)
        pParent->DataChanged();
}

rtl::OUString SAL_CALL ScTableConditionalEntry::getFormula1() throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    return aExpr1;
}

void SAL_CALL ScTableConditionalEntry::setFormula1( const rtl::OUString& aFormula1 )
                                                throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    aExpr1 = String( aFormula1 );
    if (pParent)
        pParent->DataChanged();
}

rtl::OUString SAL_CALL ScTableConditionalEntry::getFormula2() throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    return aExpr2;
}

void SAL_CALL ScTableConditionalEntry::setFormula2( const rtl::OUString& aFormula2 )
                                                throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    aExpr2 = String( aFormula2 );
    if (pParent)
        pParent->DataChanged();
}

table::CellAddress SAL_CALL ScTableConditionalEntry::getSourcePosition() throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    table::CellAddress aRet;
    aRet.Column = aSrcPos.Col();
    aRet.Row    = aSrcPos.Row();
    aRet.Sheet  = aSrcPos.Tab();
    return aRet;
}

void SAL_CALL ScTableConditionalEntry::setSourcePosition( const table::CellAddress& aSourcePosition )
                                            throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    aSrcPos.Set( (SCCOL)aSourcePosition.Column, (SCROW)aSourcePosition.Row, aSourcePosition.Sheet );
    if (pParent)
        pParent->DataChanged();
}

// XSheetConditionalEntry

rtl::OUString SAL_CALL ScTableConditionalEntry::getStyleName() throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    return ScStyleNameConversion::DisplayToProgrammaticName( aStyle, SFX_STYLE_FAMILY_PARA );
}

void SAL_CALL ScTableConditionalEntry::setStyleName( const rtl::OUString& aStyleName )
                                            throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    aStyle = ScStyleNameConversion::ProgrammaticToDisplayName( aStyleName, SFX_STYLE_FAMILY_PARA );
    if (pParent)
        pParent->DataChanged();
}

//------------------------------------------------------------------------

ScTableValidationObj::ScTableValidationObj() :
    aPropSet( lcl_GetValidatePropertyMap() )
{
}

ScTableValidationObj::ScTableValidationObj(ScDocument* pDoc, ULONG nKey,
                                            BOOL bEnglish, BOOL bCompileXML) :
    aPropSet( lcl_GetValidatePropertyMap() )
{
    //	Eintrag aus dem Dokument lesen...

    BOOL bFound = FALSE;
    if ( pDoc && nKey )
    {
        const ScValidationData*	pData = pDoc->GetValidationEntry( nKey );
        if (pData)
        {
            nMode = pData->GetOperation();
            aSrcPos = pData->GetValidSrcPos();  // #b4974740# valid pos for expressions
            aExpr1 = pData->GetExpression( aSrcPos, 0, 0, bEnglish, bCompileXML );
            aExpr2 = pData->GetExpression( aSrcPos, 1, 0, bEnglish, bCompileXML );
            nValMode = pData->GetDataMode();
            bIgnoreBlank = pData->IsIgnoreBlank();
            nShowList = pData->GetListType();
            bShowInput = pData->GetInput( aInputTitle, aInputMessage );
            ScValidErrorStyle eStyle;
            bShowError = pData->GetErrMsg( aErrorTitle, aErrorMessage, eStyle );
            nErrorStyle = eStyle;

            bFound = TRUE;
        }
    }
    if (!bFound)
        ClearData_Impl();		// Defaults
}

ScValidationData* ScTableValidationObj::CreateValidationData( ScDocument* pDoc,
                                            BOOL bEnglish, BOOL bCompileXML ) const
{
    //	ScValidationData = Core-Struktur

    ScValidationData* pRet = new ScValidationData( (ScValidationMode)nValMode,
                                                   (ScConditionMode)nMode,
                                                   aExpr1, aExpr2, pDoc, aSrcPos,
                                                   bEnglish, bCompileXML );
    pRet->SetIgnoreBlank(bIgnoreBlank);
    pRet->SetListType(nShowList);

    // set strings for error / input even if disabled (and disable afterwards)
    pRet->SetInput( aInputTitle, aInputMessage );
    if (!bShowInput)
        pRet->ResetInput();
    pRet->SetError( aErrorTitle, aErrorMessage, (ScValidErrorStyle)nErrorStyle );
    if (!bShowError)
        pRet->ResetError();

    if ( aPosString.Len() )
        pRet->SetSrcString( aPosString );

    return pRet;
}

void ScTableValidationObj::ClearData_Impl()
{
    nMode		 = SC_COND_NONE;
    nValMode	 = SC_VALID_ANY;
    bIgnoreBlank = TRUE;
    nShowList    = sheet::TableValidationVisibility::UNSORTED;
    bShowInput	 = FALSE;
    bShowError	 = FALSE;
    nErrorStyle	 = SC_VALERR_STOP;
    aSrcPos.Set(0,0,0);
    aExpr1.Erase();
    aExpr2.Erase();
    aInputTitle.Erase();
    aInputMessage.Erase();
    aErrorTitle.Erase();
    aErrorMessage.Erase();
}

ScTableValidationObj::~ScTableValidationObj()
{
}

void ScTableValidationObj::DataChanged()
{
    //	wenn's mal das "lebende Objekt" ist, muss hier was passieren...
}

// XSheetCondition

sheet::ConditionOperator SAL_CALL ScTableValidationObj::getOperator()
                                                throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    return lcl_ConditionModeToOperator( (ScConditionMode)nMode );
}

void SAL_CALL ScTableValidationObj::setOperator( sheet::ConditionOperator nOperator )
                                                throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    nMode = lcl_ConditionOperatorToMode( nOperator );
    DataChanged();
}

rtl::OUString SAL_CALL ScTableValidationObj::getFormula1() throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    return aExpr1;
}

void SAL_CALL ScTableValidationObj::setFormula1( const rtl::OUString& aFormula1 )
                                                throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    aExpr1 = String( aFormula1 );
    DataChanged();
}

rtl::OUString SAL_CALL ScTableValidationObj::getFormula2() throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    return aExpr2;
}

void SAL_CALL ScTableValidationObj::setFormula2( const rtl::OUString& aFormula2 )
                                                throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    aExpr2 = String( aFormula2 );
    DataChanged();
}

table::CellAddress SAL_CALL ScTableValidationObj::getSourcePosition() throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    table::CellAddress aRet;
    aRet.Column = aSrcPos.Col();
    aRet.Row    = aSrcPos.Row();
    aRet.Sheet  = aSrcPos.Tab();
    return aRet;
}

void SAL_CALL ScTableValidationObj::setSourcePosition( const table::CellAddress& aSourcePosition )
                                            throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    aSrcPos.Set( (SCCOL)aSourcePosition.Column, (SCROW)aSourcePosition.Row, aSourcePosition.Sheet );
    DataChanged();
}

uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableValidationObj::getPropertySetInfo()
                                                        throw(uno::RuntimeException)
{
    ScUnoGuard aGuard;
    static uno::Reference<beans::XPropertySetInfo> aRef(
        new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
    return aRef;
}

void SAL_CALL ScTableValidationObj::setPropertyValue(
                        const rtl::OUString& aPropertyName, const uno::Any& aValue )
                throw(beans::UnknownPropertyException, beans::PropertyVetoException,
                        lang::IllegalArgumentException, lang::WrappedTargetException,
                        uno::RuntimeException)
{
    ScUnoGuard aGuard;
    String aString(aPropertyName);

    if ( aString.EqualsAscii( SC_UNONAME_SHOWINP ) )	   bShowInput = ScUnoHelpFunctions::GetBoolFromAny( aValue );
    else if ( aString.EqualsAscii( SC_UNONAME_SHOWERR ) )  bShowError = ScUnoHelpFunctions::GetBoolFromAny( aValue );
    else if ( aString.EqualsAscii( SC_UNONAME_IGNOREBL ) ) bIgnoreBlank = ScUnoHelpFunctions::GetBoolFromAny( aValue );
    else if ( aString.EqualsAscii( SC_UNONAME_SHOWLIST ) ) aValue >>= nShowList;
    else if ( aString.EqualsAscii( SC_UNONAME_INPTITLE ) )
    {
        rtl::OUString aStrVal;
        if ( aValue >>= aStrVal )
            aInputTitle = String( aStrVal );
    }
    else if ( aString.EqualsAscii( SC_UNONAME_INPMESS ) )
    {
        rtl::OUString aStrVal;
        if ( aValue >>= aStrVal )
            aInputMessage = String( aStrVal );
    }
    else if ( aString.EqualsAscii( SC_UNONAME_ERRTITLE ) )
    {
        rtl::OUString aStrVal;
        if ( aValue >>= aStrVal )
            aErrorTitle = String( aStrVal );
    }
    else if ( aString.EqualsAscii( SC_UNONAME_ERRMESS ) )
    {
        rtl::OUString aStrVal;
        if ( aValue >>= aStrVal )
            aErrorMessage = String( aStrVal );
    }
    else if ( aString.EqualsAscii( SC_UNONAME_TYPE ) )
    {
        sheet::ValidationType eType = (sheet::ValidationType)
                                ScUnoHelpFunctions::GetEnumFromAny( aValue );
        switch (eType)
        {
            case sheet::ValidationType_ANY:		 nValMode = SC_VALID_ANY;	  break;
            case sheet::ValidationType_WHOLE:	 nValMode = SC_VALID_WHOLE;   break;
            case sheet::ValidationType_DECIMAL:  nValMode = SC_VALID_DECIMAL; break;
            case sheet::ValidationType_DATE:	 nValMode = SC_VALID_DATE;	  break;
            case sheet::ValidationType_TIME:	 nValMode = SC_VALID_TIME;	  break;
            case sheet::ValidationType_TEXT_LEN: nValMode = SC_VALID_TEXTLEN; break;
            case sheet::ValidationType_LIST:	 nValMode = SC_VALID_LIST;	  break;
            case sheet::ValidationType_CUSTOM:	 nValMode = SC_VALID_CUSTOM;  break;
        }
    }
    else if ( aString.EqualsAscii( SC_UNONAME_ERRALSTY ) )
    {
        sheet::ValidationAlertStyle eStyle = (sheet::ValidationAlertStyle)
                                ScUnoHelpFunctions::GetEnumFromAny( aValue );
        switch (eStyle)
        {
            case sheet::ValidationAlertStyle_STOP:	  nErrorStyle = SC_VALERR_STOP;	   break;
            case sheet::ValidationAlertStyle_WARNING: nErrorStyle = SC_VALERR_WARNING; break;
            case sheet::ValidationAlertStyle_INFO:	  nErrorStyle = SC_VALERR_INFO;	   break;
            case sheet::ValidationAlertStyle_MACRO:   nErrorStyle = SC_VALERR_MACRO;   break;
        }
    }
    else if ( aString.EqualsAscii( SC_UNONAME_SOURCESTR ) )
    {
        // internal - only for XML filter, not in PropertySetInfo, only set

        rtl::OUString aStrVal;
        if ( aValue >>= aStrVal )
            aPosString = String( aStrVal );
    }

    DataChanged();
}

uno::Any SAL_CALL ScTableValidationObj::getPropertyValue( const rtl::OUString& aPropertyName )
                throw(beans::UnknownPropertyException, lang::WrappedTargetException,
                        uno::RuntimeException)
{
    ScUnoGuard aGuard;
    String aString(aPropertyName);
    uno::Any aRet;

    if ( aString.EqualsAscii( SC_UNONAME_SHOWINP ) )	   ScUnoHelpFunctions::SetBoolInAny( aRet, bShowInput );
    else if ( aString.EqualsAscii( SC_UNONAME_SHOWERR ) )  ScUnoHelpFunctions::SetBoolInAny( aRet, bShowError );
    else if ( aString.EqualsAscii( SC_UNONAME_IGNOREBL ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, bIgnoreBlank );
    else if ( aString.EqualsAscii( SC_UNONAME_SHOWLIST ) ) aRet <<= nShowList;
    else if ( aString.EqualsAscii( SC_UNONAME_INPTITLE ) ) aRet <<= rtl::OUString( aInputTitle );
    else if ( aString.EqualsAscii( SC_UNONAME_INPMESS ) )  aRet <<= rtl::OUString( aInputMessage );
    else if ( aString.EqualsAscii( SC_UNONAME_ERRTITLE ) ) aRet <<= rtl::OUString( aErrorTitle );
    else if ( aString.EqualsAscii( SC_UNONAME_ERRMESS ) )  aRet <<= rtl::OUString( aErrorMessage );
    else if ( aString.EqualsAscii( SC_UNONAME_TYPE ) )
    {
        sheet::ValidationType eType = sheet::ValidationType_ANY;
        switch (nValMode)
        {
            case SC_VALID_ANY:		eType = sheet::ValidationType_ANY;		break;
            case SC_VALID_WHOLE:	eType = sheet::ValidationType_WHOLE;	break;
            case SC_VALID_DECIMAL:	eType = sheet::ValidationType_DECIMAL;	break;
            case SC_VALID_DATE:		eType = sheet::ValidationType_DATE;		break;
            case SC_VALID_TIME:		eType = sheet::ValidationType_TIME;		break;
            case SC_VALID_TEXTLEN:	eType = sheet::ValidationType_TEXT_LEN; break;
            case SC_VALID_LIST:		eType = sheet::ValidationType_LIST;		break;
            case SC_VALID_CUSTOM:	eType = sheet::ValidationType_CUSTOM;	break;
        }
        aRet <<= eType;
    }
    else if ( aString.EqualsAscii( SC_UNONAME_ERRALSTY ) )
    {
        sheet::ValidationAlertStyle eStyle = sheet::ValidationAlertStyle_STOP;
        switch (nErrorStyle)
        {
            case SC_VALERR_STOP:	eStyle = sheet::ValidationAlertStyle_STOP;	  break;
            case SC_VALERR_WARNING:	eStyle = sheet::ValidationAlertStyle_WARNING; break;
            case SC_VALERR_INFO:	eStyle = sheet::ValidationAlertStyle_INFO;	  break;
            case SC_VALERR_MACRO:	eStyle = sheet::ValidationAlertStyle_MACRO;   break;
        }
        aRet <<= eStyle;
    }

    return aRet;
}

SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableValidationObj )

// XUnoTunnel

sal_Int64 SAL_CALL ScTableValidationObj::getSomething(
                const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
{
    if ( rId.getLength() == 16 &&
          0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
                                    rId.getConstArray(), 16 ) )
    {
        return (sal_Int64)this;
    }
    return 0;
}

// static
const uno::Sequence<sal_Int8>& ScTableValidationObj::getUnoTunnelId()
{
    static uno::Sequence<sal_Int8> * pSeq = 0;
    if( !pSeq )
    {
        osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
        if( !pSeq )
        {
            static uno::Sequence< sal_Int8 > aSeq( 16 );
            rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
            pSeq = &aSeq;
        }
    }
    return *pSeq;
}

// static
ScTableValidationObj* ScTableValidationObj::getImplementation(
                                const uno::Reference<beans::XPropertySet> xObj )
{
    ScTableValidationObj* pRet = NULL;
    uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
    if (xUT.is())
        pRet = (ScTableValidationObj*) xUT->getSomething( getUnoTunnelId() );
    return pRet;
}

//------------------------------------------------------------------------