1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fmtuno.cxx,v $
10 * $Revision: 1.18.32.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 #include <tools/debug.hxx>
39 #include <com/sun/star/sheet/ValidationAlertStyle.hpp>
40 #include <com/sun/star/sheet/ValidationType.hpp>
41 #include <com/sun/star/sheet/TableValidationVisibility.hpp>
44 #include "miscuno.hxx"
45 #include "validat.hxx"
46 #include "document.hxx"
47 #include "unoguard.hxx"
48 #include "unonames.hxx"
49 #include "styleuno.hxx" // ScStyleNameConversion
50 #include "tokenarray.hxx"
51 #include "tokenuno.hxx"
53 using namespace ::com::sun::star
;
54 using namespace ::formula
;
56 //------------------------------------------------------------------------
58 // Map nur fuer PropertySetInfo
60 const SfxItemPropertyMapEntry
* lcl_GetValidatePropertyMap()
62 static SfxItemPropertyMapEntry aValidatePropertyMap_Impl
[] =
64 {MAP_CHAR_LEN(SC_UNONAME_ERRALSTY
), 0, &getCppuType((sheet::ValidationAlertStyle
*)0), 0, 0},
65 {MAP_CHAR_LEN(SC_UNONAME_ERRMESS
), 0, &getCppuType((rtl::OUString
*)0), 0, 0},
66 {MAP_CHAR_LEN(SC_UNONAME_ERRTITLE
), 0, &getCppuType((rtl::OUString
*)0), 0, 0},
67 {MAP_CHAR_LEN(SC_UNONAME_IGNOREBL
), 0, &getBooleanCppuType(), 0, 0},
68 {MAP_CHAR_LEN(SC_UNONAME_INPMESS
), 0, &getCppuType((rtl::OUString
*)0), 0, 0},
69 {MAP_CHAR_LEN(SC_UNONAME_INPTITLE
), 0, &getCppuType((rtl::OUString
*)0), 0, 0},
70 {MAP_CHAR_LEN(SC_UNONAME_SHOWERR
), 0, &getBooleanCppuType(), 0, 0},
71 {MAP_CHAR_LEN(SC_UNONAME_SHOWINP
), 0, &getBooleanCppuType(), 0, 0},
72 {MAP_CHAR_LEN(SC_UNONAME_SHOWLIST
), 0, &getCppuType((sal_Int16
*)0), 0, 0},
73 {MAP_CHAR_LEN(SC_UNONAME_TYPE
), 0, &getCppuType((sheet::ValidationType
*)0), 0, 0},
76 return aValidatePropertyMap_Impl
;
79 //------------------------------------------------------------------------
81 SC_SIMPLE_SERVICE_INFO( ScTableConditionalEntry
, "ScTableConditionalEntry", "com.sun.star.sheet.TableConditionalEntry" )
82 SC_SIMPLE_SERVICE_INFO( ScTableConditionalFormat
, "ScTableConditionalFormat", "com.sun.star.sheet.TableConditionalFormat" )
83 SC_SIMPLE_SERVICE_INFO( ScTableValidationObj
, "ScTableValidationObj", "com.sun.star.sheet.TableValidation" )
85 //------------------------------------------------------------------------
87 sheet::ConditionOperator
lcl_ConditionModeToOperator( ScConditionMode eMode
)
89 sheet::ConditionOperator eOper
= sheet::ConditionOperator_NONE
;
92 case SC_COND_EQUAL
: eOper
= sheet::ConditionOperator_EQUAL
; break;
93 case SC_COND_LESS
: eOper
= sheet::ConditionOperator_LESS
; break;
94 case SC_COND_GREATER
: eOper
= sheet::ConditionOperator_GREATER
; break;
95 case SC_COND_EQLESS
: eOper
= sheet::ConditionOperator_LESS_EQUAL
; break;
96 case SC_COND_EQGREATER
: eOper
= sheet::ConditionOperator_GREATER_EQUAL
; break;
97 case SC_COND_NOTEQUAL
: eOper
= sheet::ConditionOperator_NOT_EQUAL
; break;
98 case SC_COND_BETWEEN
: eOper
= sheet::ConditionOperator_BETWEEN
; break;
99 case SC_COND_NOTBETWEEN
: eOper
= sheet::ConditionOperator_NOT_BETWEEN
; break;
100 case SC_COND_DIRECT
: eOper
= sheet::ConditionOperator_FORMULA
; break;
103 // added to avoid warnings
109 ScConditionMode
lcl_ConditionOperatorToMode( sheet::ConditionOperator eOper
)
111 ScConditionMode eMode
= SC_COND_NONE
;
114 case sheet::ConditionOperator_EQUAL
: eMode
= SC_COND_EQUAL
; break;
115 case sheet::ConditionOperator_LESS
: eMode
= SC_COND_LESS
; break;
116 case sheet::ConditionOperator_GREATER
: eMode
= SC_COND_GREATER
; break;
117 case sheet::ConditionOperator_LESS_EQUAL
: eMode
= SC_COND_EQLESS
; break;
118 case sheet::ConditionOperator_GREATER_EQUAL
: eMode
= SC_COND_EQGREATER
; break;
119 case sheet::ConditionOperator_NOT_EQUAL
: eMode
= SC_COND_NOTEQUAL
; break;
120 case sheet::ConditionOperator_BETWEEN
: eMode
= SC_COND_BETWEEN
; break;
121 case sheet::ConditionOperator_NOT_BETWEEN
: eMode
= SC_COND_NOTBETWEEN
; break;
122 case sheet::ConditionOperator_FORMULA
: eMode
= SC_COND_DIRECT
; break;
125 // added to avoid warnings
131 //------------------------------------------------------------------------
133 ScCondFormatEntryItem::ScCondFormatEntryItem() :
134 meGrammar1( FormulaGrammar::GRAM_UNSPECIFIED
),
135 meGrammar2( FormulaGrammar::GRAM_UNSPECIFIED
),
136 meMode( SC_COND_NONE
)
140 //------------------------------------------------------------------------
142 ScTableConditionalFormat::ScTableConditionalFormat(
143 ScDocument
* pDoc
, ULONG nKey
, FormulaGrammar::Grammar eGrammar
)
145 // Eintrag aus dem Dokument lesen...
149 ScConditionalFormatList
* pList
= pDoc
->GetCondFormList();
152 const ScConditionalFormat
* pFormat
= pList
->GetFormat( nKey
);
155 // During save to XML.
156 if (pDoc
->IsInExternalReferenceMarking())
157 pFormat
->MarkUsedExternalReferences();
159 USHORT nEntryCount
= pFormat
->Count();
160 for (USHORT i
=0; i
<nEntryCount
; i
++)
162 ScCondFormatEntryItem aItem
;
163 const ScCondFormatEntry
* pFormatEntry
= pFormat
->GetEntry(i
);
164 aItem
.meMode
= pFormatEntry
->GetOperation();
165 aItem
.maPos
= pFormatEntry
->GetValidSrcPos();
166 aItem
.maExpr1
= pFormatEntry
->GetExpression(aItem
.maPos
, 0, 0, eGrammar
);
167 aItem
.maExpr2
= pFormatEntry
->GetExpression(aItem
.maPos
, 1, 0, eGrammar
);
168 aItem
.meGrammar1
= aItem
.meGrammar2
= eGrammar
;
169 aItem
.maStyle
= pFormatEntry
->GetStyle();
171 AddEntry_Impl(aItem
);
180 FormulaGrammar::Grammar
lclResolveGrammar( FormulaGrammar::Grammar eExtGrammar
, FormulaGrammar::Grammar eIntGrammar
)
182 if( eExtGrammar
!= FormulaGrammar::GRAM_UNSPECIFIED
)
184 OSL_ENSURE( eIntGrammar
!= FormulaGrammar::GRAM_UNSPECIFIED
, "lclResolveGrammar - unspecified grammar, using GRAM_PODF_A1" );
185 return (eIntGrammar
== FormulaGrammar::GRAM_UNSPECIFIED
) ? FormulaGrammar::GRAM_PODF_A1
: eIntGrammar
;
190 void ScTableConditionalFormat::FillFormat( ScConditionalFormat
& rFormat
,
191 ScDocument
* pDoc
, FormulaGrammar::Grammar eGrammar
) const
193 // ScConditionalFormat = Core-Struktur, muss leer sein
195 DBG_ASSERT( rFormat
.IsEmpty(), "FillFormat: Format nicht leer" );
196 USHORT nCount
= (USHORT
)aEntries
.Count();
197 for (USHORT i
=0; i
<nCount
; i
++)
199 ScTableConditionalEntry
* pEntry
= (ScTableConditionalEntry
*)aEntries
.GetObject(i
);
203 ScCondFormatEntryItem aData
;
204 pEntry
->GetData(aData
);
206 FormulaGrammar::Grammar eGrammar1
= lclResolveGrammar( eGrammar
, aData
.meGrammar1
);
207 FormulaGrammar::Grammar eGrammar2
= lclResolveGrammar( eGrammar
, aData
.meGrammar2
);
209 ScCondFormatEntry
aCoreEntry( aData
.meMode
, aData
.maExpr1
, aData
.maExpr2
,
210 pDoc
, aData
.maPos
, aData
.maStyle
, aData
.maExprNmsp1
, aData
.maExprNmsp2
, eGrammar1
, eGrammar2
);
212 if ( aData
.maPosStr
.Len() )
213 aCoreEntry
.SetSrcString( aData
.maPosStr
);
215 if ( aData
.maTokens1
.getLength() )
217 ScTokenArray aTokenArray
;
218 if ( ScTokenConversion::ConvertToTokenArray(*pDoc
, aTokenArray
, aData
.maTokens1
) )
219 aCoreEntry
.SetFormula1(aTokenArray
);
222 if ( aData
.maTokens2
.getLength() )
224 ScTokenArray aTokenArray
;
225 if ( ScTokenConversion::ConvertToTokenArray(*pDoc
, aTokenArray
, aData
.maTokens2
) )
226 aCoreEntry
.SetFormula2(aTokenArray
);
228 rFormat
.AddEntry( aCoreEntry
);
232 ScTableConditionalFormat::~ScTableConditionalFormat()
234 ScTableConditionalEntry
* pEntry
;
236 while ( ( pEntry
= (ScTableConditionalEntry
*)aEntries
.Remove() ) != NULL
)
240 void ScTableConditionalFormat::AddEntry_Impl(const ScCondFormatEntryItem
& aEntry
)
242 ScTableConditionalEntry
* pNew
= new ScTableConditionalEntry(this, aEntry
);
244 aEntries
.Insert( pNew
, LIST_APPEND
);
247 void ScTableConditionalFormat::DataChanged()
249 // wenn's mal das "lebende Objekt" ist, muss hier was passieren...
252 // XSheetConditionalFormat
254 ScTableConditionalEntry
* ScTableConditionalFormat::GetObjectByIndex_Impl(USHORT nIndex
) const
256 return (ScTableConditionalEntry
*)aEntries
.GetObject(nIndex
);
259 void SAL_CALL
ScTableConditionalFormat::addNew(
260 const uno::Sequence
<beans::PropertyValue
>& aConditionalEntry
)
261 throw(uno::RuntimeException
)
264 ScCondFormatEntryItem aEntry
;
265 aEntry
.meMode
= SC_COND_NONE
;
267 const beans::PropertyValue
* pPropArray
= aConditionalEntry
.getConstArray();
268 long nPropCount
= aConditionalEntry
.getLength();
269 for (long i
= 0; i
< nPropCount
; i
++)
271 const beans::PropertyValue
& rProp
= pPropArray
[i
];
273 if ( rProp
.Name
.equalsAscii( SC_UNONAME_OPERATOR
) )
275 sheet::ConditionOperator eOper
= (sheet::ConditionOperator
)
276 ScUnoHelpFunctions::GetEnumFromAny( rProp
.Value
);
277 aEntry
.meMode
= lcl_ConditionOperatorToMode( eOper
);
279 else if ( rProp
.Name
.equalsAscii( SC_UNONAME_FORMULA1
) )
281 rtl::OUString aStrVal
;
282 uno::Sequence
<sheet::FormulaToken
> aTokens
;
283 if ( rProp
.Value
>>= aStrVal
)
284 aEntry
.maExpr1
= aStrVal
;
285 else if ( rProp
.Value
>>= aTokens
)
287 aEntry
.maExpr1
.Erase();
288 aEntry
.maTokens1
= aTokens
;
291 else if ( rProp
.Name
.equalsAscii( SC_UNONAME_FORMULA2
) )
293 rtl::OUString aStrVal
;
294 uno::Sequence
<sheet::FormulaToken
> aTokens
;
295 if ( rProp
.Value
>>= aStrVal
)
296 aEntry
.maExpr2
= aStrVal
;
297 else if ( rProp
.Value
>>= aTokens
)
299 aEntry
.maExpr2
.Erase();
300 aEntry
.maTokens2
= aTokens
;
303 else if ( rProp
.Name
.equalsAscii( SC_UNONAME_SOURCEPOS
) )
305 table::CellAddress aAddress
;
306 if ( rProp
.Value
>>= aAddress
)
307 aEntry
.maPos
= ScAddress( (SCCOL
)aAddress
.Column
, (SCROW
)aAddress
.Row
, aAddress
.Sheet
);
309 else if ( rProp
.Name
.equalsAscii( SC_UNONAME_SOURCESTR
) )
311 rtl::OUString aStrVal
;
312 if ( rProp
.Value
>>= aStrVal
)
313 aEntry
.maPosStr
= String( aStrVal
);
315 else if ( rProp
.Name
.equalsAscii( SC_UNONAME_STYLENAME
) )
317 rtl::OUString aStrVal
;
318 if ( rProp
.Value
>>= aStrVal
)
319 aEntry
.maStyle
= ScStyleNameConversion::ProgrammaticToDisplayName(
320 aStrVal
, SFX_STYLE_FAMILY_PARA
);
322 else if ( rProp
.Name
.equalsAscii( SC_UNONAME_FORMULANMSP1
) )
324 rtl::OUString aStrVal
;
325 if ( rProp
.Value
>>= aStrVal
)
326 aEntry
.maExprNmsp1
= aStrVal
;
328 else if ( rProp
.Name
.equalsAscii( SC_UNONAME_FORMULANMSP2
) )
330 rtl::OUString aStrVal
;
331 if ( rProp
.Value
>>= aStrVal
)
332 aEntry
.maExprNmsp2
= aStrVal
;
334 else if ( rProp
.Name
.equalsAscii( SC_UNONAME_GRAMMAR1
) )
337 if ( rProp
.Value
>>= nVal
)
338 aEntry
.meGrammar1
= static_cast< FormulaGrammar::Grammar
>( nVal
);
340 else if ( rProp
.Name
.equalsAscii( SC_UNONAME_GRAMMAR2
) )
343 if ( rProp
.Value
>>= nVal
)
344 aEntry
.meGrammar2
= static_cast< FormulaGrammar::Grammar
>( nVal
);
348 DBG_ERROR("falsche Property");
353 AddEntry_Impl(aEntry
);
357 void SAL_CALL
ScTableConditionalFormat::removeByIndex( sal_Int32 nIndex
)
358 throw(uno::RuntimeException
)
361 ScTableConditionalEntry
* pEntry
= (ScTableConditionalEntry
*)aEntries
.GetObject(nIndex
);
364 aEntries
.Remove(pEntry
);
370 void SAL_CALL
ScTableConditionalFormat::clear() throw(uno::RuntimeException
)
373 ScTableConditionalEntry
* pEntry
;
375 while ( ( pEntry
= (ScTableConditionalEntry
*)aEntries
.Remove() ) != NULL
)
381 // XEnumerationAccess
383 uno::Reference
<container::XEnumeration
> SAL_CALL
ScTableConditionalFormat::createEnumeration()
384 throw(uno::RuntimeException
)
387 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.TableConditionalEntryEnumeration")));
392 sal_Int32 SAL_CALL
ScTableConditionalFormat::getCount() throw(uno::RuntimeException
)
395 return aEntries
.Count();
398 uno::Any SAL_CALL
ScTableConditionalFormat::getByIndex( sal_Int32 nIndex
)
399 throw(lang::IndexOutOfBoundsException
,
400 lang::WrappedTargetException
, uno::RuntimeException
)
403 uno::Reference
<sheet::XSheetConditionalEntry
> xEntry(GetObjectByIndex_Impl((USHORT
)nIndex
));
405 return uno::makeAny(xEntry
);
407 throw lang::IndexOutOfBoundsException();
408 // return uno::Any();
411 uno::Type SAL_CALL
ScTableConditionalFormat::getElementType() throw(uno::RuntimeException
)
414 return getCppuType((uno::Reference
<sheet::XSheetConditionalEntry
>*)0);
417 sal_Bool SAL_CALL
ScTableConditionalFormat::hasElements() throw(uno::RuntimeException
)
420 return ( getCount() != 0 );
423 // conditional format entries have no real names
424 // -> generate name from index
426 rtl::OUString
lcl_GetEntryNameFromIndex( sal_Int32 nIndex
)
428 rtl::OUString
aRet( RTL_CONSTASCII_USTRINGPARAM( "Entry" ) );
429 aRet
+= rtl::OUString::valueOf( nIndex
);
433 uno::Any SAL_CALL
ScTableConditionalFormat::getByName( const rtl::OUString
& aName
)
434 throw(container::NoSuchElementException
,
435 lang::WrappedTargetException
, uno::RuntimeException
)
439 uno::Reference
<sheet::XSheetConditionalEntry
> xEntry
;
440 long nCount
= aEntries
.Count();
441 for (long i
=0; i
<nCount
; i
++)
442 if ( aName
== lcl_GetEntryNameFromIndex(i
) )
444 xEntry
.set(GetObjectByIndex_Impl((USHORT
)i
));
449 return uno::makeAny(xEntry
);
451 throw container::NoSuchElementException();
452 // return uno::Any();
455 uno::Sequence
<rtl::OUString
> SAL_CALL
ScTableConditionalFormat::getElementNames()
456 throw(uno::RuntimeException
)
460 long nCount
= aEntries
.Count();
461 uno::Sequence
<rtl::OUString
> aNames(nCount
);
462 rtl::OUString
* pArray
= aNames
.getArray();
463 for (long i
=0; i
<nCount
; i
++)
464 pArray
[i
] = lcl_GetEntryNameFromIndex(i
);
469 sal_Bool SAL_CALL
ScTableConditionalFormat::hasByName( const rtl::OUString
& aName
)
470 throw(uno::RuntimeException
)
474 long nCount
= aEntries
.Count();
475 for (long i
=0; i
<nCount
; i
++)
476 if ( aName
== lcl_GetEntryNameFromIndex(i
) )
484 sal_Int64 SAL_CALL
ScTableConditionalFormat::getSomething(
485 const uno::Sequence
<sal_Int8
>& rId
) throw(uno::RuntimeException
)
487 if ( rId
.getLength() == 16 &&
488 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
489 rId
.getConstArray(), 16 ) )
491 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_IntPtr
>(this));
497 const uno::Sequence
<sal_Int8
>& ScTableConditionalFormat::getUnoTunnelId()
499 static uno::Sequence
<sal_Int8
> * pSeq
= 0;
502 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
505 static uno::Sequence
< sal_Int8
> aSeq( 16 );
506 rtl_createUuid( (sal_uInt8
*)aSeq
.getArray(), 0, sal_True
);
514 ScTableConditionalFormat
* ScTableConditionalFormat::getImplementation(
515 const uno::Reference
<sheet::XSheetConditionalEntries
> xObj
)
517 ScTableConditionalFormat
* pRet
= NULL
;
518 uno::Reference
<lang::XUnoTunnel
> xUT( xObj
, uno::UNO_QUERY
);
520 pRet
= reinterpret_cast<ScTableConditionalFormat
*>(sal::static_int_cast
<sal_IntPtr
>(xUT
->getSomething(getUnoTunnelId())));
524 //------------------------------------------------------------------------
526 //UNUSED2008-05 ScTableConditionalEntry::ScTableConditionalEntry() :
527 //UNUSED2008-05 pParent( NULL )
531 ScTableConditionalEntry::ScTableConditionalEntry(ScTableConditionalFormat
* pPar
,
532 const ScCondFormatEntryItem
& aItem
) :
540 ScTableConditionalEntry::~ScTableConditionalEntry()
546 void ScTableConditionalEntry::GetData(ScCondFormatEntryItem
& rData
) const
553 sheet::ConditionOperator SAL_CALL
ScTableConditionalEntry::getOperator()
554 throw(uno::RuntimeException
)
557 return lcl_ConditionModeToOperator( aData
.meMode
);
560 void SAL_CALL
ScTableConditionalEntry::setOperator( sheet::ConditionOperator nOperator
)
561 throw(uno::RuntimeException
)
564 aData
.meMode
= lcl_ConditionOperatorToMode( nOperator
);
566 pParent
->DataChanged();
569 rtl::OUString SAL_CALL
ScTableConditionalEntry::getFormula1() throw(uno::RuntimeException
)
572 return aData
.maExpr1
;
575 void SAL_CALL
ScTableConditionalEntry::setFormula1( const rtl::OUString
& aFormula1
)
576 throw(uno::RuntimeException
)
579 aData
.maExpr1
= String( aFormula1
);
581 pParent
->DataChanged();
584 rtl::OUString SAL_CALL
ScTableConditionalEntry::getFormula2() throw(uno::RuntimeException
)
587 return aData
.maExpr2
;
590 void SAL_CALL
ScTableConditionalEntry::setFormula2( const rtl::OUString
& aFormula2
)
591 throw(uno::RuntimeException
)
594 aData
.maExpr2
= String( aFormula2
);
596 pParent
->DataChanged();
599 table::CellAddress SAL_CALL
ScTableConditionalEntry::getSourcePosition() throw(uno::RuntimeException
)
602 table::CellAddress aRet
;
603 aRet
.Column
= aData
.maPos
.Col();
604 aRet
.Row
= aData
.maPos
.Row();
605 aRet
.Sheet
= aData
.maPos
.Tab();
609 void SAL_CALL
ScTableConditionalEntry::setSourcePosition( const table::CellAddress
& aSourcePosition
)
610 throw(uno::RuntimeException
)
613 aData
.maPos
.Set( (SCCOL
)aSourcePosition
.Column
, (SCROW
)aSourcePosition
.Row
, aSourcePosition
.Sheet
);
615 pParent
->DataChanged();
618 // XSheetConditionalEntry
620 rtl::OUString SAL_CALL
ScTableConditionalEntry::getStyleName() throw(uno::RuntimeException
)
623 return ScStyleNameConversion::DisplayToProgrammaticName( aData
.maStyle
, SFX_STYLE_FAMILY_PARA
);
626 void SAL_CALL
ScTableConditionalEntry::setStyleName( const rtl::OUString
& aStyleName
)
627 throw(uno::RuntimeException
)
630 aData
.maStyle
= ScStyleNameConversion::ProgrammaticToDisplayName( aStyleName
, SFX_STYLE_FAMILY_PARA
);
632 pParent
->DataChanged();
635 //------------------------------------------------------------------------
637 ScTableValidationObj::ScTableValidationObj(ScDocument
* pDoc
, ULONG nKey
,
638 const formula::FormulaGrammar::Grammar eGrammar
) :
639 aPropSet( lcl_GetValidatePropertyMap() )
641 // Eintrag aus dem Dokument lesen...
646 const ScValidationData
* pData
= pDoc
->GetValidationEntry( nKey
);
649 nMode
= sal::static_int_cast
<USHORT
>( pData
->GetOperation() );
650 aSrcPos
= pData
->GetValidSrcPos(); // #b4974740# valid pos for expressions
651 aExpr1
= pData
->GetExpression( aSrcPos
, 0, 0, eGrammar
);
652 aExpr2
= pData
->GetExpression( aSrcPos
, 1, 0, eGrammar
);
653 meGrammar1
= meGrammar2
= eGrammar
;
654 nValMode
= sal::static_int_cast
<USHORT
>( pData
->GetDataMode() );
655 bIgnoreBlank
= pData
->IsIgnoreBlank();
656 nShowList
= pData
->GetListType();
657 bShowInput
= pData
->GetInput( aInputTitle
, aInputMessage
);
658 ScValidErrorStyle eStyle
;
659 bShowError
= pData
->GetErrMsg( aErrorTitle
, aErrorMessage
, eStyle
);
660 nErrorStyle
= sal::static_int_cast
<USHORT
>( eStyle
);
662 // During save to XML, sheet::ValidationType_ANY formulas are not
663 // saved, even if in the list, see
664 // ScMyValidationsContainer::GetCondition(), so shall not mark
666 if (nValMode
!= SC_VALID_ANY
&& pDoc
->IsInExternalReferenceMarking())
667 pData
->MarkUsedExternalReferences();
673 ClearData_Impl(); // Defaults
676 ScValidationData
* ScTableValidationObj::CreateValidationData( ScDocument
* pDoc
,
677 formula::FormulaGrammar::Grammar eGrammar
) const
679 // ScValidationData = Core-Struktur
681 FormulaGrammar::Grammar eGrammar1
= lclResolveGrammar( eGrammar
, meGrammar1
);
682 FormulaGrammar::Grammar eGrammar2
= lclResolveGrammar( eGrammar
, meGrammar2
);
684 ScValidationData
* pRet
= new ScValidationData( (ScValidationMode
)nValMode
,
685 (ScConditionMode
)nMode
,
686 aExpr1
, aExpr2
, pDoc
, aSrcPos
,
687 maExprNmsp1
, maExprNmsp2
,
688 eGrammar1
, eGrammar2
);
689 pRet
->SetIgnoreBlank(bIgnoreBlank
);
690 pRet
->SetListType(nShowList
);
692 if ( aTokens1
.getLength() )
694 ScTokenArray aTokenArray
;
695 if ( ScTokenConversion::ConvertToTokenArray(*pDoc
, aTokenArray
, aTokens1
) )
696 pRet
->SetFormula1(aTokenArray
);
699 if ( aTokens2
.getLength() )
701 ScTokenArray aTokenArray
;
702 if ( ScTokenConversion::ConvertToTokenArray(*pDoc
, aTokenArray
, aTokens2
) )
703 pRet
->SetFormula2(aTokenArray
);
706 // set strings for error / input even if disabled (and disable afterwards)
707 pRet
->SetInput( aInputTitle
, aInputMessage
);
710 pRet
->SetError( aErrorTitle
, aErrorMessage
, (ScValidErrorStyle
)nErrorStyle
);
714 if ( aPosString
.Len() )
715 pRet
->SetSrcString( aPosString
);
720 void ScTableValidationObj::ClearData_Impl()
722 nMode
= SC_COND_NONE
;
723 nValMode
= SC_VALID_ANY
;
725 nShowList
= sheet::TableValidationVisibility::UNSORTED
;
728 nErrorStyle
= SC_VALERR_STOP
;
734 meGrammar1
= meGrammar2
= FormulaGrammar::GRAM_UNSPECIFIED
; // will be overriden when needed
736 aInputMessage
.Erase();
738 aErrorMessage
.Erase();
741 ScTableValidationObj::~ScTableValidationObj()
745 void ScTableValidationObj::DataChanged()
747 // wenn's mal das "lebende Objekt" ist, muss hier was passieren...
752 sheet::ConditionOperator SAL_CALL
ScTableValidationObj::getOperator()
753 throw(uno::RuntimeException
)
756 return lcl_ConditionModeToOperator( (ScConditionMode
)nMode
);
759 void SAL_CALL
ScTableValidationObj::setOperator( sheet::ConditionOperator nOperator
)
760 throw(uno::RuntimeException
)
763 nMode
= sal::static_int_cast
<USHORT
>( lcl_ConditionOperatorToMode( nOperator
) );
767 rtl::OUString SAL_CALL
ScTableValidationObj::getFormula1() throw(uno::RuntimeException
)
773 void SAL_CALL
ScTableValidationObj::setFormula1( const rtl::OUString
& aFormula1
)
774 throw(uno::RuntimeException
)
777 aExpr1
= String( aFormula1
);
781 rtl::OUString SAL_CALL
ScTableValidationObj::getFormula2() throw(uno::RuntimeException
)
787 void SAL_CALL
ScTableValidationObj::setFormula2( const rtl::OUString
& aFormula2
)
788 throw(uno::RuntimeException
)
791 aExpr2
= String( aFormula2
);
795 table::CellAddress SAL_CALL
ScTableValidationObj::getSourcePosition() throw(uno::RuntimeException
)
798 table::CellAddress aRet
;
799 aRet
.Column
= aSrcPos
.Col();
800 aRet
.Row
= aSrcPos
.Row();
801 aRet
.Sheet
= aSrcPos
.Tab();
805 void SAL_CALL
ScTableValidationObj::setSourcePosition( const table::CellAddress
& aSourcePosition
)
806 throw(uno::RuntimeException
)
809 aSrcPos
.Set( (SCCOL
)aSourcePosition
.Column
, (SCROW
)aSourcePosition
.Row
, aSourcePosition
.Sheet
);
813 uno::Sequence
<sheet::FormulaToken
> SAL_CALL
ScTableValidationObj::getTokens( sal_Int32 nIndex
)
814 throw(uno::RuntimeException
,lang::IndexOutOfBoundsException
)
817 if (nIndex
>= 2 || nIndex
< 0)
818 throw lang::IndexOutOfBoundsException();
820 return nIndex
== 0 ? aTokens1
: aTokens2
;
823 void SAL_CALL
ScTableValidationObj::setTokens( sal_Int32 nIndex
, const uno::Sequence
<sheet::FormulaToken
>& aTokens
)
824 throw(uno::RuntimeException
,lang::IndexOutOfBoundsException
)
827 if (nIndex
>= 2 || nIndex
< 0)
828 throw lang::IndexOutOfBoundsException();
835 else if (nIndex
== 1)
842 sal_Int32 SAL_CALL
ScTableValidationObj::getCount() throw(uno::RuntimeException
)
847 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
ScTableValidationObj::getPropertySetInfo()
848 throw(uno::RuntimeException
)
851 static uno::Reference
<beans::XPropertySetInfo
> aRef(
852 new SfxItemPropertySetInfo( aPropSet
.getPropertyMap() ));
856 void SAL_CALL
ScTableValidationObj::setPropertyValue(
857 const rtl::OUString
& aPropertyName
, const uno::Any
& aValue
)
858 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
859 lang::IllegalArgumentException
, lang::WrappedTargetException
,
860 uno::RuntimeException
)
863 String
aString(aPropertyName
);
865 if ( aString
.EqualsAscii( SC_UNONAME_SHOWINP
) ) bShowInput
= ScUnoHelpFunctions::GetBoolFromAny( aValue
);
866 else if ( aString
.EqualsAscii( SC_UNONAME_SHOWERR
) ) bShowError
= ScUnoHelpFunctions::GetBoolFromAny( aValue
);
867 else if ( aString
.EqualsAscii( SC_UNONAME_IGNOREBL
) ) bIgnoreBlank
= ScUnoHelpFunctions::GetBoolFromAny( aValue
);
868 else if ( aString
.EqualsAscii( SC_UNONAME_SHOWLIST
) ) aValue
>>= nShowList
;
869 else if ( aString
.EqualsAscii( SC_UNONAME_INPTITLE
) )
871 rtl::OUString aStrVal
;
872 if ( aValue
>>= aStrVal
)
873 aInputTitle
= String( aStrVal
);
875 else if ( aString
.EqualsAscii( SC_UNONAME_INPMESS
) )
877 rtl::OUString aStrVal
;
878 if ( aValue
>>= aStrVal
)
879 aInputMessage
= String( aStrVal
);
881 else if ( aString
.EqualsAscii( SC_UNONAME_ERRTITLE
) )
883 rtl::OUString aStrVal
;
884 if ( aValue
>>= aStrVal
)
885 aErrorTitle
= String( aStrVal
);
887 else if ( aString
.EqualsAscii( SC_UNONAME_ERRMESS
) )
889 rtl::OUString aStrVal
;
890 if ( aValue
>>= aStrVal
)
891 aErrorMessage
= String( aStrVal
);
893 else if ( aString
.EqualsAscii( SC_UNONAME_TYPE
) )
895 sheet::ValidationType eType
= (sheet::ValidationType
)
896 ScUnoHelpFunctions::GetEnumFromAny( aValue
);
899 case sheet::ValidationType_ANY
: nValMode
= SC_VALID_ANY
; break;
900 case sheet::ValidationType_WHOLE
: nValMode
= SC_VALID_WHOLE
; break;
901 case sheet::ValidationType_DECIMAL
: nValMode
= SC_VALID_DECIMAL
; break;
902 case sheet::ValidationType_DATE
: nValMode
= SC_VALID_DATE
; break;
903 case sheet::ValidationType_TIME
: nValMode
= SC_VALID_TIME
; break;
904 case sheet::ValidationType_TEXT_LEN
: nValMode
= SC_VALID_TEXTLEN
; break;
905 case sheet::ValidationType_LIST
: nValMode
= SC_VALID_LIST
; break;
906 case sheet::ValidationType_CUSTOM
: nValMode
= SC_VALID_CUSTOM
; break;
909 // added to avoid warnings
913 else if ( aString
.EqualsAscii( SC_UNONAME_ERRALSTY
) )
915 sheet::ValidationAlertStyle eStyle
= (sheet::ValidationAlertStyle
)
916 ScUnoHelpFunctions::GetEnumFromAny( aValue
);
919 case sheet::ValidationAlertStyle_STOP
: nErrorStyle
= SC_VALERR_STOP
; break;
920 case sheet::ValidationAlertStyle_WARNING
: nErrorStyle
= SC_VALERR_WARNING
; break;
921 case sheet::ValidationAlertStyle_INFO
: nErrorStyle
= SC_VALERR_INFO
; break;
922 case sheet::ValidationAlertStyle_MACRO
: nErrorStyle
= SC_VALERR_MACRO
; break;
925 // added to avoid warnings
929 else if ( aString
.EqualsAscii( SC_UNONAME_SOURCESTR
) )
931 // internal - only for XML filter, not in PropertySetInfo, only set
933 rtl::OUString aStrVal
;
934 if ( aValue
>>= aStrVal
)
935 aPosString
= String( aStrVal
);
937 else if ( aString
.EqualsAscii( SC_UNONAME_FORMULANMSP1
) )
939 // internal - only for XML filter, not in PropertySetInfo, only set
941 rtl::OUString aStrVal
;
942 if ( aValue
>>= aStrVal
)
943 maExprNmsp1
= aStrVal
;
945 else if ( aString
.EqualsAscii( SC_UNONAME_FORMULANMSP2
) )
947 // internal - only for XML filter, not in PropertySetInfo, only set
949 rtl::OUString aStrVal
;
950 if ( aValue
>>= aStrVal
)
951 maExprNmsp2
= aStrVal
;
953 else if ( aString
.EqualsAscii( SC_UNONAME_GRAMMAR1
) )
955 // internal - only for XML filter, not in PropertySetInfo, only set
958 if ( aValue
>>= nVal
)
959 meGrammar1
= static_cast< FormulaGrammar::Grammar
>(nVal
);
961 else if ( aString
.EqualsAscii( SC_UNONAME_GRAMMAR2
) )
963 // internal - only for XML filter, not in PropertySetInfo, only set
966 if ( aValue
>>= nVal
)
967 meGrammar2
= static_cast< FormulaGrammar::Grammar
>(nVal
);
973 uno::Any SAL_CALL
ScTableValidationObj::getPropertyValue( const rtl::OUString
& aPropertyName
)
974 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
975 uno::RuntimeException
)
978 String
aString(aPropertyName
);
981 if ( aString
.EqualsAscii( SC_UNONAME_SHOWINP
) ) ScUnoHelpFunctions::SetBoolInAny( aRet
, bShowInput
);
982 else if ( aString
.EqualsAscii( SC_UNONAME_SHOWERR
) ) ScUnoHelpFunctions::SetBoolInAny( aRet
, bShowError
);
983 else if ( aString
.EqualsAscii( SC_UNONAME_IGNOREBL
) ) ScUnoHelpFunctions::SetBoolInAny( aRet
, bIgnoreBlank
);
984 else if ( aString
.EqualsAscii( SC_UNONAME_SHOWLIST
) ) aRet
<<= nShowList
;
985 else if ( aString
.EqualsAscii( SC_UNONAME_INPTITLE
) ) aRet
<<= rtl::OUString( aInputTitle
);
986 else if ( aString
.EqualsAscii( SC_UNONAME_INPMESS
) ) aRet
<<= rtl::OUString( aInputMessage
);
987 else if ( aString
.EqualsAscii( SC_UNONAME_ERRTITLE
) ) aRet
<<= rtl::OUString( aErrorTitle
);
988 else if ( aString
.EqualsAscii( SC_UNONAME_ERRMESS
) ) aRet
<<= rtl::OUString( aErrorMessage
);
989 else if ( aString
.EqualsAscii( SC_UNONAME_TYPE
) )
991 sheet::ValidationType eType
= sheet::ValidationType_ANY
;
994 case SC_VALID_ANY
: eType
= sheet::ValidationType_ANY
; break;
995 case SC_VALID_WHOLE
: eType
= sheet::ValidationType_WHOLE
; break;
996 case SC_VALID_DECIMAL
: eType
= sheet::ValidationType_DECIMAL
; break;
997 case SC_VALID_DATE
: eType
= sheet::ValidationType_DATE
; break;
998 case SC_VALID_TIME
: eType
= sheet::ValidationType_TIME
; break;
999 case SC_VALID_TEXTLEN
: eType
= sheet::ValidationType_TEXT_LEN
; break;
1000 case SC_VALID_LIST
: eType
= sheet::ValidationType_LIST
; break;
1001 case SC_VALID_CUSTOM
: eType
= sheet::ValidationType_CUSTOM
; break;
1005 else if ( aString
.EqualsAscii( SC_UNONAME_ERRALSTY
) )
1007 sheet::ValidationAlertStyle eStyle
= sheet::ValidationAlertStyle_STOP
;
1008 switch (nErrorStyle
)
1010 case SC_VALERR_STOP
: eStyle
= sheet::ValidationAlertStyle_STOP
; break;
1011 case SC_VALERR_WARNING
: eStyle
= sheet::ValidationAlertStyle_WARNING
; break;
1012 case SC_VALERR_INFO
: eStyle
= sheet::ValidationAlertStyle_INFO
; break;
1013 case SC_VALERR_MACRO
: eStyle
= sheet::ValidationAlertStyle_MACRO
; break;
1021 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableValidationObj
)
1025 sal_Int64 SAL_CALL
ScTableValidationObj::getSomething(
1026 const uno::Sequence
<sal_Int8
>& rId
) throw(uno::RuntimeException
)
1028 if ( rId
.getLength() == 16 &&
1029 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
1030 rId
.getConstArray(), 16 ) )
1032 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_IntPtr
>(this));
1038 const uno::Sequence
<sal_Int8
>& ScTableValidationObj::getUnoTunnelId()
1040 static uno::Sequence
<sal_Int8
> * pSeq
= 0;
1043 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
1046 static uno::Sequence
< sal_Int8
> aSeq( 16 );
1047 rtl_createUuid( (sal_uInt8
*)aSeq
.getArray(), 0, sal_True
);
1055 ScTableValidationObj
* ScTableValidationObj::getImplementation(
1056 const uno::Reference
<beans::XPropertySet
> xObj
)
1058 ScTableValidationObj
* pRet
= NULL
;
1059 uno::Reference
<lang::XUnoTunnel
> xUT( xObj
, uno::UNO_QUERY
);
1061 pRet
= reinterpret_cast<ScTableValidationObj
*>(sal::static_int_cast
<sal_IntPtr
>(xUT
->getSomething(getUnoTunnelId())));
1065 //------------------------------------------------------------------------