Bugzilla bug #23969: checked in dougt/bienvenu's modified fix. NSPRPUB_RELEASE_4_0_BRANCH
authorwtc%netscape.com
Mon, 24 Jan 2000 23:27:05 +0000
branchNSPRPUB_RELEASE_4_0_BRANCH
changeset 1073 4df14efc4d25a8ef26a6788db3cce9c914fdf8d4
parent 1071 ca086c7801c3cc7da2936e5235c7f4c39c64345d
child 1074 076063ccaa48edad522318d144b61264dfb39fbb
push idunknown
push userunknown
push dateunknown
bugs23969
Bugzilla bug #23969: checked in dougt/bienvenu's modified fix. (NSPRPUB_RELEASE_4_0_BRANCH)
lib/ds/plevent.c
--- a/lib/ds/plevent.c
+++ b/lib/ds/plevent.c
@@ -96,16 +96,17 @@ struct PLEventQueue {
 #if defined(VMS)
     int		 efn;
     int		 notifyCount;
 #elif defined(XP_UNIX)
     PRInt32      eventPipe[2];
 	int          notifyCount;
 #elif defined(_WIN32) || defined(WIN16)
     HWND         eventReceiverWindow;
+    PRBool       removeMsg;
 #elif defined(XP_OS2)
     HWND         eventReceiverWindow;
 #elif defined(XP_BEOS)
     port_id      eventport;
 #endif
 };
 
 #define PR_EVENT_PTR(_qp) \
@@ -158,16 +159,19 @@ static PLEventQueue *
     mon = PR_NewNamedMonitor(name);
     if (mon == NULL) goto error;
 
     self->name = name;
     self->monitor = mon;
     self->handlerThread = handlerThread;
     self->processingEvents = PR_FALSE;
     self->type = qtype;
+#if defined(_WIN32) || defined(WIN16)
+    self->removeMsg = PR_TRUE;
+#endif
     PR_INIT_CLIST(&self->queue);
     if ( qtype == EventQueueIsNative )
     {
         err = _pl_SetupNativeNotifier(self);
         if (err) goto error;
     }
     _md_CreateEventQueue( self );
     return self;
@@ -712,16 +716,18 @@ static void
         unsigned int status;
         PR_LOG(event_lm, PR_LOG_DEBUG,
            ("$$$ Freeing event flag %d", self->efn));
         status = LIB$FREE_EF(&self->efn);
     }
 #elif defined(XP_UNIX)
     close(self->eventPipe[0]);
     close(self->eventPipe[1]);
+#elif defined(_WIN32) || defined(WIN16)
+    DestroyWindow(self->eventReceiverWindow);
 #endif
 }
 
 #if defined(_WIN32) || defined(WIN16)
 static PRStatus
 _pl_NativeNotify(PLEventQueue* self)
 {
 	PostMessage( self->eventReceiverWindow, _pr_PostEventMsgId,
@@ -804,17 +810,32 @@ static PRStatus
 #pragma unused (self)
     return PR_SUCCESS;    /* XXX can fail? */
 }
 #endif /* XP_MAC */
 
 static PRStatus
 _pl_AcknowledgeNativeNotify(PLEventQueue* self)
 {
-#if defined(VMS)
+#if defined(_WIN32) || defined(WIN16)
+    MSG aMsg;
+    /*
+     * only remove msg when we've been called directly by
+     * PL_ProcessPendingEvents, not when we've been called by
+     * the window proc because the window proc will remove the
+     * msg for us.
+     */
+    if (self->removeMsg) {
+        PR_LOG(event_lm, PR_LOG_DEBUG,
+                ("_pl_AcknowledgeNativeNotify: self=%p", self));
+        PeekMessage(&aMsg, self->eventReceiverWindow,
+                _pr_PostEventMsgId, _pr_PostEventMsgId, PM_REMOVE);
+    }
+    return PR_SUCCESS;
+#elif defined(VMS)
     PR_LOG(event_lm, PR_LOG_DEBUG,
             ("_pl_AcknowledgeNativeNotify: self=%p notifyCount=%d efn=%d",
              self, self->notifyCount, self->efn));
     /*
     ** If this is the last entry, then clear the event flag. Also make sure
     ** the flag is cleared on any spurious wakeups.
     */
     if (self->notifyCount <= 1)
@@ -943,17 +964,23 @@ LRESULT CALLBACK
 #endif
 _md_EventReceiverProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 #endif
 {
     if (_pr_PostEventMsgId == uMsg )
     {
 		PREventQueue *queue = (PREventQueue *)lParam;
     
-    	PR_ProcessPendingEvents(queue);
+#if defined(_WIN32) || defined(WIN16)
+        queue->removeMsg = PR_FALSE;
+#endif
+    	PL_ProcessPendingEvents(queue);
+#if defined(_WIN32) || defined(WIN16)
+        queue->removeMsg = PR_TRUE;
+#endif
 #ifdef XP_OS2
             return MRFROMLONG(TRUE);
 #else
             return TRUE;
 #endif
         }
     return DefWindowProc(hwnd, uMsg, wParam, lParam);
 }