update credits
[LibreOffice.git] / unotools / source / config / fltrcfg.cxx
blob1f99d48fe723c3466c65e8da17c2c85970838315
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 // -----------------------------------------------------------------------
32 #define FILTERCFG_WORD_CODE 0x0001
33 #define FILTERCFG_WORD_STORAGE 0x0002
34 #define FILTERCFG_EXCEL_CODE 0x0004
35 #define FILTERCFG_EXCEL_STORAGE 0x0008
36 #define FILTERCFG_PPOINT_CODE 0x0010
37 #define FILTERCFG_PPOINT_STORAGE 0x0020
38 #define FILTERCFG_MATH_LOAD 0x0100
39 #define FILTERCFG_MATH_SAVE 0x0200
40 #define FILTERCFG_WRITER_LOAD 0x0400
41 #define FILTERCFG_WRITER_SAVE 0x0800
42 #define FILTERCFG_CALC_LOAD 0x1000
43 #define FILTERCFG_CALC_SAVE 0x2000
44 #define FILTERCFG_IMPRESS_LOAD 0x4000
45 #define FILTERCFG_IMPRESS_SAVE 0x8000
46 #define FILTERCFG_EXCEL_EXECTBL 0x10000
47 #define FILTERCFG_ENABLE_PPT_PREVIEW 0x20000
48 #define FILTERCFG_ENABLE_EXCEL_PREVIEW 0x40000
49 #define FILTERCFG_ENABLE_WORD_PREVIEW 0x80000
50 #define FILTERCFG_USE_ENHANCED_FIELDS 0x100000
51 #define FILTERCFG_WORD_WBCTBL 0x200000
53 class SvtAppFilterOptions_Impl : public utl::ConfigItem
55 sal_Bool bLoadVBA;
56 sal_Bool bSaveVBA;
57 public:
58 SvtAppFilterOptions_Impl(const OUString& rRoot) :
59 utl::ConfigItem(rRoot),
60 bLoadVBA(sal_False),
61 bSaveVBA(sal_False) {}
62 ~SvtAppFilterOptions_Impl();
63 virtual void Commit();
64 virtual void Notify( const com::sun::star::uno::Sequence<OUString>& aPropertyNames);
65 void Load();
67 sal_Bool IsLoad() const {return bLoadVBA;}
68 void SetLoad(sal_Bool bSet)
70 if(bSet != bLoadVBA)
71 SetModified();
72 bLoadVBA = bSet;
74 sal_Bool IsSave() const {return bSaveVBA;}
75 void SetSave(sal_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 // -----------------------------------------------------------------------
127 class SvtWriterFilterOptions_Impl : public SvtAppFilterOptions_Impl
129 sal_Bool bLoadExecutable;
130 public:
131 SvtWriterFilterOptions_Impl(const OUString& rRoot) :
132 SvtAppFilterOptions_Impl(rRoot),
133 bLoadExecutable(sal_False)
135 virtual void Commit();
136 void Load();
138 sal_Bool IsLoadExecutable() const {return bLoadExecutable;}
139 void SetLoadExecutable(sal_Bool bSet)
141 if(bSet != bLoadExecutable)
142 SetModified();
143 bLoadExecutable = bSet;
147 void SvtWriterFilterOptions_Impl::Commit()
149 SvtAppFilterOptions_Impl::Commit();
151 Sequence<OUString> aNames(1);
152 aNames[0] = "Executable";
153 Sequence<Any> aValues(1);
154 aValues[0] <<= bLoadExecutable;
156 PutProperties(aNames, aValues);
159 void SvtWriterFilterOptions_Impl::Load()
161 SvtAppFilterOptions_Impl::Load();
163 Sequence<OUString> aNames(1);
164 aNames[0] = "Executable";
166 Sequence<Any> aValues = GetProperties(aNames);
167 const Any* pValues = aValues.getConstArray();
168 if(pValues[0].hasValue())
169 bLoadExecutable = *(sal_Bool*)pValues[0].getValue();
172 // -----------------------------------------------------------------------
173 class SvtCalcFilterOptions_Impl : public SvtAppFilterOptions_Impl
175 sal_Bool bLoadExecutable;
176 public:
177 SvtCalcFilterOptions_Impl(const OUString& rRoot) :
178 SvtAppFilterOptions_Impl(rRoot),
179 bLoadExecutable(sal_False)
181 virtual void Commit();
182 void Load();
184 sal_Bool IsLoadExecutable() const {return bLoadExecutable;}
185 void SetLoadExecutable(sal_Bool bSet)
187 if(bSet != bLoadExecutable)
188 SetModified();
189 bLoadExecutable = bSet;
193 void SvtCalcFilterOptions_Impl::Commit()
195 SvtAppFilterOptions_Impl::Commit();
197 Sequence<OUString> aNames(1);
198 aNames[0] = "Executable";
199 Sequence<Any> aValues(1);
200 aValues[0] <<= bLoadExecutable;
202 PutProperties(aNames, aValues);
205 void SvtCalcFilterOptions_Impl::Load()
207 SvtAppFilterOptions_Impl::Load();
209 Sequence<OUString> aNames(1);
210 aNames[0] = "Executable";
212 Sequence<Any> aValues = GetProperties(aNames);
213 const Any* pValues = aValues.getConstArray();
214 if(pValues[0].hasValue())
215 bLoadExecutable = *(sal_Bool*)pValues[0].getValue();
218 struct SvtFilterOptions_Impl
220 sal_uLong nFlags;
221 SvtWriterFilterOptions_Impl aWriterCfg;
222 SvtCalcFilterOptions_Impl aCalcCfg;
223 SvtAppFilterOptions_Impl aImpressCfg;
225 SvtFilterOptions_Impl() :
226 aWriterCfg("Office.Writer/Filter/Import/VBA"),
227 aCalcCfg("Office.Calc/Filter/Import/VBA"),
228 aImpressCfg("Office.Impress/Filter/Import/VBA")
230 nFlags = FILTERCFG_WORD_CODE |
231 FILTERCFG_WORD_STORAGE |
232 FILTERCFG_EXCEL_CODE |
233 FILTERCFG_EXCEL_STORAGE |
234 FILTERCFG_PPOINT_CODE |
235 FILTERCFG_PPOINT_STORAGE |
236 FILTERCFG_MATH_LOAD |
237 FILTERCFG_MATH_SAVE |
238 FILTERCFG_WRITER_LOAD |
239 FILTERCFG_WRITER_SAVE |
240 FILTERCFG_CALC_LOAD |
241 FILTERCFG_CALC_SAVE |
242 FILTERCFG_IMPRESS_LOAD |
243 FILTERCFG_IMPRESS_SAVE |
244 FILTERCFG_USE_ENHANCED_FIELDS;
245 Load();
248 void SetFlag( sal_uLong nFlag, sal_Bool bSet );
249 sal_Bool IsFlag( sal_uLong nFlag ) const;
250 void Load()
252 aWriterCfg.Load();
253 aCalcCfg.Load();
254 aImpressCfg.Load();
258 void SvtFilterOptions_Impl::SetFlag( sal_uLong nFlag, sal_Bool bSet )
260 switch(nFlag)
262 case FILTERCFG_WORD_CODE: aWriterCfg.SetLoad(bSet);break;
263 case FILTERCFG_WORD_STORAGE: aWriterCfg.SetSave(bSet);break;
264 case FILTERCFG_WORD_WBCTBL: aWriterCfg.SetLoadExecutable(bSet);break;
265 case FILTERCFG_EXCEL_CODE: aCalcCfg.SetLoad(bSet);break;
266 case FILTERCFG_EXCEL_STORAGE: aCalcCfg.SetSave(bSet);break;
267 case FILTERCFG_EXCEL_EXECTBL: aCalcCfg.SetLoadExecutable(bSet);break;
268 case FILTERCFG_PPOINT_CODE: aImpressCfg.SetLoad(bSet);break;
269 case FILTERCFG_PPOINT_STORAGE: aImpressCfg.SetSave(bSet);break;
270 default:
271 if( bSet )
272 nFlags |= nFlag;
273 else
274 nFlags &= ~nFlag;
278 sal_Bool SvtFilterOptions_Impl::IsFlag( sal_uLong nFlag ) const
280 sal_Bool bRet;
281 switch(nFlag)
283 case FILTERCFG_WORD_CODE : bRet = aWriterCfg.IsLoad();break;
284 case FILTERCFG_WORD_STORAGE : bRet = aWriterCfg.IsSave();break;
285 case FILTERCFG_WORD_WBCTBL : bRet = aWriterCfg.IsLoadExecutable();break;
286 case FILTERCFG_EXCEL_CODE : bRet = aCalcCfg.IsLoad();break;
287 case FILTERCFG_EXCEL_STORAGE : bRet = aCalcCfg.IsSave();break;
288 case FILTERCFG_EXCEL_EXECTBL : bRet = aCalcCfg.IsLoadExecutable();break;
289 case FILTERCFG_PPOINT_CODE : bRet = aImpressCfg.IsLoad();break;
290 case FILTERCFG_PPOINT_STORAGE : bRet = aImpressCfg.IsSave();break;
291 default:
292 bRet = 0 != (nFlags & nFlag );
294 return bRet;
297 // -----------------------------------------------------------------------
299 SvtFilterOptions::SvtFilterOptions() :
300 ConfigItem( "Office.Common/Filter/Microsoft" ),
301 pImp(new SvtFilterOptions_Impl)
303 RTL_LOGFILE_CONTEXT(aLog, "unotools SvtFilterOptions::SvtFilterOptions()");
304 EnableNotification(GetPropertyNames());
305 Load();
308 // -----------------------------------------------------------------------
309 SvtFilterOptions::~SvtFilterOptions()
311 delete pImp;
314 const Sequence<OUString>& SvtFilterOptions::GetPropertyNames()
316 static Sequence<OUString> aNames;
317 if(!aNames.getLength())
319 int nCount = 12;
320 aNames.realloc(nCount);
321 static const char* aPropNames[] =
323 "Import/MathTypeToMath", // 0
324 "Import/WinWordToWriter", // 1
325 "Import/PowerPointToImpress", // 2
326 "Import/ExcelToCalc", // 3
327 "Export/MathToMathType", // 4
328 "Export/WriterToWinWord", // 5
329 "Export/ImpressToPowerPoint", // 6
330 "Export/CalcToExcel", // 7
331 "Export/EnablePowerPointPreview", // 8
332 "Export/EnableExcelPreview", // 9
333 "Export/EnableWordPreview", // 10
334 "Import/ImportWWFieldsAsEnhancedFields" // 11
336 OUString* pNames = aNames.getArray();
337 for(int i = 0; i < nCount; i++)
338 pNames[i] = OUString::createFromAscii(aPropNames[i]);
340 return aNames;
342 //-----------------------------------------------------------------------
343 static sal_uLong lcl_GetFlag(sal_Int32 nProp)
345 sal_uLong nFlag = 0;
346 switch(nProp)
348 case 0: nFlag = FILTERCFG_MATH_LOAD; break;
349 case 1: nFlag = FILTERCFG_WRITER_LOAD; break;
350 case 2: nFlag = FILTERCFG_IMPRESS_LOAD; break;
351 case 3: nFlag = FILTERCFG_CALC_LOAD; break;
352 case 4: nFlag = FILTERCFG_MATH_SAVE; break;
353 case 5: nFlag = FILTERCFG_WRITER_SAVE; break;
354 case 6: nFlag = FILTERCFG_IMPRESS_SAVE; break;
355 case 7: nFlag = FILTERCFG_CALC_SAVE; break;
356 case 8: nFlag = FILTERCFG_ENABLE_PPT_PREVIEW; break;
357 case 9: nFlag = FILTERCFG_ENABLE_EXCEL_PREVIEW; break;
358 case 10: nFlag = FILTERCFG_ENABLE_WORD_PREVIEW; break;
359 case 11: nFlag = FILTERCFG_USE_ENHANCED_FIELDS; break;
361 default: OSL_FAIL("illegal value");
363 return nFlag;
366 void SvtFilterOptions::Notify( const Sequence<OUString>& )
368 Load();
371 void SvtFilterOptions::Commit()
373 const Sequence<OUString>& aNames = GetPropertyNames();
374 Sequence<Any> aValues(aNames.getLength());
375 Any* pValues = aValues.getArray();
377 const Type& rType = ::getBooleanCppuType();
378 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
380 sal_uLong nFlag = lcl_GetFlag(nProp);
381 sal_Bool bVal = pImp->IsFlag( nFlag);
382 pValues[nProp].setValue(&bVal, rType);
385 PutProperties(aNames, aValues);
388 void SvtFilterOptions::Load()
390 pImp->Load();
391 const Sequence<OUString>& rNames = GetPropertyNames();
392 Sequence<Any> aValues = GetProperties(rNames);
393 const Any* pValues = aValues.getConstArray();
394 DBG_ASSERT(aValues.getLength() == rNames.getLength(), "GetProperties failed");
395 if(aValues.getLength() == rNames.getLength())
397 for(int nProp = 0; nProp < rNames.getLength(); nProp++)
399 if(pValues[nProp].hasValue())
401 sal_Bool bVal = *(sal_Bool*)pValues[nProp].getValue();
402 sal_uLong nFlag = lcl_GetFlag(nProp);
403 pImp->SetFlag( nFlag, bVal);
408 // -----------------------------------------------------------------------
410 void SvtFilterOptions::SetLoadWordBasicCode( sal_Bool bFlag )
412 pImp->SetFlag( FILTERCFG_WORD_CODE, bFlag );
413 SetModified();
416 sal_Bool SvtFilterOptions::IsLoadWordBasicCode() const
418 return pImp->IsFlag( FILTERCFG_WORD_CODE );
421 void SvtFilterOptions::SetLoadWordBasicExecutable( sal_Bool bFlag )
423 pImp->SetFlag( FILTERCFG_WORD_WBCTBL, bFlag );
424 SetModified();
427 sal_Bool SvtFilterOptions::IsLoadWordBasicExecutable() const
429 return pImp->IsFlag( FILTERCFG_WORD_WBCTBL );
432 void SvtFilterOptions::SetLoadWordBasicStorage( sal_Bool bFlag )
434 pImp->SetFlag( FILTERCFG_WORD_STORAGE, bFlag );
435 SetModified();
438 sal_Bool SvtFilterOptions::IsLoadWordBasicStorage() const
440 return pImp->IsFlag( FILTERCFG_WORD_STORAGE );
443 // -----------------------------------------------------------------------
445 void SvtFilterOptions::SetLoadExcelBasicCode( sal_Bool bFlag )
447 pImp->SetFlag( FILTERCFG_EXCEL_CODE, bFlag );
448 SetModified();
451 sal_Bool SvtFilterOptions::IsLoadExcelBasicCode() const
453 return pImp->IsFlag( FILTERCFG_EXCEL_CODE );
456 void SvtFilterOptions::SetLoadExcelBasicExecutable( sal_Bool bFlag )
458 pImp->SetFlag( FILTERCFG_EXCEL_EXECTBL, bFlag );
459 SetModified();
462 sal_Bool SvtFilterOptions::IsLoadExcelBasicExecutable() const
464 return pImp->IsFlag( FILTERCFG_EXCEL_EXECTBL );
467 void SvtFilterOptions::SetLoadExcelBasicStorage( sal_Bool bFlag )
469 pImp->SetFlag( FILTERCFG_EXCEL_STORAGE, bFlag );
470 SetModified();
473 sal_Bool SvtFilterOptions::IsLoadExcelBasicStorage() const
475 return pImp->IsFlag( FILTERCFG_EXCEL_STORAGE );
478 // -----------------------------------------------------------------------
480 void SvtFilterOptions::SetLoadPPointBasicCode( sal_Bool bFlag )
482 pImp->SetFlag( FILTERCFG_PPOINT_CODE, bFlag );
483 SetModified();
486 sal_Bool SvtFilterOptions::IsLoadPPointBasicCode() const
488 return pImp->IsFlag( FILTERCFG_PPOINT_CODE );
491 void SvtFilterOptions::SetLoadPPointBasicStorage( sal_Bool bFlag )
493 pImp->SetFlag( FILTERCFG_PPOINT_STORAGE, bFlag );
494 SetModified();
497 sal_Bool SvtFilterOptions::IsLoadPPointBasicStorage() const
499 return pImp->IsFlag( FILTERCFG_PPOINT_STORAGE );
502 // -----------------------------------------------------------------------
504 sal_Bool SvtFilterOptions::IsMathType2Math() const
506 return pImp->IsFlag( FILTERCFG_MATH_LOAD );
509 void SvtFilterOptions::SetMathType2Math( sal_Bool bFlag )
511 pImp->SetFlag( FILTERCFG_MATH_LOAD, bFlag );
512 SetModified();
515 sal_Bool SvtFilterOptions::IsMath2MathType() const
517 return pImp->IsFlag( FILTERCFG_MATH_SAVE );
520 void SvtFilterOptions::SetMath2MathType( sal_Bool bFlag )
522 pImp->SetFlag( FILTERCFG_MATH_SAVE, bFlag );
523 SetModified();
527 // -----------------------------------------------------------------------
528 sal_Bool SvtFilterOptions::IsWinWord2Writer() const
530 return pImp->IsFlag( FILTERCFG_WRITER_LOAD );
533 void SvtFilterOptions::SetWinWord2Writer( sal_Bool bFlag )
535 pImp->SetFlag( FILTERCFG_WRITER_LOAD, bFlag );
536 SetModified();
539 sal_Bool SvtFilterOptions::IsWriter2WinWord() const
541 return pImp->IsFlag( FILTERCFG_WRITER_SAVE );
544 void SvtFilterOptions::SetWriter2WinWord( sal_Bool bFlag )
546 pImp->SetFlag( FILTERCFG_WRITER_SAVE, bFlag );
547 SetModified();
550 sal_Bool SvtFilterOptions::IsUseEnhancedFields() const
552 return pImp->IsFlag( FILTERCFG_USE_ENHANCED_FIELDS );
555 // -----------------------------------------------------------------------
556 sal_Bool SvtFilterOptions::IsExcel2Calc() const
558 return pImp->IsFlag( FILTERCFG_CALC_LOAD );
561 void SvtFilterOptions::SetExcel2Calc( sal_Bool bFlag )
563 pImp->SetFlag( FILTERCFG_CALC_LOAD, bFlag );
564 SetModified();
567 sal_Bool SvtFilterOptions::IsCalc2Excel() const
569 return pImp->IsFlag( FILTERCFG_CALC_SAVE );
572 void SvtFilterOptions::SetCalc2Excel( sal_Bool bFlag )
574 pImp->SetFlag( FILTERCFG_CALC_SAVE, bFlag );
575 SetModified();
579 // -----------------------------------------------------------------------
580 sal_Bool SvtFilterOptions::IsPowerPoint2Impress() const
582 return pImp->IsFlag( FILTERCFG_IMPRESS_LOAD );
585 void SvtFilterOptions::SetPowerPoint2Impress( sal_Bool bFlag )
587 pImp->SetFlag( FILTERCFG_IMPRESS_LOAD, bFlag );
588 SetModified();
591 sal_Bool SvtFilterOptions::IsImpress2PowerPoint() const
593 return pImp->IsFlag( FILTERCFG_IMPRESS_SAVE );
596 void SvtFilterOptions::SetImpress2PowerPoint( sal_Bool bFlag )
598 pImp->SetFlag( FILTERCFG_IMPRESS_SAVE, bFlag );
599 SetModified();
602 namespace
604 class theFilterOptions
605 : public rtl::Static<SvtFilterOptions, theFilterOptions>
610 SvtFilterOptions& SvtFilterOptions::Get()
612 return theFilterOptions::get();
615 // -----------------------------------------------------------------------
617 sal_Bool SvtFilterOptions::IsEnablePPTPreview() const
619 return pImp->IsFlag( FILTERCFG_ENABLE_PPT_PREVIEW );
623 sal_Bool SvtFilterOptions::IsEnableCalcPreview() const
625 return pImp->IsFlag( FILTERCFG_ENABLE_EXCEL_PREVIEW );
629 sal_Bool SvtFilterOptions::IsEnableWordPreview() const
631 return pImp->IsFlag( FILTERCFG_ENABLE_WORD_PREVIEW );
635 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */