Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / doc / iframe.cxx
blob9d60fb6a8168d65936d7a819e0cb088067619d11
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "iframe.hxx"
31 #include <sfx2/sfxdlg.hxx>
32 #include <sfx2/sfxsids.hrc>
33 #include <com/sun/star/frame/XDispatchProvider.hpp>
34 #include <com/sun/star/frame/XDispatch.hpp>
35 #include <com/sun/star/frame/XFramesSupplier.hpp>
36 #include <com/sun/star/util/XURLTransformer.hpp>
38 #include <tools/urlobj.hxx>
39 #include <tools/debug.hxx>
40 #include <rtl/ustring.hxx>
41 #include <toolkit/helper/vclunohelper.hxx>
42 #include <svtools/miscopt.hxx>
43 #include <vcl/window.hxx>
45 using namespace ::com::sun::star;
47 namespace sfx2
50 class IFrameWindow_Impl : public Window
52 uno::Reference < frame::XFrame > mxFrame;
53 sal_Bool bActive;
54 sal_Bool bBorder;
56 public:
57 IFrameWindow_Impl( Window *pParent,
58 sal_Bool bHasBorder,
59 WinBits nWinBits = 0 );
61 public:
62 sal_Bool HasBorder() const { return bBorder; }
65 IFrameWindow_Impl::IFrameWindow_Impl( Window *pParent, sal_Bool bHasBorder, WinBits nWinBits )
66 : Window( pParent, nWinBits | WB_CLIPCHILDREN | WB_NODIALOGCONTROL | WB_DOCKBORDER )
67 , bActive(sal_False)
68 , bBorder(bHasBorder)
70 if ( !bHasBorder )
71 SetBorderStyle( WINDOW_BORDER_NOBORDER );
72 else
73 SetBorderStyle( WINDOW_BORDER_NORMAL );
76 #define PROPERTY_UNBOUND 0
78 #define WID_FRAME_URL 1
79 #define WID_FRAME_NAME 2
80 #define WID_FRAME_IS_AUTO_SCROLL 3
81 #define WID_FRAME_IS_SCROLLING_MODE 4
82 #define WID_FRAME_IS_BORDER 5
83 #define WID_FRAME_IS_AUTO_BORDER 6
84 #define WID_FRAME_MARGIN_WIDTH 7
85 #define WID_FRAME_MARGIN_HEIGHT 8
87 const SfxItemPropertyMapEntry* lcl_GetIFramePropertyMap_Impl()
89 static SfxItemPropertyMapEntry aIFramePropertyMap_Impl[] =
91 { MAP_CHAR_LEN("FrameIsAutoBorder"), WID_FRAME_IS_AUTO_BORDER, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
92 { MAP_CHAR_LEN("FrameIsAutoScroll"), WID_FRAME_IS_AUTO_SCROLL, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
93 { MAP_CHAR_LEN("FrameIsBorder"), WID_FRAME_IS_BORDER, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
94 { MAP_CHAR_LEN("FrameIsScrollingMode"), WID_FRAME_IS_SCROLLING_MODE, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
95 { MAP_CHAR_LEN("FrameMarginHeight"), WID_FRAME_MARGIN_HEIGHT, &::getCppuType( (sal_Int32*)0 ), PROPERTY_UNBOUND, 0 },
96 { MAP_CHAR_LEN("FrameMarginWidth"), WID_FRAME_MARGIN_WIDTH, &::getCppuType( (sal_Int32*)0 ), PROPERTY_UNBOUND, 0 },
97 { MAP_CHAR_LEN("FrameName"), WID_FRAME_NAME, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
98 { MAP_CHAR_LEN("FrameURL"), WID_FRAME_URL, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
99 {0,0,0,0,0,0}
101 return aIFramePropertyMap_Impl;
104 SFX_IMPL_XSERVICEINFO( IFrameObject, "com.sun.star.embed.SpecialEmbeddedObject", "com.sun.star.comp.sfx2.IFrameObject" )
105 SFX_IMPL_SINGLEFACTORY( IFrameObject );
107 IFrameObject::IFrameObject( const uno::Reference < lang::XMultiServiceFactory >& rFact )
108 : mxFact( rFact )
109 , maPropMap( lcl_GetIFramePropertyMap_Impl() )
113 IFrameObject::~IFrameObject()
118 void SAL_CALL IFrameObject::initialize( const uno::Sequence< uno::Any >& aArguments ) throw ( uno::Exception, uno::RuntimeException )
120 if ( aArguments.getLength() )
121 aArguments[0] >>= mxObj;
124 sal_Bool SAL_CALL IFrameObject::load(
125 const uno::Sequence < com::sun::star::beans::PropertyValue >& /*lDescriptor*/,
126 const uno::Reference < frame::XFrame >& xFrame )
127 throw( uno::RuntimeException )
129 if ( SvtMiscOptions().IsPluginsEnabled() )
131 DBG_ASSERT( !mxFrame.is(), "Frame already existing!" );
132 Window* pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
133 IFrameWindow_Impl* pWin = new IFrameWindow_Impl( pParent, maFrmDescr.IsFrameBorderOn() );
134 pWin->SetSizePixel( pParent->GetOutputSizePixel() );
135 pWin->SetBackground();
136 pWin->Show();
138 uno::Reference < awt::XWindow > xWindow( pWin->GetComponentInterface(), uno::UNO_QUERY );
139 xFrame->setComponent( xWindow, uno::Reference < frame::XController >() );
141 // we must destroy the IFrame before the parent is destroyed
142 xWindow->addEventListener( this );
144 mxFrame = uno::Reference< frame::XFrame >( mxFact->createInstance( "com.sun.star.frame.Frame" ),uno::UNO_QUERY );
145 uno::Reference < awt::XWindow > xWin( pWin->GetComponentInterface(), uno::UNO_QUERY );
146 mxFrame->initialize( xWin );
147 mxFrame->setName( maFrmDescr.GetName() );
149 uno::Reference < frame::XFramesSupplier > xFramesSupplier( xFrame, uno::UNO_QUERY );
150 if ( xFramesSupplier.is() )
151 mxFrame->setCreator( xFramesSupplier );
153 uno::Reference< frame::XDispatchProvider > xProv( mxFrame, uno::UNO_QUERY );
155 util::URL aTargetURL;
156 aTargetURL.Complete = ::rtl::OUString( maFrmDescr.GetURL().GetMainURL( INetURLObject::NO_DECODE ) );
157 uno::Reference < util::XURLTransformer > xTrans( mxFact->createInstance( "com.sun.star.util.URLTransformer"), uno::UNO_QUERY );
158 xTrans->parseStrict( aTargetURL );
160 uno::Sequence < beans::PropertyValue > aProps(2);
161 aProps[0].Name = "PluginMode";
162 aProps[0].Value <<= (sal_Int16) 2;
163 aProps[1].Name = "ReadOnly";
164 aProps[1].Value <<= (sal_Bool) sal_True;
165 uno::Reference < frame::XDispatch > xDisp = xProv->queryDispatch( aTargetURL, "_self", 0 );
166 if ( xDisp.is() )
167 xDisp->dispatch( aTargetURL, aProps );
169 return sal_True;
172 return sal_False;
175 void SAL_CALL IFrameObject::cancel() throw( com::sun::star::uno::RuntimeException )
179 uno::Reference < util::XCloseable > xClose( mxFrame, uno::UNO_QUERY );
180 if ( xClose.is() )
181 xClose->close( sal_True );
182 mxFrame = 0;
184 catch (const uno::Exception&)
189 void SAL_CALL IFrameObject::close( sal_Bool /*bDeliverOwnership*/ ) throw( com::sun::star::util::CloseVetoException, com::sun::star::uno::RuntimeException )
193 void SAL_CALL IFrameObject::addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
197 void SAL_CALL IFrameObject::removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
201 void SAL_CALL IFrameObject::disposing( const com::sun::star::lang::EventObject& ) throw (com::sun::star::uno::RuntimeException)
203 cancel();
206 uno::Reference< beans::XPropertySetInfo > SAL_CALL IFrameObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException )
208 static uno::Reference< beans::XPropertySetInfo > xInfo = new SfxItemPropertySetInfo( maPropMap );
209 return xInfo;
212 void SAL_CALL IFrameObject::setPropertyValue(const ::rtl::OUString& aPropertyName, const uno::Any& aAny)
213 throw ( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
215 const SfxItemPropertySimpleEntry* pEntry = maPropMap.getByName( aPropertyName );
216 if( !pEntry )
217 throw beans::UnknownPropertyException();
218 switch( pEntry->nWID )
220 case WID_FRAME_URL:
222 ::rtl::OUString aURL;
223 aAny >>= aURL;
224 maFrmDescr.SetURL( String(aURL) );
226 break;
227 case WID_FRAME_NAME:
229 ::rtl::OUString aName;
230 if ( aAny >>= aName )
231 maFrmDescr.SetName( aName );
233 break;
234 case WID_FRAME_IS_AUTO_SCROLL:
236 sal_Bool bIsAutoScroll = sal_Bool();
237 if ( (aAny >>= bIsAutoScroll) && bIsAutoScroll )
238 maFrmDescr.SetScrollingMode( ScrollingAuto );
240 break;
241 case WID_FRAME_IS_SCROLLING_MODE:
243 sal_Bool bIsScroll = sal_Bool();
244 if ( aAny >>= bIsScroll )
245 maFrmDescr.SetScrollingMode( bIsScroll ? ScrollingYes : ScrollingNo );
247 break;
248 case WID_FRAME_IS_BORDER:
250 sal_Bool bIsBorder = sal_Bool();
251 if ( aAny >>= bIsBorder )
252 maFrmDescr.SetFrameBorder( bIsBorder );
254 break;
255 case WID_FRAME_IS_AUTO_BORDER:
257 sal_Bool bIsAutoBorder = sal_Bool();
258 if ( (aAny >>= bIsAutoBorder) )
260 sal_Bool bBorder = maFrmDescr.IsFrameBorderOn();
261 maFrmDescr.ResetBorder();
262 if ( bIsAutoBorder )
263 maFrmDescr.SetFrameBorder( bBorder );
266 break;
267 case WID_FRAME_MARGIN_WIDTH:
269 sal_Int32 nMargin = 0;
270 Size aSize = maFrmDescr.GetMargin();
271 if ( aAny >>= nMargin )
273 aSize.Width() = nMargin;
274 maFrmDescr.SetMargin( aSize );
277 break;
278 case WID_FRAME_MARGIN_HEIGHT:
280 sal_Int32 nMargin = 0;
281 Size aSize = maFrmDescr.GetMargin();
282 if ( aAny >>= nMargin )
284 aSize.Height() = nMargin;
285 maFrmDescr.SetMargin( aSize );
288 break;
289 default: ;
293 uno::Any SAL_CALL IFrameObject::getPropertyValue(const ::rtl::OUString& aPropertyName)
294 throw ( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
296 const SfxItemPropertySimpleEntry* pEntry = maPropMap.getByName( aPropertyName );
297 if( !pEntry )
298 throw beans::UnknownPropertyException();
299 uno::Any aAny;
300 switch( pEntry->nWID )
302 case WID_FRAME_URL:
304 aAny <<= ::rtl::OUString( maFrmDescr.GetURL().GetMainURL( INetURLObject::NO_DECODE ) );
306 break;
307 case WID_FRAME_NAME:
309 aAny <<= ::rtl::OUString( maFrmDescr.GetName() );
311 break;
312 case WID_FRAME_IS_AUTO_SCROLL:
314 sal_Bool bIsAutoScroll = ( maFrmDescr.GetScrollingMode() == ScrollingAuto );
315 aAny <<= bIsAutoScroll;
317 break;
318 case WID_FRAME_IS_SCROLLING_MODE:
320 sal_Bool bIsScroll = ( maFrmDescr.GetScrollingMode() == ScrollingYes );
321 aAny <<= bIsScroll;
323 break;
324 case WID_FRAME_IS_BORDER:
326 sal_Bool bIsBorder = maFrmDescr.IsFrameBorderOn();
327 aAny <<= bIsBorder;
329 break;
330 case WID_FRAME_IS_AUTO_BORDER:
332 sal_Bool bIsAutoBorder = !maFrmDescr.IsFrameBorderSet();
333 aAny <<= bIsAutoBorder;
335 break;
336 case WID_FRAME_MARGIN_WIDTH:
338 aAny <<= (sal_Int32 ) maFrmDescr.GetMargin().Width();
340 break;
341 case WID_FRAME_MARGIN_HEIGHT:
343 aAny <<= (sal_Int32 ) maFrmDescr.GetMargin().Height();
345 default: ;
347 return aAny;
350 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 )
354 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 )
358 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 )
362 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 )
366 ::sal_Int16 SAL_CALL IFrameObject::execute() throw (::com::sun::star::uno::RuntimeException)
368 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
369 VclAbstractDialog* pDlg = pFact->CreateEditObjectDialog( NULL, ".uno:InsertObjectFloatingFrame", mxObj );
370 if ( pDlg )
371 pDlg->Execute();
372 return 0;
375 void SAL_CALL IFrameObject::setTitle( const ::rtl::OUString& ) throw (::com::sun::star::uno::RuntimeException)
381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */