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

Generated by: LCOV version 1.10