1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
1999-11-15 12:01:38 +00:00
|
|
|
* ======================================================
|
1999-10-02 16:21:10 +00:00
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
2000-03-16 04:29:22 +00:00
|
|
|
* Copyright 1995-2000 The LyX Team.
|
1999-10-02 16:21:10 +00:00
|
|
|
*
|
1999-11-15 12:01:38 +00:00
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* International support for LyX
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include FORMS_H_LOCATION
|
|
|
|
#include "intl.h"
|
|
|
|
#include "form1.h"
|
|
|
|
#include "tex-strings.h"
|
|
|
|
#include "combox.h"
|
|
|
|
#include "lyx_gui_misc.h" // CancelCloseBoxCB
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lyxrc.h"
|
|
|
|
#include "trans_mgr.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/lstrings.h"
|
2000-03-10 13:22:20 +00:00
|
|
|
#include "language.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-25 14:18:30 +00:00
|
|
|
// a wrapper around the callback static member.
|
1999-11-15 12:01:38 +00:00
|
|
|
extern "C" void C_Intl_DispatchCallback(FL_OBJECT * ob, long code);
|
1999-10-25 14:18:30 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
Intl::Intl()
|
2000-03-12 10:35:05 +00:00
|
|
|
: prim_lang(lyxrc.primary_kbmap),
|
|
|
|
sec_lang(lyxrc.secondary_kbmap),
|
1999-12-16 06:43:25 +00:00
|
|
|
trans(new TransManager)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-03-12 10:35:05 +00:00
|
|
|
keymapon = lyxrc.use_kbmap;
|
1999-10-02 16:21:10 +00:00
|
|
|
chsetcode = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
primarykeymap = false;
|
|
|
|
curkeymap = 0;
|
|
|
|
otherkeymap = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
int Intl::SetPrimary(string const & lang)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "Primary: `" << lang << "'" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
return trans->SetPrimary(lang);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
int Intl::SetSecondary(string const & lang)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "Secondary: `" << lang << "'" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
return trans->SetSecondary(lang);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Intl::update()
|
|
|
|
{
|
1999-12-21 06:10:21 +00:00
|
|
|
int off = 0;
|
|
|
|
int prim = 0;
|
|
|
|
int sec = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (!keymapon) {
|
1999-11-15 12:01:38 +00:00
|
|
|
off = 1;
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
|
|
|
if (primarykeymap) {
|
1999-11-15 12:01:38 +00:00
|
|
|
prim = 1;
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
1999-11-15 12:01:38 +00:00
|
|
|
sec = 1;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
fl_set_button(fd_form_keymap->KeyOffBtn, off);
|
|
|
|
fl_set_button(fd_form_keymap->KeyOnBtn, prim);
|
|
|
|
fl_set_button(fd_form_keymap->KeyOnBtn2, sec);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Intl::KeyMapOn(bool on)
|
|
|
|
/* turn on/off key mappings, status in keymapon */
|
|
|
|
{
|
|
|
|
keymapon = on;
|
|
|
|
|
|
|
|
if (!fd_form_keymap) return;
|
|
|
|
|
|
|
|
fl_set_button(fd_form_keymap->KeyOffBtn, 0);
|
|
|
|
fl_set_button(fd_form_keymap->KeyOnBtn, 0);
|
|
|
|
fl_set_button(fd_form_keymap->KeyOnBtn2, 0);
|
|
|
|
|
|
|
|
if (on) {
|
|
|
|
if (primarykeymap) {
|
|
|
|
KeyMapPrim();
|
|
|
|
} else {
|
|
|
|
KeyMapSec();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fl_set_button(fd_form_keymap->KeyOffBtn, 1);
|
|
|
|
fl_hide_object(fd_form_keymap->KeymapErr);
|
|
|
|
trans->DisableKeymap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Intl::ToggleKeyMap()
|
|
|
|
{
|
|
|
|
if (keymapon && primarykeymap) {
|
|
|
|
KeyMapSec();
|
|
|
|
} else if (keymapon) {
|
|
|
|
KeyMapOn(false);
|
|
|
|
} else
|
|
|
|
KeyMapPrim();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Intl::KeyMapPrim()
|
|
|
|
{
|
|
|
|
fl_set_button(fd_form_keymap->KeyOffBtn, 0);
|
|
|
|
fl_set_button(fd_form_keymap->KeyOnBtn, 1);
|
|
|
|
fl_set_button(fd_form_keymap->KeyOnBtn2, 0);
|
|
|
|
|
|
|
|
/* read text from choice */
|
1999-12-10 00:07:59 +00:00
|
|
|
int i = Language->get();
|
2000-03-10 13:22:20 +00:00
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
string p;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (i == otherkeymap)
|
|
|
|
p = fl_get_input(fd_form_keymap->OtherKeymap);
|
|
|
|
else
|
|
|
|
p = Language->getline();
|
|
|
|
|
|
|
|
curkeymap = i;
|
|
|
|
|
|
|
|
if (p.empty() || trans->SetPrimary(p)) {
|
|
|
|
// error selecting keymap
|
|
|
|
fl_show_object(fd_form_keymap->KeymapErr);
|
|
|
|
update();
|
|
|
|
} else {
|
|
|
|
// no error
|
|
|
|
trans->EnablePrimary();
|
|
|
|
keymapon = true;
|
|
|
|
primarykeymap = true;
|
|
|
|
fl_hide_object(fd_form_keymap->KeymapErr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Intl::KeyMapSec()
|
|
|
|
{
|
|
|
|
fl_set_button(fd_form_keymap->KeyOffBtn, 0);
|
|
|
|
fl_set_button(fd_form_keymap->KeyOnBtn, 0);
|
|
|
|
fl_set_button(fd_form_keymap->KeyOnBtn2, 1);
|
|
|
|
|
|
|
|
/* read text from choice */
|
1999-11-15 12:01:38 +00:00
|
|
|
int i = Language2->get();
|
2000-03-10 13:22:20 +00:00
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
string p;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (i == otherkeymap)
|
|
|
|
p = fl_get_input(fd_form_keymap->OtherKeymap2);
|
|
|
|
else
|
|
|
|
p = Language2->getline();
|
|
|
|
curkeymap = i;
|
|
|
|
|
|
|
|
if (p.empty() || trans->SetSecondary(p)) {
|
|
|
|
// error selecting keymap
|
|
|
|
fl_show_object(fd_form_keymap->KeymapErr);
|
|
|
|
update();
|
|
|
|
} else {
|
|
|
|
// no error
|
|
|
|
trans->EnableSecondary();
|
|
|
|
keymapon = true;
|
|
|
|
primarykeymap = false;
|
|
|
|
fl_hide_object(fd_form_keymap->KeymapErr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
void Intl::LCombo(int, void * v)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
Intl * itl = static_cast<Intl*>(v);
|
1999-09-27 18:44:28 +00:00
|
|
|
itl->Keymap(23);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
void Intl::LCombo2(int, void * v)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
Intl * itl = static_cast<Intl*>(v);
|
1999-09-27 18:44:28 +00:00
|
|
|
itl->Keymap(43);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
void Intl::DispatchCallback(FL_OBJECT * ob, long code)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if (ob && (code == 0)) {
|
|
|
|
fl_hide_form(ob->form);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!ob || !(ob->u_vdata))
|
|
|
|
return;
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
Intl * itl = static_cast<Intl *>(ob->u_vdata);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
if (itl!= 0) itl->Keymap(code);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
extern "C" void C_Intl_DispatchCallback(FL_OBJECT * ob, long code)
|
1999-10-25 14:18:30 +00:00
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
Intl::DispatchCallback(ob, code);
|
1999-10-25 14:18:30 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void Intl::InitKeyMapper(bool on)
|
|
|
|
/* initialize key mapper */
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
lyxerr[Debug::INIT] << "Initializing key mappings..." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (prim_lang.empty() && sec_lang.empty())
|
|
|
|
keymapon = false;
|
|
|
|
else
|
|
|
|
keymapon = on;
|
|
|
|
|
|
|
|
Language = new Combox(FL_COMBOX_DROPLIST);
|
|
|
|
Language2 = new Combox(FL_COMBOX_DROPLIST);
|
1999-11-15 12:01:38 +00:00
|
|
|
Language->setcallback(LCombo, this);
|
|
|
|
Language2->setcallback(LCombo2, this);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
fd_form_keymap = create_form_KeyMap();
|
|
|
|
|
|
|
|
// Add the Intl* pointer
|
1999-11-15 12:01:38 +00:00
|
|
|
fd_form_keymap->AcceptChset->u_vdata =
|
|
|
|
fd_form_keymap->Charset->u_vdata =
|
|
|
|
fd_form_keymap->Accept->u_vdata =
|
|
|
|
fd_form_keymap->OtherKeymap->u_vdata =
|
|
|
|
fd_form_keymap->KeyOnBtn->u_vdata =
|
|
|
|
fd_form_keymap->KeyOffBtn->u_vdata =
|
|
|
|
fd_form_keymap->KeyOnBtn2->u_vdata = this;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// add the callbacks.
|
1999-10-25 14:18:30 +00:00
|
|
|
fl_set_object_callback(fd_form_keymap->AcceptChset,
|
1999-11-15 12:01:38 +00:00
|
|
|
C_Intl_DispatchCallback, 27);
|
1999-10-25 14:18:30 +00:00
|
|
|
fl_set_object_callback(fd_form_keymap->Charset,
|
1999-11-15 12:01:38 +00:00
|
|
|
C_Intl_DispatchCallback, 26);
|
1999-10-25 14:18:30 +00:00
|
|
|
fl_set_object_callback(fd_form_keymap->Accept,
|
1999-11-15 12:01:38 +00:00
|
|
|
C_Intl_DispatchCallback, 0);
|
1999-10-25 14:18:30 +00:00
|
|
|
|
|
|
|
fl_set_object_callback(fd_form_keymap->KeyOnBtn,
|
1999-11-15 12:01:38 +00:00
|
|
|
C_Intl_DispatchCallback, 23);
|
1999-10-25 14:18:30 +00:00
|
|
|
fl_set_object_callback(fd_form_keymap->KeyOffBtn,
|
1999-11-15 12:01:38 +00:00
|
|
|
C_Intl_DispatchCallback, 3);
|
1999-10-25 14:18:30 +00:00
|
|
|
fl_set_object_callback(fd_form_keymap->KeyOnBtn2,
|
1999-11-15 12:01:38 +00:00
|
|
|
C_Intl_DispatchCallback, 43);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// Make sure pressing the close box does not kill LyX. (RvdK)
|
1999-10-02 16:21:10 +00:00
|
|
|
fl_set_form_atclose(fd_form_keymap->KeyMap, CancelCloseBoxCB, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
fl_hide_object(fd_form_keymap->KeymapErr);
|
|
|
|
fl_hide_object(fd_form_keymap->ChsetErr);
|
2000-03-12 10:35:05 +00:00
|
|
|
fl_set_input(fd_form_keymap->Charset, lyxrc.font_norm.c_str());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// Adds two comboxes to the keyboard map
|
|
|
|
fl_addto_form(fd_form_keymap->KeyMap);
|
1999-11-15 12:01:38 +00:00
|
|
|
Language->add(120, 30, 160, 30, 300); // Primary
|
|
|
|
Language2->add(120, 110, 160, 30, 300); // Secondary
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_end_form();
|
|
|
|
|
2000-03-10 13:22:20 +00:00
|
|
|
int n = 1;
|
|
|
|
// Default is not in the language map
|
|
|
|
Language->addto("default");
|
|
|
|
Language2->addto("default");
|
|
|
|
for (Languages::const_iterator cit = languages.begin();
|
|
|
|
cit != languages.end(); ++cit) {
|
|
|
|
Language->addto((*cit).second.lang.c_str());
|
|
|
|
Language2->addto((*cit).second.lang.c_str());
|
|
|
|
++n;
|
|
|
|
}
|
2000-04-16 22:27:30 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
Language->addto(_("other..."));
|
|
|
|
Language2->addto(_("other..."));
|
1999-12-21 06:10:21 +00:00
|
|
|
otherkeymap = n + 1;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!Language->select_text(prim_lang.c_str())) {
|
|
|
|
Language->select(n+1);
|
|
|
|
fl_set_input(fd_form_keymap->OtherKeymap, prim_lang.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
trans->SetPrimary(prim_lang);
|
|
|
|
|
|
|
|
if (!Language2->select_text(sec_lang.c_str())) {
|
1999-12-21 06:10:21 +00:00
|
|
|
Language2->select(n + 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_input(fd_form_keymap->OtherKeymap2, sec_lang.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
trans->SetSecondary(sec_lang);
|
|
|
|
|
|
|
|
KeyMapOn(keymapon);
|
|
|
|
if (keymapon)
|
|
|
|
Keymap(23); // turn primary on
|
|
|
|
|
2000-03-12 10:35:05 +00:00
|
|
|
trans->setCharset(lyxrc.font_norm.c_str());
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Intl::Keymap(long code)
|
|
|
|
{
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "KeyMap callback: " << code << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
// Did you wonder if it is possible to write spagetti code with
|
|
|
|
// other constructs thatn goto's? Well here we have a nice small
|
|
|
|
// spagetti example using a switch... (Lgb)
|
1999-09-27 18:44:28 +00:00
|
|
|
switch (code) {
|
|
|
|
case 0:
|
|
|
|
/* cancel/hide */
|
|
|
|
fl_hide_form(fd_form_keymap->KeyMap);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 23:
|
|
|
|
case 43:
|
1999-11-15 12:01:38 +00:00
|
|
|
if (code == 3) {
|
1999-09-27 18:44:28 +00:00
|
|
|
KeyMapOn(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
code -= 19; // change to language change type code
|
|
|
|
|
|
|
|
case 4: // 4 and 24 will never be called directly, they will only be
|
1999-11-15 12:01:38 +00:00
|
|
|
case 24: // called through 3, 23, 43 (lgb)
|
|
|
|
if (code == 4) {
|
1999-09-27 18:44:28 +00:00
|
|
|
KeyMapPrim();
|
|
|
|
} else {
|
|
|
|
KeyMapSec();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 27: /* set new font norm */
|
1999-11-15 12:01:38 +00:00
|
|
|
char const * p = fl_get_input(fd_form_keymap->Charset);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (trans->setCharset(p))
|
|
|
|
fl_show_object(fd_form_keymap->ChsetErr);
|
|
|
|
else
|
|
|
|
fl_hide_object(fd_form_keymap->ChsetErr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Intl::MenuKeymap()
|
|
|
|
{
|
|
|
|
if (fd_form_keymap->KeyMap->visible) {
|
|
|
|
fl_raise_form(fd_form_keymap->KeyMap);
|
|
|
|
} else fl_show_form(fd_form_keymap->KeyMap, FL_PLACE_MOUSE,
|
|
|
|
FL_FULLBORDER, _("Key Mappings"));
|
|
|
|
}
|