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 SDEXT_PRESENTER_VIEW_FACTORY_HXX
29 #define SDEXT_PRESENTER_VIEW_FACTORY_HXX
30 
31 #include "PresenterController.hxx"
32 #include <cppuhelper/compbase1.hxx>
33 #include <cppuhelper/basemutex.hxx>
34 #include <com/sun/star/lang/XInitialization.hpp>
35 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
36 #include <com/sun/star/drawing/framework/XResourceFactory.hpp>
37 #include <com/sun/star/drawing/framework/XView.hpp>
38 #include <com/sun/star/frame/XFrame.hpp>
39 #include <com/sun/star/uno/XComponentContext.hpp>
40 #include <rtl/ref.hxx>
41 #include <boost/scoped_ptr.hpp>
42 
43 namespace css = ::com::sun::star;
44 
45 namespace sdext { namespace presenter {
46 
47 class PresenterPaneContainer;
48 
49 namespace {
50     typedef ::cppu::WeakComponentImplHelper1 <
51         css::drawing::framework::XResourceFactory
52     > PresenterViewFactoryInterfaceBase;
53 }
54 
55 /** Base class for presenter views that allows the view factory to store
56     them in a cache and reuse deactivated views.
57 */
58 class CachablePresenterView
59 {
60 public:
61     virtual void ActivatePresenterView (void);
62 
63     /** Called when the view is put into a cache.  The view must not paint
64         itself while being deactive.
65     */
66     virtual void DeactivatePresenterView (void);
67 
68     /** Called before the view is disposed.  This gives the view the
69         oportunity to trigger actions that may lead to (synchronous)
70         callbacks that do not result in DisposedExceptions.
71     */
72     virtual void ReleaseView (void);
73 
74 protected:
75     bool mbIsPresenterViewActive;
76 
77     CachablePresenterView (void);
78 };
79 
80 
81 
82 
83 /** Factory of the presenter screen specific views.  The supported set of
84     views includes:
85         a life view of the current slide,
86         a static preview of the next slide,
87         the notes of the current slide,
88         a tool bar
89 */
90 class PresenterViewFactory
91     : public ::cppu::BaseMutex,
92       public PresenterViewFactoryInterfaceBase
93 {
94 public:
95     static const ::rtl::OUString msCurrentSlidePreviewViewURL;
96     static const ::rtl::OUString msNextSlidePreviewViewURL;
97     static const ::rtl::OUString msNotesViewURL;
98     static const ::rtl::OUString msToolBarViewURL;
99     static const ::rtl::OUString msSlideSorterURL;
100     static const ::rtl::OUString msHelpViewURL;
101 
102     /** Create a new instance of this class and register it as resource
103         factory in the drawing framework of the given controller.
104         This registration keeps it alive.  When the drawing framework is
105         shut down and releases its reference to the factory then the factory
106         is destroyed.
107     */
108     static css::uno::Reference<css::drawing::framework::XResourceFactory> Create (
109         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
110         const css::uno::Reference<css::frame::XController>& rxController,
111         const ::rtl::Reference<PresenterController>& rpPresenterController);
112     virtual ~PresenterViewFactory (void);
113 
114     static ::rtl::OUString getImplementationName_static (void);
115     static css::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static (void);
116     static css::uno::Reference<css::uno::XInterface> Create(
117         const css::uno::Reference<css::uno::XComponentContext>& rxContext)
118         SAL_THROW((css::uno::Exception));
119 
120     virtual void SAL_CALL disposing (void)
121         throw (css::uno::RuntimeException);
122 
123 
124     // XResourceFactory
125 
126     virtual css::uno::Reference<css::drawing::framework::XResource>
127         SAL_CALL createResource (
128             const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId)
129         throw (css::uno::RuntimeException);
130 
131     virtual void SAL_CALL
132         releaseResource (
133             const css::uno::Reference<css::drawing::framework::XResource>& rxPane)
134         throw (css::uno::RuntimeException);
135 
136 private:
137     css::uno::Reference<css::uno::XComponentContext> mxComponentContext;
138     css::uno::Reference<css::drawing::framework::XConfigurationController>
139         mxConfigurationController;
140     css::uno::WeakReference<css::frame::XController> mxControllerWeak;
141     ::rtl::Reference<PresenterController> mpPresenterController;
142     typedef ::std::pair<css::uno::Reference<css::drawing::framework::XView>,
143         css::uno::Reference<css::drawing::framework::XPane> > ViewResourceDescriptor;
144     typedef ::std::map<rtl::OUString, ViewResourceDescriptor> ResourceContainer;
145     ::boost::scoped_ptr<ResourceContainer> mpResourceCache;
146 
147     PresenterViewFactory (
148         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
149         const css::uno::Reference<css::frame::XController>& rxController,
150         const ::rtl::Reference<PresenterController>& rpPresenterController);
151 
152     void Register (const css::uno::Reference<css::frame::XController>& rxController);
153 
154     css::uno::Reference<css::drawing::framework::XView> CreateSlideShowView(
155         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId) const;
156 
157     css::uno::Reference<css::drawing::framework::XView> CreateSlidePreviewView(
158         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId,
159         const css::uno::Reference<css::drawing::framework::XPane>& rxPane) const;
160 
161     css::uno::Reference<css::drawing::framework::XView> CreateToolBarView(
162         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId) const;
163 
164     css::uno::Reference<css::drawing::framework::XView> CreateNotesView(
165         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId,
166         const css::uno::Reference<css::drawing::framework::XPane>& rxPane) const;
167 
168     css::uno::Reference<css::drawing::framework::XView> CreateSlideSorterView(
169         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId) const;
170 
171     css::uno::Reference<css::drawing::framework::XView> CreateHelpView(
172         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId) const;
173 
174     css::uno::Reference<css::drawing::framework::XResource> GetViewFromCache (
175         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId,
176         const css::uno::Reference<css::drawing::framework::XPane>& rxAnchorPane) const;
177     css::uno::Reference<css::drawing::framework::XResource> CreateView(
178         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId,
179         const css::uno::Reference<css::drawing::framework::XPane>& rxAnchorPane);
180 
181     void ThrowIfDisposed (void) const throw (::com::sun::star::lang::DisposedException);
182 };
183 
184 } }
185 
186 #endif
187