DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2817
Version: 1.3-feature


Here is a patch to add a hook to track timeouts the main reason to
implement it for me is to catch exceptions on win32 with mingw.

It is in the same line of the Fl::handle hook.

ex:

Fl::do_call_timeout_ = &my_do_call_timeouts;

void my_do_call_timeouts(Fl_Timeout_Handler th, void *data){
    try {
        (*th)(data);
    }
    catch(DBException &e)
    {
        fl_alert(e.what());
    }
 }


Link: http://www.fltk.org/str.php?L2817
Version: 1.3-feature
Index: FL/Fl.H
===================================================================
--- FL/Fl.H     (revision 9310)
+++ FL/Fl.H     (working copy)
@@ -99,6 +99,8 @@
     \see Fl::event_dispatch(Fl_Event_Dispatch) */
 typedef int (*Fl_Event_Dispatch)(int event, Fl_Window *w);
 
+/** Signature of user hook to call timeouts */
+typedef void (*Fl_Do_Call_Timeout)(Fl_Timeout_Handler th, void *data);
 /** @} */ /* group callback_functions */
 
 
@@ -134,6 +136,7 @@
   static Fl_Window* grab_;
   static int compose_state;
   static void call_screen_init(); // recompute screen number and dimensions
+  static Fl_Do_Call_Timeout do_call_timeout_;
 #endif
   /**
     If true then flush() will do something.
Index: src/Fl.cxx
===================================================================
--- src/Fl.cxx  (revision 9310)
+++ src/Fl.cxx  (working copy)
@@ -106,6 +106,7 @@
 int            Fl::e_length;
 
 Fl_Event_Dispatch Fl::e_dispatch = 0;
+Fl_Do_Call_Timeout Fl::do_call_timeout_ = 0;
 
 unsigned char   Fl::options_[] = { 0, 0 };
 unsigned char   Fl::options_read_ = 0;
@@ -483,7 +484,8 @@
       t->next = free_timeout;
       free_timeout = t;
       // Now it is safe for the callback to do add_timeout:
-      cb(argp);
+         if(Fl::do_call_timeout_) (*Fl::do_call_timeout_)(cb, argp);
+      else cb(argp);
     }
   } else {
     reset_clock = 1; // we are not going to check the clock
Index: src/Fl_cocoa.mm
===================================================================
--- src/Fl_cocoa.mm     (revision 9310)
+++ src/Fl_cocoa.mm     (working copy)
@@ -519,7 +519,8 @@
     MacTimeout& t = mac_timers[i];
     if (t.timer == timer  &&  t.data == data) {
       t.pending = 0;
-      (*t.callback)(data);
+         if(Fl::do_call_timeout_) (*Fl::do_call_timeout_)(t.callback, data);
+         else (*t.callback)(data);
       if (t.pending==0)
         delete_timer(t);
       break;
Index: src/Fl_mac.cxx
===================================================================
--- src/Fl_mac.cxx      (revision 9310)
+++ src/Fl_mac.cxx      (working copy)
@@ -665,7 +665,8 @@
         MacTimeout& t = mac_timers[i];
         if (t.timer == timer  &&  t.data == data) {
             t.pending = 0;
-            (*t.callback)(data);
+                       if(Fl::do_call_timeout_) 
(*Fl::do_call_timeout_)(t.callback, data);
+                   else (*t.callback)(data);
             if (t.pending==0)
               delete_timer(t);
             break;
Index: src/Fl_win32.cxx
===================================================================
--- src/Fl_win32.cxx    (revision 9310)
+++ src/Fl_win32.cxx    (working copy)
@@ -1692,7 +1692,8 @@
         void*              data = win32_timers[id].data;
         delete_timer(win32_timers[id]);
         if (cb) {
-          (*cb)(data);
+                 if(Fl::do_call_timeout_) (*Fl::do_call_timeout_)(cb, data);
+                 else (*cb)(data);
         }
       }
     }
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to