Author: matt
Date: 2011-01-25 11:54:09 -0800 (Tue, 25 Jan 2011)
New Revision: 8314
Log:
Added Fl::event_dispatch() which can add a function to FLTK that monitors all 
events before they reach Fl::handle(). STR 2532

Modified:
   branches/branch-1.3/FL/Fl.H
   branches/branch-1.3/src/Fl.cxx
   branches/branch-1.3/src/fl_font_mac.cxx

Modified: branches/branch-1.3/FL/Fl.H
===================================================================
--- branches/branch-1.3/FL/Fl.H 2011-01-25 15:44:40 UTC (rev 8313)
+++ branches/branch-1.3/FL/Fl.H 2011-01-25 19:54:09 UTC (rev 8314)
@@ -104,6 +104,9 @@
 /** signature of args functions passed as parameters */
 typedef int (*Fl_Args_Handler)(int argc, char **argv, int &i);
 
+/** signature of event_dispatch functions passed as parameters */
+typedef int (*Fl_Event_Dispatch)(int event, Fl_Window *w);
+
 /** @} */ /* group callback_functions */
 
 
@@ -129,6 +132,7 @@
   static int e_keysym;
   static char* e_text;
   static int e_length;
+  static Fl_Event_Dispatch e_dispatch;
   static Fl_Widget* belowmouse_;
   static Fl_Widget* pushed_;
   static Fl_Widget* focus_;
@@ -696,6 +700,14 @@
   static void focus(Fl_Widget*);
   static void add_handler(Fl_Event_Handler h);
   static void remove_handler(Fl_Event_Handler h);
+  /** Set a new event dispatch function.
+  The event dispatch function is called after native events are converted to 
+  FLTK events, but before they are handled by FLTK. If the dispatch function
+  returns a value other than 0, FLTK will not handle the event any further.
+  \param d new dispatch function, can be NULL */
+  static void event_dispatch(Fl_Event_Dispatch d) { e_dispatch = d; }
+  /** Return the current event dispatch function. */
+  static Fl_Event_Dispatch event_dispatch() { return e_dispatch; }
   /** @} */
 
   /** \defgroup  fl_clipboard  Selection & Clipboard functions

Modified: branches/branch-1.3/src/Fl.cxx
===================================================================
--- branches/branch-1.3/src/Fl.cxx      2011-01-25 15:44:40 UTC (rev 8313)
+++ branches/branch-1.3/src/Fl.cxx      2011-01-25 19:54:09 UTC (rev 8314)
@@ -89,6 +89,8 @@
 char           *Fl::e_text = (char *)"";
 int            Fl::e_length;
 
+Fl_Event_Dispatch Fl::e_dispatch = 0;
+
 unsigned char   Fl::options_[] = { 0, 0 };
 unsigned char   Fl::options_read_ = 0;
 
@@ -727,7 +729,7 @@
   them returns non zero then the event is ignored.  Events that cause
   this to be called are:
   
-  - FL_SHORTCUT events that are not recognized by any  widget.
+  - FL_SHORTCUT events that are not recognized by any widget.
     This lets you provide global shortcut keys.
   - System events that FLTK does not recognize.  See fl_xevent.
   - \e Some other events when the widget FLTK selected  returns
@@ -978,6 +980,12 @@
   widget uses the event.
 */
 {
+  if (e_dispatch) {
+    int ret = e_dispatch(e, window);
+    if (ret)
+      return ret;
+  }
+  
   e_number = e;
   if (fl_local_grab) return fl_local_grab(e);
 

Modified: branches/branch-1.3/src/fl_font_mac.cxx
===================================================================
--- branches/branch-1.3/src/fl_font_mac.cxx     2011-01-25 15:44:40 UTC (rev 
8313)
+++ branches/branch-1.3/src/fl_font_mac.cxx     2011-01-25 19:54:09 UTC (rev 
8314)
@@ -312,7 +312,7 @@
       i++; // because a pair of UniChar's represent a single character
       continue;
       }
-    unsigned int r = uni >> 7; // index of the character block containing uni
+    unsigned int r = uni >> 9; // index of the character block containing uni
     if (!fl_fontsize->width[r]) { // this character block has not been hit yet
 //fprintf(stderr,"r=%d size=%d name=%s\n",r,fl_fontsize->size, 
fl_fontsize->q_name);
       // allocate memory to hold width of each character in the block

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to