mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-05 13:45:46 +00:00
Added a real timer implementation for Motif
This commit is contained in:
parent
860e5e5305
commit
084e77f7b7
@ -21,11 +21,17 @@
|
||||
#include "prlog.h"
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include "Xm/Xm.h"
|
||||
|
||||
static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID);
|
||||
|
||||
// Hack for now. This is Bad because it creates a dependency between the widget
|
||||
// library and this library. This needs to be replaced with having code
|
||||
// to pass an interface which can be queried for the app context.
|
||||
extern XtAppContext gAppContext;
|
||||
|
||||
/*
|
||||
* Implementation of timers lifted from Windows front-end file timer.cpp
|
||||
* Implementation of timers using Xt timer facility
|
||||
*/
|
||||
class TimerImpl : public nsITimer {
|
||||
public:
|
||||
@ -47,7 +53,9 @@ public:
|
||||
|
||||
virtual void Cancel();
|
||||
virtual PRUint32 GetDelay() { return mDelay; }
|
||||
virtual void SetDelay(PRUint32 aDelay) { };
|
||||
virtual void SetDelay(PRUint32 aDelay) { mDelay=aDelay; };
|
||||
|
||||
void FireTimeout();
|
||||
|
||||
private:
|
||||
nsresult Init(PRUint32 aDelay);
|
||||
@ -58,9 +66,24 @@ private:
|
||||
nsITimerCallback *mCallback;
|
||||
// PRBool mRepeat;
|
||||
TimerImpl *mNext;
|
||||
XtIntervalId mTimerId;
|
||||
};
|
||||
|
||||
//TimerImpl *TimerImpl::gTimerList = NULL;
|
||||
void TimerImpl::FireTimeout()
|
||||
{
|
||||
if (mFunc != NULL) {
|
||||
(*mFunc)(this, mClosure);
|
||||
}
|
||||
else if (mCallback != NULL) {
|
||||
mCallback->Notify(this); // Fire the timer
|
||||
}
|
||||
}
|
||||
|
||||
void nsTimerExpired(XtPointer aCallData)
|
||||
{
|
||||
TimerImpl* timer = (TimerImpl *)aCallData;
|
||||
timer->FireTimeout();
|
||||
}
|
||||
|
||||
|
||||
TimerImpl::TimerImpl()
|
||||
@ -69,6 +92,7 @@ TimerImpl::TimerImpl()
|
||||
mFunc = NULL;
|
||||
mCallback = NULL;
|
||||
mNext = NULL;
|
||||
mTimerId = 0;
|
||||
}
|
||||
|
||||
TimerImpl::~TimerImpl()
|
||||
@ -85,6 +109,8 @@ TimerImpl::Init(nsTimerCallbackFunc aFunc,
|
||||
mClosure = aClosure;
|
||||
// mRepeat = aRepeat;
|
||||
|
||||
mTimerId = XtAppAddTimeOut(gAppContext, aDelay,(XtTimerCallbackProc)nsTimerExpired, this);
|
||||
|
||||
return Init(aDelay);
|
||||
}
|
||||
|
||||
@ -96,6 +122,8 @@ TimerImpl::Init(nsITimerCallback *aCallback,
|
||||
mCallback = aCallback;
|
||||
// mRepeat = aRepeat;
|
||||
|
||||
mTimerId = XtAppAddTimeOut(gAppContext, aDelay, (XtTimerCallbackProc)nsTimerExpired, this);
|
||||
|
||||
return Init(aDelay);
|
||||
}
|
||||
|
||||
@ -114,7 +142,7 @@ NS_IMPL_ISUPPORTS(TimerImpl, kITimerIID)
|
||||
void
|
||||
TimerImpl::Cancel()
|
||||
{
|
||||
|
||||
XtRemoveTimeOut(mTimerId);
|
||||
}
|
||||
|
||||
NS_BASE nsresult NS_NewTimer(nsITimer** aInstancePtrResult)
|
||||
|
Loading…
x
Reference in New Issue
Block a user