1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef __FRAMEWORK_UICONFIGURATION_MODULEUICONFIGMANAGER_HXX_ 29 #define __FRAMEWORK_UICONFIGURATION_MODULEUICONFIGMANAGER_HXX_ 30 31 32 /** Attention: stl headers must(!) be included at first. Otherwhise it can make trouble 33 with solaris headers ... 34 */ 35 #include <vector> 36 #include <list> 37 #include <hash_map> 38 39 //_________________________________________________________________________________________________________________ 40 // my own includes 41 //_________________________________________________________________________________________________________________ 42 #include <accelerators/presethandler.hxx> 43 #include <threadhelp/threadhelpbase.hxx> 44 #include <macros/generic.hxx> 45 #include <macros/xinterface.hxx> 46 #include <macros/xtypeprovider.hxx> 47 #include <macros/xserviceinfo.hxx> 48 #include <stdtypes.h> 49 #include <uiconfiguration/moduleimagemanager.hxx> 50 51 //_________________________________________________________________________________________________________________ 52 // interface includes 53 //_________________________________________________________________________________________________________________ 54 #include <com/sun/star/lang/XServiceInfo.hpp> 55 #include <com/sun/star/lang/XTypeProvider.hpp> 56 #include <com/sun/star/lang/XComponent.hpp> 57 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp> 58 #include <com/sun/star/ui/XUIConfiguration.hpp> 59 #include <com/sun/star/ui/XUIConfigurationManager.hpp> 60 #include <com/sun/star/ui/XModuleUIConfigurationManager.hpp> 61 #include <com/sun/star/ui/UIElementType.hpp> 62 #include <com/sun/star/lang/XInitialization.hpp> 63 #include <com/sun/star/ui/ConfigurationEvent.hpp> 64 #include <com/sun/star/embed/XTransactedObject.hpp> 65 #include <com/sun/star/container/XIndexContainer.hpp> 66 67 //_________________________________________________________________________________________________________________ 68 // other includes 69 //_________________________________________________________________________________________________________________ 70 #include <cppuhelper/weak.hxx> 71 #include <cppuhelper/interfacecontainer.hxx> 72 #include <rtl/ustring.hxx> 73 74 75 namespace framework 76 { 77 class ModuleUIConfigurationManager : public com::sun::star::lang::XTypeProvider , 78 public com::sun::star::lang::XServiceInfo , 79 public com::sun::star::lang::XComponent , 80 public com::sun::star::lang::XInitialization , 81 public ::com::sun::star::ui::XUIConfiguration , 82 public ::com::sun::star::ui::XUIConfigurationManager , 83 public ::com::sun::star::ui::XModuleUIConfigurationManager , 84 public ::com::sun::star::ui::XUIConfigurationPersistence , 85 private ThreadHelpBase , // Struct for right initalization of mutex member! Must be first of baseclasses. 86 public ::cppu::OWeakObject 87 { 88 public: 89 // XInterface, XTypeProvider, XServiceInfo 90 FWK_DECLARE_XINTERFACE 91 FWK_DECLARE_XTYPEPROVIDER 92 DECLARE_XSERVICEINFO 93 94 ModuleUIConfigurationManager( com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > xServiceManager ); 95 virtual ~ModuleUIConfigurationManager(); 96 97 // XComponent 98 virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException); 99 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); 100 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 101 102 // XInitialization 103 virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 104 105 // XUIConfiguration 106 virtual void SAL_CALL addConfigurationListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); 107 virtual void SAL_CALL removeConfigurationListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); 108 109 // XUIConfigurationManager 110 virtual void SAL_CALL reset() throw (::com::sun::star::uno::RuntimeException); 111 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > SAL_CALL getUIElementsInfo( sal_Int16 ElementType ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 112 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > SAL_CALL createSettings( ) throw (::com::sun::star::uno::RuntimeException); 113 virtual sal_Bool SAL_CALL hasSettings( const ::rtl::OUString& ResourceURL ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 114 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > SAL_CALL getSettings( const ::rtl::OUString& ResourceURL, sal_Bool bWriteable ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 115 virtual void SAL_CALL replaceSettings( const ::rtl::OUString& ResourceURL, const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& aNewData ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException); 116 virtual void SAL_CALL removeSettings( const ::rtl::OUString& ResourceURL ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException); 117 virtual void SAL_CALL insertSettings( const ::rtl::OUString& NewResourceURL, const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& aNewData ) throw (::com::sun::star::container::ElementExistException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException); 118 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getImageManager() throw (::com::sun::star::uno::RuntimeException); 119 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getShortCutManager() throw (::com::sun::star::uno::RuntimeException); 120 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getEventsManager() throw (::com::sun::star::uno::RuntimeException); 121 122 // XModuleUIConfigurationManager 123 virtual sal_Bool SAL_CALL isDefaultSettings( const ::rtl::OUString& ResourceURL ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 124 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > SAL_CALL getDefaultSettings( const ::rtl::OUString& ResourceURL ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 125 126 // XUIConfigurationPersistence 127 virtual void SAL_CALL reload() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 128 virtual void SAL_CALL store() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 129 virtual void SAL_CALL storeToStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& Storage ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 130 virtual sal_Bool SAL_CALL isModified() throw (::com::sun::star::uno::RuntimeException); 131 virtual sal_Bool SAL_CALL isReadOnly() throw (::com::sun::star::uno::RuntimeException); 132 133 private: 134 // private data types 135 enum Layer 136 { 137 LAYER_DEFAULT, 138 LAYER_USERDEFINED, 139 LAYER_COUNT 140 }; 141 142 enum NotifyOp 143 { 144 NotifyOp_Remove, 145 NotifyOp_Insert, 146 NotifyOp_Replace 147 }; 148 149 struct UIElementInfo 150 { 151 UIElementInfo( const rtl::OUString& rResourceURL, const rtl::OUString& rUIName ) : 152 aResourceURL( rResourceURL), aUIName( rUIName ) {} 153 rtl::OUString aResourceURL; 154 rtl::OUString aUIName; 155 }; 156 157 struct UIElementData 158 { 159 UIElementData() : bModified( false ), bDefault( true ), bDefaultNode( true ) {}; 160 161 rtl::OUString aResourceURL; 162 rtl::OUString aName; 163 bool bModified; // has been changed since last storing 164 bool bDefault; // default settings 165 bool bDefaultNode; // this is a default layer element data 166 com::sun::star::uno::Reference< com::sun::star::container::XIndexAccess > xSettings; 167 }; 168 169 struct UIElementType; 170 friend struct UIElementType; 171 typedef ::std::hash_map< rtl::OUString, UIElementData, OUStringHashCode, ::std::equal_to< rtl::OUString > > UIElementDataHashMap; 172 173 struct UIElementType 174 { 175 UIElementType() : bModified( false ), 176 bLoaded( false ), 177 bDefaultLayer( false ), 178 nElementType( ::com::sun::star::ui::UIElementType::UNKNOWN ) {} 179 180 181 bool bModified; 182 bool bLoaded; 183 bool bDefaultLayer; 184 sal_Int16 nElementType; 185 UIElementDataHashMap aElementsHashMap; 186 com::sun::star::uno::Reference< com::sun::star::embed::XStorage > xStorage; 187 }; 188 189 typedef ::std::vector< UIElementType > UIElementTypesVector; 190 typedef ::std::vector< ::com::sun::star::ui::ConfigurationEvent > ConfigEventNotifyContainer; 191 typedef ::std::hash_map< rtl::OUString, UIElementInfo, OUStringHashCode, ::std::equal_to< rtl::OUString > > UIElementInfoHashMap; 192 193 // private methods 194 void impl_Initialize(); 195 void implts_notifyContainerListener( const ::com::sun::star::ui::ConfigurationEvent& aEvent, NotifyOp eOp ); 196 void impl_fillSequenceWithElementTypeInfo( UIElementInfoHashMap& aUIElementInfoCollection, sal_Int16 nElementType ); 197 void impl_preloadUIElementTypeList( Layer eLayer, sal_Int16 nElementType ); 198 UIElementData* impl_findUIElementData( const rtl::OUString& aResourceURL, sal_Int16 nElementType, bool bLoad = true ); 199 void impl_requestUIElementData( sal_Int16 nElementType, Layer eLayer, UIElementData& aUIElementData ); 200 void impl_storeElementTypeData( com::sun::star::uno::Reference< com::sun::star::embed::XStorage > xStorage, UIElementType& rElementType, bool bResetModifyState = true ); 201 void impl_resetElementTypeData( UIElementType& rUserElementType, UIElementType& rDefaultElementType, ConfigEventNotifyContainer& rRemoveNotifyContainer, ConfigEventNotifyContainer& rReplaceNotifyContainer ); 202 void impl_reloadElementTypeData( UIElementType& rUserElementType, UIElementType& rDefaultElementType, ConfigEventNotifyContainer& rRemoveNotifyContainer, ConfigEventNotifyContainer& rReplaceNotifyContainer ); 203 204 UIElementTypesVector m_aUIElements[LAYER_COUNT]; 205 PresetHandler* m_pStorageHandler[::com::sun::star::ui::UIElementType::COUNT]; 206 com::sun::star::uno::Reference< com::sun::star::embed::XStorage > m_xDefaultConfigStorage; 207 com::sun::star::uno::Reference< com::sun::star::embed::XStorage > m_xUserConfigStorage; 208 bool m_bReadOnly; 209 bool m_bInitialized; 210 bool m_bModified; 211 bool m_bConfigRead; 212 bool m_bDisposed; 213 rtl::OUString m_aXMLPostfix; 214 rtl::OUString m_aPropUIName; 215 rtl::OUString m_aPropResourceURL; 216 rtl::OUString m_aModuleIdentifier; 217 rtl::OUString m_aModuleShortName; 218 com::sun::star::uno::Reference< com::sun::star::embed::XTransactedObject > m_xUserRootCommit; 219 com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xServiceManager; 220 ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerContainer; /// container for ALL Listener 221 com::sun::star::uno::Reference< com::sun::star::lang::XComponent > m_xModuleImageManager; 222 com::sun::star::uno::Reference< com::sun::star::uno::XInterface > m_xModuleAcceleratorManager; 223 }; 224 } 225 226 #endif // __FRAMEWORK_UICONFIGURATION_MODULEUICONFIGMANAGER_HXX_ 227