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 "Context.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 class Context;
40 class ContextList;
41 
42 /** Read the content of the Sidebar.xcu file and provide access
43     methods so that the sidebar can easily decide which content panels
44     to display for a certain context.
45 */
46 class ResourceManager
47 {
48 public:
49     static ResourceManager& Instance (void);
50 
51     const DeckDescriptor* GetBestMatchingDeck (
52         const Context& rContext,
53         const cssu::Reference<css::frame::XFrame>& rxFrame);
54 
55     const DeckDescriptor* GetDeckDescriptor (
56         const ::rtl::OUString& rsDeckId) const;
57     const PanelDescriptor* GetPanelDescriptor (
58         const ::rtl::OUString& rsPanelId) const;
59 
60     /** Excluded or include a deck from being displayed in the tab
61         bar.
62         Note that this value is not persistent.
63         The flag can not be set directly at a DeckDescriptor object
64         because the ResourceManager gives access to to them only
65         read-only.
66     */
67     void SetIsDeckEnabled (
68         const ::rtl::OUString& rsDeckId,
69         const bool bIsEnabled);
70 
71     typedef ::std::vector<rtl::OUString> IdContainer;
72     class PanelContextDescriptor
73     {
74     public:
75         ::rtl::OUString msId;
76         ::rtl::OUString msMenuCommand;
77         bool mbIsInitiallyVisible;
78     };
79     typedef ::std::vector<PanelContextDescriptor> PanelContextDescriptorContainer;
80 
81     const IdContainer& GetMatchingDecks (
82         IdContainer& rDeckDescriptors,
83         const Context& rContext,
84         const cssu::Reference<css::frame::XFrame>& rxFrame);
85 
86     const PanelContextDescriptorContainer& GetMatchingPanels (
87         PanelContextDescriptorContainer& rPanelDescriptors,
88         const Context& rContext,
89         const ::rtl::OUString& rsDeckId,
90         const cssu::Reference<css::frame::XFrame>& rxFrame);
91 
92     static ::rtl::OUString GetModuleName (
93         const cssu::Reference<css::frame::XFrame>& rxFrame);
94 
95 private:
96     ResourceManager (void);
97     ~ResourceManager (void);
98     class Deleter;
99     friend class Deleter;
100 
101     typedef ::std::vector<DeckDescriptor> DeckContainer;
102     DeckContainer maDecks;
103     typedef ::std::vector<PanelDescriptor> PanelContainer;
104     PanelContainer maPanels;
105     mutable ::std::set<rtl::OUString> maProcessedApplications;
106 
107     void ReadDeckList (void);
108     void ReadPanelList (void);
109     void ReadContextList (
110         const ::utl::OConfigurationNode& rNode,
111         ContextList& rContextList,
112         const ::rtl::OUString& rsDefaultMenuCommand) const;
113     void ReadLegacyAddons (
114         const cssu::Reference<css::frame::XFrame>& rxFrame);
115     ::utl::OConfigurationTreeRoot GetLegacyAddonRootNode (
116         const ::rtl::OUString& rsModuleName) const;
117     void GetToolPanelNodeNames (
118         ::std::vector<rtl::OUString>& rMatchingNames,
119         const ::utl::OConfigurationTreeRoot aRoot) const;
120 };
121 
122 
123 } } // end of namespace sfx2::sidebar
124 
125 #endif
126