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