]> git.lyx.org Git - lyx.git/blob - src/kbmap.h
OK I'll try guii1 again ...
[lyx.git] / src / kbmap.h
1 // -*- C++ -*-
2 /**
3  * \file kbmap.h
4  * Copyright 1995-2002 the LyX Team
5  * Read the file COPYING
6  *
7  * \author Lars Gullik Bjønnes <larsbj@lyx.org>
8  * \author John Levon <moz@compsoc.man.ac.uk>
9  */
10
11 #ifndef KBMAP_H
12 #define KBMAP_H
13
14 #ifdef __GNUG__
15 #pragma interface
16 #endif
17
18 #include "LString.h"
19
20 #include <boost/shared_ptr.hpp>
21
22 #include <list>
23
24 class kb_sequence;
25
26 /// Defines key maps and actions for key sequences
27 class kb_keymap {
28 public:
29         /**
30          * Bind a key sequence to an action.
31          * @return 0 on success, or position in string seq where error
32          * occurs.
33          */
34         string::size_type bind(string const & seq, int action);
35
36         /// print all available keysyms
37         string const print() const;
38
39         /**
40          * Look up a key press in the keymap.
41          * @param key the keysym
42          * @param mod the modifiers
43          * @param seq the current key sequence so far
44          * @return the action / LFUN_PREFIX / LFUN_UNKNOWN_ACTION
45          */
46         int lookup(unsigned int key,
47                    unsigned int mod, kb_sequence * seq) const;
48
49         /// Given an action, find all keybindings.
50         string const findbinding(int action,
51                                  string const & prefix = string()) const;
52
53         /**
54          * Returns a string of the given keysym, with modifiers.
55          * @param key the key
56          * @param mod the modifiers
57          */
58         static string const printKeysym(unsigned int key, unsigned int mod);
59
60         /// return the ISO value of a keysym
61         static char getiso(unsigned int i);
62
63 private:
64         ///
65         struct kb_key {
66                 /// Keysym
67                 unsigned int code;
68
69                 /// Modifier masks
70                 unsigned int mod;
71
72                 /// Keymap for prefix keys
73                 boost::shared_ptr<kb_keymap> table;
74
75                 /// Action for !prefix keys
76                 int action;
77         };
78
79
80         /**
81          * Define an action for a key sequence.
82          * @param r internal recursion level
83          */
84         void defkey(kb_sequence * seq, int action, unsigned int r = 0);
85
86         ///  Returns a string of the given key
87         string const printKey(kb_key const & key) const;
88
89         /// is the table empty ?
90         bool empty() const {
91                 return table.empty();
92         }
93         ///
94         typedef std::list<kb_key> Table;
95         ///
96         Table table;
97 };
98
99 #endif // KBMAP_H