This commit was manufactured by cvs2svn to create tag
[lyx.git] / src / kbmap.h
blob8f41d2484cfe5d672127b020a1c300591fe5a766
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 \* ==================================================================== */
9 #ifndef KBMAP_H
10 #define KBMAP_H
12 #ifdef __GNUG__
13 #pragma interface
14 #endif
16 #include <X11/Xlib.h>
18 #include "LString.h"
20 #define KB_PREALLOC 16
21 #define KB_HASHSIZE 128 // yes, yes - I know. 128 is not exactly prime :-)
22 // ... but we are dealing with ASCII chars mostly.
24 class kb_keymap;
25 class kb_sequence;
27 ///
28 struct kb_key {
29 /// Keysym
30 unsigned int code;
32 /// Modifier masks
33 unsigned int mod;
35 /// Keymap for prefix keys
36 kb_keymap *table;
38 /// Action for !prefix keys
39 int action;
43 /// Defines key maps and actions for key sequences
44 class kb_keymap {
45 public:
46 ///
47 kb_keymap() {
48 size = 0;
49 table = 0;
51 ///
52 ~kb_keymap();
54 /// Bind a key-sequence to an action
55 /** Returns 0 on success. Otherwise, position in string where
56 error occured. */
57 int bind(char const* seq, int action);
59 ///
60 int print(char* buf, int maxlen) const;
62 /// Look up a key in the keymap
63 int lookup(KeySym key, unsigned mod, kb_sequence *seq);
65 /// Given an action, find all keybindings.
66 string findbinding(int action) const;
67 private:
68 /// Define a new key sequence
69 int defkey(kb_sequence *seq, int action, int idx = 0);
71 /// Size of the table (<0: hashtab)
72 int size;
74 /// Holds the defined keys
75 /** Both kinds of tables ends with NoSymbol */
76 union
78 /// Table for linear array
79 kb_key *table;
81 /// Hash table holding key lists
82 kb_key **htable;
87 /// Holds a key sequence and the current and standard keymaps
88 class kb_sequence {
89 public:
90 ///
91 kb_sequence() {
92 stdmap = curmap = 0;
93 sequence = staticseq;
94 modifiers = staticmod;
95 length = 0;
96 size = KB_PREALLOC;
99 ///
103 ~kb_sequence()
105 if (sequence != staticseq) {
106 delete sequence;
107 delete modifiers;
111 /// Add a key to the key sequence and look it up in the curmap
112 /** Add a key to the key sequence and look it up in the curmap
113 if the latter is defined. */
114 int addkey(KeySym key, unsigned mod, unsigned nmod = 0);
117 int print(char *buf, int maxlen, bool when_defined = false) const; //RVDK_PATCH_5
120 int printOptions(char *buf, int maxlen) const;
122 /// Make length negative to mark the sequence as deleted
123 void delseq();
126 char getiso();
129 KeySym getsym();
132 void reset();
135 int parse(char const *s);
137 /// Keymap to use if a new sequence is starting
138 kb_keymap *stdmap;
140 /// Keymap to use for the next key
141 kb_keymap *curmap;
143 /// Array holding the current key sequence
144 /** If sequence[length-1] < 0xff it can be used as ISO8859 char */
145 unsigned int *sequence;
148 unsigned int *modifiers;
150 /// Current length of key sequence
151 int length;
153 private:
154 /// Static array preallocated for sequence
155 unsigned int staticseq[KB_PREALLOC];
158 unsigned int staticmod[KB_PREALLOC];
160 /// Physically allocated storage size
161 int size;
164 #endif