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 #ifndef SFX_SIDEBAR_RESOURCE_MANAGER_HXX
23 #define SFX_SIDEBAR_RESOURCE_MANAGER_HXX
24 
25 #include "DeckDescriptor.hxx"
26 #include "PanelDescriptor.hxx"
27 #include "sfx2/sidebar/EnumContext.hxx"
28 #include <unotools/confignode.hxx>
29 #include <com/sun/star/frame/XFrame.hpp>
30 #include <set>
31 #include <boost/shared_ptr.hpp>
32 
33 
34 namespace css = ::com::sun::star;
35 namespace cssu = ::com::sun::star::uno;
36 
37 namespace sfx2 { namespace sidebar {
38 
39 /** Read the content of the Sidebar.xcu file and provide access
40     methods so that the sidebar can easily decide which content panels
41     to display for a certain context.
42 */
43 class ResourceManager
44 {
45 public:
46     static ResourceManager& Instance (void);
47 
48     const DeckDescriptor* GetBestMatchingDeck (
49         const EnumContext& rContext,
50         const cssu::Reference<css::frame::XFrame>& rxFrame);
51 
52     const DeckDescriptor* GetDeckDescriptor (
53         const ::rtl::OUString& rsDeckId) const;
54     const PanelDescriptor* GetPanelDescriptor (
55         const ::rtl::OUString& rsPanelId) const;
56 
57     /** Excluded or include a deck from being displayed in the tab
58         bar.
59         Note that this value is not persistent.
60         The flag can not be set directly at a DeckDescriptor object
61         because the ResourceManager gives access to to them only
62         read-only.
63     */
64     void SetIsDeckEnabled (
65         const ::rtl::OUString& rsDeckId,
66         const bool bIsEnabled);
67 
68     typedef ::std::vector<rtl::OUString> IdContainer;
69 
70     const IdContainer& GetMatchingDecks (
71         IdContainer& rDeckDescriptors,
72         const EnumContext& rContext,
73         const cssu::Reference<css::frame::XFrame>& rxFrame);
74 
75     const IdContainer& GetMatchingPanels (
76         IdContainer& rPanelDescriptors,
77         const EnumContext& rContext,
78         const ::rtl::OUString& rsDeckId,
79         const cssu::Reference<css::frame::XFrame>& rxFrame);
80 
81     static ::rtl::OUString GetModuleName (
82         const cssu::Reference<css::frame::XFrame>& rxFrame);
83 
84 private:
85     ResourceManager (void);
86     ~ResourceManager (void);
87     class Deleter;
88     friend class Deleter;
89 
90     typedef ::std::vector<DeckDescriptor> DeckContainer;
91     DeckContainer maDecks;
92     typedef ::std::vector<PanelDescriptor> PanelContainer;
93     PanelContainer maPanels;
94     mutable ::std::set<rtl::OUString> maProcessedApplications;
95 
96     void ReadDeckList (void);
97     void ReadPanelList (void);
98     void ReadContextList (
99         const ::utl::OConfigurationNode& rNode,
100         ::std::vector<EnumContext>& rContextContainer) const;
101     void ReadLegacyAddons (
102         const cssu::Reference<css::frame::XFrame>& rxFrame);
103     ::utl::OConfigurationTreeRoot GetLegacyAddonRootNode (
104         const ::rtl::OUString& rsModuleName) const;
105     void GetToolPanelNodeNames (
106         ::std::vector<rtl::OUString>& rMatchingNames,
107         const ::utl::OConfigurationTreeRoot aRoot) const;
108 };
109 
110 
111 } } // end of namespace sfx2::sidebar
112 
113 #endif
114