From 2cb20d8feeb3ef01f5177151b30ae57f03c0f492 Mon Sep 17 00:00:00 2001 From: "Jerry.Kirk%Nexwarecorp.com" Date: Wed, 8 Sep 1999 20:11:24 +0000 Subject: [PATCH] Major change in ncCEvent, I made another encapsulation layer called nsCPhEvent git-svn-id: svn://10.0.0.236/trunk@46394 18797224-902f-48f8-a5cc-f745e15eee43 --- .../appshell/eventloop/photon/Makefile.in | 9 +- .../appshell/eventloop/photon/nsCAppLoop.h | 1 + .../appshell/eventloop/photon/nsCEvent.cpp | 59 ++++++------ .../appshell/eventloop/photon/nsCEvent.h | 7 +- .../eventloop/photon/nsCEventFilter.h | 1 - .../appshell/eventloop/photon/nsCPhEvent.cpp | 89 +++++++++++++++++++ .../appshell/eventloop/photon/nsCPhEvent.h | 43 +++++++++ .../appshell/eventloop/photon/nsCPhFilter.h | 2 +- .../eventloop/photon/nsCPlatformBaseLoop.cpp | 80 +++++++++++++++-- 9 files changed, 246 insertions(+), 45 deletions(-) create mode 100644 mozilla/xpcom/appshell/eventloop/photon/nsCPhEvent.cpp create mode 100644 mozilla/xpcom/appshell/eventloop/photon/nsCPhEvent.h diff --git a/mozilla/xpcom/appshell/eventloop/photon/Makefile.in b/mozilla/xpcom/appshell/eventloop/photon/Makefile.in index 1519419c6d9..f96d64ed41f 100644 --- a/mozilla/xpcom/appshell/eventloop/photon/Makefile.in +++ b/mozilla/xpcom/appshell/eventloop/photon/Makefile.in @@ -31,12 +31,13 @@ REQUIRES=xpcom IS_COMPONENT = 1 CPPSRCS = \ + nsCPhEvent.cpp \ nsCEvent.cpp \ - nsCEventFilter.cpp + nsCEventFilter.cpp \ + nsCPlatformBaseLoop.cpp \ + nsCAppLoop.cpp -# nsCPlatformBaseLoop.cpp - -LOCAL_INCLUDES += -I../xp +LOCAL_INCLUDES += -I. -I../xp include $(topsrcdir)/config/config.mk diff --git a/mozilla/xpcom/appshell/eventloop/photon/nsCAppLoop.h b/mozilla/xpcom/appshell/eventloop/photon/nsCAppLoop.h index 75776271ca6..cb2a5e1c045 100644 --- a/mozilla/xpcom/appshell/eventloop/photon/nsCAppLoop.h +++ b/mozilla/xpcom/appshell/eventloop/photon/nsCAppLoop.h @@ -23,6 +23,7 @@ #ifndef nsCAppLoop_h__ #define nsCAppLoop_h__ + #include "nsCBaseAppLoop.h" class nsCAppLoop : public nsCBaseAppLoop diff --git a/mozilla/xpcom/appshell/eventloop/photon/nsCEvent.cpp b/mozilla/xpcom/appshell/eventloop/photon/nsCEvent.cpp index b5198b9d282..c1c139481c9 100644 --- a/mozilla/xpcom/appshell/eventloop/photon/nsCEvent.cpp +++ b/mozilla/xpcom/appshell/eventloop/photon/nsCEvent.cpp @@ -22,35 +22,33 @@ */ #include "nsCRT.h" - #include "nsCEvent.h" +#include +PRLogModuleInfo *PhEventLog = PR_NewLogModule("PhEventLog"); + +#include "nsPhEventLog.h" + //***************************************************************************** //*** nsCEvent: Object Management //***************************************************************************** nsCEvent::nsCEvent(void* platformEventData) { + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCEvent::nsCEvent platformEventData=<%p>\n", platformEventData)); + NS_INIT_REFCNT(); - - if (platformEventData) - { - mEventBufferSz = PhGetMsgSize ( (PhEvent_t *) platformEventData ); - m_msg = (PhEvent_t *) malloc( mEventBufferSz ); - if (m_msg); - nsCRT::memcpy(m_msg, platformEventData, mEventBufferSz); - } - else - { - mEventBufferSz = sizeof(PhEvent_t); - m_msg = (PhEvent_t *) malloc( mEventBufferSz ); - if (m_msg); - nsCRT::memset(m_msg, 0, mEventBufferSz); - } + m_msg = new nsCPhEvent( (PhEvent_t *) platformEventData); } nsCEvent::~nsCEvent() { + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCEvent::~nsCEvent\n")); + + if (m_msg) + { + delete m_msg; + } } //***************************************************************************** @@ -66,35 +64,40 @@ NS_IMPL_ISUPPORTS1(nsCEvent, nsIEvent) NS_IMETHODIMP nsCEvent::GetNativeData(nsNativeEventDataType dataType, void** data) { + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCEvent::GetNativeData dataType=<%d> data=<%p>\n", dataType, data)); + + NS_ENSURE_ARG(nsNativeEventDataTypes::PhotonMsgStruct == dataType); NS_ENSURE_ARG_POINTER(data); *data = m_msg; - return NS_OK; } NS_IMETHODIMP nsCEvent::SetNativeData(nsNativeEventDataType dataType, void* data) { + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCEvent::SetNativeData dataType=<%d>\n", dataType)); + NS_ENSURE_ARG(nsNativeEventDataTypes::PhotonMsgStruct == dataType); if(!data) { /* Get rid of the Event */ - nsCRT::memset(m_msg, 0, mEventBufferSz); + if (m_msg) + delete m_msg; + m_msg = new nsCPhEvent(NULL); } else { - unsigned long locEventBufferSz = PhGetMsgSize ( (PhEvent_t *) data ); - if (locEventBufferSz > mEventBufferSz) - { - mEventBufferSz = locEventBufferSz; - m_msg = (PhEvent_t *) realloc( mEventBufferSz, mEventBufferSz ); - NS_ENSURE_ARG_POINTER(m_msg); - } - nsCRT::memcpy(m_msg, data, mEventBufferSz); - } + /* Get rid of the Event */ + if (m_msg) + delete m_msg; + + nsCPhEvent *aEvent = (nsCPhEvent *) data; + m_msg = new nsCPhEvent(aEvent->m_msg); + } return NS_OK; -} \ No newline at end of file +} + \ No newline at end of file diff --git a/mozilla/xpcom/appshell/eventloop/photon/nsCEvent.h b/mozilla/xpcom/appshell/eventloop/photon/nsCEvent.h index 57b6d651b21..2b05b487171 100644 --- a/mozilla/xpcom/appshell/eventloop/photon/nsCEvent.h +++ b/mozilla/xpcom/appshell/eventloop/photon/nsCEvent.h @@ -24,7 +24,7 @@ #ifndef nsCEvent_h__ #define nsCEvent_h__ -#include "PhT.h" +#include "nsCPhEvent.h" #include "nsIEvent.h" class nsCEvent : public nsIEvent @@ -35,13 +35,12 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIEVENT - + protected: virtual ~nsCEvent(); protected: - PhEvent_t *m_msg; - unsigned long mEventBufferSz; + nsCPhEvent *m_msg; }; #endif /* nsCEvent_h__ */ diff --git a/mozilla/xpcom/appshell/eventloop/photon/nsCEventFilter.h b/mozilla/xpcom/appshell/eventloop/photon/nsCEventFilter.h index 617932172fa..a0518599490 100644 --- a/mozilla/xpcom/appshell/eventloop/photon/nsCEventFilter.h +++ b/mozilla/xpcom/appshell/eventloop/photon/nsCEventFilter.h @@ -24,7 +24,6 @@ #ifndef nsCEventFilter_h__ #define nsCEventFilter_h__ -#include "PhT.h" #include "nsIEventFilter.h" #include "nsCPhFilter.h" diff --git a/mozilla/xpcom/appshell/eventloop/photon/nsCPhEvent.cpp b/mozilla/xpcom/appshell/eventloop/photon/nsCPhEvent.cpp new file mode 100644 index 00000000000..199d406f1bc --- /dev/null +++ b/mozilla/xpcom/appshell/eventloop/photon/nsCPhEvent.cpp @@ -0,0 +1,89 @@ +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the Mozilla browser. + * + * The Initial Developer of the Original Code is Netscape + * Communications, Inc. Portions created by Netscape are + * Copyright (C) 1999, Mozilla. All Rights Reserved. + * + * Contributor(s): + * Jerry Kirk + */ + +#include "nsCRT.h" +#include "nsCPhEvent.h" + +#include "nsPhEventLog.h" + +//***************************************************************************** +//*** nsCPhEvent: Object Management +//***************************************************************************** + +nsCPhEvent::nsCPhEvent(PhEvent_t* platformEventData) +{ + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCPhEvent::nsCPhEvent platformEventData=<%p>\n", platformEventData)); + + if (platformEventData) + { + mEventBufferSz = PhGetMsgSize ( platformEventData ); + m_msg = (PhEvent_t *) malloc( mEventBufferSz ); + if (m_msg); + nsCRT::memcpy(m_msg, platformEventData, mEventBufferSz); + } + else + { + mEventBufferSz = sizeof(PhEvent_t); + m_msg = (PhEvent_t *) malloc( mEventBufferSz ); + if (m_msg); + nsCRT::memset(m_msg, 0, mEventBufferSz); + } +} + +nsCPhEvent::~nsCPhEvent() +{ + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCPhEvent::~nsCPhEvent\n")); + + if (m_msg) + { + free(m_msg); + m_msg = nsnull; + mEventBufferSz = 0; + } +} + +unsigned long nsCPhEvent::GetEventBufferSize() +{ + return mEventBufferSz; +} + +unsigned long nsCPhEvent::GetEventSize() +{ + unsigned long theEventSize = 0; + if (m_msg) + theEventSize = PhGetMsgSize ( (PhEvent_t *) m_msg ); + + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCPhEvent::GetEventSize theEventSize=<%d>\n", theEventSize)); + + return theEventSize; +} + +nsresult nsCPhEvent::ResizeEvent(unsigned long aEventSize) +{ + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCPhEvent::ResizeEvent old_size=<%d> new_size=<%d>\n", mEventBufferSz, aEventSize)); + + mEventBufferSz = aEventSize; + m_msg = (PhEvent_t *) realloc( m_msg, mEventBufferSz ); + NS_ENSURE_ARG_POINTER(m_msg); + return NS_OK; +} + \ No newline at end of file diff --git a/mozilla/xpcom/appshell/eventloop/photon/nsCPhEvent.h b/mozilla/xpcom/appshell/eventloop/photon/nsCPhEvent.h new file mode 100644 index 00000000000..dbb8764e15b --- /dev/null +++ b/mozilla/xpcom/appshell/eventloop/photon/nsCPhEvent.h @@ -0,0 +1,43 @@ +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the Mozilla browser. + * + * The Initial Developer of the Original Code is Netscape + * Communications, Inc. Portions created by Netscape are + * Copyright (C) 1999, Mozilla. All Rights Reserved. + * + * Contributor(s): + * Jerry Kirk + */ + +#ifndef nsCPhEvent_h__ +#define nsCPhEvent_h__ + +#include "PhT.h" + +class nsCPhEvent +{ +public: + nsCPhEvent(PhEvent_t *platformEventData=nsnull); + virtual ~nsCPhEvent(); + + unsigned long GetEventBufferSize(); + unsigned long GetEventSize(); + nsresult ResizeEvent(unsigned long aEventSize); + +public: + PhEvent_t *m_msg; + unsigned long mEventBufferSz; +}; + +#endif /* nsCPhEvent_h__ */ diff --git a/mozilla/xpcom/appshell/eventloop/photon/nsCPhFilter.h b/mozilla/xpcom/appshell/eventloop/photon/nsCPhFilter.h index 98a8afc0b8f..98c4fe3eac2 100644 --- a/mozilla/xpcom/appshell/eventloop/photon/nsCPhFilter.h +++ b/mozilla/xpcom/appshell/eventloop/photon/nsCPhFilter.h @@ -24,7 +24,7 @@ #ifndef nsCPhFilter_h__ #define nsCPhFilter_h__ -#include "PhT.h" +//#include "PhT.h" class nsCPhFilter { diff --git a/mozilla/xpcom/appshell/eventloop/photon/nsCPlatformBaseLoop.cpp b/mozilla/xpcom/appshell/eventloop/photon/nsCPlatformBaseLoop.cpp index d2df1abd55d..c39468d4d98 100644 --- a/mozilla/xpcom/appshell/eventloop/photon/nsCPlatformBaseLoop.cpp +++ b/mozilla/xpcom/appshell/eventloop/photon/nsCPlatformBaseLoop.cpp @@ -22,8 +22,12 @@ */ #include "nsCPlatformBaseLoop.h" +#include "nsCPhEvent.h" #include "nsCPhFilter.h" +#include "nsPhEventLog.h" +#include + //***************************************************************************** //*** nsCPlatformBaseLoop: Object Management //***************************************************************************** @@ -32,10 +36,13 @@ nsCPlatformBaseLoop::nsCPlatformBaseLoop(nsEventLoopType type) : nsCBaseLoop(type) { m_PhThreadId = pthread_self(); + + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCPlatformBaseLoop::nsCPlatformBaseLoop nsEventLoopType=<%d> m_PhThreadId=<%d>\n", type, m_PhThreadId)); } nsCPlatformBaseLoop::~nsCPlatformBaseLoop() { + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCPlatformBaseLoop::~nsCPlatformBaseLoop m_PhThreadId=<%d>\n", m_PhThreadId)); } //***************************************************************************** @@ -46,17 +53,49 @@ nsCPlatformBaseLoop::~nsCPlatformBaseLoop() nsresult nsCPlatformBaseLoop::PlatformGetNextEvent(void* platformFilterData, void* platformEventData) { + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCPlatformBaseLoop::PlatformGetNextEvent platformFilterData=<%p> platformEventData=<%p>\n", platformFilterData, platformEventData)); + nsCPhFilter* filter=(nsCPhFilter*)platformFilterData; - PhEvent_t* pEvent = (PhEvent_t*) platformEventData; - if(::GetMessage(pMsg, filter->hWnd, filter->wMsgFilterMin, - filter->wMsgFilterMax)) - return NS_OK; - return NS_COMFALSE; + nsCPhEvent* pEvent = (nsCPhEvent*) platformEventData; + PRBool done = PR_FALSE; + + if(filter != NULL) + { + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCPlatformBaseLoop::PlatformGetNextEvent Filters not supported\n")); + + return NS_COMFALSE; + } + + while(!done) + { + switch( PhEventNext(pEvent->m_msg, pEvent->GetEventBufferSize())) + { + case Ph_EVENT_MSG: + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCPlatformBaseLoop::PlatformGetNextEvent GetMessage\n")); + done = PR_TRUE; + break; + case Ph_RESIZE_MSG: + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCPlatformBaseLoop::PlatformGetNextEvent Resize Message from <%d> to <%d>\n", pEvent->GetEventBufferSize(), pEvent->GetEventSize())); + pEvent->ResizeEvent(pEvent->GetEventSize()); + break; + } + } + + return NS_OK; } nsresult nsCPlatformBaseLoop::PlatformPeekNextEvent(void* platformFilterData, void* platformEventData, PRBool fRemoveEvent) { + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCPlatformBaseLoop::PlatformPeekNextEvent platformFilterData=<%p> platformEventData=<%p> fRemoveEvent=<%d>\n", platformFilterData, platformEventData, fRemoveEvent)); + + if(fRemoveEvent == PR_FALSE) + { + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCPlatformBaseLoop::PlatformPeekNextEvent Leaving the element on the queue is not supported\n")); + return NS_COMFALSE; + } + +#if 0 nsCWinFilter* filter=(nsCWinFilter*)platformFilterData; MSG* pMsg=(MSG*)platformEventData; @@ -67,32 +106,51 @@ nsresult nsCPlatformBaseLoop::PlatformPeekNextEvent(void* platformFilterData, if(::PeekMessage(pMsg, filter->hWnd, filter->wMsgFilterMin, filter->wMsgFilterMax, filter->wRemoveFlags)) return NS_OK; +#endif return NS_COMFALSE; } nsresult nsCPlatformBaseLoop::PlatformTranslateEvent(void* platformEventData) { + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCPlatformBaseLoop::PlatformTranslateEvent platformEventData=<%p>\n", platformEventData)); + +#if 0 MSG* pMsg=(MSG*)platformEventData; ::TranslateMessage(pMsg); +#endif + return NS_OK; } nsresult nsCPlatformBaseLoop::PlatformDispatchEvent(void* platformEventData) { + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCPlatformBaseLoop::PlatformDispatchEvent platformEventData=<%p>\n", platformEventData)); + +#if 0 MSG* pMsg=(MSG*)platformEventData; ::DispatchMessage(pMsg); +#endif + return NS_OK; } nsresult nsCPlatformBaseLoop::PlatformSendLoopEvent(void* platformEventData, PRInt32* result) { + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCPlatformBaseLoop::PlatformSendLoopEvent platformEventData=<%p>\n", platformEventData)); + +#if 0 MSG* pMsg=(MSG*)platformEventData; *result = ::SendMessage(pMsg->hwnd, pMsg->message, pMsg->wParam,pMsg->lParam); +#endif + return NS_OK; } nsresult nsCPlatformBaseLoop::PlatformPostLoopEvent(void* platformEventData) { + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCPlatformBaseLoop::PlatformPostLoopEvent platformEventData=<%p>\n", platformEventData)); + +#if 0 MSG* pMsg=(MSG*)platformEventData; if(!pMsg->hwnd) { @@ -102,21 +160,29 @@ nsresult nsCPlatformBaseLoop::PlatformPostLoopEvent(void* platformEventData) } else if(!::PostMessage(pMsg->hwnd, pMsg->message, pMsg->wParam, pMsg->lParam)) return NS_ERROR_FAILURE; +#endif + return NS_OK; } nsNativeEventDataType nsCPlatformBaseLoop::PlatformGetEventType() { - return nsNativeEventDataTypes::WinMsgStruct; + return nsNativeEventDataTypes::PhotonMsgStruct; } nsNativeEventDataType nsCPlatformBaseLoop::PlatformGetFilterType() { - return nsNativeFilterDataTypes::WinFilter; + return nsNativeFilterDataTypes::PhotonFilter; } PRInt32 nsCPlatformBaseLoop::PlatformGetReturnCode(void* platformEventData) { + PR_LOG(PhEventLog, PR_LOG_DEBUG, ("nsCPlatformBaseLoop::PlatformGetReturnCode platformEventData=<%p>\n", platformEventData)); + +#if 0 MSG* pMsg=(MSG*)platformEventData; return pMsg->wParam; +#endif + + return -1; } \ No newline at end of file