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 setlocale(LC_CTYPE, "");
49 if (!XSupportsLocale()) {
51 << "InitLyXLookup: X does not support this locale."
55 if (!XSetLocaleModifiers("")) {
56 lyxerr[Debug::KEY] << "InitLyXLookup: Could not set modifiers "
57 "for this locale." << endl;
61 // This part will have to be done for each frame
62 xim = XOpenIM (display, 0, 0, 0);
64 xic = XCreateIC(xim, XNInputStyle,
65 XIMPreeditNothing | XIMStatusNothing,
66 XNClientWindow, window,
67 XNFocusWindow, window,
71 lyxerr[Debug::KEY] << "InitLyXLookup: could not create "
72 "an input context" << endl;
78 lyxerr[Debug::KEY] << "InitLyXLookup: could not open "
79 "an input method." << endl;
84 bool isDeadEvent(XEvent * event,
85 char * buffer_return, int bytes_buffer,
86 KeySym * keysym_return)
88 XLookupString(&event->xkey, buffer_return,
89 bytes_buffer, keysym_return,
92 // somehow it is necessary to do the lookup. Why? (JMarc)
93 if (!lyxrc.override_x_deadkeys)
96 // Can this be done safely in any other way?
97 // This is all the dead keys I know of in X11R6.1
98 switch (*keysym_return) {
105 #ifdef XK_dead_circumflex
106 case XK_dead_circumflex:
111 #ifdef XK_dead_macron
117 #ifdef XK_dead_abovedot
118 case XK_dead_abovedot:
120 #ifdef XK_dead_diaeresis
121 case XK_dead_diaeresis:
123 #ifdef XK_dead_abovering
124 case XK_dead_abovering:
126 #ifdef XK_dead_doubleacute
127 case XK_dead_doubleacute:
132 #ifdef XK_dead_cedilla
133 case XK_dead_cedilla:
135 #ifdef XK_dead_ogonek
141 #ifdef XK_dead_voiced_sound
142 case XK_dead_voiced_sound:
144 #ifdef XK_dead_semivoiced_sound
145 case XK_dead_semivoiced_sound:
147 #ifdef XK_dead_belowdot
148 case XK_dead_belowdot:
157 // This is called instead of XLookupString()
158 int LyXLookupString(XEvent * event,
159 char * buffer_return, int bytes_buffer,
160 KeySym * keysym_return)
164 if (isDeadEvent(event, buffer_return, bytes_buffer,
167 << "LyXLookupString: found DeadEvent" << endl;
171 if (XFilterEvent (event, None)) {
172 lyxerr[Debug::KEY] <<"XFilterEvent" << endl;
173 *keysym_return = NoSymbol;
177 if (event->type != KeyPress)
178 lyxerr << "LyXLookupString: wrong event type"
179 << event->type << endl;
180 Status status_return = 0;
182 result = XmbLookupString(xic, &event->xkey, buffer_return,
183 bytes_buffer, keysym_return,
185 switch (status_return) {
186 case XBufferOverflow:
187 lyxerr[Debug::KEY] << "XBufferOverflow" << endl;
190 lyxerr[Debug::KEY] << "XLookupBoth "
191 << string(buffer_return, result)
195 lyxerr[Debug::KEY] << "XLookupChars "
196 << string(buffer_return, result)
199 *keysym_return = NoSymbol;
202 lyxerr[Debug::KEY] << "XLookupKeySym" << endl;
206 lyxerr[Debug::KEY] << "XLookupNone" << endl;
207 *keysym_return = NoSymbol;
211 lyxerr << "Unknown status_return from"
212 " XmbLookupString" << endl;
216 result = XLookupString(&event->xkey, buffer_return,
217 bytes_buffer, keysym_return,
224 // This is called after the main window has been destroyed
225 void CloseLyXLookup()
228 lyxerr[Debug::KEY] << "CloseLyXLookup: destroying input context"
237 #else // We do not have XOpenIM, so we stick with normal XLookupString
239 #include <X11/Xlib.h>
240 #include <X11/Xutil.h>
242 XComposeStatus compose_status= {0, 0};
244 // This is called after the main LyX window has been created
245 void InitLyXLookup(Display *, Window )
250 // This is called instead of XLookupString(). I this particular case,
251 // this *is* XLookupString...
252 int LyXLookupString(XEvent * event,
253 char * buffer_return, int bytes_buffer,
254 KeySym * keysym_return)
256 return XLookupString(&event->xkey, buffer_return,
257 bytes_buffer, keysym_return,
261 // This is called after the main window has been destroyed
262 void CloseLyXLookup()
267 #endif // HAVE_XOPENIM