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.
22 #include <X11/Xutil.h>
23 #include <X11/keysym.h>
29 #include "lyxlookup.h"
37 XComposeStatus compose_status= {0, 0};
39 // This is called after the main LyX window has been created
40 void InitLyXLookup(Display * display, Window window)
44 // This part could be done before opening display
45 setlocale(LC_CTYPE, "");
46 if (!XSupportsLocale()) {
48 << "InitLyXLookup: X does not support this locale."
52 if (!XSetLocaleModifiers("")) {
53 lyxerr[Debug::KEY] << "InitLyXLookup: Could not set modifiers "
54 "for this locale." << endl;
58 // This part will have to be done for each frame
59 xim = XOpenIM (display, 0, 0, 0);
61 xic = XCreateIC(xim, XNInputStyle,
62 XIMPreeditNothing | XIMStatusNothing,
63 XNClientWindow, window,
64 XNFocusWindow, window,
68 lyxerr[Debug::KEY] << "InitLyXLookup: could not create "
69 "an input context" << endl;
75 lyxerr[Debug::KEY] << "InitLyXLookup: could not open "
76 "an input method." << endl;
81 bool isDeadEvent(XEvent * event,
82 char * buffer_return, int bytes_buffer,
83 KeySym * keysym_return)
85 XLookupString(&event->xkey, buffer_return,
86 bytes_buffer, keysym_return,
89 // somehow it is necessary to do the lookup. Why? (JMarc)
90 if (!lyxrc.override_x_deadkeys)
93 // Can this be done safely in any other way?
94 // This is all the dead keys I know of in X11R6.1
95 switch (*keysym_return) {
102 #ifdef XK_dead_circumflex
103 case XK_dead_circumflex:
108 #ifdef XK_dead_macron
114 #ifdef XK_dead_abovedot
115 case XK_dead_abovedot:
117 #ifdef XK_dead_diaeresis
118 case XK_dead_diaeresis:
120 #ifdef XK_dead_abovering
121 case XK_dead_abovering:
123 #ifdef XK_dead_doubleacute
124 case XK_dead_doubleacute:
129 #ifdef XK_dead_cedilla
130 case XK_dead_cedilla:
132 #ifdef XK_dead_ogonek
138 #ifdef XK_dead_voiced_sound
139 case XK_dead_voiced_sound:
141 #ifdef XK_dead_semivoiced_sound
142 case XK_dead_semivoiced_sound:
144 #ifdef XK_dead_belowdot
145 case XK_dead_belowdot:
154 // This is called instead of XLookupString()
155 int LyXLookupString(XEvent * event,
156 char * buffer_return, int bytes_buffer,
157 KeySym * keysym_return)
161 if (isDeadEvent(event, buffer_return, bytes_buffer,
164 << "LyXLookupString: found DeadEvent" << endl;
168 if (XFilterEvent (event, None)) {
169 lyxerr[Debug::KEY] <<"XFilterEvent" << endl;
170 *keysym_return = NoSymbol;
174 if (event->type != KeyPress)
175 lyxerr << "LyXLookupString: wrong event type"
176 << event->type << endl;
177 Status status_return = 0;
179 result = XmbLookupString(xic, &event->xkey, buffer_return,
180 bytes_buffer, keysym_return,
182 switch(status_return) {
183 case XBufferOverflow:
184 lyxerr[Debug::KEY] << "XBufferOverflow" << endl;
187 lyxerr[Debug::KEY] << "XLookupBoth"
188 << string(buffer_return, result)
192 lyxerr[Debug::KEY] << "XLookupChars "
193 << string(buffer_return, result)
196 *keysym_return = NoSymbol;
199 lyxerr[Debug::KEY] << "XLookupKeySym" << endl;
203 lyxerr[Debug::KEY] << "XLookupNone" << endl;
204 *keysym_return = NoSymbol;
208 lyxerr << "Unknown status_return from"
209 " XmbLookupString" << endl;
213 result = XLookupString(&event->xkey, buffer_return,
214 bytes_buffer, keysym_return,
221 // This is called after the main window has been destroyed
222 void CloseLyXLookup()
225 lyxerr[Debug::KEY] << "CloseLyXLookup: destroying input context"
234 #else // We do not have XOpenIM, so we stick with normal XLookupString
236 #include <X11/Xlib.h>
237 #include <X11/Xutil.h>
239 XComposeStatus compose_status= {0, 0};
241 // This is called after the main LyX window has been created
242 void InitLyXLookup(Display *, Window )
247 // This is called instead of XLookupString(). I this particular case,
248 // this *is* XLookupString...
249 int LyXLookupString(XEvent * event,
250 char * buffer_return, int bytes_buffer,
251 KeySym * keysym_return)
253 return XLookupString(&event->xkey, buffer_return,
254 bytes_buffer, keysym_return,
258 // This is called after the main window has been destroyed
259 void CloseLyXLookup()
264 #endif // HAVE_XOPENIM