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.
20 #include FORMS_H_LOCATION
21 //#include <X11/Xlib.h>
22 //#include <X11/Xutil.h>
23 //#include <X11/keysym.h>
30 #include "lyxlookup.h"
38 XComposeStatus compose_status= {0, 0};
40 // This is called after the main LyX window has been created
41 void InitLyXLookup(Display * display, Window window)
45 // This part could be done before opening display
46 setlocale(LC_CTYPE, "");
47 if (!XSupportsLocale()) {
49 << "InitLyXLookup: X does not support this locale."
53 if (!XSetLocaleModifiers("")) {
54 lyxerr[Debug::KEY] << "InitLyXLookup: Could not set modifiers "
55 "for this locale." << endl;
59 // This part will have to be done for each frame
60 xim = XOpenIM (display, 0, 0, 0);
62 xic = XCreateIC(xim, XNInputStyle,
63 XIMPreeditNothing | XIMStatusNothing,
64 XNClientWindow, window,
65 XNFocusWindow, window,
69 lyxerr[Debug::KEY] << "InitLyXLookup: could not create "
70 "an input context" << endl;
76 lyxerr[Debug::KEY] << "InitLyXLookup: could not open "
77 "an input method." << endl;
82 bool isDeadEvent(XEvent * event,
83 char * buffer_return, int bytes_buffer,
84 KeySym * keysym_return)
86 XLookupString(&event->xkey, buffer_return,
87 bytes_buffer, keysym_return,
90 // somehow it is necessary to do the lookup. Why? (JMarc)
91 if (!lyxrc.override_x_deadkeys)
94 // Can this be done safely in any other way?
95 // This is all the dead keys I know of in X11R6.1
96 switch (*keysym_return) {
103 #ifdef XK_dead_circumflex
104 case XK_dead_circumflex:
109 #ifdef XK_dead_macron
115 #ifdef XK_dead_abovedot
116 case XK_dead_abovedot:
118 #ifdef XK_dead_diaeresis
119 case XK_dead_diaeresis:
121 #ifdef XK_dead_abovering
122 case XK_dead_abovering:
124 #ifdef XK_dead_doubleacute
125 case XK_dead_doubleacute:
130 #ifdef XK_dead_cedilla
131 case XK_dead_cedilla:
133 #ifdef XK_dead_ogonek
139 #ifdef XK_dead_voiced_sound
140 case XK_dead_voiced_sound:
142 #ifdef XK_dead_semivoiced_sound
143 case XK_dead_semivoiced_sound:
145 #ifdef XK_dead_belowdot
146 case XK_dead_belowdot:
155 // This is called instead of XLookupString()
156 int LyXLookupString(XEvent * event,
157 char * buffer_return, int bytes_buffer,
158 KeySym * keysym_return)
162 if (isDeadEvent(event, buffer_return, bytes_buffer,
165 << "LyXLookupString: found DeadEvent" << endl;
169 if (XFilterEvent (event, None)) {
170 lyxerr[Debug::KEY] <<"XFilterEvent" << endl;
171 *keysym_return = NoSymbol;
175 if (event->type != KeyPress)
176 lyxerr << "LyXLookupString: wrong event type"
177 << event->type << endl;
178 Status status_return = 0;
180 result = XmbLookupString(xic, &event->xkey, buffer_return,
181 bytes_buffer, keysym_return,
183 switch(status_return) {
184 case XBufferOverflow:
185 lyxerr[Debug::KEY] << "XBufferOverflow" << endl;
188 lyxerr[Debug::KEY] << "XLookupBoth"
189 << string(buffer_return, result)
193 lyxerr[Debug::KEY] << "XLookupChars "
194 << string(buffer_return, result)
197 *keysym_return = NoSymbol;
200 lyxerr[Debug::KEY] << "XLookupKeySym" << endl;
204 lyxerr[Debug::KEY] << "XLookupNone" << endl;
205 *keysym_return = NoSymbol;
209 lyxerr << "Unknown status_return from"
210 " XmbLookupString" << endl;
214 result = XLookupString(&event->xkey, buffer_return,
215 bytes_buffer, keysym_return,
222 // This is called after the main window has been destroyed
223 void CloseLyXLookup()
226 lyxerr[Debug::KEY] << "CloseLyXLookup: destroying input context"
235 #else // We do not have XOpenIM, so we stick with normal XLookupString
237 #include <X11/Xlib.h>
238 #include <X11/Xutil.h>
240 XComposeStatus compose_status= {0, 0};
242 // This is called after the main LyX window has been created
243 void InitLyXLookup(Display *, Window )
248 // This is called instead of XLookupString(). I this particular case,
249 // this *is* XLookupString...
250 int LyXLookupString(XEvent * event,
251 char * buffer_return, int bytes_buffer,
252 KeySym * keysym_return)
254 return XLookupString(&event->xkey, buffer_return,
255 bytes_buffer, keysym_return,
259 // This is called after the main window has been destroyed
260 void CloseLyXLookup()
265 #endif // HAVE_XOPENIM