]> git.lyx.org Git - lyx.git/blob - src/kbmap.h
e2e15f228608cf9f9c8443457c8ad5dd93588dab
[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 "LString.h"
17
18 #define KB_PREALLOC  16
19
20 class kb_keymap;
21 class kb_sequence;
22
23 ///
24 struct kb_key {
25         /// Keysym
26         unsigned int code;
27         
28         /// Modifier masks
29         unsigned int mod;
30         
31         /// Keymap for prefix keys
32         kb_keymap * table;
33         
34         /// Action for !prefix keys
35         int action;
36 };
37
38
39 /// Defines key maps and actions for key sequences
40 class kb_keymap {
41 public:
42         ///
43         kb_keymap() {
44                 size = 0; 
45                 table = 0;
46         }
47         ///
48         ~kb_keymap();
49         
50         /// Bind a key-sequence to an action
51         /** Returns 0 on success. Otherwise, position in string where
52             error occured. */
53         int bind(char const * seq, int action);
54
55         ///
56         void print(string & buf) const;
57         
58         /// Look up a key in the keymap
59         int lookup(unsigned long key, unsigned mod, kb_sequence * seq);
60
61         /// Given an action, find all keybindings.
62         string findbinding(int action) const;
63 private:
64         /// Define a new key sequence
65         int defkey(kb_sequence * seq, int action, int idx = 0);
66         
67         /// Size of the table (<0: hashtab)
68         int size;
69         
70         /// Holds the defined keys
71         /// Table for linear array, table ends with NoSymbol.
72         kb_key * table;
73 };
74
75
76 /// Holds a key sequence and the current and standard keymaps
77 class kb_sequence {
78 public:
79         ///
80         kb_sequence() {
81                 stdmap = curmap = 0;
82                 sequence = staticseq;
83                 modifiers = staticmod;
84                 length = 0; 
85                 size = KB_PREALLOC;
86         }
87         
88         ///
89         
90         
91         ///
92         ~kb_sequence()
93                 {
94                         if (sequence != staticseq) {
95                                 delete sequence;
96                                 delete modifiers;
97                         }
98                 }
99         
100         /// Add a key to the key sequence and look it up in the curmap
101         /** Add a key to the key sequence and look it up in the curmap
102             if the latter is defined. */
103         int addkey(unsigned long key, unsigned mod, unsigned nmod = 0);
104
105         ///
106         int print(string & buf, bool when_defined = false) const;
107         
108         ///
109         int printOptions(string & buf) const;
110         
111         /// Make length negative to mark the sequence as deleted
112         void delseq();
113         
114         ///
115         char getiso();
116         
117         ///
118         unsigned long getsym();
119         
120         ///
121         void reset();
122         
123         ///
124         int parse(char const * s);
125         
126         /// Keymap to use if a new sequence is starting
127         kb_keymap * stdmap;
128         
129         /// Keymap to use for the next key
130         kb_keymap * curmap;
131         
132         /// Array holding the current key sequence
133         /** If sequence[length-1] < 0xff it can be used as ISO8859 char */
134         unsigned int * sequence;
135         
136         ///
137         unsigned int * modifiers;
138         
139         /// Current length of key sequence
140         int length;
141         
142 private:
143         /// Static array preallocated for sequence
144         unsigned int staticseq[KB_PREALLOC];
145         
146         ///
147         unsigned int staticmod[KB_PREALLOC];
148         
149         /// Physically allocated storage size
150         int size;
151 };
152
153 #endif