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     static ::rtl::OUString GetModuleName (
106         const cssu::Reference<css::frame::XFrame>& rxFrame);
107 
108 private:
109     ResourceManager (void);
110     ~ResourceManager (void);
111     class Deleter;
112     friend class Deleter;
113 
114     typedef ::std::vector<DeckDescriptor> DeckContainer;
115     DeckContainer maDecks;
116     typedef ::std::vector<PanelDescriptor> PanelContainer;
117     PanelContainer maPanels;
118     mutable ::std::set<rtl::OUString> maProcessedApplications;
119 
120     void ReadDeckList (void);
121     void ReadPanelList (void);
122     void ReadContextList (
123         const ::utl::OConfigurationNode& rNode,
124         ContextList& rContextList,
125         const ::rtl::OUString& rsDefaultMenuCommand) const;
126     void ReadLegacyAddons (
127         const cssu::Reference<css::frame::XFrame>& rxFrame);
128     ::utl::OConfigurationTreeRoot GetLegacyAddonRootNode (
129         const ::rtl::OUString& rsModuleName) const;
130     void GetToolPanelNodeNames (
131         ::std::vector<rtl::OUString>& rMatchingNames,
132         const ::utl::OConfigurationTreeRoot aRoot) const;
133     bool IsDeckEnabled (
134         const ::rtl::OUString& rsDeckId,
135         const Context& rContext,
136         const cssu::Reference<css::frame::XFrame>& rxFrame) const;
137 };
138 
139 
140 } } // end of namespace sfx2::sidebar
141 
142 #endif
143