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_WINDOW_MANAGER_HXX
25 #define SDEXT_PRESENTER_PRESENTER_WINDOW_MANAGER_HXX
26 
27 #include "PresenterPaneContainer.hxx"
28 #include "PresenterTheme.hxx"
29 #include <com/sun/star/awt/Point.hpp>
30 #include <com/sun/star/awt/XFocusListener.hpp>
31 #include <com/sun/star/awt/XGraphics.hpp>
32 #include <com/sun/star/awt/XMouseMotionListener.hpp>
33 #include <com/sun/star/awt/XPaintListener.hpp>
34 #include <com/sun/star/awt/XWindow.hpp>
35 #include <com/sun/star/awt/XWindowListener.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/document/XEventListener.hpp>
38 #include <com/sun/star/drawing/framework/XPane.hpp>
39 #include <com/sun/star/rendering/XBitmap.hpp>
40 #include <com/sun/star/rendering/XSprite.hpp>
41 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
42 #include <com/sun/star/uno/XComponentContext.hpp>
43 #include <cppuhelper/basemutex.hxx>
44 #include <cppuhelper/compbase4.hxx>
45 #include <tools/gen.hxx>
46 #include <rtl/ref.hxx>
47 #include <boost/noncopyable.hpp>
48 #include <boost/shared_ptr.hpp>
49 
50 namespace css = ::com::sun::star;
51 
52 namespace sdext { namespace presenter {
53 
54 class PresenterController;
55 class PresenterPaneBorderPainter;
56 class PresenterTheme;
57 
58 namespace {
59     typedef ::cppu::WeakComponentImplHelper4<
60         css::awt::XWindowListener,
61         css::awt::XPaintListener,
62         css::awt::XMouseListener,
63         css::awt::XFocusListener
64     > PresenterWindowManagerInterfaceBase;
65 }
66 
67 
68 /** A simple manager of the positions of the panes of the presenter screen.
69     Uses relative coordinates of the four sides of each pane.  Allows panes
70     to be moved or resized with the mouse.
71 */
72 class PresenterWindowManager
73     : private ::boost::noncopyable,
74       protected ::cppu::BaseMutex,
75       public PresenterWindowManagerInterfaceBase
76 {
77 public:
78     PresenterWindowManager (
79         const ::css::uno::Reference<css::uno::XComponentContext>& rxContext,
80         const ::rtl::Reference<PresenterPaneContainer>& rpPaneContainer,
81         const ::rtl::Reference<PresenterController>& rpPresenterController);
82     virtual ~PresenterWindowManager (void);
83 
84     void SAL_CALL disposing (void);
85 
86     void SetParentPane (const css::uno::Reference<css::drawing::framework::XPane>& rxPane);
87     void SetTheme (const ::boost::shared_ptr<PresenterTheme>& rpTheme);
88     void NotifyPaneCreation (const PresenterPaneContainer::SharedPaneDescriptor& rpDescriptor);
89     void NotifyViewCreation (const css::uno::Reference<css::drawing::framework::XView>& rxView);
90     void SetPanePosSizeRelative (
91         const css::uno::Reference<css::drawing::framework::XResourceId>& rxPaneId,
92         const double nRelativeX,
93         const double nRelativeY,
94         const double nRelativeWidth,
95         const double nRelativeHeight);
96     void SetPanePosSizeAbsolute (
97         const ::rtl::OUString& rsPaneURL,
98         const double nX,
99         const double nY,
100         const double nWidth,
101         const double nHeight);
102     void SetPaneBorderPainter (const ::rtl::Reference<PresenterPaneBorderPainter>& rPainter);
103     css::uno::Reference<css::awt::XWindow> GetParentWindow (void) const;
104     css::uno::Reference<css::rendering::XCanvas> GetParentCanvas (void) const;
105     void Update (void);
106     void Layout (void);
107 
108     void SetSlideSorterState (bool bIsActive);
109     void SetHelpViewState (bool bIsActive);
110 
111     enum LayoutMode { LM_Standard, LM_Notes, LM_Generic };
112 private:
113     void SetLayoutMode (const LayoutMode eMode);
114     LayoutMode GetLayoutMode (void) const;
115 
116     bool IsSlideSorterActive (void) const;
117     bool IsHelpViewActive (void) const;
118 public:
119     enum ViewMode { VM_Standard, VM_Notes, VM_SlideOverview, VM_Help };
120     /** The high-level method to switch the view mode.  Use this instead of
121         SetLayoutMode and Set(Help|SlideSorter)State when possible.
122     */
123     void SetViewMode (const ViewMode eMode);
124 
125     ViewMode GetViewMode (void) const;
126 
127     /** Restore the layout mode (or slide sorter state) from the
128         configuration.
129     */
130     void RestoreViewMode (void);
131 
132     void AddLayoutListener (
133         const css::uno::Reference<css::document::XEventListener>& rxListener);
134     void RemoveLayoutListener (
135         const css::uno::Reference<css::document::XEventListener>& rxListener);
136 
137     // XWindowListener
138 
139     virtual void SAL_CALL windowResized (const css::awt::WindowEvent& rEvent)
140         throw (css::uno::RuntimeException);
141 
142     virtual void SAL_CALL windowMoved (const css::awt::WindowEvent& rEvent)
143         throw (css::uno::RuntimeException);
144 
145     virtual void SAL_CALL windowShown (const css::lang::EventObject& rEvent)
146         throw (css::uno::RuntimeException);
147 
148     virtual void SAL_CALL windowHidden (const css::lang::EventObject& rEvent)
149         throw (css::uno::RuntimeException);
150 
151 
152     // XPaintListener
153 
154     virtual void SAL_CALL windowPaint (const css::awt::PaintEvent& rEvent)
155         throw (css::uno::RuntimeException);
156 
157 
158     // XMouseListener
159 
160     virtual void SAL_CALL mousePressed (const css::awt::MouseEvent& rEvent)
161         throw(css::uno::RuntimeException);
162 
163     virtual void SAL_CALL mouseReleased (const css::awt::MouseEvent& rEvent)
164         throw(css::uno::RuntimeException);
165 
166     virtual void SAL_CALL mouseEntered (const css::awt::MouseEvent& rEvent)
167         throw(css::uno::RuntimeException);
168 
169     virtual void SAL_CALL mouseExited (const css::awt::MouseEvent& rEvent)
170         throw(css::uno::RuntimeException);
171 
172 
173     // XFocusListener
174 
175     virtual void SAL_CALL focusGained (const css::awt::FocusEvent& rEvent)
176         throw (css::uno::RuntimeException);
177 
178     virtual void SAL_CALL focusLost (const css::awt::FocusEvent& rEvent)
179         throw (css::uno::RuntimeException);
180 
181 
182     // XEventListener
183 
184     virtual void SAL_CALL disposing (
185         const com::sun::star::lang::EventObject& rEvent)
186         throw (com::sun::star::uno::RuntimeException);
187 
188 private:
189     css::uno::Reference<css::uno::XComponentContext> mxComponentContext;
190     ::rtl::Reference<PresenterController> mpPresenterController;
191     css::uno::Reference<css::awt::XWindow> mxParentWindow;
192     css::uno::Reference<css::rendering::XCanvas> mxParentCanvas;
193     css::uno::Reference<css::uno::XInterface> mxPaneBorderManager;
194     ::rtl::Reference<PresenterPaneBorderPainter> mpPaneBorderPainter;
195     ::rtl::Reference<PresenterPaneContainer> mpPaneContainer;
196     bool mbIsLayoutPending;
197     /** This flag is set to <TRUE/> while the Layout() method is being
198         executed.  Prevents windowMoved() and windowResized() from changing
199         the window sizes.
200     */
201     bool mbIsLayouting;
202     ::boost::shared_ptr<PresenterTheme> mpTheme;
203     SharedBitmapDescriptor mpBackgroundBitmap;
204     css::uno::Reference<css::rendering::XBitmap> mxScaledBackgroundBitmap;
205     css::util::Color maPaneBackgroundColor;
206     css::uno::Reference<css::rendering::XPolyPolygon2D> mxClipPolygon;
207     LayoutMode meLayoutMode;
208     bool mbIsSlideSorterActive;
209     bool mbIsHelpViewActive;
210     typedef ::std::vector<css::uno::Reference<css::document::XEventListener> >
211         LayoutListenerContainer;
212     LayoutListenerContainer maLayoutListeners;
213     bool mbIsMouseClickPending;
214 
215     bool PaintChildren (const css::awt::PaintEvent& rEvent) const;
216     void UpdateWindowSize (const css::uno::Reference<css::awt::XWindow>& rxBorderWindow);
217     void PaintBackground (const css::awt::Rectangle& rUpdateBox);
218     void ProvideBackgroundBitmap (void);
219     css::uno::Reference<css::rendering::XPolyPolygon2D> CreateClipPolyPolygon (void) const;
220     void ToTop ();
221 
222     void UpdateWindowList (void);
223     bool ChildNeedsRepaint (
224         const css::uno::Reference<css::drawing::framework::XPane>& rxPane) const;
225 
226     void Invalidate (void);
227 
228     void StoreViewMode (const ViewMode eViewMode);
229 
230     void LayoutStandardMode (void);
231     void LayoutNotesMode (void);
232     void LayoutUnknownMode (void);
233     void LayoutSlideSorterMode (void);
234     void LayoutHelpMode (void);
235 
236     /** Layout the tool bar and return its outer bounding box.
237     */
238     css::geometry::RealRectangle2D LayoutToolBar (void);
239 
240     css::awt::Size CalculatePaneSize (
241         const double nOuterWidth,
242         const ::rtl::OUString& rsPaneURL);
243 
244     /** Notify changes of the layout mode and of the slide sorter state.
245     */
246     void NotifyLayoutModeChange (void);
247 
248     void NotifyDisposing (void);
249 
250     void ThrowIfDisposed (void) const throw (::com::sun::star::lang::DisposedException);
251 };
252 
253 } }
254 
255 #endif
256