LibreOffice Module sc (master) 1
fmtuno.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
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>
32
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>
41
42using namespace ::com::sun::star;
43using namespace ::formula;
44
45// map only for PropertySetInfo
46
48{
49 static const SfxItemPropertyMapEntry aValidatePropertyMap_Impl[] =
50 {
61 };
62 return aValidatePropertyMap_Impl;
63}
64
65SC_SIMPLE_SERVICE_INFO( ScTableConditionalEntry, "ScTableConditionalEntry", "com.sun.star.sheet.TableConditionalEntry" )
66SC_SIMPLE_SERVICE_INFO( ScTableConditionalFormat, "ScTableConditionalFormat", "com.sun.star.sheet.TableConditionalFormat" )
67SC_SIMPLE_SERVICE_INFO( ScTableValidationObj, "ScTableValidationObj", "com.sun.star.sheet.TableValidation" )
68
70{
71 sal_Int32 eOper = sheet::ConditionOperator2::NONE;
72 switch (eMode)
73 {
74 case ScConditionMode::Equal: eOper = sheet::ConditionOperator2::EQUAL; break;
75 case ScConditionMode::Less: eOper = sheet::ConditionOperator2::LESS; break;
76 case ScConditionMode::Greater: eOper = sheet::ConditionOperator2::GREATER; break;
77 case ScConditionMode::EqLess: eOper = sheet::ConditionOperator2::LESS_EQUAL; break;
78 case ScConditionMode::EqGreater: eOper = sheet::ConditionOperator2::GREATER_EQUAL; break;
79 case ScConditionMode::NotEqual: eOper = sheet::ConditionOperator2::NOT_EQUAL; break;
80 case ScConditionMode::Between: eOper = sheet::ConditionOperator2::BETWEEN; break;
81 case ScConditionMode::NotBetween: eOper = sheet::ConditionOperator2::NOT_BETWEEN; break;
83 case ScConditionMode::Duplicate: eOper = sheet::ConditionOperator2::DUPLICATE; break;
84 default:
85 {
86 // added to avoid warnings
87 }
88 }
89 return eOper;
90}
91
92static sheet::ConditionOperator lcl_ConditionModeToOperator( ScConditionMode eMode )
93{
94 sheet::ConditionOperator eOper = sheet::ConditionOperator_NONE;
95 switch (eMode)
96 {
97 case ScConditionMode::Equal: eOper = sheet::ConditionOperator_EQUAL; break;
98 case ScConditionMode::Less: eOper = sheet::ConditionOperator_LESS; break;
99 case ScConditionMode::Greater: eOper = sheet::ConditionOperator_GREATER; break;
100 case ScConditionMode::EqLess: eOper = sheet::ConditionOperator_LESS_EQUAL; break;
101 case ScConditionMode::EqGreater: eOper = sheet::ConditionOperator_GREATER_EQUAL; break;
102 case ScConditionMode::NotEqual: eOper = sheet::ConditionOperator_NOT_EQUAL; break;
103 case ScConditionMode::Between: eOper = sheet::ConditionOperator_BETWEEN; break;
104 case ScConditionMode::NotBetween: eOper = sheet::ConditionOperator_NOT_BETWEEN; break;
105 case ScConditionMode::Direct: eOper = sheet::ConditionOperator_FORMULA; break;
106 default:
107 {
108 // added to avoid warnings
109 }
110 }
111 return eOper;
112}
113
114static ScConditionMode lcl_ConditionOperatorToMode( sheet::ConditionOperator eOper )
115{
117 switch (eOper)
118 {
119 case sheet::ConditionOperator_EQUAL: eMode = ScConditionMode::Equal; break;
120 case sheet::ConditionOperator_LESS: eMode = ScConditionMode::Less; break;
121 case sheet::ConditionOperator_GREATER: eMode = ScConditionMode::Greater; break;
122 case sheet::ConditionOperator_LESS_EQUAL: eMode = ScConditionMode::EqLess; break;
123 case sheet::ConditionOperator_GREATER_EQUAL: eMode = ScConditionMode::EqGreater; break;
124 case sheet::ConditionOperator_NOT_EQUAL: eMode = ScConditionMode::NotEqual; break;
125 case sheet::ConditionOperator_BETWEEN: eMode = ScConditionMode::Between; break;
126 case sheet::ConditionOperator_NOT_BETWEEN: eMode = ScConditionMode::NotBetween; break;
127 case sheet::ConditionOperator_FORMULA: eMode = ScConditionMode::Direct; break;
128 default:
129 {
130 // added to avoid warnings
131 }
132 }
133 return eMode;
134}
135
137 meGrammar1( FormulaGrammar::GRAM_UNSPECIFIED ),
138 meGrammar2( FormulaGrammar::GRAM_UNSPECIFIED ),
140{
141}
142
144 const ScDocument* pDoc, sal_uLong nKey, SCTAB nTab, FormulaGrammar::Grammar eGrammar)
145{
146 // read the entry from the document...
147
148 if ( !(pDoc && nKey) )
149 return;
150
151 ScConditionalFormatList* pList = pDoc->GetCondFormList(nTab);
152 if (!pList)
153 return;
154
155 const ScConditionalFormat* pFormat = pList->GetFormat( nKey );
156 if (!pFormat)
157 return;
158
159 // During save to XML.
162
163 size_t nEntryCount = pFormat->size();
164 for (size_t i=0; i<nEntryCount; i++)
165 {
167 const ScFormatEntry* pFrmtEntry = pFormat->GetEntry(i);
168 if(pFrmtEntry->GetType() != ScFormatEntry::Type::Condition &&
170 continue;
171
172 const ScCondFormatEntry* pFormatEntry = static_cast<const ScCondFormatEntry*>(pFrmtEntry);
173 aItem.meMode = pFormatEntry->GetOperation();
174 aItem.maPos = pFormatEntry->GetValidSrcPos();
175 aItem.maExpr1 = pFormatEntry->GetExpression(aItem.maPos, 0, 0, eGrammar);
176 aItem.maExpr2 = pFormatEntry->GetExpression(aItem.maPos, 1, 0, eGrammar);
177 aItem.meGrammar1 = aItem.meGrammar2 = eGrammar;
178 aItem.maStyle = pFormatEntry->GetStyle();
179
180 AddEntry_Impl(aItem);
181 }
182}
183
184namespace {
185
186FormulaGrammar::Grammar lclResolveGrammar( FormulaGrammar::Grammar eExtGrammar, FormulaGrammar::Grammar eIntGrammar )
187{
188 if( eExtGrammar != FormulaGrammar::GRAM_UNSPECIFIED )
189 return eExtGrammar;
190 OSL_ENSURE( eIntGrammar != FormulaGrammar::GRAM_UNSPECIFIED, "lclResolveGrammar - unspecified grammar, using GRAM_API" );
191 return (eIntGrammar == FormulaGrammar::GRAM_UNSPECIFIED) ? FormulaGrammar::GRAM_API : eIntGrammar;
192}
193
194} // namespace
195
197 ScDocument& rDoc, FormulaGrammar::Grammar eGrammar) const
198{
199 // ScConditionalFormat = Core-Struktur, has to be empty
200
201 OSL_ENSURE( rFormat.IsEmpty(), "FillFormat: format not empty" );
202
203 for (const auto & i : maEntries)
204 {
206 i->GetData(aData);
207
208 FormulaGrammar::Grammar eGrammar1 = lclResolveGrammar( eGrammar, aData.meGrammar1 );
209 FormulaGrammar::Grammar eGrammar2 = lclResolveGrammar( eGrammar, aData.meGrammar2 );
210
211 ScCondFormatEntry* pCoreEntry = new ScCondFormatEntry( aData.meMode, aData.maExpr1, aData.maExpr2,
212 rDoc, aData.maPos, aData.maStyle, aData.maExprNmsp1, aData.maExprNmsp2, eGrammar1, eGrammar2 );
213
214 if ( !aData.maPosStr.isEmpty() )
215 pCoreEntry->SetSrcString( aData.maPosStr );
216
217 if ( aData.maTokens1.hasElements() )
218 {
219 ScTokenArray aTokenArray(rDoc);
220 if ( ScTokenConversion::ConvertToTokenArray(rDoc, aTokenArray, aData.maTokens1) )
221 pCoreEntry->SetFormula1(aTokenArray);
222 }
223
224 if ( aData.maTokens2.hasElements() )
225 {
226 ScTokenArray aTokenArray(rDoc);
227 if ( ScTokenConversion::ConvertToTokenArray(rDoc, aTokenArray, aData.maTokens2) )
228 pCoreEntry->SetFormula2(aTokenArray);
229 }
230 rFormat.AddEntry( pCoreEntry );
231 }
232}
233
235{
236}
237
239{
241 maEntries.emplace_back(pNew);
242}
243
244// XSheetConditionalFormat
245
247{
248 return nIndex < maEntries.size() ? maEntries[nIndex].get() : nullptr;
249}
250
252 const uno::Sequence<beans::PropertyValue >& aConditionalEntry )
253{
254 SolarMutexGuard aGuard;
257
258 for (const beans::PropertyValue& rProp : aConditionalEntry)
259 {
260 if ( rProp.Name == SC_UNONAME_OPERATOR )
261 {
262 sal_Int32 eOper = ScUnoHelpFunctions::GetEnumFromAny( rProp.Value );
263 aEntry.meMode = ScConditionEntry::GetModeFromApi( static_cast<sheet::ConditionOperator>(eOper) );
264 }
265 else if ( rProp.Name == SC_UNONAME_FORMULA1 )
266 {
267 OUString aStrVal;
268 uno::Sequence<sheet::FormulaToken> aTokens;
269 if ( rProp.Value >>= aStrVal )
270 aEntry.maExpr1 = aStrVal;
271 else if ( rProp.Value >>= aTokens )
272 {
273 aEntry.maExpr1.clear();
274 aEntry.maTokens1 = aTokens;
275 }
276 }
277 else if ( rProp.Name == SC_UNONAME_FORMULA2 )
278 {
279 OUString aStrVal;
280 uno::Sequence<sheet::FormulaToken> aTokens;
281 if ( rProp.Value >>= aStrVal )
282 aEntry.maExpr2 = aStrVal;
283 else if ( rProp.Value >>= aTokens )
284 {
285 aEntry.maExpr2.clear();
286 aEntry.maTokens2 = aTokens;
287 }
288 }
289 else if ( rProp.Name == SC_UNONAME_SOURCEPOS )
290 {
291 table::CellAddress aAddress;
292 if ( rProp.Value >>= aAddress )
293 aEntry.maPos = ScAddress( static_cast<SCCOL>(aAddress.Column), static_cast<SCROW>(aAddress.Row), aAddress.Sheet );
294 }
295 else if ( rProp.Name == SC_UNONAME_SOURCESTR )
296 {
297 OUString aStrVal;
298 if ( rProp.Value >>= aStrVal )
299 aEntry.maPosStr = aStrVal;
300 }
301 else if ( rProp.Name == SC_UNONAME_STYLENAME )
302 {
303 OUString aStrVal;
304 if ( rProp.Value >>= aStrVal )
306 aStrVal, SfxStyleFamily::Para );
307 }
308 else if ( rProp.Name == SC_UNONAME_FORMULANMSP1 )
309 {
310 OUString aStrVal;
311 if ( rProp.Value >>= aStrVal )
312 aEntry.maExprNmsp1 = aStrVal;
313 }
314 else if ( rProp.Name == SC_UNONAME_FORMULANMSP2 )
315 {
316 OUString aStrVal;
317 if ( rProp.Value >>= aStrVal )
318 aEntry.maExprNmsp2 = aStrVal;
319 }
320 else if ( rProp.Name == SC_UNONAME_GRAMMAR1 )
321 {
322 sal_Int32 nVal = 0;
323 if ( rProp.Value >>= nVal )
324 aEntry.meGrammar1 = static_cast< FormulaGrammar::Grammar >( nVal );
325 }
326 else if ( rProp.Name == SC_UNONAME_GRAMMAR2 )
327 {
328 sal_Int32 nVal = 0;
329 if ( rProp.Value >>= nVal )
330 aEntry.meGrammar2 = static_cast< FormulaGrammar::Grammar >( nVal );
331 }
332 else
333 {
334 OSL_FAIL("wrong property");
336 }
337 }
338
339 AddEntry_Impl(aEntry);
340}
341
342void SAL_CALL ScTableConditionalFormat::removeByIndex( sal_Int32 nIndex )
343{
344 SolarMutexGuard aGuard;
345
346 if (nIndex >= 0 && o3tl::make_unsigned(nIndex) < maEntries.size())
347 {
348 maEntries.erase(maEntries.begin()+nIndex);
349 }
350}
351
353{
354 SolarMutexGuard aGuard;
355 maEntries.clear();
356}
357
358// XEnumerationAccess
359
360uno::Reference<container::XEnumeration> SAL_CALL ScTableConditionalFormat::createEnumeration()
361{
362 SolarMutexGuard aGuard;
363 return new ScIndexEnumeration(this, "com.sun.star.sheet.TableConditionalEntryEnumeration");
364}
365
366// XIndexAccess
367
369{
370 SolarMutexGuard aGuard;
371 return maEntries.size();
372}
373
375{
376 SolarMutexGuard aGuard;
377 uno::Reference<sheet::XSheetConditionalEntry> xEntry(GetObjectByIndex_Impl(static_cast<sal_uInt16>(nIndex)));
378 if (!xEntry.is())
379 throw lang::IndexOutOfBoundsException();
380
381 return uno::Any(xEntry);
382}
383
385{
387}
388
390{
391 SolarMutexGuard aGuard;
392 return ( getCount() != 0 );
393}
394
395// conditional format entries have no real names
396// -> generate name from index
397
398static OUString lcl_GetEntryNameFromIndex( sal_Int32 nIndex )
399{
400 OUString aRet = "Entry" + OUString::number( nIndex );
401 return aRet;
402}
403
404uno::Any SAL_CALL ScTableConditionalFormat::getByName( const OUString& aName )
405{
406 SolarMutexGuard aGuard;
407
408 uno::Reference<sheet::XSheetConditionalEntry> xEntry;
410 for (tools::Long i=0; i<nCount; i++)
412 {
413 xEntry.set(GetObjectByIndex_Impl(static_cast<sal_uInt16>(i)));
414 break;
415 }
416
417 if (!xEntry.is())
418 throw container::NoSuchElementException();
419
420 return uno::Any(xEntry);
421}
422
423uno::Sequence<OUString> SAL_CALL ScTableConditionalFormat::getElementNames()
424{
425 SolarMutexGuard aGuard;
426
428 uno::Sequence<OUString> aNames(nCount);
429 OUString* pArray = aNames.getArray();
430 for (tools::Long i=0; i<nCount; i++)
431 pArray[i] = lcl_GetEntryNameFromIndex(i);
432
433 return aNames;
434}
435
436sal_Bool SAL_CALL ScTableConditionalFormat::hasByName( const OUString& aName )
437{
438 SolarMutexGuard aGuard;
439
441 for (tools::Long i=0; i<nCount; i++)
443 return true;
444
445 return false;
446}
447
449 aData(std::move( aItem ))
450{
451 // #i113668# only store the settings, keep no reference to parent object
452}
453
455{
456}
457
459{
460 rData = aData;
461}
462
463// XSheetCondition
464
465sheet::ConditionOperator SAL_CALL ScTableConditionalEntry::getOperator()
466{
467 SolarMutexGuard aGuard;
469}
470
471void SAL_CALL ScTableConditionalEntry::setOperator( sheet::ConditionOperator nOperator )
472{
473 SolarMutexGuard aGuard;
475}
476
478{
479 SolarMutexGuard aGuard;
481}
482
483void SAL_CALL ScTableConditionalEntry::setConditionOperator( sal_Int32 nOperator )
484{
485 SolarMutexGuard aGuard;
486 aData.meMode = ScConditionEntry::GetModeFromApi( static_cast<sheet::ConditionOperator>(nOperator) );
487}
488
490{
491 SolarMutexGuard aGuard;
492 return aData.maExpr1;
493}
494
495void SAL_CALL ScTableConditionalEntry::setFormula1( const OUString& aFormula1 )
496{
497 SolarMutexGuard aGuard;
498 aData.maExpr1 = aFormula1;
499}
500
502{
503 SolarMutexGuard aGuard;
504 return aData.maExpr2;
505}
506
507void SAL_CALL ScTableConditionalEntry::setFormula2( const OUString& aFormula2 )
508{
509 SolarMutexGuard aGuard;
510 aData.maExpr2 = aFormula2;
511}
512
514{
515 SolarMutexGuard aGuard;
516 table::CellAddress aRet;
517 aRet.Column = aData.maPos.Col();
518 aRet.Row = aData.maPos.Row();
519 aRet.Sheet = aData.maPos.Tab();
520 return aRet;
521}
522
523void SAL_CALL ScTableConditionalEntry::setSourcePosition( const table::CellAddress& aSourcePosition )
524{
525 SolarMutexGuard aGuard;
526 aData.maPos.Set( static_cast<SCCOL>(aSourcePosition.Column), static_cast<SCROW>(aSourcePosition.Row), aSourcePosition.Sheet );
527}
528
529// XSheetConditionalEntry
530
532{
533 SolarMutexGuard aGuard;
534 return ScStyleNameConversion::DisplayToProgrammaticName( aData.maStyle, SfxStyleFamily::Para );
535}
536
537void SAL_CALL ScTableConditionalEntry::setStyleName( const OUString& aStyleName )
538{
539 SolarMutexGuard aGuard;
540 aData.maStyle = ScStyleNameConversion::ProgrammaticToDisplayName( aStyleName, SfxStyleFamily::Para );
541}
542
544 const formula::FormulaGrammar::Grammar eGrammar) :
545 aPropSet( lcl_GetValidatePropertyMap() )
546{
547 // read the entry from the document...
548
549 bool bFound = false;
550 if (nKey)
551 {
552 const ScValidationData* pData = rDoc.GetValidationEntry( nKey );
553 if (pData)
554 {
555 nMode = pData->GetOperation();
556 aSrcPos = pData->GetValidSrcPos(); // valid pos for expressions
557 aExpr1 = pData->GetExpression( aSrcPos, 0, 0, eGrammar );
558 aExpr2 = pData->GetExpression( aSrcPos, 1, 0, eGrammar );
559 meGrammar1 = meGrammar2 = eGrammar;
560 nValMode = sal::static_int_cast<sal_uInt16>( pData->GetDataMode() );
561 bIgnoreBlank = pData->IsIgnoreBlank();
562 nShowList = pData->GetListType();
564 ScValidErrorStyle eStyle;
565 bShowError = pData->GetErrMsg( aErrorTitle, aErrorMessage, eStyle );
566 nErrorStyle = sal::static_int_cast<sal_uInt16>( eStyle );
567
568 // During save to XML, sheet::ValidationType_ANY formulas are not
569 // saved, even if in the list, see
570 // ScMyValidationsContainer::GetCondition(), so shall not mark
571 // anything in use.
573 pData->MarkUsedExternalReferences();
574
575 bFound = true;
576 }
577 }
578 if (!bFound)
579 ClearData_Impl(); // Defaults
580}
581
583 formula::FormulaGrammar::Grammar eGrammar ) const
584{
585 // ScValidationData = Core-Struktur
586
587 FormulaGrammar::Grammar eGrammar1 = lclResolveGrammar( eGrammar, meGrammar1 );
588 FormulaGrammar::Grammar eGrammar2 = lclResolveGrammar( eGrammar, meGrammar2 );
589
591 nMode,
592 aExpr1, aExpr2, rDoc, aSrcPos,
594 eGrammar1, eGrammar2 );
596 pRet->SetListType(nShowList);
597
598 if ( aTokens1.hasElements() )
599 {
600 ScTokenArray aTokenArray(rDoc);
601 if ( ScTokenConversion::ConvertToTokenArray(rDoc, aTokenArray, aTokens1) )
602 pRet->SetFormula1(aTokenArray);
603 }
604
605 if ( aTokens2.hasElements() )
606 {
607 ScTokenArray aTokenArray(rDoc);
608 if ( ScTokenConversion::ConvertToTokenArray(rDoc, aTokenArray, aTokens2) )
609 pRet->SetFormula2(aTokenArray);
610 }
611
612 // set strings for error / input even if disabled (and disable afterwards)
614 if (!bShowInput)
615 pRet->ResetInput();
617 if (!bShowError)
618 pRet->ResetError();
619
620 if ( !aPosString.isEmpty() )
621 pRet->SetSrcString( aPosString );
622
623 return pRet;
624}
625
627{
630 bIgnoreBlank = true;
631 nShowList = sheet::TableValidationVisibility::UNSORTED;
632 bShowInput = false;
633 bShowError = false;
635 aSrcPos.Set(0,0,0);
636 aExpr1.clear();
637 aExpr2.clear();
638 maExprNmsp1.clear();
639 maExprNmsp2.clear();
640 meGrammar1 = meGrammar2 = FormulaGrammar::GRAM_UNSPECIFIED; // will be overridden when needed
641 aInputTitle.clear();
642 aInputMessage.clear();
643 aErrorTitle.clear();
644 aErrorMessage.clear();
645}
646
648{
649}
650
651// XSheetCondition
652
653sheet::ConditionOperator SAL_CALL ScTableValidationObj::getOperator()
654{
655 SolarMutexGuard aGuard;
657}
658
659void SAL_CALL ScTableValidationObj::setOperator( sheet::ConditionOperator nOperator )
660{
661 SolarMutexGuard aGuard;
662 nMode = lcl_ConditionOperatorToMode( nOperator );
663}
664
666{
667 SolarMutexGuard aGuard;
669}
670
671void SAL_CALL ScTableValidationObj::setConditionOperator( sal_Int32 nOperator )
672{
673 SolarMutexGuard aGuard;
674 nMode = ScConditionEntry::GetModeFromApi( static_cast<css::sheet::ConditionOperator>(nOperator) );
675}
676
678{
679 SolarMutexGuard aGuard;
680 return aExpr1;
681}
682
683void SAL_CALL ScTableValidationObj::setFormula1( const OUString& aFormula1 )
684{
685 SolarMutexGuard aGuard;
686 aExpr1 = aFormula1;
687}
688
690{
691 SolarMutexGuard aGuard;
692 return aExpr2;
693}
694
695void SAL_CALL ScTableValidationObj::setFormula2( const OUString& aFormula2 )
696{
697 SolarMutexGuard aGuard;
698 aExpr2 = aFormula2;
699}
700
701table::CellAddress SAL_CALL ScTableValidationObj::getSourcePosition()
702{
703 SolarMutexGuard aGuard;
704 table::CellAddress aRet;
705 aRet.Column = aSrcPos.Col();
706 aRet.Row = aSrcPos.Row();
707 aRet.Sheet = aSrcPos.Tab();
708 return aRet;
709}
710
711void SAL_CALL ScTableValidationObj::setSourcePosition( const table::CellAddress& aSourcePosition )
712{
713 SolarMutexGuard aGuard;
714 aSrcPos.Set( static_cast<SCCOL>(aSourcePosition.Column), static_cast<SCROW>(aSourcePosition.Row), aSourcePosition.Sheet );
715}
716
717uno::Sequence<sheet::FormulaToken> SAL_CALL ScTableValidationObj::getTokens( sal_Int32 nIndex )
718{
719 SolarMutexGuard aGuard;
720 if (nIndex >= 2 || nIndex < 0)
721 throw lang::IndexOutOfBoundsException();
722
723 return nIndex == 0 ? aTokens1 : aTokens2;
724}
725
726void SAL_CALL ScTableValidationObj::setTokens( sal_Int32 nIndex, const uno::Sequence<sheet::FormulaToken>& aTokens )
727{
728 SolarMutexGuard aGuard;
729 if (nIndex >= 2 || nIndex < 0)
730 throw lang::IndexOutOfBoundsException();
731
732 if (nIndex == 0)
733 {
734 aTokens1 = aTokens;
735 aExpr1.clear();
736 }
737 else if (nIndex == 1)
738 {
739 aTokens2 = aTokens;
740 aExpr2.clear();
741 }
742}
743
745{
746 return 2;
747}
748
749uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableValidationObj::getPropertySetInfo()
750{
751 SolarMutexGuard aGuard;
752 static uno::Reference<beans::XPropertySetInfo> aRef(
754 return aRef;
755}
756
758 const OUString& aPropertyName, const uno::Any& aValue )
759{
760 SolarMutexGuard aGuard;
761
762 if ( aPropertyName == SC_UNONAME_SHOWINP ) bShowInput = ScUnoHelpFunctions::GetBoolFromAny( aValue );
763 else if ( aPropertyName == SC_UNONAME_SHOWERR ) bShowError = ScUnoHelpFunctions::GetBoolFromAny( aValue );
764 else if ( aPropertyName == SC_UNONAME_IGNOREBL ) bIgnoreBlank = ScUnoHelpFunctions::GetBoolFromAny( aValue );
765 else if ( aPropertyName == SC_UNONAME_SHOWLIST ) aValue >>= nShowList;
766 else if ( aPropertyName == SC_UNONAME_INPTITLE )
767 {
768 OUString aStrVal;
769 if ( aValue >>= aStrVal )
770 aInputTitle = aStrVal;
771 }
772 else if ( aPropertyName == SC_UNONAME_INPMESS )
773 {
774 OUString aStrVal;
775 if ( aValue >>= aStrVal )
776 aInputMessage = aStrVal;
777 }
778 else if ( aPropertyName == SC_UNONAME_ERRTITLE )
779 {
780 OUString aStrVal;
781 if ( aValue >>= aStrVal )
782 aErrorTitle = aStrVal;
783 }
784 else if ( aPropertyName == SC_UNONAME_ERRMESS )
785 {
786 OUString aStrVal;
787 if ( aValue >>= aStrVal )
788 aErrorMessage = aStrVal;
789 }
790 else if ( aPropertyName == SC_UNONAME_TYPE )
791 {
792 sheet::ValidationType eType = static_cast<sheet::ValidationType>(ScUnoHelpFunctions::GetEnumFromAny( aValue ));
793 switch (eType)
794 {
795 case sheet::ValidationType_ANY: nValMode = SC_VALID_ANY; break;
796 case sheet::ValidationType_WHOLE: nValMode = SC_VALID_WHOLE; break;
797 case sheet::ValidationType_DECIMAL: nValMode = SC_VALID_DECIMAL; break;
798 case sheet::ValidationType_DATE: nValMode = SC_VALID_DATE; break;
799 case sheet::ValidationType_TIME: nValMode = SC_VALID_TIME; break;
800 case sheet::ValidationType_TEXT_LEN: nValMode = SC_VALID_TEXTLEN; break;
801 case sheet::ValidationType_LIST: nValMode = SC_VALID_LIST; break;
802 case sheet::ValidationType_CUSTOM: nValMode = SC_VALID_CUSTOM; break;
803 default:
804 {
805 // added to avoid warnings
806 }
807 }
808 }
809 else if ( aPropertyName == SC_UNONAME_ERRALSTY )
810 {
811 sheet::ValidationAlertStyle eStyle = static_cast<sheet::ValidationAlertStyle>(ScUnoHelpFunctions::GetEnumFromAny( aValue ));
812 switch (eStyle)
813 {
814 case sheet::ValidationAlertStyle_STOP: nErrorStyle = SC_VALERR_STOP; break;
815 case sheet::ValidationAlertStyle_WARNING: nErrorStyle = SC_VALERR_WARNING; break;
816 case sheet::ValidationAlertStyle_INFO: nErrorStyle = SC_VALERR_INFO; break;
817 case sheet::ValidationAlertStyle_MACRO: nErrorStyle = SC_VALERR_MACRO; break;
818 default:
819 {
820 // added to avoid warnings
821 }
822 }
823 }
824 else if ( aPropertyName == SC_UNONAME_SOURCESTR )
825 {
826 // internal - only for XML filter, not in PropertySetInfo, only set
827
828 OUString aStrVal;
829 if ( aValue >>= aStrVal )
830 aPosString = aStrVal;
831 }
832 else if ( aPropertyName == SC_UNONAME_FORMULANMSP1 )
833 {
834 // internal - only for XML filter, not in PropertySetInfo, only set
835
836 OUString aStrVal;
837 if ( aValue >>= aStrVal )
838 maExprNmsp1 = aStrVal;
839 }
840 else if ( aPropertyName == SC_UNONAME_FORMULANMSP2 )
841 {
842 // internal - only for XML filter, not in PropertySetInfo, only set
843
844 OUString aStrVal;
845 if ( aValue >>= aStrVal )
846 maExprNmsp2 = aStrVal;
847 }
848 else if ( aPropertyName == SC_UNONAME_GRAMMAR1 )
849 {
850 // internal - only for XML filter, not in PropertySetInfo, only set
851
852 sal_Int32 nVal = 0;
853 if ( aValue >>= nVal )
854 meGrammar1 = static_cast< FormulaGrammar::Grammar >(nVal);
855 }
856 else if ( aPropertyName == SC_UNONAME_GRAMMAR2 )
857 {
858 // internal - only for XML filter, not in PropertySetInfo, only set
859
860 sal_Int32 nVal = 0;
861 if ( aValue >>= nVal )
862 meGrammar2 = static_cast< FormulaGrammar::Grammar >(nVal);
863 }
864}
865
866uno::Any SAL_CALL ScTableValidationObj::getPropertyValue( const OUString& aPropertyName )
867{
868 SolarMutexGuard aGuard;
869 uno::Any aRet;
870
871 if ( aPropertyName == SC_UNONAME_SHOWINP ) aRet <<= bShowInput;
872 else if ( aPropertyName == SC_UNONAME_SHOWERR ) aRet <<= bShowError;
873 else if ( aPropertyName == SC_UNONAME_IGNOREBL ) aRet <<= bIgnoreBlank;
874 else if ( aPropertyName == SC_UNONAME_SHOWLIST ) aRet <<= nShowList;
875 else if ( aPropertyName == SC_UNONAME_INPTITLE ) aRet <<= aInputTitle;
876 else if ( aPropertyName == SC_UNONAME_INPMESS ) aRet <<= aInputMessage;
877 else if ( aPropertyName == SC_UNONAME_ERRTITLE ) aRet <<= aErrorTitle;
878 else if ( aPropertyName == SC_UNONAME_ERRMESS ) aRet <<= aErrorMessage;
879 else if ( aPropertyName == SC_UNONAME_TYPE )
880 {
881 sheet::ValidationType eType = sheet::ValidationType_ANY;
882 switch (nValMode)
883 {
884 case SC_VALID_ANY: eType = sheet::ValidationType_ANY; break;
885 case SC_VALID_WHOLE: eType = sheet::ValidationType_WHOLE; break;
886 case SC_VALID_DECIMAL: eType = sheet::ValidationType_DECIMAL; break;
887 case SC_VALID_DATE: eType = sheet::ValidationType_DATE; break;
888 case SC_VALID_TIME: eType = sheet::ValidationType_TIME; break;
889 case SC_VALID_TEXTLEN: eType = sheet::ValidationType_TEXT_LEN; break;
890 case SC_VALID_LIST: eType = sheet::ValidationType_LIST; break;
891 case SC_VALID_CUSTOM: eType = sheet::ValidationType_CUSTOM; break;
892 }
893 aRet <<= eType;
894 }
895 else if ( aPropertyName == SC_UNONAME_ERRALSTY )
896 {
897 sheet::ValidationAlertStyle eStyle = sheet::ValidationAlertStyle_STOP;
898 switch (nErrorStyle)
899 {
900 case SC_VALERR_STOP: eStyle = sheet::ValidationAlertStyle_STOP; break;
901 case SC_VALERR_WARNING: eStyle = sheet::ValidationAlertStyle_WARNING; break;
902 case SC_VALERR_INFO: eStyle = sheet::ValidationAlertStyle_INFO; break;
903 case SC_VALERR_MACRO: eStyle = sheet::ValidationAlertStyle_MACRO; break;
904 }
905 aRet <<= eStyle;
906 }
907
908 return aRet;
909}
910
912
913/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SCTAB Tab() const
Definition: address.hxx:283
void Set(SCCOL nCol, SCROW nRow, SCTAB nTab)
Definition: address.hxx:403
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
const OUString & GetStyle() const
Definition: conditio.hxx:472
ScAddress GetValidSrcPos() const
Return a position that's adjusted to allow textual representation of expressions if possible.
Definition: conditio.cxx:1341
void SetIgnoreBlank(bool bSet)
Definition: conditio.cxx:418
void SetFormula1(const ScTokenArray &rArray)
Definition: conditio.cxx:471
static ScConditionMode GetModeFromApi(css::sheet::ConditionOperator nOperator)
Definition: conditio.cxx:1411
ScConditionMode GetOperation() const
Definition: conditio.hxx:368
void SetFormula2(const ScTokenArray &rArray)
Definition: conditio.cxx:483
void SetSrcString(const OUString &rNew)
Definition: conditio.cxx:463
OUString GetExpression(const ScAddress &rCursor, sal_uInt16 nPos, sal_uInt32 nNumFmt=0, const formula::FormulaGrammar::Grammar eGrammar=formula::FormulaGrammar::GRAM_DEFAULT) const
Definition: conditio.cxx:1250
ScConditionalFormat * GetFormat(sal_uInt32 nKey)
Definition: conditio.cxx:2084
bool IsEmpty() const
Definition: conditio.cxx:1777
bool MarkUsedExternalReferences() const
Definition: conditio.cxx:2022
void AddEntry(ScFormatEntry *pNew)
Definition: conditio.cxx:1762
const ScFormatEntry * GetEntry(sal_uInt16 nPos) const
Definition: conditio.cxx:1796
size_t size() const
Definition: conditio.cxx:1782
SC_DLLPUBLIC const ScValidationData * GetValidationEntry(sal_uInt32 nIndex) const
Definition: documen4.cxx:881
SC_DLLPUBLIC ScConditionalFormatList * GetCondFormList(SCTAB nTab) const
Definition: documen4.cxx:867
bool IsInExternalReferenceMarking() const
Definition: documen3.cxx:642
virtual Type GetType() const =0
static SC_DLLPUBLIC OUString ProgrammaticToDisplayName(const OUString &rProgName, SfxStyleFamily nType)
static OUString DisplayToProgrammaticName(const OUString &rDispName, SfxStyleFamily nType)
virtual sal_Int32 SAL_CALL getConditionOperator() override
Definition: fmtuno.cxx:477
virtual void SAL_CALL setStyleName(const OUString &aStyleName) override
Definition: fmtuno.cxx:537
ScCondFormatEntryItem aData
Definition: fmtuno.hxx:120
virtual void SAL_CALL setSourcePosition(const css::table::CellAddress &aSourcePosition) override
Definition: fmtuno.cxx:523
virtual OUString SAL_CALL getFormula1() override
Definition: fmtuno.cxx:489
virtual ~ScTableConditionalEntry() override
Definition: fmtuno.cxx:454
virtual void SAL_CALL setOperator(css::sheet::ConditionOperator nOperator) override
Definition: fmtuno.cxx:471
virtual void SAL_CALL setFormula1(const OUString &aFormula1) override
Definition: fmtuno.cxx:495
virtual void SAL_CALL setFormula2(const OUString &aFormula2) override
Definition: fmtuno.cxx:507
virtual void SAL_CALL setConditionOperator(sal_Int32 nOperator) override
Definition: fmtuno.cxx:483
virtual OUString SAL_CALL getFormula2() override
Definition: fmtuno.cxx:501
virtual OUString SAL_CALL getStyleName() override
Definition: fmtuno.cxx:531
virtual css::table::CellAddress SAL_CALL getSourcePosition() override
Definition: fmtuno.cxx:513
virtual css::sheet::ConditionOperator SAL_CALL getOperator() override
Definition: fmtuno.cxx:465
ScTableConditionalEntry()=delete
void GetData(ScCondFormatEntryItem &rData) const
Definition: fmtuno.cxx:458
virtual void SAL_CALL addNew(const css::uno::Sequence< css::beans::PropertyValue > &aConditionalEntry) override
Definition: fmtuno.cxx:251
std::vector< rtl::Reference< ScTableConditionalEntry > > maEntries
Definition: fmtuno.hxx:73
void FillFormat(ScConditionalFormat &rFormat, ScDocument &rDoc, formula::FormulaGrammar::Grammar eGrammar) const
Definition: fmtuno.cxx:196
virtual ~ScTableConditionalFormat() override
Definition: fmtuno.cxx:234
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
Definition: fmtuno.cxx:423
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
Definition: fmtuno.cxx:404
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
Definition: fmtuno.cxx:436
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: fmtuno.cxx:360
virtual void SAL_CALL clear() override
Definition: fmtuno.cxx:352
ScTableConditionalEntry * GetObjectByIndex_Impl(sal_uInt16 nIndex) const
Definition: fmtuno.cxx:246
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
Definition: fmtuno.cxx:374
void AddEntry_Impl(const ScCondFormatEntryItem &aEntry)
Definition: fmtuno.cxx:238
virtual sal_Int32 SAL_CALL getCount() override
Definition: fmtuno.cxx:368
virtual css::uno::Type SAL_CALL getElementType() override
Definition: fmtuno.cxx:384
virtual void SAL_CALL removeByIndex(sal_Int32 nIndex) override
Definition: fmtuno.cxx:342
virtual sal_Bool SAL_CALL hasElements() override
Definition: fmtuno.cxx:389
ScValidationData * CreateValidationData(ScDocument &rDoc, formula::FormulaGrammar::Grammar eGrammar) const
Definition: fmtuno.cxx:582
virtual css::sheet::ConditionOperator SAL_CALL getOperator() override
Definition: fmtuno.cxx:653
virtual void SAL_CALL setTokens(sal_Int32 nIndex, const css::uno::Sequence< css::sheet::FormulaToken > &aTokens) override
Definition: fmtuno.cxx:726
ScTableValidationObj()=delete
OUString maExprNmsp2
Definition: fmtuno.hxx:163
OUString aInputTitle
Definition: fmtuno.hxx:174
virtual void SAL_CALL setFormula1(const OUString &aFormula1) override
Definition: fmtuno.cxx:683
sal_uInt16 nValMode
Definition: fmtuno.hxx:170
OUString aInputMessage
Definition: fmtuno.hxx:175
ScAddress aSrcPos
Definition: fmtuno.hxx:168
OUString aErrorMessage
Definition: fmtuno.hxx:179
virtual sal_Int32 SAL_CALL getConditionOperator() override
Definition: fmtuno.cxx:665
formula::FormulaGrammar::Grammar meGrammar1
Definition: fmtuno.hxx:164
virtual void SAL_CALL setSourcePosition(const css::table::CellAddress &aSourcePosition) override
Definition: fmtuno.cxx:711
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: fmtuno.cxx:757
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: fmtuno.cxx:866
virtual sal_Int32 SAL_CALL getCount() override
Definition: fmtuno.cxx:744
virtual ~ScTableValidationObj() override
Definition: fmtuno.cxx:647
OUString aErrorTitle
Definition: fmtuno.hxx:178
virtual css::table::CellAddress SAL_CALL getSourcePosition() override
Definition: fmtuno.cxx:701
sal_Int16 nShowList
Definition: fmtuno.hxx:172
css::uno::Sequence< css::sheet::FormulaToken > aTokens1
Definition: fmtuno.hxx:166
ScConditionMode nMode
Definition: fmtuno.hxx:159
virtual OUString SAL_CALL getFormula1() override
Definition: fmtuno.cxx:677
virtual OUString SAL_CALL getFormula2() override
Definition: fmtuno.cxx:689
virtual void SAL_CALL setConditionOperator(sal_Int32 nOperator) override
Definition: fmtuno.cxx:671
sal_uInt16 nErrorStyle
Definition: fmtuno.hxx:177
css::uno::Sequence< css::sheet::FormulaToken > aTokens2
Definition: fmtuno.hxx:167
OUString maExprNmsp1
Definition: fmtuno.hxx:162
virtual void SAL_CALL setFormula2(const OUString &aFormula2) override
Definition: fmtuno.cxx:695
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: fmtuno.cxx:749
virtual css::uno::Sequence< css::sheet::FormulaToken > SAL_CALL getTokens(sal_Int32 nIndex) override
Definition: fmtuno.cxx:717
formula::FormulaGrammar::Grammar meGrammar2
Definition: fmtuno.hxx:165
OUString aPosString
Definition: fmtuno.hxx:169
virtual void SAL_CALL setOperator(css::sheet::ConditionOperator nOperator) override
Definition: fmtuno.cxx:659
SfxItemPropertySet aPropSet
Definition: fmtuno.hxx:158
static SC_DLLPUBLIC bool ConvertToTokenArray(ScDocument &rDoc, ScTokenArray &rTokenArray, const css::uno::Sequence< css::sheet::FormulaToken > &rSequence)
Definition: tokenuno.cxx:374
static sal_Int32 GetEnumFromAny(const css::uno::Any &aAny)
Definition: miscuno.cxx:161
static bool GetBoolFromAny(const css::uno::Any &aAny)
Definition: miscuno.cxx:139
void SetListType(sal_Int16 nListType)
Definition: validat.hxx:121
void SetInput(const OUString &rTitle, const OUString &rMsg)
Definition: validat.cxx:161
void ResetInput()
Definition: validat.cxx:151
void SetError(const OUString &rTitle, const OUString &rMsg, ScValidErrorStyle eStyle)
Definition: validat.cxx:168
void ResetError()
Definition: validat.cxx:156
const SfxItemPropertyMap & getPropertyMap() const
css::uno::Type const & get()
ColorMode meMode
ScConditionMode
Definition: conditio.hxx:60
int nCount
DocumentType eType
static sheet::ConditionOperator lcl_ConditionModeToOperator(ScConditionMode eMode)
Definition: fmtuno.cxx:92
static o3tl::span< const SfxItemPropertyMapEntry > lcl_GetValidatePropertyMap()
Definition: fmtuno.cxx:47
static ScConditionMode lcl_ConditionOperatorToMode(sheet::ConditionOperator eOper)
Definition: fmtuno.cxx:114
static OUString lcl_GetEntryNameFromIndex(sal_Int32 nIndex)
Definition: fmtuno.cxx:398
static sal_Int32 lcl_ConditionModeToOperatorNew(ScConditionMode eMode)
Definition: fmtuno.cxx:69
sal_Int32 nIndex
OUString aName
Mode eMode
std::unique_ptr< sal_Int32[]> pData
#define SC_SIMPLE_SERVICE_INFO(ClassName, ClassNameAscii, ServiceAscii)
Definition: miscuno.hxx:63
#define SC_IMPL_DUMMY_PROPERTY_LISTENER(ClassName)
Definition: miscuno.hxx:72
constexpr OUStringLiteral aData
int i
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
long Long
sal_uIntPtr sal_uLong
formula::FormulaGrammar::Grammar meGrammar2
Definition: fmtuno.hxx:59
css::uno::Sequence< css::sheet::FormulaToken > maTokens2
Definition: fmtuno.hxx:50
css::uno::Sequence< css::sheet::FormulaToken > maTokens1
Definition: fmtuno.hxx:49
formula::FormulaGrammar::Grammar meGrammar1
Definition: fmtuno.hxx:58
OUString maExprNmsp2
Definition: fmtuno.hxx:54
ScConditionMode meMode
Definition: fmtuno.hxx:60
OUString maExprNmsp1
Definition: fmtuno.hxx:53
unsigned char sal_Bool
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17
constexpr OUStringLiteral SC_UNONAME_FORMULANMSP1
Definition: unonames.hxx:348
constexpr OUStringLiteral SC_UNONAME_STYLENAME
Definition: unonames.hxx:352
constexpr OUStringLiteral SC_UNONAME_FORMULA1
Definition: unonames.hxx:344
constexpr OUStringLiteral SC_UNONAME_FORMULA2
Definition: unonames.hxx:345
constexpr OUStringLiteral SC_UNONAME_SHOWINP
Definition: unonames.hxx:362
constexpr OUStringLiteral SC_UNONAME_SHOWERR
Definition: unonames.hxx:361
constexpr OUStringLiteral SC_UNONAME_IGNOREBL
Definition: unonames.hxx:358
constexpr OUStringLiteral SC_UNONAME_FORMULANMSP2
Definition: unonames.hxx:349
constexpr OUStringLiteral SC_UNONAME_SOURCESTR
Definition: unonames.hxx:347
constexpr OUStringLiteral SC_UNONAME_ERRALSTY
Definition: unonames.hxx:355
constexpr OUStringLiteral SC_UNONAME_TYPE
Definition: unonames.hxx:364
constexpr OUStringLiteral SC_UNONAME_GRAMMAR2
Definition: unonames.hxx:351
constexpr OUStringLiteral SC_UNONAME_OPERATOR
Definition: unonames.hxx:343
constexpr OUStringLiteral SC_UNONAME_INPMESS
Definition: unonames.hxx:359
constexpr OUStringLiteral SC_UNONAME_SOURCEPOS
Definition: unonames.hxx:346
constexpr OUStringLiteral SC_UNONAME_ERRTITLE
Definition: unonames.hxx:357
constexpr OUStringLiteral SC_UNONAME_ERRMESS
Definition: unonames.hxx:356
constexpr OUStringLiteral SC_UNONAME_SHOWLIST
Definition: unonames.hxx:363
constexpr OUStringLiteral SC_UNONAME_GRAMMAR1
Definition: unonames.hxx:350
constexpr OUStringLiteral SC_UNONAME_INPTITLE
Definition: unonames.hxx:360
ScValidationMode
Definition: validat.hxx:41
@ SC_VALID_TEXTLEN
Definition: validat.hxx:47
@ SC_VALID_TIME
Definition: validat.hxx:46
@ SC_VALID_CUSTOM
Definition: validat.hxx:49
@ SC_VALID_ANY
Definition: validat.hxx:42
@ SC_VALID_DECIMAL
Definition: validat.hxx:44
@ SC_VALID_WHOLE
Definition: validat.hxx:43
@ SC_VALID_DATE
Definition: validat.hxx:45
@ SC_VALID_LIST
Definition: validat.hxx:48
ScValidErrorStyle
Definition: validat.hxx:53
@ SC_VALERR_MACRO
Definition: validat.hxx:57
@ SC_VALERR_STOP
Definition: validat.hxx:54
@ SC_VALERR_WARNING
Definition: validat.hxx:55
@ SC_VALERR_INFO
Definition: validat.hxx:56