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