Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / unoobj / fmtuno.cxx
blob0084fa3f23a5107f836254295a5925110e7fb283
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 .
21 #include <boost/bind.hpp>
23 #include <vcl/svapp.hxx>
24 #include <comphelper/servicehelper.hxx>
26 #include <com/sun/star/sheet/ValidationAlertStyle.hpp>
27 #include <com/sun/star/sheet/ValidationType.hpp>
28 #include <com/sun/star/sheet/TableValidationVisibility.hpp>
30 #include "fmtuno.hxx"
31 #include "miscuno.hxx"
32 #include "validat.hxx"
33 #include "document.hxx"
34 #include "unonames.hxx"
35 #include "styleuno.hxx"
36 #include "tokenarray.hxx"
37 #include "tokenuno.hxx"
38 #include "stylehelper.hxx"
40 using namespace ::com::sun::star;
41 using namespace ::formula;
43 //------------------------------------------------------------------------
45 // Map nur fuer PropertySetInfo
47 static const SfxItemPropertyMapEntry* lcl_GetValidatePropertyMap()
49 static const SfxItemPropertyMapEntry aValidatePropertyMap_Impl[] =
51 {MAP_CHAR_LEN(SC_UNONAME_ERRALSTY), 0, &getCppuType((sheet::ValidationAlertStyle*)0), 0, 0},
52 {MAP_CHAR_LEN(SC_UNONAME_ERRMESS), 0, &getCppuType((OUString*)0), 0, 0},
53 {MAP_CHAR_LEN(SC_UNONAME_ERRTITLE), 0, &getCppuType((OUString*)0), 0, 0},
54 {MAP_CHAR_LEN(SC_UNONAME_IGNOREBL), 0, &getBooleanCppuType(), 0, 0},
55 {MAP_CHAR_LEN(SC_UNONAME_INPMESS), 0, &getCppuType((OUString*)0), 0, 0},
56 {MAP_CHAR_LEN(SC_UNONAME_INPTITLE), 0, &getCppuType((OUString*)0), 0, 0},
57 {MAP_CHAR_LEN(SC_UNONAME_SHOWERR), 0, &getBooleanCppuType(), 0, 0},
58 {MAP_CHAR_LEN(SC_UNONAME_SHOWINP), 0, &getBooleanCppuType(), 0, 0},
59 {MAP_CHAR_LEN(SC_UNONAME_SHOWLIST), 0, &getCppuType((sal_Int16*)0), 0, 0},
60 {MAP_CHAR_LEN(SC_UNONAME_TYPE), 0, &getCppuType((sheet::ValidationType*)0), 0, 0},
61 {0,0,0,0,0,0}
63 return aValidatePropertyMap_Impl;
66 //------------------------------------------------------------------------
68 SC_SIMPLE_SERVICE_INFO( ScTableConditionalEntry, "ScTableConditionalEntry", "com.sun.star.sheet.TableConditionalEntry" )
69 SC_SIMPLE_SERVICE_INFO( ScTableConditionalFormat, "ScTableConditionalFormat", "com.sun.star.sheet.TableConditionalFormat" )
70 SC_SIMPLE_SERVICE_INFO( ScTableValidationObj, "ScTableValidationObj", "com.sun.star.sheet.TableValidation" )
72 //------------------------------------------------------------------------
74 static sal_Int32 lcl_ConditionModeToOperatorNew( ScConditionMode eMode )
76 sal_Int32 eOper = sheet::ConditionOperator2::NONE;
77 switch (eMode)
79 case SC_COND_EQUAL: eOper = sheet::ConditionOperator2::EQUAL; break;
80 case SC_COND_LESS: eOper = sheet::ConditionOperator2::LESS; break;
81 case SC_COND_GREATER: eOper = sheet::ConditionOperator2::GREATER; break;
82 case SC_COND_EQLESS: eOper = sheet::ConditionOperator2::LESS_EQUAL; break;
83 case SC_COND_EQGREATER: eOper = sheet::ConditionOperator2::GREATER_EQUAL; break;
84 case SC_COND_NOTEQUAL: eOper = sheet::ConditionOperator2::NOT_EQUAL; break;
85 case SC_COND_BETWEEN: eOper = sheet::ConditionOperator2::BETWEEN; break;
86 case SC_COND_NOTBETWEEN: eOper = sheet::ConditionOperator2::NOT_BETWEEN; break;
87 case SC_COND_DIRECT: eOper = sheet::ConditionOperator2::FORMULA; break;
88 case SC_COND_DUPLICATE: eOper = sheet::ConditionOperator2::DUPLICATE; break;
89 default:
91 // added to avoid warnings
94 return eOper;
97 static sheet::ConditionOperator lcl_ConditionModeToOperator( ScConditionMode eMode )
99 sheet::ConditionOperator eOper = sheet::ConditionOperator_NONE;
100 switch (eMode)
102 case SC_COND_EQUAL: eOper = sheet::ConditionOperator_EQUAL; break;
103 case SC_COND_LESS: eOper = sheet::ConditionOperator_LESS; break;
104 case SC_COND_GREATER: eOper = sheet::ConditionOperator_GREATER; break;
105 case SC_COND_EQLESS: eOper = sheet::ConditionOperator_LESS_EQUAL; break;
106 case SC_COND_EQGREATER: eOper = sheet::ConditionOperator_GREATER_EQUAL; break;
107 case SC_COND_NOTEQUAL: eOper = sheet::ConditionOperator_NOT_EQUAL; break;
108 case SC_COND_BETWEEN: eOper = sheet::ConditionOperator_BETWEEN; break;
109 case SC_COND_NOTBETWEEN: eOper = sheet::ConditionOperator_NOT_BETWEEN; break;
110 case SC_COND_DIRECT: eOper = sheet::ConditionOperator_FORMULA; break;
111 default:
113 // added to avoid warnings
116 return eOper;
119 static ScConditionMode lcl_ConditionOperatorToMode( sheet::ConditionOperator eOper )
121 ScConditionMode eMode = SC_COND_NONE;
122 switch (eOper)
124 case sheet::ConditionOperator_EQUAL: eMode = SC_COND_EQUAL; break;
125 case sheet::ConditionOperator_LESS: eMode = SC_COND_LESS; break;
126 case sheet::ConditionOperator_GREATER: eMode = SC_COND_GREATER; break;
127 case sheet::ConditionOperator_LESS_EQUAL: eMode = SC_COND_EQLESS; break;
128 case sheet::ConditionOperator_GREATER_EQUAL: eMode = SC_COND_EQGREATER; break;
129 case sheet::ConditionOperator_NOT_EQUAL: eMode = SC_COND_NOTEQUAL; break;
130 case sheet::ConditionOperator_BETWEEN: eMode = SC_COND_BETWEEN; break;
131 case sheet::ConditionOperator_NOT_BETWEEN: eMode = SC_COND_NOTBETWEEN; break;
132 case sheet::ConditionOperator_FORMULA: eMode = SC_COND_DIRECT; break;
133 default:
135 // added to avoid warnings
138 return eMode;
141 //------------------------------------------------------------------------
143 ScCondFormatEntryItem::ScCondFormatEntryItem() :
144 meGrammar1( FormulaGrammar::GRAM_UNSPECIFIED ),
145 meGrammar2( FormulaGrammar::GRAM_UNSPECIFIED ),
146 meMode( SC_COND_NONE )
150 //------------------------------------------------------------------------
152 ScTableConditionalFormat::ScTableConditionalFormat(
153 ScDocument* pDoc, sal_uLong nKey, SCTAB nTab, FormulaGrammar::Grammar eGrammar)
155 // Eintrag aus dem Dokument lesen...
157 if ( pDoc && nKey )
159 ScConditionalFormatList* pList = pDoc->GetCondFormList(nTab);
160 if (pList)
162 const ScConditionalFormat* pFormat = pList->GetFormat( nKey );
163 if (pFormat)
165 // During save to XML.
166 if (pDoc->IsInExternalReferenceMarking())
167 pFormat->MarkUsedExternalReferences();
169 size_t nEntryCount = pFormat->size();
170 for (size_t i=0; i<nEntryCount; i++)
172 ScCondFormatEntryItem aItem;
173 const ScFormatEntry* pFrmtEntry = pFormat->GetEntry(i);
174 if(pFrmtEntry->GetType() != condformat::CONDITION)
175 continue;
177 const ScCondFormatEntry* pFormatEntry = static_cast<const ScCondFormatEntry*>(pFrmtEntry);
178 aItem.meMode = pFormatEntry->GetOperation();
179 aItem.maPos = pFormatEntry->GetValidSrcPos();
180 aItem.maExpr1 = pFormatEntry->GetExpression(aItem.maPos, 0, 0, eGrammar);
181 aItem.maExpr2 = pFormatEntry->GetExpression(aItem.maPos, 1, 0, eGrammar);
182 aItem.meGrammar1 = aItem.meGrammar2 = eGrammar;
183 aItem.maStyle = pFormatEntry->GetStyle();
185 AddEntry_Impl(aItem);
192 namespace {
194 FormulaGrammar::Grammar lclResolveGrammar( FormulaGrammar::Grammar eExtGrammar, FormulaGrammar::Grammar eIntGrammar )
196 if( eExtGrammar != FormulaGrammar::GRAM_UNSPECIFIED )
197 return eExtGrammar;
198 OSL_ENSURE( eIntGrammar != FormulaGrammar::GRAM_UNSPECIFIED, "lclResolveGrammar - unspecified grammar, using GRAM_PODF_A1" );
199 return (eIntGrammar == FormulaGrammar::GRAM_UNSPECIFIED) ? FormulaGrammar::GRAM_PODF_A1 : eIntGrammar;
202 } // namespace
204 void ScTableConditionalFormat::FillFormat( ScConditionalFormat& rFormat,
205 ScDocument* pDoc, FormulaGrammar::Grammar eGrammar) const
207 // ScConditionalFormat = Core-Struktur, muss leer sein
209 OSL_ENSURE( rFormat.IsEmpty(), "FillFormat: Format nicht leer" );
211 std::vector<ScTableConditionalEntry*>::const_iterator iter;
212 for (iter = aEntries.begin(); iter != aEntries.end(); ++iter)
214 ScCondFormatEntryItem aData;
215 (*iter)->GetData(aData);
217 FormulaGrammar::Grammar eGrammar1 = lclResolveGrammar( eGrammar, aData.meGrammar1 );
218 FormulaGrammar::Grammar eGrammar2 = lclResolveGrammar( eGrammar, aData.meGrammar2 );
220 ScCondFormatEntry* pCoreEntry = new ScCondFormatEntry( aData.meMode, aData.maExpr1, aData.maExpr2,
221 pDoc, aData.maPos, aData.maStyle, aData.maExprNmsp1, aData.maExprNmsp2, eGrammar1, eGrammar2 );
223 if ( !aData.maPosStr.isEmpty() )
224 pCoreEntry->SetSrcString( aData.maPosStr );
226 if ( aData.maTokens1.getLength() )
228 ScTokenArray aTokenArray;
229 if ( ScTokenConversion::ConvertToTokenArray(*pDoc, aTokenArray, aData.maTokens1) )
230 pCoreEntry->SetFormula1(aTokenArray);
233 if ( aData.maTokens2.getLength() )
235 ScTokenArray aTokenArray;
236 if ( ScTokenConversion::ConvertToTokenArray(*pDoc, aTokenArray, aData.maTokens2) )
237 pCoreEntry->SetFormula2(aTokenArray);
239 rFormat.AddEntry( pCoreEntry );
243 ScTableConditionalFormat::~ScTableConditionalFormat()
245 std::for_each(aEntries.begin(),aEntries.end(),boost::bind(&ScTableConditionalEntry::release,_1));
248 void ScTableConditionalFormat::AddEntry_Impl(const ScCondFormatEntryItem& aEntry)
250 ScTableConditionalEntry* pNew = new ScTableConditionalEntry(aEntry);
251 pNew->acquire();
252 aEntries.push_back(pNew);
255 // XSheetConditionalFormat
257 ScTableConditionalEntry* ScTableConditionalFormat::GetObjectByIndex_Impl(sal_uInt16 nIndex) const
259 return nIndex < aEntries.size() ? aEntries[nIndex] : NULL;
262 void SAL_CALL ScTableConditionalFormat::addNew(
263 const uno::Sequence<beans::PropertyValue >& aConditionalEntry )
264 throw(uno::RuntimeException)
266 SolarMutexGuard aGuard;
267 ScCondFormatEntryItem aEntry;
268 aEntry.meMode = SC_COND_NONE;
270 const beans::PropertyValue* pPropArray = aConditionalEntry.getConstArray();
271 long nPropCount = aConditionalEntry.getLength();
272 for (long i = 0; i < nPropCount; i++)
274 const beans::PropertyValue& rProp = pPropArray[i];
276 if ( rProp.Name == SC_UNONAME_OPERATOR )
278 sal_Int32 eOper = ScUnoHelpFunctions::GetEnumFromAny( rProp.Value );
279 aEntry.meMode = ScConditionEntry::GetModeFromApi( eOper );
281 else if ( rProp.Name == SC_UNONAME_FORMULA1 )
283 OUString aStrVal;
284 uno::Sequence<sheet::FormulaToken> aTokens;
285 if ( rProp.Value >>= aStrVal )
286 aEntry.maExpr1 = aStrVal;
287 else if ( rProp.Value >>= aTokens )
289 aEntry.maExpr1 = "";
290 aEntry.maTokens1 = aTokens;
293 else if ( rProp.Name == SC_UNONAME_FORMULA2 )
295 OUString aStrVal;
296 uno::Sequence<sheet::FormulaToken> aTokens;
297 if ( rProp.Value >>= aStrVal )
298 aEntry.maExpr2 = aStrVal;
299 else if ( rProp.Value >>= aTokens )
301 aEntry.maExpr2 = "";
302 aEntry.maTokens2 = aTokens;
305 else if ( rProp.Name == SC_UNONAME_SOURCEPOS )
307 table::CellAddress aAddress;
308 if ( rProp.Value >>= aAddress )
309 aEntry.maPos = ScAddress( (SCCOL)aAddress.Column, (SCROW)aAddress.Row, aAddress.Sheet );
311 else if ( rProp.Name == SC_UNONAME_SOURCESTR )
313 OUString aStrVal;
314 if ( rProp.Value >>= aStrVal )
315 aEntry.maPosStr = aStrVal;
317 else if ( rProp.Name == SC_UNONAME_STYLENAME )
319 OUString aStrVal;
320 if ( rProp.Value >>= aStrVal )
321 aEntry.maStyle = ScStyleNameConversion::ProgrammaticToDisplayName(
322 aStrVal, SFX_STYLE_FAMILY_PARA );
324 else if ( rProp.Name == SC_UNONAME_FORMULANMSP1 )
326 OUString aStrVal;
327 if ( rProp.Value >>= aStrVal )
328 aEntry.maExprNmsp1 = aStrVal;
330 else if ( rProp.Name == SC_UNONAME_FORMULANMSP2 )
332 OUString aStrVal;
333 if ( rProp.Value >>= aStrVal )
334 aEntry.maExprNmsp2 = aStrVal;
336 else if ( rProp.Name == SC_UNONAME_GRAMMAR1 )
338 sal_Int32 nVal = 0;
339 if ( rProp.Value >>= nVal )
340 aEntry.meGrammar1 = static_cast< FormulaGrammar::Grammar >( nVal );
342 else if ( rProp.Name == SC_UNONAME_GRAMMAR2 )
344 sal_Int32 nVal = 0;
345 if ( rProp.Value >>= nVal )
346 aEntry.meGrammar2 = static_cast< FormulaGrammar::Grammar >( nVal );
348 else
350 OSL_FAIL("falsche Property");
351 //! Exception...
355 AddEntry_Impl(aEntry);
358 void SAL_CALL ScTableConditionalFormat::removeByIndex( sal_Int32 nIndex )
359 throw(uno::RuntimeException)
361 SolarMutexGuard aGuard;
363 if (nIndex < static_cast<sal_Int32>(aEntries.size()))
365 std::vector<ScTableConditionalEntry*>::iterator iter = aEntries.begin()+nIndex;
367 (*iter)->release();
368 aEntries.erase(iter);
372 void SAL_CALL ScTableConditionalFormat::clear() throw(uno::RuntimeException)
374 SolarMutexGuard aGuard;
375 std::for_each(aEntries.begin(),aEntries.end(),
376 boost::bind(&ScTableConditionalEntry::release,_1));
378 aEntries.clear();
381 // XEnumerationAccess
383 uno::Reference<container::XEnumeration> SAL_CALL ScTableConditionalFormat::createEnumeration()
384 throw(uno::RuntimeException)
386 SolarMutexGuard aGuard;
387 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.TableConditionalEntryEnumeration"));
390 // XIndexAccess
392 sal_Int32 SAL_CALL ScTableConditionalFormat::getCount() throw(uno::RuntimeException)
394 SolarMutexGuard aGuard;
395 return aEntries.size();
398 uno::Any SAL_CALL ScTableConditionalFormat::getByIndex( sal_Int32 nIndex )
399 throw(lang::IndexOutOfBoundsException,
400 lang::WrappedTargetException, uno::RuntimeException)
402 SolarMutexGuard aGuard;
403 uno::Reference<sheet::XSheetConditionalEntry> xEntry(GetObjectByIndex_Impl((sal_uInt16)nIndex));
404 if (xEntry.is())
405 return uno::makeAny(xEntry);
406 else
407 throw lang::IndexOutOfBoundsException();
410 uno::Type SAL_CALL ScTableConditionalFormat::getElementType() throw(uno::RuntimeException)
412 SolarMutexGuard aGuard;
413 return getCppuType((uno::Reference<sheet::XSheetConditionalEntry>*)0);
416 sal_Bool SAL_CALL ScTableConditionalFormat::hasElements() throw(uno::RuntimeException)
418 SolarMutexGuard aGuard;
419 return ( getCount() != 0 );
422 // conditional format entries have no real names
423 // -> generate name from index
425 static OUString lcl_GetEntryNameFromIndex( sal_Int32 nIndex )
427 OUString aRet( "Entry" );
428 aRet += OUString::number( nIndex );
429 return aRet;
432 uno::Any SAL_CALL ScTableConditionalFormat::getByName( const OUString& aName )
433 throw(container::NoSuchElementException,
434 lang::WrappedTargetException, uno::RuntimeException)
436 SolarMutexGuard aGuard;
438 uno::Reference<sheet::XSheetConditionalEntry> xEntry;
439 long nCount = aEntries.size();
440 for (long i=0; i<nCount; i++)
441 if ( aName == lcl_GetEntryNameFromIndex(i) )
443 xEntry.set(GetObjectByIndex_Impl((sal_uInt16)i));
444 break;
447 if (xEntry.is())
448 return uno::makeAny(xEntry);
449 else
450 throw container::NoSuchElementException();
453 uno::Sequence<OUString> SAL_CALL ScTableConditionalFormat::getElementNames()
454 throw(uno::RuntimeException)
456 SolarMutexGuard aGuard;
458 long nCount = aEntries.size();
459 uno::Sequence<OUString> aNames(nCount);
460 OUString* pArray = aNames.getArray();
461 for (long i=0; i<nCount; i++)
462 pArray[i] = lcl_GetEntryNameFromIndex(i);
464 return aNames;
467 sal_Bool SAL_CALL ScTableConditionalFormat::hasByName( const OUString& aName )
468 throw(uno::RuntimeException)
470 SolarMutexGuard aGuard;
472 long nCount = aEntries.size();
473 for (long i=0; i<nCount; i++)
474 if ( aName == lcl_GetEntryNameFromIndex(i) )
475 return sal_True;
477 return false;
480 // XUnoTunnel
482 sal_Int64 SAL_CALL ScTableConditionalFormat::getSomething(
483 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
485 if ( rId.getLength() == 16 &&
486 0 == memcmp( getUnoTunnelId().getConstArray(),
487 rId.getConstArray(), 16 ) )
489 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
491 return 0;
494 namespace
496 class theScTableConditionalFormatUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScTableConditionalFormatUnoTunnelId> {};
499 const uno::Sequence<sal_Int8>& ScTableConditionalFormat::getUnoTunnelId()
501 return theScTableConditionalFormatUnoTunnelId::get().getSeq();
504 ScTableConditionalFormat* ScTableConditionalFormat::getImplementation(
505 const uno::Reference<sheet::XSheetConditionalEntries> xObj )
507 ScTableConditionalFormat* pRet = NULL;
508 uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
509 if (xUT.is())
510 pRet = reinterpret_cast<ScTableConditionalFormat*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
511 return pRet;
514 //------------------------------------------------------------------------
516 ScTableConditionalEntry::ScTableConditionalEntry(const ScCondFormatEntryItem& aItem) :
517 aData( aItem )
519 // #i113668# only store the settings, keep no reference to parent object
522 ScTableConditionalEntry::~ScTableConditionalEntry()
526 void ScTableConditionalEntry::GetData(ScCondFormatEntryItem& rData) const
528 rData = aData;
531 // XSheetCondition
533 sheet::ConditionOperator SAL_CALL ScTableConditionalEntry::getOperator()
534 throw(uno::RuntimeException)
536 SolarMutexGuard aGuard;
537 return lcl_ConditionModeToOperator( aData.meMode );
540 void SAL_CALL ScTableConditionalEntry::setOperator( sheet::ConditionOperator nOperator )
541 throw(uno::RuntimeException)
543 SolarMutexGuard aGuard;
544 aData.meMode = lcl_ConditionOperatorToMode( nOperator );
547 sal_Int32 SAL_CALL ScTableConditionalEntry::getConditionOperator()
548 throw(uno::RuntimeException)
550 SolarMutexGuard aGuard;
551 return lcl_ConditionModeToOperatorNew( aData.meMode );
554 void SAL_CALL ScTableConditionalEntry::setConditionOperator( sal_Int32 nOperator )
555 throw(uno::RuntimeException)
557 SolarMutexGuard aGuard;
558 aData.meMode = ScConditionEntry::GetModeFromApi( nOperator );
561 OUString SAL_CALL ScTableConditionalEntry::getFormula1() throw(uno::RuntimeException)
563 SolarMutexGuard aGuard;
564 return aData.maExpr1;
567 void SAL_CALL ScTableConditionalEntry::setFormula1( const OUString& aFormula1 )
568 throw(uno::RuntimeException)
570 SolarMutexGuard aGuard;
571 aData.maExpr1 = aFormula1;
574 OUString SAL_CALL ScTableConditionalEntry::getFormula2() throw(uno::RuntimeException)
576 SolarMutexGuard aGuard;
577 return aData.maExpr2;
580 void SAL_CALL ScTableConditionalEntry::setFormula2( const OUString& aFormula2 )
581 throw(uno::RuntimeException)
583 SolarMutexGuard aGuard;
584 aData.maExpr2 = aFormula2;
587 table::CellAddress SAL_CALL ScTableConditionalEntry::getSourcePosition() throw(uno::RuntimeException)
589 SolarMutexGuard aGuard;
590 table::CellAddress aRet;
591 aRet.Column = aData.maPos.Col();
592 aRet.Row = aData.maPos.Row();
593 aRet.Sheet = aData.maPos.Tab();
594 return aRet;
597 void SAL_CALL ScTableConditionalEntry::setSourcePosition( const table::CellAddress& aSourcePosition )
598 throw(uno::RuntimeException)
600 SolarMutexGuard aGuard;
601 aData.maPos.Set( (SCCOL)aSourcePosition.Column, (SCROW)aSourcePosition.Row, aSourcePosition.Sheet );
604 // XSheetConditionalEntry
606 OUString SAL_CALL ScTableConditionalEntry::getStyleName() throw(uno::RuntimeException)
608 SolarMutexGuard aGuard;
609 return ScStyleNameConversion::DisplayToProgrammaticName( aData.maStyle, SFX_STYLE_FAMILY_PARA );
612 void SAL_CALL ScTableConditionalEntry::setStyleName( const OUString& aStyleName )
613 throw(uno::RuntimeException)
615 SolarMutexGuard aGuard;
616 aData.maStyle = ScStyleNameConversion::ProgrammaticToDisplayName( aStyleName, SFX_STYLE_FAMILY_PARA );
619 //------------------------------------------------------------------------
621 ScTableValidationObj::ScTableValidationObj(ScDocument* pDoc, sal_uLong nKey,
622 const formula::FormulaGrammar::Grammar eGrammar) :
623 aPropSet( lcl_GetValidatePropertyMap() )
625 // Eintrag aus dem Dokument lesen...
627 bool bFound = false;
628 if ( pDoc && nKey )
630 const ScValidationData* pData = pDoc->GetValidationEntry( nKey );
631 if (pData)
633 nMode = sal::static_int_cast<sal_uInt16>( pData->GetOperation() );
634 aSrcPos = pData->GetValidSrcPos(); // valid pos for expressions
635 aExpr1 = pData->GetExpression( aSrcPos, 0, 0, eGrammar );
636 aExpr2 = pData->GetExpression( aSrcPos, 1, 0, eGrammar );
637 meGrammar1 = meGrammar2 = eGrammar;
638 nValMode = sal::static_int_cast<sal_uInt16>( pData->GetDataMode() );
639 bIgnoreBlank = pData->IsIgnoreBlank();
640 nShowList = pData->GetListType();
641 bShowInput = pData->GetInput( aInputTitle, aInputMessage );
642 ScValidErrorStyle eStyle;
643 bShowError = pData->GetErrMsg( aErrorTitle, aErrorMessage, eStyle );
644 nErrorStyle = sal::static_int_cast<sal_uInt16>( eStyle );
646 // During save to XML, sheet::ValidationType_ANY formulas are not
647 // saved, even if in the list, see
648 // ScMyValidationsContainer::GetCondition(), so shall not mark
649 // anything in use.
650 if (nValMode != SC_VALID_ANY && pDoc->IsInExternalReferenceMarking())
651 pData->MarkUsedExternalReferences();
653 bFound = true;
656 if (!bFound)
657 ClearData_Impl(); // Defaults
660 ScValidationData* ScTableValidationObj::CreateValidationData( ScDocument* pDoc,
661 formula::FormulaGrammar::Grammar eGrammar ) const
663 // ScValidationData = Core-Struktur
665 FormulaGrammar::Grammar eGrammar1 = lclResolveGrammar( eGrammar, meGrammar1 );
666 FormulaGrammar::Grammar eGrammar2 = lclResolveGrammar( eGrammar, meGrammar2 );
668 ScValidationData* pRet = new ScValidationData( (ScValidationMode)nValMode,
669 (ScConditionMode)nMode,
670 aExpr1, aExpr2, pDoc, aSrcPos,
671 maExprNmsp1, maExprNmsp2,
672 eGrammar1, eGrammar2 );
673 pRet->SetIgnoreBlank(bIgnoreBlank);
674 pRet->SetListType(nShowList);
676 if ( aTokens1.getLength() )
678 ScTokenArray aTokenArray;
679 if ( ScTokenConversion::ConvertToTokenArray(*pDoc, aTokenArray, aTokens1) )
680 pRet->SetFormula1(aTokenArray);
683 if ( aTokens2.getLength() )
685 ScTokenArray aTokenArray;
686 if ( ScTokenConversion::ConvertToTokenArray(*pDoc, aTokenArray, aTokens2) )
687 pRet->SetFormula2(aTokenArray);
690 // set strings for error / input even if disabled (and disable afterwards)
691 pRet->SetInput( aInputTitle, aInputMessage );
692 if (!bShowInput)
693 pRet->ResetInput();
694 pRet->SetError( aErrorTitle, aErrorMessage, (ScValidErrorStyle)nErrorStyle );
695 if (!bShowError)
696 pRet->ResetError();
698 if ( !aPosString.isEmpty() )
699 pRet->SetSrcString( aPosString );
701 return pRet;
704 void ScTableValidationObj::ClearData_Impl()
706 nMode = SC_COND_NONE;
707 nValMode = SC_VALID_ANY;
708 bIgnoreBlank = sal_True;
709 nShowList = sheet::TableValidationVisibility::UNSORTED;
710 bShowInput = false;
711 bShowError = false;
712 nErrorStyle = SC_VALERR_STOP;
713 aSrcPos.Set(0,0,0);
714 aExpr1 = "";
715 aExpr2 = "";
716 maExprNmsp1 = "";
717 maExprNmsp2 = "";
718 meGrammar1 = meGrammar2 = FormulaGrammar::GRAM_UNSPECIFIED; // will be overriden when needed
719 aInputTitle = OUString();
720 aInputMessage = OUString();
721 aErrorTitle = OUString();
722 aErrorMessage = OUString();
725 ScTableValidationObj::~ScTableValidationObj()
729 // XSheetCondition
731 sheet::ConditionOperator SAL_CALL ScTableValidationObj::getOperator()
732 throw(uno::RuntimeException)
734 SolarMutexGuard aGuard;
735 return lcl_ConditionModeToOperator( (ScConditionMode)nMode );
738 void SAL_CALL ScTableValidationObj::setOperator( sheet::ConditionOperator nOperator )
739 throw(uno::RuntimeException)
741 SolarMutexGuard aGuard;
742 nMode = sal::static_int_cast<sal_uInt16>( lcl_ConditionOperatorToMode( nOperator ) );
745 sal_Int32 SAL_CALL ScTableValidationObj::getConditionOperator()
746 throw(uno::RuntimeException)
748 SolarMutexGuard aGuard;
749 return lcl_ConditionModeToOperatorNew( (ScConditionMode)nMode );
752 void SAL_CALL ScTableValidationObj::setConditionOperator( sal_Int32 nOperator )
753 throw(uno::RuntimeException)
755 SolarMutexGuard aGuard;
756 nMode = sal::static_int_cast<sal_uInt16>( ScConditionEntry::GetModeFromApi( nOperator ) );
759 OUString SAL_CALL ScTableValidationObj::getFormula1() throw(uno::RuntimeException)
761 SolarMutexGuard aGuard;
762 return aExpr1;
765 void SAL_CALL ScTableValidationObj::setFormula1( const OUString& aFormula1 )
766 throw(uno::RuntimeException)
768 SolarMutexGuard aGuard;
769 aExpr1 = aFormula1;
772 OUString SAL_CALL ScTableValidationObj::getFormula2() throw(uno::RuntimeException)
774 SolarMutexGuard aGuard;
775 return aExpr2;
778 void SAL_CALL ScTableValidationObj::setFormula2( const OUString& aFormula2 )
779 throw(uno::RuntimeException)
781 SolarMutexGuard aGuard;
782 aExpr2 = aFormula2;
785 table::CellAddress SAL_CALL ScTableValidationObj::getSourcePosition() throw(uno::RuntimeException)
787 SolarMutexGuard aGuard;
788 table::CellAddress aRet;
789 aRet.Column = aSrcPos.Col();
790 aRet.Row = aSrcPos.Row();
791 aRet.Sheet = aSrcPos.Tab();
792 return aRet;
795 void SAL_CALL ScTableValidationObj::setSourcePosition( const table::CellAddress& aSourcePosition )
796 throw(uno::RuntimeException)
798 SolarMutexGuard aGuard;
799 aSrcPos.Set( (SCCOL)aSourcePosition.Column, (SCROW)aSourcePosition.Row, aSourcePosition.Sheet );
802 uno::Sequence<sheet::FormulaToken> SAL_CALL ScTableValidationObj::getTokens( sal_Int32 nIndex )
803 throw(uno::RuntimeException,lang::IndexOutOfBoundsException)
805 SolarMutexGuard aGuard;
806 if (nIndex >= 2 || nIndex < 0)
807 throw lang::IndexOutOfBoundsException();
809 return nIndex == 0 ? aTokens1 : aTokens2;
812 void SAL_CALL ScTableValidationObj::setTokens( sal_Int32 nIndex, const uno::Sequence<sheet::FormulaToken>& aTokens )
813 throw(uno::RuntimeException,lang::IndexOutOfBoundsException)
815 SolarMutexGuard aGuard;
816 if (nIndex >= 2 || nIndex < 0)
817 throw lang::IndexOutOfBoundsException();
819 if (nIndex == 0)
821 aTokens1 = aTokens;
822 aExpr1 = "";
824 else if (nIndex == 1)
826 aTokens2 = aTokens;
827 aExpr2 = "";
831 sal_Int32 SAL_CALL ScTableValidationObj::getCount() throw(uno::RuntimeException)
833 return 2;
836 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableValidationObj::getPropertySetInfo()
837 throw(uno::RuntimeException)
839 SolarMutexGuard aGuard;
840 static uno::Reference<beans::XPropertySetInfo> aRef(
841 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
842 return aRef;
845 void SAL_CALL ScTableValidationObj::setPropertyValue(
846 const OUString& aPropertyName, const uno::Any& aValue )
847 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
848 lang::IllegalArgumentException, lang::WrappedTargetException,
849 uno::RuntimeException)
851 SolarMutexGuard aGuard;
852 OUString aString(aPropertyName);
854 if ( aString.equalsAscii( SC_UNONAME_SHOWINP ) ) bShowInput = ScUnoHelpFunctions::GetBoolFromAny( aValue );
855 else if ( aString.equalsAscii( SC_UNONAME_SHOWERR ) ) bShowError = ScUnoHelpFunctions::GetBoolFromAny( aValue );
856 else if ( aString.equalsAscii( SC_UNONAME_IGNOREBL ) ) bIgnoreBlank = ScUnoHelpFunctions::GetBoolFromAny( aValue );
857 else if ( aString.equalsAscii( SC_UNONAME_SHOWLIST ) ) aValue >>= nShowList;
858 else if ( aString.equalsAscii( SC_UNONAME_INPTITLE ) )
860 OUString aStrVal;
861 if ( aValue >>= aStrVal )
862 aInputTitle = aStrVal;
864 else if ( aString.equalsAscii( SC_UNONAME_INPMESS ) )
866 OUString aStrVal;
867 if ( aValue >>= aStrVal )
868 aInputMessage = aStrVal;
870 else if ( aString.equalsAscii( SC_UNONAME_ERRTITLE ) )
872 OUString aStrVal;
873 if ( aValue >>= aStrVal )
874 aErrorTitle = aStrVal;
876 else if ( aString.equalsAscii( SC_UNONAME_ERRMESS ) )
878 OUString aStrVal;
879 if ( aValue >>= aStrVal )
880 aErrorMessage = aStrVal;
882 else if ( aString.equalsAscii( SC_UNONAME_TYPE ) )
884 sheet::ValidationType eType = (sheet::ValidationType)
885 ScUnoHelpFunctions::GetEnumFromAny( aValue );
886 switch (eType)
888 case sheet::ValidationType_ANY: nValMode = SC_VALID_ANY; break;
889 case sheet::ValidationType_WHOLE: nValMode = SC_VALID_WHOLE; break;
890 case sheet::ValidationType_DECIMAL: nValMode = SC_VALID_DECIMAL; break;
891 case sheet::ValidationType_DATE: nValMode = SC_VALID_DATE; break;
892 case sheet::ValidationType_TIME: nValMode = SC_VALID_TIME; break;
893 case sheet::ValidationType_TEXT_LEN: nValMode = SC_VALID_TEXTLEN; break;
894 case sheet::ValidationType_LIST: nValMode = SC_VALID_LIST; break;
895 case sheet::ValidationType_CUSTOM: nValMode = SC_VALID_CUSTOM; break;
896 default:
898 // added to avoid warnings
902 else if ( aString.equalsAscii( SC_UNONAME_ERRALSTY ) )
904 sheet::ValidationAlertStyle eStyle = (sheet::ValidationAlertStyle)
905 ScUnoHelpFunctions::GetEnumFromAny( aValue );
906 switch (eStyle)
908 case sheet::ValidationAlertStyle_STOP: nErrorStyle = SC_VALERR_STOP; break;
909 case sheet::ValidationAlertStyle_WARNING: nErrorStyle = SC_VALERR_WARNING; break;
910 case sheet::ValidationAlertStyle_INFO: nErrorStyle = SC_VALERR_INFO; break;
911 case sheet::ValidationAlertStyle_MACRO: nErrorStyle = SC_VALERR_MACRO; break;
912 default:
914 // added to avoid warnings
918 else if ( aString.equalsAscii( SC_UNONAME_SOURCESTR ) )
920 // internal - only for XML filter, not in PropertySetInfo, only set
922 OUString aStrVal;
923 if ( aValue >>= aStrVal )
924 aPosString = aStrVal;
926 else if ( aString.equalsAscii( SC_UNONAME_FORMULANMSP1 ) )
928 // internal - only for XML filter, not in PropertySetInfo, only set
930 OUString aStrVal;
931 if ( aValue >>= aStrVal )
932 maExprNmsp1 = aStrVal;
934 else if ( aString.equalsAscii( SC_UNONAME_FORMULANMSP2 ) )
936 // internal - only for XML filter, not in PropertySetInfo, only set
938 OUString aStrVal;
939 if ( aValue >>= aStrVal )
940 maExprNmsp2 = aStrVal;
942 else if ( aString.equalsAscii( SC_UNONAME_GRAMMAR1 ) )
944 // internal - only for XML filter, not in PropertySetInfo, only set
946 sal_Int32 nVal = 0;
947 if ( aValue >>= nVal )
948 meGrammar1 = static_cast< FormulaGrammar::Grammar >(nVal);
950 else if ( aString.equalsAscii( SC_UNONAME_GRAMMAR2 ) )
952 // internal - only for XML filter, not in PropertySetInfo, only set
954 sal_Int32 nVal = 0;
955 if ( aValue >>= nVal )
956 meGrammar2 = static_cast< FormulaGrammar::Grammar >(nVal);
960 uno::Any SAL_CALL ScTableValidationObj::getPropertyValue( const OUString& aPropertyName )
961 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
962 uno::RuntimeException)
964 SolarMutexGuard aGuard;
965 OUString aString(aPropertyName);
966 uno::Any aRet;
968 if ( aString.equalsAscii( SC_UNONAME_SHOWINP ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, bShowInput );
969 else if ( aString.equalsAscii( SC_UNONAME_SHOWERR ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, bShowError );
970 else if ( aString.equalsAscii( SC_UNONAME_IGNOREBL ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, bIgnoreBlank );
971 else if ( aString.equalsAscii( SC_UNONAME_SHOWLIST ) ) aRet <<= nShowList;
972 else if ( aString.equalsAscii( SC_UNONAME_INPTITLE ) ) aRet <<= OUString( aInputTitle );
973 else if ( aString.equalsAscii( SC_UNONAME_INPMESS ) ) aRet <<= OUString( aInputMessage );
974 else if ( aString.equalsAscii( SC_UNONAME_ERRTITLE ) ) aRet <<= OUString( aErrorTitle );
975 else if ( aString.equalsAscii( SC_UNONAME_ERRMESS ) ) aRet <<= OUString( aErrorMessage );
976 else if ( aString.equalsAscii( SC_UNONAME_TYPE ) )
978 sheet::ValidationType eType = sheet::ValidationType_ANY;
979 switch (nValMode)
981 case SC_VALID_ANY: eType = sheet::ValidationType_ANY; break;
982 case SC_VALID_WHOLE: eType = sheet::ValidationType_WHOLE; break;
983 case SC_VALID_DECIMAL: eType = sheet::ValidationType_DECIMAL; break;
984 case SC_VALID_DATE: eType = sheet::ValidationType_DATE; break;
985 case SC_VALID_TIME: eType = sheet::ValidationType_TIME; break;
986 case SC_VALID_TEXTLEN: eType = sheet::ValidationType_TEXT_LEN; break;
987 case SC_VALID_LIST: eType = sheet::ValidationType_LIST; break;
988 case SC_VALID_CUSTOM: eType = sheet::ValidationType_CUSTOM; break;
990 aRet <<= eType;
992 else if ( aString.equalsAscii( SC_UNONAME_ERRALSTY ) )
994 sheet::ValidationAlertStyle eStyle = sheet::ValidationAlertStyle_STOP;
995 switch (nErrorStyle)
997 case SC_VALERR_STOP: eStyle = sheet::ValidationAlertStyle_STOP; break;
998 case SC_VALERR_WARNING: eStyle = sheet::ValidationAlertStyle_WARNING; break;
999 case SC_VALERR_INFO: eStyle = sheet::ValidationAlertStyle_INFO; break;
1000 case SC_VALERR_MACRO: eStyle = sheet::ValidationAlertStyle_MACRO; break;
1002 aRet <<= eStyle;
1005 return aRet;
1008 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableValidationObj )
1010 // XUnoTunnel
1012 sal_Int64 SAL_CALL ScTableValidationObj::getSomething(
1013 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
1015 if ( rId.getLength() == 16 &&
1016 0 == memcmp( getUnoTunnelId().getConstArray(),
1017 rId.getConstArray(), 16 ) )
1019 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
1021 return 0;
1024 namespace
1026 class theScTableValidationObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScTableValidationObjUnoTunnelId> {};
1029 const uno::Sequence<sal_Int8>& ScTableValidationObj::getUnoTunnelId()
1031 return theScTableValidationObjUnoTunnelId::get().getSeq();
1034 ScTableValidationObj* ScTableValidationObj::getImplementation(
1035 const uno::Reference<beans::XPropertySet> xObj )
1037 ScTableValidationObj* pRet = NULL;
1038 uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
1039 if (xUT.is())
1040 pRet = reinterpret_cast<ScTableValidationObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
1041 return pRet;
1044 //------------------------------------------------------------------------
1049 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */