LibreOffice Module sfx2 (master) 1
appinit.cxx
Go to the documentation of this file.
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 <tools/svlibrary.h>
31#include <svtools/soerr.hxx>
33#include <svtools/ehdl.hxx>
35#include <osl/module.hxx>
38
39#include <vcl/specialchars.hxx>
40#include <vcl/help.hxx>
41#include <vcl/svapp.hxx>
42
43#include <unoctitm.hxx>
44#include <appdata.hxx>
45#include <sfx2/dispatch.hxx>
46#include <nochaos.hxx>
47
48using namespace ::com::sun::star::uno;
49using namespace ::com::sun::star::frame;
50using namespace ::com::sun::star::lang;
51using namespace ::com::sun::star;
52
53namespace {
54
55class SfxTerminateListener_Impl : public ::cppu::WeakImplHelper< XTerminateListener, XServiceInfo >
56{
57public:
58
59 // XTerminateListener
60 virtual void SAL_CALL queryTermination( const EventObject& aEvent ) override;
61 virtual void SAL_CALL notifyTermination( const EventObject& aEvent ) override;
62 virtual void SAL_CALL disposing( const EventObject& Source ) override;
63
64 // XServiceInfo
65 virtual OUString SAL_CALL getImplementationName() override;
66 virtual sal_Bool SAL_CALL supportsService( const OUString& sServiceName ) override;
67 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
68};
69
70}
71
72void SAL_CALL SfxTerminateListener_Impl::disposing( const EventObject& )
73{
74}
75
76void SAL_CALL SfxTerminateListener_Impl::queryTermination( const EventObject& )
77{
78}
79
80void SAL_CALL SfxTerminateListener_Impl::notifyTermination( const EventObject& aEvent )
81{
82 Reference< XDesktop > xDesktop( aEvent.Source, UNO_QUERY );
83 if( xDesktop.is() )
84 xDesktop->removeTerminateListener( this );
85
86 SolarMutexGuard aGuard;
88
89 SfxApplication* pApp = SfxGetpApp();
90 pApp->Broadcast( SfxHint( SfxHintId::Deinitializing ) );
91 pApp->Get_Impl()->mxAppDispatch->ReleaseAll();
92 pApp->Get_Impl()->mxAppDispatch.clear();
93
94 css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
95 css::uno::Reference< css::document::XDocumentEventListener > xGlobalBroadcaster(css::frame::theGlobalEventBroadcaster::get(xContext), css::uno::UNO_QUERY_THROW);
96
97 css::document::DocumentEvent aEvent2;
98 aEvent2.EventName = "OnCloseApp";
99 xGlobalBroadcaster->documentEventOccured(aEvent2);
100
101 delete pApp;
103}
104
105OUString SAL_CALL SfxTerminateListener_Impl::getImplementationName()
106{
107 return "com.sun.star.comp.sfx2.SfxTerminateListener";
108}
109
110sal_Bool SAL_CALL SfxTerminateListener_Impl::supportsService( const OUString& sServiceName )
111{
112 return cppu::supportsService(this, sServiceName);
113}
114
115Sequence< OUString > SAL_CALL SfxTerminateListener_Impl::getSupportedServiceNames()
116{
117 // Note: That service does not really exists .-)
118 // But this implementation is not thought to be registered really within our service.rdb.
119 // At least we need the implementation name only to identify these service at the global desktop instance.
120 // The desktop must know, which listener will terminate the SfxApplication in real !
121 // It must call this special listener as last one ... otherwise we shutdown the SfxApplication BEFORE other listener
122 // can react ...
123 return { "com.sun.star.frame.TerminateListener" };
124}
125
126
127typedef bool (*PFunc_getSpecialCharsForEdit)(weld::Widget* i_pParent, const vcl::Font& i_rFont, OUString& o_rOutString);
128
129
130// Lazy binding of the GetSpecialCharsForEdit function as it resides in
131// a library above us.
132
133
134#ifndef DISABLE_DYNLOADING
135
136extern "C" { static void thisModule() {} }
137
138#else
139
140extern "C" bool GetSpecialCharsForEdit(weld::Widget* i_pParent, const vcl::Font& i_rFont, OUString& o_rOutString);
141
142#endif
143
144static OUString SfxGetSpecialCharsForEdit(weld::Widget* pParent, const vcl::Font& rFont)
145{
146 static const PFunc_getSpecialCharsForEdit pfunc_getSpecialCharsForEdit = [] {
147 PFunc_getSpecialCharsForEdit pfunc = nullptr;
148#ifndef DISABLE_DYNLOADING
149 osl::Module aMod;
150 aMod.loadRelative(&thisModule, SVLIBRARY("cui"));
151
152 // get symbol
153 pfunc = reinterpret_cast<PFunc_getSpecialCharsForEdit>(aMod.getFunctionSymbol("GetSpecialCharsForEdit"));
154 DBG_ASSERT( pfunc, "GetSpecialCharsForEdit() not found!" );
155 aMod.release();
156#else
158#endif
159 return pfunc;
160 }();
161
162 OUString aRet;
163 if ( pfunc_getSpecialCharsForEdit )
164 {
165 SolarMutexGuard aGuard;
166 (*pfunc_getSpecialCharsForEdit)( pParent, rFont, aRet );
167 }
168 return aRet;
169}
170
171
173{
174#ifdef TLX_VALIDATE
175 StgIo::SetErrorLink( LINK( this, SfxStorageErrHdl, Error ) );
176#endif
177
178 Reference < XDesktop2 > xDesktop = Desktop::create ( ::comphelper::getProcessComponentContext() );
179 xDesktop->addTerminateListener( new SfxTerminateListener_Impl );
180
181 pImpl->mxAppDispatch = new SfxStatusDispatcher;
182
183 // SV-Look
186
187 pImpl->m_pToolsErrorHdl.emplace(
188 RID_ERRHDL, ErrCodeArea::Io, ErrCodeArea::Vcl);
189
190 pImpl->m_pSoErrorHdl.emplace(
191 RID_SO_ERROR_HANDLER, ErrCodeArea::So, ErrCodeArea::So, SvtResLocale());
192#if HAVE_FEATURE_SCRIPTING
193 pImpl->m_pSbxErrorHdl.emplace(
194 RID_BASIC_START, ErrCodeArea::Sbx, ErrCodeArea::Sbx, BasResLocale());
195#endif
196
198 {
199 SolarMutexGuard aGuard;
200 //ensure instantiation of listener that manages the internal recently-used
201 //list
202 pImpl->mxAppPickList.emplace(*this);
203 }
204
205 DBG_ASSERT( !pImpl->pAppDispat, "AppDispatcher already exists" );
206 pImpl->pAppDispat.emplace();
207 pImpl->pSlotPool.emplace();
208
210
211 // initialize the subclass
212 pImpl->bDowning = false;
213
214 // get CHAOS item pool...
215 pImpl->pPool = NoChaos::GetItemPool();
216 SetPool( pImpl->pPool );
217
218 if ( pImpl->bDowning )
219 return;
220
221 // build the app dispatcher
222 pImpl->pAppDispat->Push(*this);
223 pImpl->pAppDispat->Flush();
224 pImpl->pAppDispat->DoActivate_Impl( true );
225
226 {
227 SolarMutexGuard aGuard;
228 // Set special characters callback on vcl edit control
230 }
231}
232
233/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< css::document::XDocumentEventListener > xGlobalBroadcaster
SfxApplication * SfxGetpApp()
Definition: app.hxx:231
bool(* PFunc_getSpecialCharsForEdit)(weld::Widget *i_pParent, const vcl::Font &i_rFont, OUString &o_rOutString)
Definition: appinit.cxx:127
static OUString SfxGetSpecialCharsForEdit(weld::Widget *pParent, const vcl::Font &rFont)
Definition: appinit.cxx:144
static void thisModule()
Definition: appinit.cxx:136
AnyEventRef aEvent
static void Quit()
static void EnableContextHelp()
static void EnableExtHelp()
static SfxItemPool * GetItemPool()
Definition: nochaos.cxx:73
rtl::Reference< SfxStatusDispatcher > mxAppDispatch
Definition: appdata.hxx:83
SAL_DLLPRIVATE SfxAppData_Impl * Get_Impl() const
Definition: app.hxx:169
std::unique_ptr< SfxAppData_Impl > pImpl
Definition: app.hxx:97
SAL_DLLPRIVATE void Initialize_Impl()
Definition: appinit.cxx:172
static SAL_DLLPRIVATE void Registrations_Impl()
Definition: appreg.cxx:37
void Broadcast(const SfxHint &rHint)
void SetPool(SfxItemPool *pNewPool)
With this method, the subclasses register their special <SfxItemPool> in the SfxShell.
Definition: shell.hxx:525
static void storeConfigItems()
static bool IsFuzzing()
#define DBG_ASSERT(sCon, aError)
SVT_DLLPUBLIC const ErrMsgCode RID_ERRHDL[]
SAL_DLLPUBLIC_EXPORT bool GetSpecialCharsForEdit(weld::Widget *i_pParent, const vcl::Font &i_rFont, OUString &o_rResult)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Error
void SetGetSpecialCharsFunction(FncGetSpecialChars fn)
BASIC_DLLPUBLIC std::pair< TranslateId, ErrCode > const RID_BASIC_START[]
std::locale BasResLocale()
SVT_DLLPUBLIC const ErrMsgCode RID_SO_ERROR_HANDLER[]
#define SVLIBRARY(Base)
SVT_DLLPUBLIC std::locale SvtResLocale()
unsigned char sal_Bool