1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <sfx2/app.hxx> 32*cdf0e10cSrcweir #include <com/sun/star/frame/XTerminateListener.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx> 34*cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <svtools/soerr.hxx> 38*cdf0e10cSrcweir #include <svtools/svtools.hrc> 39*cdf0e10cSrcweir #include <unotools/saveopt.hxx> 40*cdf0e10cSrcweir #include <unotools/localisationoptions.hxx> 41*cdf0e10cSrcweir #include <tools/config.hxx> 42*cdf0e10cSrcweir #ifndef _SV_RESARY_HXX 43*cdf0e10cSrcweir #include <tools/resary.hxx> 44*cdf0e10cSrcweir #endif 45*cdf0e10cSrcweir #include <tools/urlobj.hxx> 46*cdf0e10cSrcweir #include <svl/intitem.hxx> 47*cdf0e10cSrcweir #include <svl/eitem.hxx> 48*cdf0e10cSrcweir #include <svl/stritem.hxx> 49*cdf0e10cSrcweir #ifndef _MSGBOX_HXX //autogen 50*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 51*cdf0e10cSrcweir #endif 52*cdf0e10cSrcweir #include <svtools/ehdl.hxx> 53*cdf0e10cSrcweir #ifndef _UNOTOOLS_PROCESSFACTORY_HXX 54*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 55*cdf0e10cSrcweir #endif 56*cdf0e10cSrcweir #include <unotools/configmgr.hxx> 57*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 58*cdf0e10cSrcweir #include <vos/security.hxx> 59*cdf0e10cSrcweir #include <ucbhelper/configurationkeys.hxx> 60*cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 61*cdf0e10cSrcweir #include <unotools/historyoptions.hxx> 62*cdf0e10cSrcweir #include <unotools/moduleoptions.hxx> 63*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx> 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir #include <rtl/logfile.hxx> 66*cdf0e10cSrcweir #include <vcl/edit.hxx> 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir #include <sfx2/unoctitm.hxx> 69*cdf0e10cSrcweir #include "app.hrc" 70*cdf0e10cSrcweir #include "sfxlocal.hrc" 71*cdf0e10cSrcweir #include "appdata.hxx" 72*cdf0e10cSrcweir #include "arrdecl.hxx" 73*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 74*cdf0e10cSrcweir #include <sfx2/docfac.hxx> 75*cdf0e10cSrcweir #include <sfx2/evntconf.hxx> 76*cdf0e10cSrcweir #include "intro.hxx" 77*cdf0e10cSrcweir #include <sfx2/mnumgr.hxx> 78*cdf0e10cSrcweir #include <sfx2/msgpool.hxx> 79*cdf0e10cSrcweir #include <sfx2/progress.hxx> 80*cdf0e10cSrcweir #include "sfx2/sfxhelp.hxx" 81*cdf0e10cSrcweir #include "sfx2/sfxresid.hxx" 82*cdf0e10cSrcweir #include "sfxtypes.hxx" 83*cdf0e10cSrcweir #include <sfx2/viewsh.hxx> 84*cdf0e10cSrcweir #include "nochaos.hxx" 85*cdf0e10cSrcweir #include <sfx2/fcontnr.hxx> 86*cdf0e10cSrcweir #include "helper.hxx" // SfxContentHelper::Kill() 87*cdf0e10cSrcweir #include "sfxpicklist.hxx" 88*cdf0e10cSrcweir #include <tools/svlibrary.hxx> 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir #ifdef UNX 91*cdf0e10cSrcweir #define stricmp(a,b) strcmp(a,b) 92*cdf0e10cSrcweir #endif 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 95*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 96*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 97*cdf0e10cSrcweir using namespace ::com::sun::star; 98*cdf0e10cSrcweir namespace css = ::com::sun::star; 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir class SfxTerminateListener_Impl : public ::cppu::WeakImplHelper2< XTerminateListener, XServiceInfo > 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir public: 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir // XTerminateListener 105*cdf0e10cSrcweir virtual void SAL_CALL queryTermination( const EventObject& aEvent ) throw( TerminationVetoException, RuntimeException ); 106*cdf0e10cSrcweir virtual void SAL_CALL notifyTermination( const EventObject& aEvent ) throw( RuntimeException ); 107*cdf0e10cSrcweir virtual void SAL_CALL disposing( const EventObject& Source ) throw( RuntimeException ); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir // XServiceInfo 110*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName() throw (RuntimeException); 111*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& sServiceName ) throw (RuntimeException); 112*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException); 113*cdf0e10cSrcweir }; 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir void SAL_CALL SfxTerminateListener_Impl::disposing( const EventObject& ) throw( RuntimeException ) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir void SAL_CALL SfxTerminateListener_Impl::queryTermination( const EventObject& ) throw(TerminationVetoException, RuntimeException ) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 122*cdf0e10cSrcweir if ( !SFX_APP()->QueryExit_Impl() ) 123*cdf0e10cSrcweir throw TerminationVetoException(); 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir void SAL_CALL SfxTerminateListener_Impl::notifyTermination( const EventObject& aEvent ) throw(RuntimeException ) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir static ::rtl::OUString SERVICE_GLOBALEVENTBROADCASTER = ::rtl::OUString::createFromAscii("com.sun.star.frame.GlobalEventBroadcaster"); 129*cdf0e10cSrcweir static ::rtl::OUString EVENT_QUIT_APP = ::rtl::OUString::createFromAscii("OnCloseApp"); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir Reference< XDesktop > xDesktop( aEvent.Source, UNO_QUERY ); 132*cdf0e10cSrcweir if( xDesktop.is() == sal_True ) 133*cdf0e10cSrcweir xDesktop->removeTerminateListener( this ); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 136*cdf0e10cSrcweir utl::ConfigManager::GetConfigManager()->StoreConfigItems(); 137*cdf0e10cSrcweir SfxApplication* pApp = SFX_APP(); 138*cdf0e10cSrcweir pApp->Broadcast( SfxSimpleHint( SFX_HINT_DEINITIALIZING ) ); 139*cdf0e10cSrcweir pApp->Get_Impl()->pAppDispatch->ReleaseAll(); 140*cdf0e10cSrcweir pApp->Get_Impl()->pAppDispatch->release(); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); 143*cdf0e10cSrcweir css::uno::Reference< css::document::XEventListener > xGlobalBroadcaster(xSMGR->createInstance(SERVICE_GLOBALEVENTBROADCASTER), css::uno::UNO_QUERY); 144*cdf0e10cSrcweir if (xGlobalBroadcaster.is()) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir css::document::EventObject aEvent2; 147*cdf0e10cSrcweir aEvent2.EventName = EVENT_QUIT_APP; 148*cdf0e10cSrcweir xGlobalBroadcaster->notifyEvent(aEvent2); 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir //pApp->Deinitialize(); 152*cdf0e10cSrcweir delete pApp; 153*cdf0e10cSrcweir Application::Quit(); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir ::rtl::OUString SAL_CALL SfxTerminateListener_Impl::getImplementationName() throw (RuntimeException) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir static const ::rtl::OUString IMPLNAME = ::rtl::OUString::createFromAscii("com.sun.star.comp.sfx2.SfxTerminateListener"); 159*cdf0e10cSrcweir return IMPLNAME; 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir ::sal_Bool SAL_CALL SfxTerminateListener_Impl::supportsService( const ::rtl::OUString& sServiceName ) throw (RuntimeException) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir Sequence< ::rtl::OUString > lNames = getSupportedServiceNames(); 165*cdf0e10cSrcweir ::sal_Int32 c = lNames.getLength(); 166*cdf0e10cSrcweir ::sal_Int32 i = 0; 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir for (i=0; i<c; ++i) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir if (lNames[i].equals(sServiceName)) 171*cdf0e10cSrcweir return sal_True; 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir return sal_False; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL SfxTerminateListener_Impl::getSupportedServiceNames() throw (RuntimeException) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir // Note: That service does not realy exists .-) 180*cdf0e10cSrcweir // But this implementation is not thought to be registered realy within our service.rdb. 181*cdf0e10cSrcweir // At least we need the implementation name only to identify these service at the global desktop instance. 182*cdf0e10cSrcweir // The desktop must know, which listener will terminate the SfxApplication in real ! 183*cdf0e10cSrcweir // It must call this special listener as last one ... otherwise we shutdown the SfxApplication BEFORE other listener 184*cdf0e10cSrcweir // can react ... 185*cdf0e10cSrcweir static const ::rtl::OUString SERVICENAME = ::rtl::OUString::createFromAscii("com.sun.star.frame.TerminateListener"); 186*cdf0e10cSrcweir Sequence< ::rtl::OUString > lNames(1); 187*cdf0e10cSrcweir lNames[0] = SERVICENAME; 188*cdf0e10cSrcweir return lNames; 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir //==================================================================== 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir #define DOSTRING( x ) #x 194*cdf0e10cSrcweir #define STRING( x ) DOSTRING( x ) 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir typedef bool ( *PFunc_getSpecialCharsForEdit)( Window* i_pParent, const Font& i_rFont, String& o_rOutString ); 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir //==================================================================== 199*cdf0e10cSrcweir // Lazy binding of the GetSpecialCharsForEdit function as it resides in 200*cdf0e10cSrcweir // a library above us. 201*cdf0e10cSrcweir //==================================================================== 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir extern "C" { static void SAL_CALL thisModule() {} } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir String GetSpecialCharsForEdit(Window* pParent, const Font& rFont) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir static bool bDetermineFunction = false; 208*cdf0e10cSrcweir static PFunc_getSpecialCharsForEdit pfunc_getSpecialCharsForEdit = 0; 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 211*cdf0e10cSrcweir if ( !bDetermineFunction ) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir bDetermineFunction = true; 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir static ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "cui" ) ) ); 216*cdf0e10cSrcweir oslModule handleMod = osl_loadModuleRelative( 217*cdf0e10cSrcweir &thisModule, aLibName.pData, 0 ); 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir // get symbol 220*cdf0e10cSrcweir ::rtl::OUString aSymbol( RTL_CONSTASCII_USTRINGPARAM( "GetSpecialCharsForEdit" ) ); 221*cdf0e10cSrcweir pfunc_getSpecialCharsForEdit = (PFunc_getSpecialCharsForEdit)osl_getFunctionSymbol( handleMod, aSymbol.pData ); 222*cdf0e10cSrcweir DBG_ASSERT( pfunc_getSpecialCharsForEdit, "GetSpecialCharsForEdit() not found!" ); 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir String aRet; 226*cdf0e10cSrcweir if ( pfunc_getSpecialCharsForEdit ) 227*cdf0e10cSrcweir (*pfunc_getSpecialCharsForEdit)( pParent, rFont, aRet ); 228*cdf0e10cSrcweir return aRet; 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir //==================================================================== 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir bool SfxApplication::Initialize_Impl() 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mb93783) ::SfxApplication::Initialize_Impl" ); 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir #ifdef TLX_VALIDATE 238*cdf0e10cSrcweir StgIo::SetErrorLink( LINK( this, SfxStorageErrHdl, Error ) ); 239*cdf0e10cSrcweir #endif 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir Reference < XDesktop > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY ); 242*cdf0e10cSrcweir if (!xDesktop.is()) 243*cdf0e10cSrcweir throw RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Couldn't create mandatory desktop service!" )), xDesktop ); 244*cdf0e10cSrcweir xDesktop->addTerminateListener( new SfxTerminateListener_Impl() ); 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir Application::EnableAutoHelpId(); 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir pAppData_Impl->pAppDispatch = new SfxStatusDispatcher; 249*cdf0e10cSrcweir pAppData_Impl->pAppDispatch->acquire(); 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir // SV-Look 252*cdf0e10cSrcweir Help::EnableContextHelp(); 253*cdf0e10cSrcweir Help::EnableExtHelp(); 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir SvtLocalisationOptions aLocalisation; 256*cdf0e10cSrcweir Application::EnableAutoMnemonic ( aLocalisation.IsAutoMnemonic() ); 257*cdf0e10cSrcweir Application::SetDialogScaleX ( (short)(aLocalisation.GetDialogScale()) ); 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir #ifdef DBG_UTIL 261*cdf0e10cSrcweir // Der SimplerErrorHandler dient Debugzwecken. In der Product werden 262*cdf0e10cSrcweir // nichtgehandelte Fehler durch Errorcode 1 an SFX gegeben. 263*cdf0e10cSrcweir new SimpleErrorHandler; 264*cdf0e10cSrcweir #endif 265*cdf0e10cSrcweir pAppData_Impl->pBasicResMgr = CreateResManager("sb"); 266*cdf0e10cSrcweir pAppData_Impl->pSvtResMgr = CreateResManager("svt"); 267*cdf0e10cSrcweir new SfxErrorHandler( RID_ERRHDL, ERRCODE_AREA_TOOLS, ERRCODE_AREA_LIB1 ); 268*cdf0e10cSrcweir new SfxErrorHandler( RID_SO_ERROR_HANDLER, ERRCODE_AREA_SO, ERRCODE_AREA_SO_END, pAppData_Impl->pSvtResMgr ); 269*cdf0e10cSrcweir new SfxErrorHandler( RID_BASIC_START, ERRCODE_AREA_SBX, ERRCODE_AREA_SBX_END, pAppData_Impl->pBasicResMgr ); 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir // diverse Pointer 272*cdf0e10cSrcweir SfxPickList::GetOrCreate( SvtHistoryOptions().GetSize( ePICKLIST ) ); 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////// 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir DBG_ASSERT( !pAppData_Impl->pAppDispat, "AppDispatcher already exists" ); 277*cdf0e10cSrcweir pAppData_Impl->pAppDispat = new SfxDispatcher((SfxDispatcher*)0); 278*cdf0e10cSrcweir pAppData_Impl->pSlotPool = new SfxSlotPool; 279*cdf0e10cSrcweir pAppData_Impl->pTbxCtrlFac = new SfxTbxCtrlFactArr_Impl; 280*cdf0e10cSrcweir pAppData_Impl->pStbCtrlFac = new SfxStbCtrlFactArr_Impl; 281*cdf0e10cSrcweir pAppData_Impl->pMenuCtrlFac = new SfxMenuCtrlFactArr_Impl; 282*cdf0e10cSrcweir pAppData_Impl->pViewFrames = new SfxViewFrameArr_Impl; 283*cdf0e10cSrcweir pAppData_Impl->pViewShells = new SfxViewShellArr_Impl; 284*cdf0e10cSrcweir pAppData_Impl->pObjShells = new SfxObjectShellArr_Impl; 285*cdf0e10cSrcweir pAppData_Impl->nInterfaces = SFX_INTERFACE_APP+8; 286*cdf0e10cSrcweir pAppData_Impl->pInterfaces = new SfxInterface*[pAppData_Impl->nInterfaces]; 287*cdf0e10cSrcweir memset( pAppData_Impl->pInterfaces, 0, sizeof(SfxInterface*) * pAppData_Impl->nInterfaces ); 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir Registrations_Impl(); 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir // Subklasse initialisieren 292*cdf0e10cSrcweir pAppData_Impl->bDowning = sal_False; 293*cdf0e10cSrcweir Init(); 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir // get CHAOS item pool... 296*cdf0e10cSrcweir pAppData_Impl->pPool = NoChaos::GetItemPool(); 297*cdf0e10cSrcweir SetPool( pAppData_Impl->pPool ); 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir if ( pAppData_Impl->bDowning ) 300*cdf0e10cSrcweir return sal_False; 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir // App-Dispatcher aufbauen 303*cdf0e10cSrcweir pAppData_Impl->pAppDispat->Push(*this); 304*cdf0e10cSrcweir pAppData_Impl->pAppDispat->Flush(); 305*cdf0e10cSrcweir pAppData_Impl->pAppDispat->DoActivate_Impl( sal_True, NULL ); 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 309*cdf0e10cSrcweir // Set special characters callback on vcl edit control 310*cdf0e10cSrcweir Edit::SetGetSpecialCharsFunction(&GetSpecialCharsForEdit); 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir return sal_True; 314*cdf0e10cSrcweir } 315