]> git.lyx.org Git - lyx.git/blob - src/kbmap.h
cosmetic fix
[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 #include "LString.h"
15 #include "frontends/key_state.h"
16 #include "frontends/LyXKeySym.h"
17
18 #include <vector>
19
20 class kb_sequence;
21
22 /// Defines key maps and actions for key sequences
23 class kb_keymap {
24 public:
25         /**
26          * Bind a key sequence to an action.
27          * @return 0 on success, or position in string seq where error
28          * occurs.
29          * See kb_sequence::parse for the syntax of the seq string
30          */
31         string::size_type bind(string const & seq, int action);
32
33         // Parse a bind file
34         bool kb_keymap::read(string const & bind_file);
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(LyXKeySymPtr key,
47                    key_modifier::state 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 as a keysym
56          * @param mod the modifiers
57          */
58         static string const printKeysym(LyXKeySymPtr key,
59                                         key_modifier::state mod);
60
61         typedef std::pair<key_modifier::state, key_modifier::state> modifier_pair;
62
63 private:
64         ///
65         struct kb_key {
66                 /// Keysym
67                 LyXKeySymPtr code;
68
69                 /// Modifier masks
70                 modifier_pair 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          * 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::vector<kb_key> Table;
94         ///
95         Table table;
96 };
97
98 #endif // KBMAP_H