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
448// XUnoTunnel
449
451
453 aData(std::move( aItem ))
454{
455 // #i113668# only store the settings, keep no reference to parent object
456}
457
459{
460}
461
463{
464 rData = aData;
465}
466
467// XSheetCondition
468
469sheet::ConditionOperator SAL_CALL ScTableConditionalEntry::getOperator()
470{
471 SolarMutexGuard aGuard;
473}
474
475void SAL_CALL ScTableConditionalEntry::setOperator( sheet::ConditionOperator nOperator )
476{
477 SolarMutexGuard aGuard;
479}
480
482{
483 SolarMutexGuard aGuard;
485}
486
487void SAL_CALL ScTableConditionalEntry::setConditionOperator( sal_Int32 nOperator )
488{
489 SolarMutexGuard aGuard;
490 aData.meMode = ScConditionEntry::GetModeFromApi( static_cast<sheet::ConditionOperator>(nOperator) );
491}
492
494{
495 SolarMutexGuard aGuard;
496 return aData.maExpr1;
497}
498
499void SAL_CALL ScTableConditionalEntry::setFormula1( const OUString& aFormula1 )
500{
501 SolarMutexGuard aGuard;
502 aData.maExpr1 = aFormula1;
503}
504
506{
507 SolarMutexGuard aGuard;
508 return aData.maExpr2;
509}
510
511void SAL_CALL ScTableConditionalEntry::setFormula2( const OUString& aFormula2 )
512{
513 SolarMutexGuard aGuard;
514 aData.maExpr2 = aFormula2;
515}
516
518{
519 SolarMutexGuard aGuard;
520 table::CellAddress aRet;
521 aRet.Column = aData.maPos.Col();
522 aRet.Row = aData.maPos.Row();
523 aRet.Sheet = aData.maPos.Tab();
524 return aRet;
525}
526
527void SAL_CALL ScTableConditionalEntry::setSourcePosition( const table::CellAddress& aSourcePosition )
528{
529 SolarMutexGuard aGuard;
530 aData.maPos.Set( static_cast<SCCOL>(aSourcePosition.Column), static_cast<SCROW>(aSourcePosition.Row), aSourcePosition.Sheet );
531}
532
533// XSheetConditionalEntry
534
536{
537 SolarMutexGuard aGuard;
538 return ScStyleNameConversion::DisplayToProgrammaticName( aData.maStyle, SfxStyleFamily::Para );
539}
540
541void SAL_CALL ScTableConditionalEntry::setStyleName( const OUString& aStyleName )
542{
543 SolarMutexGuard aGuard;
544 aData.maStyle = ScStyleNameConversion::ProgrammaticToDisplayName( aStyleName, SfxStyleFamily::Para );
545}
546
548 const formula::FormulaGrammar::Grammar eGrammar) :
549 aPropSet( lcl_GetValidatePropertyMap() )
550{
551 // read the entry from the document...
552
553 bool bFound = false;
554 if (nKey)
555 {
556 const ScValidationData* pData = rDoc.GetValidationEntry( nKey );
557 if (pData)
558 {
559 nMode = pData->GetOperation();
560 aSrcPos = pData->GetValidSrcPos(); // valid pos for expressions
561 aExpr1 = pData->GetExpression( aSrcPos, 0, 0, eGrammar );
562 aExpr2 = pData->GetExpression( aSrcPos, 1, 0, eGrammar );
563 meGrammar1 = meGrammar2 = eGrammar;
564 nValMode = sal::static_int_cast<sal_uInt16>( pData->GetDataMode() );
565 bIgnoreBlank = pData->IsIgnoreBlank();
566 nShowList = pData->GetListType();
568 ScValidErrorStyle eStyle;
569 bShowError = pData->GetErrMsg( aErrorTitle, aErrorMessage, eStyle );
570 nErrorStyle = sal::static_int_cast<sal_uInt16>( eStyle );
571
572 // During save to XML, sheet::ValidationType_ANY formulas are not
573 // saved, even if in the list, see
574 // ScMyValidationsContainer::GetCondition(), so shall not mark
575 // anything in use.
577 pData->MarkUsedExternalReferences();
578
579 bFound = true;
580 }
581 }
582 if (!bFound)
583 ClearData_Impl(); // Defaults
584}
585
587 formula::FormulaGrammar::Grammar eGrammar ) const
588{
589 // ScValidationData = Core-Struktur
590
591 FormulaGrammar::Grammar eGrammar1 = lclResolveGrammar( eGrammar, meGrammar1 );
592 FormulaGrammar::Grammar eGrammar2 = lclResolveGrammar( eGrammar, meGrammar2 );
593
595 nMode,
596 aExpr1, aExpr2, rDoc, aSrcPos,
598 eGrammar1, eGrammar2 );
600 pRet->SetListType(nShowList);
601
602 if ( aTokens1.hasElements() )
603 {
604 ScTokenArray aTokenArray(rDoc);
605 if ( ScTokenConversion::ConvertToTokenArray(rDoc, aTokenArray, aTokens1) )
606 pRet->SetFormula1(aTokenArray);
607 }
608
609 if ( aTokens2.hasElements() )
610 {
611 ScTokenArray aTokenArray(rDoc);
612 if ( ScTokenConversion::ConvertToTokenArray(rDoc, aTokenArray, aTokens2) )
613 pRet->SetFormula2(aTokenArray);
614 }
615
616 // set strings for error / input even if disabled (and disable afterwards)
618 if (!bShowInput)
619 pRet->ResetInput();
621 if (!bShowError)
622 pRet->ResetError();
623
624 if ( !aPosString.isEmpty() )
625 pRet->SetSrcString( aPosString );
626
627 return pRet;
628}
629
631{
634 bIgnoreBlank = true;
635 nShowList = sheet::TableValidationVisibility::UNSORTED;
636 bShowInput = false;
637 bShowError = false;
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();
649}
650
652{
653}
654
655// XSheetCondition
656
657sheet::ConditionOperator SAL_CALL ScTableValidationObj::getOperator()
658{
659 SolarMutexGuard aGuard;
661}
662
663void SAL_CALL ScTableValidationObj::setOperator( sheet::ConditionOperator nOperator )
664{
665 SolarMutexGuard aGuard;
666 nMode = lcl_ConditionOperatorToMode( nOperator );
667}
668
670{
671 SolarMutexGuard aGuard;
673}
674
675void SAL_CALL ScTableValidationObj::setConditionOperator( sal_Int32 nOperator )
676{
677 SolarMutexGuard aGuard;
678 nMode = ScConditionEntry::GetModeFromApi( static_cast<css::sheet::ConditionOperator>(nOperator) );
679}
680
682{
683 SolarMutexGuard aGuard;
684 return aExpr1;
685}
686
687void SAL_CALL ScTableValidationObj::setFormula1( const OUString& aFormula1 )
688{
689 SolarMutexGuard aGuard;
690 aExpr1 = aFormula1;
691}
692
694{
695 SolarMutexGuard aGuard;
696 return aExpr2;
697}
698
699void SAL_CALL ScTableValidationObj::setFormula2( const OUString& aFormula2 )
700{
701 SolarMutexGuard aGuard;
702 aExpr2 = aFormula2;
703}
704
705table::CellAddress SAL_CALL ScTableValidationObj::getSourcePosition()
706{
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;
713}
714
715void SAL_CALL ScTableValidationObj::setSourcePosition( const table::CellAddress& aSourcePosition )
716{
717 SolarMutexGuard aGuard;
718 aSrcPos.Set( static_cast<SCCOL>(aSourcePosition.Column), static_cast<SCROW>(aSourcePosition.Row), aSourcePosition.Sheet );
719}
720
721uno::Sequence<sheet::FormulaToken> SAL_CALL ScTableValidationObj::getTokens( sal_Int32 nIndex )
722{
723 SolarMutexGuard aGuard;
724 if (nIndex >= 2 || nIndex < 0)
725 throw lang::IndexOutOfBoundsException();
726
727 return nIndex == 0 ? aTokens1 : aTokens2;
728}
729
730void SAL_CALL ScTableValidationObj::setTokens( sal_Int32 nIndex, const uno::Sequence<sheet::FormulaToken>& aTokens )
731{
732 SolarMutexGuard aGuard;
733 if (nIndex >= 2 || nIndex < 0)
734 throw lang::IndexOutOfBoundsException();
735
736 if (nIndex == 0)
737 {
738 aTokens1 = aTokens;
739 aExpr1.clear();
740 }
741 else if (nIndex == 1)
742 {
743 aTokens2 = aTokens;
744 aExpr2.clear();
745 }
746}
747
749{
750 return 2;
751}
752
753uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableValidationObj::getPropertySetInfo()
754{
755 SolarMutexGuard aGuard;
756 static uno::Reference<beans::XPropertySetInfo> aRef(
758 return aRef;
759}
760
762 const OUString& aPropertyName, const uno::Any& aValue )
763{
764 SolarMutexGuard aGuard;
765
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_SHOWLIST ) aValue >>= nShowList;
770 else if ( aPropertyName == SC_UNONAME_INPTITLE )
771 {
772 OUString aStrVal;
773 if ( aValue >>= aStrVal )
774 aInputTitle = aStrVal;
775 }
776 else if ( aPropertyName == SC_UNONAME_INPMESS )
777 {
778 OUString aStrVal;
779 if ( aValue >>= aStrVal )
780 aInputMessage = aStrVal;
781 }
782 else if ( aPropertyName == SC_UNONAME_ERRTITLE )
783 {
784 OUString aStrVal;
785 if ( aValue >>= aStrVal )
786 aErrorTitle = aStrVal;
787 }
788 else if ( aPropertyName == SC_UNONAME_ERRMESS )
789 {
790 OUString aStrVal;
791 if ( aValue >>= aStrVal )
792 aErrorMessage = aStrVal;
793 }
794 else if ( aPropertyName == SC_UNONAME_TYPE )
795 {
796 sheet::ValidationType eType = static_cast<sheet::ValidationType>(ScUnoHelpFunctions::GetEnumFromAny( aValue ));
797 switch (eType)
798 {
799 case sheet::ValidationType_ANY: nValMode = SC_VALID_ANY; break;
800 case sheet::ValidationType_WHOLE: nValMode = SC_VALID_WHOLE; break;
801 case sheet::ValidationType_DECIMAL: nValMode = SC_VALID_DECIMAL; break;
802 case sheet::ValidationType_DATE: nValMode = SC_VALID_DATE; break;
803 case sheet::ValidationType_TIME: nValMode = SC_VALID_TIME; break;
804 case sheet::ValidationType_TEXT_LEN: nValMode = SC_VALID_TEXTLEN; break;
805 case sheet::ValidationType_LIST: nValMode = SC_VALID_LIST; break;
806 case sheet::ValidationType_CUSTOM: nValMode = SC_VALID_CUSTOM; break;
807 default:
808 {
809 // added to avoid warnings
810 }
811 }
812 }
813 else if ( aPropertyName == SC_UNONAME_ERRALSTY )
814 {
815 sheet::ValidationAlertStyle eStyle = static_cast<sheet::ValidationAlertStyle>(ScUnoHelpFunctions::GetEnumFromAny( aValue ));
816 switch (eStyle)
817 {
818 case sheet::ValidationAlertStyle_STOP: nErrorStyle = SC_VALERR_STOP; break;
819 case sheet::ValidationAlertStyle_WARNING: nErrorStyle = SC_VALERR_WARNING; break;
820 case sheet::ValidationAlertStyle_INFO: nErrorStyle = SC_VALERR_INFO; break;
821 case sheet::ValidationAlertStyle_MACRO: nErrorStyle = SC_VALERR_MACRO; break;
822 default:
823 {
824 // added to avoid warnings
825 }
826 }
827 }
828 else if ( aPropertyName == SC_UNONAME_SOURCESTR )
829 {
830 // internal - only for XML filter, not in PropertySetInfo, only set
831
832 OUString aStrVal;
833 if ( aValue >>= aStrVal )
834 aPosString = aStrVal;
835 }
836 else if ( aPropertyName == SC_UNONAME_FORMULANMSP1 )
837 {
838 // internal - only for XML filter, not in PropertySetInfo, only set
839
840 OUString aStrVal;
841 if ( aValue >>= aStrVal )
842 maExprNmsp1 = aStrVal;
843 }
844 else if ( aPropertyName == SC_UNONAME_FORMULANMSP2 )
845 {
846 // internal - only for XML filter, not in PropertySetInfo, only set
847
848 OUString aStrVal;
849 if ( aValue >>= aStrVal )
850 maExprNmsp2 = aStrVal;
851 }
852 else if ( aPropertyName == SC_UNONAME_GRAMMAR1 )
853 {
854 // internal - only for XML filter, not in PropertySetInfo, only set
855
856 sal_Int32 nVal = 0;
857 if ( aValue >>= nVal )
858 meGrammar1 = static_cast< FormulaGrammar::Grammar >(nVal);
859 }
860 else if ( aPropertyName == SC_UNONAME_GRAMMAR2 )
861 {
862 // internal - only for XML filter, not in PropertySetInfo, only set
863
864 sal_Int32 nVal = 0;
865 if ( aValue >>= nVal )
866 meGrammar2 = static_cast< FormulaGrammar::Grammar >(nVal);
867 }
868}
869
870uno::Any SAL_CALL ScTableValidationObj::getPropertyValue( const OUString& aPropertyName )
871{
872 SolarMutexGuard aGuard;
873 uno::Any aRet;
874
875 if ( aPropertyName == SC_UNONAME_SHOWINP ) aRet <<= bShowInput;
876 else if ( aPropertyName == SC_UNONAME_SHOWERR ) aRet <<= bShowError;
877 else if ( aPropertyName == SC_UNONAME_IGNOREBL ) aRet <<= bIgnoreBlank;
878 else if ( aPropertyName == SC_UNONAME_SHOWLIST ) aRet <<= nShowList;
879 else if ( aPropertyName == SC_UNONAME_INPTITLE ) aRet <<= aInputTitle;
880 else if ( aPropertyName == SC_UNONAME_INPMESS ) aRet <<= aInputMessage;
881 else if ( aPropertyName == SC_UNONAME_ERRTITLE ) aRet <<= aErrorTitle;
882 else if ( aPropertyName == SC_UNONAME_ERRMESS ) aRet <<= aErrorMessage;
883 else if ( aPropertyName == SC_UNONAME_TYPE )
884 {
885 sheet::ValidationType eType = sheet::ValidationType_ANY;
886 switch (nValMode)
887 {
888 case SC_VALID_ANY: eType = sheet::ValidationType_ANY; break;
889 case SC_VALID_WHOLE: eType = sheet::ValidationType_WHOLE; break;
890 case SC_VALID_DECIMAL: eType = sheet::ValidationType_DECIMAL; break;
891 case SC_VALID_DATE: eType = sheet::ValidationType_DATE; break;
892 case SC_VALID_TIME: eType = sheet::ValidationType_TIME; break;
893 case SC_VALID_TEXTLEN: eType = sheet::ValidationType_TEXT_LEN; break;
894 case SC_VALID_LIST: eType = sheet::ValidationType_LIST; break;
895 case SC_VALID_CUSTOM: eType = sheet::ValidationType_CUSTOM; break;
896 }
897 aRet <<= eType;
898 }
899 else if ( aPropertyName == SC_UNONAME_ERRALSTY )
900 {
901 sheet::ValidationAlertStyle eStyle = sheet::ValidationAlertStyle_STOP;
902 switch (nErrorStyle)
903 {
904 case SC_VALERR_STOP: eStyle = sheet::ValidationAlertStyle_STOP; break;
905 case SC_VALERR_WARNING: eStyle = sheet::ValidationAlertStyle_WARNING; break;
906 case SC_VALERR_INFO: eStyle = sheet::ValidationAlertStyle_INFO; break;
907 case SC_VALERR_MACRO: eStyle = sheet::ValidationAlertStyle_MACRO; break;
908 }
909 aRet <<= eStyle;
910 }
911
912 return aRet;
913}
914
916
917// XUnoTunnel
918
920
921/* 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:481
virtual void SAL_CALL setStyleName(const OUString &aStyleName) override
Definition: fmtuno.cxx:541
ScCondFormatEntryItem aData
Definition: fmtuno.hxx:125
virtual void SAL_CALL setSourcePosition(const css::table::CellAddress &aSourcePosition) override
Definition: fmtuno.cxx:527
virtual OUString SAL_CALL getFormula1() override
Definition: fmtuno.cxx:493
virtual ~ScTableConditionalEntry() override
Definition: fmtuno.cxx:458
virtual void SAL_CALL setOperator(css::sheet::ConditionOperator nOperator) override
Definition: fmtuno.cxx:475
virtual void SAL_CALL setFormula1(const OUString &aFormula1) override
Definition: fmtuno.cxx:499
virtual void SAL_CALL setFormula2(const OUString &aFormula2) override
Definition: fmtuno.cxx:511
virtual void SAL_CALL setConditionOperator(sal_Int32 nOperator) override
Definition: fmtuno.cxx:487
virtual OUString SAL_CALL getFormula2() override
Definition: fmtuno.cxx:505
virtual OUString SAL_CALL getStyleName() override
Definition: fmtuno.cxx:535
virtual css::table::CellAddress SAL_CALL getSourcePosition() override
Definition: fmtuno.cxx:517
virtual css::sheet::ConditionOperator SAL_CALL getOperator() override
Definition: fmtuno.cxx:469
ScTableConditionalEntry()=delete
void GetData(ScCondFormatEntryItem &rData) const
Definition: fmtuno.cxx:462
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:75
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:586
virtual css::sheet::ConditionOperator SAL_CALL getOperator() override
Definition: fmtuno.cxx:657
virtual void SAL_CALL setTokens(sal_Int32 nIndex, const css::uno::Sequence< css::sheet::FormulaToken > &aTokens) override
Definition: fmtuno.cxx:730
ScTableValidationObj()=delete
OUString maExprNmsp2
Definition: fmtuno.hxx:169
OUString aInputTitle
Definition: fmtuno.hxx:180
virtual void SAL_CALL setFormula1(const OUString &aFormula1) override
Definition: fmtuno.cxx:687
sal_uInt16 nValMode
Definition: fmtuno.hxx:176
OUString aInputMessage
Definition: fmtuno.hxx:181
ScAddress aSrcPos
Definition: fmtuno.hxx:174
OUString aErrorMessage
Definition: fmtuno.hxx:185
virtual sal_Int32 SAL_CALL getConditionOperator() override
Definition: fmtuno.cxx:669
formula::FormulaGrammar::Grammar meGrammar1
Definition: fmtuno.hxx:170
virtual void SAL_CALL setSourcePosition(const css::table::CellAddress &aSourcePosition) override
Definition: fmtuno.cxx:715
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: fmtuno.cxx:761
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: fmtuno.cxx:870
virtual sal_Int32 SAL_CALL getCount() override
Definition: fmtuno.cxx:748
virtual ~ScTableValidationObj() override
Definition: fmtuno.cxx:651
OUString aErrorTitle
Definition: fmtuno.hxx:184
virtual css::table::CellAddress SAL_CALL getSourcePosition() override
Definition: fmtuno.cxx:705
sal_Int16 nShowList
Definition: fmtuno.hxx:178
css::uno::Sequence< css::sheet::FormulaToken > aTokens1
Definition: fmtuno.hxx:172
ScConditionMode nMode
Definition: fmtuno.hxx:165
virtual OUString SAL_CALL getFormula1() override
Definition: fmtuno.cxx:681
virtual OUString SAL_CALL getFormula2() override
Definition: fmtuno.cxx:693
virtual void SAL_CALL setConditionOperator(sal_Int32 nOperator) override
Definition: fmtuno.cxx:675
sal_uInt16 nErrorStyle
Definition: fmtuno.hxx:183
css::uno::Sequence< css::sheet::FormulaToken > aTokens2
Definition: fmtuno.hxx:173
OUString maExprNmsp1
Definition: fmtuno.hxx:168
virtual void SAL_CALL setFormula2(const OUString &aFormula2) override
Definition: fmtuno.cxx:699
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: fmtuno.cxx:753
virtual css::uno::Sequence< css::sheet::FormulaToken > SAL_CALL getTokens(sal_Int32 nIndex) override
Definition: fmtuno.cxx:721
formula::FormulaGrammar::Grammar meGrammar2
Definition: fmtuno.hxx:171
OUString aPosString
Definition: fmtuno.hxx:175
virtual void SAL_CALL setOperator(css::sheet::ConditionOperator nOperator) override
Definition: fmtuno.cxx:663
SfxItemPropertySet aPropSet
Definition: fmtuno.hxx:164
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:117
void SetInput(const OUString &rTitle, const OUString &rMsg)
Definition: validat.cxx:160
void ResetInput()
Definition: validat.cxx:150
void SetError(const OUString &rTitle, const OUString &rMsg, ScValidErrorStyle eStyle)
Definition: validat.cxx:167
void ResetError()
Definition: validat.cxx:155
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
UNO3_GETIMPLEMENTATION_IMPL(ScTableConditionalFormat)
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:60
css::uno::Sequence< css::sheet::FormulaToken > maTokens2
Definition: fmtuno.hxx:51
css::uno::Sequence< css::sheet::FormulaToken > maTokens1
Definition: fmtuno.hxx:50
formula::FormulaGrammar::Grammar meGrammar1
Definition: fmtuno.hxx:59
OUString maExprNmsp2
Definition: fmtuno.hxx:55
ScConditionMode meMode
Definition: fmtuno.hxx:61
OUString maExprNmsp1
Definition: fmtuno.hxx:54
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:39
@ SC_VALID_TEXTLEN
Definition: validat.hxx:45
@ SC_VALID_TIME
Definition: validat.hxx:44
@ SC_VALID_CUSTOM
Definition: validat.hxx:47
@ SC_VALID_ANY
Definition: validat.hxx:40
@ SC_VALID_DECIMAL
Definition: validat.hxx:42
@ SC_VALID_WHOLE
Definition: validat.hxx:41
@ SC_VALID_DATE
Definition: validat.hxx:43
@ SC_VALID_LIST
Definition: validat.hxx:46
ScValidErrorStyle
Definition: validat.hxx:51
@ SC_VALERR_MACRO
Definition: validat.hxx:55
@ SC_VALERR_STOP
Definition: validat.hxx:52
@ SC_VALERR_WARNING
Definition: validat.hxx:53
@ SC_VALERR_INFO
Definition: validat.hxx:54