LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/doc - iframe.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 168 1.2 %
Date: 2012-12-27 Functions: 3 32 9.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      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/XFramesSupplier.hpp>
      27             : #include <com/sun/star/util/URLTransformer.hpp>
      28             : #include <com/sun/star/util/XURLTransformer.hpp>
      29             : 
      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>
      37             : 
      38             : using namespace ::com::sun::star;
      39             : 
      40             : namespace sfx2
      41             : {
      42             : 
      43           0 : class IFrameWindow_Impl : public Window
      44             : {
      45             :     uno::Reference < frame::XFrame > mxFrame;
      46             :     sal_Bool                bBorder;
      47             : 
      48             : public:
      49             :     IFrameWindow_Impl( Window *pParent,
      50             :                        sal_Bool bHasBorder,
      51             :                        WinBits nWinBits = 0 );
      52             : 
      53             : public:
      54             :     sal_Bool        HasBorder() const { return bBorder; }
      55             : };
      56             : 
      57           0 : IFrameWindow_Impl::IFrameWindow_Impl( Window *pParent, sal_Bool bHasBorder, WinBits nWinBits )
      58             :     : Window( pParent, nWinBits | WB_CLIPCHILDREN | WB_NODIALOGCONTROL | WB_DOCKBORDER )
      59           0 :     , bBorder(bHasBorder)
      60             : {
      61           0 :     if ( !bHasBorder )
      62           0 :         SetBorderStyle( WINDOW_BORDER_NOBORDER );
      63             :     else
      64           0 :         SetBorderStyle( WINDOW_BORDER_NORMAL );
      65           0 : }
      66             : 
      67             : #define PROPERTY_UNBOUND 0
      68             : 
      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
      77             : 
      78           0 : const SfxItemPropertyMapEntry* lcl_GetIFramePropertyMap_Impl()
      79             : {
      80             :     static SfxItemPropertyMapEntry aIFramePropertyMap_Impl[] =
      81             :     {
      82           0 :         { MAP_CHAR_LEN("FrameIsAutoBorder"),    WID_FRAME_IS_AUTO_BORDER,   &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
      83           0 :         { MAP_CHAR_LEN("FrameIsAutoScroll"),    WID_FRAME_IS_AUTO_SCROLL,   &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
      84           0 :         { MAP_CHAR_LEN("FrameIsBorder"),        WID_FRAME_IS_BORDER,        &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
      85           0 :         { MAP_CHAR_LEN("FrameIsScrollingMode"), WID_FRAME_IS_SCROLLING_MODE, &::getBooleanCppuType(), PROPERTY_UNBOUND, 0 },
      86           0 :         { MAP_CHAR_LEN("FrameMarginHeight"),    WID_FRAME_MARGIN_HEIGHT,    &::getCppuType( (sal_Int32*)0 ), PROPERTY_UNBOUND, 0 },
      87           0 :         { MAP_CHAR_LEN("FrameMarginWidth"),     WID_FRAME_MARGIN_WIDTH,     &::getCppuType( (sal_Int32*)0 ), PROPERTY_UNBOUND, 0 },
      88           0 :         { MAP_CHAR_LEN("FrameName"),            WID_FRAME_NAME,             &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
      89           0 :         { MAP_CHAR_LEN("FrameURL"),             WID_FRAME_URL,              &::getCppuType((const ::rtl::OUString*)0), PROPERTY_UNBOUND, 0 },
      90             :         {0,0,0,0,0,0}
      91           0 :     };
      92           0 :     return aIFramePropertyMap_Impl;
      93             : }
      94             : 
      95          44 : SFX_IMPL_XSERVICEINFO( IFrameObject, "com.sun.star.embed.SpecialEmbeddedObject", "com.sun.star.comp.sfx2.IFrameObject" )
      96           0 : SFX_IMPL_SINGLEFACTORY( IFrameObject );
      97             : 
      98           0 : IFrameObject::IFrameObject( const uno::Reference < lang::XMultiServiceFactory >& rFact )
      99             :     : mxFact( rFact )
     100           0 :     , maPropMap( lcl_GetIFramePropertyMap_Impl() )
     101             : {
     102           0 : }
     103             : 
     104           0 : IFrameObject::~IFrameObject()
     105             : {
     106           0 : }
     107             : 
     108             : 
     109           0 : void SAL_CALL IFrameObject::initialize( const uno::Sequence< uno::Any >& aArguments ) throw ( uno::Exception, uno::RuntimeException )
     110             : {
     111           0 :     if ( aArguments.getLength() )
     112           0 :         aArguments[0] >>= mxObj;
     113           0 : }
     114             : 
     115           0 : 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 )
     119             : {
     120           0 :     if ( SvtMiscOptions().IsPluginsEnabled() )
     121             :     {
     122             :         DBG_ASSERT( !mxFrame.is(), "Frame already existing!" );
     123           0 :         Window* pParent = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
     124           0 :         IFrameWindow_Impl* pWin = new IFrameWindow_Impl( pParent, maFrmDescr.IsFrameBorderOn() );
     125           0 :         pWin->SetSizePixel( pParent->GetOutputSizePixel() );
     126           0 :         pWin->SetBackground();
     127           0 :         pWin->Show();
     128             : 
     129           0 :         uno::Reference < awt::XWindow > xWindow( pWin->GetComponentInterface(), uno::UNO_QUERY );
     130           0 :         xFrame->setComponent( xWindow, uno::Reference < frame::XController >() );
     131             : 
     132             :         // we must destroy the IFrame before the parent is destroyed
     133           0 :         xWindow->addEventListener( this );
     134             : 
     135           0 :         mxFrame = uno::Reference< frame::XFrame >( mxFact->createInstance( "com.sun.star.frame.Frame" ),uno::UNO_QUERY );
     136           0 :         uno::Reference < awt::XWindow > xWin( pWin->GetComponentInterface(), uno::UNO_QUERY );
     137           0 :         mxFrame->initialize( xWin );
     138           0 :         mxFrame->setName( maFrmDescr.GetName() );
     139             : 
     140           0 :         uno::Reference < frame::XFramesSupplier > xFramesSupplier( xFrame, uno::UNO_QUERY );
     141           0 :         if ( xFramesSupplier.is() )
     142           0 :             mxFrame->setCreator( xFramesSupplier );
     143             : 
     144           0 :         uno::Reference< frame::XDispatchProvider > xProv( mxFrame, uno::UNO_QUERY );
     145             : 
     146           0 :         util::URL aTargetURL;
     147           0 :         aTargetURL.Complete = ::rtl::OUString( maFrmDescr.GetURL().GetMainURL( INetURLObject::NO_DECODE ) );
     148           0 :         uno::Reference < util::XURLTransformer > xTrans( util::URLTransformer::create( ::comphelper::getComponentContext(mxFact) ) );
     149           0 :         xTrans->parseStrict( aTargetURL );
     150             : 
     151           0 :         uno::Sequence < beans::PropertyValue > aProps(2);
     152           0 :         aProps[0].Name = "PluginMode";
     153           0 :         aProps[0].Value <<= (sal_Int16) 2;
     154           0 :         aProps[1].Name = "ReadOnly";
     155           0 :         aProps[1].Value <<= (sal_Bool) sal_True;
     156           0 :         uno::Reference < frame::XDispatch > xDisp = xProv->queryDispatch( aTargetURL, "_self", 0 );
     157           0 :         if ( xDisp.is() )
     158           0 :             xDisp->dispatch( aTargetURL, aProps );
     159             : 
     160           0 :         return sal_True;
     161             :     }
     162             : 
     163           0 :     return sal_False;
     164             : }
     165             : 
     166           0 : void SAL_CALL IFrameObject::cancel() throw( com::sun::star::uno::RuntimeException )
     167             : {
     168             :     try
     169             :     {
     170           0 :         uno::Reference < util::XCloseable > xClose( mxFrame, uno::UNO_QUERY );
     171           0 :         if ( xClose.is() )
     172           0 :             xClose->close( sal_True );
     173           0 :         mxFrame = 0;
     174             :     }
     175           0 :     catch (const uno::Exception&)
     176             :     {
     177             :     }
     178           0 : }
     179             : 
     180           0 : void SAL_CALL IFrameObject::close( sal_Bool /*bDeliverOwnership*/ ) throw( com::sun::star::util::CloseVetoException, com::sun::star::uno::RuntimeException )
     181             : {
     182           0 : }
     183             : 
     184           0 : void SAL_CALL IFrameObject::addCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
     185             : {
     186           0 : }
     187             : 
     188           0 : void SAL_CALL IFrameObject::removeCloseListener( const com::sun::star::uno::Reference < com::sun::star::util::XCloseListener >& ) throw( com::sun::star::uno::RuntimeException )
     189             : {
     190           0 : }
     191             : 
     192           0 : void SAL_CALL IFrameObject::disposing( const com::sun::star::lang::EventObject& ) throw (com::sun::star::uno::RuntimeException)
     193             : {
     194           0 :     cancel();
     195           0 : }
     196             : 
     197           0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL IFrameObject::getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException )
     198             : {
     199           0 :     static uno::Reference< beans::XPropertySetInfo > xInfo = new SfxItemPropertySetInfo( maPropMap );
     200           0 :     return xInfo;
     201             : }
     202             : 
     203           0 : void SAL_CALL IFrameObject::setPropertyValue(const ::rtl::OUString& aPropertyName, const uno::Any& aAny)
     204             :     throw ( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
     205             : {
     206           0 :     const SfxItemPropertySimpleEntry*  pEntry = maPropMap.getByName( aPropertyName );
     207           0 :     if( !pEntry )
     208           0 :          throw beans::UnknownPropertyException();
     209           0 :     switch( pEntry->nWID )
     210             :     {
     211             :     case WID_FRAME_URL:
     212             :     {
     213           0 :         ::rtl::OUString aURL;
     214           0 :         aAny >>= aURL;
     215           0 :         maFrmDescr.SetURL( String(aURL) );
     216             :     }
     217           0 :     break;
     218             :     case WID_FRAME_NAME:
     219             :     {
     220           0 :         ::rtl::OUString aName;
     221           0 :         if ( aAny >>= aName )
     222           0 :             maFrmDescr.SetName( aName );
     223             :     }
     224           0 :     break;
     225             :     case WID_FRAME_IS_AUTO_SCROLL:
     226             :     {
     227           0 :         sal_Bool bIsAutoScroll = sal_Bool();
     228           0 :         if ( (aAny >>= bIsAutoScroll) && bIsAutoScroll )
     229           0 :             maFrmDescr.SetScrollingMode( ScrollingAuto );
     230             :     }
     231           0 :     break;
     232             :     case WID_FRAME_IS_SCROLLING_MODE:
     233             :     {
     234           0 :         sal_Bool bIsScroll = sal_Bool();
     235           0 :         if ( aAny >>= bIsScroll )
     236           0 :             maFrmDescr.SetScrollingMode( bIsScroll ? ScrollingYes : ScrollingNo );
     237             :     }
     238           0 :     break;
     239             :     case WID_FRAME_IS_BORDER:
     240             :     {
     241           0 :         sal_Bool bIsBorder = sal_Bool();
     242           0 :         if ( aAny >>= bIsBorder )
     243           0 :             maFrmDescr.SetFrameBorder( bIsBorder );
     244             :     }
     245           0 :     break;
     246             :     case WID_FRAME_IS_AUTO_BORDER:
     247             :     {
     248           0 :         sal_Bool bIsAutoBorder = sal_Bool();
     249           0 :         if ( (aAny >>= bIsAutoBorder) )
     250             :         {
     251           0 :             sal_Bool bBorder = maFrmDescr.IsFrameBorderOn();
     252           0 :             maFrmDescr.ResetBorder();
     253           0 :             if ( bIsAutoBorder )
     254           0 :                 maFrmDescr.SetFrameBorder( bBorder );
     255             :         }
     256             :     }
     257           0 :     break;
     258             :     case WID_FRAME_MARGIN_WIDTH:
     259             :     {
     260           0 :         sal_Int32 nMargin = 0;
     261           0 :         Size aSize = maFrmDescr.GetMargin();
     262           0 :         if ( aAny >>= nMargin )
     263             :         {
     264           0 :             aSize.Width() = nMargin;
     265           0 :             maFrmDescr.SetMargin( aSize );
     266             :         }
     267             :     }
     268           0 :     break;
     269             :     case WID_FRAME_MARGIN_HEIGHT:
     270             :     {
     271           0 :         sal_Int32 nMargin = 0;
     272           0 :         Size aSize = maFrmDescr.GetMargin();
     273           0 :         if ( aAny >>= nMargin )
     274             :         {
     275           0 :             aSize.Height() = nMargin;
     276           0 :             maFrmDescr.SetMargin( aSize );
     277             :         }
     278             :     }
     279           0 :     break;
     280             :     default: ;
     281             :     }
     282           0 : }
     283             : 
     284           0 : uno::Any SAL_CALL IFrameObject::getPropertyValue(const ::rtl::OUString& aPropertyName)
     285             :         throw ( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
     286             : {
     287           0 :     const SfxItemPropertySimpleEntry*  pEntry = maPropMap.getByName( aPropertyName );
     288           0 :     if( !pEntry )
     289           0 :          throw beans::UnknownPropertyException();
     290           0 :     uno::Any aAny;
     291           0 :     switch( pEntry->nWID )
     292             :     {
     293             :     case WID_FRAME_URL:
     294             :     {
     295           0 :         aAny <<= ::rtl::OUString( maFrmDescr.GetURL().GetMainURL( INetURLObject::NO_DECODE ) );
     296             :     }
     297           0 :     break;
     298             :     case WID_FRAME_NAME:
     299             :     {
     300           0 :         aAny <<= ::rtl::OUString( maFrmDescr.GetName() );
     301             :     }
     302           0 :     break;
     303             :     case WID_FRAME_IS_AUTO_SCROLL:
     304             :     {
     305           0 :         sal_Bool bIsAutoScroll = ( maFrmDescr.GetScrollingMode() == ScrollingAuto );
     306           0 :         aAny <<= bIsAutoScroll;
     307             :     }
     308           0 :     break;
     309             :     case WID_FRAME_IS_SCROLLING_MODE:
     310             :     {
     311           0 :         sal_Bool bIsScroll = ( maFrmDescr.GetScrollingMode() == ScrollingYes );
     312           0 :         aAny <<= bIsScroll;
     313             :     }
     314           0 :     break;
     315             :     case WID_FRAME_IS_BORDER:
     316             :     {
     317           0 :         sal_Bool bIsBorder = maFrmDescr.IsFrameBorderOn();
     318           0 :         aAny <<= bIsBorder;
     319             :     }
     320           0 :     break;
     321             :     case WID_FRAME_IS_AUTO_BORDER:
     322             :     {
     323           0 :         sal_Bool bIsAutoBorder = !maFrmDescr.IsFrameBorderSet();
     324           0 :         aAny <<= bIsAutoBorder;
     325             :     }
     326           0 :     break;
     327             :     case WID_FRAME_MARGIN_WIDTH:
     328             :     {
     329           0 :         aAny <<= (sal_Int32 ) maFrmDescr.GetMargin().Width();
     330             :     }
     331           0 :     break;
     332             :     case WID_FRAME_MARGIN_HEIGHT:
     333             :     {
     334           0 :         aAny <<= (sal_Int32 ) maFrmDescr.GetMargin().Height();
     335             :     }
     336             :     default: ;
     337             :     }
     338           0 :     return aAny;
     339             : }
     340             : 
     341           0 : 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 )
     342             : {
     343           0 : }
     344             : 
     345           0 : 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 )
     346             : {
     347           0 : }
     348             : 
     349           0 : 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 )
     350             : {
     351           0 : }
     352             : 
     353           0 : 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 )
     354             : {
     355           0 : }
     356             : 
     357           0 : ::sal_Int16 SAL_CALL IFrameObject::execute() throw (::com::sun::star::uno::RuntimeException)
     358             : {
     359           0 :     SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
     360           0 :     VclAbstractDialog* pDlg = pFact->CreateEditObjectDialog( NULL, ".uno:InsertObjectFloatingFrame", mxObj );
     361           0 :     if ( pDlg )
     362           0 :         pDlg->Execute();
     363           0 :     return 0;
     364             : }
     365             : 
     366           0 : void SAL_CALL IFrameObject::setTitle( const ::rtl::OUString& ) throw (::com::sun::star::uno::RuntimeException)
     367             : {
     368           0 : }
     369             : 
     370          66 : }
     371             : 
     372             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10