Factored the common code found in all the platforms into a single base class that is inserted higher up the class heirarchy. This allows us to further reduce the amount of cut and paste code that would have to be done.

This commit is contained in:
tbogard%aol.net 1999-09-01 11:09:10 +00:00
parent b0bda3ec10
commit 80c60a6e0c
15 changed files with 191 additions and 283 deletions

View File

@ -33,6 +33,7 @@ CPP_OBJS= \
.\..\xp\$(OBJDIR)\nsCBaseAppLoop.obj \
.\..\xp\$(OBJDIR)\nsCBaseBreathLoop.obj \
.\..\xp\$(OBJDIR)\nsCBaseThreadLoop.obj \
.\$(OBJDIR)\nsCPlatformBaseLoop.obj \
.\$(OBJDIR)\nsCEvent.obj \
.\$(OBJDIR)\nsCEventFilter.obj \
.\$(OBJDIR)\nsCAppLoop.obj \

View File

@ -29,7 +29,6 @@
nsCAppLoop::nsCAppLoop() : nsCBaseAppLoop()
{
m_WinThreadId = ::GetCurrentThreadId();
}
nsCAppLoop::~nsCAppLoop()
@ -60,82 +59,4 @@ nsresult nsCAppLoop::PlatformExit(PRInt32 exitCode)
{
PostQuitMessage(exitCode);
return NS_OK;
}
nsresult nsCAppLoop::PlatformGetNextEvent(void* platformFilterData,
void* platformEventData)
{
nsCWinFilter* filter=(nsCWinFilter*)platformFilterData;
MSG* pMsg=(MSG*)platformEventData;
if(::GetMessage(pMsg, filter->hWnd, filter->wMsgFilterMin,
filter->wMsgFilterMax))
return NS_OK;
return NS_COMFALSE;
}
nsresult nsCAppLoop::PlatformPeekNextEvent(void* platformFilterData,
void* platformEventData, PRBool fRemoveEvent)
{
nsCWinFilter* filter=(nsCWinFilter*)platformFilterData;
MSG* pMsg=(MSG*)platformEventData;
if(fRemoveEvent)
filter->wRemoveFlags|= PM_REMOVE;
else
filter->wRemoveFlags&= ~PM_REMOVE;
if(::PeekMessage(pMsg, filter->hWnd, filter->wMsgFilterMin,
filter->wMsgFilterMax, filter->wRemoveFlags))
return NS_OK;
return NS_COMFALSE;
}
nsresult nsCAppLoop::PlatformTranslateEvent(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
::TranslateMessage(pMsg);
return NS_OK;
}
nsresult nsCAppLoop::PlatformDispatchEvent(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
::DispatchMessage(pMsg);
return NS_OK;
}
nsresult nsCAppLoop::PlatformSendLoopEvent(void* platformEventData, PRInt32* result)
{
MSG* pMsg=(MSG*)platformEventData;
*result = ::SendMessage(pMsg->hwnd, pMsg->message, pMsg->wParam,pMsg->lParam);
return NS_OK;
}
nsresult nsCAppLoop::PlatformPostLoopEvent(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
if(!pMsg->hwnd)
{
if(!::PostThreadMessage(m_WinThreadId, pMsg->message, pMsg->wParam,
pMsg->lParam))
return NS_ERROR_FAILURE;
}
else if(!::PostMessage(pMsg->hwnd, pMsg->message, pMsg->wParam, pMsg->lParam))
return NS_ERROR_FAILURE;
return NS_OK;
}
nsNativeEventDataType nsCAppLoop::PlatformGetEventType()
{
return nsNativeEventDataTypes::WinMsgStruct;
}
nsNativeEventDataType nsCAppLoop::PlatformGetFilterType()
{
return nsNativeFilterDataTypes::WinFilter;
}
PRInt32 nsCAppLoop::PlatformGetReturnCode(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
return pMsg->wParam;
}

View File

