Commits (2)
......@@ -556,7 +556,7 @@ static int hook_loop()
{
if (gApplication::mustQuit())
break;
if (CWINDOW_must_quit() && CWatcher::count() == 0 && gTrayIcon::visibleCount() == 0)
if (CWINDOW_must_quit() && CWatcher::count() == 0 && gTrayIcon::visibleCount() == 0 && !GB.HasActiveTimer())
break;
_must_check_quit = false;
}
......
......@@ -570,7 +570,7 @@ static int hook_loop()
{
if (gApplication::mustQuit())
break;
if (CWINDOW_must_quit() && CWatcher::count() == 0 && gTrayIcon::visibleCount() == 0)
if (CWINDOW_must_quit() && CWatcher::count() == 0 && gTrayIcon::visibleCount() == 0 && !GB.HasActiveTimer())
break;
_must_check_quit = false;
}
......
......@@ -842,7 +842,7 @@ static bool must_quit(void)
#if DEBUG_WINDOW
qDebug("must_quit: Window = %d Watch = %d in_event_loop = %d MAIN_in_message_box = %d _prevent_quit = %d", CWindow::count, CWatch::count, in_event_loop, MAIN_in_message_box, _prevent_quit);
#endif
return CWINDOW_must_quit() && CWatch::count == 0 && in_event_loop && MAIN_in_message_box == 0 && _prevent_quit == 0;
return CWINDOW_must_quit() && CWatch::count == 0 && in_event_loop && MAIN_in_message_box == 0 && _prevent_quit == 0 && !GB.HasActiveTimer();
}
static void check_quit_now(intptr_t param)
......
......@@ -578,7 +578,7 @@ static bool must_quit(void)
#if DEBUG_WINDOW
qDebug("must_quit: Window = %d Watch = %d in_event_loop = %d MAIN_in_message_box = %d _prevent_quit = %d", CWindow::count, CWatch::count, in_event_loop, MAIN_in_message_box, _prevent_quit);
#endif
return CWINDOW_must_quit() && CWatch::count == 0 && in_event_loop && MAIN_in_message_box == 0 && _prevent_quit == 0;
return CWINDOW_must_quit() && CWatch::count == 0 && in_event_loop && MAIN_in_message_box == 0 && _prevent_quit == 0 && !GB.HasActiveTimer();
}
static void check_quit_now(intptr_t param)
......
......@@ -108,6 +108,7 @@ const void *const GAMBAS_Api[] =
(void *)GB_GetEvent,
(void *)GB_GetLastEventName,
(void *)CTIMER_raise,
(void *)GB_HasActiveTimer,
(void *)GB_Stopped,
(void *)GB_IsRaiseLocked,
......@@ -458,6 +459,12 @@ void *GB_Hook(int type, void *hook)
}
bool GB_HasActiveTimer(void)
{
return CTIMER_active_count > 0;
}
bool GB_LoadComponent(const char *name)
{
CATCH_ERROR
......
......@@ -46,6 +46,7 @@ int GB_GetEvent(void *class, char *name);
char *GB_GetLastEventName(void);
bool GB_Stopped(void);
bool GB_IsRaiseLocked(void *object);
bool GB_HasActiveTimer(void);
int GB_NParam(void);
const char *GB_GetUnknown(void);
......
......@@ -36,18 +36,26 @@
#define EXT(_ob) ((CTIMER_EXT *)((CTIMER *)_ob)->ext)
int CTIMER_active_count = 0;
DECLARE_EVENT(EVENT_Timer);
static void enable_timer(CTIMER *_object, bool on)
{
if (on != (THIS->id != 0))
HOOK_DEFAULT(timer, WATCH_timer)((GB_TIMER *)THIS, on);
if (on == (THIS->id != 0))
return;
HOOK_DEFAULT(timer, WATCH_timer)((GB_TIMER *)THIS, on);
if (on && (THIS->id == 0))
GB_Error("Too many active timers");
CTIMER_active_count += on ? 1 : -1;
}
CTIMER *CTIMER_every(int delay, GB_TIMER_CALLBACK callback, intptr_t param)
{
CTIMER *timer;
......@@ -67,6 +75,7 @@ CTIMER *CTIMER_every(int delay, GB_TIMER_CALLBACK callback, intptr_t param)
return timer;
}
void CTIMER_raise(void *_object)
{
if (THIS->task == EXEC_task)
......@@ -106,8 +115,7 @@ END_METHOD
BEGIN_METHOD_VOID(Timer_free)
if (THIS->id)
HOOK_DEFAULT(timer, WATCH_timer)((GB_TIMER *)THIS, FALSE);
enable_timer(THIS, FALSE);
if (THIS->ext)
IFREE(THIS->ext);
......
......@@ -38,7 +38,11 @@ typedef
typedef GB_TIMER CTIMER;
#ifndef __GBX_C_TIMER_C
extern GB_DESC NATIVE_Timer[];
extern int CTIMER_active_count;
#else
#define THIS ((CTIMER *)_object)
......
......@@ -999,6 +999,7 @@ typedef
int (*GetEvent)(GB_CLASS, const char *);
char *(*GetLastEventName)(void);
void (*RaiseTimer)(void *);
bool (*HasActiveTimer)(void);
bool (*Stopped)(void);
bool (*IsRaiseLocked)(void *);
......