Bug 281375 [BEOS] Implement toolkit/xre and xpfe/bootstrap native app support

patch by thesuckiestemail@yahoo.se r=sergei_d sr=neil a=asa
This commit is contained in:
timeless%mozdev.org 2005-04-15 15:12:19 +00:00
Родитель a2374e42b4
Коммит 1c938ac3e2
2 изменённых файлов: 271 добавлений и 219 удалений

Просмотреть файл

@ -21,6 +21,7 @@
*
* Contributor(s):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
* Fredrik Holmqvist <thesuckiestemail@yahoo.se>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -248,78 +249,6 @@ char **__argv;
int *__pargc;
#endif /* XP_OS2 */
#if defined(XP_BEOS)
#include <AppKit.h>
#include <AppFileInfo.h>
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 (nsnull == 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";
}
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"
@ -388,7 +317,7 @@ static void InitializeMacOSXApp(int argc, char* argv[])
/*********************************************/
// Default implemenations for nativeAppSupport
// If your platform implements these functions if def out this code.
#if !defined(MOZ_WIDGET_COCOA) && !defined(MOZ_WIDGET_PHOTON) && !defined( XP_WIN) && !defined(XP_OS2) && !defined( XP_BEOS ) && !defined(MOZ_WIDGET_GTK) && !defined(MOZ_WIDGET_GTK2)
#if !defined(MOZ_WIDGET_COCOA) && !defined(MOZ_WIDGET_PHOTON) && !defined( XP_WIN) && !defined(XP_OS2) && !defined(MOZ_WIDGET_GTK) && !defined(MOZ_WIDGET_GTK2)
nsresult NS_CreateSplashScreen(nsISplashScreen **aResult)
{
@ -423,7 +352,7 @@ PRBool NS_CanRun()
// nsISplashScreen will be removed.
//
#if !defined(XP_WIN) && !defined(XP_OS2) && !defined(MOZ_WIDGET_GTK) && !defined(MOZ_WIDGET_GTK2) && !defined(XP_MAC) && (!defined(XP_MACOSX) || defined(MOZ_WIDGET_COCOA))
#if !defined(XP_WIN) && !defined(XP_OS2)&& !defined( XP_BEOS ) && !defined(MOZ_WIDGET_GTK) && !defined(MOZ_WIDGET_GTK2) && !defined(XP_MAC) && (!defined(XP_MACOSX) || defined(MOZ_WIDGET_COCOA))
nsresult NS_CreateNativeAppSupport(nsINativeAppSupport **aResult)
{
@ -1664,11 +1593,6 @@ int main(int argc, char* argv[])
ScopedFPHandler handler;
#endif /* XP_OS2 */
#if defined(XP_BEOS)
if (NS_OK != InitializeBeOSApp())
return 1;
#endif
#if defined(XP_MACOSX)
InitializeMacOSXApp(argc, argv);
#endif

Просмотреть файл

@ -21,6 +21,7 @@
*
* Contributor(s):
* Takashi Toyoshima <toyoshim@be-in.org>
* Fredrik Holmqvist <thesuckiestemail@yahoo.se>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -42,6 +43,7 @@
#include "nsIObserver.h"
#include <Application.h>
#include <AppFileInfo.h>
#include <Window.h>
#include <View.h>
#include <StringView.h>
@ -54,175 +56,301 @@
#define DEBUG_SPLASH 1
#endif
class nsSplashScreenBeOS : public nsISplashScreen,
public nsIObserver {
class nsNativeAppSupportBeOS : public nsNativeAppSupportBase, public nsIObserver
{
public:
nsSplashScreenBeOS();
virtual ~nsSplashScreenBeOS();
nsNativeAppSupportBeOS();
~nsNativeAppSupportBeOS();
NS_DECL_ISUPPORTS
NS_DECL_NSINATIVEAPPSUPPORT
NS_DECL_NSIOBSERVER
private:
nsresult LoadBitmap();
NS_DECL_ISUPPORTS
BWindow *window;
BBitmap *bitmap;
BStringView *textView;
}; // nsNativeAppSupportBeOS
NS_IMETHOD Show();
NS_IMETHOD Hide();
NS_DECL_NSIOBSERVER
class nsBeOSApp : public BApplication
{
public:
nsBeOSApp(sem_id sem) : BApplication(GetAppSig()), init(sem)
{}
void ReadyToRun()
{
release_sem(init);
}
static int32 Main(void *args)
{
nsBeOSApp *app = new nsBeOSApp( (sem_id)args );
if(app == NULL)
return B_ERROR;
return app->Run();
}
private:
nsresult LoadBitmap();
BWindow *window;
BBitmap *bitmap;
BStringView *textView;
}; // class nsSplashScreenBeOS
char *GetAppSig()
{
image_info info;
int32 cookie = 0;
BFile file;
BAppFileInfo appFileInfo;
static char sig[B_MIME_TYPE_LENGTH];
nsSplashScreenBeOS::nsSplashScreenBeOS()
: window( NULL ) , bitmap( NULL ), textView(NULL) {
#ifdef DEBUG_SPLASH
puts("nsSplashScreenBeOS::nsSlpashScreenBeOS()");
#endif
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 sig;
return "application/x-vnd.Mozilla";
}
sem_id init;
}; //class nsBeOSApp
// Create and return an instance of class nsNativeAppSupportBeOS.
nsresult
NS_CreateNativeAppSupport(nsINativeAppSupport **aResult)
{
if(!aResult)
return NS_ERROR_NULL_POINTER;
nsNativeAppSupportBeOS *pNative = new nsNativeAppSupportBeOS();
if (!pNative)
return NS_ERROR_OUT_OF_MEMORY;
*aResult = pNative;
NS_ADDREF(*aResult);
return NS_OK;
}
nsSplashScreenBeOS::~nsSplashScreenBeOS() {
#ifdef DEBUG_SPLASH
puts("nsSplashScreenBeOS::~nsSlpashScreenBeOS()");
#endif
Hide();
nsNativeAppSupportBeOS::nsNativeAppSupportBeOS()
: window(NULL) , bitmap(NULL), textView(NULL)
{}
nsNativeAppSupportBeOS::~nsNativeAppSupportBeOS()
{
if(window != NULL)
HideSplashScreen();
}
NS_IMPL_ISUPPORTS2(nsSplashScreenBeOS, nsISplashScreen, nsIObserver)
NS_IMPL_ISUPPORTS2(nsNativeAppSupportBeOS, nsINativeAppSupport, nsIObserver)
NS_IMETHODIMP
nsSplashScreenBeOS::Show() {
#ifdef DEBUG_SPLASH
puts("nsSplashScreenBeOS::Show()");
#endif
if (NULL == bitmap && NS_OK != LoadBitmap())
return NS_ERROR_FAILURE;
nsNativeAppSupportBeOS::Start(PRBool *aResult)
{
NS_ENSURE_ARG(aResult);
NS_ENSURE_TRUE(be_app == NULL, NS_ERROR_NOT_INITIALIZED);
// 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;
sem_id initsem = create_sem(0, "Mozilla BApplication init");
if(initsem < B_OK)
return NS_ERROR_FAILURE;
thread_id tid = spawn_thread(nsBeOSApp::Main, "Mozilla BApplication", B_NORMAL_PRIORITY, (void *)initsem);
*aResult = PR_TRUE;
if(tid < B_OK || B_OK != resume_thread(tid))
*aResult = PR_FALSE;
if(B_OK != acquire_sem(initsem))
*aResult = PR_FALSE;
if(B_OK != delete_sem(initsem))
*aResult = PR_FALSE;
return *aResult == PR_TRUE ? NS_OK : NS_ERROR_FAILURE;
}
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;
nsNativeAppSupportBeOS::Stop(PRBool *aResult)
{
NS_ENSURE_ARG(aResult);
NS_ENSURE_TRUE(be_app, NS_ERROR_NOT_INITIALIZED);
*aResult = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsSplashScreenBeOS::Observe(nsISupports *aSubject,
nsNativeAppSupportBeOS::Quit()
{
return NS_OK;
}
NS_IMETHODIMP
nsNativeAppSupportBeOS::EnsureProfile(nsICmdLineService* args)
{
return NS_OK;
}
NS_IMETHODIMP
nsNativeAppSupportBeOS::ReOpen()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsNativeAppSupportBeOS::OnLastWindowClosing()
{
return NS_OK;
}
NS_IMETHODIMP
nsNativeAppSupportBeOS::GetIsServerMode(PRBool *aIsServerMode)
{
*aIsServerMode = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsNativeAppSupportBeOS::SetIsServerMode(PRBool aIsServerMode)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsNativeAppSupportBeOS::StartServerMode()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsNativeAppSupportBeOS::SetShouldShowUI(PRBool aShouldShowUI)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsNativeAppSupportBeOS::GetShouldShowUI(PRBool *aShouldShowUI)
{
*aShouldShowUI = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsNativeAppSupportBeOS::ShowSplashScreen()
{
#ifdef DEBUG_SPLASH
puts("nsNativeAppSupportBeOS::ShowSplashScreen()");
#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
nsNativeAppSupportBeOS::HideSplashScreen()
{
#ifdef DEBUG_SPLASH
puts("nsNativeAppSupportBeOS::HideSplashScreen()");
#endif
if(NULL != window)
{
if(window->Lock())
window->Quit();
window = NULL;
}
if(NULL != bitmap) {
delete bitmap;
bitmap = NULL;
}
return NS_OK;
}
NS_IMETHODIMP
nsNativeAppSupportBeOS::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *someData)
{
if (!bitmap) return NS_OK;
nsCAutoString statusString;
statusString.AssignWithConversion(someData);
if (textView == NULL) {
if(!bitmap)
return NS_OK;
nsCAutoString statusString;
statusString.AssignWithConversion(someData);
if(textView != NULL)
{
if (textView->LockLooper())
{
textView->SetText(statusString.get());
textView->UnlockLooper();
}
return NS_OK;
}
BRect textRect = bitmap->Bounds();
textView = new BStringView(textRect,
"splash text",
statusString.get(),
B_FOLLOW_LEFT | B_FOLLOW_V_CENTER);
if (textView) {
// Reduce the view size, and take into account the image frame
textRect.bottom -= 10;
textRect.left += 10;
textRect.right -= 10;
textRect.top = textRect.bottom - 20;
"splash text",
statusString.get(),
B_FOLLOW_LEFT | B_FOLLOW_V_CENTER);
textView->SetViewColor(B_TRANSPARENT_COLOR);
textView->SetHighColor(255,255,255,0);
textView->SetLowColor(0,0,0,0);
window->AddChild(textView);
}
} else {
if (textView->LockLooper()) {
textView->SetText(statusString.get());
textView->UnlockLooper();
}
}
return NS_OK;
if(!textView)
return NS_OK;
// Reduce the view size, and take into account the image frame
textRect.bottom -= 10;
textRect.left += 10;
textRect.right -= 10;
textRect.top = textRect.bottom - 20;
textView->SetViewColor(B_TRANSPARENT_COLOR);
textView->SetHighColor(255,255,255,0);
textView->SetLowColor(0,0,0,0);
window->AddChild(textView);
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 instance of BeOS splash screen object.
nsresult
NS_CreateSplashScreen( nsISplashScreen **aResult ) {
if ( aResult ) {
*aResult = new nsSplashScreenBeOS;
if ( *aResult ) {
NS_ADDREF( *aResult );
return NS_OK;
} else {
return NS_ERROR_OUT_OF_MEMORY;
}
} else {
return NS_ERROR_NULL_POINTER;
}
}
PRBool NS_CanRun()
nsNativeAppSupportBeOS::LoadBitmap()
{
return PR_TRUE;
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;
}