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;
167 if (XFilterEvent (event, None)) {
168 //lyxerr <<"XFilterEvent");
169 *keysym_return = NoSymbol;
172 if (event->type != KeyPress)
173 lyxerr << "LyXLookupString: wrong event type"
174 << event->type << endl;
175 Status status_return = 0;
177 result = XmbLookupString(xic, &event->xkey, buffer_return,
178 bytes_buffer, keysym_return,
180 switch(status_return) {
182 //lyxerr <<"XLookupBoth");
185 //lyxerr <<"XLookupChars");
186 *keysym_return = NoSymbol;
189 //lyxerr <<"XLookupKeySym");
193 //lyxerr <<"default");
194 *keysym_return = NoSymbol;
199 result = XLookupString(&event->xkey, buffer_return,
200 bytes_buffer, keysym_return,
206 // This is called after the main window has been destroyed
207 void CloseLyXLookup()
210 lyxerr[Debug::KEY] << "CloseLyXLookup: destroying input context"
219 #else // We do not have XOpenIM, so we stick with normal XLookupString
221 #include <X11/Xlib.h>
222 #include <X11/Xutil.h>
224 XComposeStatus compose_status= {0, 0};
226 // This is called after the main LyX window has been created
227 void InitLyXLookup(Display *, Window )
232 // This is called instead of XLookupString(). I this particular case,
233 // this *is* XLookupString...
234 int LyXLookupString(XEvent * event,
235 char * buffer_return, int bytes_buffer,
236 KeySym * keysym_return)
238 return XLookupString(&event->xkey, buffer_return,
239 bytes_buffer, keysym_return,
243 // This is called after the main window has been destroyed
244 void CloseLyXLookup()
249 #endif // HAVE_XOPENIM