fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / unoobj / fmtuno.cxx
blob02cf321ed6163b18229518f8fe13d1e072a1cfed
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 <boost/bind.hpp>
22 #include <vcl/svapp.hxx>
23 #include <comphelper/servicehelper.hxx>
25 #include <com/sun/star/sheet/ValidationAlertStyle.hpp>
26 #include <com/sun/star/sheet/ValidationType.hpp>
27 #include <com/sun/star/sheet/TableValidationVisibility.hpp>
29 #include "fmtuno.hxx"
30 #include "miscuno.hxx"
31 #include "validat.hxx"
32 #include "document.hxx"
33 #include "unonames.hxx"
34 #include "styleuno.hxx"
35 #include "tokenarray.hxx"
36 #include "tokenuno.hxx"
37 #include "stylehelper.hxx"
39 using namespace ::com::sun::star;
40 using namespace ::formula;
42 // Map nur fuer PropertySetInfo
44 static const SfxItemPropertyMapEntry* lcl_GetValidatePropertyMap()
46 static const SfxItemPropertyMapEntry aValidatePropertyMap_Impl[] =
48 {OUString(SC_UNONAME_ERRALSTY), 0, cppu::UnoType<sheet::ValidationAlertStyle>::get(), 0, 0},
49 {OUString(SC_UNONAME_ERRMESS), 0, cppu::UnoType<OUString>::get(), 0, 0},
50 {OUString(SC_UNONAME_ERRTITLE), 0, cppu::UnoType<OUString>::get(), 0, 0},
51 {OUString(SC_UNONAME_IGNOREBL), 0, cppu::UnoType<bool>::get(), 0, 0},
52 {OUString(SC_UNONAME_INPMESS), 0, cppu::UnoType<OUString>::get(), 0, 0},
53 {OUString(SC_UNONAME_INPTITLE), 0, cppu::UnoType<OUString>::get(), 0, 0},
54 {OUString(SC_UNONAME_SHOWERR), 0, cppu::UnoType<bool>::get(), 0, 0},
55 {OUString(SC_UNONAME_SHOWINP), 0, cppu::UnoType<bool>::get(), 0, 0},
56 {OUString(SC_UNONAME_SHOWLIST), 0, cppu::UnoType<sal_Int16>::get(), 0, 0},
57 {OUString(SC_UNONAME_TYPE), 0, cppu::UnoType<sheet::ValidationType>::get(), 0, 0},
58 { OUString(), 0, css::uno::Type(), 0, 0 }
60 return aValidatePropertyMap_Impl;
63 SC_SIMPLE_SERVICE_INFO( ScTableConditionalEntry, "ScTableConditionalEntry", "com.sun.star.sheet.TableConditionalEntry" )
64 SC_SIMPLE_SERVICE_INFO( ScTableConditionalFormat, "ScTableConditionalFormat", "com.sun.star.sheet.TableConditionalFormat" )
65 SC_SIMPLE_SERVICE_INFO( ScTableValidationObj, "ScTableValidationObj", "com.sun.star.sheet.TableValidation" )
67 static sal_Int32 lcl_ConditionModeToOperatorNew( ScConditionMode eMode )
69 sal_Int32 eOper = sheet::ConditionOperator2::NONE;
70 switch (eMode)
72 case SC_COND_EQUAL: eOper = sheet::ConditionOperator2::EQUAL; break;
73 case SC_COND_LESS: eOper = sheet::ConditionOperator2::LESS; break;
74 case SC_COND_GREATER: eOper = sheet::ConditionOperator2::GREATER; break;
75 case SC_COND_EQLESS: eOper = sheet::ConditionOperator2::LESS_EQUAL; break;
76 case SC_COND_EQGREATER: eOper = sheet::ConditionOperator2::GREATER_EQUAL; break;
77 case SC_COND_NOTEQUAL: eOper = sheet::ConditionOperator2::NOT_EQUAL; break;
78 case SC_COND_BETWEEN: eOper = sheet::ConditionOperator2::BETWEEN; break;
79 case SC_COND_NOTBETWEEN: eOper = sheet::ConditionOperator2::NOT_BETWEEN; break;
80 case SC_COND_DIRECT: eOper = sheet::ConditionOperator2::FORMULA; break;
81 case SC_COND_DUPLICATE: eOper = sheet::ConditionOperator2::DUPLICATE; break;
82 default:
84 // added to avoid warnings
87 return eOper;
90 static sheet::ConditionOperator lcl_ConditionModeToOperator( ScConditionMode eMode )
92 sheet::ConditionOperator eOper = sheet::ConditionOperator_NONE;
93 switch (eMode)
95 case SC_COND_EQUAL: eOper = sheet::ConditionOperator_EQUAL; break;
96 case SC_COND_LESS: eOper = sheet::ConditionOperator_LESS; break;
97 case SC_COND_GREATER: eOper = sheet::ConditionOperator_GREATER; break;
98 case SC_COND_EQLESS: eOper = sheet::ConditionOperator_LESS_EQUAL; break;
99 case SC_COND_EQGREATER: eOper = sheet::ConditionOperator_GREATER_EQUAL; break;
100 case SC_COND_NOTEQUAL: eOper = sheet::ConditionOperator_NOT_EQUAL; break;
101 case SC_COND_BETWEEN: eOper = sheet::ConditionOperator_BETWEEN; break;
102 case SC_COND_NOTBETWEEN: eOper = sheet::ConditionOperator_NOT_BETWEEN; break;
103 case SC_COND_DIRECT: eOper = sheet::ConditionOperator_FORMULA; break;
104 default:
106 // added to avoid warnings
109 return eOper;
112 static ScConditionMode lcl_ConditionOperatorToMode( sheet::ConditionOperator eOper )
114 ScConditionMode eMode = SC_COND_NONE;
115 switch (eOper)
117 case sheet::ConditionOperator_EQUAL: eMode = SC_COND_EQUAL; break;
118 case sheet::ConditionOperator_LESS: eMode = SC_COND_LESS; break;
119 case sheet::ConditionOperator_GREATER: eMode = SC_COND_GREATER; break;
120 case sheet::ConditionOperator_LESS_EQUAL: eMode = SC_COND_EQLESS; break;
121 case sheet::ConditionOperator_GREATER_EQUAL: eMode = SC_COND_EQGREATER; break;
122 case sheet::ConditionOperator_NOT_EQUAL: eMode = SC_COND_NOTEQUAL; break;
123 case sheet::ConditionOperator_BETWEEN: eMode = SC_COND_BETWEEN; break;
124 case sheet::ConditionOperator_NOT_BETWEEN: eMode = SC_COND_NOTBETWEEN; break;
125 case sheet::ConditionOperator_FORMULA: eMode = SC_COND_DIRECT; break;
126 default:
128 // added to avoid warnings
131 return eMode;
134 ScCondFormatEntryItem::ScCondFormatEntryItem() :
135 meGrammar1( FormulaGrammar::GRAM_UNSPECIFIED ),
136 meGrammar2( FormulaGrammar::GRAM_UNSPECIFIED ),
137 meMode( SC_COND_NONE )
141 ScTableConditionalFormat::ScTableConditionalFormat(
142 ScDocument* pDoc, sal_uLong nKey, SCTAB nTab, FormulaGrammar::Grammar eGrammar)
144 // Eintrag aus dem Dokument lesen...
146 if ( pDoc && nKey )
148 ScConditionalFormatList* pList = pDoc->GetCondFormList(nTab);
149 if (pList)
151 const ScConditionalFormat* pFormat = pList->GetFormat( nKey );
152 if (pFormat)
154 // During save to XML.
155 if (pDoc->IsInExternalReferenceMarking())
156 pFormat->MarkUsedExternalReferences();
158 size_t nEntryCount = pFormat->size();
159 for (size_t i=0; i<nEntryCount; i++)
161 ScCondFormatEntryItem aItem;
162 const ScFormatEntry* pFrmtEntry = pFormat->GetEntry(i);
163 if(pFrmtEntry->GetType() != condformat::CONDITION)
164 continue;
166 const ScCondFormatEntry* pFormatEntry = static_cast<const ScCondFormatEntry*>(pFrmtEntry);
167 aItem.meMode = pFormatEntry->GetOperation();
168 aItem.maPos = pFormatEntry->GetValidSrcPos();
169 aItem.maExpr1 = pFormatEntry->GetExpression(aItem.maPos, 0, 0, eGrammar);
170 aItem.maExpr2 = pFormatEntry->GetExpression(aItem.maPos, 1, 0, eGrammar);
171 aItem.meGrammar1 = aItem.meGrammar2 = eGrammar;
172 aItem.maStyle = pFormatEntry->GetStyle();
174 AddEntry_Impl(aItem);
181 namespace {
183 FormulaGrammar::Grammar lclResolveGrammar( FormulaGrammar::Grammar eExtGrammar, FormulaGrammar::Grammar eIntGrammar )
185 if( eExtGrammar != FormulaGrammar::GRAM_UNSPECIFIED )
186 return eExtGrammar;
187 OSL_ENSURE( eIntGrammar != FormulaGrammar::GRAM_UNSPECIFIED, "lclResolveGrammar - unspecified grammar, using GRAM_PODF_A1" );
188 return (eIntGrammar == FormulaGrammar::GRAM_UNSPECIFIED) ? FormulaGrammar::GRAM_PODF_A1 : eIntGrammar;
191 } // namespace
193 void ScTableConditionalFormat::FillFormat( ScConditionalFormat& rFormat,
194 ScDocument* pDoc, FormulaGrammar::Grammar eGrammar) const
196 // ScConditionalFormat = Core-Struktur, muss leer sein
198 OSL_ENSURE( rFormat.IsEmpty(), "FillFormat: Format nicht leer" );
200 std::vector<ScTableConditionalEntry*>::const_iterator iter;
201 for (iter = aEntries.begin(); iter != aEntries.end(); ++iter)
203 ScCondFormatEntryItem aData;
204 (*iter)->GetData(aData);
206 FormulaGrammar::Grammar eGrammar1 = lclResolveGrammar( eGrammar, aData.meGrammar1 );
207 FormulaGrammar::Grammar eGrammar2 = lclResolveGrammar( eGrammar, aData.meGrammar2 );
209 ScCondFormatEntry* pCoreEntry = new ScCondFormatEntry( aData.meMode, aData.maExpr1, aData.maExpr2,
210 pDoc, aData.maPos, aData.maStyle, aData.maExprNmsp1, aData.maExprNmsp2, eGrammar1, eGrammar2 );
212 if ( !aData.maPosStr.isEmpty() )
213 pCoreEntry->SetSrcString( aData.maPosStr );
215 if ( aData.maTokens1.getLength() )
217 ScTokenArray aTokenArray;
218 if ( ScTokenConversion::ConvertToTokenArray(*pDoc, aTokenArray, aData.maTokens1) )
219 pCoreEntry->SetFormula1(aTokenArray);
222 if ( aData.maTokens2.getLength() )
224 ScTokenArray aTokenArray;
225 if ( ScTokenConversion::ConvertToTokenArray(*pDoc, aTokenArray, aData.maTokens2) )
226 pCoreEntry->SetFormula2(aTokenArray);
228 rFormat.AddEntry( pCoreEntry );
232 ScTableConditionalFormat::~ScTableConditionalFormat()
234 std::for_each(aEntries.begin(),aEntries.end(),boost::bind(&ScTableConditionalEntry::release,_1));
237 void ScTableConditionalFormat::AddEntry_Impl(const ScCondFormatEntryItem& aEntry)
239 ScTableConditionalEntry* pNew = new ScTableConditionalEntry(aEntry);
240 pNew->acquire();
241 aEntries.push_back(pNew);
244 // XSheetConditionalFormat
246 ScTableConditionalEntry* ScTableConditionalFormat::GetObjectByIndex_Impl(sal_uInt16 nIndex) const
248 return nIndex < aEntries.size() ? aEntries[nIndex] : NULL;
251 void SAL_CALL ScTableConditionalFormat::addNew(
252 const uno::Sequence<beans::PropertyValue >& aConditionalEntry )
253 throw(uno::RuntimeException, std::exception)
255 SolarMutexGuard aGuard;
256 ScCondFormatEntryItem aEntry;
257 aEntry.meMode = SC_COND_NONE;
259 const beans::PropertyValue* pPropArray = aConditionalEntry.getConstArray();
260 long nPropCount = aConditionalEntry.getLength();
261 for (long i = 0; i < nPropCount; i++)
263 const beans::PropertyValue& rProp = pPropArray[i];
265 if ( rProp.Name == SC_UNONAME_OPERATOR )
267 sal_Int32 eOper = ScUnoHelpFunctions::GetEnumFromAny( rProp.Value );
268 aEntry.meMode = ScConditionEntry::GetModeFromApi( eOper );
270 else if ( rProp.Name == SC_UNONAME_FORMULA1 )
272 OUString aStrVal;
273 uno::Sequence<sheet::FormulaToken> aTokens;
274 if ( rProp.Value >>= aStrVal )
275 aEntry.maExpr1 = aStrVal;
276 else if ( rProp.Value >>= aTokens )
278 aEntry.maExpr1.clear();
279 aEntry.maTokens1 = aTokens;
282 else if ( rProp.Name == SC_UNONAME_FORMULA2 )
284 OUString aStrVal;
285 uno::Sequence<sheet::FormulaToken> aTokens;
286 if ( rProp.Value >>= aStrVal )
287 aEntry.maExpr2 = aStrVal;
288 else if ( rProp.Value >>= aTokens )
290 aEntry.maExpr2.clear();
291 aEntry.maTokens2 = aTokens;
294 else if ( rProp.Name == SC_UNONAME_SOURCEPOS )
296 table::CellAddress aAddress;
297 if ( rProp.Value >>= aAddress )
298 aEntry.maPos = ScAddress( (SCCOL)aAddress.Column, (SCROW)aAddress.Row, aAddress.Sheet );
300 else if ( rProp.Name == SC_UNONAME_SOURCESTR )
302 OUString aStrVal;
303 if ( rProp.Value >>= aStrVal )
304 aEntry.maPosStr = aStrVal;
306 else if ( rProp.Name == SC_UNONAME_STYLENAME )
308 OUString aStrVal;
309 if ( rProp.Value >>= aStrVal )
310 aEntry.maStyle = ScStyleNameConversion::ProgrammaticToDisplayName(
311 aStrVal, SFX_STYLE_FAMILY_PARA );
313 else if ( rProp.Name == SC_UNONAME_FORMULANMSP1 )
315 OUString aStrVal;
316 if ( rProp.Value >>= aStrVal )
317 aEntry.maExprNmsp1 = aStrVal;
319 else if ( rProp.Name == SC_UNONAME_FORMULANMSP2 )
321 OUString aStrVal;
322 if ( rProp.Value >>= aStrVal )
323 aEntry.maExprNmsp2 = aStrVal;
325 else if ( rProp.Name == SC_UNONAME_GRAMMAR1 )
327 sal_Int32 nVal = 0;
328 if ( rProp.Value >>= nVal )
329 aEntry.meGrammar1 = static_cast< FormulaGrammar::Grammar >( nVal );
331 else if ( rProp.Name == SC_UNONAME_GRAMMAR2 )
333 sal_Int32 nVal = 0;
334 if ( rProp.Value >>= nVal )
335 aEntry.meGrammar2 = static_cast< FormulaGrammar::Grammar >( nVal );
337 else
339 OSL_FAIL("falsche Property");
340 //! Exception...
344 AddEntry_Impl(aEntry);
347 void SAL_CALL ScTableConditionalFormat::removeByIndex( sal_Int32 nIndex )
348 throw(uno::RuntimeException, std::exception)
350 SolarMutexGuard aGuard;
352 if (nIndex < static_cast<sal_Int32>(aEntries.size()) && nIndex >= 0)
354 std::vector<ScTableConditionalEntry*>::iterator iter = aEntries.begin()+nIndex;
356 (*iter)->release();
357 aEntries.erase(iter);
361 void SAL_CALL ScTableConditionalFormat::clear() throw(uno::RuntimeException, std::exception)
363 SolarMutexGuard aGuard;
364 std::for_each(aEntries.begin(),aEntries.end(),
365 boost::bind(&ScTableConditionalEntry::release,_1));
367 aEntries.clear();
370 // XEnumerationAccess
372 uno::Reference<container::XEnumeration> SAL_CALL ScTableConditionalFormat::createEnumeration()
373 throw(uno::RuntimeException, std::exception)
375 SolarMutexGuard aGuard;
376 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.TableConditionalEntryEnumeration"));
379 // XIndexAccess
381 sal_Int32 SAL_CALL ScTableConditionalFormat::getCount() throw(uno::RuntimeException, std::exception)
383 SolarMutexGuard aGuard;
384 return aEntries.size();
387 uno::Any SAL_CALL ScTableConditionalFormat::getByIndex( sal_Int32 nIndex )
388 throw(lang::IndexOutOfBoundsException,
389 lang::WrappedTargetException, uno::RuntimeException, std::exception)
391 SolarMutexGuard aGuard;
392 uno::Reference<sheet::XSheetConditionalEntry> xEntry(GetObjectByIndex_Impl((sal_uInt16)nIndex));
393 if (xEntry.is())
394 return uno::makeAny(xEntry);
395 else
396 throw lang::IndexOutOfBoundsException();
399 uno::Type SAL_CALL ScTableConditionalFormat::getElementType() throw(uno::RuntimeException, std::exception)
401 SolarMutexGuard aGuard;
402 return cppu::UnoType<sheet::XSheetConditionalEntry>::get();
405 sal_Bool SAL_CALL ScTableConditionalFormat::hasElements() throw(uno::RuntimeException, std::exception)
407 SolarMutexGuard aGuard;
408 return ( getCount() != 0 );
411 // conditional format entries have no real names
412 // -> generate name from index
414 static OUString lcl_GetEntryNameFromIndex( sal_Int32 nIndex )
416 OUString aRet( "Entry" );
417 aRet += OUString::number( nIndex );
418 return aRet;
421 uno::Any SAL_CALL ScTableConditionalFormat::getByName( const OUString& aName )
422 throw(container::NoSuchElementException,
423 lang::WrappedTargetException, uno::RuntimeException, std::exception)
425 SolarMutexGuard aGuard;
427 uno::Reference<sheet::XSheetConditionalEntry> xEntry;
428 long nCount = aEntries.size();
429 for (long i=0; i<nCount; i++)
430 if ( aName == lcl_GetEntryNameFromIndex(i) )
432 xEntry.set(GetObjectByIndex_Impl((sal_uInt16)i));
433 break;
436 if (xEntry.is())
437 return uno::makeAny(xEntry);
438 else
439 throw container::NoSuchElementException();
442 uno::Sequence<OUString> SAL_CALL ScTableConditionalFormat::getElementNames()
443 throw(uno::RuntimeException, std::exception)
445 SolarMutexGuard aGuard;
447 long nCount = aEntries.size();
448 uno::Sequence<OUString> aNames(nCount);
449 OUString* pArray = aNames.getArray();
450 for (long i=0; i<nCount; i++)
451 pArray[i] = lcl_GetEntryNameFromIndex(i);
453 return aNames;
456 sal_Bool SAL_CALL ScTableConditionalFormat::hasByName( const OUString& aName )
457 throw(uno::RuntimeException, std::exception)
459 SolarMutexGuard aGuard;
461 long nCount = aEntries.size();
462 for (long i=0; i<nCount; i++)
463 if ( aName == lcl_GetEntryNameFromIndex(i) )
464 return sal_True;
466 return false;
469 // XUnoTunnel
471 sal_Int64 SAL_CALL ScTableConditionalFormat::getSomething(
472 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException, std::exception)
474 if ( rId.getLength() == 16 &&
475 0 == memcmp( getUnoTunnelId().getConstArray(),
476 rId.getConstArray(), 16 ) )
478 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
480 return 0;
483 namespace
485 class theScTableConditionalFormatUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScTableConditionalFormatUnoTunnelId> {};
488 const uno::Sequence<sal_Int8>& ScTableConditionalFormat::getUnoTunnelId()
490 return theScTableConditionalFormatUnoTunnelId::get().getSeq();
493 ScTableConditionalFormat* ScTableConditionalFormat::getImplementation(const uno::Reference<sheet::XSheetConditionalEntries>& rObj)
495 ScTableConditionalFormat* pRet = NULL;
496 uno::Reference<lang::XUnoTunnel> xUT(rObj, uno::UNO_QUERY);
497 if (xUT.is())
498 pRet = reinterpret_cast<ScTableConditionalFormat*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
499 return pRet;
502 ScTableConditionalEntry::ScTableConditionalEntry(const ScCondFormatEntryItem& aItem) :
503 aData( aItem )
505 // #i113668# only store the settings, keep no reference to parent object
508 ScTableConditionalEntry::~ScTableConditionalEntry()
512 void ScTableConditionalEntry::GetData(ScCondFormatEntryItem& rData) const
514 rData = aData;
517 // XSheetCondition
519 sheet::ConditionOperator SAL_CALL ScTableConditionalEntry::getOperator()
520 throw(uno::RuntimeException, std::exception)
522 SolarMutexGuard aGuard;
523 return lcl_ConditionModeToOperator( aData.meMode );
526 void SAL_CALL ScTableConditionalEntry::setOperator( sheet::ConditionOperator nOperator )
527 throw(uno::RuntimeException, std::exception)
529 SolarMutexGuard aGuard;
530 aData.meMode = lcl_ConditionOperatorToMode( nOperator );
533 sal_Int32 SAL_CALL ScTableConditionalEntry::getConditionOperator()
534 throw(uno::RuntimeException, std::exception)
536 SolarMutexGuard aGuard;
537 return lcl_ConditionModeToOperatorNew( aData.meMode );
540 void SAL_CALL ScTableConditionalEntry::setConditionOperator( sal_Int32 nOperator )
541 throw(uno::RuntimeException, std::exception)
543 SolarMutexGuard aGuard;
544 aData.meMode = ScConditionEntry::GetModeFromApi( nOperator );
547 OUString SAL_CALL ScTableConditionalEntry::getFormula1() throw(uno::RuntimeException, std::exception)
549 SolarMutexGuard aGuard;
550 return aData.maExpr1;
553 void SAL_CALL ScTableConditionalEntry::setFormula1( const OUString& aFormula1 )
554 throw(uno::RuntimeException, std::exception)
556 SolarMutexGuard aGuard;
557 aData.maExpr1 = aFormula1;
560 OUString SAL_CALL ScTableConditionalEntry::getFormula2() throw(uno::RuntimeException, std::exception)
562 SolarMutexGuard aGuard;
563 return aData.maExpr2;
566 void SAL_CALL ScTableConditionalEntry::setFormula2( const OUString& aFormula2 )
567 throw(uno::RuntimeException, std::exception)
569 SolarMutexGuard aGuard;
570 aData.maExpr2 = aFormula2;
573 table::CellAddress SAL_CALL ScTableConditionalEntry::getSourcePosition() throw(uno::RuntimeException, std::exception)
575 SolarMutexGuard aGuard;
576 table::CellAddress aRet;
577 aRet.Column = aData.maPos.Col();
578 aRet.Row = aData.maPos.Row();
579 aRet.Sheet = aData.maPos.Tab();
580 return aRet;
583 void SAL_CALL ScTableConditionalEntry::setSourcePosition( const table::CellAddress& aSourcePosition )
584 throw(uno::RuntimeException, std::exception)
586 SolarMutexGuard aGuard;
587 aData.maPos.Set( (SCCOL)aSourcePosition.Column, (SCROW)aSourcePosition.Row, aSourcePosition.Sheet );
590 // XSheetConditionalEntry
592 OUString SAL_CALL ScTableConditionalEntry::getStyleName() throw(uno::RuntimeException, std::exception)
594 SolarMutexGuard aGuard;
595 return ScStyleNameConversion::DisplayToProgrammaticName( aData.maStyle, SFX_STYLE_FAMILY_PARA );
598 void SAL_CALL ScTableConditionalEntry::setStyleName( const OUString& aStyleName )
599 throw(uno::RuntimeException, std::exception)
601 SolarMutexGuard aGuard;
602 aData.maStyle = ScStyleNameConversion::ProgrammaticToDisplayName( aStyleName, SFX_STYLE_FAMILY_PARA );
605 ScTableValidationObj::ScTableValidationObj(ScDocument* pDoc, sal_uLong nKey,
606 const formula::FormulaGrammar::Grammar eGrammar) :
607 aPropSet( lcl_GetValidatePropertyMap() )
609 // Eintrag aus dem Dokument lesen...
611 bool bFound = false;
612 if ( pDoc && nKey )
614 const ScValidationData* pData = pDoc->GetValidationEntry( nKey );
615 if (pData)
617 nMode = sal::static_int_cast<sal_uInt16>( pData->GetOperation() );
618 aSrcPos = pData->GetValidSrcPos(); // valid pos for expressions
619 aExpr1 = pData->GetExpression( aSrcPos, 0, 0, eGrammar );
620 aExpr2 = pData->GetExpression( aSrcPos, 1, 0, eGrammar );
621 meGrammar1 = meGrammar2 = eGrammar;
622 nValMode = sal::static_int_cast<sal_uInt16>( pData->GetDataMode() );
623 bIgnoreBlank = pData->IsIgnoreBlank();
624 nShowList = pData->GetListType();
625 bShowInput = pData->GetInput( aInputTitle, aInputMessage );
626 ScValidErrorStyle eStyle;
627 bShowError = pData->GetErrMsg( aErrorTitle, aErrorMessage, eStyle );
628 nErrorStyle = sal::static_int_cast<sal_uInt16>( eStyle );
630 // During save to XML, sheet::ValidationType_ANY formulas are not
631 // saved, even if in the list, see
632 // ScMyValidationsContainer::GetCondition(), so shall not mark
633 // anything in use.
634 if (nValMode != SC_VALID_ANY && pDoc->IsInExternalReferenceMarking())
635 pData->MarkUsedExternalReferences();
637 bFound = true;
640 if (!bFound)
641 ClearData_Impl(); // Defaults
644 ScValidationData* ScTableValidationObj::CreateValidationData( ScDocument* pDoc,
645 formula::FormulaGrammar::Grammar eGrammar ) const
647 // ScValidationData = Core-Struktur
649 FormulaGrammar::Grammar eGrammar1 = lclResolveGrammar( eGrammar, meGrammar1 );
650 FormulaGrammar::Grammar eGrammar2 = lclResolveGrammar( eGrammar, meGrammar2 );
652 ScValidationData* pRet = new ScValidationData( (ScValidationMode)nValMode,
653 (ScConditionMode)nMode,
654 aExpr1, aExpr2, pDoc, aSrcPos,
655 maExprNmsp1, maExprNmsp2,
656 eGrammar1, eGrammar2 );
657 pRet->SetIgnoreBlank(bIgnoreBlank);
658 pRet->SetListType(nShowList);
660 if ( aTokens1.getLength() )
662 ScTokenArray aTokenArray;
663 if ( ScTokenConversion::ConvertToTokenArray(*pDoc, aTokenArray, aTokens1) )
664 pRet->SetFormula1(aTokenArray);
667 if ( aTokens2.getLength() )
669 ScTokenArray aTokenArray;
670 if ( ScTokenConversion::ConvertToTokenArray(*pDoc, aTokenArray, aTokens2) )
671 pRet->SetFormula2(aTokenArray);
674 // set strings for error / input even if disabled (and disable afterwards)
675 pRet->SetInput( aInputTitle, aInputMessage );
676 if (!bShowInput)
677 pRet->ResetInput();
678 pRet->SetError( aErrorTitle, aErrorMessage, (ScValidErrorStyle)nErrorStyle );
679 if (!bShowError)
680 pRet->ResetError();
682 if ( !aPosString.isEmpty() )
683 pRet->SetSrcString( aPosString );
685 return pRet;
688 void ScTableValidationObj::ClearData_Impl()
690 nMode = SC_COND_NONE;
691 nValMode = SC_VALID_ANY;
692 bIgnoreBlank = true;
693 nShowList = sheet::TableValidationVisibility::UNSORTED;
694 bShowInput = false;
695 bShowError = false;
696 nErrorStyle = SC_VALERR_STOP;
697 aSrcPos.Set(0,0,0);
698 aExpr1.clear();
699 aExpr2.clear();
700 maExprNmsp1.clear();
701 maExprNmsp2.clear();
702 meGrammar1 = meGrammar2 = FormulaGrammar::GRAM_UNSPECIFIED; // will be overridden when needed
703 aInputTitle.clear();
704 aInputMessage.clear();
705 aErrorTitle.clear();
706 aErrorMessage.clear();
709 ScTableValidationObj::~ScTableValidationObj()
713 // XSheetCondition
715 sheet::ConditionOperator SAL_CALL ScTableValidationObj::getOperator()
716 throw(uno::RuntimeException, std::exception)
718 SolarMutexGuard aGuard;
719 return lcl_ConditionModeToOperator( (ScConditionMode)nMode );
722 void SAL_CALL ScTableValidationObj::setOperator( sheet::ConditionOperator nOperator )
723 throw(uno::RuntimeException, std::exception)
725 SolarMutexGuard aGuard;
726 nMode = sal::static_int_cast<sal_uInt16>( lcl_ConditionOperatorToMode( nOperator ) );
729 sal_Int32 SAL_CALL ScTableValidationObj::getConditionOperator()
730 throw(uno::RuntimeException, std::exception)
732 SolarMutexGuard aGuard;
733 return lcl_ConditionModeToOperatorNew( (ScConditionMode)nMode );
736 void SAL_CALL ScTableValidationObj::setConditionOperator( sal_Int32 nOperator )
737 throw(uno::RuntimeException, std::exception)
739 SolarMutexGuard aGuard;
740 nMode = sal::static_int_cast<sal_uInt16>( ScConditionEntry::GetModeFromApi( nOperator ) );
743 OUString SAL_CALL ScTableValidationObj::getFormula1() throw(uno::RuntimeException, std::exception)
745 SolarMutexGuard aGuard;
746 return aExpr1;
749 void SAL_CALL ScTableValidationObj::setFormula1( const OUString& aFormula1 )
750 throw(uno::RuntimeException, std::exception)
752 SolarMutexGuard aGuard;
753 aExpr1 = aFormula1;
756 OUString SAL_CALL ScTableValidationObj::getFormula2() throw(uno::RuntimeException, std::exception)
758 SolarMutexGuard aGuard;
759 return aExpr2;
762 void SAL_CALL ScTableValidationObj::setFormula2( const OUString& aFormula2 )
763 throw(uno::RuntimeException, std::exception)
765 SolarMutexGuard aGuard;
766 aExpr2 = aFormula2;
769 table::CellAddress SAL_CALL ScTableValidationObj::getSourcePosition() throw(uno::RuntimeException, std::exception)
771 SolarMutexGuard aGuard;
772 table::CellAddress aRet;
773 aRet.Column = aSrcPos.Col();
774 aRet.Row = aSrcPos.Row();
775 aRet.Sheet = aSrcPos.Tab();
776 return aRet;
779 void SAL_CALL ScTableValidationObj::setSourcePosition( const table::CellAddress& aSourcePosition )
780 throw(uno::RuntimeException, std::exception)
782 SolarMutexGuard aGuard;
783 aSrcPos.Set( (SCCOL)aSourcePosition.Column, (SCROW)aSourcePosition.Row, aSourcePosition.Sheet );
786 uno::Sequence<sheet::FormulaToken> SAL_CALL ScTableValidationObj::getTokens( sal_Int32 nIndex )
787 throw(uno::RuntimeException,lang::IndexOutOfBoundsException, std::exception)
789 SolarMutexGuard aGuard;
790 if (nIndex >= 2 || nIndex < 0)
791 throw lang::IndexOutOfBoundsException();
793 return nIndex == 0 ? aTokens1 : aTokens2;
796 void SAL_CALL ScTableValidationObj::setTokens( sal_Int32 nIndex, const uno::Sequence<sheet::FormulaToken>& aTokens )
797 throw(uno::RuntimeException,lang::IndexOutOfBoundsException, std::exception)
799 SolarMutexGuard aGuard;
800 if (nIndex >= 2 || nIndex < 0)
801 throw lang::IndexOutOfBoundsException();
803 if (nIndex == 0)
805 aTokens1 = aTokens;
806 aExpr1.clear();
808 else if (nIndex == 1)
810 aTokens2 = aTokens;
811 aExpr2.clear();
815 sal_Int32 SAL_CALL ScTableValidationObj::getCount() throw(uno::RuntimeException, std::exception)
817 return 2;
820 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableValidationObj::getPropertySetInfo()
821 throw(uno::RuntimeException, std::exception)
823 SolarMutexGuard aGuard;
824 static uno::Reference<beans::XPropertySetInfo> aRef(
825 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
826 return aRef;
829 void SAL_CALL ScTableValidationObj::setPropertyValue(
830 const OUString& aPropertyName, const uno::Any& aValue )
831 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
832 lang::IllegalArgumentException, lang::WrappedTargetException,
833 uno::RuntimeException, std::exception)
835 SolarMutexGuard aGuard;
836 OUString aString(aPropertyName);
838 if ( aString == SC_UNONAME_SHOWINP ) bShowInput = ScUnoHelpFunctions::GetBoolFromAny( aValue );
839 else if ( aString == SC_UNONAME_SHOWERR ) bShowError = ScUnoHelpFunctions::GetBoolFromAny( aValue );
840 else if ( aString == SC_UNONAME_IGNOREBL ) bIgnoreBlank = ScUnoHelpFunctions::GetBoolFromAny( aValue );
841 else if ( aString == SC_UNONAME_SHOWLIST ) aValue >>= nShowList;
842 else if ( aString == SC_UNONAME_INPTITLE )
844 OUString aStrVal;
845 if ( aValue >>= aStrVal )
846 aInputTitle = aStrVal;
848 else if ( aString == SC_UNONAME_INPMESS )
850 OUString aStrVal;
851 if ( aValue >>= aStrVal )
852 aInputMessage = aStrVal;
854 else if ( aString == SC_UNONAME_ERRTITLE )
856 OUString aStrVal;
857 if ( aValue >>= aStrVal )
858 aErrorTitle = aStrVal;
860 else if ( aString == SC_UNONAME_ERRMESS )
862 OUString aStrVal;
863 if ( aValue >>= aStrVal )
864 aErrorMessage = aStrVal;
866 else if ( aString == SC_UNONAME_TYPE )
868 sheet::ValidationType eType = (sheet::ValidationType)
869 ScUnoHelpFunctions::GetEnumFromAny( aValue );
870 switch (eType)
872 case sheet::ValidationType_ANY: nValMode = SC_VALID_ANY; break;
873 case sheet::ValidationType_WHOLE: nValMode = SC_VALID_WHOLE; break;
874 case sheet::ValidationType_DECIMAL: nValMode = SC_VALID_DECIMAL; break;
875 case sheet::ValidationType_DATE: nValMode = SC_VALID_DATE; break;
876 case sheet::ValidationType_TIME: nValMode = SC_VALID_TIME; break;
877 case sheet::ValidationType_TEXT_LEN: nValMode = SC_VALID_TEXTLEN; break;
878 case sheet::ValidationType_LIST: nValMode = SC_VALID_LIST; break;
879 case sheet::ValidationType_CUSTOM: nValMode = SC_VALID_CUSTOM; break;
880 default:
882 // added to avoid warnings
886 else if ( aString == SC_UNONAME_ERRALSTY )
888 sheet::ValidationAlertStyle eStyle = (sheet::ValidationAlertStyle)
889 ScUnoHelpFunctions::GetEnumFromAny( aValue );
890 switch (eStyle)
892 case sheet::ValidationAlertStyle_STOP: nErrorStyle = SC_VALERR_STOP; break;
893 case sheet::ValidationAlertStyle_WARNING: nErrorStyle = SC_VALERR_WARNING; break;
894 case sheet::ValidationAlertStyle_INFO: nErrorStyle = SC_VALERR_INFO; break;
895 case sheet::ValidationAlertStyle_MACRO: nErrorStyle = SC_VALERR_MACRO; break;
896 default:
898 // added to avoid warnings
902 else if ( aString == SC_UNONAME_SOURCESTR )
904 // internal - only for XML filter, not in PropertySetInfo, only set
906 OUString aStrVal;
907 if ( aValue >>= aStrVal )
908 aPosString = aStrVal;
910 else if ( aString == SC_UNONAME_FORMULANMSP1 )
912 // internal - only for XML filter, not in PropertySetInfo, only set
914 OUString aStrVal;
915 if ( aValue >>= aStrVal )
916 maExprNmsp1 = aStrVal;
918 else if ( aString == SC_UNONAME_FORMULANMSP2 )
920 // internal - only for XML filter, not in PropertySetInfo, only set
922 OUString aStrVal;
923 if ( aValue >>= aStrVal )
924 maExprNmsp2 = aStrVal;
926 else if ( aString == SC_UNONAME_GRAMMAR1 )
928 // internal - only for XML filter, not in PropertySetInfo, only set
930 sal_Int32 nVal = 0;
931 if ( aValue >>= nVal )
932 meGrammar1 = static_cast< FormulaGrammar::Grammar >(nVal);
934 else if ( aString == SC_UNONAME_GRAMMAR2 )
936 // internal - only for XML filter, not in PropertySetInfo, only set
938 sal_Int32 nVal = 0;
939 if ( aValue >>= nVal )
940 meGrammar2 = static_cast< FormulaGrammar::Grammar >(nVal);
944 uno::Any SAL_CALL ScTableValidationObj::getPropertyValue( const OUString& aPropertyName )
945 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
946 uno::RuntimeException, std::exception)
948 SolarMutexGuard aGuard;
949 OUString aString(aPropertyName);
950 uno::Any aRet;
952 if ( aString == SC_UNONAME_SHOWINP ) ScUnoHelpFunctions::SetBoolInAny( aRet, bShowInput );
953 else if ( aString == SC_UNONAME_SHOWERR ) ScUnoHelpFunctions::SetBoolInAny( aRet, bShowError );
954 else if ( aString == SC_UNONAME_IGNOREBL ) ScUnoHelpFunctions::SetBoolInAny( aRet, bIgnoreBlank );
955 else if ( aString == SC_UNONAME_SHOWLIST ) aRet <<= nShowList;
956 else if ( aString == SC_UNONAME_INPTITLE ) aRet <<= OUString( aInputTitle );
957 else if ( aString == SC_UNONAME_INPMESS ) aRet <<= OUString( aInputMessage );
958 else if ( aString == SC_UNONAME_ERRTITLE ) aRet <<= OUString( aErrorTitle );
959 else if ( aString == SC_UNONAME_ERRMESS ) aRet <<= OUString( aErrorMessage );
960 else if ( aString == SC_UNONAME_TYPE )
962 sheet::ValidationType eType = sheet::ValidationType_ANY;
963 switch (nValMode)
965 case SC_VALID_ANY: eType = sheet::ValidationType_ANY; break;
966 case SC_VALID_WHOLE: eType = sheet::ValidationType_WHOLE; break;
967 case SC_VALID_DECIMAL: eType = sheet::ValidationType_DECIMAL; break;
968 case SC_VALID_DATE: eType = sheet::ValidationType_DATE; break;
969 case SC_VALID_TIME: eType = sheet::ValidationType_TIME; break;
970 case SC_VALID_TEXTLEN: eType = sheet::ValidationType_TEXT_LEN; break;
971 case SC_VALID_LIST: eType = sheet::ValidationType_LIST; break;
972 case SC_VALID_CUSTOM: eType = sheet::ValidationType_CUSTOM; break;
974 aRet <<= eType;
976 else if ( aString == SC_UNONAME_ERRALSTY )
978 sheet::ValidationAlertStyle eStyle = sheet::ValidationAlertStyle_STOP;
979 switch (nErrorStyle)
981 case SC_VALERR_STOP: eStyle = sheet::ValidationAlertStyle_STOP; break;
982 case SC_VALERR_WARNING: eStyle = sheet::ValidationAlertStyle_WARNING; break;
983 case SC_VALERR_INFO: eStyle = sheet::ValidationAlertStyle_INFO; break;
984 case SC_VALERR_MACRO: eStyle = sheet::ValidationAlertStyle_MACRO; break;
986 aRet <<= eStyle;
989 return aRet;
992 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableValidationObj )
994 // XUnoTunnel
996 sal_Int64 SAL_CALL ScTableValidationObj::getSomething(
997 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException, std::exception)
999 if ( rId.getLength() == 16 &&
1000 0 == memcmp( getUnoTunnelId().getConstArray(),
1001 rId.getConstArray(), 16 ) )
1003 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
1005 return 0;
1008 namespace
1010 class theScTableValidationObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScTableValidationObjUnoTunnelId> {};
1013 const uno::Sequence<sal_Int8>& ScTableValidationObj::getUnoTunnelId()
1015 return theScTableValidationObjUnoTunnelId::get().getSeq();
1018 ScTableValidationObj* ScTableValidationObj::getImplementation(const uno::Reference<beans::XPropertySet>& rObj)
1020 ScTableValidationObj* pRet = NULL;
1021 uno::Reference<lang::XUnoTunnel> xUT(rObj, uno::UNO_QUERY);
1022 if (xUT.is())
1023 pRet = reinterpret_cast<ScTableValidationObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
1024 return pRet;
1027 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */