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_UICONFIGMANAGER_HXX_
25 #define __FRAMEWORK_UICONFIGURATION_UICONFIGMANAGER_HXX_
26 
27 
28 /** Attention: stl headers must(!) be included at first. Otherwise 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 <threadhelp/threadhelpbase.hxx>
39 #include <macros/generic.hxx>
40 #include <macros/xinterface.hxx>
41 #include <macros/xtypeprovider.hxx>
42 #include <macros/xserviceinfo.hxx>
43 #include <stdtypes.h>
44 #include <uiconfiguration/imagemanager.hxx>
45 
46 //_________________________________________________________________________________________________________________
47 //	interface includes
48 //_________________________________________________________________________________________________________________
49 #include <com/sun/star/lang/XServiceInfo.hpp>
50 #include <com/sun/star/lang/XTypeProvider.hpp>
51 #include <com/sun/star/lang/XComponent.hpp>
52 #include <com/sun/star/ui/XUIConfiguration.hpp>
53 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
54 
55 #ifndef _COM_SUN_STAR_UI_XUICONFIGURATIONSTORGAE_HPP_
56 #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
57 #endif
58 #include <com/sun/star/ui/XUIConfigurationManager.hpp>
59 #include <com/sun/star/ui/ConfigurationEvent.hpp>
60 #include <com/sun/star/ui/UIElementType.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 UIConfigurationManager :   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::ui::XUIConfiguration             ,
77                                      public ::com::sun::star::ui::XUIConfigurationManager      ,
78                                      public ::com::sun::star::ui::XUIConfigurationPersistence  ,
79                                      public ::com::sun::star::ui::XUIConfigurationStorage      ,
80                                      private ThreadHelpBase						,	// Struct for right initialization of mutex member! Must be first of baseclasses.
81 							         public ::cppu::OWeakObject
82     {
83         public:
84             //  XInterface, XTypeProvider, XServiceInfo
85             FWK_DECLARE_XINTERFACE
86             FWK_DECLARE_XTYPEPROVIDER
87             DECLARE_XSERVICEINFO
88 
89             UIConfigurationManager( com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > xServiceManager );
90             virtual ~UIConfigurationManager();
91 
92             // XComponent
93             virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException);
94             virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
95             virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
96 
97             // XUIConfiguration
98             virtual void SAL_CALL addConfigurationListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
99             virtual void SAL_CALL removeConfigurationListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
100 
101             // XUIConfigurationManager
102             virtual void SAL_CALL reset() throw (::com::sun::star::uno::RuntimeException);
103             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);
104             virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > SAL_CALL createSettings(  ) throw (::com::sun::star::uno::RuntimeException);
105             virtual sal_Bool SAL_CALL hasSettings( const ::rtl::OUString& ResourceURL ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
106             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);
107             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);
108             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);
109             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);
110             virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getImageManager() throw (::com::sun::star::uno::RuntimeException);
111             virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getShortCutManager() throw (::com::sun::star::uno::RuntimeException);
112             virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getEventsManager() throw (::com::sun::star::uno::RuntimeException);
113 
114             // XUIConfigurationPersistence
115             virtual void SAL_CALL reload() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
116             virtual void SAL_CALL store() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
117             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);
118             virtual sal_Bool SAL_CALL isModified() throw (::com::sun::star::uno::RuntimeException);
119             virtual sal_Bool SAL_CALL isReadOnly() throw (::com::sun::star::uno::RuntimeException);
120 
121             // XUIConfigurationStorage
122             virtual void SAL_CALL setStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& Storage ) throw (::com::sun::star::uno::RuntimeException);
123             virtual sal_Bool SAL_CALL hasStorage() throw (::com::sun::star::uno::RuntimeException);
124 
125         private:
126             // private data types
127             enum NotifyOp
128             {
129                 NotifyOp_Remove,
130                 NotifyOp_Insert,
131                 NotifyOp_Replace
132             };
133 
134             struct UIElementInfo
135             {
UIElementInfoframework::UIConfigurationManager::UIElementInfo136                 UIElementInfo( const rtl::OUString& rResourceURL, const rtl::OUString& rUIName ) :
137                     aResourceURL( rResourceURL), aUIName( rUIName ) {}
138                 rtl::OUString   aResourceURL;
139                 rtl::OUString   aUIName;
140             };
141 
142             struct UIElementData
143             {
UIElementDataframework::UIConfigurationManager::UIElementData144                 UIElementData() : bModified( false ), bDefault( true ) {};
145 
146                 rtl::OUString aResourceURL;
147                 rtl::OUString aName;
148                 bool          bModified;        // has been changed since last storing
149                 bool          bDefault;         // default settings
150                 com::sun::star::uno::Reference< com::sun::star::container::XIndexAccess > xSettings;
151             };
152 
153 		    struct UIElementType;
154             friend struct UIElementType;
155 		    typedef ::std::hash_map< rtl::OUString, UIElementData, rtl::OUStringHash, ::std::equal_to< rtl::OUString > > UIElementDataHashMap;
156 
157             struct UIElementType
158             {
UIElementTypeframework::UIConfigurationManager::UIElementType159                 UIElementType() : bModified( false ),
160                                   bLoaded( false ),
161                                   bDefaultLayer( false ),
162                                   nElementType( ::com::sun::star::ui::UIElementType::UNKNOWN ) {}
163 
164 
165                 bool                                                              bModified;
166                 bool                                                              bLoaded;
167                 bool                                                              bDefaultLayer;
168                 sal_Int16                                                         nElementType;
169                 UIElementDataHashMap                                              aElementsHashMap;
170                 com::sun::star::uno::Reference< com::sun::star::embed::XStorage > xStorage;
171             };
172 
173             typedef ::std::vector< UIElementType > UIElementTypesVector;
174             typedef ::std::vector< ::com::sun::star::ui::ConfigurationEvent > ConfigEventNotifyContainer;
175             typedef ::std::hash_map< rtl::OUString, UIElementInfo, rtl::OUStringHash, ::std::equal_to< rtl::OUString > > UIElementInfoHashMap;
176 
177             // private methods
178             void            impl_Initialize();
179             void            implts_notifyContainerListener( const ::com::sun::star::ui::ConfigurationEvent& aEvent, NotifyOp eOp );
180             void            impl_fillSequenceWithElementTypeInfo( UIElementInfoHashMap& aUIElementInfoCollection, sal_Int16 nElementType );
181             void            impl_preloadUIElementTypeList( sal_Int16 nElementType );
182             UIElementData*  impl_findUIElementData( const rtl::OUString& aResourceURL, sal_Int16 nElementType, bool bLoad = true );
183             void            impl_requestUIElementData( sal_Int16 nElementType, UIElementData& aUIElementData );
184             void            impl_storeElementTypeData( com::sun::star::uno::Reference< com::sun::star::embed::XStorage >& xStorage, UIElementType& rElementType, bool bResetModifyState = true );
185             void            impl_resetElementTypeData( UIElementType& rDocElementType, ConfigEventNotifyContainer& rRemoveNotifyContainer );
186             void            impl_reloadElementTypeData( UIElementType& rDocElementType, ConfigEventNotifyContainer& rRemoveNotifyContainer, ConfigEventNotifyContainer& rReplaceNotifyContainer );
187 
188             UIElementTypesVector                                                            m_aUIElements;
189             com::sun::star::uno::Reference< com::sun::star::embed::XStorage >               m_xDocConfigStorage;
190             bool                                                                            m_bReadOnly;
191             bool                                                                            m_bInitialized;
192             bool                                                                            m_bModified;
193             bool                                                                            m_bConfigRead;
194             bool                                                                            m_bDisposed;
195             rtl::OUString                                                                   m_aXMLPostfix;
196             rtl::OUString                                                                   m_aPropUIName;
197             rtl::OUString                                                                   m_aPropResourceURL;
198             rtl::OUString                                                                   m_aModuleIdentifier;
199             com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >    m_xServiceManager;
200             ::cppu::OMultiTypeInterfaceContainerHelper                                      m_aListenerContainer;   /// container for ALL Listener
201             com::sun::star::uno::Reference< com::sun::star::lang::XComponent >              m_xImageManager;
202             com::sun::star::uno::Reference< com::sun::star::uno::XInterface >               m_xAccConfig;
203    };
204 }
205 
206 #endif // __FRAMEWORK_UICONFIGURATION_UICONFIGMANAGER_HXX_
207