1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
1999-11-15 12:01:38 +00:00
|
|
|
* ======================================================
|
1999-10-07 18:44:17 +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-07 18:44:17 +00:00
|
|
|
*
|
1999-11-15 12:01:38 +00:00
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_XOPENIM
|
|
|
|
// This part is the full blown Input Method manager for X11R5 and up.
|
|
|
|
// For the plain-and-old-X11R4 version, see later.
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
#ifdef HAVE_LOCALE_H
|
|
|
|
#include <locale.h>
|
|
|
|
#endif
|
2000-03-02 02:19:43 +00:00
|
|
|
#include <clocale>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
2000-05-10 11:50:11 +00:00
|
|
|
#include "lyxrc.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
|
|
|
static XIM xim;
|
|
|
|
static XIC xic;
|
1999-11-15 12:01:38 +00:00
|
|
|
XComposeStatus compose_status= {0, 0};
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// This is called after the main LyX window has been created
|
1999-11-22 16:19:48 +00:00
|
|
|
void InitLyXLookup(Display * display, Window window)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
xic = 0;
|
1999-11-22 16:19:48 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// This part could be done before opening display
|
1999-11-15 12:01:38 +00:00
|
|
|
setlocale(LC_CTYPE, "");
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!XSupportsLocale()) {
|
1999-11-25 17:29:19 +00:00
|
|
|
lyxerr[Debug::KEY]
|
1999-11-22 16:19:48 +00:00
|
|
|
<< "InitLyXLookup: X does not support this locale."
|
|
|
|
<< endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!XSetLocaleModifiers("")) {
|
1999-11-25 17:29:19 +00:00
|
|
|
lyxerr[Debug::KEY] << "InitLyXLookup: Could not set modifiers "
|
1999-11-09 23:52:04 +00:00
|
|
|
"for this locale." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-11-22 16:19:48 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// This part will have to be done for each frame
|
1999-10-02 16:21:10 +00:00
|
|
|
xim = XOpenIM (display, 0, 0, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (xim) {
|
1999-11-22 16:19:48 +00:00
|
|
|
xic = XCreateIC(xim, XNInputStyle,
|
|
|
|
XIMPreeditNothing | XIMStatusNothing,
|
|
|
|
XNClientWindow, window,
|
|
|
|
XNFocusWindow, window,
|
|
|
|
0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (!xic) {
|
1999-11-25 17:29:19 +00:00
|
|
|
lyxerr[Debug::KEY] << "InitLyXLookup: could not create "
|
1999-11-09 23:52:04 +00:00
|
|
|
"an input context" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
XCloseIM (xim);
|
1999-10-02 16:21:10 +00:00
|
|
|
xim = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
1999-11-25 17:29:19 +00:00
|
|
|
lyxerr[Debug::KEY] << "InitLyXLookup: could not open "
|
1999-11-09 23:52:04 +00:00
|
|
|
"an input method." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
1999-11-22 16:19:48 +00:00
|
|
|
bool isDeadEvent(XEvent * event,
|
|
|
|
char * buffer_return, int bytes_buffer,
|
|
|
|
KeySym * keysym_return)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
XLookupString(&event->xkey, buffer_return,
|
|
|
|
bytes_buffer, keysym_return,
|
1999-10-02 16:21:10 +00:00
|
|
|
0);
|
2000-05-10 11:50:11 +00:00
|
|
|
|
|
|
|
// somehow it is necessary to do the lookup. Why? (JMarc)
|
|
|
|
if (!lyxrc.override_x_deadkeys)
|
|
|
|
return false;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Can this be done safely in any other way?
|
|
|
|
// This is all the dead keys I know of in X11R6.1
|
2000-05-10 11:50:11 +00:00
|
|
|
switch (*keysym_return) {
|
1999-09-27 18:44:28 +00:00
|
|
|
#ifdef XK_dead_grave
|
2000-05-10 11:50:11 +00:00
|
|
|
case XK_dead_grave:
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_acute
|
2000-05-10 11:50:11 +00:00
|
|
|
case XK_dead_acute:
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_circumflex
|
2000-05-10 11:50:11 +00:00
|
|
|
case XK_dead_circumflex:
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_tilde
|
2000-05-10 11:50:11 +00:00
|
|
|
case XK_dead_tilde:
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_macron
|
2000-05-10 11:50:11 +00:00
|
|
|
case XK_dead_macron:
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_breve
|
2000-05-10 11:50:11 +00:00
|
|
|
case XK_dead_breve:
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_abovedot
|
2000-05-10 11:50:11 +00:00
|
|
|
case XK_dead_abovedot:
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_diaeresis
|
2000-05-10 11:50:11 +00:00
|
|
|
case XK_dead_diaeresis:
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_abovering
|
2000-05-10 11:50:11 +00:00
|
|
|
case XK_dead_abovering:
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_doubleacute
|
2000-05-10 11:50:11 +00:00
|
|
|
case XK_dead_doubleacute:
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_caron
|
2000-05-10 11:50:11 +00:00
|
|
|
case XK_dead_caron:
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_cedilla
|
2000-05-10 11:50:11 +00:00
|
|
|
case XK_dead_cedilla:
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_ogonek
|
2000-05-10 11:50:11 +00:00
|
|
|
case XK_dead_ogonek:
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_iota
|
2000-05-10 11:50:11 +00:00
|
|
|
case XK_dead_iota:
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_voiced_sound
|
2000-05-10 11:50:11 +00:00
|
|
|
case XK_dead_voiced_sound:
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_semivoiced_sound
|
2000-05-10 11:50:11 +00:00
|
|
|
case XK_dead_semivoiced_sound:
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_belowdot
|
2000-05-10 11:50:11 +00:00
|
|
|
case XK_dead_belowdot:
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
return true;
|
2000-05-10 11:50:11 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This is called instead of XLookupString()
|
1999-11-22 16:19:48 +00:00
|
|
|
int LyXLookupString(XEvent * event,
|
|
|
|
char * buffer_return, int bytes_buffer,
|
|
|
|
KeySym * keysym_return)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
if (xic) {
|
|
|
|
if (isDeadEvent(event, buffer_return, bytes_buffer,
|
2000-05-10 11:50:11 +00:00
|
|
|
keysym_return)) {
|
|
|
|
lyxerr[Debug::KEY]
|
|
|
|
<< "LyXLookupString: found DeadEvent" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (XFilterEvent (event, None)) {
|
1999-10-07 18:44:17 +00:00
|
|
|
//lyxerr <<"XFilterEvent");
|
1999-09-27 18:44:28 +00:00
|
|
|
*keysym_return = NoSymbol;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (event->type != KeyPress)
|
1999-11-09 23:52:04 +00:00
|
|
|
lyxerr << "LyXLookupString: wrong event type"
|
|
|
|
<< event->type << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
Status status_return;
|
|
|
|
|
|
|
|
result = XmbLookupString(xic, &event->xkey, buffer_return,
|
|
|
|
bytes_buffer, keysym_return,
|
|
|
|
&status_return);
|
|
|
|
switch(status_return) {
|
|
|
|
case XLookupBoth:
|
1999-10-07 18:44:17 +00:00
|
|
|
//lyxerr <<"XLookupBoth");
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case XLookupChars:
|
1999-10-07 18:44:17 +00:00
|
|
|
//lyxerr <<"XLookupChars");
|
1999-09-27 18:44:28 +00:00
|
|
|
*keysym_return = NoSymbol;
|
|
|
|
break;
|
|
|
|
case XLookupKeySym:
|
1999-10-07 18:44:17 +00:00
|
|
|
//lyxerr <<"XLookupKeySym");
|
1999-09-27 18:44:28 +00:00
|
|
|
result = 0;
|
|
|
|
break;
|
|
|
|
default:
|
1999-10-07 18:44:17 +00:00
|
|
|
//lyxerr <<"default");
|
1999-09-27 18:44:28 +00:00
|
|
|
*keysym_return = NoSymbol;
|
|
|
|
result = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = XLookupString(&event->xkey, buffer_return,
|
|
|
|
bytes_buffer, keysym_return,
|
|
|
|
&compose_status);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is called after the main window has been destroyed
|
|
|
|
void CloseLyXLookup()
|
|
|
|
{
|
|
|
|
if (xic) {
|
1999-11-25 17:29:19 +00:00
|
|
|
lyxerr[Debug::KEY] << "CloseLyXLookup: destroying input context"
|
1999-11-09 23:52:04 +00:00
|
|
|
<< endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
XDestroyIC(xic);
|
2000-01-20 01:41:55 +00:00
|
|
|
xic = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
XCloseIM(xim);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else // We do not have XOpenIM, so we stick with normal XLookupString
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
XComposeStatus compose_status= {0, 0};
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// This is called after the main LyX window has been created
|
1999-11-22 16:19:48 +00:00
|
|
|
void InitLyXLookup(Display *, Window )
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
//Nothing to do.
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is called instead of XLookupString(). I this particular case,
|
|
|
|
// this *is* XLookupString...
|
1999-11-22 16:19:48 +00:00
|
|
|
int LyXLookupString(XEvent * event,
|
|
|
|
char * buffer_return, int bytes_buffer,
|
|
|
|
KeySym * keysym_return)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return XLookupString(&event->xkey, buffer_return,
|
|
|
|
bytes_buffer, keysym_return,
|
|
|
|
&compose_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is called after the main window has been destroyed
|
|
|
|
void CloseLyXLookup()
|
|
|
|
{
|
|
|
|
// Nothing to do
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HAVE_XOPENIM
|