LCOV - code coverage report
Current view: top level - framework/source/uifactory - windowcontentfactorymanager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 20 81 24.7 %
Date: 2012-08-25 Functions: 2 14 14.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 12 150 8.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      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.
      15                 :            :  *
      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).
      21                 :            :  *
      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.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <uifactory/windowcontentfactorymanager.hxx>
      30                 :            : #include <uifactory/uielementfactorymanager.hxx>
      31                 :            : #include <threadhelp/resetableguard.hxx>
      32                 :            : #include "services.h"
      33                 :            : 
      34                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      35                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      36                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      37                 :            : #include <com/sun/star/container/XNameContainer.hpp>
      38                 :            : #include <com/sun/star/container/XContainer.hpp>
      39                 :            : #include <com/sun/star/frame/XFrame.hpp>
      40                 :            : #include <com/sun/star/awt/XToolkit.hpp>
      41                 :            : #include <com/sun/star/awt/XControlModel.hpp>
      42                 :            : #include <com/sun/star/awt/XControl.hpp>
      43                 :            : 
      44                 :            : #include <rtl/ustrbuf.hxx>
      45                 :            : #include <cppuhelper/weak.hxx>
      46                 :            : #include <tools/urlobj.hxx>
      47                 :            : #include <tools/diagnose_ex.h>
      48                 :            : #include <vcl/svapp.hxx>
      49                 :            : 
      50                 :            : //_________________________________________________________________________________________________________________
      51                 :            : //  Defines
      52                 :            : //_________________________________________________________________________________________________________________
      53                 :            : 
      54                 :            : using namespace ::com::sun::star;
      55                 :            : 
      56                 :            : //_________________________________________________________________________________________________________________
      57                 :            : //  Namespace
      58                 :            : //_________________________________________________________________________________________________________________
      59                 :            : 
      60                 :            : namespace framework
      61                 :            : {
      62                 :            : 
      63                 :            : //*****************************************************************************************************************
      64                 :            : //  XInterface, XTypeProvider, XServiceInfo
      65                 :            : //*****************************************************************************************************************
      66 [ #  # ][ #  # ]:        466 : DEFINE_XSERVICEINFO_ONEINSTANCESERVICE  (   WindowContentFactoryManager                     ,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      67                 :            :                                             ::cppu::OWeakObject                             ,
      68                 :            :                                             SERVICENAME_WINDOWCONTENTFACTORYMANAGER         ,
      69                 :            :                                             IMPLEMENTATIONNAME_WINDOWCONTENTFACTORYMANAGER
      70                 :            :                                         )
      71                 :            : 
      72                 :          0 : DEFINE_INIT_SERVICE                     (   WindowContentFactoryManager, {} )
      73                 :            : 
      74                 :          0 : WindowContentFactoryManager::WindowContentFactoryManager( const uno::Reference< lang::XMultiServiceFactory >& xServiceManager ) :
      75                 :          0 :     ThreadHelpBase( &Application::GetSolarMutex() ),
      76                 :            :     m_bConfigRead( sal_False ),
      77         [ #  # ]:          0 :     m_xServiceManager( xServiceManager )
      78                 :            : {
      79 [ #  # ][ #  # ]:          0 :     m_pConfigAccess = new ConfigurationAccess_FactoryManager( m_xServiceManager,rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI.WindowContentFactories/Registered/ContentFactories" )) );
      80                 :          0 :     m_pConfigAccess->acquire();
      81 [ #  # ][ #  # ]:          0 :     m_xModuleManager = uno::Reference< frame::XModuleManager >( m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), uno::UNO_QUERY );
         [ #  # ][ #  # ]
                 [ #  # ]
      82                 :          0 : }
      83                 :            : 
      84         [ #  # ]:          0 : WindowContentFactoryManager::~WindowContentFactoryManager()
      85                 :            : {
      86         [ #  # ]:          0 :     ResetableGuard aLock( m_aLock );
      87                 :            : 
      88                 :            :     // reduce reference count
      89         [ #  # ]:          0 :     m_pConfigAccess->release();
      90         [ #  # ]:          0 : }
      91                 :            : 
      92                 :       7195 : void WindowContentFactoryManager::RetrieveTypeNameFromResourceURL( const rtl::OUString& aResourceURL, rtl::OUString& aType, rtl::OUString& aName )
      93                 :            : {
      94                 :       7195 :     const sal_Int32 RESOURCEURL_PREFIX_SIZE = 17;
      95                 :       7195 :     const char      RESOURCEURL_PREFIX[] = "private:resource/";
      96                 :            : 
      97   [ +  -  +  - ]:      14390 :     if (( aResourceURL.indexOf( RESOURCEURL_PREFIX ) == 0 ) &&
                 [ +  - ]
      98                 :       7195 :         ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE ))
      99                 :            :     {
     100                 :       7195 :         rtl::OUString aTmpStr( aResourceURL.copy( RESOURCEURL_PREFIX_SIZE ));
     101                 :       7195 :         sal_Int32 nToken = 0;
     102                 :       7195 :         sal_Int32 nPart  = 0;
     103         [ +  + ]:      14422 :         do
     104                 :            :         {
     105                 :      14422 :             ::rtl::OUString sToken = aTmpStr.getToken( 0, '/', nToken);
     106         [ +  - ]:      14422 :             if ( !sToken.isEmpty() )
     107                 :            :             {
     108         [ +  + ]:      14422 :                 if ( nPart == 0 )
     109                 :       7195 :                     aType = sToken;
     110         [ +  + ]:       7227 :                 else if ( nPart == 1 )
     111                 :       7227 :                     aName = sToken;
     112                 :            :                 else
     113                 :            :                     break;
     114                 :      14390 :                 nPart++;
     115         [ +  + ]:      14422 :             }
     116                 :            :         }
     117                 :       7195 :         while( nToken >=0 );
     118                 :            :     }
     119                 :       7195 : }
     120                 :            : 
     121                 :            : // XSingleComponentFactory
     122                 :          0 : uno::Reference< uno::XInterface > SAL_CALL WindowContentFactoryManager::createInstanceWithContext(
     123                 :            :     const uno::Reference< uno::XComponentContext >& /*xContext*/ )
     124                 :            : throw (uno::Exception, uno::RuntimeException)
     125                 :            : {
     126                 :          0 :     uno::Reference< uno::XInterface > xWindow;
     127                 :          0 :     return xWindow;
     128                 :            : }
     129                 :            : 
     130                 :          0 : uno::Reference< uno::XInterface > SAL_CALL WindowContentFactoryManager::createInstanceWithArgumentsAndContext(
     131                 :            :     const uno::Sequence< uno::Any >& Arguments, const uno::Reference< uno::XComponentContext >& Context )
     132                 :            : throw (uno::Exception, uno::RuntimeException)
     133                 :            : {
     134                 :          0 :     uno::Reference< uno::XInterface > xWindow;
     135                 :          0 :     uno::Reference< frame::XFrame >   xFrame;
     136                 :          0 :     ::rtl::OUString                   aResourceURL;
     137                 :            : 
     138         [ #  # ]:          0 :     for (sal_Int32 i=0; i < Arguments.getLength(); i++ )
     139                 :            :     {
     140                 :          0 :         beans::PropertyValue aPropValue;
     141 [ #  # ][ #  # ]:          0 :         if ( Arguments[i] >>= aPropValue )
     142                 :            :         {
     143         [ #  # ]:          0 :             if ( aPropValue.Name == "Frame" )
     144         [ #  # ]:          0 :                 aPropValue.Value >>= xFrame;
     145         [ #  # ]:          0 :             else if ( aPropValue.Name == "ResourceURL" )
     146                 :          0 :                 aPropValue.Value >>= aResourceURL;
     147                 :            :         }
     148                 :          0 :     }
     149                 :            : 
     150                 :          0 :     uno::Reference< frame::XModuleManager > xModuleManager;
     151                 :            :     // SAFE
     152                 :            :     {
     153         [ #  # ]:          0 :         ResetableGuard aLock( m_aLock );
     154 [ #  # ][ #  # ]:          0 :         xModuleManager = m_xModuleManager;
     155                 :            :     }
     156                 :            :     // UNSAFE
     157                 :            : 
     158                 :            :     // Determine the module identifier
     159                 :          0 :     ::rtl::OUString aType;
     160                 :          0 :     ::rtl::OUString aName;
     161                 :          0 :     ::rtl::OUString aModuleId;
     162                 :            :     try
     163                 :            :     {
     164 [ #  # ][ #  # ]:          0 :         if ( xFrame.is() && xModuleManager.is() )
                 [ #  # ]
     165 [ #  # ][ #  # ]:          0 :             aModuleId = xModuleManager->identify( uno::Reference< uno::XInterface >( xFrame, uno::UNO_QUERY ) );
         [ #  # ][ #  # ]
     166                 :            :     }
     167         [ #  # ]:          0 :     catch ( const frame::UnknownModuleException& )
     168                 :            :     {
     169                 :            :     }
     170                 :            : 
     171         [ #  # ]:          0 :     RetrieveTypeNameFromResourceURL( aResourceURL, aType, aName );
     172   [ #  #  #  #  :          0 :     if ( !aType.isEmpty() &&
           #  # ][ #  # ]
     173                 :          0 :          !aName.isEmpty() &&
     174                 :          0 :          !aModuleId.isEmpty() )
     175                 :            :     {
     176                 :          0 :         ::rtl::OUString                   aImplementationName;
     177         [ #  # ]:          0 :         uno::Reference< uno::XInterface > xHolder( static_cast<cppu::OWeakObject*>(this), uno::UNO_QUERY );
     178                 :            : 
     179                 :            :         // Detetmine the implementation name of the window content factory dependent on the
     180                 :            :         // module identifier, user interface element type and name
     181                 :            :         // SAFE
     182         [ #  # ]:          0 :         ResetableGuard aLock( m_aLock );
     183                 :            : 
     184         [ #  # ]:          0 :         if ( !m_bConfigRead )
     185                 :            :         {
     186                 :          0 :             m_bConfigRead = sal_True;
     187         [ #  # ]:          0 :             m_pConfigAccess->readConfigurationData();
     188                 :            :         }
     189                 :            : 
     190         [ #  # ]:          0 :         aImplementationName = m_pConfigAccess->getFactorySpecifierFromTypeNameModule( aType, aName, aModuleId );
     191         [ #  # ]:          0 :         if ( !aImplementationName.isEmpty() )
     192                 :            :         {
     193         [ #  # ]:          0 :             aLock.unlock();
     194                 :            :             // UNSAFE
     195                 :            : 
     196 [ #  # ][ #  # ]:          0 :             uno::Reference< lang::XMultiServiceFactory > xServiceManager( Context->getServiceManager(), uno::UNO_QUERY );
                 [ #  # ]
     197         [ #  # ]:          0 :             if ( xServiceManager.is() )
     198                 :            :             {
     199                 :            :                 uno::Reference< lang::XSingleComponentFactory > xFactory(
     200 [ #  # ][ #  # ]:          0 :                     xServiceManager->createInstance( aImplementationName ), uno::UNO_QUERY );
                 [ #  # ]
     201         [ #  # ]:          0 :                 if ( xFactory.is() )
     202                 :            :                 {
     203                 :            :                     // Be careful: We call external code. Therefore here we have to catch all exceptions
     204                 :            :                     try
     205                 :            :                     {
     206 [ #  # ][ #  # ]:          0 :                         xWindow = xFactory->createInstanceWithArgumentsAndContext( Arguments, Context );
         [ #  # ][ #  # ]
     207                 :            :                     }
     208         [ #  # ]:          0 :                     catch ( uno::Exception& )
     209                 :            :                     {
     210                 :            :                         DBG_UNHANDLED_EXCEPTION();
     211                 :            :                     }
     212                 :          0 :                 }
     213                 :          0 :             }
     214         [ #  # ]:          0 :         }
     215                 :            :     }
     216                 :            : 
     217                 :            :     // UNSAFE
     218         [ #  # ]:          0 :     if ( !xWindow.is())
     219                 :            :     {
     220                 :            :         // Fallback: Use internal factory code to create a toolkit dialog as a content window
     221 [ #  # ][ #  # ]:          0 :         xWindow = createInstanceWithContext(Context);
     222                 :            :     }
     223                 :            : 
     224                 :          0 :     return xWindow;
     225                 :            : }
     226                 :            : 
     227                 :            : } // namespace framework
     228                 :            : 
     229                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10