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 <config_features.h>
22 #include <unotools/fltrcfg.hxx>
23 #include <tools/debug.hxx>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/uno/Sequence.hxx>
29 using namespace com::sun::star::uno
;
31 #define FILTERCFG_WORD_CODE 0x0001
32 #define FILTERCFG_WORD_STORAGE 0x0002
33 #define FILTERCFG_EXCEL_CODE 0x0004
34 #define FILTERCFG_EXCEL_STORAGE 0x0008
35 #define FILTERCFG_PPOINT_CODE 0x0010
36 #define FILTERCFG_PPOINT_STORAGE 0x0020
37 #define FILTERCFG_MATH_LOAD 0x0100
38 #define FILTERCFG_MATH_SAVE 0x0200
39 #define FILTERCFG_WRITER_LOAD 0x0400
40 #define FILTERCFG_WRITER_SAVE 0x0800
41 #define FILTERCFG_CALC_LOAD 0x1000
42 #define FILTERCFG_CALC_SAVE 0x2000
43 #define FILTERCFG_IMPRESS_LOAD 0x4000
44 #define FILTERCFG_IMPRESS_SAVE 0x8000
45 #define FILTERCFG_EXCEL_EXECTBL 0x10000
46 #define FILTERCFG_ENABLE_PPT_PREVIEW 0x20000
47 #define FILTERCFG_ENABLE_EXCEL_PREVIEW 0x40000
48 #define FILTERCFG_ENABLE_WORD_PREVIEW 0x80000
49 #define FILTERCFG_USE_ENHANCED_FIELDS 0x100000
50 #define FILTERCFG_WORD_WBCTBL 0x200000
51 #define FILTERCFG_SMARTART_SHAPE_LOAD 0x400000
53 class SvtAppFilterOptions_Impl
: public utl::ConfigItem
58 SvtAppFilterOptions_Impl(const OUString
& rRoot
) :
59 utl::ConfigItem(rRoot
),
62 virtual ~SvtAppFilterOptions_Impl();
63 virtual void Commit() SAL_OVERRIDE
;
64 virtual void Notify( const com::sun::star::uno::Sequence
<OUString
>& aPropertyNames
) SAL_OVERRIDE
;
67 bool IsLoad() const {return bLoadVBA
;}
68 void SetLoad(bool bSet
)
74 bool IsSave() const {return bSaveVBA
;}
75 void SetSave(bool bSet
)
83 SvtAppFilterOptions_Impl::~SvtAppFilterOptions_Impl()
89 void SvtAppFilterOptions_Impl::Commit()
91 Sequence
<OUString
> aNames(2);
92 OUString
* pNames
= aNames
.getArray();
95 Sequence
<Any
> aValues(aNames
.getLength());
96 Any
* pValues
= aValues
.getArray();
98 const Type
& rType
= ::getBooleanCppuType();
99 pValues
[0].setValue(&bLoadVBA
, rType
);
100 pValues
[1].setValue(&bSaveVBA
, rType
);
102 PutProperties(aNames
, aValues
);
105 void SvtAppFilterOptions_Impl::Notify( const Sequence
< OUString
>& )
107 // no listeners supported yet
110 void SvtAppFilterOptions_Impl::Load()
112 Sequence
<OUString
> aNames(2);
113 OUString
* pNames
= aNames
.getArray();
117 Sequence
<Any
> aValues
= GetProperties(aNames
);
118 const Any
* pValues
= aValues
.getConstArray();
120 if(pValues
[0].hasValue())
121 bLoadVBA
= *(sal_Bool
*)pValues
[0].getValue();
122 if(pValues
[1].hasValue())
123 bSaveVBA
= *(sal_Bool
*)pValues
[1].getValue();
126 class SvtWriterFilterOptions_Impl
: public SvtAppFilterOptions_Impl
128 bool bLoadExecutable
;
130 SvtWriterFilterOptions_Impl(const OUString
& rRoot
) :
131 SvtAppFilterOptions_Impl(rRoot
),
132 bLoadExecutable(false)
134 virtual void Commit() SAL_OVERRIDE
;
137 bool IsLoadExecutable() const {return bLoadExecutable
;}
138 void SetLoadExecutable(bool bSet
)
140 if(bSet
!= bLoadExecutable
)
142 bLoadExecutable
= bSet
;
146 void SvtWriterFilterOptions_Impl::Commit()
148 SvtAppFilterOptions_Impl::Commit();
150 Sequence
<OUString
> aNames(1);
151 aNames
[0] = "Executable";
152 Sequence
<Any
> aValues(1);
153 aValues
[0] <<= bLoadExecutable
;
155 PutProperties(aNames
, aValues
);
158 void SvtWriterFilterOptions_Impl::Load()
160 SvtAppFilterOptions_Impl::Load();
162 Sequence
<OUString
> aNames(1);
163 aNames
[0] = "Executable";
165 Sequence
<Any
> aValues
= GetProperties(aNames
);
166 const Any
* pValues
= aValues
.getConstArray();
167 if(pValues
[0].hasValue())
168 bLoadExecutable
= *(sal_Bool
*)pValues
[0].getValue();
171 class SvtCalcFilterOptions_Impl
: public SvtAppFilterOptions_Impl
173 bool bLoadExecutable
;
175 SvtCalcFilterOptions_Impl(const OUString
& rRoot
) :
176 SvtAppFilterOptions_Impl(rRoot
),
177 bLoadExecutable(false)
179 virtual void Commit() SAL_OVERRIDE
;
182 bool IsLoadExecutable() const {return bLoadExecutable
;}
183 void SetLoadExecutable(bool bSet
)
185 if(bSet
!= bLoadExecutable
)
187 bLoadExecutable
= bSet
;
191 void SvtCalcFilterOptions_Impl::Commit()
193 SvtAppFilterOptions_Impl::Commit();
195 Sequence
<OUString
> aNames(1);
196 aNames
[0] = "Executable";
197 Sequence
<Any
> aValues(1);
198 aValues
[0] <<= bLoadExecutable
;
200 PutProperties(aNames
, aValues
);
203 void SvtCalcFilterOptions_Impl::Load()
205 SvtAppFilterOptions_Impl::Load();
207 Sequence
<OUString
> aNames(1);
208 aNames
[0] = "Executable";
210 Sequence
<Any
> aValues
= GetProperties(aNames
);
211 const Any
* pValues
= aValues
.getConstArray();
212 if(pValues
[0].hasValue())
213 bLoadExecutable
= *(sal_Bool
*)pValues
[0].getValue();
216 struct SvtFilterOptions_Impl
219 SvtWriterFilterOptions_Impl aWriterCfg
;
220 SvtCalcFilterOptions_Impl aCalcCfg
;
221 SvtAppFilterOptions_Impl aImpressCfg
;
223 SvtFilterOptions_Impl() :
224 aWriterCfg("Office.Writer/Filter/Import/VBA"),
225 aCalcCfg("Office.Calc/Filter/Import/VBA"),
226 aImpressCfg("Office.Impress/Filter/Import/VBA")
228 nFlags
= FILTERCFG_WORD_CODE
|
229 FILTERCFG_WORD_STORAGE
|
230 FILTERCFG_EXCEL_CODE
|
231 FILTERCFG_EXCEL_STORAGE
|
232 FILTERCFG_PPOINT_CODE
|
233 FILTERCFG_PPOINT_STORAGE
|
234 FILTERCFG_MATH_LOAD
|
235 FILTERCFG_MATH_SAVE
|
236 FILTERCFG_WRITER_LOAD
|
237 FILTERCFG_WRITER_SAVE
|
238 FILTERCFG_CALC_LOAD
|
239 FILTERCFG_CALC_SAVE
|
240 FILTERCFG_IMPRESS_LOAD
|
241 FILTERCFG_IMPRESS_SAVE
|
242 FILTERCFG_USE_ENHANCED_FIELDS
|
243 FILTERCFG_SMARTART_SHAPE_LOAD
;
247 void SetFlag( sal_uLong nFlag
, bool bSet
);
248 bool IsFlag( sal_uLong nFlag
) const;
257 void SvtFilterOptions_Impl::SetFlag( sal_uLong nFlag
, bool bSet
)
261 case FILTERCFG_WORD_CODE
: aWriterCfg
.SetLoad(bSet
);break;
262 case FILTERCFG_WORD_STORAGE
: aWriterCfg
.SetSave(bSet
);break;
263 case FILTERCFG_WORD_WBCTBL
: aWriterCfg
.SetLoadExecutable(bSet
);break;
264 case FILTERCFG_EXCEL_CODE
: aCalcCfg
.SetLoad(bSet
);break;
265 case FILTERCFG_EXCEL_STORAGE
: aCalcCfg
.SetSave(bSet
);break;
266 case FILTERCFG_EXCEL_EXECTBL
: aCalcCfg
.SetLoadExecutable(bSet
);break;
267 case FILTERCFG_PPOINT_CODE
: aImpressCfg
.SetLoad(bSet
);break;
268 case FILTERCFG_PPOINT_STORAGE
: aImpressCfg
.SetSave(bSet
);break;
277 bool SvtFilterOptions_Impl::IsFlag( sal_uLong nFlag
) const
282 case FILTERCFG_WORD_CODE
: bRet
= aWriterCfg
.IsLoad();break;
283 case FILTERCFG_WORD_STORAGE
: bRet
= aWriterCfg
.IsSave();break;
284 case FILTERCFG_WORD_WBCTBL
: bRet
= aWriterCfg
.IsLoadExecutable();break;
285 case FILTERCFG_EXCEL_CODE
: bRet
= aCalcCfg
.IsLoad();break;
286 case FILTERCFG_EXCEL_STORAGE
: bRet
= aCalcCfg
.IsSave();break;
287 case FILTERCFG_EXCEL_EXECTBL
: bRet
= aCalcCfg
.IsLoadExecutable();break;
288 case FILTERCFG_PPOINT_CODE
: bRet
= aImpressCfg
.IsLoad();break;
289 case FILTERCFG_PPOINT_STORAGE
: bRet
= aImpressCfg
.IsSave();break;
291 bRet
= 0 != (nFlags
& nFlag
);
296 SvtFilterOptions::SvtFilterOptions() :
297 ConfigItem( "Office.Common/Filter/Microsoft" ),
298 pImp(new SvtFilterOptions_Impl
)
300 EnableNotification(GetPropertyNames());
304 SvtFilterOptions::~SvtFilterOptions()
309 const Sequence
<OUString
>& SvtFilterOptions::GetPropertyNames()
311 static Sequence
<OUString
> aNames
;
312 if(!aNames
.getLength())
315 aNames
.realloc(nCount
);
316 static const char* aPropNames
[] =
318 "Import/MathTypeToMath", // 0
319 "Import/WinWordToWriter", // 1
320 "Import/PowerPointToImpress", // 2
321 "Import/ExcelToCalc", // 3
322 "Export/MathToMathType", // 4
323 "Export/WriterToWinWord", // 5
324 "Export/ImpressToPowerPoint", // 6
325 "Export/CalcToExcel", // 7
326 "Export/EnablePowerPointPreview", // 8
327 "Export/EnableExcelPreview", // 9
328 "Export/EnableWordPreview", // 10
329 "Import/ImportWWFieldsAsEnhancedFields", // 11
330 "Import/SmartArtToShapes" // 12
332 OUString
* pNames
= aNames
.getArray();
333 for(int i
= 0; i
< nCount
; i
++)
334 pNames
[i
] = OUString::createFromAscii(aPropNames
[i
]);
339 static sal_uLong
lcl_GetFlag(sal_Int32 nProp
)
344 case 0: nFlag
= FILTERCFG_MATH_LOAD
; break;
345 case 1: nFlag
= FILTERCFG_WRITER_LOAD
; break;
346 case 2: nFlag
= FILTERCFG_IMPRESS_LOAD
; break;
347 case 3: nFlag
= FILTERCFG_CALC_LOAD
; break;
348 case 4: nFlag
= FILTERCFG_MATH_SAVE
; break;
349 case 5: nFlag
= FILTERCFG_WRITER_SAVE
; break;
350 case 6: nFlag
= FILTERCFG_IMPRESS_SAVE
; break;
351 case 7: nFlag
= FILTERCFG_CALC_SAVE
; break;
352 case 8: nFlag
= FILTERCFG_ENABLE_PPT_PREVIEW
; break;
353 case 9: nFlag
= FILTERCFG_ENABLE_EXCEL_PREVIEW
; break;
354 case 10: nFlag
= FILTERCFG_ENABLE_WORD_PREVIEW
; break;
355 case 11: nFlag
= FILTERCFG_USE_ENHANCED_FIELDS
; break;
356 case 12: nFlag
= FILTERCFG_SMARTART_SHAPE_LOAD
; break;
358 default: OSL_FAIL("illegal value");
363 void SvtFilterOptions::Notify( const Sequence
<OUString
>& )
368 void SvtFilterOptions::Commit()
370 const Sequence
<OUString
>& aNames
= GetPropertyNames();
371 Sequence
<Any
> aValues(aNames
.getLength());
372 Any
* pValues
= aValues
.getArray();
374 const Type
& rType
= ::getBooleanCppuType();
375 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
377 sal_uLong nFlag
= lcl_GetFlag(nProp
);
378 sal_Bool bVal
= pImp
->IsFlag( nFlag
);
379 pValues
[nProp
].setValue(&bVal
, rType
);
382 PutProperties(aNames
, aValues
);
385 void SvtFilterOptions::Load()
388 const Sequence
<OUString
>& rNames
= GetPropertyNames();
389 Sequence
<Any
> aValues
= GetProperties(rNames
);
390 const Any
* pValues
= aValues
.getConstArray();
391 DBG_ASSERT(aValues
.getLength() == rNames
.getLength(), "GetProperties failed");
392 if(aValues
.getLength() == rNames
.getLength())
394 for(int nProp
= 0; nProp
< rNames
.getLength(); nProp
++)
396 if(pValues
[nProp
].hasValue())
398 bool bVal
= *(sal_Bool
*)pValues
[nProp
].getValue();
399 sal_uLong nFlag
= lcl_GetFlag(nProp
);
400 pImp
->SetFlag( nFlag
, bVal
);
406 void SvtFilterOptions::SetLoadWordBasicCode( bool bFlag
)
408 pImp
->SetFlag( FILTERCFG_WORD_CODE
, bFlag
);
412 bool SvtFilterOptions::IsLoadWordBasicCode() const
414 return pImp
->IsFlag( FILTERCFG_WORD_CODE
);
417 void SvtFilterOptions::SetLoadWordBasicExecutable( bool bFlag
)
419 pImp
->SetFlag( FILTERCFG_WORD_WBCTBL
, bFlag
);
423 bool SvtFilterOptions::IsLoadWordBasicExecutable() const
425 return pImp
->IsFlag( FILTERCFG_WORD_WBCTBL
);
428 void SvtFilterOptions::SetLoadWordBasicStorage( bool bFlag
)
430 pImp
->SetFlag( FILTERCFG_WORD_STORAGE
, bFlag
);
434 bool SvtFilterOptions::IsLoadWordBasicStorage() const
436 return pImp
->IsFlag( FILTERCFG_WORD_STORAGE
);
439 void SvtFilterOptions::SetLoadExcelBasicCode( bool bFlag
)
441 pImp
->SetFlag( FILTERCFG_EXCEL_CODE
, bFlag
);
445 bool SvtFilterOptions::IsLoadExcelBasicCode() const
447 return pImp
->IsFlag( FILTERCFG_EXCEL_CODE
);
450 void SvtFilterOptions::SetLoadExcelBasicExecutable( bool bFlag
)
452 pImp
->SetFlag( FILTERCFG_EXCEL_EXECTBL
, bFlag
);
456 bool SvtFilterOptions::IsLoadExcelBasicExecutable() const
458 return pImp
->IsFlag( FILTERCFG_EXCEL_EXECTBL
);
461 void SvtFilterOptions::SetLoadExcelBasicStorage( bool bFlag
)
463 pImp
->SetFlag( FILTERCFG_EXCEL_STORAGE
, bFlag
);
467 bool SvtFilterOptions::IsLoadExcelBasicStorage() const
469 return pImp
->IsFlag( FILTERCFG_EXCEL_STORAGE
);
472 void SvtFilterOptions::SetLoadPPointBasicCode( bool bFlag
)
474 pImp
->SetFlag( FILTERCFG_PPOINT_CODE
, bFlag
);
478 bool SvtFilterOptions::IsLoadPPointBasicCode() const
480 return pImp
->IsFlag( FILTERCFG_PPOINT_CODE
);
483 void SvtFilterOptions::SetLoadPPointBasicStorage( bool bFlag
)
485 pImp
->SetFlag( FILTERCFG_PPOINT_STORAGE
, bFlag
);
489 bool SvtFilterOptions::IsLoadPPointBasicStorage() const
491 return pImp
->IsFlag( FILTERCFG_PPOINT_STORAGE
);
494 bool SvtFilterOptions::IsMathType2Math() const
496 return pImp
->IsFlag( FILTERCFG_MATH_LOAD
);
499 void SvtFilterOptions::SetMathType2Math( bool bFlag
)
501 pImp
->SetFlag( FILTERCFG_MATH_LOAD
, bFlag
);
505 bool SvtFilterOptions::IsMath2MathType() const
507 return pImp
->IsFlag( FILTERCFG_MATH_SAVE
);
510 void SvtFilterOptions::SetMath2MathType( bool bFlag
)
512 pImp
->SetFlag( FILTERCFG_MATH_SAVE
, bFlag
);
516 bool SvtFilterOptions::IsWinWord2Writer() const
518 return pImp
->IsFlag( FILTERCFG_WRITER_LOAD
);
521 void SvtFilterOptions::SetWinWord2Writer( bool bFlag
)
523 pImp
->SetFlag( FILTERCFG_WRITER_LOAD
, bFlag
);
527 bool SvtFilterOptions::IsWriter2WinWord() const
529 return pImp
->IsFlag( FILTERCFG_WRITER_SAVE
);
532 void SvtFilterOptions::SetWriter2WinWord( bool bFlag
)
534 pImp
->SetFlag( FILTERCFG_WRITER_SAVE
, bFlag
);
538 bool SvtFilterOptions::IsUseEnhancedFields() const
540 return pImp
->IsFlag( FILTERCFG_USE_ENHANCED_FIELDS
);
543 bool SvtFilterOptions::IsExcel2Calc() const
545 return pImp
->IsFlag( FILTERCFG_CALC_LOAD
);
548 void SvtFilterOptions::SetExcel2Calc( bool bFlag
)
550 pImp
->SetFlag( FILTERCFG_CALC_LOAD
, bFlag
);
554 bool SvtFilterOptions::IsCalc2Excel() const
556 return pImp
->IsFlag( FILTERCFG_CALC_SAVE
);
559 void SvtFilterOptions::SetCalc2Excel( bool bFlag
)
561 pImp
->SetFlag( FILTERCFG_CALC_SAVE
, bFlag
);
565 bool SvtFilterOptions::IsPowerPoint2Impress() const
567 return pImp
->IsFlag( FILTERCFG_IMPRESS_LOAD
);
570 void SvtFilterOptions::SetPowerPoint2Impress( bool bFlag
)
572 pImp
->SetFlag( FILTERCFG_IMPRESS_LOAD
, bFlag
);
576 bool SvtFilterOptions::IsImpress2PowerPoint() const
578 return pImp
->IsFlag( FILTERCFG_IMPRESS_SAVE
);
581 void SvtFilterOptions::SetImpress2PowerPoint( bool bFlag
)
583 pImp
->SetFlag( FILTERCFG_IMPRESS_SAVE
, bFlag
);
587 bool SvtFilterOptions::IsSmartArt2Shape() const
589 return pImp
->IsFlag( FILTERCFG_SMARTART_SHAPE_LOAD
);
592 void SvtFilterOptions::SetSmartArt2Shape( bool bFlag
)
594 pImp
->SetFlag( FILTERCFG_SMARTART_SHAPE_LOAD
, bFlag
);
600 class theFilterOptions
601 : public rtl::Static
<SvtFilterOptions
, theFilterOptions
>
606 SvtFilterOptions
& SvtFilterOptions::Get()
608 return theFilterOptions::get();
611 bool SvtFilterOptions::IsEnablePPTPreview() const
613 return pImp
->IsFlag( FILTERCFG_ENABLE_PPT_PREVIEW
);
616 bool SvtFilterOptions::IsEnableCalcPreview() const
618 return pImp
->IsFlag( FILTERCFG_ENABLE_EXCEL_PREVIEW
);
621 bool SvtFilterOptions::IsEnableWordPreview() const
623 return pImp
->IsFlag( FILTERCFG_ENABLE_WORD_PREVIEW
);
626 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */