- // Check to see if it's still on
- if (!wxTimerList.Find((long)timer))
- return;
-
- if (timer->m_id == 0)
- return; // Avoid to process spurious timer events
-
- if (!timer->m_oneShot)
- timer->m_id = XtAppAddTimeOut((XtAppContext) wxTheApp->GetAppContext(),
- timer->m_milli,
- (XtTimerCallbackProc) wxTimerCallback,
- (XtPointer) timer);
- else
- timer->m_id = 0;
-
- timer->Notify();
+public:
+ wxTimerScheduler() : m_timers(NULL) {}
+
+ void QueueTimer(wxTimerDesc *desc, unsigned long when = 0);
+ void RemoveTimer(wxTimerDesc *desc);
+ void NotifyTimers();
+
+private:
+ wxTimerDesc *m_timers;
+};
+
+void wxTimerScheduler::QueueTimer(wxTimerDesc *desc, unsigned long when)
+{
+ if ( desc->running )
+ return; // already scheduled
+
+ if ( when == 0 )
+ {
+ unsigned long local = wxGetLocalTimeMillis().ToLong();
+ when = local + desc->timer->GetInterval();
+ }
+ desc->shotTime = when;
+ desc->running = TRUE;
+
+ wxLogTrace("mgl_timer", "queued timer %p at tick %i",
+ desc->timer, when);
+
+ if ( m_timers )
+ {
+ wxTimerDesc *d = m_timers;
+ while ( d->next && d->next->shotTime < when ) d = d->next;
+ desc->next = d->next;
+ desc->prev = d;
+ if ( d->next )
+ d->next->prev = desc;
+ d->next = desc;
+ }
+ else
+ {
+ m_timers = desc;
+ desc->prev = desc->next = NULL;
+ }
+}
+
+void wxTimerScheduler::RemoveTimer(wxTimerDesc *desc)
+{
+ desc->running = FALSE;
+ if ( desc == m_timers )
+ m_timers = desc->next;
+ if ( desc->prev )
+ desc->prev->next = desc->next;
+ if ( desc->next )
+ desc->next->prev = desc->prev;
+ desc->prev = desc->next = NULL;