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 "PresenterSpritePane.hxx"
28 #include "PresenterGeometryHelper.hxx"
29 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
30 #include <com/sun/star/rendering/CompositeOperation.hpp>
31 #include <osl/mutex.hxx>
32 
33 using namespace ::com::sun::star;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::drawing::framework;
36 using ::rtl::OUString;
37 
38 namespace sdext { namespace presenter {
39 
40 //===== PresenterSpritePane =========================================================
41 
PresenterSpritePane(const Reference<XComponentContext> & rxContext,const::rtl::Reference<PresenterController> & rpPresenterController)42 PresenterSpritePane::PresenterSpritePane (const Reference<XComponentContext>& rxContext,
43         const ::rtl::Reference<PresenterController>& rpPresenterController)
44     : PresenterPaneBase(rxContext, rpPresenterController),
45       mxParentWindow(),
46       mxParentCanvas(),
47       mpSprite(new PresenterSprite())
48 {
49     Reference<lang::XMultiComponentFactory> xFactory (
50         mxComponentContext->getServiceManager(), UNO_QUERY_THROW);
51     mxPresenterHelper = Reference<drawing::XPresenterHelper>(
52         xFactory->createInstanceWithContext(
53             OUString::createFromAscii("com.sun.star.comp.Draw.PresenterHelper"),
54             mxComponentContext),
55         UNO_QUERY_THROW);
56 }
57 
58 
59 
60 
~PresenterSpritePane(void)61 PresenterSpritePane::~PresenterSpritePane (void)
62 {
63 }
64 
65 
66 
67 
disposing(void)68 void PresenterSpritePane::disposing (void)
69 {
70     mpSprite->SetFactory(NULL);
71     mxParentWindow = NULL;
72     mxParentCanvas = NULL;
73     PresenterPaneBase::disposing();
74 }
75 
76 
77 
78 
79 //----- XPane -----------------------------------------------------------------
80 
getWindow(void)81 Reference<awt::XWindow> SAL_CALL PresenterSpritePane::getWindow (void)
82     throw (RuntimeException)
83 {
84     ThrowIfDisposed();
85     return mxContentWindow;
86 }
87 
88 
89 
90 
getCanvas(void)91 Reference<rendering::XCanvas> SAL_CALL PresenterSpritePane::getCanvas (void)
92     throw (RuntimeException)
93 {
94     ThrowIfDisposed();
95 
96     if ( ! mxContentCanvas.is())
97         UpdateCanvases();
98 
99     return mxContentCanvas;
100 }
101 
102 
103 
104 
105 //----- XWindowListener -------------------------------------------------------
106 
windowResized(const awt::WindowEvent & rEvent)107 void SAL_CALL PresenterSpritePane::windowResized (const awt::WindowEvent& rEvent)
108     throw (RuntimeException)
109 {
110     (void)rEvent;
111     PresenterPaneBase::windowResized(rEvent);
112 
113     mpSprite->Resize(geometry::RealSize2D(rEvent.Width, rEvent.Height));
114     LayoutContextWindow();
115     UpdateCanvases();
116 }
117 
118 
119 
120 
121 
windowMoved(const awt::WindowEvent & rEvent)122 void SAL_CALL PresenterSpritePane::windowMoved (const awt::WindowEvent& rEvent)
123     throw (RuntimeException)
124 {
125     (void)rEvent;
126     PresenterPaneBase::windowMoved(rEvent);
127 
128     awt::Rectangle aBox (
129         mxPresenterHelper->getWindowExtentsRelative(mxBorderWindow, mxParentWindow));
130     mpSprite->MoveTo(geometry::RealPoint2D(aBox.X, aBox.Y));
131     mpSprite->Update();
132 }
133 
134 
135 
136 
windowShown(const lang::EventObject & rEvent)137 void SAL_CALL PresenterSpritePane::windowShown (const lang::EventObject& rEvent)
138     throw (RuntimeException)
139 {
140     (void)rEvent;
141     PresenterPaneBase::windowShown(rEvent);
142 
143     mpSprite->Show();
144     ToTop();
145 
146     if (mxContentWindow.is())
147     {
148         LayoutContextWindow();
149         mxContentWindow->setVisible(sal_True);
150     }
151 }
152 
153 
154 
155 
windowHidden(const lang::EventObject & rEvent)156 void SAL_CALL PresenterSpritePane::windowHidden (const lang::EventObject& rEvent)
157     throw (RuntimeException)
158 {
159     (void)rEvent;
160     PresenterPaneBase::windowHidden(rEvent);
161 
162     mpSprite->Hide();
163     if (mxContentWindow.is())
164         mxContentWindow->setVisible(sal_False);
165 }
166 
167 
168 
169 
170 //----- XPaintListener --------------------------------------------------------
171 
windowPaint(const awt::PaintEvent & rEvent)172 void SAL_CALL PresenterSpritePane::windowPaint (const awt::PaintEvent& rEvent)
173     throw (RuntimeException)
174 {
175     (void)rEvent;
176     ThrowIfDisposed();
177 
178     /*
179     Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxParentCanvas, UNO_QUERY);
180     if (xSpriteCanvas.is())
181         xSpriteCanvas->updateScreen(sal_False);
182     */
183 }
184 
185 
186 
187 
188 //-----------------------------------------------------------------------------
189 
190 
GetSprite(void)191 ::boost::shared_ptr<PresenterSprite> PresenterSpritePane::GetSprite (void)
192 {
193     return mpSprite;
194 }
195 
196 
197 
198 
ShowTransparentBorder(void)199 void PresenterSpritePane::ShowTransparentBorder (void)
200 {
201 }
202 
203 
204 
205 
UpdateCanvases(void)206 void PresenterSpritePane::UpdateCanvases (void)
207 {
208     Reference<XComponent> xContentCanvasComponent (mxContentCanvas, UNO_QUERY);
209     if (xContentCanvasComponent.is())
210     {
211         if (xContentCanvasComponent.is())
212             xContentCanvasComponent->dispose();
213     }
214 
215     // The border canvas is the content canvas of the sprite.
216     mxBorderCanvas = mpSprite->GetCanvas();
217 
218     // The content canvas is a wrapper of the border canvas.
219     if (mxBorderCanvas.is())
220         mxContentCanvas = mxPresenterHelper->createSharedCanvas(
221             mxParentCanvas,
222             mxParentWindow,
223             mxBorderCanvas,
224             mxBorderWindow,
225             mxContentWindow);
226 
227     const awt::Rectangle aWindowBox (mxBorderWindow->getPosSize());
228     PaintBorder(awt::Rectangle(0,0,aWindowBox.Width,aWindowBox.Height));
229 }
230 
231 
232 
233 
CreateCanvases(const css::uno::Reference<css::awt::XWindow> & rxParentWindow,const css::uno::Reference<css::rendering::XSpriteCanvas> & rxParentCanvas)234 void PresenterSpritePane::CreateCanvases (
235     const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
236     const css::uno::Reference<css::rendering::XSpriteCanvas>& rxParentCanvas)
237 {
238     OSL_ASSERT(!mxParentWindow.is() || mxParentWindow==rxParentWindow);
239     OSL_ASSERT(!mxParentCanvas.is() || mxParentCanvas==rxParentCanvas);
240     mxParentWindow = rxParentWindow;
241     mxParentCanvas = rxParentCanvas;
242 
243     mpSprite->SetFactory(mxParentCanvas);
244     if (mxBorderWindow.is())
245     {
246         const awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
247         mpSprite->Resize(geometry::RealSize2D(aBorderBox.Width, aBorderBox.Height));
248     }
249 
250     UpdateCanvases();
251 }
252 
253 
254 
255 
256 } } // end of namespace ::sd::presenter
257