Bump version to 4.3-4
[LibreOffice.git] / unotools / source / config / fltrcfg.cxx
blob6c2c473da3ec2cc435fbdd017460e59efa245b2a
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 <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>
28 using namespace utl;
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
55 bool bLoadVBA;
56 bool bSaveVBA;
57 public:
58 SvtAppFilterOptions_Impl(const OUString& rRoot) :
59 utl::ConfigItem(rRoot),
60 bLoadVBA(false),
61 bSaveVBA(false) {}
62 virtual ~SvtAppFilterOptions_Impl();
63 virtual void Commit() SAL_OVERRIDE;
64 virtual void Notify( const com::sun::star::uno::Sequence<OUString>& aPropertyNames) SAL_OVERRIDE;
65 void Load();
67 bool IsLoad() const {return bLoadVBA;}
68 void SetLoad(bool bSet)
70 if(bSet != bLoadVBA)
71 SetModified();
72 bLoadVBA = bSet;
74 bool IsSave() const {return bSaveVBA;}
75 void SetSave(bool bSet)
77 if(bSet != bSaveVBA)
78 SetModified();
79 bSaveVBA = bSet;
83 SvtAppFilterOptions_Impl::~SvtAppFilterOptions_Impl()
85 if(IsModified())
86 Commit();
89 void SvtAppFilterOptions_Impl::Commit()
91 Sequence<OUString> aNames(2);
92 OUString* pNames = aNames.getArray();
93 pNames[0] = "Load";
94 pNames[1] = "Save";
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();
114 pNames[0] = "Load";
115 pNames[1] = "Save";
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;
129 public:
130 SvtWriterFilterOptions_Impl(const OUString& rRoot) :
131 SvtAppFilterOptions_Impl(rRoot),
132 bLoadExecutable(false)
134 virtual void Commit() SAL_OVERRIDE;
135 void Load();
137 bool IsLoadExecutable() const {return bLoadExecutable;}
138 void SetLoadExecutable(bool bSet)
140 if(bSet != bLoadExecutable)
141 SetModified();
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;
174 public:
175 SvtCalcFilterOptions_Impl(const OUString& rRoot) :
176 SvtAppFilterOptions_Impl(rRoot),
177 bLoadExecutable(false)
179 virtual void Commit() SAL_OVERRIDE;
180 void Load();
182 bool IsLoadExecutable() const {return bLoadExecutable;}
183 void SetLoadExecutable(bool bSet)
185 if(bSet != bLoadExecutable)
186 SetModified();
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
218 sal_uLong nFlags;
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;
244 Load();
247 void SetFlag( sal_uLong nFlag, bool bSet );
248 bool IsFlag( sal_uLong nFlag ) const;
249 void Load()
251 aWriterCfg.Load();
252 aCalcCfg.Load();
253 aImpressCfg.Load();
257 void SvtFilterOptions_Impl::SetFlag( sal_uLong nFlag, bool bSet )
259 switch(nFlag)
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;
269 default:
270 if( bSet )
271 nFlags |= nFlag;
272 else
273 nFlags &= ~nFlag;
277 bool SvtFilterOptions_Impl::IsFlag( sal_uLong nFlag ) const
279 bool bRet;
280 switch(nFlag)
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;
290 default:
291 bRet = 0 != (nFlags & nFlag );
293 return bRet;
296 SvtFilterOptions::SvtFilterOptions() :
297 ConfigItem( "Office.Common/Filter/Microsoft" ),
298 pImp(new SvtFilterOptions_Impl)
300 EnableNotification(GetPropertyNames());
301 Load();
304 SvtFilterOptions::~SvtFilterOptions()
306 delete pImp;
309 const Sequence<OUString>& SvtFilterOptions::GetPropertyNames()
311 static Sequence<OUString> aNames;
312 if(!aNames.getLength())
314 int nCount = 13;
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]);
336 return aNames;
339 static sal_uLong lcl_GetFlag(sal_Int32 nProp)
341 sal_uLong nFlag = 0;
342 switch(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");
360 return nFlag;
363 void SvtFilterOptions::Notify( const Sequence<OUString>& )
365 Load();
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()
387 pImp->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 );
409 SetModified();
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 );
420 SetModified();
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 );
431 SetModified();
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 );
442 SetModified();
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 );
453 SetModified();
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 );
464 SetModified();
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 );
475 SetModified();
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 );
486 SetModified();
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 );
502 SetModified();
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 );
513 SetModified();
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 );
524 SetModified();
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 );
535 SetModified();
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 );
551 SetModified();
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 );
562 SetModified();
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 );
573 SetModified();
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 );
584 SetModified();
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 );
595 SetModified();
598 namespace
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: */