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_TOOL_BAR_HXX
25 #define SDEXT_PRESENTER_TOOL_BAR_HXX
26 
27 #include "PresenterController.hxx"
28 #include "PresenterViewFactory.hxx"
29 
30 #include <cppuhelper/basemutex.hxx>
31 #include <cppuhelper/compbase3.hxx>
32 #include <cppuhelper/compbase5.hxx>
33 #include <com/sun/star/awt/ActionEvent.hpp>
34 #include <com/sun/star/awt/XActionListener.hpp>
35 #include <com/sun/star/awt/XButton.hpp>
36 #include <com/sun/star/awt/XControl.hpp>
37 #include <com/sun/star/awt/XControlContainer.hpp>
38 #include <com/sun/star/awt/XFixedText.hpp>
39 #include <com/sun/star/awt/XMouseListener.hpp>
40 #include <com/sun/star/awt/XMouseMotionListener.hpp>
41 #include <com/sun/star/awt/XPaintListener.hpp>
42 #include <com/sun/star/awt/XWindowListener.hpp>
43 #include <com/sun/star/container/XNameAccess.hpp>
44 #include <com/sun/star/drawing/XDrawPage.hpp>
45 #include <com/sun/star/drawing/XDrawView.hpp>
46 #include <com/sun/star/drawing/XPresenterHelper.hpp>
47 #include <com/sun/star/drawing/framework/XView.hpp>
48 #include <com/sun/star/drawing/framework/XResourceId.hpp>
49 #include <com/sun/star/frame/XController.hpp>
50 #include <map>
51 #include <boost/scoped_ptr.hpp>
52 #include <boost/function.hpp>
53 #include <boost/noncopyable.hpp>
54 
55 namespace css = ::com::sun::star;
56 
57 namespace {
58     typedef cppu::WeakComponentImplHelper5<
59         css::awt::XWindowListener,
60         css::awt::XPaintListener,
61         css::awt::XMouseListener,
62         css::awt::XMouseMotionListener,
63         css::drawing::XDrawView
64         > PresenterToolBarInterfaceBase;
65 
66     typedef cppu::WeakComponentImplHelper3<
67         css::awt::XPaintListener,
68         css::drawing::framework::XView,
69         css::drawing::XDrawView
70         > PresenterToolBarViewInterfaceBase;
71 }
72 
73 namespace sdext { namespace presenter {
74 
75 /** A simple tool bar that can display bitmapped buttons and labels.  At the
76     moment there are buttons for moving to the next and previous slide and
77     to the next effect.  A label displayes the index of the current slide
78     and the total number of slides.
79 */
80 class PresenterToolBar
81     : private ::cppu::BaseMutex,
82       private ::boost::noncopyable,
83       public PresenterToolBarInterfaceBase,
84       public CachablePresenterView
85 {
86 public:
87     typedef ::boost::function<void(void)> Action;
88 
89     enum Anchor { Left, Center, Right };
90 
91     PresenterToolBar (
92         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
93         const css::uno::Reference<css::awt::XWindow>& rxWindow,
94         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
95         const ::rtl::Reference<PresenterController>& rpPresenterController,
96         const Anchor eAnchor);
97     virtual ~PresenterToolBar (void);
98 
99     void Initialize (
100         const ::rtl::OUString& rsConfigurationPath);
101 
102     virtual void SAL_CALL disposing (void);
103 
104     void InvalidateArea (
105         const css::awt::Rectangle& rRepaintBox,
106         const bool bSynchronous);
107     sal_Int32 GetSlideCount (void);
108     sal_Int32 GetCurrentSlideIndex (void);
109     void RequestLayout (void);
110     css::geometry::RealSize2D GetSize (void);
111     css::geometry::RealSize2D GetMinimalSize (void);
112     ::rtl::Reference<PresenterController> GetPresenterController (void) const;
113     css::uno::Reference<css::awt::XWindow> GetWindow (void) const;
114     css::uno::Reference<css::uno::XComponentContext> GetComponentContext (void) const;
115 
116     // lang::XEventListener
117 
118     virtual void SAL_CALL
119         disposing (const css::lang::EventObject& rEventObject)
120         throw (css::uno::RuntimeException);
121 
122 
123     // XWindowListener
124 
125     virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent)
126         throw (css::uno::RuntimeException);
127 
128     virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent)
129         throw (css::uno::RuntimeException);
130 
131     virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent)
132         throw (css::uno::RuntimeException);
133 
134     virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent)
135         throw (css::uno::RuntimeException);
136 
137 
138     // XPaintListener
139 
140     virtual void SAL_CALL windowPaint (const css::awt::PaintEvent& rEvent)
141         throw (css::uno::RuntimeException);
142 
143 
144     // XMouseListener
145 
146     virtual void SAL_CALL mousePressed (const css::awt::MouseEvent& rEvent)
147         throw (css::uno::RuntimeException);
148 
149     virtual void SAL_CALL mouseReleased (const css::awt::MouseEvent& rEvent)
150         throw (css::uno::RuntimeException);
151 
152     virtual void SAL_CALL mouseEntered (const css::awt::MouseEvent& rEvent)
153         throw (css::uno::RuntimeException);
154 
155     virtual void SAL_CALL mouseExited (const css::awt::MouseEvent& rEvent)
156         throw (css::uno::RuntimeException);
157 
158 
159     // XMouseMotionListener
160 
161     virtual void SAL_CALL mouseMoved (const css::awt::MouseEvent& rEvent)
162         throw (css::uno::RuntimeException);
163 
164     virtual void SAL_CALL mouseDragged (const css::awt::MouseEvent& rEvent)
165         throw (css::uno::RuntimeException);
166 
167 
168     // XDrawView
169 
170     virtual void SAL_CALL setCurrentPage (
171         const css::uno::Reference<css::drawing::XDrawPage>& rxSlide)
172         throw (css::uno::RuntimeException);
173 
174     virtual css::uno::Reference<css::drawing::XDrawPage> SAL_CALL getCurrentPage (void)
175         throw (css::uno::RuntimeException);
176 
177     class Context;
178 
179 private:
180     css::uno::Reference<css::uno::XComponentContext> mxComponentContext;
181 
182     class ElementContainerPart;
183     typedef ::boost::shared_ptr<ElementContainerPart> SharedElementContainerPart;
184     typedef ::std::vector<SharedElementContainerPart> ElementContainer;
185     ElementContainer maElementContainer;
186     SharedElementContainerPart mpCurrentContainerPart;
187     css::uno::Reference<css::awt::XWindow> mxWindow;
188     css::uno::Reference<css::rendering::XCanvas> mxCanvas;
189     css::uno::Reference<css::presentation::XSlideShowController> mxSlideShowController;
190     css::uno::Reference<css::drawing::XDrawPage> mxCurrentSlide;
191     ::rtl::Reference<PresenterController> mpPresenterController;
192     bool mbIsLayoutPending;
193     const Anchor meAnchor;
194     css::geometry::RealRectangle2D maBoundingBox;
195     /** The minimal size that is necessary to display all elements without
196         overlap and with minimal gaps between them.
197     */
198     css::geometry::RealSize2D maMinimalSize;
199 
200     void CreateControls (
201         const ::rtl::OUString& rsConfigurationPath);
202     void Layout (const css::uno::Reference<css::rendering::XCanvas>& rxCanvas);
203     css::geometry::RealSize2D CalculatePartSize (
204         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
205         const SharedElementContainerPart& rpPart,
206         const bool bIsHorizontal);
207     void LayoutPart (
208         const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
209         const SharedElementContainerPart& rpPart,
210         const css::geometry::RealRectangle2D& rBoundingBox,
211         const css::geometry::RealSize2D& rPartSize,
212         const bool bIsHorizontal);
213     void Clear (
214         const css::awt::Rectangle& rUpdateBox,
215         const css::rendering::ViewState& rViewState);
216     void Paint (
217         const css::awt::Rectangle& rUpdateBox,
218         const css::rendering::ViewState& rViewState);
219 
220     void UpdateSlideNumber (void);
221 
222     void CheckMouseOver (
223         const css::awt::MouseEvent& rEvent,
224         const bool bOverWindow,
225         const bool bMouseDown=false);
226 
227     void ProcessEntry (
228         const ::css::uno::Reference<css::beans::XPropertySet>& rProperties,
229         Context& rContext);
230 
231     /** This method throws a DisposedException when the object has already been
232         disposed.
233     */
234     void ThrowIfDisposed (void) const
235         throw (css::lang::DisposedException);
236 };
237 
238 
239 
240 
241 /** View for the PresenterToolBar.
242 */
243 class PresenterToolBarView
244     : private ::cppu::BaseMutex,
245       private ::boost::noncopyable,
246       public PresenterToolBarViewInterfaceBase
247 {
248 public:
249     explicit PresenterToolBarView (
250         const css::uno::Reference<css::uno::XComponentContext>& rxContext,
251         const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId,
252         const css::uno::Reference<css::frame::XController>& rxController,
253         const ::rtl::Reference<PresenterController>& rpPresenterController);
254     virtual ~PresenterToolBarView (void);
255 
256     virtual void SAL_CALL disposing (void);
257 
258     ::rtl::Reference<PresenterToolBar> GetPresenterToolBar (void) const;
259 
260 
261     // XPaintListener
262 
263     virtual void SAL_CALL windowPaint (const css::awt::PaintEvent& rEvent)
264         throw (css::uno::RuntimeException);
265 
266 
267     // lang::XEventListener
268 
269     virtual void SAL_CALL
270         disposing (const css::lang::EventObject& rEventObject)
271         throw (css::uno::RuntimeException);
272 
273 
274     // XResourceId
275 
276     virtual css::uno::Reference<css::drawing::framework::XResourceId> SAL_CALL getResourceId (void)
277         throw (css::uno::RuntimeException);
278 
279     virtual sal_Bool SAL_CALL isAnchorOnly (void)
280         throw (com::sun::star::uno::RuntimeException);
281 
282 
283     // XDrawView
284 
285     virtual void SAL_CALL setCurrentPage (
286         const css::uno::Reference<css::drawing::XDrawPage>& rxSlide)
287         throw (css::uno::RuntimeException);
288 
289     virtual css::uno::Reference<css::drawing::XDrawPage> SAL_CALL getCurrentPage (void)
290         throw (css::uno::RuntimeException);
291 
292 private:
293     //    css::uno::Reference<css::uno::XComponentContext> mxComponentContext;
294     css::uno::Reference<css::drawing::framework::XPane> mxPane;
295     css::uno::Reference<css::drawing::framework::XResourceId> mxViewId;
296     css::uno::Reference<css::awt::XWindow> mxWindow;
297     css::uno::Reference<css::rendering::XCanvas> mxCanvas;
298     ::rtl::Reference<PresenterController> mpPresenterController;
299     css::uno::Reference<css::presentation::XSlideShowController> mxSlideShowController;
300     ::rtl::Reference<PresenterToolBar> mpToolBar;
301 
302     /** This method throws a DisposedException when the object has already been
303         disposed.
304     */
305     void ThrowIfDisposed (void) const
306         throw (css::lang::DisposedException);
307 };
308 
309 } } // end of namespace ::sdext::presenter
310 
311 #endif
312