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

Generated by: LCOV version 1.11