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

Generated by: LCOV version 1.10