Here's a proper patch. It works for me. How I tested this : create a doc with an english par, russian par, and polish par.
Map Cyrillic_zhe to F11 Map lcaron to F10 Change english encoding to iso8859-15 (just to test the Eurosign) move to each par and check that F10,F11, etc. do the right thing. They do, but one problem : If I create a new paragraph, then apply a language change to it, it doesn't seem to work properly. I do not understand why. Anyway, I think I'm going to apply this unless there's strong objection. Kornel, if you can't insert Cyrillic_a with this patch, I feel farily sure it means that your Qt or system is simply buggy. Inserting Cyrillic_a is just fine for me. Still, -dbg key might still be interesting. This can get some real testing in pre2. btw, why don't we default to is8859-15 for most of the languages ? Comments ? regards john Index: BufferView.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.C,v retrieving revision 1.113 diff -u -r1.113 BufferView.C --- BufferView.C 21 Oct 2002 16:21:51 -0000 1.113 +++ BufferView.C 19 Dec 2002 22:03:58 -0000 @@ -933,6 +933,18 @@ } +Encoding const * BufferView::getEncoding() const +{ + LyXText * t = getLyXText(); + if (!t) + return 0; + + LyXCursor const & c= t->cursor; + LyXFont const font = c.par()->getFont(buffer()->params, c.pos()); + return font.language()->encoding(); +} + + void BufferView::haveSelection(bool sel) { pimpl_->workarea().haveSelection(sel); Index: BufferView.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.h,v retrieving revision 1.112 diff -u -r1.112 BufferView.h --- BufferView.h 1 Dec 2002 21:10:35 -0000 1.112 +++ BufferView.h 19 Dec 2002 22:04:00 -0000 @@ -30,6 +30,7 @@ class Painter; class UpdatableInset; class WordLangTuple; +class Encoding; /** * A buffer view encapsulates a view onto a particular @@ -123,6 +124,9 @@ int unlockInset(UpdatableInset * inset); /// unlock the currently locked inset void insetUnlock(); + + /// return the current encoding at the cursor + Encoding const * getEncoding() const; /// return the parent language of the given inset Language const * getParentLanguage(Inset * inset) const; Index: kbsequence.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/kbsequence.C,v retrieving revision 1.28 diff -u -r1.28 kbsequence.C --- kbsequence.C 1 Dec 2002 22:59:17 -0000 1.28 +++ kbsequence.C 19 Dec 2002 22:04:13 -0000 @@ -166,20 +166,6 @@ } -LyXKeySymPtr kb_sequence::getsym() const -{ - if (sequence.size() == 0) - return LyXKeySymPtr(LyXKeySymFactory::create()); - return sequence.back(); -} - - -char kb_sequence::getLastKeyEncoded() const -{ - return getsym()->getISOEncoded(); -} - - void kb_sequence::reset() { mark_deleted(); Index: kbsequence.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/kbsequence.h,v retrieving revision 1.13 diff -u -r1.13 kbsequence.h --- kbsequence.h 11 Aug 2002 16:27:09 -0000 1.13 +++ kbsequence.h 19 Dec 2002 22:04:15 -0000 @@ -71,13 +71,6 @@ /// Mark the sequence as deleted. void mark_deleted(); - /** - * 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; - /// Reset sequence to become "deleted" void reset(); @@ -100,9 +93,6 @@ kb_keymap * curmap; private: - /// get the keysym of last in sequence - LyXKeySymPtr getsym() const; - /** * Array holding the current key sequence as KeySyms. * If sequence[length - 1] < 0xff it can be used as ISO8859 char Index: lyxfunc.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v retrieving revision 1.388 diff -u -r1.388 lyxfunc.C --- lyxfunc.C 18 Dec 2002 14:24:31 -0000 1.388 +++ lyxfunc.C 19 Dec 2002 22:04:30 -0000 @@ -31,6 +31,7 @@ #include "gettext.h" #include "Lsstream.h" #include "trans_mgr.h" +#include "encoding.h" #include "layout.h" #include "bufferview_funcs.h" #include "frontends/LyXView.h" @@ -101,6 +102,7 @@ LyXFunc::LyXFunc(LyXView * o) : owner(o), + encoded_last_key(0), keyseq(toplevel_keymap.get(), toplevel_keymap.get()), cancel_meta_seq(toplevel_keymap.get(), toplevel_keymap.get()), meta_fake_bit(key_modifier::none) @@ -134,9 +136,9 @@ void LyXFunc::handleKeyFunc(kb_action action) { - char c = keyseq.getLastKeyEncoded(); + char c = encoded_last_key; - if (keyseq.length() > 1) { + if (keyseq.length()) { c = 0; } @@ -175,6 +177,10 @@ return; } + Encoding const * encoding = view()->getEncoding(); + + encoded_last_key = keysym->getISOEncoded(encoding ? encoding->Name() : ""); + // Do a one-deep top-level lookup for // cancel and meta-fake keys. RVDK_PATCH_5 cancel_meta_seq.reset(); @@ -239,16 +245,15 @@ } if (action == LFUN_SELFINSERT) { - char c = keysym->getISOEncoded(); - string argument; + if (encoded_last_key != 0) { + string arg; + arg += encoded_last_key; - // FIXME: why ... - if (c != 0) - argument = c; + dispatch(FuncRequest(view(), LFUN_SELFINSERT, arg)); - dispatch(FuncRequest(view(), LFUN_SELFINSERT, argument)); - lyxerr[Debug::KEY] << "SelfInsert arg[`" + lyxerr[Debug::KEY] << "SelfInsert arg[`" << argument << "']" << endl; + } } else { dispatch(action); } @@ -760,7 +765,7 @@ #endif if ((action == LFUN_UNKNOWN_ACTION) && argument.empty()) { - argument = keyseq.getLastKeyEncoded(); + argument = encoded_last_key; } // Undo/Redo is a bit tricky for insets. if (action == LFUN_UNDO) { Index: lyxfunc.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.h,v retrieving revision 1.52 diff -u -r1.52 lyxfunc.h --- lyxfunc.h 1 Dec 2002 22:59:17 -0000 1.52 +++ lyxfunc.h 19 Dec 2002 22:04:31 -0000 @@ -77,6 +77,10 @@ /// LyXView * owner; + + /// the last character added to the key sequence, in ISO encoded form + char encoded_last_key; + /// kb_sequence keyseq; /// Index: frontends/LyXKeySym.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/LyXKeySym.h,v retrieving revision 1.7 diff -u -r1.7 LyXKeySym.h --- frontends/LyXKeySym.h 12 Dec 2002 13:46:05 -0000 1.7 +++ frontends/LyXKeySym.h 19 Dec 2002 22:05:25 -0000 @@ -47,7 +47,7 @@ * This converts the LyXKeySym to a 8-bit encoded character. * This relies on user to use the right encoding. */ - virtual char getISOEncoded() const = 0; + virtual char getISOEncoded(string const & encoding) const = 0; }; Index: frontends/qt2/QLyXKeySym.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QLyXKeySym.C,v retrieving revision 1.16 diff -u -r1.16 QLyXKeySym.C --- frontends/qt2/QLyXKeySym.C 19 Dec 2002 18:44:31 -0000 1.16 +++ frontends/qt2/QLyXKeySym.C 19 Dec 2002 22:05:32 -0000 @@ -23,7 +23,75 @@ #include <qevent.h> #include <qtextcodec.h> +#include <map> + using std::endl; +using std::map; + +namespace { + +typedef map<string, QTextCodec *> EncodingMap; +EncodingMap encoding_map; + +char const encode(string const & encoding, QString const & str) +{ + QTextCodec * codec = 0; + + EncodingMap::const_iterator cit = encoding_map.find(encoding); + if (cit == encoding_map.end()) { + lyxerr[Debug::KEY] << "Unrecognised encoding " + << encoding << endl; + codec = QTextCodec::codecForLocale(); + } else { + codec = cit->second; + } + + if (!codec) { + lyxerr[Debug::KEY] << "No codec exists for encoding " + << encoding << endl; + codec = QTextCodec::codecForLocale(); + } + + lyxerr[Debug::KEY] << "Using codec " << fromqstr(codec->name()) << endl; + + if (!codec->canEncode(str)) { + lyxerr[Debug::KEY] << "Oof. Can't encode the text !" << endl; + return 0; + } + + QCString tmpstr = codec->fromUnicode(str); + char const * tmpcstr = tmpstr; + return tmpcstr[0]; +} + +} + + +void initEncodings() +{ + // when no document open + encoding_map[""] = QTextCodec::codecForLocale(); + + encoding_map["iso8859-1"] = QTextCodec::codecForName("ISO 8859-1"); + encoding_map["iso8859-2"] = QTextCodec::codecForName("ISO 8859-2"); + encoding_map["iso8859-3"] = QTextCodec::codecForName("ISO 8859-3"); + encoding_map["iso8859-4"] = QTextCodec::codecForName("ISO 8859-4"); + encoding_map["iso8859-5"] = QTextCodec::codecForName("ISO 8859-5"); + encoding_map["iso8859-6"] = QTextCodec::codecForName("ISO 8859-6"); + encoding_map["iso8859-7"] = QTextCodec::codecForName("ISO 8859-7"); + encoding_map["iso8859-9"] = QTextCodec::codecForName("ISO 8859-9"); + encoding_map["iso8859-15"] = QTextCodec::codecForName("ISO 8859-15"); + encoding_map["cp1255"] = QTextCodec::codecForName("CP 1255"); + encoding_map["cp1251"] = QTextCodec::codecForName("CP 1251"); + encoding_map["koi8"] = QTextCodec::codecForName("KOI8-R"); + encoding_map["koi8-u"] = QTextCodec::codecForName("KOI8-U"); + + // FIXME + encoding_map["tis620-0"] = 0; + encoding_map["pt154"] = 0; + + // There are lots more codecs in Qt too ... +} QLyXKeySym::QLyXKeySym() @@ -81,9 +149,9 @@ } -char QLyXKeySym::getISOEncoded() const +char QLyXKeySym::getISOEncoded(string const & encoding) const { - unsigned char const c = fromqstr(text_)[0]; + unsigned char const c = encode(encoding, text_); lyxerr[Debug::KEY] << "ISOEncoded returning value " << int(c) << endl; return c; } Index: frontends/qt2/QLyXKeySym.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QLyXKeySym.h,v retrieving revision 1.9 diff -u -r1.9 QLyXKeySym.h --- frontends/qt2/QLyXKeySym.h 12 Dec 2002 13:46:06 -0000 1.9 +++ frontends/qt2/QLyXKeySym.h 19 Dec 2002 22:05:32 -0000 @@ -58,7 +58,7 @@ * This converts the LyXKeySym to a 8-bit encoded character. * This relies on user to use the right encoding. */ - virtual char getISOEncoded() const; + virtual char getISOEncoded(string const & encoding) const; /// int key() const { return key_; Index: frontends/qt2/lyx_gui.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/lyx_gui.C,v retrieving revision 1.26 diff -u -r1.26 lyx_gui.C --- frontends/qt2/lyx_gui.C 18 Dec 2002 14:24:32 -0000 1.26 +++ frontends/qt2/lyx_gui.C 19 Dec 2002 22:05:38 -0000 @@ -79,10 +79,14 @@ // FIXME: wrong place ! LyXServer * lyxserver; +// in QLyXKeySym.C +extern void initEncodings(); + #ifdef Q_WS_X11 extern bool lyxX11EventFilter(XEvent * xev); #endif + class LQApplication : public QApplication { public: @@ -93,13 +97,16 @@ #endif }; + LQApplication::LQApplication(int &argc, char **argv) : QApplication( argc, argv ) {} + LQApplication::~LQApplication() {} + void lyx_gui::parse_init(int & argc, char * argv[]) { static LQApplication a(argc, argv); @@ -111,6 +118,8 @@ // needs to be done before reading lyxrc lyxrc.dpi = getDPI(); + + initEncodings(); } Index: frontends/xforms/XLyXKeySym.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/XLyXKeySym.C,v retrieving revision 1.5 diff -u -r1.5 XLyXKeySym.C --- frontends/xforms/XLyXKeySym.C 20 Oct 2002 01:48:28 -0000 1.5 +++ frontends/xforms/XLyXKeySym.C 19 Dec 2002 22:05:42 -0000 @@ -69,7 +69,7 @@ } -char XLyXKeySym::getISOEncoded() const +char XLyXKeySym::getISOEncoded(string const &) const { if (keysym_ == NoSymbol) { return 0; Index: frontends/xforms/XLyXKeySym.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/XLyXKeySym.h,v retrieving revision 1.5 diff -u -r1.5 XLyXKeySym.h --- frontends/xforms/XLyXKeySym.h 20 Oct 2002 01:48:28 -0000 1.5 +++ frontends/xforms/XLyXKeySym.h 19 Dec 2002 22:05:42 -0000 @@ -47,7 +47,7 @@ * This converts the LyXKeySym to a 8-bit encoded character. * This relies on user to use the right encoding. */ - virtual char getISOEncoded() const; + virtual char getISOEncoded(string const & encoding) const; /// unsigned int keysym() const { -- "ALL television is children's television." - Richard Adler