Update ooo320-m1
[ooovba.git] / svx / source / cui / optsave.cxx
blob18385e584b590eeea1d32092ee164e75c9ece207
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: optsave.cxx,v $
10 * $Revision: 1.21 $
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_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
36 #endif
38 // include ---------------------------------------------------------------
39 #include <tools/shl.hxx>
40 #include <svtools/eitem.hxx>
41 #include <svtools/intitem.hxx>
42 #define _SVX_OPTSAVE_CXX
44 #include "optsave.hrc"
45 #include <svx/dialogs.hrc>
47 #include "optsave.hxx"
48 #include <svx/dialmgr.hxx>
49 #include <comphelper/processfactory.hxx>
50 #include <comphelper/sequenceasvector.hxx>
51 #include <comphelper/sequenceashashmap.hxx>
52 #include <svtools/moduleoptions.hxx>
53 #include <svtools/saveopt.hxx>
54 #include <comphelper/sequenceasvector.hxx>
55 #include <comphelper/sequenceashashmap.hxx>
56 #include <com/sun/star/container/XContainerQuery.hpp>
57 #include <com/sun/star/container/XEnumeration.hpp>
58 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
59 #include <com/sun/star/container/XNameContainer.hpp>
60 #include <com/sun/star/container/XContainerQuery.hpp>
61 #include <com/sun/star/container/XEnumeration.hpp>
62 #include <com/sun/star/beans/PropertyValue.hpp>
63 #include <com/sun/star/util/XFlushable.hpp>
64 #include <sfx2/docfilt.hxx>
65 #include <svtools/stdctrl.hxx>
66 #include <vcl/fixed.hxx>
67 #include <vcl/msgbox.hxx>
68 #include <unotools/configitem.hxx>
69 #include <svtools/optionsdlg.hxx>
71 #include <vcl/msgbox.hxx>
73 using namespace com::sun::star::uno;
74 using namespace com::sun::star::util;
75 using namespace com::sun::star::lang;
76 using namespace com::sun::star::beans;
77 using namespace com::sun::star::container;
78 using namespace comphelper;
79 using rtl::OUString;
81 #define C2U(cChar) OUString::createFromAscii(cChar)
82 #define C2S(cChar) String( RTL_CONSTASCII_STRINGPARAM(cChar) )
83 #define CFG_PAGE_AND_GROUP C2S("General"), C2S("LoadSave")
84 // !! you have to update these index, if you changed the list of the child windows !!
85 #define WININDEX_AUTOSAVE ((USHORT)6)
86 #define WININDEX_SAVEURL_RELFSYS ((USHORT)9)
88 // -------------------- --------------------------------------------------
89 class FilterWarningDialog_Impl : public ModalDialog
91 OKButton aOk;
92 CancelButton aCancel;
93 FixedImage aImage;
94 FixedInfo aFilterWarningFT;
96 public:
97 FilterWarningDialog_Impl(Window* pParent);
99 void SetFilterName(const String& rFilterUIName);
101 // ----------------------------------------------------------------------
102 FilterWarningDialog_Impl::FilterWarningDialog_Impl(Window* pParent) :
103 ModalDialog(pParent, SVX_RES( RID_SVXDLG_FILTER_WARNING ) ),
104 aOk( this, SVX_RES(PB_OK )),
105 aCancel( this, SVX_RES(PB_CANCEL )),
106 aImage( this, SVX_RES(IMG_WARNING )),
107 aFilterWarningFT( this, SVX_RES(FT_FILTER_WARNING ))
109 FreeResource();
110 aImage.SetImage(WarningBox::GetStandardImage());
112 // ----------------------------------------------------------------------
113 void FilterWarningDialog_Impl::SetFilterName(const String& rFilterUIName)
115 String sTmp(aFilterWarningFT.GetText());
116 sTmp.SearchAndReplaceAscii("%1", rFilterUIName);
117 aFilterWarningFT.SetText(sTmp);
119 // ----------------------------------------------------------------------
120 #ifdef FILTER_WARNING_ENABLED
121 class SvxAlienFilterWarningConfig_Impl : public utl::ConfigItem
123 sal_Bool bWarning;
124 com::sun::star::uno::Sequence< OUString > aPropNames;
126 public:
127 SvxAlienFilterWarningConfig_Impl();
128 ~SvxAlienFilterWarningConfig_Impl();
130 virtual void Commit();
132 void ResetWarning()
134 if(bWarning)
136 bWarning = sal_False;
137 ConfigItem::SetModified();
141 sal_Bool IsWarning()const{return bWarning;}
143 // ----------------------------------------------------------------------
144 SvxAlienFilterWarningConfig_Impl::SvxAlienFilterWarningConfig_Impl() :
145 ConfigItem(C2U("TypeDetection.Misc/Defaults"),
146 CONFIG_MODE_IMMEDIATE_UPDATE),
147 aPropNames(1),
148 bWarning(sal_True)
150 aPropNames.getArray()[0] = C2U("ShowAlienFilterWarning");
151 Sequence<Any> aValues = GetProperties(aPropNames);
152 const Any* pValues = aValues.getConstArray();
153 DBG_ASSERT(aValues.getLength() == aPropNames.getLength(), "GetProperties failed");
154 if(aValues.getLength() == aPropNames.getLength() &&
155 pValues[0].hasValue() &&
156 pValues[0].getValueType() == ::getBooleanCppuType())
157 bWarning = *(sal_Bool*)pValues[0].getValue();
159 // ----------------------------------------------------------------------
160 SvxAlienFilterWarningConfig_Impl::~SvxAlienFilterWarningConfig_Impl()
162 if(IsModified())
163 Commit();
165 // ----------------------------------------------------------------------
166 void SvxAlienFilterWarningConfig_Impl::Commit()
168 Sequence<Any> aValues(aPropNames.getLength());
169 Any* pValues = aValues.getArray();
170 pValues[0].setValue(&bWarning, ::getBooleanCppuType());
171 PutProperties(aPropNames, aValues);
173 #endif // FILTER_WARNING_ENABLED
174 // ----------------------------------------------------------------------
175 // ----------------------------------------------------------------------
177 struct SvxSaveTabPage_Impl
179 Reference< XNameContainer > xFact;
180 Sequence< OUString > aFilterArr[APP_COUNT];
181 Sequence< sal_Bool > aAlienArr[APP_COUNT];
182 Sequence< sal_Bool > aODFArr[APP_COUNT];
183 Sequence< OUString > aUIFilterArr[APP_COUNT];
184 OUString aDefaultArr[APP_COUNT];
185 sal_Bool aDefaultReadonlyArr[APP_COUNT];
186 sal_Bool bInitialized;
188 SvxSaveTabPage_Impl();
189 ~SvxSaveTabPage_Impl();
192 SvxSaveTabPage_Impl::SvxSaveTabPage_Impl() : bInitialized( sal_False )
196 SvxSaveTabPage_Impl::~SvxSaveTabPage_Impl()
200 // class SvxSaveTabPage --------------------------------------------------
202 SfxSaveTabPage::SfxSaveTabPage( Window* pParent, const SfxItemSet& rCoreSet ) :
204 SfxTabPage( pParent, SVX_RES( RID_SFXPAGE_SAVE ), rCoreSet ),
206 aLoadFL ( this, SVX_RES( LB_LOAD ) ),
207 aLoadUserSettingsCB ( this, SVX_RES( CB_LOAD_SETTINGS ) ),
208 aLoadDocPrinterCB ( this, SVX_RES( CB_LOAD_DOCPRINTER ) ),
210 aSaveFL ( this, SVX_RES( GB_SAVE ) ),
211 aDocInfoCB ( this, SVX_RES( BTN_DOCINFO ) ),
212 aBackupFI ( this, SVX_RES( FI_BACKUP ) ),
213 aBackupCB ( this, SVX_RES( BTN_BACKUP ) ),
214 aAutoSaveCB ( this, SVX_RES( BTN_AUTOSAVE ) ),
215 aAutoSaveEdit ( this, SVX_RES( ED_AUTOSAVE ) ),
216 aMinuteFT ( this, SVX_RES( FT_MINUTE ) ),
217 aRelativeFsysCB ( this, SVX_RES( BTN_RELATIVE_FSYS ) ),
218 aRelativeInetCB ( this, SVX_RES( BTN_RELATIVE_INET ) ),
220 aDefaultFormatFL ( this, SVX_RES( FL_FILTER ) ),
221 aODFVersionFT ( this, SVX_RES( FT_ODF_VERSION ) ),
222 aODFVersionLB ( this, SVX_RES( LB_ODF_VERSION ) ),
223 aSizeOptimizationCB ( this, SVX_RES( BTN_NOPRETTYPRINTING ) ),
224 aWarnAlienFormatCB ( this, SVX_RES( BTN_WARNALIENFORMAT ) ),
225 aDocTypeFT ( this, SVX_RES( FT_APP ) ),
226 aDocTypeLB ( this, SVX_RES( LB_APP ) ),
227 aSaveAsFT ( this, SVX_RES( FT_FILTER ) ),
228 aSaveAsFI ( this, SVX_RES( FI_FILTER ) ),
229 aSaveAsLB ( this, SVX_RES( LB_FILTER ) ),
230 aODFWarningFI ( this, SVX_RES( FI_ODF_WARNING ) ),
231 aODFWarningFT ( this, SVX_RES( FT_WARN ) ),
233 pImpl ( new SvxSaveTabPage_Impl )
236 sal_Bool bHighContrast = GetDisplayBackground().GetColor().IsDark();
237 aODFWarningFI.SetImage(
238 Image( SVX_RES( bHighContrast ? IMG_ODF_WARNING_HC : IMG_ODF_WARNING ) ) );
240 FreeResource();
242 Link aLink = LINK( this, SfxSaveTabPage, AutoClickHdl_Impl );
243 aAutoSaveCB.SetClickHdl( aLink );
244 aAutoSaveEdit.SetMaxTextLen( 2 );
246 SvtModuleOptions aModuleOpt;
247 if ( !aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SMATH ) )
249 aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_MATH ));
250 aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_MATH ));
252 else
254 pImpl->aDefaultArr[APP_MATH] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_MATH);
255 pImpl->aDefaultReadonlyArr[APP_MATH] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_MATH);
258 if ( !aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
260 aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_DRAW ));
261 aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_DRAW ));
263 else
265 pImpl->aDefaultArr[APP_DRAW] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_DRAW);
266 pImpl->aDefaultReadonlyArr[APP_DRAW] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_DRAW);
269 if ( !aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
271 aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_IMPRESS ));
272 aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_IMPRESS ));
274 else
276 pImpl->aDefaultArr[APP_IMPRESS] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_IMPRESS);
277 pImpl->aDefaultReadonlyArr[APP_IMPRESS] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_IMPRESS);
280 if ( !aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
282 aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_CALC ));
283 aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_CALC ));
285 else
287 pImpl->aDefaultArr[APP_CALC] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_CALC);
288 pImpl->aDefaultReadonlyArr[APP_CALC] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_CALC);
291 if ( !aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
293 aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_WRITER ));
294 aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_WRITER_WEB ));
295 aSaveAsLB.RemoveEntry(aSaveAsLB.GetEntryPos( (void*) APP_WRITER_GLOBAL ));
296 aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_WRITER ));
297 aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_WRITER_WEB ));
298 aDocTypeLB.RemoveEntry(aDocTypeLB.GetEntryPos( (void*) APP_WRITER_GLOBAL ));
300 else
302 pImpl->aDefaultArr[APP_WRITER] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_WRITER);
303 pImpl->aDefaultArr[APP_WRITER_WEB] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_WRITERWEB);
304 pImpl->aDefaultArr[APP_WRITER_GLOBAL] = aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_WRITERGLOBAL);
305 pImpl->aDefaultReadonlyArr[APP_WRITER] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_WRITER);
306 pImpl->aDefaultReadonlyArr[APP_WRITER_WEB] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_WRITERWEB);
307 pImpl->aDefaultReadonlyArr[APP_WRITER_GLOBAL] = aModuleOpt.IsDefaultFilterReadonly(SvtModuleOptions::E_WRITERGLOBAL);
310 aLink = LINK( this, SfxSaveTabPage, ODFVersionHdl_Impl );
311 aODFVersionLB.SetSelectHdl( aLink );
312 aLink = LINK( this, SfxSaveTabPage, FilterHdl_Impl );
313 aDocTypeLB.SetSelectHdl( aLink );
314 aSaveAsLB.SetSelectHdl( aLink );
316 DetectHiddenControls();
319 // -----------------------------------------------------------------------
321 SfxSaveTabPage::~SfxSaveTabPage()
323 delete pImpl;
326 // -----------------------------------------------------------------------
328 SfxTabPage* SfxSaveTabPage::Create( Window* pParent,
329 const SfxItemSet& rAttrSet )
331 return ( new SfxSaveTabPage( pParent, rAttrSet ) );
334 /* -----------------------------05.04.01 13:10--------------------------------
336 ---------------------------------------------------------------------------*/
337 OUString lcl_ExtractUIName(const Sequence<PropertyValue> rProperties)
339 OUString sRet;
340 const PropertyValue* pProperties = rProperties.getConstArray();
341 for(int nProp = 0; nProp < rProperties.getLength(); nProp++)
343 if(!pProperties[nProp].Name.compareToAscii("UIName"))
345 pProperties[nProp].Value >>= sRet;
346 break;
349 return sRet;
351 // -----------------------------------------------------------------------
352 bool SfxSaveTabPage::AcceptFilter( USHORT nPos )
354 const OUString* pFilters = pImpl->aFilterArr[nPos].getConstArray();
355 sal_Bool bAlien = sal_False, bODF = sal_False;
356 OUString* pUIFilters = pImpl->aUIFilterArr[nPos].getArray();
357 OUString sUIName;
358 for(int nFilter = 0; nFilter < pImpl->aFilterArr[nPos].getLength(); nFilter++)
360 if( pImpl->aDefaultArr[nPos] == pFilters[nFilter] )
362 bAlien = pImpl->aAlienArr[nPos][nFilter];
363 bODF = pImpl->aODFArr[nPos][nFilter];
364 sUIName = pUIFilters[nFilter];;
365 break;
368 bool bSet = true;
369 return bSet;
371 // -----------------------------------------------------------------------
372 void SfxSaveTabPage::DetectHiddenControls()
374 long nDelta = 0;
375 // the index of the first child window which perhaps have to move upwards
376 USHORT nWinIndex = WININDEX_SAVEURL_RELFSYS;
377 SvtOptionsDialogOptions aOptionsDlgOpt;
379 if ( aOptionsDlgOpt.IsOptionHidden( C2S("Backup"), CFG_PAGE_AND_GROUP ) )
381 // hide controls of "Backup"
382 aBackupFI.Hide();
383 aBackupCB.Hide();
384 // the other controls have to move upwards the height of checkbox + space
385 nDelta = aAutoSaveCB.GetPosPixel().Y() - aBackupCB.GetPosPixel().Y();
388 if ( aOptionsDlgOpt.IsOptionHidden( C2S("AutoSave"), CFG_PAGE_AND_GROUP ) )
390 // hide controls of "AutoSave"
391 aAutoSaveCB.Hide();
392 aAutoSaveEdit.Hide();
393 aMinuteFT.Hide();
394 // the other controls have to move upwards the height of checkbox + space
395 nDelta += aRelativeFsysCB.GetPosPixel().Y() - aAutoSaveCB.GetPosPixel().Y();
397 else if ( nDelta > 0 )
398 // the "AutoSave" controls have to move upwards too
399 nWinIndex = WININDEX_AUTOSAVE;
401 if ( nDelta > 0 )
403 USHORT i, nChildCount = GetChildCount();
404 for ( i = nWinIndex; i < nChildCount; ++i )
406 Window* pWin = GetChild(i);
407 Point aPos = pWin->GetPosPixel();
408 aPos.Y() -= nDelta;
409 pWin->SetPosPixel( aPos );
413 // -----------------------------------------------------------------------
414 BOOL SfxSaveTabPage::FillItemSet( SfxItemSet& rSet )
416 BOOL bModified = FALSE;
417 SvtSaveOptions aSaveOpt;
418 if(aLoadUserSettingsCB.IsChecked() != aLoadUserSettingsCB.GetSavedValue())
420 aSaveOpt.SetLoadUserSettings(aLoadUserSettingsCB.IsChecked());
423 if ( aLoadDocPrinterCB.IsChecked() != aLoadDocPrinterCB.GetSavedValue() )
424 aSaveOpt.SetLoadDocumentPrinter( aLoadDocPrinterCB.IsChecked() );
426 if ( aODFVersionLB.GetSelectEntryPos() != aODFVersionLB.GetSavedValue() )
428 long nVersion = long( aODFVersionLB.GetEntryData( aODFVersionLB.GetSelectEntryPos() ) );
429 aSaveOpt.SetODFDefaultVersion( SvtSaveOptions::ODFDefaultVersion( nVersion ) );
432 if ( aDocInfoCB.IsChecked() != aDocInfoCB.GetSavedValue() )
434 rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_DOCINFO ),
435 aDocInfoCB.IsChecked() ) );
436 bModified |= TRUE;
439 if ( aBackupCB.IsEnabled() && aBackupCB.IsChecked() != aBackupCB.GetSavedValue() )
441 rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_BACKUP ),
442 aBackupCB.IsChecked() ) );
443 bModified |= TRUE;
446 if ( aSizeOptimizationCB.IsChecked() != aSizeOptimizationCB.GetSavedValue() )
448 rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_PRETTYPRINTING ), !aSizeOptimizationCB.IsChecked() ) );
449 bModified |= TRUE;
452 if ( aAutoSaveCB.IsChecked() != aAutoSaveCB.GetSavedValue() )
454 rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_AUTOSAVE ),
455 aAutoSaveCB.IsChecked() ) );
456 bModified |= TRUE;
458 if ( aWarnAlienFormatCB.IsChecked() != aWarnAlienFormatCB.GetSavedValue() )
460 rSet.Put( SfxBoolItem( GetWhich( SID_ATTR_WARNALIENFORMAT ),
461 aWarnAlienFormatCB.IsChecked() ) );
462 bModified |= TRUE;
465 if ( aAutoSaveEdit.GetText() != aAutoSaveEdit.GetSavedValue() )
467 rSet.Put( SfxUInt16Item( GetWhich( SID_ATTR_AUTOSAVEMINUTE ),
468 (UINT16)aAutoSaveEdit.GetValue() ) );
469 bModified |= TRUE;
471 // relativ speichern
472 if ( aRelativeFsysCB.IsChecked() != aRelativeFsysCB.GetSavedValue() )
474 rSet.Put( SfxBoolItem( GetWhich( SID_SAVEREL_FSYS ),
475 aRelativeFsysCB.IsChecked() ) );
476 bModified |= TRUE;
479 if ( aRelativeInetCB.IsChecked() != aRelativeInetCB.GetSavedValue() )
481 rSet.Put( SfxBoolItem( GetWhich( SID_SAVEREL_INET ),
482 aRelativeInetCB.IsChecked() ) );
483 bModified |= TRUE;
486 SvtModuleOptions aModuleOpt;
487 if(pImpl->aDefaultArr[APP_MATH].getLength() &&
488 pImpl->aDefaultArr[APP_MATH] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_MATH) &&
489 AcceptFilter( APP_MATH ))
490 aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_MATH, pImpl->aDefaultArr[APP_MATH]);
492 if( pImpl->aDefaultArr[APP_DRAW].getLength() &&
493 pImpl->aDefaultArr[APP_DRAW] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_DRAW) &&
494 AcceptFilter( APP_DRAW ))
495 aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_DRAW, pImpl->aDefaultArr[APP_DRAW]);
497 if(pImpl->aDefaultArr[APP_IMPRESS].getLength() &&
498 pImpl->aDefaultArr[APP_IMPRESS] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_IMPRESS)&&
499 AcceptFilter( APP_IMPRESS ))
500 aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_IMPRESS, pImpl->aDefaultArr[APP_IMPRESS]);
502 if(pImpl->aDefaultArr[APP_CALC].getLength() &&
503 pImpl->aDefaultArr[APP_CALC] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_CALC)&&
504 AcceptFilter( APP_CALC ))
505 aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_CALC, pImpl->aDefaultArr[APP_CALC]);
507 if(pImpl->aDefaultArr[APP_WRITER].getLength() &&
508 pImpl->aDefaultArr[APP_WRITER] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_WRITER)&&
509 AcceptFilter( APP_WRITER))
510 aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_WRITER, pImpl->aDefaultArr[APP_WRITER]);
512 if(pImpl->aDefaultArr[APP_WRITER_WEB].getLength() &&
513 pImpl->aDefaultArr[APP_WRITER_WEB] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_WRITERWEB)&&
514 AcceptFilter( APP_WRITER_WEB ))
515 aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_WRITERWEB, pImpl->aDefaultArr[APP_WRITER_WEB]);
517 if(pImpl->aDefaultArr[APP_WRITER_GLOBAL].getLength() &&
518 pImpl->aDefaultArr[APP_WRITER_GLOBAL] != aModuleOpt.GetFactoryDefaultFilter(SvtModuleOptions::E_WRITERGLOBAL)&&
519 AcceptFilter( APP_WRITER_GLOBAL ))
520 aModuleOpt.SetFactoryDefaultFilter(SvtModuleOptions::E_WRITERGLOBAL, pImpl->aDefaultArr[APP_WRITER_GLOBAL]);
522 return bModified;
525 // -----------------------------------------------------------------------
527 sal_Bool isODFFormat( OUString sFilter )
529 static const char* aODFFormats[] =
531 "writer8",
532 "writer8_template",
533 "writerglobal8",
534 "writerglobal8_writer",
535 "calc8",
536 "calc8_template",
537 "draw8",
538 "draw8_template",
539 "impress8",
540 "impress8_template",
541 "impress8_draw",
542 "chart8",
543 "math8",
544 NULL
547 sal_Bool bRet = sal_False;
548 int i = 0;
549 while ( aODFFormats[i] != NULL )
551 if ( sFilter.equalsAscii( aODFFormats[i++] ) )
553 bRet = sal_True;
554 break;
558 return bRet;
561 void SfxSaveTabPage::Reset( const SfxItemSet& )
563 SvtSaveOptions aSaveOpt;
564 aLoadUserSettingsCB.Check(aSaveOpt.IsLoadUserSettings());
565 aLoadUserSettingsCB.SaveValue();
566 aLoadDocPrinterCB.Check( aSaveOpt.IsLoadDocumentPrinter() );
567 aLoadDocPrinterCB.SaveValue();
569 if ( !pImpl->bInitialized )
573 Reference< XMultiServiceFactory > xMSF = comphelper::getProcessServiceFactory();
574 pImpl->xFact = Reference<XNameContainer>(
575 xMSF->createInstance(C2U("com.sun.star.document.FilterFactory")), UNO_QUERY);
577 DBG_ASSERT(pImpl->xFact.is(), "service com.sun.star.document.FilterFactory unavailable");
578 Reference< XContainerQuery > xQuery(pImpl->xFact, UNO_QUERY);
579 if(xQuery.is())
581 for(USHORT n = 0; n < aDocTypeLB.GetEntryCount(); n++)
583 long nData = (long) aDocTypeLB.GetEntryData(n);
584 OUString sCommand;
585 sCommand = C2U("matchByDocumentService=%1:iflags=");
586 sCommand += String::CreateFromInt32(SFX_FILTER_IMPORT|SFX_FILTER_EXPORT);
587 sCommand += C2U(":eflags=");
588 sCommand += String::CreateFromInt32(SFX_FILTER_NOTINFILEDLG);
589 sCommand += C2U(":default_first");
590 String sReplace;
591 switch(nData)
593 case APP_WRITER : sReplace = C2U("com.sun.star.text.TextDocument"); break;
594 case APP_WRITER_WEB : sReplace = C2U("com.sun.star.text.WebDocument"); break;
595 case APP_WRITER_GLOBAL : sReplace = C2U("com.sun.star.text.GlobalDocument"); break;
596 case APP_CALC : sReplace = C2U("com.sun.star.sheet.SpreadsheetDocument");break;
597 case APP_IMPRESS : sReplace = C2U("com.sun.star.presentation.PresentationDocument");break;
598 case APP_DRAW : sReplace = C2U("com.sun.star.drawing.DrawingDocument");break;
599 case APP_MATH : sReplace = C2U("com.sun.star.formula.FormulaProperties");break;
600 default: DBG_ERROR("illegal user data");
602 String sTmp(sCommand);
603 sTmp.SearchAndReplaceAscii("%1", sReplace);
604 sCommand = sTmp;
605 Reference< XEnumeration > xList = xQuery->createSubSetEnumerationByQuery(sCommand);
606 SequenceAsVector< OUString > lList;
607 SequenceAsVector< sal_Bool > lAlienList;
608 SequenceAsVector< sal_Bool > lODFList;
609 while(xList->hasMoreElements())
611 SequenceAsHashMap aFilter(xList->nextElement());
612 OUString sFilter = aFilter.getUnpackedValueOrDefault(OUString::createFromAscii("Name"),OUString());
613 if (sFilter.getLength())
615 sal_Int32 nFlags = aFilter.getUnpackedValueOrDefault(OUString::createFromAscii("Flags"),sal_Int32());
616 lList.push_back(sFilter);
617 lAlienList.push_back(0 != (nFlags & SFX_FILTER_ALIEN));
618 lODFList.push_back( isODFFormat( sFilter ) );
621 pImpl->aFilterArr[nData] = lList.getAsConstList();
622 pImpl->aAlienArr[nData] = lAlienList.getAsConstList();
623 pImpl->aODFArr[nData] = lODFList.getAsConstList();
626 aDocTypeLB.SelectEntryPos(0);
627 FilterHdl_Impl(&aDocTypeLB);
629 catch(Exception& )
631 DBG_ERROR("exception in FilterFactory access");
634 pImpl->bInitialized = sal_True;
637 aDocInfoCB.Check(aSaveOpt.IsDocInfoSave());
638 // aDocInfoCB.Enable(!aSaveOpt.IsReadOnly(SvtSaveOptions::E_DOCINFSAVE));
640 aBackupCB.Check(aSaveOpt.IsBackup());
641 BOOL bBackupRO = aSaveOpt.IsReadOnly(SvtSaveOptions::E_BACKUP);
642 aBackupCB.Enable(!bBackupRO);
643 aBackupFI.Show(bBackupRO);
645 aAutoSaveCB.Check(aSaveOpt.IsAutoSave());
646 aWarnAlienFormatCB.Check(aSaveOpt.IsWarnAlienFormat());
647 aWarnAlienFormatCB.Enable(!aSaveOpt.IsReadOnly(SvtSaveOptions::E_WARNALIENFORMAT));
648 // aAutoSaveCB.Enable(!aSaveOpt.IsReadOnly(SvtSaveOptions::E_AUTOSAVE));
650 // the pretty printing
651 aSizeOptimizationCB.Check( !aSaveOpt.IsPrettyPrinting());
652 // aSizeOptimizationCB.Enable(!aSaveOpt.IsReadOnly(SvtSaveOptions::E_DOPRETTYPRINTING ));
655 aAutoSaveEdit.SetValue( aSaveOpt.GetAutoSaveTime() );
656 // aAutoSaveEdit.Enable(!aSaveOpt.IsReadOnly(SvtSaveOptions::E_AUTOSAVETIME));
658 // relativ speichern
659 aRelativeFsysCB.Check( aSaveOpt.IsSaveRelFSys() );
660 // aRelativeFsysCB.Enable(!aSaveOpt.IsReadOnly(SvtSaveOptions::E_SAVERELFSYS));
662 aRelativeInetCB.Check( aSaveOpt.IsSaveRelINet() );
663 // aRelativeInetCB.Enable(!aSaveOpt.IsReadOnly(SvtSaveOptions::E_SAVERELINET));
665 void* pDefaultVersion = (void*)long( aSaveOpt.GetODFDefaultVersion() );
666 aODFVersionLB.SelectEntryPos( aODFVersionLB.GetEntryPos( pDefaultVersion ) );
668 AutoClickHdl_Impl( &aAutoSaveCB );
669 ODFVersionHdl_Impl( &aODFVersionLB );
671 aDocInfoCB.SaveValue();
672 aBackupCB.SaveValue();
673 aWarnAlienFormatCB.SaveValue();
674 aSizeOptimizationCB.SaveValue();
675 aAutoSaveCB.SaveValue();
676 aAutoSaveEdit.SaveValue();
677 // aAutoSavePromptBtn.SaveValue();
679 aRelativeFsysCB.SaveValue();
680 aRelativeInetCB.SaveValue();
681 aODFVersionLB.SaveValue();
684 // -----------------------------------------------------------------------
686 IMPL_LINK( SfxSaveTabPage, AutoClickHdl_Impl, CheckBox *, pBox )
688 if ( pBox == &aAutoSaveCB )
690 if ( aAutoSaveCB.IsChecked() )
692 aAutoSaveEdit.Enable();
693 aMinuteFT.Enable();
694 // aAutoSavePromptBtn.Enable();
695 aAutoSaveEdit.GrabFocus();
697 else
699 aAutoSaveEdit.Disable();
700 aMinuteFT.Disable();
701 // aAutoSavePromptBtn.Disable();
704 return 0;
706 /* -----------------------------05.04.01 13:10--------------------------------
708 ---------------------------------------------------------------------------*/
709 OUString lcl_ExtracUIName(const Sequence<PropertyValue> rProperties)
711 OUString sRet;
712 sal_Int32 nFlags;
713 const PropertyValue* pProperties = rProperties.getConstArray();
714 for(int nProp = 0; nProp < rProperties.getLength(); nProp++)
716 if(!pProperties[nProp].Name.compareToAscii("UIName"))
718 pProperties[nProp].Value >>= sRet;
719 //! break;
721 else if(!pProperties[nProp].Name.compareToAscii("Flags"))
723 if ( pProperties[nProp].Value >>= nFlags )
725 nFlags &= 0x100;
728 else if(!pProperties[nProp].Name.compareToAscii("Name"))
730 pProperties[nProp].Value >>= sRet;
733 return sRet;
735 /* -----------------------------05.04.01 13:37--------------------------------
737 ---------------------------------------------------------------------------*/
738 IMPL_LINK( SfxSaveTabPage, FilterHdl_Impl, ListBox *, pBox )
740 USHORT nCurPos = aDocTypeLB.GetSelectEntryPos();
742 long nData = -1;
743 if(nCurPos < APP_COUNT)
744 nData = (long) aDocTypeLB.GetEntryData(nCurPos);
746 if ( nData >= 0 && nData < APP_COUNT )
748 if(&aDocTypeLB == pBox)
750 aSaveAsLB.Clear();
751 const OUString* pFilters = pImpl->aFilterArr[nData].getConstArray();
752 if(!pImpl->aUIFilterArr[nData].getLength())
754 pImpl->aUIFilterArr[nData].realloc(pImpl->aFilterArr[nData].getLength());
755 OUString* pUIFilters = pImpl->aUIFilterArr[nData].getArray();
756 for(int nFilter = 0; nFilter < pImpl->aFilterArr[nData].getLength(); nFilter++)
758 Any aProps = pImpl->xFact->getByName(pFilters[nFilter]);
759 Sequence<PropertyValue> aProperties;
760 aProps >>= aProperties;
761 pUIFilters[nFilter] = lcl_ExtracUIName(aProperties);
764 const OUString* pUIFilters = pImpl->aUIFilterArr[nData].getConstArray();
765 OUString sSelect;
766 for(int i = 0; i < pImpl->aUIFilterArr[nData].getLength(); i++)
768 USHORT nEntryPos = aSaveAsLB.InsertEntry(pUIFilters[i]);
769 if ( pImpl->aODFArr[nData][i] )
770 aSaveAsLB.SetEntryData( nEntryPos, (void*)pImpl );
771 if(pFilters[i] == pImpl->aDefaultArr[nData])
772 sSelect = pUIFilters[i];
774 if(sSelect.getLength())
775 aSaveAsLB.SelectEntry(sSelect);
776 aSaveAsFI.Show(pImpl->aDefaultReadonlyArr[nData]);
777 aSaveAsFT.Enable(!pImpl->aDefaultReadonlyArr[nData]);
778 aSaveAsLB.Enable(!pImpl->aDefaultReadonlyArr[nData]);
780 else
782 OUString sSelect = pBox->GetSelectEntry();
783 const OUString* pFilters = pImpl->aFilterArr[nData].getConstArray();
784 OUString* pUIFilters = pImpl->aUIFilterArr[nData].getArray();
785 for(int i = 0; i < pImpl->aUIFilterArr[nData].getLength(); i++)
786 if(pUIFilters[i] == sSelect)
788 sSelect = pFilters[i];
789 break;
792 pImpl->aDefaultArr[nData] = sSelect;
796 ODFVersionHdl_Impl( &aSaveAsLB );
797 return 0;
800 IMPL_LINK( SfxSaveTabPage, ODFVersionHdl_Impl, ListBox *, EMPTYARG )
802 long nVersion = long( aODFVersionLB.GetEntryData( aODFVersionLB.GetSelectEntryPos() ) );
803 bool bShown = SvtSaveOptions::ODFDefaultVersion( nVersion ) != SvtSaveOptions::ODFVER_LATEST;
804 if ( bShown )
806 bool bHasODFFormat = false;
807 USHORT i = 0, nCount = aSaveAsLB.GetEntryCount();
808 for ( ; i < nCount; ++ i )
810 if ( aSaveAsLB.GetEntryData(i) != NULL )
812 bHasODFFormat = true;
813 break;
817 bShown = !bHasODFFormat
818 || ( aSaveAsLB.GetEntryData( aSaveAsLB.GetSelectEntryPos() ) != NULL );
821 aODFWarningFI.Show( bShown );
822 aODFWarningFT.Show( bShown );
824 return 0;