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