merge the formfield patch from ooo-build
[ooovba.git] / sfx2 / source / appl / appinit.cxx
bloba995006238d14a619d3a1aa7bf7a791e9c505351
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();
148 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
149 css::uno::Reference< css::document::XEventListener > xGlobalBroadcaster(xSMGR->createInstance(SERVICE_GLOBALEVENTBROADCASTER), css::uno::UNO_QUERY);
150 if (xGlobalBroadcaster.is())
152 css::document::EventObject aEvent2;
153 aEvent2.EventName = EVENT_QUIT_APP;
154 xGlobalBroadcaster->notifyEvent(aEvent2);
157 //pApp->Deinitialize();
158 delete pApp;
159 Application::Quit();
162 ::rtl::OUString SAL_CALL SfxTerminateListener_Impl::getImplementationName() throw (RuntimeException)
164 static const ::rtl::OUString IMPLNAME = ::rtl::OUString::createFromAscii("com.sun.star.comp.sfx2.SfxTerminateListener");
165 return IMPLNAME;
168 ::sal_Bool SAL_CALL SfxTerminateListener_Impl::supportsService( const ::rtl::OUString& sServiceName ) throw (RuntimeException)
170 Sequence< ::rtl::OUString > lNames = getSupportedServiceNames();
171 ::sal_Int32 c = lNames.getLength();
172 ::sal_Int32 i = 0;
174 for (i=0; i<c; ++i)
176 if (lNames[i].equals(sServiceName))
177 return sal_True;
180 return sal_False;
183 Sequence< ::rtl::OUString > SAL_CALL SfxTerminateListener_Impl::getSupportedServiceNames() throw (RuntimeException)
185 // Note: That service does not realy exists .-)
186 // But this implementation is not thought to be registered realy within our service.rdb.
187 // At least we need the implementation name only to identify these service at the global desktop instance.
188 // The desktop must know, which listener will terminate the SfxApplication in real !
189 // It must call this special listener as last one ... otherwise we shutdown the SfxApplication BEFORE other listener
190 // can react ...
191 static const ::rtl::OUString SERVICENAME = ::rtl::OUString::createFromAscii("com.sun.star.frame.TerminateListener");
192 Sequence< ::rtl::OUString > lNames(1);
193 lNames[0] = SERVICENAME;
194 return lNames;
197 //====================================================================
199 #define DOSTRING( x ) #x
200 #define STRING( x ) DOSTRING( x )
202 typedef bool ( *PFunc_getSpecialCharsForEdit)( Window* i_pParent, const Font& i_rFont, String& o_rOutString );
204 //====================================================================
205 // Lazy binding of the GetSpecialCharsForEdit function as it resides in
206 // a library above us.
207 //====================================================================
209 extern "C" { static void SAL_CALL thisModule() {} }
211 String GetSpecialCharsForEdit(Window* pParent, const Font& rFont)
213 static bool bDetermineFunction = false;
214 static PFunc_getSpecialCharsForEdit pfunc_getSpecialCharsForEdit = 0;
216 ::vos::OGuard aGuard( Application::GetSolarMutex() );
217 if ( !bDetermineFunction )
219 bDetermineFunction = true;
221 String sLibName = String::CreateFromAscii( STRING( DLL_NAME ) );
222 sLibName.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "sfx" ) ), String( RTL_CONSTASCII_USTRINGPARAM( "cui" ) ) );
224 rtl::OUString aLibName( sLibName );
225 oslModule handleMod = osl_loadModuleRelative(
226 &thisModule, aLibName.pData, 0 );
228 // get symbol
229 ::rtl::OUString aSymbol( RTL_CONSTASCII_USTRINGPARAM( "GetSpecialCharsForEdit" ) );
230 pfunc_getSpecialCharsForEdit = (PFunc_getSpecialCharsForEdit)osl_getFunctionSymbol( handleMod, aSymbol.pData );
231 DBG_ASSERT( pfunc_getSpecialCharsForEdit, "GetSpecialCharsForEdit() not found!" );
234 String aRet;
235 if ( pfunc_getSpecialCharsForEdit )
236 (*pfunc_getSpecialCharsForEdit)( pParent, rFont, aRet );
237 return aRet;
240 //====================================================================
242 FASTBOOL SfxApplication::Initialize_Impl()
244 RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mb93783) ::SfxApplication::Initialize_Impl" );
246 #ifdef TLX_VALIDATE
247 StgIo::SetErrorLink( LINK( this, SfxStorageErrHdl, Error ) );
248 #endif
250 Reference < XDesktop > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
251 if (!xDesktop.is())
252 throw RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Couldn't create mandatory desktop service!" )), xDesktop );
253 xDesktop->addTerminateListener( new SfxTerminateListener_Impl() );
255 Application::EnableAutoHelpId();
257 pAppData_Impl->pAppDispatch = new SfxStatusDispatcher;
258 pAppData_Impl->pAppDispatch->acquire();
260 // SV-Look
261 Help::EnableContextHelp();
262 Help::EnableExtHelp();
264 SvtLocalisationOptions aLocalisation;
265 Application::EnableAutoMnemonic ( aLocalisation.IsAutoMnemonic() );
266 Application::SetDialogScaleX ( (short)(aLocalisation.GetDialogScale()) );
269 #ifdef DBG_UTIL
270 // Der SimplerErrorHandler dient Debugzwecken. In der Product werden
271 // nichtgehandelte Fehler durch Errorcode 1 an SFX gegeben.
272 new SimpleErrorHandler;
273 #endif
274 new SfxErrorHandler(RID_ERRHDL, ERRCODE_AREA_TOOLS, ERRCODE_AREA_LIB1);
276 new SfxErrorHandler(
277 RID_SO_ERROR_HANDLER, ERRCODE_AREA_SO, ERRCODE_AREA_SO_END);
278 new SfxErrorHandler(
279 (RID_SJ_START +1), ERRCODE_AREA_JAVA, ERRCODE_AREA_JAVA_END);
280 new SfxErrorHandler(
281 RID_BASIC_START, ERRCODE_AREA_SBX, ERRCODE_AREA_SBX_END );
283 // diverse Pointer
284 SfxPickList::GetOrCreate( SvtHistoryOptions().GetSize( ePICKLIST ) );
286 /////////////////////////////////////////////////////////////////
288 DBG_ASSERT( !pAppData_Impl->pAppDispat, "AppDispatcher already exists" );
289 pAppData_Impl->pAppDispat = new SfxDispatcher((SfxDispatcher*)0);
290 pAppData_Impl->pSlotPool = new SfxSlotPool;
291 pAppData_Impl->pTbxCtrlFac = new SfxTbxCtrlFactArr_Impl;
292 pAppData_Impl->pStbCtrlFac = new SfxStbCtrlFactArr_Impl;
293 pAppData_Impl->pMenuCtrlFac = new SfxMenuCtrlFactArr_Impl;
294 pAppData_Impl->pViewFrames = new SfxViewFrameArr_Impl;
295 pAppData_Impl->pViewShells = new SfxViewShellArr_Impl;
296 pAppData_Impl->pObjShells = new SfxObjectShellArr_Impl;
297 pAppData_Impl->nInterfaces = SFX_INTERFACE_APP+8;
298 pAppData_Impl->pInterfaces = new SfxInterface*[pAppData_Impl->nInterfaces];
299 memset( pAppData_Impl->pInterfaces, 0, sizeof(SfxInterface*) * pAppData_Impl->nInterfaces );
301 Registrations_Impl();
303 // Subklasse initialisieren
304 pAppData_Impl->bDowning = sal_False;
305 Init();
307 // get CHAOS item pool...
308 pAppData_Impl->pPool = NoChaos::GetItemPool();
309 SetPool( pAppData_Impl->pPool );
311 if ( pAppData_Impl->bDowning )
312 return sal_False;
314 // App-Dispatcher aufbauen
315 pAppData_Impl->pAppDispat->Push(*this);
316 pAppData_Impl->pAppDispat->Flush();
317 pAppData_Impl->pAppDispat->DoActivate_Impl( sal_True, NULL );
320 ::vos::OGuard aGuard( Application::GetSolarMutex() );
321 // Set special characters callback on vcl edit control
322 Edit::SetGetSpecialCharsFunction(&GetSpecialCharsForEdit);
325 return sal_True;