Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / unotools / source / config / fltrcfg.cxx
blob834e92c183f18e2fdf4612194e88d151d238ea77
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 .
21 #include <unotools/fltrcfg.hxx>
22 #include <tools/debug.hxx>
24 #include <rtl/logfile.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 using ::rtl::OUString;
33 #define C2U(cChar) OUString(RTL_CONSTASCII_USTRINGPARAM(cChar))
35 // -----------------------------------------------------------------------
36 #define FILTERCFG_WORD_CODE 0x0001
37 #define FILTERCFG_WORD_STORAGE 0x0002
38 #define FILTERCFG_EXCEL_CODE 0x0004
39 #define FILTERCFG_EXCEL_STORAGE 0x0008
40 #define FILTERCFG_PPOINT_CODE 0x0010
41 #define FILTERCFG_PPOINT_STORAGE 0x0020
42 #define FILTERCFG_MATH_LOAD 0x0100
43 #define FILTERCFG_MATH_SAVE 0x0200
44 #define FILTERCFG_WRITER_LOAD 0x0400
45 #define FILTERCFG_WRITER_SAVE 0x0800
46 #define FILTERCFG_CALC_LOAD 0x1000
47 #define FILTERCFG_CALC_SAVE 0x2000
48 #define FILTERCFG_IMPRESS_LOAD 0x4000
49 #define FILTERCFG_IMPRESS_SAVE 0x8000
50 #define FILTERCFG_EXCEL_EXECTBL 0x10000
51 #define FILTERCFG_ENABLE_PPT_PREVIEW 0x20000
52 #define FILTERCFG_ENABLE_EXCEL_PREVIEW 0x40000
53 #define FILTERCFG_ENABLE_WORD_PREVIEW 0x80000
54 #define FILTERCFG_USE_ENHANCED_FIELDS 0x100000
55 #define FILTERCFG_WORD_WBCTBL 0x200000
57 class SvtAppFilterOptions_Impl : public utl::ConfigItem
59 sal_Bool bLoadVBA;
60 sal_Bool bSaveVBA;
61 public:
62 SvtAppFilterOptions_Impl(const OUString& rRoot) :
63 utl::ConfigItem(rRoot),
64 bLoadVBA(sal_False),
65 bSaveVBA(sal_False) {}
66 ~SvtAppFilterOptions_Impl();
67 virtual void Commit();
68 virtual void Notify( const com::sun::star::uno::Sequence<rtl::OUString>& aPropertyNames);
69 void Load();
71 sal_Bool IsLoad() const {return bLoadVBA;}
72 void SetLoad(sal_Bool bSet)
74 if(bSet != bLoadVBA)
75 SetModified();
76 bLoadVBA = bSet;
78 sal_Bool IsSave() const {return bSaveVBA;}
79 void SetSave(sal_Bool bSet)
81 if(bSet != bSaveVBA)
82 SetModified();
83 bSaveVBA = bSet;
87 SvtAppFilterOptions_Impl::~SvtAppFilterOptions_Impl()
89 if(IsModified())
90 Commit();
93 void SvtAppFilterOptions_Impl::Commit()
95 Sequence<OUString> aNames(2);
96 OUString* pNames = aNames.getArray();
97 pNames[0] = C2U("Load");
98 pNames[1] = C2U("Save");
99 Sequence<Any> aValues(aNames.getLength());
100 Any* pValues = aValues.getArray();
102 const Type& rType = ::getBooleanCppuType();
103 pValues[0].setValue(&bLoadVBA, rType);
104 pValues[1].setValue(&bSaveVBA, rType);
106 PutProperties(aNames, aValues);
109 void SvtAppFilterOptions_Impl::Notify( const Sequence< rtl::OUString >& )
111 // no listeners supported yet
114 void SvtAppFilterOptions_Impl::Load()
116 Sequence<OUString> aNames(2);
117 OUString* pNames = aNames.getArray();
118 pNames[0] = C2U("Load");
119 pNames[1] = C2U("Save");
121 Sequence<Any> aValues = GetProperties(aNames);
122 const Any* pValues = aValues.getConstArray();
124 if(pValues[0].hasValue())
125 bLoadVBA = *(sal_Bool*)pValues[0].getValue();
126 if(pValues[1].hasValue())
127 bSaveVBA = *(sal_Bool*)pValues[1].getValue();
130 // -----------------------------------------------------------------------
131 class SvtWriterFilterOptions_Impl : public SvtAppFilterOptions_Impl
133 sal_Bool bLoadExecutable;
134 public:
135 SvtWriterFilterOptions_Impl(const OUString& rRoot) :
136 SvtAppFilterOptions_Impl(rRoot),
137 bLoadExecutable(sal_False)
139 virtual void Commit();
140 void Load();
142 sal_Bool IsLoadExecutable() const {return bLoadExecutable;}
143 void SetLoadExecutable(sal_Bool bSet)
145 if(bSet != bLoadExecutable)
146 SetModified();
147 bLoadExecutable = bSet;
151 void SvtWriterFilterOptions_Impl::Commit()
153 SvtAppFilterOptions_Impl::Commit();
155 Sequence<OUString> aNames(1);
156 aNames[0] = C2U("Executable");
157 Sequence<Any> aValues(1);
158 aValues[0] <<= bLoadExecutable;
160 PutProperties(aNames, aValues);
163 void SvtWriterFilterOptions_Impl::Load()
165 SvtAppFilterOptions_Impl::Load();
167 Sequence<OUString> aNames(1);
168 aNames[0] = C2U("Executable");
170 Sequence<Any> aValues = GetProperties(aNames);
171 const Any* pValues = aValues.getConstArray();
172 if(pValues[0].hasValue())
173 bLoadExecutable = *(sal_Bool*)pValues[0].getValue();
176 // -----------------------------------------------------------------------
177 class SvtCalcFilterOptions_Impl : public SvtAppFilterOptions_Impl
179 sal_Bool bLoadExecutable;
180 public:
181 SvtCalcFilterOptions_Impl(const OUString& rRoot) :
182 SvtAppFilterOptions_Impl(rRoot),
183 bLoadExecutable(sal_False)
185 virtual void Commit();
186 void Load();
188 sal_Bool IsLoadExecutable() const {return bLoadExecutable;}
189 void SetLoadExecutable(sal_Bool bSet)
191 if(bSet != bLoadExecutable)
192 SetModified();
193 bLoadExecutable = bSet;
197 void SvtCalcFilterOptions_Impl::Commit()
199 SvtAppFilterOptions_Impl::Commit();
201 Sequence<OUString> aNames(1);
202 aNames[0] = C2U("Executable");
203 Sequence<Any> aValues(1);
204 aValues[0] <<= bLoadExecutable;
206 PutProperties(aNames, aValues);
209 void SvtCalcFilterOptions_Impl::Load()
211 SvtAppFilterOptions_Impl::Load();
213 Sequence<OUString> aNames(1);
214 aNames[0] = C2U("Executable");
216 Sequence<Any> aValues = GetProperties(aNames);
217 const Any* pValues = aValues.getConstArray();
218 if(pValues[0].hasValue())
219 bLoadExecutable = *(sal_Bool*)pValues[0].getValue();
222 struct SvtFilterOptions_Impl
224 sal_uLong nFlags;
225 SvtWriterFilterOptions_Impl aWriterCfg;
226 SvtCalcFilterOptions_Impl aCalcCfg;
227 SvtAppFilterOptions_Impl aImpressCfg;
229 SvtFilterOptions_Impl() :
230 aWriterCfg(C2U("Office.Writer/Filter/Import/VBA")),
231 aCalcCfg(C2U("Office.Calc/Filter/Import/VBA")),
232 aImpressCfg(C2U("Office.Impress/Filter/Import/VBA"))
234 nFlags = FILTERCFG_WORD_CODE |
235 FILTERCFG_WORD_STORAGE |
236 FILTERCFG_EXCEL_CODE |
237 FILTERCFG_EXCEL_STORAGE |
238 FILTERCFG_PPOINT_CODE |
239 FILTERCFG_PPOINT_STORAGE |
240 FILTERCFG_MATH_LOAD |
241 FILTERCFG_MATH_SAVE |
242 FILTERCFG_WRITER_LOAD |
243 FILTERCFG_WRITER_SAVE |
244 FILTERCFG_CALC_LOAD |
245 FILTERCFG_CALC_SAVE |
246 FILTERCFG_IMPRESS_LOAD |
247 FILTERCFG_IMPRESS_SAVE |
248 FILTERCFG_USE_ENHANCED_FIELDS;
249 Load();
252 void SetFlag( sal_uLong nFlag, sal_Bool bSet );
253 sal_Bool IsFlag( sal_uLong nFlag ) const;
254 void Load()
256 aWriterCfg.Load();
257 aCalcCfg.Load();
258 aImpressCfg.Load();
262 void SvtFilterOptions_Impl::SetFlag( sal_uLong nFlag, sal_Bool bSet )
264 switch(nFlag)
266 case FILTERCFG_WORD_CODE: aWriterCfg.SetLoad(bSet);break;
267 case FILTERCFG_WORD_STORAGE: aWriterCfg.SetSave(bSet);break;
268 case FILTERCFG_WORD_WBCTBL: aWriterCfg.SetLoadExecutable(bSet);break;
269 case FILTERCFG_EXCEL_CODE: aCalcCfg.SetLoad(bSet);break;
270 case FILTERCFG_EXCEL_STORAGE: aCalcCfg.SetSave(bSet);break;
271 case FILTERCFG_EXCEL_EXECTBL: aCalcCfg.SetLoadExecutable(bSet);break;
272 case FILTERCFG_PPOINT_CODE: aImpressCfg.SetLoad(bSet);break;
273 case FILTERCFG_PPOINT_STORAGE: aImpressCfg.SetSave(bSet);break;
274 default:
275 if( bSet )
276 nFlags |= nFlag;
277 else
278 nFlags &= ~nFlag;
282 sal_Bool SvtFilterOptions_Impl::IsFlag( sal_uLong nFlag ) const
284 sal_Bool bRet;
285 switch(nFlag)
287 case FILTERCFG_WORD_CODE : bRet = aWriterCfg.IsLoad();break;
288 case FILTERCFG_WORD_STORAGE : bRet = aWriterCfg.IsSave();break;
289 case FILTERCFG_WORD_WBCTBL : bRet = aWriterCfg.IsLoadExecutable();break;
290 case FILTERCFG_EXCEL_CODE : bRet = aCalcCfg.IsLoad();break;
291 case FILTERCFG_EXCEL_STORAGE : bRet = aCalcCfg.IsSave();break;
292 case FILTERCFG_EXCEL_EXECTBL : bRet = aCalcCfg.IsLoadExecutable();break;
293 case FILTERCFG_PPOINT_CODE : bRet = aImpressCfg.IsLoad();break;
294 case FILTERCFG_PPOINT_STORAGE : bRet = aImpressCfg.IsSave();break;
295 default:
296 bRet = 0 != (nFlags & nFlag );
298 return bRet;
301 // -----------------------------------------------------------------------
303 SvtFilterOptions::SvtFilterOptions() :
304 ConfigItem( C2U("Office.Common/Filter/Microsoft") ),
305 pImp(new SvtFilterOptions_Impl)
307 RTL_LOGFILE_CONTEXT(aLog, "unotools SvtFilterOptions::SvtFilterOptions()");
308 EnableNotification(GetPropertyNames());
309 Load();
312 // -----------------------------------------------------------------------
313 SvtFilterOptions::~SvtFilterOptions()
315 delete pImp;
318 const Sequence<OUString>& SvtFilterOptions::GetPropertyNames()
320 static Sequence<OUString> aNames;
321 if(!aNames.getLength())
323 int nCount = 12;
324 aNames.realloc(nCount);
325 static const char* aPropNames[] =
327 "Import/MathTypeToMath", // 0
328 "Import/WinWordToWriter", // 1
329 "Import/PowerPointToImpress", // 2
330 "Import/ExcelToCalc", // 3
331 "Export/MathToMathType", // 4
332 "Export/WriterToWinWord", // 5
333 "Export/ImpressToPowerPoint", // 6
334 "Export/CalcToExcel", // 7
335 "Export/EnablePowerPointPreview", // 8
336 "Export/EnableExcelPreview", // 9
337 "Export/EnableWordPreview", // 10
338 "Import/ImportWWFieldsAsEnhancedFields" // 11
340 OUString* pNames = aNames.getArray();
341 for(int i = 0; i < nCount; i++)
342 pNames[i] = OUString::createFromAscii(aPropNames[i]);
344 return aNames;
346 //-----------------------------------------------------------------------
347 static sal_uLong lcl_GetFlag(sal_Int32 nProp)
349 sal_uLong nFlag = 0;
350 switch(nProp)
352 case 0: nFlag = FILTERCFG_MATH_LOAD; break;
353 case 1: nFlag = FILTERCFG_WRITER_LOAD; break;
354 case 2: nFlag = FILTERCFG_IMPRESS_LOAD; break;
355 case 3: nFlag = FILTERCFG_CALC_LOAD; break;
356 case 4: nFlag = FILTERCFG_MATH_SAVE; break;
357 case 5: nFlag = FILTERCFG_WRITER_SAVE; break;
358 case 6: nFlag = FILTERCFG_IMPRESS_SAVE; break;
359 case 7: nFlag = FILTERCFG_CALC_SAVE; break;
360 case 8: nFlag = FILTERCFG_ENABLE_PPT_PREVIEW; break;
361 case 9: nFlag = FILTERCFG_ENABLE_EXCEL_PREVIEW; break;
362 case 10: nFlag = FILTERCFG_ENABLE_WORD_PREVIEW; break;
363 case 11: nFlag = FILTERCFG_USE_ENHANCED_FIELDS; break;
365 default: OSL_FAIL("illegal value");
367 return nFlag;
370 void SvtFilterOptions::Notify( const Sequence<OUString>& )
372 Load();
375 void SvtFilterOptions::Commit()
377 const Sequence<OUString>& aNames = GetPropertyNames();
378 Sequence<Any> aValues(aNames.getLength());
379 Any* pValues = aValues.getArray();
381 const Type& rType = ::getBooleanCppuType();
382 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
384 sal_uLong nFlag = lcl_GetFlag(nProp);
385 sal_Bool bVal = pImp->IsFlag( nFlag);
386 pValues[nProp].setValue(&bVal, rType);
389 PutProperties(aNames, aValues);
392 void SvtFilterOptions::Load()
394 pImp->Load();
395 const Sequence<OUString>& rNames = GetPropertyNames();
396 Sequence<Any> aValues = GetProperties(rNames);
397 const Any* pValues = aValues.getConstArray();
398 DBG_ASSERT(aValues.getLength() == rNames.getLength(), "GetProperties failed");
399 if(aValues.getLength() == rNames.getLength())
401 for(int nProp = 0; nProp < rNames.getLength(); nProp++)
403 if(pValues[nProp].hasValue())
405 sal_Bool bVal = *(sal_Bool*)pValues[nProp].getValue();
406 sal_uLong nFlag = lcl_GetFlag(nProp);
407 pImp->SetFlag( nFlag, bVal);
412 // -----------------------------------------------------------------------
414 void SvtFilterOptions::SetLoadWordBasicCode( sal_Bool bFlag )
416 pImp->SetFlag( FILTERCFG_WORD_CODE, bFlag );
417 SetModified();
420 sal_Bool SvtFilterOptions::IsLoadWordBasicCode() const
422 return pImp->IsFlag( FILTERCFG_WORD_CODE );
425 void SvtFilterOptions::SetLoadWordBasicExecutable( sal_Bool bFlag )
427 pImp->SetFlag( FILTERCFG_WORD_WBCTBL, bFlag );
428 SetModified();
431 sal_Bool SvtFilterOptions::IsLoadWordBasicExecutable() const
433 return pImp->IsFlag( FILTERCFG_WORD_WBCTBL );
436 void SvtFilterOptions::SetLoadWordBasicStorage( sal_Bool bFlag )
438 pImp->SetFlag( FILTERCFG_WORD_STORAGE, bFlag );
439 SetModified();
442 sal_Bool SvtFilterOptions::IsLoadWordBasicStorage() const
444 return pImp->IsFlag( FILTERCFG_WORD_STORAGE );
447 // -----------------------------------------------------------------------
449 void SvtFilterOptions::SetLoadExcelBasicCode( sal_Bool bFlag )
451 pImp->SetFlag( FILTERCFG_EXCEL_CODE, bFlag );
452 SetModified();
455 sal_Bool SvtFilterOptions::IsLoadExcelBasicCode() const
457 return pImp->IsFlag( FILTERCFG_EXCEL_CODE );
460 void SvtFilterOptions::SetLoadExcelBasicExecutable( sal_Bool bFlag )
462 pImp->SetFlag( FILTERCFG_EXCEL_EXECTBL, bFlag );
463 SetModified();
466 sal_Bool SvtFilterOptions::IsLoadExcelBasicExecutable() const
468 return pImp->IsFlag( FILTERCFG_EXCEL_EXECTBL );
471 void SvtFilterOptions::SetLoadExcelBasicStorage( sal_Bool bFlag )
473 pImp->SetFlag( FILTERCFG_EXCEL_STORAGE, bFlag );
474 SetModified();
477 sal_Bool SvtFilterOptions::IsLoadExcelBasicStorage() const
479 return pImp->IsFlag( FILTERCFG_EXCEL_STORAGE );
482 // -----------------------------------------------------------------------
484 void SvtFilterOptions::SetLoadPPointBasicCode( sal_Bool bFlag )
486 pImp->SetFlag( FILTERCFG_PPOINT_CODE, bFlag );
487 SetModified();
490 sal_Bool SvtFilterOptions::IsLoadPPointBasicCode() const
492 return pImp->IsFlag( FILTERCFG_PPOINT_CODE );
495 void SvtFilterOptions::SetLoadPPointBasicStorage( sal_Bool bFlag )
497 pImp->SetFlag( FILTERCFG_PPOINT_STORAGE, bFlag );
498 SetModified();
501 sal_Bool SvtFilterOptions::IsLoadPPointBasicStorage() const
503 return pImp->IsFlag( FILTERCFG_PPOINT_STORAGE );
506 // -----------------------------------------------------------------------
508 sal_Bool SvtFilterOptions::IsMathType2Math() const
510 return pImp->IsFlag( FILTERCFG_MATH_LOAD );
513 void SvtFilterOptions::SetMathType2Math( sal_Bool bFlag )
515 pImp->SetFlag( FILTERCFG_MATH_LOAD, bFlag );
516 SetModified();
519 sal_Bool SvtFilterOptions::IsMath2MathType() const
521 return pImp->IsFlag( FILTERCFG_MATH_SAVE );
524 void SvtFilterOptions::SetMath2MathType( sal_Bool bFlag )
526 pImp->SetFlag( FILTERCFG_MATH_SAVE, bFlag );
527 SetModified();
531 // -----------------------------------------------------------------------
532 sal_Bool SvtFilterOptions::IsWinWord2Writer() const
534 return pImp->IsFlag( FILTERCFG_WRITER_LOAD );
537 void SvtFilterOptions::SetWinWord2Writer( sal_Bool bFlag )
539 pImp->SetFlag( FILTERCFG_WRITER_LOAD, bFlag );
540 SetModified();
543 sal_Bool SvtFilterOptions::IsWriter2WinWord() const
545 return pImp->IsFlag( FILTERCFG_WRITER_SAVE );
548 void SvtFilterOptions::SetWriter2WinWord( sal_Bool bFlag )
550 pImp->SetFlag( FILTERCFG_WRITER_SAVE, bFlag );
551 SetModified();
554 sal_Bool SvtFilterOptions::IsUseEnhancedFields() const
556 return pImp->IsFlag( FILTERCFG_USE_ENHANCED_FIELDS );
559 // -----------------------------------------------------------------------
560 sal_Bool SvtFilterOptions::IsExcel2Calc() const
562 return pImp->IsFlag( FILTERCFG_CALC_LOAD );
565 void SvtFilterOptions::SetExcel2Calc( sal_Bool bFlag )
567 pImp->SetFlag( FILTERCFG_CALC_LOAD, bFlag );
568 SetModified();
571 sal_Bool SvtFilterOptions::IsCalc2Excel() const
573 return pImp->IsFlag( FILTERCFG_CALC_SAVE );
576 void SvtFilterOptions::SetCalc2Excel( sal_Bool bFlag )
578 pImp->SetFlag( FILTERCFG_CALC_SAVE, bFlag );
579 SetModified();
583 // -----------------------------------------------------------------------
584 sal_Bool SvtFilterOptions::IsPowerPoint2Impress() const
586 return pImp->IsFlag( FILTERCFG_IMPRESS_LOAD );
589 void SvtFilterOptions::SetPowerPoint2Impress( sal_Bool bFlag )
591 pImp->SetFlag( FILTERCFG_IMPRESS_LOAD, bFlag );
592 SetModified();
595 sal_Bool SvtFilterOptions::IsImpress2PowerPoint() const
597 return pImp->IsFlag( FILTERCFG_IMPRESS_SAVE );
600 void SvtFilterOptions::SetImpress2PowerPoint( sal_Bool bFlag )
602 pImp->SetFlag( FILTERCFG_IMPRESS_SAVE, bFlag );
603 SetModified();
606 namespace
608 class theFilterOptions
609 : public rtl::Static<SvtFilterOptions, theFilterOptions>
614 SvtFilterOptions& SvtFilterOptions::Get()
616 return theFilterOptions::get();
619 // -----------------------------------------------------------------------
621 sal_Bool SvtFilterOptions::IsEnablePPTPreview() const
623 return pImp->IsFlag( FILTERCFG_ENABLE_PPT_PREVIEW );
627 sal_Bool SvtFilterOptions::IsEnableCalcPreview() const
629 return pImp->IsFlag( FILTERCFG_ENABLE_EXCEL_PREVIEW );
633 sal_Bool SvtFilterOptions::IsEnableWordPreview() const
635 return pImp->IsFlag( FILTERCFG_ENABLE_WORD_PREVIEW );
639 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */