LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/appl - appinit.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 66 98 67.3 %
Date: 2012-12-17 Functions: 7 12 58.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/XDesktop.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         216 : 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           8 : void SAL_CALL SfxTerminateListener_Impl::queryTermination( const EventObject& ) throw(TerminationVetoException, RuntimeException )
      94             : {
      95           8 :     SolarMutexGuard aGuard;
      96           8 :     if ( !SFX_APP()->QueryExit_Impl() )
      97           0 :         throw TerminationVetoException();
      98           8 : }
      99             : 
     100           8 : void SAL_CALL SfxTerminateListener_Impl::notifyTermination( const EventObject& aEvent ) throw(RuntimeException )
     101             : {
     102           8 :     Reference< XDesktop > xDesktop( aEvent.Source, UNO_QUERY );
     103           8 :     if( xDesktop.is() == sal_True )
     104           8 :         xDesktop->removeTerminateListener( this );
     105             : 
     106           8 :     SolarMutexGuard aGuard;
     107           8 :     utl::ConfigManager::storeConfigItems();
     108             : 
     109           8 :     SfxApplication* pApp = SFX_APP();
     110           8 :     pApp->Broadcast( SfxSimpleHint( SFX_HINT_DEINITIALIZING ) );
     111           8 :     pApp->Get_Impl()->pAppDispatch->ReleaseAll();
     112           8 :     pApp->Get_Impl()->pAppDispatch->release();
     113             : 
     114           8 :     css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
     115           8 :     css::uno::Reference< css::document::XEventListener > xGlobalBroadcaster(css::frame::GlobalEventBroadcaster::create(xContext), css::uno::UNO_QUERY_THROW);
     116             : 
     117           8 :     css::document::EventObject aEvent2;
     118           8 :     aEvent2.EventName = "OnCloseApp";
     119           8 :     xGlobalBroadcaster->notifyEvent(aEvent2);
     120             : 
     121           8 :     delete pApp;
     122           8 :     Application::Quit();
     123           8 : }
     124             : 
     125          80 : ::rtl::OUString SAL_CALL SfxTerminateListener_Impl::getImplementationName() throw (RuntimeException)
     126             : {
     127          80 :     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          72 : 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          72 :     Reference < XDesktop > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
     219          72 :     if (!xDesktop.is())
     220           0 :          throw RuntimeException( rtl::OUString( "Couldn't create mandatory desktop service!" ), xDesktop );
     221          72 :     xDesktop->addTerminateListener( new SfxTerminateListener_Impl() );
     222             : 
     223          72 :     Application::EnableAutoHelpId();
     224             : 
     225          72 :     pAppData_Impl->pAppDispatch = new SfxStatusDispatcher;
     226          72 :     pAppData_Impl->pAppDispatch->acquire();
     227             : 
     228             :     // SV-Look
     229          72 :     Help::EnableContextHelp();
     230          72 :     Help::EnableExtHelp();
     231             : 
     232          72 :     SvtLocalisationOptions aLocalisation;
     233          72 :     Application::EnableAutoMnemonic ( aLocalisation.IsAutoMnemonic() );
     234          72 :     Application::SetDialogScaleX    ( (short)(aLocalisation.GetDialogScale()) );
     235             : 
     236             : 
     237             : #ifdef DBG_UTIL
     238             :     // The SimplerErrorHandler is for debugging. In the Product errors
     239             :     // not processed are given to SFX as Errorcode 1.
     240             :     pAppData_Impl->m_pSimpleErrorHdl = new SimpleErrorHandler;
     241             : #endif
     242             :     pAppData_Impl->m_pToolsErrorHdl = new SfxErrorHandler(
     243          72 :         RID_ERRHDL, ERRCODE_AREA_TOOLS, ERRCODE_AREA_LIB1);
     244             : 
     245          72 :     pAppData_Impl->pBasicResMgr = CreateResManager("sb");
     246          72 :     pAppData_Impl->pSvtResMgr = CreateResManager("svt");
     247             : 
     248             :     pAppData_Impl->m_pSoErrorHdl = new SfxErrorHandler(
     249          72 :         RID_SO_ERROR_HANDLER, ERRCODE_AREA_SO, ERRCODE_AREA_SO_END, pAppData_Impl->pSvtResMgr );
     250             :     pAppData_Impl->m_pSbxErrorHdl = new SfxErrorHandler(
     251          72 :         RID_BASIC_START, ERRCODE_AREA_SBX, ERRCODE_AREA_SBX_END, pAppData_Impl->pBasicResMgr );
     252             : 
     253             :     //ensure instantiation of listener that manages the internal recently-used
     254             :     //list
     255          72 :     SfxPickList::ensure();
     256             : 
     257             :     DBG_ASSERT( !pAppData_Impl->pAppDispat, "AppDispatcher already exists" );
     258          72 :     pAppData_Impl->pAppDispat = new SfxDispatcher((SfxDispatcher*)0);
     259          72 :     pAppData_Impl->pSlotPool = new SfxSlotPool;
     260          72 :     pAppData_Impl->pTbxCtrlFac = new SfxTbxCtrlFactArr_Impl;
     261          72 :     pAppData_Impl->pStbCtrlFac = new SfxStbCtrlFactArr_Impl;
     262          72 :     pAppData_Impl->pMenuCtrlFac = new SfxMenuCtrlFactArr_Impl;
     263          72 :     pAppData_Impl->pViewFrames = new SfxViewFrameArr_Impl;
     264          72 :     pAppData_Impl->pViewShells = new SfxViewShellArr_Impl;
     265          72 :     pAppData_Impl->pObjShells = new SfxObjectShellArr_Impl;
     266          72 :     pAppData_Impl->nInterfaces = SFX_INTERFACE_APP+8;
     267          72 :     pAppData_Impl->pInterfaces = new SfxInterface*[pAppData_Impl->nInterfaces];
     268          72 :     memset( pAppData_Impl->pInterfaces, 0, sizeof(SfxInterface*) * pAppData_Impl->nInterfaces );
     269             : 
     270          72 :     Registrations_Impl();
     271             : 
     272             :     // Subklasse initialisieren
     273          72 :     pAppData_Impl->bDowning = sal_False;
     274          72 :     Init();
     275             : 
     276             :     // get CHAOS item pool...
     277          72 :     pAppData_Impl->pPool = NoChaos::GetItemPool();
     278          72 :     SetPool( pAppData_Impl->pPool );
     279             : 
     280          72 :     if ( pAppData_Impl->bDowning )
     281           0 :         return sal_False;
     282             : 
     283             :     // App-Dispatcher aufbauen
     284          72 :     pAppData_Impl->pAppDispat->Push(*this);
     285          72 :     pAppData_Impl->pAppDispat->Flush();
     286          72 :     pAppData_Impl->pAppDispat->DoActivate_Impl( sal_True, NULL );
     287             : 
     288             :     {
     289          72 :         SolarMutexGuard aGuard;
     290             :         // Set special characters callback on vcl edit control
     291          72 :         Edit::SetGetSpecialCharsFunction(&GetSpecialCharsForEdit);
     292             :     }
     293             : 
     294          72 :     return sal_True;
     295             : }
     296             : 
     297             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10