Branch data Line data Source code
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 : :
21 : : #include <sfx2/app.hxx>
22 : : #include <com/sun/star/frame/XTerminateListener.hpp>
23 : : #include <com/sun/star/uno/Reference.hxx>
24 : : #include <com/sun/star/frame/XDesktop.hpp>
25 : : #include <com/sun/star/lang/XServiceInfo.hpp>
26 : :
27 : : #include <svtools/soerr.hxx>
28 : : #include <svtools/svtools.hrc>
29 : : #include <unotools/saveopt.hxx>
30 : : #include <unotools/localisationoptions.hxx>
31 : : #include <svl/intitem.hxx>
32 : : #include <svl/eitem.hxx>
33 : : #include <svl/stritem.hxx>
34 : : #include <vcl/msgbox.hxx>
35 : : #include <svtools/ehdl.hxx>
36 : : #include <comphelper/processfactory.hxx>
37 : : #include <unotools/configmgr.hxx>
38 : : #include <rtl/ustrbuf.hxx>
39 : : #include <osl/security.hxx>
40 : : #include <ucbhelper/configurationkeys.hxx>
41 : : #include <unotools/pathoptions.hxx>
42 : : #include <unotools/historyoptions.hxx>
43 : : #include <unotools/moduleoptions.hxx>
44 : : #include <cppuhelper/implbase2.hxx>
45 : :
46 : : #include <rtl/logfile.hxx>
47 : : #include <vcl/edit.hxx>
48 : :
49 : : #include <sfx2/unoctitm.hxx>
50 : : #include "app.hrc"
51 : : #include "sfxlocal.hrc"
52 : : #include "appdata.hxx"
53 : : #include "arrdecl.hxx"
54 : : #include <sfx2/dispatch.hxx>
55 : : #include <sfx2/docfac.hxx>
56 : : #include <sfx2/evntconf.hxx>
57 : : #include <sfx2/mnumgr.hxx>
58 : : #include <sfx2/msgpool.hxx>
59 : : #include <sfx2/progress.hxx>
60 : : #include "sfx2/sfxhelp.hxx"
61 : : #include "sfx2/sfxresid.hxx"
62 : : #include "sfxtypes.hxx"
63 : : #include <sfx2/viewsh.hxx>
64 : : #include "nochaos.hxx"
65 : : #include <sfx2/fcontnr.hxx>
66 : : #include "helper.hxx" // SfxContentHelper::Kill()
67 : : #include "sfxpicklist.hxx"
68 : :
69 : : using namespace ::com::sun::star::uno;
70 : : using namespace ::com::sun::star::frame;
71 : : using namespace ::com::sun::star::lang;
72 : : using namespace ::com::sun::star;
73 : : namespace css = ::com::sun::star;
74 : :
75 [ - + ]: 699 : class SfxTerminateListener_Impl : public ::cppu::WeakImplHelper2< XTerminateListener, XServiceInfo >
76 : : {
77 : : public:
78 : :
79 : : // XTerminateListener
80 : : virtual void SAL_CALL queryTermination( const EventObject& aEvent ) throw( TerminationVetoException, RuntimeException );
81 : : virtual void SAL_CALL notifyTermination( const EventObject& aEvent ) throw( RuntimeException );
82 : : virtual void SAL_CALL disposing( const EventObject& Source ) throw( RuntimeException );
83 : :
84 : : // XServiceInfo
85 : : virtual ::rtl::OUString SAL_CALL getImplementationName() throw (RuntimeException);
86 : : virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& sServiceName ) throw (RuntimeException);
87 : : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
88 : : };
89 : :
90 : 0 : void SAL_CALL SfxTerminateListener_Impl::disposing( const EventObject& ) throw( RuntimeException )
91 : : {
92 : 0 : }
93 : :
94 : 158 : void SAL_CALL SfxTerminateListener_Impl::queryTermination( const EventObject& ) throw(TerminationVetoException, RuntimeException )
95 : : {
96 [ + - ]: 158 : SolarMutexGuard aGuard;
97 [ + - ][ + - ]: 158 : if ( !SFX_APP()->QueryExit_Impl() )
[ - + ]
98 [ # # ][ + - ]: 158 : throw TerminationVetoException();
99 : 158 : }
100 : :
101 : 158 : void SAL_CALL SfxTerminateListener_Impl::notifyTermination( const EventObject& aEvent ) throw(RuntimeException )
102 : : {
103 [ + - ]: 158 : Reference< XDesktop > xDesktop( aEvent.Source, UNO_QUERY );
104 [ + - ]: 158 : if( xDesktop.is() == sal_True )
105 [ + - ][ + - ]: 158 : xDesktop->removeTerminateListener( this );
[ + - ]
106 : :
107 [ + - ]: 158 : SolarMutexGuard aGuard;
108 [ + - ]: 158 : utl::ConfigManager::storeConfigItems();
109 : :
110 [ + - ]: 158 : SfxApplication* pApp = SFX_APP();
111 [ + - ][ + - ]: 158 : pApp->Broadcast( SfxSimpleHint( SFX_HINT_DEINITIALIZING ) );
[ + - ]
112 [ + - ]: 158 : pApp->Get_Impl()->pAppDispatch->ReleaseAll();
113 : 158 : pApp->Get_Impl()->pAppDispatch->release();
114 : :
115 [ + - ]: 158 : css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
116 [ + - ][ + - ]: 158 : css::uno::Reference< css::document::XEventListener > xGlobalBroadcaster(xSMGR->createInstance("com.sun.star.frame.GlobalEventBroadcaster"), css::uno::UNO_QUERY);
[ + - ]
117 [ + - ]: 158 : if (xGlobalBroadcaster.is())
118 : : {
119 [ + - ]: 158 : css::document::EventObject aEvent2;
120 : 158 : aEvent2.EventName = "OnCloseApp";
121 [ + - ][ + - ]: 158 : xGlobalBroadcaster->notifyEvent(aEvent2);
[ + - ]
122 : : }
123 : :
124 [ + - ][ + - ]: 158 : delete pApp;
125 [ + - ][ + - ]: 158 : Application::Quit();
126 : 158 : }
127 : :
128 : 391 : ::rtl::OUString SAL_CALL SfxTerminateListener_Impl::getImplementationName() throw (RuntimeException)
129 : : {
130 : 391 : return ::rtl::OUString("com.sun.star.comp.sfx2.SfxTerminateListener");
131 : : }
132 : :
133 : 0 : ::sal_Bool SAL_CALL SfxTerminateListener_Impl::supportsService( const ::rtl::OUString& sServiceName ) throw (RuntimeException)
134 : : {
135 [ # # ]: 0 : Sequence< ::rtl::OUString > lNames = getSupportedServiceNames();
136 : 0 : ::sal_Int32 c = lNames.getLength();
137 : 0 : ::sal_Int32 i = 0;
138 : :
139 [ # # ]: 0 : for (i=0; i<c; ++i)
140 : : {
141 [ # # ][ # # ]: 0 : if (lNames[i].equals(sServiceName))
142 : 0 : return sal_True;
143 : : }
144 : :
145 [ # # ]: 0 : return sal_False;
146 : : }
147 : :
148 : 0 : Sequence< ::rtl::OUString > SAL_CALL SfxTerminateListener_Impl::getSupportedServiceNames() throw (RuntimeException)
149 : : {
150 : : // Note: That service does not realy exists .-)
151 : : // But this implementation is not thought to be registered realy within our service.rdb.
152 : : // At least we need the implementation name only to identify these service at the global desktop instance.
153 : : // The desktop must know, which listener will terminate the SfxApplication in real !
154 : : // It must call this special listener as last one ... otherwise we shutdown the SfxApplication BEFORE other listener
155 : : // can react ...
156 [ # # ][ # # ]: 0 : static const ::rtl::OUString SERVICENAME("com.sun.star.frame.TerminateListener");
157 : 0 : Sequence< ::rtl::OUString > lNames(1);
158 [ # # ]: 0 : lNames[0] = SERVICENAME;
159 : 0 : return lNames;
160 : : }
161 : :
162 : : //====================================================================
163 : :
164 : : typedef bool ( *PFunc_getSpecialCharsForEdit)( Window* i_pParent, const Font& i_rFont, String& o_rOutString );
165 : :
166 : : //====================================================================
167 : : // Lazy binding of the GetSpecialCharsForEdit function as it resides in
168 : : // a library above us.
169 : : //====================================================================
170 : :
171 : 0 : extern "C" { static void SAL_CALL thisModule() {} }
172 : :
173 : 0 : String GetSpecialCharsForEdit(Window* pParent, const Font& rFont)
174 : : {
175 : : static bool bDetermineFunction = false;
176 : : static PFunc_getSpecialCharsForEdit pfunc_getSpecialCharsForEdit = 0;
177 : :
178 [ # # ]: 0 : SolarMutexGuard aGuard;
179 [ # # ]: 0 : if ( !bDetermineFunction )
180 : : {
181 : 0 : bDetermineFunction = true;
182 : :
183 [ # # ][ # # ]: 0 : static ::rtl::OUString aLibName( SVLIBRARY( "cui" ) );
184 : : oslModule handleMod = osl_loadModuleRelative(
185 [ # # ]: 0 : &thisModule, aLibName.pData, 0 );
186 : :
187 : : // get symbol
188 : 0 : ::rtl::OUString aSymbol( "GetSpecialCharsForEdit" );
189 [ # # ]: 0 : pfunc_getSpecialCharsForEdit = (PFunc_getSpecialCharsForEdit)osl_getFunctionSymbol( handleMod, aSymbol.pData );
190 : 0 : DBG_ASSERT( pfunc_getSpecialCharsForEdit, "GetSpecialCharsForEdit() not found!" );
191 : : }
192 : :
193 [ # # ]: 0 : String aRet;
194 [ # # ]: 0 : if ( pfunc_getSpecialCharsForEdit )
195 [ # # ]: 0 : (*pfunc_getSpecialCharsForEdit)( pParent, rFont, aRet );
196 [ # # ]: 0 : return aRet;
197 : : }
198 : :
199 : : //====================================================================
200 : :
201 : 233 : bool SfxApplication::Initialize_Impl()
202 : : {
203 : : RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mb93783) ::SfxApplication::Initialize_Impl" );
204 : :
205 : : #ifdef TLX_VALIDATE
206 : : StgIo::SetErrorLink( LINK( this, SfxStorageErrHdl, Error ) );
207 : : #endif
208 : :
209 [ + - ][ + - ]: 233 : Reference < XDesktop > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
210 [ - + ]: 233 : if (!xDesktop.is())
211 [ # # ]: 0 : throw RuntimeException( rtl::OUString( "Couldn't create mandatory desktop service!" ), xDesktop );
212 [ + - ][ + - ]: 233 : xDesktop->addTerminateListener( new SfxTerminateListener_Impl() );
[ + - ][ + - ]
[ + - ]
213 : :
214 [ + - ]: 233 : Application::EnableAutoHelpId();
215 : :
216 [ + - ]: 233 : pAppData_Impl->pAppDispatch = new SfxStatusDispatcher;
217 : 233 : pAppData_Impl->pAppDispatch->acquire();
218 : :
219 : : // SV-Look
220 [ + - ]: 233 : Help::EnableContextHelp();
221 [ + - ]: 233 : Help::EnableExtHelp();
222 : :
223 [ + - ]: 233 : SvtLocalisationOptions aLocalisation;
224 [ + - ][ + - ]: 233 : Application::EnableAutoMnemonic ( aLocalisation.IsAutoMnemonic() );
225 [ + - ][ + - ]: 233 : Application::SetDialogScaleX ( (short)(aLocalisation.GetDialogScale()) );
226 : :
227 : :
228 : : #ifdef DBG_UTIL
229 : : // The SimplerErrorHandler is for debugging. In the Product errors
230 : : // not processed are given to SFX as Errorcode 1.
231 : : pAppData_Impl->m_pSimpleErrorHdl = new SimpleErrorHandler;
232 : : #endif
233 : : pAppData_Impl->m_pToolsErrorHdl = new SfxErrorHandler(
234 [ + - ][ + - ]: 233 : RID_ERRHDL, ERRCODE_AREA_TOOLS, ERRCODE_AREA_LIB1);
235 : :
236 [ + - ]: 233 : pAppData_Impl->pBasicResMgr = CreateResManager("sb");
237 [ + - ]: 233 : pAppData_Impl->pSvtResMgr = CreateResManager("svt");
238 : :
239 : : pAppData_Impl->m_pSoErrorHdl = new SfxErrorHandler(
240 [ + - ][ + - ]: 233 : RID_SO_ERROR_HANDLER, ERRCODE_AREA_SO, ERRCODE_AREA_SO_END, pAppData_Impl->pSvtResMgr );
241 : : pAppData_Impl->m_pSbxErrorHdl = new SfxErrorHandler(
242 [ + - ][ + - ]: 233 : RID_BASIC_START, ERRCODE_AREA_SBX, ERRCODE_AREA_SBX_END, pAppData_Impl->pBasicResMgr );
243 : :
244 : : //ensure instantiation of listener that manages the internal recently-used
245 : : //list
246 [ + - ]: 233 : SfxPickList::ensure();
247 : :
248 : : DBG_ASSERT( !pAppData_Impl->pAppDispat, "AppDispatcher already exists" );
249 [ + - ][ + - ]: 233 : pAppData_Impl->pAppDispat = new SfxDispatcher((SfxDispatcher*)0);
250 [ + - ][ + - ]: 233 : pAppData_Impl->pSlotPool = new SfxSlotPool;
251 [ + - ][ + - ]: 233 : pAppData_Impl->pTbxCtrlFac = new SfxTbxCtrlFactArr_Impl;
252 [ + - ][ + - ]: 233 : pAppData_Impl->pStbCtrlFac = new SfxStbCtrlFactArr_Impl;
253 [ + - ][ + - ]: 233 : pAppData_Impl->pMenuCtrlFac = new SfxMenuCtrlFactArr_Impl;
254 [ + - ][ + - ]: 233 : pAppData_Impl->pViewFrames = new SfxViewFrameArr_Impl;
255 [ + - ][ + - ]: 233 : pAppData_Impl->pViewShells = new SfxViewShellArr_Impl;
256 [ + - ][ + - ]: 233 : pAppData_Impl->pObjShells = new SfxObjectShellArr_Impl;
257 : 233 : pAppData_Impl->nInterfaces = SFX_INTERFACE_APP+8;
258 [ + - ]: 233 : pAppData_Impl->pInterfaces = new SfxInterface*[pAppData_Impl->nInterfaces];
259 : 233 : memset( pAppData_Impl->pInterfaces, 0, sizeof(SfxInterface*) * pAppData_Impl->nInterfaces );
260 : :
261 [ + - ]: 233 : Registrations_Impl();
262 : :
263 : : // Subklasse initialisieren
264 : 233 : pAppData_Impl->bDowning = sal_False;
265 [ + - ]: 233 : Init();
266 : :
267 : : // get CHAOS item pool...
268 [ + - ]: 233 : pAppData_Impl->pPool = NoChaos::GetItemPool();
269 : 233 : SetPool( pAppData_Impl->pPool );
270 : :
271 [ - + ]: 233 : if ( pAppData_Impl->bDowning )
272 : 0 : return sal_False;
273 : :
274 : : // App-Dispatcher aufbauen
275 [ + - ]: 233 : pAppData_Impl->pAppDispat->Push(*this);
276 [ + - ]: 233 : pAppData_Impl->pAppDispat->Flush();
277 [ + - ]: 233 : pAppData_Impl->pAppDispat->DoActivate_Impl( sal_True, NULL );
278 : :
279 : : {
280 [ + - ]: 233 : SolarMutexGuard aGuard;
281 : : // Set special characters callback on vcl edit control
282 [ + - ][ + - ]: 233 : Edit::SetGetSpecialCharsFunction(&GetSpecialCharsForEdit);
283 : : }
284 : :
285 [ + - ]: 233 : return sal_True;
286 : : }
287 : :
288 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|