1999-09-27 18:44:28 +00:00
|
|
|
|
//<2F>-*- C++ -*-
|
2002-02-26 10:50:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file kbmap.h
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-02-26 10:50:48 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author John Levon
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-02-26 10:50:48 +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
|
|
|
|
|
2003-09-21 23:00:47 +00:00
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
|
2002-05-26 17:33:14 +00:00
|
|
|
|
#include "frontends/key_state.h"
|
2003-09-06 20:08:10 +00:00
|
|
|
|
|
|
|
|
|
#include <boost/shared_ptr.hpp>
|
2002-05-22 01:16:37 +00:00
|
|
|
|
|
2003-06-18 13:47:11 +00:00
|
|
|
|
#include <vector>
|
2002-05-22 01:16:37 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
class kb_sequence;
|
2003-09-06 20:08:10 +00:00
|
|
|
|
class LyXKeySym;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
/// 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
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::string::size_type bind(std::string const & seq, FuncRequest const & func);
|
1999-12-16 06:43:25 +00:00
|
|
|
|
|
2003-07-26 23:04:39 +00:00
|
|
|
|
// Parse a bind file
|
2003-10-06 15:43:21 +00:00
|
|
|
|
bool read(std::string const & bind_file);
|
2003-07-26 23:04:39 +00:00
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
/// print all available keysyms
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::string const print() const;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-09-06 20:08:10 +00:00
|
|
|
|
///
|
|
|
|
|
typedef boost::shared_ptr<LyXKeySym> LyXKeySymPtr;
|
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
|
|
|
|
|
*/
|
2003-09-21 23:00:47 +00:00
|
|
|
|
FuncRequest const &
|
|
|
|
|
lookup(LyXKeySymPtr key,
|
|
|
|
|
key_modifier::state mod, kb_sequence * seq) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
/// Given an action, find all keybindings.
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::string const findbinding(FuncRequest const & func,
|
|
|
|
|
std::string const & prefix = std::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
|
|
|
|
|
*/
|
2004-03-26 15:12:35 +00:00
|
|
|
|
static std::string const printKeySym(LyXKeySym const & 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
|
2003-09-21 23:00:47 +00:00
|
|
|
|
FuncRequest func;
|
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
|
|
|
|
|
*/
|
2003-09-21 23:00:47 +00:00
|
|
|
|
void defkey(kb_sequence * seq, FuncRequest const & func,
|
|
|
|
|
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
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::string const printKey(kb_key const & key) const;
|
2001-11-30 13:25:38 +00:00
|
|
|
|
|
|
|
|
|
/// 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
|
|
|
|
///
|
2003-06-18 13:47:11 +00:00
|
|
|
|
typedef std::vector<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
|