1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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/Desktop.hpp>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
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>
46 #include <rtl/logfile.hxx>
47 #include <vcl/edit.hxx>
49 #include <sfx2/unoctitm.hxx>
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"
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
;
74 class SfxTerminateListener_Impl
: public ::cppu::WeakImplHelper2
< XTerminateListener
, XServiceInfo
>
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
);
84 virtual OUString SAL_CALL
getImplementationName() throw (RuntimeException
);
85 virtual ::sal_Bool SAL_CALL
supportsService( const OUString
& sServiceName
) throw (RuntimeException
);
86 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw (RuntimeException
);
89 void SAL_CALL
SfxTerminateListener_Impl::disposing( const EventObject
& ) throw( RuntimeException
)
93 void SAL_CALL
SfxTerminateListener_Impl::queryTermination( const EventObject
& ) throw(TerminationVetoException
, RuntimeException
)
95 SolarMutexGuard aGuard
;
96 if ( !SFX_APP()->QueryExit_Impl() )
97 throw TerminationVetoException();
100 void SAL_CALL
SfxTerminateListener_Impl::notifyTermination( const EventObject
& aEvent
) throw(RuntimeException
)
102 Reference
< XDesktop
> xDesktop( aEvent
.Source
, UNO_QUERY
);
103 if( xDesktop
.is() == sal_True
)
104 xDesktop
->removeTerminateListener( this );
106 SolarMutexGuard aGuard
;
107 utl::ConfigManager::storeConfigItems();
109 SfxApplication
* pApp
= SFX_APP();
110 pApp
->Broadcast( SfxSimpleHint( SFX_HINT_DEINITIALIZING
) );
111 pApp
->Get_Impl()->pAppDispatch
->ReleaseAll();
112 pApp
->Get_Impl()->pAppDispatch
->release();
114 css::uno::Reference
< css::uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
115 css::uno::Reference
< css::document::XEventListener
> xGlobalBroadcaster(css::frame::GlobalEventBroadcaster::create(xContext
), css::uno::UNO_QUERY_THROW
);
117 css::document::EventObject aEvent2
;
118 aEvent2
.EventName
= "OnCloseApp";
119 xGlobalBroadcaster
->notifyEvent(aEvent2
);
125 OUString SAL_CALL
SfxTerminateListener_Impl::getImplementationName() throw (RuntimeException
)
127 return OUString("com.sun.star.comp.sfx2.SfxTerminateListener");
130 ::sal_Bool SAL_CALL
SfxTerminateListener_Impl::supportsService( const OUString
& sServiceName
) throw (RuntimeException
)
132 Sequence
< OUString
> lNames
= getSupportedServiceNames();
133 ::sal_Int32 c
= lNames
.getLength();
138 if (lNames
[i
].equals(sServiceName
))
145 Sequence
< OUString
> SAL_CALL
SfxTerminateListener_Impl::getSupportedServiceNames() throw (RuntimeException
)
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
153 static const OUString
SERVICENAME("com.sun.star.frame.TerminateListener");
154 Sequence
< OUString
> lNames(1);
155 lNames
[0] = SERVICENAME
;
159 //====================================================================
161 typedef bool ( *PFunc_getSpecialCharsForEdit
)( Window
* i_pParent
, const Font
& i_rFont
, String
& o_rOutString
);
163 //====================================================================
164 // Lazy binding of the GetSpecialCharsForEdit function as it resides in
165 // a library above us.
166 //====================================================================
168 #ifndef DISABLE_DYNLOADING
170 extern "C" { static void SAL_CALL
thisModule() {} }
174 extern "C" bool GetSpecialCharsForEdit( Window
* i_pParent
, const Font
& i_rFont
, String
& o_rOutString
);
178 String
GetSpecialCharsForEdit(Window
* pParent
, const Font
& rFont
)
180 static bool bDetermineFunction
= false;
181 static PFunc_getSpecialCharsForEdit pfunc_getSpecialCharsForEdit
= 0;
183 SolarMutexGuard aGuard
;
184 if ( !bDetermineFunction
)
186 bDetermineFunction
= true;
188 #ifndef DISABLE_DYNLOADING
189 static OUString
aLibName( SVLIBRARY( "cui" ) );
190 oslModule handleMod
= osl_loadModuleRelative(
191 &thisModule
, aLibName
.pData
, 0 );
194 OUString
aSymbol( "GetSpecialCharsForEdit" );
195 pfunc_getSpecialCharsForEdit
= (PFunc_getSpecialCharsForEdit
)osl_getFunctionSymbol( handleMod
, aSymbol
.pData
);
196 DBG_ASSERT( pfunc_getSpecialCharsForEdit
, "GetSpecialCharsForEdit() not found!" );
198 pfunc_getSpecialCharsForEdit
= GetSpecialCharsForEdit
;
203 if ( pfunc_getSpecialCharsForEdit
)
204 (*pfunc_getSpecialCharsForEdit
)( pParent
, rFont
, aRet
);
208 //====================================================================
210 bool SfxApplication::Initialize_Impl()
212 RTL_LOGFILE_CONTEXT( aLog
, "sfx2 (mb93783) ::SfxApplication::Initialize_Impl" );
215 StgIo::SetErrorLink( LINK( this, SfxStorageErrHdl
, Error
) );
218 Reference
< XDesktop2
> xDesktop
= Desktop::create ( ::comphelper::getProcessComponentContext() );
219 xDesktop
->addTerminateListener( new SfxTerminateListener_Impl() );
221 Application::EnableAutoHelpId();
223 pAppData_Impl
->pAppDispatch
= new SfxStatusDispatcher
;
224 pAppData_Impl
->pAppDispatch
->acquire();
227 Help::EnableContextHelp();
228 Help::EnableExtHelp();
230 SvtLocalisationOptions aLocalisation
;
231 Application::EnableAutoMnemonic ( aLocalisation
.IsAutoMnemonic() );
232 Application::SetDialogScaleX ( (short)(aLocalisation
.GetDialogScale()) );
236 // The SimplerErrorHandler is for debugging. In the Product errors
237 // not processed are given to SFX as Errorcode 1.
238 pAppData_Impl
->m_pSimpleErrorHdl
= new SimpleErrorHandler
;
240 pAppData_Impl
->m_pToolsErrorHdl
= new SfxErrorHandler(
241 RID_ERRHDL
, ERRCODE_AREA_TOOLS
, ERRCODE_AREA_LIB1
);
243 #ifndef DISABLE_SCRIPTING
244 pAppData_Impl
->pBasicResMgr
= CreateResManager("sb");
246 pAppData_Impl
->pSvtResMgr
= CreateResManager("svt");
248 pAppData_Impl
->m_pSoErrorHdl
= new SfxErrorHandler(
249 RID_SO_ERROR_HANDLER
, ERRCODE_AREA_SO
, ERRCODE_AREA_SO_END
, pAppData_Impl
->pSvtResMgr
);
250 #ifndef DISABLE_SCRIPTING
251 pAppData_Impl
->m_pSbxErrorHdl
= new SfxErrorHandler(
252 RID_BASIC_START
, ERRCODE_AREA_SBX
, ERRCODE_AREA_SBX_END
, pAppData_Impl
->pBasicResMgr
);
254 //ensure instantiation of listener that manages the internal recently-used
256 SfxPickList::ensure();
258 DBG_ASSERT( !pAppData_Impl
->pAppDispat
, "AppDispatcher already exists" );
259 pAppData_Impl
->pAppDispat
= new SfxDispatcher((SfxDispatcher
*)0);
260 pAppData_Impl
->pSlotPool
= new SfxSlotPool
;
261 pAppData_Impl
->pTbxCtrlFac
= new SfxTbxCtrlFactArr_Impl
;
262 pAppData_Impl
->pStbCtrlFac
= new SfxStbCtrlFactArr_Impl
;
263 pAppData_Impl
->pMenuCtrlFac
= new SfxMenuCtrlFactArr_Impl
;
264 pAppData_Impl
->pViewFrames
= new SfxViewFrameArr_Impl
;
265 pAppData_Impl
->pViewShells
= new SfxViewShellArr_Impl
;
266 pAppData_Impl
->pObjShells
= new SfxObjectShellArr_Impl
;
267 pAppData_Impl
->nInterfaces
= SFX_INTERFACE_APP
+8;
268 pAppData_Impl
->pInterfaces
= new SfxInterface
*[pAppData_Impl
->nInterfaces
];
269 memset( pAppData_Impl
->pInterfaces
, 0, sizeof(SfxInterface
*) * pAppData_Impl
->nInterfaces
);
271 Registrations_Impl();
273 // Subklasse initialisieren
274 pAppData_Impl
->bDowning
= sal_False
;
277 // get CHAOS item pool...
278 pAppData_Impl
->pPool
= NoChaos::GetItemPool();
279 SetPool( pAppData_Impl
->pPool
);
281 if ( pAppData_Impl
->bDowning
)
284 // App-Dispatcher aufbauen
285 pAppData_Impl
->pAppDispat
->Push(*this);
286 pAppData_Impl
->pAppDispat
->Flush();
287 pAppData_Impl
->pAppDispat
->DoActivate_Impl( sal_True
, NULL
);
290 SolarMutexGuard aGuard
;
291 // Set special characters callback on vcl edit control
292 Edit::SetGetSpecialCharsFunction(&GetSpecialCharsForEdit
);
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */