encodings patch + default win pos

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5905 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2003-01-05 22:38:42 +00:00
parent 23defe0e4f
commit 74c871a9fc
18 changed files with 150 additions and 51 deletions

View 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);

View 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;

View 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

View 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

View 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;
};

View 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.

View File

@ -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 @@ 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;
}

View 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_;

View 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();
}

View 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;

View 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;

View 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

View File

@ -69,7 +69,7 @@ string XLyXKeySym::getSymbolName() const
}
char XLyXKeySym::getISOEncoded() const
char XLyXKeySym::getISOEncoded(string const &) const
{
if (keysym_ == NoSymbol) {
return 0;

View 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 {

View 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();

View 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

View 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[`"
<< 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) {

View 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;
///