LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sfx2 / source / appl / appinit.cxx
bloba20bec46333452f24a40b7ca994f40c89d44671f
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>
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::frame;
52 using namespace ::com::sun::star::lang;
53 using namespace ::com::sun::star;
55 namespace {
57 class SfxTerminateListener_Impl : public ::cppu::WeakImplHelper< XTerminateListener, XServiceInfo >
59 public:
61 // XTerminateListener
62 virtual void SAL_CALL queryTermination( const EventObject& aEvent ) override;
63 virtual void SAL_CALL notifyTermination( const EventObject& aEvent ) override;
64 virtual void SAL_CALL disposing( const EventObject& Source ) override;
66 // XServiceInfo
67 virtual OUString SAL_CALL getImplementationName() override;
68 virtual sal_Bool SAL_CALL supportsService( const OUString& sServiceName ) override;
69 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
74 void SAL_CALL SfxTerminateListener_Impl::disposing( const EventObject& )
78 void SAL_CALL SfxTerminateListener_Impl::queryTermination( const EventObject& )
82 void SAL_CALL SfxTerminateListener_Impl::notifyTermination( const EventObject& aEvent )
84 Reference< XDesktop > xDesktop( aEvent.Source, UNO_QUERY );
85 if( xDesktop.is() )
86 xDesktop->removeTerminateListener( this );
88 SolarMutexGuard aGuard;
89 utl::ConfigManager::storeConfigItems();
91 SfxApplication* pApp = SfxGetpApp();
92 pApp->Broadcast( SfxHint( SfxHintId::Deinitializing ) );
93 pApp->Get_Impl()->mxAppDispatch->ReleaseAll();
94 pApp->Get_Impl()->mxAppDispatch.clear();
96 css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
97 css::uno::Reference< css::document::XDocumentEventListener > xGlobalBroadcaster(css::frame::theGlobalEventBroadcaster::get(xContext), css::uno::UNO_QUERY_THROW);
99 css::document::DocumentEvent aEvent2;
100 aEvent2.EventName = "OnCloseApp";
101 xGlobalBroadcaster->documentEventOccured(aEvent2);
103 delete pApp;
104 Application::Quit();
107 OUString SAL_CALL SfxTerminateListener_Impl::getImplementationName()
109 return "com.sun.star.comp.sfx2.SfxTerminateListener";
112 sal_Bool SAL_CALL SfxTerminateListener_Impl::supportsService( const OUString& sServiceName )
114 return cppu::supportsService(this, sServiceName);
117 Sequence< OUString > SAL_CALL SfxTerminateListener_Impl::getSupportedServiceNames()
119 // Note: That service does not really exists .-)
120 // But this implementation is not thought to be registered really within our service.rdb.
121 // At least we need the implementation name only to identify these service at the global desktop instance.
122 // The desktop must know, which listener will terminate the SfxApplication in real !
123 // It must call this special listener as last one ... otherwise we shutdown the SfxApplication BEFORE other listener
124 // can react ...
125 return { "com.sun.star.frame.TerminateListener" };
129 typedef bool (*PFunc_getSpecialCharsForEdit)(weld::Widget* i_pParent, const vcl::Font& i_rFont, OUString& o_rOutString);
132 // Lazy binding of the GetSpecialCharsForEdit function as it resides in
133 // a library above us.
136 #ifndef DISABLE_DYNLOADING
138 extern "C" { static void thisModule() {} }
140 #else
142 extern "C" bool GetSpecialCharsForEdit(weld::Widget* i_pParent, const vcl::Font& i_rFont, OUString& o_rOutString);
144 #endif
146 static OUString SfxGetSpecialCharsForEdit(weld::Widget* pParent, const vcl::Font& rFont)
148 static const PFunc_getSpecialCharsForEdit pfunc_getSpecialCharsForEdit = [] {
149 PFunc_getSpecialCharsForEdit pfunc = nullptr;
150 #ifndef DISABLE_DYNLOADING
151 osl::Module aMod;
152 aMod.loadRelative(&thisModule, SVLIBRARY("cui"));
154 // get symbol
155 pfunc = reinterpret_cast<PFunc_getSpecialCharsForEdit>(aMod.getFunctionSymbol("GetSpecialCharsForEdit"));
156 DBG_ASSERT( pfunc, "GetSpecialCharsForEdit() not found!" );
157 aMod.release();
158 #else
159 pfunc = GetSpecialCharsForEdit;
160 #endif
161 return pfunc;
162 }();
164 OUString aRet;
165 if ( pfunc_getSpecialCharsForEdit )
167 SolarMutexGuard aGuard;
168 (*pfunc_getSpecialCharsForEdit)( pParent, rFont, aRet );
170 return aRet;
174 void SfxApplication::Initialize_Impl()
176 #ifdef TLX_VALIDATE
177 StgIo::SetErrorLink( LINK( this, SfxStorageErrHdl, Error ) );
178 #endif
180 Reference < XDesktop2 > xDesktop = Desktop::create ( ::comphelper::getProcessComponentContext() );
181 xDesktop->addTerminateListener( new SfxTerminateListener_Impl );
183 pImpl->mxAppDispatch = new SfxStatusDispatcher;
185 // SV-Look
186 Help::EnableContextHelp();
187 Help::EnableExtHelp();
189 pImpl->m_pToolsErrorHdl.emplace(
190 RID_ERRHDL, ErrCodeArea::Io, ErrCodeArea::Vcl);
192 pImpl->m_pSoErrorHdl.emplace(
193 RID_SO_ERROR_HANDLER, ErrCodeArea::So, ErrCodeArea::So, SvtResLocale());
194 #if HAVE_FEATURE_SCRIPTING
195 pImpl->m_pSbxErrorHdl.emplace(
196 RID_BASIC_START, ErrCodeArea::Sbx, ErrCodeArea::Sbx, BasResLocale());
197 #endif
199 if (!utl::ConfigManager::IsFuzzing())
201 SolarMutexGuard aGuard;
202 //ensure instantiation of listener that manages the internal recently-used
203 //list
204 pImpl->mxAppPickList.emplace(*this);
207 DBG_ASSERT( !pImpl->pAppDispat, "AppDispatcher already exists" );
208 pImpl->pAppDispat.emplace();
209 pImpl->pSlotPool.emplace();
211 Registrations_Impl();
213 // initialize the subclass
214 pImpl->bDowning = false;
216 // get CHAOS item pool...
217 pImpl->pPool = NoChaos::GetItemPool();
218 SetPool( pImpl->pPool );
220 if ( pImpl->bDowning )
221 return;
223 // build the app dispatcher
224 pImpl->pAppDispat->Push(*this);
225 pImpl->pAppDispat->Flush();
226 pImpl->pAppDispat->DoActivate_Impl( true );
229 SolarMutexGuard aGuard;
230 // Set special characters callback on vcl edit control
231 vcl::SetGetSpecialCharsFunction(&SfxGetSpecialCharsForEdit);
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */