Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / sfx2 / source / appl / appinit.cxx
blobfbecd9d66b61d91d9988355b5294412944c1f0d0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <tools/svlibrary.h>
31 #include <svtools/soerr.hxx>
32 #include <unotools/configmgr.hxx>
33 #include <svtools/ehdl.hxx>
34 #include <comphelper/processfactory.hxx>
35 #include <osl/module.hxx>
36 #include <cppuhelper/implbase.hxx>
37 #include <cppuhelper/supportsservice.hxx>
39 #include <vcl/specialchars.hxx>
40 #include <vcl/help.hxx>
41 #include <vcl/svapp.hxx>
43 #include <unoctitm.hxx>
44 #include <appdata.hxx>
45 #include <sfx2/dispatch.hxx>
46 #include <sfx2/msgpool.hxx>
47 #include <nochaos.hxx>
48 #include <sfxpicklist.hxx>
49 #include <ctrlfactoryimpl.hxx>
50 #include <shellimpl.hxx>
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::frame;
54 using namespace ::com::sun::star::lang;
55 using namespace ::com::sun::star;
57 namespace {
59 class SfxTerminateListener_Impl : public ::cppu::WeakImplHelper< XTerminateListener, XServiceInfo >
61 public:
63 // XTerminateListener
64 virtual void SAL_CALL queryTermination( const EventObject& aEvent ) override;
65 virtual void SAL_CALL notifyTermination( const EventObject& aEvent ) override;
66 virtual void SAL_CALL disposing( const EventObject& Source ) override;
68 // XServiceInfo
69 virtual OUString SAL_CALL getImplementationName() override;
70 virtual sal_Bool SAL_CALL supportsService( const OUString& sServiceName ) override;
71 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
76 void SAL_CALL SfxTerminateListener_Impl::disposing( const EventObject& )
80 void SAL_CALL SfxTerminateListener_Impl::queryTermination( const EventObject& )
84 void SAL_CALL SfxTerminateListener_Impl::notifyTermination( const EventObject& aEvent )
86 Reference< XDesktop > xDesktop( aEvent.Source, UNO_QUERY );
87 if( xDesktop.is() )
88 xDesktop->removeTerminateListener( this );
90 SolarMutexGuard aGuard;
91 utl::ConfigManager::storeConfigItems();
93 SfxApplication* pApp = SfxGetpApp();
94 pApp->Broadcast( SfxHint( SfxHintId::Deinitializing ) );
95 pApp->Get_Impl()->mxAppDispatch->ReleaseAll();
96 pApp->Get_Impl()->mxAppDispatch.clear();
98 css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
99 css::uno::Reference< css::document::XDocumentEventListener > xGlobalBroadcaster(css::frame::theGlobalEventBroadcaster::get(xContext), css::uno::UNO_QUERY_THROW);
101 css::document::DocumentEvent aEvent2;
102 aEvent2.EventName = "OnCloseApp";
103 xGlobalBroadcaster->documentEventOccured(aEvent2);
105 delete pApp;
106 Application::Quit();
109 OUString SAL_CALL SfxTerminateListener_Impl::getImplementationName()
111 return "com.sun.star.comp.sfx2.SfxTerminateListener";
114 sal_Bool SAL_CALL SfxTerminateListener_Impl::supportsService( const OUString& sServiceName )
116 return cppu::supportsService(this, sServiceName);
119 Sequence< OUString > SAL_CALL SfxTerminateListener_Impl::getSupportedServiceNames()
121 // Note: That service does not really exists .-)
122 // But this implementation is not thought to be registered really within our service.rdb.
123 // At least we need the implementation name only to identify these service at the global desktop instance.
124 // The desktop must know, which listener will terminate the SfxApplication in real !
125 // It must call this special listener as last one ... otherwise we shutdown the SfxApplication BEFORE other listener
126 // can react ...
127 return { "com.sun.star.frame.TerminateListener" };
131 typedef bool (*PFunc_getSpecialCharsForEdit)(weld::Widget* i_pParent, const vcl::Font& i_rFont, OUString& o_rOutString);
134 // Lazy binding of the GetSpecialCharsForEdit function as it resides in
135 // a library above us.
138 #ifndef DISABLE_DYNLOADING
140 extern "C" { static void thisModule() {} }
142 #else
144 extern "C" bool GetSpecialCharsForEdit(weld::Widget* i_pParent, const vcl::Font& i_rFont, OUString& o_rOutString);
146 #endif
148 static OUString SfxGetSpecialCharsForEdit(weld::Widget* pParent, const vcl::Font& rFont)
150 static bool bDetermineFunction = false;
151 static PFunc_getSpecialCharsForEdit pfunc_getSpecialCharsForEdit = nullptr;
153 SolarMutexGuard aGuard;
154 if ( !bDetermineFunction )
156 bDetermineFunction = true;
158 #ifndef DISABLE_DYNLOADING
159 osl::Module aMod;
160 aMod.loadRelative(&thisModule, SVLIBRARY("cui"));
162 // get symbol
163 pfunc_getSpecialCharsForEdit = reinterpret_cast<PFunc_getSpecialCharsForEdit>(aMod.getFunctionSymbol("GetSpecialCharsForEdit"));
164 DBG_ASSERT( pfunc_getSpecialCharsForEdit, "GetSpecialCharsForEdit() not found!" );
165 aMod.release();
166 #else
167 pfunc_getSpecialCharsForEdit = GetSpecialCharsForEdit;
168 #endif
171 OUString aRet;
172 if ( pfunc_getSpecialCharsForEdit )
173 (*pfunc_getSpecialCharsForEdit)( pParent, rFont, aRet );
174 return aRet;
178 void SfxApplication::Initialize_Impl()
180 #ifdef TLX_VALIDATE
181 StgIo::SetErrorLink( LINK( this, SfxStorageErrHdl, Error ) );
182 #endif
184 Reference < XDesktop2 > xDesktop = Desktop::create ( ::comphelper::getProcessComponentContext() );
185 xDesktop->addTerminateListener( new SfxTerminateListener_Impl );
187 pImpl->mxAppDispatch = new SfxStatusDispatcher;
189 // SV-Look
190 Help::EnableContextHelp();
191 Help::EnableExtHelp();
193 pImpl->m_pToolsErrorHdl.reset(new SfxErrorHandler(
194 RID_ERRHDL, ErrCodeArea::Io, ErrCodeArea::Vcl));
196 pImpl->m_pSoErrorHdl.reset(new SfxErrorHandler(
197 RID_SO_ERROR_HANDLER, ErrCodeArea::So, ErrCodeArea::So, SvtResLocale()));
198 #if HAVE_FEATURE_SCRIPTING
199 pImpl->m_pSbxErrorHdl.reset(new SfxErrorHandler(
200 RID_BASIC_START, ErrCodeArea::Sbx, ErrCodeArea::Sbx, BasResLocale()));
201 #endif
203 if (!utl::ConfigManager::IsFuzzing())
205 SolarMutexGuard aGuard;
206 //ensure instantiation of listener that manages the internal recently-used
207 //list
208 pImpl->mxAppPickList.reset(new SfxPickList(*this));
211 DBG_ASSERT( !pImpl->pAppDispat, "AppDispatcher already exists" );
212 pImpl->pAppDispat.reset(new SfxDispatcher);
213 pImpl->pSlotPool.reset(new SfxSlotPool);
214 pImpl->pTbxCtrlFac.reset(new SfxTbxCtrlFactArr_Impl);
215 pImpl->pStbCtrlFac.reset(new SfxStbCtrlFactArr_Impl);
216 pImpl->pViewFrames.reset(new SfxViewFrameArr_Impl);
217 pImpl->pViewShells.reset(new SfxViewShellArr_Impl);
218 pImpl->pObjShells.reset(new SfxObjectShellArr_Impl);
220 Registrations_Impl();
222 // initialize the subclass
223 pImpl->bDowning = false;
225 // get CHAOS item pool...
226 pImpl->pPool = NoChaos::GetItemPool();
227 SetPool( pImpl->pPool );
229 if ( pImpl->bDowning )
230 return;
232 // build the app dispatcher
233 pImpl->pAppDispat->Push(*this);
234 pImpl->pAppDispat->Flush();
235 pImpl->pAppDispat->DoActivate_Impl( true );
238 SolarMutexGuard aGuard;
239 // Set special characters callback on vcl edit control
240 vcl::SetGetSpecialCharsFunction(&SfxGetSpecialCharsForEdit);
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */