tSupport for GTK+ timeouts added to Windows port - vaccinewars - be a doctor and try to vaccinate the world
 (HTM) git clone git://src.adamsgaard.dk/vaccinewars
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit e40abf49838d86a57c90f8bb5bd384b6e2a982b8
 (DIR) parent 84b3f77040b303ad27ecafea95e0fe6a5b48dcb7
 (HTM) Author: Ben Webb <ben@salilab.org>
       Date:   Tue, 10 Apr 2001 13:19:21 +0000
       
       Support for GTK+ timeouts added to Windows port
       
       
       Diffstat:
         M src/gtkport.c                       |      75 +++++++++++++++++++++++++++++++
         M src/gtkport.h                       |       3 +++
       
       2 files changed, 78 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/src/gtkport.c b/src/gtkport.c
       t@@ -242,6 +242,15 @@ struct _GdkInput {
           gpointer data;
        };
        
       +typedef struct _GtkTimeout GtkTimeout;
       +
       +struct _GtkTimeout {
       +   guint32 interval;
       +   GtkFunction function;
       +   gpointer data;
       +   guint id;
       +};
       +
        typedef struct _GtkItemFactoryChild GtkItemFactoryChild;
        
        struct _GtkItemFactoryChild {
       t@@ -621,6 +630,7 @@ static HINSTANCE hInst;
        static HFONT hFont;
        static GSList *WindowList=NULL;
        static GSList *GdkInputs=NULL;
       +static GSList *GtkTimeouts=NULL;
        static HWND TopLevel=NULL;
        long AsyncSocketError=0;
        
       t@@ -652,6 +662,22 @@ static void DispatchSocketEvent(SOCKET sock,long event) {
           }
        }
        
       +static void DispatchTimeoutEvent(UINT id) {
       +   GSList *list;
       +   GtkTimeout *timeout;
       +   for (list=GtkTimeouts;list;list=g_slist_next(list)) {
       +      timeout=(GtkTimeout *)list->data;
       +      if (timeout->id == id) {
       +         if (timeout->function) {
       +            if (!(*timeout->function)(timeout->data)) {
       +               gtk_timeout_remove(id);
       +            }
       +         }
       +         break;
       +      }
       +   }
       +}
       +
        LRESULT CALLBACK GtkPanedProc(HWND hwnd,UINT msg,UINT wParam,LONG lParam) {
           PAINTSTRUCT ps;
           HPEN oldpen,dkpen,ltpen;
       t@@ -861,6 +887,9 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT msg,UINT wParam,LONG lParam) {
                 DispatchSocketEvent((SOCKET)wParam,WSAGETSELECTEVENT(lParam));
                 AsyncSocketError=0;
                 break;
       +      case WM_TIMER:
       +         DispatchTimeoutEvent((UINT)wParam);
       +         return FALSE;
              default:
                 return DefWindowProc(hwnd,msg,wParam,lParam);
           }
       t@@ -4230,6 +4259,52 @@ gint GtkMessageBox(GtkWidget *parent,const gchar *Text,
                             Text,Title,Options);
        }
        
       +guint gtk_timeout_add(guint32 interval,GtkFunction function,gpointer data) {
       +   GtkTimeout *timeout;
       +   GSList *list;
       +   guint id=1;
       +
       +/* Get an unused ID */
       +   list=GtkTimeouts;
       +   while (list) {
       +      timeout=(GtkTimeout *)list->data;
       +      if (timeout->id == id) {
       +         id++; list=GtkTimeouts;
       +      } else {
       +         list=g_slist_next(list);
       +      }
       +   }
       +
       +   timeout=g_new(GtkTimeout,1);
       +   timeout->interval = interval;
       +   timeout->function = function;
       +   timeout->data = data;
       +
       +   timeout->id=SetTimer(TopLevel,id,interval,NULL);
       +   if (timeout->id==0) {
       +      g_warning("Failed to create timer!");
       +   }
       +
       +   GtkTimeouts = g_slist_append(GtkTimeouts,timeout);
       +   return timeout->id;
       +}
       +
       +void gtk_timeout_remove(guint timeout_handler_id) {
       +   GSList *list;
       +   GtkTimeout *timeout;
       +   for (list=GtkTimeouts;list;list=g_slist_next(list)) {
       +      timeout=(GtkTimeout *)list->data;
       +      if (timeout->id == timeout_handler_id) {
       +         if (KillTimer(TopLevel,timeout->id)==0) {
       +            g_warning("Failed to kill timer!");
       +         }
       +         GtkTimeouts=g_slist_remove(GtkTimeouts,timeout);
       +         g_free(timeout);
       +         break;
       +      }
       +   }
       +}
       +
        #else   /* CYGWIN */
        guint SetAccelerator(GtkWidget *labelparent,gchar *Text,
                             GtkWidget *sendto,gchar *signal,
 (DIR) diff --git a/src/gtkport.h b/src/gtkport.h
       t@@ -54,6 +54,7 @@ typedef enum {
           GDK_INPUT_EXCEPTION = 1 << 2
        } GdkInputCondition;
        
       +typedef gint (*GtkFunction)(gpointer data);
        typedef void (*GdkInputFunction)(gpointer data,gint source,
                                         GdkInputCondition condition);
        typedef gchar* (*GtkTranslateFunc)(const gchar *path,gpointer func_data);
       t@@ -663,6 +664,8 @@ GtkWidget *gtk_progress_bar_new();
        void gtk_progress_bar_set_orientation(GtkProgressBar *pbar,
                                              GtkProgressBarOrientation orientation);
        void gtk_progress_bar_update(GtkProgressBar *pbar,gfloat percentage);
       +guint gtk_timeout_add(guint32 interval,GtkFunction function,gpointer data);
       +void gtk_timeout_remove(guint timeout_handler_id);
        
        extern long AsyncSocketError;