LCOV - code coverage report
Current view: top level - svtools/source/misc - svtaccessiblefactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 30 71 42.3 %
Date: 2012-08-25 Functions: 6 26 23.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 22 50 44.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 "svtaccessiblefactory.hxx"
      30                 :            : #include <osl/module.h>
      31                 :            : 
      32                 :            : // #define UNLOAD_ON_LAST_CLIENT_DYING
      33                 :            :     // this is not recommended currently. If enabled, the implementation will log
      34                 :            :     // the number of active clients, and unload the acc library when the last client
      35                 :            :     // goes away.
      36                 :            :     // Sounds like a good idea, unfortunately, there's no guarantee that all objects
      37                 :            :     // implemented in this library are already dead.
      38                 :            :     // Iow, just because an object implementing an XAccessible (implemented in this lib
      39                 :            :     // here) died, it's not said that everybody released all references to the
      40                 :            :     // XAccessibleContext used by this component, and implemented in the acc lib.
      41                 :            :     // So we cannot really unload the lib.
      42                 :            :     //
      43                 :            :     // Alternatively, if the lib would us own "usage counting", i.e. every component
      44                 :            :     // implemented therein would affect a static ref count, the acc lib could care
      45                 :            :     // for unloading itself.
      46                 :            : 
      47                 :            : //........................................................................
      48                 :            : namespace svt
      49                 :            : {
      50                 :            : //........................................................................
      51                 :            : 
      52                 :            :     using namespace ::com::sun::star::uno;
      53                 :            :     using namespace ::com::sun::star::awt;
      54                 :            :     using namespace ::com::sun::star::accessibility;
      55                 :            : 
      56                 :            :     namespace
      57                 :            :     {
      58                 :            : #ifdef UNLOAD_ON_LAST_CLIENT_DYING
      59                 :            :         static oslInterlockedCount                      s_nAccessibleFactoryAccesss = 0;
      60                 :            : #endif // UNLOAD_ON_LAST_CLIENT_DYING
      61                 :            :         static oslModule                                s_hAccessibleImplementationModule = NULL;
      62                 :            :         static GetSvtAccessibilityComponentFactory      s_pAccessibleFactoryFunc = NULL;
      63                 :        281 :         static ::rtl::Reference< IAccessibleFactory >   s_pFactory;
      64                 :            : 
      65                 :            :         //====================================================================
      66                 :            :         //= AccessibleDummyFactory
      67                 :            :         //====================================================================
      68                 :            :         class AccessibleDummyFactory : public IAccessibleFactory
      69                 :            :         {
      70                 :            :         public:
      71                 :            :             AccessibleDummyFactory();
      72                 :            : 
      73                 :            :         protected:
      74                 :            :             virtual ~AccessibleDummyFactory();
      75                 :            : 
      76                 :            :         private:
      77                 :            :             AccessibleDummyFactory( const AccessibleDummyFactory& );            // never implemented
      78                 :            :             AccessibleDummyFactory& operator=( const AccessibleDummyFactory& ); // never implemented
      79                 :            : 
      80                 :            :             oslInterlockedCount m_refCount;
      81                 :            : 
      82                 :            :         public:
      83                 :            :             // IReference
      84                 :            :             virtual oslInterlockedCount SAL_CALL acquire();
      85                 :            :             virtual oslInterlockedCount SAL_CALL release();
      86                 :            : 
      87                 :            :             // IAccessibleFactory
      88                 :            :             virtual IAccessibleTabListBox*
      89                 :          0 :                 createAccessibleTabListBox(
      90                 :            :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*rxParent*/,
      91                 :            :                     SvHeaderTabListBox& /*rBox*/
      92                 :            :                 ) const
      93                 :            :             {
      94                 :          0 :                 return NULL;
      95                 :            :             }
      96                 :            : 
      97                 :            :             virtual IAccessibleBrowseBox*
      98                 :          0 :                 createAccessibleBrowseBox(
      99                 :            :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*_rxParent*/,
     100                 :            :                     IAccessibleTableProvider& /*_rBrowseBox*/
     101                 :            :                 ) const
     102                 :            :             {
     103                 :          0 :                 return NULL;
     104                 :            :             }
     105                 :            : 
     106                 :            :             virtual table::IAccessibleTableControl*
     107                 :          0 :                 createAccessibleTableControl(
     108                 :            :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*_rxParent*/,
     109                 :            :                     table::IAccessibleTable& /*_rTable*/
     110                 :            :                 ) const
     111                 :            :             {
     112                 :          0 :                 return NULL;
     113                 :            :             }
     114                 :            : 
     115                 :            :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
     116                 :          0 :                 createAccessibleIconChoiceCtrl(
     117                 :            :                     SvtIconChoiceCtrl& /*_rIconCtrl*/,
     118                 :            :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*_xParent*/
     119                 :            :                 ) const
     120                 :            :             {
     121                 :          0 :                 return NULL;
     122                 :            :             }
     123                 :            : 
     124                 :            :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
     125                 :          0 :                 createAccessibleTabBar(
     126                 :            :                     TabBar& /*_rTabBar*/
     127                 :            :                 ) const
     128                 :            :             {
     129                 :          0 :                 return NULL;
     130                 :            :             }
     131                 :            : 
     132                 :            :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
     133                 :          0 :                 createAccessibleTextWindowContext(
     134                 :            :                     VCLXWindow* /*pVclXWindow*/, TextEngine& /*rEngine*/, TextView& /*rView*/, bool /*bCompoundControlChild*/
     135                 :            :                 ) const
     136                 :            :             {
     137                 :          0 :                 return NULL;
     138                 :            :             }
     139                 :            : 
     140                 :            :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
     141                 :          0 :                 createAccessibleTreeListBox(
     142                 :            :                     SvTreeListBox& /*_rListBox*/,
     143                 :            :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*_xParent*/
     144                 :            :                 ) const
     145                 :            :             {
     146                 :          0 :                 return NULL;
     147                 :            :             }
     148                 :            : 
     149                 :            :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
     150                 :          0 :                 createAccessibleBrowseBoxHeaderBar(
     151                 :            :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*rxParent*/,
     152                 :            :                     IAccessibleTableProvider& /*_rOwningTable*/,
     153                 :            :                     AccessibleBrowseBoxObjType /*_eObjType*/
     154                 :            :                 ) const
     155                 :            :             {
     156                 :          0 :                 return NULL;
     157                 :            :             }
     158                 :            : 
     159                 :            :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
     160                 :          0 :                 createAccessibleBrowseBoxTableCell(
     161                 :            :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*_rxParent*/,
     162                 :            :                     IAccessibleTableProvider& /*_rBrowseBox*/,
     163                 :            :                     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& /*_xFocusWindow*/,
     164                 :            :                     sal_Int32 /*_nRowId*/,
     165                 :            :                     sal_uInt16 /*_nColId*/,
     166                 :            :                     sal_Int32 /*_nOffset*/
     167                 :            :                 ) const
     168                 :            :             {
     169                 :          0 :                 return NULL;
     170                 :            :             }
     171                 :            : 
     172                 :            :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
     173                 :          0 :                 createAccessibleBrowseBoxHeaderCell(
     174                 :            :                     sal_Int32 /*_nColumnRowId*/,
     175                 :            :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*rxParent*/,
     176                 :            :                     IAccessibleTableProvider& /*_rBrowseBox*/,
     177                 :            :                     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& /*_xFocusWindow*/,
     178                 :            :                     AccessibleBrowseBoxObjType  /*_eObjType*/
     179                 :            :                 ) const
     180                 :            :             {
     181                 :          0 :                 return NULL;
     182                 :            :             }
     183                 :            : 
     184                 :            :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
     185                 :          0 :                 createAccessibleCheckBoxCell(
     186                 :            :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*_rxParent*/,
     187                 :            :                     IAccessibleTableProvider& /*_rBrowseBox*/,
     188                 :            :                     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& /*_xFocusWindow*/,
     189                 :            :                     sal_Int32 /*_nRowPos*/,
     190                 :            :                     sal_uInt16 /*_nColPos*/,
     191                 :            :                     const TriState& /*_eState*/,
     192                 :            :                     sal_Bool /*_bEnabled*/,
     193                 :            :                     sal_Bool /*_bIsTriState*/
     194                 :            :                 ) const
     195                 :            :             {
     196                 :          0 :                 return NULL;
     197                 :            :             }
     198                 :            : 
     199                 :            :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
     200                 :          0 :                 createEditBrowseBoxTableCellAccess(
     201                 :            :                     const ::com::sun::star::uno::Reference< com::sun::star::accessibility::XAccessible >& /*_rxParent*/,
     202                 :            :                     const ::com::sun::star::uno::Reference< com::sun::star::accessibility::XAccessible >& /*_rxControlAccessible*/,
     203                 :            :                     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& /*_rxFocusWindow*/,
     204                 :            :                     IAccessibleTableProvider& /*_rBrowseBox*/,
     205                 :            :                     sal_Int32 /*_nRowPos*/,
     206                 :            :                     sal_uInt16 /*_nColPos*/
     207                 :            :                 ) const
     208                 :            :             {
     209                 :          0 :                 return NULL;
     210                 :            :             }
     211                 :            : 
     212                 :            :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
     213                 :          0 :                 createAccessibleToolPanelDeck(
     214                 :            :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*i_rAccessibleParent*/,
     215                 :            :                     ::svt::ToolPanelDeck& /*i_rPanelDeck*/
     216                 :            :                 )
     217                 :            :             {
     218                 :          0 :                 return NULL;
     219                 :            :             }
     220                 :            :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
     221                 :          0 :                 createAccessibleToolPanelTabBar(
     222                 :            :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*i_rAccessibleParent*/,
     223                 :            :                     ::svt::IToolPanelDeck& /*i_rPanelDeck*/,
     224                 :            :                     ::svt::PanelTabBar& /*i_rTabBar*/
     225                 :            :                 )
     226                 :            :             {
     227                 :          0 :                 return NULL;
     228                 :            :             }
     229                 :            :         };
     230                 :            : 
     231                 :            :         //----------------------------------------------------------------
     232                 :          0 :         AccessibleDummyFactory::AccessibleDummyFactory()
     233                 :            :         {
     234                 :          0 :         }
     235                 :            : 
     236                 :            :         //----------------------------------------------------------------
     237                 :          0 :         AccessibleDummyFactory::~AccessibleDummyFactory()
     238                 :            :         {
     239         [ #  # ]:          0 :         }
     240                 :            : 
     241                 :            :         //----------------------------------------------------------------
     242                 :          0 :         oslInterlockedCount SAL_CALL AccessibleDummyFactory::acquire()
     243                 :            :         {
     244                 :          0 :             return osl_incrementInterlockedCount( &m_refCount );
     245                 :            :         }
     246                 :            : 
     247                 :            :         //----------------------------------------------------------------
     248                 :          0 :         oslInterlockedCount SAL_CALL AccessibleDummyFactory::release()
     249                 :            :         {
     250         [ #  # ]:          0 :             if ( 0 == osl_decrementInterlockedCount( &m_refCount ) )
     251                 :            :             {
     252         [ #  # ]:          0 :                 delete this;
     253                 :          0 :                 return 0;
     254                 :            :             }
     255                 :          0 :             return m_refCount;
     256                 :            :         }
     257                 :            :     }
     258                 :            : 
     259                 :            :     //====================================================================
     260                 :            :     //= AccessibleFactoryAccess
     261                 :            :     //====================================================================
     262                 :            :     //--------------------------------------------------------------------
     263                 :        651 :     AccessibleFactoryAccess::AccessibleFactoryAccess()
     264                 :        651 :         :m_bInitialized( false )
     265                 :            :     {
     266                 :        651 :     }
     267                 :            : 
     268                 :            :     //--------------------------------------------------------------------
     269                 :          0 :     extern "C" { static void SAL_CALL thisModule() {} }
     270                 :            : 
     271                 :          6 :     void AccessibleFactoryAccess::ensureInitialized()
     272                 :            :     {
     273         [ +  - ]:          6 :         if ( m_bInitialized )
     274                 :          6 :             return;
     275                 :            : 
     276 [ +  - ][ +  - ]:          6 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     277                 :            : 
     278                 :            : #ifdef UNLOAD_ON_LAST_CLIENT_DYING
     279                 :            :         if ( 1 == osl_incrementInterlockedCount( &s_nAccessibleFactoryAccesss ) )
     280                 :            :         {   // the first client
     281                 :            : #endif // UNLOAD_ON_LAST_CLIENT_DYING
     282                 :            :             // load the library implementing the factory
     283         [ +  + ]:          6 :             if ( !s_pFactory.get() )
     284                 :            :             {
     285                 :          2 :                 const ::rtl::OUString sModuleName( SVLIBRARY( "acc" ));
     286         [ +  - ]:          2 :                 s_hAccessibleImplementationModule = osl_loadModuleRelative( &thisModule, sModuleName.pData, 0 );
     287         [ +  - ]:          2 :                 if ( s_hAccessibleImplementationModule != NULL )
     288                 :            :                 {
     289                 :          2 :                     const ::rtl::OUString sFactoryCreationFunc( "getSvtAccessibilityComponentFactory" );
     290                 :            :                     s_pAccessibleFactoryFunc = (GetSvtAccessibilityComponentFactory)
     291         [ +  - ]:          2 :                         osl_getFunctionSymbol( s_hAccessibleImplementationModule, sFactoryCreationFunc.pData );
     292                 :            : 
     293                 :            :                 }
     294                 :            :                 OSL_ENSURE( s_pAccessibleFactoryFunc, "ac_registerClient: could not load the library, or not retrieve the needed symbol!" );
     295                 :            : 
     296                 :            :                 // get a factory instance
     297         [ +  - ]:          2 :                 if ( s_pAccessibleFactoryFunc )
     298                 :            :                 {
     299         [ +  - ]:          2 :                     IAccessibleFactory* pFactory = static_cast< IAccessibleFactory* >( (*s_pAccessibleFactoryFunc)() );
     300         [ +  - ]:          2 :                     if ( pFactory )
     301                 :            :                     {
     302         [ +  - ]:          2 :                         s_pFactory = pFactory;
     303         [ +  - ]:          2 :                         pFactory->release();
     304                 :            :                     }
     305                 :          2 :                 }
     306                 :            :             }
     307                 :            : 
     308         [ -  + ]:          6 :             if ( !s_pFactory.get() )
     309                 :            :                 // the attempt to load the lib, or to create the factory, failed
     310                 :            :                 // -> fall back to a dummy factory
     311 [ #  # ][ #  # ]:          0 :                 s_pFactory = new AccessibleDummyFactory;
     312                 :            : #ifdef UNLOAD_ON_LAST_CLIENT_DYING
     313                 :            :         }
     314                 :            : #endif
     315                 :            : 
     316         [ +  - ]:          6 :         m_bInitialized = true;
     317                 :            :     }
     318                 :            : 
     319                 :            :     //--------------------------------------------------------------------
     320                 :        645 :     AccessibleFactoryAccess::~AccessibleFactoryAccess()
     321                 :            :     {
     322         [ +  + ]:        645 :         if ( m_bInitialized )
     323                 :            :         {
     324 [ +  - ][ +  - ]:          6 :             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
                 [ +  - ]
     325                 :            : 
     326                 :            : #ifdef UNLOAD_ON_LAST_CLIENT_DYING
     327                 :            :             if( 0 == osl_decrementInterlockedCount( &s_nAccessibleFactoryAccesss ) )
     328                 :            :             {
     329                 :            :                 s_pFactory = NULL;
     330                 :            :                 s_pAccessibleFactoryFunc = NULL;
     331                 :            :                 if ( s_hAccessibleImplementationModule )
     332                 :            :                 {
     333                 :            :                     osl_unloadModule( s_hAccessibleImplementationModule );
     334                 :            :                     s_hAccessibleImplementationModule = NULL;
     335                 :            :                 }
     336                 :            :             }
     337                 :            : #endif // UNLOAD_ON_LAST_CLIENT_DYING
     338                 :            :         }
     339                 :        645 :     }
     340                 :            : 
     341                 :            :     //--------------------------------------------------------------------
     342                 :          6 :     IAccessibleFactory& AccessibleFactoryAccess::getFactory()
     343                 :            :     {
     344                 :          6 :         ensureInitialized();
     345                 :            :         DBG_ASSERT( s_pFactory.is(), "AccessibleFactoryAccess::getFactory: at least a dummy factory should have been created!" );
     346                 :          6 :         return *s_pFactory;
     347                 :            :     }
     348                 :            : 
     349                 :            : //........................................................................
     350 [ +  - ][ +  - ]:        843 : }   // namespace svt
     351                 :            : //........................................................................
     352                 :            : 
     353                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10