Update ooo320-m1
[ooovba.git] / sfx2 / source / doc / iframe.cxx
blob071c69a77b4a62c25e4926b2a484f7c8b60530eb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: iframe.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 #include "iframe.hxx"
35 #include <sfx2/sfxdlg.hxx>
36 #include <sfx2/sfxsids.hrc>
37 #include <com/sun/star/frame/XDispatchProvider.hpp>
38 #include <com/sun/star/frame/XDispatch.hpp>
39 #include <com/sun/star/frame/XFramesSupplier.hpp>
40 #include <com/sun/star/util/XURLTransformer.hpp>
42 #include <tools/urlobj.hxx>
43 #include <tools/debug.hxx>
44 #include <rtl/ustring.hxx>
45 #include <toolkit/helper/vclunohelper.hxx>
46 #include <svtools/miscopt.hxx>
47 #include <vcl/window.hxx>
49 using namespace ::com::sun::star;
51 namespace sfx2
54 class IFrameWindow_Impl : public Window
56 uno::Reference < frame::XFrame > mxFrame;
57 sal_Bool bActive;
58 sal_Bool bBorder;
60 public:
61 IFrameWindow_Impl( Window *pParent,
62 sal_Bool bHasBorder,
63 WinBits nWinBits = 0 );
65 public:
66 void SetBorder( sal_Bool bNewBorder = sal_True );
67 sal_Bool HasBorder() const { return bBorder; }
70 IFrameWindow_Impl::IFrameWindow_Impl( Window *pParent, sal_Bool bHasBorder, WinBits nWinBits )
71 : Window( pParent, nWinBits | WB_CLIPCHILDREN | WB_NODIALOGCONTROL | WB_DOCKBORDER )
72 , bActive(sal_False)
73 , bBorder(bHasBorder)
75 if ( !bHasBorder )
76 SetBorderStyle( WINDOW_BORDER_NOBORDER );
77 else
78 SetBorderStyle( WINDOW_BORDER_NORMAL );
79 //SetActivateMode( ACTIVATE_MODE_GRABFOCUS );
82 void IFrameWindow_Impl::SetBorder( sal_Bool bNewBorder )
84 if ( bBorder != bNewBorder )
86 Size aSize = GetSizePixel();
87 bBorder = bNewBorder;
88 if ( bBorder )
89 SetBorderStyle( WINDOW_BORDER_NORMAL );
90 else
91 SetBorderStyle( WINDOW_BORDER_NOBORDER );
92 if ( GetSizePixel() != aSize )
93 SetSizePixel( aSize );
97 #define PROPERTY_UNBOUND 0
99 #define WID_FRAME_URL 1
100 #define WID_FRAME_NAME 2
101 #define WID_FRAME_IS_AUTO_SCROLL 3
102 #define WID_FRAME_IS_SCROLLING_MODE 4
103 #define WID_FRAME_IS_BORDER 5
104 #define WID_FRAME_IS_AUTO_BORDER 6
105 #define WID_FRAME_MARGIN_WIDTH 7
106 #define WID_FRAME_MARGIN_HEIGHT 8
108 const SfxItemPropertyMapEntry* lcl_GetIFramePropertyMap_Impl()
110 static SfxItemPropertyMapEntry aIFramePropertyMap_Impl[] =
112 { MAP_CHAR_LEN("FrameIsAutoBorder"), WID_FRAME_IS_AUTO_BORDER, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
113 { MAP_CHAR_LEN("FrameIsAutoScroll"), WID_FRAME_IS_AUTO_SCROLL, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
114 { MAP_CHAR_LEN("FrameIsBorder"), WID_FRAME_IS_BORDER, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
115 { MAP_CHAR_LEN("FrameIsScrollingMode"), WID_FRAME_IS_SCROLLING_MODE, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
116 { MAP_CHAR_LEN("FrameMarginHeight"), WID_FRAME_MARGIN_HEIGHT, &::getCppuType( (sal_Int32*)0 ), PROPERTY_UNBOUND, 0 },
117 { MAP_CHAR_LEN("FrameMarginWidth"), WID_FRAME_MARGIN_WIDTH, &::getCppuType( (sal_Int32*)0 ), PROPERTY_UNBOUND, 0 },
118 { MAP_CHAR_LEN("FrameName"), WID_FRAME_NAME, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
119 { MAP_CHAR_LEN("FrameURL"), WID_FRAME_URL, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
120 {0,0,0,0,0,0}
122 return aIFramePropertyMap_Impl;
125 SFX_IMPL_XSERVICEINFO( IFrameObject, "com.sun.star.embed.SpecialEmbeddedObject", "com.sun.star.comp.sfx2.IFrameObject" )
126 SFX_IMPL_SINGLEFACTORY( IFrameObject );
128 IFrameObject::IFrameObject( const uno::Reference < lang::XMultiServiceFactory >& rFact )
129 : mxFact( rFact )
130 , maPropMap( lcl_GetIFramePropertyMap_Impl() )
134 IFrameObject::~IFrameObject()
139 void SAL_CALL IFrameObject::initialize( const uno::Sequence< uno::Any >& aArguments ) throw ( uno::Exception, uno::RuntimeException )
141 if ( aArguments.getLength() )
142 aArguments[0] >>= mxObj;
145 sal_Bool SAL_CALL IFrameObject::load(
146 const uno::Sequence < com::sun::star::beans::PropertyValue >& /*lDescriptor*/,
147 const uno::Reference < frame::XFrame >& xFrame )
148 throw( uno::RuntimeException )
150 if ( SvtMiscOptions().IsPluginsEnabled() )
152 DBG_ASSERT( !mxFrame.is(), "Frame already existing!" );
153 Window* pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
154 IFrameWindow_Impl* pWin = new IFrameWindow_Impl( pParent, maFrmDescr.IsFrameBorderOn() );
155 pWin->SetSizePixel( pParent->GetOutputSizePixel() );
156 pWin->SetBackground();
157 pWin->Show();
159 uno::Reference < awt::XWindow > xWindow( pWin->GetComponentInterface(), uno::UNO_QUERY );
160 xFrame->setComponent( xWindow, uno::Reference < frame::XController >() );
162 // we must destroy the IFrame before the parent is destroyed
163 xWindow->addEventListener( this );
165 mxFrame = uno::Reference< frame::XFrame >( mxFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Frame" ) ),
166 uno::UNO_QUERY );
167 uno::Reference < awt::XWindow > xWin( pWin->GetComponentInterface(), uno::UNO_QUERY );
168 mxFrame->initialize( xWin );
169 mxFrame->setName( maFrmDescr.GetName() );
171 uno::Reference < frame::XFramesSupplier > xFramesSupplier( xFrame, uno::UNO_QUERY );
172 if ( xFramesSupplier.is() )
173 mxFrame->setCreator( xFramesSupplier );
175 uno::Reference< frame::XDispatchProvider > xProv( mxFrame, uno::UNO_QUERY );
177 util::URL aTargetURL;
178 aTargetURL.Complete = ::rtl::OUString( maFrmDescr.GetURL().GetMainURL( INetURLObject::NO_DECODE ) );
179 uno::Reference < util::XURLTransformer > xTrans( mxFact->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), uno::UNO_QUERY );
180 xTrans->parseStrict( aTargetURL );
182 uno::Sequence < beans::PropertyValue > aProps(2);
183 aProps[0].Name = ::rtl::OUString::createFromAscii("PluginMode");
184 aProps[0].Value <<= (sal_Int16) 2;
185 aProps[1].Name = ::rtl::OUString::createFromAscii("ReadOnly");
186 aProps[1].Value <<= (sal_Bool) sal_True;
187 uno::Reference < frame::XDispatch > xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString::createFromAscii("_self"), 0 );
188 if ( xDisp.is() )
189 xDisp->dispatch( aTargetURL, aProps );
191 return TRUE;
194 return FALSE;
197 void SAL_CALL IFrameObject::cancel() throw( com::sun::star::uno::RuntimeException )
201 uno::Reference < util::XCloseable > xClose( mxFrame, uno::UNO_QUERY );
202 if ( xClose.is() )
203 xClose->close( sal_True );
204 mxFrame = 0;
206 catch ( uno::Exception& )
210 void SAL_CALL IFrameObject::close( sal_Bool /*bDeliverOwnership*/ ) throw( com::sun::star::util::CloseVetoException, com::sun::star::uno::RuntimeException )
214 void SAL_CALL IFrameObject::addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
218 void SAL_CALL IFrameObject::removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
222 void SAL_CALL IFrameObject::disposing( const com::sun::star::lang::EventObject& ) throw (com::sun::star::uno::RuntimeException)
224 cancel();
227 uno::Reference< beans::XPropertySetInfo > SAL_CALL IFrameObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException )
229 static uno::Reference< beans::XPropertySetInfo > xInfo = new SfxItemPropertySetInfo( &maPropMap );
230 return xInfo;
233 void SAL_CALL IFrameObject::setPropertyValue(const ::rtl::OUString& aPropertyName, const uno::Any& aAny)
234 throw ( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
236 const SfxItemPropertySimpleEntry* pEntry = maPropMap.getByName( aPropertyName );
237 if( !pEntry )
238 throw beans::UnknownPropertyException();
239 switch( pEntry->nWID )
241 case WID_FRAME_URL:
243 ::rtl::OUString aURL;
244 aAny >>= aURL;
245 maFrmDescr.SetURL( String(aURL) );
247 break;
248 case WID_FRAME_NAME:
250 ::rtl::OUString aName;
251 if ( aAny >>= aName )
252 maFrmDescr.SetName( aName );
254 break;
255 case WID_FRAME_IS_AUTO_SCROLL:
257 sal_Bool bIsAutoScroll = sal_Bool();
258 if ( (aAny >>= bIsAutoScroll) && bIsAutoScroll )
259 maFrmDescr.SetScrollingMode( ScrollingAuto );
261 break;
262 case WID_FRAME_IS_SCROLLING_MODE:
264 sal_Bool bIsScroll = sal_Bool();
265 if ( aAny >>= bIsScroll )
266 maFrmDescr.SetScrollingMode( bIsScroll ? ScrollingYes : ScrollingNo );
268 break;
269 case WID_FRAME_IS_BORDER:
271 sal_Bool bIsBorder = sal_Bool();
272 if ( aAny >>= bIsBorder )
273 maFrmDescr.SetFrameBorder( bIsBorder );
275 break;
276 case WID_FRAME_IS_AUTO_BORDER:
278 sal_Bool bIsAutoBorder = sal_Bool();
279 if ( (aAny >>= bIsAutoBorder) )
281 BOOL bBorder = maFrmDescr.IsFrameBorderOn();
282 maFrmDescr.ResetBorder();
283 if ( bIsAutoBorder )
284 maFrmDescr.SetFrameBorder( bBorder );
287 break;
288 case WID_FRAME_MARGIN_WIDTH:
290 sal_Int32 nMargin = 0;
291 Size aSize = maFrmDescr.GetMargin();
292 if ( aAny >>= nMargin )
294 aSize.Width() = nMargin;
295 maFrmDescr.SetMargin( aSize );
298 break;
299 case WID_FRAME_MARGIN_HEIGHT:
301 sal_Int32 nMargin = 0;
302 Size aSize = maFrmDescr.GetMargin();
303 if ( aAny >>= nMargin )
305 aSize.Height() = nMargin;
306 maFrmDescr.SetMargin( aSize );
309 break;
310 default: ;
314 uno::Any SAL_CALL IFrameObject::getPropertyValue(const ::rtl::OUString& aPropertyName)
315 throw ( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
317 const SfxItemPropertySimpleEntry* pEntry = maPropMap.getByName( aPropertyName );
318 if( !pEntry )
319 throw beans::UnknownPropertyException();
320 uno::Any aAny;
321 switch( pEntry->nWID )
323 case WID_FRAME_URL:
325 aAny <<= ::rtl::OUString( maFrmDescr.GetURL().GetMainURL( INetURLObject::NO_DECODE ) );
327 break;
328 case WID_FRAME_NAME:
330 aAny <<= ::rtl::OUString( maFrmDescr.GetName() );
332 break;
333 case WID_FRAME_IS_AUTO_SCROLL:
335 sal_Bool bIsAutoScroll = ( maFrmDescr.GetScrollingMode() == ScrollingAuto );
336 aAny <<= bIsAutoScroll;
338 break;
339 case WID_FRAME_IS_SCROLLING_MODE:
341 sal_Bool bIsScroll = ( maFrmDescr.GetScrollingMode() == ScrollingYes );
342 aAny <<= bIsScroll;
344 break;
345 case WID_FRAME_IS_BORDER:
347 sal_Bool bIsBorder = maFrmDescr.IsFrameBorderOn();
348 aAny <<= bIsBorder;
350 break;
351 case WID_FRAME_IS_AUTO_BORDER:
353 sal_Bool bIsAutoBorder = !maFrmDescr.IsFrameBorderSet();
354 aAny <<= bIsAutoBorder;
356 break;
357 case WID_FRAME_MARGIN_WIDTH:
359 aAny <<= (sal_Int32 ) maFrmDescr.GetMargin().Width();
361 break;
362 case WID_FRAME_MARGIN_HEIGHT:
364 aAny <<= (sal_Int32 ) maFrmDescr.GetMargin().Height();
366 default: ;
368 return aAny;
371 void SAL_CALL IFrameObject::addPropertyChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
375 void SAL_CALL IFrameObject::removePropertyChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
379 void SAL_CALL IFrameObject::addVetoableChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
383 void SAL_CALL IFrameObject::removeVetoableChangeListener(const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener > & ) throw( ::com::sun::star::uno::RuntimeException )
387 ::sal_Int16 SAL_CALL IFrameObject::execute() throw (::com::sun::star::uno::RuntimeException)
389 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
390 VclAbstractDialog* pDlg = pFact->CreateEditObjectDialog( NULL, SID_INSERT_FLOATINGFRAME, mxObj );
391 if ( pDlg )
392 pDlg->Execute();
393 return 0;
396 void SAL_CALL IFrameObject::setTitle( const ::rtl::OUString& ) throw (::com::sun::star::uno::RuntimeException)