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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sdext.hxx"
30 
31 #include "PresenterPane.hxx"
32 #include "PresenterController.hxx"
33 #include "PresenterPaintManager.hxx"
34 #include <com/sun/star/awt/XWindowPeer.hpp>
35 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
36 #include <com/sun/star/drawing/CanvasFeature.hpp>
37 #include <com/sun/star/rendering/CompositeOperation.hpp>
38 #include <osl/mutex.hxx>
39 
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::drawing::framework;
43 using ::rtl::OUString;
44 
45 namespace sdext { namespace presenter {
46 
47 //===== PresenterPane =========================================================
48 
49 PresenterPane::PresenterPane (
50     const Reference<XComponentContext>& rxContext,
51         const ::rtl::Reference<PresenterController>& rpPresenterController)
52     : PresenterPaneBase(rxContext, rpPresenterController),
53       maBoundingBox()
54 {
55     Reference<lang::XMultiComponentFactory> xFactory (
56         mxComponentContext->getServiceManager(), UNO_QUERY_THROW);
57     mxPresenterHelper = Reference<drawing::XPresenterHelper>(
58         xFactory->createInstanceWithContext(
59             OUString::createFromAscii("com.sun.star.comp.Draw.PresenterHelper"),
60             mxComponentContext),
61         UNO_QUERY_THROW);
62 }
63 
64 
65 
66 
67 PresenterPane::~PresenterPane (void)
68 {
69 }
70 
71 
72 
73 
74 //----- XPane -----------------------------------------------------------------
75 
76 Reference<awt::XWindow> SAL_CALL PresenterPane::getWindow (void)
77     throw (RuntimeException)
78 {
79     ThrowIfDisposed();
80     return mxContentWindow;
81 }
82 
83 
84 
85 
86 Reference<rendering::XCanvas> SAL_CALL PresenterPane::getCanvas (void)
87     throw (RuntimeException)
88 {
89     ThrowIfDisposed();
90     return mxContentCanvas;
91 }
92 
93 
94 
95 
96 //----- XWindowListener -------------------------------------------------------
97 
98 void SAL_CALL PresenterPane::windowResized (const awt::WindowEvent& rEvent)
99     throw (RuntimeException)
100 {
101     (void)rEvent;
102     PresenterPaneBase::windowResized(rEvent);
103 
104     Invalidate(maBoundingBox);
105 
106     LayoutContextWindow();
107     ToTop();
108 
109     UpdateBoundingBox();
110     Invalidate(maBoundingBox);
111 }
112 
113 
114 
115 
116 
117 void SAL_CALL PresenterPane::windowMoved (const awt::WindowEvent& rEvent)
118     throw (RuntimeException)
119 {
120     (void)rEvent;
121     PresenterPaneBase::windowMoved(rEvent);
122 
123     Invalidate(maBoundingBox);
124 
125     ToTop();
126 
127     UpdateBoundingBox();
128     Invalidate(maBoundingBox);
129 }
130 
131 
132 
133 
134 void SAL_CALL PresenterPane::windowShown (const lang::EventObject& rEvent)
135     throw (RuntimeException)
136 {
137     (void)rEvent;
138     PresenterPaneBase::windowShown(rEvent);
139 
140     ToTop();
141 
142     if (mxContentWindow.is())
143     {
144         LayoutContextWindow();
145         mxContentWindow->setVisible(sal_True);
146     }
147 
148     UpdateBoundingBox();
149     Invalidate(maBoundingBox);
150 }
151 
152 
153 
154 
155 void SAL_CALL PresenterPane::windowHidden (const lang::EventObject& rEvent)
156     throw (RuntimeException)
157 {
158     (void)rEvent;
159     PresenterPaneBase::windowHidden(rEvent);
160 
161     if (mxContentWindow.is())
162         mxContentWindow->setVisible(sal_False);
163 }
164 
165 
166 
167 
168 //----- XPaintListener --------------------------------------------------------
169 
170 void SAL_CALL PresenterPane::windowPaint (const awt::PaintEvent& rEvent)
171     throw (RuntimeException)
172 {
173     (void)rEvent;
174     ThrowIfDisposed();
175 
176     PaintBorder(rEvent.UpdateRect);
177 }
178 
179 
180 
181 
182 //-----------------------------------------------------------------------------
183 
184 
185 void PresenterPane::CreateCanvases (
186     const Reference<awt::XWindow>& rxParentWindow,
187     const Reference<rendering::XSpriteCanvas>& rxParentCanvas)
188 {
189     if ( ! mxPresenterHelper.is())
190         return;
191     if ( ! rxParentWindow.is())
192         return;
193     if ( ! rxParentCanvas.is())
194         return;
195 
196     mxBorderCanvas = mxPresenterHelper->createSharedCanvas(
197         rxParentCanvas,
198         rxParentWindow,
199         Reference<rendering::XCanvas>(rxParentCanvas, UNO_QUERY),
200         rxParentWindow,
201         mxBorderWindow);
202     mxContentCanvas = mxPresenterHelper->createSharedCanvas(
203         rxParentCanvas,
204         rxParentWindow,
205         Reference<rendering::XCanvas>(rxParentCanvas, UNO_QUERY),
206         rxParentWindow,
207         mxContentWindow);
208 
209     PaintBorder(mxBorderWindow->getPosSize());
210 }
211 
212 
213 
214 
215 void PresenterPane::Invalidate (const css::awt::Rectangle& rRepaintBox)
216 {
217     // Invalidate the parent window to be able to invalidate an area outside
218     // the current window area.
219     mpPresenterController->GetPaintManager()->Invalidate(mxParentWindow, rRepaintBox);
220 }
221 
222 
223 
224 
225 void PresenterPane::UpdateBoundingBox (void)
226 {
227     if (mxBorderWindow.is() && IsVisible())
228         maBoundingBox = mxBorderWindow->getPosSize();
229     else
230         maBoundingBox = awt::Rectangle();
231 }
232 
233 
234 } } // end of namespace ::sd::presenter
235