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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org 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 version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include "rtl/logfile.hxx"
#include <osl/file.hxx>
#include <osl/signal.h>
#include "tools/tools.h"
#include "tools/debug.hxx"
#include "tools/resmgr.hxx"
#include "comphelper/processfactory.hxx"
#include "unotools/syslocaleoptions.hxx"
#include "unotools/fontcfg.hxx"
#include "vcl/svapp.hxx"
#include "vcl/wrkwin.hxx"
#include "vcl/cvtgrf.hxx"
#include "vcl/image.hxx"
#include "vcl/settings.hxx"
#include "vcl/unowrap.hxx"
#include "vcl/configsettings.hxx"
#include "vcl/lazydelete.hxx"
#ifdef WNT
#include <svsys.h>
#include <process.h> // for _beginthreadex
#include <ole2.h> // for _beginthreadex
#endif
// [ed 5/14/02 Add in explicit check for quartz graphics. OS X will define
// unx for both quartz and X11 graphics, but we include svunx.h only if we're
// building X11 graphics layers.
#if defined UNX && ! defined QUARTZ
//#include "svunx.h"
#endif
//#include "svsys.h"
#include "salinst.hxx"
#include "salwtype.hxx"
#include "svdata.hxx"
#include "dbggui.hxx"
#include "accmgr.hxx"
#include "idlemgr.hxx"
#include "outdev.h"
#include "outfont.hxx"
#include "print.h"
#include "salsys.hxx"
#include "saltimer.hxx"
#include "salimestatus.hxx"
#include "impimagetree.hxx"
#include "xconnection.hxx"
#include "osl/process.h"
#include "com/sun/star/lang/XMultiServiceFactory.hpp"
#include "com/sun/star/lang/XComponent.hpp"
#include "cppuhelper/implbase1.hxx"
#include "uno/current_context.hxx"
#if OSL_DEBUG_LEVEL > 0
#include <typeinfo>
#include "rtl/strbuf.hxx"
#endif
using ::rtl::OUString;
using namespace ::com::sun::star;
// =======================================================================
oslSignalAction SAL_CALL VCLExceptionSignal_impl( void* /*pData*/, oslSignalInfo* pInfo)
{
static bool bIn = false;
// Wenn wir nocheinmal abstuerzen, verabschieden wir uns gleich
if ( !bIn )
{
sal_uInt16 nVCLException = 0;
// UAE
if ( (pInfo->Signal == osl_Signal_AccessViolation) ||
(pInfo->Signal == osl_Signal_IntegerDivideByZero) ||
(pInfo->Signal == osl_Signal_FloatDivideByZero) ||
(pInfo->Signal == osl_Signal_DebugBreak) )
nVCLException = EXC_SYSTEM;
// RC
if ((pInfo->Signal == osl_Signal_User) &&
(pInfo->UserSignal == OSL_SIGNAL_USER_RESOURCEFAILURE) )
nVCLException = EXC_RSCNOTLOADED;
// DISPLAY-Unix
if ((pInfo->Signal == osl_Signal_User) &&
(pInfo->UserSignal == OSL_SIGNAL_USER_X11SUBSYSTEMERROR) )
nVCLException = EXC_DISPLAY;
// Remote-Client
if ((pInfo->Signal == osl_Signal_User) &&
(pInfo->UserSignal == OSL_SIGNAL_USER_RVPCONNECTIONERROR) )
nVCLException = EXC_REMOTE;
if ( nVCLException )
{
bIn = true;
SolarMutexGuard aLock;
// Timer nicht mehr anhalten, da ansonsten die UAE-Box
// auch nicht mehr gepaintet wird
ImplSVData* pSVData = ImplGetSVData();
if ( pSVData->mpApp )
{
sal_uInt16 nOldMode = Application::GetSystemWindowMode();
Application::SetSystemWindowMode( nOldMode & ~SYSTEMWINDOW_MODE_NOAUTOMODE );
pSVData->mpApp->Exception( nVCLException );
Application::SetSystemWindowMode( nOldMode );
}
bIn = false;
return osl_Signal_ActCallNextHdl;
}
}
return osl_Signal_ActCallNextHdl;
}
// =======================================================================
int ImplSVMain()
{
// The 'real' SVMain()
RTL_LOGFILE_CONTEXT( aLog, "vcl (ss112471) ::SVMain" );
ImplSVData* pSVData = ImplGetSVData();
DBG_ASSERT( pSVData->mpApp, "no instance of class Application" );
uno::Reference<lang::XMultiServiceFactory> xMS;
int nReturn = EXIT_FAILURE;
sal_Bool bInit = InitVCL( xMS );
if( bInit )
{
// Application-Main rufen
pSVData->maAppData.mbInAppMain = sal_True;
nReturn = pSVData->mpApp->Main();
pSVData->maAppData.mbInAppMain = sal_False;
}
if( pSVData->mxDisplayConnection.is() )
{
pSVData->mxDisplayConnection->terminate();
pSVData->mxDisplayConnection.clear();
}
// This is a hack to work around the problem of the asynchronous nature
// of bridging accessibility through Java: on shutdown there might still
// be some events in the AWT EventQueue, which need the SolarMutex which
// - on the other hand - is destroyed in DeInitVCL(). So empty the queue
// here ..
uno::Reference< lang::XComponent > xComponent(pSVData->mxAccessBridge, uno::UNO_QUERY);
if( xComponent.is() )
{
sal_uLong nCount = Application::ReleaseSolarMutex();
xComponent->dispose();
Application::AcquireSolarMutex(nCount);
pSVData->mxAccessBridge.clear();
}
DeInitVCL();
return nReturn;
}
int SVMain()
{
// #i47888# allow for alternative initialization as required for e.g. MacOSX
extern sal_Bool ImplSVMainHook( int* );
int nRet;
if( ImplSVMainHook( &nRet ) )
return nRet;
else
return ImplSVMain();
}
// 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
oslSignalHandler pExceptionHandler = NULL;
class Application_Impl : public Application
{
public:
int Main() { return EXIT_SUCCESS; };
};
class DesktopEnvironmentContext: public cppu::WeakImplHelper1< com::sun::star::uno::XCurrentContext >
{
public:
DesktopEnvironmentContext( const com::sun::star::uno::Reference< com::sun::star::uno::XCurrentContext > & ctx)
: m_xNextContext( ctx ) {}
// XCurrentContext
virtual com::sun::star::uno::Any SAL_CALL getValueByName( const rtl::OUString& Name )
throw (com::sun::star::uno::RuntimeException);
private:
com::sun::star::uno::Reference< com::sun::star::uno::XCurrentContext > m_xNextContext;
};
uno::Any SAL_CALL DesktopEnvironmentContext::getValueByName( const rtl::OUString& Name) throw (uno::RuntimeException)
{
uno::Any retVal;
if (Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("system.desktop-environment")))
{
retVal = uno::makeAny( Application::GetDesktopEnvironment() );
}
else if( m_xNextContext.is() )
{
// Call next context in chain if found
retVal = m_xNextContext->getValueByName( Name );
}
return retVal;
}
sal_Bool InitVCL( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr )
{
RTL_LOGFILE_CONTEXT( aLog, "vcl (ss112471) ::InitVCL" );
if( pExceptionHandler != NULL )
return sal_False;
if( ! ImplGetSVData() )
ImplInitSVData();
if( !ImplGetSVData()->mpApp )
{
pOwnSvApp = new Application_Impl();
}
InitSalMain();
/*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 = ::osl::Thread::getCurrentIdentifier();
// Sal initialisieren
RTL_LOGFILE_CONTEXT_TRACE( aLog, "{ ::CreateSalInstance" );
pSVData->mpDefInst = CreateSalInstance();
if ( !pSVData->mpDefInst )
return sal_False;
RTL_LOGFILE_CONTEXT_TRACE( aLog, "} ::CreateSalInstance" );
// Desktop Environment context (to be able to get value of "system.desktop-environment" as soon as possible)
com::sun::star::uno::setCurrentContext(
new DesktopEnvironmentContext( com::sun::star::uno::getCurrentContext() ) );
// Initialize application instance (should be done after initialization of VCL SAL part)
if( pSVData->mpApp )
// call init to initialize application class
// soffice/sfx implementation creates the global service manager
pSVData->mpApp->Init();
// Den AppFileName gleich holen und absolut machen, bevor das
// WorkingDirectory sich aendert...
rtl::OUString aExeFileName;
osl_getExecutableFile( &aExeFileName.pData );
// convert path to native file format
rtl::OUString aNativeFileName;
osl::FileBase::getSystemPathFromFileURL( aExeFileName, aNativeFileName );
pSVData->maAppData.mpAppFileName = new String( aNativeFileName );
// Initialize global data
pSVData->maGDIData.mpScreenFontList = new ImplDevFontList;
pSVData->maGDIData.mpScreenFontCache = new ImplFontCache( sal_False );
pSVData->maGDIData.mpGrfConverter = new GraphicConverter;
// Exception-Handler setzen
pExceptionHandler = osl_addSignalHandler(VCLExceptionSignal_impl, NULL);
// Debug-Daten initialisieren
DBGGUI_INIT();
return sal_True;
}
namespace
{
/** Serves for destroying the VCL UNO wrapper as late as possible. This avoids
crash at exit in some special cases when a11y is enabled (e.g., when
a bundled extension is registered/deregistered during startup, forcing exit
while the app is still in splash screen.)
*/
class VCLUnoWrapperDeleter : public cppu::WeakImplHelper1<com::sun::star::lang::XEventListener>
{
virtual void SAL_CALL disposing(lang::EventObject const& rSource) throw(uno::RuntimeException);
};
void
VCLUnoWrapperDeleter::disposing(lang::EventObject const& /* rSource */)
throw(uno::RuntimeException)
{
ImplSVData* const pSVData = ImplGetSVData();
if (pSVData && pSVData->mpUnoWrapper)
{
pSVData->mpUnoWrapper->Destroy();
pSVData->mpUnoWrapper = NULL;
}
}
}
void DeInitVCL()
{
ImplSVData* pSVData = ImplGetSVData();
pSVData->mbDeInit = sal_True;
vcl::DeleteOnDeinitBase::ImplDeleteOnDeInit();
// give ime status a chance to destroy its own windows
delete pSVData->mpImeStatus;
pSVData->mpImeStatus = NULL;
#if OSL_DEBUG_LEVEL > 0
rtl::OStringBuffer aBuf( 256 );
aBuf.append( "DeInitVCL: some top Windows are still alive\n" );
long nTopWindowCount = Application::GetTopWindowCount();
long nBadTopWindows = nTopWindowCount;
for( long i = 0; i < nTopWindowCount; i++ )
{
Window* pWin = Application::GetTopWindow( i );
// default window will be destroyed further down
// but may still be useful during deinit up to that point
if( pWin == pSVData->mpDefaultWin )
nBadTopWindows--;
else
{
aBuf.append( "text = \"" );
aBuf.append( rtl::OUStringToOString( pWin->GetText(), osl_getThreadTextEncoding() ) );
aBuf.append( "\" type = \"" );
aBuf.append( typeid(*pWin).name() );
aBuf.append( "\", ptr = 0x" );
aBuf.append( sal_Int64( pWin ), 16 );
aBuf.append( "\n" );
}
}
DBG_ASSERT( nBadTopWindows==0, aBuf.getStr() );
#endif
ImplImageTreeSingletonRef()->shutDown();
osl_removeSignalHandler( pExceptionHandler);
pExceptionHandler = NULL;
// Debug Daten zuruecksetzen
DBGGUI_DEINIT();
// free global data
delete pSVData->maGDIData.mpGrfConverter;
if( pSVData->mpSettingsConfigItem )
delete pSVData->mpSettingsConfigItem, pSVData->mpSettingsConfigItem = NULL;
if( pSVData->maGDIData.mpDefaultFontConfiguration )
delete pSVData->maGDIData.mpDefaultFontConfiguration, pSVData->maGDIData.mpDefaultFontConfiguration = NULL;
if( pSVData->maGDIData.mpFontSubstConfiguration )
delete pSVData->maGDIData.mpFontSubstConfiguration, pSVData->maGDIData.mpFontSubstConfiguration = NULL;
if ( pSVData->maAppData.mpIdleMgr )
delete pSVData->maAppData.mpIdleMgr;
Timer::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->maCtrlData.mpDisclosurePlus )
{
delete pSVData->maCtrlData.mpDisclosurePlus;
pSVData->maCtrlData.mpDisclosurePlus = NULL;
}
if ( pSVData->maCtrlData.mpDisclosureMinus )
{
delete pSVData->maCtrlData.mpDisclosureMinus;
pSVData->maCtrlData.mpDisclosureMinus = NULL;
}
if ( pSVData->mpDefaultWin )
{
delete pSVData->mpDefaultWin;
pSVData->mpDefaultWin = NULL;
}
if ( pSVData->mpUnoWrapper )
{
try
{
uno::Reference<lang::XComponent> const xDesktop(
comphelper::createProcessComponent(
OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop"))),
uno::UNO_QUERY_THROW)
;
xDesktop->addEventListener(new VCLUnoWrapperDeleter());
}
catch (uno::Exception const&)
{
// ignore
}
}
pSVData->maAppData.mxMSF.clear();
if( pSVData->mpApp )
{
sal_uLong nCount = Application::ReleaseSolarMutex();
// 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();
Application::AcquireSolarMutex(nCount);
}
if ( pSVData->maAppData.mpSettings )
{
if ( pSVData->maAppData.mpCfgListener )
{
pSVData->maAppData.mpSettings->GetSysLocale().GetOptions().RemoveListener( pSVData->maAppData.mpCfgListener );
delete pSVData->maAppData.mpCfgListener;
}
delete pSVData->maAppData.mpSettings;
pSVData->maAppData.mpSettings = NULL;
}
if ( pSVData->maAppData.mpAccelMgr )
{
delete pSVData->maAppData.mpAccelMgr;
pSVData->maAppData.mpAccelMgr = 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.mpEventListeners )
{
delete pSVData->maAppData.mpEventListeners;
pSVData->maAppData.mpEventListeners = NULL;
}
if ( pSVData->maAppData.mpKeyListeners )
{
delete pSVData->maAppData.mpKeyListeners;
pSVData->maAppData.mpKeyListeners = 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();
if ( pSVData->mpResMgr )
{
delete pSVData->mpResMgr;
pSVData->mpResMgr = NULL;
}
ResMgr::DestroyAllResMgr();
// destroy all Sal interfaces before destorying the instance
// and thereby unloading the plugin
delete pSVData->mpSalSystem;
pSVData->mpSalSystem = NULL;
delete pSVData->mpSalTimer;
pSVData->mpSalTimer = NULL;
// Sal deinitialisieren
DestroySalInstance( pSVData->mpDefInst );
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;
extern "C"
{
static void SAL_CALL MainWorkerFunction( void* pArgs )
{
((WorkerThreadData*)pArgs)->pWorker( ((WorkerThreadData*)pArgs)->pThreadData );
delete (WorkerThreadData*)pArgs;
hThreadID = 0;
}
} // extern "C"
#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_destroyThread( hThreadID );
#endif
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|