1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995 Matthias Ettrich
|
|
|
|
* Copyright (C) 1995-1998 The LyX team.
|
|
|
|
*
|
|
|
|
*======================================================*/
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
#include "error.h"
|
|
|
|
|
|
|
|
static XIM xim;
|
|
|
|
static XIC xic;
|
1999-10-02 16:21:10 +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
|
|
|
|
void InitLyXLookup(Display* display, Window window)
|
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
xic = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// This part could be done before opening display
|
|
|
|
setlocale(LC_CTYPE,"");
|
|
|
|
if (!XSupportsLocale()) {
|
|
|
|
lyxerr.debug("InitLyXLookup: X does not support this locale.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!XSetLocaleModifiers("")) {
|
|
|
|
lyxerr.debug("InitLyXLookup: Could not set modifiers "
|
|
|
|
"for this locale.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
xic = XCreateIC (xim,
|
|
|
|
XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
|
|
|
|
XNClientWindow, window,
|
|
|
|
XNFocusWindow, window,
|
1999-10-02 16:21:10 +00:00
|
|
|
0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (!xic) {
|
|
|
|
lyxerr.debug("InitLyXLookup: could not create "
|
|
|
|
"an input context");
|
|
|
|
XCloseIM (xim);
|
1999-10-02 16:21:10 +00:00
|
|
|
xim = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
lyxerr.debug("InitLyXLookup: could not open "
|
|
|
|
"an input method.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
bool isDeadEvent(XEvent *event,
|
|
|
|
char *buffer_return, int bytes_buffer,
|
|
|
|
KeySym *keysym_return)
|
|
|
|
{
|
|
|
|
XLookupString(&event->xkey, buffer_return,
|
|
|
|
bytes_buffer, keysym_return,
|
1999-10-02 16:21:10 +00:00
|
|
|
0);
|
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
|
|
|
|
if (false
|
|
|
|
#ifdef XK_dead_grave
|
|
|
|
|| *keysym_return == XK_dead_grave
|
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_acute
|
|
|
|
|| *keysym_return == XK_dead_acute
|
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_circumflex
|
|
|
|
|| *keysym_return == XK_dead_circumflex
|
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_tilde
|
|
|
|
|| *keysym_return == XK_dead_tilde
|
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_macron
|
|
|
|
|| *keysym_return == XK_dead_macron
|
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_breve
|
|
|
|
|| *keysym_return == XK_dead_breve
|
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_abovedot
|
|
|
|
|| *keysym_return == XK_dead_abovedot
|
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_diaeresis
|
|
|
|
|| *keysym_return == XK_dead_diaeresis
|
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_abovering
|
|
|
|
|| *keysym_return == XK_dead_abovering
|
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_doubleacute
|
|
|
|
|| *keysym_return == XK_dead_doubleacute
|
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_caron
|
|
|
|
|| *keysym_return == XK_dead_caron
|
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_cedilla
|
|
|
|
|| *keysym_return == XK_dead_cedilla
|
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_ogonek
|
|
|
|
|| *keysym_return == XK_dead_ogonek
|
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_iota
|
|
|
|
|| *keysym_return == XK_dead_iota
|
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_voiced_sound
|
|
|
|
|| *keysym_return == XK_dead_voiced_sound
|
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_semivoiced_sound
|
|
|
|
|| *keysym_return == XK_dead_semivoiced_sound
|
|
|
|
#endif
|
|
|
|
#ifdef XK_dead_belowdot
|
|
|
|
|| *keysym_return == XK_dead_belowdot
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This is called instead of XLookupString()
|
|
|
|
int LyXLookupString(XEvent *event,
|
|
|
|
char *buffer_return, int bytes_buffer,
|
|
|
|
KeySym *keysym_return)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
if (xic) {
|
|
|
|
if (isDeadEvent(event, buffer_return, bytes_buffer,
|
|
|
|
keysym_return)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (XFilterEvent (event, None)) {
|
|
|
|
//lyxerr.print("XFilterEvent");
|
|
|
|
*keysym_return = NoSymbol;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (event->type != KeyPress)
|
|
|
|
lyxerr.print("LyXLookupString: wrong event type"
|
1999-10-02 16:21:10 +00:00
|
|
|
+string(event->type));
|
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:
|
|
|
|
//lyxerr.print("XLookupBoth");
|
|
|
|
break;
|
|
|
|
case XLookupChars:
|
|
|
|
//lyxerr.print("XLookupChars");
|
|
|
|
*keysym_return = NoSymbol;
|
|
|
|
break;
|
|
|
|
case XLookupKeySym:
|
|
|
|
//lyxerr.print("XLookupKeySym");
|
|
|
|
result = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
//lyxerr.print("default");
|
|
|
|
*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) {
|
|
|
|
lyxerr.debug("CloseLyXLookup: destroying input context");
|
|
|
|
XDestroyIC(xic);
|
|
|
|
XCloseIM(xim);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else // We do not have XOpenIM, so we stick with normal XLookupString
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
|
1999-10-02 16:21:10 +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
|
|
|
|
void InitLyXLookup(Display* , Window )
|
|
|
|
{
|
|
|
|
//Nothing to do.
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is called instead of XLookupString(). I this particular case,
|
|
|
|
// this *is* XLookupString...
|
|
|
|
int LyXLookupString(XEvent *event,
|
|
|
|
char *buffer_return, int bytes_buffer,
|
|
|
|
KeySym *keysym_return)
|
|
|
|
{
|
|
|
|
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
|