xref: /aoo42x/main/vcl/source/app/svmain.cxx (revision 86e1cf34)
19f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59f62ea84SAndrew Rist  * distributed with this work for additional information
69f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
99f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
109f62ea84SAndrew Rist  *
119f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
129f62ea84SAndrew Rist  *
139f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149f62ea84SAndrew Rist  * software distributed under the License is distributed on an
159f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
179f62ea84SAndrew Rist  * specific language governing permissions and limitations
189f62ea84SAndrew Rist  * under the License.
199f62ea84SAndrew Rist  *
209f62ea84SAndrew Rist  *************************************************************/
219f62ea84SAndrew Rist 
229f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "rtl/logfile.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "osl/file.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "vos/signal.hxx"
32cdf0e10cSrcweir #include "vos/process.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "tools/tools.h"
35cdf0e10cSrcweir #include "tools/debug.hxx"
36cdf0e10cSrcweir #include "tools/unqid.hxx"
37cdf0e10cSrcweir #include "tools/resmgr.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include "comphelper/processfactory.hxx"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include "unotools/syslocaleoptions.hxx"
42cdf0e10cSrcweir #include "unotools/fontcfg.hxx"
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include "vcl/svapp.hxx"
45cdf0e10cSrcweir #include "vcl/wrkwin.hxx"
46cdf0e10cSrcweir #include "vcl/cvtgrf.hxx"
47cdf0e10cSrcweir #include "vcl/image.hxx"
48cdf0e10cSrcweir #include "vcl/settings.hxx"
49cdf0e10cSrcweir #include "vcl/unowrap.hxx"
50cdf0e10cSrcweir #include "vcl/configsettings.hxx"
51cdf0e10cSrcweir #include "vcl/lazydelete.hxx"
52cdf0e10cSrcweir 
53cdf0e10cSrcweir #ifdef WNT
54cdf0e10cSrcweir #include <tools/prewin.h>
55cdf0e10cSrcweir #include <process.h>    // for _beginthreadex
56cdf0e10cSrcweir #include <ole2.h>   // for _beginthreadex
57cdf0e10cSrcweir #include <tools/postwin.h>
58df906e24SSteve Yin #include <com/sun/star/accessibility/XMSAAService.hpp>
59df906e24SSteve Yin #include <win/g_msaasvc.h>
60df906e24SSteve Yin using namespace com::sun::star::accessibility;
61cdf0e10cSrcweir #endif
62cdf0e10cSrcweir 
63cdf0e10cSrcweir // [ed 5/14/02 Add in explicit check for quartz graphics.  OS X will define
64cdf0e10cSrcweir // unx for both quartz and X11 graphics, but we include svunx.h only if we're
65cdf0e10cSrcweir // building X11 graphics layers.
66cdf0e10cSrcweir 
67cdf0e10cSrcweir #if defined UNX && ! defined QUARTZ
68cdf0e10cSrcweir //#include "svunx.h"
69cdf0e10cSrcweir #endif
70cdf0e10cSrcweir 
71cdf0e10cSrcweir //#include "svsys.h"
72cdf0e10cSrcweir 
73cdf0e10cSrcweir #include "salinst.hxx"
74cdf0e10cSrcweir #include "salwtype.hxx"
75cdf0e10cSrcweir #include "svdata.hxx"
76cdf0e10cSrcweir #include "dbggui.hxx"
77cdf0e10cSrcweir #include "accmgr.hxx"
78cdf0e10cSrcweir #include "idlemgr.hxx"
79cdf0e10cSrcweir #include "outdev.h"
80cdf0e10cSrcweir #include "outfont.hxx"
81cdf0e10cSrcweir #include "print.h"
82cdf0e10cSrcweir #include "salsys.hxx"
83cdf0e10cSrcweir #include "saltimer.hxx"
84cdf0e10cSrcweir #include "salimestatus.hxx"
85cdf0e10cSrcweir #include "impimagetree.hxx"
86cdf0e10cSrcweir #include "xconnection.hxx"
87cdf0e10cSrcweir 
88cdf0e10cSrcweir #include "com/sun/star/lang/XMultiServiceFactory.hpp"
89cdf0e10cSrcweir #include "com/sun/star/lang/XComponent.hpp"
90cdf0e10cSrcweir 
91cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx"
92cdf0e10cSrcweir #include "uno/current_context.hxx"
93cdf0e10cSrcweir 
94cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
95cdf0e10cSrcweir #include <typeinfo>
96cdf0e10cSrcweir #include "rtl/strbuf.hxx"
97cdf0e10cSrcweir #endif
98cdf0e10cSrcweir 
99cdf0e10cSrcweir namespace {
100cdf0e10cSrcweir 
101cdf0e10cSrcweir namespace css = com::sun::star;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir using namespace ::rtl;
106cdf0e10cSrcweir using namespace ::com::sun::star::uno;
107cdf0e10cSrcweir using namespace ::com::sun::star::lang;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 
111cdf0e10cSrcweir // =======================================================================
112cdf0e10cSrcweir 
113cdf0e10cSrcweir class ImplVCLExceptionHandler : public ::vos::OSignalHandler
114cdf0e10cSrcweir {
115cdf0e10cSrcweir public:
116cdf0e10cSrcweir     virtual ::vos::OSignalHandler::TSignalAction SAL_CALL signal( ::vos::OSignalHandler::TSignalInfo* pInfo );
117cdf0e10cSrcweir };
118cdf0e10cSrcweir 
119cdf0e10cSrcweir // -----------------------------------------------------------------------
120cdf0e10cSrcweir 
signal(::vos::OSignalHandler::TSignalInfo * pInfo)121cdf0e10cSrcweir ::vos::OSignalHandler::TSignalAction SAL_CALL ImplVCLExceptionHandler::signal( ::vos::OSignalHandler::TSignalInfo* pInfo )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir     static sal_Bool bIn = sal_False;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     // Wenn wir nocheinmal abstuerzen, verabschieden wir uns gleich
126cdf0e10cSrcweir     if ( !bIn )
127cdf0e10cSrcweir     {
128cdf0e10cSrcweir         sal_uInt16 nVCLException = 0;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         // UAE
131cdf0e10cSrcweir         if ( (pInfo->Signal == osl_Signal_AccessViolation)     ||
132cdf0e10cSrcweir              (pInfo->Signal == osl_Signal_IntegerDivideByZero) ||
133cdf0e10cSrcweir              (pInfo->Signal == osl_Signal_FloatDivideByZero)   ||
134cdf0e10cSrcweir              (pInfo->Signal == osl_Signal_DebugBreak) )
135cdf0e10cSrcweir             nVCLException = EXC_SYSTEM;
136cdf0e10cSrcweir 
137cdf0e10cSrcweir         // RC
138cdf0e10cSrcweir         if ((pInfo->Signal == osl_Signal_User) &&
139cdf0e10cSrcweir             (pInfo->UserSignal == OSL_SIGNAL_USER_RESOURCEFAILURE) )
140cdf0e10cSrcweir             nVCLException = EXC_RSCNOTLOADED;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir         // DISPLAY-Unix
143cdf0e10cSrcweir         if ((pInfo->Signal == osl_Signal_User) &&
144cdf0e10cSrcweir             (pInfo->UserSignal == OSL_SIGNAL_USER_X11SUBSYSTEMERROR) )
145cdf0e10cSrcweir             nVCLException = EXC_DISPLAY;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir         // Remote-Client
148cdf0e10cSrcweir         if ((pInfo->Signal == osl_Signal_User) &&
149cdf0e10cSrcweir             (pInfo->UserSignal == OSL_SIGNAL_USER_RVPCONNECTIONERROR) )
150cdf0e10cSrcweir             nVCLException = EXC_REMOTE;
151cdf0e10cSrcweir 
152cdf0e10cSrcweir         if ( nVCLException )
153cdf0e10cSrcweir         {
154cdf0e10cSrcweir             bIn = sal_True;
155cdf0e10cSrcweir 
156cdf0e10cSrcweir             ::vos::OGuard aLock(&Application::GetSolarMutex());
157cdf0e10cSrcweir 
158cdf0e10cSrcweir             // Timer nicht mehr anhalten, da ansonsten die UAE-Box
159cdf0e10cSrcweir             // auch nicht mehr gepaintet wird
160cdf0e10cSrcweir             ImplSVData* pSVData = ImplGetSVData();
161cdf0e10cSrcweir             if ( pSVData->mpApp )
162cdf0e10cSrcweir             {
163cdf0e10cSrcweir                 sal_uInt16 nOldMode = Application::GetSystemWindowMode();
164cdf0e10cSrcweir                 Application::SetSystemWindowMode( nOldMode & ~SYSTEMWINDOW_MODE_NOAUTOMODE );
165cdf0e10cSrcweir                 pSVData->mpApp->Exception( nVCLException );
166cdf0e10cSrcweir                 Application::SetSystemWindowMode( nOldMode );
167cdf0e10cSrcweir             }
168cdf0e10cSrcweir             bIn = sal_False;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir             return vos::OSignalHandler::TAction_CallNextHandler;
171cdf0e10cSrcweir         }
172cdf0e10cSrcweir     }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     return vos::OSignalHandler::TAction_CallNextHandler;
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir // =======================================================================
ImplSVMain()178cdf0e10cSrcweir sal_Bool ImplSVMain()
179cdf0e10cSrcweir {
180cdf0e10cSrcweir     // The 'real' SVMain()
181cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "vcl (ss112471) ::SVMain" );
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     ImplSVData* pSVData = ImplGetSVData();
184cdf0e10cSrcweir 
185cdf0e10cSrcweir     DBG_ASSERT( pSVData->mpApp, "no instance of class Application" );
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     css::uno::Reference<XMultiServiceFactory> xMS;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 
190cdf0e10cSrcweir     sal_Bool bInit = InitVCL( xMS );
191cdf0e10cSrcweir 
192cdf0e10cSrcweir     if( bInit )
193cdf0e10cSrcweir     {
194cdf0e10cSrcweir         // Application-Main rufen
195cdf0e10cSrcweir         pSVData->maAppData.mbInAppMain = sal_True;
196cdf0e10cSrcweir         pSVData->mpApp->Main();
197cdf0e10cSrcweir         pSVData->maAppData.mbInAppMain = sal_False;
198cdf0e10cSrcweir     }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     if( pSVData->mxDisplayConnection.is() )
201cdf0e10cSrcweir     {
202cdf0e10cSrcweir         pSVData->mxDisplayConnection->terminate();
203cdf0e10cSrcweir         pSVData->mxDisplayConnection.clear();
204cdf0e10cSrcweir     }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     // This is a hack to work around the problem of the asynchronous nature
207cdf0e10cSrcweir     // of bridging accessibility through Java: on shutdown there might still
208cdf0e10cSrcweir     // be some events in the AWT EventQueue, which need the SolarMutex which
209cdf0e10cSrcweir     // - on the other hand - is destroyed in DeInitVCL(). So empty the queue
210cdf0e10cSrcweir     // here ..
211cdf0e10cSrcweir 	css::uno::Reference< XComponent > xComponent(pSVData->mxAccessBridge, UNO_QUERY);
212cdf0e10cSrcweir 	if( xComponent.is() )
213cdf0e10cSrcweir 	{
214cdf0e10cSrcweir 	  sal_uLong nCount = Application::ReleaseSolarMutex();
215cdf0e10cSrcweir 	  xComponent->dispose();
216cdf0e10cSrcweir 	  Application::AcquireSolarMutex(nCount);
217cdf0e10cSrcweir 	  pSVData->mxAccessBridge.clear();
218cdf0e10cSrcweir 	}
219cdf0e10cSrcweir 
220cdf0e10cSrcweir     DeInitVCL();
221df906e24SSteve Yin 	#ifdef WNT
222df906e24SSteve Yin 		if( g_acc_manager1 )
223df906e24SSteve Yin 			g_acc_manager1->release();
224df906e24SSteve Yin 	#endif
225cdf0e10cSrcweir     return bInit;
226cdf0e10cSrcweir }
227cdf0e10cSrcweir 
SVMain()228cdf0e10cSrcweir sal_Bool SVMain()
229cdf0e10cSrcweir {
230cdf0e10cSrcweir     // #i47888# allow for alternative initialization as required for e.g. MacOSX
231cdf0e10cSrcweir     extern sal_Bool ImplSVMainHook( sal_Bool* );
232cdf0e10cSrcweir 
233cdf0e10cSrcweir     sal_Bool bInit;
234cdf0e10cSrcweir     if( ImplSVMainHook( &bInit ) )
235cdf0e10cSrcweir         return bInit;
236cdf0e10cSrcweir     else
237cdf0e10cSrcweir         return ImplSVMain();
238cdf0e10cSrcweir }
239cdf0e10cSrcweir // This variable is set, when no Application object is instantiated
240cdf0e10cSrcweir // before SVInit is called
241cdf0e10cSrcweir static Application *        pOwnSvApp = NULL;
242cdf0e10cSrcweir // Exception handler. pExceptionHandler != NULL => VCL already inited
243cdf0e10cSrcweir ImplVCLExceptionHandler *   pExceptionHandler = NULL;
244cdf0e10cSrcweir 
245cdf0e10cSrcweir class Application_Impl : public Application
246cdf0e10cSrcweir {
247cdf0e10cSrcweir public:
Main()248cdf0e10cSrcweir     void                Main(){};
249cdf0e10cSrcweir };
250cdf0e10cSrcweir 
251cdf0e10cSrcweir class DesktopEnvironmentContext: public cppu::WeakImplHelper1< com::sun::star::uno::XCurrentContext >
252cdf0e10cSrcweir {
253cdf0e10cSrcweir public:
DesktopEnvironmentContext(const com::sun::star::uno::Reference<com::sun::star::uno::XCurrentContext> & ctx)254cdf0e10cSrcweir     DesktopEnvironmentContext( const com::sun::star::uno::Reference< com::sun::star::uno::XCurrentContext > & ctx)
255cdf0e10cSrcweir         : m_xNextContext( ctx ) {}
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     // XCurrentContext
258cdf0e10cSrcweir     virtual com::sun::star::uno::Any SAL_CALL getValueByName( const rtl::OUString& Name )
259cdf0e10cSrcweir             throw (com::sun::star::uno::RuntimeException);
260cdf0e10cSrcweir 
261cdf0e10cSrcweir private:
262cdf0e10cSrcweir     com::sun::star::uno::Reference< com::sun::star::uno::XCurrentContext > m_xNextContext;
263cdf0e10cSrcweir };
264cdf0e10cSrcweir 
getValueByName(const rtl::OUString & Name)265cdf0e10cSrcweir Any SAL_CALL DesktopEnvironmentContext::getValueByName( const rtl::OUString& Name) throw (RuntimeException)
266cdf0e10cSrcweir {
267cdf0e10cSrcweir     Any retVal;
268cdf0e10cSrcweir 
269cdf0e10cSrcweir     if ( 0 == Name.compareToAscii( "system.desktop-environment" ) )
270cdf0e10cSrcweir     {
271cdf0e10cSrcweir         retVal = makeAny( Application::GetDesktopEnvironment() );
272cdf0e10cSrcweir     }
273cdf0e10cSrcweir     else if( m_xNextContext.is() )
274cdf0e10cSrcweir     {
275cdf0e10cSrcweir         // Call next context in chain if found
276cdf0e10cSrcweir         retVal = m_xNextContext->getValueByName( Name );
277cdf0e10cSrcweir     }
278cdf0e10cSrcweir     return retVal;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir 
InitVCL(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & rSMgr)281cdf0e10cSrcweir sal_Bool InitVCL( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr )
282cdf0e10cSrcweir {
283cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "vcl (ss112471) ::InitVCL" );
284cdf0e10cSrcweir 
285cdf0e10cSrcweir     if( pExceptionHandler != NULL )
286cdf0e10cSrcweir         return sal_False;
287cdf0e10cSrcweir 
288cdf0e10cSrcweir     if( ! ImplGetSVData() )
289cdf0e10cSrcweir         ImplInitSVData();
290cdf0e10cSrcweir 
291cdf0e10cSrcweir     if( !ImplGetSVData()->mpApp )
292cdf0e10cSrcweir     {
293cdf0e10cSrcweir         pOwnSvApp = new Application_Impl();
294cdf0e10cSrcweir     }
295cdf0e10cSrcweir     InitSalMain();
296cdf0e10cSrcweir 
297cdf0e10cSrcweir     /*AllSettings aAS;
298cdf0e10cSrcweir     Application::SetSettings( aAS );// ???
299cdf0e10cSrcweir     */
300cdf0e10cSrcweir     ImplSVData* pSVData = ImplGetSVData();
301cdf0e10cSrcweir 
302cdf0e10cSrcweir     // SV bei den Tools anmelden
303cdf0e10cSrcweir     InitTools();
304cdf0e10cSrcweir 
305cdf0e10cSrcweir     DBG_ASSERT( !pSVData->maAppData.mxMSF.is(), "VCL service factory already set" );
306cdf0e10cSrcweir     pSVData->maAppData.mxMSF = rSMgr;
307cdf0e10cSrcweir 
308cdf0e10cSrcweir     // Main-Thread-Id merken
309cdf0e10cSrcweir     pSVData->mnMainThreadId = ::vos::OThread::getCurrentIdentifier();
310cdf0e10cSrcweir 
311cdf0e10cSrcweir     vos::OStartupInfo   aStartInfo;
312cdf0e10cSrcweir     rtl::OUString       aExeFileName;
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 
315cdf0e10cSrcweir     // Sal initialisieren
316cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_TRACE( aLog, "{ ::CreateSalInstance" );
317cdf0e10cSrcweir     pSVData->mpDefInst = CreateSalInstance();
318cdf0e10cSrcweir     if ( !pSVData->mpDefInst )
319cdf0e10cSrcweir         return sal_False;
320cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_TRACE( aLog, "} ::CreateSalInstance" );
321cdf0e10cSrcweir 
322cdf0e10cSrcweir     // Desktop Environment context (to be able to get value of "system.desktop-environment" as soon as possible)
323cdf0e10cSrcweir     com::sun::star::uno::setCurrentContext(
324cdf0e10cSrcweir         new DesktopEnvironmentContext( com::sun::star::uno::getCurrentContext() ) );
325cdf0e10cSrcweir 
326cdf0e10cSrcweir 	// Initialize application instance (should be done after initialization of VCL SAL part)
327cdf0e10cSrcweir     if( pSVData->mpApp )
328cdf0e10cSrcweir         // call init to initialize application class
329cdf0e10cSrcweir         // soffice/sfx implementation creates the global service manager
330cdf0e10cSrcweir         pSVData->mpApp->Init();
331cdf0e10cSrcweir 
332cdf0e10cSrcweir     // Den AppFileName gleich holen und absolut machen, bevor das
333cdf0e10cSrcweir     // WorkingDirectory sich aendert...
334cdf0e10cSrcweir     aStartInfo.getExecutableFile( aExeFileName );
335cdf0e10cSrcweir 
336cdf0e10cSrcweir     // convert path to native file format
337cdf0e10cSrcweir     rtl::OUString aNativeFileName;
338cdf0e10cSrcweir     osl::FileBase::getSystemPathFromFileURL( aExeFileName, aNativeFileName );
339cdf0e10cSrcweir     pSVData->maAppData.mpAppFileName = new String( aNativeFileName );
340cdf0e10cSrcweir 
341cdf0e10cSrcweir     // Initialize global data
342cdf0e10cSrcweir     pSVData->maGDIData.mpScreenFontList     = new ImplDevFontList;
343cdf0e10cSrcweir     pSVData->maGDIData.mpScreenFontCache    = new ImplFontCache( sal_False );
344cdf0e10cSrcweir     pSVData->maGDIData.mpGrfConverter       = new GraphicConverter;
345cdf0e10cSrcweir 
346cdf0e10cSrcweir     // Exception-Handler setzen
347cdf0e10cSrcweir     pExceptionHandler = new ImplVCLExceptionHandler();
348cdf0e10cSrcweir 
349cdf0e10cSrcweir     // Debug-Daten initialisieren
350cdf0e10cSrcweir     DBGGUI_INIT();
351cdf0e10cSrcweir 
352cdf0e10cSrcweir     return sal_True;
353cdf0e10cSrcweir }
354cdf0e10cSrcweir 
DeInitVCL()355cdf0e10cSrcweir void DeInitVCL()
356cdf0e10cSrcweir {
357cdf0e10cSrcweir     ImplSVData* pSVData = ImplGetSVData();
358cdf0e10cSrcweir     pSVData->mbDeInit = sal_True;
359cdf0e10cSrcweir 
360cdf0e10cSrcweir     vcl::DeleteOnDeinitBase::ImplDeleteOnDeInit();
361cdf0e10cSrcweir 
362cdf0e10cSrcweir     // give ime status a chance to destroy its own windows
363cdf0e10cSrcweir 	delete pSVData->mpImeStatus;
364cdf0e10cSrcweir 	pSVData->mpImeStatus = NULL;
365cdf0e10cSrcweir 
366cdf0e10cSrcweir     #if OSL_DEBUG_LEVEL > 0
367cdf0e10cSrcweir     rtl::OStringBuffer aBuf( 256 );
368cdf0e10cSrcweir     aBuf.append( "DeInitVCL: some top Windows are still alive\n" );
369cdf0e10cSrcweir     long nTopWindowCount = Application::GetTopWindowCount();
370cdf0e10cSrcweir     long nBadTopWindows = nTopWindowCount;
371cdf0e10cSrcweir     for( long i = 0; i < nTopWindowCount; i++ )
372cdf0e10cSrcweir     {
373cdf0e10cSrcweir         Window* pWin = Application::GetTopWindow( i );
374cdf0e10cSrcweir         // default window will be destroyed further down
375cdf0e10cSrcweir         // but may still be useful during deinit up to that point
376cdf0e10cSrcweir         if( pWin == pSVData->mpDefaultWin )
377cdf0e10cSrcweir             nBadTopWindows--;
378cdf0e10cSrcweir         else
379cdf0e10cSrcweir         {
380cdf0e10cSrcweir             aBuf.append( "text = \"" );
381cdf0e10cSrcweir             aBuf.append( rtl::OUStringToOString( pWin->GetText(), osl_getThreadTextEncoding() ) );
382cdf0e10cSrcweir             aBuf.append( "\" type = \"" );
383cdf0e10cSrcweir             aBuf.append( typeid(*pWin).name() );
384cdf0e10cSrcweir             aBuf.append( "\", ptr = 0x" );
385cdf0e10cSrcweir             aBuf.append( sal_Int64( pWin ), 16 );
386cdf0e10cSrcweir             aBuf.append( "\n" );
387cdf0e10cSrcweir         }
388cdf0e10cSrcweir     }
389cdf0e10cSrcweir     DBG_ASSERT( nBadTopWindows==0, aBuf.getStr() );
390cdf0e10cSrcweir     #endif
391cdf0e10cSrcweir 
392cdf0e10cSrcweir     ImplImageTreeSingletonRef()->shutDown();
393cdf0e10cSrcweir 
394cdf0e10cSrcweir     delete pExceptionHandler;
395cdf0e10cSrcweir     pExceptionHandler = NULL;
396cdf0e10cSrcweir 
397cdf0e10cSrcweir     // Debug Daten zuruecksetzen
398cdf0e10cSrcweir     DBGGUI_DEINIT();
399cdf0e10cSrcweir 
400cdf0e10cSrcweir     // free global data
401cdf0e10cSrcweir     delete pSVData->maGDIData.mpGrfConverter;
402cdf0e10cSrcweir 
403cdf0e10cSrcweir     if( pSVData->mpSettingsConfigItem )
404cdf0e10cSrcweir         delete pSVData->mpSettingsConfigItem, pSVData->mpSettingsConfigItem = NULL;
405cdf0e10cSrcweir     if( pSVData->maGDIData.mpDefaultFontConfiguration )
406cdf0e10cSrcweir         delete pSVData->maGDIData.mpDefaultFontConfiguration, pSVData->maGDIData.mpDefaultFontConfiguration = NULL;
407cdf0e10cSrcweir     if( pSVData->maGDIData.mpFontSubstConfiguration )
408cdf0e10cSrcweir         delete pSVData->maGDIData.mpFontSubstConfiguration, pSVData->maGDIData.mpFontSubstConfiguration = NULL;
409cdf0e10cSrcweir 
410cdf0e10cSrcweir     if ( pSVData->maAppData.mpIdleMgr )
411cdf0e10cSrcweir         delete pSVData->maAppData.mpIdleMgr;
412cdf0e10cSrcweir     Timer::ImplDeInitTimer();
413cdf0e10cSrcweir 
414cdf0e10cSrcweir     if ( pSVData->maWinData.mpMsgBoxImgList )
415cdf0e10cSrcweir     {
416cdf0e10cSrcweir         delete pSVData->maWinData.mpMsgBoxImgList;
417cdf0e10cSrcweir         pSVData->maWinData.mpMsgBoxImgList = NULL;
418cdf0e10cSrcweir     }
419cdf0e10cSrcweir     if ( pSVData->maWinData.mpMsgBoxHCImgList )
420cdf0e10cSrcweir     {
421cdf0e10cSrcweir         delete pSVData->maWinData.mpMsgBoxHCImgList;
422cdf0e10cSrcweir         pSVData->maWinData.mpMsgBoxHCImgList = NULL;
423cdf0e10cSrcweir     }
424cdf0e10cSrcweir     if ( pSVData->maCtrlData.mpCheckImgList )
425cdf0e10cSrcweir     {
426cdf0e10cSrcweir         delete pSVData->maCtrlData.mpCheckImgList;
427cdf0e10cSrcweir         pSVData->maCtrlData.mpCheckImgList = NULL;
428cdf0e10cSrcweir     }
429cdf0e10cSrcweir     if ( pSVData->maCtrlData.mpRadioImgList )
430cdf0e10cSrcweir     {
431cdf0e10cSrcweir         delete pSVData->maCtrlData.mpRadioImgList;
432cdf0e10cSrcweir         pSVData->maCtrlData.mpRadioImgList = NULL;
433cdf0e10cSrcweir     }
434cdf0e10cSrcweir     if ( pSVData->maCtrlData.mpPinImgList )
435cdf0e10cSrcweir     {
436cdf0e10cSrcweir         delete pSVData->maCtrlData.mpPinImgList;
437cdf0e10cSrcweir         pSVData->maCtrlData.mpPinImgList = NULL;
438cdf0e10cSrcweir     }
439cdf0e10cSrcweir     if ( pSVData->maCtrlData.mpSplitHPinImgList )
440cdf0e10cSrcweir     {
441cdf0e10cSrcweir         delete pSVData->maCtrlData.mpSplitHPinImgList;
442cdf0e10cSrcweir         pSVData->maCtrlData.mpSplitHPinImgList = NULL;
443cdf0e10cSrcweir     }
444cdf0e10cSrcweir     if ( pSVData->maCtrlData.mpSplitVPinImgList )
445cdf0e10cSrcweir     {
446cdf0e10cSrcweir         delete pSVData->maCtrlData.mpSplitVPinImgList;
447cdf0e10cSrcweir         pSVData->maCtrlData.mpSplitVPinImgList = NULL;
448cdf0e10cSrcweir     }
449cdf0e10cSrcweir     if ( pSVData->maCtrlData.mpSplitHArwImgList )
450cdf0e10cSrcweir     {
451cdf0e10cSrcweir         delete pSVData->maCtrlData.mpSplitHArwImgList;
452cdf0e10cSrcweir         pSVData->maCtrlData.mpSplitHArwImgList = NULL;
453cdf0e10cSrcweir     }
454cdf0e10cSrcweir     if ( pSVData->maCtrlData.mpSplitVArwImgList )
455cdf0e10cSrcweir     {
456cdf0e10cSrcweir         delete pSVData->maCtrlData.mpSplitVArwImgList;
457cdf0e10cSrcweir         pSVData->maCtrlData.mpSplitVArwImgList = NULL;
458cdf0e10cSrcweir     }
459cdf0e10cSrcweir     if ( pSVData->maCtrlData.mpDisclosurePlus )
460cdf0e10cSrcweir     {
461cdf0e10cSrcweir         delete pSVData->maCtrlData.mpDisclosurePlus;
462cdf0e10cSrcweir         pSVData->maCtrlData.mpDisclosurePlus = NULL;
463cdf0e10cSrcweir     }
464cdf0e10cSrcweir     if ( pSVData->maCtrlData.mpDisclosurePlusHC )
465cdf0e10cSrcweir     {
466cdf0e10cSrcweir         delete pSVData->maCtrlData.mpDisclosurePlusHC;
467cdf0e10cSrcweir         pSVData->maCtrlData.mpDisclosurePlusHC = NULL;
468cdf0e10cSrcweir     }
469cdf0e10cSrcweir     if ( pSVData->maCtrlData.mpDisclosureMinus )
470cdf0e10cSrcweir     {
471cdf0e10cSrcweir         delete pSVData->maCtrlData.mpDisclosureMinus;
472cdf0e10cSrcweir         pSVData->maCtrlData.mpDisclosureMinus = NULL;
473cdf0e10cSrcweir     }
474cdf0e10cSrcweir     if ( pSVData->maCtrlData.mpDisclosureMinusHC )
475cdf0e10cSrcweir     {
476cdf0e10cSrcweir         delete pSVData->maCtrlData.mpDisclosureMinusHC;
477cdf0e10cSrcweir         pSVData->maCtrlData.mpDisclosureMinusHC = NULL;
478cdf0e10cSrcweir     }
479cdf0e10cSrcweir     if ( pSVData->mpDefaultWin )
480cdf0e10cSrcweir     {
481cdf0e10cSrcweir         delete pSVData->mpDefaultWin;
482cdf0e10cSrcweir         pSVData->mpDefaultWin = NULL;
483cdf0e10cSrcweir     }
484cdf0e10cSrcweir 
485cdf0e10cSrcweir 	// #114285# Moved here from ImplDeInitSVData...
486cdf0e10cSrcweir     if ( pSVData->mpUnoWrapper )
487cdf0e10cSrcweir     {
488cdf0e10cSrcweir         pSVData->mpUnoWrapper->Destroy();
489cdf0e10cSrcweir         pSVData->mpUnoWrapper = NULL;
490cdf0e10cSrcweir     }
491cdf0e10cSrcweir 
492cdf0e10cSrcweir     pSVData->maAppData.mxMSF.clear();
493cdf0e10cSrcweir 
494cdf0e10cSrcweir     if( pSVData->mpApp )
495cdf0e10cSrcweir         // call deinit to deinitialize application class
496cdf0e10cSrcweir         // soffice/sfx implementation disposes the global service manager
497cdf0e10cSrcweir         // Warning: After this call you can't call uno services
498cdf0e10cSrcweir         pSVData->mpApp->DeInit();
499cdf0e10cSrcweir 
500cdf0e10cSrcweir     if ( pSVData->maAppData.mpSettings )
501cdf0e10cSrcweir     {
502cdf0e10cSrcweir 		if ( pSVData->maAppData.mpCfgListener )
503cdf0e10cSrcweir 		{
504cdf0e10cSrcweir 			pSVData->maAppData.mpSettings->GetSysLocale().GetOptions().RemoveListener( pSVData->maAppData.mpCfgListener );
505cdf0e10cSrcweir 			delete pSVData->maAppData.mpCfgListener;
506cdf0e10cSrcweir 		}
507cdf0e10cSrcweir 
508cdf0e10cSrcweir         delete pSVData->maAppData.mpSettings;
509cdf0e10cSrcweir         pSVData->maAppData.mpSettings = NULL;
510cdf0e10cSrcweir     }
511cdf0e10cSrcweir     if ( pSVData->maAppData.mpAccelMgr )
512cdf0e10cSrcweir     {
513cdf0e10cSrcweir         delete pSVData->maAppData.mpAccelMgr;
514cdf0e10cSrcweir         pSVData->maAppData.mpAccelMgr = NULL;
515cdf0e10cSrcweir     }
516cdf0e10cSrcweir     if ( pSVData->maAppData.mpUniqueIdCont )
517cdf0e10cSrcweir     {
518cdf0e10cSrcweir         delete pSVData->maAppData.mpUniqueIdCont;
519cdf0e10cSrcweir         pSVData->maAppData.mpUniqueIdCont = NULL;
520cdf0e10cSrcweir     }
521cdf0e10cSrcweir     if ( pSVData->maAppData.mpAppFileName )
522cdf0e10cSrcweir     {
523cdf0e10cSrcweir         delete pSVData->maAppData.mpAppFileName;
524cdf0e10cSrcweir         pSVData->maAppData.mpAppFileName = NULL;
525cdf0e10cSrcweir     }
526cdf0e10cSrcweir     if ( pSVData->maAppData.mpAppName )
527cdf0e10cSrcweir     {
528cdf0e10cSrcweir         delete pSVData->maAppData.mpAppName;
529cdf0e10cSrcweir         pSVData->maAppData.mpAppName = NULL;
530cdf0e10cSrcweir     }
531cdf0e10cSrcweir     if ( pSVData->maAppData.mpDisplayName )
532cdf0e10cSrcweir     {
533cdf0e10cSrcweir         delete pSVData->maAppData.mpDisplayName;
534cdf0e10cSrcweir         pSVData->maAppData.mpDisplayName = NULL;
535cdf0e10cSrcweir     }
536cdf0e10cSrcweir     if ( pSVData->maAppData.mpEventListeners )
537cdf0e10cSrcweir     {
538cdf0e10cSrcweir         delete pSVData->maAppData.mpEventListeners;
539cdf0e10cSrcweir         pSVData->maAppData.mpEventListeners = NULL;
540cdf0e10cSrcweir     }
541cdf0e10cSrcweir     if ( pSVData->maAppData.mpKeyListeners )
542cdf0e10cSrcweir     {
543cdf0e10cSrcweir         delete pSVData->maAppData.mpKeyListeners;
544cdf0e10cSrcweir         pSVData->maAppData.mpKeyListeners = NULL;
545cdf0e10cSrcweir     }
546cdf0e10cSrcweir 
547cdf0e10cSrcweir     if ( pSVData->maAppData.mpFirstHotKey )
548cdf0e10cSrcweir         ImplFreeHotKeyData();
549cdf0e10cSrcweir     if ( pSVData->maAppData.mpFirstEventHook )
550cdf0e10cSrcweir         ImplFreeEventHookData();
551cdf0e10cSrcweir 
552cdf0e10cSrcweir     ImplDeletePrnQueueList();
553cdf0e10cSrcweir     delete pSVData->maGDIData.mpScreenFontList;
554cdf0e10cSrcweir     pSVData->maGDIData.mpScreenFontList = NULL;
555cdf0e10cSrcweir     delete pSVData->maGDIData.mpScreenFontCache;
556cdf0e10cSrcweir     pSVData->maGDIData.mpScreenFontCache = NULL;
557cdf0e10cSrcweir     ImplFreeOutDevFontData();
558cdf0e10cSrcweir 
559cdf0e10cSrcweir     if ( pSVData->mpResMgr )
560cdf0e10cSrcweir     {
561cdf0e10cSrcweir         delete pSVData->mpResMgr;
562cdf0e10cSrcweir         pSVData->mpResMgr = NULL;
563cdf0e10cSrcweir     }
564cdf0e10cSrcweir 
565cdf0e10cSrcweir     ResMgr::DestroyAllResMgr();
566cdf0e10cSrcweir 
567cdf0e10cSrcweir 	// destroy all Sal interfaces before destorying the instance
568cdf0e10cSrcweir 	// and thereby unloading the plugin
569cdf0e10cSrcweir 	delete pSVData->mpSalSystem;
570cdf0e10cSrcweir 	pSVData->mpSalSystem = NULL;
571cdf0e10cSrcweir 	delete pSVData->mpSalTimer;
572cdf0e10cSrcweir 	pSVData->mpSalTimer = NULL;
573cdf0e10cSrcweir 
574cdf0e10cSrcweir     // Sal deinitialisieren
575cdf0e10cSrcweir     DestroySalInstance( pSVData->mpDefInst );
576cdf0e10cSrcweir 
577cdf0e10cSrcweir     DeInitTools();
578cdf0e10cSrcweir 
579cdf0e10cSrcweir     DeInitSalMain();
580cdf0e10cSrcweir 
581cdf0e10cSrcweir     if( pOwnSvApp )
582cdf0e10cSrcweir     {
583cdf0e10cSrcweir         delete pOwnSvApp;
584cdf0e10cSrcweir         pOwnSvApp = NULL;
585cdf0e10cSrcweir     }
586cdf0e10cSrcweir }
587cdf0e10cSrcweir 
588cdf0e10cSrcweir // only one call is allowed
589cdf0e10cSrcweir struct WorkerThreadData
590cdf0e10cSrcweir {
591cdf0e10cSrcweir     oslWorkerFunction   pWorker;
592cdf0e10cSrcweir     void *              pThreadData;
WorkerThreadDataWorkerThreadData593cdf0e10cSrcweir     WorkerThreadData( oslWorkerFunction pWorker_, void * pThreadData_ )
594cdf0e10cSrcweir         : pWorker( pWorker_ )
595cdf0e10cSrcweir         , pThreadData( pThreadData_ )
596cdf0e10cSrcweir     {
597cdf0e10cSrcweir     }
598cdf0e10cSrcweir };
599cdf0e10cSrcweir 
600cdf0e10cSrcweir #ifdef WNT
601cdf0e10cSrcweir static HANDLE hThreadID = 0;
_threadmain(void * pArgs)602cdf0e10cSrcweir static unsigned __stdcall _threadmain( void *pArgs )
603cdf0e10cSrcweir {
604cdf0e10cSrcweir     OleInitialize( NULL );
605cdf0e10cSrcweir     ((WorkerThreadData*)pArgs)->pWorker( ((WorkerThreadData*)pArgs)->pThreadData );
606cdf0e10cSrcweir     delete (WorkerThreadData*)pArgs;
607cdf0e10cSrcweir     OleUninitialize();
608cdf0e10cSrcweir     hThreadID = 0;
609cdf0e10cSrcweir     return 0;
610cdf0e10cSrcweir }
611cdf0e10cSrcweir #else
612cdf0e10cSrcweir static oslThread hThreadID = 0;
613cdf0e10cSrcweir extern "C"
614cdf0e10cSrcweir {
MainWorkerFunction(void * pArgs)615cdf0e10cSrcweir static void SAL_CALL MainWorkerFunction( void* pArgs )
616cdf0e10cSrcweir {
617cdf0e10cSrcweir     ((WorkerThreadData*)pArgs)->pWorker( ((WorkerThreadData*)pArgs)->pThreadData );
618cdf0e10cSrcweir     delete (WorkerThreadData*)pArgs;
619cdf0e10cSrcweir     hThreadID = 0;
620cdf0e10cSrcweir }
621cdf0e10cSrcweir } // extern "C"
622cdf0e10cSrcweir #endif
623cdf0e10cSrcweir 
CreateMainLoopThread(oslWorkerFunction pWorker,void * pThreadData)624cdf0e10cSrcweir void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData )
625cdf0e10cSrcweir {
626cdf0e10cSrcweir #ifdef WNT
627cdf0e10cSrcweir     // sal thread alway call CoInitializeEx, so a sysdepen implementation is necessary
628cdf0e10cSrcweir 
629cdf0e10cSrcweir     unsigned uThreadID;
630cdf0e10cSrcweir     hThreadID = (HANDLE)_beginthreadex(
631cdf0e10cSrcweir         NULL,       // no security handle
632cdf0e10cSrcweir         0,          // stacksize 0 means default
633cdf0e10cSrcweir         _threadmain,    // thread worker function
634cdf0e10cSrcweir         new WorkerThreadData( pWorker, pThreadData ),       // arguments for worker function
635*86e1cf34SPedro Giffuni         0,          // 0 means: create immediately otherwise use CREATE_SUSPENDED
636cdf0e10cSrcweir         &uThreadID );   // thread id to fill
637cdf0e10cSrcweir #else
638cdf0e10cSrcweir     hThreadID = osl_createThread( MainWorkerFunction, new WorkerThreadData( pWorker, pThreadData ) );
639cdf0e10cSrcweir #endif
640cdf0e10cSrcweir }
641cdf0e10cSrcweir 
JoinMainLoopThread()642cdf0e10cSrcweir void JoinMainLoopThread()
643cdf0e10cSrcweir {
644cdf0e10cSrcweir     if( hThreadID )
645cdf0e10cSrcweir     {
646cdf0e10cSrcweir #ifdef WNT
647cdf0e10cSrcweir         WaitForSingleObject(hThreadID, INFINITE);
648cdf0e10cSrcweir #else
649cdf0e10cSrcweir         osl_joinWithThread(hThreadID);
650cdf0e10cSrcweir         osl_destroyThread( hThreadID );
651cdf0e10cSrcweir #endif
652cdf0e10cSrcweir     }
653cdf0e10cSrcweir }
654