Bump version to 4.1-6
[LibreOffice.git] / sfx2 / source / doc / iframe.cxx
blobd43d3383e3fe6a8f57c2edc1c746327db00196f7
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 "iframe.hxx"
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;
40 namespace sfx2
43 class IFrameWindow_Impl : public Window
45 uno::Reference < frame::XFrame2 > mxFrame;
46 sal_Bool bBorder;
48 public:
49 IFrameWindow_Impl( Window *pParent,
50 sal_Bool bHasBorder,
51 WinBits nWinBits = 0 );
53 public:
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 )
59 , bBorder(bHasBorder)
61 if ( !bHasBorder )
62 SetBorderStyle( WINDOW_BORDER_NOBORDER );
63 else
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 },
90 {0,0,0,0,0,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();
127 pWin->Show();
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 );
155 if ( xDisp.is() )
156 xDisp->dispatch( aTargetURL, aProps );
158 return sal_True;
161 return sal_False;
164 void SAL_CALL IFrameObject::cancel() throw( com::sun::star::uno::RuntimeException )
168 uno::Reference < util::XCloseable > xClose( mxFrame, uno::UNO_QUERY );
169 if ( xClose.is() )
170 xClose->close( sal_True );
171 mxFrame = 0;
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)
192 cancel();
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 );
198 return xInfo;
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 );
205 if( !pEntry )
206 throw beans::UnknownPropertyException();
207 switch( pEntry->nWID )
209 case WID_FRAME_URL:
211 OUString aURL;
212 aAny >>= aURL;
213 maFrmDescr.SetURL( String(aURL) );
215 break;
216 case WID_FRAME_NAME:
218 OUString aName;
219 if ( aAny >>= aName )
220 maFrmDescr.SetName( aName );
222 break;
223 case WID_FRAME_IS_AUTO_SCROLL:
225 sal_Bool bIsAutoScroll = sal_Bool();
226 if ( (aAny >>= bIsAutoScroll) && bIsAutoScroll )
227 maFrmDescr.SetScrollingMode( ScrollingAuto );
229 break;
230 case WID_FRAME_IS_SCROLLING_MODE:
232 sal_Bool bIsScroll = sal_Bool();
233 if ( aAny >>= bIsScroll )
234 maFrmDescr.SetScrollingMode( bIsScroll ? ScrollingYes : ScrollingNo );
236 break;
237 case WID_FRAME_IS_BORDER:
239 sal_Bool bIsBorder = sal_Bool();
240 if ( aAny >>= bIsBorder )
241 maFrmDescr.SetFrameBorder( bIsBorder );
243 break;
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();
251 if ( bIsAutoBorder )
252 maFrmDescr.SetFrameBorder( bBorder );
255 break;
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 );
266 break;
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 );
277 break;
278 default: ;
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 );
286 if( !pEntry )
287 throw beans::UnknownPropertyException();
288 uno::Any aAny;
289 switch( pEntry->nWID )
291 case WID_FRAME_URL:
293 aAny <<= OUString( maFrmDescr.GetURL().GetMainURL( INetURLObject::NO_DECODE ) );
295 break;
296 case WID_FRAME_NAME:
298 aAny <<= OUString( maFrmDescr.GetName() );
300 break;
301 case WID_FRAME_IS_AUTO_SCROLL:
303 sal_Bool bIsAutoScroll = ( maFrmDescr.GetScrollingMode() == ScrollingAuto );
304 aAny <<= bIsAutoScroll;
306 break;
307 case WID_FRAME_IS_SCROLLING_MODE:
309 sal_Bool bIsScroll = ( maFrmDescr.GetScrollingMode() == ScrollingYes );
310 aAny <<= bIsScroll;
312 break;
313 case WID_FRAME_IS_BORDER:
315 sal_Bool bIsBorder = maFrmDescr.IsFrameBorderOn();
316 aAny <<= bIsBorder;
318 break;
319 case WID_FRAME_IS_AUTO_BORDER:
321 sal_Bool bIsAutoBorder = !maFrmDescr.IsFrameBorderSet();
322 aAny <<= bIsAutoBorder;
324 break;
325 case WID_FRAME_MARGIN_WIDTH:
327 aAny <<= (sal_Int32 ) maFrmDescr.GetMargin().Width();
329 break;
330 case WID_FRAME_MARGIN_HEIGHT:
332 aAny <<= (sal_Int32 ) maFrmDescr.GetMargin().Height();
334 default: ;
336 return aAny;
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 );
359 if ( pDlg )
360 pDlg->Execute();
361 return 0;
364 void SAL_CALL IFrameObject::setTitle( const OUString& ) throw (::com::sun::star::uno::RuntimeException)
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */