xref: /aoo41x/main/sfx2/source/appl/appinit.cxx (revision d119d52d)
1*d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d119d52dSAndrew Rist  * distributed with this work for additional information
6*d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9*d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d119d52dSAndrew Rist  *
11*d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d119d52dSAndrew Rist  *
13*d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15*d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d119d52dSAndrew Rist  * specific language governing permissions and limitations
18*d119d52dSAndrew Rist  * under the License.
19*d119d52dSAndrew Rist  *
20*d119d52dSAndrew Rist  *************************************************************/
21*d119d52dSAndrew Rist 
22*d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <sfx2/app.hxx>
28cdf0e10cSrcweir #include <com/sun/star/frame/XTerminateListener.hpp>
29cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx>
30cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <svtools/soerr.hxx>
34cdf0e10cSrcweir #include <svtools/svtools.hrc>
35cdf0e10cSrcweir #include <unotools/saveopt.hxx>
36cdf0e10cSrcweir #include <unotools/localisationoptions.hxx>
37cdf0e10cSrcweir #include <tools/config.hxx>
38cdf0e10cSrcweir #ifndef _SV_RESARY_HXX
39cdf0e10cSrcweir #include <tools/resary.hxx>
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir #include <tools/urlobj.hxx>
42cdf0e10cSrcweir #include <svl/intitem.hxx>
43cdf0e10cSrcweir #include <svl/eitem.hxx>
44cdf0e10cSrcweir #include <svl/stritem.hxx>
45cdf0e10cSrcweir #ifndef _MSGBOX_HXX //autogen
46cdf0e10cSrcweir #include <vcl/msgbox.hxx>
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir #include <svtools/ehdl.hxx>
49cdf0e10cSrcweir #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
50cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
51cdf0e10cSrcweir #endif
52cdf0e10cSrcweir #include <unotools/configmgr.hxx>
53cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
54cdf0e10cSrcweir #include <vos/security.hxx>
55cdf0e10cSrcweir #include <ucbhelper/configurationkeys.hxx>
56cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
57cdf0e10cSrcweir #include <unotools/historyoptions.hxx>
58cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
59cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
60cdf0e10cSrcweir 
61cdf0e10cSrcweir #include <rtl/logfile.hxx>
62cdf0e10cSrcweir #include <vcl/edit.hxx>
63cdf0e10cSrcweir 
64cdf0e10cSrcweir #include <sfx2/unoctitm.hxx>
65cdf0e10cSrcweir #include "app.hrc"
66cdf0e10cSrcweir #include "sfxlocal.hrc"
67cdf0e10cSrcweir #include "appdata.hxx"
68cdf0e10cSrcweir #include "arrdecl.hxx"
69cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
70cdf0e10cSrcweir #include <sfx2/docfac.hxx>
71cdf0e10cSrcweir #include <sfx2/evntconf.hxx>
72cdf0e10cSrcweir #include "intro.hxx"
73cdf0e10cSrcweir #include <sfx2/mnumgr.hxx>
74cdf0e10cSrcweir #include <sfx2/msgpool.hxx>
75cdf0e10cSrcweir #include <sfx2/progress.hxx>
76cdf0e10cSrcweir #include "sfx2/sfxhelp.hxx"
77cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
78cdf0e10cSrcweir #include "sfxtypes.hxx"
79cdf0e10cSrcweir #include <sfx2/viewsh.hxx>
80cdf0e10cSrcweir #include "nochaos.hxx"
81cdf0e10cSrcweir #include <sfx2/fcontnr.hxx>
82cdf0e10cSrcweir #include "helper.hxx"	// SfxContentHelper::Kill()
83cdf0e10cSrcweir #include "sfxpicklist.hxx"
84cdf0e10cSrcweir #include <tools/svlibrary.hxx>
85cdf0e10cSrcweir 
86cdf0e10cSrcweir #ifdef UNX
87cdf0e10cSrcweir #define stricmp(a,b) strcmp(a,b)
88cdf0e10cSrcweir #endif
89cdf0e10cSrcweir 
90cdf0e10cSrcweir using namespace ::com::sun::star::uno;
91cdf0e10cSrcweir using namespace ::com::sun::star::frame;
92cdf0e10cSrcweir using namespace ::com::sun::star::lang;
93cdf0e10cSrcweir using namespace ::com::sun::star;
94cdf0e10cSrcweir namespace css = ::com::sun::star;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir class SfxTerminateListener_Impl : public ::cppu::WeakImplHelper2< XTerminateListener, XServiceInfo >
97cdf0e10cSrcweir {
98cdf0e10cSrcweir public:
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     // XTerminateListener
101cdf0e10cSrcweir     virtual void SAL_CALL queryTermination( const EventObject& aEvent ) throw( TerminationVetoException, RuntimeException );
102cdf0e10cSrcweir     virtual void SAL_CALL notifyTermination( const EventObject& aEvent ) throw( RuntimeException );
103cdf0e10cSrcweir     virtual void SAL_CALL disposing( const EventObject& Source ) throw( RuntimeException );
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     // XServiceInfo
106cdf0e10cSrcweir     virtual ::rtl::OUString SAL_CALL getImplementationName() throw (RuntimeException);
107cdf0e10cSrcweir     virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& sServiceName ) throw (RuntimeException);
108cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
109cdf0e10cSrcweir };
110cdf0e10cSrcweir 
disposing(const EventObject &)111cdf0e10cSrcweir void SAL_CALL SfxTerminateListener_Impl::disposing( const EventObject& ) throw( RuntimeException )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
queryTermination(const EventObject &)115cdf0e10cSrcweir void SAL_CALL SfxTerminateListener_Impl::queryTermination( const EventObject& ) throw(TerminationVetoException, RuntimeException )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
118cdf0e10cSrcweir     if ( !SFX_APP()->QueryExit_Impl() )
119cdf0e10cSrcweir         throw TerminationVetoException();
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
notifyTermination(const EventObject & aEvent)122cdf0e10cSrcweir void SAL_CALL SfxTerminateListener_Impl::notifyTermination( const EventObject& aEvent ) throw(RuntimeException )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir     static ::rtl::OUString SERVICE_GLOBALEVENTBROADCASTER = ::rtl::OUString::createFromAscii("com.sun.star.frame.GlobalEventBroadcaster");
125cdf0e10cSrcweir     static ::rtl::OUString EVENT_QUIT_APP                 = ::rtl::OUString::createFromAscii("OnCloseApp");
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     Reference< XDesktop > xDesktop( aEvent.Source, UNO_QUERY );
128cdf0e10cSrcweir     if( xDesktop.is() == sal_True )
129cdf0e10cSrcweir         xDesktop->removeTerminateListener( this );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
132cdf0e10cSrcweir     utl::ConfigManager::GetConfigManager()->StoreConfigItems();
133cdf0e10cSrcweir     SfxApplication* pApp = SFX_APP();
134cdf0e10cSrcweir     pApp->Broadcast( SfxSimpleHint( SFX_HINT_DEINITIALIZING ) );
135cdf0e10cSrcweir     pApp->Get_Impl()->pAppDispatch->ReleaseAll();
136cdf0e10cSrcweir     pApp->Get_Impl()->pAppDispatch->release();
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
139cdf0e10cSrcweir     css::uno::Reference< css::document::XEventListener > xGlobalBroadcaster(xSMGR->createInstance(SERVICE_GLOBALEVENTBROADCASTER), css::uno::UNO_QUERY);
140cdf0e10cSrcweir     if (xGlobalBroadcaster.is())
141cdf0e10cSrcweir     {
142cdf0e10cSrcweir         css::document::EventObject aEvent2;
143cdf0e10cSrcweir         aEvent2.EventName = EVENT_QUIT_APP;
144cdf0e10cSrcweir         xGlobalBroadcaster->notifyEvent(aEvent2);
145cdf0e10cSrcweir     }
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     //pApp->Deinitialize();
148cdf0e10cSrcweir 	delete pApp;
149cdf0e10cSrcweir 	Application::Quit();
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
getImplementationName()152cdf0e10cSrcweir ::rtl::OUString SAL_CALL SfxTerminateListener_Impl::getImplementationName() throw (RuntimeException)
153cdf0e10cSrcweir {
154cdf0e10cSrcweir     static const ::rtl::OUString IMPLNAME = ::rtl::OUString::createFromAscii("com.sun.star.comp.sfx2.SfxTerminateListener");
155cdf0e10cSrcweir     return IMPLNAME;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
supportsService(const::rtl::OUString & sServiceName)158cdf0e10cSrcweir ::sal_Bool SAL_CALL SfxTerminateListener_Impl::supportsService( const ::rtl::OUString& sServiceName ) throw (RuntimeException)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir     Sequence< ::rtl::OUString > lNames  = getSupportedServiceNames();
161cdf0e10cSrcweir     ::sal_Int32                 c       = lNames.getLength();
162cdf0e10cSrcweir     ::sal_Int32                 i       = 0;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     for (i=0; i<c; ++i)
165cdf0e10cSrcweir     {
166cdf0e10cSrcweir         if (lNames[i].equals(sServiceName))
167cdf0e10cSrcweir             return sal_True;
168cdf0e10cSrcweir     }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     return sal_False;
171cdf0e10cSrcweir }
172cdf0e10cSrcweir 
getSupportedServiceNames()173cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL SfxTerminateListener_Impl::getSupportedServiceNames() throw (RuntimeException)
174cdf0e10cSrcweir {
175cdf0e10cSrcweir     // Note: That service  does not realy exists .-)
176cdf0e10cSrcweir     // But this implementation is not thought to be registered realy within our service.rdb.
177cdf0e10cSrcweir     // At least we need the implementation name only to identify these service at the global desktop instance.
178cdf0e10cSrcweir     // The desktop must know, which listener will terminate the SfxApplication in real !
179cdf0e10cSrcweir     // It must call this special listener as last one ... otherwise we shutdown the SfxApplication BEFORE other listener
180cdf0e10cSrcweir     // can react ...
181cdf0e10cSrcweir     static const ::rtl::OUString SERVICENAME = ::rtl::OUString::createFromAscii("com.sun.star.frame.TerminateListener");
182cdf0e10cSrcweir     Sequence< ::rtl::OUString > lNames(1);
183cdf0e10cSrcweir     lNames[0] = SERVICENAME;
184cdf0e10cSrcweir     return lNames;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir //====================================================================
188cdf0e10cSrcweir 
189cdf0e10cSrcweir #define DOSTRING( x )			   			#x
190cdf0e10cSrcweir #define STRING( x )				   			DOSTRING( x )
191cdf0e10cSrcweir 
192cdf0e10cSrcweir typedef bool ( *PFunc_getSpecialCharsForEdit)( Window* i_pParent, const Font& i_rFont, String& o_rOutString );
193cdf0e10cSrcweir 
194cdf0e10cSrcweir //====================================================================
195cdf0e10cSrcweir // Lazy binding of the GetSpecialCharsForEdit function as it resides in
196cdf0e10cSrcweir // a library above us.
197cdf0e10cSrcweir //====================================================================
198cdf0e10cSrcweir 
thisModule()199cdf0e10cSrcweir extern "C" { static void SAL_CALL thisModule() {} }
200cdf0e10cSrcweir 
GetSpecialCharsForEdit(Window * pParent,const Font & rFont)201cdf0e10cSrcweir String GetSpecialCharsForEdit(Window* pParent, const Font& rFont)
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     static bool bDetermineFunction = false;
204cdf0e10cSrcweir     static PFunc_getSpecialCharsForEdit pfunc_getSpecialCharsForEdit = 0;
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
207cdf0e10cSrcweir     if ( !bDetermineFunction )
208cdf0e10cSrcweir     {
209cdf0e10cSrcweir         bDetermineFunction = true;
210cdf0e10cSrcweir 
211cdf0e10cSrcweir         static ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( SVLIBRARY( "cui" ) ) );
212cdf0e10cSrcweir         oslModule handleMod = osl_loadModuleRelative(
213cdf0e10cSrcweir             &thisModule, aLibName.pData, 0 );
214cdf0e10cSrcweir 
215cdf0e10cSrcweir         // get symbol
216cdf0e10cSrcweir         ::rtl::OUString aSymbol( RTL_CONSTASCII_USTRINGPARAM( "GetSpecialCharsForEdit" ) );
217cdf0e10cSrcweir         pfunc_getSpecialCharsForEdit = (PFunc_getSpecialCharsForEdit)osl_getFunctionSymbol( handleMod, aSymbol.pData );
218cdf0e10cSrcweir 	    DBG_ASSERT( pfunc_getSpecialCharsForEdit, "GetSpecialCharsForEdit() not found!" );
219cdf0e10cSrcweir     }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir     String aRet;
222cdf0e10cSrcweir     if ( pfunc_getSpecialCharsForEdit )
223cdf0e10cSrcweir         (*pfunc_getSpecialCharsForEdit)( pParent, rFont, aRet );
224cdf0e10cSrcweir     return aRet;
225cdf0e10cSrcweir }
226cdf0e10cSrcweir 
227cdf0e10cSrcweir //====================================================================
228cdf0e10cSrcweir 
Initialize_Impl()229cdf0e10cSrcweir bool SfxApplication::Initialize_Impl()
230cdf0e10cSrcweir {
231cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mb93783) ::SfxApplication::Initialize_Impl" );
232cdf0e10cSrcweir 
233cdf0e10cSrcweir #ifdef TLX_VALIDATE
234cdf0e10cSrcweir 	StgIo::SetErrorLink( LINK( this, SfxStorageErrHdl, Error ) );
235cdf0e10cSrcweir #endif
236cdf0e10cSrcweir 
237cdf0e10cSrcweir     Reference < XDesktop > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
238cdf0e10cSrcweir     if (!xDesktop.is())
239cdf0e10cSrcweir          throw RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Couldn't create mandatory desktop service!" )), xDesktop );
240cdf0e10cSrcweir     xDesktop->addTerminateListener( new SfxTerminateListener_Impl() );
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 	Application::EnableAutoHelpId();
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 	pAppData_Impl->pAppDispatch = new SfxStatusDispatcher;
245cdf0e10cSrcweir 	pAppData_Impl->pAppDispatch->acquire();
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 	// SV-Look
248cdf0e10cSrcweir 	Help::EnableContextHelp();
249cdf0e10cSrcweir 	Help::EnableExtHelp();
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 	SvtLocalisationOptions aLocalisation;
252cdf0e10cSrcweir 	Application::EnableAutoMnemonic	( aLocalisation.IsAutoMnemonic() );
253cdf0e10cSrcweir 	Application::SetDialogScaleX	( (short)(aLocalisation.GetDialogScale()) );
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 
256cdf0e10cSrcweir #ifdef DBG_UTIL
257cdf0e10cSrcweir 	// Der SimplerErrorHandler dient Debugzwecken. In der Product werden
258cdf0e10cSrcweir 	// nichtgehandelte Fehler durch Errorcode 1 an SFX gegeben.
259cdf0e10cSrcweir 	new SimpleErrorHandler;
260cdf0e10cSrcweir #endif
261cdf0e10cSrcweir 	pAppData_Impl->pBasicResMgr = CreateResManager("sb");
262cdf0e10cSrcweir 	pAppData_Impl->pSvtResMgr = CreateResManager("svt");
263cdf0e10cSrcweir 	new SfxErrorHandler( RID_ERRHDL, ERRCODE_AREA_TOOLS, ERRCODE_AREA_LIB1 );
264cdf0e10cSrcweir     new SfxErrorHandler( RID_SO_ERROR_HANDLER, ERRCODE_AREA_SO, ERRCODE_AREA_SO_END, pAppData_Impl->pSvtResMgr );
265cdf0e10cSrcweir 	new SfxErrorHandler( RID_BASIC_START, ERRCODE_AREA_SBX, ERRCODE_AREA_SBX_END, pAppData_Impl->pBasicResMgr );
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 	// diverse Pointer
268cdf0e10cSrcweir 	SfxPickList::GetOrCreate( SvtHistoryOptions().GetSize( ePICKLIST ) );
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 	/////////////////////////////////////////////////////////////////
271cdf0e10cSrcweir 
272cdf0e10cSrcweir     DBG_ASSERT( !pAppData_Impl->pAppDispat, "AppDispatcher already exists" );
273cdf0e10cSrcweir     pAppData_Impl->pAppDispat = new SfxDispatcher((SfxDispatcher*)0);
274cdf0e10cSrcweir     pAppData_Impl->pSlotPool = new SfxSlotPool;
275cdf0e10cSrcweir     pAppData_Impl->pTbxCtrlFac = new SfxTbxCtrlFactArr_Impl;
276cdf0e10cSrcweir     pAppData_Impl->pStbCtrlFac = new SfxStbCtrlFactArr_Impl;
277cdf0e10cSrcweir     pAppData_Impl->pMenuCtrlFac = new SfxMenuCtrlFactArr_Impl;
278cdf0e10cSrcweir     pAppData_Impl->pViewFrames = new SfxViewFrameArr_Impl;
279cdf0e10cSrcweir     pAppData_Impl->pViewShells = new SfxViewShellArr_Impl;
280cdf0e10cSrcweir     pAppData_Impl->pObjShells = new SfxObjectShellArr_Impl;
281cdf0e10cSrcweir     pAppData_Impl->nInterfaces = SFX_INTERFACE_APP+8;
282cdf0e10cSrcweir     pAppData_Impl->pInterfaces = new SfxInterface*[pAppData_Impl->nInterfaces];
283cdf0e10cSrcweir     memset( pAppData_Impl->pInterfaces, 0, sizeof(SfxInterface*) * pAppData_Impl->nInterfaces );
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 	Registrations_Impl();
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 	// Subklasse initialisieren
288cdf0e10cSrcweir     pAppData_Impl->bDowning = sal_False;
289cdf0e10cSrcweir 	Init();
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 	// get CHAOS item pool...
292cdf0e10cSrcweir 	pAppData_Impl->pPool = NoChaos::GetItemPool();
293cdf0e10cSrcweir 	SetPool( pAppData_Impl->pPool );
294cdf0e10cSrcweir 
295cdf0e10cSrcweir     if ( pAppData_Impl->bDowning )
296cdf0e10cSrcweir 		return sal_False;
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 	// App-Dispatcher aufbauen
299cdf0e10cSrcweir     pAppData_Impl->pAppDispat->Push(*this);
300cdf0e10cSrcweir     pAppData_Impl->pAppDispat->Flush();
301cdf0e10cSrcweir     pAppData_Impl->pAppDispat->DoActivate_Impl( sal_True, NULL );
302cdf0e10cSrcweir 
303cdf0e10cSrcweir     {
304cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
305cdf0e10cSrcweir         // Set special characters callback on vcl edit control
306cdf0e10cSrcweir         Edit::SetGetSpecialCharsFunction(&GetSpecialCharsForEdit);
307cdf0e10cSrcweir     }
308cdf0e10cSrcweir 
309cdf0e10cSrcweir     return sal_True;
310cdf0e10cSrcweir }
311