1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SD_FRAMEWORK_RESOURCE_MANAGER_HXX
29 #define SD_FRAMEWORK_RESOURCE_MANAGER_HXX
30 
31 #include "MutexOwner.hxx"
32 #include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp>
33 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
34 #include <com/sun/star/frame/XController.hpp>
35 #include <cppuhelper/compbase1.hxx>
36 #include <boost/scoped_ptr.hpp>
37 
38 namespace css = ::com::sun::star;
39 
40 namespace {
41 
42 typedef ::cppu::WeakComponentImplHelper1 <
43     ::com::sun::star::drawing::framework::XConfigurationChangeListener
44     > ResourceManagerInterfaceBase;
45 
46 } // end of anonymous namespace.
47 
48 
49 namespace sd { namespace framework {
50 
51 /** Manage the activation state of one resource depending on the view in the
52     center pane.  The ResourceManager remembers in which configuration to
53     activate and in which to deactivate the resource.  When the resource is
54     deactivated or activated manually by the user then the ResourceManager
55     detects this and remembers it for the future.
56 */
57 class ResourceManager
58     : private sd::MutexOwner,
59       public ResourceManagerInterfaceBase
60 {
61 public:
62     ResourceManager (
63         const ::com::sun::star::uno::Reference<
64             ::com::sun::star::frame::XController>& rxController,
65         const ::com::sun::star::uno::Reference<
66             ::com::sun::star::drawing::framework::XResourceId>& rxResourceId);
67     virtual ~ResourceManager (void);
68 
69     /** Remember the given URL as one of a center pane view for which to
70         activate the resource managed by the called object.
71     */
72     void AddActiveMainView (const ::rtl::OUString& rsMainViewURL);
73 
74     virtual void SAL_CALL disposing (void);
75 
76     /** Allow the ResourceManager to make resource activation or
77         deactivation requests.
78     */
79     void Enable (void);
80 
81     /** Disable the resource management.  When called, the ResourceManager
82         requests the resource to be deactivated.  Until enabled again it
83         does not make any further requests for resource activation or
84         deactivation.
85 
86         Call this for example to hide resources in read-only mode.
87     */
88     void Disable (void);
89 
90     // XConfigurationChangeListener
91 
92     virtual void SAL_CALL notifyConfigurationChange (
93         const com::sun::star::drawing::framework::ConfigurationChangeEvent& rEvent)
94         throw (com::sun::star::uno::RuntimeException);
95 
96     // XEventListener
97 
98     virtual void SAL_CALL disposing (
99         const com::sun::star::lang::EventObject& rEvent)
100         throw (com::sun::star::uno::RuntimeException);
101 
102 protected:
103     ::com::sun::star::uno::Reference<com::sun::star::drawing::framework::XConfigurationController>
104         mxConfigurationController;
105 
106 private:
107     class MainViewContainer;
108     ::boost::scoped_ptr<MainViewContainer> mpActiveMainViewContainer;
109 
110     /// The resource managed by this class.
111     css::uno::Reference<css::drawing::framework::XResourceId> mxResourceId;
112 
113     /// The anchor of the main view.
114     css::uno::Reference<css::drawing::framework::XResourceId> mxMainViewAnchorId;
115 
116     ::rtl::OUString msCurrentMainViewURL;
117     bool mbIsEnabled;
118 
119     void HandleMainViewSwitch (
120         const ::rtl::OUString& rsViewURL,
121         const ::com::sun::star::uno::Reference<
122             com::sun::star::drawing::framework::XConfiguration>& rxConfiguration,
123         const bool bIsActivated);
124     void HandleResourceRequest(
125         bool bActivation,
126         const ::com::sun::star::uno::Reference<
127             com::sun::star::drawing::framework::XConfiguration>& rxConfiguration);
128     void UpdateForMainViewShell (void);
129 };
130 
131 } } // end of namespace sd::framework
132 
133 #endif
134