]> git.lyx.org Git - lyx.git/blob - src/kbmap.h
kb3 patch from John
[lyx.git] / src / kbmap.h
1 // -*- C++ -*-
2 /* ======================================================================= *\
3    File   : kbmap.h, kbmap.h,v 1.3 1996/12/10 04:35:57 larsbj Exp
4    Author : chb, 30.Oct.1995
5    Docu   : see kbmap.C
6    Purpose: class definitions for XKeyEvent keymap handling
7    \* ==================================================================== */
8
9 #ifndef KBMAP_H
10 #define KBMAP_H
11
12 #ifdef __GNUG__
13 #pragma interface
14 #endif
15
16 #include <list>
17 #include <boost/smart_ptr.hpp>
18
19 #include "commandtags.h"
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, kb_action 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         kb_action lookup(unsigned int key,
46                 unsigned int mod, kb_sequence * seq) const;
47
48         /// Given an action, find all keybindings.
49         string const findbinding(kb_action 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                 kb_action 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, kb_action 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