2007-04-27 08:19:12 +00:00
|
|
|
// -*- C++ -*-
|
2001-11-30 13:25:38 +00:00
|
|
|
/**
|
2007-04-27 08:19:12 +00:00
|
|
|
* \file KeySequence.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.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-11-30 13:25:38 +00:00
|
|
|
*/
|
2000-02-04 09:38:32 +00:00
|
|
|
|
2007-10-02 21:51:54 +00:00
|
|
|
#ifndef KEYSEQUENCE_H
|
|
|
|
#define KEYSEQUENCE_H
|
2000-02-04 09:38:32 +00:00
|
|
|
|
2007-10-02 21:51:54 +00:00
|
|
|
#include "frontends/KeyModifier.h"
|
2007-04-27 08:43:38 +00:00
|
|
|
#include "frontends/KeySymbol.h"
|
2003-09-06 20:08:10 +00:00
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
#include <string>
|
2002-05-26 17:33:14 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2007-04-27 08:05:58 +00:00
|
|
|
class KeyMap;
|
2003-09-21 23:00:47 +00:00
|
|
|
class FuncRequest;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
/// Holds a key sequence and the current and standard keymaps
|
2007-04-27 08:19:12 +00:00
|
|
|
class KeySequence {
|
2000-02-04 09:38:32 +00:00
|
|
|
public:
|
2007-09-17 18:41:03 +00:00
|
|
|
typedef std::vector<KeySymbol> Sequence;
|
2002-08-11 16:27:10 +00:00
|
|
|
|
2007-04-27 08:05:58 +00:00
|
|
|
friend class KeyMap;
|
2001-11-30 13:25:38 +00:00
|
|
|
|
2007-09-17 22:51:03 +00:00
|
|
|
KeySequence() : stdmap(0), curmap(0), deleted_(true) {}
|
2000-02-04 09:38:32 +00:00
|
|
|
///
|
2007-04-27 08:19:12 +00:00
|
|
|
KeySequence(KeyMap * std, KeyMap * cur)
|
2002-06-18 15:44:30 +00:00
|
|
|
: stdmap(std), curmap(cur), deleted_(false) {}
|
2000-02-04 09:38:32 +00:00
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
/**
|
|
|
|
* Add a key to the key sequence and look it up in the curmap
|
|
|
|
* if the latter is defined.
|
2002-06-18 15:44:30 +00:00
|
|
|
* @param keysym the key to add
|
2001-11-30 13:25:38 +00:00
|
|
|
* @param mod modifier mask
|
2001-12-10 15:59:20 +00:00
|
|
|
* @param nmod which modifiers to mask out for equality test
|
2001-11-30 13:25:38 +00:00
|
|
|
* @return the action matching this key sequence or LFUN_UNKNOWN_ACTION
|
|
|
|
*/
|
2007-10-02 21:51:54 +00:00
|
|
|
FuncRequest const & addkey(KeySymbol const & keysym, KeyModifier mod,
|
|
|
|
KeyModifier nmod = NoModifier);
|
2001-11-30 13:25:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a sequence of keys from a string to the sequence
|
|
|
|
* @return string::npos if OK, else error position in string
|
|
|
|
*
|
|
|
|
* Keys in the string must be separated with whitespace;
|
2002-06-18 15:44:30 +00:00
|
|
|
* Use the keysym names used by XStringToKeysym, f.ex.
|
|
|
|
* "Space", "a", "Return", ...
|
2001-11-30 13:25:38 +00:00
|
|
|
* Prefixes are S-, C-, M- for shift, control, meta
|
2002-06-18 15:44:30 +00:00
|
|
|
* Prefixes can also be ignored by using the Tilde "~"
|
|
|
|
* f.ex.: "~S-Space".
|
2001-11-30 13:25:38 +00:00
|
|
|
*/
|
2007-04-27 08:19:12 +00:00
|
|
|
size_t parse(std::string const & s);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2007-10-20 20:28:05 +00:00
|
|
|
enum outputFormat {
|
|
|
|
Portable, //< use a more portable format
|
|
|
|
ForGui, //< use platform specific translations and special characters
|
|
|
|
BindFile //< the format used in lyx bind files
|
|
|
|
};
|
2017-07-03 17:45:58 +00:00
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
/**
|
|
|
|
* Return the current sequence as a string.
|
2007-10-20 20:28:05 +00:00
|
|
|
* @param format output format
|
2001-11-30 13:25:38 +00:00
|
|
|
* @see parse()
|
|
|
|
*/
|
2007-10-20 20:28:05 +00:00
|
|
|
docstring const print(outputFormat format) const;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
/**
|
|
|
|
* Return the current sequence and available options as
|
|
|
|
* a string. No options are added if no curmap kb map exists.
|
2007-05-28 22:27:45 +00:00
|
|
|
* @param forgui true if the string should use translations and
|
|
|
|
* special characters.
|
2001-11-30 13:25:38 +00:00
|
|
|
*/
|
2007-01-04 17:10:24 +00:00
|
|
|
docstring const printOptions(bool forgui) const;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
/// Reset sequence to become "deleted"
|
2000-02-04 09:38:32 +00:00
|
|
|
void reset();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
/// clear in full
|
|
|
|
void clear();
|
|
|
|
|
2008-07-22 08:29:50 +00:00
|
|
|
/// remove last key in sequence
|
|
|
|
void removeKey();
|
|
|
|
|
2007-04-27 08:19:12 +00:00
|
|
|
bool deleted() const { return deleted_; }
|
2001-11-30 13:25:38 +00:00
|
|
|
|
|
|
|
/// length of sequence
|
2007-04-27 08:19:12 +00:00
|
|
|
size_t length() const { return sequence.size(); }
|
2001-11-30 13:25:38 +00:00
|
|
|
|
2009-04-02 15:56:12 +00:00
|
|
|
private:
|
2000-02-04 09:38:32 +00:00
|
|
|
/// Keymap to use if a new sequence is starting
|
2007-04-27 08:05:58 +00:00
|
|
|
KeyMap * stdmap;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
/// Keymap to use for the next key
|
2007-04-27 08:05:58 +00:00
|
|
|
KeyMap * curmap;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
/**
|
2002-06-18 15:44:30 +00:00
|
|
|
* Array holding the current key sequence as KeySyms.
|
2002-08-11 16:27:10 +00:00
|
|
|
* If sequence[length - 1] < 0xff it can be used as ISO8859 char
|
2001-11-30 13:25:38 +00:00
|
|
|
*/
|
2007-04-27 08:19:12 +00:00
|
|
|
Sequence sequence;
|
2002-06-18 15:44:30 +00:00
|
|
|
|
2007-10-02 21:51:54 +00:00
|
|
|
typedef std::pair<KeyModifier, KeyModifier> ModifierPair;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
/// modifiers for keys in the sequence
|
2007-10-02 21:51:54 +00:00
|
|
|
std::vector<ModifierPair> modifiers;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
/// is keysequence deleted ?
|
|
|
|
bool deleted_;
|
2000-02-04 09:38:32 +00:00
|
|
|
};
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
#endif
|