LCOV - code coverage report
Current view: top level - sfx2/source/appl - module.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 154 0.0 %
Date: 2014-04-14 Functions: 0 36 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <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           0 : SfxModule_Impl::SfxModule_Impl()
      66           0 :  : pSlotPool(0), pTbxCtrlFac(0), pStbCtrlFac(0), pMenuCtrlFac(0), pFactArr(0), pImgListSmall(0), pImgListBig(0)
      67             : {
      68           0 : }
      69             : 
      70           0 : SfxModule_Impl::~SfxModule_Impl()
      71             : {
      72           0 :     delete pSlotPool;
      73           0 :     delete pTbxCtrlFac;
      74           0 :     delete pStbCtrlFac;
      75           0 :     delete pMenuCtrlFac;
      76           0 :     delete pFactArr;
      77           0 :     delete pImgListSmall;
      78           0 :     delete pImgListBig;
      79           0 : }
      80             : 
      81           0 : ImageList* SfxModule_Impl::GetImageList( ResMgr* pResMgr, bool bBig )
      82             : {
      83           0 :     ImageList*& rpList = bBig ? pImgListBig : pImgListSmall;
      84           0 :     if ( !rpList )
      85             :     {
      86           0 :         ResId aResId( bBig ? ( RID_DEFAULTIMAGELIST_LC ) : ( RID_DEFAULTIMAGELIST_SC ), *pResMgr );
      87             : 
      88           0 :         aResId.SetRT( RSC_IMAGELIST );
      89             : 
      90             :         DBG_ASSERT( pResMgr->IsAvailable(aResId), "No default ImageList!" );
      91             : 
      92           0 :         if ( pResMgr->IsAvailable(aResId) )
      93           0 :             rpList = new ImageList( aResId );
      94             :         else
      95           0 :             rpList = new ImageList();
      96             :     }
      97             : 
      98           0 :     return rpList; }
      99             : 
     100           0 : TYPEINIT1(SfxModule, SfxShell);
     101             : 
     102             : 
     103             : 
     104           0 : SFX_IMPL_INTERFACE(SfxModule,SfxShell,SfxResId(0))
     105             : {
     106           0 : }
     107             : 
     108             : 
     109             : 
     110           0 : ResMgr* SfxModule::GetResMgr()
     111             : {
     112           0 :     return pResMgr;
     113             : }
     114             : 
     115             : 
     116             : 
     117           0 : SfxModule::SfxModule( ResMgr* pMgrP, bool bDummyP,
     118             :                       SfxObjectFactory* pFactoryP, ... )
     119           0 :     : pResMgr( pMgrP ), bDummy( bDummyP ), pImpl(0L)
     120             : {
     121           0 :     Construct_Impl();
     122             :     va_list pVarArgs;
     123           0 :     va_start( pVarArgs, pFactoryP );
     124           0 :     for ( SfxObjectFactory *pArg = pFactoryP; pArg;
     125           0 :          pArg = va_arg( pVarArgs, SfxObjectFactory* ) )
     126           0 :         pArg->SetModule_Impl( this );
     127           0 :     va_end(pVarArgs);
     128           0 : }
     129             : 
     130           0 : void SfxModule::Construct_Impl()
     131             : {
     132           0 :     if( !bDummy )
     133             :     {
     134           0 :         SfxApplication *pApp = SFX_APP();
     135           0 :         SfxModuleArr_Impl& rArr = GetModules_Impl();
     136           0 :         SfxModule* pPtr = (SfxModule*)this;
     137           0 :         rArr.push_back( pPtr );
     138           0 :         pImpl = new SfxModule_Impl;
     139           0 :         pImpl->pSlotPool = new SfxSlotPool( &pApp->GetAppSlotPool_Impl(), pResMgr );
     140             : 
     141           0 :         pImpl->pTbxCtrlFac=0;
     142           0 :         pImpl->pStbCtrlFac=0;
     143           0 :         pImpl->pMenuCtrlFac=0;
     144           0 :         pImpl->pFactArr=0;
     145           0 :         pImpl->pImgListSmall=0;
     146           0 :         pImpl->pImgListBig=0;
     147             : 
     148           0 :         SetPool( &pApp->GetPool() );
     149             :     }
     150           0 : }
     151             : 
     152             : 
     153             : 
     154           0 : SfxModule::~SfxModule()
     155             : {
     156           0 :     if( !bDummy )
     157             :     {
     158           0 :         if ( SFX_APP()->Get_Impl() )
     159             :         {
     160             :             // The module will be destroyed before the Deinitialize,
     161             :             // so remove from the array
     162           0 :             SfxModuleArr_Impl& rArr = GetModules_Impl();
     163           0 :             for( sal_uInt16 nPos = rArr.size(); nPos--; )
     164             :             {
     165           0 :                 if( rArr[ nPos ] == this )
     166             :                 {
     167           0 :                     rArr.erase( rArr.begin() + nPos );
     168           0 :                     break;
     169             :                 }
     170             :             }
     171             : 
     172           0 :             delete pImpl;
     173             :         }
     174             : 
     175           0 :         delete pResMgr;
     176             :     }
     177           0 : }
     178             : 
     179             : 
     180             : 
     181           0 : SfxSlotPool* SfxModule::GetSlotPool() const
     182             : {
     183           0 :     return pImpl->pSlotPool;
     184             : }
     185             : 
     186             : 
     187             : 
     188           0 : void SfxModule::RegisterChildWindow(SfxChildWinFactory *pFact)
     189             : {
     190             :     DBG_ASSERT( pImpl, "No real Module!" );
     191             : 
     192           0 :     if (!pImpl->pFactArr)
     193           0 :         pImpl->pFactArr = new SfxChildWinFactArr_Impl;
     194             : 
     195           0 :     for (sal_uInt16 nFactory=0; nFactory<pImpl->pFactArr->size(); ++nFactory)
     196             :     {
     197           0 :         if (pFact->nId ==  (*pImpl->pFactArr)[nFactory]->nId)
     198             :         {
     199           0 :             pImpl->pFactArr->erase( pImpl->pFactArr->begin() + nFactory );
     200             :             SAL_WARN("sfx.appl", "ChildWindow registered multiple times!");
     201           0 :             return;
     202             :         }
     203             :     }
     204             : 
     205           0 :     pImpl->pFactArr->push_back( pFact );
     206             : }
     207             : 
     208             : 
     209             : 
     210           0 : void SfxModule::RegisterToolBoxControl( SfxTbxCtrlFactory *pFact )
     211             : {
     212           0 :     if (!pImpl->pTbxCtrlFac)
     213           0 :         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           0 :     pImpl->pTbxCtrlFac->push_back( pFact );
     228           0 : }
     229             : 
     230             : 
     231             : 
     232           0 : void SfxModule::RegisterStatusBarControl( SfxStbCtrlFactory *pFact )
     233             : {
     234           0 :     if (!pImpl->pStbCtrlFac)
     235           0 :         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           0 :     pImpl->pStbCtrlFac->push_back( pFact );
     250           0 : }
     251             : 
     252             : 
     253             : 
     254           0 : void SfxModule::RegisterMenuControl( SfxMenuCtrlFactory *pFact )
     255             : {
     256           0 :     if (!pImpl->pMenuCtrlFac)
     257           0 :         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           0 :     pImpl->pMenuCtrlFac->push_back( pFact );
     272           0 : }
     273             : 
     274             : 
     275             : 
     276           0 : SfxTbxCtrlFactArr_Impl*  SfxModule::GetTbxCtrlFactories_Impl() const
     277             : {
     278           0 :     return pImpl->pTbxCtrlFac;
     279             : }
     280             : 
     281             : 
     282             : 
     283           0 : SfxStbCtrlFactArr_Impl*  SfxModule::GetStbCtrlFactories_Impl() const
     284             : {
     285           0 :     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           0 : SfxChildWinFactArr_Impl* SfxModule::GetChildWinFactories_Impl() const
     298             : {
     299           0 :     return pImpl->pFactArr;
     300             : }
     301             : 
     302           0 : ImageList* SfxModule::GetImageList_Impl( bool bBig )
     303             : {
     304           0 :     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           0 : SfxModuleArr_Impl& SfxModule::GetModules_Impl()
     313             : {
     314           0 :     if( !pModules )
     315           0 :         pModules = new SfxModuleArr_Impl;
     316           0 :     return *pModules;
     317             : };
     318             : 
     319           0 : void SfxModule::DestroyModules_Impl()
     320             : {
     321           0 :     if ( pModules )
     322             :     {
     323           0 :         SfxModuleArr_Impl& rModules = *pModules;
     324           0 :         for( sal_uInt16 nPos = rModules.size(); nPos--; )
     325             :         {
     326           0 :             SfxModule* pMod = rModules[nPos];
     327           0 :             delete pMod;
     328             :         }
     329           0 :         delete pModules, pModules = 0;
     330             :     }
     331           0 : }
     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           0 : bool SfxModule::IsChildWindowAvailable( const sal_uInt16 i_nId, const SfxViewFrame* i_pViewFrame ) const
     341             : {
     342           0 :     if ( i_nId != SID_TASKPANE )
     343             :         // by default, assume it is
     344           0 :         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           0 : SfxModule* SfxModule::GetActiveModule( SfxViewFrame* pFrame )
     352             : {
     353           0 :     if ( !pFrame )
     354           0 :         pFrame = SfxViewFrame::Current();
     355           0 :     SfxObjectShell* pSh = 0;
     356           0 :     if( pFrame )
     357           0 :         pSh = pFrame->GetObjectShell();
     358           0 :     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 :     return pModule->GetFieldUnit();
     379             : }
     380             : 
     381           0 : FieldUnit SfxModule::GetCurrentFieldUnit()
     382             : {
     383           0 :     FieldUnit eUnit = FUNIT_INCH;
     384           0 :     SfxModule* pModule = GetActiveModule();
     385           0 :     if ( pModule )
     386             :     {
     387           0 :         const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC );
     388           0 :         if ( pItem )
     389           0 :             eUnit = (FieldUnit)( (SfxUInt16Item*)pItem )->GetValue();
     390             :     }
     391             :     else
     392             :         SAL_WARN( "sfx.appl", "GetModuleFieldUnit(): no module found" );
     393           0 :     return eUnit;
     394             : }
     395             : 
     396           0 : FieldUnit SfxModule::GetFieldUnit() const
     397             : {
     398           0 :     FieldUnit eUnit = FUNIT_INCH;
     399           0 :     const SfxPoolItem* pItem = GetItem( SID_ATTR_METRIC );
     400           0 :     if ( pItem )
     401           0 :         eUnit = (FieldUnit)( (SfxUInt16Item*)pItem )->GetValue();
     402           0 :     return eUnit;
     403             : }
     404             : 
     405             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10