@ -39,20 +39,6 @@ protected:
// Internal Platform Implementations of nsIEventLoop
// (Error checking is ensured above)
nsresult PlatformExit(PRInt32 exitCode);
nsresult PlatformGetNextEvent(void* platformFilterData, void* platformEventData);
nsresult PlatformPeekNextEvent(void* FilterData, void* platformEventData,
PRBool fRemoveElement);
nsresult PlatformTranslateEvent(void* platformEventData);
nsresult PlatformDispatchEvent(void* platformEventData);
nsresult PlatformSendLoopEvent(void* platformEventData, PRInt32* result);
nsresult PlatformPostLoopEvent(void* platformEventData);
nsNativeEventDataType PlatformGetEventType();
nsNativeFilterDataType PlatformGetFilterType();
PRInt32 PlatformGetReturnCode(void* platformEventData);
protected:
DWORD m_WinThreadId;
};
#endif /* nsCAppLoop_h__ */

View File

@ -29,7 +29,6 @@
nsCBreathLoop::nsCBreathLoop() : nsCBaseBreathLoop()
{
m_WinThreadId = ::GetCurrentThreadId();
}
nsCBreathLoop::~nsCBreathLoop()
@ -62,78 +61,6 @@ nsresult nsCBreathLoop::PlatformExit(PRInt32 exitCode)
return NS_OK;
}
nsresult nsCBreathLoop::PlatformGetNextEvent(void* platformFilterData,
void* platformEventData)
{
nsCWinFilter* filter=(nsCWinFilter*)platformFilterData;
MSG* pMsg=(MSG*)platformEventData;
if(::GetMessage(pMsg, filter->hWnd, filter->wMsgFilterMin,
filter->wMsgFilterMax))
return NS_OK;
return NS_COMFALSE;
}
nsresult nsCBreathLoop::PlatformPeekNextEvent(void* platformFilterData,
void* platformEventData, PRBool fRemoveEvent)
{
nsCWinFilter* filter=(nsCWinFilter*)platformFilterData;
MSG* pMsg=(MSG*)platformEventData;
if(fRemoveEvent)
filter->wRemoveFlags|= PM_REMOVE;
else
filter->wRemoveFlags&= ~PM_REMOVE;
if(::PeekMessage(pMsg, filter->hWnd, filter->wMsgFilterMin,
filter->wMsgFilterMax, filter->wRemoveFlags))
return NS_OK;
return NS_COMFALSE;
}
nsresult nsCBreathLoop::PlatformTranslateEvent(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
::TranslateMessage(pMsg);
return NS_OK;
}
nsresult nsCBreathLoop::PlatformDispatchEvent(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
::DispatchMessage(pMsg);
return NS_OK;
}
nsresult nsCBreathLoop::PlatformSendLoopEvent(void* platformEventData, PRInt32* result)
{
MSG* pMsg=(MSG*)platformEventData;
*result = ::SendMessage(pMsg->hwnd, pMsg->message, pMsg->wParam,pMsg->lParam);
return NS_OK;
}
nsresult nsCBreathLoop::PlatformPostLoopEvent(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
if(!pMsg->hwnd)
{
if(!::PostThreadMessage(m_WinThreadId, pMsg->message, pMsg->wParam,
pMsg->lParam))
return NS_ERROR_FAILURE;
}
else if(!::PostMessage(pMsg->hwnd, pMsg->message, pMsg->wParam, pMsg->lParam))
return NS_ERROR_FAILURE;
return NS_OK;
}
nsNativeEventDataType nsCBreathLoop::PlatformGetEventType()
{
return nsNativeEventDataTypes::WinMsgStruct;
}
nsNativeEventDataType nsCBreathLoop::PlatformGetFilterType()
{
return nsNativeFilterDataTypes::WinFilter;
}
PRInt32 nsCBreathLoop::PlatformGetReturnCode(void* platformEventData)
{
return 0;

View File

@ -39,20 +39,8 @@ protected:
// Internal Platform Implementations of nsIEventLoop
// (Error checking is ensured above)
nsresult PlatformExit(PRInt32 exitCode);
nsresult PlatformGetNextEvent(void* platformFilterData, void* platformEventData);
nsresult PlatformPeekNextEvent(void* FilterData, void* platformEventData,
PRBool fRemoveElement);
nsresult PlatformTranslateEvent(void* platformEventData);
nsresult PlatformDispatchEvent(void* platformEventData);
nsresult PlatformSendLoopEvent(void* platformEventData, PRInt32* result);
nsresult PlatformPostLoopEvent(void* platformEventData);
nsNativeEventDataType PlatformGetEventType();
nsNativeFilterDataType PlatformGetFilterType();
PRInt32 PlatformGetReturnCode(void* platformEventData);
protected:
DWORD m_WinThreadId;
};
#endif /* nsCBreathLoop_h__ */

