]> git.lyx.org Git - lyx.git/blob - src/kbmap.h
Store and use QImage rather than QPixmap.
[lyx.git] / src / kbmap.h
1 // -*- C++ -*-
2 /**
3  * \file kbmap.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author John Levon
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef KBMAP_H
15 #define KBMAP_H
16
17 #include "funcrequest.h"
18
19 #include "frontends/key_state.h"
20
21 #include <boost/shared_ptr.hpp>
22
23 #include <vector>
24
25 class kb_sequence;
26 class LyXKeySym;
27
28 /// Defines key maps and actions for key sequences
29 class kb_keymap {
30 public:
31         /**
32          * Bind a key sequence to an action.
33          * @return 0 on success, or position in string seq where error
34          * occurs.
35          * See kb_sequence::parse for the syntax of the seq string
36          */
37         std::string::size_type bind(std::string const & seq, FuncRequest const & func);
38
39         // Parse a bind file
40         bool read(std::string const & bind_file);
41
42         /// print all available keysyms
43         std::string const print() const;
44
45         ///
46         typedef boost::shared_ptr<LyXKeySym> LyXKeySymPtr;
47         /**
48          * Look up a key press in the keymap.
49          * @param key the keysym
50          * @param mod the modifiers
51          * @param seq the current key sequence so far
52          * @return the action / LFUN_PREFIX / LFUN_UNKNOWN_ACTION
53          */
54         FuncRequest const &
55         lookup(LyXKeySymPtr key,
56                key_modifier::state mod, kb_sequence * seq) const;
57
58         /// Given an action, find all keybindings.
59         std::string const findbinding(FuncRequest const & func,
60                                  std::string const & prefix = std::string()) const;
61
62         /**
63          * Returns a string of the given keysym, with modifiers.
64          * @param key the key as a keysym
65          * @param mod the modifiers
66          */
67         static std::string const printKeySym(LyXKeySym const & key,
68                                              key_modifier::state mod);
69
70         typedef std::pair<key_modifier::state, key_modifier::state> modifier_pair;
71
72 private:
73         ///
74         struct kb_key {
75                 /// Keysym
76                 LyXKeySymPtr code;
77
78                 /// Modifier masks
79                 modifier_pair mod;
80
81                 /// Keymap for prefix keys
82                 boost::shared_ptr<kb_keymap> table;
83
84                 /// Action for !prefix keys
85                 FuncRequest func;
86         };
87
88         /**
89          * Define an action for a key sequence.
90          * @param r internal recursion level
91          */
92         void defkey(kb_sequence * seq, FuncRequest const & func,
93                     unsigned int r = 0);
94
95         ///  Returns a string of the given key
96         std::string const printKey(kb_key const & key) const;
97
98         /// is the table empty ?
99         bool empty() const {
100                 return table.empty();
101         }
102         ///
103         typedef std::vector<kb_key> Table;
104         ///
105         Table table;
106 };
107
108 #endif // KBMAP_H