LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/appl - module.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 115 156 73.7 %
Date: 2012-12-17 Functions: 26 36 72.2 %
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 <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          70 : SfxModule_Impl::SfxModule_Impl()
      66          70 :  : pSlotPool(0)
      67             : {
      68          70 : }
      69             : 
      70           2 : SfxModule_Impl::~SfxModule_Impl()
      71             : {
      72           2 :     delete pSlotPool;
      73           2 :     delete pTbxCtrlFac;
      74           2 :     delete pStbCtrlFac;
      75           2 :     delete pMenuCtrlFac;
      76           2 :     delete pFactArr;
      77           2 :     delete pImgListSmall;
      78           2 :     delete pImgListBig;
      79           2 : }
      80             : 
      81          24 : ImageList* SfxModule_Impl::GetImageList( ResMgr* pResMgr, bool bBig )
      82             : {
      83          24 :     ImageList*& rpList = bBig ? pImgListBig : pImgListSmall;
      84          24 :     if ( !rpList )
      85             :     {
      86          24 :         ResId aResId( bBig ? ( RID_DEFAULTIMAGELIST_LC ) : ( RID_DEFAULTIMAGELIST_SC ), *pResMgr );
      87             : 
      88          24 :         aResId.SetRT( RSC_IMAGELIST );
      89             : 
      90             :         DBG_ASSERT( pResMgr->IsAvailable(aResId), "No default ImageList!" );
      91             : 
      92          24 :         if ( pResMgr->IsAvailable(aResId) )
      93          24 :             rpList = new ImageList( aResId );
      94             :         else
      95           0 :             rpList = new ImageList();
      96             :     }
      97             : 
      98          24 :     return rpList; }
      99             : 
     100       11878 : TYPEINIT1(SfxModule, SfxShell);
     101             : 
     102             : //=========================================================================
     103             : 
     104         252 : SFX_IMPL_INTERFACE(SfxModule,SfxShell,SfxResId(0))
     105             : {
     106          72 : }
     107             : 
     108             : //====================================================================
     109             : 
     110       28174 : ResMgr* SfxModule::GetResMgr()
     111             : {
     112       28174 :     return pResMgr;
     113             : }
     114             : 
     115             : //====================================================================
     116             : 
     117          70 : SfxModule::SfxModule( ResMgr* pMgrP, sal_Bool bDummyP,
     118             :                       SfxObjectFactory* pFactoryP, ... )
     119          70 :     : pResMgr( pMgrP ), bDummy( bDummyP ), pImpl(0L)
     120             : {
     121          70 :     Construct_Impl();
     122             :     va_list pVarArgs;
     123          70 :     va_start( pVarArgs, pFactoryP );
     124         182 :     for ( SfxObjectFactory *pArg = pFactoryP; pArg;
     125         112 :          pArg = va_arg( pVarArgs, SfxObjectFactory* ) )
     126         112 :         pArg->SetModule_Impl( this );
     127          70 :     va_end(pVarArgs);
     128          70 : }
     129             : 
     130          70 : void SfxModule::Construct_Impl()
     131             : {
     132          70 :     if( !bDummy )
     133             :     {
     134          70 :         SfxApplication *pApp = SFX_APP();
     135          70 :         SfxModuleArr_Impl& rArr = GetModules_Impl();
     136          70 :         SfxModule* pPtr = (SfxModule*)this;
     137          70 :         rArr.push_back( pPtr );
     138          70 :         pImpl = new SfxModule_Impl;
     139          70 :         pImpl->pSlotPool = new SfxSlotPool( &pApp->GetAppSlotPool_Impl(), pResMgr );
     140             : 
     141          70 :         pImpl->pTbxCtrlFac=0;
     142          70 :         pImpl->pStbCtrlFac=0;
     143          70 :         pImpl->pMenuCtrlFac=0;
     144          70 :         pImpl->pFactArr=0;
     145          70 :         pImpl->pImgListSmall=0;
     146          70 :         pImpl->pImgListBig=0;
     147             : 
     148          70 :         SetPool( &pApp->GetPool() );
     149             :     }
     150          70 : }
     151             : 
     152             : //====================================================================
     153             : 
     154           4 : SfxModule::~SfxModule()
     155             : {
     156           2 :     if( !bDummy )
     157             :     {
     158           2 :         if ( SFX_APP()->Get_Impl() )
     159             :         {
     160             :             // The module will be destroyed before the Deinitialize,
     161             :             // so remove from the array
     162           2 :             SfxModuleArr_Impl& rArr = GetModules_Impl();
     163           4 :             for( sal_uInt16 nPos = rArr.size(); nPos--; )
     164             :             {
     165           2 :                 if( rArr[ nPos ] == this )
     166             :                 {
     167           2 :                     rArr.erase( rArr.begin() + nPos );
     168           2 :                     break;
     169             :                 }
     170             :             }
     171             : 
     172           2 :             delete pImpl;
     173             :         }
     174             : 
     175           2 :         delete pResMgr;
     176             :     }
     177           2 : }
     178             : 
     179             : //-------------------------------------------------------------------------
     180             : 
     181       30556 : SfxSlotPool* SfxModule::GetSlotPool() const
     182             : {
     183       30556 :     return pImpl->pSlotPool;
     184             : }
     185             : 
     186             : //-------------------------------------------------------------------------
     187             : 
     188        1534 : void SfxModule::RegisterChildWindow(SfxChildWinFactory *pFact)
     189             : {
     190             :     DBG_ASSERT( pImpl, "No real Module!" );
     191             : 
     192        1534 :     if (!pImpl->pFactArr)
     193          70 :         pImpl->pFactArr = new SfxChildWinFactArr_Impl;
     194             : 
     195       19666 :     for (sal_uInt16 nFactory=0; nFactory<pImpl->pFactArr->size(); ++nFactory)
     196             :     {
     197       18132 :         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        1534 :             return;
     202             :         }
     203             :     }
     204             : 
     205        1534 :     pImpl->pFactArr->push_back( pFact );
     206             : }
     207             : 
     208             : //-------------------------------------------------------------------------
     209             : 
     210        3262 : void SfxModule::RegisterToolBoxControl( SfxTbxCtrlFactory *pFact )
     211             : {
     212        3262 :     if (!pImpl->pTbxCtrlFac)
     213          70 :         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        3262 :     pImpl->pTbxCtrlFac->push_back( pFact );
     228        3262 : }
     229             : 
     230             : //-------------------------------------------------------------------------
     231             : 
     232         562 : void SfxModule::RegisterStatusBarControl( SfxStbCtrlFactory *pFact )
     233             : {
     234         562 :     if (!pImpl->pStbCtrlFac)
     235          70 :         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         562 :     pImpl->pStbCtrlFac->push_back( pFact );
     250         562 : }
     251             : 
     252             : //-------------------------------------------------------------------------
     253             : 
     254         170 : void SfxModule::RegisterMenuControl( SfxMenuCtrlFactory *pFact )
     255             : {
     256         170 :     if (!pImpl->pMenuCtrlFac)
     257          64 :         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         170 :     pImpl->pMenuCtrlFac->push_back( pFact );
     272         170 : }
     273             : 
     274             : //-------------------------------------------------------------------------
     275             : 
     276         116 : SfxTbxCtrlFactArr_Impl*  SfxModule::GetTbxCtrlFactories_Impl() const
     277             : {
     278         116 :     return pImpl->pTbxCtrlFac;
     279             : }
     280             : 
     281             : //-------------------------------------------------------------------------
     282             : 
     283          22 : SfxStbCtrlFactArr_Impl*  SfxModule::GetStbCtrlFactories_Impl() const
     284             : {
     285          22 :     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        9036 : SfxChildWinFactArr_Impl* SfxModule::GetChildWinFactories_Impl() const
     298             : {
     299        9036 :     return pImpl->pFactArr;
     300             : }
     301             : 
     302          24 : ImageList* SfxModule::GetImageList_Impl( sal_Bool bBig )
     303             : {
     304          24 :     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          72 : SfxModuleArr_Impl& SfxModule::GetModules_Impl()
     313             : {
     314          72 :     if( !pModules )
     315          66 :         pModules = new SfxModuleArr_Impl;
     316          72 :     return *pModules;
     317             : };
     318             : 
     319           8 : void SfxModule::DestroyModules_Impl()
     320             : {
     321           8 :     if ( pModules )
     322             :     {
     323           2 :         SfxModuleArr_Impl& rModules = *pModules;
     324           6 :         for( sal_uInt16 nPos = rModules.size(); nPos--; )
     325             :         {
     326           2 :             SfxModule* pMod = rModules[nPos];
     327           2 :             delete pMod;
     328             :         }
     329           2 :         delete pModules, pModules = 0;
     330             :     }
     331           8 : }
     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        1384 : bool SfxModule::IsChildWindowAvailable( const sal_uInt16 i_nId, const SfxViewFrame* i_pViewFrame ) const
     341             : {
     342        1384 :     if ( i_nId != SID_TASKPANE )
     343             :         // by default, assume it is
     344        1384 :         return true;
     345             : 
     346           0 :     const SfxViewFrame* pViewFrame = i_pViewFrame ? i_pViewFrame : GetFrame();
     347           0 :     ENSURE_OR_RETURN( pViewFrame, "SfxModule::IsChildWindowAvailable: no frame to ask for the module identifier!", false );
     348           0 :     return ::sfx2::ModuleTaskPane::ModuleHasToolPanels( pViewFrame->GetFrame().GetFrameInterface() );
     349             : }
     350             : 
     351       28650 : SfxModule* SfxModule::GetActiveModule( SfxViewFrame* pFrame )
     352             : {
     353       28650 :     if ( !pFrame )
     354       13130 :         pFrame = SfxViewFrame::Current();
     355       28650 :     SfxObjectShell* pSh = 0;
     356       28650 :     if( pFrame )
     357       23861 :         pSh = pFrame->GetObjectShell();
     358       28650 :     return pSh ? pSh->GetModule() : 0;
     359             : }
     360             : 
     361           0 : FieldUnit SfxModule::GetModuleFieldUnit( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > const & i_frame )
     362             : {
     363           0 :     ENSURE_OR_RETURN( i_frame.is(), "SfxModule::GetModuleFieldUnit: invalid frame!", FUNIT_100TH_MM );
     364             : 
     365             :     // find SfxViewFrame for the given XFrame
     366           0 :     SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst();
     367           0 :     while ( pViewFrame != NULL )
     368             :     {
     369           0 :         if ( pViewFrame->GetFrame().GetFrameInterface() == i_frame )
     370           0 :             break;
     371           0 :         pViewFrame = SfxViewFrame::GetNext( *pViewFrame );
     372             :     }
     373           0 :     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           0 :     SfxModule const * pModule = GetActiveModule( pViewFrame );
     377           0 :     ENSURE_OR_RETURN( pModule != NULL, "SfxModule::GetModuleFieldUnit: no SfxModule for the given frame!", FUNIT_100TH_MM );
     378           0 :         if ( pModule )
     379           0 :                 return pModule->GetFieldUnit();
     380           0 :         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           0 : FieldUnit SfxModule::GetFieldUnit() const
     399             : {
     400           0 :     FieldUnit eUnit = FUNIT_INCH;
     401           0 :     const SfxPoolItem* pItem = GetItem( SID_ATTR_METRIC );
     402           0 :     if ( pItem )
     403           0 :         eUnit = (FieldUnit)( (SfxUInt16Item*)pItem )->GetValue();
     404           0 :     return eUnit;
     405             : }
     406             : 
     407             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10