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_UIFACTORY_FACTORYCONFIGURATION_HXX_
29 #define __FRAMEWORK_UIFACTORY_FACTORYCONFIGURATION_HXX_
30 #include <threadhelp/threadhelpbase.hxx>
31 #include <macros/generic.hxx>
32 #include <macros/xinterface.hxx>
33 #include <macros/xtypeprovider.hxx>
34 #include <macros/xserviceinfo.hxx>
35 #include <stdtypes.h>
36 
37 //_________________________________________________________________________________________________________________
38 //	interface includes
39 //_________________________________________________________________________________________________________________
40 #include <com/sun/star/lang/XServiceInfo.hpp>
41 #include <com/sun/star/lang/XTypeProvider.hpp>
42 #include <com/sun/star/container/XContainerListener.hpp>
43 #include <com/sun/star/container/XNameAccess.hpp>
44 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
45 #include <com/sun/star/frame/XUIControllerRegistration.hpp>
46 
47 //_________________________________________________________________________________________________________________
48 //	other includes
49 //_________________________________________________________________________________________________________________
50 #include <cppuhelper/implbase1.hxx>
51 #include <rtl/ustring.hxx>
52 
53 //_________________________________________________________________________________________________________________
54 //	Namespace
55 //_________________________________________________________________________________________________________________
56 //
57 
58 namespace framework
59 {
60 
61 //*****************************************************************************************************************
62 //	Configuration access class for PopupMenuControllerFactory implementation
63 //*****************************************************************************************************************
64 class ConfigurationAccess_ControllerFactory : // interfaces
65                                                     private ThreadHelpBase,
66                                                     public  ::cppu::WeakImplHelper1< ::com::sun::star::container::XContainerListener>
67 {
68 public:
69                     ConfigurationAccess_ControllerFactory( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager,const ::rtl::OUString& _sRoot,bool _bAskValue = false );
70     virtual       ~ConfigurationAccess_ControllerFactory();
71 
72     void          readConfigurationData();
73     void          updateConfigurationData();
74 
75     rtl::OUString getServiceFromCommandModule( const rtl::OUString& rCommandURL, const rtl::OUString& rModule ) const;
76     rtl::OUString getValueFromCommandModule( const rtl::OUString& rCommandURL, const rtl::OUString& rModule ) const;
77     void          addServiceToCommandModule( const rtl::OUString& rCommandURL, const rtl::OUString& rModule, const rtl::OUString& rServiceSpecifier );
78     void          removeServiceFromCommandModule( const rtl::OUString& rCommandURL, const rtl::OUString& rModule );
79     inline bool   hasValue() const { return m_bAskValue; }
80 
81     // container.XContainerListener
82     virtual void SAL_CALL elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
83     virtual void SAL_CALL elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
84     virtual void SAL_CALL elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
85 
86     // lang.XEventListener
87     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
88 
89 private:
90     struct ControllerInfo
91     {
92         rtl::OUString m_aImplementationName;
93         rtl::OUString m_aValue;
94         ControllerInfo(const ::rtl::OUString& _aImplementationName,const ::rtl::OUString& _aValue) : m_aImplementationName(_aImplementationName),m_aValue(_aValue){}
95         ControllerInfo(){}
96     };
97     class MenuControllerMap : public std::hash_map< rtl::OUString,
98                                                          ControllerInfo,
99                                                          OUStringHashCode,
100                                                          ::std::equal_to< ::rtl::OUString > >
101     {
102         inline void free()
103         {
104             MenuControllerMap().swap( *this );
105         }
106     };
107 
108     sal_Bool impl_getElementProps( const ::com::sun::star::uno::Any& aElement, rtl::OUString& aCommand, rtl::OUString& aModule, rtl::OUString& aServiceSpecifier,rtl::OUString& aValue ) const;
109 
110     rtl::OUString                     m_aPropCommand;
111     rtl::OUString                     m_aPropModule;
112     rtl::OUString                     m_aPropController;
113     rtl::OUString                     m_aPropValue;
114     rtl::OUString                     m_sRoot;
115     MenuControllerMap                 m_aMenuControllerMap;
116     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >    m_xServiceManager;
117     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >    m_xConfigProvider;
118     ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >        m_xConfigAccess;
119     sal_Bool                          m_bConfigAccessInitialized;
120     bool                              m_bAskValue;
121 };
122 
123 } // namespace framework
124 #endif // __FRAMEWORK_UIFACTORY_FACTORYCONFIGURATION_HXX_
125