xref: /trunk/main/sdext/source/presenter/PresenterSpritePane.cxx (revision 45c5a00162811bd03b87fcb4fe9996782f2b59ec)
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 
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 
61 PresenterSpritePane::~PresenterSpritePane (void)
62 {
63 }
64 
65 
66 
67 
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 
81 Reference<awt::XWindow> SAL_CALL PresenterSpritePane::getWindow (void)
82 {
83     ThrowIfDisposed();
84     return mxContentWindow;
85 }
86 
87 
88 
89 
90 Reference<rendering::XCanvas> SAL_CALL PresenterSpritePane::getCanvas (void)
91 {
92     ThrowIfDisposed();
93 
94     if ( ! mxContentCanvas.is())
95         UpdateCanvases();
96 
97     return mxContentCanvas;
98 }
99 
100 
101 
102 
103 //----- XWindowListener -------------------------------------------------------
104 
105 void SAL_CALL PresenterSpritePane::windowResized (const awt::WindowEvent& rEvent)
106 {
107     (void)rEvent;
108     PresenterPaneBase::windowResized(rEvent);
109 
110     mpSprite->Resize(geometry::RealSize2D(rEvent.Width, rEvent.Height));
111     LayoutContextWindow();
112     UpdateCanvases();
113 }
114 
115 
116 
117 
118 
119 void SAL_CALL PresenterSpritePane::windowMoved (const awt::WindowEvent& rEvent)
120 {
121     (void)rEvent;
122     PresenterPaneBase::windowMoved(rEvent);
123 
124     awt::Rectangle aBox (
125         mxPresenterHelper->getWindowExtentsRelative(mxBorderWindow, mxParentWindow));
126     mpSprite->MoveTo(geometry::RealPoint2D(aBox.X, aBox.Y));
127     mpSprite->Update();
128 }
129 
130 
131 
132 
133 void SAL_CALL PresenterSpritePane::windowShown (const lang::EventObject& rEvent)
134 {
135     (void)rEvent;
136     PresenterPaneBase::windowShown(rEvent);
137 
138     mpSprite->Show();
139     ToTop();
140 
141     if (mxContentWindow.is())
142     {
143         LayoutContextWindow();
144         mxContentWindow->setVisible(sal_True);
145     }
146 }
147 
148 
149 
150 
151 void SAL_CALL PresenterSpritePane::windowHidden (const lang::EventObject& rEvent)
152 {
153     (void)rEvent;
154     PresenterPaneBase::windowHidden(rEvent);
155 
156     mpSprite->Hide();
157     if (mxContentWindow.is())
158         mxContentWindow->setVisible(sal_False);
159 }
160 
161 
162 
163 
164 //----- XPaintListener --------------------------------------------------------
165 
166 void SAL_CALL PresenterSpritePane::windowPaint (const awt::PaintEvent& rEvent)
167 {
168     (void)rEvent;
169     ThrowIfDisposed();
170 
171     /*
172     Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxParentCanvas, UNO_QUERY);
173     if (xSpriteCanvas.is())
174         xSpriteCanvas->updateScreen(sal_False);
175     */
176 }
177 
178 
179 
180 
181 //-----------------------------------------------------------------------------
182 
183 
184 ::boost::shared_ptr<PresenterSprite> PresenterSpritePane::GetSprite (void)
185 {
186     return mpSprite;
187 }
188 
189 
190 
191 
192 void PresenterSpritePane::ShowTransparentBorder (void)
193 {
194 }
195 
196 
197 
198 
199 void PresenterSpritePane::UpdateCanvases (void)
200 {
201     Reference<XComponent> xContentCanvasComponent (mxContentCanvas, UNO_QUERY);
202     if (xContentCanvasComponent.is())
203     {
204         if (xContentCanvasComponent.is())
205             xContentCanvasComponent->dispose();
206     }
207 
208     // The border canvas is the content canvas of the sprite.
209     mxBorderCanvas = mpSprite->GetCanvas();
210 
211     // The content canvas is a wrapper of the border canvas.
212     if (mxBorderCanvas.is())
213         mxContentCanvas = mxPresenterHelper->createSharedCanvas(
214             mxParentCanvas,
215             mxParentWindow,
216             mxBorderCanvas,
217             mxBorderWindow,
218             mxContentWindow);
219 
220     const awt::Rectangle aWindowBox (mxBorderWindow->getPosSize());
221     PaintBorder(awt::Rectangle(0,0,aWindowBox.Width,aWindowBox.Height));
222 }
223 
224 
225 
226 
227 void PresenterSpritePane::CreateCanvases (
228     const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
229     const css::uno::Reference<css::rendering::XSpriteCanvas>& rxParentCanvas)
230 {
231     OSL_ASSERT(!mxParentWindow.is() || mxParentWindow==rxParentWindow);
232     OSL_ASSERT(!mxParentCanvas.is() || mxParentCanvas==rxParentCanvas);
233     mxParentWindow = rxParentWindow;
234     mxParentCanvas = rxParentCanvas;
235 
236     mpSprite->SetFactory(mxParentCanvas);
237     if (mxBorderWindow.is())
238     {
239         const awt::Rectangle aBorderBox (mxBorderWindow->getPosSize());
240         mpSprite->Resize(geometry::RealSize2D(aBorderBox.Width, aBorderBox.Height));
241     }
242 
243     UpdateCanvases();
244 }
245 
246 
247 
248 
249 } } // end of namespace ::sd::presenter
250