Added paint and mousemove events

git-svn-id: svn://10.0.0.236/trunk@8124 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
dcone%netscape.com 1998-08-18 16:23:13 +00:00
parent be00ad7fad
commit 7fc549fd57
7 changed files with 230 additions and 72 deletions

Binary file not shown.

View File

@ -22,13 +22,11 @@
#define IsUserWindow(wp) (wp && ((((WindowPeek)wp)->windowKind) >= userKind))
nsWindow* nsMacMessagePump::gCurrentWindow = nsnull; // needed for exit and enter events
//-------------------------------------------------------------------------
//
// Initialize the message pump
//
//-------------------------------------------------------------------------
//==============================================================
nsMacMessagePump::nsMacMessagePump(nsMacMessenger *aTheMessageProc)
{
@ -38,47 +36,44 @@ nsMacMessagePump::nsMacMessagePump(nsMacMessenger *aTheMessageProc)
}
//-------------------------------------------------------------------------
//
// Initialize the message pump
//
//-------------------------------------------------------------------------
//==============================================================
nsMacMessagePump::~nsMacMessagePump()
{
}
//-------------------------------------------------------------------------
//
// Enter a message handler loop
//
//-------------------------------------------------------------------------
//==============================================================
PRBool
nsMacMessagePump::DoMessagePump()
{
PRBool stillrunning = PR_TRUE;
EventRecord theevent;
RgnHandle fMouseRgn=NULL;
long sleep=0;
PRInt16 haveevent;
WindowPtr whichwindow;
RgnHandle currgn;
#define SUSPENDRESUMEMESSAGE 0x01
#define MOUSEMOVEDMESSAGE 0xFA
mRunning = PR_TRUE;
mInBackground = PR_FALSE;
// calculate the regions to watch
currgn = ::NewRgn();
SetRectRgn(currgn,-32000,-32000,-32000,-32000);
while(mRunning && stillrunning)
{
haveevent = ::WaitNextEvent(everyEvent,&theevent,sleep,fMouseRgn);
haveevent = ::WaitNextEvent(everyEvent,&theevent,sleep,currgn);
if(haveevent)
{
switch(theevent.what)
{
case nullEvent:
DoIdleWidgets();
break;
case diskEvt:
if(theevent.message<0)
{
@ -95,19 +90,10 @@ WindowPtr whichwindow;
DoMouseDown(&theevent);
break;
case mouseUp:
DoMouseUp(&theevent);
break;
case updateEvt:
whichwindow = (WindowPtr)theevent.message;
if (IsUserWindow(whichwindow))
{
SetPort(whichwindow);
BeginUpdate(whichwindow);
// generate a paint event
EndUpdate(whichwindow);
}
DoPaintEvent(&theevent);
break;
case activateEvt:
whichwindow = (WindowPtr)theevent.message;
@ -130,20 +116,33 @@ WindowPtr whichwindow;
switch(evtype)
{
case MOUSEMOVEDMESSAGE:
DoMouseMove(&theevent);
break;
case SUSPENDRESUMEMESSAGE:
if(theevent.message&0x00000001)
{
// resume message
mInBackground = PR_FALSE;
}
else
{
// suspend message
mInBackground = PR_TRUE;
}
}
break;
}
}
else
{
switch(theevent.what)
{
case nullEvent:
DoIdleWidgets();
break;
}
}
if(mMessenger)
stillrunning = mMessenger->IsRunning();
}
@ -154,18 +153,50 @@ WindowPtr whichwindow;
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Handle and pass on Idle events
//
//-------------------------------------------------------------------------
//==============================================================
void
nsMacMessagePump::DoPaintEvent(EventRecord *aTheEvent)
{
WindowPtr whichwindow;
nsPaintEvent pevent;
nsWindow *thewindow;
nsRect rect;
whichwindow = (WindowPtr)aTheEvent->message;
if (IsUserWindow(whichwindow))
{
SetPort(whichwindow);
BeginUpdate(whichwindow);
thewindow = (nsWindow*)(((WindowPeek)whichwindow)->refCon);
if(thewindow != nsnull)
{
thewindow = thewindow->FindWidgetHit(aTheEvent->where);
// generate a paint event
pevent.message = NS_PAINT;
pevent.widget = thewindow;
pevent.eventStructType = NS_PAINT_EVENT;
pevent.point.x = aTheEvent->where.h;
pevent.point.y = aTheEvent->where.v;
pevent.rect = &rect;
pevent.time = 0;
thewindow->OnPaint(pevent);
}
EndUpdate(whichwindow);
}
}
//==============================================================
void
nsMacMessagePump::DoIdleWidgets()
{
WindowPtr whichwindow;
PRInt16 partcode;
nsWindow *thewindow;
nsIWidget *thewidget;
whichwindow = ::FrontWindow();
while(whichwindow)
@ -178,21 +209,17 @@ nsIWidget *thewidget;
}
//-------------------------------------------------------------------------
//
// Handle the mousedown event
//
//-------------------------------------------------------------------------
//==============================================================
void
nsMacMessagePump::DoMouseDown(EventRecord *aTheEvent)
{
WindowPtr whichwindow;
PRInt16 partcode;
nsWindow *thewindow;
nsWindow *thewidget;
Rect therect;
long newsize; // window's new size
nsMouseEvent mevent;
nsMouseEvent mouseevent;
partcode = FindWindow(aTheEvent->where,&whichwindow);
@ -212,13 +239,17 @@ nsMouseEvent mevent;
if(thewindow)
{
// mousedown inside the content region
mevent.time = 1000;
mevent.isShift = FALSE;
mevent.isControl = FALSE;
mevent.isAlt = FALSE;
mevent.clickCount = 1;
mevent.eventStructType = NS_MOUSE_EVENT;
thewindow->DispatchMouseEvent(mevent);
mouseevent.message = NS_MOUSE_LEFT_BUTTON_DOWN;
mouseevent.widget = (nsWindow *) thewindow;
mouseevent.point.x = aTheEvent->where.h;
mouseevent.point.y = aTheEvent->where.v;
mouseevent.time = 0;
mouseevent.isShift = FALSE;
mouseevent.isControl = FALSE;
mouseevent.isAlt = FALSE;
mouseevent.clickCount = 1;
mouseevent.eventStructType = NS_MOUSE_EVENT;
thewindow->DispatchMouseEvent(mouseevent);
}
break;
case inDrag:
@ -268,12 +299,123 @@ nsMouseEvent mevent;
}
}
//-------------------------------------------------------------------------
//
// Handle the key events
//
//-------------------------------------------------------------------------
void nsMacMessagePump::DoKey(EventRecord *aTheEvent)
//==============================================================
void
nsMacMessagePump::DoMouseUp(EventRecord *aTheEvent)
{
WindowPtr whichwindow;
PRInt16 partcode;
nsWindow *thewindow;
nsMouseEvent mouseevent;
partcode = FindWindow(aTheEvent->where,&whichwindow);
if(whichwindow!=0)
{
SelectWindow(whichwindow);
thewindow = (nsWindow*)(((WindowPeek)whichwindow)->refCon);
if(thewindow != nsnull)
thewindow = thewindow->FindWidgetHit(aTheEvent->where);
switch(partcode)
{
case inSysWindow:
break;
case inContent:
if(thewindow)
{
// mousedown inside the content region
mouseevent.message = NS_MOUSE_LEFT_BUTTON_UP;
mouseevent.widget = (nsWindow *) thewindow;
mouseevent.point.x = aTheEvent->where.h;
mouseevent.point.y = aTheEvent->where.v;
mouseevent.time = 0;
mouseevent.isShift = FALSE;
mouseevent.isControl = FALSE;
mouseevent.isAlt = FALSE;
mouseevent.clickCount = 1;
mouseevent.eventStructType = NS_MOUSE_EVENT;
thewindow->DispatchMouseEvent(mouseevent);
}
break;
}
}
}
//==============================================================
void
nsMacMessagePump::DoMouseMove(EventRecord *aTheEvent)
{
WindowPtr whichwindow;
PRInt16 partcode;
nsWindow *thewindow,*lastwindow;
nsMouseEvent mouseevent;
if (*(long*)&mMousePoint == *(long*)&aTheEvent->where)
return;
partcode = FindWindow(aTheEvent->where,&whichwindow);
mouseevent.point.x = aTheEvent->where.h;
mouseevent.point.y = aTheEvent->where.v;
mouseevent.time = 0;
mouseevent.isShift = FALSE;
mouseevent.isControl = FALSE;
mouseevent.isAlt = FALSE;
mouseevent.clickCount = 1;
mouseevent.eventStructType = NS_MOUSE_EVENT;
lastwindow = this->GetCurrentWindow();
mMousePoint = aTheEvent->where;
switch(partcode)
{
case inContent:
thewindow = nsnull;
if(whichwindow!=nsnull)
thewindow = (nsWindow*)(((WindowPeek)whichwindow)->refCon);
if(thewindow != nsnull)
thewindow = thewindow->FindWidgetHit(aTheEvent->where);
if(thewindow)
{
if(lastwindow == nsnull || thewindow != lastwindow)
{
// mouseenter
this->SetCurrentWindow(thewindow);
mouseevent.message = NS_MOUSE_ENTER;
mouseevent.widget = (nsWindow *) thewindow;
thewindow->DispatchMouseEvent(mouseevent);
}
else
{
// mousedown inside the content region
mouseevent.message = NS_MOUSE_MOVE;
mouseevent.widget = (nsWindow *) thewindow;
thewindow->DispatchMouseEvent(mouseevent);
}
}
break;
default:
if(lastwindow != nsnull)
{
this->SetCurrentWindow(nsnull);
mouseevent.message = NS_MOUSE_EXIT;
mouseevent.widget = (nsWindow *) lastwindow;
lastwindow->DispatchMouseEvent(mouseevent);
}
break;
}
}
//==============================================================
void
nsMacMessagePump::DoKey(EventRecord *aTheEvent)
{
char ch;
WindowPtr whichwindow;
@ -292,3 +434,5 @@ WindowPtr whichwindow;
}
}
}
//==============================================================

View File

@ -20,6 +20,7 @@
#define nsMacMessagePump_h__
#include "nsToolKit.h"
#include "nsWindow.h"
#include <Fonts.h>
#include <TextEdit.h>
#include <Dialogs.h>
@ -33,7 +34,7 @@ class nsMacMessenger
{
// CLASS MEMBERS
private:
PRBool mRunning;
PRBool mRunning;
// CLASS METHODS
private:
@ -55,8 +56,12 @@ class nsMacMessagePump
{
// CLASS MEMBERS
private:
PRBool mRunning;
nsMacMessenger *mMessenger;
PRBool mRunning;
nsMacMessenger *mMessenger;
Point mMousePoint; // keep track of where the mouse is at all times
PRBool mInBackground;
static nsWindow *gCurrentWindow;
// CLASS METHODS
private:
@ -65,10 +70,15 @@ class nsMacMessagePump
nsMacMessagePump(nsMacMessenger *aTheMessageProc);
virtual ~nsMacMessagePump();
PRBool DoMessagePump();
void DoMouseDown(EventRecord *aTheEvent);
void DoKey(EventRecord *aTheEvent);
void DoIdleWidgets();
PRBool DoMessagePump();
void DoMouseDown(EventRecord *aTheEvent);
void DoMouseUp(EventRecord *aTheEvent);
void DoMouseMove(EventRecord *aTheEvent);
void DoPaintEvent(EventRecord *aTheEvent);
void DoKey(EventRecord *aTheEvent);
void DoIdleWidgets();
void SetCurrentWindow(nsWindow *aTheWin) { gCurrentWindow = aTheWin;}
nsWindow* GetCurrentWindow(void) {return(gCurrentWindow);}
};

View File

@ -38,6 +38,7 @@ static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
//-------------------------------------------------------------------------
//
// nsWindow constructor
@ -95,7 +96,6 @@ nsWindow::~nsWindow()
mWindowRegion = nsnull;
}
//XtDestroyWidget(mWidget);
//if (nsnull != mGC) {
//::XFreeGC((Display *)GetNativeData(NS_NATIVE_DISPLAY),mGC);
@ -904,6 +904,8 @@ PRBool nsWindow::OnPaint(nsPaintEvent &event)
static NS_DEFINE_IID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID);
static NS_DEFINE_IID(kRenderingContextIID, NS_IRENDERING_CONTEXT_IID);
printf("Painting the Widget\n");
/*
if (NS_OK == NSRepository::CreateInstance(kRenderingContextCID,
nsnull,

View File

@ -51,9 +51,9 @@ public:
NS_DECL_ISUPPORTS
NS_IMETHOD QueryObject(const nsIID& aIID, void** aInstancePtr);
nsrefcnt AddRefObject(void);
nsrefcnt ReleaseObject(void);
NS_IMETHOD QueryObject(const nsIID& aIID, void** aInstancePtr);
nsrefcnt AddRefObject(void);
nsrefcnt ReleaseObject(void);
// nsIWidget interface
virtual void Create(nsIWidget *aParent,

View File

@ -18,6 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
//---- Factory Includes & Stuff -----//
#include "nsIFactory.h"
#include "nsRepository.h"
@ -97,7 +98,7 @@ char * gFailedMsg = NULL;
#define TEXT_HEIGHT 30
#endif
#define DEBUG_MOUSE 0
#define DEBUG_MOUSE 1
#define NUM_COMBOBOX_ITEMS 8
#define kSetCaret "Set Caret"
@ -819,7 +820,7 @@ void DumpRects()
*/
nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent)
{
// printf("aEvent->message %d\n", aEvent->message);
printf("aEvent->message %d\n", aEvent->message);
nsEventStatus result = nsEventStatus_eIgnore;
switch(aEvent->message) {
@ -1546,8 +1547,9 @@ nsresult WidgetTest(int *argc, char **argv)
window->Show(PR_TRUE);
window->SetCursor(eCursor_hyperlink);
#endif
if(appShell)
return(appShell->Run());
return(appShell->Run());
}