tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / unoobj / fmtuno.cxx
blobdeaf80656f3efd68c16390ec911d754914676561
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <o3tl/safeint.hxx>
23 #include <osl/diagnose.h>
24 #include <svl/style.hxx>
25 #include <utility>
26 #include <vcl/svapp.hxx>
27 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
28 #include <com/sun/star/sheet/ConditionOperator2.hpp>
29 #include <com/sun/star/sheet/ValidationAlertStyle.hpp>
30 #include <com/sun/star/sheet/ValidationType.hpp>
31 #include <com/sun/star/sheet/TableValidationVisibility.hpp>
33 #include <fmtuno.hxx>
34 #include <miscuno.hxx>
35 #include <validat.hxx>
36 #include <document.hxx>
37 #include <unonames.hxx>
38 #include <tokenarray.hxx>
39 #include <tokenuno.hxx>
40 #include <stylehelper.hxx>
42 using namespace ::com::sun::star;
43 using namespace ::formula;
45 // map only for PropertySetInfo
47 static std::span<const SfxItemPropertyMapEntry> lcl_GetValidatePropertyMap()
49 static const SfxItemPropertyMapEntry aValidatePropertyMap_Impl[] =
51 { SC_UNONAME_ERRALSTY, 0, cppu::UnoType<sheet::ValidationAlertStyle>::get(), 0, 0},
52 { SC_UNONAME_ERRMESS, 0, cppu::UnoType<OUString>::get(), 0, 0},
53 { SC_UNONAME_ERRTITLE, 0, cppu::UnoType<OUString>::get(), 0, 0},
54 { SC_UNONAME_IGNOREBL, 0, cppu::UnoType<bool>::get(), 0, 0},
55 { SC_UNONAME_ISCASE, 0, cppu::UnoType<bool>::get(), 0, 0},
56 { SC_UNONAME_INPMESS, 0, cppu::UnoType<OUString>::get(), 0, 0},
57 { SC_UNONAME_INPTITLE, 0, cppu::UnoType<OUString>::get(), 0, 0},
58 { SC_UNONAME_SHOWERR, 0, cppu::UnoType<bool>::get(), 0, 0},
59 { SC_UNONAME_SHOWINP, 0, cppu::UnoType<bool>::get(), 0, 0},
60 { SC_UNONAME_SHOWLIST, 0, cppu::UnoType<sal_Int16>::get(), 0, 0},
61 { SC_UNONAME_TYPE, 0, cppu::UnoType<sheet::ValidationType>::get(), 0, 0},
63 return aValidatePropertyMap_Impl;
66 SC_SIMPLE_SERVICE_INFO( ScTableConditionalEntry, u"ScTableConditionalEntry"_ustr, u"com.sun.star.sheet.TableConditionalEntry"_ustr )
67 SC_SIMPLE_SERVICE_INFO( ScTableConditionalFormat, u"ScTableConditionalFormat"_ustr, u"com.sun.star.sheet.TableConditionalFormat"_ustr )
68 SC_SIMPLE_SERVICE_INFO( ScTableValidationObj, u"ScTableValidationObj"_ustr, u"com.sun.star.sheet.TableValidation"_ustr )
70 static sal_Int32 lcl_ConditionModeToOperatorNew( ScConditionMode eMode )
72 sal_Int32 eOper = sheet::ConditionOperator2::NONE;
73 switch (eMode)
75 case ScConditionMode::Equal: eOper = sheet::ConditionOperator2::EQUAL; break;
76 case ScConditionMode::Less: eOper = sheet::ConditionOperator2::LESS; break;
77 case ScConditionMode::Greater: eOper = sheet::ConditionOperator2::GREATER; break;
78 case ScConditionMode::EqLess: eOper = sheet::ConditionOperator2::LESS_EQUAL; break;
79 case ScConditionMode::EqGreater: eOper = sheet::ConditionOperator2::GREATER_EQUAL; break;
80 case ScConditionMode::NotEqual: eOper = sheet::ConditionOperator2::NOT_EQUAL; break;
81 case ScConditionMode::Between: eOper = sheet::ConditionOperator2::BETWEEN; break;
82 case ScConditionMode::NotBetween: eOper = sheet::ConditionOperator2::NOT_BETWEEN; break;
83 case ScConditionMode::Direct: eOper = sheet::ConditionOperator2::FORMULA; break;
84 case ScConditionMode::Duplicate: eOper = sheet::ConditionOperator2::DUPLICATE; break;
85 default:
87 // added to avoid warnings
90 return eOper;
93 static sheet::ConditionOperator lcl_ConditionModeToOperator( ScConditionMode eMode )
95 sheet::ConditionOperator eOper = sheet::ConditionOperator_NONE;
96 switch (eMode)
98 case ScConditionMode::Equal: eOper = sheet::ConditionOperator_EQUAL; break;
99 case ScConditionMode::Less: eOper = sheet::ConditionOperator_LESS; break;
100 case ScConditionMode::Greater: eOper = sheet::ConditionOperator_GREATER; break;
101 case ScConditionMode::EqLess: eOper = sheet::ConditionOperator_LESS_EQUAL; break;
102 case ScConditionMode::EqGreater: eOper = sheet::ConditionOperator_GREATER_EQUAL; break;
103 case ScConditionMode::NotEqual: eOper = sheet::ConditionOperator_NOT_EQUAL; break;
104 case ScConditionMode::Between: eOper = sheet::ConditionOperator_BETWEEN; break;
105 case ScConditionMode::NotBetween: eOper = sheet::ConditionOperator_NOT_BETWEEN; break;
106 case ScConditionMode::Direct: eOper = sheet::ConditionOperator_FORMULA; break;
107 default:
109 // added to avoid warnings
112 return eOper;
115 static ScConditionMode lcl_ConditionOperatorToMode( sheet::ConditionOperator eOper )
117 ScConditionMode eMode = ScConditionMode::NONE;
118 switch (eOper)
120 case sheet::ConditionOperator_EQUAL: eMode = ScConditionMode::Equal; break;
121 case sheet::ConditionOperator_LESS: eMode = ScConditionMode::Less; break;
122 case sheet::ConditionOperator_GREATER: eMode = ScConditionMode::Greater; break;
123 case sheet::ConditionOperator_LESS_EQUAL: eMode = ScConditionMode::EqLess; break;
124 case sheet::ConditionOperator_GREATER_EQUAL: eMode = ScConditionMode::EqGreater; break;
125 case sheet::ConditionOperator_NOT_EQUAL: eMode = ScConditionMode::NotEqual; break;
126 case sheet::ConditionOperator_BETWEEN: eMode = ScConditionMode::Between; break;
127 case sheet::ConditionOperator_NOT_BETWEEN: eMode = ScConditionMode::NotBetween; break;
128 case sheet::ConditionOperator_FORMULA: eMode = ScConditionMode::Direct; break;
129 default:
131 // added to avoid warnings
134 return eMode;
137 ScCondFormatEntryItem::ScCondFormatEntryItem() :
138 meGrammar1( FormulaGrammar::GRAM_UNSPECIFIED ),
139 meGrammar2( FormulaGrammar::GRAM_UNSPECIFIED ),
140 meMode( ScConditionMode::NONE )
144 ScTableConditionalFormat::ScTableConditionalFormat(
145 const ScDocument* pDoc, sal_uLong nKey, SCTAB nTab, FormulaGrammar::Grammar eGrammar)
147 // read the entry from the document...
149 if ( !(pDoc && nKey) )
150 return;
152 ScConditionalFormatList* pList = pDoc->GetCondFormList(nTab);
153 if (!pList)
154 return;
156 const ScConditionalFormat* pFormat = pList->GetFormat( nKey );
157 if (!pFormat)
158 return;
160 // During save to XML.
161 if (pDoc->IsInExternalReferenceMarking())
162 pFormat->MarkUsedExternalReferences();
164 size_t nEntryCount = pFormat->size();
165 for (size_t i=0; i<nEntryCount; i++)
167 ScCondFormatEntryItem aItem;
168 const ScFormatEntry* pFrmtEntry = pFormat->GetEntry(i);
169 if(pFrmtEntry->GetType() != ScFormatEntry::Type::Condition &&
170 pFrmtEntry->GetType() != ScFormatEntry::Type::ExtCondition)
171 continue;
173 const ScCondFormatEntry* pFormatEntry = static_cast<const ScCondFormatEntry*>(pFrmtEntry);
174 aItem.meMode = pFormatEntry->GetOperation();
175 aItem.maPos = pFormatEntry->GetValidSrcPos();
176 aItem.maExpr1 = pFormatEntry->GetExpression(aItem.maPos, 0, 0, eGrammar);
177 aItem.maExpr2 = pFormatEntry->GetExpression(aItem.maPos, 1, 0, eGrammar);
178 aItem.meGrammar1 = aItem.meGrammar2 = eGrammar;
179 aItem.maStyle = pFormatEntry->GetStyle();
181 AddEntry_Impl(aItem);
185 namespace {
187 FormulaGrammar::Grammar lclResolveGrammar( FormulaGrammar::Grammar eExtGrammar, FormulaGrammar::Grammar eIntGrammar )
189 if( eExtGrammar != FormulaGrammar::GRAM_UNSPECIFIED )
190 return eExtGrammar;
191 OSL_ENSURE( eIntGrammar != FormulaGrammar::GRAM_UNSPECIFIED, "lclResolveGrammar - unspecified grammar, using GRAM_API" );
192 return (eIntGrammar == FormulaGrammar::GRAM_UNSPECIFIED) ? FormulaGrammar::GRAM_API : eIntGrammar;
195 } // namespace
197 void ScTableConditionalFormat::FillFormat( ScConditionalFormat& rFormat,
198 ScDocument& rDoc, FormulaGrammar::Grammar eGrammar) const
200 // ScConditionalFormat = Core-Struktur, has to be empty
202 OSL_ENSURE( rFormat.IsEmpty(), "FillFormat: format not empty" );
204 for (const auto & i : maEntries)
206 ScCondFormatEntryItem aData;
207 i->GetData(aData);
209 FormulaGrammar::Grammar eGrammar1 = lclResolveGrammar( eGrammar, aData.meGrammar1 );
210 FormulaGrammar::Grammar eGrammar2 = lclResolveGrammar( eGrammar, aData.meGrammar2 );
212 ScCondFormatEntry* pCoreEntry = new ScCondFormatEntry( aData.meMode, aData.maExpr1, aData.maExpr2,
213 rDoc, aData.maPos, aData.maStyle, aData.maExprNmsp1, aData.maExprNmsp2, eGrammar1, eGrammar2 );
215 if ( !aData.maPosStr.isEmpty() )
216 pCoreEntry->SetSrcString( aData.maPosStr );
218 if ( aData.maTokens1.hasElements() )
220 ScTokenArray aTokenArray(rDoc);
221 if ( ScTokenConversion::ConvertToTokenArray(rDoc, aTokenArray, aData.maTokens1) )
222 pCoreEntry->SetFormula1(aTokenArray);
225 if ( aData.maTokens2.hasElements() )
227 ScTokenArray aTokenArray(rDoc);
228 if ( ScTokenConversion::ConvertToTokenArray(rDoc, aTokenArray, aData.maTokens2) )
229 pCoreEntry->SetFormula2(aTokenArray);
231 rFormat.AddEntry( pCoreEntry );
235 ScTableConditionalFormat::~ScTableConditionalFormat()
239 void ScTableConditionalFormat::AddEntry_Impl(const ScCondFormatEntryItem& aEntry)
241 rtl::Reference<ScTableConditionalEntry> pNew = new ScTableConditionalEntry(aEntry);
242 maEntries.emplace_back(pNew);
245 // XSheetConditionalFormat
247 ScTableConditionalEntry* ScTableConditionalFormat::GetObjectByIndex_Impl(sal_uInt16 nIndex) const
249 return nIndex < maEntries.size() ? maEntries[nIndex].get() : nullptr;
252 void SAL_CALL ScTableConditionalFormat::addNew(
253 const uno::Sequence<beans::PropertyValue >& aConditionalEntry )
255 SolarMutexGuard aGuard;
256 ScCondFormatEntryItem aEntry;
257 aEntry.meMode = ScConditionMode::NONE;
259 for (const beans::PropertyValue& rProp : aConditionalEntry)
261 if ( rProp.Name == SC_UNONAME_OPERATOR )
263 sal_Int32 eOper = ScUnoHelpFunctions::GetEnumFromAny( rProp.Value );
264 aEntry.meMode = ScConditionEntry::GetModeFromApi( static_cast<sheet::ConditionOperator>(eOper) );
266 else if ( rProp.Name == SC_UNONAME_FORMULA1 )
268 OUString aStrVal;
269 uno::Sequence<sheet::FormulaToken> aTokens;
270 if ( rProp.Value >>= aStrVal )
271 aEntry.maExpr1 = aStrVal;
272 else if ( rProp.Value >>= aTokens )
274 aEntry.maExpr1.clear();
275 aEntry.maTokens1 = std::move(aTokens);
278 else if ( rProp.Name == SC_UNONAME_FORMULA2 )
280 OUString aStrVal;
281 uno::Sequence<sheet::FormulaToken> aTokens;
282 if ( rProp.Value >>= aStrVal )
283 aEntry.maExpr2 = aStrVal;
284 else if ( rProp.Value >>= aTokens )
286 aEntry.maExpr2.clear();
287 aEntry.maTokens2 = std::move(aTokens);
290 else if ( rProp.Name == SC_UNONAME_SOURCEPOS )
292 table::CellAddress aAddress;
293 if ( rProp.Value >>= aAddress )
294 aEntry.maPos = ScAddress( static_cast<SCCOL>(aAddress.Column), static_cast<SCROW>(aAddress.Row), aAddress.Sheet );
296 else if ( rProp.Name == SC_UNONAME_SOURCESTR )
298 OUString aStrVal;
299 if ( rProp.Value >>= aStrVal )
300 aEntry.maPosStr = aStrVal;
302 else if ( rProp.Name == SC_UNONAME_STYLENAME )
304 OUString aStrVal;
305 if ( rProp.Value >>= aStrVal )
306 aEntry.maStyle = ScStyleNameConversion::ProgrammaticToDisplayName(
307 aStrVal, SfxStyleFamily::Para );
309 else if ( rProp.Name == SC_UNONAME_FORMULANMSP1 )
311 OUString aStrVal;
312 if ( rProp.Value >>= aStrVal )
313 aEntry.maExprNmsp1 = aStrVal;
315 else if ( rProp.Name == SC_UNONAME_FORMULANMSP2 )
317 OUString aStrVal;
318 if ( rProp.Value >>= aStrVal )
319 aEntry.maExprNmsp2 = aStrVal;
321 else if ( rProp.Name == SC_UNONAME_GRAMMAR1 )
323 sal_Int32 nVal = 0;
324 if ( rProp.Value >>= nVal )
325 aEntry.meGrammar1 = static_cast< FormulaGrammar::Grammar >( nVal );
327 else if ( rProp.Name == SC_UNONAME_GRAMMAR2 )
329 sal_Int32 nVal = 0;
330 if ( rProp.Value >>= nVal )
331 aEntry.meGrammar2 = static_cast< FormulaGrammar::Grammar >( nVal );
333 else
335 OSL_FAIL("wrong property");
336 //! Exception...
340 AddEntry_Impl(aEntry);
343 void SAL_CALL ScTableConditionalFormat::removeByIndex( sal_Int32 nIndex )
345 SolarMutexGuard aGuard;
347 if (nIndex >= 0 && o3tl::make_unsigned(nIndex) < maEntries.size())
349 maEntries.erase(maEntries.begin()+nIndex);
353 void SAL_CALL ScTableConditionalFormat::clear()
355 SolarMutexGuard aGuard;
356 maEntries.clear();
359 // XEnumerationAccess
361 uno::Reference<container::XEnumeration> SAL_CALL ScTableConditionalFormat::createEnumeration()
363 SolarMutexGuard aGuard;
364 return new ScIndexEnumeration(this, u"com.sun.star.sheet.TableConditionalEntryEnumeration"_ustr);
367 // XIndexAccess
369 sal_Int32 SAL_CALL ScTableConditionalFormat::getCount()
371 SolarMutexGuard aGuard;
372 return maEntries.size();
375 uno::Any SAL_CALL ScTableConditionalFormat::getByIndex( sal_Int32 nIndex )
377 SolarMutexGuard aGuard;
378 uno::Reference<sheet::XSheetConditionalEntry> xEntry(GetObjectByIndex_Impl(static_cast<sal_uInt16>(nIndex)));
379 if (!xEntry.is())
380 throw lang::IndexOutOfBoundsException();
382 return uno::Any(xEntry);
385 uno::Type SAL_CALL ScTableConditionalFormat::getElementType()
387 return cppu::UnoType<sheet::XSheetConditionalEntry>::get();
390 sal_Bool SAL_CALL ScTableConditionalFormat::hasElements()
392 SolarMutexGuard aGuard;
393 return ( getCount() != 0 );
396 // conditional format entries have no real names
397 // -> generate name from index
399 static OUString lcl_GetEntryNameFromIndex( sal_Int32 nIndex )
401 OUString aRet = "Entry" + OUString::number( nIndex );
402 return aRet;
405 uno::Any SAL_CALL ScTableConditionalFormat::getByName( const OUString& aName )
407 SolarMutexGuard aGuard;
409 uno::Reference<sheet::XSheetConditionalEntry> xEntry;
410 tools::Long nCount = maEntries.size();
411 for (tools::Long i=0; i<nCount; i++)
412 if ( aName == lcl_GetEntryNameFromIndex(i) )
414 xEntry.set(GetObjectByIndex_Impl(static_cast<sal_uInt16>(i)));
415 break;
418 if (!xEntry.is())
419 throw container::NoSuchElementException();
421 return uno::Any(xEntry);
424 uno::Sequence<OUString> SAL_CALL ScTableConditionalFormat::getElementNames()
426 SolarMutexGuard aGuard;
428 tools::Long nCount = maEntries.size();
429 uno::Sequence<OUString> aNames(nCount);
430 OUString* pArray = aNames.getArray();
431 for (tools::Long i=0; i<nCount; i++)
432 pArray[i] = lcl_GetEntryNameFromIndex(i);
434 return aNames;
437 sal_Bool SAL_CALL ScTableConditionalFormat::hasByName( const OUString& aName )
439 SolarMutexGuard aGuard;
441 tools::Long nCount = maEntries.size();
442 for (tools::Long i=0; i<nCount; i++)
443 if ( aName == lcl_GetEntryNameFromIndex(i) )
444 return true;
446 return false;
449 ScTableConditionalEntry::ScTableConditionalEntry(ScCondFormatEntryItem aItem) :
450 aData(std::move( aItem ))
452 // #i113668# only store the settings, keep no reference to parent object
455 ScTableConditionalEntry::~ScTableConditionalEntry()
459 void ScTableConditionalEntry::GetData(ScCondFormatEntryItem& rData) const
461 rData = aData;
464 // XSheetCondition
466 sheet::ConditionOperator SAL_CALL ScTableConditionalEntry::getOperator()
468 SolarMutexGuard aGuard;
469 return lcl_ConditionModeToOperator( aData.meMode );
472 void SAL_CALL ScTableConditionalEntry::setOperator( sheet::ConditionOperator nOperator )
474 SolarMutexGuard aGuard;
475 aData.meMode = lcl_ConditionOperatorToMode( nOperator );
478 sal_Int32 SAL_CALL ScTableConditionalEntry::getConditionOperator()
480 SolarMutexGuard aGuard;
481 return lcl_ConditionModeToOperatorNew( aData.meMode );
484 void SAL_CALL ScTableConditionalEntry::setConditionOperator( sal_Int32 nOperator )
486 SolarMutexGuard aGuard;
487 aData.meMode = ScConditionEntry::GetModeFromApi( static_cast<sheet::ConditionOperator>(nOperator) );
490 OUString SAL_CALL ScTableConditionalEntry::getFormula1()
492 SolarMutexGuard aGuard;
493 return aData.maExpr1;
496 void SAL_CALL ScTableConditionalEntry::setFormula1( const OUString& aFormula1 )
498 SolarMutexGuard aGuard;
499 aData.maExpr1 = aFormula1;
502 OUString SAL_CALL ScTableConditionalEntry::getFormula2()
504 SolarMutexGuard aGuard;
505 return aData.maExpr2;
508 void SAL_CALL ScTableConditionalEntry::setFormula2( const OUString& aFormula2 )
510 SolarMutexGuard aGuard;
511 aData.maExpr2 = aFormula2;
514 table::CellAddress SAL_CALL ScTableConditionalEntry::getSourcePosition()
516 SolarMutexGuard aGuard;
517 table::CellAddress aRet;
518 aRet.Column = aData.maPos.Col();
519 aRet.Row = aData.maPos.Row();
520 aRet.Sheet = aData.maPos.Tab();
521 return aRet;
524 void SAL_CALL ScTableConditionalEntry::setSourcePosition( const table::CellAddress& aSourcePosition )
526 SolarMutexGuard aGuard;
527 aData.maPos.Set( static_cast<SCCOL>(aSourcePosition.Column), static_cast<SCROW>(aSourcePosition.Row), aSourcePosition.Sheet );
530 // XSheetConditionalEntry
532 OUString SAL_CALL ScTableConditionalEntry::getStyleName()
534 SolarMutexGuard aGuard;
535 return ScStyleNameConversion::DisplayToProgrammaticName( aData.maStyle, SfxStyleFamily::Para );
538 void SAL_CALL ScTableConditionalEntry::setStyleName( const OUString& aStyleName )
540 SolarMutexGuard aGuard;
541 aData.maStyle = ScStyleNameConversion::ProgrammaticToDisplayName( aStyleName, SfxStyleFamily::Para );
544 ScTableValidationObj::ScTableValidationObj(const ScDocument& rDoc, sal_uInt32 nKey,
545 const formula::FormulaGrammar::Grammar eGrammar) :
546 aPropSet( lcl_GetValidatePropertyMap() )
548 // read the entry from the document...
550 bool bFound = false;
551 if (nKey)
553 const ScValidationData* pData = rDoc.GetValidationEntry( nKey );
554 if (pData)
556 nMode = pData->GetOperation();
557 aSrcPos = pData->GetValidSrcPos(); // valid pos for expressions
558 aExpr1 = pData->GetExpression( aSrcPos, 0, 0, eGrammar );
559 aExpr2 = pData->GetExpression( aSrcPos, 1, 0, eGrammar );
560 meGrammar1 = meGrammar2 = eGrammar;
561 nValMode = sal::static_int_cast<sal_uInt16>( pData->GetDataMode() );
562 bIgnoreBlank = pData->IsIgnoreBlank();
563 bCaseSensitive = pData->IsCaseSensitive();
564 nShowList = pData->GetListType();
565 bShowInput = pData->GetInput( aInputTitle, aInputMessage );
566 ScValidErrorStyle eStyle;
567 bShowError = pData->GetErrMsg( aErrorTitle, aErrorMessage, eStyle );
568 nErrorStyle = sal::static_int_cast<sal_uInt16>( eStyle );
570 // During save to XML, sheet::ValidationType_ANY formulas are not
571 // saved, even if in the list, see
572 // ScMyValidationsContainer::GetCondition(), so shall not mark
573 // anything in use.
574 if (nValMode != SC_VALID_ANY && rDoc.IsInExternalReferenceMarking())
575 pData->MarkUsedExternalReferences();
577 bFound = true;
580 if (!bFound)
581 ClearData_Impl(); // Defaults
584 ScValidationData* ScTableValidationObj::CreateValidationData( ScDocument& rDoc,
585 formula::FormulaGrammar::Grammar eGrammar ) const
587 // ScValidationData = Core-Struktur
589 FormulaGrammar::Grammar eGrammar1 = lclResolveGrammar( eGrammar, meGrammar1 );
590 FormulaGrammar::Grammar eGrammar2 = lclResolveGrammar( eGrammar, meGrammar2 );
592 ScValidationData* pRet = new ScValidationData( static_cast<ScValidationMode>(nValMode),
593 nMode,
594 aExpr1, aExpr2, rDoc, aSrcPos,
595 maExprNmsp1, maExprNmsp2,
596 eGrammar1, eGrammar2 );
597 pRet->SetIgnoreBlank(bIgnoreBlank);
598 pRet->SetCaseSensitive(bCaseSensitive);
599 pRet->SetListType(nShowList);
601 if ( aTokens1.hasElements() )
603 ScTokenArray aTokenArray(rDoc);
604 if ( ScTokenConversion::ConvertToTokenArray(rDoc, aTokenArray, aTokens1) )
605 pRet->SetFormula1(aTokenArray);
608 if ( aTokens2.hasElements() )
610 ScTokenArray aTokenArray(rDoc);
611 if ( ScTokenConversion::ConvertToTokenArray(rDoc, aTokenArray, aTokens2) )
612 pRet->SetFormula2(aTokenArray);
615 // set strings for error / input even if disabled (and disable afterwards)
616 pRet->SetInput( aInputTitle, aInputMessage );
617 if (!bShowInput)
618 pRet->ResetInput();
619 pRet->SetError( aErrorTitle, aErrorMessage, static_cast<ScValidErrorStyle>(nErrorStyle) );
620 if (!bShowError)
621 pRet->ResetError();
623 if ( !aPosString.isEmpty() )
624 pRet->SetSrcString( aPosString );
626 return pRet;
629 void ScTableValidationObj::ClearData_Impl()
631 nMode = ScConditionMode::NONE;
632 nValMode = SC_VALID_ANY;
633 bIgnoreBlank = true;
634 bCaseSensitive = false;
635 nShowList = sheet::TableValidationVisibility::UNSORTED;
636 bShowInput = false;
637 bShowError = false;
638 nErrorStyle = SC_VALERR_STOP;
639 aSrcPos.Set(0,0,0);
640 aExpr1.clear();
641 aExpr2.clear();
642 maExprNmsp1.clear();
643 maExprNmsp2.clear();
644 meGrammar1 = meGrammar2 = FormulaGrammar::GRAM_UNSPECIFIED; // will be overridden when needed
645 aInputTitle.clear();
646 aInputMessage.clear();
647 aErrorTitle.clear();
648 aErrorMessage.clear();
651 ScTableValidationObj::~ScTableValidationObj()
655 // XSheetCondition
657 sheet::ConditionOperator SAL_CALL ScTableValidationObj::getOperator()
659 SolarMutexGuard aGuard;
660 return lcl_ConditionModeToOperator( nMode );
663 void SAL_CALL ScTableValidationObj::setOperator( sheet::ConditionOperator nOperator )
665 SolarMutexGuard aGuard;
666 nMode = lcl_ConditionOperatorToMode( nOperator );
669 sal_Int32 SAL_CALL ScTableValidationObj::getConditionOperator()
671 SolarMutexGuard aGuard;
672 return lcl_ConditionModeToOperatorNew( nMode );
675 void SAL_CALL ScTableValidationObj::setConditionOperator( sal_Int32 nOperator )
677 SolarMutexGuard aGuard;
678 nMode = ScConditionEntry::GetModeFromApi( static_cast<css::sheet::ConditionOperator>(nOperator) );
681 OUString SAL_CALL ScTableValidationObj::getFormula1()
683 SolarMutexGuard aGuard;
684 return aExpr1;
687 void SAL_CALL ScTableValidationObj::setFormula1( const OUString& aFormula1 )
689 SolarMutexGuard aGuard;
690 aExpr1 = aFormula1;
693 OUString SAL_CALL ScTableValidationObj::getFormula2()
695 SolarMutexGuard aGuard;
696 return aExpr2;
699 void SAL_CALL ScTableValidationObj::setFormula2( const OUString& aFormula2 )
701 SolarMutexGuard aGuard;
702 aExpr2 = aFormula2;
705 table::CellAddress SAL_CALL ScTableValidationObj::getSourcePosition()
707 SolarMutexGuard aGuard;
708 table::CellAddress aRet;
709 aRet.Column = aSrcPos.Col();
710 aRet.Row = aSrcPos.Row();
711 aRet.Sheet = aSrcPos.Tab();
712 return aRet;
715 void SAL_CALL ScTableValidationObj::setSourcePosition( const table::CellAddress& aSourcePosition )
717 SolarMutexGuard aGuard;
718 aSrcPos.Set( static_cast<SCCOL>(aSourcePosition.Column), static_cast<SCROW>(aSourcePosition.Row), aSourcePosition.Sheet );
721 uno::Sequence<sheet::FormulaToken> SAL_CALL ScTableValidationObj::getTokens( sal_Int32 nIndex )
723 SolarMutexGuard aGuard;
724 if (nIndex >= 2 || nIndex < 0)
725 throw lang::IndexOutOfBoundsException();
727 return nIndex == 0 ? aTokens1 : aTokens2;
730 void SAL_CALL ScTableValidationObj::setTokens( sal_Int32 nIndex, const uno::Sequence<sheet::FormulaToken>& aTokens )
732 SolarMutexGuard aGuard;
733 if (nIndex >= 2 || nIndex < 0)
734 throw lang::IndexOutOfBoundsException();
736 if (nIndex == 0)
738 aTokens1 = aTokens;
739 aExpr1.clear();
741 else if (nIndex == 1)
743 aTokens2 = aTokens;
744 aExpr2.clear();
748 sal_Int32 SAL_CALL ScTableValidationObj::getCount()
750 return 2;
753 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableValidationObj::getPropertySetInfo()
755 SolarMutexGuard aGuard;
756 static uno::Reference<beans::XPropertySetInfo> aRef(
757 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
758 return aRef;
761 void SAL_CALL ScTableValidationObj::setPropertyValue(
762 const OUString& aPropertyName, const uno::Any& aValue )
764 SolarMutexGuard aGuard;
766 if ( aPropertyName == SC_UNONAME_SHOWINP ) bShowInput = ScUnoHelpFunctions::GetBoolFromAny( aValue );
767 else if ( aPropertyName == SC_UNONAME_SHOWERR ) bShowError = ScUnoHelpFunctions::GetBoolFromAny( aValue );
768 else if ( aPropertyName == SC_UNONAME_IGNOREBL ) bIgnoreBlank = ScUnoHelpFunctions::GetBoolFromAny( aValue );
769 else if ( aPropertyName == SC_UNONAME_ISCASE ) bCaseSensitive = ScUnoHelpFunctions::GetBoolFromAny( aValue );
770 else if ( aPropertyName == SC_UNONAME_SHOWLIST ) aValue >>= nShowList;
771 else if ( aPropertyName == SC_UNONAME_INPTITLE )
773 OUString aStrVal;
774 if ( aValue >>= aStrVal )
775 aInputTitle = aStrVal;
777 else if ( aPropertyName == SC_UNONAME_INPMESS )
779 OUString aStrVal;
780 if ( aValue >>= aStrVal )
781 aInputMessage = aStrVal;
783 else if ( aPropertyName == SC_UNONAME_ERRTITLE )
785 OUString aStrVal;
786 if ( aValue >>= aStrVal )
787 aErrorTitle = aStrVal;
789 else if ( aPropertyName == SC_UNONAME_ERRMESS )
791 OUString aStrVal;
792 if ( aValue >>= aStrVal )
793 aErrorMessage = aStrVal;
795 else if ( aPropertyName == SC_UNONAME_TYPE )
797 sheet::ValidationType eType = static_cast<sheet::ValidationType>(ScUnoHelpFunctions::GetEnumFromAny( aValue ));
798 switch (eType)
800 case sheet::ValidationType_ANY: nValMode = SC_VALID_ANY; break;
801 case sheet::ValidationType_WHOLE: nValMode = SC_VALID_WHOLE; break;
802 case sheet::ValidationType_DECIMAL: nValMode = SC_VALID_DECIMAL; break;
803 case sheet::ValidationType_DATE: nValMode = SC_VALID_DATE; break;
804 case sheet::ValidationType_TIME: nValMode = SC_VALID_TIME; break;
805 case sheet::ValidationType_TEXT_LEN: nValMode = SC_VALID_TEXTLEN; break;
806 case sheet::ValidationType_LIST: nValMode = SC_VALID_LIST; break;
807 case sheet::ValidationType_CUSTOM: nValMode = SC_VALID_CUSTOM; break;
808 default:
810 // added to avoid warnings
814 else if ( aPropertyName == SC_UNONAME_ERRALSTY )
816 sheet::ValidationAlertStyle eStyle = static_cast<sheet::ValidationAlertStyle>(ScUnoHelpFunctions::GetEnumFromAny( aValue ));
817 switch (eStyle)
819 case sheet::ValidationAlertStyle_STOP: nErrorStyle = SC_VALERR_STOP; break;
820 case sheet::ValidationAlertStyle_WARNING: nErrorStyle = SC_VALERR_WARNING; break;
821 case sheet::ValidationAlertStyle_INFO: nErrorStyle = SC_VALERR_INFO; break;
822 case sheet::ValidationAlertStyle_MACRO: nErrorStyle = SC_VALERR_MACRO; break;
823 default:
825 // added to avoid warnings
829 else if ( aPropertyName == SC_UNONAME_SOURCESTR )
831 // internal - only for XML filter, not in PropertySetInfo, only set
833 OUString aStrVal;
834 if ( aValue >>= aStrVal )
835 aPosString = aStrVal;
837 else if ( aPropertyName == SC_UNONAME_FORMULANMSP1 )
839 // internal - only for XML filter, not in PropertySetInfo, only set
841 OUString aStrVal;
842 if ( aValue >>= aStrVal )
843 maExprNmsp1 = aStrVal;
845 else if ( aPropertyName == SC_UNONAME_FORMULANMSP2 )
847 // internal - only for XML filter, not in PropertySetInfo, only set
849 OUString aStrVal;
850 if ( aValue >>= aStrVal )
851 maExprNmsp2 = aStrVal;
853 else if ( aPropertyName == SC_UNONAME_GRAMMAR1 )
855 // internal - only for XML filter, not in PropertySetInfo, only set
857 sal_Int32 nVal = 0;
858 if ( aValue >>= nVal )
859 meGrammar1 = static_cast< FormulaGrammar::Grammar >(nVal);
861 else if ( aPropertyName == SC_UNONAME_GRAMMAR2 )
863 // internal - only for XML filter, not in PropertySetInfo, only set
865 sal_Int32 nVal = 0;
866 if ( aValue >>= nVal )
867 meGrammar2 = static_cast< FormulaGrammar::Grammar >(nVal);
871 uno::Any SAL_CALL ScTableValidationObj::getPropertyValue( const OUString& aPropertyName )
873 SolarMutexGuard aGuard;
874 uno::Any aRet;
876 if ( aPropertyName == SC_UNONAME_SHOWINP ) aRet <<= bShowInput;
877 else if ( aPropertyName == SC_UNONAME_SHOWERR ) aRet <<= bShowError;
878 else if ( aPropertyName == SC_UNONAME_IGNOREBL ) aRet <<= bIgnoreBlank;
879 else if ( aPropertyName == SC_UNONAME_ISCASE ) aRet <<= bCaseSensitive;
880 else if ( aPropertyName == SC_UNONAME_SHOWLIST ) aRet <<= nShowList;
881 else if ( aPropertyName == SC_UNONAME_INPTITLE ) aRet <<= aInputTitle;
882 else if ( aPropertyName == SC_UNONAME_INPMESS ) aRet <<= aInputMessage;
883 else if ( aPropertyName == SC_UNONAME_ERRTITLE ) aRet <<= aErrorTitle;
884 else if ( aPropertyName == SC_UNONAME_ERRMESS ) aRet <<= aErrorMessage;
885 else if ( aPropertyName == SC_UNONAME_TYPE )
887 sheet::ValidationType eType = sheet::ValidationType_ANY;
888 switch (nValMode)
890 case SC_VALID_ANY: eType = sheet::ValidationType_ANY; break;
891 case SC_VALID_WHOLE: eType = sheet::ValidationType_WHOLE; break;
892 case SC_VALID_DECIMAL: eType = sheet::ValidationType_DECIMAL; break;
893 case SC_VALID_DATE: eType = sheet::ValidationType_DATE; break;
894 case SC_VALID_TIME: eType = sheet::ValidationType_TIME; break;
895 case SC_VALID_TEXTLEN: eType = sheet::ValidationType_TEXT_LEN; break;
896 case SC_VALID_LIST: eType = sheet::ValidationType_LIST; break;
897 case SC_VALID_CUSTOM: eType = sheet::ValidationType_CUSTOM; break;
899 aRet <<= eType;
901 else if ( aPropertyName == SC_UNONAME_ERRALSTY )
903 sheet::ValidationAlertStyle eStyle = sheet::ValidationAlertStyle_STOP;
904 switch (nErrorStyle)
906 case SC_VALERR_STOP: eStyle = sheet::ValidationAlertStyle_STOP; break;
907 case SC_VALERR_WARNING: eStyle = sheet::ValidationAlertStyle_WARNING; break;
908 case SC_VALERR_INFO: eStyle = sheet::ValidationAlertStyle_INFO; break;
909 case SC_VALERR_MACRO: eStyle = sheet::ValidationAlertStyle_MACRO; break;
911 aRet <<= eStyle;
914 return aRet;
917 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableValidationObj )
919 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */