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