merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / config / moduleoptions.cxx
blob8097f2eedbbcfbbd7e1711c913007d48df7b2d41
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: moduleoptions.cxx,v $
10 * $Revision: 1.36 $
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"
33 #ifndef GCC
34 #endif
36 //_________________________________________________________________________________________________________________
37 // includes
38 //_________________________________________________________________________________________________________________
40 #include <svtools/moduleoptions.hxx>
41 #include <comphelper/sequenceashashmap.hxx>
42 #include <unotools/configmgr.hxx>
43 #include <unotools/configitem.hxx>
44 #include <unotools/processfactory.hxx>
45 #include <osl/diagnose.h>
46 #include <rtl/ustrbuf.hxx>
48 #include <rtl/logfile.hxx>
49 #include <com/sun/star/uno/Any.hxx>
50 #include <com/sun/star/uno/Sequence.hxx>
51 #include <com/sun/star/beans/PropertyValue.hpp>
52 #include <com/sun/star/container/XNameAccess.hpp>
53 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
54 #include <com/sun/star/lang/XServiceInfo.hpp>
55 #include <com/sun/star/document/XTypeDetection.hpp>
56 #include <com/sun/star/util/XStringSubstitution.hpp>
58 #include "itemholder1.hxx"
60 //_________________________________________________________________________________________________________________
61 // namespaces
62 //_________________________________________________________________________________________________________________
64 #ifndef css
65 namespace css = ::com::sun::star;
66 #endif
68 //_________________________________________________________________________________________________________________
69 // const
70 //_________________________________________________________________________________________________________________
72 /*-************************************************************************************************************//**
73 @descr These values are used to define neccessary keys from our configuration management to support
74 all functionality of these implementation.
75 It's a fast way to make changes if some keys change his name or location!
77 Property handle are neccessary to specify right position in return list of configuration
78 for asked values. We ask it with a list of properties to get his values. The returned list
79 has the same order like our given name list!
80 e.g.:
81 NAMELIST[ PROPERTYHANDLE_xxx ] => VALUELIST[ PROPERTYHANDLE_xxx ]
82 *//*-*************************************************************************************************************/
83 #define ROOTNODE_FACTORIES ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Setup/Office/Factories" ))
84 #define PATHSEPERATOR ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/" ))
86 // Attention: The property "ooSetupFactoryEmptyDocumentURL" is read from configuration but not used! There is
87 // special code that uses hard coded strings to return them.
88 #define PROPERTYNAME_SHORTNAME ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupFactoryShortName" ))
89 #define PROPERTYNAME_TEMPLATEFILE ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupFactoryTemplateFile" ))
90 #define PROPERTYNAME_WINDOWATTRIBUTES ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupFactoryWindowAttributes"))
91 #define PROPERTYNAME_EMPTYDOCUMENTURL ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupFactoryEmptyDocumentURL"))
92 #define PROPERTYNAME_DEFAULTFILTER ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupFactoryDefaultFilter" ))
93 #define PROPERTYNAME_ICON ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupFactoryIcon" ))
95 #define PROPERTYHANDLE_SHORTNAME 0
96 #define PROPERTYHANDLE_TEMPLATEFILE 1
97 #define PROPERTYHANDLE_WINDOWATTRIBUTES 2
98 #define PROPERTYHANDLE_EMPTYDOCUMENTURL 3
99 #define PROPERTYHANDLE_DEFAULTFILTER 4
100 #define PROPERTYHANDLE_ICON 5
102 #define PROPERTYCOUNT 6
104 #define FACTORYNAME_WRITER ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextDocument" ))
105 #define FACTORYNAME_WRITERWEB ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.WebDocument" ))
106 #define FACTORYNAME_WRITERGLOBAL ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.GlobalDocument" ))
107 #define FACTORYNAME_CALC ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadsheetDocument" ))
108 #define FACTORYNAME_DRAW ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.DrawingDocument" ))
109 #define FACTORYNAME_IMPRESS ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.PresentationDocument"))
110 #define FACTORYNAME_MATH ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.formula.FormulaProperties" ))
111 #define FACTORYNAME_CHART ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart2.ChartDocument" ))
112 #define FACTORYNAME_DATABASE ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.OfficeDatabaseDocument" ))
113 #define FACTORYNAME_STARTMODULE ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.StartModule" ))
115 #define FACTORYCOUNT 10
117 /*-************************************************************************************************************//**
118 @descr This struct hold information about one factory. We declare a complete array which can hold infos
119 for all well known factories. Values of enum "EFactory" (see header!) are directly used as index!
120 So we can support a fast access on these informations.
121 *//*-*************************************************************************************************************/
122 struct FactoryInfo
124 public:
125 //---------------------------------------------------------------------------------------------------------
126 // initialize empty struct
127 FactoryInfo()
129 free();
130 // @@@ should be supplied from outside!
131 xSMgr = ::utl::getProcessServiceFactory();
134 //---------------------------------------------------------------------------------------------------------
135 // easy way to reset struct member!
136 void free()
138 bInstalled = sal_False ;
139 sFactory = ::rtl::OUString() ;
140 sShortName = ::rtl::OUString() ;
141 sTemplateFile = ::rtl::OUString() ;
142 sWindowAttributes = ::rtl::OUString() ;
143 sEmptyDocumentURL = ::rtl::OUString() ;
144 sDefaultFilter = ::rtl::OUString() ;
145 nIcon = 0 ;
146 bChangedTemplateFile = sal_False ;
147 bChangedWindowAttributes = sal_False ;
148 bChangedEmptyDocumentURL = sal_False ;
149 bChangedDefaultFilter = sal_False ;
150 bChangedIcon = sal_False ;
151 bDefaultFilterReadonly = sal_False ;
154 //---------------------------------------------------------------------------------------------------------
155 // returns list of properties, which has changed only!
156 // We use given value of sNodeBase to build full qualified pathes ...
157 // Last sign of it must be "/". Beacuse we use it directly, without any additional things!
158 css::uno::Sequence< css::beans::PropertyValue > getChangedProperties( const ::rtl::OUString& sNodeBase )
160 // a) reserve memory for max. count of changed properties
161 // b) add names and values of changed ones only and count it
162 // c) resize return list by using count
163 css::uno::Sequence< css::beans::PropertyValue > lProperties ( 4 );
164 sal_Int8 nRealyChanged = 0 ;
166 if( bChangedTemplateFile == sal_True )
168 lProperties[nRealyChanged].Name = sNodeBase + PROPERTYNAME_TEMPLATEFILE;
170 if ( sTemplateFile.getLength() > 0 )
172 lProperties[nRealyChanged].Value
173 <<= getStringSubstitution()
174 ->reSubstituteVariables( sTemplateFile );
176 else
178 lProperties[nRealyChanged].Value <<= sTemplateFile;
181 ++nRealyChanged;
183 if( bChangedWindowAttributes == sal_True )
185 lProperties[nRealyChanged].Name = sNodeBase + PROPERTYNAME_WINDOWATTRIBUTES;
186 lProperties[nRealyChanged].Value <<= sWindowAttributes;
187 ++nRealyChanged;
189 if( bChangedEmptyDocumentURL == sal_True )
191 lProperties[nRealyChanged].Name = sNodeBase + PROPERTYNAME_EMPTYDOCUMENTURL;
192 lProperties[nRealyChanged].Value <<= sEmptyDocumentURL;
193 ++nRealyChanged;
195 if( bChangedDefaultFilter == sal_True )
197 lProperties[nRealyChanged].Name = sNodeBase + PROPERTYNAME_DEFAULTFILTER;
198 lProperties[nRealyChanged].Value <<= sDefaultFilter;
199 ++nRealyChanged;
201 if( bChangedIcon == sal_True )
203 lProperties[nRealyChanged].Name = sNodeBase + PROPERTYNAME_ICON;
204 lProperties[nRealyChanged].Value <<= nIcon;
205 ++nRealyChanged;
208 // Don't forget to reset changed flags! Otherwise we save it again and again and ...
209 bChangedTemplateFile = sal_False ;
210 bChangedWindowAttributes = sal_False ;
211 bChangedEmptyDocumentURL = sal_False ;
212 bChangedDefaultFilter = sal_False ;
213 bChangedIcon = sal_False ;
215 lProperties.realloc( nRealyChanged );
216 return lProperties;
219 //---------------------------------------------------------------------------------------------------------
220 // We must support setting AND marking of changed values.
221 // That's why we can't make our member public. We must use get/set/init methods
222 // to control access on it!
223 sal_Bool getInstalled () const { return bInstalled; };
224 ::rtl::OUString getFactory () const { return sFactory; };
225 ::rtl::OUString getShortName () const { return sShortName; };
226 ::rtl::OUString getTemplateFile () const { return sTemplateFile; };
227 ::rtl::OUString getWindowAttributes () const { return sWindowAttributes; };
228 ::rtl::OUString getEmptyDocumentURL () const { return sEmptyDocumentURL; };
229 ::rtl::OUString getDefaultFilter () const { return sDefaultFilter; };
230 sal_Bool isDefaultFilterReadonly() const { return bDefaultFilterReadonly; }
231 sal_Int32 getIcon () const { return nIcon; };
233 //---------------------------------------------------------------------------------------------------------
234 // If you call set-methods - we check for changes of valkues and mark it.
235 // But if you whish to set it without that ... you must initialize it!
236 void initInstalled ( sal_Bool bNewInstalled ) { bInstalled = bNewInstalled ; }
237 void initFactory ( const ::rtl::OUString& sNewFactory ) { sFactory = sNewFactory ; }
238 void initShortName ( const ::rtl::OUString& sNewShortName ) { sShortName = sNewShortName ; }
239 void initWindowAttributes ( const ::rtl::OUString& sNewWindowAttributes ) { sWindowAttributes = sNewWindowAttributes ; }
240 void initEmptyDocumentURL ( const ::rtl::OUString& sNewEmptyDocumentURL ) { sEmptyDocumentURL = sNewEmptyDocumentURL ; }
241 void initDefaultFilter ( const ::rtl::OUString& sNewDefaultFilter ) { sDefaultFilter = sNewDefaultFilter ; }
242 void setDefaultFilterReadonly( const sal_Bool bVal){bDefaultFilterReadonly = bVal;}
243 void initIcon ( sal_Int32 nNewIcon ) { nIcon = nNewIcon ; }
245 //---------------------------------------------------------------------------------------------------------
246 void initTemplateFile( const ::rtl::OUString& sNewTemplateFile )
248 if ( sNewTemplateFile.getLength() > 0 )
250 sTemplateFile
251 = getStringSubstitution()
252 ->substituteVariables( sNewTemplateFile, sal_False );
254 else
256 sTemplateFile = sNewTemplateFile;
260 //---------------------------------------------------------------------------------------------------------
261 void setInstalled( sal_Bool bNewInstalled )
263 bInstalled = bNewInstalled;
266 //---------------------------------------------------------------------------------------------------------
267 void setFactory( const ::rtl::OUString& sNewFactory )
269 sFactory = sNewFactory;
272 //---------------------------------------------------------------------------------------------------------
273 void setShortName( const ::rtl::OUString& sNewShortName )
275 sShortName = sNewShortName;
278 //---------------------------------------------------------------------------------------------------------
279 void setTemplateFile( const ::rtl::OUString& sNewTemplateFile )
281 if( sTemplateFile != sNewTemplateFile )
283 sTemplateFile = sNewTemplateFile;
284 bChangedTemplateFile = sal_True ;
288 //---------------------------------------------------------------------------------------------------------
289 void setWindowAttributes( const ::rtl::OUString& sNewWindowAttributes )
291 if( sWindowAttributes != sNewWindowAttributes )
293 sWindowAttributes = sNewWindowAttributes;
294 bChangedWindowAttributes = sal_True ;
298 //---------------------------------------------------------------------------------------------------------
299 void setEmptyDocumentURL( const ::rtl::OUString& sNewEmptyDocumentURL )
301 if( sEmptyDocumentURL != sNewEmptyDocumentURL )
303 sEmptyDocumentURL = sNewEmptyDocumentURL;
304 bChangedEmptyDocumentURL = sal_True ;
308 //---------------------------------------------------------------------------------------------------------
309 void setDefaultFilter( const ::rtl::OUString& sNewDefaultFilter )
311 if( sDefaultFilter != sNewDefaultFilter )
313 sDefaultFilter = sNewDefaultFilter;
314 bChangedDefaultFilter = sal_True ;
318 //---------------------------------------------------------------------------------------------------------
319 void setIcon( sal_Int32 nNewIcon )
321 if( nNewIcon != nNewIcon )
323 nNewIcon = nNewIcon;
324 bChangedIcon = sal_True;
328 private:
329 css::uno::Reference< css::util::XStringSubstitution > getStringSubstitution()
331 if ( !xSubstVars.is() )
333 xSubstVars
334 = css::uno::Reference< css::util::XStringSubstitution >(
335 xSMgr->createInstance(
336 ::rtl::OUString(
337 RTL_CONSTASCII_USTRINGPARAM(
338 "com.sun.star.util.PathSubstitution" ) ) ),
339 css::uno::UNO_QUERY );
340 if ( !xSubstVars.is() )
341 throw css::uno::RuntimeException(
342 ::rtl::OUString(
343 RTL_CONSTASCII_USTRINGPARAM(
344 "Cannot instanciate service "
345 "com.sun.star.util.PathSubstitution" ) ),
346 css::uno::Reference< css::uno::XInterface >() );
348 return xSubstVars;
351 sal_Bool bInstalled ;
352 ::rtl::OUString sFactory ;
353 ::rtl::OUString sShortName ;
354 ::rtl::OUString sTemplateFile ;
355 ::rtl::OUString sWindowAttributes ;
356 ::rtl::OUString sEmptyDocumentURL ;
357 ::rtl::OUString sDefaultFilter ;
358 sal_Int32 nIcon ;
360 sal_Bool bChangedTemplateFile :1 ;
361 sal_Bool bChangedWindowAttributes :1 ;
362 sal_Bool bChangedEmptyDocumentURL :1 ;
363 sal_Bool bChangedDefaultFilter :1 ;
364 sal_Bool bChangedIcon :1 ;
365 sal_Bool bDefaultFilterReadonly :1 ;
367 css::uno::Reference< css::lang::XMultiServiceFactory > xSMgr;
368 css::uno::Reference< css::util::XStringSubstitution > xSubstVars;
371 typedef FactoryInfo FactoryInfoList[FACTORYCOUNT];
373 /*-************************************************************************************************************//**
374 @short IMPL data container for wrapper class SvtModulOptions!
375 @descr These class is used as a static data container of class SvtModuleOptions. The hold it by using
376 a refcount and make it threadsafe by using an osl mutex. So we don't must do anything for that.
377 We can implement pure functionality to read/write configuration data only.
379 @implements -
380 @base ConfigItem
382 @devstatus ready to use
383 @threadsafe no
384 *//*-*************************************************************************************************************/
385 class SvtModuleOptions_Impl : public ::utl::ConfigItem
387 //-------------------------------------------------------------------------------------------------------------
388 // public methods
389 //-------------------------------------------------------------------------------------------------------------
390 public:
391 //---------------------------------------------------------------------------------------------------------
392 // constructor / destructor
393 //---------------------------------------------------------------------------------------------------------
394 SvtModuleOptions_Impl(SvtModuleOptions* pOutsideClass);
395 ~SvtModuleOptions_Impl();
397 //---------------------------------------------------------------------------------------------------------
398 // overloaded methods of baseclass
399 //---------------------------------------------------------------------------------------------------------
400 virtual void Notify( const css::uno::Sequence< ::rtl::OUString >& lPropertyNames );
401 virtual void Commit( );
403 //---------------------------------------------------------------------------------------------------------
404 // public interface
405 //---------------------------------------------------------------------------------------------------------
406 sal_Bool IsModuleInstalled ( SvtModuleOptions::EModule eModule ) const;
407 ::com::sun::star::uno::Sequence < ::rtl::OUString > GetAllServiceNames();
408 ::rtl::OUString GetFactoryName ( SvtModuleOptions::EFactory eFactory ) const;
409 ::rtl::OUString GetFactoryShortName ( SvtModuleOptions::EFactory eFactory ) const;
410 ::rtl::OUString GetFactoryStandardTemplate( SvtModuleOptions::EFactory eFactory ) const;
411 ::rtl::OUString GetFactoryWindowAttributes( SvtModuleOptions::EFactory eFactory ) const;
412 ::rtl::OUString GetFactoryEmptyDocumentURL( SvtModuleOptions::EFactory eFactory ) const;
413 ::rtl::OUString GetFactoryDefaultFilter ( SvtModuleOptions::EFactory eFactory ) const;
414 sal_Bool IsDefaultFilterReadonly( SvtModuleOptions::EFactory eFactory ) const;
415 sal_Int32 GetFactoryIcon ( SvtModuleOptions::EFactory eFactory ) const;
416 static sal_Bool ClassifyFactoryByName ( const ::rtl::OUString& sName ,
417 SvtModuleOptions::EFactory& eFactory );
418 void SetFactoryStandardTemplate( SvtModuleOptions::EFactory eFactory ,
419 const ::rtl::OUString& sTemplate );
420 void SetFactoryWindowAttributes( SvtModuleOptions::EFactory eFactory ,
421 const ::rtl::OUString& sAttributes);
422 void SetFactoryDefaultFilter ( SvtModuleOptions::EFactory eFactory ,
423 const ::rtl::OUString& sFilter );
424 void MakeReadonlyStatesAvailable();
426 //-------------------------------------------------------------------------------------------------------------
427 // private methods
428 //-------------------------------------------------------------------------------------------------------------
429 private:
430 static css::uno::Sequence< ::rtl::OUString > impl_ExpandSetNames ( const css::uno::Sequence< ::rtl::OUString >& lSetNames );
431 void impl_Read ( const css::uno::Sequence< ::rtl::OUString >& lSetNames );
433 //-------------------------------------------------------------------------------------------------------------
434 // private types
435 //-------------------------------------------------------------------------------------------------------------
436 private:
438 //-------------------------------------------------------------------------------------------------------------
439 // private member
440 //-------------------------------------------------------------------------------------------------------------
441 private:
442 FactoryInfoList m_lFactories;
443 sal_Bool m_bReadOnlyStatesWellKnown;
444 SvtModuleOptions* m_pOutsideClass;
447 //_________________________________________________________________________________________________________________
448 // definitions
449 //_________________________________________________________________________________________________________________
451 /*-************************************************************************************************************//**
452 @short default ctor
453 @descr We open our configuration here and read all neccessary values from it.
454 These values are cached till everyone call Commit(). Then we write changed ones back to cfg.
456 @seealso baseclass ConfigItem
457 @seealso method impl_Read()
459 @param -
460 @return -
462 @onerror -
463 @threadsafe no
464 *//*-*************************************************************************************************************/
465 SvtModuleOptions_Impl::SvtModuleOptions_Impl(SvtModuleOptions* pOutsideClass)
466 : ::utl::ConfigItem( ROOTNODE_FACTORIES )
467 , m_bReadOnlyStatesWellKnown( sal_False )
468 , m_pOutsideClass( pOutsideClass )
470 // First initialize list of factory infos! Otherwise we couldnt gurantee right working of these class.
471 for( sal_Int32 nFactory=0; nFactory<FACTORYCOUNT; ++nFactory )
472 m_lFactories[nFactory].free();
474 // Get name list of all existing set node names in configuration to read her properties in impl_Read().
475 // These list is a list of long names of our factories.
476 const css::uno::Sequence< ::rtl::OUString > lFactories = GetNodeNames( ::rtl::OUString() );
477 impl_Read( lFactories );
479 // Enable notification for changes by using configuration directly.
480 // So we can update our internal values immediatly.
481 EnableNotification( lFactories );
484 /*-************************************************************************************************************//**
485 @short default dtor
486 @descr If any values of our cache was modified we should write it back to configuration.
488 @attention Don't forget to call "SetModified()" method of base class ConfigItem if any interface method
489 of this class modify internal member list m_lFactories! Otherwise Commit() will never be called!!!
491 @seealso baseclass ConfigItem
493 @param -
494 @return -
496 @onerror -
497 @threadsafe no
498 *//*-*************************************************************************************************************/
499 SvtModuleOptions_Impl::~SvtModuleOptions_Impl()
501 if( IsModified() == sal_True )
503 Commit();
507 /*-************************************************************************************************************//**
508 @short called for notify of configmanager
509 @descr These method is called from the ConfigManager before application ends or from the
510 PropertyChangeListener if the sub tree broadcasts changes. You must update our
511 internal values.
513 @attention We are registered for pure set node names only. So we can use our internal method "impl_Read()" to
514 update our info list. Because - these method expand given name list to full qualified property list
515 and use it to read the values. These values are filled into our internal member list m_lFactories
516 at right position.
518 @seealso method impl_Read()
520 @param "lNames" is the list of set node entries which should be updated.
521 @return -
523 @onerror -
524 @threadsafe no
525 *//*-*************************************************************************************************************/
526 void SvtModuleOptions_Impl::Notify( const css::uno::Sequence< ::rtl::OUString >& )
528 OSL_ENSURE( sal_False, "SvtModuleOptions_Impl::Notify()\nNot implemented yet!\n" );
531 /*-****************************************************************************************************//**
532 @short write changes to configuration
533 @descr These method writes the changed values into the sub tree
534 and should always called in our destructor to guarantee consistency of config data.
536 @attention We clear complete set in configuration first and write it completly new! So we don't must
537 distinguish between existing, added or removed elements. Our internal cached values
538 are the only and right ones.
540 @seealso baseclass ConfigItem
542 @param -
543 @return -
545 @onerror -
546 @threadsafe no
547 *//*-*****************************************************************************************************/
548 void SvtModuleOptions_Impl::Commit()
550 // Reserve memory for ALL possible factory properties!
551 // Step over all factories and get her realy changed values only.
552 // Build list of these ones and use it for commit.
553 css::uno::Sequence< css::beans::PropertyValue > lCommitProperties( FACTORYCOUNT*PROPERTYCOUNT );
554 FactoryInfo* pInfo = NULL ;
555 sal_Int32 nRealCount = 0 ;
556 ::rtl::OUString sBasePath ;
557 for( sal_Int32 nFactory=0; nFactory<FACTORYCOUNT; ++nFactory )
559 pInfo = &(m_lFactories[nFactory]);
561 // These path is used to build full qualified property names ....
562 // See pInfo->getChangedProperties() for further informations
563 sBasePath = PATHSEPERATOR + pInfo->getFactory() + PATHSEPERATOR;
565 const css::uno::Sequence< css::beans::PropertyValue > lChangedProperties = pInfo->getChangedProperties ( sBasePath );
566 const css::beans::PropertyValue* pChangedProperties = lChangedProperties.getConstArray();
567 sal_Int32 nPropertyCount = lChangedProperties.getLength();
568 for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty )
570 lCommitProperties[nRealCount] = pChangedProperties[nProperty];
571 ++nRealCount;
574 // Resize commit list to real size.
575 // If nothing to do - suppress calling of configuration ...
576 // It could be to expensive :-)
577 if( nRealCount > 0 )
579 lCommitProperties.realloc( nRealCount );
580 SetSetProperties( ::rtl::OUString(), lCommitProperties );
584 /*-****************************************************************************************************//**
585 @short access method to get internal values
586 @descr These methods implement easy access to our internal values.
587 You give us right enum value to specify which module interest you ... we return right information.
589 @attention Some poeple use any value as enum ... but we support in header specified values only!
590 We use it directly as index in our internal list. If enum value isn't right - we crash with an
591 "index out of range"!!! Please use me right - otherwise there is no guarantee.
593 @seealso -
595 @param "eModule" , index in list - specify module
596 @param "eFactory" , index in list - specify factory
597 @param "sTemplate", set new standard template for these factory
598 @return Queried information.
600 @onerror We return default values. (mostly "not installed"!)
601 @threadsafe no
602 *//*-*****************************************************************************************************/
603 sal_Bool SvtModuleOptions_Impl::IsModuleInstalled( SvtModuleOptions::EModule eModule ) const
605 sal_Bool bInstalled = sal_False;
606 switch( eModule )
608 case SvtModuleOptions::E_SWRITER : bInstalled = m_lFactories[SvtModuleOptions::E_WRITER].getInstalled();
609 break;
610 case SvtModuleOptions::E_SWEB : bInstalled = m_lFactories[SvtModuleOptions::E_WRITERWEB].getInstalled();
611 break;
612 case SvtModuleOptions::E_SGLOBAL : bInstalled = m_lFactories[SvtModuleOptions::E_WRITERGLOBAL].getInstalled();
613 break;
614 case SvtModuleOptions::E_SCALC : bInstalled = m_lFactories[SvtModuleOptions::E_CALC].getInstalled();
615 break;
616 case SvtModuleOptions::E_SDRAW : bInstalled = m_lFactories[SvtModuleOptions::E_DRAW].getInstalled();
617 break;
618 case SvtModuleOptions::E_SIMPRESS : bInstalled = m_lFactories[SvtModuleOptions::E_IMPRESS].getInstalled();
619 break;
620 case SvtModuleOptions::E_SMATH : bInstalled = m_lFactories[SvtModuleOptions::E_MATH].getInstalled();
621 break;
622 case SvtModuleOptions::E_SCHART : bInstalled = m_lFactories[SvtModuleOptions::E_CHART].getInstalled();
623 break;
624 case SvtModuleOptions::E_SSTARTMODULE : bInstalled = m_lFactories[SvtModuleOptions::E_STARTMODULE].getInstalled();
625 break;
626 case SvtModuleOptions::E_SBASIC : bInstalled = sal_True; // Couldn't be deselected by setup yet!
627 break;
628 case SvtModuleOptions::E_SDATABASE : bInstalled = m_lFactories[SvtModuleOptions::E_DATABASE].getInstalled();
629 break;
632 return bInstalled;
635 ::com::sun::star::uno::Sequence < ::rtl::OUString > SvtModuleOptions_Impl::GetAllServiceNames()
637 sal_uInt32 nCount=0;
638 if( m_lFactories[SvtModuleOptions::E_WRITER].getInstalled() )
639 nCount++;
640 if ( m_lFactories[SvtModuleOptions::E_WRITERWEB].getInstalled() )
641 nCount++;
642 if ( m_lFactories[SvtModuleOptions::E_WRITERGLOBAL].getInstalled() )
643 nCount++;
644 if( m_lFactories[SvtModuleOptions::E_SCALC].getInstalled() )
645 nCount++;
646 if( m_lFactories[SvtModuleOptions::E_SDRAW].getInstalled() )
647 nCount++;
648 if( m_lFactories[SvtModuleOptions::E_SIMPRESS].getInstalled() )
649 nCount++;
650 if( m_lFactories[SvtModuleOptions::E_SCHART].getInstalled() )
651 nCount++;
652 if( m_lFactories[SvtModuleOptions::E_SMATH].getInstalled() )
653 nCount++;
654 if( m_lFactories[SvtModuleOptions::E_SBASIC].getInstalled() )
655 nCount++;
656 if( m_lFactories[SvtModuleOptions::E_SDATABASE].getInstalled() )
657 nCount++;
659 css::uno::Sequence < ::rtl::OUString > aRet( nCount );
660 sal_Int32 n=0;
661 if( m_lFactories[SvtModuleOptions::E_WRITER].getInstalled() )
662 aRet[n++] = m_lFactories[SvtModuleOptions::E_WRITER].getFactory();
663 if ( m_lFactories[SvtModuleOptions::E_WRITERWEB].getInstalled() )
664 aRet[n++] = m_lFactories[SvtModuleOptions::E_WRITERWEB].getFactory();
665 if ( m_lFactories[SvtModuleOptions::E_WRITERGLOBAL].getInstalled() )
666 aRet[n++] = m_lFactories[SvtModuleOptions::E_WRITERGLOBAL].getFactory();
667 if( m_lFactories[SvtModuleOptions::E_SCALC].getInstalled() )
668 aRet[n++] = m_lFactories[SvtModuleOptions::E_SCALC].getFactory();
669 if( m_lFactories[SvtModuleOptions::E_SDRAW].getInstalled() )
670 aRet[n++] = m_lFactories[SvtModuleOptions::E_SDRAW].getFactory();
671 if( m_lFactories[SvtModuleOptions::E_SIMPRESS].getInstalled() )
672 aRet[n++] = m_lFactories[SvtModuleOptions::E_SIMPRESS].getFactory();
673 if( m_lFactories[SvtModuleOptions::E_SCHART].getInstalled() )
674 aRet[n++] = m_lFactories[SvtModuleOptions::E_SCHART].getFactory();
675 if( m_lFactories[SvtModuleOptions::E_SMATH].getInstalled() )
676 aRet[n++] = m_lFactories[SvtModuleOptions::E_SMATH].getFactory();
677 if( m_lFactories[SvtModuleOptions::E_SBASIC].getInstalled() )
678 aRet[n++] = m_lFactories[SvtModuleOptions::E_SBASIC].getFactory();
679 if( m_lFactories[SvtModuleOptions::E_SDATABASE].getInstalled() )
680 aRet[n++] = m_lFactories[SvtModuleOptions::E_SDATABASE].getFactory();
682 return aRet;
685 //*****************************************************************************************************************
686 ::rtl::OUString SvtModuleOptions_Impl::GetFactoryName( SvtModuleOptions::EFactory eFactory ) const
688 ::rtl::OUString sName;
690 if( eFactory>=0 && eFactory<FACTORYCOUNT )
692 sName = m_lFactories[eFactory].getFactory();
695 return sName;
698 //*****************************************************************************************************************
699 ::rtl::OUString SvtModuleOptions_Impl::GetFactoryShortName( SvtModuleOptions::EFactory eFactory ) const
701 // Attention: Hard configured yet ... because it's not fine to make changes possible by xml file yet.
702 // But it's good to plan further possibilities!
704 //return m_lFactories[eFactory].sShortName;
706 ::rtl::OUString sShortName;
707 switch( eFactory )
709 case SvtModuleOptions::E_WRITER : sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("swriter"));
710 break;
711 case SvtModuleOptions::E_WRITERWEB : sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("swriter/web"));
712 break;
713 case SvtModuleOptions::E_WRITERGLOBAL : sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("swriter/GlobalDocument"));
714 break;
715 case SvtModuleOptions::E_CALC : sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("scalc"));
716 break;
717 case SvtModuleOptions::E_DRAW : sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdraw"));
718 break;
719 case SvtModuleOptions::E_IMPRESS : sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("simpress"));
720 break;
721 case SvtModuleOptions::E_MATH : sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("smath"));
722 break;
723 case SvtModuleOptions::E_CHART : sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("schart"));
724 break;
725 case SvtModuleOptions::E_BASIC : sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sbasic"));
726 break;
727 case SvtModuleOptions::E_DATABASE : sShortName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdatabase"));
728 break;
729 default:
730 OSL_ASSERT( "unknown factory" );
731 break;
734 return sShortName;
737 //*****************************************************************************************************************
738 ::rtl::OUString SvtModuleOptions_Impl::GetFactoryStandardTemplate( SvtModuleOptions::EFactory eFactory ) const
740 ::rtl::OUString sFile;
742 if( eFactory>=0 && eFactory<FACTORYCOUNT )
744 sFile = m_lFactories[eFactory].getTemplateFile();
747 return sFile;
750 //*****************************************************************************************************************
751 ::rtl::OUString SvtModuleOptions_Impl::GetFactoryWindowAttributes( SvtModuleOptions::EFactory eFactory ) const
753 ::rtl::OUString sAttributes;
755 if( eFactory>=0 && eFactory<FACTORYCOUNT )
757 sAttributes = m_lFactories[eFactory].getWindowAttributes();
760 return sAttributes;
763 //*****************************************************************************************************************
764 ::rtl::OUString SvtModuleOptions_Impl::GetFactoryEmptyDocumentURL( SvtModuleOptions::EFactory eFactory ) const
766 // Attention: Hard configured yet ... because it's not fine to make changes possible by xml file yet.
767 // But it's good to plan further possibilities!
769 //return m_lFactories[eFactory].getEmptyDocumentURL();
771 ::rtl::OUString sURL;
772 switch( eFactory )
774 case SvtModuleOptions::E_WRITER : sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/swriter"));
775 break;
776 case SvtModuleOptions::E_WRITERWEB : sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/swriter/web"));
777 break;
778 case SvtModuleOptions::E_WRITERGLOBAL : sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/swriter/GlobalDocument"));
779 break;
780 case SvtModuleOptions::E_CALC : sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/scalc"));
781 break;
782 case SvtModuleOptions::E_DRAW : sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/sdraw"));
783 break;
784 case SvtModuleOptions::E_IMPRESS : sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/simpress?slot=6686"));
785 break;
786 case SvtModuleOptions::E_MATH : sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/smath"));
787 break;
788 case SvtModuleOptions::E_CHART : sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/schart"));
789 break;
790 case SvtModuleOptions::E_BASIC : sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/sbasic"));
791 break;
792 case SvtModuleOptions::E_DATABASE : sURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/sdatabase?Interactive"));
793 break;
794 default:
795 OSL_ASSERT( "unknown factory" );
796 break;
798 return sURL;
801 //*****************************************************************************************************************
802 ::rtl::OUString SvtModuleOptions_Impl::GetFactoryDefaultFilter( SvtModuleOptions::EFactory eFactory ) const
804 ::rtl::OUString sDefaultFilter;
806 if( eFactory>=0 && eFactory<FACTORYCOUNT )
808 sDefaultFilter = m_lFactories[eFactory].getDefaultFilter();
810 return sDefaultFilter;
812 //*****************************************************************************************************************
813 sal_Bool SvtModuleOptions_Impl::IsDefaultFilterReadonly( SvtModuleOptions::EFactory eFactory ) const
815 sal_Bool bRet = sal_False;
816 if( eFactory>=0 && eFactory<FACTORYCOUNT )
818 bRet = m_lFactories[eFactory].isDefaultFilterReadonly();
820 return bRet;
823 //*****************************************************************************************************************
824 sal_Int32 SvtModuleOptions_Impl::GetFactoryIcon( SvtModuleOptions::EFactory eFactory ) const
826 sal_Int32 nIcon = 0;
828 if( eFactory>=0 && eFactory<FACTORYCOUNT )
830 nIcon = m_lFactories[eFactory].getIcon();
833 return nIcon;
836 //*****************************************************************************************************************
837 void SvtModuleOptions_Impl::SetFactoryStandardTemplate( SvtModuleOptions::EFactory eFactory ,
838 const ::rtl::OUString& sTemplate )
840 if( eFactory>=0 && eFactory<FACTORYCOUNT )
842 m_lFactories[eFactory].setTemplateFile( sTemplate );
843 SetModified();
847 //*****************************************************************************************************************
848 void SvtModuleOptions_Impl::SetFactoryWindowAttributes( SvtModuleOptions::EFactory eFactory ,
849 const ::rtl::OUString& sAttributes)
851 if( eFactory>=0 && eFactory<FACTORYCOUNT )
853 m_lFactories[eFactory].setWindowAttributes( sAttributes );
854 SetModified();
858 //*****************************************************************************************************************
859 void SvtModuleOptions_Impl::SetFactoryDefaultFilter( SvtModuleOptions::EFactory eFactory,
860 const ::rtl::OUString& sFilter )
862 if( eFactory>=0 && eFactory<FACTORYCOUNT )
864 m_lFactories[eFactory].setDefaultFilter( sFilter );
865 SetModified();
869 /*-************************************************************************************************************//**
870 @short return list of key names of ouer configuration management which represent our module tree
871 @descr You give use a list of current existing set node names .. and we expand it for all
872 well known properties which are neccessary for this implementation.
873 These full expanded list should be used to get values of this properties.
875 @seealso ctor
877 @param -
878 @return List of all relative addressed properties of given set entry names.
880 @onerror List will be empty.
881 @threadsafe no
882 *//*-*************************************************************************************************************/
883 css::uno::Sequence< ::rtl::OUString > SvtModuleOptions_Impl::impl_ExpandSetNames( const css::uno::Sequence< ::rtl::OUString >& lSetNames )
885 sal_Int32 nCount = lSetNames.getLength() ;
886 css::uno::Sequence< ::rtl::OUString > lPropNames ( nCount*PROPERTYCOUNT );
887 ::rtl::OUString* pPropNames = lPropNames.getArray() ;
888 sal_Int32 nPropStart = 0 ;
890 for( sal_Int32 nName=0; nName<nCount; ++nName )
892 pPropNames[nPropStart+PROPERTYHANDLE_SHORTNAME ] = lSetNames[nName] + PATHSEPERATOR + PROPERTYNAME_SHORTNAME ;
893 pPropNames[nPropStart+PROPERTYHANDLE_TEMPLATEFILE ] = lSetNames[nName] + PATHSEPERATOR + PROPERTYNAME_TEMPLATEFILE ;
894 pPropNames[nPropStart+PROPERTYHANDLE_WINDOWATTRIBUTES] = lSetNames[nName] + PATHSEPERATOR + PROPERTYNAME_WINDOWATTRIBUTES;
895 pPropNames[nPropStart+PROPERTYHANDLE_EMPTYDOCUMENTURL] = lSetNames[nName] + PATHSEPERATOR + PROPERTYNAME_EMPTYDOCUMENTURL;
896 pPropNames[nPropStart+PROPERTYHANDLE_DEFAULTFILTER ] = lSetNames[nName] + PATHSEPERATOR + PROPERTYNAME_DEFAULTFILTER ;
897 pPropNames[nPropStart+PROPERTYHANDLE_ICON ] = lSetNames[nName] + PATHSEPERATOR + PROPERTYNAME_ICON ;
898 nPropStart += PROPERTYCOUNT;
901 return lPropNames;
904 /*-************************************************************************************************************//**
905 @short helper to classify given factory by name
906 @descr Every factory has his own long and short name. So we can match right enum value for internal using.
908 @attention We change in/out parameter "eFactory" in every case! But you should use it only, if return value is TRUE!
909 Algorithm: Set out-parameter to propably value ... and check the longname.
910 If it match with these factory - break operation and return true AND right set parameter.
911 Otherwise try next one and so on. If no factory was found return false. Out parameter eFactory
912 is set to last tried value but shouldn't be used! Because our return value is false!
914 @seealso -
916 @param "sLongName" , long name of factory, which should be classified
917 @return "eFactory" , right enum value, which match given long name
918 and true for successfully classification, false otherwise
920 @onerror We return false.
921 @threadsafe no
922 *//*-*************************************************************************************************************/
923 sal_Bool SvtModuleOptions_Impl::ClassifyFactoryByName( const ::rtl::OUString& sName, SvtModuleOptions::EFactory& eFactory )
925 sal_Bool bState;
927 eFactory = SvtModuleOptions::E_WRITER ;
928 bState = ( sName == FACTORYNAME_WRITER );
930 if( bState == sal_False )
932 eFactory = SvtModuleOptions::E_WRITERWEB ;
933 bState = ( sName == FACTORYNAME_WRITERWEB );
935 // no else!
936 if( bState == sal_False )
938 eFactory = SvtModuleOptions::E_WRITERGLOBAL ;
939 bState = ( sName == FACTORYNAME_WRITERGLOBAL );
941 // no else!
942 if( bState == sal_False )
944 eFactory = SvtModuleOptions::E_CALC ;
945 bState = ( sName == FACTORYNAME_CALC );
947 // no else!
948 if( bState == sal_False )
950 eFactory = SvtModuleOptions::E_DRAW ;
951 bState = ( sName == FACTORYNAME_DRAW );
953 // no else!
954 if( bState == sal_False )
956 eFactory = SvtModuleOptions::E_IMPRESS ;
957 bState = ( sName == FACTORYNAME_IMPRESS );
959 // no else!
960 if( bState == sal_False )
962 eFactory = SvtModuleOptions::E_MATH ;
963 bState = ( sName == FACTORYNAME_MATH );
965 // no else!
966 if( bState == sal_False )
968 eFactory = SvtModuleOptions::E_CHART ;
969 bState = ( sName == FACTORYNAME_CHART );
971 // no else!
972 if( bState == sal_False )
974 eFactory = SvtModuleOptions::E_DATABASE ;
975 bState = ( sName == FACTORYNAME_DATABASE );
977 // no else!
978 if( bState == sal_False )
980 eFactory = SvtModuleOptions::E_STARTMODULE ;
981 bState = ( sName == FACTORYNAME_STARTMODULE);
984 return bState;
987 /*-************************************************************************************************************//**
988 @short read factory configuration
989 @descr Give us a list of pure factory names (long names!) which can be used as
990 direct set node names ... and we read her property values and fill internal list.
991 These method can be used by initial reading at ctor and later updating by "Notify()".
993 @seealso ctor
994 @seealso method Notify()
996 @param "lFactories" is the list of set node entries which should be readed.
997 @return -
999 @onerror We do nothing.
1000 @threadsafe no
1001 *//*-*************************************************************************************************************/
1002 void SvtModuleOptions_Impl::impl_Read( const css::uno::Sequence< ::rtl::OUString >& lFactories )
1004 // Expand every set node name in lFactories to full qualified pathes to his properties
1005 // and get right values from configuration.
1006 const css::uno::Sequence< ::rtl::OUString > lProperties = impl_ExpandSetNames( lFactories );
1007 const css::uno::Sequence< css::uno::Any > lValues = GetProperties( lProperties );
1009 // Safe impossible cases.
1010 // We need values from ALL configuration keys.
1011 // Follow assignment use order of values in relation to our list of key names!
1012 OSL_ENSURE( !(lProperties.getLength()!=lValues.getLength()), "SvtModuleOptions_Impl::impl_Read()\nI miss some values of configuration keys!\n" );
1014 // Algorithm: We step over all given factory names and classify it. These enum value can be used as direct index
1015 // in our member list m_lFactories! VAriable nPropertyStart marks start position of every factory
1016 // and her properties in expanded property/value list. The defines PROPERTHANDLE_xxx are used as offset values
1017 // added to nPropertyStart. So we can address every property relative in these lists.
1018 // If we found any valid values ... we reset all existing informations for corresponding m_lFactories-entry and
1019 // use a pointer to these struct in memory directly to set new values.
1020 // But we set it only, if bInstalled is true. Otherwise all other values of a factory can be undeclared .. They
1021 // shouldn't be used then.
1022 // Attention: If a propertyset of a factory will be ignored we must step to next start position of next factory infos!
1023 // see "nPropertyStart += PROPERTYCOUNT" ...
1025 sal_Int32 nPropertyStart = 0 ;
1026 sal_Int32 nNodeCount = lFactories.getLength();
1027 FactoryInfo* pInfo = NULL ;
1028 SvtModuleOptions::EFactory eFactory ;
1030 for( sal_Int32 nSetNode=0; nSetNode<nNodeCount; ++nSetNode )
1032 const ::rtl::OUString& sFactoryName = lFactories[nSetNode];
1033 if( ClassifyFactoryByName( sFactoryName, eFactory ) == sal_True )
1035 ::rtl::OUString sTemp;
1036 sal_Int32 nTemp = 0;
1038 pInfo = &(m_lFactories[eFactory]);
1039 pInfo->free();
1041 pInfo->initInstalled( sal_True );
1042 pInfo->initFactory ( sFactoryName );
1044 if (lValues[nPropertyStart+PROPERTYHANDLE_SHORTNAME] >>= sTemp)
1045 pInfo->initShortName( sTemp );
1046 if (lValues[nPropertyStart+PROPERTYHANDLE_TEMPLATEFILE] >>= sTemp)
1047 pInfo->initTemplateFile( sTemp );
1048 if (lValues[nPropertyStart+PROPERTYHANDLE_WINDOWATTRIBUTES] >>= sTemp)
1049 pInfo->initWindowAttributes( sTemp );
1050 if (lValues[nPropertyStart+PROPERTYHANDLE_EMPTYDOCUMENTURL] >>= sTemp)
1051 pInfo->initEmptyDocumentURL( sTemp );
1052 if (lValues[nPropertyStart+PROPERTYHANDLE_DEFAULTFILTER ] >>= sTemp)
1053 pInfo->initDefaultFilter( sTemp );
1054 if (lValues[nPropertyStart+PROPERTYHANDLE_ICON] >>= nTemp)
1055 pInfo->initIcon( nTemp );
1057 nPropertyStart += PROPERTYCOUNT;
1061 //*****************************************************************************************************************
1062 void SvtModuleOptions_Impl::MakeReadonlyStatesAvailable()
1064 if (m_bReadOnlyStatesWellKnown)
1065 return;
1067 css::uno::Sequence< ::rtl::OUString > lFactories = GetNodeNames(::rtl::OUString());
1068 sal_Int32 c = lFactories.getLength();
1069 sal_Int32 i = 0;
1070 for (i=0; i<c; ++i)
1072 ::rtl::OUStringBuffer sPath(256);
1073 sPath.append(lFactories[i] );
1074 sPath.append(PATHSEPERATOR );
1075 sPath.append(PROPERTYNAME_DEFAULTFILTER);
1077 lFactories[i] = sPath.makeStringAndClear();
1080 css::uno::Sequence< sal_Bool > lReadonlyStates = GetReadOnlyStates(lFactories);
1081 for (i=0; i<c; ++i)
1083 ::rtl::OUString& rFactoryName = lFactories[i];
1084 SvtModuleOptions::EFactory eFactory ;
1086 if (!ClassifyFactoryByName(rFactoryName, eFactory))
1087 continue;
1089 FactoryInfo& rInfo = m_lFactories[eFactory];
1090 rInfo.setDefaultFilterReadonly(lReadonlyStates[i]);
1093 m_bReadOnlyStatesWellKnown = sal_True;
1096 //*****************************************************************************************************************
1097 // initialize static member
1098 // DON'T DO IT IN YOUR HEADER!
1099 // see definition for further informations
1100 //*****************************************************************************************************************
1101 SvtModuleOptions_Impl* SvtModuleOptions::m_pDataContainer = NULL ;
1102 sal_Int32 SvtModuleOptions::m_nRefCount = 0 ;
1104 /*-************************************************************************************************************//**
1105 @short standard constructor and destructor
1106 @descr This will initialize an instance with default values. We initialize/deinitialize our static data
1107 container and create a static mutex, which is used for threadsafe code in further time of this object.
1109 @seealso method impl_GetOwnStaticMutex()
1111 @param -
1112 @return -
1114 @onerror -
1115 @threadsafe yes
1116 *//*-*************************************************************************************************************/
1117 SvtModuleOptions::SvtModuleOptions()
1119 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1120 ++m_nRefCount;
1121 if( m_nRefCount == 1 )
1123 RTL_LOGFILE_CONTEXT(aLog, "svtools ( ??? ) ::SvtModuleOptions_Impl::ctor()");
1124 m_pDataContainer = new SvtModuleOptions_Impl(this);
1126 ItemHolder1::holdConfigItem(E_MODULEOPTIONS);
1130 //*****************************************************************************************************************
1131 SvtModuleOptions::~SvtModuleOptions()
1133 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1134 --m_nRefCount;
1135 if( m_nRefCount == 0 )
1137 delete m_pDataContainer;
1138 m_pDataContainer = NULL;
1142 /*-************************************************************************************************************//**
1143 @short access to configuration data
1144 @descr This methods allow read/write access to configuration values.
1145 They are threadsafe. All calls are forwarded to impl-data-container. See there for further informations!
1147 @seealso method impl_GetOwnStaticMutex()
1149 @param -
1150 @return -
1152 @onerror -
1153 @threadsafe yes
1154 *//*-*************************************************************************************************************/
1155 sal_Bool SvtModuleOptions::IsModuleInstalled( EModule eModule ) const
1157 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1158 return m_pDataContainer->IsModuleInstalled( eModule );
1161 //*****************************************************************************************************************
1162 ::rtl::OUString SvtModuleOptions::GetFactoryName( EFactory eFactory ) const
1164 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1165 return m_pDataContainer->GetFactoryName( eFactory );
1168 //*****************************************************************************************************************
1169 ::rtl::OUString SvtModuleOptions::GetFactoryShortName( EFactory eFactory ) const
1171 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1172 return m_pDataContainer->GetFactoryShortName( eFactory );
1175 //*****************************************************************************************************************
1176 ::rtl::OUString SvtModuleOptions::GetFactoryStandardTemplate( EFactory eFactory ) const
1178 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1179 return m_pDataContainer->GetFactoryStandardTemplate( eFactory );
1182 //*****************************************************************************************************************
1183 ::rtl::OUString SvtModuleOptions::GetFactoryWindowAttributes( EFactory eFactory ) const
1185 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1186 return m_pDataContainer->GetFactoryWindowAttributes( eFactory );
1189 //*****************************************************************************************************************
1190 ::rtl::OUString SvtModuleOptions::GetFactoryEmptyDocumentURL( EFactory eFactory ) const
1192 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1193 return m_pDataContainer->GetFactoryEmptyDocumentURL( eFactory );
1196 //*****************************************************************************************************************
1197 ::rtl::OUString SvtModuleOptions::GetFactoryDefaultFilter( EFactory eFactory ) const
1199 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1200 return m_pDataContainer->GetFactoryDefaultFilter( eFactory );
1202 //*****************************************************************************************************************
1203 sal_Bool SvtModuleOptions::IsDefaultFilterReadonly( EFactory eFactory ) const
1205 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1206 m_pDataContainer->MakeReadonlyStatesAvailable();
1207 return m_pDataContainer->IsDefaultFilterReadonly( eFactory );
1209 //*****************************************************************************************************************
1210 sal_Int32 SvtModuleOptions::GetFactoryIcon( EFactory eFactory ) const
1212 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1213 return m_pDataContainer->GetFactoryIcon( eFactory );
1216 //*****************************************************************************************************************
1217 sal_Bool SvtModuleOptions::ClassifyFactoryByName( const ::rtl::OUString& sName ,
1218 EFactory& eFactory )
1220 // We don't need any mutex here ... because we don't use any member here!
1221 return SvtModuleOptions_Impl::ClassifyFactoryByName( sName, eFactory );
1224 //*****************************************************************************************************************
1225 void SvtModuleOptions::SetFactoryStandardTemplate( EFactory eFactory ,
1226 const ::rtl::OUString& sTemplate )
1228 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1229 m_pDataContainer->SetFactoryStandardTemplate( eFactory, sTemplate );
1232 //*****************************************************************************************************************
1233 void SvtModuleOptions::SetFactoryWindowAttributes( EFactory eFactory ,
1234 const ::rtl::OUString& sAttributes)
1236 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1237 m_pDataContainer->SetFactoryWindowAttributes( eFactory, sAttributes );
1240 //*****************************************************************************************************************
1241 void SvtModuleOptions::SetFactoryDefaultFilter( EFactory eFactory,
1242 const ::rtl::OUString& sFilter )
1244 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1245 m_pDataContainer->SetFactoryDefaultFilter( eFactory, sFilter );
1248 //*****************************************************************************************************************
1249 sal_Bool SvtModuleOptions::IsMath() const
1251 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1252 return m_pDataContainer->IsModuleInstalled( E_SMATH );
1255 //*****************************************************************************************************************
1256 sal_Bool SvtModuleOptions::IsChart() const
1258 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1259 return m_pDataContainer->IsModuleInstalled( E_SCHART );
1262 //*****************************************************************************************************************
1263 sal_Bool SvtModuleOptions::IsCalc() const
1265 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1266 return m_pDataContainer->IsModuleInstalled( E_SCALC );
1269 //*****************************************************************************************************************
1270 sal_Bool SvtModuleOptions::IsDraw() const
1272 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1273 return m_pDataContainer->IsModuleInstalled( E_SDRAW );
1276 //*****************************************************************************************************************
1277 sal_Bool SvtModuleOptions::IsWriter() const
1279 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1280 return m_pDataContainer->IsModuleInstalled( E_SWRITER );
1283 //*****************************************************************************************************************
1284 sal_Bool SvtModuleOptions::IsImpress() const
1286 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1287 return m_pDataContainer->IsModuleInstalled( E_SIMPRESS );
1290 //*****************************************************************************************************************
1291 sal_Bool SvtModuleOptions::IsBasicIDE() const
1293 return sal_True;
1295 //*****************************************************************************************************************
1296 sal_Bool SvtModuleOptions::IsDataBase() const
1298 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1299 return m_pDataContainer->IsModuleInstalled( E_SDATABASE );
1301 //*****************************************************************************************************************
1302 sal_uInt32 SvtModuleOptions::GetFeatures() const
1304 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1306 sal_uInt32 nFeature = 0;
1308 if( m_pDataContainer->IsModuleInstalled( E_SWRITER ) == sal_True )
1309 nFeature |= FEATUREFLAG_WRITER;
1310 if( m_pDataContainer->IsModuleInstalled( E_SCALC ) == sal_True )
1311 nFeature |= FEATUREFLAG_CALC;
1312 if( m_pDataContainer->IsModuleInstalled( E_SDRAW ) == sal_True )
1313 nFeature |= FEATUREFLAG_DRAW;
1314 if( m_pDataContainer->IsModuleInstalled( E_SIMPRESS ) == sal_True )
1315 nFeature |= FEATUREFLAG_IMPRESS;
1316 if( m_pDataContainer->IsModuleInstalled( E_SCHART ) == sal_True )
1317 nFeature |= FEATUREFLAG_CHART;
1318 if( m_pDataContainer->IsModuleInstalled( E_SMATH ) == sal_True )
1319 nFeature |= FEATUREFLAG_MATH;
1320 if( m_pDataContainer->IsModuleInstalled( E_SBASIC ) == sal_True )
1321 nFeature |= FEATUREFLAG_BASICIDE;
1322 if( m_pDataContainer->IsModuleInstalled( E_SDATABASE ) == sal_True )
1323 nFeature |= FEATUREFLAG_INSIGHT;
1325 return nFeature;
1328 /*-****************************************************************************************************//**
1329 @short return a reference to a static mutex
1330 @descr These class is threadsafe.
1331 We create a static mutex only for one time and use it to protect our refcount and container
1332 member!
1334 @seealso -
1336 @param -
1337 @return A reference to a static mutex member.
1339 @onerror -
1340 @threadsafe yes
1341 *//*-*****************************************************************************************************/
1342 ::osl::Mutex& SvtModuleOptions::impl_GetOwnStaticMutex()
1344 // Initialize static mutex only for one time!
1345 static ::osl::Mutex* pMutex = NULL;
1346 // If these method first called (Mutex not already exist!) ...
1347 if( pMutex == NULL )
1349 // ... we must create a new one. Protect follow code with the global mutex -
1350 // It must be - we create a static variable!
1351 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
1352 // We must check our pointer again - because it can be that another instance of ouer class will be fastr then these!
1353 if( pMutex == NULL )
1355 // Create the new mutex and set it for return on static variable.
1356 static ::osl::Mutex aMutex;
1357 pMutex = &aMutex;
1360 // Return new created or already existing mutex object.
1361 return *pMutex;
1364 ::rtl::OUString SvtModuleOptions::GetModuleName( EModule eModule ) const
1366 switch( eModule )
1368 case SvtModuleOptions::E_SWRITER : { return ::rtl::OUString::createFromAscii("Writer"); }
1369 case SvtModuleOptions::E_SWEB : { return ::rtl::OUString::createFromAscii("Web"); }
1370 case SvtModuleOptions::E_SGLOBAL : { return ::rtl::OUString::createFromAscii("Global"); }
1371 case SvtModuleOptions::E_SCALC : { return ::rtl::OUString::createFromAscii("Calc"); }
1372 case SvtModuleOptions::E_SDRAW : { return ::rtl::OUString::createFromAscii("Draw"); }
1373 case SvtModuleOptions::E_SIMPRESS : { return ::rtl::OUString::createFromAscii("Impress"); }
1374 case SvtModuleOptions::E_SMATH : { return ::rtl::OUString::createFromAscii("Math"); }
1375 case SvtModuleOptions::E_SCHART : { return ::rtl::OUString::createFromAscii("Chart"); }
1376 case SvtModuleOptions::E_SBASIC : { return ::rtl::OUString::createFromAscii("Basic"); }
1377 case SvtModuleOptions::E_SDATABASE : { return ::rtl::OUString::createFromAscii("Database"); }
1378 default:
1379 OSL_ASSERT( "unknown module" );
1380 break;
1383 return ::rtl::OUString();
1386 ::rtl::OUString SvtModuleOptions::GetModuleName( EFactory eFactory ) const
1388 switch( eFactory )
1390 case SvtModuleOptions::E_WRITER : { return ::rtl::OUString::createFromAscii("Writer"); }
1391 case SvtModuleOptions::E_WRITERWEB : { return ::rtl::OUString::createFromAscii("Writer"); }
1392 case SvtModuleOptions::E_WRITERGLOBAL : { return ::rtl::OUString::createFromAscii("Writer"); }
1393 case SvtModuleOptions::E_CALC : { return ::rtl::OUString::createFromAscii("Calc"); }
1394 case SvtModuleOptions::E_DRAW : { return ::rtl::OUString::createFromAscii("Draw"); }
1395 case SvtModuleOptions::E_IMPRESS : { return ::rtl::OUString::createFromAscii("Impress"); }
1396 case SvtModuleOptions::E_MATH : { return ::rtl::OUString::createFromAscii("Math"); }
1397 case SvtModuleOptions::E_CHART : { return ::rtl::OUString::createFromAscii("Chart"); }
1398 case SvtModuleOptions::E_BASIC : { return ::rtl::OUString::createFromAscii("Basic"); }
1399 case SvtModuleOptions::E_DATABASE : { return ::rtl::OUString::createFromAscii("Database"); }
1400 default:
1401 OSL_ASSERT( "unknown factory" );
1402 break;
1405 return ::rtl::OUString();
1408 /*-----------------------------------------------
1409 07.03.2004 15:03
1410 -----------------------------------------------*/
1411 SvtModuleOptions::EFactory SvtModuleOptions::ClassifyFactoryByShortName(const ::rtl::OUString& sName)
1413 if (sName.equalsAscii("swriter"))
1414 return E_WRITER;
1415 if (sName.equalsIgnoreAsciiCaseAscii("swriter/Web")) // sometimes they are registerd for swriter/web :-(
1416 return E_WRITERWEB;
1417 if (sName.equalsIgnoreAsciiCaseAscii("swriter/GlobalDocument")) // sometimes they are registerd for swriter/globaldocument :-(
1418 return E_WRITERGLOBAL;
1419 if (sName.equalsAscii("scalc"))
1420 return E_CALC;
1421 if (sName.equalsAscii("sdraw"))
1422 return E_DRAW;
1423 if (sName.equalsAscii("simpress"))
1424 return E_IMPRESS;
1425 if (sName.equalsAscii("schart"))
1426 return E_CHART;
1427 if (sName.equalsAscii("smath"))
1428 return E_MATH;
1429 if (sName.equalsAscii("sbasic"))
1430 return E_BASIC;
1431 if (sName.equalsAscii("sdatabase"))
1432 return E_DATABASE;
1434 return E_UNKNOWN_FACTORY;
1437 /*-----------------------------------------------
1438 31.07.2003 10:41
1439 -----------------------------------------------*/
1440 SvtModuleOptions::EFactory SvtModuleOptions::ClassifyFactoryByServiceName(const ::rtl::OUString& sName)
1442 if (sName.equals(FACTORYNAME_WRITERGLOBAL))
1443 return E_WRITERGLOBAL;
1444 if (sName.equals(FACTORYNAME_WRITERWEB))
1445 return E_WRITERWEB;
1446 if (sName.equals(FACTORYNAME_WRITER))
1447 return E_WRITER;
1448 if (sName.equals(FACTORYNAME_CALC))
1449 return E_CALC;
1450 if (sName.equals(FACTORYNAME_DRAW))
1451 return E_DRAW;
1452 if (sName.equals(FACTORYNAME_IMPRESS))
1453 return E_IMPRESS;
1454 if (sName.equals(FACTORYNAME_MATH))
1455 return E_MATH;
1456 if (sName.equals(FACTORYNAME_CHART))
1457 return E_CHART;
1458 if (sName.equals(FACTORYNAME_DATABASE))
1459 return E_DATABASE;
1461 return E_UNKNOWN_FACTORY;
1464 /*-----------------------------------------------
1465 31.07.2003 14:39
1466 -----------------------------------------------*/
1467 SvtModuleOptions::EFactory SvtModuleOptions::ClassifyFactoryByURL(const ::rtl::OUString& sURL ,
1468 const css::uno::Sequence< css::beans::PropertyValue >& lMediaDescriptor)
1470 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::utl::getProcessServiceFactory();
1471 if (!xSMGR.is())
1472 return E_UNKNOWN_FACTORY;
1474 css::uno::Reference< css::container::XNameAccess > xFilterCfg;
1475 css::uno::Reference< css::container::XNameAccess > xTypeCfg ;
1478 xFilterCfg = css::uno::Reference< css::container::XNameAccess >(
1479 xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.document.FilterFactory")), css::uno::UNO_QUERY);
1480 xTypeCfg = css::uno::Reference< css::container::XNameAccess >(
1481 xSMGR->createInstance(::rtl::OUString::createFromAscii("com.sun.star.document.TypeDetection")), css::uno::UNO_QUERY);
1483 catch(const css::uno::RuntimeException&)
1484 { throw; }
1485 catch(const css::uno::Exception&)
1486 { return E_UNKNOWN_FACTORY; }
1488 ::comphelper::SequenceAsHashMap stlDesc(lMediaDescriptor);
1490 // is there already a filter inside the descriptor?
1491 ::rtl::OUString sFilterName = stlDesc.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("FilterName"), ::rtl::OUString());
1492 if (sFilterName.getLength())
1496 ::comphelper::SequenceAsHashMap stlFilterProps (xFilterCfg->getByName(sFilterName));
1497 ::rtl::OUString sDocumentService = stlFilterProps.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("DocumentService"), ::rtl::OUString());
1498 SvtModuleOptions::EFactory eApp = SvtModuleOptions::ClassifyFactoryByServiceName(sDocumentService);
1500 if (eApp != E_UNKNOWN_FACTORY)
1501 return eApp;
1503 catch(const css::uno::RuntimeException&)
1504 { throw; }
1505 catch(const css::uno::Exception&)
1506 { /* do nothing here ... may the following code can help!*/ }
1509 // is there already a type inside the descriptor?
1510 ::rtl::OUString sTypeName = stlDesc.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("TypeName"), ::rtl::OUString());
1511 if (!sTypeName.getLength())
1513 // no :-(
1514 // start flat detection of URL
1515 css::uno::Reference< css::document::XTypeDetection > xDetect(xTypeCfg, css::uno::UNO_QUERY);
1516 sTypeName = xDetect->queryTypeByURL(sURL);
1519 if (!sTypeName.getLength())
1520 return E_UNKNOWN_FACTORY;
1522 // yes - there is a type info
1523 // Try to find the preferred filter.
1526 ::comphelper::SequenceAsHashMap stlTypeProps (xTypeCfg->getByName(sTypeName));
1527 ::rtl::OUString sPreferredFilter = stlTypeProps.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("PreferredFilter"), ::rtl::OUString());
1528 ::comphelper::SequenceAsHashMap stlFilterProps (xFilterCfg->getByName(sPreferredFilter));
1529 ::rtl::OUString sDocumentService = stlFilterProps.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("DocumentService"), ::rtl::OUString());
1530 SvtModuleOptions::EFactory eApp = SvtModuleOptions::ClassifyFactoryByServiceName(sDocumentService);
1532 if (eApp != E_UNKNOWN_FACTORY)
1533 return eApp;
1535 catch(const css::uno::RuntimeException&)
1536 { throw; }
1537 catch(const css::uno::Exception&)
1538 { /* do nothing here ... may the following code can help!*/ }
1540 // no filter/no type/no detection result => no fun :-)
1541 return E_UNKNOWN_FACTORY;
1544 /*-----------------------------------------------
1545 31.07.2003 10:41
1546 -----------------------------------------------*/
1547 SvtModuleOptions::EFactory SvtModuleOptions::ClassifyFactoryByModel(const css::uno::Reference< css::frame::XModel >& xModel)
1549 css::uno::Reference< css::lang::XServiceInfo > xInfo(xModel, css::uno::UNO_QUERY);
1550 if (!xInfo.is())
1551 return E_UNKNOWN_FACTORY;
1553 const css::uno::Sequence< ::rtl::OUString > lServices = xInfo->getSupportedServiceNames();
1554 const ::rtl::OUString* pServices = lServices.getConstArray();
1556 for (sal_Int32 i=0; i<lServices.getLength() ; ++i)
1558 SvtModuleOptions::EFactory eApp = SvtModuleOptions::ClassifyFactoryByServiceName(pServices[i]);
1559 if (eApp != E_UNKNOWN_FACTORY)
1560 return eApp;
1563 return E_UNKNOWN_FACTORY;
1566 ::com::sun::star::uno::Sequence < ::rtl::OUString > SvtModuleOptions::GetAllServiceNames()
1568 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1569 return m_pDataContainer->GetAllServiceNames();
1572 ::rtl::OUString SvtModuleOptions::GetDefaultModuleName()
1574 ::rtl::OUString aModule;
1575 if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SWRITER))
1576 aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_WRITER);
1577 else
1578 if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SCALC))
1579 aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_CALC);
1580 else
1581 if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SIMPRESS))
1582 aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_IMPRESS);
1583 else
1584 if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SDATABASE))
1585 aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_DATABASE);
1586 else
1587 if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SDRAW))
1588 aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_DRAW);
1589 else
1590 if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SWEB))
1591 aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_WRITERWEB);
1592 else
1593 if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SGLOBAL))
1594 aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_WRITERGLOBAL);
1595 else
1596 if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SMATH))
1597 aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_MATH);
1598 return aModule;