kb3 patch from John

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3120 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2001-11-30 13:25:38 +00:00
parent 94b5a7b163
commit 39eec46bd3
14 changed files with 285 additions and 519 deletions

View File

@ -1,3 +1,18 @@
2001-11-26 John Levon <moz@compsoc.man.ac.uk>
* LyXAction.h:
* LyXAction.C:
* lyxfunc.h:
* lyxfunc.C:
* kbmap.h:
* kbmap.C:
* lyxrc.C:
* kbsequence.h:
* kbsequence.C: part re-write of old kb code
* Painter.C:
* WorkArea.C: remove Lgb_bug_find_hack
2001-11-30 José Matos <jamatos@fep.up.pt>
* buffer.C (makeDocBookFile): add a comment to point a hack.

View File

@ -445,7 +445,7 @@ LyXAction::LyXAction()
// Search for an existent pseudoaction, return LFUN_UNKNOWN_ACTION
// if it doesn't exist.
int LyXAction::searchActionArg(kb_action action, string const & arg) const
kb_action LyXAction::searchActionArg(kb_action action, string const & arg) const
{
arg_map::const_iterator pit = lyx_arg_map.find(action);
@ -473,7 +473,7 @@ int LyXAction::searchActionArg(kb_action action, string const & arg) const
<< action << '|'
<< arg << "] = " << aci->second << endl;
return aci->second;
return kb_action(aci->second);
}

View File

@ -83,7 +83,7 @@ public:
kb_action retrieveActionArg(int i, string & arg) const;
/// Search for an existent pseudoaction, return -1 if it doesn't exist.
int searchActionArg(kb_action action, string const & arg) const;
kb_action searchActionArg(kb_action action, string const & arg) const;
/// Check if a value is a pseudo-action.
bool isPseudoAction(int) const;

View File

@ -47,18 +47,8 @@ Painter::Painter(WorkArea & wa)
/* Basic drawing routines */
extern bool Lgb_bug_find_hack;
PainterBase & Painter::point(int x, int y, LColor::color c)
{
if (lyxerr.debugging(Debug::GUI)) {
if (!Lgb_bug_find_hack)
lyxerr << "point not called from "
"workarea::workhandler\n";
lyxerr[Debug::INFO] << "Painter drawable: "
<< owner.getPixmap() << endl;
}
XDrawPoint(display, owner.getPixmap(),
lyxColorHandler->getGCForeground(c), x, y);
return *this;
@ -70,14 +60,6 @@ PainterBase & Painter::line(int x1, int y1, int x2, int y2,
enum line_style ls,
enum line_width lw)
{
if (lyxerr.debugging(Debug::GUI)) {
if (!Lgb_bug_find_hack)
lyxerr << "line not called from "
"workarea::workhandler\n";
lyxerr[Debug::INFO] << "Painter drawable: "
<< owner.getPixmap() << endl;
}
XDrawLine(display, owner.getPixmap(),
lyxColorHandler->getGCLinepars(ls, lw, col),
x1, y1, x2, y2);
@ -90,14 +72,6 @@ PainterBase & Painter::lines(int const * xp, int const * yp, int np,
enum line_style ls,
enum line_width lw)
{
if (lyxerr.debugging(Debug::GUI)) {
if (!Lgb_bug_find_hack)
lyxerr << "lines not called from "
"workarea::workhandler\n";
lyxerr[Debug::INFO] << "Painter drawable: "
<< owner.getPixmap() << endl;
}
#ifndef HAVE_AUTO_PTR
XPoint * points = new XPoint[np];
#else
@ -124,14 +98,6 @@ PainterBase & Painter::rectangle(int x, int y, int w, int h,
enum line_style ls,
enum line_width lw)
{
if (lyxerr.debugging(Debug::GUI)) {
if (!Lgb_bug_find_hack)
lyxerr << "rectangle not called from "
"workarea::workhandler\n";
lyxerr << "Painter drawable: "
<< owner.getPixmap() << endl;
}
XDrawRectangle(display, owner.getPixmap(),
lyxColorHandler->getGCLinepars(ls, lw, col),
x, y, w, h);
@ -142,14 +108,6 @@ PainterBase & Painter::rectangle(int x, int y, int w, int h,
PainterBase & Painter::fillRectangle(int x, int y, int w, int h,
LColor::color col)
{
if (lyxerr.debugging(Debug::GUI)) {
if (!Lgb_bug_find_hack)
lyxerr << "fillrectangle not called from "
"workarea::workhandler\n";
lyxerr << "Painter drawable: "
<< owner.getPixmap() << endl;
}
XFillRectangle(display, owner.getPixmap(),
lyxColorHandler->getGCForeground(col), x, y, w, h);
return *this;
@ -159,13 +117,6 @@ PainterBase & Painter::fillRectangle(int x, int y, int w, int h,
PainterBase & Painter::fillPolygon(int const * xp, int const * yp, int np,
LColor::color col)
{
if (lyxerr.debugging(Debug::GUI)) {
if (!Lgb_bug_find_hack)
lyxerr <<"fillpolygon not called from "
"workarea::workhandler\n";
lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
}
#ifndef HAVE_AUTO_PTR
XPoint * points = new XPoint[np];
#else
@ -190,13 +141,6 @@ PainterBase & Painter::arc(int x, int y,
unsigned int w, unsigned int h,
int a1, int a2, LColor::color col)
{
if (lyxerr.debugging(Debug::GUI)) {
if (!Lgb_bug_find_hack)
lyxerr << "arc not called from "
"workarea::workhandler\n";
lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
}
XDrawArc(display, owner.getPixmap(),
lyxColorHandler->getGCForeground(col),
x, y, w, h, a1, a2);
@ -210,13 +154,6 @@ PainterBase & Painter::segments(int const * x1, int const * y1,
LColor::color col,
enum line_style ls, enum line_width lw)
{
if (lyxerr.debugging(Debug::GUI)) {
if (!Lgb_bug_find_hack)
lyxerr << "segments not called from "
"workarea::workhandler\n";
lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
}
#ifndef HAVE_AUTO_PTR
XSegment * s= new XSegment[ns];
#else
@ -239,13 +176,6 @@ PainterBase & Painter::segments(int const * x1, int const * y1,
PainterBase & Painter::pixmap(int x, int y, int w, int h, Pixmap bitmap)
{
if (lyxerr.debugging(Debug::GUI)) {
if (!Lgb_bug_find_hack)
lyxerr << "workAreaExpose not called from "
"workarea::workhandler\n";
lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
}
XGCValues val;
val.function = GXcopy;
GC gc = XCreateGC(display, owner.getPixmap(),
@ -301,12 +231,6 @@ PainterBase & Painter::text(int x, int y, char const * s, size_t ls,
return *this;
}
if (lyxerr.debugging(Debug::GUI)) {
if (!Lgb_bug_find_hack)
lyxerr << "text not called from "
"workarea::workhandler\n";
lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
}
GC gc = lyxColorHandler->getGCForeground(f.realColor());
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
lyxfont::XSetFont(display, gc, f);
@ -344,12 +268,6 @@ PainterBase & Painter::text(int x, int y, char const * s, size_t ls,
PainterBase & Painter::text(int x, int y, XChar2b const * s, int ls,
LyXFont const & f)
{
if (lyxerr.debugging(Debug::GUI)) {
if (!Lgb_bug_find_hack)
lyxerr << "text not called from "
"workarea::workhandler\n";
lyxerr << "Painter drawable: " << owner.getPixmap() << endl;
}
GC gc = lyxColorHandler->getGCForeground(f.realColor());
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
lyxfont::XSetFont(display, gc, f);

View File

@ -325,8 +325,6 @@ void WorkArea::scroll_cb(FL_OBJECT * ob, long)
}
bool Lgb_bug_find_hack = false;
int WorkArea::work_area_handler(FL_OBJECT * ob, int event,
FL_Coord, FL_Coord ,
int key, void * xev)
@ -347,9 +345,7 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event,
return 1;
lyxerr[Debug::WORKAREA] << "Workarea event: DRAW" << endl;
area->createPixmap(area->workWidth(), area->height());
Lgb_bug_find_hack = true;
area->workAreaExpose();
Lgb_bug_find_hack = false;
break;
case FL_PUSH:
if (!ev || ev->xbutton.button == 0) break;

View File

@ -439,7 +439,7 @@ int Menubar::Pimpl::create_submenu(Window win, LyXView * view,
// Get the keys bound to this action, but keep only the
// first one later
string const accel = toplevel_keymap->findbinding(item.action());
string const accel = toplevel_keymap->findbinding(kb_action(item.action()));
// Build the menu label from all the info
string label = item.label();

View File

@ -1,8 +1,8 @@
/* This file is part of
* ======================================================
*
* ======================================================
*
* LyX, The Document Processor
*
*
* Copyright 1995 Matthias Ettrich
* Copyright 1995-2001 The LyX Team.
*
@ -10,7 +10,6 @@
#include <config.h>
//#include <cstring>
#include <X11/Xlib.h>
#ifdef __GNUG__
@ -24,25 +23,13 @@
using std::endl;
// The only modifiers that we handle. We want to throw away things
// like NumLock.
// like NumLock.
enum { ModsMask = ShiftMask | ControlMask | Mod1Mask };
// === static functions ===================================================
/* ---F+------------------------------------------------------------------ *\
Function : printKeysym
Called by : kb_sequence::print and printKeyMap. RVDK_PATCH_5
Purpose : prints a keysym, including modifiers.
Parameters: key - keysym
mod - modifiers
buf - string where the result goes
maxlen - length of string (including '\0')
Returns : length of printed string if ok, 0 otherwise.
\* ---F------------------------------------------------------------------- */
void printKeysym(unsigned int key, unsigned int mod, string & buf)
string const kb_keymap::printKeysym(unsigned int key, unsigned int mod)
{
string buf;
mod &= ModsMask;
char const * const s = XKeysymToString(key);
@ -51,27 +38,40 @@ void printKeysym(unsigned int key, unsigned int mod, string & buf)
if (mod & ControlMask) buf += "C-";
if (mod & Mod1Mask) buf += "M-";
if (s) buf += s;
return buf;
}
/* ---F+------------------------------------------------------------------ *\
Function : printKeyTab
Called by : kb_keymap::print
Purpose : print the keysyms found in the given key table. RVDK_PATCH_5
Parameters: tabPt - keytable pointer
buf - string where the result goes
maxLen - length of string (including '\0')
Returns : length of printed string.
\* ---F------------------------------------------------------------------- */
void kb_keymap::printKey(kb_key const & key, string & buf)
char kb_keymap::getiso(unsigned int c)
{
printKeysym(key.code, key.mod & 0xffff, buf);
switch (c & 0x0000FF00) {
// latin 1 byte 3 = 0
case 0x00000000: break;
// latin 2 byte 3 = 1
case 0x00000100:
// latin 3 byte 3 = 2
case 0x00000200:
// latin 4 byte 3 = 3
case 0x00000300:
// latin 8 byte 3 = 18 (0x12)
case 0x00001200:
// latin 9 byte 3 = 19 (0x13)
case 0x00001300:
c &= 0x000000FF;
break;
default:
c = 0;
}
return c;
}
string const kb_keymap::printKey(kb_key const & key) const
{
return printKeysym(key.code, key.mod & 0xffff);
}
// This binds a key to an action
string::size_type kb_keymap::bind(string const & seq, int action)
string::size_type kb_keymap::bind(string const & seq, kb_action action)
{
if (lyxerr.debugging(Debug::KBMAP)) {
lyxerr << "BIND: Sequence `"
@ -79,39 +79,30 @@ string::size_type kb_keymap::bind(string const & seq, int action)
<< action << "'" << endl;
}
kb_sequence k;
kb_sequence k(0, 0);
string::size_type const res = k.parse(seq);
if (res == string::npos) {
defkey(&k, action);
} else
} else {
lyxerr[Debug::KBMAP] << "Parse error at position " << res
<< " in key sequence '" << seq << "'."
<< endl;
}
return res;
}
/* ---F+------------------------------------------------------------------ *\
Function : kb_keymap::lookup
Called by : [user], kb_sequence::add()
Purpose : look up a key press in a given keymap
Parameters: key - the keysym of the key press
mod - the modifier mask of the keypress
seq - the key-sequence retrieved so far
Returns : user defined action; 0 for prefix key, -1 if key not found
\* ---F------------------------------------------------------------------- */
int kb_keymap::lookup(unsigned int key,
kb_action kb_keymap::lookup(unsigned int key,
unsigned int mod, kb_sequence * seq) const
{
if (table.empty()) {
seq->curmap = seq->stdmap;
seq->delseq();
return -1;
seq->mark_deleted();
return LFUN_UNKNOWN_ACTION;
}
//unsigned int msk1, msk0;
//suppress modifier bits we do not handle
mod &= ModsMask;
@ -120,15 +111,15 @@ int kb_keymap::lookup(unsigned int key,
unsigned int const msk1 = cit->mod & 0xffff;
unsigned int const msk0 = (cit->mod >> 16) & 0xffff;
if (cit->code == key && (mod & ~msk0) == msk1) {
// math found:
// match found
if (cit->table.get()) {
// this is a prefix key - set new map
seq->curmap = cit->table.get();
return 0;
return LFUN_PREFIX;
} else {
// final key - reset map
seq->curmap = seq->stdmap;
seq->delseq();
seq->mark_deleted();
return cit->action;
}
}
@ -136,105 +127,73 @@ int kb_keymap::lookup(unsigned int key,
// error - key not found:
seq->curmap = seq->stdmap;
seq->delseq();
return -1;
seq->mark_deleted();
return LFUN_UNKNOWN_ACTION;
}
/* ---F+------------------------------------------------------------------ *\
Function : kb_keymap::print
Called by : [user]
Purpose : Prints all the available keysyms. RVDK_PATCH_5
Parameters: buf - string where output goes.
maxLen - available length in string, including `\0'.
Returns : updated maxLen.
\* ---F------------------------------------------------------------------- */
void kb_keymap::print(string & buf) const
string const kb_keymap::print() const
{
string buf;
for (Table::const_iterator cit = table.begin();
cit != table.end(); ++cit) {
printKey((*cit), buf);
buf += printKey((*cit));
buf += ' ';
}
return buf;
}
/* ---F+------------------------------------------------------------------ *\
Function : kb_keymap::defkey
Called by : [user]
Purpose : define an action for a key sequence
Parameters: seq - the key sequence
action - the action to be defined
idx - recursion depth
Returns : 0 if ok.
\* ---F------------------------------------------------------------------- */
int kb_keymap::defkey(kb_sequence * seq, int action, int idx /*= 0*/)
void kb_keymap::defkey(kb_sequence * seq, kb_action action, unsigned int r)
{
unsigned int const code = seq->sequence[idx];
if (code == NoSymbol) return -1;
unsigned int const code = seq->sequence[r];
if (code == NoSymbol) return;
unsigned int const modmsk = seq->modifiers[idx];
unsigned int const modmsk = seq->modifiers[r];
// --- check if key is already there --------------------------------
if (table.size() != 0) { // without this I get strange crashes
Table::iterator end = table.end();
for (Table::iterator it = table.begin(); it != end; ++it) {
// check if key is already there
for (Table::iterator it = table.begin(); it != table.end(); ++it) {
if (code == it->code && modmsk == it->mod) {
// overwrite binding
if (idx + 1 == seq->length) {
string buf;
seq->print(buf, true);
if (r + 1 == seq->length()) {
lyxerr[Debug::KBMAP]
<< "Warning: New binding for '"
<< buf
<< seq->print()
<< "' is overriding old binding..."
<< endl;
if (it->table.get()) {
if (it->table.get()) {
it->table.reset(0);
}
it->action = action;
return 0;
return;
} else if (!it->table.get()) {
string buf;
seq->print(buf, true);
lyxerr << "Error: New binding for '" << buf
lyxerr << "Error: New binding for '" << seq->print()
<< "' is overriding old binding..."
<< endl;
return -1;
<< endl;
return;
} else {
return it->table->defkey(seq, action,
idx + 1);
it->table->defkey(seq, action, r + 1);
return;
}
}
}
}
Table::iterator newone = table.insert(table.end(), kb_key());
newone->code = code;
newone->mod = modmsk;
if (idx + 1 == seq->length) {
if (r + 1 == seq->length()) {
newone->action = action;
newone->table.reset(0);
return 0;
return;
} else {
newone->table.reset(new kb_keymap);
return newone->table->defkey(seq, action, idx + 1);
newone->table->defkey(seq, action, r + 1);
return;
}
}
string const kb_keymap::keyname(kb_key const & k)
{
string buf;
printKeysym(k.code, k.mod, buf);
return buf;
}
// Finds a key for a keyaction, if possible
string const kb_keymap::findbinding(int act, string const & prefix) const
string const kb_keymap::findbinding(kb_action act, string const & prefix) const
{
string res;
if (table.empty()) return res;
@ -245,15 +204,13 @@ string const kb_keymap::findbinding(int act, string const & prefix) const
if (cit->table.get()) {
res += cit->table->findbinding(act,
prefix
+ keyname((*cit))
+ printKey((*cit))
+ " ");
} else if (cit->action == act) {
res += "[";
res += prefix + keyname((*cit));
res += prefix + printKey((*cit));
res += "] ";
}
}
return res;
}
/* === End of File: kbmap.C ============================================== */

View File

@ -16,6 +16,8 @@
#include <list>
#include <boost/smart_ptr.hpp>
#include "commandtags.h"
#include "LString.h"
class kb_sequence;
@ -23,21 +25,40 @@ class kb_sequence;
/// Defines key maps and actions for key sequences
class kb_keymap {
public:
/** Bind a key-sequence to an action.
Returns 0 on success. Otherwise, position in string where
error occured. */
string::size_type bind(string const & seq, int action);
/**
* Bind a key sequence to an action.
* @return 0 on success, or position in string seq where error
* occurs.
*/
string::size_type bind(string const & seq, kb_action action);
///
void print(string & buf) const;
/// print all available keysyms
string const print() const;
/// Look up a key in the keymap
int lookup(unsigned int key,
unsigned int mod, kb_sequence * seq) const;
/**
* 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
*/
kb_action lookup(unsigned int key,
unsigned int mod, kb_sequence * seq) const;
/// Given an action, find all keybindings.
string const findbinding(int action,
string const findbinding(kb_action action,
string const & prefix = string()) const;
/**
* Returns a string of the given keysym, with modifiers.
* @param key the key
* @param mod the modifiers
*/
static string const printKeysym(unsigned int key, unsigned int mod);
/// return the ISO value of a keysym
static char getiso(unsigned int i);
private:
///
struct kb_key {
@ -51,19 +72,20 @@ private:
boost::shared_ptr<kb_keymap> table;
/// Action for !prefix keys
int action;
kb_action action;
};
/// Define a new key sequence
int defkey(kb_sequence * seq, int action, int idx = 0);
///
static string const keyname(kb_key const & k);
/**
* Define an action for a key sequence.
* @param r internal recursion level
*/
void defkey(kb_sequence * seq, kb_action action, unsigned int r = 0);
///
static
void printKey(kb_key const & key, string & buf);
///
/// Returns a string of the given key
string const printKey(kb_key const & key) const;
/// is the table empty ?
bool empty() const {
return table.empty();
}

View File

@ -1,8 +1,8 @@
/* This file is part of
* ======================================================
*
* ======================================================
*
* LyX, The Document Processor
*
*
* Copyright 1995 Matthias Ettrich
* Copyright 1995-2001 The LyX Team.
*
@ -25,87 +25,46 @@
using std::endl;
// The only modifiers that we handle. We want to throw away things
// like NumLock.
// like NumLock.
enum { ModsMask = ShiftMask | ControlMask | Mod1Mask };
// === static functions ===================================================
/* ---F+------------------------------------------------------------------ *\
Function : printKeysym
Called by : kb_sequence::print and printKeyMap. RVDK_PATCH_5
Purpose : prints a keysym, including modifiers.
Parameters: key - keysym
mod - modifiers
buf - string where the result goes
maxlen - length of string (including '\0')
Returns : length of printed string if ok, 0 otherwise.
\* ---F------------------------------------------------------------------- */
extern
void printKeysym(unsigned int key, unsigned int mod, string & buf);
// === kb_sequence methods ================================================
/* ---F+------------------------------------------------------------------ *\
Function : kb_sequence::addkey
Called by : [user]
Purpose : add a key to the sequence, look up in map and return action
Parameters: key - keysym of key
mod - modifier mask
nmod - modifier veto mask (unused now)
Returns : action or -1 if error (no map defined or key not found)
\* ---F------------------------------------------------------------------- */
int kb_sequence::addkey(unsigned int key,
unsigned int mod, unsigned int nmod /*= 0*/)
kb_action kb_sequence::addkey(unsigned int key, unsigned int mod)
{
//lyxerr << "kb_sequence::addkey: length is [" << length << "]\n"
// << "kb_sequence::addkey::key == [" << key << "]\n"
// << "kb_sequence::addkey::mod == [" << mod << "]" << endl;
if (length <= 0) {
length = 0;
// adding a key to a deleted sequence
// starts a new sequence
if (deleted_) {
deleted_ = false;
length_ = 0;
sequence.clear();
modifiers.clear();
}
modifiers.push_back(mod + (nmod << 16));
modifiers.push_back(mod);
sequence.push_back(key);
++length;
++length_;
if (curmap)
if (curmap) {
return curmap->lookup(key, mod, this);
}
return -1;
return LFUN_UNKNOWN_ACTION;
}
/* ---F+------------------------------------------------------------------ *\
Function : kb_sequence::parse
Called by : [user]
Purpose : parse a string that holds a key sequence and add the keys
Parameters: s - string holding the key sequence
Returns : string::npos if ok, error pos if error
Note : Keys must be separated with whitespace;
Use the keysym names used by XStringToKeysym
Prefixes are S-, C-, M- for shift, control, meta
\* ---F------------------------------------------------------------------- */
string::size_type kb_sequence::parse(string const & s)
{
if (s.empty()) return 1;
string::size_type i = 0;
unsigned int mod = 0, nmod = 0;
unsigned int mod = 0;
while (i < s.length()) {
if (s[i] == ' ')
++i;
if (i >= s.length())
break;
if (i + 1 < s.length() && s[i + 1] == '-') {
if (i + 1 < s.length() && s[i + 1] == '-') {
switch (s[i]) {
case 's': case 'S':
mod |= ShiftMask;
@ -126,15 +85,12 @@ string::size_type kb_sequence::parse(string const & s)
&& s[i + 2] == '-') {
switch (s[i + 1]) {
case 's': case 'S':
nmod |= ShiftMask;
i += 3;
continue;
case 'c': case 'C':
nmod |= ControlMask;
i += 3;
continue;
case 'm': case 'M':
nmod |= Mod1Mask;
i += 3;
continue;
default:
@ -155,14 +111,13 @@ string::size_type kb_sequence::parse(string const & s)
}
i = j;
addkey(key, mod, nmod);
addkey(key, mod);
mod = 0;
nmod = 0;
}
}
// empty sequence?
if (!length)
if (!length_)
return 0;
// everything is fine
@ -170,103 +125,53 @@ string::size_type kb_sequence::parse(string const & s)
}
/* ---F+------------------------------------------------------------------ *\
Function : kb_sequence::print
Called by : [user]
Purpose : print the currently defined sequence into a string
Parameters: buf - string where the result goes
when_defined - only print when sequence is real: length > 0.
Returns : 0, if ok, -1 if string too long
\* ---F------------------------------------------------------------------- */
int kb_sequence::print(string & buf, bool when_defined) const
string const kb_sequence::print() const
{
//lyxerr << "kb_sequence::print: length is [" << length << "]" << endl;
KeySym key;
unsigned int mod;
int l = length;
if (l < 0 && !when_defined ) l = -l;
for (int i = 0; i < l; ++i) {
key = sequence[i];
mod = modifiers[i] & 0xffff;
//lyxerr << "kb_sequence::sequence[" << i << "] == [" << key << "]\n"
// << "kb_sequence::modifiers[" << i << "] == [" << mod << "]"
// << endl;
string buf;
printKeysym(key, mod, buf); // RVDK_PATCH_5
if (deleted_)
return buf;
for (std::vector<unsigned int>::size_type i = 0; i < length_; ++i) {
buf += kb_keymap::printKeysym(sequence[i], modifiers[i] & 0xffff);
if (i + 1 < l) { // append a blank
// append a blank
if (i + 1 < length_) {
buf += ' ';
}
}
return 0;
return buf;
}
/* ---F+------------------------------------------------------------------ *\
Function : kb_sequence::printOptions
Called by : [user]
Purpose : print the available key options from the current state in the
sequence. RVDK_PATCH_5
Parameters: buf - string where the result goes
maxlen - length of string (including '\0')
Returns : 0, if ok, -1 if string too long
\* ---F------------------------------------------------------------------- */
int kb_sequence::printOptions(string & buf) const
string const kb_sequence::printOptions() const
{
print(buf, true);
string buf;
buf += print();
if (!curmap) return -1;
if (!curmap)
return buf;
buf += _(" options: ");
curmap->print(buf);
return 0;
buf += curmap->print();
return buf;
}
/* ---F+------------------------------------------------------------------ *\
Function : kb_sequence::delseq
Called by : [user]
Purpose : mark the sequence as deleted
Parameters: none
Returns : nothing
\* ---F------------------------------------------------------------------- */
void kb_sequence::delseq()
void kb_sequence::mark_deleted()
{
// negative length marks sequence as deleted, but we can still
// print() it or retrieve the last char using getiso()
length = -length;
deleted_ = true;
}
/* ---F+------------------------------------------------------------------ *\
Function : kb_sequence::getsym
Called by : [user], getiso
Purpose : get the keysym of the last key in sequence
Parameters: none
Returns : keysym
\* ---F------------------------------------------------------------------- */
unsigned int kb_sequence::getsym() const
{
int l = length;
if (l == 0) return NoSymbol;
if (l < 0) l = -l;
return sequence[l - 1];
if (length_ == 0) return NoSymbol;
return sequence[length_ - 1];
}
/* ---F+------------------------------------------------------------------ *\
Function : kb_sequence::getiso
Called by : [user]
Purpose : return iso character code of last key, if any
Parameters: none
Returns : iso code or 0 if none
\* ---F------------------------------------------------------------------- */
char kb_sequence::getiso() const
{
unsigned int const c = getsym();
@ -274,47 +179,20 @@ char kb_sequence::getiso() const
lyxerr[Debug::KBMAP] << "Raw keysym: "
<< std::hex << c << std::dec << endl;
lyxerr[Debug::KBMAP] << "byte 3: "
<< std::hex << (c & 0x0000FF00) << std::dec
<< std::hex << (c & 0xff00) << std::dec
<< endl;
switch (c & 0x0000FF00) {
// latin 1 byte 3 = 0
case 0x00000000:
return c;
// latin 2 byte 3 = 1
case 0x00000100:
// latin 3 byte 3 = 2
case 0x00000200:
// latin 4 byte 3 = 3
case 0x00000300:
// latin 8 byte 3 = 18 (0x12)
case 0x00001200:
// latin 9 byte 3 = 19 (0x13)
case 0x00001300:
return c & 0x000000FF;
default:
return '\0';
}
// not a latin char we know of
// Yes but this is already handled above (JMarc)
//return '\0';
return kb_keymap::getiso(c);
}
/* ---F+------------------------------------------------------------------ *\
Function : kb_sequence::reset
Called by : [user]
Purpose : reset sequence to initial state. RVDK_PATCH_5
Parameters: none
Returns : void
\* ---F------------------------------------------------------------------- */
void kb_sequence::reset()
{
delseq();
mark_deleted();
curmap = stdmap;
if (length > 0) length = -length;
}
/* === End of File: kbmap.C ============================================== */
void kb_sequence::clear()
{
length_ = 0;
reset();
}

View File

@ -1,10 +1,9 @@
// -*- C++ -*-
/* ======================================================================= *\
File : kbmap.h, kbmap.h,v 1.3 1996/12/10 04:35:57 larsbj Exp
Author : chb, 30.Oct.1995
Docu : see kbmap.C
Purpose: class definitions for XKeyEvent keymap handling
\* ==================================================================== */
/**
* \file kbsequence.h
* Copyright 2001 the LyX Team
* Read the file COPYING
*/
#ifndef KBSEQUENCE_H
#define KBSEQUENCE_H
@ -16,57 +15,96 @@
#include <vector>
#include "LString.h"
#include "commandtags.h"
class kb_keymap;
/// Holds a key sequence and the current and standard keymaps
class kb_sequence {
public:
///
kb_sequence() {
stdmap = curmap = 0;
length = 0;
}
/** Add a key to the key sequence and look it up in the curmap
if the latter is defined. */
int addkey(unsigned int key, unsigned int mod, unsigned int nmod = 0);
friend class kb_keymap;
///
int print(string & buf, bool when_defined = false) const;
///
int printOptions(string & buf) const;
/// Make length negative to mark the sequence as deleted
void delseq();
kb_sequence(kb_keymap * std, kb_keymap * cur)
: stdmap(std), curmap(cur), length_(0), deleted_(false) {}
///
char getiso() const;
///
unsigned int getsym() const;
///
void reset();
///
/**
* Add a key to the key sequence and look it up in the curmap
* if the latter is defined.
* @param mod modifier mask
* @return the action matching this key sequence or LFUN_UNKNOWN_ACTION
*/
kb_action addkey(unsigned int key, unsigned int mod);
/**
* 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;
* Use the keysym names used by XStringToKeysym
* Prefixes are S-, C-, M- for shift, control, meta
*/
string::size_type parse(string const & s);
/**
* Return the current sequence as a string.
* @see parse()
*/
string const print() const;
/**
* Return the current sequence and available options as
* a string. No options are added if no curmap kb map exists.
*/
string const printOptions() const;
/// Mark the sequence as deleted.
void mark_deleted();
/// Return the ISO value of the last keysym in sequence, or 0
char getiso() const;
/// Reset sequence to become "deleted"
void reset();
/// clear in full
void clear();
bool deleted() const {
return deleted_;
}
/// length of sequence
std::vector<unsigned int>::size_type length() const {
return length_;
}
/// Keymap to use if a new sequence is starting
kb_keymap * stdmap;
/// Keymap to use for the next key
kb_keymap * curmap;
/** Array holding the current key sequence.
If sequence[length-1] < 0xff it can be used as ISO8859 char */
private:
/// get the keysym of last in sequence
unsigned int getsym() const;
/**
* Array holding the current key sequence.
* If sequence[length-1] < 0xff it can be used as ISO8859 char
*/
std::vector<unsigned int> sequence;
///
/// modifiers for keys in the sequence
std::vector<unsigned int> modifiers;
/// Current length of key sequence
int length;
std::vector<unsigned int>::size_type length_;
/// is keysequence deleted ?
bool deleted_;
};
#endif

View File

@ -160,12 +160,13 @@ bool LyXFunc::show_sc = true;
LyXFunc::LyXFunc(LyXView * o)
: owner(o)
: owner(o),
keyseq(toplevel_keymap.get(), toplevel_keymap.get()),
cancel_meta_seq(toplevel_keymap.get(), toplevel_keymap.get())
{
meta_fake_bit = 0;
lyx_dead_action = LFUN_NOACTION;
lyx_calling_dead_action = LFUN_NOACTION;
setupLocalKeymap();
}
@ -204,14 +205,15 @@ void LyXFunc::handleKeyFunc(kb_action action)
{
char c = keyseq.getiso();
if (keyseq.length != -1) c = 0;
if (keyseq.length() > 1) {
c = 0;
}
owner->getIntl()->getTrans()
.deadkey(c, get_accent(action).accent, TEXT(false));
// Need to reset, in case the minibuffer calls these
// Need to clear, in case the minibuffer calls these
// actions
keyseq.reset();
keyseq.length = 0;
keyseq.clear();
// copied verbatim from do_accent_char
owner->view()->update(TEXT(false),
BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
@ -281,14 +283,15 @@ void LyXFunc::processKeySym(KeySym keysym, unsigned int state)
// Dont remove this unless you know what you are doing.
meta_fake_bit = 0;
if (action == 0) action = LFUN_PREFIX;
// can this happen now ?
if (action == LFUN_NOACTION) {
action = LFUN_PREFIX;
}
if (lyxerr.debugging(Debug::KEY)) {
string buf;
keyseq.print(buf);
lyxerr << "Key [action="
<< action << "]["
<< buf << "]"
<< keyseq.print() << "]"
<< endl;
}
@ -296,13 +299,11 @@ void LyXFunc::processKeySym(KeySym keysym, unsigned int state)
// why not return already here if action == -1 and
// num_bytes == 0? (Lgb)
if (keyseq.length > 1 || keyseq.length < -1) {
string buf;
keyseq.print(buf);
owner->message(buf);
if (keyseq.length() > 1 && !keyseq.deleted()) {
owner->message(keyseq.print());
}
if (action == -1) {
if (action == LFUN_UNKNOWN_ACTION) {
// It is unknown, but what if we remove all
// the modifiers? (Lgb)
action = keyseq.addkey(keysym, 0);
@ -312,35 +313,18 @@ void LyXFunc::processKeySym(KeySym keysym, unsigned int state)
<< "Action now set to ["
<< action << "]" << endl;
}
if (action == -1) {
if (action == LFUN_UNKNOWN_ACTION) {
owner->message(_("Unknown function."));
return;
}
}
if (action == LFUN_SELFINSERT) {
// This is very X dependant.
// This is very X dependent.
unsigned int c = keysym;
switch (c & 0x0000FF00) {
// latin 1 byte 3 = 0
case 0x00000000: break;
// latin 2 byte 3 = 1
case 0x00000100:
// latin 3 byte 3 = 2
case 0x00000200:
// latin 4 byte 3 = 3
case 0x00000300:
// latin 8 byte 3 = 18 (0x12)
case 0x00001200:
// latin 9 byte 3 = 19 (0x13)
case 0x00001300:
c &= 0x000000FF;
break;
default:
c = 0;
break;
}
c = kb_keymap::getiso(c);
if (c > 0)
argument = static_cast<char>(c);
lyxerr[Debug::KEY] << "SelfInsert arg[`"
@ -817,7 +801,7 @@ string const LyXFunc::dispatch(int ac,
if (owner->view()->available() && owner->view()->theLockingInset()) {
UpdatableInset::RESULT result;
if ((action > 1) || ((action == LFUN_UNKNOWN_ACTION) &&
(keyseq.length >= -1)))
(!keyseq.deleted())))
{
if ((action==LFUN_UNKNOWN_ACTION) && argument.empty()){
argument = keyseq.getiso();
@ -994,9 +978,7 @@ string const LyXFunc::dispatch(int ac,
owner->view()->update(TEXT(),
BufferView::SELECT|BufferView::FITCUR);
}
string buf;
keyseq.print(buf, true);
owner->message(buf);
owner->message(keyseq.print());
}
break;
@ -1024,9 +1006,7 @@ string const LyXFunc::dispatch(int ac,
case LFUN_META_FAKE: // RVDK_PATCH_5
{
meta_fake_bit = Mod1Mask;
string buf;
keyseq.print(buf, true);
setMessage(buf); // RVDK_PATCH_5
setMessage(keyseq.print());
}
break;
@ -1375,9 +1355,7 @@ string const LyXFunc::dispatch(int ac,
case LFUN_NOTIFY:
{
string buf;
keyseq.print(buf);
dispatch_buffer = buf;
dispatch_buffer = keyseq.print();
lyxserver->notifyClient(dispatch_buffer);
}
break;
@ -1635,7 +1613,7 @@ exit_with_message:
// for it in minibuffer
string comname = lyxaction.getActionName(action);
int pseudoaction = action;
kb_action pseudoaction = action;
bool argsadded = false;
if (!argument.empty()) {
@ -2031,14 +2009,15 @@ void LyXFunc::initMiniBuffer()
// When meta-fake key is pressed, show the key sequence so far + "M-".
if (wasMetaKey()) {
keyseqStr();
text = keyseq.print();
text += "M-";
}
// Else, when a non-complete key sequence is pressed,
// show the available options.
else if (keyseqUncomplete())
text = keyseqOptions();
else if (keyseq.length() > 1) {
text = keyseq.printOptions();
}
// Else, show the buffer state.
else if (owner->view()->available()) {

View File

@ -55,17 +55,6 @@ public:
/// The last key was meta
bool wasMetaKey() const;
// These can't be global because are part of the
// internal state (ale970227)
/// Get the current keyseq string
string const keyseqStr() const;
/// Is the key sequence uncomplete?
bool keyseqUncomplete() const;
/// get options for the current keyseq
string const keyseqOptions() const;
/// True if lyxfunc reports an error
bool errorStat() const { return errorstat; }
/// Buffer to store result messages
@ -141,33 +130,6 @@ bool LyXFunc::wasMetaKey() const
}
inline
string const LyXFunc::keyseqStr() const
{
// Why not just remove this function
string text;
keyseq.print(text, true);
return text;
}
inline
string const LyXFunc::keyseqOptions() const
{
// Why not just remove this function
string text;
keyseq.printOptions(text);
return text;
}
inline
bool LyXFunc::keyseqUncomplete() const
{
return (keyseq.length > 0);
}
inline
void LyXFunc::setHintMessage(bool hm)
{

View File

@ -736,7 +736,7 @@ int LyXRC::read(string const & filename)
<< cmd << "' Action `"
<< action << '\'' << endl;
}
res = toplevel_keymap->bind(seq, action);
res = toplevel_keymap->bind(seq, kb_action(action));
if (res != string::npos
&& lyxerr.debugging(Debug::LYXRC)) {
lexrc.printError(

View File

@ -2603,6 +2603,7 @@ int LyXTabular::Ascii(Buffer const * buf, ostream & os) const
InsetText * LyXTabular::GetCellInset(int cell) const
{
lyxerr << "LyXTabular::GetCellInset: cell=" << cell <<endl;
cur_cell = cell;
return & cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;
}