1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX team.
9 * ====================================================== */
12 #pragma implementation
18 // This part is the full blown Input Method manager for X11R5 and up.
19 // For the plain-and-old-X11R4 version, see later.
21 #include <X11/Xutil.h>
22 #include <X11/keysym.h>
28 #include "lyxlookup.h"
36 XComposeStatus compose_status= {0, 0};
38 // This is called after the main LyX window has been created
39 void InitLyXLookup(Display * display, Window window)
44 << "InitLyXLookup: creating an input context."
47 // This part could be done before opening display
48 string oldlocale = setlocale(LC_CTYPE, 0);
49 setlocale(LC_CTYPE, "");
50 if (!XSupportsLocale()) {
52 << "InitLyXLookup: X does not support this locale."
56 // reset the LC_CTYPE locale to previous value.
57 setlocale(LC_CTYPE, oldlocale.c_str());
60 if (!(locmod = XSetLocaleModifiers(""))) {
61 lyxerr[Debug::KEY] << "InitLyXLookup: Could not set modifiers "
62 "for this locale." << endl;
66 lyxerr[Debug::KEY] << "InitLyXLookup: X locale modifiers are `"
67 << locmod << '\'' << endl;
69 // This part will have to be done for each frame
70 xim = XOpenIM (display, 0, 0, 0);
74 XIMPreeditNothing|XIMStatusNothing,
75 XNClientWindow, window,
76 XNFocusWindow, window,
80 lyxerr[Debug::KEY] << "InitLyXLookup: "
81 "could not create an input context" << endl;
87 lyxerr[Debug::KEY] << "InitLyXLookup: could not open "
88 "an input method." << endl;
93 bool isDeadEvent(KeySym keysym)
95 // Can this be done safely in any other way?
96 // This is all the dead keys I know of in X11R6.1
104 #ifdef XK_dead_circumflex
105 case XK_dead_circumflex:
110 #ifdef XK_dead_macron
116 #ifdef XK_dead_abovedot
117 case XK_dead_abovedot:
119 #ifdef XK_dead_diaeresis
120 case XK_dead_diaeresis:
122 #ifdef XK_dead_abovering
123 case XK_dead_abovering:
125 #ifdef XK_dead_doubleacute
126 case XK_dead_doubleacute:
131 #ifdef XK_dead_cedilla
132 case XK_dead_cedilla:
134 #ifdef XK_dead_ogonek
140 #ifdef XK_dead_voiced_sound
141 case XK_dead_voiced_sound:
143 #ifdef XK_dead_semivoiced_sound
144 case XK_dead_semivoiced_sound:
146 #ifdef XK_dead_belowdot
147 case XK_dead_belowdot:
156 // This is called instead of XLookupString()
157 int LyXLookupString(XEvent * event,
158 char * buffer_return, int bytes_buffer,
159 KeySym * keysym_return)
161 if (event->type != KeyPress) {
162 lyxerr << "LyXLookupString: wrong event type: "
163 << event->type << endl;
170 // somehow it is necessary to do the lookup. Why? (JMarc)
171 XLookupString(&event->xkey, buffer_return,
172 bytes_buffer, keysym_return,
175 if (lyxrc.override_x_deadkeys &&
176 isDeadEvent(*keysym_return)) {
178 << "LyXLookupString: found DeadEvent" << endl;
183 if (XFilterEvent (event, None)) {
184 lyxerr[Debug::KEY] <<"XFilterEvent" << endl;
185 *keysym_return = NoSymbol;
189 Status status_return = 0;
191 result = XmbLookupString(xic, &event->xkey, buffer_return,
192 bytes_buffer, keysym_return,
194 switch (status_return) {
195 case XBufferOverflow:
196 lyxerr[Debug::KEY] << "XBufferOverflow" << endl;
199 lyxerr[Debug::KEY] << "XLookupBoth "
200 << string(buffer_return, result)
204 lyxerr[Debug::KEY] << "XLookupChars "
205 << string(buffer_return, result)
208 *keysym_return = NoSymbol;
211 lyxerr[Debug::KEY] << "XLookupKeySym" << endl;
215 lyxerr[Debug::KEY] << "XLookupNone" << endl;
216 *keysym_return = NoSymbol;
220 lyxerr << "Unknown status_return from"
221 " XmbLookupString" << endl;
225 result = XLookupString(&event->xkey, buffer_return,
226 bytes_buffer, keysym_return,
233 // This is called after the main window has been destroyed
234 void CloseLyXLookup()
237 lyxerr[Debug::KEY] << "CloseLyXLookup: destroying input context"
246 #else // We do not have XOpenIM, so we stick with normal XLookupString
248 #include <X11/Xlib.h>
249 #include <X11/Xutil.h>
251 XComposeStatus compose_status= {0, 0};
253 // This is called after the main LyX window has been created
254 void InitLyXLookup(Display *, Window )
259 // This is called instead of XLookupString(). I this particular case,
260 // this *is* XLookupString...
261 int LyXLookupString(XEvent * event,
262 char * buffer_return, int bytes_buffer,
263 KeySym * keysym_return)
265 return XLookupString(&event->xkey, buffer_return,
266 bytes_buffer, keysym_return,
270 // This is called after the main window has been destroyed
271 void CloseLyXLookup()
276 #endif // HAVE_XOPENIM