home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / lyx-0.13.2.tar.gz / lyx-0.13.2.tar / lyx-0.13.2 / src / lyxlookup.C < prev    next >
C/C++ Source or Header  |  1998-04-23  |  4KB  |  192 lines

  1. /* This file is part of
  2. * ======================================================
  3. *           LyX, The Document Processor
  4. *      
  5. *        Copyright (C) 1995 Matthias Ettrich 
  6. *           Copyright (C) 1995-1998 The LyX team.
  7. *
  8. *======================================================*/
  9.  
  10. #include <config.h>
  11. #include <X11/Xlib.h>
  12. #include <X11/Xutil.h>
  13. #include <X11/keysym.h>
  14. #ifdef HAVE_LOCALE_H
  15. #include <locale.h>
  16. #endif
  17.  
  18. #include "error.h"
  19.  
  20. static XIM xim;
  21. static XIC xic;
  22. XComposeStatus compose_status={NULL,0};
  23.  
  24. // This is called after the main LyX window has been created
  25. void InitLyXLookup(Display* display, Window window) 
  26. {
  27.     xic = NULL;
  28.  
  29.     // This part could be done before opening display
  30.     setlocale(LC_CTYPE,"");
  31.            if (!XSupportsLocale()) {
  32.         lyxerr.debug("InitLyXLookup: X does not support this locale.");
  33.         return;
  34.     } 
  35.     if (!XSetLocaleModifiers("")) {
  36.         lyxerr.debug("InitLyXLookup: Could not set modifiers "
  37.                  "for this locale.");
  38.         return;
  39.     }
  40.  
  41.     // This part will have to be done for each frame
  42.     xim = XOpenIM (display, NULL, NULL, NULL);
  43.     if (xim) {
  44.         xic = XCreateIC (xim,  
  45.                 XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
  46.                 XNClientWindow, window,
  47.                 XNFocusWindow, window, 
  48.                 NULL);
  49.         
  50.         if (!xic) {
  51.             lyxerr.debug("InitLyXLookup: could not create "
  52.                      "an input context");
  53.             XCloseIM (xim);
  54.             xim = NULL;
  55.         } 
  56.     }
  57.     else 
  58.         lyxerr.debug("InitLyXLookup: could not open "
  59.                  "an input method.");
  60.  
  61. }
  62.  
  63.  
  64. static
  65. bool isDeadEvent(XEvent *event,
  66.           char *buffer_return, int bytes_buffer,
  67.           KeySym *keysym_return)
  68. {
  69.     XLookupString(&event->xkey, buffer_return,
  70.               bytes_buffer, keysym_return,
  71.               NULL);
  72.     // Can this be done safely in any other way?
  73.     // This is all the dead keys I know of in X11R6.1
  74.     if (false
  75. #ifdef XK_dead_grave
  76.         || *keysym_return == XK_dead_grave
  77. #endif
  78. #ifdef XK_dead_acute
  79.         || *keysym_return == XK_dead_acute
  80. #endif
  81. #ifdef XK_dead_circumflex
  82.         || *keysym_return == XK_dead_circumflex
  83. #endif
  84. #ifdef XK_dead_tilde
  85.         || *keysym_return == XK_dead_tilde
  86. #endif
  87. #ifdef XK_dead_macron
  88.         || *keysym_return == XK_dead_macron
  89. #endif
  90. #ifdef XK_dead_breve
  91.         || *keysym_return == XK_dead_breve
  92. #endif
  93. #ifdef XK_dead_abovedot
  94.         || *keysym_return == XK_dead_abovedot
  95. #endif
  96. #ifdef XK_dead_diaeresis
  97.         || *keysym_return == XK_dead_diaeresis
  98. #endif
  99. #ifdef XK_dead_abovering
  100.         || *keysym_return == XK_dead_abovering
  101. #endif
  102. #ifdef XK_dead_doubleacute
  103.         || *keysym_return == XK_dead_doubleacute
  104. #endif
  105. #ifdef XK_dead_caron
  106.         || *keysym_return == XK_dead_caron
  107. #endif
  108. #ifdef XK_dead_cedilla
  109.         || *keysym_return == XK_dead_cedilla
  110. #endif
  111. #ifdef XK_dead_ogonek
  112.         || *keysym_return == XK_dead_ogonek
  113. #endif
  114. #ifdef XK_dead_iota
  115.         || *keysym_return == XK_dead_iota
  116. #endif
  117. #ifdef XK_dead_voiced_sound
  118.         || *keysym_return == XK_dead_voiced_sound
  119. #endif
  120. #ifdef XK_dead_semivoiced_sound
  121.         || *keysym_return == XK_dead_semivoiced_sound
  122. #endif
  123. #ifdef XK_dead_belowdot
  124.         || *keysym_return == XK_dead_belowdot
  125. #endif
  126.         )
  127.         return true;
  128.     return false;
  129. }
  130.  
  131.  
  132. // This is called instead of XLookupString()
  133. int LyXLookupString(XEvent *event,    
  134.             char *buffer_return, int bytes_buffer,
  135.             KeySym *keysym_return) 
  136. {
  137.     int result = 0;
  138.     if (xic) {
  139.         if (isDeadEvent(event, buffer_return, bytes_buffer,
  140.                  keysym_return)) {
  141.             return 0;
  142.         }
  143.         if (XFilterEvent (event, None)) {
  144.             //lyxerr.print("XFilterEvent");
  145.             *keysym_return = NoSymbol;
  146.                         return 0;
  147.         }
  148.         if (event->type != KeyPress); //NB!
  149.         //lyxerr.print("LyXLookupString: wrong event type" 
  150.         //          +LString(event->type));
  151.         Status status_return;
  152.         
  153.         result =  XmbLookupString(xic, &event->xkey, buffer_return,
  154.                        bytes_buffer, keysym_return,
  155.                        &status_return);
  156.         switch(status_return) {
  157.         case XLookupBoth:
  158.             //lyxerr.print("XLookupBoth");
  159.             break;
  160.         case XLookupChars:
  161.             //lyxerr.print("XLookupChars");
  162.             *keysym_return = NoSymbol;
  163.             break;
  164.         case XLookupKeySym:
  165.             //lyxerr.print("XLookupKeySym");
  166.             result = 0;
  167.             break;
  168.         default:
  169.             //lyxerr.print("default");
  170.             *keysym_return = NoSymbol;
  171.             result = 0;
  172.             break;
  173.         }
  174.     } else {
  175.         result = XLookupString(&event->xkey, buffer_return,
  176.                   bytes_buffer, keysym_return,
  177.                   &compose_status);
  178.     }
  179.     return result;
  180. }
  181.  
  182. // This is called after the main window has been destroyed
  183. void CloseLyXLookup() 
  184. {
  185.     if (xic) {
  186.         lyxerr.debug("CloseLyXLookup: destroying input context");
  187.         XDestroyIC(xic);
  188.         XCloseIM(xim);
  189.     }
  190. }
  191.