Update ooo320-m1
[ooovba.git] / svtools / source / config / fltrcfg.cxx
blob529e72bf3ede1e47f400ad0d0e35bb1ccf2a81a7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fltrcfg.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #include "fltrcfg.hxx"
35 #include <tools/debug.hxx>
37 #include <rtl/logfile.hxx>
38 #include <com/sun/star/uno/Any.hxx>
39 #include <com/sun/star/uno/Sequence.hxx>
41 using namespace utl;
42 using namespace rtl;
43 using namespace com::sun::star::uno;
45 #define C2U(cChar) OUString::createFromAscii(cChar)
47 // -----------------------------------------------------------------------
48 #define FILTERCFG_WORD_CODE 0x0001
49 #define FILTERCFG_WORD_STORAGE 0x0002
50 #define FILTERCFG_EXCEL_CODE 0x0004
51 #define FILTERCFG_EXCEL_STORAGE 0x0008
52 #define FILTERCFG_PPOINT_CODE 0x0010
53 #define FILTERCFG_PPOINT_STORAGE 0x0020
54 #define FILTERCFG_MATH_LOAD 0x0100
55 #define FILTERCFG_MATH_SAVE 0x0200
56 #define FILTERCFG_WRITER_LOAD 0x0400
57 #define FILTERCFG_WRITER_SAVE 0x0800
58 #define FILTERCFG_CALC_LOAD 0x1000
59 #define FILTERCFG_CALC_SAVE 0x2000
60 #define FILTERCFG_IMPRESS_LOAD 0x4000
61 #define FILTERCFG_IMPRESS_SAVE 0x8000
62 #define FILTERCFG_EXCEL_EXECTBL 0x10000
63 #define FILTERCFG_ENABLE_PPT_PREVIEW 0x20000
64 #define FILTERCFG_ENABLE_EXCEL_PREVIEW 0x40000
65 #define FILTERCFG_ENABLE_WORD_PREVIEW 0x80000
66 #define FILTERCFG_USE_ENHANCED_FIELDS 0x100000
68 static SvtFilterOptions* pOptions=0;
70 /* -----------------------------22.01.01 10:23--------------------------------
72 ---------------------------------------------------------------------------*/
73 class SvtAppFilterOptions_Impl : public utl::ConfigItem
75 sal_Bool bLoadVBA;
76 sal_Bool bSaveVBA;
77 public:
78 SvtAppFilterOptions_Impl(const OUString& rRoot) :
79 utl::ConfigItem(rRoot),
80 bLoadVBA(sal_False),
81 bSaveVBA(sal_False) {}
82 ~SvtAppFilterOptions_Impl();
83 virtual void Commit();
84 void Load();
86 sal_Bool IsLoad() const {return bLoadVBA;}
87 void SetLoad(sal_Bool bSet)
89 if(bSet != bLoadVBA)
90 SetModified();
91 bLoadVBA = bSet;
93 sal_Bool IsSave() const {return bSaveVBA;}
94 void SetSave(sal_Bool bSet)
96 if(bSet != bSaveVBA)
97 SetModified();
98 bSaveVBA = bSet;
102 /* -----------------------------22.01.01 11:08--------------------------------
104 ---------------------------------------------------------------------------*/
105 SvtAppFilterOptions_Impl::~SvtAppFilterOptions_Impl()
107 if(IsModified())
108 Commit();
110 /* -----------------------------22.01.01 10:38--------------------------------
112 ---------------------------------------------------------------------------*/
113 void SvtAppFilterOptions_Impl::Commit()
115 Sequence<OUString> aNames(2);
116 OUString* pNames = aNames.getArray();
117 pNames[0] = C2U("Load");
118 pNames[1] = C2U("Save");
119 Sequence<Any> aValues(aNames.getLength());
120 Any* pValues = aValues.getArray();
122 const Type& rType = ::getBooleanCppuType();
123 pValues[0].setValue(&bLoadVBA, rType);
124 pValues[1].setValue(&bSaveVBA, rType);
126 PutProperties(aNames, aValues);
128 /* -----------------------------22.01.01 10:38--------------------------------
130 ---------------------------------------------------------------------------*/
131 void SvtAppFilterOptions_Impl::Load()
133 Sequence<OUString> aNames(2);
134 OUString* pNames = aNames.getArray();
135 pNames[0] = C2U("Load");
136 pNames[1] = C2U("Save");
138 Sequence<Any> aValues = GetProperties(aNames);
139 const Any* pValues = aValues.getConstArray();
141 if(pValues[0].hasValue())
142 bLoadVBA = *(sal_Bool*)pValues[0].getValue();
143 if(pValues[1].hasValue())
144 bSaveVBA = *(sal_Bool*)pValues[1].getValue();
147 // -----------------------------------------------------------------------
148 class SvtCalcFilterOptions_Impl : public SvtAppFilterOptions_Impl
150 sal_Bool bLoadExecutable;
151 public:
152 SvtCalcFilterOptions_Impl(const OUString& rRoot) :
153 SvtAppFilterOptions_Impl(rRoot),
154 bLoadExecutable(sal_False)
156 virtual void Commit();
157 void Load();
159 sal_Bool IsLoadExecutable() const {return bLoadExecutable;}
160 void SetLoadExecutable(sal_Bool bSet)
162 if(bSet != bLoadExecutable)
163 SetModified();
164 bLoadExecutable = bSet;
168 void SvtCalcFilterOptions_Impl::Commit()
170 SvtAppFilterOptions_Impl::Commit();
172 Sequence<OUString> aNames(1);
173 aNames[0] = C2U("Executable");
174 Sequence<Any> aValues(1);
175 aValues[0] <<= bLoadExecutable;
177 PutProperties(aNames, aValues);
180 void SvtCalcFilterOptions_Impl::Load()
182 SvtAppFilterOptions_Impl::Load();
184 Sequence<OUString> aNames(1);
185 aNames[0] = C2U("Executable");
187 Sequence<Any> aValues = GetProperties(aNames);
188 const Any* pValues = aValues.getConstArray();
189 if(pValues[0].hasValue())
190 bLoadExecutable = *(sal_Bool*)pValues[0].getValue();
193 /* -----------------------------22.01.01 10:32--------------------------------
195 ---------------------------------------------------------------------------*/
196 struct SvtFilterOptions_Impl
198 ULONG nFlags;
199 SvtAppFilterOptions_Impl aWriterCfg;
200 SvtCalcFilterOptions_Impl aCalcCfg;
201 SvtAppFilterOptions_Impl aImpressCfg;
203 SvtFilterOptions_Impl() :
204 aWriterCfg(C2U("Office.Writer/Filter/Import/VBA")),
205 aCalcCfg(C2U("Office.Calc/Filter/Import/VBA")),
206 aImpressCfg(C2U("Office.Impress/Filter/Import/VBA"))
208 nFlags = FILTERCFG_WORD_CODE |
209 FILTERCFG_WORD_STORAGE |
210 FILTERCFG_EXCEL_CODE |
211 FILTERCFG_EXCEL_STORAGE |
212 FILTERCFG_PPOINT_CODE |
213 FILTERCFG_PPOINT_STORAGE |
214 FILTERCFG_MATH_LOAD |
215 FILTERCFG_MATH_SAVE |
216 FILTERCFG_WRITER_LOAD |
217 FILTERCFG_WRITER_SAVE |
218 FILTERCFG_CALC_LOAD |
219 FILTERCFG_CALC_SAVE |
220 FILTERCFG_IMPRESS_LOAD |
221 FILTERCFG_IMPRESS_SAVE |
222 FILTERCFG_USE_ENHANCED_FIELDS;
223 Load();
226 void SetFlag( ULONG nFlag, BOOL bSet );
227 BOOL IsFlag( ULONG nFlag ) const;
228 void Load()
230 aWriterCfg.Load();
231 aCalcCfg.Load();
232 aImpressCfg.Load();
235 /* -----------------------------22.01.01 10:34--------------------------------
237 ---------------------------------------------------------------------------*/
238 void SvtFilterOptions_Impl::SetFlag( ULONG nFlag, BOOL bSet )
240 switch(nFlag)
242 case FILTERCFG_WORD_CODE: aWriterCfg.SetLoad(bSet);break;
243 case FILTERCFG_WORD_STORAGE: aWriterCfg.SetSave(bSet);break;
244 case FILTERCFG_EXCEL_CODE: aCalcCfg.SetLoad(bSet);break;
245 case FILTERCFG_EXCEL_STORAGE: aCalcCfg.SetSave(bSet);break;
246 case FILTERCFG_EXCEL_EXECTBL: aCalcCfg.SetLoadExecutable(bSet);break;
247 case FILTERCFG_PPOINT_CODE: aImpressCfg.SetLoad(bSet);break;
248 case FILTERCFG_PPOINT_STORAGE: aImpressCfg.SetSave(bSet);break;
249 default:
250 if( bSet )
251 nFlags |= nFlag;
252 else
253 nFlags &= ~nFlag;
256 /* -----------------------------22.01.01 10:35--------------------------------
258 ---------------------------------------------------------------------------*/
259 BOOL SvtFilterOptions_Impl::IsFlag( ULONG nFlag ) const
261 BOOL bRet;
262 switch(nFlag)
264 case FILTERCFG_WORD_CODE : bRet = aWriterCfg.IsLoad();break;
265 case FILTERCFG_WORD_STORAGE : bRet = aWriterCfg.IsSave();break;
266 case FILTERCFG_EXCEL_CODE : bRet = aCalcCfg.IsLoad();break;
267 case FILTERCFG_EXCEL_STORAGE : bRet = aCalcCfg.IsSave();break;
268 case FILTERCFG_EXCEL_EXECTBL : bRet = aCalcCfg.IsLoadExecutable();break;
269 case FILTERCFG_PPOINT_CODE : bRet = aImpressCfg.IsLoad();break;
270 case FILTERCFG_PPOINT_STORAGE : bRet = aImpressCfg.IsSave();break;
271 default:
272 bRet = 0 != (nFlags & nFlag );
274 return bRet;
277 // -----------------------------------------------------------------------
279 SvtFilterOptions::SvtFilterOptions() :
280 ConfigItem( C2U("Office.Common/Filter/Microsoft") ),
281 pImp(new SvtFilterOptions_Impl)
283 RTL_LOGFILE_CONTEXT(aLog, "svtools SvtFilterOptions::SvtFilterOptions()");
284 EnableNotification(GetPropertyNames());
285 Load();
287 // -----------------------------------------------------------------------
288 SvtFilterOptions::~SvtFilterOptions()
290 delete pImp;
292 /* -----------------------------22.01.01 08:45--------------------------------
294 ---------------------------------------------------------------------------*/
295 const Sequence<OUString>& SvtFilterOptions::GetPropertyNames()
297 static Sequence<OUString> aNames;
298 if(!aNames.getLength())
300 int nCount = 12;
301 aNames.realloc(nCount);
302 static const char* aPropNames[] =
304 "Import/MathTypeToMath", // 0
305 "Import/WinWordToWriter", // 1
306 "Import/PowerPointToImpress", // 2
307 "Import/ExcelToCalc", // 3
308 "Export/MathToMathType", // 4
309 "Export/WriterToWinWord", // 5
310 "Export/ImpressToPowerPoint", // 6
311 "Export/CalcToExcel", // 7
312 "Export/EnablePowerPointPreview", // 8
313 "Export/EnableExcelPreview", // 9
314 "Export/EnableWordPreview", // 10
315 "Import/ImportWWFieldsAsEnhancedFields" // 11
317 OUString* pNames = aNames.getArray();
318 for(int i = 0; i < nCount; i++)
319 pNames[i] = C2U(aPropNames[i]);
321 return aNames;
323 //-----------------------------------------------------------------------
324 static ULONG lcl_GetFlag(sal_Int32 nProp)
326 ULONG nFlag = 0;
327 switch(nProp)
329 case 0: nFlag = FILTERCFG_MATH_LOAD; break;
330 case 1: nFlag = FILTERCFG_WRITER_LOAD; break;
331 case 2: nFlag = FILTERCFG_IMPRESS_LOAD; break;
332 case 3: nFlag = FILTERCFG_CALC_LOAD; break;
333 case 4: nFlag = FILTERCFG_MATH_SAVE; break;
334 case 5: nFlag = FILTERCFG_WRITER_SAVE; break;
335 case 6: nFlag = FILTERCFG_IMPRESS_SAVE; break;
336 case 7: nFlag = FILTERCFG_CALC_SAVE; break;
337 case 8: nFlag = FILTERCFG_ENABLE_PPT_PREVIEW; break;
338 case 9: nFlag = FILTERCFG_ENABLE_EXCEL_PREVIEW; break;
339 case 10: nFlag = FILTERCFG_ENABLE_WORD_PREVIEW; break;
340 case 11: nFlag = FILTERCFG_USE_ENHANCED_FIELDS; break;
342 default: DBG_ERROR("illegal value");
344 return nFlag;
346 /*-- 22.01.01 08:53:03---------------------------------------------------
348 -----------------------------------------------------------------------*/
349 void SvtFilterOptions::Notify( const Sequence<OUString>& )
351 Load();
353 /*-- 22.01.01 08:53:04---------------------------------------------------
355 -----------------------------------------------------------------------*/
356 void SvtFilterOptions::Commit()
358 const Sequence<OUString>& aNames = GetPropertyNames();
359 Sequence<Any> aValues(aNames.getLength());
360 Any* pValues = aValues.getArray();
362 const Type& rType = ::getBooleanCppuType();
363 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
365 ULONG nFlag = lcl_GetFlag(nProp);
366 sal_Bool bVal = pImp->IsFlag( nFlag);
367 pValues[nProp].setValue(&bVal, rType);
370 PutProperties(aNames, aValues);
372 /*-- 22.01.01 08:53:04---------------------------------------------------
374 -----------------------------------------------------------------------*/
375 void SvtFilterOptions::Load()
377 pImp->Load();
378 const Sequence<OUString>& rNames = GetPropertyNames();
379 Sequence<Any> aValues = GetProperties(rNames);
380 const Any* pValues = aValues.getConstArray();
381 DBG_ASSERT(aValues.getLength() == rNames.getLength(), "GetProperties failed");
382 if(aValues.getLength() == rNames.getLength())
384 for(int nProp = 0; nProp < rNames.getLength(); nProp++)
386 if(pValues[nProp].hasValue())
388 sal_Bool bVal = *(sal_Bool*)pValues[nProp].getValue();
389 ULONG nFlag = lcl_GetFlag(nProp);
390 pImp->SetFlag( nFlag, bVal);
395 // -----------------------------------------------------------------------
397 void SvtFilterOptions::SetLoadWordBasicCode( BOOL bFlag )
399 pImp->SetFlag( FILTERCFG_WORD_CODE, bFlag );
400 SetModified();
403 BOOL SvtFilterOptions::IsLoadWordBasicCode() const
405 return pImp->IsFlag( FILTERCFG_WORD_CODE );
408 void SvtFilterOptions::SetLoadWordBasicStorage( BOOL bFlag )
410 pImp->SetFlag( FILTERCFG_WORD_STORAGE, bFlag );
411 SetModified();
414 BOOL SvtFilterOptions::IsLoadWordBasicStorage() const
416 return pImp->IsFlag( FILTERCFG_WORD_STORAGE );
419 // -----------------------------------------------------------------------
421 void SvtFilterOptions::SetLoadExcelBasicCode( BOOL bFlag )
423 pImp->SetFlag( FILTERCFG_EXCEL_CODE, bFlag );
424 SetModified();
427 BOOL SvtFilterOptions::IsLoadExcelBasicCode() const
429 return pImp->IsFlag( FILTERCFG_EXCEL_CODE );
432 void SvtFilterOptions::SetLoadExcelBasicExecutable( BOOL bFlag )
434 pImp->SetFlag( FILTERCFG_EXCEL_EXECTBL, bFlag );
435 SetModified();
438 BOOL SvtFilterOptions::IsLoadExcelBasicExecutable() const
440 return pImp->IsFlag( FILTERCFG_EXCEL_EXECTBL );
443 void SvtFilterOptions::SetLoadExcelBasicStorage( BOOL bFlag )
445 pImp->SetFlag( FILTERCFG_EXCEL_STORAGE, bFlag );
446 SetModified();
449 BOOL SvtFilterOptions::IsLoadExcelBasicStorage() const
451 return pImp->IsFlag( FILTERCFG_EXCEL_STORAGE );
454 // -----------------------------------------------------------------------
456 void SvtFilterOptions::SetLoadPPointBasicCode( BOOL bFlag )
458 pImp->SetFlag( FILTERCFG_PPOINT_CODE, bFlag );
459 SetModified();
462 BOOL SvtFilterOptions::IsLoadPPointBasicCode() const
464 return pImp->IsFlag( FILTERCFG_PPOINT_CODE );
467 void SvtFilterOptions::SetLoadPPointBasicStorage( BOOL bFlag )
469 pImp->SetFlag( FILTERCFG_PPOINT_STORAGE, bFlag );
470 SetModified();
473 BOOL SvtFilterOptions::IsLoadPPointBasicStorage() const
475 return pImp->IsFlag( FILTERCFG_PPOINT_STORAGE );
478 // -----------------------------------------------------------------------
480 BOOL SvtFilterOptions::IsMathType2Math() const
482 return pImp->IsFlag( FILTERCFG_MATH_LOAD );
485 void SvtFilterOptions::SetMathType2Math( BOOL bFlag )
487 pImp->SetFlag( FILTERCFG_MATH_LOAD, bFlag );
488 SetModified();
491 BOOL SvtFilterOptions::IsMath2MathType() const
493 return pImp->IsFlag( FILTERCFG_MATH_SAVE );
496 void SvtFilterOptions::SetMath2MathType( BOOL bFlag )
498 pImp->SetFlag( FILTERCFG_MATH_SAVE, bFlag );
499 SetModified();
503 // -----------------------------------------------------------------------
504 BOOL SvtFilterOptions::IsWinWord2Writer() const
506 return pImp->IsFlag( FILTERCFG_WRITER_LOAD );
509 void SvtFilterOptions::SetWinWord2Writer( BOOL bFlag )
511 pImp->SetFlag( FILTERCFG_WRITER_LOAD, bFlag );
512 SetModified();
515 BOOL SvtFilterOptions::IsWriter2WinWord() const
517 return pImp->IsFlag( FILTERCFG_WRITER_SAVE );
520 void SvtFilterOptions::SetWriter2WinWord( BOOL bFlag )
522 pImp->SetFlag( FILTERCFG_WRITER_SAVE, bFlag );
523 SetModified();
526 BOOL SvtFilterOptions::IsUseEnhancedFields() const
528 return pImp->IsFlag( FILTERCFG_USE_ENHANCED_FIELDS );
531 void SvtFilterOptions::SetUseEnhancedFields( BOOL bFlag )
533 pImp->SetFlag( FILTERCFG_USE_ENHANCED_FIELDS, bFlag );
534 SetModified();
537 // -----------------------------------------------------------------------
538 BOOL SvtFilterOptions::IsExcel2Calc() const
540 return pImp->IsFlag( FILTERCFG_CALC_LOAD );
543 void SvtFilterOptions::SetExcel2Calc( BOOL bFlag )
545 pImp->SetFlag( FILTERCFG_CALC_LOAD, bFlag );
546 SetModified();
549 BOOL SvtFilterOptions::IsCalc2Excel() const
551 return pImp->IsFlag( FILTERCFG_CALC_SAVE );
554 void SvtFilterOptions::SetCalc2Excel( BOOL bFlag )
556 pImp->SetFlag( FILTERCFG_CALC_SAVE, bFlag );
557 SetModified();
561 // -----------------------------------------------------------------------
562 BOOL SvtFilterOptions::IsPowerPoint2Impress() const
564 return pImp->IsFlag( FILTERCFG_IMPRESS_LOAD );
567 void SvtFilterOptions::SetPowerPoint2Impress( BOOL bFlag )
569 pImp->SetFlag( FILTERCFG_IMPRESS_LOAD, bFlag );
570 SetModified();
573 BOOL SvtFilterOptions::IsImpress2PowerPoint() const
575 return pImp->IsFlag( FILTERCFG_IMPRESS_SAVE );
578 void SvtFilterOptions::SetImpress2PowerPoint( BOOL bFlag )
580 pImp->SetFlag( FILTERCFG_IMPRESS_SAVE, bFlag );
581 SetModified();
584 SvtFilterOptions* SvtFilterOptions::Get()
586 if ( !pOptions )
587 pOptions = new SvtFilterOptions;
588 return pOptions;
591 // -----------------------------------------------------------------------
593 BOOL SvtFilterOptions::IsEnablePPTPreview() const
595 return pImp->IsFlag( FILTERCFG_ENABLE_PPT_PREVIEW );
599 BOOL SvtFilterOptions::IsEnableCalcPreview() const
601 return pImp->IsFlag( FILTERCFG_ENABLE_EXCEL_PREVIEW );
605 BOOL SvtFilterOptions::IsEnableWordPreview() const
607 return pImp->IsFlag( FILTERCFG_ENABLE_WORD_PREVIEW );