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* GetDeckDescriptor (
52         const ::rtl::OUString& rsDeckId) const;
53     const PanelDescriptor* GetPanelDescriptor (
54         const ::rtl::OUString& rsPanelId) const;
55 
56     /** Excluded or include a deck from being displayed in the tab
57         bar.
58         Note that this value is not persistent.
59         The flag can not be set directly at a DeckDescriptor object
60         because the ResourceManager gives access to to them only
61         read-only.
62     */
63     void SetIsDeckEnabled (
64         const ::rtl::OUString& rsDeckId,
65         const bool bIsEnabled);
66 
67     class DeckContextDescriptor
68     {
69     public:
70         ::rtl::OUString msId;
71         bool mbIsEnabled;
72     };
73     typedef ::std::vector<DeckContextDescriptor> DeckContextDescriptorContainer;
74 
75     class PanelContextDescriptor
76     {
77     public:
78         ::rtl::OUString msId;
79         ::rtl::OUString msMenuCommand;
80         bool mbIsInitiallyVisible;
81         bool mbShowForReadOnlyDocuments;
82     };
83     typedef ::std::vector<PanelContextDescriptor> PanelContextDescriptorContainer;
84 
85     const DeckContextDescriptorContainer& GetMatchingDecks (
86         DeckContextDescriptorContainer& rDeckDescriptors,
87         const Context& rContext,
88         const bool bIsDocumentReadOnly,
89         const cssu::Reference<css::frame::XFrame>& rxFrame);
90 
91     const PanelContextDescriptorContainer& GetMatchingPanels (
92         PanelContextDescriptorContainer& rPanelDescriptors,
93         const Context& rContext,
94         const ::rtl::OUString& rsDeckId,
95         const cssu::Reference<css::frame::XFrame>& rxFrame);
96 
97     /** Remember the expansions state per panel and context.
98         This is not persistent past application end.
99     */
100     void StorePanelExpansionState (
101         const ::rtl::OUString& rsPanelId,
102         const bool bExpansionState,
103         const Context& rContext);
104 
105 private:
106     ResourceManager (void);
107     ~ResourceManager (void);
108     class Deleter;
109     friend class Deleter;
110 
111     typedef ::std::vector<DeckDescriptor> DeckContainer;
112     DeckContainer maDecks;
113     typedef ::std::vector<PanelDescriptor> PanelContainer;
114     PanelContainer maPanels;
115     mutable ::std::set<rtl::OUString> maProcessedApplications;
116 
117     void ReadDeckList (void);
118     void ReadPanelList (void);
119     void ReadContextList (
120         const ::utl::OConfigurationNode& rNode,
121         ContextList& rContextList,
122         const ::rtl::OUString& rsDefaultMenuCommand) const;
123     void ReadLegacyAddons (
124         const cssu::Reference<css::frame::XFrame>& rxFrame);
125     ::utl::OConfigurationTreeRoot GetLegacyAddonRootNode (
126         const ::rtl::OUString& rsModuleName) const;
127     void GetToolPanelNodeNames (
128         ::std::vector<rtl::OUString>& rMatchingNames,
129         const ::utl::OConfigurationTreeRoot aRoot) const;
130     bool IsDeckEnabled (
131         const ::rtl::OUString& rsDeckId,
132         const Context& rContext,
133         const cssu::Reference<css::frame::XFrame>& rxFrame) const;
134 };
135 
136 
137 } } // end of namespace sfx2::sidebar
138 
139 #endif
140