/src/libreoffice/sfx2/source/appl/appinit.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <config_features.h> |
21 | | |
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> |
28 | | |
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> |
39 | | |
40 | | #include <vcl/specialchars.hxx> |
41 | | #include <vcl/help.hxx> |
42 | | #include <vcl/svapp.hxx> |
43 | | |
44 | | #include <unoctitm.hxx> |
45 | | #include <appdata.hxx> |
46 | | #include <sfx2/dispatch.hxx> |
47 | | #include <nochaos.hxx> |
48 | | |
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; |
53 | | |
54 | | namespace { |
55 | | |
56 | | class SfxTerminateListener_Impl : public ::cppu::WeakImplHelper< XTerminateListener, XServiceInfo > |
57 | | { |
58 | | public: |
59 | | |
60 | | // XTerminateListener |
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; |
64 | | |
65 | | // XServiceInfo |
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; |
69 | | }; |
70 | | |
71 | | } |
72 | | |
73 | | void SAL_CALL SfxTerminateListener_Impl::disposing( const EventObject& ) |
74 | 0 | { |
75 | 0 | } |
76 | | |
77 | | void SAL_CALL SfxTerminateListener_Impl::queryTermination( const EventObject& ) |
78 | 0 | { |
79 | 0 | } |
80 | | |
81 | | void SAL_CALL SfxTerminateListener_Impl::notifyTermination( const EventObject& aEvent ) |
82 | 0 | { |
83 | 0 | Reference< XDesktop > xDesktop( aEvent.Source, UNO_QUERY ); |
84 | 0 | if( xDesktop.is() ) |
85 | 0 | xDesktop->removeTerminateListener( this ); |
86 | |
|
87 | 0 | SolarMutexGuard aGuard; |
88 | 0 | utl::ConfigManager::storeConfigItems(); |
89 | |
|
90 | 0 | SfxApplication* pApp = SfxGetpApp(); |
91 | 0 | pApp->Broadcast( SfxHint( SfxHintId::Deinitializing ) ); |
92 | 0 | pApp->Get_Impl()->mxAppDispatch->ReleaseAll(); |
93 | 0 | pApp->Get_Impl()->mxAppDispatch.clear(); |
94 | |
|
95 | 0 | const css::uno::Reference< css::uno::XComponentContext >& xContext = ::comphelper::getProcessComponentContext(); |
96 | 0 | css::uno::Reference< css::document::XDocumentEventListener > xGlobalBroadcaster(css::frame::theGlobalEventBroadcaster::get(xContext), css::uno::UNO_QUERY_THROW); |
97 | |
|
98 | 0 | css::document::DocumentEvent aEvent2; |
99 | 0 | aEvent2.EventName = "OnCloseApp"; |
100 | 0 | xGlobalBroadcaster->documentEventOccured(aEvent2); |
101 | |
|
102 | 0 | delete pApp; |
103 | 0 | Application::Quit(); |
104 | 0 | } |
105 | | |
106 | | OUString SAL_CALL SfxTerminateListener_Impl::getImplementationName() |
107 | 27 | { |
108 | 27 | return u"com.sun.star.comp.sfx2.SfxTerminateListener"_ustr; |
109 | 27 | } |
110 | | |
111 | | sal_Bool SAL_CALL SfxTerminateListener_Impl::supportsService( const OUString& sServiceName ) |
112 | 0 | { |
113 | 0 | return cppu::supportsService(this, sServiceName); |
114 | 0 | } |
115 | | |
116 | | Sequence< OUString > SAL_CALL SfxTerminateListener_Impl::getSupportedServiceNames() |
117 | 0 | { |
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 |
123 | | // can react ... |
124 | 0 | return { u"com.sun.star.frame.TerminateListener"_ustr }; |
125 | 0 | } |
126 | | |
127 | | |
128 | | typedef bool (*PFunc_getSpecialCharsForEdit)(weld::Widget* i_pParent, const vcl::Font& i_rFont, OUString& o_rOutString); |
129 | | |
130 | | |
131 | | // Lazy binding of the GetSpecialCharsForEdit function as it resides in |
132 | | // a library above us. |
133 | | |
134 | | |
135 | | #ifndef DISABLE_DYNLOADING |
136 | | |
137 | | extern "C" { static void thisModule() {} } |
138 | | |
139 | | #else |
140 | | |
141 | | extern "C" bool GetSpecialCharsForEdit(weld::Widget* i_pParent, const vcl::Font& i_rFont, OUString& o_rOutString); |
142 | | |
143 | | #endif |
144 | | |
145 | | static OUString SfxGetSpecialCharsForEdit(weld::Widget* pParent, const vcl::Font& rFont) |
146 | 0 | { |
147 | 0 | static const PFunc_getSpecialCharsForEdit pfunc_getSpecialCharsForEdit = [] { |
148 | 0 | PFunc_getSpecialCharsForEdit pfunc = nullptr; |
149 | | #ifndef DISABLE_DYNLOADING |
150 | | osl::Module aMod; |
151 | | aMod.loadRelative( |
152 | | &thisModule, |
153 | | #if ENABLE_MERGELIBS |
154 | | SVLIBRARY("merged") |
155 | | #else |
156 | | SVLIBRARY("cui") |
157 | | #endif |
158 | | ); |
159 | | |
160 | | // get symbol |
161 | | pfunc = reinterpret_cast<PFunc_getSpecialCharsForEdit>(aMod.getFunctionSymbol("GetSpecialCharsForEdit")); |
162 | | DBG_ASSERT( pfunc, "GetSpecialCharsForEdit() not found!" ); |
163 | | aMod.release(); |
164 | | #else |
165 | 0 | pfunc = GetSpecialCharsForEdit; |
166 | 0 | #endif |
167 | 0 | return pfunc; |
168 | 0 | }(); |
169 | |
|
170 | 0 | OUString aRet; |
171 | 0 | if ( pfunc_getSpecialCharsForEdit ) |
172 | 0 | { |
173 | 0 | SolarMutexGuard aGuard; |
174 | 0 | (*pfunc_getSpecialCharsForEdit)( pParent, rFont, aRet ); |
175 | 0 | } |
176 | 0 | return aRet; |
177 | 0 | } |
178 | | |
179 | | |
180 | | void SfxApplication::Initialize_Impl() |
181 | 27 | { |
182 | | #ifdef TLX_VALIDATE |
183 | | StgIo::SetErrorLink( LINK( this, SfxStorageErrHdl, Error ) ); |
184 | | #endif |
185 | | |
186 | 27 | Reference < XDesktop2 > xDesktop = Desktop::create ( ::comphelper::getProcessComponentContext() ); |
187 | 27 | xDesktop->addTerminateListener( new SfxTerminateListener_Impl ); |
188 | | |
189 | 27 | pImpl->mxAppDispatch = new SfxStatusDispatcher; |
190 | | |
191 | | // SV-Look |
192 | 27 | Help::EnableContextHelp(); |
193 | 27 | Help::EnableExtHelp(); |
194 | | |
195 | 27 | pImpl->m_pToolsErrorHdl.emplace( |
196 | 27 | RID_ERRHDL, ErrCodeArea::Io, ErrCodeArea::Vcl); |
197 | | |
198 | 27 | pImpl->m_pSoErrorHdl.emplace( |
199 | 27 | RID_SO_ERROR_HANDLER, ErrCodeArea::So, ErrCodeArea::So, SvtResLocale()); |
200 | | #if HAVE_FEATURE_SCRIPTING |
201 | | pImpl->m_pSbxErrorHdl.emplace( |
202 | | RID_BASIC_START, ErrCodeArea::Sbx, ErrCodeArea::Sbx, BasResLocale()); |
203 | | #endif |
204 | | |
205 | 27 | if (!comphelper::IsFuzzing()) |
206 | 0 | { |
207 | 0 | SolarMutexGuard aGuard; |
208 | | //ensure instantiation of listener that manages the internal recently-used |
209 | | //list |
210 | 0 | pImpl->mxAppPickList.emplace(*this); |
211 | 0 | } |
212 | | |
213 | 27 | DBG_ASSERT( !pImpl->pAppDispat, "AppDispatcher already exists" ); |
214 | 27 | pImpl->pAppDispat.emplace(); |
215 | 27 | pImpl->pSlotPool.emplace(); |
216 | | |
217 | 27 | Registrations_Impl(); |
218 | | |
219 | | // initialize the subclass |
220 | 27 | pImpl->bDowning = false; |
221 | | |
222 | | // get CHAOS item pool... |
223 | 27 | pImpl->pPool = NoChaos::GetItemPool(); |
224 | 27 | SetPool( pImpl->pPool ); |
225 | | |
226 | 27 | if ( pImpl->bDowning ) |
227 | 0 | return; |
228 | | |
229 | | // build the app dispatcher |
230 | 27 | pImpl->pAppDispat->Push(*this); |
231 | 27 | pImpl->pAppDispat->Flush(); |
232 | 27 | pImpl->pAppDispat->DoActivate_Impl( true ); |
233 | | |
234 | 27 | { |
235 | 27 | SolarMutexGuard aGuard; |
236 | | // Set special characters callback on vcl edit control |
237 | 27 | vcl::SetGetSpecialCharsFunction(&SfxGetSpecialCharsForEdit); |
238 | 27 | } |
239 | 27 | } |
240 | | |
241 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |