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