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>
45 #include <cppuhelper/supportsservice.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>
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 return cppu::supportsService(this, sServiceName
);
135 Sequence
< OUString
> SAL_CALL
SfxTerminateListener_Impl::getSupportedServiceNames() throw (RuntimeException
)
137 // Note: That service does not realy exists .-)
138 // But this implementation is not thought to be registered realy within our service.rdb.
139 // At least we need the implementation name only to identify these service at the global desktop instance.
140 // The desktop must know, which listener will terminate the SfxApplication in real !
141 // It must call this special listener as last one ... otherwise we shutdown the SfxApplication BEFORE other listener
143 static const OUString
SERVICENAME("com.sun.star.frame.TerminateListener");
144 Sequence
< OUString
> lNames(1);
145 lNames
[0] = SERVICENAME
;
149 //====================================================================
151 typedef bool ( *PFunc_getSpecialCharsForEdit
)( Window
* i_pParent
, const Font
& i_rFont
, OUString
& o_rOutString
);
153 //====================================================================
154 // Lazy binding of the GetSpecialCharsForEdit function as it resides in
155 // a library above us.
156 //====================================================================
158 #ifndef DISABLE_DYNLOADING
160 extern "C" { static void SAL_CALL
thisModule() {} }
164 extern "C" bool GetSpecialCharsForEdit( Window
* i_pParent
, const Font
& i_rFont
, OUString
& o_rOutString
);
168 OUString
GetSpecialCharsForEdit(Window
* pParent
, const Font
& rFont
)
170 static bool bDetermineFunction
= false;
171 static PFunc_getSpecialCharsForEdit pfunc_getSpecialCharsForEdit
= 0;
173 SolarMutexGuard aGuard
;
174 if ( !bDetermineFunction
)
176 bDetermineFunction
= true;
178 #ifndef DISABLE_DYNLOADING
179 static OUString
aLibName( SVLIBRARY( "cui" ) );
180 oslModule handleMod
= osl_loadModuleRelative(
181 &thisModule
, aLibName
.pData
, 0 );
184 OUString
aSymbol( "GetSpecialCharsForEdit" );
185 pfunc_getSpecialCharsForEdit
= (PFunc_getSpecialCharsForEdit
)osl_getFunctionSymbol( handleMod
, aSymbol
.pData
);
186 DBG_ASSERT( pfunc_getSpecialCharsForEdit
, "GetSpecialCharsForEdit() not found!" );
188 pfunc_getSpecialCharsForEdit
= GetSpecialCharsForEdit
;
193 if ( pfunc_getSpecialCharsForEdit
)
194 (*pfunc_getSpecialCharsForEdit
)( pParent
, rFont
, aRet
);
198 //====================================================================
200 bool SfxApplication::Initialize_Impl()
202 SAL_INFO( "sfx.appl", "sfx2 (mb93783) ::SfxApplication::Initialize_Impl" );
205 StgIo::SetErrorLink( LINK( this, SfxStorageErrHdl
, Error
) );
208 Reference
< XDesktop2
> xDesktop
= Desktop::create ( ::comphelper::getProcessComponentContext() );
209 xDesktop
->addTerminateListener( new SfxTerminateListener_Impl() );
211 Application::EnableAutoHelpId();
213 pAppData_Impl
->pAppDispatch
= new SfxStatusDispatcher
;
214 pAppData_Impl
->pAppDispatch
->acquire();
217 Help::EnableContextHelp();
218 Help::EnableExtHelp();
220 SvtLocalisationOptions aLocalisation
;
221 Application::EnableAutoMnemonic ( aLocalisation
.IsAutoMnemonic() );
222 Application::SetDialogScaleX ( (short)(aLocalisation
.GetDialogScale()) );
226 // The SimplerErrorHandler is for debugging. In the Product errors
227 // not processed are given to SFX as Errorcode 1.
228 pAppData_Impl
->m_pSimpleErrorHdl
= new SimpleErrorHandler
;
230 pAppData_Impl
->m_pToolsErrorHdl
= new SfxErrorHandler(
231 RID_ERRHDL
, ERRCODE_AREA_TOOLS
, ERRCODE_AREA_LIB1
);
233 #ifndef DISABLE_SCRIPTING
234 pAppData_Impl
->pBasicResMgr
= CreateResManager("sb");
236 pAppData_Impl
->pSvtResMgr
= CreateResManager("svt");
238 pAppData_Impl
->m_pSoErrorHdl
= new SfxErrorHandler(
239 RID_SO_ERROR_HANDLER
, ERRCODE_AREA_SO
, ERRCODE_AREA_SO_END
, pAppData_Impl
->pSvtResMgr
);
240 #ifndef DISABLE_SCRIPTING
241 pAppData_Impl
->m_pSbxErrorHdl
= new SfxErrorHandler(
242 RID_BASIC_START
, ERRCODE_AREA_SBX
, ERRCODE_AREA_SBX_END
, pAppData_Impl
->pBasicResMgr
);
244 //ensure instantiation of listener that manages the internal recently-used
246 SfxPickList::ensure();
248 DBG_ASSERT( !pAppData_Impl
->pAppDispat
, "AppDispatcher already exists" );
249 pAppData_Impl
->pAppDispat
= new SfxDispatcher((SfxDispatcher
*)0);
250 pAppData_Impl
->pSlotPool
= new SfxSlotPool
;
251 pAppData_Impl
->pTbxCtrlFac
= new SfxTbxCtrlFactArr_Impl
;
252 pAppData_Impl
->pStbCtrlFac
= new SfxStbCtrlFactArr_Impl
;
253 pAppData_Impl
->pMenuCtrlFac
= new SfxMenuCtrlFactArr_Impl
;
254 pAppData_Impl
->pViewFrames
= new SfxViewFrameArr_Impl
;
255 pAppData_Impl
->pViewShells
= new SfxViewShellArr_Impl
;
256 pAppData_Impl
->pObjShells
= new SfxObjectShellArr_Impl
;
257 pAppData_Impl
->nInterfaces
= SFX_INTERFACE_APP
+8;
258 pAppData_Impl
->pInterfaces
= new SfxInterface
*[pAppData_Impl
->nInterfaces
];
259 memset( pAppData_Impl
->pInterfaces
, 0, sizeof(SfxInterface
*) * pAppData_Impl
->nInterfaces
);
261 Registrations_Impl();
263 // Subklasse initialisieren
264 pAppData_Impl
->bDowning
= sal_False
;
267 // get CHAOS item pool...
268 pAppData_Impl
->pPool
= NoChaos::GetItemPool();
269 SetPool( pAppData_Impl
->pPool
);
271 if ( pAppData_Impl
->bDowning
)
274 // App-Dispatcher aufbauen
275 pAppData_Impl
->pAppDispat
->Push(*this);
276 pAppData_Impl
->pAppDispat
->Flush();
277 pAppData_Impl
->pAppDispat
->DoActivate_Impl( sal_True
, NULL
);
280 SolarMutexGuard aGuard
;
281 // Set special characters callback on vcl edit control
282 Edit::SetGetSpecialCharsFunction(&GetSpecialCharsForEdit
);
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */