Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / appl / appinit.cxx
blob472a6e7e18fb3b92333984b35f1ac2767ae449c1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <sfx2/app.hxx>
31 #include <com/sun/star/frame/XTerminateListener.hpp>
32 #include <com/sun/star/uno/Reference.hxx>
33 #include <com/sun/star/frame/XDesktop.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <svtools/soerr.hxx>
37 #include <svtools/svtools.hrc>
38 #include <unotools/saveopt.hxx>
39 #include <unotools/localisationoptions.hxx>
40 #include <svl/intitem.hxx>
41 #include <svl/eitem.hxx>
42 #include <svl/stritem.hxx>
43 #include <vcl/msgbox.hxx>
44 #include <svtools/ehdl.hxx>
45 #include <comphelper/processfactory.hxx>
46 #include <unotools/configmgr.hxx>
47 #include <rtl/ustrbuf.hxx>
48 #include <osl/security.hxx>
49 #include <ucbhelper/configurationkeys.hxx>
50 #include <unotools/pathoptions.hxx>
51 #include <unotools/historyoptions.hxx>
52 #include <unotools/moduleoptions.hxx>
53 #include <cppuhelper/implbase2.hxx>
55 #include <rtl/logfile.hxx>
56 #include <vcl/edit.hxx>
58 #include <sfx2/unoctitm.hxx>
59 #include "app.hrc"
60 #include "sfxlocal.hrc"
61 #include "appdata.hxx"
62 #include "arrdecl.hxx"
63 #include <sfx2/dispatch.hxx>
64 #include <sfx2/docfac.hxx>
65 #include <sfx2/evntconf.hxx>
66 #include <sfx2/mnumgr.hxx>
67 #include <sfx2/msgpool.hxx>
68 #include <sfx2/progress.hxx>
69 #include "sfx2/sfxhelp.hxx"
70 #include "sfx2/sfxresid.hxx"
71 #include "sfxtypes.hxx"
72 #include <sfx2/viewsh.hxx>
73 #include "nochaos.hxx"
74 #include <sfx2/fcontnr.hxx>
75 #include "helper.hxx" // SfxContentHelper::Kill()
76 #include "sfxpicklist.hxx"
78 using namespace ::com::sun::star::uno;
79 using namespace ::com::sun::star::frame;
80 using namespace ::com::sun::star::lang;
81 using namespace ::com::sun::star;
82 namespace css = ::com::sun::star;
84 class SfxTerminateListener_Impl : public ::cppu::WeakImplHelper2< XTerminateListener, XServiceInfo >
86 public:
88 // XTerminateListener
89 virtual void SAL_CALL queryTermination( const EventObject& aEvent ) throw( TerminationVetoException, RuntimeException );
90 virtual void SAL_CALL notifyTermination( const EventObject& aEvent ) throw( RuntimeException );
91 virtual void SAL_CALL disposing( const EventObject& Source ) throw( RuntimeException );
93 // XServiceInfo
94 virtual ::rtl::OUString SAL_CALL getImplementationName() throw (RuntimeException);
95 virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& sServiceName ) throw (RuntimeException);
96 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
99 void SAL_CALL SfxTerminateListener_Impl::disposing( const EventObject& ) throw( RuntimeException )
103 void SAL_CALL SfxTerminateListener_Impl::queryTermination( const EventObject& ) throw(TerminationVetoException, RuntimeException )
105 SolarMutexGuard aGuard;
106 if ( !SFX_APP()->QueryExit_Impl() )
107 throw TerminationVetoException();
110 void SAL_CALL SfxTerminateListener_Impl::notifyTermination( const EventObject& aEvent ) throw(RuntimeException )
112 static ::rtl::OUString SERVICE_GLOBALEVENTBROADCASTER("com.sun.star.frame.GlobalEventBroadcaster");
113 static ::rtl::OUString EVENT_QUIT_APP ("OnCloseApp");
115 Reference< XDesktop > xDesktop( aEvent.Source, UNO_QUERY );
116 if( xDesktop.is() == sal_True )
117 xDesktop->removeTerminateListener( this );
119 SolarMutexGuard aGuard;
120 utl::ConfigManager::storeConfigItems();
122 SfxApplication* pApp = SFX_APP();
123 pApp->Broadcast( SfxSimpleHint( SFX_HINT_DEINITIALIZING ) );
124 pApp->Get_Impl()->pAppDispatch->ReleaseAll();
125 pApp->Get_Impl()->pAppDispatch->release();
127 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
128 css::uno::Reference< css::document::XEventListener > xGlobalBroadcaster(xSMGR->createInstance(SERVICE_GLOBALEVENTBROADCASTER), css::uno::UNO_QUERY);
129 if (xGlobalBroadcaster.is())
131 css::document::EventObject aEvent2;
132 aEvent2.EventName = EVENT_QUIT_APP;
133 xGlobalBroadcaster->notifyEvent(aEvent2);
136 delete pApp;
137 Application::Quit();
140 ::rtl::OUString SAL_CALL SfxTerminateListener_Impl::getImplementationName() throw (RuntimeException)
142 static const ::rtl::OUString IMPLNAME("com.sun.star.comp.sfx2.SfxTerminateListener");
143 return IMPLNAME;
146 ::sal_Bool SAL_CALL SfxTerminateListener_Impl::supportsService( const ::rtl::OUString& sServiceName ) throw (RuntimeException)
148 Sequence< ::rtl::OUString > lNames = getSupportedServiceNames();
149 ::sal_Int32 c = lNames.getLength();
150 ::sal_Int32 i = 0;
152 for (i=0; i<c; ++i)
154 if (lNames[i].equals(sServiceName))
155 return sal_True;
158 return sal_False;
161 Sequence< ::rtl::OUString > SAL_CALL SfxTerminateListener_Impl::getSupportedServiceNames() throw (RuntimeException)
163 // Note: That service does not realy exists .-)
164 // But this implementation is not thought to be registered realy within our service.rdb.
165 // At least we need the implementation name only to identify these service at the global desktop instance.
166 // The desktop must know, which listener will terminate the SfxApplication in real !
167 // It must call this special listener as last one ... otherwise we shutdown the SfxApplication BEFORE other listener
168 // can react ...
169 static const ::rtl::OUString SERVICENAME("com.sun.star.frame.TerminateListener");
170 Sequence< ::rtl::OUString > lNames(1);
171 lNames[0] = SERVICENAME;
172 return lNames;
175 //====================================================================
177 typedef bool ( *PFunc_getSpecialCharsForEdit)( Window* i_pParent, const Font& i_rFont, String& o_rOutString );
179 //====================================================================
180 // Lazy binding of the GetSpecialCharsForEdit function as it resides in
181 // a library above us.
182 //====================================================================
184 extern "C" { static void SAL_CALL thisModule() {} }
186 String GetSpecialCharsForEdit(Window* pParent, const Font& rFont)
188 static bool bDetermineFunction = false;
189 static PFunc_getSpecialCharsForEdit pfunc_getSpecialCharsForEdit = 0;
191 SolarMutexGuard aGuard;
192 if ( !bDetermineFunction )
194 bDetermineFunction = true;
196 static ::rtl::OUString aLibName( SVLIBRARY( "cui" ) );
197 oslModule handleMod = osl_loadModuleRelative(
198 &thisModule, aLibName.pData, 0 );
200 // get symbol
201 ::rtl::OUString aSymbol( "GetSpecialCharsForEdit" );
202 pfunc_getSpecialCharsForEdit = (PFunc_getSpecialCharsForEdit)osl_getFunctionSymbol( handleMod, aSymbol.pData );
203 DBG_ASSERT( pfunc_getSpecialCharsForEdit, "GetSpecialCharsForEdit() not found!" );
206 String aRet;
207 if ( pfunc_getSpecialCharsForEdit )
208 (*pfunc_getSpecialCharsForEdit)( pParent, rFont, aRet );
209 return aRet;
212 //====================================================================
214 bool SfxApplication::Initialize_Impl()
216 RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mb93783) ::SfxApplication::Initialize_Impl" );
218 #ifdef TLX_VALIDATE
219 StgIo::SetErrorLink( LINK( this, SfxStorageErrHdl, Error ) );
220 #endif
222 Reference < XDesktop > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
223 if (!xDesktop.is())
224 throw RuntimeException( rtl::OUString( "Couldn't create mandatory desktop service!" ), xDesktop );
225 xDesktop->addTerminateListener( new SfxTerminateListener_Impl() );
227 Application::EnableAutoHelpId();
229 pAppData_Impl->pAppDispatch = new SfxStatusDispatcher;
230 pAppData_Impl->pAppDispatch->acquire();
232 // SV-Look
233 Help::EnableContextHelp();
234 Help::EnableExtHelp();
236 SvtLocalisationOptions aLocalisation;
237 Application::EnableAutoMnemonic ( aLocalisation.IsAutoMnemonic() );
238 Application::SetDialogScaleX ( (short)(aLocalisation.GetDialogScale()) );
241 #ifdef DBG_UTIL
242 // The SimplerErrorHandler is for debugging. In the Product errors
243 // not processed are given to SFX as Errorcode 1.
244 pAppData_Impl->m_pSimpleErrorHdl = new SimpleErrorHandler;
245 #endif
246 pAppData_Impl->m_pToolsErrorHdl = new SfxErrorHandler(
247 RID_ERRHDL, ERRCODE_AREA_TOOLS, ERRCODE_AREA_LIB1);
249 pAppData_Impl->pBasicResMgr = CreateResManager("sb");
250 pAppData_Impl->pSvtResMgr = CreateResManager("svt");
252 pAppData_Impl->m_pSoErrorHdl = new SfxErrorHandler(
253 RID_SO_ERROR_HANDLER, ERRCODE_AREA_SO, ERRCODE_AREA_SO_END, pAppData_Impl->pSvtResMgr );
254 pAppData_Impl->m_pSbxErrorHdl = new SfxErrorHandler(
255 RID_BASIC_START, ERRCODE_AREA_SBX, ERRCODE_AREA_SBX_END, pAppData_Impl->pBasicResMgr );
257 //ensure instantiation of listener that manages the internal recently-used
258 //list
259 SfxPickList::ensure();
261 DBG_ASSERT( !pAppData_Impl->pAppDispat, "AppDispatcher already exists" );
262 pAppData_Impl->pAppDispat = new SfxDispatcher((SfxDispatcher*)0);
263 pAppData_Impl->pSlotPool = new SfxSlotPool;
264 pAppData_Impl->pTbxCtrlFac = new SfxTbxCtrlFactArr_Impl;
265 pAppData_Impl->pStbCtrlFac = new SfxStbCtrlFactArr_Impl;
266 pAppData_Impl->pMenuCtrlFac = new SfxMenuCtrlFactArr_Impl;
267 pAppData_Impl->pViewFrames = new SfxViewFrameArr_Impl;
268 pAppData_Impl->pViewShells = new SfxViewShellArr_Impl;
269 pAppData_Impl->pObjShells = new SfxObjectShellArr_Impl;
270 pAppData_Impl->nInterfaces = SFX_INTERFACE_APP+8;
271 pAppData_Impl->pInterfaces = new SfxInterface*[pAppData_Impl->nInterfaces];
272 memset( pAppData_Impl->pInterfaces, 0, sizeof(SfxInterface*) * pAppData_Impl->nInterfaces );
274 Registrations_Impl();
276 // Subklasse initialisieren
277 pAppData_Impl->bDowning = sal_False;
278 Init();
280 // get CHAOS item pool...
281 pAppData_Impl->pPool = NoChaos::GetItemPool();
282 SetPool( pAppData_Impl->pPool );
284 if ( pAppData_Impl->bDowning )
285 return sal_False;
287 // App-Dispatcher aufbauen
288 pAppData_Impl->pAppDispat->Push(*this);
289 pAppData_Impl->pAppDispat->Flush();
290 pAppData_Impl->pAppDispat->DoActivate_Impl( sal_True, NULL );
293 SolarMutexGuard aGuard;
294 // Set special characters callback on vcl edit control
295 Edit::SetGetSpecialCharsFunction(&GetSpecialCharsForEdit);
298 return sal_True;
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */