LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/appl - appinit.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 43 96 44.8 %
Date: 2012-12-27 Functions: 5 12 41.7 %
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             : 
      21             : #include <sfx2/app.hxx>
      22             : #include <com/sun/star/frame/XTerminateListener.hpp>
      23             : #include <com/sun/star/uno/Reference.hxx>
      24             : #include <com/sun/star/frame/GlobalEventBroadcaster.hpp>
      25             : #include <com/sun/star/frame/Desktop.hpp>
      26             : #include <com/sun/star/lang/XServiceInfo.hpp>
      27             : 
      28             : #include <svtools/soerr.hxx>
      29             : #include <svtools/svtools.hrc>
      30             : #include <unotools/saveopt.hxx>
      31             : #include <unotools/localisationoptions.hxx>
      32             : #include <svl/intitem.hxx>
      33             : #include <svl/eitem.hxx>
      34             : #include <svl/stritem.hxx>
      35             : #include <vcl/msgbox.hxx>
      36             : #include <svtools/ehdl.hxx>
      37             : #include <comphelper/processfactory.hxx>
      38             : #include <unotools/configmgr.hxx>
      39             : #include <rtl/ustrbuf.hxx>
      40             : #include <osl/security.hxx>
      41             : #include <unotools/pathoptions.hxx>
      42             : #include <unotools/historyoptions.hxx>
      43             : #include <unotools/moduleoptions.hxx>
      44             : #include <cppuhelper/implbase2.hxx>
      45             : 
      46             : #include <rtl/logfile.hxx>
      47             : #include <vcl/edit.hxx>
      48             : 
      49             : #include <sfx2/unoctitm.hxx>
      50             : #include "app.hrc"
      51             : #include "sfxlocal.hrc"
      52             : #include "appdata.hxx"
      53             : #include "arrdecl.hxx"
      54             : #include <sfx2/dispatch.hxx>
      55             : #include <sfx2/docfac.hxx>
      56             : #include <sfx2/evntconf.hxx>
      57             : #include <sfx2/mnumgr.hxx>
      58             : #include <sfx2/msgpool.hxx>
      59             : #include <sfx2/progress.hxx>
      60             : #include "sfx2/sfxhelp.hxx"
      61             : #include "sfx2/sfxresid.hxx"
      62             : #include "sfxtypes.hxx"
      63             : #include <sfx2/viewsh.hxx>
      64             : #include "nochaos.hxx"
      65             : #include <sfx2/fcontnr.hxx>
      66             : #include "helper.hxx"   // SfxContentHelper::Kill()
      67             : #include "sfxpicklist.hxx"
      68             : 
      69             : using namespace ::com::sun::star::uno;
      70             : using namespace ::com::sun::star::frame;
      71             : using namespace ::com::sun::star::lang;
      72             : using namespace ::com::sun::star;
      73             : 
      74          57 : class SfxTerminateListener_Impl : public ::cppu::WeakImplHelper2< XTerminateListener, XServiceInfo >
      75             : {
      76             : public:
      77             : 
      78             :     // XTerminateListener
      79             :     virtual void SAL_CALL queryTermination( const EventObject& aEvent ) throw( TerminationVetoException, RuntimeException );
      80             :     virtual void SAL_CALL notifyTermination( const EventObject& aEvent ) throw( RuntimeException );
      81             :     virtual void SAL_CALL disposing( const EventObject& Source ) throw( RuntimeException );
      82             : 
      83             :     // XServiceInfo
      84             :     virtual ::rtl::OUString SAL_CALL getImplementationName() throw (RuntimeException);
      85             :     virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& sServiceName ) throw (RuntimeException);
      86             :     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
      87             : };
      88             : 
      89           0 : void SAL_CALL SfxTerminateListener_Impl::disposing( const EventObject& ) throw( RuntimeException )
      90             : {
      91           0 : }
      92             : 
      93           0 : void SAL_CALL SfxTerminateListener_Impl::queryTermination( const EventObject& ) throw(TerminationVetoException, RuntimeException )
      94             : {
      95           0 :     SolarMutexGuard aGuard;
      96           0 :     if ( !SFX_APP()->QueryExit_Impl() )
      97           0 :         throw TerminationVetoException();
      98           0 : }
      99             : 
     100           0 : void SAL_CALL SfxTerminateListener_Impl::notifyTermination( const EventObject& aEvent ) throw(RuntimeException )
     101             : {
     102           0 :     Reference< XDesktop > xDesktop( aEvent.Source, UNO_QUERY );
     103           0 :     if( xDesktop.is() == sal_True )
     104           0 :         xDesktop->removeTerminateListener( this );
     105             : 
     106           0 :     SolarMutexGuard aGuard;
     107           0 :     utl::ConfigManager::storeConfigItems();
     108             : 
     109           0 :     SfxApplication* pApp = SFX_APP();
     110           0 :     pApp->Broadcast( SfxSimpleHint( SFX_HINT_DEINITIALIZING ) );
     111           0 :     pApp->Get_Impl()->pAppDispatch->ReleaseAll();
     112           0 :     pApp->Get_Impl()->pAppDispatch->release();
     113             : 
     114           0 :     css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
     115           0 :     css::uno::Reference< css::document::XEventListener > xGlobalBroadcaster(css::frame::GlobalEventBroadcaster::create(xContext), css::uno::UNO_QUERY_THROW);
     116             : 
     117           0 :     css::document::EventObject aEvent2;
     118           0 :     aEvent2.EventName = "OnCloseApp";
     119           0 :     xGlobalBroadcaster->notifyEvent(aEvent2);
     120             : 
     121           0 :     delete pApp;
     122           0 :     Application::Quit();
     123           0 : }
     124             : 
     125          19 : ::rtl::OUString SAL_CALL SfxTerminateListener_Impl::getImplementationName() throw (RuntimeException)
     126             : {
     127          19 :     return ::rtl::OUString("com.sun.star.comp.sfx2.SfxTerminateListener");
     128             : }
     129             : 
     130           0 : ::sal_Bool SAL_CALL SfxTerminateListener_Impl::supportsService( const ::rtl::OUString& sServiceName ) throw (RuntimeException)
     131             : {
     132           0 :     Sequence< ::rtl::OUString > lNames  = getSupportedServiceNames();
     133           0 :     ::sal_Int32                 c       = lNames.getLength();
     134           0 :     ::sal_Int32                 i       = 0;
     135             : 
     136           0 :     for (i=0; i<c; ++i)
     137             :     {
     138           0 :         if (lNames[i].equals(sServiceName))
     139           0 :             return sal_True;
     140             :     }
     141             : 
     142           0 :     return sal_False;
     143             : }
     144             : 
     145           0 : Sequence< ::rtl::OUString > SAL_CALL SfxTerminateListener_Impl::getSupportedServiceNames() throw (RuntimeException)
     146             : {
     147             :     // Note: That service  does not realy exists .-)
     148             :     // But this implementation is not thought to be registered realy within our service.rdb.
     149             :     // At least we need the implementation name only to identify these service at the global desktop instance.
     150             :     // The desktop must know, which listener will terminate the SfxApplication in real !
     151             :     // It must call this special listener as last one ... otherwise we shutdown the SfxApplication BEFORE other listener
     152             :     // can react ...
     153           0 :     static const ::rtl::OUString SERVICENAME("com.sun.star.frame.TerminateListener");
     154           0 :     Sequence< ::rtl::OUString > lNames(1);
     155           0 :     lNames[0] = SERVICENAME;
     156           0 :     return lNames;
     157             : }
     158             : 
     159             : //====================================================================
     160             : 
     161             : typedef bool ( *PFunc_getSpecialCharsForEdit)( Window* i_pParent, const Font& i_rFont, String& o_rOutString );
     162             : 
     163             : //====================================================================
     164             : // Lazy binding of the GetSpecialCharsForEdit function as it resides in
     165             : // a library above us.
     166             : //====================================================================
     167             : 
     168             : #ifndef DISABLE_DYNLOADING
     169             : 
     170           0 : extern "C" { static void SAL_CALL thisModule() {} }
     171             : 
     172             : #else
     173             : 
     174             : extern "C" bool GetSpecialCharsForEdit( Window* i_pParent, const Font& i_rFont, String& o_rOutString );
     175             : 
     176             : #endif
     177             : 
     178           0 : String GetSpecialCharsForEdit(Window* pParent, const Font& rFont)
     179             : {
     180             :     static bool bDetermineFunction = false;
     181             :     static PFunc_getSpecialCharsForEdit pfunc_getSpecialCharsForEdit = 0;
     182             : 
     183           0 :     SolarMutexGuard aGuard;
     184           0 :     if ( !bDetermineFunction )
     185             :     {
     186           0 :         bDetermineFunction = true;
     187             : 
     188             : #ifndef DISABLE_DYNLOADING
     189           0 :         static ::rtl::OUString aLibName( SVLIBRARY( "cui"  ) );
     190             :         oslModule handleMod = osl_loadModuleRelative(
     191           0 :             &thisModule, aLibName.pData, 0 );
     192             : 
     193             :         // get symbol
     194           0 :         ::rtl::OUString aSymbol( "GetSpecialCharsForEdit"  );
     195           0 :         pfunc_getSpecialCharsForEdit = (PFunc_getSpecialCharsForEdit)osl_getFunctionSymbol( handleMod, aSymbol.pData );
     196           0 :         DBG_ASSERT( pfunc_getSpecialCharsForEdit, "GetSpecialCharsForEdit() not found!" );
     197             : #else
     198             :         pfunc_getSpecialCharsForEdit = GetSpecialCharsForEdit;
     199             : #endif
     200             :     }
     201             : 
     202           0 :     String aRet;
     203           0 :     if ( pfunc_getSpecialCharsForEdit )
     204           0 :         (*pfunc_getSpecialCharsForEdit)( pParent, rFont, aRet );
     205           0 :     return aRet;
     206             : }
     207             : 
     208             : //====================================================================
     209             : 
     210          19 : bool SfxApplication::Initialize_Impl()
     211             : {
     212             :     RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mb93783) ::SfxApplication::Initialize_Impl" );
     213             : 
     214             : #ifdef TLX_VALIDATE
     215             :     StgIo::SetErrorLink( LINK( this, SfxStorageErrHdl, Error ) );
     216             : #endif
     217             : 
     218          19 :     Reference < XDesktop2 > xDesktop = Desktop::create ( ::comphelper::getProcessComponentContext() );
     219          19 :     xDesktop->addTerminateListener( new SfxTerminateListener_Impl() );
     220             : 
     221          19 :     Application::EnableAutoHelpId();
     222             : 
     223          19 :     pAppData_Impl->pAppDispatch = new SfxStatusDispatcher;
     224          19 :     pAppData_Impl->pAppDispatch->acquire();
     225             : 
     226             :     // SV-Look
     227          19 :     Help::EnableContextHelp();
     228          19 :     Help::EnableExtHelp();
     229             : 
     230          19 :     SvtLocalisationOptions aLocalisation;
     231          19 :     Application::EnableAutoMnemonic ( aLocalisation.IsAutoMnemonic() );
     232          19 :     Application::SetDialogScaleX    ( (short)(aLocalisation.GetDialogScale()) );
     233             : 
     234             : 
     235             : #ifdef DBG_UTIL
     236             :     // The SimplerErrorHandler is for debugging. In the Product errors
     237             :     // not processed are given to SFX as Errorcode 1.
     238             :     pAppData_Impl->m_pSimpleErrorHdl = new SimpleErrorHandler;
     239             : #endif
     240             :     pAppData_Impl->m_pToolsErrorHdl = new SfxErrorHandler(
     241          19 :         RID_ERRHDL, ERRCODE_AREA_TOOLS, ERRCODE_AREA_LIB1);
     242             : 
     243          19 :     pAppData_Impl->pBasicResMgr = CreateResManager("sb");
     244          19 :     pAppData_Impl->pSvtResMgr = CreateResManager("svt");
     245             : 
     246             :     pAppData_Impl->m_pSoErrorHdl = new SfxErrorHandler(
     247          19 :         RID_SO_ERROR_HANDLER, ERRCODE_AREA_SO, ERRCODE_AREA_SO_END, pAppData_Impl->pSvtResMgr );
     248             :     pAppData_Impl->m_pSbxErrorHdl = new SfxErrorHandler(
     249          19 :         RID_BASIC_START, ERRCODE_AREA_SBX, ERRCODE_AREA_SBX_END, pAppData_Impl->pBasicResMgr );
     250             : 
     251             :     //ensure instantiation of listener that manages the internal recently-used
     252             :     //list
     253          19 :     SfxPickList::ensure();
     254             : 
     255             :     DBG_ASSERT( !pAppData_Impl->pAppDispat, "AppDispatcher already exists" );
     256          19 :     pAppData_Impl->pAppDispat = new SfxDispatcher((SfxDispatcher*)0);
     257          19 :     pAppData_Impl->pSlotPool = new SfxSlotPool;
     258          19 :     pAppData_Impl->pTbxCtrlFac = new SfxTbxCtrlFactArr_Impl;
     259          19 :     pAppData_Impl->pStbCtrlFac = new SfxStbCtrlFactArr_Impl;
     260          19 :     pAppData_Impl->pMenuCtrlFac = new SfxMenuCtrlFactArr_Impl;
     261          19 :     pAppData_Impl->pViewFrames = new SfxViewFrameArr_Impl;
     262          19 :     pAppData_Impl->pViewShells = new SfxViewShellArr_Impl;
     263          19 :     pAppData_Impl->pObjShells = new SfxObjectShellArr_Impl;
     264          19 :     pAppData_Impl->nInterfaces = SFX_INTERFACE_APP+8;
     265          19 :     pAppData_Impl->pInterfaces = new SfxInterface*[pAppData_Impl->nInterfaces];
     266          19 :     memset( pAppData_Impl->pInterfaces, 0, sizeof(SfxInterface*) * pAppData_Impl->nInterfaces );
     267             : 
     268          19 :     Registrations_Impl();
     269             : 
     270             :     // Subklasse initialisieren
     271          19 :     pAppData_Impl->bDowning = sal_False;
     272          19 :     Init();
     273             : 
     274             :     // get CHAOS item pool...
     275          19 :     pAppData_Impl->pPool = NoChaos::GetItemPool();
     276          19 :     SetPool( pAppData_Impl->pPool );
     277             : 
     278          19 :     if ( pAppData_Impl->bDowning )
     279           0 :         return sal_False;
     280             : 
     281             :     // App-Dispatcher aufbauen
     282          19 :     pAppData_Impl->pAppDispat->Push(*this);
     283          19 :     pAppData_Impl->pAppDispat->Flush();
     284          19 :     pAppData_Impl->pAppDispat->DoActivate_Impl( sal_True, NULL );
     285             : 
     286             :     {
     287          19 :         SolarMutexGuard aGuard;
     288             :         // Set special characters callback on vcl edit control
     289          19 :         Edit::SetGetSpecialCharsFunction(&GetSpecialCharsForEdit);
     290             :     }
     291             : 
     292          19 :     return sal_True;
     293             : }
     294             : 
     295             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10