1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_FRAMEWORK_INC_UIFACTORY_FACTORYCONFIGURATION_HXX
21 #define INCLUDED_FRAMEWORK_INC_UIFACTORY_FACTORYCONFIGURATION_HXX
22 
23 #include <com/sun/star/container/XContainerListener.hpp>
24 #include <com/sun/star/container/XNameAccess.hpp>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 
28 #include <cppuhelper/implbase.hxx>
29 #include <rtl/ustring.hxx>
30 #include <unordered_map>
31 
32 //  Namespace
33 
34 namespace framework
35 {
36 
37 //  Configuration access class for PopupMenuControllerFactory implementation
38 
39 class ConfigurationAccess_ControllerFactory : // interfaces
40                                                     public  ::cppu::WeakImplHelper< css::container::XContainerListener>
41 {
42 public:
43                     ConfigurationAccess_ControllerFactory( const css::uno::Reference< css::uno::XComponentContext >& rxContext, const OUString& _sRoot );
44     virtual       ~ConfigurationAccess_ControllerFactory() override;
45 
46     void          readConfigurationData();
47     void          updateConfigurationData();
48 
49     OUString getServiceFromCommandModule( const OUString& rCommandURL, const OUString& rModule ) const;
50     OUString getValueFromCommandModule( const OUString& rCommandURL, const OUString& rModule ) const;
51     void          addServiceToCommandModule( const OUString& rCommandURL, const OUString& rModule, const OUString& rServiceSpecifier );
52     void          removeServiceFromCommandModule( const OUString& rCommandURL, const OUString& rModule );
53 
54     // container.XContainerListener
55     virtual void SAL_CALL elementInserted( const css::container::ContainerEvent& Event ) override;
56     virtual void SAL_CALL elementRemoved( const css::container::ContainerEvent& Event ) override;
57     virtual void SAL_CALL elementReplaced( const css::container::ContainerEvent& Event ) override;
58 
59     // lang.XEventListener
60     virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
61 
62 private:
63     struct ControllerInfo
64     {
65         OUString m_aImplementationName;
66         OUString m_aValue;
ControllerInfoframework::ConfigurationAccess_ControllerFactory::ControllerInfo67         ControllerInfo(const OUString& _aImplementationName,const OUString& _aValue) : m_aImplementationName(_aImplementationName),m_aValue(_aValue){}
ControllerInfoframework::ConfigurationAccess_ControllerFactory::ControllerInfo68         ControllerInfo(){}
69     };
70     class MenuControllerMap : public std::unordered_map< OUString,
71                                                          ControllerInfo >
72     {
73     };
74 
75     bool impl_getElementProps( const css::uno::Any& aElement, OUString& aCommand, OUString& aModule, OUString& aServiceSpecifier,OUString& aValue ) const;
76 
77     mutable osl::Mutex           m_mutex;
78     OUString                     m_aPropCommand;
79     OUString                     m_aPropModule;
80     OUString                     m_aPropController;
81     OUString                     m_aPropValue;
82     OUString                     m_sRoot;
83     MenuControllerMap            m_aMenuControllerMap;
84     css::uno::Reference< css::lang::XMultiServiceFactory >    m_xConfigProvider;
85     css::uno::Reference< css::container::XNameAccess >        m_xConfigAccess;
86     css::uno::Reference< css::container::XContainerListener > m_xConfigAccessListener;
87     bool                          m_bConfigAccessInitialized;
88 };
89 
90 } // namespace framework
91 #endif // INCLUDED_FRAMEWORK_INC_UIFACTORY_FACTORYCONFIGURATION_HXX
92 
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
94