diff --git a/mozilla/widget/src/beos/nsAppShell.cpp b/mozilla/widget/src/beos/nsAppShell.cpp index d3f83b0c8af..5eed84fa001 100644 --- a/mozilla/widget/src/beos/nsAppShell.cpp +++ b/mozilla/widget/src/beos/nsAppShell.cpp @@ -35,9 +35,8 @@ #include "prprf.h" #include "nsGUIEvent.h" +#include #include -#include -#include static int gBAppCount = 0; @@ -82,60 +81,6 @@ NS_DEFINE_IID(kIAppShellIID, NS_IAPPSHELL_IID); NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); NS_IMPL_ISUPPORTS(nsAppShell,kIAppShellIID); -static bool GetAppSig(char *sig) -{ - app_info appInfo; - BFile file; - BAppFileInfo appFileInfo; - image_info info; - int32 cookie = 0; - - *sig = 0; - return get_next_image_info(0, &cookie, &info) == B_OK && - file.SetTo(info.name, B_READ_ONLY) == B_OK && - appFileInfo.SetTo(&file) == B_OK && - appFileInfo.GetSignature(sig) == B_OK; -} - -class nsBeOSApp : public BApplication -{ - public: - sem_id init; - - nsBeOSApp(const char *signature, sem_id initsem); - virtual void ReadyToRun(void); -}; - -nsBeOSApp::nsBeOSApp(const char *signature, sem_id initsem) - : BApplication(signature), init(initsem) -{ -} - -void nsBeOSApp::ReadyToRun(void) -{ - release_sem(init); -} - -// Return B_OK for success, anything else error! -int32 bapp_thread(void *arg) -{ - // create and start BApplication - char sig[B_MIME_TYPE_LENGTH + 1]; - int32 error = B_OK; - - GetAppSig(sig); - nsBeOSApp *app = new nsBeOSApp(sig, (sem_id)arg); - if(app) - { - app->Run(); - } - else - { - error = B_NO_MEMORY; - } - return error; -} - //------------------------------------------------------------------------- // // nsAppShell constructor @@ -147,13 +92,7 @@ nsAppShell::nsAppShell() NS_INIT_REFCNT(); mDispatchListener = 0; - if(gBAppCount++ == 0) - { - sem_id initsem = create_sem(0, "bapp init"); - resume_thread(spawn_thread(bapp_thread, "BApplication", B_NORMAL_PRIORITY, (void *)initsem)); - acquire_sem(initsem); - delete_sem(initsem); - } + gBAppCount++; } diff --git a/mozilla/xpfe/bootstrap/Makefile.in b/mozilla/xpfe/bootstrap/Makefile.in index 1906283238c..6d2b502cfeb 100644 --- a/mozilla/xpfe/bootstrap/Makefile.in +++ b/mozilla/xpfe/bootstrap/Makefile.in @@ -151,6 +151,8 @@ endif ifeq ($(MOZ_WIDGET_TOOLKIT),beos) BEOS_PROGRAM_RESOURCE = $(srcdir)/apprunner-beos.rsrc +CPPSRCS += nsNativeAppSupportBeOS.cpp +CPPSRCS += nsNativeAppSupportBase.cpp endif ifeq ($(MOZ_WIDGET_TOOLKIT),photon) diff --git a/mozilla/xpfe/bootstrap/apprunner-beos.rsrc b/mozilla/xpfe/bootstrap/apprunner-beos.rsrc index d0b0067e02d..3e2c9048b10 100644 Binary files a/mozilla/xpfe/bootstrap/apprunner-beos.rsrc and b/mozilla/xpfe/bootstrap/apprunner-beos.rsrc differ diff --git a/mozilla/xpfe/bootstrap/nsAppRunner.cpp b/mozilla/xpfe/bootstrap/nsAppRunner.cpp index f32d6d807ef..95620e685e0 100644 --- a/mozilla/xpfe/bootstrap/nsAppRunner.cpp +++ b/mozilla/xpfe/bootstrap/nsAppRunner.cpp @@ -125,6 +125,78 @@ apprunner_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); extern void InstallUnixSignalHandlers(const char *ProgramName); #endif +#if defined(XP_BEOS) + +#include +#include + +class nsBeOSApp : public BApplication +{ +public: + nsBeOSApp(sem_id sem) + : BApplication(GetAppSig()), init(sem) + { + } + + void ReadyToRun(void) + { + release_sem(init); + } + + static int32 Main(void *args) + { + nsBeOSApp *app = new nsBeOSApp((sem_id)args); + if (NULL == app) + return B_ERROR; + return app->Run(); + } + +private: + char *GetAppSig(void) + { + app_info appInfo; + BFile file; + BAppFileInfo appFileInfo; + image_info info; + int32 cookie = 0; + static char sig[B_MIME_TYPE_LENGTH]; + + sig[0] = 0; + if (get_next_image_info(0, &cookie, &info) != B_OK || + file.SetTo(info.name, B_READ_ONLY) != B_OK || + appFileInfo.SetTo(&file) != B_OK || + appFileInfo.GetSignature(sig) != B_OK) + { + return "application/x-vnd.mozilla.apprunner"; + } + return sig; + } + + sem_id init; +}; + +static nsresult InitializeBeOSApp(void) +{ + nsresult rv = NS_OK; + + sem_id initsem = create_sem(0, "beapp init"); + if (initsem < B_OK) + return NS_ERROR_FAILURE; + + thread_id tid = spawn_thread(nsBeOSApp::Main, "BApplication", B_NORMAL_PRIORITY, (void *)initsem); + if (tid < B_OK || B_OK != resume_thread(tid)) + rv = NS_ERROR_FAILURE; + + if (B_OK != acquire_sem(initsem)) + rv = NS_ERROR_FAILURE; + if (B_OK != delete_sem(initsem)) + rv = NS_ERROR_FAILURE; + + return rv; +} + +#endif // XP_BEOS + #if defined(XP_MAC) #include "macstdlibextras.h" @@ -172,7 +244,7 @@ static char *sWatcherServiceContractID = "@mozilla.org/embedcomp/window-watcher; /*********************************************/ // Default implemenations for nativeAppSupport // If your platform implements these functions if def out this code. -#if !defined (XP_MAC ) && !defined(NTO) && !defined( XP_PC ) +#if !defined (XP_MAC ) && !defined(NTO) && !defined( XP_PC ) && !defined( XP_BEOS ) nsresult NS_CreateSplashScreen( nsISplashScreen **aResult ) { @@ -206,7 +278,7 @@ PRBool NS_CanRun() // then rely on nsINativeAppSupport and its use of // nsISplashScreen will be removed. // -#if !defined( XP_PC ) +#if !defined( XP_PC ) && !defined( XP_BEOS ) nsresult NS_CreateNativeAppSupport( nsINativeAppSupport **aResult ) { @@ -1445,6 +1517,11 @@ int main(int argc, char* argv[]) InstallUnixSignalHandlers(argv[0]); #endif +#if defined(XP_BEOS) + if (NS_OK != InitializeBeOSApp()) + return 1; +#endif + // Handle -help and -version command line arguments. // They should% return quick, so we deal with them here. if (HandleDumpArguments(argc, argv)) diff --git a/mozilla/xpfe/bootstrap/nsNativeAppSupportBeOS.cpp b/mozilla/xpfe/bootstrap/nsNativeAppSupportBeOS.cpp new file mode 100644 index 00000000000..40c41430d1a --- /dev/null +++ b/mozilla/xpfe/bootstrap/nsNativeAppSupportBeOS.cpp @@ -0,0 +1,269 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * 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.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Takashi Toyoshima + */ +#include "nsNativeAppSupportBase.h" +#include "nsString.h" +#include "nsICmdLineService.h" +#include "nsCOMPtr.h" +#include "nsXPIDLString.h" +#include "nsIComponentManager.h" +#include "nsIServiceManager.h" +#include "nsIAppShellService.h" +#include "nsAppShellCIDs.h" +#include "nsIDOMWindowInternal.h" + +#include +#include +#include +#include +#include +#include + +#ifdef DEBUG +#define DEBUG_SPLASH 1 +#endif + +class nsSplashScreenBeOS : public nsISplashScreen { +public: + nsSplashScreenBeOS(); + ~nsSplashScreenBeOS(); + + 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; + } + +private: + nsresult LoadBitmap(); + + nsrefcnt mRefCnt; + BWindow *window; + BBitmap *bitmap; +}; // class nsSplashScreenBeOS + +class nsNativeAppSupportBeOS : public nsNativeAppSupportBase { +public: + // Overrides of base implementation. + NS_IMETHOD Start( PRBool *aResult ); + NS_IMETHOD Stop( PRBool *aResult ); + NS_IMETHOD Quit(); + +private: + nsrefcnt mRefCnt; +}; // nsNativeAppSupportBeOS + +nsSplashScreenBeOS::nsSplashScreenBeOS() + : mRefCnt( 0 ) , window( NULL ) , bitmap( NULL ) { +#ifdef DEBUG_SPLASH + puts("nsSplashScreenBeOS::nsSlpashScreenBeOS()"); +#endif +} + +nsSplashScreenBeOS::~nsSplashScreenBeOS() { +#ifdef DEBUG_SPLASH + puts("nsSplashScreenBeOS::~nsSlpashScreenBeOS()"); +#endif + Hide(); +} + +NS_IMETHODIMP +nsSplashScreenBeOS::Show() { +#ifdef DEBUG_SPLASH + puts("nsSplashScreenBeOS::Show()"); +#endif + if (NULL == bitmap && NS_OK != LoadBitmap()) + return NS_ERROR_FAILURE; + + // Get the center position. + BScreen scr; + BRect scrRect = scr.Frame(); + BRect bmpRect = bitmap->Bounds(); + float winX = (scrRect.right - bmpRect.right) / 2; + float winY = (scrRect.bottom - bmpRect.bottom) / 2; + BRect winRect(winX, winY, winX + bmpRect.right, winY + bmpRect.bottom); +#ifdef DEBUG_SPLASH + printf("SplashRect (%f, %f) - (%f, %f)\n", winRect.left, winRect.top, + winRect.right, winRect.bottom); +#endif + if (NULL == window) { + window = new BWindow(winRect, + "mozilla splash", + B_NO_BORDER_WINDOW_LOOK, + B_MODAL_APP_WINDOW_FEEL, + 0); + if (NULL == window) + return NS_ERROR_FAILURE; + BView *view = new BView(bmpRect, "splash view", B_FOLLOW_ALL_SIDES, B_WILL_DRAW); + if (NULL != view) { + window->AddChild(view); + view->SetViewBitmap(bitmap); + } + window->Show(); + } + return NS_OK; +} + +NS_IMETHODIMP +nsSplashScreenBeOS::Hide() { +#ifdef DEBUG_SPLASH + puts("nsSplashScreenBeOS::Hide()"); +#endif + if (NULL != window) { + if (window->Lock()) + window->Quit(); + window = NULL; + } + if (NULL != bitmap) { + delete bitmap; + bitmap = NULL; + } + return NS_OK; +} + +nsresult +nsSplashScreenBeOS::LoadBitmap() { + BResources *rsrc = be_app->AppResources(); + if (NULL == rsrc) + return NS_ERROR_FAILURE; + size_t length; + const void *data = rsrc->LoadResource('BBMP', "MOZILLA:SPLASH", &length); + if (NULL == data) + return NS_ERROR_FAILURE; + BMessage msg; + if (B_OK != msg.Unflatten((const char *)data)) + return NS_ERROR_FAILURE; + BBitmap *bmp = new BBitmap(&msg); + if (NULL == bmp) + return NS_ERROR_FAILURE; + bitmap = new BBitmap(bmp, true); + if (NULL == bitmap) { + delete bmp; + return NS_ERROR_FAILURE; + } + return NS_OK; +} + +// Create and return an instance of class nsNativeAppSupportBeOS. +nsresult +NS_CreateNativeAppSupport( nsINativeAppSupport **aResult ) { + if ( aResult ) { + *aResult = new nsNativeAppSupportBeOS(); + if ( *aResult ) { + NS_ADDREF( *aResult ); + } else { + return NS_ERROR_OUT_OF_MEMORY; + } + } else { + return NS_ERROR_NULL_POINTER; + } + return NS_OK; +} + +// Create instance of BeOS splash screen object. +nsresult +NS_CreateSplashScreen( nsISplashScreen **aResult ) { + if ( aResult ) { + *aResult = new nsSplashScreenBeOS; + if ( *aResult ) { + NS_ADDREF( *aResult ); + } else { + return NS_ERROR_OUT_OF_MEMORY; + } + } else { + return NS_ERROR_NULL_POINTER; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsNativeAppSupportBeOS::Start( PRBool *aResult ) { + NS_ENSURE_ARG( aResult ); + + nsresult rv = NS_OK; +#ifdef DEBUG_SPLASH + puts("nsNativeAppSupportBeOS::Start()"); +#endif + *aResult = PR_TRUE; + + return rv; +} + +NS_IMETHODIMP +nsNativeAppSupportBeOS::Stop( PRBool *aResult ) { + NS_ENSURE_ARG( aResult ); + + nsresult rv = NS_OK; +#ifdef DEBUG_SPLASH + puts("nsNativeAppSupportBeOS::Stop()"); +#endif + *aResult = PR_TRUE; + + return rv; +} + +NS_IMETHODIMP +nsNativeAppSupportBeOS::Quit() { +#ifdef DEBUG_SPLASH + puts("nsNativeAppSupportBeOS::Quit()"); +#endif + + return NS_OK; +} + +PRBool NS_CanRun() +{ + return PR_TRUE; +} +