1999-09-27 18:44:28 +00:00
|
|
|
|
//<2F>-*- C++ -*-
|
2002-02-26 10:50:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file kbmap.h
|
|
|
|
|
* Copyright 1995-2002 the LyX Team
|
|
|
|
|
* Read the file COPYING
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes <larsbj@lyx.org>
|
|
|
|
|
* \author John Levon <moz@compsoc.man.ac.uk>
|
|
|
|
|
*/
|
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
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
#include "LString.h"
|
2002-05-26 17:33:14 +00:00
|
|
|
|
#include "frontends/key_state.h"
|
2002-06-18 15:44:30 +00:00
|
|
|
|
#include "frontends/LyXKeySym.h"
|
2002-05-22 01:16:37 +00:00
|
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
|
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-06-18 15:44:30 +00:00
|
|
|
|
* See kb_sequence::parse for the syntax of the seq string
|
2001-11-30 13:25:38 +00:00
|
|
|
|
*/
|
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;
|
2002-03-21 17:27:08 +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-06-18 15:44:30 +00:00
|
|
|
|
int lookup(LyXKeySymPtr key,
|
2002-05-26 17:33:14 +00:00
|
|
|
|
key_modifier::state 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.
|
2002-06-18 15:44:30 +00:00
|
|
|
|
* @param key the key as a keysym
|
2001-11-30 13:25:38 +00:00
|
|
|
|
* @param mod the modifiers
|
|
|
|
|
*/
|
2002-06-18 15:44:30 +00:00
|
|
|
|
static string const printKeysym(LyXKeySymPtr key,
|
|
|
|
|
key_modifier::state mod);
|
2001-11-30 13:25:38 +00:00
|
|
|
|
|
2002-05-26 17:33:14 +00:00
|
|
|
|
typedef std::pair<key_modifier::state, key_modifier::state> modifier_pair;
|
2002-06-10 07:57:39 +00:00
|
|
|
|
|
|
|
|
|
private:
|
2000-02-04 09:38:32 +00:00
|
|
|
|
///
|
|
|
|
|
struct kb_key {
|
|
|
|
|
/// Keysym
|
2002-06-18 15:44:30 +00:00
|
|
|
|
LyXKeySymPtr code;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
/// Modifier masks
|
2002-05-26 17:33:14 +00:00
|
|
|
|
modifier_pair mod;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
/// Keymap for prefix keys
|
2001-03-07 16:18:05 +00:00
|
|
|
|
boost::shared_ptr<kb_keymap> table;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
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);
|
2002-03-21 17:27:08 +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
|
|
|
|
};
|
|
|
|
|
|
2002-02-26 10:50:48 +00:00
|
|
|
|
#endif // KBMAP_H
|