]> git.lyx.org Git - lyx.git/blob - src/kbmap.h
move pasteParagraph to global scope
[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 #include "frontends/LyXKeySym.h"
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          * See kb_sequence::parse for the syntax of the seq string
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(LyXKeySymPtr 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 as a keysym
57          * @param mod the modifiers
58          */
59         static string const printKeysym(LyXKeySymPtr key,
60                                         key_modifier::state mod);
61
62         typedef std::pair<key_modifier::state, key_modifier::state> modifier_pair;
63
64 private:
65         ///
66         struct kb_key {
67                 /// Keysym
68                 LyXKeySymPtr code;
69
70                 /// Modifier masks
71                 modifier_pair mod;
72
73                 /// Keymap for prefix keys
74                 boost::shared_ptr<kb_keymap> table;
75
76                 /// Action for !prefix keys
77                 int action;
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