1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
1999-10-02 16:21:10 +00:00
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-1999 The LyX Team.
|
|
|
|
*
|
1999-10-07 18:44:17 +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"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
extern LyXRC* lyxrc;
|
|
|
|
|
1999-10-25 14:18:30 +00:00
|
|
|
// a wrapper around the callback static member.
|
|
|
|
extern "C" void C_Intl_DispatchCallback(FL_OBJECT *ob,long code);
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
Intl::Intl()
|
|
|
|
: prim_lang(lyxrc->primary_kbmap),
|
|
|
|
sec_lang(lyxrc->secondary_kbmap),
|
|
|
|
trans(new TransManager)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Intl::~Intl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
int off,prim,sec;
|
|
|
|
|
|
|
|
off=prim=sec=0;
|
|
|
|
|
|
|
|
if (!keymapon) {
|
|
|
|
off=1;
|
|
|
|
} else {
|
|
|
|
if (primarykeymap) {
|
|
|
|
prim=1;
|
|
|
|
} else {
|
|
|
|
sec=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fl_set_button(fd_form_keymap->KeyOffBtn,off);
|
|
|
|
fl_set_button(fd_form_keymap->KeyOnBtn,prim);
|
|
|
|
fl_set_button(fd_form_keymap->KeyOnBtn2,sec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
int i;
|
1999-10-02 16:21:10 +00:00
|
|
|
string p;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
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 */
|
|
|
|
i = Language->get();
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "Table: " << tex_babel[i-1] << endl;
|
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()
|
|
|
|
{
|
|
|
|
int i;
|
1999-10-02 16:21:10 +00:00
|
|
|
string p;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
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 */
|
|
|
|
i = Language2->get();
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
if (lyxerr.debugging(Debug::KBMAP))
|
|
|
|
lyxerr << "Table: " << tex_babel[i-1] << endl;
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Intl::LCombo(int, void *v)
|
|
|
|
{
|
|
|
|
Intl *itl = (Intl*) v;
|
|
|
|
itl->Keymap(23);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Intl::LCombo2(int, void *v)
|
|
|
|
{
|
|
|
|
Intl *itl = (Intl*) v;
|
|
|
|
itl->Keymap(43);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Intl::DispatchCallback(FL_OBJECT *ob,long code)
|
|
|
|
{
|
|
|
|
if (ob && (code == 0)) {
|
|
|
|
fl_hide_form(ob->form);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!ob || !(ob->u_vdata))
|
|
|
|
return;
|
|
|
|
|
|
|
|
Intl *itl=(Intl *)ob->u_vdata;
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
if (itl!=0) itl->Keymap(code);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-10-25 14:18:30 +00:00
|
|
|
extern "C" void C_Intl_DispatchCallback(FL_OBJECT *ob,long code)
|
|
|
|
{
|
|
|
|
Intl::DispatchCallback(ob,code);
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
void Intl::InitKeyMapper(bool on)
|
|
|
|
/* initialize key mapper */
|
|
|
|
{
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::KBMAP] << "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);
|
|
|
|
Language->setcallback(LCombo,this);
|
|
|
|
Language2->setcallback(LCombo2,this);
|
|
|
|
|
|
|
|
fd_form_keymap = create_form_KeyMap();
|
|
|
|
|
|
|
|
// Add the Intl* pointer
|
|
|
|
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=(void *)this;
|
|
|
|
|
|
|
|
// add the callbacks.
|
1999-10-25 14:18:30 +00:00
|
|
|
fl_set_object_callback(fd_form_keymap->AcceptChset,
|
|
|
|
C_Intl_DispatchCallback,27);
|
|
|
|
fl_set_object_callback(fd_form_keymap->Charset,
|
|
|
|
C_Intl_DispatchCallback,26);
|
|
|
|
fl_set_object_callback(fd_form_keymap->Accept,
|
|
|
|
C_Intl_DispatchCallback,0);
|
|
|
|
|
|
|
|
fl_set_object_callback(fd_form_keymap->KeyOnBtn,
|
|
|
|
C_Intl_DispatchCallback,23);
|
|
|
|
fl_set_object_callback(fd_form_keymap->KeyOffBtn,
|
|
|
|
C_Intl_DispatchCallback,3);
|
|
|
|
fl_set_object_callback(fd_form_keymap->KeyOnBtn2,
|
|
|
|
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);
|
|
|
|
fl_set_input(fd_form_keymap->Charset, lyxrc->font_norm.c_str());
|
|
|
|
|
|
|
|
// Adds two comboxes to the keyboard map
|
|
|
|
fl_addto_form(fd_form_keymap->KeyMap);
|
|
|
|
Language->add(120,30,160,30,300); // Primary
|
|
|
|
Language2->add(120,110,160,30,300); // Secondary
|
|
|
|
fl_end_form();
|
|
|
|
|
|
|
|
int n=0;
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
if (!strlen(tex_babel[n]))
|
|
|
|
break;
|
|
|
|
else {
|
|
|
|
Language->addto(tex_babel[n]);
|
|
|
|
Language2->addto(tex_babel[n]);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Language->addto(_("other..."));
|
|
|
|
Language2->addto(_("other..."));
|
|
|
|
otherkeymap = n+1;
|
|
|
|
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())) {
|
|
|
|
Language2->select(n+1);
|
|
|
|
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
|
|
|
|
|
|
|
|
trans->setCharset(lyxrc->font_norm.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Intl::Keymap(long code)
|
|
|
|
{
|
|
|
|
char const *p;
|
|
|
|
|
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
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
case 0:
|
|
|
|
/* cancel/hide */
|
|
|
|
fl_hide_form(fd_form_keymap->KeyMap);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 23:
|
|
|
|
case 43:
|
|
|
|
if (code==3) {
|
|
|
|
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
|
|
|
|
case 24: // called through 3,23,43 (lgb)
|
|
|
|
if (code==4) {
|
|
|
|
KeyMapPrim();
|
|
|
|
} else {
|
|
|
|
KeyMapSec();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 27: /* set new font norm */
|
|
|
|
p = fl_get_input(fd_form_keymap->Charset);
|
|
|
|
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"));
|
|
|
|
}
|