View File

@ -0,0 +1,121 @@
/* -*- 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):
* Travis Bogard <travis@netscape.com>
*/
#include "nsCPlatformBaseLoop.h"
#include "nsCWinFilter.h"
//*****************************************************************************
//*** nsCPlatformBaseLoop: Object Management
//*****************************************************************************
nsCPlatformBaseLoop::nsCPlatformBaseLoop(nsEventLoopType type) :
nsCBaseLoop(type)
{
m_WinThreadId = ::GetCurrentThreadId();
}
nsCPlatformBaseLoop::~nsCPlatformBaseLoop()
{
}
//*****************************************************************************
// nsCPlatformBaseLoop:: Internal Platform Implementations of nsIEventLoop
// (Error checking is ensured above)
//*****************************************************************************
nsresult nsCPlatformBaseLoop::PlatformGetNextEvent(void* platformFilterData,
void* platformEventData)
{
nsCWinFilter* filter=(nsCWinFilter*)platformFilterData;
MSG* pMsg=(MSG*)platformEventData;
if(::GetMessage(pMsg, filter->hWnd, filter->wMsgFilterMin,
filter->wMsgFilterMax))
return NS_OK;
return NS_COMFALSE;
}
nsresult nsCPlatformBaseLoop::PlatformPeekNextEvent(void* platformFilterData,
void* platformEventData, PRBool fRemoveEvent)
{
nsCWinFilter* filter=(nsCWinFilter*)platformFilterData;
MSG* pMsg=(MSG*)platformEventData;
if(fRemoveEvent)
filter->wRemoveFlags|= PM_REMOVE;
else
filter->wRemoveFlags&= ~PM_REMOVE;
if(::PeekMessage(pMsg, filter->hWnd, filter->wMsgFilterMin,
filter->wMsgFilterMax, filter->wRemoveFlags))
return NS_OK;
return NS_COMFALSE;
}
nsresult nsCPlatformBaseLoop::PlatformTranslateEvent(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
::TranslateMessage(pMsg);
return NS_OK;
}
nsresult nsCPlatformBaseLoop::PlatformDispatchEvent(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
::DispatchMessage(pMsg);
return NS_OK;
}
nsresult nsCPlatformBaseLoop::PlatformSendLoopEvent(void* platformEventData, PRInt32* result)
{
MSG* pMsg=(MSG*)platformEventData;
*result = ::SendMessage(pMsg->hwnd, pMsg->message, pMsg->wParam,pMsg->lParam);
return NS_OK;
}
nsresult nsCPlatformBaseLoop::PlatformPostLoopEvent(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
if(!pMsg->hwnd)
{
if(!::PostThreadMessage(m_WinThreadId, pMsg->message, pMsg->wParam,
pMsg->lParam))
return NS_ERROR_FAILURE;
}
else if(!::PostMessage(pMsg->hwnd, pMsg->message, pMsg->wParam, pMsg->lParam))
return NS_ERROR_FAILURE;
return NS_OK;
}
nsNativeEventDataType nsCPlatformBaseLoop::PlatformGetEventType()
{
return nsNativeEventDataTypes::WinMsgStruct;
}
nsNativeEventDataType nsCPlatformBaseLoop::PlatformGetFilterType()
{
return nsNativeFilterDataTypes::WinFilter;
}
PRInt32 nsCPlatformBaseLoop::PlatformGetReturnCode(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
return pMsg->wParam;
}

View File

@ -0,0 +1,56 @@
/* -*- 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):
* Travis Bogard <travis@netscape.com>
*/
#ifndef nsCPlatformBaseLoop_h__
#define nsCPlatformBaseLoop_h__
#include "windows.h"
#include "nsCBaseLoop.h"
class nsCPlatformBaseLoop : public nsCBaseLoop
{
protected:
nsCPlatformBaseLoop(nsEventLoopType type);
virtual ~nsCPlatformBaseLoop();
// Internal Platform Implementations of nsIEventLoop
// (Error checking is ensured above)
// We can over-ride these at a high level because they are the same
// across all types of event loops.
nsresult PlatformGetNextEvent(void* platformFilterData, void* platformEventData);
nsresult PlatformPeekNextEvent(void* FilterData, void* platformEventData,
PRBool fRemoveElement);
nsresult PlatformTranslateEvent(void* platformEventData);
nsresult PlatformDispatchEvent(void* platformEventData);
nsresult PlatformSendLoopEvent(void* platformEventData, PRInt32* result);
nsresult PlatformPostLoopEvent(void* platformEventData);
nsNativeEventDataType PlatformGetEventType();
nsNativeFilterDataType PlatformGetFilterType();
PRInt32 PlatformGetReturnCode(void* platformEventData);
protected:
DWORD m_WinThreadId;
};
#endif /* nsCAppLoop_h__ */

View File

@ -29,7 +29,6 @@
nsCThreadLoop::nsCThreadLoop() : nsCBaseThreadLoop()
{
m_WinThreadId = ::GetCurrentThreadId();
}
nsCThreadLoop::~nsCThreadLoop()
@ -60,84 +59,4 @@ nsresult nsCThreadLoop::PlatformExit(PRInt32 exitCode)
{
::PostThreadMessage(m_WinThreadId, WM_QUIT, 0, 0);
return NS_OK;
}
nsresult nsCThreadLoop::PlatformGetNextEvent(void* platformFilterData,
void* platformEventData)
{
nsCWinFilter* filter=(nsCWinFilter*)platformFilterData;
MSG* pMsg=(MSG*)platformEventData;
if(::GetMessage(pMsg, filter->hWnd, filter->wMsgFilterMin,
filter->wMsgFilterMax))
return NS_OK;
return NS_COMFALSE;
}
nsresult nsCThreadLoop::PlatformPeekNextEvent(void* platformFilterData,
void* platformEventData, PRBool fRemoveEvent)
{
nsCWinFilter* filter=(nsCWinFilter*)platformFilterData;
MSG* pMsg=(MSG*)platformEventData;
if(fRemoveEvent)
filter->wRemoveFlags|= PM_REMOVE;
else
filter->wRemoveFlags&= ~PM_REMOVE;
if(::PeekMessage(pMsg, filter->hWnd, filter->wMsgFilterMin,
filter->wMsgFilterMax, filter->wRemoveFlags))
return NS_OK;
return NS_COMFALSE;
}
nsresult nsCThreadLoop::PlatformTranslateEvent(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
::TranslateMessage(pMsg);
return NS_OK;
}
nsresult nsCThreadLoop::PlatformDispatchEvent(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
::DispatchMessage(pMsg);
return NS_OK;
}
nsresult nsCThreadLoop::PlatformSendLoopEvent(void* platformEventData, PRInt32* result)
{
MSG* pMsg=(MSG*)platformEventData;
*result = ::SendMessage(pMsg->hwnd, pMsg->message, pMsg->wParam,pMsg->lParam);
return NS_OK;
}
nsresult nsCThreadLoop::PlatformPostLoopEvent(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
if(!pMsg->hwnd)
{
if(!::PostThreadMessage(m_WinThreadId, pMsg->message, pMsg->wParam,
pMsg->lParam))
return NS_ERROR_FAILURE;
}
else if(!::PostMessage(pMsg->hwnd, pMsg->message, pMsg->wParam, pMsg->lParam))
return NS_ERROR_FAILURE;
return NS_OK;
}
nsNativeEventDataType nsCThreadLoop::PlatformGetEventType()
{
return nsNativeEventDataTypes::WinMsgStruct;
}
nsNativeEventDataType nsCThreadLoop::PlatformGetFilterType()
{
return nsNativeFilterDataTypes::WinFilter;
}
PRInt32 nsCThreadLoop::PlatformGetReturnCode(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
return pMsg->wParam;
}
}

