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>
24 #include <tools/solar.h>
25 #include <osl/diagnose.h>
27 #include <com/sun/star/uno/Any.hxx>
28 #include <com/sun/star/uno/Sequence.hxx>
31 using namespace com::sun::star::uno
;
33 #define FILTERCFG_WORD_CODE 0x0001
34 #define FILTERCFG_WORD_STORAGE 0x0002
35 #define FILTERCFG_EXCEL_CODE 0x0004
36 #define FILTERCFG_EXCEL_STORAGE 0x0008
37 #define FILTERCFG_PPOINT_CODE 0x0010
38 #define FILTERCFG_PPOINT_STORAGE 0x0020
39 #define FILTERCFG_MATH_LOAD 0x0100
40 #define FILTERCFG_MATH_SAVE 0x0200
41 #define FILTERCFG_WRITER_LOAD 0x0400
42 #define FILTERCFG_WRITER_SAVE 0x0800
43 #define FILTERCFG_CALC_LOAD 0x1000
44 #define FILTERCFG_CALC_SAVE 0x2000
45 #define FILTERCFG_IMPRESS_LOAD 0x4000
46 #define FILTERCFG_IMPRESS_SAVE 0x8000
47 #define FILTERCFG_EXCEL_EXECTBL 0x10000
48 #define FILTERCFG_ENABLE_PPT_PREVIEW 0x20000
49 #define FILTERCFG_ENABLE_EXCEL_PREVIEW 0x40000
50 #define FILTERCFG_ENABLE_WORD_PREVIEW 0x80000
51 #define FILTERCFG_USE_ENHANCED_FIELDS 0x100000
52 #define FILTERCFG_WORD_WBCTBL 0x200000
53 #define FILTERCFG_SMARTART_SHAPE_LOAD 0x400000
54 #define FILTERCFG_CHAR_BACKGROUND_TO_HIGHLIGHTING 0x8000000
56 class SvtAppFilterOptions_Impl
: public utl::ConfigItem
63 virtual void ImplCommit() SAL_OVERRIDE
;
66 SvtAppFilterOptions_Impl(const OUString
& rRoot
) :
67 utl::ConfigItem(rRoot
),
70 virtual ~SvtAppFilterOptions_Impl();
71 virtual void Notify( const com::sun::star::uno::Sequence
<OUString
>& aPropertyNames
) SAL_OVERRIDE
;
74 bool IsLoad() const {return bLoadVBA
;}
75 void SetLoad(bool bSet
)
81 bool IsSave() const {return bSaveVBA
;}
82 void SetSave(bool bSet
)
90 SvtAppFilterOptions_Impl::~SvtAppFilterOptions_Impl()
92 assert(!IsModified()); // should have been committed
95 void SvtAppFilterOptions_Impl::ImplCommit()
97 Sequence
<OUString
> aNames(2);
98 OUString
* pNames
= aNames
.getArray();
101 Sequence
<Any
> aValues(aNames
.getLength());
102 Any
* pValues
= aValues
.getArray();
104 const Type
& rType
= cppu::UnoType
<bool>::get();
105 pValues
[0].setValue(&bLoadVBA
, rType
);
106 pValues
[1].setValue(&bSaveVBA
, rType
);
108 PutProperties(aNames
, aValues
);
111 void SvtAppFilterOptions_Impl::Notify( const Sequence
< OUString
>& )
113 // no listeners supported yet
116 void SvtAppFilterOptions_Impl::Load()
118 Sequence
<OUString
> aNames(2);
119 OUString
* pNames
= aNames
.getArray();
123 Sequence
<Any
> aValues
= GetProperties(aNames
);
124 const Any
* pValues
= aValues
.getConstArray();
126 if(pValues
[0].hasValue())
127 bLoadVBA
= *static_cast<sal_Bool
const *>(pValues
[0].getValue());
128 if(pValues
[1].hasValue())
129 bSaveVBA
= *static_cast<sal_Bool
const *>(pValues
[1].getValue());
132 class SvtWriterFilterOptions_Impl
: public SvtAppFilterOptions_Impl
135 bool bLoadExecutable
;
137 virtual void ImplCommit() SAL_OVERRIDE
;
140 SvtWriterFilterOptions_Impl(const OUString
& rRoot
) :
141 SvtAppFilterOptions_Impl(rRoot
),
142 bLoadExecutable(false)
146 bool IsLoadExecutable() const {return bLoadExecutable
;}
147 void SetLoadExecutable(bool bSet
)
149 if(bSet
!= bLoadExecutable
)
151 bLoadExecutable
= bSet
;
155 void SvtWriterFilterOptions_Impl::ImplCommit()
157 SvtAppFilterOptions_Impl::ImplCommit();
159 Sequence
<OUString
> aNames(1);
160 aNames
[0] = "Executable";
161 Sequence
<Any
> aValues(1);
162 aValues
[0] <<= bLoadExecutable
;
164 PutProperties(aNames
, aValues
);
167 void SvtWriterFilterOptions_Impl::Load()
169 SvtAppFilterOptions_Impl::Load();
171 Sequence
<OUString
> aNames(1);
172 aNames
[0] = "Executable";
174 Sequence
<Any
> aValues
= GetProperties(aNames
);
175 const Any
* pValues
= aValues
.getConstArray();
176 if(pValues
[0].hasValue())
177 bLoadExecutable
= *static_cast<sal_Bool
const *>(pValues
[0].getValue());
180 class SvtCalcFilterOptions_Impl
: public SvtAppFilterOptions_Impl
183 bool bLoadExecutable
;
185 virtual void ImplCommit() SAL_OVERRIDE
;
188 SvtCalcFilterOptions_Impl(const OUString
& rRoot
) :
189 SvtAppFilterOptions_Impl(rRoot
),
190 bLoadExecutable(false)
194 bool IsLoadExecutable() const {return bLoadExecutable
;}
195 void SetLoadExecutable(bool bSet
)
197 if(bSet
!= bLoadExecutable
)
199 bLoadExecutable
= bSet
;
203 void SvtCalcFilterOptions_Impl::ImplCommit()
205 SvtAppFilterOptions_Impl::ImplCommit();
207 Sequence
<OUString
> aNames(1);
208 aNames
[0] = "Executable";
209 Sequence
<Any
> aValues(1);
210 aValues
[0] <<= bLoadExecutable
;
212 PutProperties(aNames
, aValues
);
215 void SvtCalcFilterOptions_Impl::Load()
217 SvtAppFilterOptions_Impl::Load();
219 Sequence
<OUString
> aNames(1);
220 aNames
[0] = "Executable";
222 Sequence
<Any
> aValues
= GetProperties(aNames
);
223 const Any
* pValues
= aValues
.getConstArray();
224 if(pValues
[0].hasValue())
225 bLoadExecutable
= *static_cast<sal_Bool
const *>(pValues
[0].getValue());
228 struct SvtFilterOptions_Impl
231 SvtWriterFilterOptions_Impl aWriterCfg
;
232 SvtCalcFilterOptions_Impl aCalcCfg
;
233 SvtAppFilterOptions_Impl aImpressCfg
;
235 SvtFilterOptions_Impl() :
236 aWriterCfg("Office.Writer/Filter/Import/VBA"),
237 aCalcCfg("Office.Calc/Filter/Import/VBA"),
238 aImpressCfg("Office.Impress/Filter/Import/VBA")
240 nFlags
= FILTERCFG_WORD_CODE
|
241 FILTERCFG_WORD_STORAGE
|
242 FILTERCFG_EXCEL_CODE
|
243 FILTERCFG_EXCEL_STORAGE
|
244 FILTERCFG_PPOINT_CODE
|
245 FILTERCFG_PPOINT_STORAGE
|
246 FILTERCFG_MATH_LOAD
|
247 FILTERCFG_MATH_SAVE
|
248 FILTERCFG_WRITER_LOAD
|
249 FILTERCFG_WRITER_SAVE
|
250 FILTERCFG_CALC_LOAD
|
251 FILTERCFG_CALC_SAVE
|
252 FILTERCFG_IMPRESS_LOAD
|
253 FILTERCFG_IMPRESS_SAVE
|
254 FILTERCFG_USE_ENHANCED_FIELDS
|
255 FILTERCFG_SMARTART_SHAPE_LOAD
|
256 FILTERCFG_CHAR_BACKGROUND_TO_HIGHLIGHTING
;
260 void SetFlag( sal_uLong nFlag
, bool bSet
);
261 bool IsFlag( sal_uLong nFlag
) const;
270 void SvtFilterOptions_Impl::SetFlag( sal_uLong nFlag
, bool bSet
)
274 case FILTERCFG_WORD_CODE
: aWriterCfg
.SetLoad(bSet
);break;
275 case FILTERCFG_WORD_STORAGE
: aWriterCfg
.SetSave(bSet
);break;
276 case FILTERCFG_WORD_WBCTBL
: aWriterCfg
.SetLoadExecutable(bSet
);break;
277 case FILTERCFG_EXCEL_CODE
: aCalcCfg
.SetLoad(bSet
);break;
278 case FILTERCFG_EXCEL_STORAGE
: aCalcCfg
.SetSave(bSet
);break;
279 case FILTERCFG_EXCEL_EXECTBL
: aCalcCfg
.SetLoadExecutable(bSet
);break;
280 case FILTERCFG_PPOINT_CODE
: aImpressCfg
.SetLoad(bSet
);break;
281 case FILTERCFG_PPOINT_STORAGE
: aImpressCfg
.SetSave(bSet
);break;
290 bool SvtFilterOptions_Impl::IsFlag( sal_uLong nFlag
) const
295 case FILTERCFG_WORD_CODE
: bRet
= aWriterCfg
.IsLoad();break;
296 case FILTERCFG_WORD_STORAGE
: bRet
= aWriterCfg
.IsSave();break;
297 case FILTERCFG_WORD_WBCTBL
: bRet
= aWriterCfg
.IsLoadExecutable();break;
298 case FILTERCFG_EXCEL_CODE
: bRet
= aCalcCfg
.IsLoad();break;
299 case FILTERCFG_EXCEL_STORAGE
: bRet
= aCalcCfg
.IsSave();break;
300 case FILTERCFG_EXCEL_EXECTBL
: bRet
= aCalcCfg
.IsLoadExecutable();break;
301 case FILTERCFG_PPOINT_CODE
: bRet
= aImpressCfg
.IsLoad();break;
302 case FILTERCFG_PPOINT_STORAGE
: bRet
= aImpressCfg
.IsSave();break;
304 bRet
= 0 != (nFlags
& nFlag
);
309 SvtFilterOptions::SvtFilterOptions() :
310 ConfigItem( "Office.Common/Filter/Microsoft" ),
311 pImp(new SvtFilterOptions_Impl
)
313 EnableNotification(GetPropertyNames());
317 SvtFilterOptions::~SvtFilterOptions()
322 const Sequence
<OUString
>& SvtFilterOptions::GetPropertyNames()
324 static Sequence
<OUString
> aNames
;
325 if(!aNames
.getLength())
328 aNames
.realloc(nCount
);
329 static const char* aPropNames
[] =
331 "Import/MathTypeToMath", // 0
332 "Import/WinWordToWriter", // 1
333 "Import/PowerPointToImpress", // 2
334 "Import/ExcelToCalc", // 3
335 "Export/MathToMathType", // 4
336 "Export/WriterToWinWord", // 5
337 "Export/ImpressToPowerPoint", // 6
338 "Export/CalcToExcel", // 7
339 "Export/EnablePowerPointPreview", // 8
340 "Export/EnableExcelPreview", // 9
341 "Export/EnableWordPreview", // 10
342 "Import/ImportWWFieldsAsEnhancedFields", // 11
343 "Import/SmartArtToShapes", // 12
344 "Export/CharBackgroundToHighlighting" // 13
346 OUString
* pNames
= aNames
.getArray();
347 for(int i
= 0; i
< nCount
; i
++)
348 pNames
[i
] = OUString::createFromAscii(aPropNames
[i
]);
353 static sal_uLong
lcl_GetFlag(sal_Int32 nProp
)
358 case 0: nFlag
= FILTERCFG_MATH_LOAD
; break;
359 case 1: nFlag
= FILTERCFG_WRITER_LOAD
; break;
360 case 2: nFlag
= FILTERCFG_IMPRESS_LOAD
; break;
361 case 3: nFlag
= FILTERCFG_CALC_LOAD
; break;
362 case 4: nFlag
= FILTERCFG_MATH_SAVE
; break;
363 case 5: nFlag
= FILTERCFG_WRITER_SAVE
; break;
364 case 6: nFlag
= FILTERCFG_IMPRESS_SAVE
; break;
365 case 7: nFlag
= FILTERCFG_CALC_SAVE
; break;
366 case 8: nFlag
= FILTERCFG_ENABLE_PPT_PREVIEW
; break;
367 case 9: nFlag
= FILTERCFG_ENABLE_EXCEL_PREVIEW
; break;
368 case 10: nFlag
= FILTERCFG_ENABLE_WORD_PREVIEW
; break;
369 case 11: nFlag
= FILTERCFG_USE_ENHANCED_FIELDS
; break;
370 case 12: nFlag
= FILTERCFG_SMARTART_SHAPE_LOAD
; break;
371 case 13: nFlag
= FILTERCFG_CHAR_BACKGROUND_TO_HIGHLIGHTING
; break;
373 default: OSL_FAIL("illegal value");
378 void SvtFilterOptions::Notify( const Sequence
<OUString
>& )
383 void SvtFilterOptions::ImplCommit()
385 const Sequence
<OUString
>& aNames
= GetPropertyNames();
386 Sequence
<Any
> aValues(aNames
.getLength());
387 Any
* pValues
= aValues
.getArray();
389 const Type
& rType
= cppu::UnoType
<bool>::get();
390 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
392 sal_uLong nFlag
= lcl_GetFlag(nProp
);
393 sal_Bool bVal
= pImp
->IsFlag( nFlag
);
394 pValues
[nProp
].setValue(&bVal
, rType
);
397 PutProperties(aNames
, aValues
);
400 void SvtFilterOptions::Load()
403 const Sequence
<OUString
>& rNames
= GetPropertyNames();
404 Sequence
<Any
> aValues
= GetProperties(rNames
);
405 const Any
* pValues
= aValues
.getConstArray();
406 DBG_ASSERT(aValues
.getLength() == rNames
.getLength(), "GetProperties failed");
407 if(aValues
.getLength() == rNames
.getLength())
409 for(int nProp
= 0; nProp
< rNames
.getLength(); nProp
++)
411 if(pValues
[nProp
].hasValue())
413 bool bVal
= *static_cast<sal_Bool
const *>(pValues
[nProp
].getValue());
414 sal_uLong nFlag
= lcl_GetFlag(nProp
);
415 pImp
->SetFlag( nFlag
, bVal
);
421 void SvtFilterOptions::SetLoadWordBasicCode( bool bFlag
)
423 pImp
->SetFlag( FILTERCFG_WORD_CODE
, bFlag
);
427 bool SvtFilterOptions::IsLoadWordBasicCode() const
429 return pImp
->IsFlag( FILTERCFG_WORD_CODE
);
432 void SvtFilterOptions::SetLoadWordBasicExecutable( bool bFlag
)
434 pImp
->SetFlag( FILTERCFG_WORD_WBCTBL
, bFlag
);
438 bool SvtFilterOptions::IsLoadWordBasicExecutable() const
440 return pImp
->IsFlag( FILTERCFG_WORD_WBCTBL
);
443 void SvtFilterOptions::SetLoadWordBasicStorage( bool bFlag
)
445 pImp
->SetFlag( FILTERCFG_WORD_STORAGE
, bFlag
);
449 bool SvtFilterOptions::IsLoadWordBasicStorage() const
451 return pImp
->IsFlag( FILTERCFG_WORD_STORAGE
);
454 void SvtFilterOptions::SetLoadExcelBasicCode( bool bFlag
)
456 pImp
->SetFlag( FILTERCFG_EXCEL_CODE
, bFlag
);
460 bool SvtFilterOptions::IsLoadExcelBasicCode() const
462 return pImp
->IsFlag( FILTERCFG_EXCEL_CODE
);
465 void SvtFilterOptions::SetLoadExcelBasicExecutable( bool bFlag
)
467 pImp
->SetFlag( FILTERCFG_EXCEL_EXECTBL
, bFlag
);
471 bool SvtFilterOptions::IsLoadExcelBasicExecutable() const
473 return pImp
->IsFlag( FILTERCFG_EXCEL_EXECTBL
);
476 void SvtFilterOptions::SetLoadExcelBasicStorage( bool bFlag
)
478 pImp
->SetFlag( FILTERCFG_EXCEL_STORAGE
, bFlag
);
482 bool SvtFilterOptions::IsLoadExcelBasicStorage() const
484 return pImp
->IsFlag( FILTERCFG_EXCEL_STORAGE
);
487 void SvtFilterOptions::SetLoadPPointBasicCode( bool bFlag
)
489 pImp
->SetFlag( FILTERCFG_PPOINT_CODE
, bFlag
);
493 bool SvtFilterOptions::IsLoadPPointBasicCode() const
495 return pImp
->IsFlag( FILTERCFG_PPOINT_CODE
);
498 void SvtFilterOptions::SetLoadPPointBasicStorage( bool bFlag
)
500 pImp
->SetFlag( FILTERCFG_PPOINT_STORAGE
, bFlag
);
504 bool SvtFilterOptions::IsLoadPPointBasicStorage() const
506 return pImp
->IsFlag( FILTERCFG_PPOINT_STORAGE
);
509 bool SvtFilterOptions::IsMathType2Math() const
511 return pImp
->IsFlag( FILTERCFG_MATH_LOAD
);
514 void SvtFilterOptions::SetMathType2Math( bool bFlag
)
516 pImp
->SetFlag( FILTERCFG_MATH_LOAD
, bFlag
);
520 bool SvtFilterOptions::IsMath2MathType() const
522 return pImp
->IsFlag( FILTERCFG_MATH_SAVE
);
525 void SvtFilterOptions::SetMath2MathType( bool bFlag
)
527 pImp
->SetFlag( FILTERCFG_MATH_SAVE
, bFlag
);
531 bool SvtFilterOptions::IsWinWord2Writer() const
533 return pImp
->IsFlag( FILTERCFG_WRITER_LOAD
);
536 void SvtFilterOptions::SetWinWord2Writer( bool bFlag
)
538 pImp
->SetFlag( FILTERCFG_WRITER_LOAD
, bFlag
);
542 bool SvtFilterOptions::IsWriter2WinWord() const
544 return pImp
->IsFlag( FILTERCFG_WRITER_SAVE
);
547 void SvtFilterOptions::SetWriter2WinWord( bool bFlag
)
549 pImp
->SetFlag( FILTERCFG_WRITER_SAVE
, bFlag
);
553 bool SvtFilterOptions::IsUseEnhancedFields() const
555 return pImp
->IsFlag( FILTERCFG_USE_ENHANCED_FIELDS
);
558 bool SvtFilterOptions::IsExcel2Calc() const
560 return pImp
->IsFlag( FILTERCFG_CALC_LOAD
);
563 void SvtFilterOptions::SetExcel2Calc( bool bFlag
)
565 pImp
->SetFlag( FILTERCFG_CALC_LOAD
, bFlag
);
569 bool SvtFilterOptions::IsCalc2Excel() const
571 return pImp
->IsFlag( FILTERCFG_CALC_SAVE
);
574 void SvtFilterOptions::SetCalc2Excel( bool bFlag
)
576 pImp
->SetFlag( FILTERCFG_CALC_SAVE
, bFlag
);
580 bool SvtFilterOptions::IsPowerPoint2Impress() const
582 return pImp
->IsFlag( FILTERCFG_IMPRESS_LOAD
);
585 void SvtFilterOptions::SetPowerPoint2Impress( bool bFlag
)
587 pImp
->SetFlag( FILTERCFG_IMPRESS_LOAD
, bFlag
);
591 bool SvtFilterOptions::IsImpress2PowerPoint() const
593 return pImp
->IsFlag( FILTERCFG_IMPRESS_SAVE
);
596 void SvtFilterOptions::SetImpress2PowerPoint( bool bFlag
)
598 pImp
->SetFlag( FILTERCFG_IMPRESS_SAVE
, bFlag
);
602 bool SvtFilterOptions::IsSmartArt2Shape() const
604 return pImp
->IsFlag( FILTERCFG_SMARTART_SHAPE_LOAD
);
607 void SvtFilterOptions::SetSmartArt2Shape( bool bFlag
)
609 pImp
->SetFlag( FILTERCFG_SMARTART_SHAPE_LOAD
, bFlag
);
615 class theFilterOptions
616 : public rtl::Static
<SvtFilterOptions
, theFilterOptions
>
621 SvtFilterOptions
& SvtFilterOptions::Get()
623 return theFilterOptions::get();
626 bool SvtFilterOptions::IsEnablePPTPreview() const
628 return pImp
->IsFlag( FILTERCFG_ENABLE_PPT_PREVIEW
);
631 bool SvtFilterOptions::IsEnableCalcPreview() const
633 return pImp
->IsFlag( FILTERCFG_ENABLE_EXCEL_PREVIEW
);
636 bool SvtFilterOptions::IsEnableWordPreview() const
638 return pImp
->IsFlag( FILTERCFG_ENABLE_WORD_PREVIEW
);
642 bool SvtFilterOptions::IsCharBackground2Highlighting() const
644 return pImp
->IsFlag( FILTERCFG_CHAR_BACKGROUND_TO_HIGHLIGHTING
);
647 bool SvtFilterOptions::IsCharBackground2Shading() const
649 return !pImp
->IsFlag( FILTERCFG_CHAR_BACKGROUND_TO_HIGHLIGHTING
);
652 void SvtFilterOptions::SetCharBackground2Highlighting()
654 pImp
->SetFlag( FILTERCFG_CHAR_BACKGROUND_TO_HIGHLIGHTING
, true );
658 void SvtFilterOptions::SetCharBackground2Shading()
660 pImp
->SetFlag( FILTERCFG_CHAR_BACKGROUND_TO_HIGHLIGHTING
, false );
664 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */