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 <basic/sbdef.hxx>
30 #include <comphelper/configuration.hxx>
31 #include <tools/svlibrary.h>
32 #include <svtools/soerr.hxx>
33 #include <unotools/configmgr.hxx>
34 #include <svtools/ehdl.hxx>
35 #include <comphelper/processfactory.hxx>
36 #include <osl/module.hxx>
37 #include <cppuhelper/implbase.hxx>
38 #include <cppuhelper/supportsservice.hxx>
40 #include <vcl/specialchars.hxx>
41 #include <vcl/help.hxx>
42 #include <vcl/svapp.hxx>
44 #include <unoctitm.hxx>
45 #include <appdata.hxx>
46 #include <sfx2/dispatch.hxx>
47 #include <nochaos.hxx>
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::frame
;
51 using namespace ::com::sun::star::lang
;
52 using namespace ::com::sun::star
;
56 class SfxTerminateListener_Impl
: public ::cppu::WeakImplHelper
< XTerminateListener
, XServiceInfo
>
61 virtual void SAL_CALL
queryTermination( const EventObject
& aEvent
) override
;
62 virtual void SAL_CALL
notifyTermination( const EventObject
& aEvent
) override
;
63 virtual void SAL_CALL
disposing( const EventObject
& Source
) override
;
66 virtual OUString SAL_CALL
getImplementationName() override
;
67 virtual sal_Bool SAL_CALL
supportsService( const OUString
& sServiceName
) override
;
68 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
73 void SAL_CALL
SfxTerminateListener_Impl::disposing( const EventObject
& )
77 void SAL_CALL
SfxTerminateListener_Impl::queryTermination( const EventObject
& )
81 void SAL_CALL
SfxTerminateListener_Impl::notifyTermination( const EventObject
& aEvent
)
83 Reference
< XDesktop
> xDesktop( aEvent
.Source
, UNO_QUERY
);
85 xDesktop
->removeTerminateListener( this );
87 SolarMutexGuard aGuard
;
88 utl::ConfigManager::storeConfigItems();
90 SfxApplication
* pApp
= SfxGetpApp();
91 pApp
->Broadcast( SfxHint( SfxHintId::Deinitializing
) );
92 pApp
->Get_Impl()->mxAppDispatch
->ReleaseAll();
93 pApp
->Get_Impl()->mxAppDispatch
.clear();
95 const css::uno::Reference
< css::uno::XComponentContext
>& xContext
= ::comphelper::getProcessComponentContext();
96 css::uno::Reference
< css::document::XDocumentEventListener
> xGlobalBroadcaster(css::frame::theGlobalEventBroadcaster::get(xContext
), css::uno::UNO_QUERY_THROW
);
98 css::document::DocumentEvent aEvent2
;
99 aEvent2
.EventName
= "OnCloseApp";
100 xGlobalBroadcaster
->documentEventOccured(aEvent2
);
106 OUString SAL_CALL
SfxTerminateListener_Impl::getImplementationName()
108 return u
"com.sun.star.comp.sfx2.SfxTerminateListener"_ustr
;
111 sal_Bool SAL_CALL
SfxTerminateListener_Impl::supportsService( const OUString
& sServiceName
)
113 return cppu::supportsService(this, sServiceName
);
116 Sequence
< OUString
> SAL_CALL
SfxTerminateListener_Impl::getSupportedServiceNames()
118 // Note: That service does not really exists .-)
119 // But this implementation is not thought to be registered really within our service.rdb.
120 // At least we need the implementation name only to identify these service at the global desktop instance.
121 // The desktop must know, which listener will terminate the SfxApplication in real !
122 // It must call this special listener as last one ... otherwise we shutdown the SfxApplication BEFORE other listener
124 return { u
"com.sun.star.frame.TerminateListener"_ustr
};
128 typedef bool (*PFunc_getSpecialCharsForEdit
)(weld::Widget
* i_pParent
, const vcl::Font
& i_rFont
, OUString
& o_rOutString
);
131 // Lazy binding of the GetSpecialCharsForEdit function as it resides in
132 // a library above us.
135 #ifndef DISABLE_DYNLOADING
137 extern "C" { static void thisModule() {} }
141 extern "C" bool GetSpecialCharsForEdit(weld::Widget
* i_pParent
, const vcl::Font
& i_rFont
, OUString
& o_rOutString
);
145 static OUString
SfxGetSpecialCharsForEdit(weld::Widget
* pParent
, const vcl::Font
& rFont
)
147 static const PFunc_getSpecialCharsForEdit pfunc_getSpecialCharsForEdit
= [] {
148 PFunc_getSpecialCharsForEdit pfunc
= nullptr;
149 #ifndef DISABLE_DYNLOADING
151 aMod
.loadRelative(&thisModule
, SVLIBRARY("cui"));
154 pfunc
= reinterpret_cast<PFunc_getSpecialCharsForEdit
>(aMod
.getFunctionSymbol("GetSpecialCharsForEdit"));
155 DBG_ASSERT( pfunc
, "GetSpecialCharsForEdit() not found!" );
158 pfunc
= GetSpecialCharsForEdit
;
164 if ( pfunc_getSpecialCharsForEdit
)
166 SolarMutexGuard aGuard
;
167 (*pfunc_getSpecialCharsForEdit
)( pParent
, rFont
, aRet
);
173 void SfxApplication::Initialize_Impl()
176 StgIo::SetErrorLink( LINK( this, SfxStorageErrHdl
, Error
) );
179 Reference
< XDesktop2
> xDesktop
= Desktop::create ( ::comphelper::getProcessComponentContext() );
180 xDesktop
->addTerminateListener( new SfxTerminateListener_Impl
);
182 pImpl
->mxAppDispatch
= new SfxStatusDispatcher
;
185 Help::EnableContextHelp();
186 Help::EnableExtHelp();
188 pImpl
->m_pToolsErrorHdl
.emplace(
189 RID_ERRHDL
, ErrCodeArea::Io
, ErrCodeArea::Vcl
);
191 pImpl
->m_pSoErrorHdl
.emplace(
192 RID_SO_ERROR_HANDLER
, ErrCodeArea::So
, ErrCodeArea::So
, SvtResLocale());
193 #if HAVE_FEATURE_SCRIPTING
194 pImpl
->m_pSbxErrorHdl
.emplace(
195 RID_BASIC_START
, ErrCodeArea::Sbx
, ErrCodeArea::Sbx
, BasResLocale());
198 if (!comphelper::IsFuzzing())
200 SolarMutexGuard aGuard
;
201 //ensure instantiation of listener that manages the internal recently-used
203 pImpl
->mxAppPickList
.emplace(*this);
206 DBG_ASSERT( !pImpl
->pAppDispat
, "AppDispatcher already exists" );
207 pImpl
->pAppDispat
.emplace();
208 pImpl
->pSlotPool
.emplace();
210 Registrations_Impl();
212 // initialize the subclass
213 pImpl
->bDowning
= false;
215 // get CHAOS item pool...
216 pImpl
->pPool
= NoChaos::GetItemPool();
217 SetPool( pImpl
->pPool
);
219 if ( pImpl
->bDowning
)
222 // build the app dispatcher
223 pImpl
->pAppDispat
->Push(*this);
224 pImpl
->pAppDispat
->Flush();
225 pImpl
->pAppDispat
->DoActivate_Impl( true );
228 SolarMutexGuard aGuard
;
229 // Set special characters callback on vcl edit control
230 vcl::SetGetSpecialCharsFunction(&SfxGetSpecialCharsForEdit
);
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */