Bump version to 4.1-6
[LibreOffice.git] / sfx2 / source / doc / plugin.cxx
blob07857565212c553dd8c4bc591a52a3e5266486a7
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 #include "plugin.hxx"
22 #include <com/sun/star/plugin/PluginManager.hpp>
23 #include <com/sun/star/plugin/XPluginManager.hpp>
24 #include <com/sun/star/plugin/PluginMode.hpp>
25 #include <com/sun/star/awt/XControl.hpp>
27 #include <comphelper/processfactory.hxx>
28 #include <rtl/ustring.hxx>
29 #include <toolkit/helper/vclunohelper.hxx>
30 #include <svtools/miscopt.hxx>
31 #include <vcl/window.hxx>
33 using namespace ::com::sun::star;
35 namespace sfx2
38 class PluginWindow_Impl : public Window
40 public:
41 uno::Reference < awt::XWindow > xWindow;
42 PluginWindow_Impl( Window* pParent )
43 : Window( pParent, WB_CLIPCHILDREN )
46 virtual void Resize();
49 void PluginWindow_Impl::Resize()
51 Size aSize( GetOutputSizePixel() );
52 if ( xWindow.is() )
53 xWindow->setPosSize( 0, 0, aSize.Width(), aSize.Height(), WINDOW_POSSIZE_SIZE );
56 #define PROPERTY_UNBOUND 0
58 #define WID_COMMANDS 1
59 #define WID_MIMETYPE 2
60 #define WID_URL 3
61 const SfxItemPropertyMapEntry* lcl_GetPluginPropertyMap_Impl()
63 static SfxItemPropertyMapEntry aPluginPropertyMap_Impl[] =
65 { MAP_CHAR_LEN("PluginCommands"), WID_COMMANDS, &::getCppuType((::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >*)0), PROPERTY_UNBOUND, 0},
66 { MAP_CHAR_LEN("PluginMimeType"), WID_MIMETYPE, &::getCppuType((const OUString*)0), PROPERTY_UNBOUND, 0 },
67 { MAP_CHAR_LEN("PluginURL"), WID_URL , &::getCppuType((const OUString*)0), PROPERTY_UNBOUND, 0 },
68 {0,0,0,0,0,0}
70 return aPluginPropertyMap_Impl;
73 SFX_IMPL_XSERVICEINFO( PluginObject, "com.sun.star.embed.SpecialEmbeddedObject", "com.sun.star.comp.sfx2.PluginObject" )
74 SFX_IMPL_SINGLEFACTORY( PluginObject );
76 PluginObject::PluginObject( const uno::Reference < lang::XMultiServiceFactory >& rFact )
77 : mxFact( rFact )
78 , maPropMap( lcl_GetPluginPropertyMap_Impl() )
82 PluginObject::~PluginObject()
86 void SAL_CALL PluginObject::initialize( const uno::Sequence< uno::Any >& aArguments ) throw ( uno::Exception, uno::RuntimeException )
88 if ( aArguments.getLength() )
89 aArguments[0] >>= mxObj;
92 sal_Bool SAL_CALL PluginObject::load(
93 const uno::Sequence < com::sun::star::beans::PropertyValue >& /*lDescriptor*/,
94 const uno::Reference < frame::XFrame >& xFrame )
95 throw( uno::RuntimeException )
97 uno::Reference< plugin::XPluginManager > xPMgr( plugin::PluginManager::create(comphelper::getComponentContext(mxFact)) );
99 if ( SvtMiscOptions().IsPluginsEnabled() )
101 Window* pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
102 PluginWindow_Impl* pWin = new PluginWindow_Impl( pParent );
103 pWin->SetSizePixel( pParent->GetOutputSizePixel() );
104 pWin->SetBackground();
105 pWin->Show();
107 size_t nCount = maCmdList.size();
108 uno::Sequence < OUString > aCmds( nCount ), aArgs( nCount );
109 OUString *pCmds = aCmds.getArray(), *pArgs = aArgs.getArray();
110 for( size_t i = 0; i < nCount; i++ )
112 pCmds[i] = maCmdList[ i ].GetCommand();
113 pArgs[i] = maCmdList[ i ].GetArgument();
116 mxPlugin = xPMgr->createPluginFromURL(
117 xPMgr->createPluginContext(), plugin::PluginMode::EMBED, aCmds, aArgs, uno::Reference< awt::XToolkit >(),
118 uno::Reference< awt::XWindowPeer >( pWin->GetComponentInterface() ), maURL );
120 if ( mxPlugin.is() )
122 uno::Reference< awt::XWindow > xWindow( mxPlugin, uno::UNO_QUERY );
123 if ( xWindow.is() )
125 pWin->xWindow = xWindow;
126 pWin->Resize();
127 xWindow->setVisible( sal_True );
132 uno::Reference< awt::XControl > xControl( mxPlugin, uno::UNO_QUERY );
133 if( xControl.is() )
135 uno::Reference< awt::XControlModel > xModel = xControl->getModel();
136 uno::Reference< beans::XPropertySet > xProp( xModel, ::uno::UNO_QUERY );
137 if( xProp.is() )
139 uno::Any aValue = xProp->getPropertyValue( OUString( "URL" ) );
140 aValue >>= maURL;
141 aValue = xProp->getPropertyValue( OUString( "TYPE" ) );
142 aValue >>= maMimeType;
146 catch( const uno::Exception& )
151 uno::Reference < awt::XWindow > xWindow( pWin->GetComponentInterface(), uno::UNO_QUERY );
153 // we must destroy the plugin before the parent is destroyed
154 xWindow->addEventListener( this );
155 xFrame->setComponent( xWindow, uno::Reference < frame::XController >() );
156 return mxPlugin.is() ? sal_True : sal_False;
159 return sal_False;
162 void SAL_CALL PluginObject::cancel() throw( com::sun::star::uno::RuntimeException )
164 uno::Reference< lang::XComponent > xComp( mxPlugin, uno::UNO_QUERY );
165 if (xComp.is())
166 xComp->dispose();
167 mxPlugin = 0;
170 void SAL_CALL PluginObject::close( sal_Bool /*bDeliverOwnership*/ ) throw( com::sun::star::util::CloseVetoException, com::sun::star::uno::RuntimeException )
174 void SAL_CALL PluginObject::addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
178 void SAL_CALL PluginObject::removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
182 void SAL_CALL PluginObject::disposing( const com::sun::star::lang::EventObject& ) throw (com::sun::star::uno::RuntimeException)
184 cancel();
187 uno::Reference< beans::XPropertySetInfo > SAL_CALL PluginObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException )
189 static uno::Reference< beans::XPropertySetInfo > xInfo = new SfxItemPropertySetInfo( maPropMap );
190 return xInfo;
193 void SAL_CALL PluginObject::setPropertyValue(const OUString& aPropertyName, const uno::Any& aAny)
194 throw ( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
196 if ( aPropertyName == "PluginURL" )
198 aAny >>= maURL;
200 else if ( aPropertyName == "PluginMimeType" )
202 aAny >>= maMimeType;
204 else if ( aPropertyName == "PluginCommands" )
206 maCmdList.clear();
207 uno::Sequence < beans::PropertyValue > aCommandSequence;
208 if( aAny >>= aCommandSequence )
209 maCmdList.FillFromSequence( aCommandSequence );
211 else
212 throw beans::UnknownPropertyException();
215 uno::Any SAL_CALL PluginObject::getPropertyValue(const OUString& aPropertyName)
216 throw ( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
218 uno::Any aAny;
219 if ( aPropertyName == "PluginURL" )
221 aAny <<= maURL;
223 else if ( aPropertyName == "PluginMimeType" )
225 aAny <<= maMimeType;
227 else if ( aPropertyName == "PluginCommands" )
229 uno::Sequence< beans::PropertyValue > aCommandSequence;
230 maCmdList.FillSequence( aCommandSequence );
231 aAny <<= aCommandSequence;
233 else
234 throw beans::UnknownPropertyException();
235 return aAny;
238 void SAL_CALL PluginObject::addPropertyChangeListener(const OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
242 void SAL_CALL PluginObject::removePropertyChangeListener(const OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
246 void SAL_CALL PluginObject::addVetoableChangeListener(const OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
250 void SAL_CALL PluginObject::removeVetoableChangeListener(const OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */