fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / slideshow / source / engine / shapes / viewappletshape.cxx
blob00f2456c7c1ead0ed16cba75e095428297878387
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 // must be first
22 #include <canvas/verbosetrace.hxx>
23 #include <tools/diagnose_ex.h>
24 #include <canvas/debug.hxx>
26 #include <comphelper/anytostring.hxx>
27 #include <cppuhelper/exc_hlp.hxx>
29 #include <basegfx/matrix/b2dhommatrix.hxx>
30 #include <basegfx/range/b2irange.hxx>
31 #include <basegfx/tools/canvastools.hxx>
33 #include <cppcanvas/spritecanvas.hxx>
34 #include <canvas/canvastools.hxx>
36 #include <com/sun/star/uno/XComponentContext.hpp>
37 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
38 #include <com/sun/star/rendering/XCanvas.hpp>
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/beans/PropertyValue.hpp>
42 #include <com/sun/star/util/XCloseable.hpp>
43 #include <com/sun/star/awt/WindowDescriptor.hpp>
44 #include <com/sun/star/awt/Toolkit.hpp>
45 #include <com/sun/star/awt/XWindow2.hpp>
46 #include <com/sun/star/awt/XWindowPeer.hpp>
47 #include <com/sun/star/awt/WindowAttribute.hpp>
48 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
49 #include <com/sun/star/awt/PosSize.hpp>
50 #include <com/sun/star/frame/Frame.hpp>
51 #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
53 #include "viewappletshape.hxx"
54 #include "tools.hxx"
57 using namespace ::com::sun::star;
59 namespace slideshow
61 namespace internal
63 ViewAppletShape::ViewAppletShape( const ViewLayerSharedPtr& rViewLayer,
64 const uno::Reference< drawing::XShape >& rxShape,
65 const OUString& rServiceName,
66 const char** pPropCopyTable,
67 sal_Size nNumPropEntries,
68 const uno::Reference< uno::XComponentContext >& rxContext ) :
69 mpViewLayer( rViewLayer ),
70 mxViewer(),
71 mxFrame(),
72 mxComponentContext( rxContext )
74 ENSURE_OR_THROW( rxShape.is(), "ViewAppletShape::ViewAppletShape(): Invalid Shape" );
75 ENSURE_OR_THROW( mpViewLayer, "ViewAppletShape::ViewAppletShape(): Invalid View" );
76 ENSURE_OR_THROW( mpViewLayer->getCanvas(), "ViewAppletShape::ViewAppletShape(): Invalid ViewLayer canvas" );
77 ENSURE_OR_THROW( mxComponentContext.is(), "ViewAppletShape::ViewAppletShape(): Invalid component context" );
79 uno::Reference<lang::XMultiComponentFactory> xFactory(
80 mxComponentContext->getServiceManager(),
81 uno::UNO_QUERY_THROW );
83 mxViewer.set( xFactory->createInstanceWithContext( rServiceName,
84 mxComponentContext),
85 uno::UNO_QUERY_THROW );
87 uno::Reference< beans::XPropertySet > xShapePropSet( rxShape,
88 uno::UNO_QUERY_THROW );
89 uno::Reference< beans::XPropertySet > mxViewerPropSet( mxViewer,
90 uno::UNO_QUERY_THROW );
92 // copy shape properties to applet viewer
93 OUString aPropName;
94 for( sal_Size i=0; i<nNumPropEntries; ++i )
96 aPropName = OUString::createFromAscii( pPropCopyTable[i] );
97 mxViewerPropSet->setPropertyValue( aPropName,
98 xShapePropSet->getPropertyValue(
99 aPropName ));
105 ViewAppletShape::~ViewAppletShape()
109 endApplet();
111 catch (uno::Exception &)
113 OSL_FAIL( OUStringToOString(
114 comphelper::anyToString(
115 cppu::getCaughtException() ),
116 RTL_TEXTENCODING_UTF8 ).getStr() );
122 ViewLayerSharedPtr ViewAppletShape::getViewLayer() const
124 return mpViewLayer;
129 bool ViewAppletShape::startApplet( const ::basegfx::B2DRectangle& rBounds )
131 ENSURE_OR_RETURN_FALSE( mpViewLayer && mpViewLayer->getCanvas() && mpViewLayer->getCanvas()->getUNOCanvas().is(),
132 "ViewAppletShape::startApplet(): Invalid or disposed view" );
135 ::cppcanvas::CanvasSharedPtr pCanvas = mpViewLayer->getCanvas();
137 uno::Reference< beans::XPropertySet > xPropSet( pCanvas->getUNOCanvas()->getDevice(),
138 uno::UNO_QUERY_THROW );
140 uno::Reference< awt::XWindow2 > xParentWindow(
141 xPropSet->getPropertyValue(
142 OUString("Window" )),
143 uno::UNO_QUERY_THROW );
145 uno::Reference<lang::XMultiComponentFactory> xFactory(
146 mxComponentContext->getServiceManager() );
148 if( xFactory.is() )
150 // create an awt window to contain the applet
151 // ==========================================
153 uno::Reference< awt::XToolkit2 > xToolkit = awt::Toolkit::create(mxComponentContext);
155 awt::WindowDescriptor aOwnWinDescriptor( awt::WindowClass_SIMPLE,
156 OUString(),
157 uno::Reference< awt::XWindowPeer >(xParentWindow,
158 uno::UNO_QUERY_THROW),
160 awt::Rectangle(),
161 awt::WindowAttribute::SHOW
162 | awt::VclWindowPeerAttribute::CLIPCHILDREN );
164 uno::Reference< awt::XWindowPeer > xNewWinPeer(
165 xToolkit->createWindow( aOwnWinDescriptor ));
166 uno::Reference< awt::XWindow > xOwnWindow( xNewWinPeer,
167 uno::UNO_QUERY_THROW );
170 // create a frame, and load the applet into it
171 // ===========================================
173 mxFrame = frame::Frame::create( mxComponentContext );
174 mxFrame->initialize( xOwnWindow );
176 uno::Reference < frame::XSynchronousFrameLoader > xLoader( mxViewer,
177 uno::UNO_QUERY_THROW );
178 xLoader->load( uno::Sequence < beans::PropertyValue >(),
179 uno::Reference<frame::XFrame>(mxFrame, uno::UNO_QUERY_THROW) );
182 // resize surrounding window and applet to current shape size
183 // ==========================================================
185 ::basegfx::B2DRange aTmpRange;
186 ::canvas::tools::calcTransformedRectBounds( aTmpRange,
187 rBounds,
188 mpViewLayer->getTransformation() );
189 const ::basegfx::B2IRange& rPixelBounds(
190 ::basegfx::unotools::b2ISurroundingRangeFromB2DRange( aTmpRange ));
192 uno::Reference< awt::XWindow > xSurroundingWindow( mxFrame->getContainerWindow() );
193 if( xSurroundingWindow.is() )
194 xSurroundingWindow->setPosSize( static_cast<sal_Int32>(rPixelBounds.getMinX()),
195 static_cast<sal_Int32>(rPixelBounds.getMinY()),
196 static_cast<sal_Int32>(rPixelBounds.getWidth()),
197 static_cast<sal_Int32>(rPixelBounds.getHeight()),
198 awt::PosSize::POSSIZE );
200 uno::Reference< awt::XWindow > xAppletWindow( mxFrame->getComponentWindow() );
201 if( xAppletWindow.is() )
202 xAppletWindow->setPosSize( 0, 0,
203 static_cast<sal_Int32>(rPixelBounds.getWidth()),
204 static_cast<sal_Int32>(rPixelBounds.getHeight()),
205 awt::PosSize::POSSIZE );
208 catch (uno::Exception &)
210 return false;
213 return true;
218 void ViewAppletShape::endApplet()
220 uno::Reference<util::XCloseable> xCloseable(
221 mxFrame,
222 uno::UNO_QUERY );
224 if( xCloseable.is() )
226 xCloseable->close( sal_True );
227 mxFrame.clear();
233 bool ViewAppletShape::render( const ::basegfx::B2DRectangle& rBounds ) const
235 ::cppcanvas::CanvasSharedPtr pCanvas = mpViewLayer->getCanvas();
237 if( !pCanvas )
238 return false;
240 if( !mxFrame.is() )
242 // fill the shape background with black
243 fillRect( pCanvas,
244 rBounds,
245 0xFFFFFFFFU );
248 return true;
251 bool ViewAppletShape::resize( const ::basegfx::B2DRectangle& rBounds ) const
253 if( !mxFrame.is() )
254 return false;
256 ::basegfx::B2DRange aTmpRange;
257 ::canvas::tools::calcTransformedRectBounds( aTmpRange,
258 rBounds,
259 mpViewLayer->getTransformation() );
260 const ::basegfx::B2IRange& rPixelBounds(
261 ::basegfx::unotools::b2ISurroundingRangeFromB2DRange( aTmpRange ));
263 uno::Reference< awt::XWindow > xFrameWindow( mxFrame->getContainerWindow() );
264 if( xFrameWindow.is() )
265 xFrameWindow->setPosSize( static_cast<sal_Int32>(rPixelBounds.getMinX()),
266 static_cast<sal_Int32>(rPixelBounds.getMinY()),
267 static_cast<sal_Int32>(rPixelBounds.getWidth()),
268 static_cast<sal_Int32>(rPixelBounds.getHeight()),
269 awt::PosSize::POSSIZE );
271 uno::Reference< awt::XWindow > xAppletWindow( mxFrame->getComponentWindow() );
272 if( xAppletWindow.is() )
273 xAppletWindow->setPosSize( 0, 0,
274 static_cast<sal_Int32>(rPixelBounds.getWidth()),
275 static_cast<sal_Int32>(rPixelBounds.getHeight()),
276 awt::PosSize::POSSIZE );
278 return true;
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */