}
+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);
class Painter;
class UpdatableInset;
class WordLangTuple;
+class Encoding;
/**
* A buffer view encapsulates a view onto a particular
/// 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;
+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
+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
* 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;
};
+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.
#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()
}
-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;
}
* 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_;
}
-void QtView::show(int x, int y, string const & title)
+void QtView::show()
{
- move(x, y);
- setCaption(toqstr(title));
+ setCaption(qt_("LyX"));
QMainWindow::show();
}
~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;
// 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:
// needs to be done before reading lyxrc
lyxrc.dpi = getDPI();
+
+ initEncodings();
}
unsigned int height = 510;
QtView view(width, height);
- view.show(xpos, ypos, "LyX");
+ view.show();
view.init();
Buffer * last = 0;
+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
}
-char XLyXKeySym::getISOEncoded() const
+char XLyXKeySym::getISOEncoded(string const &) const
{
if (keysym_ == NoSymbol) {
return 0;
* 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 {
}
-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();
/// 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();
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
#include "gettext.h"
#include "Lsstream.h"
#include "trans_mgr.h"
+#include "encoding.h"
#include "layout.h"
#include "bufferview_funcs.h"
#include "frontends/LyXView.h"
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)
void LyXFunc::handleKeyFunc(kb_action action)
{
- char c = keyseq.getLastKeyEncoded();
+ char c = encoded_last_key;
- if (keyseq.length() > 1) {
+ if (keyseq.length()) {
c = 0;
}
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();
}
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);
}
#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) {
///
LyXView * owner;
+
+ /// the last character added to the key sequence, in ISO encoded form
+ char encoded_last_key;
+
///
kb_sequence keyseq;
///