nss: upgrade to release 3.73
[LibreOffice.git] / sfx2 / source / doc / iframe.cxx
blobe37607c91a4642e799755608ac3ebbabe9af8993
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 .
20 #include <sal/config.h>
22 #include <com/sun/star/awt/XWindowPeer.hpp>
23 #include <com/sun/star/frame/XDispatch.hpp>
24 #include <com/sun/star/frame/Frame.hpp>
25 #include <com/sun/star/frame/XFrame2.hpp>
26 #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
27 #include <com/sun/star/util/URLTransformer.hpp>
28 #include <com/sun/star/util/XURLTransformer.hpp>
29 #include <com/sun/star/util/XCloseable.hpp>
30 #include <com/sun/star/lang/XEventListener.hpp>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
34 #include <com/sun/star/embed/XEmbeddedObject.hpp>
36 #include <cppuhelper/implbase.hxx>
37 #include <cppuhelper/supportsservice.hxx>
38 #include <officecfg/Office/Common.hxx>
39 #include <svl/itemprop.hxx>
40 #include <sfx2/frmdescr.hxx>
41 #include <sfx2/sfxdlg.hxx>
42 #include <toolkit/helper/vclunohelper.hxx>
43 #include <vcl/window.hxx>
44 #include <tools/debug.hxx>
46 using namespace ::com::sun::star;
48 namespace {
50 class IFrameObject : public ::cppu::WeakImplHelper <
51 css::util::XCloseable,
52 css::lang::XEventListener,
53 css::frame::XSynchronousFrameLoader,
54 css::ui::dialogs::XExecutableDialog,
55 css::lang::XServiceInfo,
56 css::beans::XPropertySet >
58 css::uno::Reference < css::uno::XComponentContext > mxContext;
59 css::uno::Reference < css::frame::XFrame2 > mxFrame;
60 css::uno::Reference < css::embed::XEmbeddedObject > mxObj;
61 SfxItemPropertyMap maPropMap;
62 SfxFrameDescriptor maFrmDescr;
64 public:
65 /// @throws css::uno::Exception
66 /// @throws css::uno::RuntimeException
67 IFrameObject(const css::uno::Reference < css::uno::XComponentContext>& rxContext, const css::uno::Sequence< css::uno::Any >& aArguments);
69 virtual OUString SAL_CALL getImplementationName() override
71 return "com.sun.star.comp.sfx2.IFrameObject";
74 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
76 return cppu::supportsService(this, ServiceName);
79 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
81 css::uno::Sequence< OUString > aSeq { "com.sun.star.frame.SpecialEmbeddedObject" };
82 return aSeq;
85 virtual sal_Bool SAL_CALL load( const css::uno::Sequence < css::beans::PropertyValue >& lDescriptor,
86 const css::uno::Reference < css::frame::XFrame >& xFrame ) override;
87 virtual void SAL_CALL cancel() override;
88 virtual void SAL_CALL close( sal_Bool bDeliverOwnership ) override;
89 virtual void SAL_CALL addCloseListener( const css::uno::Reference < css::util::XCloseListener >& xListener ) override;
90 virtual void SAL_CALL removeCloseListener( const css::uno::Reference < css::util::XCloseListener >& xListener ) override;
91 virtual void SAL_CALL disposing( const css::lang::EventObject& aEvent ) override ;
92 virtual void SAL_CALL setTitle( const OUString& aTitle ) override;
93 virtual ::sal_Int16 SAL_CALL execute( ) override;
94 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override;
95 virtual void SAL_CALL addPropertyChangeListener(const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > & aListener) override;
96 virtual void SAL_CALL removePropertyChangeListener(const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > & aListener) override;
97 virtual void SAL_CALL addVetoableChangeListener(const OUString& aPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > & aListener) override;
98 virtual void SAL_CALL removeVetoableChangeListener(const OUString& aPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > & aListener) override;
99 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
100 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
103 class IFrameWindow_Impl : public vcl::Window
105 public:
106 IFrameWindow_Impl( vcl::Window *pParent, bool bHasBorder );
109 IFrameWindow_Impl::IFrameWindow_Impl( vcl::Window *pParent, bool bHasBorder )
110 : Window( pParent, WB_CLIPCHILDREN | WB_NODIALOGCONTROL )
112 if ( !bHasBorder )
113 SetBorderStyle( WindowBorderStyle::NOBORDER );
114 else
115 SetBorderStyle( WindowBorderStyle::NORMAL );
118 #define PROPERTY_UNBOUND 0
120 #define WID_FRAME_URL 1
121 #define WID_FRAME_NAME 2
122 #define WID_FRAME_IS_AUTO_SCROLL 3
123 #define WID_FRAME_IS_SCROLLING_MODE 4
124 #define WID_FRAME_IS_BORDER 5
125 #define WID_FRAME_IS_AUTO_BORDER 6
126 #define WID_FRAME_MARGIN_WIDTH 7
127 #define WID_FRAME_MARGIN_HEIGHT 8
129 const SfxItemPropertyMapEntry* lcl_GetIFramePropertyMap_Impl()
131 static const SfxItemPropertyMapEntry aIFramePropertyMap_Impl[] =
133 { u"FrameIsAutoBorder", WID_FRAME_IS_AUTO_BORDER, cppu::UnoType<bool>::get(), PROPERTY_UNBOUND, 0 },
134 { u"FrameIsAutoScroll", WID_FRAME_IS_AUTO_SCROLL, cppu::UnoType<bool>::get(), PROPERTY_UNBOUND, 0 },
135 { u"FrameIsBorder", WID_FRAME_IS_BORDER, cppu::UnoType<bool>::get(), PROPERTY_UNBOUND, 0 },
136 { u"FrameIsScrollingMode", WID_FRAME_IS_SCROLLING_MODE,cppu::UnoType<bool>::get(), PROPERTY_UNBOUND, 0 },
137 { u"FrameMarginHeight", WID_FRAME_MARGIN_HEIGHT, cppu::UnoType<sal_Int32>::get(), PROPERTY_UNBOUND, 0 },
138 { u"FrameMarginWidth", WID_FRAME_MARGIN_WIDTH, cppu::UnoType<sal_Int32>::get(), PROPERTY_UNBOUND, 0 },
139 { u"FrameName", WID_FRAME_NAME, cppu::UnoType<OUString>::get(), PROPERTY_UNBOUND, 0 },
140 { u"FrameURL", WID_FRAME_URL, cppu::UnoType<OUString>::get(), PROPERTY_UNBOUND, 0 },
141 { u"", 0, css::uno::Type(), 0, 0 }
143 return aIFramePropertyMap_Impl;
146 IFrameObject::IFrameObject(const uno::Reference < uno::XComponentContext >& rxContext, const css::uno::Sequence< css::uno::Any >& aArguments)
147 : mxContext( rxContext )
148 , maPropMap( lcl_GetIFramePropertyMap_Impl() )
150 if ( aArguments.hasElements() )
151 aArguments[0] >>= mxObj;
154 sal_Bool SAL_CALL IFrameObject::load(
155 const uno::Sequence < css::beans::PropertyValue >& /*lDescriptor*/,
156 const uno::Reference < frame::XFrame >& xFrame )
158 if ( officecfg::Office::Common::Misc::PluginsEnabled::get() )
160 DBG_ASSERT( !mxFrame.is(), "Frame already existing!" );
161 VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
162 VclPtr<IFrameWindow_Impl> pWin = VclPtr<IFrameWindow_Impl>::Create( pParent, maFrmDescr.IsFrameBorderOn() );
163 pWin->SetSizePixel( pParent->GetOutputSizePixel() );
164 pWin->SetBackground();
165 pWin->Show();
167 uno::Reference < awt::XWindow > xWindow( pWin->GetComponentInterface(), uno::UNO_QUERY );
168 xFrame->setComponent( xWindow, uno::Reference < frame::XController >() );
170 // we must destroy the IFrame before the parent is destroyed
171 xWindow->addEventListener( this );
173 mxFrame = frame::Frame::create( mxContext );
174 uno::Reference < awt::XWindow > xWin( pWin->GetComponentInterface(), uno::UNO_QUERY );
175 mxFrame->initialize( xWin );
176 mxFrame->setName( maFrmDescr.GetName() );
178 uno::Reference < frame::XFramesSupplier > xFramesSupplier( xFrame, uno::UNO_QUERY );
179 if ( xFramesSupplier.is() )
180 mxFrame->setCreator( xFramesSupplier );
182 util::URL aTargetURL;
183 aTargetURL.Complete = maFrmDescr.GetURL().GetMainURL( INetURLObject::DecodeMechanism::NONE );
184 uno::Reference < util::XURLTransformer > xTrans( util::URLTransformer::create( mxContext ) );
185 xTrans->parseStrict( aTargetURL );
187 uno::Sequence < beans::PropertyValue > aProps(2);
188 aProps[0].Name = "PluginMode";
189 aProps[0].Value <<= sal_Int16(2);
190 aProps[1].Name = "ReadOnly";
191 aProps[1].Value <<= true;
192 uno::Reference < frame::XDispatch > xDisp = mxFrame->queryDispatch( aTargetURL, "_self", 0 );
193 if ( xDisp.is() )
194 xDisp->dispatch( aTargetURL, aProps );
196 return true;
199 return false;
202 void SAL_CALL IFrameObject::cancel()
206 uno::Reference < util::XCloseable > xClose( mxFrame, uno::UNO_QUERY );
207 if ( xClose.is() )
208 xClose->close( true );
209 mxFrame = nullptr;
211 catch (const uno::Exception&)
216 void SAL_CALL IFrameObject::close( sal_Bool /*bDeliverOwnership*/ )
220 void SAL_CALL IFrameObject::addCloseListener( const css::uno::Reference < css::util::XCloseListener >& )
224 void SAL_CALL IFrameObject::removeCloseListener( const css::uno::Reference < css::util::XCloseListener >& )
228 void SAL_CALL IFrameObject::disposing( const css::lang::EventObject& )
230 cancel();
233 uno::Reference< beans::XPropertySetInfo > SAL_CALL IFrameObject::getPropertySetInfo()
235 static uno::Reference< beans::XPropertySetInfo > xInfo = new SfxItemPropertySetInfo( maPropMap );
236 return xInfo;
239 void SAL_CALL IFrameObject::setPropertyValue(const OUString& aPropertyName, const uno::Any& aAny)
241 const SfxItemPropertySimpleEntry* pEntry = maPropMap.getByName( aPropertyName );
242 if( !pEntry )
243 throw beans::UnknownPropertyException(aPropertyName);
244 switch( pEntry->nWID )
246 case WID_FRAME_URL:
248 OUString aURL;
249 aAny >>= aURL;
250 maFrmDescr.SetURL( aURL );
252 break;
253 case WID_FRAME_NAME:
255 OUString aName;
256 if ( aAny >>= aName )
257 maFrmDescr.SetName( aName );
259 break;
260 case WID_FRAME_IS_AUTO_SCROLL:
262 bool bIsAutoScroll;
263 if ( (aAny >>= bIsAutoScroll) && bIsAutoScroll )
264 maFrmDescr.SetScrollingMode( ScrollingMode::Auto );
266 break;
267 case WID_FRAME_IS_SCROLLING_MODE:
269 bool bIsScroll;
270 if ( aAny >>= bIsScroll )
271 maFrmDescr.SetScrollingMode( bIsScroll ? ScrollingMode::Yes : ScrollingMode::No );
273 break;
274 case WID_FRAME_IS_BORDER:
276 bool bIsBorder;
277 if ( aAny >>= bIsBorder )
278 maFrmDescr.SetFrameBorder( bIsBorder );
280 break;
281 case WID_FRAME_IS_AUTO_BORDER:
283 bool bIsAutoBorder;
284 if ( aAny >>= bIsAutoBorder )
286 bool bBorder = maFrmDescr.IsFrameBorderOn();
287 maFrmDescr.ResetBorder();
288 if ( bIsAutoBorder )
289 maFrmDescr.SetFrameBorder( bBorder );
292 break;
293 case WID_FRAME_MARGIN_WIDTH:
295 sal_Int32 nMargin = 0;
296 Size aSize = maFrmDescr.GetMargin();
297 if ( aAny >>= nMargin )
299 aSize.setWidth( nMargin );
300 maFrmDescr.SetMargin( aSize );
303 break;
304 case WID_FRAME_MARGIN_HEIGHT:
306 sal_Int32 nMargin = 0;
307 Size aSize = maFrmDescr.GetMargin();
308 if ( aAny >>= nMargin )
310 aSize.setHeight( nMargin );
311 maFrmDescr.SetMargin( aSize );
314 break;
315 default: ;
319 uno::Any SAL_CALL IFrameObject::getPropertyValue(const OUString& aPropertyName)
321 const SfxItemPropertySimpleEntry* pEntry = maPropMap.getByName( aPropertyName );
322 if( !pEntry )
323 throw beans::UnknownPropertyException(aPropertyName);
324 uno::Any aAny;
325 switch( pEntry->nWID )
327 case WID_FRAME_URL:
329 aAny <<= maFrmDescr.GetURL().GetMainURL( INetURLObject::DecodeMechanism::NONE );
331 break;
332 case WID_FRAME_NAME:
334 aAny <<= maFrmDescr.GetName();
336 break;
337 case WID_FRAME_IS_AUTO_SCROLL:
339 bool bIsAutoScroll = ( maFrmDescr.GetScrollingMode() == ScrollingMode::Auto );
340 aAny <<= bIsAutoScroll;
342 break;
343 case WID_FRAME_IS_SCROLLING_MODE:
345 bool bIsScroll = ( maFrmDescr.GetScrollingMode() == ScrollingMode::Yes );
346 aAny <<= bIsScroll;
348 break;
349 case WID_FRAME_IS_BORDER:
351 bool bIsBorder = maFrmDescr.IsFrameBorderOn();
352 aAny <<= bIsBorder;
354 break;
355 case WID_FRAME_IS_AUTO_BORDER:
357 bool bIsAutoBorder = !maFrmDescr.IsFrameBorderSet();
358 aAny <<= bIsAutoBorder;
360 break;
361 case WID_FRAME_MARGIN_WIDTH:
363 aAny <<= static_cast<sal_Int32>(maFrmDescr.GetMargin().Width());
365 break;
366 case WID_FRAME_MARGIN_HEIGHT:
368 aAny <<= static_cast<sal_Int32>(maFrmDescr.GetMargin().Height());
370 break;
371 default: ;
373 return aAny;
376 void SAL_CALL IFrameObject::addPropertyChangeListener(const OUString&, const css::uno::Reference< css::beans::XPropertyChangeListener > & )
380 void SAL_CALL IFrameObject::removePropertyChangeListener(const OUString&, const css::uno::Reference< css::beans::XPropertyChangeListener > & )
384 void SAL_CALL IFrameObject::addVetoableChangeListener(const OUString&, const css::uno::Reference< css::beans::XVetoableChangeListener > & )
388 void SAL_CALL IFrameObject::removeVetoableChangeListener(const OUString&, const css::uno::Reference< css::beans::XVetoableChangeListener > & )
392 ::sal_Int16 SAL_CALL IFrameObject::execute()
394 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
395 //we really should set a parent here
396 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateEditObjectDialog(nullptr, ".uno:InsertObjectFloatingFrame", mxObj));
397 pDlg->Execute();
398 return 0;
401 void SAL_CALL IFrameObject::setTitle( const OUString& )
407 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
408 com_sun_star_comp_sfx2_IFrameObject_get_implementation(
409 css::uno::XComponentContext *context,
410 css::uno::Sequence<css::uno::Any> const &arguments)
412 return cppu::acquire(new IFrameObject(context, arguments));
415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */