summaryrefslogtreecommitdiff
path: root/vcl/source/app/svmain.cxx
blob: 71e9c3c49bc66358c1befc6f0e12d04df7c5d3ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
/*************************************************************************
 *
 *  $RCSfile: svmain.cxx,v $
 *
 *  $Revision: 1.14 $
 *
 *  last change: $Author: mm $ $Date: 2001-02-23 18:07:40 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#define _SV_SVMAIN_CXX

#ifdef WNT
#include <tools/prewin.h>
#include <process.h>    // for _beginthreadex
#include <ole2.h>   // for _beginthreadex
#include <tools/postwin.h>
#endif

#ifdef UNX
#include <svunx.h>
#endif

#ifndef _SV_SALDATA_HXX
#include <saldata.hxx>
#endif
#ifndef _SV_SVSYS_HXX
#include <svsys.h>
#endif
#ifndef _SV_SALINST_HXX
#include <salinst.hxx>
#endif
#ifndef _SV_SALSOUND_HXX
#include <salsound.hxx>
#endif
#ifndef _SV_SALOGL_HXX
#include <salogl.hxx>
#endif
#ifndef _SV_SALWTYPE_HXX
#include <salwtype.hxx>
#endif
#ifndef _VOS_SIGNAL_HXX
#include <vos/signal.hxx>
#endif
#ifndef _VOS_SOCKET_HXX
#include <vos/socket.hxx>
#endif
#ifndef _TOOLS_H
#include <tools/tools.h>
#endif
#ifndef _DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef _UNIQID_HXX
#include <tools/unqid.hxx>
#endif
#ifndef _SV_SVDATA_HXX
#include <svdata.hxx>
#endif
#ifndef _SV_DBGGUI_HXX
#include <dbggui.hxx>
#endif
#ifndef _SV_SVAPP_HXX
#include <svapp.hxx>
#endif
#ifndef _SV_WRKWIN_HXX
#include <wrkwin.hxx>
#endif
#ifndef _SV_CVTGRF_HXX
#include <cvtgrf.hxx>
#endif
#ifndef _SV_IMAGE_HXX
#include <image.hxx>
#endif
#ifndef _SV_RESMGR_HXX
#include <resmgr.hxx>
#endif
#ifndef _SV_ACCMGR_HXX
#include <accmgr.hxx>
#endif
#ifndef _SV_IDLEMGR_HXX
#include <idlemgr.hxx>
#endif
#ifndef _SV_OUTDEV_H
#include <outdev.h>
#endif
#ifndef _SV_OUTFONT_HXX
#include <outfont.hxx>
#endif
#ifndef _SV_PRINT_H
#include <print.h>
#endif
#ifndef _SV_SETTINGS_HXX
#include <settings.hxx>
#endif
#ifndef TF_SVDATA
// HACK: Only for Exception-Hack
#ifndef _SV_SYSEXCHG_HXX
#include <sysexchg.hxx>
#endif
#endif

#include <vos/process.hxx>
#include <osl/file.hxx>

#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
#include <comphelper/processfactory.hxx>
#endif

#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#endif

#ifdef REMOTE_APPSERVER
#include <config.hxx>
#include <ooffice.hxx>
#include <rversion.h>
#include <xevthdl.hxx>
#include <rmevents.hxx>
#include <rmprint.hxx>
#include <outdev.h>
#include <vos/mutex.hxx>
#include <vos/timer.hxx>
#include "rvp.hxx"
#include <unotools/atom.hxx>


#include <com/sun/star/portal/client/XRmStatus.hpp>
#include <com/sun/star/portal/client/XRmSync.hpp>

using namespace ::rtl;
using namespace ::cppu;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::portal::client;

#ifdef UNX
class SalData
{

    void Init (int *pIPointer, char *pCPointer[] );
};
void SalData::Init (int *pIPointer, char *pCPointer[] )
{};
#endif /* UNX */

#endif /* REMOTE_APPSERVER */

#pragma hdrstop

// =======================================================================

class ImplVCLExceptionHandler : public ::vos::OSignalHandler
{
public:
    virtual ::vos::OSignalHandler::TSignalAction SAL_CALL signal( ::vos::OSignalHandler::TSignalInfo* pInfo );
};

// -----------------------------------------------------------------------

::vos::OSignalHandler::TSignalAction SAL_CALL ImplVCLExceptionHandler::signal( ::vos::OSignalHandler::TSignalInfo* pInfo )
{
    static BOOL bIn = FALSE;

    // Wenn wir nocheinmal abstuerzen, verabschieden wir uns gleich
    if ( !bIn )
    {
        USHORT nVCLException = 0;

        // UAE
        if ( (pInfo->Signal == TSignal_AccessViolation)     ||
             (pInfo->Signal == TSignal_IntegerDivideByZero) ||
             (pInfo->Signal == TSignal_FloatDivideByZero)   ||
             (pInfo->Signal == TSignal_DebugBreak) )
            nVCLException = EXC_SYSTEM;

        // RC
        if ((pInfo->Signal == TSignal_SignalUser) &&
            (pInfo->UserSignal == OSL_SIGNAL_USER_RESOURCEFAILURE) )
            nVCLException = EXC_RSCNOTLOADED;

        // DISPLAY-Unix
        if ((pInfo->Signal == TSignal_SignalUser) &&
            (pInfo->UserSignal == OSL_SIGNAL_USER_X11SUBSYSTEMERROR) )
            nVCLException = EXC_DISPLAY;

        // Remote-Client
        if ((pInfo->Signal == TSignal_SignalUser) &&
            (pInfo->UserSignal == OSL_SIGNAL_USER_RVPCONNECTIONERROR) )
            nVCLException = EXC_REMOTE;

        if ( nVCLException )
        {
            bIn = TRUE;
            // Timer nicht mehr anhalten, da ansonsten die UAE-Box
            // auch nicht mehr gepaintet wird
            ImplSVData* pSVData = ImplGetSVData();
            if ( pSVData->mpApp )
            {
                USHORT nOldMode = Application::GetSystemWindowMode();
                Application::SetSystemWindowMode( nOldMode & ~SYSTEMWINDOW_MODE_NOAUTOMODE );
                pSVData->mpApp->Exception( nVCLException );
                Application::SetSystemWindowMode( nOldMode );
            }
            bIn = FALSE;

#ifndef REMOTE_APPSERVER
            return NAMESPACE_VOS(OSignalHandler)::TAction_CallNextHandler;
#else
            return NAMESPACE_VOS(OSignalHandler)::TAction_KillApplication;
#endif
        }
    }

    return NAMESPACE_VOS(OSignalHandler)::TAction_CallNextHandler;
}

// =======================================================================
BOOL SVMain()
{
    ImplSVData* pSVData = ImplGetSVData();

    DBG_ASSERT( pSVData->mpApp, "no instance of class Application" );

    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xMS;

    BOOL bInit = InitVCL( xMS );

    if( bInit )
    {
        // Application-Main rufen
        pSVData->maAppData.mbInAppMain = TRUE;
        pSVData->mpApp->Main();
        pSVData->maAppData.mbInAppMain = FALSE;
    }

    DeInitVCL();
    return bInit;
}

// This variable is set, when no Application object is instantiated
// before SVInit is called
static Application *        pOwnSvApp = NULL;
// Exception handler. pExceptionHandler != NULL => VCL already inited
ImplVCLExceptionHandler *   pExceptionHandler = NULL;

class Application_Impl : public Application
{
public:
    void                Main(){};
};

BOOL InitVCL( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr )
{
    if( pExceptionHandler != NULL )
        return FALSE;

    if( !ImplGetSVData()->mpApp )
    {
        pOwnSvApp = new Application_Impl();
    }
    InitSalMain();

#ifdef WNT
    // remember data, copied from WinMain
    SalData* pData = GetAppSalData();
    if ( pData )    // Im AppServer NULL
    {
        STARTUPINFO aSI;
        aSI.cb = sizeof( aSI );
        GetStartupInfo( &aSI );
        pData->mhInst                   = GetModuleHandle( NULL );
        pData->mhPrevInst               = NULL;
        pData->mnCmdShow                = aSI.wShowWindow;
    }
#endif

    /*AllSettings aAS;
    Application::SetSettings( aAS );// ???
    */
    ImplSVData* pSVData = ImplGetSVData();

    // SV bei den Tools anmelden
    InitTools();

    //DBG_ASSERT( !pSVData->maAppData.mxMSF.is(), "VCL service factory already set" )
    //pSVData->maAppData.mxMSF = rSMgr;

    // Main-Thread-Id merken
    pSVData->mnMainThreadId = ::vos::OThread::getCurrentIdentifier();

    NAMESPACE_VOS( OStartupInfo )   aStartInfo;
    NAMESPACE_RTL( OUString )       aExeFileName;

#ifdef REMOTE_APPSERVER
    // create condition now to avoid race
    pSVData->mpStartUpCond = new NAMESPACE_VOS(OCondition);

    pSVData->mpUserInfo = new UserOnPrintServer;

    Application::EnterMultiThread( TRUE );
#endif

    if( pSVData->mpApp )
        // call init to initialize application class
        // soffice/sfx implementation creates the global service manager
        pSVData->mpApp->Init();

#ifdef REMOTE_APPSERVER
    {
    Reference< XMultiServiceFactory > rSMgr = ::comphelper::getProcessServiceFactory();

    pSVData->mpRmEventQueue = new RmEventQueue;
    pSVData->mpRemotePrinterList = new RemotePrinterList( rSMgr );
    pSVData->mpWindowObjectMutex = new VOS_NAMESPACE(OMutex,vos);
    pSVData->maAppData.mpSolarMutex = new ImplRemoteYieldMutex;

    pSVData->maGDIData.mpScreenFontList   = new ImplDevFontList;
    pSVData->maGDIData.mpScreenFontCache  = new ImplFontCache( FALSE );

    // OSL_ENSURE( 0 , "Office is waiting ....\n" );
    pSVData->mpStartUpCond->wait();
    delete pSVData->mpStartUpCond;
    pSVData->mpStartUpCond = NULL;

    // we have to acquire solar mutex before we do our first rvp call!
    pSVData->maAppData.mpSolarMutex->acquire();

    if( pSVData->mxClientFactory.is() )
    {
/*
        pSVData->mpRVPNormalSync = new RVPSync(
            Reference< ::com::sun::star::portal::client::XRmSync >(
                pSVData->mxClientFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "RVPSync_Normal.stardiv.de" ) ) ), UNO_QUERY ));

        pSVData->mpRVPSoundSync = new RVPSync(
            Reference< ::com::sun::star::portal::client::XRmSync >(
                pSVData->mxClientFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "RVPSync_Sound.stardiv.de" ) ) ), UNO_QUERY ));

        pSVData->mpAtoms = new ::utl::AtomClient(
            Reference< ::com::sun::star::util::XAtomServer >(
                pSVData->mxClientFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "ClientAtomServer.stardiv.de" ) ) ), UNO_QUERY ) );

        Reference< XInterface > rX = pSVData->mxClientFactory->createInstance(
            OUString( RTL_CONSTASCII_USTRINGPARAM( "OfficeStatus.stardiv.de" ) ) );

        pSVData->mxStatus = Reference < ::com::sun::star::portal::client::XRmStatus > ( rX , UNO_QUERY );
        CHECK_FOR_RVPSYNC_NORMAL()
*/
        if ( pSVData->mnRemoteVersion != REMOTE_VCLVERSION )
//      if( pSVData->mxStatus->GetRemoteVersion() != REMOTE_VCLVERSION )
        {
//          CHECK_FOR_RVPSYNC_NORMAL()
//          pSVData->mxStatus->ShowError(
//              OUString( RTL_CONSTASCII_USTRINGPARAM("Wrong Office-Version")), 0 );
            CHECK_FOR_RVPSYNC_NORMAL()
            pSVData->mxStatus->Quit();
            return sal_False;
        }
    }
    else
    {
        return sal_False;
    }

    ImplInitRemotePrinterList();

//  pSVData->maAppData.mpSolarMutex->acquire();
    }

#endif

    // Sal initialisieren
#ifndef REMOTE_APPSERVER
    pSVData->mpDefInst = CreateSalInstance();
    if ( !pSVData->mpDefInst )
        return FALSE;
#endif

    // Den AppFileName gleich holen und absolut machen, bevor das
    // WorkingDirectory sich aendert...
    aStartInfo.getExecutableFile( aExeFileName );

    // convert path to native file format
    rtl::OUString aNativeFileName;
    osl::FileBase::getSystemPathFromNormalizedPath(aExeFileName, aNativeFileName);

    pSVData->maAppData.mpAppFileName = new String( aNativeFileName );

    // Initialize global data
    pSVData->maGDIData.mpScreenFontList     = new ImplDevFontList;
    pSVData->maGDIData.mpScreenFontCache    = new ImplFontCache( FALSE );
    pSVData->maGDIData.mpGrfConverter       = new GraphicConverter;

    // Exception-Handler setzen
#ifndef TF_SVDATA
    // HACK: Hier SystemExchange initialisieren, damit Exception-Handler unter Windows funktioniert
    CreateSystemExchange();
#endif
    pExceptionHandler = new ImplVCLExceptionHandler();

    // Debug-Daten initialisieren
    DBGGUI_INIT();

    return TRUE;
}

void DeInitVCL()
{
    delete pExceptionHandler;
    pExceptionHandler = NULL;

    ImplSVData* pSVData = ImplGetSVData();

    // Debug Daten zuruecksetzen
    DBGGUI_DEINIT();

    // Access list
    List* pList = pSVData->maAppData.mpAccessList;
    if( pList )
    {
        for( void* pLink = pList->First(); pLink; pLink = pList->Next() )
            delete (Link*) pLink;
        delete pList;
        pSVData->maAppData.mpAccessList = NULL;
    }

    // globale daten wieder freigeben
#ifndef REMOTE_APPSERVER
    SalSound::Release();
    SalOpenGL::Release();
#endif

    // free global data
    delete pSVData->maGDIData.mpGrfConverter;

    if ( pSVData->maAppData.mpIdleMgr )
        delete pSVData->maAppData.mpIdleMgr;
    ImplDeInitTimer();

    if ( pSVData->maWinData.mpMsgBoxImgList )
    {
        delete pSVData->maWinData.mpMsgBoxImgList;
        pSVData->maWinData.mpMsgBoxImgList = NULL;
    }
    if ( pSVData->maCtrlData.mpCheckImgList )
    {
        delete pSVData->maCtrlData.mpCheckImgList;
        pSVData->maCtrlData.mpCheckImgList = NULL;
    }
    if ( pSVData->maCtrlData.mpRadioImgList )
    {
        delete pSVData->maCtrlData.mpRadioImgList;
        pSVData->maCtrlData.mpRadioImgList = NULL;
    }
    if ( pSVData->maCtrlData.mpPinImgList )
    {
        delete pSVData->maCtrlData.mpPinImgList;
        pSVData->maCtrlData.mpPinImgList = NULL;
    }
    if ( pSVData->maCtrlData.mpSplitHPinImgList )
    {
        delete pSVData->maCtrlData.mpSplitHPinImgList;
        pSVData->maCtrlData.mpSplitHPinImgList = NULL;
    }
    if ( pSVData->maCtrlData.mpSplitVPinImgList )
    {
        delete pSVData->maCtrlData.mpSplitVPinImgList;
        pSVData->maCtrlData.mpSplitVPinImgList = NULL;
    }
    if ( pSVData->maCtrlData.mpSplitHArwImgList )
    {
        delete pSVData->maCtrlData.mpSplitHArwImgList;
        pSVData->maCtrlData.mpSplitHArwImgList = NULL;
    }
    if ( pSVData->maCtrlData.mpSplitVArwImgList )
    {
        delete pSVData->maCtrlData.mpSplitVArwImgList;
        pSVData->maCtrlData.mpSplitVArwImgList = NULL;
    }
    if ( pSVData->mpDefaultWin )
    {
        delete pSVData->mpDefaultWin;
        pSVData->mpDefaultWin = NULL;
    }
    if ( pSVData->mpResMgr )
    {
        delete pSVData->mpResMgr;
        pSVData->mpResMgr = NULL;
    }

#ifdef REMOTE_APPSERVER
    if( pSVData->mpUserInfo )
    {
        try
        {
            delete pSVData->mpUserInfo;
        }
        catch(::com::sun::star::uno::Exception&)
        {
        }
        pSVData->mpUserInfo = NULL;
    }
    if( pSVData->mpRemotePrinterList )
    {
        try
        {
            delete pSVData->mpRemotePrinterList;
        }
        catch(::com::sun::star::uno::Exception&)
        {
        }
        pSVData->mpRemotePrinterList = NULL;
    }
    if ( pSVData->mpClientPrintersInfo )
    {
        try
        {
            delete pSVData->mpClientPrintersInfo;
        }
        catch (::com::sun::star::uno::Exception&)
        {
        }
        pSVData->mpClientPrintersInfo;
    }
    if( pSVData->mxClientFactory.is() )
    {
        try
        {
            pSVData->mxClientFactory = Reference < XMultiServiceFactory >();
        }
        catch(::com::sun::star::uno::Exception&)
        {
        }
    }

    if( pSVData->mxMultiFactory.is() )
    {
        try
        {
            pSVData->mxMultiFactory.clear();
        }
        catch(::com::sun::star::uno::Exception&)
        {
        }

    }
    CORmStarOffice::eraseRemoteCaches();
    if( pSVData->mxStatus.is() )
    {
        try
        {
             CHECK_FOR_RVPSYNC_NORMAL()

            delete pSVData->mpRVPNormalSync;
            delete pSVData->mpRVPSoundSync;
            delete pSVData->mpAtoms;

            pSVData->mxStatus->Quit();
            pSVData->mxStatus = Reference < ::com::sun::star::portal::client::XRmStatus >();
        }
         catch(::com::sun::star::uno::Exception&)
         {
         }
    }

    if( pSVData->mpApp )
        // call deinit to deinitialize application class
        // soffice/sfx implementation disposes the global service manager
        // Warning: After this call you can't call uno services
        pSVData->mpApp->DeInit();

    pSVData->maAppData.mpSolarMutex->release();
    delete pSVData->maAppData.mpSolarMutex;
    pSVData->maAppData.mpSolarMutex = NULL;
    pSVData->mpOTimer->release();
    pSVData->mpOTimer = NULL;
    delete pSVData->mpRmEventQueue;
    pSVData->mpRmEventQueue = NULL;
    delete pSVData->mpWindowObjectMutex;
    pSVData->mpWindowObjectMutex = NULL;

    if ( pSVData->mpKeyNames )
    {
        for( String* pObj = pSVData->mpKeyNames->First(); pObj; pObj = pSVData->mpKeyNames->Next() )
            delete pObj;
        delete pSVData->mpKeyNames;
    }
#else
    if( pSVData->mpApp )
        // call deinit to deinitialize application class
        // soffice/sfx implementation disposes the global service manager
        // Warning: After this call you can't call uno services
        pSVData->mpApp->DeInit();
#endif

    if ( pSVData->maAppData.mpSettings )
    {
        delete pSVData->maAppData.mpSettings;
        pSVData->maAppData.mpSettings = NULL;
    }
    if ( pSVData->maAppData.mpAccelMgr )
    {
        delete pSVData->maAppData.mpAccelMgr;
        pSVData->maAppData.mpAccelMgr = NULL;
    }
    if ( pSVData->maAppData.mpUniqueIdCont )
    {
        delete pSVData->maAppData.mpUniqueIdCont;
        pSVData->maAppData.mpUniqueIdCont = NULL;
    }
    if ( pSVData->maAppData.mpAppFileName )
    {
        delete pSVData->maAppData.mpAppFileName;
        pSVData->maAppData.mpAppFileName = NULL;
    }
    if ( pSVData->maAppData.mpAppName )
    {
        delete pSVData->maAppData.mpAppName;
        pSVData->maAppData.mpAppName = NULL;
    }
    if ( pSVData->maAppData.mpDisplayName )
    {
        delete pSVData->maAppData.mpDisplayName;
        pSVData->maAppData.mpDisplayName = NULL;
    }
    if ( pSVData->maAppData.mpResPath )
    {
        delete pSVData->maAppData.mpResPath;
        pSVData->maAppData.mpResPath = NULL;
    }

    if ( pSVData->maAppData.mpFirstHotKey )
        ImplFreeHotKeyData();
    if ( pSVData->maAppData.mpFirstEventHook )
        ImplFreeEventHookData();

    ImplDeletePrnQueueList();
    delete pSVData->maGDIData.mpScreenFontList;
    pSVData->maGDIData.mpScreenFontList = NULL;
    delete pSVData->maGDIData.mpScreenFontCache;
    pSVData->maGDIData.mpScreenFontCache = NULL;
    ImplFreeOutDevFontData();

    ResMgr::DestroyAllResMgr();

    // Sal deinitialisieren
#ifndef REMOTE_APPSERVER
    DestroySalInstance( pSVData->mpDefInst );
#endif

    DeInitTools();

    DeInitSalMain();
    if( pOwnSvApp )
    {
        delete pOwnSvApp;
        pOwnSvApp = NULL;
    }
}

// only one call is allowed
struct WorkerThreadData
{
    oslWorkerFunction   pWorker;
    void *              pThreadData;
    WorkerThreadData( oslWorkerFunction pWorker_, void * pThreadData_ )
        : pWorker( pWorker_ )
        , pThreadData( pThreadData_ )
    {
    }
};

#ifdef WNT
static HANDLE hThreadID = 0;
static unsigned __stdcall _threadmain( void *pArgs )
{
    OleInitialize( NULL );
    ((WorkerThreadData*)pArgs)->pWorker( ((WorkerThreadData*)pArgs)->pThreadData );
    delete (WorkerThreadData*)pArgs;
    OleUninitialize();
    hThreadID = 0;
    return 0;
}
#else
static oslThread hThreadID = 0;
static void SAL_CALL MainWorkerFunction( void* pArgs )
{
    ((WorkerThreadData*)pArgs)->pWorker( ((WorkerThreadData*)pArgs)->pThreadData );
    delete (WorkerThreadData*)pArgs;
    hThreadID = 0;
}
#endif

void CreateMainLoopThread( oslWorkerFunction pWorker, void * pThreadData )
{
#ifdef WNT
    // sal thread alway call CoInitializeEx, so a sysdepen implementation is necessary

    unsigned uThreadID;
    hThreadID = (HANDLE)_beginthreadex(
        NULL,       // no security handle
        0,          // stacksize 0 means default
        _threadmain,    // thread worker function
        new WorkerThreadData( pWorker, pThreadData ),       // arguments for worker function
        0,          // 0 means: create immediatly otherwise use CREATE_SUSPENDED
        &uThreadID );   // thread id to fill
#else
    hThreadID = osl_createThread( MainWorkerFunction, new WorkerThreadData( pWorker, pThreadData ) );
#endif
}

void JoinMainLoopThread()
{
    if( hThreadID )
    {
#ifdef WNT
        WaitForSingleObject(hThreadID, INFINITE);
#else
        osl_joinWithThread(hThreadID);
        osl_freeThreadHandle( hThreadID );
#endif
    }
}