]> git.lyx.org Git - lyx.git/blob - src/kbmap.h
removed a warning from screen and added CFLAGS in lyx.spec.in.
[lyx.git] / src / kbmap.h
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 #include "LString.h"
19
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.
23
24 class kb_keymap;
25 class kb_sequence;
26
27 ///
28 struct kb_key {
29         /// Keysym
30         unsigned int code;
31         
32         /// Modifier masks
33         unsigned int mod;
34         
35         /// Keymap for prefix keys
36         kb_keymap *table;
37         
38         /// Action for !prefix keys
39         int action;
40 };
41
42
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;
50         }
51         ///
52         ~kb_keymap();
53         
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);
58         
59         ///
60         int print(char* buf, int maxlen) const;
61         
62         /// Look up a key in the keymap
63         int lookup(KeySym key, unsigned mod, kb_sequence *seq);
64
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);
70         
71         /// Size of the table (<0: hashtab)
72        int size;
73         
74         /// Holds the defined keys
75         /** Both kinds of tables ends with NoSymbol */
76         union
77         {
78                 /// Table for linear array
79                 kb_key *table;
80                 
81                 /// Hash table holding key lists
82                 kb_key **htable;
83         };
84 };
85
86
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;
97         }
98         
99         ///
100         
101         
102         ///
103         ~kb_sequence()
104         {
105                 if (sequence != staticseq) {
106                         delete sequence;
107                         delete modifiers;
108                 }
109         }
110         
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);
115         
116         ///
117         int print(char *buf, int maxlen, bool when_defined = false) const; //RVDK_PATCH_5
118         
119         ///
120         int printOptions(char *buf, int maxlen) const;
121         
122         /// Make length negative to mark the sequence as deleted
123         void delseq();
124         
125         ///
126         char getiso();
127         
128         ///
129         KeySym getsym();
130         
131         ///
132         void reset();
133         
134         ///
135         int parse(char const *s);
136         
137         /// Keymap to use if a new sequence is starting
138         kb_keymap *stdmap;
139         
140         /// Keymap to use for the next key
141         kb_keymap *curmap;
142         
143         /// Array holding the current key sequence
144         /** If sequence[length-1] < 0xff it can be used as ISO8859 char */
145         unsigned int *sequence;
146         
147         ///
148         unsigned int *modifiers;
149         
150         /// Current length of key sequence
151         int length;
152         
153 private:
154         /// Static array preallocated for sequence
155         unsigned int staticseq[KB_PREALLOC];
156         
157         ///
158         unsigned int staticmod[KB_PREALLOC];
159         
160         /// Physically allocated storage size
161         int size;
162 };
163
164 #endif