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

[STR New]

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


Attached file "fltk-1_v4_v2.3.x-dead-chars-x11.patch"...


Link: http://www.fltk.org/str.php?L2599
Version: 1.3-feature
Index: FL/Enumerations.H
===================================================================
--- FL/Enumerations.H   (revision 8623)
+++ FL/Enumerations.H   (working copy)
@@ -423,6 +423,25 @@
 
 /*@}*/         // group: Event States
 
+/** \name Compose States
+
+       These constants define the state of character composition for the
+       current keyboard event.
+       
+       \sa Fl::event_compose_state(), Fl::event_compose_symbol()
+*/
+
+/*@{*/
+
+enum Fl_Compose {
+  FL_COMPOSE_UNKNOWN = 0,      ///< current compose status cannot be determined
+  FL_COMPOSE_NONE,             ///< no composition active for this event
+  FL_COMPOSE_INTERMEDIATE,     ///< the current event is part of a composition 
but does not end it
+  FL_COMPOSE_FINAL,            ///< a composed character has successfully been 
constructed
+};
+
+/*@}*/         // group: Compose States
+
 /** \name Box Types
     \brief FLTK standard box types
     
Index: FL/Fl.H
===================================================================
--- FL/Fl.H     (revision 8548)
+++ FL/Fl.H     (working copy)
@@ -133,6 +133,8 @@
   static int e_keysym;
   static char* e_text;
   static int e_length;
+  static int e_compose_state;
+  static const char* e_compose_symbol;
   static Fl_Event_Dispatch e_dispatch;
   static Fl_Widget* belowmouse_;
   static Fl_Widget* pushed_;
@@ -685,6 +687,9 @@
   */
   static int event_length() {return e_length;}
 
+  static int event_compose_state();
+  static const char* event_compose_symbol();
+
   static int compose(int &del);
   static void compose_reset();
   static int event_inside(int,int,int,int);
Index: src/Fl_compose.cxx
===================================================================
--- src/Fl_compose.cxx  (revision 8618)
+++ src/Fl_compose.cxx  (working copy)
@@ -29,8 +29,9 @@
 #include <FL/x.H>
 
 #ifndef FL_DOXYGEN
-// at present, this is effectively used by Mac OS X only
 int Fl::compose_state = 0;
+int Fl::e_compose_state = FL_COMPOSE_UNKNOWN;
+const char* Fl::e_compose_symbol = "";
 #endif
 
 #if !defined(WIN32) && !defined(__APPLE__)
@@ -57,6 +58,7 @@
  */
 int Fl::compose(int& del) {
   // character composition is now handled by the OS
+  unsigned char ascii = (unsigned)e_text[0];
   del = 0;
 #if defined(__APPLE__)
   // this stuff is to be treated as a function key
@@ -65,20 +67,16 @@
     return 0;
   }
 #elif defined(WIN32)
-  unsigned char ascii = (unsigned)e_text[0];
   if ((e_state & (FL_ALT | FL_META)) && !(ascii & 128)) return 0;
 #else
-  unsigned char ascii = (unsigned)e_text[0];
   if ((e_state & (FL_ALT | FL_META | FL_CTRL)) && !(ascii & 128)) return 0;
 #endif
   if(Fl::compose_state) {
     del = Fl::compose_state;
     Fl::compose_state = 0;
   } else {
-#ifndef __APPLE__
     // Only insert non-control characters:
     if (! (ascii & ~31 && ascii!=127)) { return 0; }
-#endif
   }
   return 1;
 }
@@ -97,6 +95,31 @@
 #endif
 }
 
+/**
+  Returns what role the current key press plays in constructing a composed
+  character.
+  \see Fl_Compose
+ */
+int Fl::event_compose_state()
+{
+  return e_compose_state;
+}
+
+/**
+  Returns the raw symbol associated with the current event. This will be
+  the same as what Fl::event_text() returns except when the compose state
+  is FL_COMPOSE_INTERMEDIATE or FL_COMPOSE_FINAL.
+  \see Fl_Compose
+ */
+const char* Fl::event_compose_symbol()
+{
+  if ((e_compose_state == FL_COMPOSE_INTERMEDIATE) ||
+      (e_compose_state == FL_COMPOSE_FINAL))
+    return e_compose_symbol;
+
+  return Fl::event_text();
+}
+
 //
 // End of "$Id$"
 //
