1999-09-27 18:44:28 +00:00
|
|
|
|
//<2F>-*- C++ -*-
|
|
|
|
|
/* ======================================================================= *\
|
|
|
|
|
File : kbmap.h, kbmap.h,v 1.3 1996/12/10 04:35:57 larsbj Exp
|
|
|
|
|
Author : chb, 30.Oct.1995
|
|
|
|
|
Docu : see kbmap.C
|
|
|
|
|
Purpose: class definitions for XKeyEvent keymap handling
|
1999-10-07 18:44:17 +00:00
|
|
|
|
\* ==================================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#ifndef KBMAP_H
|
|
|
|
|
#define KBMAP_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
|
#pragma interface
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
#include <list>
|
2001-03-07 16:18:05 +00:00
|
|
|
|
#include <boost/smart_ptr.hpp>
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
#include "LString.h"
|
2000-01-20 01:41:55 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
class kb_sequence;
|
|
|
|
|
|
|
|
|
|
/// Defines key maps and actions for key sequences
|
|
|
|
|
class kb_keymap {
|
|
|
|
|
public:
|
2001-11-30 13:25:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Bind a key sequence to an action.
|
|
|
|
|
* @return 0 on success, or position in string seq where error
|
|
|
|
|
* occurs.
|
|
|
|
|
*/
|
2002-01-12 20:00:47 +00:00
|
|
|
|
string::size_type bind(string const & seq, int action);
|
1999-12-16 06:43:25 +00:00
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
/// print all available keysyms
|
|
|
|
|
string const print() const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Look up a key press in the keymap.
|
|
|
|
|
* @param key the keysym
|
|
|
|
|
* @param mod the modifiers
|
|
|
|
|
* @param seq the current key sequence so far
|
|
|
|
|
* @return the action / LFUN_PREFIX / LFUN_UNKNOWN_ACTION
|
|
|
|
|
*/
|
2002-01-12 20:00:47 +00:00
|
|
|
|
int lookup(unsigned int key,
|
|
|
|
|
unsigned int mod, kb_sequence * seq) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
/// Given an action, find all keybindings.
|
2002-01-12 20:00:47 +00:00
|
|
|
|
string const findbinding(int action,
|
2001-05-17 15:11:01 +00:00
|
|
|
|
string const & prefix = string()) const;
|
2001-11-30 13:25:38 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a string of the given keysym, with modifiers.
|
|
|
|
|
* @param key the key
|
|
|
|
|
* @param mod the modifiers
|
|
|
|
|
*/
|
|
|
|
|
static string const printKeysym(unsigned int key, unsigned int mod);
|
|
|
|
|
|
|
|
|
|
/// return the ISO value of a keysym
|
|
|
|
|
static char getiso(unsigned int i);
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
private:
|
2000-02-04 09:38:32 +00:00
|
|
|
|
///
|
|
|
|
|
struct kb_key {
|
|
|
|
|
/// Keysym
|
|
|
|
|
unsigned int code;
|
|
|
|
|
|
|
|
|
|
/// Modifier masks
|
|
|
|
|
unsigned int mod;
|
|
|
|
|
|
|
|
|
|
/// Keymap for prefix keys
|
2001-03-07 16:18:05 +00:00
|
|
|
|
boost::shared_ptr<kb_keymap> table;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
|
|
/// Action for !prefix keys
|
2002-01-12 20:00:47 +00:00
|
|
|
|
int action;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
};
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Define an action for a key sequence.
|
|
|
|
|
* @param r internal recursion level
|
|
|
|
|
*/
|
2002-01-12 20:00:47 +00:00
|
|
|
|
void defkey(kb_sequence * seq, int action, unsigned int r = 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
/// Returns a string of the given key
|
|
|
|
|
string const printKey(kb_key const & key) const;
|
|
|
|
|
|
|
|
|
|
/// is the table empty ?
|
2000-02-04 09:38:32 +00:00
|
|
|
|
bool empty() const {
|
|
|
|
|
return table.empty();
|
2000-01-25 12:35:27 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
///
|
2000-04-04 00:19:15 +00:00
|
|
|
|
typedef std::list<kb_key> Table;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
///
|
2000-02-04 09:38:32 +00:00
|
|
|
|
Table table;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|