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_unotools.hxx" 30 31 #include <unotools/fltrcfg.hxx> 32 #include <tools/debug.hxx> 33 34 #include <rtl/logfile.hxx> 35 #include <com/sun/star/uno/Any.hxx> 36 #include <com/sun/star/uno/Sequence.hxx> 37 38 using namespace utl; 39 using namespace rtl; 40 using namespace com::sun::star::uno; 41 42 #define C2U(cChar) OUString::createFromAscii(cChar) 43 44 // ----------------------------------------------------------------------- 45 #define FILTERCFG_WORD_CODE 0x0001 46 #define FILTERCFG_WORD_STORAGE 0x0002 47 #define FILTERCFG_EXCEL_CODE 0x0004 48 #define FILTERCFG_EXCEL_STORAGE 0x0008 49 #define FILTERCFG_PPOINT_CODE 0x0010 50 #define FILTERCFG_PPOINT_STORAGE 0x0020 51 #define FILTERCFG_MATH_LOAD 0x0100 52 #define FILTERCFG_MATH_SAVE 0x0200 53 #define FILTERCFG_WRITER_LOAD 0x0400 54 #define FILTERCFG_WRITER_SAVE 0x0800 55 #define FILTERCFG_CALC_LOAD 0x1000 56 #define FILTERCFG_CALC_SAVE 0x2000 57 #define FILTERCFG_IMPRESS_LOAD 0x4000 58 #define FILTERCFG_IMPRESS_SAVE 0x8000 59 #define FILTERCFG_EXCEL_EXECTBL 0x10000 60 #define FILTERCFG_ENABLE_PPT_PREVIEW 0x20000 61 #define FILTERCFG_ENABLE_EXCEL_PREVIEW 0x40000 62 #define FILTERCFG_ENABLE_WORD_PREVIEW 0x80000 63 #define FILTERCFG_USE_ENHANCED_FIELDS 0x100000 64 65 static SvtFilterOptions* pOptions=0; 66 67 /* -----------------------------22.01.01 10:23-------------------------------- 68 69 ---------------------------------------------------------------------------*/ 70 class SvtAppFilterOptions_Impl : public utl::ConfigItem 71 { 72 sal_Bool bLoadVBA; 73 sal_Bool bSaveVBA; 74 public: 75 SvtAppFilterOptions_Impl(const OUString& rRoot) : 76 utl::ConfigItem(rRoot), 77 bLoadVBA(sal_False), 78 bSaveVBA(sal_False) {} 79 ~SvtAppFilterOptions_Impl(); 80 virtual void Commit(); 81 virtual void Notify( const com::sun::star::uno::Sequence<rtl::OUString>& aPropertyNames); 82 void Load(); 83 84 sal_Bool IsLoad() const {return bLoadVBA;} 85 void SetLoad(sal_Bool bSet) 86 { 87 if(bSet != bLoadVBA) 88 SetModified(); 89 bLoadVBA = bSet; 90 } 91 sal_Bool IsSave() const {return bSaveVBA;} 92 void SetSave(sal_Bool bSet) 93 { 94 if(bSet != bSaveVBA) 95 SetModified(); 96 bSaveVBA = bSet; 97 } 98 }; 99 100 /* -----------------------------22.01.01 11:08-------------------------------- 101 102 ---------------------------------------------------------------------------*/ 103 SvtAppFilterOptions_Impl::~SvtAppFilterOptions_Impl() 104 { 105 if(IsModified()) 106 Commit(); 107 } 108 /* -----------------------------22.01.01 10:38-------------------------------- 109 110 ---------------------------------------------------------------------------*/ 111 void SvtAppFilterOptions_Impl::Commit() 112 { 113 Sequence<OUString> aNames(2); 114 OUString* pNames = aNames.getArray(); 115 pNames[0] = C2U("Load"); 116 pNames[1] = C2U("Save"); 117 Sequence<Any> aValues(aNames.getLength()); 118 Any* pValues = aValues.getArray(); 119 120 const Type& rType = ::getBooleanCppuType(); 121 pValues[0].setValue(&bLoadVBA, rType); 122 pValues[1].setValue(&bSaveVBA, rType); 123 124 PutProperties(aNames, aValues); 125 } 126 127 void SvtAppFilterOptions_Impl::Notify( const Sequence< rtl::OUString >& ) 128 { 129 // no listeners supported yet 130 } 131 132 133 /* -----------------------------22.01.01 10:38-------------------------------- 134 135 ---------------------------------------------------------------------------*/ 136 void SvtAppFilterOptions_Impl::Load() 137 { 138 Sequence<OUString> aNames(2); 139 OUString* pNames = aNames.getArray(); 140 pNames[0] = C2U("Load"); 141 pNames[1] = C2U("Save"); 142 143 Sequence<Any> aValues = GetProperties(aNames); 144 const Any* pValues = aValues.getConstArray(); 145 146 if(pValues[0].hasValue()) 147 bLoadVBA = *(sal_Bool*)pValues[0].getValue(); 148 if(pValues[1].hasValue()) 149 bSaveVBA = *(sal_Bool*)pValues[1].getValue(); 150 } 151 152 // ----------------------------------------------------------------------- 153 class SvtCalcFilterOptions_Impl : public SvtAppFilterOptions_Impl 154 { 155 sal_Bool bLoadExecutable; 156 public: 157 SvtCalcFilterOptions_Impl(const OUString& rRoot) : 158 SvtAppFilterOptions_Impl(rRoot), 159 bLoadExecutable(sal_False) 160 {} 161 virtual void Commit(); 162 void Load(); 163 164 sal_Bool IsLoadExecutable() const {return bLoadExecutable;} 165 void SetLoadExecutable(sal_Bool bSet) 166 { 167 if(bSet != bLoadExecutable) 168 SetModified(); 169 bLoadExecutable = bSet; 170 } 171 }; 172 173 void SvtCalcFilterOptions_Impl::Commit() 174 { 175 SvtAppFilterOptions_Impl::Commit(); 176 177 Sequence<OUString> aNames(1); 178 aNames[0] = C2U("Executable"); 179 Sequence<Any> aValues(1); 180 aValues[0] <<= bLoadExecutable; 181 182 PutProperties(aNames, aValues); 183 } 184 185 void SvtCalcFilterOptions_Impl::Load() 186 { 187 SvtAppFilterOptions_Impl::Load(); 188 189 Sequence<OUString> aNames(1); 190 aNames[0] = C2U("Executable"); 191 192 Sequence<Any> aValues = GetProperties(aNames); 193 const Any* pValues = aValues.getConstArray(); 194 if(pValues[0].hasValue()) 195 bLoadExecutable = *(sal_Bool*)pValues[0].getValue(); 196 } 197 198 /* -----------------------------22.01.01 10:32-------------------------------- 199 200 ---------------------------------------------------------------------------*/ 201 struct SvtFilterOptions_Impl 202 { 203 sal_uLong nFlags; 204 SvtAppFilterOptions_Impl aWriterCfg; 205 SvtCalcFilterOptions_Impl aCalcCfg; 206 SvtAppFilterOptions_Impl aImpressCfg; 207 208 SvtFilterOptions_Impl() : 209 aWriterCfg(C2U("Office.Writer/Filter/Import/VBA")), 210 aCalcCfg(C2U("Office.Calc/Filter/Import/VBA")), 211 aImpressCfg(C2U("Office.Impress/Filter/Import/VBA")) 212 { 213 nFlags = FILTERCFG_WORD_CODE | 214 FILTERCFG_WORD_STORAGE | 215 FILTERCFG_EXCEL_CODE | 216 FILTERCFG_EXCEL_STORAGE | 217 FILTERCFG_PPOINT_CODE | 218 FILTERCFG_PPOINT_STORAGE | 219 FILTERCFG_MATH_LOAD | 220 FILTERCFG_MATH_SAVE | 221 FILTERCFG_WRITER_LOAD | 222 FILTERCFG_WRITER_SAVE | 223 FILTERCFG_CALC_LOAD | 224 FILTERCFG_CALC_SAVE | 225 FILTERCFG_IMPRESS_LOAD | 226 FILTERCFG_IMPRESS_SAVE | 227 FILTERCFG_USE_ENHANCED_FIELDS; 228 Load(); 229 } 230 231 void SetFlag( sal_uLong nFlag, sal_Bool bSet ); 232 sal_Bool IsFlag( sal_uLong nFlag ) const; 233 void Load() 234 { 235 aWriterCfg.Load(); 236 aCalcCfg.Load(); 237 aImpressCfg.Load(); 238 } 239 }; 240 /* -----------------------------22.01.01 10:34-------------------------------- 241 242 ---------------------------------------------------------------------------*/ 243 void SvtFilterOptions_Impl::SetFlag( sal_uLong nFlag, sal_Bool bSet ) 244 { 245 switch(nFlag) 246 { 247 case FILTERCFG_WORD_CODE: aWriterCfg.SetLoad(bSet);break; 248 case FILTERCFG_WORD_STORAGE: aWriterCfg.SetSave(bSet);break; 249 case FILTERCFG_EXCEL_CODE: aCalcCfg.SetLoad(bSet);break; 250 case FILTERCFG_EXCEL_STORAGE: aCalcCfg.SetSave(bSet);break; 251 case FILTERCFG_EXCEL_EXECTBL: aCalcCfg.SetLoadExecutable(bSet);break; 252 case FILTERCFG_PPOINT_CODE: aImpressCfg.SetLoad(bSet);break; 253 case FILTERCFG_PPOINT_STORAGE: aImpressCfg.SetSave(bSet);break; 254 default: 255 if( bSet ) 256 nFlags |= nFlag; 257 else 258 nFlags &= ~nFlag; 259 } 260 } 261 /* -----------------------------22.01.01 10:35-------------------------------- 262 263 ---------------------------------------------------------------------------*/ 264 sal_Bool SvtFilterOptions_Impl::IsFlag( sal_uLong nFlag ) const 265 { 266 sal_Bool bRet; 267 switch(nFlag) 268 { 269 case FILTERCFG_WORD_CODE : bRet = aWriterCfg.IsLoad();break; 270 case FILTERCFG_WORD_STORAGE : bRet = aWriterCfg.IsSave();break; 271 case FILTERCFG_EXCEL_CODE : bRet = aCalcCfg.IsLoad();break; 272 case FILTERCFG_EXCEL_STORAGE : bRet = aCalcCfg.IsSave();break; 273 case FILTERCFG_EXCEL_EXECTBL : bRet = aCalcCfg.IsLoadExecutable();break; 274 case FILTERCFG_PPOINT_CODE : bRet = aImpressCfg.IsLoad();break; 275 case FILTERCFG_PPOINT_STORAGE : bRet = aImpressCfg.IsSave();break; 276 default: 277 bRet = 0 != (nFlags & nFlag ); 278 } 279 return bRet; 280 } 281 282 // ----------------------------------------------------------------------- 283 284 SvtFilterOptions::SvtFilterOptions() : 285 ConfigItem( C2U("Office.Common/Filter/Microsoft") ), 286 pImp(new SvtFilterOptions_Impl) 287 { 288 RTL_LOGFILE_CONTEXT(aLog, "unotools SvtFilterOptions::SvtFilterOptions()"); 289 EnableNotification(GetPropertyNames()); 290 Load(); 291 } 292 // ----------------------------------------------------------------------- 293 SvtFilterOptions::~SvtFilterOptions() 294 { 295 delete pImp; 296 } 297 /* -----------------------------22.01.01 08:45-------------------------------- 298 299 ---------------------------------------------------------------------------*/ 300 const Sequence<OUString>& SvtFilterOptions::GetPropertyNames() 301 { 302 static Sequence<OUString> aNames; 303 if(!aNames.getLength()) 304 { 305 int nCount = 12; 306 aNames.realloc(nCount); 307 static const char* aPropNames[] = 308 { 309 "Import/MathTypeToMath", // 0 310 "Import/WinWordToWriter", // 1 311 "Import/PowerPointToImpress", // 2 312 "Import/ExcelToCalc", // 3 313 "Export/MathToMathType", // 4 314 "Export/WriterToWinWord", // 5 315 "Export/ImpressToPowerPoint", // 6 316 "Export/CalcToExcel", // 7 317 "Export/EnablePowerPointPreview", // 8 318 "Export/EnableExcelPreview", // 9 319 "Export/EnableWordPreview", // 10 320 "Import/ImportWWFieldsAsEnhancedFields" // 11 321 }; 322 OUString* pNames = aNames.getArray(); 323 for(int i = 0; i < nCount; i++) 324 pNames[i] = C2U(aPropNames[i]); 325 } 326 return aNames; 327 } 328 //----------------------------------------------------------------------- 329 static sal_uLong lcl_GetFlag(sal_Int32 nProp) 330 { 331 sal_uLong nFlag = 0; 332 switch(nProp) 333 { 334 case 0: nFlag = FILTERCFG_MATH_LOAD; break; 335 case 1: nFlag = FILTERCFG_WRITER_LOAD; break; 336 case 2: nFlag = FILTERCFG_IMPRESS_LOAD; break; 337 case 3: nFlag = FILTERCFG_CALC_LOAD; break; 338 case 4: nFlag = FILTERCFG_MATH_SAVE; break; 339 case 5: nFlag = FILTERCFG_WRITER_SAVE; break; 340 case 6: nFlag = FILTERCFG_IMPRESS_SAVE; break; 341 case 7: nFlag = FILTERCFG_CALC_SAVE; break; 342 case 8: nFlag = FILTERCFG_ENABLE_PPT_PREVIEW; break; 343 case 9: nFlag = FILTERCFG_ENABLE_EXCEL_PREVIEW; break; 344 case 10: nFlag = FILTERCFG_ENABLE_WORD_PREVIEW; break; 345 case 11: nFlag = FILTERCFG_USE_ENHANCED_FIELDS; break; 346 347 default: DBG_ERROR("illegal value"); 348 } 349 return nFlag; 350 } 351 /*-- 22.01.01 08:53:03--------------------------------------------------- 352 353 -----------------------------------------------------------------------*/ 354 void SvtFilterOptions::Notify( const Sequence<OUString>& ) 355 { 356 Load(); 357 } 358 /*-- 22.01.01 08:53:04--------------------------------------------------- 359 360 -----------------------------------------------------------------------*/ 361 void SvtFilterOptions::Commit() 362 { 363 const Sequence<OUString>& aNames = GetPropertyNames(); 364 Sequence<Any> aValues(aNames.getLength()); 365 Any* pValues = aValues.getArray(); 366 367 const Type& rType = ::getBooleanCppuType(); 368 for(int nProp = 0; nProp < aNames.getLength(); nProp++) 369 { 370 sal_uLong nFlag = lcl_GetFlag(nProp); 371 sal_Bool bVal = pImp->IsFlag( nFlag); 372 pValues[nProp].setValue(&bVal, rType); 373 374 } 375 PutProperties(aNames, aValues); 376 } 377 /*-- 22.01.01 08:53:04--------------------------------------------------- 378 379 -----------------------------------------------------------------------*/ 380 void SvtFilterOptions::Load() 381 { 382 pImp->Load(); 383 const Sequence<OUString>& rNames = GetPropertyNames(); 384 Sequence<Any> aValues = GetProperties(rNames); 385 const Any* pValues = aValues.getConstArray(); 386 DBG_ASSERT(aValues.getLength() == rNames.getLength(), "GetProperties failed"); 387 if(aValues.getLength() == rNames.getLength()) 388 { 389 for(int nProp = 0; nProp < rNames.getLength(); nProp++) 390 { 391 if(pValues[nProp].hasValue()) 392 { 393 sal_Bool bVal = *(sal_Bool*)pValues[nProp].getValue(); 394 sal_uLong nFlag = lcl_GetFlag(nProp); 395 pImp->SetFlag( nFlag, bVal); 396 } 397 } 398 } 399 } 400 // ----------------------------------------------------------------------- 401 402 void SvtFilterOptions::SetLoadWordBasicCode( sal_Bool bFlag ) 403 { 404 pImp->SetFlag( FILTERCFG_WORD_CODE, bFlag ); 405 SetModified(); 406 } 407 408 sal_Bool SvtFilterOptions::IsLoadWordBasicCode() const 409 { 410 return pImp->IsFlag( FILTERCFG_WORD_CODE ); 411 } 412 413 void SvtFilterOptions::SetLoadWordBasicStorage( sal_Bool bFlag ) 414 { 415 pImp->SetFlag( FILTERCFG_WORD_STORAGE, bFlag ); 416 SetModified(); 417 } 418 419 sal_Bool SvtFilterOptions::IsLoadWordBasicStorage() const 420 { 421 return pImp->IsFlag( FILTERCFG_WORD_STORAGE ); 422 } 423 424 // ----------------------------------------------------------------------- 425 426 void SvtFilterOptions::SetLoadExcelBasicCode( sal_Bool bFlag ) 427 { 428 pImp->SetFlag( FILTERCFG_EXCEL_CODE, bFlag ); 429 SetModified(); 430 } 431 432 sal_Bool SvtFilterOptions::IsLoadExcelBasicCode() const 433 { 434 return pImp->IsFlag( FILTERCFG_EXCEL_CODE ); 435 } 436 437 void SvtFilterOptions::SetLoadExcelBasicExecutable( sal_Bool bFlag ) 438 { 439 pImp->SetFlag( FILTERCFG_EXCEL_EXECTBL, bFlag ); 440 SetModified(); 441 } 442 443 sal_Bool SvtFilterOptions::IsLoadExcelBasicExecutable() const 444 { 445 return pImp->IsFlag( FILTERCFG_EXCEL_EXECTBL ); 446 } 447 448 void SvtFilterOptions::SetLoadExcelBasicStorage( sal_Bool bFlag ) 449 { 450 pImp->SetFlag( FILTERCFG_EXCEL_STORAGE, bFlag ); 451 SetModified(); 452 } 453 454 sal_Bool SvtFilterOptions::IsLoadExcelBasicStorage() const 455 { 456 return pImp->IsFlag( FILTERCFG_EXCEL_STORAGE ); 457 } 458 459 // ----------------------------------------------------------------------- 460 461 void SvtFilterOptions::SetLoadPPointBasicCode( sal_Bool bFlag ) 462 { 463 pImp->SetFlag( FILTERCFG_PPOINT_CODE, bFlag ); 464 SetModified(); 465 } 466 467 sal_Bool SvtFilterOptions::IsLoadPPointBasicCode() const 468 { 469 return pImp->IsFlag( FILTERCFG_PPOINT_CODE ); 470 } 471 472 void SvtFilterOptions::SetLoadPPointBasicStorage( sal_Bool bFlag ) 473 { 474 pImp->SetFlag( FILTERCFG_PPOINT_STORAGE, bFlag ); 475 SetModified(); 476 } 477 478 sal_Bool SvtFilterOptions::IsLoadPPointBasicStorage() const 479 { 480 return pImp->IsFlag( FILTERCFG_PPOINT_STORAGE ); 481 } 482 483 // ----------------------------------------------------------------------- 484 485 sal_Bool SvtFilterOptions::IsMathType2Math() const 486 { 487 return pImp->IsFlag( FILTERCFG_MATH_LOAD ); 488 } 489 490 void SvtFilterOptions::SetMathType2Math( sal_Bool bFlag ) 491 { 492 pImp->SetFlag( FILTERCFG_MATH_LOAD, bFlag ); 493 SetModified(); 494 } 495 496 sal_Bool SvtFilterOptions::IsMath2MathType() const 497 { 498 return pImp->IsFlag( FILTERCFG_MATH_SAVE ); 499 } 500 501 void SvtFilterOptions::SetMath2MathType( sal_Bool bFlag ) 502 { 503 pImp->SetFlag( FILTERCFG_MATH_SAVE, bFlag ); 504 SetModified(); 505 } 506 507 508 // ----------------------------------------------------------------------- 509 sal_Bool SvtFilterOptions::IsWinWord2Writer() const 510 { 511 return pImp->IsFlag( FILTERCFG_WRITER_LOAD ); 512 } 513 514 void SvtFilterOptions::SetWinWord2Writer( sal_Bool bFlag ) 515 { 516 pImp->SetFlag( FILTERCFG_WRITER_LOAD, bFlag ); 517 SetModified(); 518 } 519 520 sal_Bool SvtFilterOptions::IsWriter2WinWord() const 521 { 522 return pImp->IsFlag( FILTERCFG_WRITER_SAVE ); 523 } 524 525 void SvtFilterOptions::SetWriter2WinWord( sal_Bool bFlag ) 526 { 527 pImp->SetFlag( FILTERCFG_WRITER_SAVE, bFlag ); 528 SetModified(); 529 } 530 531 sal_Bool SvtFilterOptions::IsUseEnhancedFields() const 532 { 533 return false; // disable for now; 534 // return pImp->IsFlag( FILTERCFG_USE_ENHANCED_FIELDS ); 535 } 536 537 void SvtFilterOptions::SetUseEnhancedFields( sal_Bool bFlag ) 538 { 539 pImp->SetFlag( FILTERCFG_USE_ENHANCED_FIELDS, bFlag ); 540 SetModified(); 541 } 542 543 // ----------------------------------------------------------------------- 544 sal_Bool SvtFilterOptions::IsExcel2Calc() const 545 { 546 return pImp->IsFlag( FILTERCFG_CALC_LOAD ); 547 } 548 549 void SvtFilterOptions::SetExcel2Calc( sal_Bool bFlag ) 550 { 551 pImp->SetFlag( FILTERCFG_CALC_LOAD, bFlag ); 552 SetModified(); 553 } 554 555 sal_Bool SvtFilterOptions::IsCalc2Excel() const 556 { 557 return pImp->IsFlag( FILTERCFG_CALC_SAVE ); 558 } 559 560 void SvtFilterOptions::SetCalc2Excel( sal_Bool bFlag ) 561 { 562 pImp->SetFlag( FILTERCFG_CALC_SAVE, bFlag ); 563 SetModified(); 564 } 565 566 567 // ----------------------------------------------------------------------- 568 sal_Bool SvtFilterOptions::IsPowerPoint2Impress() const 569 { 570 return pImp->IsFlag( FILTERCFG_IMPRESS_LOAD ); 571 } 572 573 void SvtFilterOptions::SetPowerPoint2Impress( sal_Bool bFlag ) 574 { 575 pImp->SetFlag( FILTERCFG_IMPRESS_LOAD, bFlag ); 576 SetModified(); 577 } 578 579 sal_Bool SvtFilterOptions::IsImpress2PowerPoint() const 580 { 581 return pImp->IsFlag( FILTERCFG_IMPRESS_SAVE ); 582 } 583 584 void SvtFilterOptions::SetImpress2PowerPoint( sal_Bool bFlag ) 585 { 586 pImp->SetFlag( FILTERCFG_IMPRESS_SAVE, bFlag ); 587 SetModified(); 588 } 589 590 SvtFilterOptions* SvtFilterOptions::Get() 591 { 592 if ( !pOptions ) 593 pOptions = new SvtFilterOptions; 594 return pOptions; 595 } 596 597 // ----------------------------------------------------------------------- 598 599 sal_Bool SvtFilterOptions::IsEnablePPTPreview() const 600 { 601 return pImp->IsFlag( FILTERCFG_ENABLE_PPT_PREVIEW ); 602 } 603 604 605 sal_Bool SvtFilterOptions::IsEnableCalcPreview() const 606 { 607 return pImp->IsFlag( FILTERCFG_ENABLE_EXCEL_PREVIEW ); 608 } 609 610 611 sal_Bool SvtFilterOptions::IsEnableWordPreview() const 612 { 613 return pImp->IsFlag( FILTERCFG_ENABLE_WORD_PREVIEW ); 614 } 615 616 617