From b605d3dfbe02fe522c0ffc9dbc92dea749a568bc Mon Sep 17 00:00:00 2001 From: "law%netscape.com" Date: Fri, 4 Feb 2000 14:40:08 +0000 Subject: [PATCH] New splash screen stuff for windows version (plus removal of console from windows release builds); b=6391/22542, r=davidm@netscape.com (travis@netscape.com for the console stuff) git-svn-id: svn://10.0.0.236/trunk@59770 18797224-902f-48f8-a5cc-f745e15eee43 --- .../appshell/public/nsIAppShellService.idl | 10 +- .../xpfe/appshell/src/nsAppShellService.cpp | 39 +++---- .../xpfe/appshell/src/nsWebShellWindow.cpp | 9 ++ mozilla/xpfe/bootstrap/makefile.win | 24 +++- mozilla/xpfe/bootstrap/nsAppRunner.cpp | 49 ++++++--- mozilla/xpfe/bootstrap/nsNativeAppSupport.h | 4 +- .../xpfe/bootstrap/nsNativeAppSupportMac.cpp | 104 ++++++++++++++---- 7 files changed, 179 insertions(+), 60 deletions(-) diff --git a/mozilla/xpfe/appshell/public/nsIAppShellService.idl b/mozilla/xpfe/appshell/public/nsIAppShellService.idl index 10c23660eb1..977cdf63430 100644 --- a/mozilla/xpfe/appshell/public/nsIAppShellService.idl +++ b/mozilla/xpfe/appshell/public/nsIAppShellService.idl @@ -26,12 +26,14 @@ %{C++ #include "nscore.h" #include "nsCom.h" +#include "nsISplashScreen.h" %} interface nsIWebShellWindow; interface nsIURI; interface nsIXULWindowCallbacks; interface nsICmdLineService; +interface nsISplashScreen; [ptr] native JSContext(JSContext); @@ -58,7 +60,7 @@ interface nsIAppShellService : nsISupports * @param aCmdLineService is stored and passed to appshell components as * they are initialized. */ - void Initialize(in nsICmdLineService aCmdLineService); + void Initialize(in nsICmdLineService aCmdLineService, in nsISplashScreen splashScreen ); /** * Runs an application event loop: normally the main event pump which @@ -176,4 +178,10 @@ interface nsIAppShellService : nsISupports * @param aWindow you see the pattern */ void UnregisterTopLevelWindow(in nsIWebShellWindow aWindow); + + /** + * Remove the splash screen (if visible). This need be called + * only once per application session. + */ + void HideSplashScreen(); }; diff --git a/mozilla/xpfe/appshell/src/nsAppShellService.cpp b/mozilla/xpfe/appshell/src/nsAppShellService.cpp index 7ce5812ca4e..a76c98d9d65 100644 --- a/mozilla/xpfe/appshell/src/nsAppShellService.cpp +++ b/mozilla/xpfe/appshell/src/nsAppShellService.cpp @@ -53,11 +53,6 @@ #include "prprf.h" #endif -/* For Javascript Namespace Access */ -#include "nsDOMCID.h" -#include "nsIScriptNameSetRegistry.h" -#include "nsAppShellNameSet.h" - #include "nsWidgetsCID.h" #include "nsIStreamObserver.h" @@ -75,7 +70,6 @@ /* Define Class IDs */ static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); -static NS_DEFINE_CID(kCScriptNameSetRegistryCID, NS_SCRIPT_NAMESET_REGISTRY_CID); static NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID); static NS_DEFINE_CID(kMetaCharsetCID, NS_META_CHARSET_CID); @@ -117,6 +111,7 @@ protected: nsIWindowMediator* mWindowMediator; nsCOMPtr mHiddenWindow; PRBool mDeleteCalled; + nsISplashScreen *mSplashScreen; // The mShutdownTimer is set in Quit() to asynchronously call the // ExitCallback(). This allows one last pass through any events in @@ -133,6 +128,7 @@ nsAppShellService::nsAppShellService() : mWindowMediator( NULL ) mWindowList = nsnull; mCmdLineService = nsnull; mDeleteCalled = PR_FALSE; + mSplashScreen = nsnull; } nsAppShellService::~nsAppShellService() @@ -141,6 +137,7 @@ nsAppShellService::~nsAppShellService() NS_IF_RELEASE(mAppShell); NS_IF_RELEASE(mWindowList); NS_IF_RELEASE(mCmdLineService); + NS_IF_RELEASE(mSplashScreen); if (mHiddenWindow) mHiddenWindow->Close(); // merely releasing the ref isn't enough! if (mWindowMediator) @@ -168,7 +165,8 @@ NS_INTERFACE_MAP_END NS_IMETHODIMP -nsAppShellService::Initialize( nsICmdLineService *aCmdLineService ) +nsAppShellService::Initialize( nsICmdLineService *aCmdLineService, + nsISplashScreen *aSplashScreen ) { nsresult rv; @@ -180,6 +178,10 @@ nsAppShellService::Initialize( nsICmdLineService *aCmdLineService ) mCmdLineService = aCmdLineService; NS_IF_ADDREF( mCmdLineService ); + // Remember the splash screen. + mSplashScreen = aSplashScreen; + NS_IF_ADDREF( mSplashScreen ); + // Create the Event Queue for the UI thread... nsIEventQueueService* eventQService; rv = nsServiceManager::GetService(kEventQueueServiceCID, @@ -190,20 +192,6 @@ nsAppShellService::Initialize( nsICmdLineService *aCmdLineService ) rv = eventQService->CreateThreadEventQueue(); } - // Register the nsAppShellNameSet with the global nameset registry... - nsIScriptNameSetRegistry *registry; - rv = nsServiceManager::GetService(kCScriptNameSetRegistryCID, - NS_GET_IID(nsIScriptNameSetRegistry), - (nsISupports **)®istry); - if (NS_FAILED(rv)) { - goto done; - } - - nsAppShellNameSet* nameSet; - nameSet = new nsAppShellNameSet(); - registry->AddExternalNameSet(nameSet); - /* XXX: do we need to release this service? When we do, it get deleted,and our name is lost. */ - // Create the toplevel window list... rv = NS_NewISupportsArray(&mWindowList); if (NS_FAILED(rv)) { @@ -946,3 +934,12 @@ void nsAppShellService::RegisterObserver(PRBool aRegister) } } +NS_IMETHODIMP +nsAppShellService::HideSplashScreen() { + // Hide the splash screen (and release it) if there is one. + if ( mSplashScreen ) { + mSplashScreen->Hide(); + NS_RELEASE( mSplashScreen ); + } + return NS_OK; +} diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp index c19758767d7..89b09c55a64 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp @@ -1398,6 +1398,15 @@ nsWebShellWindow::Show(PRBool aShow) { windowMediator->UpdateWindowTimeStamp( this ); } + // Hide splash screen (if there is one). + static PRBool splashScreenGone = PR_FALSE; + if ( !splashScreenGone ) { + NS_WITH_SERVICE(nsIAppShellService, appShellService, kAppShellServiceCID, &rv); + if ( NS_SUCCEEDED(rv) && appShellService ) { + appShellService->HideSplashScreen(); + } + splashScreenGone = PR_TRUE; + } mDebuting = PR_FALSE; return NS_OK; } diff --git a/mozilla/xpfe/bootstrap/makefile.win b/mozilla/xpfe/bootstrap/makefile.win index f55a424a54a..6ccbf673c0b 100644 --- a/mozilla/xpfe/bootstrap/makefile.win +++ b/mozilla/xpfe/bootstrap/makefile.win @@ -30,21 +30,19 @@ MODULE=raptor CPPSRCS= \ nsAppRunner.cpp \ nsSetupRegistry.cpp \ + nsNativeAppSupportWin.cpp \ $(NULL) CPP_OBJS= \ .\$(OBJDIR)\nsAppRunner.obj \ .\$(OBJDIR)\nsSetupRegistry.obj \ + .\$(OBJDIR)\nsNativeAppSupportWin.obj \ $(NULL) LINCS=-I$(PUBLIC)\raptor \ -I$(PUBLIC)\xpcom \ -I$(PUBLIC)\base \ -!ifdef NECKO -I$(PUBLIC)\necko \ -!else - -I$(PUBLIC)\netlib \ -!endif -I$(PUBLIC)\pref \ -I$(PUBLIC)\js \ -I$(PUBLIC)\dom \ @@ -72,12 +70,30 @@ LINCS=-I$(PUBLIC)\raptor \ MAKE_OBJ_TYPE = EXE PROGRAM = .\$(OBJDIR)\mozilla.exe +RESFILE = splash.res LCFLAGS = \ $(LCFLAGS) \ $(DEFINES) \ $(NULL) +# This code removes the console from release builds +# (unless you've set MOZ_WINCONSOLE=1). +!ifndef MOZ_WINCONSOLE +!if $(MOZ_DEBUG) +MOZ_WINCONSOLE=1 +!else +MOZ_WINCONSOLE=0 +!endif +!endif + +# Set subsystem type according to whether we want a console. +!if $(MOZ_WINCONSOLE) +LFLAGS= $(LFLAGS) /subsystem:console +!else +LFLAGS= $(LFLAGS) /subsystem:windows +!endif + # These are the libraries we need to link with to create the exe LLIBS= \ $(DIST)\lib\xpcom.lib \ diff --git a/mozilla/xpfe/bootstrap/nsAppRunner.cpp b/mozilla/xpfe/bootstrap/nsAppRunner.cpp index 61f21fce771..8a55d3e37fe 100644 --- a/mozilla/xpfe/bootstrap/nsAppRunner.cpp +++ b/mozilla/xpfe/bootstrap/nsAppRunner.cpp @@ -121,13 +121,16 @@ static NS_DEFINE_CID(kProfileCID, NS_PROFILE_CID); /*********************************************/ // Default implemenations for nativeAppSupport // If your platform implements these functions if def out this code. -#if !defined (XP_MAC ) -void NS_ShowSplashScreen() +#if !defined (XP_MAC ) && ( !defined( XP_PC ) || !defined( WIN32 ) ) +nsresult NS_CreateSplashScreen( nsISplashScreen **aResult ) { -} - -void NS_HideSplashScreen() -{ + nsresult rv = NS_OK; + if ( aResult ) { + *aResult = 0; + } else { + rv = NS_ERROR_NULL_POINTER; + } + return rv; } PRBool NS_CanRun() @@ -470,7 +473,10 @@ static nsresult Ensure1Window( nsICmdLineService* cmdLineArgs) #include #endif -static nsresult main1(int argc, char* argv[]) +// Note: splashScreen is an owning reference that this function has responsibility +// to release. This responsibility is delegated to the app shell service +// (see nsAppShellService::Initialize call, below). +static nsresult main1(int argc, char* argv[], nsISplashScreen *splashScreen ) { nsresult rv; @@ -525,10 +531,13 @@ static nsresult main1(int argc, char* argv[]) NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get the appshell service"); if (NS_FAILED(rv)) { + splashScreen->Hide(); return rv; } - rv = appShell->Initialize( cmdLineArgs ); + rv = appShell->Initialize( cmdLineArgs, splashScreen ); + // We are done with the splash screen here; the app shell owns it now. + NS_IF_RELEASE( splashScreen ); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to initialize appshell"); if ( NS_FAILED(rv) ) return rv; @@ -592,7 +601,6 @@ static nsresult main1(int argc, char* argv[]) if ( NS_SUCCEEDED(rv) ) walletService->WALLET_FetchFromNetCenter(); - NS_HideSplashScreen(); // Start main event loop rv = appShell->Run(); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to run appshell"); @@ -667,7 +675,15 @@ int main(int argc, char* argv[]) if( !NS_CanRun() ) return 1; - NS_ShowSplashScreen(); + // Note: this object is not released here. It is passed to main1 which + // has responsibility to release it. + nsISplashScreen *splash = 0; + rv = NS_CreateSplashScreen( &splash ); + NS_ASSERTION( NS_SUCCEEDED(rv), "NS_CreateSplashScreen failed" ); + // If the platform has a splash screen, show it ASAP. + if ( splash ) { + splash->Show(); + } rv = NS_InitXPCOM(NULL, NULL); NS_ASSERTION( NS_SUCCEEDED(rv), "NS_InitXPCOM failed" ); @@ -687,9 +703,7 @@ int main(int argc, char* argv[]) su->StartupTasks(); } - - nsresult result = main1( argc, argv ); - + nsresult result = main1( argc, argv, splash ); { // Scoping this in a block to force the pref service to be @@ -722,3 +736,12 @@ int main(int argc, char* argv[]) NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); return TranslateReturnValue( result ); } + +#if defined( XP_PC ) && defined( WIN32 ) +// We need WinMain in order to not be a console app. This function is +// unused if we are a console application. +int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR args, int ) { + // Do the real work. + return main( __argc, __argv ); +} +#endif // XP_PC && WIN32 diff --git a/mozilla/xpfe/bootstrap/nsNativeAppSupport.h b/mozilla/xpfe/bootstrap/nsNativeAppSupport.h index 79d4ef327af..ea671aaa3c3 100644 --- a/mozilla/xpfe/bootstrap/nsNativeAppSupport.h +++ b/mozilla/xpfe/bootstrap/nsNativeAppSupport.h @@ -21,9 +21,9 @@ */ #include "prtypes.h" +#include "nsISplashScreen.h" -void NS_ShowSplashScreen(); -void NS_HideSplashScreen(); +nsresult NS_CreateSplashScreen( nsISplashScreen **aResult ); PRBool NS_CanRun(); diff --git a/mozilla/xpfe/bootstrap/nsNativeAppSupportMac.cpp b/mozilla/xpfe/bootstrap/nsNativeAppSupportMac.cpp index 670440a519e..da11a6106c3 100644 --- a/mozilla/xpfe/bootstrap/nsNativeAppSupportMac.cpp +++ b/mozilla/xpfe/bootstrap/nsNativeAppSupportMac.cpp @@ -26,30 +26,96 @@ #include -static DialogPtr splashDialog = NULL; -static PicHandle picHandle; #define rSplashDialog 512 -void NS_ShowSplashScreen() -{ - - splashDialog = ::GetNewDialog( rSplashDialog, nil, (WindowPtr)-1L ); - picHandle = GetPicture( rSplashDialog ); - SetWindowPic( splashDialog, picHandle ); - ::ShowWindow( splashDialog ); - ::SetPort( splashDialog ); - Rect rect = (**picHandle).picFrame; - ::DrawPicture( picHandle, &rect ); +class nsSplashScreenMac : public nsISplashScreen { +public: + nsSplashScreenMac() + : mDialog( 0 ), mPicHandle( 0 ), mRefCnt( 0 ) { + } + ~nsSplashScreenMac() { + Hide(); + } + + NS_IMETHOD Show(); + NS_IMETHOD Hide(); + + // nsISupports methods + NS_IMETHOD_(nsrefcnt) AddRef() { + mRefCnt++; + return mRefCnt; + } + NS_IMETHOD_(nsrefcnt) Release() { + --mRefCnt; + if ( !mRefCnt ) { + delete this; + return 0; + } + return mRefCnt; + } + NS_IMETHOD QueryInterface( const nsIID &iid, void**p ) { + nsresult rv = NS_OK; + if ( p ) { + *p = 0; + if ( iid.Equals( NS_GET_IID( nsISplashScreen ) ) ) { + nsISplashScreen *result = this; + *p = result; + NS_ADDREF( result ); + } else if ( iid.Equals( NS_GET_IID( nsISupports ) ) ) { + nsISupports *result = NS_STATIC_CAST( nsISupports*, this ); + *p = result; + NS_ADDREF( result ); + } else { + rv = NS_NOINTERFACE; + } + } else { + rv = NS_ERROR_NULL_POINTER; + } + return rv; + } + + DialogPtr mDialog; + PicHandle mPicHandle; + nsrefcnt mRefCnt; +}; // class nsSplashScreenMac + +NS_IMETHODIMP +nsSplashScreenMac::Show() { + mDialog = ::GetNewDialog( rSplashDialog, nil, (WindowPtr)-1L ); + mPicHandle = GetPicture( rSplashDialog ); + SetWindowPic( mDialog, mPicHandle ); + ::ShowWindow( mDialog ); + ::SetPort( mDialog ); + Rect rect = (**mPicHandle).picFrame; + ::DrawPicture( mPicHandle, &rect ); + return NS_OK; } -void NS_HideSplashScreen() -{ - if ( splashDialog ) - { - ReleaseResource( (Handle)picHandle ); - SetWindowPic( splashDialog, NULL ); - DisposeWindow( splashDialog ); +NS_IMETHODIMP +nsSplashScreenMac::Hide() { + if ( mDialog ) { + ReleaseResource( (Handle)mPicHandle ); + mPicHandle = 0; + SetWindowPic( mDialog, NULL ); + DisposeWindow( mDialog ); + mDialog = 0; } + return NS_OK; +} + +nsresult NS_CreateSplashScreen(nsISplashScreen**aResult) +{ + if ( aResult ) { + *aResult = new nsSplashScreenMac; + if ( *aResult ) { + NS_ADDREF( *aResult ); + return NS_OK; + } else { + return NS_ERROR_OUT_OF_MEMORY; + } + } else { + return NS_ERROR_NULL_POINTER; + } } PRBool NS_CanRun()