1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sc.hxx" 30 31 32 33 #include <tools/debug.hxx> 34 #include <rtl/uuid.h> 35 36 #include <com/sun/star/sheet/ValidationAlertStyle.hpp> 37 #include <com/sun/star/sheet/ValidationType.hpp> 38 #include <com/sun/star/sheet/TableValidationVisibility.hpp> 39 40 #include "fmtuno.hxx" 41 #include "miscuno.hxx" 42 #include "validat.hxx" 43 #include "document.hxx" 44 #include "unoguard.hxx" 45 #include "unonames.hxx" 46 #include "styleuno.hxx" // ScStyleNameConversion 47 #include "tokenarray.hxx" 48 #include "tokenuno.hxx" 49 50 using namespace ::com::sun::star; 51 using namespace ::formula; 52 53 //------------------------------------------------------------------------ 54 55 // Map nur fuer PropertySetInfo 56 57 const SfxItemPropertyMapEntry* lcl_GetValidatePropertyMap() 58 { 59 static SfxItemPropertyMapEntry aValidatePropertyMap_Impl[] = 60 { 61 {MAP_CHAR_LEN(SC_UNONAME_ERRALSTY), 0, &getCppuType((sheet::ValidationAlertStyle*)0), 0, 0}, 62 {MAP_CHAR_LEN(SC_UNONAME_ERRMESS), 0, &getCppuType((rtl::OUString*)0), 0, 0}, 63 {MAP_CHAR_LEN(SC_UNONAME_ERRTITLE), 0, &getCppuType((rtl::OUString*)0), 0, 0}, 64 {MAP_CHAR_LEN(SC_UNONAME_IGNOREBL), 0, &getBooleanCppuType(), 0, 0}, 65 {MAP_CHAR_LEN(SC_UNONAME_INPMESS), 0, &getCppuType((rtl::OUString*)0), 0, 0}, 66 {MAP_CHAR_LEN(SC_UNONAME_INPTITLE), 0, &getCppuType((rtl::OUString*)0), 0, 0}, 67 {MAP_CHAR_LEN(SC_UNONAME_SHOWERR), 0, &getBooleanCppuType(), 0, 0}, 68 {MAP_CHAR_LEN(SC_UNONAME_SHOWINP), 0, &getBooleanCppuType(), 0, 0}, 69 {MAP_CHAR_LEN(SC_UNONAME_SHOWLIST), 0, &getCppuType((sal_Int16*)0), 0, 0}, 70 {MAP_CHAR_LEN(SC_UNONAME_TYPE), 0, &getCppuType((sheet::ValidationType*)0), 0, 0}, 71 {0,0,0,0,0,0} 72 }; 73 return aValidatePropertyMap_Impl; 74 } 75 76 //------------------------------------------------------------------------ 77 78 SC_SIMPLE_SERVICE_INFO( ScTableConditionalEntry, "ScTableConditionalEntry", "com.sun.star.sheet.TableConditionalEntry" ) 79 SC_SIMPLE_SERVICE_INFO( ScTableConditionalFormat, "ScTableConditionalFormat", "com.sun.star.sheet.TableConditionalFormat" ) 80 SC_SIMPLE_SERVICE_INFO( ScTableValidationObj, "ScTableValidationObj", "com.sun.star.sheet.TableValidation" ) 81 82 //------------------------------------------------------------------------ 83 84 sheet::ConditionOperator lcl_ConditionModeToOperator( ScConditionMode eMode ) 85 { 86 sheet::ConditionOperator eOper = sheet::ConditionOperator_NONE; 87 switch (eMode) 88 { 89 case SC_COND_EQUAL: eOper = sheet::ConditionOperator_EQUAL; break; 90 case SC_COND_LESS: eOper = sheet::ConditionOperator_LESS; break; 91 case SC_COND_GREATER: eOper = sheet::ConditionOperator_GREATER; break; 92 case SC_COND_EQLESS: eOper = sheet::ConditionOperator_LESS_EQUAL; break; 93 case SC_COND_EQGREATER: eOper = sheet::ConditionOperator_GREATER_EQUAL; break; 94 case SC_COND_NOTEQUAL: eOper = sheet::ConditionOperator_NOT_EQUAL; break; 95 case SC_COND_BETWEEN: eOper = sheet::ConditionOperator_BETWEEN; break; 96 case SC_COND_NOTBETWEEN: eOper = sheet::ConditionOperator_NOT_BETWEEN; break; 97 case SC_COND_DIRECT: eOper = sheet::ConditionOperator_FORMULA; break; 98 default: 99 { 100 // added to avoid warnings 101 } 102 } 103 return eOper; 104 } 105 106 ScConditionMode lcl_ConditionOperatorToMode( sheet::ConditionOperator eOper ) 107 { 108 ScConditionMode eMode = SC_COND_NONE; 109 switch (eOper) 110 { 111 case sheet::ConditionOperator_EQUAL: eMode = SC_COND_EQUAL; break; 112 case sheet::ConditionOperator_LESS: eMode = SC_COND_LESS; break; 113 case sheet::ConditionOperator_GREATER: eMode = SC_COND_GREATER; break; 114 case sheet::ConditionOperator_LESS_EQUAL: eMode = SC_COND_EQLESS; break; 115 case sheet::ConditionOperator_GREATER_EQUAL: eMode = SC_COND_EQGREATER; break; 116 case sheet::ConditionOperator_NOT_EQUAL: eMode = SC_COND_NOTEQUAL; break; 117 case sheet::ConditionOperator_BETWEEN: eMode = SC_COND_BETWEEN; break; 118 case sheet::ConditionOperator_NOT_BETWEEN: eMode = SC_COND_NOTBETWEEN; break; 119 case sheet::ConditionOperator_FORMULA: eMode = SC_COND_DIRECT; break; 120 default: 121 { 122 // added to avoid warnings 123 } 124 } 125 return eMode; 126 } 127 128 //------------------------------------------------------------------------ 129 130 ScCondFormatEntryItem::ScCondFormatEntryItem() : 131 meGrammar1( FormulaGrammar::GRAM_UNSPECIFIED ), 132 meGrammar2( FormulaGrammar::GRAM_UNSPECIFIED ), 133 meMode( SC_COND_NONE ) 134 { 135 } 136 137 //------------------------------------------------------------------------ 138 139 ScTableConditionalFormat::ScTableConditionalFormat( 140 ScDocument* pDoc, sal_uLong nKey, FormulaGrammar::Grammar eGrammar) 141 { 142 // Eintrag aus dem Dokument lesen... 143 144 if ( pDoc && nKey ) 145 { 146 ScConditionalFormatList* pList = pDoc->GetCondFormList(); 147 if (pList) 148 { 149 const ScConditionalFormat* pFormat = pList->GetFormat( nKey ); 150 if (pFormat) 151 { 152 // During save to XML. 153 if (pDoc->IsInExternalReferenceMarking()) 154 pFormat->MarkUsedExternalReferences(); 155 156 sal_uInt16 nEntryCount = pFormat->Count(); 157 for (sal_uInt16 i=0; i<nEntryCount; i++) 158 { 159 ScCondFormatEntryItem aItem; 160 const ScCondFormatEntry* pFormatEntry = pFormat->GetEntry(i); 161 aItem.meMode = pFormatEntry->GetOperation(); 162 aItem.maPos = pFormatEntry->GetValidSrcPos(); 163 aItem.maExpr1 = pFormatEntry->GetExpression(aItem.maPos, 0, 0, eGrammar); 164 aItem.maExpr2 = pFormatEntry->GetExpression(aItem.maPos, 1, 0, eGrammar); 165 aItem.meGrammar1 = aItem.meGrammar2 = eGrammar; 166 aItem.maStyle = pFormatEntry->GetStyle(); 167 168 AddEntry_Impl(aItem); 169 } 170 } 171 } 172 } 173 } 174 175 namespace { 176 177 FormulaGrammar::Grammar lclResolveGrammar( FormulaGrammar::Grammar eExtGrammar, FormulaGrammar::Grammar eIntGrammar ) 178 { 179 if( eExtGrammar != FormulaGrammar::GRAM_UNSPECIFIED ) 180 return eExtGrammar; 181 OSL_ENSURE( eIntGrammar != FormulaGrammar::GRAM_UNSPECIFIED, "lclResolveGrammar - unspecified grammar, using GRAM_PODF_A1" ); 182 return (eIntGrammar == FormulaGrammar::GRAM_UNSPECIFIED) ? FormulaGrammar::GRAM_PODF_A1 : eIntGrammar; 183 } 184 185 } // namespace 186 187 void ScTableConditionalFormat::FillFormat( ScConditionalFormat& rFormat, 188 ScDocument* pDoc, FormulaGrammar::Grammar eGrammar) const 189 { 190 // ScConditionalFormat = Core-Struktur, muss leer sein 191 192 DBG_ASSERT( rFormat.IsEmpty(), "FillFormat: Format nicht leer" ); 193 sal_uInt16 nCount = (sal_uInt16)aEntries.Count(); 194 for (sal_uInt16 i=0; i<nCount; i++) 195 { 196 ScTableConditionalEntry* pEntry = (ScTableConditionalEntry*)aEntries.GetObject(i); 197 if ( !pEntry ) 198 continue; 199 200 ScCondFormatEntryItem aData; 201 pEntry->GetData(aData); 202 203 FormulaGrammar::Grammar eGrammar1 = lclResolveGrammar( eGrammar, aData.meGrammar1 ); 204 FormulaGrammar::Grammar eGrammar2 = lclResolveGrammar( eGrammar, aData.meGrammar2 ); 205 206 ScCondFormatEntry aCoreEntry( aData.meMode, aData.maExpr1, aData.maExpr2, 207 pDoc, aData.maPos, aData.maStyle, aData.maExprNmsp1, aData.maExprNmsp2, eGrammar1, eGrammar2 ); 208 209 if ( aData.maPosStr.Len() ) 210 aCoreEntry.SetSrcString( aData.maPosStr ); 211 212 if ( aData.maTokens1.getLength() ) 213 { 214 ScTokenArray aTokenArray; 215 if ( ScTokenConversion::ConvertToTokenArray(*pDoc, aTokenArray, aData.maTokens1) ) 216 aCoreEntry.SetFormula1(aTokenArray); 217 } 218 219 if ( aData.maTokens2.getLength() ) 220 { 221 ScTokenArray aTokenArray; 222 if ( ScTokenConversion::ConvertToTokenArray(*pDoc, aTokenArray, aData.maTokens2) ) 223 aCoreEntry.SetFormula2(aTokenArray); 224 } 225 rFormat.AddEntry( aCoreEntry ); 226 } 227 } 228 229 ScTableConditionalFormat::~ScTableConditionalFormat() 230 { 231 ScTableConditionalEntry* pEntry; 232 aEntries.First(); 233 while ( ( pEntry = (ScTableConditionalEntry*)aEntries.Remove() ) != NULL ) 234 pEntry->release(); 235 } 236 237 void ScTableConditionalFormat::AddEntry_Impl(const ScCondFormatEntryItem& aEntry) 238 { 239 ScTableConditionalEntry* pNew = new ScTableConditionalEntry(aEntry); 240 pNew->acquire(); 241 aEntries.Insert( pNew, LIST_APPEND ); 242 } 243 244 // XSheetConditionalFormat 245 246 ScTableConditionalEntry* ScTableConditionalFormat::GetObjectByIndex_Impl(sal_uInt16 nIndex) const 247 { 248 return (ScTableConditionalEntry*)aEntries.GetObject(nIndex); 249 } 250 251 void SAL_CALL ScTableConditionalFormat::addNew( 252 const uno::Sequence<beans::PropertyValue >& aConditionalEntry ) 253 throw(uno::RuntimeException) 254 { 255 ScUnoGuard aGuard; 256 ScCondFormatEntryItem aEntry; 257 aEntry.meMode = SC_COND_NONE; 258 259 const beans::PropertyValue* pPropArray = aConditionalEntry.getConstArray(); 260 long nPropCount = aConditionalEntry.getLength(); 261 for (long i = 0; i < nPropCount; i++) 262 { 263 const beans::PropertyValue& rProp = pPropArray[i]; 264 265 if ( rProp.Name.equalsAscii( SC_UNONAME_OPERATOR ) ) 266 { 267 sheet::ConditionOperator eOper = (sheet::ConditionOperator) 268 ScUnoHelpFunctions::GetEnumFromAny( rProp.Value ); 269 aEntry.meMode = lcl_ConditionOperatorToMode( eOper ); 270 } 271 else if ( rProp.Name.equalsAscii( SC_UNONAME_FORMULA1 ) ) 272 { 273 rtl::OUString aStrVal; 274 uno::Sequence<sheet::FormulaToken> aTokens; 275 if ( rProp.Value >>= aStrVal ) 276 aEntry.maExpr1 = aStrVal; 277 else if ( rProp.Value >>= aTokens ) 278 { 279 aEntry.maExpr1.Erase(); 280 aEntry.maTokens1 = aTokens; 281 } 282 } 283 else if ( rProp.Name.equalsAscii( SC_UNONAME_FORMULA2 ) ) 284 { 285 rtl::OUString aStrVal; 286 uno::Sequence<sheet::FormulaToken> aTokens; 287 if ( rProp.Value >>= aStrVal ) 288 aEntry.maExpr2 = aStrVal; 289 else if ( rProp.Value >>= aTokens ) 290 { 291 aEntry.maExpr2.Erase(); 292 aEntry.maTokens2 = aTokens; 293 } 294 } 295 else if ( rProp.Name.equalsAscii( SC_UNONAME_SOURCEPOS ) ) 296 { 297 table::CellAddress aAddress; 298 if ( rProp.Value >>= aAddress ) 299 aEntry.maPos = ScAddress( (SCCOL)aAddress.Column, (SCROW)aAddress.Row, aAddress.Sheet ); 300 } 301 else if ( rProp.Name.equalsAscii( SC_UNONAME_SOURCESTR ) ) 302 { 303 rtl::OUString aStrVal; 304 if ( rProp.Value >>= aStrVal ) 305 aEntry.maPosStr = String( aStrVal ); 306 } 307 else if ( rProp.Name.equalsAscii( SC_UNONAME_STYLENAME ) ) 308 { 309 rtl::OUString aStrVal; 310 if ( rProp.Value >>= aStrVal ) 311 aEntry.maStyle = ScStyleNameConversion::ProgrammaticToDisplayName( 312 aStrVal, SFX_STYLE_FAMILY_PARA ); 313 } 314 else if ( rProp.Name.equalsAscii( SC_UNONAME_FORMULANMSP1 ) ) 315 { 316 rtl::OUString aStrVal; 317 if ( rProp.Value >>= aStrVal ) 318 aEntry.maExprNmsp1 = aStrVal; 319 } 320 else if ( rProp.Name.equalsAscii( SC_UNONAME_FORMULANMSP2 ) ) 321 { 322 rtl::OUString aStrVal; 323 if ( rProp.Value >>= aStrVal ) 324 aEntry.maExprNmsp2 = aStrVal; 325 } 326 else if ( rProp.Name.equalsAscii( SC_UNONAME_GRAMMAR1 ) ) 327 { 328 sal_Int32 nVal = 0; 329 if ( rProp.Value >>= nVal ) 330 aEntry.meGrammar1 = static_cast< FormulaGrammar::Grammar >( nVal ); 331 } 332 else if ( rProp.Name.equalsAscii( SC_UNONAME_GRAMMAR2 ) ) 333 { 334 sal_Int32 nVal = 0; 335 if ( rProp.Value >>= nVal ) 336 aEntry.meGrammar2 = static_cast< FormulaGrammar::Grammar >( nVal ); 337 } 338 else 339 { 340 DBG_ERROR("falsche Property"); 341 //! Exception... 342 } 343 } 344 345 AddEntry_Impl(aEntry); 346 } 347 348 void SAL_CALL ScTableConditionalFormat::removeByIndex( sal_Int32 nIndex ) 349 throw(uno::RuntimeException) 350 { 351 ScUnoGuard aGuard; 352 ScTableConditionalEntry* pEntry = (ScTableConditionalEntry*)aEntries.GetObject(nIndex); 353 if (pEntry) 354 { 355 aEntries.Remove(pEntry); 356 pEntry->release(); 357 } 358 } 359 360 void SAL_CALL ScTableConditionalFormat::clear() throw(uno::RuntimeException) 361 { 362 ScUnoGuard aGuard; 363 ScTableConditionalEntry* pEntry; 364 aEntries.First(); 365 while ( ( pEntry = (ScTableConditionalEntry*)aEntries.Remove() ) != NULL ) 366 pEntry->release(); 367 } 368 369 // XEnumerationAccess 370 371 uno::Reference<container::XEnumeration> SAL_CALL ScTableConditionalFormat::createEnumeration() 372 throw(uno::RuntimeException) 373 { 374 ScUnoGuard aGuard; 375 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.TableConditionalEntryEnumeration"))); 376 } 377 378 // XIndexAccess 379 380 sal_Int32 SAL_CALL ScTableConditionalFormat::getCount() throw(uno::RuntimeException) 381 { 382 ScUnoGuard aGuard; 383 return aEntries.Count(); 384 } 385 386 uno::Any SAL_CALL ScTableConditionalFormat::getByIndex( sal_Int32 nIndex ) 387 throw(lang::IndexOutOfBoundsException, 388 lang::WrappedTargetException, uno::RuntimeException) 389 { 390 ScUnoGuard aGuard; 391 uno::Reference<sheet::XSheetConditionalEntry> xEntry(GetObjectByIndex_Impl((sal_uInt16)nIndex)); 392 if (xEntry.is()) 393 return uno::makeAny(xEntry); 394 else 395 throw lang::IndexOutOfBoundsException(); 396 // return uno::Any(); 397 } 398 399 uno::Type SAL_CALL ScTableConditionalFormat::getElementType() throw(uno::RuntimeException) 400 { 401 ScUnoGuard aGuard; 402 return getCppuType((uno::Reference<sheet::XSheetConditionalEntry>*)0); 403 } 404 405 sal_Bool SAL_CALL ScTableConditionalFormat::hasElements() throw(uno::RuntimeException) 406 { 407 ScUnoGuard aGuard; 408 return ( getCount() != 0 ); 409 } 410 411 // conditional format entries have no real names 412 // -> generate name from index 413 414 rtl::OUString lcl_GetEntryNameFromIndex( sal_Int32 nIndex ) 415 { 416 rtl::OUString aRet( RTL_CONSTASCII_USTRINGPARAM( "Entry" ) ); 417 aRet += rtl::OUString::valueOf( nIndex ); 418 return aRet; 419 } 420 421 uno::Any SAL_CALL ScTableConditionalFormat::getByName( const rtl::OUString& aName ) 422 throw(container::NoSuchElementException, 423 lang::WrappedTargetException, uno::RuntimeException) 424 { 425 ScUnoGuard aGuard; 426 427 uno::Reference<sheet::XSheetConditionalEntry> xEntry; 428 long nCount = aEntries.Count(); 429 for (long i=0; i<nCount; i++) 430 if ( aName == lcl_GetEntryNameFromIndex(i) ) 431 { 432 xEntry.set(GetObjectByIndex_Impl((sal_uInt16)i)); 433 break; 434 } 435 436 if (xEntry.is()) 437 return uno::makeAny(xEntry); 438 else 439 throw container::NoSuchElementException(); 440 // return uno::Any(); 441 } 442 443 uno::Sequence<rtl::OUString> SAL_CALL ScTableConditionalFormat::getElementNames() 444 throw(uno::RuntimeException) 445 { 446 ScUnoGuard aGuard; 447 448 long nCount = aEntries.Count(); 449 uno::Sequence<rtl::OUString> aNames(nCount); 450 rtl::OUString* pArray = aNames.getArray(); 451 for (long i=0; i<nCount; i++) 452 pArray[i] = lcl_GetEntryNameFromIndex(i); 453 454 return aNames; 455 } 456 457 sal_Bool SAL_CALL ScTableConditionalFormat::hasByName( const rtl::OUString& aName ) 458 throw(uno::RuntimeException) 459 { 460 ScUnoGuard aGuard; 461 462 long nCount = aEntries.Count(); 463 for (long i=0; i<nCount; i++) 464 if ( aName == lcl_GetEntryNameFromIndex(i) ) 465 return sal_True; 466 467 return sal_False; 468 } 469 470 // XUnoTunnel 471 472 sal_Int64 SAL_CALL ScTableConditionalFormat::getSomething( 473 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) 474 { 475 if ( rId.getLength() == 16 && 476 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), 477 rId.getConstArray(), 16 ) ) 478 { 479 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this)); 480 } 481 return 0; 482 } 483 484 // static 485 const uno::Sequence<sal_Int8>& ScTableConditionalFormat::getUnoTunnelId() 486 { 487 static uno::Sequence<sal_Int8> * pSeq = 0; 488 if( !pSeq ) 489 { 490 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 491 if( !pSeq ) 492 { 493 static uno::Sequence< sal_Int8 > aSeq( 16 ); 494 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); 495 pSeq = &aSeq; 496 } 497 } 498 return *pSeq; 499 } 500 501 // static 502 ScTableConditionalFormat* ScTableConditionalFormat::getImplementation( 503 const uno::Reference<sheet::XSheetConditionalEntries> xObj ) 504 { 505 ScTableConditionalFormat* pRet = NULL; 506 uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); 507 if (xUT.is()) 508 pRet = reinterpret_cast<ScTableConditionalFormat*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId()))); 509 return pRet; 510 } 511 512 //------------------------------------------------------------------------ 513 514 //UNUSED2008-05 ScTableConditionalEntry::ScTableConditionalEntry() : 515 //UNUSED2008-05 pParent( NULL ) 516 //UNUSED2008-05 { 517 //UNUSED2008-05 } 518 519 ScTableConditionalEntry::ScTableConditionalEntry(const ScCondFormatEntryItem& aItem) : 520 aData( aItem ) 521 { 522 // #i113668# only store the settings, keep no reference to parent object 523 } 524 525 ScTableConditionalEntry::~ScTableConditionalEntry() 526 { 527 } 528 529 void ScTableConditionalEntry::GetData(ScCondFormatEntryItem& rData) const 530 { 531 rData = aData; 532 } 533 534 // XSheetCondition 535 536 sheet::ConditionOperator SAL_CALL ScTableConditionalEntry::getOperator() 537 throw(uno::RuntimeException) 538 { 539 ScUnoGuard aGuard; 540 return lcl_ConditionModeToOperator( aData.meMode ); 541 } 542 543 void SAL_CALL ScTableConditionalEntry::setOperator( sheet::ConditionOperator nOperator ) 544 throw(uno::RuntimeException) 545 { 546 ScUnoGuard aGuard; 547 aData.meMode = lcl_ConditionOperatorToMode( nOperator ); 548 } 549 550 rtl::OUString SAL_CALL ScTableConditionalEntry::getFormula1() throw(uno::RuntimeException) 551 { 552 ScUnoGuard aGuard; 553 return aData.maExpr1; 554 } 555 556 void SAL_CALL ScTableConditionalEntry::setFormula1( const rtl::OUString& aFormula1 ) 557 throw(uno::RuntimeException) 558 { 559 ScUnoGuard aGuard; 560 aData.maExpr1 = String( aFormula1 ); 561 } 562 563 rtl::OUString SAL_CALL ScTableConditionalEntry::getFormula2() throw(uno::RuntimeException) 564 { 565 ScUnoGuard aGuard; 566 return aData.maExpr2; 567 } 568 569 void SAL_CALL ScTableConditionalEntry::setFormula2( const rtl::OUString& aFormula2 ) 570 throw(uno::RuntimeException) 571 { 572 ScUnoGuard aGuard; 573 aData.maExpr2 = String( aFormula2 ); 574 } 575 576 table::CellAddress SAL_CALL ScTableConditionalEntry::getSourcePosition() throw(uno::RuntimeException) 577 { 578 ScUnoGuard aGuard; 579 table::CellAddress aRet; 580 aRet.Column = aData.maPos.Col(); 581 aRet.Row = aData.maPos.Row(); 582 aRet.Sheet = aData.maPos.Tab(); 583 return aRet; 584 } 585 586 void SAL_CALL ScTableConditionalEntry::setSourcePosition( const table::CellAddress& aSourcePosition ) 587 throw(uno::RuntimeException) 588 { 589 ScUnoGuard aGuard; 590 aData.maPos.Set( (SCCOL)aSourcePosition.Column, (SCROW)aSourcePosition.Row, aSourcePosition.Sheet ); 591 } 592 593 // XSheetConditionalEntry 594 595 rtl::OUString SAL_CALL ScTableConditionalEntry::getStyleName() throw(uno::RuntimeException) 596 { 597 ScUnoGuard aGuard; 598 return ScStyleNameConversion::DisplayToProgrammaticName( aData.maStyle, SFX_STYLE_FAMILY_PARA ); 599 } 600 601 void SAL_CALL ScTableConditionalEntry::setStyleName( const rtl::OUString& aStyleName ) 602 throw(uno::RuntimeException) 603 { 604 ScUnoGuard aGuard; 605 aData.maStyle = ScStyleNameConversion::ProgrammaticToDisplayName( aStyleName, SFX_STYLE_FAMILY_PARA ); 606 } 607 608 //------------------------------------------------------------------------ 609 610 ScTableValidationObj::ScTableValidationObj(ScDocument* pDoc, sal_uLong nKey, 611 const formula::FormulaGrammar::Grammar eGrammar) : 612 aPropSet( lcl_GetValidatePropertyMap() ) 613 { 614 // Eintrag aus dem Dokument lesen... 615 616 sal_Bool bFound = sal_False; 617 if ( pDoc && nKey ) 618 { 619 const ScValidationData* pData = pDoc->GetValidationEntry( nKey ); 620 if (pData) 621 { 622 nMode = sal::static_int_cast<sal_uInt16>( pData->GetOperation() ); 623 aSrcPos = pData->GetValidSrcPos(); // #b4974740# valid pos for expressions 624 aExpr1 = pData->GetExpression( aSrcPos, 0, 0, eGrammar ); 625 aExpr2 = pData->GetExpression( aSrcPos, 1, 0, eGrammar ); 626 meGrammar1 = meGrammar2 = eGrammar; 627 nValMode = sal::static_int_cast<sal_uInt16>( pData->GetDataMode() ); 628 bIgnoreBlank = pData->IsIgnoreBlank(); 629 nShowList = pData->GetListType(); 630 bShowInput = pData->GetInput( aInputTitle, aInputMessage ); 631 ScValidErrorStyle eStyle; 632 bShowError = pData->GetErrMsg( aErrorTitle, aErrorMessage, eStyle ); 633 nErrorStyle = sal::static_int_cast<sal_uInt16>( eStyle ); 634 635 // During save to XML, sheet::ValidationType_ANY formulas are not 636 // saved, even if in the list, see 637 // ScMyValidationsContainer::GetCondition(), so shall not mark 638 // anything in use. 639 if (nValMode != SC_VALID_ANY && pDoc->IsInExternalReferenceMarking()) 640 pData->MarkUsedExternalReferences(); 641 642 bFound = sal_True; 643 } 644 } 645 if (!bFound) 646 ClearData_Impl(); // Defaults 647 } 648 649 ScValidationData* ScTableValidationObj::CreateValidationData( ScDocument* pDoc, 650 formula::FormulaGrammar::Grammar eGrammar ) const 651 { 652 // ScValidationData = Core-Struktur 653 654 FormulaGrammar::Grammar eGrammar1 = lclResolveGrammar( eGrammar, meGrammar1 ); 655 FormulaGrammar::Grammar eGrammar2 = lclResolveGrammar( eGrammar, meGrammar2 ); 656 657 ScValidationData* pRet = new ScValidationData( (ScValidationMode)nValMode, 658 (ScConditionMode)nMode, 659 aExpr1, aExpr2, pDoc, aSrcPos, 660 maExprNmsp1, maExprNmsp2, 661 eGrammar1, eGrammar2 ); 662 pRet->SetIgnoreBlank(bIgnoreBlank); 663 pRet->SetListType(nShowList); 664 665 if ( aTokens1.getLength() ) 666 { 667 ScTokenArray aTokenArray; 668 if ( ScTokenConversion::ConvertToTokenArray(*pDoc, aTokenArray, aTokens1) ) 669 pRet->SetFormula1(aTokenArray); 670 } 671 672 if ( aTokens2.getLength() ) 673 { 674 ScTokenArray aTokenArray; 675 if ( ScTokenConversion::ConvertToTokenArray(*pDoc, aTokenArray, aTokens2) ) 676 pRet->SetFormula2(aTokenArray); 677 } 678 679 // set strings for error / input even if disabled (and disable afterwards) 680 pRet->SetInput( aInputTitle, aInputMessage ); 681 if (!bShowInput) 682 pRet->ResetInput(); 683 pRet->SetError( aErrorTitle, aErrorMessage, (ScValidErrorStyle)nErrorStyle ); 684 if (!bShowError) 685 pRet->ResetError(); 686 687 if ( aPosString.Len() ) 688 pRet->SetSrcString( aPosString ); 689 690 return pRet; 691 } 692 693 void ScTableValidationObj::ClearData_Impl() 694 { 695 nMode = SC_COND_NONE; 696 nValMode = SC_VALID_ANY; 697 bIgnoreBlank = sal_True; 698 nShowList = sheet::TableValidationVisibility::UNSORTED; 699 bShowInput = sal_False; 700 bShowError = sal_False; 701 nErrorStyle = SC_VALERR_STOP; 702 aSrcPos.Set(0,0,0); 703 aExpr1.Erase(); 704 aExpr2.Erase(); 705 maExprNmsp1.Erase(); 706 maExprNmsp2.Erase(); 707 meGrammar1 = meGrammar2 = FormulaGrammar::GRAM_UNSPECIFIED; // will be overriden when needed 708 aInputTitle.Erase(); 709 aInputMessage.Erase(); 710 aErrorTitle.Erase(); 711 aErrorMessage.Erase(); 712 } 713 714 ScTableValidationObj::~ScTableValidationObj() 715 { 716 } 717 718 // XSheetCondition 719 720 sheet::ConditionOperator SAL_CALL ScTableValidationObj::getOperator() 721 throw(uno::RuntimeException) 722 { 723 ScUnoGuard aGuard; 724 return lcl_ConditionModeToOperator( (ScConditionMode)nMode ); 725 } 726 727 void SAL_CALL ScTableValidationObj::setOperator( sheet::ConditionOperator nOperator ) 728 throw(uno::RuntimeException) 729 { 730 ScUnoGuard aGuard; 731 nMode = sal::static_int_cast<sal_uInt16>( lcl_ConditionOperatorToMode( nOperator ) ); 732 } 733 734 rtl::OUString SAL_CALL ScTableValidationObj::getFormula1() throw(uno::RuntimeException) 735 { 736 ScUnoGuard aGuard; 737 return aExpr1; 738 } 739 740 void SAL_CALL ScTableValidationObj::setFormula1( const rtl::OUString& aFormula1 ) 741 throw(uno::RuntimeException) 742 { 743 ScUnoGuard aGuard; 744 aExpr1 = String( aFormula1 ); 745 } 746 747 rtl::OUString SAL_CALL ScTableValidationObj::getFormula2() throw(uno::RuntimeException) 748 { 749 ScUnoGuard aGuard; 750 return aExpr2; 751 } 752 753 void SAL_CALL ScTableValidationObj::setFormula2( const rtl::OUString& aFormula2 ) 754 throw(uno::RuntimeException) 755 { 756 ScUnoGuard aGuard; 757 aExpr2 = String( aFormula2 ); 758 } 759 760 table::CellAddress SAL_CALL ScTableValidationObj::getSourcePosition() throw(uno::RuntimeException) 761 { 762 ScUnoGuard aGuard; 763 table::CellAddress aRet; 764 aRet.Column = aSrcPos.Col(); 765 aRet.Row = aSrcPos.Row(); 766 aRet.Sheet = aSrcPos.Tab(); 767 return aRet; 768 } 769 770 void SAL_CALL ScTableValidationObj::setSourcePosition( const table::CellAddress& aSourcePosition ) 771 throw(uno::RuntimeException) 772 { 773 ScUnoGuard aGuard; 774 aSrcPos.Set( (SCCOL)aSourcePosition.Column, (SCROW)aSourcePosition.Row, aSourcePosition.Sheet ); 775 } 776 777 uno::Sequence<sheet::FormulaToken> SAL_CALL ScTableValidationObj::getTokens( sal_Int32 nIndex ) 778 throw(uno::RuntimeException,lang::IndexOutOfBoundsException) 779 { 780 ScUnoGuard aGuard; 781 if (nIndex >= 2 || nIndex < 0) 782 throw lang::IndexOutOfBoundsException(); 783 784 return nIndex == 0 ? aTokens1 : aTokens2; 785 } 786 787 void SAL_CALL ScTableValidationObj::setTokens( sal_Int32 nIndex, const uno::Sequence<sheet::FormulaToken>& aTokens ) 788 throw(uno::RuntimeException,lang::IndexOutOfBoundsException) 789 { 790 ScUnoGuard aGuard; 791 if (nIndex >= 2 || nIndex < 0) 792 throw lang::IndexOutOfBoundsException(); 793 794 if (nIndex == 0) 795 { 796 aTokens1 = aTokens; 797 aExpr1.Erase(); 798 } 799 else if (nIndex == 1) 800 { 801 aTokens2 = aTokens; 802 aExpr2.Erase(); 803 } 804 } 805 806 sal_Int32 SAL_CALL ScTableValidationObj::getCount() throw(uno::RuntimeException) 807 { 808 return 2; 809 } 810 811 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableValidationObj::getPropertySetInfo() 812 throw(uno::RuntimeException) 813 { 814 ScUnoGuard aGuard; 815 static uno::Reference<beans::XPropertySetInfo> aRef( 816 new SfxItemPropertySetInfo( aPropSet.getPropertyMap() )); 817 return aRef; 818 } 819 820 void SAL_CALL ScTableValidationObj::setPropertyValue( 821 const rtl::OUString& aPropertyName, const uno::Any& aValue ) 822 throw(beans::UnknownPropertyException, beans::PropertyVetoException, 823 lang::IllegalArgumentException, lang::WrappedTargetException, 824 uno::RuntimeException) 825 { 826 ScUnoGuard aGuard; 827 String aString(aPropertyName); 828 829 if ( aString.EqualsAscii( SC_UNONAME_SHOWINP ) ) bShowInput = ScUnoHelpFunctions::GetBoolFromAny( aValue ); 830 else if ( aString.EqualsAscii( SC_UNONAME_SHOWERR ) ) bShowError = ScUnoHelpFunctions::GetBoolFromAny( aValue ); 831 else if ( aString.EqualsAscii( SC_UNONAME_IGNOREBL ) ) bIgnoreBlank = ScUnoHelpFunctions::GetBoolFromAny( aValue ); 832 else if ( aString.EqualsAscii( SC_UNONAME_SHOWLIST ) ) aValue >>= nShowList; 833 else if ( aString.EqualsAscii( SC_UNONAME_INPTITLE ) ) 834 { 835 rtl::OUString aStrVal; 836 if ( aValue >>= aStrVal ) 837 aInputTitle = String( aStrVal ); 838 } 839 else if ( aString.EqualsAscii( SC_UNONAME_INPMESS ) ) 840 { 841 rtl::OUString aStrVal; 842 if ( aValue >>= aStrVal ) 843 aInputMessage = String( aStrVal ); 844 } 845 else if ( aString.EqualsAscii( SC_UNONAME_ERRTITLE ) ) 846 { 847 rtl::OUString aStrVal; 848 if ( aValue >>= aStrVal ) 849 aErrorTitle = String( aStrVal ); 850 } 851 else if ( aString.EqualsAscii( SC_UNONAME_ERRMESS ) ) 852 { 853 rtl::OUString aStrVal; 854 if ( aValue >>= aStrVal ) 855 aErrorMessage = String( aStrVal ); 856 } 857 else if ( aString.EqualsAscii( SC_UNONAME_TYPE ) ) 858 { 859 sheet::ValidationType eType = (sheet::ValidationType) 860 ScUnoHelpFunctions::GetEnumFromAny( aValue ); 861 switch (eType) 862 { 863 case sheet::ValidationType_ANY: nValMode = SC_VALID_ANY; break; 864 case sheet::ValidationType_WHOLE: nValMode = SC_VALID_WHOLE; break; 865 case sheet::ValidationType_DECIMAL: nValMode = SC_VALID_DECIMAL; break; 866 case sheet::ValidationType_DATE: nValMode = SC_VALID_DATE; break; 867 case sheet::ValidationType_TIME: nValMode = SC_VALID_TIME; break; 868 case sheet::ValidationType_TEXT_LEN: nValMode = SC_VALID_TEXTLEN; break; 869 case sheet::ValidationType_LIST: nValMode = SC_VALID_LIST; break; 870 case sheet::ValidationType_CUSTOM: nValMode = SC_VALID_CUSTOM; break; 871 default: 872 { 873 // added to avoid warnings 874 } 875 } 876 } 877 else if ( aString.EqualsAscii( SC_UNONAME_ERRALSTY ) ) 878 { 879 sheet::ValidationAlertStyle eStyle = (sheet::ValidationAlertStyle) 880 ScUnoHelpFunctions::GetEnumFromAny( aValue ); 881 switch (eStyle) 882 { 883 case sheet::ValidationAlertStyle_STOP: nErrorStyle = SC_VALERR_STOP; break; 884 case sheet::ValidationAlertStyle_WARNING: nErrorStyle = SC_VALERR_WARNING; break; 885 case sheet::ValidationAlertStyle_INFO: nErrorStyle = SC_VALERR_INFO; break; 886 case sheet::ValidationAlertStyle_MACRO: nErrorStyle = SC_VALERR_MACRO; break; 887 default: 888 { 889 // added to avoid warnings 890 } 891 } 892 } 893 else if ( aString.EqualsAscii( SC_UNONAME_SOURCESTR ) ) 894 { 895 // internal - only for XML filter, not in PropertySetInfo, only set 896 897 rtl::OUString aStrVal; 898 if ( aValue >>= aStrVal ) 899 aPosString = String( aStrVal ); 900 } 901 else if ( aString.EqualsAscii( SC_UNONAME_FORMULANMSP1 ) ) 902 { 903 // internal - only for XML filter, not in PropertySetInfo, only set 904 905 rtl::OUString aStrVal; 906 if ( aValue >>= aStrVal ) 907 maExprNmsp1 = aStrVal; 908 } 909 else if ( aString.EqualsAscii( SC_UNONAME_FORMULANMSP2 ) ) 910 { 911 // internal - only for XML filter, not in PropertySetInfo, only set 912 913 rtl::OUString aStrVal; 914 if ( aValue >>= aStrVal ) 915 maExprNmsp2 = aStrVal; 916 } 917 else if ( aString.EqualsAscii( SC_UNONAME_GRAMMAR1 ) ) 918 { 919 // internal - only for XML filter, not in PropertySetInfo, only set 920 921 sal_Int32 nVal = 0; 922 if ( aValue >>= nVal ) 923 meGrammar1 = static_cast< FormulaGrammar::Grammar >(nVal); 924 } 925 else if ( aString.EqualsAscii( SC_UNONAME_GRAMMAR2 ) ) 926 { 927 // internal - only for XML filter, not in PropertySetInfo, only set 928 929 sal_Int32 nVal = 0; 930 if ( aValue >>= nVal ) 931 meGrammar2 = static_cast< FormulaGrammar::Grammar >(nVal); 932 } 933 } 934 935 uno::Any SAL_CALL ScTableValidationObj::getPropertyValue( const rtl::OUString& aPropertyName ) 936 throw(beans::UnknownPropertyException, lang::WrappedTargetException, 937 uno::RuntimeException) 938 { 939 ScUnoGuard aGuard; 940 String aString(aPropertyName); 941 uno::Any aRet; 942 943 if ( aString.EqualsAscii( SC_UNONAME_SHOWINP ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, bShowInput ); 944 else if ( aString.EqualsAscii( SC_UNONAME_SHOWERR ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, bShowError ); 945 else if ( aString.EqualsAscii( SC_UNONAME_IGNOREBL ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, bIgnoreBlank ); 946 else if ( aString.EqualsAscii( SC_UNONAME_SHOWLIST ) ) aRet <<= nShowList; 947 else if ( aString.EqualsAscii( SC_UNONAME_INPTITLE ) ) aRet <<= rtl::OUString( aInputTitle ); 948 else if ( aString.EqualsAscii( SC_UNONAME_INPMESS ) ) aRet <<= rtl::OUString( aInputMessage ); 949 else if ( aString.EqualsAscii( SC_UNONAME_ERRTITLE ) ) aRet <<= rtl::OUString( aErrorTitle ); 950 else if ( aString.EqualsAscii( SC_UNONAME_ERRMESS ) ) aRet <<= rtl::OUString( aErrorMessage ); 951 else if ( aString.EqualsAscii( SC_UNONAME_TYPE ) ) 952 { 953 sheet::ValidationType eType = sheet::ValidationType_ANY; 954 switch (nValMode) 955 { 956 case SC_VALID_ANY: eType = sheet::ValidationType_ANY; break; 957 case SC_VALID_WHOLE: eType = sheet::ValidationType_WHOLE; break; 958 case SC_VALID_DECIMAL: eType = sheet::ValidationType_DECIMAL; break; 959 case SC_VALID_DATE: eType = sheet::ValidationType_DATE; break; 960 case SC_VALID_TIME: eType = sheet::ValidationType_TIME; break; 961 case SC_VALID_TEXTLEN: eType = sheet::ValidationType_TEXT_LEN; break; 962 case SC_VALID_LIST: eType = sheet::ValidationType_LIST; break; 963 case SC_VALID_CUSTOM: eType = sheet::ValidationType_CUSTOM; break; 964 } 965 aRet <<= eType; 966 } 967 else if ( aString.EqualsAscii( SC_UNONAME_ERRALSTY ) ) 968 { 969 sheet::ValidationAlertStyle eStyle = sheet::ValidationAlertStyle_STOP; 970 switch (nErrorStyle) 971 { 972 case SC_VALERR_STOP: eStyle = sheet::ValidationAlertStyle_STOP; break; 973 case SC_VALERR_WARNING: eStyle = sheet::ValidationAlertStyle_WARNING; break; 974 case SC_VALERR_INFO: eStyle = sheet::ValidationAlertStyle_INFO; break; 975 case SC_VALERR_MACRO: eStyle = sheet::ValidationAlertStyle_MACRO; break; 976 } 977 aRet <<= eStyle; 978 } 979 980 return aRet; 981 } 982 983 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableValidationObj ) 984 985 // XUnoTunnel 986 987 sal_Int64 SAL_CALL ScTableValidationObj::getSomething( 988 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) 989 { 990 if ( rId.getLength() == 16 && 991 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), 992 rId.getConstArray(), 16 ) ) 993 { 994 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this)); 995 } 996 return 0; 997 } 998 999 // static 1000 const uno::Sequence<sal_Int8>& ScTableValidationObj::getUnoTunnelId() 1001 { 1002 static uno::Sequence<sal_Int8> * pSeq = 0; 1003 if( !pSeq ) 1004 { 1005 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 1006 if( !pSeq ) 1007 { 1008 static uno::Sequence< sal_Int8 > aSeq( 16 ); 1009 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); 1010 pSeq = &aSeq; 1011 } 1012 } 1013 return *pSeq; 1014 } 1015 1016 // static 1017 ScTableValidationObj* ScTableValidationObj::getImplementation( 1018 const uno::Reference<beans::XPropertySet> xObj ) 1019 { 1020 ScTableValidationObj* pRet = NULL; 1021 uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); 1022 if (xUT.is()) 1023 pRet = reinterpret_cast<ScTableValidationObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId()))); 1024 return pRet; 1025 } 1026 1027 //------------------------------------------------------------------------ 1028 1029 1030 1031 1032