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