View File

@ -39,20 +39,8 @@ protected:
// Internal Platform Implementations of nsIEventLoop
// (Error checking is ensured above)
nsresult PlatformExit(PRInt32 exitCode);
nsresult PlatformGetNextEvent(void* platformFilterData, void* platformEventData);
nsresult PlatformPeekNextEvent(void* FilterData, void* platformEventData,
PRBool fRemoveElement);
nsresult PlatformTranslateEvent(void* platformEventData);
nsresult PlatformDispatchEvent(void* platformEventData);
nsresult PlatformSendLoopEvent(void* platformEventData, PRInt32* result);
nsresult PlatformPostLoopEvent(void* platformEventData);
nsNativeEventDataType PlatformGetEventType();
nsNativeFilterDataType PlatformGetFilterType();
PRInt32 PlatformGetReturnCode(void* platformEventData);
protected:
DWORD m_WinThreadId;
};
#endif /* nsCThreadLoop_h__ */

View File

@ -30,7 +30,7 @@
//*** nsCBaseAppLoop: Object Management
//*****************************************************************************
nsCBaseAppLoop::nsCBaseAppLoop() : nsCBaseLoop(nsEventLoopTypes::MainAppLoop)
nsCBaseAppLoop::nsCBaseAppLoop() : nsCPlatformBaseLoop(nsEventLoopTypes::MainAppLoop)
{
}

View File

@ -23,9 +23,9 @@
#ifndef nsCBaseAppLoop_h__
#define nsCBaseAppLoop_h__
#include "nsCBaseLoop.h"
#include "nsCPlatformBaseLoop.h"
class nsCBaseAppLoop : public nsCBaseLoop
class nsCBaseAppLoop : public nsCPlatformBaseLoop
{
public:

View File

@ -30,7 +30,8 @@
//*** nsCBaseBreathLoop: Object Management
//*****************************************************************************
nsCBaseBreathLoop::nsCBaseBreathLoop() : nsCBaseLoop(nsEventLoopTypes::AppBreathLoop)
nsCBaseBreathLoop::nsCBaseBreathLoop() :
nsCPlatformBaseLoop(nsEventLoopTypes::AppBreathLoop)
{
}

View File

@ -23,9 +23,9 @@
#ifndef nsCBaseBreathLoop_h__
#define nsCBaseBreathLoop_h__
#include "nsCBaseLoop.h"
#include "nsCPlatformBaseLoop.h"
class nsCBaseBreathLoop : public nsCBaseLoop
class nsCBaseBreathLoop : public nsCPlatformBaseLoop
{
public:

View File

@ -31,7 +31,7 @@
//*****************************************************************************
nsCBaseThreadLoop::nsCBaseThreadLoop() :
nsCBaseLoop(nsEventLoopTypes::ThreadLoop)
nsCPlatformBaseLoop(nsEventLoopTypes::ThreadLoop)
{
}

View File

@ -23,9 +23,9 @@
#ifndef nsCBaseThreadLoop_h__
#define nsCBaseThreadLoop_h__
#include "nsCBaseLoop.h"
#include "nsCPlatformBaseLoop.h"
class nsCBaseThreadLoop : public nsCBaseLoop
class nsCBaseThreadLoop : public nsCPlatformBaseLoop
{
public: