]> git.lyx.org Git - lyx.git/blob - src/kbmap.h
Reduce Michael's buglist.
[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 <list>
17 #include <boost/smart_ptr.hpp>
18
19 #include "LString.h"
20
21 class kb_sequence;
22
23 /// Defines key maps and actions for key sequences
24 class kb_keymap {
25 public:
26         /** Bind a key-sequence to an action.
27             Returns 0 on success. Otherwise, position in string where
28             error occured. */
29         string::size_type bind(string const & seq, int action);
30
31         ///
32         void print(string & buf) const;
33         
34         /// Look up a key in the keymap
35         int lookup(unsigned int key,
36                    unsigned int mod, kb_sequence * seq) const;
37
38         /// Given an action, find all keybindings.
39         string const findbinding(int action,
40                                  string const & prefix = string()) const;
41 private:
42         ///
43         struct kb_key {
44                 /// Keysym
45                 unsigned int code;
46                 
47                 /// Modifier masks
48                 unsigned int mod;
49                 
50                 /// Keymap for prefix keys
51                 boost::shared_ptr<kb_keymap> table;
52                 
53                 /// Action for !prefix keys
54                 int action;
55         };
56
57
58         /// Define a new key sequence
59         int defkey(kb_sequence * seq, int action, int idx = 0);
60         ///
61         static string const keyname(kb_key const & k);
62         
63         ///
64         static
65         void printKey(kb_key const & key, string & buf);
66         ///
67         bool empty() const {
68                 return table.empty();
69         }
70         ///
71         typedef std::list<kb_key> Table;
72         ///
73         Table table;
74 };
75
76 #endif