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