summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormm <mm@openoffice.org>2001-02-22 14:44:00 +0000
committermm <mm@openoffice.org>2001-02-22 14:44:00 +0000
commit109b0e5ea423660e705d51dc7f03ef55ec57ad8b (patch)
treedc16df0e52052143f6f2452ec9627ef44d559c44
parent78ddc5565455bfee47da9371d39779b3721ef58a (diff)
vcl possibly without main
-rw-r--r--vcl/aqua/source/app/salinst.cxx67
-rw-r--r--vcl/source/app/svapp.cxx15
-rw-r--r--vcl/source/app/svmain.cxx185
-rw-r--r--vcl/unx/source/app/salinst.cxx17
-rw-r--r--vcl/win/source/app/salinst.cxx12
5 files changed, 256 insertions, 40 deletions
diff --git a/vcl/aqua/source/app/salinst.cxx b/vcl/aqua/source/app/salinst.cxx
index 6418e1c21d84..d0b74b2843c7 100644
--- a/vcl/aqua/source/app/salinst.cxx
+++ b/vcl/aqua/source/app/salinst.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: salinst.cxx,v $
*
- * $Revision: 1.25 $
+ * $Revision: 1.26 $
*
- * last change: $Author: hjs $ $Date: 2001-02-06 15:43:46 $
+ * last change: $Author: mm $ $Date: 2001-02-22 15:44:00 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -63,6 +63,9 @@
#include <stdio.h>
+#ifndef _FSYS_HXX
+#include <tools/fsys.hxx>
+#endif
#ifndef _SV_SALDATA_HXX
#include <saldata.hxx>
#endif
@@ -84,6 +87,9 @@
#ifndef _SV_DIALOG_HXX
#include <dialog.hxx>
#endif
+#ifndef _SV_VCLAUTORELEASEPOOL_H
+#include <VCLAutoreleasePool.h>
+#endif
#ifndef _SV_VCLAPPLICATION_H
#include <VCLApplication.h>
#endif
@@ -119,6 +125,63 @@ void DeInitSalData()
}
// -----------------------------------------------------------------------
+static VCLAUTORELEASEPOOL hMainAutoreleasePool = 0;
+void InitSalMain()
+{
+ // Need to include the absolute path for this executable in the PATH
+ // and STAR_RESOURCEPATH environment variables so that the resource manager
+ // can find resource files and in the DYLD_LIBRARY_PATH environment
+ // variable so that the dynamic library loader can find shared libraries
+ ByteString aPath( getenv( "PATH" ) );
+ ByteString aCmdPath( argv[0] );
+ // Get absolute path of command's directory
+ if ( aCmdPath.Len() ) {
+ DirEntry aCmdDirEntry( aCmdPath );
+ aCmdDirEntry.ToAbs();
+ aCmdPath = ByteString( aCmdDirEntry.GetPath().GetFull(), RTL_TEXTENCODING_ASCII_US );
+ }
+ if ( aPath.Len() ) {
+ if ( aCmdPath.Len() )
+ aCmdPath += ByteString( DirEntry::GetSearchDelimiter(), RTL_TEXTENCODING_ASCII_US );
+ aCmdPath += aPath;
+ }
+ // Assign to PATH environment variable
+ if ( aCmdPath.Len() ) {
+ aPath = ByteString( "PATH=" );
+ aPath += aCmdPath;
+ putenv( aPath.GetBuffer() );
+ }
+ // Assign to STAR_RESOURCEPATH environment variable
+ if ( aCmdPath.Len() ) {
+ aPath = ByteString( "STAR_RESOURCEPATH=" );
+ aPath += aCmdPath;
+ putenv( aPath.GetBuffer() );
+ }
+ // Assign to DYLD_LIBRARY_PATH environment variable
+ if ( aCmdPath.Len() ) {
+ aPath = ByteString( "DYLD_LIBRARY_PATH=" );
+ aPath += aCmdPath;
+ putenv( aPath.GetBuffer() );
+ }
+
+ // Setup up autorelease pool for Objective-C objects
+ hMainAutoreleasePool = VCLAutoreleasePool_Init();
+
+ // Initialize application's connection to the window server
+ VCLApplication_SharedApplication();
+
+}
+
+// -----------------------------------------------------------------------
+
+void DeInitSalMain()
+{
+ // Release autorelease pool
+ VCLAutoreleasePool_Release( hMainAutoreleasePool );
+ hMainAutoreleasePool = 0;
+}
+
+// -----------------------------------------------------------------------
void SetFilterCallback( void* pCallback, void* pInst )
{
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index a4c71da84072..0d1d72e23da2 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: svapp.cxx,v $
*
- * $Revision: 1.10 $
+ * $Revision: 1.11 $
*
- * last change: $Author: obr $ $Date: 2001-02-14 08:22:14 $
+ * last change: $Author: mm $ $Date: 2001-02-22 15:37:03 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -1986,14 +1986,3 @@ BOOL Application::IsHeadlessModeEnabled()
return IsDialogCancelEnabled();
}
-// =======================================================================
-
-void InitVCL()
-{
-}
-
-// -----------------------------------------------------------------------
-
-void DeInitVCL()
-{
-}
diff --git a/vcl/source/app/svmain.cxx b/vcl/source/app/svmain.cxx
index 343ddba5a2e1..4eb21f574f0a 100644
--- a/vcl/source/app/svmain.cxx
+++ b/vcl/source/app/svmain.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: svmain.cxx,v $
*
- * $Revision: 1.11 $
+ * $Revision: 1.12 $
*
- * last change: $Author: obr $ $Date: 2001-02-14 08:22:15 $
+ * last change: $Author: mm $ $Date: 2001-02-22 15:37:03 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -61,6 +61,16 @@
#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
+
+#ifndef _SV_SALDATA_HXX
+#include <saldata.hxx>
+#endif
#ifndef _SV_SVSYS_HXX
#include <svsys.h>
#endif
@@ -248,13 +258,71 @@ public:
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 > & )
+{
+ 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();
@@ -273,9 +341,10 @@ BOOL SVMain()
Application::EnterMultiThread( TRUE );
#endif
- // call init to initialize application class
- // soffice/sfx implementation creates the global service manager
- pSVData->mpApp->Init();
+ if( pSVData->mpApp )
+ // call init to initialize application class
+ // soffice/sfx implementation creates the global service manager
+ pSVData->mpApp->Init();
#ifdef REMOTE_APPSERVER
{
@@ -368,15 +437,20 @@ BOOL SVMain()
// HACK: Hier SystemExchange initialisieren, damit Exception-Handler unter Windows funktioniert
CreateSystemExchange();
#endif
- ImplVCLExceptionHandler aExceptionHandler;
+ pExceptionHandler = new ImplVCLExceptionHandler();
// Debug-Daten initialisieren
DBGGUI_INIT();
- // Application-Main rufen
- pSVData->maAppData.mbInAppMain = TRUE;
- pSVData->mpApp->Main();
- pSVData->maAppData.mbInAppMain = FALSE;
+ return TRUE;
+}
+
+void DeInitVCL()
+{
+ delete pExceptionHandler;
+ pExceptionHandler = NULL;
+
+ ImplSVData* pSVData = ImplGetSVData();
// Debug Daten zuruecksetzen
DBGGUI_DEINIT();
@@ -530,10 +604,11 @@ BOOL SVMain()
}
}
- // 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();
+ 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;
@@ -552,10 +627,11 @@ BOOL SVMain()
delete pSVData->mpKeyNames;
}
#else
- // 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();
+ 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 )
@@ -615,7 +691,74 @@ BOOL SVMain()
DeInitTools();
- return TRUE;
+ if( pOwnSvApp )
+ {
+ DeInitSalMain();
+ 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
- return FALSE;
+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
+ }
}
diff --git a/vcl/unx/source/app/salinst.cxx b/vcl/unx/source/app/salinst.cxx
index 0cd6526b42a0..7be6069dd15d 100644
--- a/vcl/unx/source/app/salinst.cxx
+++ b/vcl/unx/source/app/salinst.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: salinst.cxx,v $
*
- * $Revision: 1.7 $
+ * $Revision: 1.8 $
*
- * last change: $Author: rt $ $Date: 2001-02-07 16:19:50 $
+ * last change: $Author: mm $ $Date: 2001-02-22 15:40:32 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -172,6 +172,19 @@ final void DeInitSalData()
SetSalData( NULL );
}
+void InitSalMain()
+{
+ if (GetSalData())
+ {
+ int argc = 0;
+ GetSalData()->Init( &argc, 0 );
+ }
+}
+
+void DeInitSalMain()
+{
+}
+
final void SetFilterCallback( void* pCallback, void* pInst )
{
SalData* pSalData = GetSalData();
diff --git a/vcl/win/source/app/salinst.cxx b/vcl/win/source/app/salinst.cxx
index d9f6c324d07c..5759909514c2 100644
--- a/vcl/win/source/app/salinst.cxx
+++ b/vcl/win/source/app/salinst.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: salinst.cxx,v $
*
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: pl $ $Date: 2001-02-01 14:12:53 $
+ * last change: $Author: mm $ $Date: 2001-02-22 15:40:00 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -419,6 +419,14 @@ void DeInitSalData()
SetSalData( NULL );
}
+void InitSalMain()
+{
+}
+
+void DeInitSalMain()
+{
+}
+
// -----------------------------------------------------------------------
void SetFilterCallback( void* pCallback, void* pInst )