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 .
20 #include <config_features.h>
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>
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>
48 #include <vcl/edit.hxx>
49 #include <vcl/scheduler.hxx>
51 #include <sfx2/unoctitm.hxx>
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>
69 #include "sfxpicklist.hxx"
70 #include <ctrlfactoryimpl.hxx>
71 #include <shellimpl.hxx>
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
;
78 class SfxTerminateListener_Impl
: public ::cppu::WeakImplHelper2
< XTerminateListener
, XServiceInfo
>
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
;
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
;
93 void SAL_CALL
SfxTerminateListener_Impl::disposing( const EventObject
& ) throw( RuntimeException
, std::exception
)
97 void SAL_CALL
SfxTerminateListener_Impl::queryTermination( const EventObject
& ) throw(TerminationVetoException
, RuntimeException
, std::exception
)
101 void SAL_CALL
SfxTerminateListener_Impl::notifyTermination( const EventObject
& aEvent
) throw(RuntimeException
, std::exception
)
103 Reference
< XDesktop
> xDesktop( aEvent
.Source
, UNO_QUERY
);
105 xDesktop
->removeTerminateListener( this );
107 SolarMutexGuard aGuard
;
108 utl::ConfigManager::storeConfigItems();
110 // Timers may access the SfxApplication and are only deleted in
111 // Application::Quit(), which is asynchronous (PostUserEvent) - disable!
112 Scheduler::ImplDeInitScheduler();
114 SfxApplication
* pApp
= SfxGetpApp();
115 pApp
->Broadcast( SfxSimpleHint( SFX_HINT_DEINITIALIZING
) );
116 pApp
->Get_Impl()->pAppDispatch
->ReleaseAll();
117 pApp
->Get_Impl()->pAppDispatch
->release();
119 css::uno::Reference
< css::uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
120 css::uno::Reference
< css::document::XDocumentEventListener
> xGlobalBroadcaster(css::frame::theGlobalEventBroadcaster::get(xContext
), css::uno::UNO_QUERY_THROW
);
122 css::document::DocumentEvent aEvent2
;
123 aEvent2
.EventName
= "OnCloseApp";
124 xGlobalBroadcaster
->documentEventOccured(aEvent2
);
130 OUString SAL_CALL
SfxTerminateListener_Impl::getImplementationName() throw (RuntimeException
, std::exception
)
132 return OUString("com.sun.star.comp.sfx2.SfxTerminateListener");
135 sal_Bool SAL_CALL
SfxTerminateListener_Impl::supportsService( const OUString
& sServiceName
) throw (RuntimeException
, std::exception
)
137 return cppu::supportsService(this, sServiceName
);
140 Sequence
< OUString
> SAL_CALL
SfxTerminateListener_Impl::getSupportedServiceNames() throw (RuntimeException
, std::exception
)
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
148 Sequence
< OUString
> lNames(1);
149 lNames
[0] = "com.sun.star.frame.TerminateListener";
155 typedef bool ( *PFunc_getSpecialCharsForEdit
)( vcl::Window
* i_pParent
, const vcl::Font
& i_rFont
, OUString
& o_rOutString
);
158 // Lazy binding of the GetSpecialCharsForEdit function as it resides in
159 // a library above us.
162 #ifndef DISABLE_DYNLOADING
164 extern "C" { static void SAL_CALL
thisModule() {} }
168 extern "C" bool GetSpecialCharsForEdit( vcl::Window
* i_pParent
, const vcl::Font
& i_rFont
, OUString
& o_rOutString
);
172 OUString
GetSpecialCharsForEdit(vcl::Window
* pParent
, const vcl::Font
& rFont
)
174 static bool bDetermineFunction
= false;
175 static PFunc_getSpecialCharsForEdit pfunc_getSpecialCharsForEdit
= 0;
177 SolarMutexGuard aGuard
;
178 if ( !bDetermineFunction
)
180 bDetermineFunction
= true;
182 #ifndef DISABLE_DYNLOADING
184 aMod
.loadRelative(&thisModule
, SVLIBRARY("cui"), 0);
187 OUString
aSymbol( "GetSpecialCharsForEdit" );
188 pfunc_getSpecialCharsForEdit
= reinterpret_cast<PFunc_getSpecialCharsForEdit
>(aMod
.getFunctionSymbol(aSymbol
));
189 DBG_ASSERT( pfunc_getSpecialCharsForEdit
, "GetSpecialCharsForEdit() not found!" );
192 pfunc_getSpecialCharsForEdit
= GetSpecialCharsForEdit
;
197 if ( pfunc_getSpecialCharsForEdit
)
198 (*pfunc_getSpecialCharsForEdit
)( pParent
, rFont
, aRet
);
204 bool SfxApplication::Initialize_Impl()
207 StgIo::SetErrorLink( LINK( this, SfxStorageErrHdl
, Error
) );
210 Reference
< XDesktop2
> xDesktop
= Desktop::create ( ::comphelper::getProcessComponentContext() );
211 xDesktop
->addTerminateListener( new SfxTerminateListener_Impl() );
213 Application::EnableAutoHelpId();
215 pAppData_Impl
->pAppDispatch
= new SfxStatusDispatcher
;
216 pAppData_Impl
->pAppDispatch
->acquire();
219 Help::EnableContextHelp();
220 Help::EnableExtHelp();
222 SvtLocalisationOptions aLocalisation
;
223 Application::EnableAutoMnemonic ( aLocalisation
.IsAutoMnemonic() );
224 Application::SetDialogScaleX ( (short)(aLocalisation
.GetDialogScale()) );
226 pAppData_Impl
->m_pToolsErrorHdl
= new SfxErrorHandler(
227 RID_ERRHDL
, ERRCODE_AREA_TOOLS
, ERRCODE_AREA_LIB1
);
229 #if HAVE_FEATURE_SCRIPTING
230 pAppData_Impl
->pBasicResMgr
= ResMgr::CreateResMgr("sb");
232 pAppData_Impl
->pSvtResMgr
= ResMgr::CreateResMgr("svt");
234 pAppData_Impl
->m_pSoErrorHdl
= new SfxErrorHandler(
235 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 RID_BASIC_START
, ERRCODE_AREA_SBX
, ERRCODE_AREA_SBX_END
, pAppData_Impl
->pBasicResMgr
);
240 //ensure instantiation of listener that manages the internal recently-used
242 SfxPickList::ensure();
244 DBG_ASSERT( !pAppData_Impl
->pAppDispat
, "AppDispatcher already exists" );
245 pAppData_Impl
->pAppDispat
= new SfxDispatcher((SfxDispatcher
*)0);
246 pAppData_Impl
->pSlotPool
= new SfxSlotPool
;
247 pAppData_Impl
->pTbxCtrlFac
= new SfxTbxCtrlFactArr_Impl
;
248 pAppData_Impl
->pStbCtrlFac
= new SfxStbCtrlFactArr_Impl
;
249 pAppData_Impl
->pMenuCtrlFac
= new SfxMenuCtrlFactArr_Impl
;
250 pAppData_Impl
->pViewFrames
= new SfxViewFrameArr_Impl
;
251 pAppData_Impl
->pViewShells
= new SfxViewShellArr_Impl
;
252 pAppData_Impl
->pObjShells
= new SfxObjectShellArr_Impl
;
253 pAppData_Impl
->nInterfaces
= SFX_INTERFACE_APP
+8;
254 pAppData_Impl
->pInterfaces
= new SfxInterface
*[pAppData_Impl
->nInterfaces
];
255 memset( pAppData_Impl
->pInterfaces
, 0, sizeof(SfxInterface
*) * pAppData_Impl
->nInterfaces
);
257 Registrations_Impl();
259 // Subklasse initialisieren
260 pAppData_Impl
->bDowning
= false;
262 // get CHAOS item pool...
263 pAppData_Impl
->pPool
= NoChaos::GetItemPool();
264 SetPool( pAppData_Impl
->pPool
);
266 if ( pAppData_Impl
->bDowning
)
269 // App-Dispatcher aufbauen
270 pAppData_Impl
->pAppDispat
->Push(*this);
271 pAppData_Impl
->pAppDispat
->Flush();
272 pAppData_Impl
->pAppDispat
->DoActivate_Impl( true, NULL
);
275 SolarMutexGuard aGuard
;
276 // Set special characters callback on vcl edit control
277 Edit::SetGetSpecialCharsFunction(&GetSpecialCharsForEdit
);
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */