Re-worked nsAppShell to more closely correspond to the GTK version of

nsAppShell. This caused me to have to move the PtInit call to nsToolkit,
the PtModalStart/PtModalEnd to nsWindow and the creation of the PhWidLog
to nsWidgetFactory. This is the PHOTON UI only.
This commit is contained in:
Jerry.Kirk%Nexwarecorp.com 1999-12-27 17:55:20 +00:00
parent f58f2535ae
commit 1622a83b57
10 changed files with 302 additions and 477 deletions

View File

@ -27,26 +27,18 @@
#include "nsIServiceManager.h"
#include "nsIEventQueueService.h"
#include "nsICmdLineService.h"
#include <stdlib.h>
#include "nsIWidget.h"
#include "nsIPref.h"
#include "nsPhWidgetLog.h"
#include <Pt.h>
#include <errno.h>
PRBool nsAppShell::mPtInited = PR_FALSE;
int nsAppShell::mModalCount = -1;
nsIEventQueue *kedlEQueue = nsnull;
/* Global Definitions */
int ExitMainLoop = 0;
typedef int gint; /* Need to define this for EventQueueToken */
#include <prlog.h>
PRLogModuleInfo *PhWidLog = PR_NewLogModule("PhWidLog");
#include "nsPhWidgetLog.h"
PRBool nsAppShell::gExitMainLoop = PR_FALSE;
//-------------------------------------------------------------------------
//
@ -57,109 +49,20 @@ static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static NS_DEFINE_CID(kCmdLineServiceCID, NS_COMMANDLINE_SERVICE_CID);
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
// a linked, ordered list of event queues and their tokens
class EventQueueToken {
public:
EventQueueToken(const nsIEventQueue *aQueue, const gint aToken);
const nsIEventQueue *mQueue;
gint mToken;
EventQueueToken *next;
};
EventQueueToken::EventQueueToken(const nsIEventQueue *aQueue, const gint aToken)
static int
our_photon_input_add (int fd,
PtFdProc_t event_processor_callback,
void *data)
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("EventQueueToken::EventQueueToken Constructor aQueue=<%p> aToken=<%d>\n", aQueue, aToken));
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::our_photon_input_add fd=<%d>\n", fd));
mQueue = aQueue;
mToken = aToken;
next = 0;
}
class EventQueueTokenQueue {
public:
EventQueueTokenQueue();
virtual ~EventQueueTokenQueue();
void PushToken(nsIEventQueue *aQueue, gint aToken);
PRBool PopToken(nsIEventQueue *aQueue, gint *aToken);
private:
EventQueueToken *mHead;
};
EventQueueTokenQueue::EventQueueTokenQueue()
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("EventQueueTokenQueue::EventQueueTokenQueue Constructor\n"));
mHead = 0;
}
EventQueueTokenQueue::~EventQueueTokenQueue()
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("EventQueueTokenQueue::~EventQueueTokenQueue Destructor\n"));
// if we reach this point with an empty token queue, well, fab. however,
// we expect the first event queue to still be active. so we take
// special care to unhook that queue (not that failing to do so seems
// to hurt anything). more queues than that would be an error.
//NS_ASSERTION(!mHead || !mHead->mNext, "event queue token list deleted when not empty");
// (and skip the assertion for now. we're leaking event queues because they
// are referenced by things that leak, so this assertion goes off a lot.)
if (mHead)
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("EventQueueTokenQueue::~EventQueueTokenQueue Destructor mToken=<%d>\n", mHead->mToken));
int err=PtAppRemoveFd(NULL,mHead->mToken);
if (err==-1)
{
printf ("nsAppShell::~EventQueueTokenQueue Run Error calling PtAppRemoveFd mHead->mToken=<%d> errno=<%d>\n", mHead->mToken, errno);
//abort();
}
delete mHead;
// and leak the rest. it's an error, anyway
}
}
void EventQueueTokenQueue::PushToken(nsIEventQueue *aQueue, gint aToken)
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("EventQueueTokenQueue::PushToken\n"));
EventQueueToken *newToken = new EventQueueToken(aQueue, aToken);
NS_ASSERTION(newToken, "couldn't allocate token queue element");
if (!newToken)
return NS_ERROR_OUT_OF_MEMORY;
newToken->next = mHead;
mHead = newToken;
return NS_OK;
}
PRBool EventQueueTokenQueue::PopToken(nsIEventQueue *aQueue, gint *aToken)
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("EventQueueTokenQueue::PopToken\n"));
EventQueueToken *token, *lastToken;
PRBool found = PR_FALSE;
NS_ASSERTION(mHead, "attempt to retrieve event queue token from empty queue");
if (mHead)
NS_ASSERTION(mHead->mQueue == aQueue, "retrieving event queue from past head of queue queue");
token = mHead;
lastToken = 0;
while (token && token->mQueue != aQueue) {
lastToken = token;
token = token->next;
}
if (token) {
if (lastToken)
lastToken->next = token->next;
else
mHead = token->next;
found = PR_TRUE;
*aToken = token->mToken;
delete token;
}
return found;
int err = PtAppAddFd(NULL, fd, (Pt_FD_READ | Pt_FD_NOPOLL),
event_processor_callback,data);
if (err != 0)
{
NS_ASSERTION(0,"nsAppShell::our_photon_input_add Error calling PtAppAddFD\n");
abort();
}
}
//-------------------------------------------------------------------------
@ -169,22 +72,11 @@ PRBool EventQueueTokenQueue::PopToken(nsIEventQueue *aQueue, gint *aToken)
//-------------------------------------------------------------------------
nsAppShell::nsAppShell()
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::nsAppShell Constructor\n"));
// PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::nsAppShell Constructor this=<%p>\n", this));
mEventQueue = nsnull;
mFD = -1;
NS_INIT_REFCNT();
mDispatchListener = nsnull;
mEventQueueTokens = new EventQueueTokenQueue();
// throw on error would really be civilized here
NS_ASSERTION(mEventQueueTokens, "couldn't allocate event queue token queue");
/* Run this only once per application startup */
if( !mPtInited )
{
PtInit( NULL );
PtChannelCreate(); // Force use of pulses
mPtInited = PR_TRUE;
}
}
//-------------------------------------------------------------------------
@ -194,9 +86,20 @@ nsAppShell::nsAppShell()
//-------------------------------------------------------------------------
nsAppShell::~nsAppShell()
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::~nsAppShell\n"));
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::~nsAppShell this=<%p> mFD=<%d>\n", this, mFD));
delete mEventQueueTokens;
if (mFD != -1)
{
int err=PtAppRemoveFd(NULL,mFD);
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::~nsAppShell Calling PtAppRemoveFd for mFD=<%d> err=<%d>\n", mFD, err));
if (err==-1)
{
PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsAppShell::~nsAppShell Error calling PtAppRemoveFd mFD=<%d> errno=<%d>\n", mFD, errno));
printf("nsAppShell::~EventQueueTokenQueue Run Error calling PtAppRemoveFd mFD=<%d> errno=<%d>\n", mFD, errno);
//abort();
}
}
}
@ -210,9 +113,7 @@ NS_IMPL_ISUPPORTS1(nsAppShell, nsIAppShell)
//-------------------------------------------------------------------------
NS_IMETHODIMP nsAppShell::SetDispatchListener(nsDispatchListener* aDispatchListener)
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::SetDispatchListener.\n"));
mDispatchListener = aDispatchListener;
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::SetDispatchListener. this=<%p>\n", this));
return NS_OK;
}
@ -221,12 +122,16 @@ NS_IMETHODIMP nsAppShell::SetDispatchListener(nsDispatchListener* aDispatchListe
// Enter a message handler loop
//
//-------------------------------------------------------------------------
int event_processor_callback(int fd, void *data, unsigned mode)
static int event_processor_callback(int fd, void *data, unsigned mode)
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::event_processor_callback fd=<%d> data=<%p> mode=<%d>\n", fd, data, mode));
nsIEventQueue * eventQueue = (nsIEventQueue *) data;
eventQueue->ProcessPendingEvents();
nsIEventQueue *eventQueue = (nsIEventQueue*)data;
if (eventQueue)
eventQueue->ProcessPendingEvents();
else
NS_WARNING("nsAppShell::event_processor_callback eventQueue is NULL\n");
return Pt_CONTINUE;
}
@ -271,16 +176,35 @@ NS_IMETHODIMP nsAppShell::Create(int *bac, char **bav)
//-------------------------------------------------------------------------
NS_METHOD nsAppShell::Spinup()
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::Spinup this=<%p> mModalCount=<%d>\n", this, mModalCount));
if (mModalCount != -1)
{
/* This should be -1 here... what is wrong? */
NS_ASSERTION(0,"nsAppShell::Spinup mModalCount is not -1!\n");
abort();
}
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::Spinup this=<%p>\n", this));
nsresult rv = NS_OK;
mModalCount = PtModalStart();
return NS_OK;
// Get the event queue service
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID, &rv);
if (NS_FAILED(rv)) {
NS_ASSERTION("Could not obtain event queue service", PR_FALSE);
return rv;
}
//Get the event queue for the thread.
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &mEventQueue);
// If a queue already present use it.
if (mEventQueue)
return rv;
// Create the event queue for the thread
rv = eventQService->CreateThreadEventQueue();
if (NS_OK != rv) {
NS_ASSERTION("Could not create the thread event queue", PR_FALSE);
return rv;
}
//Get the event queue for the thread
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &mEventQueue);
return rv;
}
//-------------------------------------------------------------------------
@ -290,105 +214,30 @@ NS_METHOD nsAppShell::Spinup()
//-------------------------------------------------------------------------
NS_METHOD nsAppShell::Spindown()
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::Spindown this=<%p> mModalCount=<%d>\n", this, mModalCount));
PtModalEnd( mModalCount );
mModalCount = -1;
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::Spindown this=<%p>\n", this));
if (mEventQueue)
{
mEventQueue->ProcessPendingEvents();
NS_RELEASE(mEventQueue);
}
return NS_OK;
}
#if 0
//-------------------------------------------------------------------------
//
// PushThreadEventQueue
//
//-------------------------------------------------------------------------
NS_IMETHODIMP
nsAppShell::PushThreadEventQueue()
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::PushThreadEventQueue\n"));
nsresult rv;
gint inputToken;
nsIEventQueue *eQueue;
// push a nested event queue for event processing from netlib
// onto our UI thread queue stack.
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID, &rv);
if (NS_SUCCEEDED(rv)) {
PR_Lock(mLock);
rv = eventQService->PushThreadEventQueue();
if (NS_SUCCEEDED(rv)) {
eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &eQueue);
int err;
err = PtAppAddFd(NULL,eQueue->GetEventQueueSelectFD(),Pt_FD_READ,event_processor_callback,eQueue);
if (err == -1)
{
printf("nsAppShell::PushThreadEventQueue Error calling PtAppAddFd\n");
exit(1);
}
mEventQueueTokens->PushToken(eQueue, inputToken);
}
PR_Unlock(mLock);
} else
NS_ERROR("Appshell unable to obtain eventqueue service.");
return rv;
}
//-------------------------------------------------------------------------
//
// PopThreadEventQueue
//
//-------------------------------------------------------------------------
NS_IMETHODIMP
nsAppShell::PopThreadEventQueue()
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::PopThreadEventQueue\n"));
nsresult rv;
nsIEventQueue *eQueue;
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID, &rv);
if (NS_SUCCEEDED(rv)) {
gint queueToken;
PR_Lock(mLock);
eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &eQueue);
eventQService->PopThreadEventQueue();
if (mEventQueueTokens->PopToken(eQueue, &queueToken))
{
int err;
err=PtAppRemoveFd(NULL,eQueue->GetEventQueueSelectFD());
if ( err == -1)
{
printf("nsAppShell::PopThreadEventQueue Error calling PtAppRemoveFd\n");
exit(1);
}
}
PR_Unlock(mLock);
NS_IF_RELEASE(eQueue);
} else
NS_ERROR("Appshell unable to obtain eventqueue service.");
return rv;
}
#endif
/* This routine replaces the standard PtMainLoop() for Photon */
/* We had to replace it to provide a mechanism (ExitMainLoop) to exit */
/* the loop. */
void MyMainLoop( void )
{
ExitMainLoop = 0;
while (! ExitMainLoop)
nsAppShell::gExitMainLoop = PR_FALSE;
while (! nsAppShell::gExitMainLoop)
{
PtProcessEvent();
}
NS_WARNING("MyMainLoop exiting!\n");
}
//-------------------------------------------------------------------------
@ -398,53 +247,22 @@ void MyMainLoop( void )
//-------------------------------------------------------------------------
NS_IMETHODIMP nsAppShell::Run()
{
NS_ADDREF_THIS();
nsresult rv = NS_OK;
nsIEventQueue * EQueue = nsnull;
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::Run this=<%p>\n", this));
// Get the event queue service
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID, &rv);
if (NS_FAILED(rv)) {
NS_ASSERTION("Could not obtain event queue service", PR_FALSE);
return rv;
}
if (!mEventQueue)
Spinup();
if (!mEventQueue)
return NS_ERROR_NOT_INITIALIZED;
#ifdef DEBUG
printf("Got the event queue from the service\n");
#endif /* DEBUG */
mFD = mEventQueue->GetEventQueueSelectFD();
our_photon_input_add(mFD, event_processor_callback, mEventQueue);
//Get the event queue for the thread.
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &EQueue);
MyMainLoop();
// If a queue already present use it.
if (EQueue)
goto done;
Spindown();
// Create the event queue for the thread
rv = eventQService->CreateThreadEventQueue();
if (NS_OK != rv) {
NS_ASSERTION("Could not create the thread event queue", PR_FALSE);
return rv;
}
//Get the event queue for the thread
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &EQueue);
if (NS_OK != rv) {
NS_ASSERTION("Could not obtain the thread event queue", PR_FALSE);
return rv;
}
done:
// (has to be called explicitly for this, the primordial appshell, because
// of startup ordering problems.)
ListenToEventQueue(EQueue, PR_TRUE);
MyMainLoop(); /* PtMainLoop() */
NS_IF_RELEASE(EQueue);
Release();
return NS_OK;
return NS_OK;
}
//-------------------------------------------------------------------------
@ -457,7 +275,7 @@ NS_METHOD nsAppShell::Exit()
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::Exit.\n"));
NS_WARNING("nsAppShell::Exit Called...\n");
ExitMainLoop = 1;
gExitMainLoop = PR_TRUE;
return NS_OK;
}
@ -465,100 +283,31 @@ NS_METHOD nsAppShell::Exit()
NS_METHOD nsAppShell::GetNativeEvent(PRBool &aRealEvent, void *&aEvent)
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::GetNativeEvent\n"));
nsresult res = NS_ERROR_FAILURE;
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::GetNativeEvent this=<%p>\n", this));
aEvent = NULL;
aRealEvent = PR_FALSE;
#if 0
const int EVENT_SIZE = sizeof(struct PhEvent_t) + 1000;
PhEvent_t *event = NULL;
event = PR_Malloc(EVENT_SIZE);
if (NULL != event)
{
int status;
status = PhEventPeek(event, EVENT_SIZE);
if (status == Ph_EVENT_MSG)
{
aRealEvent = PR_TRUE;
aEvent = event;
res = NS_OK;
}
else
{
PtProcessEvent();
res = NS_OK;
}
}
else
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::GetNativeEvent out of memory\n"));
NS_ASSERTION(event, "couldn't allocate a Photon event");
}
#else
PtProcessEvent();
res = NS_OK;
#endif
return res;
return NS_OK;
}
NS_METHOD nsAppShell::DispatchNativeEvent(PRBool aRealEvent, void * aEvent)
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::DispatchNativeEvent aRealEvent=<%d> aEvent=<%p>\n", aRealEvent, aEvent));
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::DispatchNativeEvent aRealEvent=<%d> aEvent=<%p> mEventQueue=<%p>\n", aRealEvent, aEvent, mEventQueue));
int err;
if ( aRealEvent == PR_TRUE )
{
err = PtEventHandler( (PhEvent_t*) aEvent );
if (err == -1)
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::DispatchNativeEvent aEvent=<%p> error=<%d>\n", aEvent, err));
return NS_ERROR_FAILURE;
}
}
return NS_OK;
if (!mEventQueue)
return NS_ERROR_NOT_INITIALIZED;
PtProcessEvent();
return mEventQueue->ProcessPendingEvents();
}
NS_IMETHODIMP nsAppShell::ListenToEventQueue(nsIEventQueue *aQueue,
PRBool aListen)
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::ListenToEventQueue\n"));
gint queueToken;
int err;
if (aListen)
{
err = PtAppAddFd(NULL,aQueue->GetEventQueueSelectFD(),Pt_FD_READ,
event_processor_callback,aQueue);
if (err == -1)
{
printf("nsAppShell::ListenToEventQueue Error calling PtAppAddFd errno=<%d>\n", errno);
if (errno != EBUSY)
abort();
}
mEventQueueTokens->PushToken(aQueue, queueToken);
}
else
{
if (mEventQueueTokens->PopToken(aQueue, &queueToken))
{
err=PtAppRemoveFd(NULL,aQueue->GetEventQueueSelectFD());
if (err == -1)
{
printf ("nsAppShell:: Run Error calling PtAppRemoveFd\n");
abort();
}
}
}
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::ListenToEventQueue aQueue=<%p> aListen=<%d>\n", aQueue, aListen));
return NS_OK;
}

View File

@ -24,48 +24,28 @@
#define nsAppShell_h__
#include "nsIAppShell.h"
#include "nsIEventQueue.h"
#include <Pt.h>
/**
* Native Photon Application shell wrapper
*/
class nsIEventQueueService;
class EventQueueTokenQueue;
class nsAppShell : public nsIAppShell
{
public:
nsAppShell();
virtual ~nsAppShell();
public:
nsAppShell();
virtual ~nsAppShell();
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS
NS_DECL_NSIAPPSHELL
PRBool OnPaint();
// nsIAppShellInterface
NS_IMETHOD Create(int* argc, char ** argv);
virtual nsresult Run();
NS_IMETHOD Spinup();
NS_IMETHOD Spindown();
NS_IMETHOD ListenToEventQueue(nsIEventQueue *aQueue, PRBool aListen);
NS_IMETHOD GetNativeEvent(PRBool &aRealEvent, void *&aEvent);
NS_IMETHOD DispatchNativeEvent(PRBool aRealEvent, void * aEvent);
NS_IMETHOD Exit();
NS_IMETHOD SetDispatchListener(nsDispatchListener* aDispatchListener);
public:
static PRBool gExitMainLoop;
private:
nsDispatchListener *mDispatchListener;
EventQueueTokenQueue *mEventQueueTokens;
static PRBool mPtInited;
static int mModalCount;
// unsigned long mEventBufferSz;
// PhEvent_t *mEvent;
// nsIEventQueueService * mEventQService;
// PRLock *mLock;
nsIEventQueue* mEventQueue;
int mFD;
};

View File

@ -77,10 +77,10 @@ NS_IMETHODIMP nsDragService::StartDragSession()
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsDragService::StartDragSession this=<%p>\n", this));
NS_WARNING("nsDragService::StartDragSession()\n");
NS_WARNING("nsDragService::StartDragSession() - Not Supported Yet");
nsBaseDragService::StartDragSession();
return NS_OK;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsDragService::EndDragSession()
@ -92,7 +92,7 @@ NS_IMETHODIMP nsDragService::EndDragSession()
//gtk_drag_source_unset(mWidget);
return NS_OK;
return NS_ERROR_FAILURE;
}

View File

@ -26,7 +26,8 @@
#include "nsPhWidgetLog.h"
/* Set our static member to NULL */
PhDrawContext_t * nsToolkit::mDefaultPhotonDrawContext = nsnull;
PhDrawContext_t *nsToolkit::mDefaultPhotonDrawContext = nsnull;
PRBool nsToolkit::mPtInited = PR_FALSE;
NS_IMPL_ISUPPORTS1(nsToolkit,nsIToolkit);
@ -37,14 +38,9 @@ NS_IMPL_ISUPPORTS1(nsToolkit,nsIToolkit);
//-------------------------------------------------------------------------
nsToolkit::nsToolkit()
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsToolkit::nsToolkit this=<%p>\n", this));
// PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsToolkit::nsToolkit this=<%p>\n", this));
NS_INIT_REFCNT();
if (mDefaultPhotonDrawContext == nsnull)
{
mDefaultPhotonDrawContext = PhDCGetCurrent();
}
}
@ -55,7 +51,7 @@ nsToolkit::nsToolkit()
//-------------------------------------------------------------------------
nsToolkit::~nsToolkit()
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsToolkit::~nsToolkit this=<%p>\n", this));
// PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsToolkit::~nsToolkit this=<%p>\n", this));
}
@ -65,6 +61,19 @@ nsToolkit::~nsToolkit()
//-------------------------------------------------------------------------
NS_METHOD nsToolkit::Init(PRThread *aThread)
{
/* Run this only once per application startup */
if( !mPtInited )
{
PtInit( NULL );
PtChannelCreate(); // Force use of pulses
mPtInited = PR_TRUE;
}
if (mDefaultPhotonDrawContext == nsnull)
{
mDefaultPhotonDrawContext = PhDCGetCurrent();
}
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsToolkit::Init this=<%p> aThread=<%p>\n", this, aThread));
return NS_OK;
}

