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 .
22 #include <sfx2/sfxdlg.hxx>
23 #include <sfx2/sfxsids.hrc>
24 #include <com/sun/star/frame/XDispatchProvider.hpp>
25 #include <com/sun/star/frame/XDispatch.hpp>
26 #include <com/sun/star/frame/Frame.hpp>
27 #include <com/sun/star/util/URLTransformer.hpp>
28 #include <com/sun/star/util/XURLTransformer.hpp>
30 #include <comphelper/processfactory.hxx>
31 #include <tools/urlobj.hxx>
32 #include <tools/debug.hxx>
33 #include <rtl/ustring.hxx>
34 #include <toolkit/helper/vclunohelper.hxx>
35 #include <svtools/miscopt.hxx>
36 #include <vcl/window.hxx>
38 using namespace ::com::sun::star
;
43 class IFrameWindow_Impl
: public Window
45 uno::Reference
< frame::XFrame2
> mxFrame
;
49 IFrameWindow_Impl( Window
*pParent
,
51 WinBits nWinBits
= 0 );
54 sal_Bool
HasBorder() const { return bBorder
; }
57 IFrameWindow_Impl::IFrameWindow_Impl( Window
*pParent
, sal_Bool bHasBorder
, WinBits nWinBits
)
58 : Window( pParent
, nWinBits
| WB_CLIPCHILDREN
| WB_NODIALOGCONTROL
| WB_DOCKBORDER
)
62 SetBorderStyle( WINDOW_BORDER_NOBORDER
);
64 SetBorderStyle( WINDOW_BORDER_NORMAL
);
67 #define PROPERTY_UNBOUND 0
69 #define WID_FRAME_URL 1
70 #define WID_FRAME_NAME 2
71 #define WID_FRAME_IS_AUTO_SCROLL 3
72 #define WID_FRAME_IS_SCROLLING_MODE 4
73 #define WID_FRAME_IS_BORDER 5
74 #define WID_FRAME_IS_AUTO_BORDER 6
75 #define WID_FRAME_MARGIN_WIDTH 7
76 #define WID_FRAME_MARGIN_HEIGHT 8
78 const SfxItemPropertyMapEntry
* lcl_GetIFramePropertyMap_Impl()
80 static SfxItemPropertyMapEntry aIFramePropertyMap_Impl
[] =
82 { MAP_CHAR_LEN("FrameIsAutoBorder"), WID_FRAME_IS_AUTO_BORDER
, &::getBooleanCppuType(), PROPERTY_UNBOUND
, 0 },
83 { MAP_CHAR_LEN("FrameIsAutoScroll"), WID_FRAME_IS_AUTO_SCROLL
, &::getBooleanCppuType(), PROPERTY_UNBOUND
, 0 },
84 { MAP_CHAR_LEN("FrameIsBorder"), WID_FRAME_IS_BORDER
, &::getBooleanCppuType(), PROPERTY_UNBOUND
, 0 },
85 { MAP_CHAR_LEN("FrameIsScrollingMode"), WID_FRAME_IS_SCROLLING_MODE
, &::getBooleanCppuType(), PROPERTY_UNBOUND
, 0 },
86 { MAP_CHAR_LEN("FrameMarginHeight"), WID_FRAME_MARGIN_HEIGHT
, &::getCppuType( (sal_Int32
*)0 ), PROPERTY_UNBOUND
, 0 },
87 { MAP_CHAR_LEN("FrameMarginWidth"), WID_FRAME_MARGIN_WIDTH
, &::getCppuType( (sal_Int32
*)0 ), PROPERTY_UNBOUND
, 0 },
88 { MAP_CHAR_LEN("FrameName"), WID_FRAME_NAME
, &::getCppuType((const OUString
*)0), PROPERTY_UNBOUND
, 0 },
89 { MAP_CHAR_LEN("FrameURL"), WID_FRAME_URL
, &::getCppuType((const OUString
*)0), PROPERTY_UNBOUND
, 0 },
92 return aIFramePropertyMap_Impl
;
95 SFX_IMPL_XSERVICEINFO_CTX( IFrameObject
, "com.sun.star.embed.SpecialEmbeddedObject", "com.sun.star.comp.sfx2.IFrameObject" )
96 SFX_IMPL_SINGLEFACTORY( IFrameObject
);
98 IFrameObject::IFrameObject( const uno::Reference
< uno::XComponentContext
>& rxContext
)
99 : mxContext( rxContext
)
100 , maPropMap( lcl_GetIFramePropertyMap_Impl() )
104 IFrameObject::~IFrameObject()
109 void SAL_CALL
IFrameObject::initialize( const uno::Sequence
< uno::Any
>& aArguments
) throw ( uno::Exception
, uno::RuntimeException
)
111 if ( aArguments
.getLength() )
112 aArguments
[0] >>= mxObj
;
115 sal_Bool SAL_CALL
IFrameObject::load(
116 const uno::Sequence
< com::sun::star::beans::PropertyValue
>& /*lDescriptor*/,
117 const uno::Reference
< frame::XFrame
>& xFrame
)
118 throw( uno::RuntimeException
)
120 if ( SvtMiscOptions().IsPluginsEnabled() )
122 DBG_ASSERT( !mxFrame
.is(), "Frame already existing!" );
123 Window
* pParent
= VCLUnoHelper::GetWindow( xFrame
->getContainerWindow() );
124 IFrameWindow_Impl
* pWin
= new IFrameWindow_Impl( pParent
, maFrmDescr
.IsFrameBorderOn() );
125 pWin
->SetSizePixel( pParent
->GetOutputSizePixel() );
126 pWin
->SetBackground();
129 uno::Reference
< awt::XWindow
> xWindow( pWin
->GetComponentInterface(), uno::UNO_QUERY
);
130 xFrame
->setComponent( xWindow
, uno::Reference
< frame::XController
>() );
132 // we must destroy the IFrame before the parent is destroyed
133 xWindow
->addEventListener( this );
135 mxFrame
= frame::Frame::create( mxContext
);
136 uno::Reference
< awt::XWindow
> xWin( pWin
->GetComponentInterface(), uno::UNO_QUERY
);
137 mxFrame
->initialize( xWin
);
138 mxFrame
->setName( maFrmDescr
.GetName() );
140 uno::Reference
< frame::XFramesSupplier
> xFramesSupplier( xFrame
, uno::UNO_QUERY
);
141 if ( xFramesSupplier
.is() )
142 mxFrame
->setCreator( xFramesSupplier
);
144 util::URL aTargetURL
;
145 aTargetURL
.Complete
= OUString( maFrmDescr
.GetURL().GetMainURL( INetURLObject::NO_DECODE
) );
146 uno::Reference
< util::XURLTransformer
> xTrans( util::URLTransformer::create( mxContext
) );
147 xTrans
->parseStrict( aTargetURL
);
149 uno::Sequence
< beans::PropertyValue
> aProps(2);
150 aProps
[0].Name
= "PluginMode";
151 aProps
[0].Value
<<= (sal_Int16
) 2;
152 aProps
[1].Name
= "ReadOnly";
153 aProps
[1].Value
<<= (sal_Bool
) sal_True
;
154 uno::Reference
< frame::XDispatch
> xDisp
= mxFrame
->queryDispatch( aTargetURL
, "_self", 0 );
156 xDisp
->dispatch( aTargetURL
, aProps
);
164 void SAL_CALL
IFrameObject::cancel() throw( com::sun::star::uno::RuntimeException
)
168 uno::Reference
< util::XCloseable
> xClose( mxFrame
, uno::UNO_QUERY
);
170 xClose
->close( sal_True
);
173 catch (const uno::Exception
&)
178 void SAL_CALL
IFrameObject::close( sal_Bool
/*bDeliverOwnership*/ ) throw( com::sun::star::util::CloseVetoException
, com::sun::star::uno::RuntimeException
)
182 void SAL_CALL
IFrameObject::addCloseListener( const com::sun::star::uno::Reference
< com::sun::star::util::XCloseListener
>& ) throw( com::sun::star::uno::RuntimeException
)
186 void SAL_CALL
IFrameObject::removeCloseListener( const com::sun::star::uno::Reference
< com::sun::star::util::XCloseListener
>& ) throw( com::sun::star::uno::RuntimeException
)
190 void SAL_CALL
IFrameObject::disposing( const com::sun::star::lang::EventObject
& ) throw (com::sun::star::uno::RuntimeException
)
195 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
IFrameObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException
)
197 static uno::Reference
< beans::XPropertySetInfo
> xInfo
= new SfxItemPropertySetInfo( maPropMap
);
201 void SAL_CALL
IFrameObject::setPropertyValue(const OUString
& aPropertyName
, const uno::Any
& aAny
)
202 throw ( beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
204 const SfxItemPropertySimpleEntry
* pEntry
= maPropMap
.getByName( aPropertyName
);
206 throw beans::UnknownPropertyException();
207 switch( pEntry
->nWID
)
213 maFrmDescr
.SetURL( String(aURL
) );
219 if ( aAny
>>= aName
)
220 maFrmDescr
.SetName( aName
);
223 case WID_FRAME_IS_AUTO_SCROLL
:
225 sal_Bool bIsAutoScroll
= sal_Bool();
226 if ( (aAny
>>= bIsAutoScroll
) && bIsAutoScroll
)
227 maFrmDescr
.SetScrollingMode( ScrollingAuto
);
230 case WID_FRAME_IS_SCROLLING_MODE
:
232 sal_Bool bIsScroll
= sal_Bool();
233 if ( aAny
>>= bIsScroll
)
234 maFrmDescr
.SetScrollingMode( bIsScroll
? ScrollingYes
: ScrollingNo
);
237 case WID_FRAME_IS_BORDER
:
239 sal_Bool bIsBorder
= sal_Bool();
240 if ( aAny
>>= bIsBorder
)
241 maFrmDescr
.SetFrameBorder( bIsBorder
);
244 case WID_FRAME_IS_AUTO_BORDER
:
246 sal_Bool bIsAutoBorder
= sal_Bool();
247 if ( (aAny
>>= bIsAutoBorder
) )
249 sal_Bool bBorder
= maFrmDescr
.IsFrameBorderOn();
250 maFrmDescr
.ResetBorder();
252 maFrmDescr
.SetFrameBorder( bBorder
);
256 case WID_FRAME_MARGIN_WIDTH
:
258 sal_Int32 nMargin
= 0;
259 Size aSize
= maFrmDescr
.GetMargin();
260 if ( aAny
>>= nMargin
)
262 aSize
.Width() = nMargin
;
263 maFrmDescr
.SetMargin( aSize
);
267 case WID_FRAME_MARGIN_HEIGHT
:
269 sal_Int32 nMargin
= 0;
270 Size aSize
= maFrmDescr
.GetMargin();
271 if ( aAny
>>= nMargin
)
273 aSize
.Height() = nMargin
;
274 maFrmDescr
.SetMargin( aSize
);
282 uno::Any SAL_CALL
IFrameObject::getPropertyValue(const OUString
& aPropertyName
)
283 throw ( beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
285 const SfxItemPropertySimpleEntry
* pEntry
= maPropMap
.getByName( aPropertyName
);
287 throw beans::UnknownPropertyException();
289 switch( pEntry
->nWID
)
293 aAny
<<= OUString( maFrmDescr
.GetURL().GetMainURL( INetURLObject::NO_DECODE
) );
298 aAny
<<= OUString( maFrmDescr
.GetName() );
301 case WID_FRAME_IS_AUTO_SCROLL
:
303 sal_Bool bIsAutoScroll
= ( maFrmDescr
.GetScrollingMode() == ScrollingAuto
);
304 aAny
<<= bIsAutoScroll
;
307 case WID_FRAME_IS_SCROLLING_MODE
:
309 sal_Bool bIsScroll
= ( maFrmDescr
.GetScrollingMode() == ScrollingYes
);
313 case WID_FRAME_IS_BORDER
:
315 sal_Bool bIsBorder
= maFrmDescr
.IsFrameBorderOn();
319 case WID_FRAME_IS_AUTO_BORDER
:
321 sal_Bool bIsAutoBorder
= !maFrmDescr
.IsFrameBorderSet();
322 aAny
<<= bIsAutoBorder
;
325 case WID_FRAME_MARGIN_WIDTH
:
327 aAny
<<= (sal_Int32
) maFrmDescr
.GetMargin().Width();
330 case WID_FRAME_MARGIN_HEIGHT
:
332 aAny
<<= (sal_Int32
) maFrmDescr
.GetMargin().Height();
339 void SAL_CALL
IFrameObject::addPropertyChangeListener(const OUString
&, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
> & ) throw( ::com::sun::star::uno::RuntimeException
)
343 void SAL_CALL
IFrameObject::removePropertyChangeListener(const OUString
&, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
> & ) throw( ::com::sun::star::uno::RuntimeException
)
347 void SAL_CALL
IFrameObject::addVetoableChangeListener(const OUString
&, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XVetoableChangeListener
> & ) throw( ::com::sun::star::uno::RuntimeException
)
351 void SAL_CALL
IFrameObject::removeVetoableChangeListener(const OUString
&, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XVetoableChangeListener
> & ) throw( ::com::sun::star::uno::RuntimeException
)
355 ::sal_Int16 SAL_CALL
IFrameObject::execute() throw (::com::sun::star::uno::RuntimeException
)
357 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
358 VclAbstractDialog
* pDlg
= pFact
->CreateEditObjectDialog( NULL
, ".uno:InsertObjectFloatingFrame", mxObj
);
364 void SAL_CALL
IFrameObject::setTitle( const OUString
& ) throw (::com::sun::star::uno::RuntimeException
)
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */