1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
29 using namespace com::sun::star::uno
;
31 enum class ConfigFlags
{
34 WordStorage
= 0x0000002,
35 ExcelCode
= 0x0000004,
36 ExcelStorage
= 0x0000008,
37 PowerPointCode
= 0x0000010,
38 PowerPointStorage
= 0x0000020,
41 WriterLoad
= 0x0000400,
42 WriterSave
= 0x0000800,
45 ImpressLoad
= 0x0004000,
46 ImpressSave
= 0x0008000,
47 ExcelExecTbl
= 0x0010000,
48 EnablePowerPointPreview
= 0x0020000,
49 EnableExcelPreview
= 0x0040000,
50 EnableWordPreview
= 0x0080000,
51 UseEnhancedFields
= 0x0100000,
52 WordWbctbl
= 0x0200000,
53 SmartArtShapeLoad
= 0x0400000,
54 CharBackgroundToHighlighting
= 0x8000000,
55 CreateMSOLockFiles
= 0x2000000,
56 VisioLoad
= 0x4000000,
59 template<> struct typed_flags
<ConfigFlags
> : is_typed_flags
<ConfigFlags
, 0xe7fff3f> {};
62 class SvtAppFilterOptions_Impl
: public utl::ConfigItem
69 virtual void ImplCommit() override
;
72 explicit SvtAppFilterOptions_Impl(const OUString
& rRoot
) :
73 utl::ConfigItem(rRoot
),
76 virtual ~SvtAppFilterOptions_Impl() override
;
77 virtual void Notify( const css::uno::Sequence
<OUString
>& aPropertyNames
) override
;
80 bool IsLoad() const {return bLoadVBA
;}
81 void SetLoad(bool bSet
)
87 bool IsSave() const {return bSaveVBA
;}
88 void SetSave(bool bSet
)
96 SvtAppFilterOptions_Impl::~SvtAppFilterOptions_Impl()
98 assert(!IsModified()); // should have been committed
101 void SvtAppFilterOptions_Impl::ImplCommit()
104 {"Load", "Save"}, {css::uno::Any(bLoadVBA
), css::uno::Any(bSaveVBA
)});
107 void SvtAppFilterOptions_Impl::Notify( const Sequence
< OUString
>& )
109 // no listeners supported yet
112 void SvtAppFilterOptions_Impl::Load()
114 Sequence
<OUString
> aNames(2);
115 OUString
* pNames
= aNames
.getArray();
119 Sequence
<Any
> aValues
= GetProperties(aNames
);
120 const Any
* pValues
= aValues
.getConstArray();
122 if(pValues
[0].hasValue())
123 bLoadVBA
= *o3tl::doAccess
<bool>(pValues
[0]);
124 if(pValues
[1].hasValue())
125 bSaveVBA
= *o3tl::doAccess
<bool>(pValues
[1]);
128 class SvtWriterFilterOptions_Impl
: public SvtAppFilterOptions_Impl
131 bool bLoadExecutable
;
133 virtual void ImplCommit() override
;
136 explicit SvtWriterFilterOptions_Impl(const OUString
& rRoot
) :
137 SvtAppFilterOptions_Impl(rRoot
),
138 bLoadExecutable(false)
142 bool IsLoadExecutable() const {return bLoadExecutable
;}
143 void SetLoadExecutable(bool bSet
)
145 if(bSet
!= bLoadExecutable
)
147 bLoadExecutable
= bSet
;
151 void SvtWriterFilterOptions_Impl::ImplCommit()
153 SvtAppFilterOptions_Impl::ImplCommit();
155 Sequence
<OUString
> aNames
{ "Executable" };
156 Sequence
<Any
> aValues(1);
157 aValues
[0] <<= bLoadExecutable
;
159 PutProperties(aNames
, aValues
);
162 void SvtWriterFilterOptions_Impl::Load()
164 SvtAppFilterOptions_Impl::Load();
166 Sequence
<OUString
> aNames
{ "Executable" };
168 Sequence
<Any
> aValues
= GetProperties(aNames
);
169 const Any
* pValues
= aValues
.getConstArray();
170 if(pValues
[0].hasValue())
171 bLoadExecutable
= *o3tl::doAccess
<bool>(pValues
[0]);
174 class SvtCalcFilterOptions_Impl
: public SvtAppFilterOptions_Impl
177 bool bLoadExecutable
;
179 virtual void ImplCommit() override
;
182 explicit SvtCalcFilterOptions_Impl(const OUString
& rRoot
) :
183 SvtAppFilterOptions_Impl(rRoot
),
184 bLoadExecutable(false)
188 bool IsLoadExecutable() const {return bLoadExecutable
;}
189 void SetLoadExecutable(bool bSet
)
191 if(bSet
!= bLoadExecutable
)
193 bLoadExecutable
= bSet
;
197 void SvtCalcFilterOptions_Impl::ImplCommit()
199 SvtAppFilterOptions_Impl::ImplCommit();
201 Sequence
<OUString
> aNames
{ "Executable" };
202 Sequence
<Any
> aValues(1);
203 aValues
[0] <<= bLoadExecutable
;
205 PutProperties(aNames
, aValues
);
208 void SvtCalcFilterOptions_Impl::Load()
210 SvtAppFilterOptions_Impl::Load();
212 Sequence
<OUString
> aNames
{ "Executable" };
214 Sequence
<Any
> aValues
= GetProperties(aNames
);
215 const Any
* pValues
= aValues
.getConstArray();
216 if(pValues
[0].hasValue())
217 bLoadExecutable
= *o3tl::doAccess
<bool>(pValues
[0]);
220 struct SvtFilterOptions_Impl
223 SvtWriterFilterOptions_Impl aWriterCfg
;
224 SvtCalcFilterOptions_Impl aCalcCfg
;
225 SvtAppFilterOptions_Impl aImpressCfg
;
227 SvtFilterOptions_Impl() :
228 aWriterCfg("Office.Writer/Filter/Import/VBA"),
229 aCalcCfg("Office.Calc/Filter/Import/VBA"),
230 aImpressCfg("Office.Impress/Filter/Import/VBA")
232 nFlags
= ConfigFlags::WordCode
|
233 ConfigFlags::WordStorage
|
234 ConfigFlags::ExcelCode
|
235 ConfigFlags::ExcelStorage
|
236 ConfigFlags::PowerPointCode
|
237 ConfigFlags::PowerPointStorage
|
238 ConfigFlags::MathLoad
|
239 ConfigFlags::MathSave
|
240 ConfigFlags::WriterLoad
|
241 ConfigFlags::WriterSave
|
242 ConfigFlags::CalcLoad
|
243 ConfigFlags::CalcSave
|
244 ConfigFlags::ImpressLoad
|
245 ConfigFlags::ImpressSave
|
246 ConfigFlags::UseEnhancedFields
|
247 ConfigFlags::SmartArtShapeLoad
|
248 ConfigFlags::CharBackgroundToHighlighting
|
249 ConfigFlags::CreateMSOLockFiles
;
253 void SetFlag( ConfigFlags nFlag
, bool bSet
);
254 bool IsFlag( ConfigFlags nFlag
) const;
263 void SvtFilterOptions_Impl::SetFlag( ConfigFlags nFlag
, bool bSet
)
267 case ConfigFlags::WordCode
: aWriterCfg
.SetLoad(bSet
);break;
268 case ConfigFlags::WordStorage
: aWriterCfg
.SetSave(bSet
);break;
269 case ConfigFlags::WordWbctbl
: aWriterCfg
.SetLoadExecutable(bSet
);break;
270 case ConfigFlags::ExcelCode
: aCalcCfg
.SetLoad(bSet
);break;
271 case ConfigFlags::ExcelStorage
: aCalcCfg
.SetSave(bSet
);break;
272 case ConfigFlags::ExcelExecTbl
: aCalcCfg
.SetLoadExecutable(bSet
);break;
273 case ConfigFlags::PowerPointCode
: aImpressCfg
.SetLoad(bSet
);break;
274 case ConfigFlags::PowerPointStorage
: aImpressCfg
.SetSave(bSet
);break;
283 bool SvtFilterOptions_Impl::IsFlag( ConfigFlags nFlag
) const
288 case ConfigFlags::WordCode
: bRet
= aWriterCfg
.IsLoad();break;
289 case ConfigFlags::WordStorage
: bRet
= aWriterCfg
.IsSave();break;
290 case ConfigFlags::WordWbctbl
: bRet
= aWriterCfg
.IsLoadExecutable();break;
291 case ConfigFlags::ExcelCode
: bRet
= aCalcCfg
.IsLoad();break;
292 case ConfigFlags::ExcelStorage
: bRet
= aCalcCfg
.IsSave();break;
293 case ConfigFlags::ExcelExecTbl
: bRet
= aCalcCfg
.IsLoadExecutable();break;
294 case ConfigFlags::PowerPointCode
: bRet
= aImpressCfg
.IsLoad();break;
295 case ConfigFlags::PowerPointStorage
: bRet
= aImpressCfg
.IsSave();break;
297 bRet
= bool(nFlags
& nFlag
);
304 const Sequence
<OUString
>& GetPropertyNames()
306 static Sequence
<OUString
> const aNames
308 "Import/MathTypeToMath", // 0
309 "Import/WinWordToWriter", // 1
310 "Import/PowerPointToImpress", // 2
311 "Import/ExcelToCalc", // 3
312 "Export/MathToMathType", // 4
313 "Export/WriterToWinWord", // 5
314 "Export/ImpressToPowerPoint", // 6
315 "Export/CalcToExcel", // 7
316 "Export/EnablePowerPointPreview", // 8
317 "Export/EnableExcelPreview", // 9
318 "Export/EnableWordPreview", // 10
319 "Import/ImportWWFieldsAsEnhancedFields", // 11
320 "Import/SmartArtToShapes", // 12
321 "Export/CharBackgroundToHighlighting", // 13
322 "Import/CreateMSOLockFiles", // 14
323 "Import/VisioToDraw" // 15
330 SvtFilterOptions::SvtFilterOptions() :
331 ConfigItem( "Office.Common/Filter/Microsoft" ),
332 pImpl(new SvtFilterOptions_Impl
)
334 EnableNotification(GetPropertyNames());
338 SvtFilterOptions::~SvtFilterOptions()
342 static ConfigFlags
lcl_GetFlag(sal_Int32 nProp
)
344 ConfigFlags nFlag
= ConfigFlags::NONE
;
347 case 0: nFlag
= ConfigFlags::MathLoad
; break;
348 case 1: nFlag
= ConfigFlags::WriterLoad
; break;
349 case 2: nFlag
= ConfigFlags::ImpressLoad
; break;
350 case 3: nFlag
= ConfigFlags::CalcLoad
; break;
351 case 4: nFlag
= ConfigFlags::MathSave
; break;
352 case 5: nFlag
= ConfigFlags::WriterSave
; break;
353 case 6: nFlag
= ConfigFlags::ImpressSave
; break;
354 case 7: nFlag
= ConfigFlags::CalcSave
; break;
355 case 8: nFlag
= ConfigFlags::EnablePowerPointPreview
; break;
356 case 9: nFlag
= ConfigFlags::EnableExcelPreview
; break;
357 case 10: nFlag
= ConfigFlags::EnableWordPreview
; break;
358 case 11: nFlag
= ConfigFlags::UseEnhancedFields
; break;
359 case 12: nFlag
= ConfigFlags::SmartArtShapeLoad
; break;
360 case 13: nFlag
= ConfigFlags::CharBackgroundToHighlighting
; break;
361 case 14: nFlag
= ConfigFlags::CreateMSOLockFiles
; break;
363 nFlag
= ConfigFlags::VisioLoad
;
366 default: OSL_FAIL("illegal value");
371 void SvtFilterOptions::Notify( const Sequence
<OUString
>& )
376 void SvtFilterOptions::ImplCommit()
378 const Sequence
<OUString
>& aNames
= GetPropertyNames();
379 Sequence
<Any
> aValues(aNames
.getLength());
380 Any
* pValues
= aValues
.getArray();
382 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
384 ConfigFlags nFlag
= lcl_GetFlag(nProp
);
385 pValues
[nProp
] <<= pImpl
->IsFlag(nFlag
);
388 PutProperties(aNames
, aValues
);
391 void SvtFilterOptions::Load()
394 const Sequence
<OUString
>& rNames
= GetPropertyNames();
395 Sequence
<Any
> aValues
= GetProperties(rNames
);
396 const Any
* pValues
= aValues
.getConstArray();
397 DBG_ASSERT(aValues
.getLength() == rNames
.getLength(), "GetProperties failed");
398 if(aValues
.getLength() == rNames
.getLength())
400 for(int nProp
= 0; nProp
< rNames
.getLength(); nProp
++)
402 if(pValues
[nProp
].hasValue())
404 bool bVal
= *o3tl::doAccess
<bool>(pValues
[nProp
]);
405 ConfigFlags nFlag
= lcl_GetFlag(nProp
);
406 pImpl
->SetFlag( nFlag
, bVal
);
412 void SvtFilterOptions::SetLoadWordBasicCode( bool bFlag
)
414 pImpl
->SetFlag( ConfigFlags::WordCode
, bFlag
);
418 bool SvtFilterOptions::IsLoadWordBasicCode() const
420 return pImpl
->IsFlag( ConfigFlags::WordCode
);
423 void SvtFilterOptions::SetLoadWordBasicExecutable( bool bFlag
)
425 pImpl
->SetFlag( ConfigFlags::WordWbctbl
, bFlag
);
429 bool SvtFilterOptions::IsLoadWordBasicExecutable() const
431 return pImpl
->IsFlag( ConfigFlags::WordWbctbl
);
434 void SvtFilterOptions::SetLoadWordBasicStorage( bool bFlag
)
436 pImpl
->SetFlag( ConfigFlags::WordStorage
, bFlag
);
440 bool SvtFilterOptions::IsLoadWordBasicStorage() const
442 return pImpl
->IsFlag( ConfigFlags::WordStorage
);
445 void SvtFilterOptions::SetLoadExcelBasicCode( bool bFlag
)
447 pImpl
->SetFlag( ConfigFlags::ExcelCode
, bFlag
);
451 bool SvtFilterOptions::IsLoadExcelBasicCode() const
453 return pImpl
->IsFlag( ConfigFlags::ExcelCode
);
456 void SvtFilterOptions::SetLoadExcelBasicExecutable( bool bFlag
)
458 pImpl
->SetFlag( ConfigFlags::ExcelExecTbl
, bFlag
);
462 bool SvtFilterOptions::IsLoadExcelBasicExecutable() const
464 return pImpl
->IsFlag( ConfigFlags::ExcelExecTbl
);
467 void SvtFilterOptions::SetLoadExcelBasicStorage( bool bFlag
)
469 pImpl
->SetFlag( ConfigFlags::ExcelStorage
, bFlag
);
473 bool SvtFilterOptions::IsLoadExcelBasicStorage() const
475 return pImpl
->IsFlag( ConfigFlags::ExcelStorage
);
478 void SvtFilterOptions::SetLoadPPointBasicCode( bool bFlag
)
480 pImpl
->SetFlag( ConfigFlags::PowerPointCode
, bFlag
);
484 bool SvtFilterOptions::IsLoadPPointBasicCode() const
486 return pImpl
->IsFlag( ConfigFlags::PowerPointCode
);
489 void SvtFilterOptions::SetLoadPPointBasicStorage( bool bFlag
)
491 pImpl
->SetFlag( ConfigFlags::PowerPointStorage
, bFlag
);
495 bool SvtFilterOptions::IsLoadPPointBasicStorage() const
497 return pImpl
->IsFlag( ConfigFlags::PowerPointStorage
);
500 bool SvtFilterOptions::IsMathType2Math() const
502 return pImpl
->IsFlag( ConfigFlags::MathLoad
);
505 void SvtFilterOptions::SetMathType2Math( bool bFlag
)
507 pImpl
->SetFlag( ConfigFlags::MathLoad
, bFlag
);
511 bool SvtFilterOptions::IsMath2MathType() const
513 return pImpl
->IsFlag( ConfigFlags::MathSave
);
516 void SvtFilterOptions::SetMath2MathType( bool bFlag
)
518 pImpl
->SetFlag( ConfigFlags::MathSave
, bFlag
);
522 bool SvtFilterOptions::IsWinWord2Writer() const
524 return pImpl
->IsFlag( ConfigFlags::WriterLoad
);
527 void SvtFilterOptions::SetWinWord2Writer( bool bFlag
)
529 pImpl
->SetFlag( ConfigFlags::WriterLoad
, bFlag
);
533 bool SvtFilterOptions::IsWriter2WinWord() const
535 return pImpl
->IsFlag( ConfigFlags::WriterSave
);
538 void SvtFilterOptions::SetWriter2WinWord( bool bFlag
)
540 pImpl
->SetFlag( ConfigFlags::WriterSave
, bFlag
);
544 bool SvtFilterOptions::IsUseEnhancedFields() const
546 return pImpl
->IsFlag( ConfigFlags::UseEnhancedFields
);
549 bool SvtFilterOptions::IsExcel2Calc() const
551 return pImpl
->IsFlag( ConfigFlags::CalcLoad
);
554 void SvtFilterOptions::SetExcel2Calc( bool bFlag
)
556 pImpl
->SetFlag( ConfigFlags::CalcLoad
, bFlag
);
560 bool SvtFilterOptions::IsCalc2Excel() const
562 return pImpl
->IsFlag( ConfigFlags::CalcSave
);
565 void SvtFilterOptions::SetCalc2Excel( bool bFlag
)
567 pImpl
->SetFlag( ConfigFlags::CalcSave
, bFlag
);
571 bool SvtFilterOptions::IsPowerPoint2Impress() const
573 return pImpl
->IsFlag( ConfigFlags::ImpressLoad
);
576 void SvtFilterOptions::SetPowerPoint2Impress( bool bFlag
)
578 pImpl
->SetFlag( ConfigFlags::ImpressLoad
, bFlag
);
582 bool SvtFilterOptions::IsImpress2PowerPoint() const
584 return pImpl
->IsFlag( ConfigFlags::ImpressSave
);
587 void SvtFilterOptions::SetImpress2PowerPoint( bool bFlag
)
589 pImpl
->SetFlag( ConfigFlags::ImpressSave
, bFlag
);
593 bool SvtFilterOptions::IsSmartArt2Shape() const
595 return pImpl
->IsFlag( ConfigFlags::SmartArtShapeLoad
);
598 void SvtFilterOptions::SetSmartArt2Shape( bool bFlag
)
600 pImpl
->SetFlag( ConfigFlags::SmartArtShapeLoad
, bFlag
);
604 bool SvtFilterOptions::IsVisio2Draw() const { return pImpl
->IsFlag(ConfigFlags::VisioLoad
); }
606 void SvtFilterOptions::SetVisio2Draw(bool bFlag
)
608 pImpl
->SetFlag(ConfigFlags::VisioLoad
, bFlag
);
614 class theFilterOptions
615 : public rtl::Static
<SvtFilterOptions
, theFilterOptions
>
620 SvtFilterOptions
& SvtFilterOptions::Get()
622 return theFilterOptions::get();
625 bool SvtFilterOptions::IsEnablePPTPreview() const
627 return pImpl
->IsFlag( ConfigFlags::EnablePowerPointPreview
);
630 bool SvtFilterOptions::IsEnableCalcPreview() const
632 return pImpl
->IsFlag( ConfigFlags::EnableExcelPreview
);
635 bool SvtFilterOptions::IsEnableWordPreview() const
637 return pImpl
->IsFlag( ConfigFlags::EnableWordPreview
);
640 bool SvtFilterOptions::IsCharBackground2Highlighting() const
642 return pImpl
->IsFlag( ConfigFlags::CharBackgroundToHighlighting
);
645 bool SvtFilterOptions::IsCharBackground2Shading() const
647 return !pImpl
->IsFlag( ConfigFlags::CharBackgroundToHighlighting
);
650 void SvtFilterOptions::SetCharBackground2Highlighting()
652 pImpl
->SetFlag( ConfigFlags::CharBackgroundToHighlighting
, true );
656 void SvtFilterOptions::SetCharBackground2Shading()
658 pImpl
->SetFlag( ConfigFlags::CharBackgroundToHighlighting
, false );
662 bool SvtFilterOptions::IsMSOLockFileCreationIsEnabled() const
664 return pImpl
->IsFlag( ConfigFlags::CreateMSOLockFiles
);
667 void SvtFilterOptions::EnableMSOLockFileCreation(bool bEnable
)
669 pImpl
->SetFlag( ConfigFlags::CreateMSOLockFiles
, bEnable
);
673 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */