Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "PresenterSlidePreview.hxx"
30 : : #include "PresenterCanvasHelper.hxx"
31 : : #include "PresenterGeometryHelper.hxx"
32 : : #include "PresenterPaintManager.hxx"
33 : : #include <com/sun/star/awt/XWindow.hpp>
34 : : #include <com/sun/star/awt/XWindowPeer.hpp>
35 : : #include <com/sun/star/beans/XPropertySet.hpp>
36 : : #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
37 : : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
38 : : #include <com/sun/star/drawing/framework/XPane.hpp>
39 : : #include <com/sun/star/rendering/CompositeOperation.hpp>
40 : :
41 : : using namespace ::com::sun::star;
42 : : using namespace ::com::sun::star::uno;
43 : : using namespace ::com::sun::star::drawing::framework;
44 : : using ::rtl::OUString;
45 : :
46 : : namespace
47 : : {
48 : : // Use a super sample factor greater than 1 to achive a poor mans
49 : : // antialiasing effect for slide previews.
50 : : const sal_Int16 gnSuperSampleFactor = 2;
51 : : }
52 : :
53 : : namespace sdext { namespace presenter {
54 : :
55 : : //===== PresenterSlidePreview =================================================
56 : :
57 : 0 : PresenterSlidePreview::PresenterSlidePreview (
58 : : const Reference<XComponentContext>& rxContext,
59 : : const Reference<XResourceId>& rxViewId,
60 : : const Reference<XPane>& rxAnchorPane,
61 : : const ::rtl::Reference<PresenterController>& rpPresenterController)
62 : : : PresenterSlidePreviewInterfaceBase(m_aMutex),
63 : : mpPresenterController(rpPresenterController),
64 : : mxPane(rxAnchorPane),
65 : : mxViewId(rxViewId),
66 : : mxPreviewRenderer(),
67 : : mxPreview(),
68 : : mxCurrentSlide(),
69 : : mnSlideAspectRatio(28.0 / 21.0),
70 : : mxWindow(),
71 [ # # ]: 0 : mxCanvas()
72 : : {
73 [ # # ][ # # : 0 : if ( ! rxContext.is()
# # # # #
# ]
74 : 0 : || ! rxViewId.is()
75 : 0 : || ! rxAnchorPane.is()
76 : 0 : || ! rpPresenterController.is())
77 : : {
78 : : throw RuntimeException(
79 : : OUString(
80 : : "PresenterSlidePreview can not be constructed due to empty argument"),
81 [ # # ][ # # ]: 0 : static_cast<XWeak*>(this));
82 : : }
83 : :
84 [ # # ][ # # ]: 0 : mxWindow = rxAnchorPane->getWindow();
[ # # ]
85 [ # # ][ # # ]: 0 : mxCanvas = rxAnchorPane->getCanvas();
[ # # ]
86 : :
87 [ # # ]: 0 : if (mxWindow.is())
88 : : {
89 [ # # ][ # # ]: 0 : mxWindow->addWindowListener(this);
[ # # ]
90 [ # # ][ # # ]: 0 : mxWindow->addPaintListener(this);
[ # # ]
91 : :
92 [ # # ]: 0 : Reference<awt::XWindowPeer> xPeer (mxWindow, UNO_QUERY);
93 [ # # ]: 0 : if (xPeer.is())
94 [ # # ][ # # ]: 0 : xPeer->setBackground(util::Color(0xff000000));
95 : :
96 [ # # ][ # # ]: 0 : mxWindow->setVisible(sal_True);
97 : : }
98 : :
99 [ # # ]: 0 : if (mpPresenterController.get() != NULL)
100 [ # # ]: 0 : mnSlideAspectRatio = mpPresenterController->GetSlideAspectRatio();
101 : :
102 [ # # ][ # # ]: 0 : Reference<lang::XMultiComponentFactory> xFactory (rxContext->getServiceManager(), UNO_QUERY);
[ # # ]
103 [ # # ]: 0 : if (xFactory.is())
104 : : mxPreviewRenderer = Reference<drawing::XSlideRenderer>(
105 [ # # ]: 0 : xFactory->createInstanceWithContext(
106 : : OUString("com.sun.star.drawing.SlideRenderer"),
107 : 0 : rxContext),
108 [ # # ][ # # ]: 0 : UNO_QUERY);
[ # # ]
109 : :
110 [ # # ]: 0 : Resize();
111 : 0 : }
112 : :
113 [ # # ][ # # ]: 0 : PresenterSlidePreview::~PresenterSlidePreview (void)
114 : : {
115 [ # # ]: 0 : }
116 : :
117 : 0 : void SAL_CALL PresenterSlidePreview::disposing (void)
118 : : {
119 [ # # ]: 0 : if (mxWindow.is())
120 : : {
121 [ # # ][ # # ]: 0 : mxWindow->removeWindowListener(this);
[ # # ]
122 [ # # ][ # # ]: 0 : mxWindow->removePaintListener(this);
[ # # ]
123 [ # # ]: 0 : mxWindow = NULL;
124 [ # # ]: 0 : mxCanvas = NULL;
125 : : }
126 : :
127 [ # # ]: 0 : Reference<lang::XComponent> xComponent (mxPreviewRenderer, UNO_QUERY);
128 [ # # ]: 0 : if (xComponent.is())
129 [ # # ][ # # ]: 0 : xComponent->dispose();
130 : 0 : }
131 : :
132 : : //----- XResourceId -----------------------------------------------------------
133 : :
134 : 0 : Reference<XResourceId> SAL_CALL PresenterSlidePreview::getResourceId (void)
135 : : throw (RuntimeException)
136 : : {
137 : 0 : return mxViewId;
138 : : }
139 : :
140 : 0 : sal_Bool SAL_CALL PresenterSlidePreview::isAnchorOnly (void)
141 : : throw (RuntimeException)
142 : : {
143 : 0 : return false;
144 : : }
145 : :
146 : : //----- XWindowListener -------------------------------------------------------
147 : :
148 : 0 : void SAL_CALL PresenterSlidePreview::windowResized (const awt::WindowEvent& rEvent)
149 : : throw (RuntimeException)
150 : : {
151 : : (void)rEvent;
152 [ # # ]: 0 : ThrowIfDisposed();
153 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
154 [ # # ][ # # ]: 0 : Resize();
155 : 0 : }
156 : :
157 : 0 : void SAL_CALL PresenterSlidePreview::windowMoved (const awt::WindowEvent& rEvent)
158 : : throw (RuntimeException)
159 : : {
160 : : (void)rEvent;
161 : 0 : }
162 : :
163 : 0 : void SAL_CALL PresenterSlidePreview::windowShown (const lang::EventObject& rEvent)
164 : : throw (RuntimeException)
165 : : {
166 : : (void)rEvent;
167 [ # # ]: 0 : ThrowIfDisposed();
168 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
169 [ # # ][ # # ]: 0 : Resize();
170 : 0 : }
171 : :
172 : 0 : void SAL_CALL PresenterSlidePreview::windowHidden (const lang::EventObject& rEvent)
173 : : throw (RuntimeException)
174 : : {
175 : : (void)rEvent;
176 : 0 : }
177 : :
178 : : //----- XPaintListener --------------------------------------------------------
179 : :
180 : 0 : void SAL_CALL PresenterSlidePreview::windowPaint (const awt::PaintEvent& rEvent)
181 : : throw (RuntimeException)
182 : : {
183 [ # # ]: 0 : ThrowIfDisposed();
184 : :
185 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
186 [ # # ]: 0 : if (mxWindow.is())
187 : : Paint(awt::Rectangle(
188 : : rEvent.UpdateRect.X,
189 : : rEvent.UpdateRect.Y,
190 : : rEvent.UpdateRect.Width,
191 [ # # ][ # # ]: 0 : rEvent.UpdateRect.Height));
192 : 0 : }
193 : :
194 : : //----- lang::XEventListener --------------------------------------------------
195 : :
196 : 0 : void SAL_CALL PresenterSlidePreview::disposing (const lang::EventObject& rEvent)
197 : : throw (RuntimeException)
198 : : {
199 [ # # ]: 0 : if (rEvent.Source == mxWindow)
200 : : {
201 : 0 : mxWindow = NULL;
202 : 0 : mxCanvas = NULL;
203 : 0 : mxPreview = NULL;
204 : : }
205 : 0 : }
206 : :
207 : : //----- XDrawView -------------------------------------------------------------
208 : :
209 : 0 : void SAL_CALL PresenterSlidePreview::setCurrentPage (const Reference<drawing::XDrawPage>& rxSlide)
210 : : throw (RuntimeException)
211 : : {
212 [ # # ]: 0 : ThrowIfDisposed();
213 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
214 [ # # ][ # # ]: 0 : SetSlide(rxSlide);
215 : 0 : }
216 : :
217 : 0 : Reference<drawing::XDrawPage> SAL_CALL PresenterSlidePreview::getCurrentPage (void)
218 : : throw (RuntimeException)
219 : : {
220 : 0 : ThrowIfDisposed();
221 : 0 : return NULL;
222 : : }
223 : :
224 : : //-----------------------------------------------------------------------------
225 : :
226 : 0 : void PresenterSlidePreview::SetSlide (const Reference<drawing::XDrawPage>& rxPage)
227 : : {
228 [ # # ]: 0 : mxCurrentSlide = rxPage;
229 [ # # ]: 0 : mxPreview = NULL;
230 : :
231 [ # # ]: 0 : Reference<beans::XPropertySet> xPropertySet (mxCurrentSlide, UNO_QUERY);
232 [ # # ]: 0 : if (xPropertySet.is())
233 : : {
234 : 0 : awt::Size aSlideSize;
235 : : try
236 : : {
237 [ # # ]: 0 : xPropertySet->getPropertyValue(
238 [ # # ]: 0 : OUString("Width")) >>= aSlideSize.Width;
239 [ # # ]: 0 : xPropertySet->getPropertyValue(
240 [ # # ][ # # ]: 0 : OUString("Height")) >>= aSlideSize.Height;
241 : : }
242 [ # # ]: 0 : catch (beans::UnknownPropertyException&)
243 : : {
244 : : OSL_ASSERT(false);
245 : : }
246 : : }
247 : :
248 : : // The preview is not transparent, therefore only this window, not its
249 : : // parent, has to be invalidated.
250 [ # # ][ # # ]: 0 : mpPresenterController->GetPaintManager()->Invalidate(mxWindow);
[ # # ]
251 : 0 : }
252 : :
253 : 0 : void PresenterSlidePreview::Paint (const awt::Rectangle& rBoundingBox)
254 : : {
255 : : (void)rBoundingBox;
256 [ # # ]: 0 : if ( ! mxWindow.is())
257 : : return;
258 [ # # ]: 0 : if ( ! mxCanvas.is())
259 : : return;
260 [ # # ]: 0 : if ( ! mxPreviewRenderer.is())
261 : : return;
262 : :
263 : : // Make sure that a preview in the correct size exists.
264 [ # # ][ # # ]: 0 : awt::Rectangle aWindowBox (mxWindow->getPosSize());
265 : :
266 [ # # ][ # # ]: 0 : if ( ! mxPreview.is() && mxCurrentSlide.is())
[ # # ]
267 : : {
268 : : // Create a new preview bitmap.
269 [ # # ]: 0 : mxPreview = mxPreviewRenderer->createPreviewForCanvas(
270 : : mxCurrentSlide,
271 : : awt::Size(aWindowBox.Width, aWindowBox.Height),
272 : : gnSuperSampleFactor,
273 [ # # ][ # # ]: 0 : mxCanvas);
274 : : }
275 : :
276 : : // Determine the bounding box of the preview.
277 : 0 : awt::Rectangle aPreviewBox;
278 [ # # ]: 0 : if (mxPreview.is())
279 : : {
280 [ # # ][ # # ]: 0 : const geometry::IntegerSize2D aPreviewSize (mxPreview->getSize());
281 : : aPreviewBox = awt::Rectangle(
282 : : (aWindowBox.Width - aPreviewSize.Width)/2,
283 : : (aWindowBox.Height - aPreviewSize.Height)/2,
284 : : aPreviewSize.Width,
285 : 0 : aPreviewSize.Height);
286 : : }
287 : : else
288 : : {
289 [ # # ]: 0 : if (mnSlideAspectRatio > 0)
290 : : {
291 [ # # ]: 0 : const awt::Size aPreviewSize (mxPreviewRenderer->calculatePreviewSize(
292 [ # # ]: 0 : mnSlideAspectRatio,awt::Size(aWindowBox.Width, aWindowBox.Height)));
293 : : aPreviewBox = awt::Rectangle(
294 : : (aWindowBox.Width - aPreviewSize.Width)/2,
295 : : (aWindowBox.Height - aPreviewSize.Height)/2,
296 : : aPreviewSize.Width,
297 : 0 : aPreviewSize.Height);
298 : : }
299 : : }
300 : :
301 : : // Paint the background.
302 : : mpPresenterController->GetCanvasHelper()->Paint(
303 [ # # ]: 0 : mpPresenterController->GetViewBackground(mxViewId->getResourceURL()),
304 : : mxCanvas,
305 : : rBoundingBox,
306 : : awt::Rectangle(0,0,aWindowBox.Width,aWindowBox.Height),
307 [ # # ][ # # ]: 0 : aPreviewBox);
[ # # ][ # # ]
[ # # ][ # # ]
308 : :
309 : : // Paint the preview.
310 : : const rendering::ViewState aViewState(
311 : : geometry::AffineMatrix2D(1,0,0, 0,1,0),
312 [ # # ][ # # ]: 0 : NULL);
313 : :
314 [ # # ]: 0 : Sequence<double> aBackgroundColor(4);
315 : : rendering::RenderState aRenderState (
316 : : geometry::AffineMatrix2D(1, 0, aPreviewBox.X, 0, 1, aPreviewBox.Y),
317 : : NULL,
318 : : aBackgroundColor,
319 [ # # ][ # # ]: 0 : rendering::CompositeOperation::SOURCE);
320 [ # # ]: 0 : PresenterCanvasHelper::SetDeviceColor(aRenderState, 0x00000000);
321 [ # # ]: 0 : if (mxPreview.is())
322 : : {
323 [ # # ][ # # ]: 0 : mxCanvas->drawBitmap(mxPreview, aViewState, aRenderState);
324 : : }
325 : : else
326 : : {
327 [ # # ]: 0 : if (mnSlideAspectRatio > 0)
328 : : {
329 : : Reference<rendering::XPolyPolygon2D> xPolygon (
330 [ # # ][ # # ]: 0 : PresenterGeometryHelper::CreatePolygon(aPreviewBox, mxCanvas->getDevice()));
[ # # ]
331 [ # # ]: 0 : if (xPolygon.is())
332 [ # # ][ # # ]: 0 : mxCanvas->fillPolyPolygon(xPolygon, aViewState, aRenderState);
333 : : }
334 : : }
335 : :
336 [ # # ]: 0 : Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxCanvas, UNO_QUERY);
337 [ # # ]: 0 : if (xSpriteCanvas.is())
338 [ # # ][ # # ]: 0 : xSpriteCanvas->updateScreen(sal_False);
[ # # ][ # # ]
[ # # ]
339 : : }
340 : :
341 : 0 : void PresenterSlidePreview::Resize (void)
342 : : {
343 [ # # ][ # # ]: 0 : if (mxPreviewRenderer.is() && mxPreview.is())
[ # # ]
344 : : {
345 [ # # ][ # # ]: 0 : const awt::Rectangle aWindowBox (mxWindow->getPosSize());
346 [ # # ]: 0 : const awt::Size aNewPreviewSize (mxPreviewRenderer->calculatePreviewSize(
347 : : mnSlideAspectRatio,
348 [ # # ]: 0 : awt::Size(aWindowBox.Width, aWindowBox.Height)));
349 [ # # ][ # # ]: 0 : const geometry::IntegerSize2D aPreviewSize (mxPreview->getSize());
350 [ # # ][ # # ]: 0 : if (aNewPreviewSize.Width==aPreviewSize.Width
351 : : && aNewPreviewSize.Height==aPreviewSize.Height)
352 : : {
353 : : // The size of the window may have changed but the preview would
354 : : // be painted in the same size (but not necessarily at the same
355 : : // position.)
356 : 0 : return;
357 : : }
358 : : }
359 : 0 : SetSlide(mxCurrentSlide);
360 : : }
361 : :
362 : 0 : void PresenterSlidePreview::ThrowIfDisposed (void)
363 : : throw (::com::sun::star::lang::DisposedException)
364 : : {
365 [ # # ][ # # ]: 0 : if (PresenterSlidePreviewInterfaceBase::rBHelper.bDisposed || PresenterSlidePreviewInterfaceBase::rBHelper.bInDispose)
366 : : {
367 : : throw lang::DisposedException (
368 : : ::rtl::OUString( "PresenterSlidePreview object has already been disposed"),
369 [ # # ][ # # ]: 0 : static_cast<uno::XWeak*>(this));
370 : : }
371 : 0 : }
372 : :
373 : : } } // end of namespace ::sd::presenter
374 : :
375 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|