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