3 * Read the file COPYING
7 * Full author contact details are available in file CREDITS
11 #pragma implementation
17 // This part is the full blown Input Method manager for X11R5 and up.
18 // For the plain-and-old-X11R4 version, see later.
20 #include <X11/Xutil.h>
21 #include <X11/keysym.h>
27 #include "lyxlookup.h"
37 XComposeStatus compose_status= {0, 0};
42 // This is called after the main LyX window has been created
43 void InitLyXLookup(Display * display, Window window)
48 << "InitLyXLookup: creating an input context."
51 // This part could be done before opening display
52 string oldlocale = setlocale(LC_CTYPE, 0);
53 setlocale(LC_CTYPE, "");
54 if (!XSupportsLocale()) {
56 << "InitLyXLookup: X does not support this locale."
60 // reset the LC_CTYPE locale to previous value.
61 setlocale(LC_CTYPE, oldlocale.c_str());
64 if (!(locmod = XSetLocaleModifiers(""))) {
65 lyxerr[Debug::KEY] << "InitLyXLookup: Could not set modifiers "
66 "for this locale." << endl;
70 lyxerr[Debug::KEY] << "InitLyXLookup: X locale modifiers are `"
71 << locmod << '\'' << endl;
73 // This part will have to be done for each frame
74 xim = XOpenIM (display, 0, 0, 0);
78 XIMPreeditNothing|XIMStatusNothing,
79 XNClientWindow, window,
80 XNFocusWindow, window,
84 lyxerr[Debug::KEY] << "InitLyXLookup: "
85 "could not create an input context" << endl;
91 lyxerr[Debug::KEY] << "InitLyXLookup: could not open "
92 "an input method." << endl;
98 bool isDeadEvent(KeySym keysym)
100 // Can this be done safely in any other way?
101 // This is all the dead keys I know of in X11R6.1
109 #ifdef XK_dead_circumflex
110 case XK_dead_circumflex:
115 #ifdef XK_dead_macron
121 #ifdef XK_dead_abovedot
122 case XK_dead_abovedot:
124 #ifdef XK_dead_diaeresis
125 case XK_dead_diaeresis:
127 #ifdef XK_dead_abovering
128 case XK_dead_abovering:
130 #ifdef XK_dead_doubleacute
131 case XK_dead_doubleacute:
136 #ifdef XK_dead_cedilla
137 case XK_dead_cedilla:
139 #ifdef XK_dead_ogonek
145 #ifdef XK_dead_voiced_sound
146 case XK_dead_voiced_sound:
148 #ifdef XK_dead_semivoiced_sound
149 case XK_dead_semivoiced_sound:
151 #ifdef XK_dead_belowdot
152 case XK_dead_belowdot:
163 // This is called instead of XLookupString()
164 int LyXLookupString(XEvent * event,
165 char * buffer_return, int bytes_buffer,
166 KeySym * keysym_return)
168 if (event->type != KeyPress) {
169 lyxerr << "LyXLookupString: wrong event type: "
170 << event->type << endl;
177 // somehow it is necessary to do the lookup. Why? (JMarc)
178 XLookupString(&event->xkey, buffer_return,
179 bytes_buffer, keysym_return,
182 if (lyxrc.override_x_deadkeys &&
183 isDeadEvent(*keysym_return)) {
185 << "LyXLookupString: found DeadEvent" << endl;
190 if (XFilterEvent (event, None)) {
191 lyxerr[Debug::KEY] <<"XFilterEvent" << endl;
192 *keysym_return = NoSymbol;
196 Status status_return = 0;
198 result = XmbLookupString(xic, &event->xkey, buffer_return,
199 bytes_buffer, keysym_return,
201 switch (status_return) {
202 case XBufferOverflow:
203 lyxerr[Debug::KEY] << "XBufferOverflow" << endl;
206 lyxerr[Debug::KEY] << "XLookupBoth "
207 << string(buffer_return, result)
211 lyxerr[Debug::KEY] << "XLookupChars "
212 << string(buffer_return, result)
215 *keysym_return = NoSymbol;
218 lyxerr[Debug::KEY] << "XLookupKeySym" << endl;
222 lyxerr[Debug::KEY] << "XLookupNone" << endl;
223 *keysym_return = NoSymbol;
227 lyxerr << "Unknown status_return from"
228 " XmbLookupString" << endl;
232 result = XLookupString(&event->xkey, buffer_return,
233 bytes_buffer, keysym_return,
240 // This is called after the main window has been destroyed
241 void CloseLyXLookup()
244 lyxerr[Debug::KEY] << "CloseLyXLookup: destroying input context"
253 #else // We do not have XOpenIM, so we stick with normal XLookupString
255 #include <X11/Xlib.h>
256 #include <X11/Xutil.h>
258 XComposeStatus compose_status= {0, 0};
260 // This is called after the main LyX window has been created
261 void InitLyXLookup(Display *, Window)
266 // This is called instead of XLookupString(). I this particular case,
267 // this *is* XLookupString...
268 int LyXLookupString(XEvent * event,
269 char * buffer_return, int bytes_buffer,
270 KeySym * keysym_return)
272 return XLookupString(&event->xkey, buffer_return,
273 bytes_buffer, keysym_return,
277 // This is called after the main window has been destroyed
278 void CloseLyXLookup()
283 #endif // HAVE_XOPENIM