LCOV - code coverage report
Current view: top level - sfx2/source/appl - module.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 138 156 88.5 %
Date: 2012-08-25 Functions: 28 36 77.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 91 166 54.8 %

           Branch data     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 <stdio.h>
      21                 :            : #include <tools/rcid.h>
      22                 :            : 
      23                 :            : #include <cstdarg>
      24                 :            : #include <sfx2/module.hxx>
      25                 :            : #include <sfx2/app.hxx>
      26                 :            : #include "arrdecl.hxx"
      27                 :            : #include "sfx2/sfxresid.hxx"
      28                 :            : #include <sfx2/msgpool.hxx>
      29                 :            : #include <sfx2/tbxctrl.hxx>
      30                 :            : #include "sfx2/stbitem.hxx"
      31                 :            : #include <sfx2/mnuitem.hxx>
      32                 :            : #include <sfx2/childwin.hxx>
      33                 :            : #include <sfx2/mnumgr.hxx>
      34                 :            : #include <sfx2/docfac.hxx>
      35                 :            : #include <sfx2/objface.hxx>
      36                 :            : #include <sfx2/viewfrm.hxx>
      37                 :            : #include <svl/intitem.hxx>
      38                 :            : #include "sfx2/taskpane.hxx"
      39                 :            : #include <tools/diagnose_ex.h>
      40                 :            : #include <rtl/strbuf.hxx>
      41                 :            : #include <sal/log.hxx>
      42                 :            : 
      43                 :            : #define SfxModule
      44                 :            : #include "sfxslots.hxx"
      45                 :            : 
      46                 :            : static SfxModuleArr_Impl* pModules=0;
      47                 :            : 
      48                 :            : class SfxModule_Impl
      49                 :            : {
      50                 :            : public:
      51                 :            : 
      52                 :            :     SfxSlotPool*                pSlotPool;
      53                 :            :     SfxTbxCtrlFactArr_Impl*     pTbxCtrlFac;
      54                 :            :     SfxStbCtrlFactArr_Impl*     pStbCtrlFac;
      55                 :            :     SfxMenuCtrlFactArr_Impl*    pMenuCtrlFac;
      56                 :            :     SfxChildWinFactArr_Impl*    pFactArr;
      57                 :            :     ImageList*                  pImgListSmall;
      58                 :            :     ImageList*                  pImgListBig;
      59                 :            : 
      60                 :            :                                 SfxModule_Impl();
      61                 :            :                                 ~SfxModule_Impl();
      62                 :            :     ImageList*                  GetImageList( ResMgr* pResMgr, bool bBig );
      63                 :            : };
      64                 :            : 
      65                 :        159 : SfxModule_Impl::SfxModule_Impl()
      66                 :        159 :  : pSlotPool(0)
      67                 :            : {
      68                 :        159 : }
      69                 :            : 
      70                 :         78 : SfxModule_Impl::~SfxModule_Impl()
      71                 :            : {
      72         [ +  - ]:         78 :     delete pSlotPool;
      73         [ +  - ]:         78 :     delete pTbxCtrlFac;
      74         [ +  - ]:         78 :     delete pStbCtrlFac;
      75         [ +  + ]:         78 :     delete pMenuCtrlFac;
      76         [ +  - ]:         78 :     delete pFactArr;
      77         [ +  + ]:         78 :     delete pImgListSmall;
      78         [ -  + ]:         78 :     delete pImgListBig;
      79                 :         78 : }
      80                 :            : 
      81                 :         42 : ImageList* SfxModule_Impl::GetImageList( ResMgr* pResMgr, bool bBig )
      82                 :            : {
      83         [ -  + ]:         42 :     ImageList*& rpList = bBig ? pImgListBig : pImgListSmall;
      84         [ +  - ]:         42 :     if ( !rpList )
      85                 :            :     {
      86         [ -  + ]:         42 :         ResId aResId( bBig ? ( RID_DEFAULTIMAGELIST_LC ) : ( RID_DEFAULTIMAGELIST_SC ), *pResMgr );
      87                 :            : 
      88                 :         42 :         aResId.SetRT( RSC_IMAGELIST );
      89                 :            : 
      90                 :            :         DBG_ASSERT( pResMgr->IsAvailable(aResId), "No default ImageList!" );
      91                 :            : 
      92 [ +  - ][ +  - ]:         42 :         if ( pResMgr->IsAvailable(aResId) )
      93 [ +  - ][ +  - ]:         42 :             rpList = new ImageList( aResId );
      94                 :            :         else
      95 [ #  # ][ #  # ]:         42 :             rpList = new ImageList();
      96                 :            :     }
      97                 :            : 
      98                 :         42 :     return rpList; }
      99                 :            : 
     100 [ +  - ][ #  # ]:      42513 : TYPEINIT1(SfxModule, SfxShell);
     101                 :            : 
     102                 :            : //=========================================================================
     103                 :            : 
     104 [ +  + ][ +  - ]:        574 : SFX_IMPL_INTERFACE(SfxModule,SfxShell,SfxResId(0))
                 [ +  - ]
     105                 :            : {
     106                 :        233 : }
     107                 :            : 
     108                 :            : //====================================================================
     109                 :            : 
     110                 :      66874 : ResMgr* SfxModule::GetResMgr()
     111                 :            : {
     112                 :      66874 :     return pResMgr;
     113                 :            : }
     114                 :            : 
     115                 :            : //====================================================================
     116                 :            : 
     117                 :        159 : SfxModule::SfxModule( ResMgr* pMgrP, sal_Bool bDummyP,
     118                 :            :                       SfxObjectFactory* pFactoryP, ... )
     119                 :        159 :     : pResMgr( pMgrP ), bDummy( bDummyP ), pImpl(0L)
     120                 :            : {
     121         [ +  - ]:        159 :     Construct_Impl();
     122                 :            :     va_list pVarArgs;
     123                 :        159 :     va_start( pVarArgs, pFactoryP );
     124         [ +  + ]:        471 :     for ( SfxObjectFactory *pArg = pFactoryP; pArg;
     125                 :        312 :          pArg = va_arg( pVarArgs, SfxObjectFactory* ) )
     126         [ +  - ]:        312 :         pArg->SetModule_Impl( this );
     127                 :        159 :     va_end(pVarArgs);
     128                 :        159 : }
     129                 :            : 
     130                 :        159 : void SfxModule::Construct_Impl()
     131                 :            : {
     132         [ +  - ]:        159 :     if( !bDummy )
     133                 :            :     {
     134         [ +  - ]:        159 :         SfxApplication *pApp = SFX_APP();
     135         [ +  - ]:        159 :         SfxModuleArr_Impl& rArr = GetModules_Impl();
     136                 :        159 :         SfxModule* pPtr = (SfxModule*)this;
     137         [ +  - ]:        159 :         rArr.push_back( pPtr );
     138         [ +  - ]:        159 :         pImpl = new SfxModule_Impl;
     139 [ +  - ][ +  - ]:        159 :         pImpl->pSlotPool = new SfxSlotPool( &pApp->GetAppSlotPool_Impl(), pResMgr );
                 [ +  - ]
     140                 :            : 
     141                 :        159 :         pImpl->pTbxCtrlFac=0;
     142                 :        159 :         pImpl->pStbCtrlFac=0;
     143                 :        159 :         pImpl->pMenuCtrlFac=0;
     144                 :        159 :         pImpl->pFactArr=0;
     145                 :        159 :         pImpl->pImgListSmall=0;
     146                 :        159 :         pImpl->pImgListBig=0;
     147                 :            : 
     148                 :        159 :         SetPool( &pApp->GetPool() );
     149                 :            :     }
     150                 :        159 : }
     151                 :            : 
     152                 :            : //====================================================================
     153                 :            : 
     154                 :         78 : SfxModule::~SfxModule()
     155                 :            : {
     156         [ +  - ]:         78 :     if( !bDummy )
     157                 :            :     {
     158 [ +  - ][ +  - ]:         78 :         if ( SFX_APP()->Get_Impl() )
     159                 :            :         {
     160                 :            :             // The module will be destroyed before the Deinitialize,
     161                 :            :             // so remove from the array
     162         [ +  - ]:         78 :             SfxModuleArr_Impl& rArr = GetModules_Impl();
     163         [ +  - ]:         78 :             for( sal_uInt16 nPos = rArr.size(); nPos--; )
     164                 :            :             {
     165 [ +  - ][ +  - ]:         78 :                 if( rArr[ nPos ] == this )
     166                 :            :                 {
     167 [ +  - ][ +  - ]:         78 :                     rArr.erase( rArr.begin() + nPos );
     168                 :         78 :                     break;
     169                 :            :                 }
     170                 :            :             }
     171                 :            : 
     172 [ +  - ][ +  - ]:         78 :             delete pImpl;
     173                 :            :         }
     174                 :            : 
     175 [ +  - ][ +  - ]:         78 :         delete pResMgr;
     176                 :            :     }
     177         [ -  + ]:         78 : }
     178                 :            : 
     179                 :            : //-------------------------------------------------------------------------
     180                 :            : 
     181                 :     889381 : SfxSlotPool* SfxModule::GetSlotPool() const
     182                 :            : {
     183                 :     889381 :     return pImpl->pSlotPool;
     184                 :            : }
     185                 :            : 
     186                 :            : //-------------------------------------------------------------------------
     187                 :            : 
     188                 :       3247 : void SfxModule::RegisterChildWindow(SfxChildWinFactory *pFact)
     189                 :            : {
     190                 :            :     DBG_ASSERT( pImpl, "No real Module!" );
     191                 :            : 
     192         [ +  + ]:       3247 :     if (!pImpl->pFactArr)
     193         [ +  - ]:        159 :         pImpl->pFactArr = new SfxChildWinFactArr_Impl;
     194                 :            : 
     195         [ +  + ]:      38018 :     for (sal_uInt16 nFactory=0; nFactory<pImpl->pFactArr->size(); ++nFactory)
     196                 :            :     {
     197         [ -  + ]:      34771 :         if (pFact->nId ==  (*pImpl->pFactArr)[nFactory]->nId)
     198                 :            :         {
     199 [ #  # ][ #  # ]:          0 :             pImpl->pFactArr->erase( pImpl->pFactArr->begin() + nFactory );
     200                 :            :             SAL_WARN("sfx2.appl", "ChildWindow registered multiple times!");
     201                 :       3247 :             return;
     202                 :            :         }
     203                 :            :     }
     204                 :            : 
     205                 :       3247 :     pImpl->pFactArr->push_back( pFact );
     206                 :            : }
     207                 :            : 
     208                 :            : //-------------------------------------------------------------------------
     209                 :            : 
     210                 :       7879 : void SfxModule::RegisterToolBoxControl( SfxTbxCtrlFactory *pFact )
     211                 :            : {
     212         [ +  + ]:       7879 :     if (!pImpl->pTbxCtrlFac)
     213         [ +  - ]:        159 :         pImpl->pTbxCtrlFac = new SfxTbxCtrlFactArr_Impl;
     214                 :            : 
     215                 :            : #ifdef DBG_UTIL
     216                 :            :     for ( sal_uInt16 n=0; n<pImpl->pTbxCtrlFac->size(); n++ )
     217                 :            :     {
     218                 :            :         SfxTbxCtrlFactory *pF = (*pImpl->pTbxCtrlFac)[n];
     219                 :            :         if ( pF->nTypeId && pF->nTypeId == pFact->nTypeId &&
     220                 :            :             (pF->nSlotId == pFact->nSlotId || pF->nSlotId == 0) )
     221                 :            :         {
     222                 :            :             DBG_WARNING("TbxController-Registering is not clearly defined!");
     223                 :            :         }
     224                 :            :     }
     225                 :            : #endif
     226                 :            : 
     227                 :       7879 :     pImpl->pTbxCtrlFac->push_back( pFact );
     228                 :       7879 : }
     229                 :            : 
     230                 :            : //-------------------------------------------------------------------------
     231                 :            : 
     232                 :       1350 : void SfxModule::RegisterStatusBarControl( SfxStbCtrlFactory *pFact )
     233                 :            : {
     234         [ +  + ]:       1350 :     if (!pImpl->pStbCtrlFac)
     235         [ +  - ]:        159 :         pImpl->pStbCtrlFac = new SfxStbCtrlFactArr_Impl;
     236                 :            : 
     237                 :            : #ifdef DBG_UTIL
     238                 :            :     for ( sal_uInt16 n=0; n<pImpl->pStbCtrlFac->size(); n++ )
     239                 :            :     {
     240                 :            :         SfxStbCtrlFactory *pF = (*pImpl->pStbCtrlFac)[n];
     241                 :            :         if ( pF->nTypeId && pF->nTypeId == pFact->nTypeId &&
     242                 :            :             (pF->nSlotId == pFact->nSlotId || pF->nSlotId == 0) )
     243                 :            :         {
     244                 :            :             DBG_WARNING("TbxController-Registering is not clearly defined!");
     245                 :            :         }
     246                 :            :     }
     247                 :            : #endif
     248                 :            : 
     249                 :       1350 :     pImpl->pStbCtrlFac->push_back( pFact );
     250                 :       1350 : }
     251                 :            : 
     252                 :            : //-------------------------------------------------------------------------
     253                 :            : 
     254                 :        446 : void SfxModule::RegisterMenuControl( SfxMenuCtrlFactory *pFact )
     255                 :            : {
     256         [ +  + ]:        446 :     if (!pImpl->pMenuCtrlFac)
     257         [ +  - ]:        149 :         pImpl->pMenuCtrlFac = new SfxMenuCtrlFactArr_Impl;
     258                 :            : 
     259                 :            : #ifdef DBG_UTIL
     260                 :            :     for ( sal_uInt16 n=0; n<pImpl->pMenuCtrlFac->size(); n++ )
     261                 :            :     {
     262                 :            :         SfxMenuCtrlFactory *pF = (*pImpl->pMenuCtrlFac)[n];
     263                 :            :         if ( pF->nTypeId && pF->nTypeId == pFact->nTypeId &&
     264                 :            :             (pF->nSlotId == pFact->nSlotId || pF->nSlotId == 0) )
     265                 :            :         {
     266                 :            :             DBG_WARNING("MenuController-Registering is not clearly defined!");
     267                 :            :         }
     268                 :            :     }
     269                 :            : #endif
     270                 :            : 
     271                 :        446 :     pImpl->pMenuCtrlFac->push_back( pFact );
     272                 :        446 : }
     273                 :            : 
     274                 :            : //-------------------------------------------------------------------------
     275                 :            : 
     276                 :      68078 : SfxTbxCtrlFactArr_Impl*  SfxModule::GetTbxCtrlFactories_Impl() const
     277                 :            : {
     278                 :      68078 :     return pImpl->pTbxCtrlFac;
     279                 :            : }
     280                 :            : 
     281                 :            : //-------------------------------------------------------------------------
     282                 :            : 
     283                 :      11507 : SfxStbCtrlFactArr_Impl*  SfxModule::GetStbCtrlFactories_Impl() const
     284                 :            : {
     285                 :      11507 :     return pImpl->pStbCtrlFac;
     286                 :            : }
     287                 :            : 
     288                 :            : //-------------------------------------------------------------------------
     289                 :            : 
     290                 :          0 : SfxMenuCtrlFactArr_Impl* SfxModule::GetMenuCtrlFactories_Impl() const
     291                 :            : {
     292                 :          0 :     return pImpl->pMenuCtrlFac;
     293                 :            : }
     294                 :            : 
     295                 :            : //-------------------------------------------------------------------------
     296                 :            : 
     297                 :      30351 : SfxChildWinFactArr_Impl* SfxModule::GetChildWinFactories_Impl() const
     298                 :            : {
     299                 :      30351 :     return pImpl->pFactArr;
     300                 :            : }
     301                 :            : 
     302                 :         42 : ImageList* SfxModule::GetImageList_Impl( sal_Bool bBig )
     303                 :            : {
     304                 :         42 :     return pImpl->GetImageList( pResMgr, bBig );
     305                 :            : }
     306                 :            : 
     307                 :          0 : SfxTabPage*     SfxModule::CreateTabPage( sal_uInt16, Window*, const SfxItemSet& )
     308                 :            : {
     309                 :          0 :     return NULL;
     310                 :            : }
     311                 :            : 
     312                 :        237 : SfxModuleArr_Impl& SfxModule::GetModules_Impl()
     313                 :            : {
     314         [ +  + ]:        237 :     if( !pModules )
     315         [ +  - ]:        137 :         pModules = new SfxModuleArr_Impl;
     316                 :        237 :     return *pModules;
     317                 :            : };
     318                 :            : 
     319                 :        158 : void SfxModule::DestroyModules_Impl()
     320                 :            : {
     321         [ +  + ]:        158 :     if ( pModules )
     322                 :            :     {
     323                 :         62 :         SfxModuleArr_Impl& rModules = *pModules;
     324         [ +  + ]:        140 :         for( sal_uInt16 nPos = rModules.size(); nPos--; )
     325                 :            :         {
     326                 :         78 :             SfxModule* pMod = rModules[nPos];
     327         [ +  - ]:         78 :             delete pMod;
     328                 :            :         }
     329         [ +  - ]:         62 :         delete pModules, pModules = 0;
     330                 :            :     }
     331                 :        158 : }
     332                 :            : 
     333                 :          0 : void SfxModule::Invalidate( sal_uInt16 nId )
     334                 :            : {
     335         [ #  # ]:          0 :     for( SfxViewFrame* pFrame = SfxViewFrame::GetFirst(); pFrame; pFrame = SfxViewFrame::GetNext( *pFrame ) )
     336         [ #  # ]:          0 :         if ( pFrame->GetObjectShell()->GetModule() == this )
     337                 :          0 :             Invalidate_Impl( pFrame->GetBindings(), nId );
     338                 :          0 : }
     339                 :            : 
     340                 :       1312 : bool SfxModule::IsChildWindowAvailable( const sal_uInt16 i_nId, const SfxViewFrame* i_pViewFrame ) const
     341                 :            : {
     342         [ +  + ]:       1312 :     if ( i_nId != SID_TASKPANE )
     343                 :            :         // by default, assume it is
     344                 :       1256 :         return true;
     345                 :            : 
     346         [ -  + ]:         56 :     const SfxViewFrame* pViewFrame = i_pViewFrame ? i_pViewFrame : GetFrame();
     347         [ -  + ]:         56 :     ENSURE_OR_RETURN( pViewFrame, "SfxModule::IsChildWindowAvailable: no frame to ask for the module identifier!", false );
     348         [ +  - ]:       1312 :     return ::sfx2::ModuleTaskPane::ModuleHasToolPanels( pViewFrame->GetFrame().GetFrameInterface() );
     349                 :            : }
     350                 :            : 
     351                 :     420309 : SfxModule* SfxModule::GetActiveModule( SfxViewFrame* pFrame )
     352                 :            : {
     353         [ +  + ]:     420309 :     if ( !pFrame )
     354                 :      34958 :         pFrame = SfxViewFrame::Current();
     355                 :     420309 :     SfxObjectShell* pSh = 0;
     356         [ +  + ]:     420309 :     if( pFrame )
     357                 :     393104 :         pSh = pFrame->GetObjectShell();
     358         [ +  + ]:     420309 :     return pSh ? pSh->GetModule() : 0;
     359                 :            : }
     360                 :            : 
     361                 :       1375 : FieldUnit SfxModule::GetModuleFieldUnit( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > const & i_frame )
     362                 :            : {
     363         [ -  + ]:       1375 :     ENSURE_OR_RETURN( i_frame.is(), "SfxModule::GetModuleFieldUnit: invalid frame!", FUNIT_100TH_MM );
     364                 :            : 
     365                 :            :     // find SfxViewFrame for the given XFrame
     366                 :       1375 :     SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst();
     367         [ +  - ]:       1499 :     while ( pViewFrame != NULL )
     368                 :            :     {
     369 [ +  - ][ +  + ]:       1499 :         if ( pViewFrame->GetFrame().GetFrameInterface() == i_frame )
     370                 :       1375 :             break;
     371                 :        124 :         pViewFrame = SfxViewFrame::GetNext( *pViewFrame );
     372                 :            :     }
     373         [ -  + ]:       1375 :     ENSURE_OR_RETURN( pViewFrame != NULL, "SfxModule::GetModuleFieldUnit: unable to find an SfxViewFrame for the given XFrame", FUNIT_100TH_MM );
     374                 :            : 
     375                 :            :     // find the module
     376                 :       1375 :     SfxModule const * pModule = GetActiveModule( pViewFrame );
     377         [ -  + ]:       1375 :     ENSURE_OR_RETURN( pModule != NULL, "SfxModule::GetModuleFieldUnit: no SfxModule for the given frame!", FUNIT_100TH_MM );
     378         [ +  - ]:       1375 :         if ( pModule )
     379                 :       1375 :                 return pModule->GetFieldUnit();
     380                 :       1375 :         return FUNIT_INCH;
     381                 :            : }
     382                 :            : 
     383                 :          0 : FieldUnit SfxModule::GetCurrentFieldUnit()
     384                 :            : {
     385                 :          0 :     FieldUnit eUnit = FUNIT_INCH;
     386                 :          0 :     SfxModule* pModule = GetActiveModule();
     387         [ #  # ]:          0 :     if ( pModule )
     388                 :            :     {
     389                 :          0 :         const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC );
     390         [ #  # ]:          0 :         if ( pItem )
     391                 :          0 :             eUnit = (FieldUnit)( (SfxUInt16Item*)pItem )->GetValue();
     392                 :            :     }
     393                 :            :     else
     394                 :            :         SAL_WARN( "sfx2.appl", "GetModuleFieldUnit(): no module found" );
     395                 :          0 :     return eUnit;
     396                 :            : }
     397                 :            : 
     398                 :       1375 : FieldUnit SfxModule::GetFieldUnit() const
     399                 :            : {
     400                 :       1375 :     FieldUnit eUnit = FUNIT_INCH;
     401                 :       1375 :     const SfxPoolItem* pItem = GetItem( SID_ATTR_METRIC );
     402         [ +  - ]:       1375 :     if ( pItem )
     403                 :       1375 :         eUnit = (FieldUnit)( (SfxUInt16Item*)pItem )->GetValue();
     404                 :       1375 :     return eUnit;
     405                 :            : }
     406                 :            : 
     407                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10