1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/frame/XDispatch.hpp>
23 #include <com/sun/star/frame/Frame.hpp>
24 #include <com/sun/star/frame/XFrame2.hpp>
25 #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
26 #include <com/sun/star/util/URLTransformer.hpp>
27 #include <com/sun/star/util/XURLTransformer.hpp>
28 #include <com/sun/star/util/XCloseable.hpp>
29 #include <com/sun/star/lang/XEventListener.hpp>
30 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
33 #include <com/sun/star/embed/XEmbeddedObject.hpp>
35 #include <cppuhelper/implbase.hxx>
36 #include <cppuhelper/supportsservice.hxx>
37 #include <rtl/ref.hxx>
38 #include <svtools/miscopt.hxx>
39 #include <svl/ownlist.hxx>
40 #include <svl/itemprop.hxx>
41 #include <sfx2/frmdescr.hxx>
42 #include <sfx2/sfxdlg.hxx>
43 #include <sfx2/sfxsids.hrc>
44 #include <toolkit/helper/vclunohelper.hxx>
45 #include <vcl/window.hxx>
47 using namespace ::com::sun::star
;
51 class IFrameObject
: public ::cppu::WeakImplHelper
<
52 css::util::XCloseable
,
53 css::lang::XEventListener
,
54 css::frame::XSynchronousFrameLoader
,
55 css::ui::dialogs::XExecutableDialog
,
56 css::lang::XServiceInfo
,
57 css::beans::XPropertySet
>
59 css::uno::Reference
< css::uno::XComponentContext
> mxContext
;
60 css::uno::Reference
< css::frame::XFrame2
> mxFrame
;
61 css::uno::Reference
< css::embed::XEmbeddedObject
> mxObj
;
62 SfxItemPropertyMap maPropMap
;
63 SfxFrameDescriptor maFrmDescr
;
66 IFrameObject(const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
, const css::uno::Sequence
< css::uno::Any
>& aArguments
)
67 throw (css::uno::Exception
, css::uno::RuntimeException
);
68 virtual ~IFrameObject() override
;
70 virtual OUString SAL_CALL
getImplementationName()
71 throw (css::uno::RuntimeException
, std::exception
) override
73 return OUString("com.sun.star.comp.sfx2.IFrameObject");
76 virtual sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
)
77 throw (css::uno::RuntimeException
, std::exception
) override
79 return cppu::supportsService(this, ServiceName
);
82 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames()
83 throw (css::uno::RuntimeException
, std::exception
) override
85 css::uno::Sequence
< OUString
> aSeq
{ "com.sun.star.frame.SpecialEmbeddedObject" };
89 virtual sal_Bool SAL_CALL
load( const css::uno::Sequence
< css::beans::PropertyValue
>& lDescriptor
,
90 const css::uno::Reference
< css::frame::XFrame
>& xFrame
) throw( css::uno::RuntimeException
, std::exception
) override
;
91 virtual void SAL_CALL
cancel() throw( css::uno::RuntimeException
, std::exception
) override
;
92 virtual void SAL_CALL
close( sal_Bool bDeliverOwnership
) throw( css::util::CloseVetoException
, css::uno::RuntimeException
, std::exception
) override
;
93 virtual void SAL_CALL
addCloseListener( const css::uno::Reference
< css::util::XCloseListener
>& xListener
) throw( css::uno::RuntimeException
, std::exception
) override
;
94 virtual void SAL_CALL
removeCloseListener( const css::uno::Reference
< css::util::XCloseListener
>& xListener
) throw( css::uno::RuntimeException
, std::exception
) override
;
95 virtual void SAL_CALL
disposing( const css::lang::EventObject
& aEvent
) throw (css::uno::RuntimeException
, std::exception
) override
;
96 virtual void SAL_CALL
setTitle( const OUString
& aTitle
) throw (css::uno::RuntimeException
, std::exception
) override
;
97 virtual ::sal_Int16 SAL_CALL
execute( ) throw (css::uno::RuntimeException
, std::exception
) override
;
98 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() throw( css::uno::RuntimeException
, std::exception
) override
;
99 virtual void SAL_CALL
addPropertyChangeListener(const OUString
& aPropertyName
, const css::uno::Reference
< css::beans::XPropertyChangeListener
> & aListener
) throw( css::uno::RuntimeException
, std::exception
) override
;
100 virtual void SAL_CALL
removePropertyChangeListener(const OUString
& aPropertyName
, const css::uno::Reference
< css::beans::XPropertyChangeListener
> & aListener
) throw( css::uno::RuntimeException
, std::exception
) override
;
101 virtual void SAL_CALL
addVetoableChangeListener(const OUString
& aPropertyName
, const css::uno::Reference
< css::beans::XVetoableChangeListener
> & aListener
) throw( css::uno::RuntimeException
, std::exception
) override
;
102 virtual void SAL_CALL
removeVetoableChangeListener(const OUString
& aPropertyName
, const css::uno::Reference
< css::beans::XVetoableChangeListener
> & aListener
) throw( css::uno::RuntimeException
, std::exception
) override
;
103 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
, const css::uno::Any
& aValue
) throw (css::beans::UnknownPropertyException
, css::beans::PropertyVetoException
, css::lang::IllegalArgumentException
, css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) override
;
104 virtual css::uno::Any SAL_CALL
getPropertyValue( const OUString
& PropertyName
) throw (css::beans::UnknownPropertyException
, css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) override
;
107 class IFrameWindow_Impl
: public vcl::Window
110 IFrameWindow_Impl( vcl::Window
*pParent
, bool bHasBorder
);
113 IFrameWindow_Impl::IFrameWindow_Impl( vcl::Window
*pParent
, bool bHasBorder
)
114 : Window( pParent
, WB_CLIPCHILDREN
| WB_NODIALOGCONTROL
| WB_DOCKBORDER
)
117 SetBorderStyle( WindowBorderStyle::NOBORDER
);
119 SetBorderStyle( WindowBorderStyle::NORMAL
);
122 #define PROPERTY_UNBOUND 0
124 #define WID_FRAME_URL 1
125 #define WID_FRAME_NAME 2
126 #define WID_FRAME_IS_AUTO_SCROLL 3
127 #define WID_FRAME_IS_SCROLLING_MODE 4
128 #define WID_FRAME_IS_BORDER 5
129 #define WID_FRAME_IS_AUTO_BORDER 6
130 #define WID_FRAME_MARGIN_WIDTH 7
131 #define WID_FRAME_MARGIN_HEIGHT 8
133 const SfxItemPropertyMapEntry
* lcl_GetIFramePropertyMap_Impl()
135 static const SfxItemPropertyMapEntry aIFramePropertyMap_Impl
[] =
137 { OUString("FrameIsAutoBorder"), WID_FRAME_IS_AUTO_BORDER
, cppu::UnoType
<bool>::get(), PROPERTY_UNBOUND
, 0 },
138 { OUString("FrameIsAutoScroll"), WID_FRAME_IS_AUTO_SCROLL
, cppu::UnoType
<bool>::get(), PROPERTY_UNBOUND
, 0 },
139 { OUString("FrameIsBorder"), WID_FRAME_IS_BORDER
, cppu::UnoType
<bool>::get(), PROPERTY_UNBOUND
, 0 },
140 { OUString("FrameIsScrollingMode"), WID_FRAME_IS_SCROLLING_MODE
,cppu::UnoType
<bool>::get(), PROPERTY_UNBOUND
, 0 },
141 { OUString("FrameMarginHeight"), WID_FRAME_MARGIN_HEIGHT
, cppu::UnoType
<sal_Int32
>::get(), PROPERTY_UNBOUND
, 0 },
142 { OUString("FrameMarginWidth"), WID_FRAME_MARGIN_WIDTH
, cppu::UnoType
<sal_Int32
>::get(), PROPERTY_UNBOUND
, 0 },
143 { OUString("FrameName"), WID_FRAME_NAME
, cppu::UnoType
<OUString
>::get(), PROPERTY_UNBOUND
, 0 },
144 { OUString("FrameURL"), WID_FRAME_URL
, cppu::UnoType
<OUString
>::get(), PROPERTY_UNBOUND
, 0 },
145 { OUString(), 0, css::uno::Type(), 0, 0 }
147 return aIFramePropertyMap_Impl
;
150 IFrameObject::IFrameObject(const uno::Reference
< uno::XComponentContext
>& rxContext
, const css::uno::Sequence
< css::uno::Any
>& aArguments
)
151 throw ( uno::Exception
, uno::RuntimeException
)
152 : mxContext( rxContext
)
153 , maPropMap( lcl_GetIFramePropertyMap_Impl() )
155 if ( aArguments
.getLength() )
156 aArguments
[0] >>= mxObj
;
159 IFrameObject::~IFrameObject()
163 sal_Bool SAL_CALL
IFrameObject::load(
164 const uno::Sequence
< css::beans::PropertyValue
>& /*lDescriptor*/,
165 const uno::Reference
< frame::XFrame
>& xFrame
)
166 throw( uno::RuntimeException
, std::exception
)
168 if ( SvtMiscOptions().IsPluginsEnabled() )
170 DBG_ASSERT( !mxFrame
.is(), "Frame already existing!" );
171 VclPtr
<vcl::Window
> pParent
= VCLUnoHelper::GetWindow( xFrame
->getContainerWindow() );
172 VclPtr
<IFrameWindow_Impl
> pWin
= VclPtr
<IFrameWindow_Impl
>::Create( pParent
, maFrmDescr
.IsFrameBorderOn() );
173 pWin
->SetSizePixel( pParent
->GetOutputSizePixel() );
174 pWin
->SetBackground();
177 uno::Reference
< awt::XWindow
> xWindow( pWin
->GetComponentInterface(), uno::UNO_QUERY
);
178 xFrame
->setComponent( xWindow
, uno::Reference
< frame::XController
>() );
180 // we must destroy the IFrame before the parent is destroyed
181 xWindow
->addEventListener( this );
183 mxFrame
= frame::Frame::create( mxContext
);
184 uno::Reference
< awt::XWindow
> xWin( pWin
->GetComponentInterface(), uno::UNO_QUERY
);
185 mxFrame
->initialize( xWin
);
186 mxFrame
->setName( maFrmDescr
.GetName() );
188 uno::Reference
< frame::XFramesSupplier
> xFramesSupplier( xFrame
, uno::UNO_QUERY
);
189 if ( xFramesSupplier
.is() )
190 mxFrame
->setCreator( xFramesSupplier
);
192 util::URL aTargetURL
;
193 aTargetURL
.Complete
= maFrmDescr
.GetURL().GetMainURL( INetURLObject::NO_DECODE
);
194 uno::Reference
< util::XURLTransformer
> xTrans( util::URLTransformer::create( mxContext
) );
195 xTrans
->parseStrict( aTargetURL
);
197 uno::Sequence
< beans::PropertyValue
> aProps(2);
198 aProps
[0].Name
= "PluginMode";
199 aProps
[0].Value
<<= (sal_Int16
) 2;
200 aProps
[1].Name
= "ReadOnly";
201 aProps
[1].Value
<<= true;
202 uno::Reference
< frame::XDispatch
> xDisp
= mxFrame
->queryDispatch( aTargetURL
, "_self", 0 );
204 xDisp
->dispatch( aTargetURL
, aProps
);
212 void SAL_CALL
IFrameObject::cancel() throw( css::uno::RuntimeException
, std::exception
)
216 uno::Reference
< util::XCloseable
> xClose( mxFrame
, uno::UNO_QUERY
);
218 xClose
->close( true );
221 catch (const uno::Exception
&)
226 void SAL_CALL
IFrameObject::close( sal_Bool
/*bDeliverOwnership*/ ) throw( css::util::CloseVetoException
, css::uno::RuntimeException
, std::exception
)
230 void SAL_CALL
IFrameObject::addCloseListener( const css::uno::Reference
< css::util::XCloseListener
>& ) throw( css::uno::RuntimeException
, std::exception
)
234 void SAL_CALL
IFrameObject::removeCloseListener( const css::uno::Reference
< css::util::XCloseListener
>& ) throw( css::uno::RuntimeException
, std::exception
)
238 void SAL_CALL
IFrameObject::disposing( const css::lang::EventObject
& ) throw (css::uno::RuntimeException
, std::exception
)
243 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
IFrameObject::getPropertySetInfo() throw( css::uno::RuntimeException
, std::exception
)
245 static uno::Reference
< beans::XPropertySetInfo
> xInfo
= new SfxItemPropertySetInfo( maPropMap
);
249 void SAL_CALL
IFrameObject::setPropertyValue(const OUString
& aPropertyName
, const uno::Any
& aAny
)
250 throw ( beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
252 const SfxItemPropertySimpleEntry
* pEntry
= maPropMap
.getByName( aPropertyName
);
254 throw beans::UnknownPropertyException();
255 switch( pEntry
->nWID
)
261 maFrmDescr
.SetURL( aURL
);
267 if ( aAny
>>= aName
)
268 maFrmDescr
.SetName( aName
);
271 case WID_FRAME_IS_AUTO_SCROLL
:
274 if ( (aAny
>>= bIsAutoScroll
) && bIsAutoScroll
)
275 maFrmDescr
.SetScrollingMode( ScrollingAuto
);
278 case WID_FRAME_IS_SCROLLING_MODE
:
281 if ( aAny
>>= bIsScroll
)
282 maFrmDescr
.SetScrollingMode( bIsScroll
? ScrollingYes
: ScrollingNo
);
285 case WID_FRAME_IS_BORDER
:
288 if ( aAny
>>= bIsBorder
)
289 maFrmDescr
.SetFrameBorder( bIsBorder
);
292 case WID_FRAME_IS_AUTO_BORDER
:
295 if ( (aAny
>>= bIsAutoBorder
) )
297 bool bBorder
= maFrmDescr
.IsFrameBorderOn();
298 maFrmDescr
.ResetBorder();
300 maFrmDescr
.SetFrameBorder( bBorder
);
304 case WID_FRAME_MARGIN_WIDTH
:
306 sal_Int32 nMargin
= 0;
307 Size aSize
= maFrmDescr
.GetMargin();
308 if ( aAny
>>= nMargin
)
310 aSize
.Width() = nMargin
;
311 maFrmDescr
.SetMargin( aSize
);
315 case WID_FRAME_MARGIN_HEIGHT
:
317 sal_Int32 nMargin
= 0;
318 Size aSize
= maFrmDescr
.GetMargin();
319 if ( aAny
>>= nMargin
)
321 aSize
.Height() = nMargin
;
322 maFrmDescr
.SetMargin( aSize
);
330 uno::Any SAL_CALL
IFrameObject::getPropertyValue(const OUString
& aPropertyName
)
331 throw ( beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
333 const SfxItemPropertySimpleEntry
* pEntry
= maPropMap
.getByName( aPropertyName
);
335 throw beans::UnknownPropertyException();
337 switch( pEntry
->nWID
)
341 aAny
<<= OUString( maFrmDescr
.GetURL().GetMainURL( INetURLObject::NO_DECODE
) );
346 aAny
<<= OUString( maFrmDescr
.GetName() );
349 case WID_FRAME_IS_AUTO_SCROLL
:
351 bool bIsAutoScroll
= ( maFrmDescr
.GetScrollingMode() == ScrollingAuto
);
352 aAny
<<= bIsAutoScroll
;
355 case WID_FRAME_IS_SCROLLING_MODE
:
357 bool bIsScroll
= ( maFrmDescr
.GetScrollingMode() == ScrollingYes
);
361 case WID_FRAME_IS_BORDER
:
363 bool bIsBorder
= maFrmDescr
.IsFrameBorderOn();
367 case WID_FRAME_IS_AUTO_BORDER
:
369 bool bIsAutoBorder
= !maFrmDescr
.IsFrameBorderSet();
370 aAny
<<= bIsAutoBorder
;
373 case WID_FRAME_MARGIN_WIDTH
:
375 aAny
<<= (sal_Int32
) maFrmDescr
.GetMargin().Width();
378 case WID_FRAME_MARGIN_HEIGHT
:
380 aAny
<<= (sal_Int32
) maFrmDescr
.GetMargin().Height();
388 void SAL_CALL
IFrameObject::addPropertyChangeListener(const OUString
&, const css::uno::Reference
< css::beans::XPropertyChangeListener
> & ) throw( css::uno::RuntimeException
, std::exception
)
392 void SAL_CALL
IFrameObject::removePropertyChangeListener(const OUString
&, const css::uno::Reference
< css::beans::XPropertyChangeListener
> & ) throw( css::uno::RuntimeException
, std::exception
)
396 void SAL_CALL
IFrameObject::addVetoableChangeListener(const OUString
&, const css::uno::Reference
< css::beans::XVetoableChangeListener
> & ) throw( css::uno::RuntimeException
, std::exception
)
400 void SAL_CALL
IFrameObject::removeVetoableChangeListener(const OUString
&, const css::uno::Reference
< css::beans::XVetoableChangeListener
> & ) throw( css::uno::RuntimeException
, std::exception
)
404 ::sal_Int16 SAL_CALL
IFrameObject::execute() throw (css::uno::RuntimeException
, std::exception
)
406 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
407 ScopedVclPtr
<VclAbstractDialog
> pDlg(pFact
->CreateEditObjectDialog( ".uno:InsertObjectFloatingFrame", mxObj
));
413 void SAL_CALL
IFrameObject::setTitle( const OUString
& ) throw (css::uno::RuntimeException
, std::exception
)
419 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
420 com_sun_star_comp_sfx2_IFrameObject_get_implementation(
421 css::uno::XComponentContext
*context
,
422 css::uno::Sequence
<css::uno::Any
> const &arguments
)
424 return cppu::acquire(new IFrameObject(context
, arguments
));
427 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */