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 / kbmap.h < prev    next >
C/C++ Source or Header  |  1998-04-23  |  3KB  |  164 lines

  1. //á-*- C++ -*-
  2. /* ======================================================================= *\
  3.    File   : kbmap.h, kbmap.h,v 1.3 1996/12/10 04:35:57 larsbj Exp
  4.    Author : chb, 30.Oct.1995
  5.    Docu   : see kbmap.C
  6.    Purpose: class definitions for XKeyEvent keymap handling
  7.    \* ======================================================================= */
  8.  
  9. #ifndef _KBMAP_H_
  10. #define _KBMAP_H_
  11.  
  12. #ifdef __GNUG__
  13. #pragma interface
  14. #endif
  15.  
  16. #include <X11/Xlib.h>
  17.  
  18. #define KB_PREALLOC  16
  19. #define KB_HASHSIZE 128   // yes, yes - I know. 128 is not exactly prime :-)
  20. // ... but we are dealing with ASCII chars mostly.
  21.  
  22. class kb_keymap;
  23. class kb_sequence;
  24. class LString;
  25.  
  26. ///
  27. struct kb_key {
  28.     /// Keysym
  29.     unsigned int code;
  30.     
  31.     /// Modifier masks
  32.     unsigned int mod;
  33.     
  34.     /// Keymap for prefix keys
  35.     kb_keymap *table;
  36.     
  37.     /// Action for !prefix keys
  38.     int action;
  39. };
  40.  
  41.  
  42. /// Defines key maps and actions for key sequences
  43. class kb_keymap {
  44. public:
  45.     ///
  46.     kb_keymap() {
  47.         size = 0; 
  48.         table = 0;
  49.     }
  50.     ///
  51.     ~kb_keymap();
  52.     
  53.     /// Bind a key-sequence to an action
  54.     /** Returns 0 on success. Otherwise, position in string where
  55.       error occured. */
  56.     int bind(LString const &seq, int action);
  57.     
  58.     ///
  59.     LString print() const;
  60.     
  61.     /// Look up a key in the keymap
  62.     int lookup(KeySym key, unsigned mod, kb_sequence *seq);
  63.  
  64.     /// Given an action, find all keybindings.
  65.     LString findbinding(int action) const;
  66. private:
  67.     /// Define a new key sequence
  68.     int defkey(kb_sequence *seq, int action, int idx = 0);
  69.     
  70.     /// Size of the table (<0: hashtab)
  71.        int size;
  72.     
  73.     /// Holds the defined keys
  74.     /** Both kinds of tables ends with NoSymbol */
  75.     union
  76.     {
  77.         /// Table for linear array
  78.         kb_key *table;
  79.         
  80.         /// Hash table holding key lists
  81.         kb_key **htable;
  82.     };
  83. };
  84.  
  85.  
  86. /// Holds a key sequence and the current and standard keymaps
  87. class kb_sequence {
  88. public:
  89.     ///
  90.     kb_sequence() {
  91.         stdmap = curmap = 0;
  92.         sequence = staticseq;
  93.         modifiers = staticmod;
  94.         length = 0; 
  95.         size = KB_PREALLOC;
  96.     }
  97.     
  98.     ///
  99.     
  100.     
  101.     ///
  102.     ~kb_sequence()
  103.     {
  104.         if (sequence != staticseq) {
  105.             delete sequence;
  106.             delete modifiers;
  107.         }
  108.     }
  109.     
  110.     /// Add a key to the key sequence and look it up in the curmap
  111.     /** Add a key to the key sequence and look it up in the curmap
  112.       if the latter is defined. */
  113.     int addkey(KeySym key, unsigned mod, unsigned nmod = 0);
  114.     
  115.     ///
  116.     LString print(bool when_defined = false) const; 
  117.     
  118.         ///
  119.     LString printOptions() const;
  120.     
  121.     /// Make length negative to mark the sequence as deleted
  122.     void delseq();
  123.     
  124.     ///
  125.     char getiso();
  126.     
  127.     ///
  128.     KeySym getsym();
  129.     
  130.     ///
  131.     void reset();
  132.     
  133.     ///
  134.     int parse(LString const&);
  135.     
  136.     /// Keymap to use if a new sequence is starting
  137.     kb_keymap *stdmap;
  138.     
  139.     /// Keymap to use for the next key
  140.     kb_keymap *curmap;
  141.     
  142.     /// Array holding the current key sequence
  143.     /** If sequence[length-1] < 0xff it can be used as ISO8859 char */
  144.     unsigned int *sequence;
  145.     
  146.     ///
  147.     unsigned int *modifiers;
  148.     
  149.     /// Current length of key sequence
  150.     int length;
  151.     
  152. private:
  153.     /// Static array preallocated for sequence
  154.     unsigned int staticseq[KB_PREALLOC];
  155.     
  156.     ///
  157.     unsigned int staticmod[KB_PREALLOC];
  158.     
  159.     /// Physically allocated storage size
  160.     int size;
  161. };
  162.  
  163. #endif
  164.