Index: src/Fl_x.cxx
===================================================================
--- src/Fl_x.cxx        (revision 8623)
+++ src/Fl_x.cxx        (working copy)
@@ -35,6 +35,8 @@
 /**** Define this if your keyboard lacks a backspace key... ****/
 /* #define BACKSPACE_HACK 1 */
 
+#  define XK_XKB_KEYS
+
 #  include <config.h>
 #  include <FL/Fl.H>
 #  include <FL/x.H>
@@ -51,6 +53,7 @@
 #  include <X11/Xmd.h>
 #  include <X11/Xlocale.h>
 #  include <X11/Xlib.h>
+#  include <X11/keysymdef.h>
 
 static Fl_Xlib_Graphics_Driver fl_xlib_driver;
 static Fl_Display_Device fl_xlib_display(&fl_xlib_driver);
@@ -921,9 +924,6 @@
 #endif
   }
 
-  if ( XFilterEvent((XEvent *)&xevent, 0) )
-      return(1);
-
   switch (xevent.type) {
 
   case KeymapNotify:
@@ -1218,11 +1218,14 @@
   case KeyRelease: {
   KEYPRESS:
     int keycode = xevent.xkey.keycode;
+    static int real_keycode;
     fl_key_vector[keycode/8] |= (1 << (keycode%8));
     static char *buffer = NULL;
     static int buffer_len = 0;
+    static char *compose_buffer = NULL;
     int len;
     KeySym keysym;
+    int hide_next = 0;
     if (buffer_len == 0) {
       buffer_len = 4096;
       buffer = (char*) malloc(buffer_len);
@@ -1231,6 +1234,12 @@
       event = FL_KEYDOWN;
       int len = 0;
 
+      // keycode 0 is a fake key, so looking that up is pointless,
+      // instead we rely on the fact that the preceding event was the
+      // real key
+      if (keycode != 0)
+        real_keycode = keycode;
+
       if (fl_xim_ic) {
        Status status;
        len = XUtf8LookupString(fl_xim_ic, (XKeyPressedEvent *)&xevent.xkey,
@@ -1242,7 +1251,111 @@
          len = XUtf8LookupString(fl_xim_ic, (XKeyPressedEvent *)&xevent.xkey,
                             buffer, buffer_len, &keysym, &status);
        }
-       keysym = XKeycodeToKeysym(fl_display, keycode, 0);
+
+        // if this returns true, then Xlib has done some compose processing
+        if (XFilterEvent((XEvent *)&xevent, 0)) {
+          XEvent peekevent;
+
+          // store a copy of the current symbol as it'll get
+          // overwritten with the composed character in the next
+          // iteration
+          if (len) {
+            if (compose_buffer)
+              free(compose_buffer);
+            compose_buffer = strdup(buffer);
+
+            Fl::e_compose_symbol = compose_buffer;
+          } else {
+            // Xutf8LookupString() doesn't give us anything for dead
+            // symbols though, so we need to figure out the symbol
+            // ourselves using the keysym
+            switch (keysym) {
+            case XK_dead_grave:
+              Fl::e_compose_symbol = "\314\200";  // U+0300 COMBINING GRAVE 
ACCENT
+              break;
+            case XK_dead_acute:
+              Fl::e_compose_symbol = "\314\201";  // U+0301 COMBINING ACUTE 
ACCENT
+              break;
+            case XK_dead_circumflex:
+              Fl::e_compose_symbol = "\314\202";  // U+0302 COMBINING 
CIRCUMFLEX ACCENT
+              break;
+            case XK_dead_tilde:
+              Fl::e_compose_symbol = "\314\203";  // U+0303 COMBINING TILDE
+              break;
+            case XK_dead_macron:
+              Fl::e_compose_symbol = "\314\204";  // U+0304 COMBINING MACRON
+              break;
+            case XK_dead_breve:
+              Fl::e_compose_symbol = "\314\206";  // U+0306 COMBINING BREVE
+              break;
+            case XK_dead_abovedot:
+              Fl::e_compose_symbol = "\314\207";  // U+0307 COMBINING DOT ABOVE
+              break;
+            case XK_dead_diaeresis:
+              Fl::e_compose_symbol = "\314\210";  // U+0308 COMBINING DIAERESIS
+              break;
+            case XK_dead_abovering:
+              Fl::e_compose_symbol = "\314\212";  // U+030A COMBINING RING 
ABOVE
+              break;
+            case XK_dead_doubleacute:
+              Fl::e_compose_symbol = "\314\213";  // U+030B COMBINING DOUBLE 
ACUTE ACCENT
+              break;
+            case XK_dead_caron:
+              Fl::e_compose_symbol = "\314\214";  // U+030C COMBINING CARON
+              break;
+            case XK_dead_cedilla:
+              Fl::e_compose_symbol = "\314\247";  // U+0327 COMBINING CEDILLA
+              break;
+            case XK_dead_ogonek:
+              Fl::e_compose_symbol = "\314\250";  // U+0328 COMBINING OGONEK
+              break;
+            case XK_dead_iota:
+              Fl::e_compose_symbol = "\341\266\245";  // U+1DA5 MODIFIER 
LETTER SMALL IOTA
+              break;
+            case XK_dead_voiced_sound:
+              Fl::e_compose_symbol = "\343\202\231";  // U+3099 COMBINING 
KATAKANA-HIRAGANA VOICED SOUND MARK
+              break;
+            case XK_dead_semivoiced_sound:
+              Fl::e_compose_symbol = "\343\202\232";  // U+309A COMBINING 
KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK
+              break;
+            case XK_dead_belowdot:
+              Fl::e_compose_symbol = "\314\243";  // U+0323 COMBINING DOT BELOW
+              break;
+            default:
+              // this is some unknown compose character
+              Fl::e_compose_symbol = "";
+            }
+          }
+
+          // if a new character was produced then Xlib has put back an event
+          // on the queue with keycode 0
+          if (XPending(fl_display)) {
+            XPeekEvent(fl_display, &peekevent);
+            if (   (peekevent.type == KeyPress) // must be a KeyPress event
+                && (peekevent.xkey.keycode == 0) // must be keycode 0
+                && (peekevent.xkey.time == xevent.xkey.time) // must be sent 
at the exact same time
+                ) {
+              XNextEvent(fl_display, &xevent);
+
+              // Something went wrong fetching the current symbol...
+              if (Fl::e_compose_symbol[0] == '\0')
+                Fl::e_compose_state = FL_COMPOSE_UNKNOWN;
+              else
+                Fl::e_compose_state = FL_COMPOSE_FINAL;
+
+              // Process things again to get the composed symbol
+              goto KEYPRESS;
+            }
+          }
+         if(Fl::e_compose_state == FL_COMPOSE_INTERMEDIATE) hide_next = 1;
+          Fl::e_compose_state = FL_COMPOSE_INTERMEDIATE;
+        } else {
+          // if the keycode is 0 then state was set earlier
+          if (keycode != 0 && keysym != XK_Shift_L && keysym != XK_Shift_R)
+            Fl::e_compose_state = FL_COMPOSE_NONE;
+        }
+
+        keysym = XKeycodeToKeysym(fl_display, real_keycode, 0);
       } else {
         //static XComposeStatus compose;
         len = XLookupString((XKeyEvent*)&(xevent.xkey),
@@ -1263,6 +1376,7 @@
       buffer[len] = 0;
       Fl::e_text = buffer;
       Fl::e_length = len;
+      if(hide_next) Fl::e_length = 0;
     } else {
       // Stupid X sends fake key-up events when a repeating key is held
       // down, probably due to some back compatibility problem. Fortunately
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to