update dev300-m58
[ooovba.git] / sfx2 / source / appl / appinit.cxx
blob13173dba7784d45fb2c838ccb2e64a47823a0b1b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: appinit.cxx,v $
10 * $Revision: 1.65 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 #include <sfx2/app.hxx>
35 #include <com/sun/star/frame/XTerminateListener.hpp>
36 #include <com/sun/star/uno/Reference.hxx>
37 #include <com/sun/star/frame/XDesktop.hpp>
38 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <svtools/soerr.hxx>
41 #include <svtools/svtools.hrc>
42 #include <svtools/saveopt.hxx>
43 #include <svtools/localisationoptions.hxx>
44 #include <tools/config.hxx>
45 #ifndef _SV_RESARY_HXX
46 #include <tools/resary.hxx>
47 #endif
48 #include <tools/urlobj.hxx>
49 #include <svtools/intitem.hxx>
50 #include <svtools/eitem.hxx>
51 #include <svtools/stritem.hxx>
52 #ifndef _MSGBOX_HXX //autogen
53 #include <vcl/msgbox.hxx>
54 #endif
55 #include <svtools/ehdl.hxx>
56 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
57 #include <comphelper/processfactory.hxx>
58 #endif
59 #include <unotools/configmgr.hxx>
60 #include <rtl/ustrbuf.hxx>
61 #include <vos/security.hxx>
62 #include <ucbhelper/configurationkeys.hxx>
63 #include <svtools/pathoptions.hxx>
64 #include <svtools/historyoptions.hxx>
65 #include <svtools/moduleoptions.hxx>
66 #include <cppuhelper/implbase2.hxx>
68 #include <rtl/logfile.hxx>
69 #include <vcl/edit.hxx>
71 #ifndef GCC
72 #endif
74 #include <sfx2/unoctitm.hxx>
75 #include "app.hrc"
76 #include "sfxlocal.hrc"
77 #include "appdata.hxx"
78 #include "arrdecl.hxx"
79 #include <sfx2/dispatch.hxx>
80 #include <sfx2/docfac.hxx>
81 #include <sfx2/evntconf.hxx>
82 #include "intro.hxx"
83 #include <sfx2/macrconf.hxx>
84 #include <sfx2/mnumgr.hxx>
85 #include <sfx2/msgpool.hxx>
86 #include <sfx2/progress.hxx>
87 #include "sfxhelp.hxx"
88 #include "sfxresid.hxx"
89 #include "sfxtypes.hxx"
90 #include <sfx2/viewsh.hxx>
91 #include "nochaos.hxx"
92 #include <sfx2/fcontnr.hxx>
93 #include "helper.hxx" // SfxContentHelper::Kill()
94 #include "sfxpicklist.hxx"
96 #ifdef UNX
97 #define stricmp(a,b) strcmp(a,b)
98 #endif
100 using namespace ::com::sun::star::uno;
101 using namespace ::com::sun::star::frame;
102 using namespace ::com::sun::star::lang;
103 using namespace ::com::sun::star;
104 namespace css = ::com::sun::star;
106 class SfxTerminateListener_Impl : public ::cppu::WeakImplHelper2< XTerminateListener, XServiceInfo >
108 public:
110 // XTerminateListener
111 virtual void SAL_CALL queryTermination( const EventObject& aEvent ) throw( TerminationVetoException, RuntimeException );
112 virtual void SAL_CALL notifyTermination( const EventObject& aEvent ) throw( RuntimeException );
113 virtual void SAL_CALL disposing( const EventObject& Source ) throw( RuntimeException );
115 // XServiceInfo
116 virtual ::rtl::OUString SAL_CALL getImplementationName() throw (RuntimeException);
117 virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& sServiceName ) throw (RuntimeException);
118 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
121 void SAL_CALL SfxTerminateListener_Impl::disposing( const EventObject& ) throw( RuntimeException )
125 void SAL_CALL SfxTerminateListener_Impl::queryTermination( const EventObject& ) throw(TerminationVetoException, RuntimeException )
127 ::vos::OGuard aGuard( Application::GetSolarMutex() );
128 if ( !SFX_APP()->QueryExit_Impl() )
129 throw TerminationVetoException();
132 void SAL_CALL SfxTerminateListener_Impl::notifyTermination( const EventObject& aEvent ) throw(RuntimeException )
134 static ::rtl::OUString SERVICE_GLOBALEVENTBROADCASTER = ::rtl::OUString::createFromAscii("com.sun.star.frame.GlobalEventBroadcaster");
135 static ::rtl::OUString EVENT_QUIT_APP = ::rtl::OUString::createFromAscii("OnCloseApp");
137 Reference< XDesktop > xDesktop( aEvent.Source, UNO_QUERY );
138 if( xDesktop.is() == sal_True )
139 xDesktop->removeTerminateListener( this );
141 ::vos::OGuard aGuard( Application::GetSolarMutex() );
142 utl::ConfigManager::GetConfigManager()->StoreConfigItems();
143 SfxApplication* pApp = SFX_APP();
144 pApp->Broadcast( SfxSimpleHint( SFX_HINT_DEINITIALIZING ) );
145 pApp->Get_Impl()->pAppDispatch->ReleaseAll();
146 pApp->Get_Impl()->pAppDispatch->release();
147 pApp->NotifyEvent(SfxEventHint( SFX_EVENT_CLOSEAPP) );
149 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
150 css::uno::Reference< css::document::XEventListener > xGlobalBroadcaster(xSMGR->createInstance(SERVICE_GLOBALEVENTBROADCASTER), css::uno::UNO_QUERY);
151 if (xGlobalBroadcaster.is())
153 css::document::EventObject aEvent2;
154 aEvent2.EventName = EVENT_QUIT_APP;
155 xGlobalBroadcaster->notifyEvent(aEvent2);
158 //pApp->Deinitialize();
159 delete pApp;
160 Application::Quit();
163 ::rtl::OUString SAL_CALL SfxTerminateListener_Impl::getImplementationName() throw (RuntimeException)
165 static const ::rtl::OUString IMPLNAME = ::rtl::OUString::createFromAscii("com.sun.star.comp.sfx2.SfxTerminateListener");
166 return IMPLNAME;
169 ::sal_Bool SAL_CALL SfxTerminateListener_Impl::supportsService( const ::rtl::OUString& sServiceName ) throw (RuntimeException)
171 Sequence< ::rtl::OUString > lNames = getSupportedServiceNames();
172 ::sal_Int32 c = lNames.getLength();
173 ::sal_Int32 i = 0;
175 for (i=0; i<c; ++i)
177 if (lNames[i].equals(sServiceName))
178 return sal_True;
181 return sal_False;
184 Sequence< ::rtl::OUString > SAL_CALL SfxTerminateListener_Impl::getSupportedServiceNames() throw (RuntimeException)
186 // Note: That service does not realy exists .-)
187 // But this implementation is not thought to be registered realy within our service.rdb.
188 // At least we need the implementation name only to identify these service at the global desktop instance.
189 // The desktop must know, which listener will terminate the SfxApplication in real !
190 // It must call this special listener as last one ... otherwise we shutdown the SfxApplication BEFORE other listener
191 // can react ...
192 static const ::rtl::OUString SERVICENAME = ::rtl::OUString::createFromAscii("com.sun.star.frame.TerminateListener");
193 Sequence< ::rtl::OUString > lNames(1);
194 lNames[0] = SERVICENAME;
195 return lNames;
198 //====================================================================
200 #define DOSTRING( x ) #x
201 #define STRING( x ) DOSTRING( x )
203 typedef bool ( *PFunc_getSpecialCharsForEdit)( Window* i_pParent, const Font& i_rFont, String& o_rOutString );
205 //====================================================================
206 // Lazy binding of the GetSpecialCharsForEdit function as it resides in
207 // a library above us.
208 //====================================================================
210 extern "C" { static void SAL_CALL thisModule() {} }
212 String GetSpecialCharsForEdit(Window* pParent, const Font& rFont)
214 static bool bDetermineFunction = false;
215 static PFunc_getSpecialCharsForEdit pfunc_getSpecialCharsForEdit = 0;
217 ::vos::OGuard aGuard( Application::GetSolarMutex() );
218 if ( !bDetermineFunction )
220 bDetermineFunction = true;
222 String sLibName = String::CreateFromAscii( STRING( DLL_NAME ) );
223 sLibName.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "sfx" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "cui" ) ) );
225 rtl::OUString aLibName( sLibName );
226 oslModule handleMod = osl_loadModuleRelative(
227 &thisModule, aLibName.pData, 0 );
229 // get symbol
230 ::rtl::OUString aSymbol( RTL_CONSTASCII_USTRINGPARAM( "GetSpecialCharsForEdit" ) );
231 pfunc_getSpecialCharsForEdit = (PFunc_getSpecialCharsForEdit)osl_getFunctionSymbol( handleMod, aSymbol.pData );
232 DBG_ASSERT( pfunc_getSpecialCharsForEdit, "GetSpecialCharsForEdit() not found!" );
235 String aRet;
236 if ( pfunc_getSpecialCharsForEdit )
237 (*pfunc_getSpecialCharsForEdit)( pParent, rFont, aRet );
238 return aRet;
241 //====================================================================
243 FASTBOOL SfxApplication::Initialize_Impl()
245 RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mb93783) ::SfxApplication::Initialize_Impl" );
247 #ifdef TLX_VALIDATE
248 StgIo::SetErrorLink( LINK( this, SfxStorageErrHdl, Error ) );
249 #endif
251 Reference < XDesktop > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
252 if (!xDesktop.is())
253 throw RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Couldn't create mandatory desktop service!" )), xDesktop );
254 xDesktop->addTerminateListener( new SfxTerminateListener_Impl() );
256 Application::EnableAutoHelpId();
258 pAppData_Impl->pAppDispatch = new SfxStatusDispatcher;
259 pAppData_Impl->pAppDispatch->acquire();
261 // SV-Look
262 Help::EnableContextHelp();
263 Help::EnableExtHelp();
265 SvtLocalisationOptions aLocalisation;
266 Application::EnableAutoMnemonic ( aLocalisation.IsAutoMnemonic() );
267 Application::SetDialogScaleX ( (short)(aLocalisation.GetDialogScale()) );
270 #ifdef DBG_UTIL
271 // Der SimplerErrorHandler dient Debugzwecken. In der Product werden
272 // nichtgehandelte Fehler durch Errorcode 1 an SFX gegeben.
273 new SimpleErrorHandler;
274 #endif
275 new SfxErrorHandler(RID_ERRHDL, ERRCODE_AREA_TOOLS, ERRCODE_AREA_LIB1);
277 new SfxErrorHandler(
278 RID_SO_ERROR_HANDLER, ERRCODE_AREA_SO, ERRCODE_AREA_SO_END);
279 new SfxErrorHandler(
280 (RID_SJ_START +1), ERRCODE_AREA_JAVA, ERRCODE_AREA_JAVA_END);
281 new SfxErrorHandler(
282 RID_BASIC_START, ERRCODE_AREA_SBX, ERRCODE_AREA_SBX_END );
284 // diverse Pointer
285 SfxPickList::GetOrCreate( SvtHistoryOptions().GetSize( ePICKLIST ) );
287 /////////////////////////////////////////////////////////////////
289 DBG_ASSERT( !pAppData_Impl->pAppDispat, "AppDispatcher already exists" );
290 pAppData_Impl->pAppDispat = new SfxDispatcher((SfxDispatcher*)0);
291 pAppData_Impl->pSlotPool = new SfxSlotPool;
292 pAppData_Impl->pTbxCtrlFac = new SfxTbxCtrlFactArr_Impl;
293 pAppData_Impl->pStbCtrlFac = new SfxStbCtrlFactArr_Impl;
294 pAppData_Impl->pMenuCtrlFac = new SfxMenuCtrlFactArr_Impl;
295 pAppData_Impl->pViewFrames = new SfxViewFrameArr_Impl;
296 pAppData_Impl->pViewShells = new SfxViewShellArr_Impl;
297 pAppData_Impl->pObjShells = new SfxObjectShellArr_Impl;
298 pAppData_Impl->nInterfaces = SFX_INTERFACE_APP+8;
299 pAppData_Impl->pInterfaces = new SfxInterface*[pAppData_Impl->nInterfaces];
300 memset( pAppData_Impl->pInterfaces, 0, sizeof(SfxInterface*) * pAppData_Impl->nInterfaces );
302 Registrations_Impl();
304 // ::vos::OGuard aGuard( Application::GetSolarMutex() );
306 // TODO/LATER: exchange confusing defines; CREATEDOC -> NEWDOC, DOCCREATED -> CREATEDOC
307 SfxEventConfiguration::RegisterEvent(SFX_EVENT_STARTAPP, String(SfxResId(STR_EVENT_STARTAPP)), SfxObjectShell::GetEventNames_Impl()[0] );
308 SfxEventConfiguration::RegisterEvent(SFX_EVENT_CLOSEAPP, String(SfxResId(STR_EVENT_CLOSEAPP)), SfxObjectShell::GetEventNames_Impl()[1] );
309 SfxEventConfiguration::RegisterEvent(SFX_EVENT_CREATEDOC, String(SfxResId(STR_EVENT_CREATEDOC)), SfxObjectShell::GetEventNames_Impl()[2] );
310 SfxEventConfiguration::RegisterEvent(SFX_EVENT_OPENDOC, String(SfxResId(STR_EVENT_OPENDOC)), SfxObjectShell::GetEventNames_Impl()[3] );
311 SfxEventConfiguration::RegisterEvent(SFX_EVENT_SAVEASDOC, String(SfxResId(STR_EVENT_SAVEASDOC)), SfxObjectShell::GetEventNames_Impl()[4] );
312 SfxEventConfiguration::RegisterEvent(SFX_EVENT_SAVEASDOCDONE, String(SfxResId(STR_EVENT_SAVEASDOCDONE)), SfxObjectShell::GetEventNames_Impl()[5] );
313 SfxEventConfiguration::RegisterEvent(SFX_EVENT_SAVEDOC, String(SfxResId(STR_EVENT_SAVEDOC)), SfxObjectShell::GetEventNames_Impl()[6] );
314 SfxEventConfiguration::RegisterEvent(SFX_EVENT_SAVEDOCDONE, String(SfxResId(STR_EVENT_SAVEDOCDONE)), SfxObjectShell::GetEventNames_Impl()[7] );
315 SfxEventConfiguration::RegisterEvent(SFX_EVENT_PREPARECLOSEDOC, String(SfxResId(STR_EVENT_PREPARECLOSEDOC)),SfxObjectShell::GetEventNames_Impl()[8] );
316 SfxEventConfiguration::RegisterEvent(SFX_EVENT_CLOSEDOC, String(SfxResId(STR_EVENT_CLOSEDOC)), SfxObjectShell::GetEventNames_Impl()[9] );
317 SfxEventConfiguration::RegisterEvent(SFX_EVENT_ACTIVATEDOC, String(SfxResId(STR_EVENT_ACTIVATEDOC)), SfxObjectShell::GetEventNames_Impl()[10] );
318 SfxEventConfiguration::RegisterEvent(SFX_EVENT_DEACTIVATEDOC, String(SfxResId(STR_EVENT_DEACTIVATEDOC)), SfxObjectShell::GetEventNames_Impl()[11] );
319 SfxEventConfiguration::RegisterEvent(SFX_EVENT_PRINTDOC, String(SfxResId(STR_EVENT_PRINTDOC)), SfxObjectShell::GetEventNames_Impl()[12] );
320 SfxEventConfiguration::RegisterEvent(SFX_EVENT_MODIFYCHANGED, String(SfxResId(STR_EVENT_MODIFYCHANGED)), SfxObjectShell::GetEventNames_Impl()[13] );
322 SfxEventConfiguration::RegisterEvent(SFX_EVENT_SAVETODOC, String(), SfxObjectShell::GetEventNames_Impl()[14] );
323 SfxEventConfiguration::RegisterEvent(SFX_EVENT_SAVETODOCDONE, String(), SfxObjectShell::GetEventNames_Impl()[15] );
324 SfxEventConfiguration::RegisterEvent(SFX_EVENT_VIEWCREATED, String(), SfxObjectShell::GetEventNames_Impl()[16] );
325 SfxEventConfiguration::RegisterEvent(SFX_EVENT_PREPARECLOSEVIEW, String(), SfxObjectShell::GetEventNames_Impl()[17] );
326 SfxEventConfiguration::RegisterEvent(SFX_EVENT_CLOSEVIEW, String(), SfxObjectShell::GetEventNames_Impl()[18] );
327 SfxEventConfiguration::RegisterEvent(SFX_EVENT_VISAREACHANGED, String(), SfxObjectShell::GetEventNames_Impl()[19] );
328 SfxEventConfiguration::RegisterEvent(SFX_EVENT_DOCCREATED, String(), SfxObjectShell::GetEventNames_Impl()[20] );
329 SfxEventConfiguration::RegisterEvent(SFX_EVENT_LOADFINISHED, String(), SfxObjectShell::GetEventNames_Impl()[21] );
330 SfxEventConfiguration::RegisterEvent(SFX_EVENT_SAVEASDOCFAILED, String(), SfxObjectShell::GetEventNames_Impl()[22] );
331 SfxEventConfiguration::RegisterEvent(SFX_EVENT_SAVEDOCFAILED, String(), SfxObjectShell::GetEventNames_Impl()[23] );
332 SfxEventConfiguration::RegisterEvent(SFX_EVENT_SAVETODOCFAILED, String(), SfxObjectShell::GetEventNames_Impl()[24] );
333 SfxEventConfiguration::RegisterEvent(SFX_HINT_TITLECHANGED, String(), SfxObjectShell::GetEventNames_Impl()[25] );
334 SfxEventConfiguration::RegisterEvent(SFX_HINT_MODECHANGED, String(), SfxObjectShell::GetEventNames_Impl()[26] );
336 // Subklasse initialisieren
337 pAppData_Impl->bDowning = sal_False;
338 Init();
340 // get CHAOS item pool...
341 pAppData_Impl->pPool = NoChaos::GetItemPool();
342 SetPool( pAppData_Impl->pPool );
344 if ( pAppData_Impl->bDowning )
345 return sal_False;
347 // App-Dispatcher aufbauen
348 pAppData_Impl->pAppDispat->Push(*this);
349 pAppData_Impl->pAppDispat->Flush();
350 pAppData_Impl->pAppDispat->DoActivate_Impl( sal_True, NULL );
353 ::vos::OGuard aGuard( Application::GetSolarMutex() );
354 // Set special characters callback on vcl edit control
355 Edit::SetGetSpecialCharsFunction(&GetSpecialCharsForEdit);
358 return sal_True;