1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 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"
38 XComposeStatus compose_status= {0, 0};
43 // This is called after the main LyX window has been created
44 void InitLyXLookup(Display * display, Window window)
49 << "InitLyXLookup: creating an input context."
52 // This part could be done before opening display
53 string oldlocale = setlocale(LC_CTYPE, 0);
54 setlocale(LC_CTYPE, "");
55 if (!XSupportsLocale()) {
57 << "InitLyXLookup: X does not support this locale."
61 // reset the LC_CTYPE locale to previous value.
62 setlocale(LC_CTYPE, oldlocale.c_str());
65 if (!(locmod = XSetLocaleModifiers(""))) {
66 lyxerr[Debug::KEY] << "InitLyXLookup: Could not set modifiers "
67 "for this locale." << endl;
71 lyxerr[Debug::KEY] << "InitLyXLookup: X locale modifiers are `"
72 << locmod << '\'' << endl;
74 // This part will have to be done for each frame
75 xim = XOpenIM (display, 0, 0, 0);
79 XIMPreeditNothing|XIMStatusNothing,
80 XNClientWindow, window,
81 XNFocusWindow, window,
85 lyxerr[Debug::KEY] << "InitLyXLookup: "
86 "could not create an input context" << endl;
92 lyxerr[Debug::KEY] << "InitLyXLookup: could not open "
93 "an input method." << endl;
99 bool isDeadEvent(KeySym keysym)
101 // Can this be done safely in any other way?
102 // This is all the dead keys I know of in X11R6.1
110 #ifdef XK_dead_circumflex
111 case XK_dead_circumflex:
116 #ifdef XK_dead_macron
122 #ifdef XK_dead_abovedot
123 case XK_dead_abovedot:
125 #ifdef XK_dead_diaeresis
126 case XK_dead_diaeresis:
128 #ifdef XK_dead_abovering
129 case XK_dead_abovering:
131 #ifdef XK_dead_doubleacute
132 case XK_dead_doubleacute:
137 #ifdef XK_dead_cedilla
138 case XK_dead_cedilla:
140 #ifdef XK_dead_ogonek
146 #ifdef XK_dead_voiced_sound
147 case XK_dead_voiced_sound:
149 #ifdef XK_dead_semivoiced_sound
150 case XK_dead_semivoiced_sound:
152 #ifdef XK_dead_belowdot
153 case XK_dead_belowdot:
164 // This is called instead of XLookupString()
165 int LyXLookupString(XEvent * event,
166 char * buffer_return, int bytes_buffer,
167 KeySym * keysym_return)
169 if (event->type != KeyPress) {
170 lyxerr << "LyXLookupString: wrong event type: "
171 << event->type << endl;
178 // somehow it is necessary to do the lookup. Why? (JMarc)
179 XLookupString(&event->xkey, buffer_return,
180 bytes_buffer, keysym_return,
183 if (lyxrc.override_x_deadkeys &&
184 isDeadEvent(*keysym_return)) {
186 << "LyXLookupString: found DeadEvent" << endl;
191 if (XFilterEvent (event, None)) {
192 lyxerr[Debug::KEY] <<"XFilterEvent" << endl;
193 *keysym_return = NoSymbol;
197 Status status_return = 0;
199 result = XmbLookupString(xic, &event->xkey, buffer_return,
200 bytes_buffer, keysym_return,
202 switch (status_return) {
203 case XBufferOverflow:
204 lyxerr[Debug::KEY] << "XBufferOverflow" << endl;
207 lyxerr[Debug::KEY] << "XLookupBoth "
208 << string(buffer_return, result)
212 lyxerr[Debug::KEY] << "XLookupChars "
213 << string(buffer_return, result)
216 *keysym_return = NoSymbol;
219 lyxerr[Debug::KEY] << "XLookupKeySym" << endl;
223 lyxerr[Debug::KEY] << "XLookupNone" << endl;
224 *keysym_return = NoSymbol;
228 lyxerr << "Unknown status_return from"
229 " XmbLookupString" << endl;
233 result = XLookupString(&event->xkey, buffer_return,
234 bytes_buffer, keysym_return,
241 // This is called after the main window has been destroyed
242 void CloseLyXLookup()
245 lyxerr[Debug::KEY] << "CloseLyXLookup: destroying input context"
254 #else // We do not have XOpenIM, so we stick with normal XLookupString
256 #include <X11/Xlib.h>
257 #include <X11/Xutil.h>
259 XComposeStatus compose_status= {0, 0};
261 // This is called after the main LyX window has been created
262 void InitLyXLookup(Display *, Window )
267 // This is called instead of XLookupString(). I this particular case,
268 // this *is* XLookupString...
269 int LyXLookupString(XEvent * event,
270 char * buffer_return, int bytes_buffer,
271 KeySym * keysym_return)
273 return XLookupString(&event->xkey, buffer_return,
274 bytes_buffer, keysym_return,
278 // This is called after the main window has been destroyed
279 void CloseLyXLookup()
284 #endif // HAVE_XOPENIM