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