]> git.lyx.org Git - features.git/commitdiff
encodings patch + default win pos
authorJohn Levon <levon@movementarian.org>
Sun, 5 Jan 2003 22:38:42 +0000 (22:38 +0000)
committerJohn Levon <levon@movementarian.org>
Sun, 5 Jan 2003 22:38:42 +0000 (22:38 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5905 a592a061-630c-0410-9148-cb99ea01b6c8

18 files changed:
src/BufferView.C
src/BufferView.h
src/ChangeLog
src/frontends/ChangeLog
src/frontends/LyXKeySym.h
src/frontends/qt2/ChangeLog
src/frontends/qt2/QLyXKeySym.C
src/frontends/qt2/QLyXKeySym.h
src/frontends/qt2/QtView.C
src/frontends/qt2/QtView.h
src/frontends/qt2/lyx_gui.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/XLyXKeySym.C
src/frontends/xforms/XLyXKeySym.h
src/kbsequence.C
src/kbsequence.h
src/lyxfunc.C
src/lyxfunc.h

index 35967e636e816fa134f504fcc671879eb42448d2..905a8da34625e6a5c4025737748248a5b1e272df 100644 (file)
@@ -933,6 +933,18 @@ Language const * BufferView::getParentLanguage(Inset * inset) const
 }
 
 
+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 04c44ce087790a004a7efbb4c24f7d2e615b7c20..5a1b44b3a4988911b054c250a07068dbd2fb5ca9 100644 (file)
@@ -30,6 +30,7 @@ class Language;
 class Painter;
 class UpdatableInset;
 class WordLangTuple;
+class Encoding;
 
 /**
  * A buffer view encapsulates a view onto a particular
@@ -124,6 +125,9 @@ public:
        /// 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 5244c493a9d1494262d2ac17578665d717584f78..96dc015bb804241f9051104dec542405760f8edd 100644 (file)
@@ -1,3 +1,15 @@
+2003-01-05  John Levon  <levon@movementarian.org>
+
+       * BufferView.h:
+       * BufferView.C: add getEncoding()
+
+       * kbsequence.h:
+       * kbsequence.C: do not store last keypress
+
+       * lyxfunc.h:
+       * lyxfunc.C: store last keypress here instead. Pass encoding
+         to getISOEncoded()
+
 2002-12-27  Jean-Marc Lasgouttes  <Jean-Marc.Lasgouttes@inria.fr>
 
        * lyx_main.C (init): remove annoying error message when following
index 807b3203f6ae37c002989852d17cad251583abc1..8f559a5b2e2de28adbb2c04ef3b43f3771549fcf 100644 (file)
@@ -1,3 +1,7 @@
+2003-01-05  John Levon  <levon@movementarian.org>
+
+       * LyXKeySym.h: pass Encoding to getISOEncoded
+
 2002-12-17  Jean-Marc Lasgouttes  <Jean-Marc.Lasgouttes@inria.fr>
 
        * lyx_gui.h: add new function lyx_gui::getStatus, which can be
index 8765b685a06aa88bb374368bca4f94e9db93034e..340808da6f7288e352fe367c0b6fa428e800c9d1 100644 (file)
@@ -47,7 +47,7 @@ public:
         * 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 dff517b2480148a8a41a9a41f1d68c227f79dc26..286fb180d5c6fdfd6c9e3fea0813cbb6ed31a621 100644 (file)
@@ -1,3 +1,12 @@
+2003-01-05  John Levon  <levon@movementarian.org>
+
+       * QLyXKeySym.h:
+       * QLyXKeySym.C: add an encoding map for getISOEncoded
+
+       * lyx_gui.C: init encodings
+
+       * QtView.h:
+       * QtView.C:
 2003-01-04  Juergen Spitzmueller  <j.spitzmueller@gmx.de>
  
        * QURL.C: isValid(): fix validation. 
index e3946dd8786a7516ef93a5c39bcd020c10d9f0db..45d8c51aecdc8b83030f17e784e2aeb319520041 100644 (file)
 #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 @@ string QLyXKeySym::getSymbolName() const
 }
 
 
-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 5ee71c405dc7d5a68141ba754e32a0fd5802bc33..740a589d9da72425b72d7510e624d2d4dc7c9976 100644 (file)
@@ -58,7 +58,7 @@ public:
         * 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 5a38bb5ed5cbf964200b904fa8520cc2e080226d..33a736cad392f93e7a9d56564307c198d333a78b 100644 (file)
@@ -142,10 +142,9 @@ void QtView::closeEvent(QCloseEvent *)
 }
 
 
-void QtView::show(int x, int y, string const & title)
+void QtView::show()
 {
-       move(x, y);
-       setCaption(toqstr(title));
+       setCaption(qt_("LyX"));
        QMainWindow::show();
 }
 
index e3b184c6d61e1da3114ea6f5c0341aaec971c12e..ecbc7027c6dd9adfc5064637c7385d6be81d4704 100644 (file)
@@ -37,13 +37,8 @@ public:
 
        ~QtView();
 
-       /**
-        * show - display the top-level window
-        * @param x x position
-        * @param y y position
-        * @param title window title
-        */
-       void show(int x, int y, string const & t = string("LyX"));
+       /// show - display the top-level window
+       void show();
 
        /// start modal operation
        virtual void prohibitInput() const;
