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 
23 
24 #ifndef SDEXT_PRESENTER_PRESENTER_SCREEN_HXX
25 #define SDEXT_PRESENTER_PRESENTER_SCREEN_HXX
26 
27 #include "PresenterConfigurationAccess.hxx"
28 #include "PresenterPaneContainer.hxx"
29 #include <cppuhelper/compbase1.hxx>
30 #include <cppuhelper/basemutex.hxx>
31 #include <com/sun/star/lang/XInitialization.hpp>
32 #include <com/sun/star/frame/XController.hpp>
33 #include <com/sun/star/frame/XModel2.hpp>
34 #include <com/sun/star/task/XJob.hpp>
35 #include <com/sun/star/document/XEventListener.hpp>
36 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
37 #include <com/sun/star/drawing/framework/XView.hpp>
38 #include <com/sun/star/presentation/XSlideShowController.hpp>
39 #include <com/sun/star/presentation/XPresentation2.hpp>
40 #include <rtl/ref.hxx>
41 #include <boost/noncopyable.hpp>
42 #include <boost/shared_ptr.hpp>
43 #include <boost/scoped_ptr.hpp>
44 
45 namespace css = ::com::sun::star;
46 
47 namespace sdext { namespace presenter {
48 
49 class PresenterWindowManager;
50 class PresenterController;
51 
52 namespace {
53     typedef ::cppu::WeakComponentImplHelper1 <
54 		css::task::XJob
55         > PresenterScreenJobInterfaceBase;
56     typedef ::cppu::WeakComponentImplHelper1 <
57 		css::lang::XEventListener
58         > PresenterScreenInterfaceBase;
59 }
60 
61 
62 
63 
64 /** The PresenterScreenJob service is instantiated every time a document is
65     created or loaded.  In its execute() method it then filters out all
66     non-Impress documents and creates and registers a new PresenterScreen
67     object.
68 */
69 class PresenterScreenJob
70     : private ::boost::noncopyable,
71       private ::cppu::BaseMutex,
72       public PresenterScreenJobInterfaceBase
73 {
74 public:
75     static ::rtl::OUString getImplementationName_static (void);
76     static css::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static (void);
77     static css::uno::Reference<css::uno::XInterface> Create(
78         const css::uno::Reference<css::uno::XComponentContext>& rxContext)
79         SAL_THROW((css::uno::Exception));
80 
81     virtual void SAL_CALL disposing (void);
82 
83 	// XJob
84 
85     virtual css::uno::Any SAL_CALL execute(
86         const css::uno::Sequence<css::beans::NamedValue >& Arguments)
87         throw (css::lang::IllegalArgumentException,
88             css::uno::Exception,
89             css::uno::RuntimeException);
90 
91 private:
92     PresenterScreenJob (const css::uno::Reference<css::uno::XComponentContext>& rxContext);
93     virtual ~PresenterScreenJob (void);
94 
95     css::uno::Reference<css::uno::XComponentContext> mxComponentContext;
96 };
97 
98 
99 
100 
101 /** This is the bootstrap class of the presenter screen.  It is registered
102     as drawing framework startup service.  That means that every drawing
103     framework instance creates an instance of this class.
104 
105     <p>A PresenterScreen object registers itself as listener for drawing
106     framework configuration changes.  It waits for the full screen marker (a
107     top level resource) to appear in the current configuration.  When that
108     happens the actual presenter screen is initialized.  A new
109     PresenterController is created and takes over the task of controlling
110     the presenter screen.</p>
111 */
112 class PresenterScreen
113     : private ::boost::noncopyable,
114       private ::cppu::BaseMutex,
115       public PresenterScreenInterfaceBase
116 {
117 public:
118     PresenterScreen (
119         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
120         const css::uno::Reference<css::frame::XModel2>& rxModel);
121     virtual ~PresenterScreen (void);
122 
123     virtual void SAL_CALL disposing (void);
124 
125     /** Make the presenter screen visible.
126     */
127     void InitializePresenterScreen (void);
128 
129     /** Do not call ShutdownPresenterScreen() directly.  Call
130         RequestShutdownPresenterScreen() instead.  It will issue an
131         asynchronous call to ShutdownPresenterScreen() when that is safe.
132     */
133     void RequestShutdownPresenterScreen (void);
134 
135 
136     // XEventListener
137 
138     virtual void SAL_CALL disposing ( const css::lang::EventObject& rEvent) throw (css::uno::RuntimeException);
139 
140 private:
141 	css::uno::Reference<css::frame::XModel2 > mxModel;
142 	css::uno::Reference<css::frame::XController> mxController;
143     css::uno::WeakReference<css::drawing::framework::XConfigurationController>
144         mxConfigurationControllerWeak;
145     css::uno::WeakReference<css::uno::XComponentContext> mxContextWeak;
146     css::uno::WeakReference<css::presentation::XSlideShowController> mxSlideShowControllerWeak;
147     ::rtl::Reference<PresenterController> mpPresenterController;
148     css::uno::Reference<css::drawing::framework::XResourceId> mxSlideShowViewId;
149     css::uno::Reference<css::drawing::framework::XConfiguration> mxSavedConfiguration;
150     ::rtl::Reference<PresenterPaneContainer> mpPaneContainer;
151     sal_Int32 mnComponentIndex;
152     css::uno::Reference<css::drawing::framework::XResourceFactory> mxPaneFactory;
153     css::uno::Reference<css::drawing::framework::XResourceFactory> mxViewFactory;
154 
155     class ViewDescriptor
156     {
157     public:
158         ::rtl::OUString msTitle;
159         ::rtl::OUString msAccessibleTitle;
160         bool mbIsOpaque;
161     };
162     typedef ::std::map<rtl::OUString,ViewDescriptor> ViewDescriptorContainer;
163     ViewDescriptorContainer maViewDescriptors;
164 
165 
166     void ShutdownPresenterScreen (void);
167 
168     /** Create and initialize the factory for presenter view specific panes.
169     */
170     void SetupPaneFactory (
171         const css::uno::Reference<css::uno::XComponentContext>& rxContext);
172 
173     /** Create and initialize the factory for presenter view specific views.
174     */
175     void SetupViewFactory (
176         const css::uno::Reference<css::uno::XComponentContext>& rxContext);
177 
178     /** Read the current layout from the configuration and call
179         ProcessLayout to bring it on to the screen.
180     */
181     void SetupConfiguration (
182         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
183         const css::uno::Reference<css::drawing::framework::XResourceId>& rxAnchorId);
184 
185     /** Read one layout from the configuration and make resource activation
186         requests to bring it on to the screen.  When one layout references a
187         parent layout then this method calls itself recursively.
188     */
189     void ProcessLayout (
190         PresenterConfigurationAccess& rConfiguration,
191         const ::rtl::OUString& rsLayoutName,
192         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
193         const css::uno::Reference<css::drawing::framework::XResourceId>& rxAnchorId);
194 
195     /** Called by ProcessLayout for a single entry of a Layouts
196         configuration list.
197     */
198     void ProcessComponent (
199         const ::rtl::OUString& rsKey,
200         const ::std::vector<css::uno::Any>& rValues,
201         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
202         const css::uno::Reference<css::drawing::framework::XResourceId>& rxAnchorId);
203 
204     /** Read the view descriptions from the configuration.
205     */
206     void ProcessViewDescriptions (
207         PresenterConfigurationAccess& rConfiguration);
208 
209     /** Called by ProcessViewDescriptions for a single entry.
210     */
211     void ProcessViewDescription (
212         const ::rtl::OUString& rsKey,
213         const ::std::vector<css::uno::Any>& rValues);
214 
215     void SetupView (
216         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
217         const css::uno::Reference<css::drawing::framework::XResourceId>& rxAnchorId,
218         const ::rtl::OUString& rsPaneURL,
219         const ::rtl::OUString& rsViewURL,
220         const PresenterPaneContainer::ViewInitializationFunction& rViewInitialization,
221         const double nLeft,
222         const double nTop,
223         const double nRight,
224         const double nBottom);
225 
226     /** Return the screen number on which to display the presenter screen.
227         @return
228             Returns -1 when the presenter screen can or shall not be
229             displayed.
230     */
231     sal_Int32 GetScreenNumber (
232         const css::uno::Reference<css::presentation::XPresentation2>& rxPresentation) const;
233 
234     /** Create a resource id for the full screen background pane so that it
235         is displayed on another screen than the full screen presentation.
236     */
237     css::uno::Reference<css::drawing::framework::XResourceId> GetMainPaneId (
238         const css::uno::Reference<css::presentation::XPresentation2>& rxPresentation) const;
239 };
240 
241 } }
242 
243 #endif
244