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_UICONFIGMANAGERIMPL_HXX_
25 #define __FRAMEWORK_UICONFIGURATION_UICONFIGMANAGERIMPL_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/UIElementType.hpp>
57 #include <com/sun/star/lang/XInitialization.hpp>
58 #include <com/sun/star/ui/ConfigurationEvent.hpp>
59 #include <com/sun/star/embed/XTransactedObject.hpp>
60 #include <com/sun/star/container/XIndexContainer.hpp>
61 
62 //_________________________________________________________________________________________________________________
63 //	other includes
64 //_________________________________________________________________________________________________________________
65 #include <cppuhelper/weak.hxx>
66 #include <cppuhelper/interfacecontainer.hxx>
67 #include <rtl/ustring.hxx>
68 
69 
70 namespace framework
71 {
72     class UIConfigurationManagerImpl :   public ThreadHelpBase		// Struct for right initalization of mutex member! Must be first of baseclasses.
73     {
74         public:
75             //  XInterface, XTypeProvider, XServiceInfo
76             UIConfigurationManagerImpl( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xServiceManager
77                                         , const com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& _xOwner
78                                         , bool _bUseDefault);
79             ~UIConfigurationManagerImpl();
80 
81             // XComponent
82             void dispose() throw (::com::sun::star::uno::RuntimeException);
83             void addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
84             void removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
85 
86             // XInitialization
87             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);
88 
89             // XUIConfiguration
90             void addConfigurationListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
91             void removeConfigurationListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
92 
93             // XUIConfigurationManager
94             void reset() throw (::com::sun::star::uno::RuntimeException);
95             ::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);
96             ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > createSettings(  ) throw (::com::sun::star::uno::RuntimeException);
97             sal_Bool hasSettings( const ::rtl::OUString& ResourceURL ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
98             ::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);
99             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);
100             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);
101             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);
102             ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getImageManager() throw (::com::sun::star::uno::RuntimeException);
103             ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getShortCutManager() throw (::com::sun::star::uno::RuntimeException);
104             ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getEventsManager() throw (::com::sun::star::uno::RuntimeException);
105 
106             // XUIConfigurationManagerImpl
107             sal_Bool isDefaultSettings( const ::rtl::OUString& ResourceURL ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
108             ::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);
109 
110             // XUIConfigurationPersistence
111             void reload() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
112             void store() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
113             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);
114             sal_Bool isModified() throw (::com::sun::star::uno::RuntimeException);
115             sal_Bool isReadOnly() throw (::com::sun::star::uno::RuntimeException);
116 
117             // XUIConfigurationStorage
118             void setStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& Storage ) throw (::com::sun::star::uno::RuntimeException);
119             sal_Bool hasStorage() throw (::com::sun::star::uno::RuntimeException);
120 
121             enum Layer
122             {
123                 LAYER_DEFAULT,
124                 LAYER_USERDEFINED,
125                 LAYER_COUNT
126             };
127 
128             enum NotifyOp
129             {
130                 NotifyOp_Remove,
131                 NotifyOp_Insert,
132                 NotifyOp_Replace
133             };
134 
135             struct UIElementInfo
136             {
UIElementInfoframework::UIConfigurationManagerImpl::UIElementInfo137                 UIElementInfo( const rtl::OUString& rResourceURL, const rtl::OUString& rUIName ) :
138                     aResourceURL( rResourceURL), aUIName( rUIName ) {}
139                 rtl::OUString   aResourceURL;
140                 rtl::OUString   aUIName;
141             };
142 
143             struct UIElementData
144             {
UIElementDataframework::UIConfigurationManagerImpl::UIElementData145                 UIElementData() : bModified( false ), bDefault( true ), bDefaultNode( true ) {};
146 
147                 rtl::OUString aResourceURL;
148                 rtl::OUString aName;
149                 bool          bModified;        // has been changed since last storing
150                 bool          bDefault;         // default settings
151                 bool          bDefaultNode;     // this is a default layer element data
152                 com::sun::star::uno::Reference< com::sun::star::container::XIndexAccess > xSettings;
153             };
154 
155 		    struct UIElementType;
156             friend struct UIElementType;
157 		    typedef ::std::hash_map< rtl::OUString, UIElementData, rtl::OUStringHash, ::std::equal_to< rtl::OUString > > UIElementDataHashMap;
158 
159             struct UIElementType
160             {
UIElementTypeframework::UIConfigurationManagerImpl::UIElementType161                 UIElementType() : bModified( false ),
162                                   bLoaded( false ),
163                                   bDefaultLayer( false ),
164                                   nElementType( ::com::sun::star::ui::UIElementType::UNKNOWN ) {}
165 
166 
167                 bool                                                              bModified;
168                 bool                                                              bLoaded;
169                 bool                                                              bDefaultLayer;
170                 sal_Int16                                                         nElementType;
171                 UIElementDataHashMap                                              aElementsHashMap;
172                 com::sun::star::uno::Reference< com::sun::star::embed::XStorage > xStorage;
173             };
174 
175             typedef ::std::vector< UIElementType > UIElementTypesVector;
176             typedef ::std::vector< ::com::sun::star::ui::ConfigurationEvent > ConfigEventNotifyContainer;
177             typedef ::std::hash_map< rtl::OUString, UIElementInfo, rtl::OUStringHash, ::std::equal_to< rtl::OUString > > UIElementInfoHashMap;
178 
179             // private methods
180             void            impl_Initialize();
181             void            implts_notifyContainerListener( const ::com::sun::star::ui::ConfigurationEvent& aEvent, NotifyOp eOp );
182             void            impl_fillSequenceWithElementTypeInfo( UIElementInfoHashMap& aUIElementInfoCollection, sal_Int16 nElementType );
183             void            impl_preloadUIElementTypeList( Layer eLayer, sal_Int16 nElementType );
184             UIElementData*  impl_findUIElementData( const rtl::OUString& aResourceURL, sal_Int16 nElementType, bool bLoad = true );
185             void            impl_requestUIElementData( sal_Int16 nElementType, Layer eLayer, UIElementData& aUIElementData );
186             void            impl_storeElementTypeData( com::sun::star::uno::Reference< com::sun::star::embed::XStorage > xStorage, UIElementType& rElementType, bool bResetModifyState = true );
187             void            impl_resetElementTypeData( UIElementType& rUserElementType, UIElementType& rDefaultElementType, ConfigEventNotifyContainer& rRemoveNotifyContainer, ConfigEventNotifyContainer& rReplaceNotifyContainer );
188             void            impl_reloadElementTypeData( UIElementType& rUserElementType, UIElementType& rDefaultElementType, ConfigEventNotifyContainer& rRemoveNotifyContainer, ConfigEventNotifyContainer& rReplaceNotifyContainer );
189 
190             UIElementTypesVector                                                            m_aUIElements[LAYER_COUNT];
191             PresetHandler*                                                                  m_pStorageHandler[::com::sun::star::ui::UIElementType::COUNT];
192             com::sun::star::uno::Reference< com::sun::star::embed::XStorage >               m_xDefaultConfigStorage;
193             com::sun::star::uno::Reference< com::sun::star::embed::XStorage >               m_xUserConfigStorage;
194             com::sun::star::uno::Reference< com::sun::star::uno::XInterface >               m_xOwner;
195             bool                                                                            m_bUseDefault;
196             bool                                                                            m_bReadOnly;
197             bool                                                                            m_bInitialized;
198             bool                                                                            m_bModified;
199             bool                                                                            m_bConfigRead;
200             bool                                                                            m_bDisposed;
201             rtl::OUString                                                                   m_aXMLPostfix;
202             rtl::OUString                                                                   m_aPropUIName;
203             rtl::OUString                                                                   m_aPropResourceURL;
204             rtl::OUString                                                                   m_aModuleIdentifier;
205             rtl::OUString                                                                   m_aModuleShortName;
206             com::sun::star::uno::Reference< com::sun::star::embed::XTransactedObject >      m_xUserRootCommit;
207             com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >    m_xServiceManager;
208             ::cppu::OMultiTypeInterfaceContainerHelper                                      m_aListenerContainer;   /// container for ALL Listener
209             com::sun::star::uno::Reference< com::sun::star::uno::XInterface >               m_xAccConfig;
210             com::sun::star::uno::Reference< com::sun::star::lang::XComponent >              m_xModuleImageManager;
211    };
212 }
213 
214 #endif // __FRAMEWORK_UICONFIGURATION_UICONFIGMANAGERIMPL_HXX_
215