]> git.lyx.org Git - lyx.git/blob - src/kbmap.h
fix typo that put too many include paths for most people
[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 <list>
19 #include <boost/smart_ptr.hpp>
20
21 #include "LString.h"
22
23 class kb_sequence;
24
25 /// Defines key maps and actions for key sequences
26 class kb_keymap {
27 public:
28         /**
29          * Bind a key sequence to an action.
30          * @return 0 on success, or position in string seq where error
31          * occurs.
32          */
33         string::size_type bind(string const & seq, int action);
34
35         /// print all available keysyms
36         string const print() const;
37
38         /**
39          * Look up a key press in the keymap.
40          * @param key the keysym
41          * @param mod the modifiers
42          * @param seq the current key sequence so far
43          * @return the action / LFUN_PREFIX / LFUN_UNKNOWN_ACTION
44          */
45         int lookup(unsigned int key,
46                    unsigned int mod, kb_sequence * seq) const;
47
48         /// Given an action, find all keybindings.
49         string const findbinding(int action,
50                                  string const & prefix = string()) const;
51
52         /**
53          * Returns a string of the given keysym, with modifiers.
54          * @param key the key
55          * @param mod the modifiers
56          */
57         static string const printKeysym(unsigned int key, unsigned int mod);
58
59         /// return the ISO value of a keysym
60         static char getiso(unsigned int i);
61
62 private:
63         ///
64         struct kb_key {
65                 /// Keysym
66                 unsigned int code;
67
68                 /// Modifier masks
69                 unsigned int mod;
70
71                 /// Keymap for prefix keys
72                 boost::shared_ptr<kb_keymap> table;
73
74                 /// Action for !prefix keys
75                 int action;
76         };
77
78
79         /**
80          * Define an action for a key sequence.
81          * @param r internal recursion level
82          */
83         void defkey(kb_sequence * seq, int action, unsigned int r = 0);
84
85         ///  Returns a string of the given key
86         string const printKey(kb_key const & key) const;
87
88         /// is the table empty ?
89         bool empty() const {
90                 return table.empty();
91         }
92         ///
93         typedef std::list<kb_key> Table;
94         ///
95         Table table;
96 };
97
98 #endif // KBMAP_H