2000-02-04 09:38:32 +00:00
|
|
|
|
//<2F>-*- C++ -*-
|
2001-11-30 13:25:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file kbsequence.h
|
|
|
|
|
* Copyright 2001 the LyX Team
|
|
|
|
|
* Read the file COPYING
|
|
|
|
|
*/
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
|
|
#ifndef KBSEQUENCE_H
|
|
|
|
|
#define KBSEQUENCE_H
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
|
#pragma interface
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-05-26 17:33:14 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "frontends/key_state.h"
|
2002-06-18 15:44:30 +00:00
|
|
|
|
#include "frontends/LyXKeySym.h"
|
2000-02-04 09:38:32 +00:00
|
|
|
|
#include "LString.h"
|
2002-05-26 17:33:14 +00:00
|
|
|
|
#include <vector>
|
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
class kb_keymap;
|
|
|
|
|
|
|
|
|
|
/// Holds a key sequence and the current and standard keymaps
|
|
|
|
|
class kb_sequence {
|
|
|
|
|
public:
|
2002-06-18 15:44:30 +00:00
|
|
|
|
typedef std::vector<LyXKeySymPtr> KeySequence;
|
2002-08-11 16:27:10 +00:00
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
friend class kb_keymap;
|
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
///
|
2001-11-30 13:25:38 +00:00
|
|
|
|
kb_sequence(kb_keymap * std, kb_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
|
|
|
|
|
*/
|
2002-06-18 15:44:30 +00:00
|
|
|
|
int addkey(LyXKeySymPtr keysym, key_modifier::state mod,
|
|
|
|
|
key_modifier::state nmod = key_modifier::none);
|
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
|
|
|
|
*/
|
|
|
|
|
string::size_type parse(string const & s);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Return the current sequence as a string.
|
|
|
|
|
* @see parse()
|
|
|
|
|
*/
|
|
|
|
|
string const print() 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.
|
|
|
|
|
*/
|
|
|
|
|
string const printOptions() const;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
/// Mark the sequence as deleted.
|
|
|
|
|
void mark_deleted();
|
2001-05-16 07:53:23 +00:00
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* Return the value of the last keysym in the sequence
|
|
|
|
|
* in the local ISO encoding. If it does not encode
|
|
|
|
|
* in this encoding, return 0.
|
|
|
|
|
*/
|
|
|
|
|
char getLastKeyEncoded() 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();
|
|
|
|
|
|
|
|
|
|
bool deleted() const {
|
|
|
|
|
return deleted_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// length of sequence
|
2002-06-18 15:44:30 +00:00
|
|
|
|
KeySequence::size_type length() const {
|
|
|
|
|
return sequence.size();
|
2001-11-30 13:25:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
/// Keymap to use if a new sequence is starting
|
|
|
|
|
kb_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
|
|
|
|
|
kb_keymap * curmap;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
private:
|
|
|
|
|
/// get the keysym of last in sequence
|
2002-06-18 15:44:30 +00:00
|
|
|
|
LyXKeySymPtr getsym() const;
|
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
|
|
|
|
*/
|
2002-06-18 15:44:30 +00:00
|
|
|
|
KeySequence sequence;
|
|
|
|
|
|
|
|
|
|
typedef std::pair<key_modifier::state, key_modifier::state>
|
|
|
|
|
modifier_pair;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
|
/// modifiers for keys in the sequence
|
2002-05-26 17:33:14 +00:00
|
|
|
|
std::vector<modifier_pair> 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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|