View File

@ -40,8 +40,8 @@ public:
static PhDrawContext_t *GetDefaultPhotonDrawContext();
private:
static PhDrawContext_t *mDefaultPhotonDrawContext;
static PRBool mPtInited;
static PhDrawContext_t *mDefaultPhotonDrawContext;
};

View File

@ -334,20 +334,6 @@ NS_IMETHODIMP nsWidget::CaptureRollupEvents(nsIRollupListener * aListener, PRBoo
return NS_OK;
}
NS_IMETHODIMP nsWidget::SetModal(PRBool aModal)
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::SetModal - Not Implemented\n"));
if (!mWidget)
return NS_ERROR_FAILURE;
PtWidget_t *toplevel = PtFindDisjoint(mWidget);
if (!toplevel)
return NS_ERROR_FAILURE;
return NS_OK;
}
NS_METHOD nsWidget::IsVisible(PRBool &aState)
{
if( mWidget )
@ -1128,6 +1114,13 @@ NS_METHOD nsWidget::SetMenuBar(nsIMenuBar * aMenuBar)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsWidget::SetModal(PRBool aModal)
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::SetModal - Not Implemented\n"));
return NS_ERROR_FAILURE;
}
NS_METHOD nsWidget::ShowMenuBar( PRBool aShow)
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::ShowMenuBar aShow=<%d> - Not Implemented.\n",aShow));
@ -1723,7 +1716,7 @@ void nsWidget::InitKeyEvent(PhKeyEvent_t *aPhKeyEvent,
anEvent.keyCode = 0; /* I think the spec says this should be 0 */
printf("nsWidget::InitKeyEvent charCode=<%d>\n", anEvent.charCode);
if (anEvent.isControl)
if ((anEvent.isControl) || (anEvent.isAlt))
{
anEvent.charCode = aPhKeyEvent->key_cap;
}
@ -1830,7 +1823,8 @@ PRBool nsWidget::DispatchKeyEvent(PhKeyEvent_t *aPhKeyEvent)
//-------------------------------------------------------------------------
int nsWidget::RawEventHandler( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo )
{
//printf ("kedl: nswidget raweventhandler\n");
//PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::RawEventHandler raweventhandler widget=<%p> this=<%p> IsFocused=<%d>\n", widget, data, PtIsFocused(widget)));
//printf("nsWidget::RawEventHandler raweventhandler widget=<%p> this=<%p> IsFocused=<%d>\n", widget, data, PtIsFocused(widget));
// Get the window which caused the event and ask it to process the message
nsWidget *someWidget = (nsWidget*) data;
@ -1849,6 +1843,7 @@ int nsWidget::RawEventHandler( PtWidget_t *widget, void *data, PtCallbackInfo_t
PRBool nsWidget::HandleEvent( PtCallbackInfo_t* aCbInfo )
{
PRBool result = PR_FALSE; // call the default nsWindow proc
int err;
PhEvent_t* event = aCbInfo->event;
switch ( event->type )
@ -1861,17 +1856,98 @@ PRBool nsWidget::HandleEvent( PtCallbackInfo_t* aCbInfo )
}
break;
case Ph_EV_PTR_MOTION_BUTTON:
case Ph_EV_DRAG:
{
PhDragEvent_t* ptrev = (PhDragEvent_t*) PhGetData( event );
nsMouseEvent theMouseEvent;
//printf("nsWidget::HandleEvent Ph_EV_DRAG subtype=<%d> flags=<%d>\n", event->subtype, ptrev->flags );
switch(event->subtype)
{
case Ph_EV_DRAG_BOUNDARY:
printf("nsWidget::HandleEvent Ph_EV_DRAG_BOUNDARY\n");
break;
case Ph_EV_DRAG_COMPLETE:
{
nsMouseEvent theMouseEvent;
PhPointerEvent_t* ptrev2 = (PhPointerEvent_t*) PhGetData( event );
printf("nsWidget::HandleEvent Ph_EV_DRAG_COMPLETE\n");
ScreenToWidget( ptrev2->pos );
InitMouseEvent(ptrev2, this, theMouseEvent, NS_MOUSE_LEFT_BUTTON_UP );
result = DispatchMouseEvent(theMouseEvent);
}
break;
case Ph_EV_DRAG_INIT:
printf("nsWidget::HandleEvent Ph_EV_DRAG_INIT\n");
break;
case Ph_EV_DRAG_KEY_EVENT:
printf("nsWidget::HandleEvent Ph_EV_DRAG_KEY_EVENT\n");
break;
case Ph_EV_DRAG_MOTION_EVENT:
{
PhPointerEvent_t* ptrev2 = (PhPointerEvent_t*) PhGetData( event );
ScreenToWidget( ptrev2->pos );
printf("nsWidget::HandleEvent Ph_EV_DRAG_MOTION_EVENT pos=(%d,%d)\n", ptrev2->pos.x,ptrev2->pos.y );
InitMouseEvent(ptrev2, this, theMouseEvent, NS_MOUSE_MOVE );
result = DispatchMouseEvent(theMouseEvent);
}
break;
case Ph_EV_DRAG_MOVE:
printf("nsWidget::HandleEvent Ph_EV_DRAG_BOUNDARY\n");
break;
case Ph_EV_DRAG_START:
printf("nsWidget::HandleEvent Ph_EV_DRAG_START\n");
break;
}
}
break;
case Ph_EV_PTR_MOTION_BUTTON:
{
PhPointerEvent_t* ptrev = (PhPointerEvent_t*) PhGetData( event );
nsMouseEvent theMouseEvent;
//printf("nsWidget::HandleEvent Ph_EV_PTR_MOTION_BUTTON\n");
if( ptrev->buttons & Ph_BUTTON_SELECT ) // Normally the left mouse button
{
/* Initiate a PhInitDrag() */
/* I am not sure what rect and boundary should be but this works */
PhRect_t rect = {0,0,0,0};
PhRect_t boundary = {0,0,640,480};
err=PhInitDrag( PtWidgetRid(mWidget), ( Ph_DRAG_KEY_MOTION | Ph_DRAG_TRACK ),&rect, &boundary, aCbInfo->event->input_group , NULL, NULL, NULL);
if (err==-1)
{
NS_WARNING("nsWidget::HandleEvent PhInitDrag Failed!\n");
result = NS_ERROR_FAILURE;
}
}
if( ptrev )
{
ScreenToWidget( ptrev->pos );
//printf("nsWidget::HandleEvent Ph_EV_PTR_MOTION_BUTTON pos=(%d,%d)\n", ptrev->pos.x,ptrev->pos.y );
InitMouseEvent(ptrev, this, theMouseEvent, NS_MOUSE_MOVE );
result = DispatchMouseEvent(theMouseEvent);
}
}
break;
case Ph_EV_PTR_MOTION_NOBUTTON:
{
PhPointerEvent_t* ptrev = (PhPointerEvent_t*) PhGetData( event );
nsMouseEvent theMouseEvent;
//printf("nsWidget::HandleEvent Ph_EV_PTR_MOTION_NOBUTTON\n");
if( ptrev )
{
ScreenToWidget( ptrev->pos );
//printf("nsWidget::HandleEvent Ph_EV_PTR_MOTION_NOBUTTON pos=(%d,%d)\n", ptrev->pos.x,ptrev->pos.y );
InitMouseEvent(ptrev, this, theMouseEvent, NS_MOUSE_MOVE );
//result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_MOVE );
result = DispatchMouseEvent(theMouseEvent);
}
}
@ -1882,22 +1958,26 @@ PRBool nsWidget::HandleEvent( PtCallbackInfo_t* aCbInfo )
PhPointerEvent_t* ptrev = (PhPointerEvent_t*) PhGetData( event );
nsMouseEvent theMouseEvent;
printf("nsWidget::HandleEvent Ph_EV_BUT_PRESS this=<%p>\n", this);
if (gRollupWidget && gRollupListener)
{
PtWidget_t *rollupWidget = gRollupWidget->GetNativeData(NS_NATIVE_WIDGET);
PtWidget_t *thisWidget = GetNativeData(NS_NATIVE_WIDGET);
printf("nsWidget::HandleEvent Ph_EV_BUT_PRESS rollupWidget=%p thisWidget=%p\n", rollupWidget, thisWidget);
printf("nsWidget::HandleEvent Ph_EV_BUT_PRESS PtFindDisjoint(thisWidget)=%p\n", PtFindDisjoint(thisWidget));
if (rollupWidget != thisWidget && PtFindDisjoint(thisWidget) != rollupWidget)
{
gRollupListener->Rollup();
return;
}
}
if( ptrev )
{
printf( "nsWidget::HandleEvent Window mouse click: (%ld,%ld)\n", ptrev->pos.x, ptrev->pos.y );
//printf( "nsWidget::HandleEvent Window mouse click: (%ld,%ld) mWidget=<%p>\n", ptrev->pos.x, ptrev->pos.y, mWidget );
ScreenToWidget( ptrev->pos );
if( ptrev->buttons & Ph_BUTTON_SELECT ) // Normally the left mouse button
@ -1916,7 +1996,7 @@ PRBool nsWidget::HandleEvent( PtCallbackInfo_t* aCbInfo )
result = DispatchMouseEvent(theMouseEvent);
}
}
break;
break;
case Ph_EV_BUT_RELEASE:
{
@ -2363,34 +2443,38 @@ PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::WorkProc damaging widget=<%p> mUpdate
return Pt_END;
}
int nsWidget::GotFocusCallback( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo )
{
nsWidget *pWidget = (nsWidget *) data;
if ((widget->parent) && (PtIsFocused(widget) != 2))
if (widget->parent)
printf("nsWidget::GotFocusCallback widget->parent=<%p> PtIsFocused(widget)=<%d>\n", widget->parent, PtIsFocused(widget));
else
printf("nsWidget::GotFocusCallback widget->parent=<%p>\n", widget->parent);
if ((!widget->parent) || (PtIsFocused(widget) != 2))
{
printf("nsWidget::GetFocusCallback Not on focus leaf! PtIsFocused(mWidget)=<%d>\n", PtIsFocused(widget));
//printf("nsWidget::GotFocusCallback widget->parent=<%p>\n", widget->parent);
return Pt_CONTINUE;
}
PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsWidget::GetFocusCallback pWidget=<%p>\n", pWidget));
PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsWidget::GotFocusCallback pWidget=<%p>\n", pWidget));
pWidget->DispatchStandardEvent(NS_GOTFOCUS);
return Pt_CONTINUE;
}
int nsWidget::LostFocusCallback( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo )
{
nsWidget *pWidget = (nsWidget *) data;
if ((widget->parent) && (PtIsFocused(widget) != 2))
{
PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsWidget::GetFocusCallback Not on focus leaf! PtIsFocused(mWidget)=<%d>\n", PtIsFocused(widget)));
printf("nsWidget::GetFocusCallback Not on focus leaf! PtIsFocused(mWidget)=<%d>\n", PtIsFocused(widget));
PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsWidget::LostFocusCallback Not on focus leaf! PtIsFocused(mWidget)=<%d>\n", PtIsFocused(widget)));
printf("nsWidget::LostFocusCallback Not on focus leaf! PtIsFocused(mWidget)=<%d>\n", PtIsFocused(widget));
return Pt_CONTINUE;
}

View File

@ -76,10 +76,10 @@ class nsWidget : public nsBaseWidget
NS_IMETHOD Destroy(void);
nsIWidget* GetParent(void);
NS_IMETHOD SetModal(PRBool aModal);
NS_IMETHOD Show(PRBool state);
NS_IMETHOD CaptureRollupEvents(nsIRollupListener *aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent);
NS_IMETHOD IsVisible(PRBool &aState);
NS_IMETHOD SetModal(PRBool aModal);
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
NS_IMETHOD Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint);

View File

@ -63,6 +63,8 @@
#include "nsXIFFormatConverter.h"
#include "nsDragService.h"
#include <prlog.h>
struct PRLogModuleInfo *PhWidLog = nsnull;
#include "nsPhWidgetLog.h"
static NS_DEFINE_IID(kCWindow, NS_WINDOW_CID);
@ -133,6 +135,12 @@ nsWidgetFactory::nsWidgetFactory(const nsCID &aClass)
{
NS_INIT_REFCNT();
mClassID = aClass;
if (!PhWidLog)
{
PhWidLog = PR_NewLogModule("PhWidLog");
}
PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsWidgetFactory::nsWidgetFactory Constructor Called\n"));
}

View File

@ -44,9 +44,10 @@
#include "nsIMenuItem.h"
#include "nsIMenuListener.h"
PRBool nsWindow::mResizeQueueInited = PR_FALSE;
PRBool nsWindow::mResizeQueueInited = PR_FALSE;
DamageQueueEntry *nsWindow::mResizeQueue = nsnull;
PtWorkProcId_t *nsWindow::mResizeProcID = nsnull;
int nsWindow::mModalCount = -1;
//-------------------------------------------------------------------------
//
@ -514,7 +515,7 @@ NS_METHOD nsWindow::CreateNative(PtWidget_t *parentWidget)
PtAddCallback(mWidget, Pt_CB_RESIZE, ResizeHandler, nsnull );
PtAddEventHandler( mWidget,
Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON |
Ph_EV_BUT_PRESS | Ph_EV_BUT_RELEASE |Ph_EV_BOUNDARY
Ph_EV_BUT_PRESS | Ph_EV_BUT_RELEASE |Ph_EV_BOUNDARY|Ph_EV_DRAG
// | Ph_EV_WM
// | Ph_EV_EXPOSE
, RawEventHandler, this );
@ -1896,52 +1897,8 @@ NS_METHOD nsWindow::ModalEventFilter(PRBool aRealEvent, void *aEvent,
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::ModalEventFilter aEvent=<%p> - Not Implemented.\n", aEvent));
#if 1
*aForWindow = PR_FALSE;
*aForWindow = PR_TRUE;
return NS_OK;
#else
PRBool isInWindow, isMouseEvent;
PhEvent_t *msg = (PhEvent_t *) aEvent;
if (aRealEvent == PR_FALSE)
{
*aForWindow = PR_FALSE;
return NS_OK;
}
isInWindow = PR_FALSE;
// Get native window
PtWidget_t *win;
win = (PtWidget_t *)GetNativeData(NS_NATIVE_WINDOW);
PtWidget_t *eWin = (PtWidget_t *) msg->collector.handle;
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::ModalEventFilter win=<%p> eWin=<%p>\n",win, eWin));
if (nsnull != eWin) {
if (win == eWin) {
isInWindow = PR_TRUE;
}
}
switch(msg->type)
{
case Ph_EV_BUT_PRESS:
case Ph_EV_BUT_RELEASE:
case Ph_EV_BUT_REPEAT:
case Ph_EV_PTR_MOTION_BUTTON:
case Ph_EV_PTR_MOTION_NOBUTTON:
isMouseEvent = PR_TRUE;
break;
default:
isMouseEvent = PR_FALSE;
break;
}
*aForWindow = isInWindow == PR_TRUE || isMouseEvent == PR_FALSE ? PR_TRUE : PR_FALSE;
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::ModalEventFilter isInWindow=<%d> isMouseEvent=<%d> aForWindow=<%d>\n", isInWindow, isMouseEvent, *aForWindow));
return NS_OK;
#endif
}
int nsWindow::MenuRegionCallback( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo)
@ -1980,11 +1937,11 @@ int nsWindow::MenuRegionCallback( PtWidget_t *widget, ApInfo_t *apinfo, PtCallba
return (Pt_CONTINUE);
}
NS_METHOD nsWindow::Flash()
NS_METHOD nsWindow::GetAttention()
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow:Flash this=(%p)\n", this ));
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::GetAttention this=(%p)\n", this ));
NS_WARNING("nsWindow:Flash Called...\n");
NS_WARNING("nsWindow::GetAttention Called...\n");
if ((mWidget) && (mWidget->parent) && (!PtIsFocused(mWidget)))
{
@ -1995,3 +1952,39 @@ NS_METHOD nsWindow::Flash()
return NS_OK;
}
NS_IMETHODIMP nsWindow::SetModal(PRBool aModal)
{
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::SetModal this=<%p> mModalCount=<%d> mWidget=<%p>\n", this, mModalCount, mWidget));
nsresult res = NS_ERROR_FAILURE;
if (!mWidget)
return NS_ERROR_FAILURE;
PtWidget_t *toplevel = PtFindDisjoint(mWidget);
if (!toplevel)
return NS_ERROR_FAILURE;
if (aModal)
{
if (mModalCount != -1)
{
NS_ASSERTION(0, "nsWindow::SetModalAlready have a Modal Window, Can't have 2");
}
else
{
mModalCount = PtModalStart();
res = NS_OK;
}
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::SetModal after call to PtModalStart mModalCount=<%d>\n", mModalCount));
}
else
{
PtModalEnd( mModalCount );
mModalCount = -1;
res = NS_OK;
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::SetModal after call to PtModalEnd mModalCount=<%d>\n", mModalCount));
}
return res;
}

View File

@ -73,11 +73,12 @@ public:
NS_IMETHOD RemoveTooltips();
NS_IMETHOD BeginResizingChildren(void);
NS_IMETHOD EndResizingChildren(void);
virtual PRBool IsChild() { return(PR_FALSE); };
virtual void SetIsDestroying( PRBool val) { mIsDestroying = val; };
virtual int GetMenuBarHeight();
virtual PRBool IsChild() { return(PR_FALSE); };
virtual void SetIsDestroying( PRBool val) { mIsDestroying = val; };
virtual int GetMenuBarHeight();
NS_IMETHOD Destroy(void);
NS_IMETHOD Flash(void);
NS_IMETHOD GetAttention(void);
NS_IMETHOD SetModal(PRBool aModal);
/* Add this because of bug 11088 */
virtual NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
@ -121,6 +122,7 @@ protected:
// nsWindowType mWindowType;
// nsBorderStyle mBorderStyle;
static PRBool mResizeQueueInited;
static int mModalCount;
PRBool mIsResizing;
nsFont *mFont;
nsIMenuBar *mMenuBar;