1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sfx2.hxx" 30 31 #include "iframe.hxx" 32 #include <sfx2/sfxdlg.hxx> 33 #include <sfx2/sfxsids.hrc> 34 #include <com/sun/star/frame/XDispatchProvider.hpp> 35 #include <com/sun/star/frame/XDispatch.hpp> 36 #include <com/sun/star/frame/XFramesSupplier.hpp> 37 #include <com/sun/star/util/XURLTransformer.hpp> 38 39 #include <tools/urlobj.hxx> 40 #include <tools/debug.hxx> 41 #include <rtl/ustring.hxx> 42 #include <toolkit/helper/vclunohelper.hxx> 43 #include <svtools/miscopt.hxx> 44 #include <vcl/window.hxx> 45 46 using namespace ::com::sun::star; 47 48 namespace sfx2 49 { 50 51 class IFrameWindow_Impl : public Window 52 { 53 uno::Reference < frame::XFrame > mxFrame; 54 sal_Bool bActive; 55 sal_Bool bBorder; 56 57 public: 58 IFrameWindow_Impl( Window *pParent, 59 sal_Bool bHasBorder, 60 WinBits nWinBits = 0 ); 61 62 public: 63 void SetBorder( sal_Bool bNewBorder = sal_True ); 64 sal_Bool HasBorder() const { return bBorder; } 65 }; 66 67 IFrameWindow_Impl::IFrameWindow_Impl( Window *pParent, sal_Bool bHasBorder, WinBits nWinBits ) 68 : Window( pParent, nWinBits | WB_CLIPCHILDREN | WB_NODIALOGCONTROL | WB_DOCKBORDER ) 69 , bActive(sal_False) 70 , bBorder(bHasBorder) 71 { 72 if ( !bHasBorder ) 73 SetBorderStyle( WINDOW_BORDER_NOBORDER ); 74 else 75 SetBorderStyle( WINDOW_BORDER_NORMAL ); 76 //SetActivateMode( ACTIVATE_MODE_GRABFOCUS ); 77 } 78 79 void IFrameWindow_Impl::SetBorder( sal_Bool bNewBorder ) 80 { 81 if ( bBorder != bNewBorder ) 82 { 83 Size aSize = GetSizePixel(); 84 bBorder = bNewBorder; 85 if ( bBorder ) 86 SetBorderStyle( WINDOW_BORDER_NORMAL ); 87 else 88 SetBorderStyle( WINDOW_BORDER_NOBORDER ); 89 if ( GetSizePixel() != aSize ) 90 SetSizePixel( aSize ); 91 } 92 } 93 94 #define PROPERTY_UNBOUND 0 95 96 #define WID_FRAME_URL 1 97 #define WID_FRAME_NAME 2 98 #define WID_FRAME_IS_AUTO_SCROLL 3 99 #define WID_FRAME_IS_SCROLLING_MODE 4 100 #define WID_FRAME_IS_BORDER 5 101 #define WID_FRAME_IS_AUTO_BORDER 6 102 #define WID_FRAME_MARGIN_WIDTH 7 103 #define WID_FRAME_MARGIN_HEIGHT 8 104 105 const SfxItemPropertyMapEntry* lcl_GetIFramePropertyMap_Impl() 106 { 107 static SfxItemPropertyMapEntry aIFramePropertyMap_Impl[] = 108 { 109 { MAP_CHAR_LEN("FrameIsAutoBorder"), WID_FRAME_IS_AUTO_BORDER, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 }, 110 { MAP_CHAR_LEN("FrameIsAutoScroll"), WID_FRAME_IS_AUTO_SCROLL, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 }, 111 { MAP_CHAR_LEN("FrameIsBorder"), WID_FRAME_IS_BORDER, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 }, 112 { MAP_CHAR_LEN("FrameIsScrollingMode"), WID_FRAME_IS_SCROLLING_MODE, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 }, 113 { MAP_CHAR_LEN("FrameMarginHeight"), WID_FRAME_MARGIN_HEIGHT, &::getCppuType( (sal_Int32*)0 ), PROPERTY_UNBOUND, 0 }, 114 { MAP_CHAR_LEN("FrameMarginWidth"), WID_FRAME_MARGIN_WIDTH, &::getCppuType( (sal_Int32*)0 ), PROPERTY_UNBOUND, 0 }, 115 { MAP_CHAR_LEN("FrameName"), WID_FRAME_NAME, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, 116 { MAP_CHAR_LEN("FrameURL"), WID_FRAME_URL, &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 }, 117 {0,0,0,0,0,0} 118 }; 119 return aIFramePropertyMap_Impl; 120 } 121 122 SFX_IMPL_XSERVICEINFO( IFrameObject, "com.sun.star.embed.SpecialEmbeddedObject", "com.sun.star.comp.sfx2.IFrameObject" ) 123 SFX_IMPL_SINGLEFACTORY( IFrameObject ); 124 125 IFrameObject::IFrameObject( const uno::Reference < lang::XMultiServiceFactory >& rFact ) 126 : mxFact( rFact ) 127 , maPropMap( lcl_GetIFramePropertyMap_Impl() ) 128 { 129 } 130 131 IFrameObject::~IFrameObject() 132 { 133 } 134 135 136 void SAL_CALL IFrameObject::initialize( const uno::Sequence< uno::Any >& aArguments ) throw ( uno::Exception, uno::RuntimeException ) 137 { 138 if ( aArguments.getLength() ) 139 aArguments[0] >>= mxObj; 140 } 141 142 sal_Bool SAL_CALL IFrameObject::load( 143 const uno::Sequence < com::sun::star::beans::PropertyValue >& /*lDescriptor*/, 144 const uno::Reference < frame::XFrame >& xFrame ) 145 throw( uno::RuntimeException ) 146 { 147 if ( SvtMiscOptions().IsPluginsEnabled() ) 148 { 149 DBG_ASSERT( !mxFrame.is(), "Frame already existing!" ); 150 Window* pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() ); 151 IFrameWindow_Impl* pWin = new IFrameWindow_Impl( pParent, maFrmDescr.IsFrameBorderOn() ); 152 pWin->SetSizePixel( pParent->GetOutputSizePixel() ); 153 pWin->SetBackground(); 154 pWin->Show(); 155 156 uno::Reference < awt::XWindow > xWindow( pWin->GetComponentInterface(), uno::UNO_QUERY ); 157 xFrame->setComponent( xWindow, uno::Reference < frame::XController >() ); 158 159 // we must destroy the IFrame before the parent is destroyed 160 xWindow->addEventListener( this ); 161 162 mxFrame = uno::Reference< frame::XFrame >( mxFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Frame" ) ), 163 uno::UNO_QUERY ); 164 uno::Reference < awt::XWindow > xWin( pWin->GetComponentInterface(), uno::UNO_QUERY ); 165 mxFrame->initialize( xWin ); 166 mxFrame->setName( maFrmDescr.GetName() ); 167 168 uno::Reference < frame::XFramesSupplier > xFramesSupplier( xFrame, uno::UNO_QUERY ); 169 if ( xFramesSupplier.is() ) 170 mxFrame->setCreator( xFramesSupplier ); 171 172 uno::Reference< frame::XDispatchProvider > xProv( mxFrame, uno::UNO_QUERY ); 173 174 util::URL aTargetURL; 175 aTargetURL.Complete = ::rtl::OUString( maFrmDescr.GetURL().GetMainURL( INetURLObject::NO_DECODE ) ); 176 uno::Reference < util::XURLTransformer > xTrans( mxFact->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), uno::UNO_QUERY ); 177 xTrans->parseStrict( aTargetURL ); 178 179 uno::Sequence < beans::PropertyValue > aProps(2); 180 aProps[0].Name = ::rtl::OUString::createFromAscii("PluginMode"); 181 aProps[0].Value <<= (sal_Int16) 2; 182 aProps[1].Name = ::rtl::OUString::createFromAscii("ReadOnly"); 183 aProps[1].Value <<= (sal_Bool) sal_True; 184 uno::Reference < frame::XDispatch > xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString::createFromAscii("_self"), 0 ); 185 if ( xDisp.is() ) 186 xDisp->dispatch( aTargetURL, aProps ); 187 188 return sal_True; 189 } 190 191 return sal_False; 192 } 193 194 void SAL_CALL IFrameObject::cancel() throw( com::sun::star::uno::RuntimeException ) 195 { 196 try 197 { 198 uno::Reference < util::XCloseable > xClose( mxFrame, uno::UNO_QUERY ); 199 if ( xClose.is() ) 200 xClose->close( sal_True ); 201 mxFrame = 0; 202 } 203 catch ( uno::Exception& ) 204 {} 205 } 206 207 void SAL_CALL IFrameObject::close( sal_Bool /*bDeliverOwnership*/ ) throw( com::sun::star::util::CloseVetoException, com::sun::star::uno::RuntimeException ) 208 { 209 } 210 211 void SAL_CALL IFrameObject::addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException ) 212 { 213 } 214 215 void SAL_CALL IFrameObject::removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException ) 216 { 217 } 218 219 void SAL_CALL IFrameObject::disposing( const com::sun::star::lang::EventObject& ) throw (com::sun::star::uno::RuntimeException) 220 { 221 cancel(); 222 } 223 224 uno::Reference< beans::XPropertySetInfo > SAL_CALL IFrameObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException ) 225 { 226 static uno::Reference< beans::XPropertySetInfo > xInfo = new SfxItemPropertySetInfo( &maPropMap ); 227 return xInfo; 228 } 229 230 void SAL_CALL IFrameObject::setPropertyValue(const ::rtl::OUString& aPropertyName, const uno::Any& aAny) 231 throw ( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException) 232 { 233 const SfxItemPropertySimpleEntry* pEntry = maPropMap.getByName( aPropertyName ); 234 if( !pEntry ) 235 throw beans::UnknownPropertyException(); 236 switch( pEntry->nWID ) 237 { 238 case WID_FRAME_URL: 239 { 240 ::rtl::OUString aURL; 241 aAny >>= aURL; 242 maFrmDescr.SetURL( String(aURL) ); 243 } 244 break; 245 case WID_FRAME_NAME: 246 { 247 ::rtl::OUString aName; 248 if ( aAny >>= aName ) 249 maFrmDescr.SetName( aName ); 250 } 251 break; 252 case WID_FRAME_IS_AUTO_SCROLL: 253 { 254 sal_Bool bIsAutoScroll = sal_Bool(); 255 if ( (aAny >>= bIsAutoScroll) && bIsAutoScroll ) 256 maFrmDescr.SetScrollingMode( ScrollingAuto ); 257 } 258 break; 259 case WID_FRAME_IS_SCROLLING_MODE: 260 { 261 sal_Bool bIsScroll = sal_Bool(); 262 if ( aAny >>= bIsScroll ) 263 maFrmDescr.SetScrollingMode( bIsScroll ? ScrollingYes : ScrollingNo ); 264 } 265 break; 266 case WID_FRAME_IS_BORDER: 267 { 268 sal_Bool bIsBorder = sal_Bool(); 269 if ( aAny >>= bIsBorder ) 270 maFrmDescr.SetFrameBorder( bIsBorder ); 271 } 272 break; 273 case WID_FRAME_IS_AUTO_BORDER: 274 { 275 sal_Bool bIsAutoBorder = sal_Bool(); 276 if ( (aAny >>= bIsAutoBorder) ) 277 { 278 sal_Bool bBorder = maFrmDescr.IsFrameBorderOn(); 279 maFrmDescr.ResetBorder(); 280 if ( bIsAutoBorder ) 281 maFrmDescr.SetFrameBorder( bBorder ); 282 } 283 } 284 break; 285 case WID_FRAME_MARGIN_WIDTH: 286 { 287 sal_Int32 nMargin = 0; 288 Size aSize = maFrmDescr.GetMargin(); 289 if ( aAny >>= nMargin ) 290 { 291 aSize.Width() = nMargin; 292 maFrmDescr.SetMargin( aSize ); 293 } 294 } 295 break; 296 case WID_FRAME_MARGIN_HEIGHT: 297 { 298 sal_Int32 nMargin = 0; 299 Size aSize = maFrmDescr.GetMargin(); 300 if ( aAny >>= nMargin ) 301 { 302 aSize.Height() = nMargin; 303 maFrmDescr.SetMargin( aSize ); 304 } 305 } 306 break; 307 default: ; 308 } 309 } 310 311 uno::Any SAL_CALL IFrameObject::getPropertyValue(const ::rtl::OUString& aPropertyName) 312 throw ( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 313 { 314 const SfxItemPropertySimpleEntry* pEntry = maPropMap.getByName( aPropertyName ); 315 if( !pEntry ) 316 throw beans::UnknownPropertyException(); 317 uno::Any aAny; 318 switch( pEntry->nWID ) 319 { 320 case WID_FRAME_URL: 321 { 322 aAny <<= ::rtl::OUString( maFrmDescr.GetURL().GetMainURL( INetURLObject::NO_DECODE ) ); 323 } 324 break; 325 case WID_FRAME_NAME: 326 { 327 aAny <<= ::rtl::OUString( maFrmDescr.GetName() ); 328 } 329 break; 330 case WID_FRAME_IS_AUTO_SCROLL: 331 { 332 sal_Bool bIsAutoScroll = ( maFrmDescr.GetScrollingMode() == ScrollingAuto ); 333 aAny <<= bIsAutoScroll; 334 } 335 break; 336 case WID_FRAME_IS_SCROLLING_MODE: 337 { 338 sal_Bool bIsScroll = ( maFrmDescr.GetScrollingMode() == ScrollingYes ); 339 aAny <<= bIsScroll; 340 } 341 break; 342 case WID_FRAME_IS_BORDER: 343 { 344 sal_Bool bIsBorder = maFrmDescr.IsFrameBorderOn(); 345 aAny <<= bIsBorder; 346 } 347 break; 348 case WID_FRAME_IS_AUTO_BORDER: 349 { 350 sal_Bool bIsAutoBorder = !maFrmDescr.IsFrameBorderSet(); 351 aAny <<= bIsAutoBorder; 352 } 353 break; 354 case WID_FRAME_MARGIN_WIDTH: 355 { 356 aAny <<= (sal_Int32 ) maFrmDescr.GetMargin().Width(); 357 } 358 break; 359 case WID_FRAME_MARGIN_HEIGHT: 360 { 361 aAny <<= (sal_Int32 ) maFrmDescr.GetMargin().Height(); 362 } 363 default: ; 364 } 365 return aAny; 366 } 367 368 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 ) 369 { 370 } 371 372 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 ) 373 { 374 } 375 376 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 ) 377 { 378 } 379 380 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 ) 381 { 382 } 383 384 ::sal_Int16 SAL_CALL IFrameObject::execute() throw (::com::sun::star::uno::RuntimeException) 385 { 386 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create(); 387 VclAbstractDialog* pDlg = pFact->CreateEditObjectDialog( NULL, rtl::OUString::createFromAscii(".uno:InsertObjectFloatingFrame"), mxObj ); 388 if ( pDlg ) 389 pDlg->Execute(); 390 return 0; 391 } 392 393 void SAL_CALL IFrameObject::setTitle( const ::rtl::OUString& ) throw (::com::sun::star::uno::RuntimeException) 394 { 395 } 396 397 } 398