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