index e6d2d1bac0a48909b5a5340ae4046589ed76df0a..a2dc25dbf3941ada37c3c7fda72103ef9d14aca7 100644 (file)
@@ -80,10 +80,14 @@ map<int, io_callback *> io_callbacks;
 // 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:
@@ -115,6 +119,8 @@ void lyx_gui::parse_init(int & argc, char * argv[])
 
        // needs to be done before reading lyxrc
        lyxrc.dpi = getDPI();
+
+       initEncodings();
 }
 
 
@@ -132,7 +138,7 @@ void lyx_gui::start(string const & batch, vector<string> const & files)
        unsigned int height = 510;
 
        QtView view(width, height);
-       view.show(xpos, ypos, "LyX");
+       view.show();
        view.init();
 
        Buffer * last = 0;
index 5f8b11f80c914768505dab6d0c8c2fbc09e61493..544987f7145a09a8e1122216674bfaa04646d1d4 100644 (file)
@@ -1,3 +1,8 @@
+2003-01-05  John Levon  <levon@movementarian.org>
+
+       * XLyXKeySym.h:
+       * XLyXKeySym.C: getISOEncoded() changed
+
 2002-12-26  Jean-Marc Lasgouttes  <Jean-Marc.Lasgouttes@inria.fr>
 
        * input_validators.C (fl_print_range_filter): remove extra space
index d8597fb29ecfa976e747ceda65123c7edad91d5f..35dd84d632cd0b12c3b69071c05204b97d82b0fb 100644 (file)
@@ -69,7 +69,7 @@ string XLyXKeySym::getSymbolName() const
 }
 
 
-char XLyXKeySym::getISOEncoded() const
+char XLyXKeySym::getISOEncoded(string const &) const
 {
        if (keysym_ == NoSymbol) {
                return 0;
index 3cd74ed57a682a79172464c56c9f73879be3b51c..bc120109b313edb509b381b7ba32d096f1be4380 100644 (file)
@@ -47,7 +47,7 @@ public:
         * 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 {
index a00c3ce44a61052734f65621a4835ca55d2de116..b56f2871de34a1bef1698a6c910232573856a607 100644 (file)
@@ -166,20 +166,6 @@ void kb_sequence::mark_deleted()
 }
 
 
-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 9aab03675caa6fa471075a308d92f6cdef783e82..35d600a415aa0a1f3124e02ce4fbd8e505e2806a 100644 (file)
@@ -71,13 +71,6 @@ public:
        /// 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 @@ public:
        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 f0467efc7924dba9c7cf881db224cb5f174371fd..a1b316d092db1365152c35f5bc238c33e02f9a6f 100644 (file)
@@ -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 @@ extern void ShowLatexLog();
 
 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::moveCursorUpdate(bool flag, bool selecting)
 
 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 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym,
                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 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym,
        }
 
        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 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
 #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 bd5e4e6b6513139077b21353016788cc214fc4a5..89037ec0494b15f51ed0e395a992802e32de9e16 100644 (file)
@@ -77,6 +77,10 @@ private:
 
        ///
        LyXView * owner;
+
+       /// the last character added to the key sequence, in ISO encoded form
+       char encoded_last_key;
+
        ///
        kb_sequence keyseq;
        ///