1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef __FRAMEWORK_UICONFIGURATION_MODULEUICONFIGMANAGER_HXX_ 25 #define __FRAMEWORK_UICONFIGURATION_MODULEUICONFIGMANAGER_HXX_ 26 27 28 /** Attention: stl headers must(!) be included at first. Otherwhise it can make trouble 29 with solaris headers ... 30 */ 31 #include <vector> 32 #include <list> 33 #include <hash_map> 34 35 //_________________________________________________________________________________________________________________ 36 // my own includes 37 //_________________________________________________________________________________________________________________ 38 #include <accelerators/presethandler.hxx> 39 #include <threadhelp/threadhelpbase.hxx> 40 #include <macros/generic.hxx> 41 #include <macros/xinterface.hxx> 42 #include <macros/xtypeprovider.hxx> 43 #include <macros/xserviceinfo.hxx> 44 #include <stdtypes.h> 45 #include <uiconfiguration/moduleimagemanager.hxx> 46 47 //_________________________________________________________________________________________________________________ 48 // interface includes 49 //_________________________________________________________________________________________________________________ 50 #include <com/sun/star/lang/XServiceInfo.hpp> 51 #include <com/sun/star/lang/XTypeProvider.hpp> 52 #include <com/sun/star/lang/XComponent.hpp> 53 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp> 54 #include <com/sun/star/ui/XUIConfiguration.hpp> 55 #include <com/sun/star/ui/XUIConfigurationManager.hpp> 56 #include <com/sun/star/ui/XModuleUIConfigurationManager.hpp> 57 #include <com/sun/star/ui/UIElementType.hpp> 58 #include <com/sun/star/lang/XInitialization.hpp> 59 #include <com/sun/star/ui/ConfigurationEvent.hpp> 60 #include <com/sun/star/embed/XTransactedObject.hpp> 61 #include <com/sun/star/container/XIndexContainer.hpp> 62 63 //_________________________________________________________________________________________________________________ 64 // other includes 65 //_________________________________________________________________________________________________________________ 66 #include <cppuhelper/weak.hxx> 67 #include <cppuhelper/interfacecontainer.hxx> 68 #include <rtl/ustring.hxx> 69 70 71 namespace framework 72 { 73 class ModuleUIConfigurationManager : public com::sun::star::lang::XTypeProvider , 74 public com::sun::star::lang::XServiceInfo , 75 public com::sun::star::lang::XComponent , 76 public com::sun::star::lang::XInitialization , 77 public ::com::sun::star::ui::XUIConfiguration , 78 public ::com::sun::star::ui::XUIConfigurationManager , 79 public ::com::sun::star::ui::XModuleUIConfigurationManager , 80 public ::com::sun::star::ui::XUIConfigurationPersistence , 81 private ThreadHelpBase , // Struct for right initalization of mutex member! Must be first of baseclasses. 82 public ::cppu::OWeakObject 83 { 84 public: 85 // XInterface, XTypeProvider, XServiceInfo 86 FWK_DECLARE_XINTERFACE 87 FWK_DECLARE_XTYPEPROVIDER 88 DECLARE_XSERVICEINFO 89 90 ModuleUIConfigurationManager( com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > xServiceManager ); 91 virtual ~ModuleUIConfigurationManager(); 92 93 // XComponent 94 virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException); 95 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); 96 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 97 98 // XInitialization 99 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); 100 101 // XUIConfiguration 102 virtual void SAL_CALL addConfigurationListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); 103 virtual void SAL_CALL removeConfigurationListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); 104 105 // XUIConfigurationManager 106 virtual void SAL_CALL reset() throw (::com::sun::star::uno::RuntimeException); 107 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); 108 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > SAL_CALL createSettings( ) throw (::com::sun::star::uno::RuntimeException); 109 virtual sal_Bool SAL_CALL hasSettings( const ::rtl::OUString& ResourceURL ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 110 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); 111 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); 112 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); 113 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); 114 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getImageManager() throw (::com::sun::star::uno::RuntimeException); 115 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getShortCutManager() throw (::com::sun::star::uno::RuntimeException); 116 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getEventsManager() throw (::com::sun::star::uno::RuntimeException); 117 118 // XModuleUIConfigurationManager 119 virtual sal_Bool SAL_CALL isDefaultSettings( const ::rtl::OUString& ResourceURL ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 120 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); 121 122 // XUIConfigurationPersistence 123 virtual void SAL_CALL reload() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 124 virtual void SAL_CALL store() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 125 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); 126 virtual sal_Bool SAL_CALL isModified() throw (::com::sun::star::uno::RuntimeException); 127 virtual sal_Bool SAL_CALL isReadOnly() throw (::com::sun::star::uno::RuntimeException); 128 129 private: 130 // private data types 131 enum Layer 132 { 133 LAYER_DEFAULT, 134 LAYER_USERDEFINED, 135 LAYER_COUNT 136 }; 137 138 enum NotifyOp 139 { 140 NotifyOp_Remove, 141 NotifyOp_Insert, 142 NotifyOp_Replace 143 }; 144 145 struct UIElementInfo 146 { UIElementInfoframework::ModuleUIConfigurationManager::UIElementInfo147 UIElementInfo( const rtl::OUString& rResourceURL, const rtl::OUString& rUIName ) : 148 aResourceURL( rResourceURL), aUIName( rUIName ) {} 149 rtl::OUString aResourceURL; 150 rtl::OUString aUIName; 151 }; 152 153 struct UIElementData 154 { UIElementDataframework::ModuleUIConfigurationManager::UIElementData155 UIElementData() : bModified( false ), bDefault( true ), bDefaultNode( true ) {}; 156 157 rtl::OUString aResourceURL; 158 rtl::OUString aName; 159 bool bModified; // has been changed since last storing 160 bool bDefault; // default settings 161 bool bDefaultNode; // this is a default layer element data 162 com::sun::star::uno::Reference< com::sun::star::container::XIndexAccess > xSettings; 163 }; 164 165 struct UIElementType; 166 friend struct UIElementType; 167 typedef ::std::hash_map< rtl::OUString, UIElementData, rtl::OUStringHash, ::std::equal_to< rtl::OUString > > UIElementDataHashMap; 168 169 struct UIElementType 170 { UIElementTypeframework::ModuleUIConfigurationManager::UIElementType171 UIElementType() : bModified( false ), 172 bLoaded( false ), 173 bDefaultLayer( false ), 174 nElementType( ::com::sun::star::ui::UIElementType::UNKNOWN ) {} 175 176 177 bool bModified; 178 bool bLoaded; 179 bool bDefaultLayer; 180 sal_Int16 nElementType; 181 UIElementDataHashMap aElementsHashMap; 182 com::sun::star::uno::Reference< com::sun::star::embed::XStorage > xStorage; 183 }; 184 185 typedef ::std::vector< UIElementType > UIElementTypesVector; 186 typedef ::std::vector< ::com::sun::star::ui::ConfigurationEvent > ConfigEventNotifyContainer; 187 typedef ::std::hash_map< rtl::OUString, UIElementInfo, rtl::OUStringHash, ::std::equal_to< rtl::OUString > > UIElementInfoHashMap; 188 189 // private methods 190 void impl_Initialize(); 191 void implts_notifyContainerListener( const ::com::sun::star::ui::ConfigurationEvent& aEvent, NotifyOp eOp ); 192 void impl_fillSequenceWithElementTypeInfo( UIElementInfoHashMap& aUIElementInfoCollection, sal_Int16 nElementType ); 193 void impl_preloadUIElementTypeList( Layer eLayer, sal_Int16 nElementType ); 194 UIElementData* impl_findUIElementData( const rtl::OUString& aResourceURL, sal_Int16 nElementType, bool bLoad = true ); 195 void impl_requestUIElementData( sal_Int16 nElementType, Layer eLayer, UIElementData& aUIElementData ); 196 void impl_storeElementTypeData( com::sun::star::uno::Reference< com::sun::star::embed::XStorage > xStorage, UIElementType& rElementType, bool bResetModifyState = true ); 197 void impl_resetElementTypeData( UIElementType& rUserElementType, UIElementType& rDefaultElementType, ConfigEventNotifyContainer& rRemoveNotifyContainer, ConfigEventNotifyContainer& rReplaceNotifyContainer ); 198 void impl_reloadElementTypeData( UIElementType& rUserElementType, UIElementType& rDefaultElementType, ConfigEventNotifyContainer& rRemoveNotifyContainer, ConfigEventNotifyContainer& rReplaceNotifyContainer ); 199 200 UIElementTypesVector m_aUIElements[LAYER_COUNT]; 201 PresetHandler* m_pStorageHandler[::com::sun::star::ui::UIElementType::COUNT]; 202 com::sun::star::uno::Reference< com::sun::star::embed::XStorage > m_xDefaultConfigStorage; 203 com::sun::star::uno::Reference< com::sun::star::embed::XStorage > m_xUserConfigStorage; 204 bool m_bReadOnly; 205 bool m_bInitialized; 206 bool m_bModified; 207 bool m_bConfigRead; 208 bool m_bDisposed; 209 rtl::OUString m_aXMLPostfix; 210 rtl::OUString m_aPropUIName; 211 rtl::OUString m_aPropResourceURL; 212 rtl::OUString m_aModuleIdentifier; 213 rtl::OUString m_aModuleShortName; 214 com::sun::star::uno::Reference< com::sun::star::embed::XTransactedObject > m_xUserRootCommit; 215 com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xServiceManager; 216 ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerContainer; /// container for ALL Listener 217 com::sun::star::uno::Reference< com::sun::star::lang::XComponent > m_xModuleImageManager; 218 com::sun::star::uno::Reference< com::sun::star::uno::XInterface > m_xModuleAcceleratorManager; 219 }; 220 } 221 222 #endif // __FRAMEWORK_UICONFIGURATION_MODULEUICONFIGMANAGER_HXX_ 223