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"
|
2006-04-13 12:18:42 +00:00
|
|
|
|
#include "frontends/LyXKeySym.h"
|
2003-09-06 20:08:10 +00:00
|
|
|
|
|
2006-12-13 14:13:01 +00:00
|
|
|
|
#include "support/docstream.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>
|
2004-07-02 10:03:22 +00:00
|
|
|
|
#include <deque>
|
2002-05-22 01:16:37 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
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
|
|
|
|
*/
|
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
|
|
|
|
|
2007-01-04 17:10:24 +00:00
|
|
|
|
/**
|
|
|
|
|
* print all available keysyms
|
|
|
|
|
* @param forgui true if the string should use translations and
|
|
|
|
|
* special characters.
|
|
|
|
|
*/
|
|
|
|
|
docstring const print(bool forgui) 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
|
2006-05-05 20:23:12 +00:00
|
|
|
|
* @return the action / LFUN_COMMAND_PREFIX / LFUN_UNKNOWN_ACTION
|
2001-11-30 13:25:38 +00:00
|
|
|
|
*/
|
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
|
|
|
|
|
2004-07-02 10:03:22 +00:00
|
|
|
|
///
|
|
|
|
|
typedef std::deque<kb_sequence> Bindings;
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/// Given an action, find all keybindings.
|
2004-07-02 10:03:22 +00:00
|
|
|
|
Bindings findbindings(FuncRequest const & func) const;
|
|
|
|
|
|
|
|
|
|
/// Given an action, print the keybindings.
|
2006-12-13 14:13:01 +00:00
|
|
|
|
docstring const printbindings(FuncRequest const & func) const;
|
2001-11-30 13:25:38 +00:00
|
|
|
|
|
2004-10-05 10:11:42 +00:00
|
|
|
|
/**
|
2004-07-07 09:32:19 +00:00
|
|
|
|
* Given an action, find the first 1-key binding (if it exists).
|
|
|
|
|
* The LyXKeySym pointer is 0 is no key is found.
|
|
|
|
|
* [only used by the Qt/Mac frontend]
|
|
|
|
|
*/
|
|
|
|
|
std::pair<LyXKeySym const *, key_modifier::state>
|
|
|
|
|
find1keybinding(FuncRequest const & func) 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
|
|
|
|
|
2004-07-02 10:03:22 +00:00
|
|
|
|
/**
|
|
|
|
|
* Given an action, find all keybindings
|
|
|
|
|
* @param func the action
|
|
|
|
|
* @param prefix a sequence to prepend the results
|
|
|
|
|
*/
|
|
|
|
|
Bindings findbindings(FuncRequest const & func,
|
|
|
|
|
kb_sequence const & prefix) 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
|
|
|
|
};
|
|
|
|
|
|
2006-10-19 07:20:32 +00:00
|
|
|
|
/// Implementation is in lyx_main.C
|
|
|
|
|
extern kb_keymap & theTopLevelKeymap();
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
2002-02-26 10:50:48 +00:00
|
|
|
|
#endif // KBMAP_H
|