X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxlookup.C;h=39916ed893366559d45c3e75fe4771ca26cda4ab;hb=4590c8cfab02a3bc56813cfb1f2e80bd1119af9e;hp=16653062fb3695eb20be412446cc571f38724c7e;hpb=4b2a999762c83627476428e595d3c1e3704a3da0;p=lyx.git diff --git a/src/lyxlookup.C b/src/lyxlookup.C index 16653062fb..39916ed893 100644 --- a/src/lyxlookup.C +++ b/src/lyxlookup.C @@ -4,7 +4,7 @@ * LyX, The Document Processor * * Copyright 1995 Matthias Ettrich - * Copyright 1995-2000 The LyX team. + * Copyright 1995-2001 The LyX team. * * ====================================================== */ @@ -17,7 +17,6 @@ #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 #include #include @@ -32,41 +31,59 @@ using std::endl; -static XIM xim; -static XIC xic; +namespace { + +XIM xim; +XIC xic; XComposeStatus compose_status= {0, 0}; +} // namespace anon + + // This is called after the main LyX window has been created void InitLyXLookup(Display * display, Window window) { xic = 0; - + + lyxerr[Debug::KEY] + << "InitLyXLookup: creating an input context." + << endl; + // This part could be done before opening display + string oldlocale = setlocale(LC_CTYPE, 0); setlocale(LC_CTYPE, ""); if (!XSupportsLocale()) { lyxerr[Debug::KEY] << "InitLyXLookup: X does not support this locale." << endl; return; - } - if (!XSetLocaleModifiers("")) { + } + // reset the LC_CTYPE locale to previous value. + setlocale(LC_CTYPE, oldlocale.c_str()); + + char const * locmod; + if (!(locmod = XSetLocaleModifiers(""))) { lyxerr[Debug::KEY] << "InitLyXLookup: Could not set modifiers " "for this locale." << endl; return; } + else + lyxerr[Debug::KEY] << "InitLyXLookup: X locale modifiers are `" + << locmod << '\'' << endl; // This part will have to be done for each frame xim = XOpenIM (display, 0, 0, 0); if (xim) { - xic = XCreateIC(xim, XNInputStyle, - XIMPreeditNothing | XIMStatusNothing, + xic = XCreateIC(xim, + XNInputStyle, + XIMPreeditNothing|XIMStatusNothing, XNClientWindow, window, XNFocusWindow, window, 0); if (!xic) { - lyxerr[Debug::KEY] << "InitLyXLookup: could not create " - "an input context" << endl; + lyxerr[Debug::KEY] << "InitLyXLookup: " + "could not create an input context" << endl; XCloseIM (xim); xim = 0; } @@ -77,22 +94,13 @@ void InitLyXLookup(Display * display, Window window) } -static -bool isDeadEvent(XEvent * event, - char * buffer_return, int bytes_buffer, - KeySym * keysym_return) -{ - XLookupString(&event->xkey, buffer_return, - bytes_buffer, keysym_return, - 0); - - // somehow it is necessary to do the lookup. Why? (JMarc) - if (!lyxrc.override_x_deadkeys) - return false; +namespace { +bool isDeadEvent(KeySym keysym) +{ // Can this be done safely in any other way? // This is all the dead keys I know of in X11R6.1 - switch (*keysym_return) { + switch (keysym) { #ifdef XK_dead_grave case XK_dead_grave: #endif @@ -150,50 +158,76 @@ bool isDeadEvent(XEvent * event, } } +} // namespace anon + // This is called instead of XLookupString() int LyXLookupString(XEvent * event, char * buffer_return, int bytes_buffer, KeySym * keysym_return) { + if (event->type != KeyPress) { + lyxerr << "LyXLookupString: wrong event type: " + << event->type << endl; + return 0; + } + int result = 0; if (xic) { - if (isDeadEvent(event, buffer_return, bytes_buffer, - keysym_return)) { +#if 1 + // somehow it is necessary to do the lookup. Why? (JMarc) + XLookupString(&event->xkey, buffer_return, + bytes_buffer, keysym_return, + 0); + + if (lyxrc.override_x_deadkeys && + isDeadEvent(*keysym_return)) { lyxerr[Debug::KEY] << "LyXLookupString: found DeadEvent" << endl; return 0; } +#endif +#if 1 if (XFilterEvent (event, None)) { - //lyxerr <<"XFilterEvent"); + lyxerr[Debug::KEY] <<"XFilterEvent" << endl; *keysym_return = NoSymbol; return 0; } - if (event->type != KeyPress) - lyxerr << "LyXLookupString: wrong event type" - << event->type << endl; +#endif Status status_return = 0; result = XmbLookupString(xic, &event->xkey, buffer_return, bytes_buffer, keysym_return, &status_return); - switch(status_return) { + switch (status_return) { + case XBufferOverflow: + lyxerr[Debug::KEY] << "XBufferOverflow" << endl; + break; case XLookupBoth: - //lyxerr <<"XLookupBoth"); + lyxerr[Debug::KEY] << "XLookupBoth " + << string(buffer_return, result) + << endl; break; case XLookupChars: - //lyxerr <<"XLookupChars"); + lyxerr[Debug::KEY] << "XLookupChars " + << string(buffer_return, result) + << endl; + *keysym_return = NoSymbol; break; case XLookupKeySym: - //lyxerr <<"XLookupKeySym"); + lyxerr[Debug::KEY] << "XLookupKeySym" << endl; result = 0; break; - default: - //lyxerr <<"default"); + case XLookupNone: + lyxerr[Debug::KEY] << "XLookupNone" << endl; *keysym_return = NoSymbol; result = 0; break; + default: + lyxerr << "Unknown status_return from" + " XmbLookupString" << endl; + break; } } else { result = XLookupString(&event->xkey, buffer_return, @@ -203,6 +237,7 @@ int LyXLookupString(XEvent * event, return result; } + // This is called after the main window has been destroyed void CloseLyXLookup() { @@ -247,3 +282,4 @@ void CloseLyXLookup() } #endif // HAVE_XOPENIM +