From 3def6cda682e8c99e44fb14f11ab903147486326 Mon Sep 17 00:00:00 2001 From: "cls%seawood.org" Date: Sun, 7 Jan 2001 08:41:49 +0000 Subject: [PATCH] Implement nsAppShell::DispatchNativeEvent() for BeOS. Thanks to Makoto Hamanaka for the patch. Bug #63649. r=cls git-svn-id: svn://10.0.0.236/trunk@84524 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/widget/src/beos/nsAppShell.cpp | 88 ++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 7 deletions(-) diff --git a/mozilla/widget/src/beos/nsAppShell.cpp b/mozilla/widget/src/beos/nsAppShell.cpp index 0e4591dd04b..f5687cdf29f 100644 --- a/mozilla/widget/src/beos/nsAppShell.cpp +++ b/mozilla/widget/src/beos/nsAppShell.cpp @@ -29,6 +29,7 @@ #include "nsSwitchToUIThread.h" #include "nsTimerBeOS.h" #include "plevent.h" +#include "prprf.h" #include #include @@ -143,8 +144,10 @@ NS_METHOD nsAppShell::Create(int* argc, char ** argv) // NOTE: this needs to be run from within the main application thread char portname[64]; char semname[64]; - sprintf(portname, "event%lx", PR_GetCurrentThread()); - sprintf(semname, "sync%lx", PR_GetCurrentThread()); + PR_snprintf(portname, sizeof(portname), "event%lx", + (long unsigned) PR_GetCurrentThread()); + PR_snprintf(semname, sizeof(semname), "sync%lx", + (long unsigned) PR_GetCurrentThread()); if((eventport = find_port(portname)) < 0) { @@ -210,7 +213,9 @@ nsresult nsAppShell::Run() break; default : +#ifdef DEBUG printf("nsAppShell::Run - UNKNOWN EVENT\n"); +#endif break; } @@ -289,14 +294,83 @@ NS_METHOD nsAppShell::Spindown() NS_METHOD nsAppShell::GetNativeEvent(PRBool &aRealEvent, void *&aEvent) { - aRealEvent = PR_FALSE; - printf("nsAppShell::GetNativeEvent - FIXME: not implemented\n"); - return NS_OK; + aRealEvent = PR_FALSE; + aEvent = 0; + + return NS_OK; } NS_METHOD nsAppShell::DispatchNativeEvent(PRBool aRealEvent, void *aEvent) { - printf("nsAppShell::DispatchNativeEvent - FIXME: not implemented\n"); - return NS_OK; + // should we check for eventport initialization ? + char portname[64]; + PR_snprintf(portname, sizeof(portname), "event%lx", + (long unsigned) PR_GetCurrentThread()); + + if((eventport = find_port(portname)) < 0) { + // not initialized +#ifdef DEBUG + printf("nsAppShell::DispatchNativeEvent() was called before init\n"); +#endif + fflush(stdout); + return NS_ERROR_FAILURE; + } + + int32 code; + ThreadInterfaceData id; + id.data = 0; + id.sync = 0; + bool gotMessage = false; + + do { + if (read_port(eventport, &code, &id, sizeof(id)) >= 0) { + switch(code) { + case 'WMti' : + { + // Hack + nsCOMPtr timer = (nsTimerBeOS *)id.data; + timer->FireTimeout(); + } + break; + case WM_CALLMETHOD : + { + MethodInfo *mInfo = (MethodInfo *)id.data; + mInfo->Invoke(); + if(! id.sync) + delete mInfo; + gotMessage = PR_TRUE; + } + break; + case 'natv' : // native queue PLEvent + { + PREventQueue *queue = (PREventQueue *)id.data; + PR_ProcessPendingEvents(queue); + gotMessage = PR_TRUE; + } + break; + default : +#ifdef DEBUG + printf("nsAppShell::Run - UNKNOWN EVENT\n"); +#endif + break; + } + + if(id.sync) + release_sem(syncsem); + + } else { + // read_port failure +#ifdef DEBUG + printf("nsAppShell::GetNativeEvent() read_port failed.\n"); +#endif + return NS_ERROR_FAILURE; + } + } while (!gotMessage); + + // no need to do this? + //if(mDispatchListener) + // mDispatchListener->AfterDispatch(); + + return NS_OK; }