nss: upgrade to release 3.73
[LibreOffice.git] / unotools / source / config / fltrcfg.cxx
blobc68ac827ee796815f429d8e7186a0c59120e7207
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <o3tl/any.hxx>
21 #include <o3tl/typed_flags_set.hxx>
22 #include <unotools/fltrcfg.hxx>
23 #include <tools/debug.hxx>
24 #include <osl/diagnose.h>
26 #include <com/sun/star/uno/Sequence.hxx>
28 using namespace utl;
29 using namespace com::sun::star::uno;
31 namespace {
33 enum class ConfigFlags {
34 NONE = 0x0000000,
35 WordCode = 0x0000001,
36 WordStorage = 0x0000002,
37 ExcelCode = 0x0000004,
38 ExcelStorage = 0x0000008,
39 PowerPointCode = 0x0000010,
40 PowerPointStorage = 0x0000020,
41 MathLoad = 0x0000100,
42 MathSave = 0x0000200,
43 WriterLoad = 0x0000400,
44 WriterSave = 0x0000800,
45 CalcLoad = 0x0001000,
46 CalcSave = 0x0002000,
47 ImpressLoad = 0x0004000,
48 ImpressSave = 0x0008000,
49 ExcelExecTbl = 0x0010000,
50 EnablePowerPointPreview = 0x0020000,
51 EnableExcelPreview = 0x0040000,
52 EnableWordPreview = 0x0080000,
53 UseEnhancedFields = 0x0100000,
54 WordWbctbl = 0x0200000,
55 SmartArtShapeLoad = 0x0400000,
56 CharBackgroundToHighlighting = 0x8000000,
57 CreateMSOLockFiles = 0x2000000,
58 VisioLoad = 0x4000000,
63 namespace o3tl {
64 template<> struct typed_flags<ConfigFlags> : is_typed_flags<ConfigFlags, 0xe7fff3f> {};
67 namespace {
69 class SvtAppFilterOptions_Impl : public utl::ConfigItem
71 private:
72 bool bLoadVBA;
73 bool bSaveVBA;
75 protected:
76 virtual void ImplCommit() override;
78 public:
79 explicit SvtAppFilterOptions_Impl(const OUString& rRoot) :
80 utl::ConfigItem(rRoot),
81 bLoadVBA(false),
82 bSaveVBA(false) {}
83 virtual ~SvtAppFilterOptions_Impl() override;
84 virtual void Notify( const css::uno::Sequence<OUString>& aPropertyNames) override;
85 void Load();
87 bool IsLoad() const {return bLoadVBA;}
88 void SetLoad(bool bSet)
90 if(bSet != bLoadVBA)
91 SetModified();
92 bLoadVBA = bSet;
94 bool IsSave() const {return bSaveVBA;}
95 void SetSave(bool bSet)
97 if(bSet != bSaveVBA)
98 SetModified();
99 bSaveVBA = bSet;
105 SvtAppFilterOptions_Impl::~SvtAppFilterOptions_Impl()
107 assert(!IsModified()); // should have been committed
110 void SvtAppFilterOptions_Impl::ImplCommit()
112 PutProperties(
113 {"Load", "Save"}, {css::uno::Any(bLoadVBA), css::uno::Any(bSaveVBA)});
116 void SvtAppFilterOptions_Impl::Notify( const Sequence< OUString >& )
118 // no listeners supported yet
121 void SvtAppFilterOptions_Impl::Load()
123 Sequence<OUString> aNames(2);
124 OUString* pNames = aNames.getArray();
125 pNames[0] = "Load";
126 pNames[1] = "Save";
128 Sequence<Any> aValues = GetProperties(aNames);
129 const Any* pValues = aValues.getConstArray();
131 if(pValues[0].hasValue())
132 bLoadVBA = *o3tl::doAccess<bool>(pValues[0]);
133 if(pValues[1].hasValue())
134 bSaveVBA = *o3tl::doAccess<bool>(pValues[1]);
137 namespace {
139 class SvtWriterFilterOptions_Impl : public SvtAppFilterOptions_Impl
141 private:
142 bool bLoadExecutable;
144 virtual void ImplCommit() override;
146 public:
147 explicit SvtWriterFilterOptions_Impl(const OUString& rRoot) :
148 SvtAppFilterOptions_Impl(rRoot),
149 bLoadExecutable(false)
151 void Load();
153 bool IsLoadExecutable() const {return bLoadExecutable;}
154 void SetLoadExecutable(bool bSet)
156 if(bSet != bLoadExecutable)
157 SetModified();
158 bLoadExecutable = bSet;
164 void SvtWriterFilterOptions_Impl::ImplCommit()
166 SvtAppFilterOptions_Impl::ImplCommit();
168 Sequence<OUString> aNames { "Executable" };
169 Sequence<Any> aValues(1);
170 aValues[0] <<= bLoadExecutable;
172 PutProperties(aNames, aValues);
175 void SvtWriterFilterOptions_Impl::Load()
177 SvtAppFilterOptions_Impl::Load();
179 Sequence<OUString> aNames { "Executable" };
181 Sequence<Any> aValues = GetProperties(aNames);
182 const Any* pValues = aValues.getConstArray();
183 if(pValues[0].hasValue())
184 bLoadExecutable = *o3tl::doAccess<bool>(pValues[0]);
187 namespace {
189 class SvtCalcFilterOptions_Impl : public SvtAppFilterOptions_Impl
191 private:
192 bool bLoadExecutable;
194 virtual void ImplCommit() override;
196 public:
197 explicit SvtCalcFilterOptions_Impl(const OUString& rRoot) :
198 SvtAppFilterOptions_Impl(rRoot),
199 bLoadExecutable(false)
201 void Load();
203 bool IsLoadExecutable() const {return bLoadExecutable;}
204 void SetLoadExecutable(bool bSet)
206 if(bSet != bLoadExecutable)
207 SetModified();
208 bLoadExecutable = bSet;
214 void SvtCalcFilterOptions_Impl::ImplCommit()
216 SvtAppFilterOptions_Impl::ImplCommit();
218 Sequence<OUString> aNames { "Executable" };
219 Sequence<Any> aValues(1);
220 aValues[0] <<= bLoadExecutable;
222 PutProperties(aNames, aValues);
225 void SvtCalcFilterOptions_Impl::Load()
227 SvtAppFilterOptions_Impl::Load();
229 Sequence<OUString> aNames { "Executable" };
231 Sequence<Any> aValues = GetProperties(aNames);
232 const Any* pValues = aValues.getConstArray();
233 if(pValues[0].hasValue())
234 bLoadExecutable = *o3tl::doAccess<bool>(pValues[0]);
237 struct SvtFilterOptions_Impl
239 ConfigFlags nFlags;
240 SvtWriterFilterOptions_Impl aWriterCfg;
241 SvtCalcFilterOptions_Impl aCalcCfg;
242 SvtAppFilterOptions_Impl aImpressCfg;
244 SvtFilterOptions_Impl() :
245 aWriterCfg("Office.Writer/Filter/Import/VBA"),
246 aCalcCfg("Office.Calc/Filter/Import/VBA"),
247 aImpressCfg("Office.Impress/Filter/Import/VBA")
249 nFlags = ConfigFlags::WordCode |
250 ConfigFlags::WordStorage |
251 ConfigFlags::ExcelCode |
252 ConfigFlags::ExcelStorage |
253 ConfigFlags::PowerPointCode |
254 ConfigFlags::PowerPointStorage |
255 ConfigFlags::MathLoad |
256 ConfigFlags::MathSave |
257 ConfigFlags::WriterLoad |
258 ConfigFlags::WriterSave |
259 ConfigFlags::CalcLoad |
260 ConfigFlags::CalcSave |
261 ConfigFlags::ImpressLoad |
262 ConfigFlags::ImpressSave |
263 ConfigFlags::UseEnhancedFields |
264 ConfigFlags::SmartArtShapeLoad |
265 ConfigFlags::CharBackgroundToHighlighting|
266 ConfigFlags::CreateMSOLockFiles;
267 Load();
270 void SetFlag( ConfigFlags nFlag, bool bSet );
271 bool IsFlag( ConfigFlags nFlag ) const;
272 void Load()
274 aWriterCfg.Load();
275 aCalcCfg.Load();
276 aImpressCfg.Load();
280 void SvtFilterOptions_Impl::SetFlag( ConfigFlags nFlag, bool bSet )
282 switch(nFlag)
284 case ConfigFlags::WordCode: aWriterCfg.SetLoad(bSet);break;
285 case ConfigFlags::WordStorage: aWriterCfg.SetSave(bSet);break;
286 case ConfigFlags::WordWbctbl: aWriterCfg.SetLoadExecutable(bSet);break;
287 case ConfigFlags::ExcelCode: aCalcCfg.SetLoad(bSet);break;
288 case ConfigFlags::ExcelStorage: aCalcCfg.SetSave(bSet);break;
289 case ConfigFlags::ExcelExecTbl: aCalcCfg.SetLoadExecutable(bSet);break;
290 case ConfigFlags::PowerPointCode: aImpressCfg.SetLoad(bSet);break;
291 case ConfigFlags::PowerPointStorage: aImpressCfg.SetSave(bSet);break;
292 default:
293 if( bSet )
294 nFlags |= nFlag;
295 else
296 nFlags &= ~nFlag;
300 bool SvtFilterOptions_Impl::IsFlag( ConfigFlags nFlag ) const
302 bool bRet;
303 switch(nFlag)
305 case ConfigFlags::WordCode : bRet = aWriterCfg.IsLoad();break;
306 case ConfigFlags::WordStorage : bRet = aWriterCfg.IsSave();break;
307 case ConfigFlags::WordWbctbl : bRet = aWriterCfg.IsLoadExecutable();break;
308 case ConfigFlags::ExcelCode : bRet = aCalcCfg.IsLoad();break;
309 case ConfigFlags::ExcelStorage : bRet = aCalcCfg.IsSave();break;
310 case ConfigFlags::ExcelExecTbl : bRet = aCalcCfg.IsLoadExecutable();break;
311 case ConfigFlags::PowerPointCode : bRet = aImpressCfg.IsLoad();break;
312 case ConfigFlags::PowerPointStorage : bRet = aImpressCfg.IsSave();break;
313 default:
314 bRet = bool(nFlags & nFlag );
316 return bRet;
319 namespace {
321 const Sequence<OUString>& GetPropertyNames()
323 static Sequence<OUString> const aNames
325 "Import/MathTypeToMath", // 0
326 "Import/WinWordToWriter", // 1
327 "Import/PowerPointToImpress", // 2
328 "Import/ExcelToCalc", // 3
329 "Export/MathToMathType", // 4
330 "Export/WriterToWinWord", // 5
331 "Export/ImpressToPowerPoint", // 6
332 "Export/CalcToExcel", // 7
333 "Export/EnablePowerPointPreview", // 8
334 "Export/EnableExcelPreview", // 9
335 "Export/EnableWordPreview", // 10
336 "Import/ImportWWFieldsAsEnhancedFields", // 11
337 "Import/SmartArtToShapes", // 12
338 "Export/CharBackgroundToHighlighting", // 13
339 "Import/CreateMSOLockFiles", // 14
340 "Import/VisioToDraw" // 15
342 return aNames;
347 SvtFilterOptions::SvtFilterOptions() :
348 ConfigItem( "Office.Common/Filter/Microsoft" ),
349 pImpl(new SvtFilterOptions_Impl)
351 EnableNotification(GetPropertyNames());
352 Load();
355 SvtFilterOptions::~SvtFilterOptions()
359 static ConfigFlags lcl_GetFlag(sal_Int32 nProp)
361 ConfigFlags nFlag = ConfigFlags::NONE;
362 switch(nProp)
364 case 0: nFlag = ConfigFlags::MathLoad; break;
365 case 1: nFlag = ConfigFlags::WriterLoad; break;
366 case 2: nFlag = ConfigFlags::ImpressLoad; break;
367 case 3: nFlag = ConfigFlags::CalcLoad; break;
368 case 4: nFlag = ConfigFlags::MathSave; break;
369 case 5: nFlag = ConfigFlags::WriterSave; break;
370 case 6: nFlag = ConfigFlags::ImpressSave; break;
371 case 7: nFlag = ConfigFlags::CalcSave; break;
372 case 8: nFlag = ConfigFlags::EnablePowerPointPreview; break;
373 case 9: nFlag = ConfigFlags::EnableExcelPreview; break;
374 case 10: nFlag = ConfigFlags::EnableWordPreview; break;
375 case 11: nFlag = ConfigFlags::UseEnhancedFields; break;
376 case 12: nFlag = ConfigFlags::SmartArtShapeLoad; break;
377 case 13: nFlag = ConfigFlags::CharBackgroundToHighlighting; break;
378 case 14: nFlag = ConfigFlags::CreateMSOLockFiles; break;
379 case 15:
380 nFlag = ConfigFlags::VisioLoad;
381 break;
383 default: OSL_FAIL("illegal value");
385 return nFlag;
388 void SvtFilterOptions::Notify( const Sequence<OUString>& )
390 Load();
393 void SvtFilterOptions::ImplCommit()
395 const Sequence<OUString>& aNames = GetPropertyNames();
396 Sequence<Any> aValues(aNames.getLength());
397 Any* pValues = aValues.getArray();
399 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
401 ConfigFlags nFlag = lcl_GetFlag(nProp);
402 pValues[nProp] <<= pImpl->IsFlag(nFlag);
405 PutProperties(aNames, aValues);
408 void SvtFilterOptions::Load()
410 pImpl->Load();
411 const Sequence<OUString>& rNames = GetPropertyNames();
412 Sequence<Any> aValues = GetProperties(rNames);
413 const Any* pValues = aValues.getConstArray();
414 DBG_ASSERT(aValues.getLength() == rNames.getLength(), "GetProperties failed");
415 if(aValues.getLength() == rNames.getLength())
417 for(int nProp = 0; nProp < rNames.getLength(); nProp++)
419 if(pValues[nProp].hasValue())
421 bool bVal = *o3tl::doAccess<bool>(pValues[nProp]);
422 ConfigFlags nFlag = lcl_GetFlag(nProp);
423 pImpl->SetFlag( nFlag, bVal);
429 void SvtFilterOptions::SetLoadWordBasicCode( bool bFlag )
431 pImpl->SetFlag( ConfigFlags::WordCode, bFlag );
432 SetModified();
435 bool SvtFilterOptions::IsLoadWordBasicCode() const
437 return pImpl->IsFlag( ConfigFlags::WordCode );
440 void SvtFilterOptions::SetLoadWordBasicExecutable( bool bFlag )
442 pImpl->SetFlag( ConfigFlags::WordWbctbl, bFlag );
443 SetModified();
446 bool SvtFilterOptions::IsLoadWordBasicExecutable() const
448 return pImpl->IsFlag( ConfigFlags::WordWbctbl );
451 void SvtFilterOptions::SetLoadWordBasicStorage( bool bFlag )
453 pImpl->SetFlag( ConfigFlags::WordStorage, bFlag );
454 SetModified();
457 bool SvtFilterOptions::IsLoadWordBasicStorage() const
459 return pImpl->IsFlag( ConfigFlags::WordStorage );
462 void SvtFilterOptions::SetLoadExcelBasicCode( bool bFlag )
464 pImpl->SetFlag( ConfigFlags::ExcelCode, bFlag );
465 SetModified();
468 bool SvtFilterOptions::IsLoadExcelBasicCode() const
470 return pImpl->IsFlag( ConfigFlags::ExcelCode );
473 void SvtFilterOptions::SetLoadExcelBasicExecutable( bool bFlag )
475 pImpl->SetFlag( ConfigFlags::ExcelExecTbl, bFlag );
476 SetModified();
479 bool SvtFilterOptions::IsLoadExcelBasicExecutable() const
481 return pImpl->IsFlag( ConfigFlags::ExcelExecTbl );
484 void SvtFilterOptions::SetLoadExcelBasicStorage( bool bFlag )
486 pImpl->SetFlag( ConfigFlags::ExcelStorage, bFlag );
487 SetModified();
490 bool SvtFilterOptions::IsLoadExcelBasicStorage() const
492 return pImpl->IsFlag( ConfigFlags::ExcelStorage );
495 void SvtFilterOptions::SetLoadPPointBasicCode( bool bFlag )
497 pImpl->SetFlag( ConfigFlags::PowerPointCode, bFlag );
498 SetModified();
501 bool SvtFilterOptions::IsLoadPPointBasicCode() const
503 return pImpl->IsFlag( ConfigFlags::PowerPointCode );
506 void SvtFilterOptions::SetLoadPPointBasicStorage( bool bFlag )
508 pImpl->SetFlag( ConfigFlags::PowerPointStorage, bFlag );
509 SetModified();
512 bool SvtFilterOptions::IsLoadPPointBasicStorage() const
514 return pImpl->IsFlag( ConfigFlags::PowerPointStorage );
517 bool SvtFilterOptions::IsMathType2Math() const
519 return pImpl->IsFlag( ConfigFlags::MathLoad );
522 void SvtFilterOptions::SetMathType2Math( bool bFlag )
524 pImpl->SetFlag( ConfigFlags::MathLoad, bFlag );
525 SetModified();
528 bool SvtFilterOptions::IsMath2MathType() const
530 return pImpl->IsFlag( ConfigFlags::MathSave );
533 void SvtFilterOptions::SetMath2MathType( bool bFlag )
535 pImpl->SetFlag( ConfigFlags::MathSave, bFlag );
536 SetModified();
539 bool SvtFilterOptions::IsWinWord2Writer() const
541 return pImpl->IsFlag( ConfigFlags::WriterLoad );
544 void SvtFilterOptions::SetWinWord2Writer( bool bFlag )
546 pImpl->SetFlag( ConfigFlags::WriterLoad, bFlag );
547 SetModified();
550 bool SvtFilterOptions::IsWriter2WinWord() const
552 return pImpl->IsFlag( ConfigFlags::WriterSave );
555 void SvtFilterOptions::SetWriter2WinWord( bool bFlag )
557 pImpl->SetFlag( ConfigFlags::WriterSave, bFlag );
558 SetModified();
561 bool SvtFilterOptions::IsUseEnhancedFields() const
563 return pImpl->IsFlag( ConfigFlags::UseEnhancedFields );
566 bool SvtFilterOptions::IsExcel2Calc() const
568 return pImpl->IsFlag( ConfigFlags::CalcLoad );
571 void SvtFilterOptions::SetExcel2Calc( bool bFlag )
573 pImpl->SetFlag( ConfigFlags::CalcLoad, bFlag );
574 SetModified();
577 bool SvtFilterOptions::IsCalc2Excel() const
579 return pImpl->IsFlag( ConfigFlags::CalcSave );
582 void SvtFilterOptions::SetCalc2Excel( bool bFlag )
584 pImpl->SetFlag( ConfigFlags::CalcSave, bFlag );
585 SetModified();
588 bool SvtFilterOptions::IsPowerPoint2Impress() const
590 return pImpl->IsFlag( ConfigFlags::ImpressLoad );
593 void SvtFilterOptions::SetPowerPoint2Impress( bool bFlag )
595 pImpl->SetFlag( ConfigFlags::ImpressLoad, bFlag );
596 SetModified();
599 bool SvtFilterOptions::IsImpress2PowerPoint() const
601 return pImpl->IsFlag( ConfigFlags::ImpressSave );
604 void SvtFilterOptions::SetImpress2PowerPoint( bool bFlag )
606 pImpl->SetFlag( ConfigFlags::ImpressSave, bFlag );
607 SetModified();
610 bool SvtFilterOptions::IsSmartArt2Shape() const
612 return pImpl->IsFlag( ConfigFlags::SmartArtShapeLoad );
615 void SvtFilterOptions::SetSmartArt2Shape( bool bFlag )
617 pImpl->SetFlag( ConfigFlags::SmartArtShapeLoad, bFlag );
618 SetModified();
621 bool SvtFilterOptions::IsVisio2Draw() const { return pImpl->IsFlag(ConfigFlags::VisioLoad); }
623 void SvtFilterOptions::SetVisio2Draw(bool bFlag)
625 pImpl->SetFlag(ConfigFlags::VisioLoad, bFlag);
626 SetModified();
629 namespace
631 class theFilterOptions
632 : public rtl::Static<SvtFilterOptions, theFilterOptions>
637 SvtFilterOptions& SvtFilterOptions::Get()
639 return theFilterOptions::get();
642 bool SvtFilterOptions::IsEnablePPTPreview() const
644 return pImpl->IsFlag( ConfigFlags::EnablePowerPointPreview );
647 bool SvtFilterOptions::IsEnableCalcPreview() const
649 return pImpl->IsFlag( ConfigFlags::EnableExcelPreview );
652 bool SvtFilterOptions::IsEnableWordPreview() const
654 return pImpl->IsFlag( ConfigFlags::EnableWordPreview );
657 bool SvtFilterOptions::IsCharBackground2Highlighting() const
659 return pImpl->IsFlag( ConfigFlags::CharBackgroundToHighlighting );
662 bool SvtFilterOptions::IsCharBackground2Shading() const
664 return !pImpl->IsFlag( ConfigFlags::CharBackgroundToHighlighting );
667 void SvtFilterOptions::SetCharBackground2Highlighting()
669 pImpl->SetFlag( ConfigFlags::CharBackgroundToHighlighting, true );
670 SetModified();
673 void SvtFilterOptions::SetCharBackground2Shading()
675 pImpl->SetFlag( ConfigFlags::CharBackgroundToHighlighting, false );
676 SetModified();
679 bool SvtFilterOptions::IsMSOLockFileCreationIsEnabled() const
681 return pImpl->IsFlag( ConfigFlags::CreateMSOLockFiles );
684 void SvtFilterOptions::EnableMSOLockFileCreation(bool bEnable)
686 pImpl->SetFlag( ConfigFlags::CreateMSOLockFiles, bEnable );
687 SetModified();
690 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */