Files
libreoffice/vcl/source/app/svmain.cxx

581 lines
16 KiB
C++
Raw Normal View History

2000-09-18 16:07:07 +00:00
/*************************************************************************
*
* $RCSfile: svmain.cxx,v $
*
* $Revision: 1.48 $
2000-09-18 16:07:07 +00:00
*
* last change: $Author: hr $ $Date: 2004-05-10 15:45:45 $
2000-09-18 16:07:07 +00:00
*
* 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): _______________________________________
*
*
************************************************************************/
2001-02-22 14:44:00 +00:00
#ifdef WNT
#include <tools/prewin.h>
#include <process.h> // for _beginthreadex
#include <ole2.h> // for _beginthreadex
#include <tools/postwin.h>
#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
2001-02-23 17:02:50 +00:00
#include <svunx.h>
#endif
2000-09-18 16:07:07 +00:00
#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 <tools/resmgr.hxx>
2000-09-18 16:07:07 +00:00
#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 _VCL_UNOWRAP_HXX
#include <unowrap.hxx>
#endif
2004-02-25 10:24:54 +00:00
#ifndef _SV_SALSYS_HXX
#include <salsys.hxx>
#endif
#ifndef _SV_SALTIMER_HXX
#include <saltimer.hxx>
#endif
#ifndef _SV_SALIMESTATUS_HXX
#include <salimestatus.hxx>
#endif
2000-09-18 16:07:07 +00:00
#include <vos/process.hxx>
#include <osl/file.hxx>
2000-10-23 06:11:04 +00:00
#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
#include <comphelper/processfactory.hxx>
#endif
2001-02-23 17:08:12 +00:00
#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#endif
2001-07-10 05:29:57 +00:00
#include <rtl/logfile.hxx>
2001-02-23 17:08:12 +00:00
using namespace ::rtl;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
2002-11-04 15:18:35 +00:00
#include <fontcfg.hxx>
2000-09-18 16:07:07 +00:00
// =======================================================================
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;
2001-03-20 09:36:58 +00:00
return vos::OSignalHandler::TAction_CallNextHandler;
2000-09-18 16:07:07 +00:00
}
}
2001-03-20 09:36:58 +00:00
return vos::OSignalHandler::TAction_CallNextHandler;
2000-09-18 16:07:07 +00:00
}
2001-02-22 14:44:00 +00:00
// =======================================================================
2000-09-18 16:07:07 +00:00
BOOL SVMain()
{
RTL_LOGFILE_CONTEXT( aLog, "vcl (ss112471) ::SVMain" );
2001-07-10 05:29:57 +00:00
2000-09-18 16:07:07 +00:00
ImplSVData* pSVData = ImplGetSVData();
DBG_ASSERT( pSVData->mpApp, "no instance of class Application" );
Reference<XMultiServiceFactory> xMS;
2001-02-22 14:44:00 +00:00
2001-02-22 14:44:00 +00:00
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(){};
};
2001-02-23 17:08:12 +00:00
BOOL InitVCL( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr )
2001-02-22 14:44:00 +00:00
{
RTL_LOGFILE_CONTEXT( aLog, "vcl (ss112471) ::InitVCL" );
2001-07-10 05:29:57 +00:00
2001-02-22 14:44:00 +00:00
if( pExceptionHandler != NULL )
return FALSE;
if( !ImplGetSVData()->mpApp )
{
pOwnSvApp = new Application_Impl();
}
2001-02-23 17:08:12 +00:00
InitSalMain();
2001-02-22 14:44:00 +00:00
/*AllSettings aAS;
Application::SetSettings( aAS );// ???
*/
ImplSVData* pSVData = ImplGetSVData();
2000-09-18 16:07:07 +00:00
// SV bei den Tools anmelden
InitTools();
DBG_ASSERT( !pSVData->maAppData.mxMSF.is(), "VCL service factory already set" )
pSVData->maAppData.mxMSF = rSMgr;
2001-02-23 17:08:12 +00:00
2000-09-18 16:07:07 +00:00
// Main-Thread-Id merken
pSVData->mnMainThreadId = ::vos::OThread::getCurrentIdentifier();
2001-03-20 09:36:58 +00:00
vos::OStartupInfo aStartInfo;
rtl::OUString aExeFileName;
2000-09-18 16:07:07 +00:00
// Sal initialisieren
RTL_LOGFILE_CONTEXT_TRACE( aLog, "{ ::CreateSalInstance" );
pSVData->mpDefInst = CreateSalInstance();
if ( !pSVData->mpDefInst )
return FALSE;
RTL_LOGFILE_CONTEXT_TRACE( aLog, "} ::CreateSalInstance" );
// Initialize application instance (should be done after initialization of VCL SAL part)
2001-02-22 14:44:00 +00:00
if( pSVData->mpApp )
// call init to initialize application class
// soffice/sfx implementation creates the global service manager
pSVData->mpApp->Init();
2000-09-18 16:07:07 +00:00
// Den AppFileName gleich holen und absolut machen, bevor das
// WorkingDirectory sich aendert...
aStartInfo.getExecutableFile( aExeFileName );
// convert path to native file format
rtl::OUString aNativeFileName;
2001-07-25 10:06:25 +00:00
osl::FileBase::getSystemPathFromFileURL( aExeFileName, aNativeFileName );
2000-09-18 16:07:07 +00:00
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
2001-02-22 14:44:00 +00:00
pExceptionHandler = new ImplVCLExceptionHandler();
2000-09-18 16:07:07 +00:00
// Debug-Daten initialisieren
DBGGUI_INIT();
2001-02-22 14:44:00 +00:00
return TRUE;
}
void DeInitVCL()
{
delete pExceptionHandler;
pExceptionHandler = NULL;
ImplSVData* pSVData = ImplGetSVData();
2000-09-18 16:07:07 +00:00
// Debug Daten zuruecksetzen
DBGGUI_DEINIT();
// free global data
delete pSVData->maGDIData.mpGrfConverter;
if( pSVData->mpSettingsConfigItem )
delete pSVData->mpSettingsConfigItem, pSVData->mpSettingsConfigItem = NULL;
if( pSVData->maGDIData.mpDefFontConfig )
delete pSVData->maGDIData.mpDefFontConfig, pSVData->maGDIData.mpDefFontConfig = NULL;
if( pSVData->maGDIData.mpFontSubstConfig )
delete pSVData->maGDIData.mpFontSubstConfig, pSVData->maGDIData.mpFontSubstConfig = NULL;
2000-09-18 16:07:07 +00:00
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;
}
2001-02-22 14:44:00 +00:00
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();
2000-11-06 07:55:14 +00:00
2000-09-18 16:07:07 +00:00
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;
}
2002-07-17 08:43:42 +00:00
if ( pSVData->maAppData.mpEventListeners )
{
delete pSVData->maAppData.mpEventListeners;
pSVData->maAppData.mpEventListeners = NULL;
}
if ( pSVData->maAppData.mpKeyListeners )
{
delete pSVData->maAppData.mpKeyListeners;
pSVData->maAppData.mpKeyListeners = NULL;
}
2000-09-18 16:07:07 +00:00
if ( pSVData->maAppData.mpFirstHotKey )
ImplFreeHotKeyData();
if ( pSVData->maAppData.mpFirstEventHook )
ImplFreeEventHookData();
// #114285# Moved here from ImplDeInitSVData...
if ( pSVData->mpUnoWrapper )
{
pSVData->mpUnoWrapper->Destroy();
pSVData->mpUnoWrapper = NULL;
}
2000-09-18 16:07:07 +00:00
ImplDeletePrnQueueList();
delete pSVData->maGDIData.mpScreenFontList;
pSVData->maGDIData.mpScreenFontList = NULL;
delete pSVData->maGDIData.mpScreenFontCache;
pSVData->maGDIData.mpScreenFontCache = NULL;
ImplFreeOutDevFontData();
ResMgr::DestroyAllResMgr();
2004-02-25 09:46:59 +00:00
// destroy all Sal interfaces before destorying the instance
// and thereby unloading the plugin
delete pSVData->mpImeStatus;
pSVData->mpImeStatus = NULL;
delete pSVData->mpSalSystem;
pSVData->mpSalSystem = NULL;
delete pSVData->mpSalTimer;
pSVData->mpSalTimer = NULL;
2000-09-18 16:07:07 +00:00
// Sal deinitialisieren
DestroySalInstance( pSVData->mpDefInst );
DeInitTools();
2001-02-23 17:08:12 +00:00
DeInitSalMain();
2001-02-22 14:44:00 +00:00
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
2000-09-18 16:07:07 +00:00
2001-02-22 14:44:00 +00:00
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 );
2001-02-22 14:44:00 +00:00
#endif
}
2000-09-18 16:07:07 +00:00
}