LCOV - code coverage report
Current view: top level - UnoControls/source/controls - framecontrol.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 175 0.0 %
Date: 2014-04-14 Functions: 0 30 0.0 %
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             : #include "framecontrol.hxx"
      21             : 
      22             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      23             : #include <com/sun/star/frame/Frame.hpp>
      24             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      25             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      26             : #include <com/sun/star/frame/XDispatch.hpp>
      27             : #include <com/sun/star/util/URLTransformer.hpp>
      28             : #include <com/sun/star/util/XURLTransformer.hpp>
      29             : #include <comphelper/processfactory.hxx>
      30             : #include <cppuhelper/typeprovider.hxx>
      31             : #include <osl/diagnose.h>
      32             : 
      33             : //  namespaces
      34             : 
      35             : using namespace ::rtl;
      36             : using namespace ::osl;
      37             : using namespace ::cppu;
      38             : using namespace ::com::sun::star::uno;
      39             : using namespace ::com::sun::star::lang;
      40             : using namespace ::com::sun::star::beans;
      41             : using namespace ::com::sun::star::awt;
      42             : using namespace ::com::sun::star::frame;
      43             : using namespace ::com::sun::star::util;
      44             : 
      45             : namespace unocontrols{
      46             : 
      47             : //  construct/destruct
      48             : 
      49           0 : FrameControl::FrameControl( const Reference< XComponentContext >& rxContext)
      50             :     : BaseControl                   ( rxContext                                                                             )
      51             :     , OBroadcastHelper              ( m_aMutex                                                                              )
      52             :     , OPropertySetHelper            ( *(static_cast< OBroadcastHelper * >(this))  )
      53             :     , m_aInterfaceContainer         ( m_aMutex                                                                              )
      54           0 :     , m_aConnectionPointContainer   ( m_aMutex                                                                              )
      55             : {
      56           0 : }
      57             : 
      58           0 : FrameControl::~FrameControl()
      59             : {
      60           0 : }
      61             : 
      62             : //  XInterface
      63             : 
      64           0 : Any SAL_CALL FrameControl::queryInterface( const Type& rType ) throw( RuntimeException, std::exception )
      65             : {
      66             :     // Attention:
      67             :     //  Don't use mutex or guard in this method!!! Is a method of XInterface.
      68           0 :     Any aReturn;
      69           0 :     Reference< XInterface > xDel = BaseControl::impl_getDelegator();
      70           0 :     if ( xDel.is() )
      71             :     {
      72             :         // If an delegator exist, forward question to his queryInterface.
      73             :         // Delegator will ask his own queryAggregation!
      74           0 :         aReturn = xDel->queryInterface( rType );
      75             :     }
      76             :     else
      77             :     {
      78             :         // If an delegator unknown, forward question to own queryAggregation.
      79           0 :         aReturn = queryAggregation( rType );
      80             :     }
      81             : 
      82           0 :     return aReturn;
      83             : }
      84             : 
      85             : //  XInterface
      86             : 
      87           0 : void SAL_CALL FrameControl::acquire() throw()
      88             : {
      89             :     // Attention:
      90             :     //  Don't use mutex or guard in this method!!! Is a method of XInterface.
      91             : 
      92             :     // Forward to baseclass
      93           0 :     BaseControl::acquire();
      94           0 : }
      95             : 
      96             : //  XInterface
      97             : 
      98           0 : void SAL_CALL FrameControl::release() throw()
      99             : {
     100             :     // Attention:
     101             :     //  Don't use mutex or guard in this method!!! Is a method of XInterface.
     102             : 
     103             :     // Forward to baseclass
     104           0 :     BaseControl::release();
     105           0 : }
     106             : 
     107             : //  XTypeProvider
     108             : 
     109           0 : Sequence< Type > SAL_CALL FrameControl::getTypes() throw( RuntimeException, std::exception )
     110             : {
     111             :     // Optimize this method !
     112             :     // We initialize a static variable only one time. And we don't must use a mutex at every call!
     113             :     // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
     114             :     static OTypeCollection* pTypeCollection = NULL;
     115             : 
     116           0 :     if ( pTypeCollection == NULL )
     117             :     {
     118             :         // Ready for multithreading; get global mutex for first call of this method only! see before
     119           0 :         MutexGuard aGuard( Mutex::getGlobalMutex() );
     120             : 
     121             :         // Control these pointer again ... it can be, that another instance will be faster then these!
     122           0 :         if ( pTypeCollection == NULL )
     123             :         {
     124             :             // Create a static typecollection ...
     125           0 :             static OTypeCollection aTypeCollection  (   ::getCppuType(( const Reference< XControlModel              >*)NULL )   ,
     126           0 :                                                           ::getCppuType(( const Reference< XControlContainer            >*)NULL )   ,
     127           0 :                                                           ::getCppuType(( const Reference< XConnectionPointContainer    >*)NULL )   ,
     128             :                                                         BaseControl::getTypes()
     129           0 :                                                     );
     130             :             // ... and set his address to static pointer!
     131           0 :             pTypeCollection = &aTypeCollection;
     132           0 :         }
     133             :     }
     134             : 
     135           0 :     return pTypeCollection->getTypes();
     136             : }
     137             : 
     138             : //  XAggregation
     139             : 
     140           0 : Any SAL_CALL FrameControl::queryAggregation( const Type& aType ) throw( RuntimeException, std::exception )
     141             : {
     142             :     // Ask for my own supported interfaces ...
     143             :     // Attention: XTypeProvider and XInterface are supported by OComponentHelper!
     144             :     Any aReturn ( ::cppu::queryInterface(   aType                                               ,
     145             :                                                static_cast< XControlModel*              > ( this )  ,
     146             :                                                static_cast< XConnectionPointContainer*  > ( this )
     147             :                                         )
     148           0 :                 );
     149             : 
     150             :     // If searched interface not supported by this class ...
     151           0 :     if ( !aReturn.hasValue() )
     152             :     {
     153             :         // ... ask baseclasses.
     154           0 :         aReturn = OPropertySetHelper::queryInterface( aType );
     155           0 :         if ( !aReturn.hasValue() )
     156             :         {
     157           0 :             aReturn = BaseControl::queryAggregation( aType );
     158             :         }
     159             :     }
     160             : 
     161           0 :     return aReturn;
     162             : }
     163             : 
     164             : //  XControl
     165             : 
     166           0 : void SAL_CALL FrameControl::createPeer( const   Reference< XToolkit >&      xToolkit    ,
     167             :                                         const   Reference< XWindowPeer >&   xParentPeer ) throw( RuntimeException, std::exception )
     168             : {
     169           0 :     BaseControl::createPeer( xToolkit, xParentPeer );
     170           0 :     if ( impl_getPeerWindow().is() )
     171             :     {
     172           0 :         if( !m_sComponentURL.isEmpty() )
     173             :         {
     174           0 :             impl_createFrame( getPeer(), m_sComponentURL, m_seqLoaderArguments );
     175             :         }
     176             :     }
     177           0 : }
     178             : 
     179             : //  XControl
     180             : 
     181           0 : sal_Bool SAL_CALL FrameControl::setModel( const Reference< XControlModel >& /*xModel*/ ) throw( RuntimeException, std::exception )
     182             : {
     183             :     // We have no model.
     184           0 :     return sal_False;
     185             : }
     186             : 
     187             : //  XControl
     188             : 
     189           0 : Reference< XControlModel > SAL_CALL FrameControl::getModel() throw( RuntimeException, std::exception )
     190             : {
     191             :     // We have no model.
     192           0 :     return Reference< XControlModel >();
     193             : }
     194             : 
     195             : //  XControl
     196             : 
     197           0 : void SAL_CALL FrameControl::dispose() throw( RuntimeException, std::exception )
     198             : {
     199           0 :     impl_deleteFrame();
     200           0 :     BaseControl::dispose();
     201           0 : }
     202             : 
     203             : //  XView
     204             : 
     205           0 : sal_Bool SAL_CALL FrameControl::setGraphics( const Reference< XGraphics >& /*xDevice*/ ) throw( RuntimeException, std::exception )
     206             : {
     207             :     // it is not possible to print this control
     208           0 :     return sal_False;
     209             : }
     210             : 
     211             : //  XView
     212             : 
     213           0 : Reference< XGraphics > SAL_CALL FrameControl::getGraphics() throw( RuntimeException, std::exception )
     214             : {
     215             :     // when its not posible to set graphics ! then its possible to return null
     216           0 :     return Reference< XGraphics >();
     217             : }
     218             : 
     219             : //  XConnectionPointContainer
     220             : 
     221           0 : Sequence< Type > SAL_CALL FrameControl::getConnectionPointTypes() throw( RuntimeException, std::exception )
     222             : {
     223             :     // Forwarded to helper class
     224           0 :     return m_aConnectionPointContainer.getConnectionPointTypes();
     225             : }
     226             : 
     227             : //  XConnectionPointContainer
     228             : 
     229           0 : Reference< XConnectionPoint > SAL_CALL FrameControl::queryConnectionPoint( const Type& aType ) throw( RuntimeException, std::exception )
     230             : {
     231             :     // Forwarded to helper class
     232           0 :     return m_aConnectionPointContainer.queryConnectionPoint( aType );
     233             : }
     234             : 
     235             : //  XConnectionPointContainer
     236             : 
     237           0 : void SAL_CALL FrameControl::advise( const   Type&                       aType       ,
     238             :                                     const   Reference< XInterface >&    xListener   ) throw( RuntimeException, std::exception )
     239             : {
     240             :     // Forwarded to helper class
     241           0 :     m_aConnectionPointContainer.advise( aType, xListener );
     242           0 : }
     243             : 
     244             : //  XConnectionPointContainer
     245             : 
     246           0 : void SAL_CALL FrameControl::unadvise(   const   Type&                       aType       ,
     247             :                                         const   Reference< XInterface >&    xListener   ) throw( RuntimeException, std::exception )
     248             : {
     249             :     // Forwarded to helper class
     250           0 :     m_aConnectionPointContainer.unadvise( aType, xListener );
     251           0 : }
     252             : 
     253             : //  impl but public method to register service
     254             : 
     255           0 : const Sequence< OUString > FrameControl::impl_getStaticSupportedServiceNames()
     256             : {
     257           0 :     MutexGuard aGuard( Mutex::getGlobalMutex() );
     258           0 :     Sequence< OUString > seqServiceNames( 1 );
     259           0 :     seqServiceNames.getArray() [0] = SERVICENAME_FRAMECONTROL;
     260           0 :     return seqServiceNames;
     261             : }
     262             : 
     263             : //  impl but public method to register service
     264             : 
     265           0 : const OUString FrameControl::impl_getStaticImplementationName()
     266             : {
     267           0 :     return OUString(IMPLEMENTATIONNAME_FRAMECONTROL);
     268             : }
     269             : 
     270             : //  OPropertySetHelper
     271             : 
     272           0 : sal_Bool FrameControl::convertFastPropertyValue(        Any&        rConvertedValue ,
     273             :                                                         Any&        rOldValue       ,
     274             :                                                         sal_Int32   nHandle         ,
     275             :                                                 const   Any&        rValue          ) throw( IllegalArgumentException )
     276             : {
     277           0 :     bool bReturn = false;
     278           0 :     switch (nHandle)
     279             :     {
     280           0 :         case PROPERTYHANDLE_COMPONENTURL        :       rConvertedValue   = rValue;
     281           0 :                                                         rOldValue       <<= m_sComponentURL;
     282           0 :                                                         bReturn           = true;
     283           0 :                                                         break;
     284             : 
     285           0 :         case PROPERTYHANDLE_LOADERARGUMENTS     :       rConvertedValue   = rValue;
     286           0 :                                                         rOldValue       <<= m_seqLoaderArguments;
     287           0 :                                                         bReturn           = true;
     288           0 :                                                         break;
     289             :     }
     290             : 
     291           0 :     if ( !bReturn )
     292             :     {
     293           0 :         throw IllegalArgumentException();
     294             :     }
     295             : 
     296           0 :     return bReturn;
     297             : }
     298             : 
     299             : //  OPropertySetHelper
     300             : 
     301           0 : void FrameControl::setFastPropertyValue_NoBroadcast(            sal_Int32   nHandle ,
     302             :                                                         const   Any&        rValue  )
     303             :                                                         throw ( ::com::sun::star::uno::Exception, std::exception )
     304             : {
     305             :     // this method only set the value
     306           0 :     MutexGuard  aGuard (m_aMutex);
     307           0 :     switch (nHandle)
     308             :     {
     309           0 :         case PROPERTYHANDLE_COMPONENTURL        :       rValue >>= m_sComponentURL;
     310           0 :                                                         if (getPeer().is())
     311             :                                                         {
     312           0 :                                                             impl_createFrame ( getPeer(), m_sComponentURL, m_seqLoaderArguments );
     313             :                                                         }
     314           0 :                                                         break;
     315             : 
     316           0 :         case PROPERTYHANDLE_LOADERARGUMENTS     :       rValue >>= m_seqLoaderArguments;
     317           0 :                                                         break;
     318             : 
     319             :         default :                                       OSL_ENSURE ( nHandle == -1, "This is an invalid property handle." );
     320           0 :     }
     321           0 : }
     322             : 
     323             : //  OPropertySetHelper
     324             : 
     325           0 : void FrameControl::getFastPropertyValue(    Any&        rRet    ,
     326             :                                             sal_Int32   nHandle ) const
     327             : {
     328           0 :     MutexGuard  aGuard ( Mutex::getGlobalMutex() );
     329             : 
     330           0 :     switch (nHandle)
     331             :     {
     332           0 :         case PROPERTYHANDLE_COMPONENTURL    :       rRet <<= m_sComponentURL;
     333           0 :                                                     break;
     334             : 
     335           0 :         case PROPERTYHANDLE_LOADERARGUMENTS :       rRet <<= m_seqLoaderArguments;
     336           0 :                                                     break;
     337             : 
     338           0 :         case PROPERTYHANDLE_FRAME           :       rRet <<= m_xFrame;
     339           0 :                                                        break;
     340             : 
     341             :         default :                                   OSL_ENSURE ( nHandle == -1, "This is an invalid property handle." );
     342           0 :     }
     343           0 : }
     344             : 
     345             : //  OPropertySetHelper
     346             : 
     347           0 : IPropertyArrayHelper& FrameControl::getInfoHelper()
     348             : {
     349             :     // Create a table that map names to index values.
     350             :     static OPropertyArrayHelper* pInfo;
     351             : 
     352           0 :     if (!pInfo)
     353             :     {
     354             :         // global method must be guarded
     355           0 :         MutexGuard  aGuard ( Mutex::getGlobalMutex() );
     356             : 
     357           0 :         if (!pInfo)
     358             :         {
     359           0 :             pInfo = new OPropertyArrayHelper( impl_getStaticPropertyDescriptor(), sal_True );
     360           0 :         }
     361             :     }
     362             : 
     363           0 :     return *pInfo;
     364             : }
     365             : 
     366             : //  OPropertySetHelper
     367             : 
     368           0 : Reference< XPropertySetInfo > SAL_CALL FrameControl::getPropertySetInfo() throw( RuntimeException, std::exception )
     369             : {
     370             :     // Optimize this method !
     371             :     // We initialize a static variable only one time. And we don't must use a mutex at every call!
     372             :     // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
     373             :     static Reference< XPropertySetInfo >* pInfo = (Reference< XPropertySetInfo >*)0;
     374           0 :     if ( pInfo == (Reference< XPropertySetInfo >*)0 )
     375             :     {
     376             :         // Ready for multithreading
     377           0 :         MutexGuard aGuard ( Mutex::getGlobalMutex () );
     378             :         // Control this pointer again, another instance can be faster then these!
     379           0 :         if ( pInfo == (Reference< XPropertySetInfo >*)0 )
     380             :         {
     381             :             // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
     382             :             // (Use method "getInfoHelper()".)
     383           0 :             static Reference< XPropertySetInfo > xInfo ( createPropertySetInfo ( getInfoHelper () ) );
     384           0 :             pInfo = &xInfo;
     385           0 :         }
     386             :     }
     387           0 :     return ( *pInfo );
     388             : }
     389             : 
     390             : //  BaseControl
     391             : 
     392           0 : WindowDescriptor* FrameControl::impl_getWindowDescriptor( const Reference< XWindowPeer >& xParentPeer )
     393             : {
     394           0 :     WindowDescriptor* pDescriptor   = new WindowDescriptor;
     395             : 
     396           0 :     pDescriptor->Type               = WindowClass_CONTAINER;
     397           0 :     pDescriptor->ParentIndex        = -1;
     398           0 :     pDescriptor->Parent             = xParentPeer;
     399           0 :     pDescriptor->Bounds             = getPosSize ();
     400           0 :     pDescriptor->WindowAttributes   = 0;
     401             : 
     402           0 :     return pDescriptor;
     403             : }
     404             : 
     405             : //  private method
     406             : 
     407           0 : void FrameControl::impl_createFrame(    const   Reference< XWindowPeer >&   xPeer       ,
     408             :                                         const   OUString&                   rURL        ,
     409             :                                         const   Sequence< PropertyValue >&  rArguments  )
     410             : {
     411           0 :     Reference< XFrame2 >     xOldFrame;
     412           0 :     Reference< XFrame2 >     xNewFrame;
     413             : 
     414             :     {
     415           0 :         MutexGuard  aGuard ( m_aMutex );
     416           0 :         xOldFrame = m_xFrame;
     417             :     }
     418             : 
     419           0 :     xNewFrame = Frame::create( impl_getComponentContext() );
     420             : 
     421           0 :     Reference< XWindow >  xWP ( xPeer, UNO_QUERY );
     422           0 :     xNewFrame->initialize ( xWP );
     423             : 
     424             :     //  option
     425             :     //xFrame->setName( "WhatYouWant" );
     426             : 
     427           0 :     Reference< XURLTransformer > xTrans = URLTransformer::create( impl_getComponentContext() );
     428             :     // load file
     429           0 :     URL aURL;
     430           0 :     aURL.Complete = rURL;
     431           0 :     xTrans->parseStrict( aURL );
     432             : 
     433           0 :     Reference< XDispatch >  xDisp = xNewFrame->queryDispatch ( aURL, OUString (), FrameSearchFlag::SELF );
     434           0 :     if (xDisp.is())
     435             :     {
     436           0 :         xDisp->dispatch ( aURL, rArguments );
     437             :     }
     438             : 
     439             :     // set the frame
     440             :     {
     441           0 :         MutexGuard aGuard ( m_aMutex );
     442           0 :         m_xFrame = xNewFrame;
     443             :     }
     444             : 
     445             :     // notify the listeners
     446           0 :     sal_Int32   nFrameId = PROPERTYHANDLE_FRAME;
     447           0 :     Any aNewFrame ( &xNewFrame, ::getCppuType((const Reference< XFrame >*)0) );
     448           0 :     Any aOldFrame ( &xOldFrame, ::getCppuType((const Reference< XFrame >*)0) );
     449             : 
     450           0 :     fire ( &nFrameId, &aNewFrame, &aOldFrame, 1, sal_False );
     451             : 
     452           0 :     if (xOldFrame.is())
     453             :     {
     454           0 :         xOldFrame->dispose ();
     455           0 :     }
     456           0 : }
     457             : 
     458             : //  private method
     459             : 
     460           0 : void FrameControl::impl_deleteFrame()
     461             : {
     462           0 :     Reference< XFrame2 >  xOldFrame;
     463           0 :     Reference< XFrame2 >  xNullFrame;
     464             : 
     465             :     {
     466             :         // do not dispose the frame in this guarded section (deadlock?)
     467           0 :         MutexGuard aGuard( m_aMutex );
     468           0 :         xOldFrame = m_xFrame;
     469           0 :         m_xFrame = Reference< XFrame2 > ();
     470             :     }
     471             : 
     472             :     // notify the listeners
     473           0 :     sal_Int32 nFrameId = PROPERTYHANDLE_FRAME;
     474           0 :     Any aNewFrame( &xNullFrame, ::getCppuType((const Reference< XFrame2 >*)0) );
     475           0 :     Any aOldFrame( &xOldFrame, ::getCppuType((const Reference< XFrame2 >*)0) );
     476           0 :     fire( &nFrameId, &aNewFrame, &aOldFrame, 1, sal_False );
     477             : 
     478             :     // dispose the frame
     479           0 :     if( xOldFrame.is() )
     480           0 :         xOldFrame->dispose();
     481           0 : }
     482             : 
     483             : //  private method
     484             : 
     485           0 : const Sequence< Property > FrameControl::impl_getStaticPropertyDescriptor()
     486             : {
     487             :     // All Properties of this implementation. The array must be sorted!
     488             :     static const Property pPropertys[PROPERTY_COUNT] =
     489             :     {
     490           0 :         Property( PROPERTYNAME_COMPONENTURL, PROPERTYHANDLE_COMPONENTURL, ::getCppuType((const OUString*)0), PropertyAttribute::BOUND | PropertyAttribute::CONSTRAINED ),
     491           0 :         Property( PROPERTYNAME_FRAME, PROPERTYHANDLE_FRAME, ::getCppuType((const Reference< XFrame >*)0), PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT   ),
     492           0 :         Property( PROPERTYNAME_LOADERARGUMENTS, PROPERTYHANDLE_LOADERARGUMENTS, ::getCppuType((const Sequence< PropertyValue >*)0), PropertyAttribute::BOUND | PropertyAttribute::CONSTRAINED )
     493           0 :     };
     494             : 
     495           0 :     static const Sequence< Property > seqPropertys( pPropertys, PROPERTY_COUNT );
     496             : 
     497           0 :     return seqPropertys;
     498             : }
     499             : 
     500             : }   // namespace unocontrols
     501             : 
     502             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10