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 * ====================================================== */
14 // This part is the full blown Input Method manager for X11R5 and up.
15 // For the plain-and-old-X11R4 version, see later.
18 #include <X11/Xutil.h>
19 #include <X11/keysym.h>
32 XComposeStatus compose_status= {0, 0};
34 // This is called after the main LyX window has been created
35 void InitLyXLookup(Display * display, Window window)
39 // This part could be done before opening display
40 setlocale(LC_CTYPE, "");
41 if (!XSupportsLocale()) {
43 << "InitLyXLookup: X does not support this locale."
47 if (!XSetLocaleModifiers("")) {
48 lyxerr[Debug::KEY] << "InitLyXLookup: Could not set modifiers "
49 "for this locale." << endl;
53 // This part will have to be done for each frame
54 xim = XOpenIM (display, 0, 0, 0);
56 xic = XCreateIC(xim, XNInputStyle,
57 XIMPreeditNothing | XIMStatusNothing,
58 XNClientWindow, window,
59 XNFocusWindow, window,
63 lyxerr[Debug::KEY] << "InitLyXLookup: could not create "
64 "an input context" << endl;
70 lyxerr[Debug::KEY] << "InitLyXLookup: could not open "
71 "an input method." << endl;
76 bool isDeadEvent(XEvent * event,
77 char * buffer_return, int bytes_buffer,
78 KeySym * keysym_return)
80 XLookupString(&event->xkey, buffer_return,
81 bytes_buffer, keysym_return,
84 // somehow it is necessary to do the lookup. Why? (JMarc)
85 if (!lyxrc.override_x_deadkeys)
88 // Can this be done safely in any other way?
89 // This is all the dead keys I know of in X11R6.1
90 switch (*keysym_return) {
97 #ifdef XK_dead_circumflex
98 case XK_dead_circumflex:
103 #ifdef XK_dead_macron
109 #ifdef XK_dead_abovedot
110 case XK_dead_abovedot:
112 #ifdef XK_dead_diaeresis
113 case XK_dead_diaeresis:
115 #ifdef XK_dead_abovering
116 case XK_dead_abovering:
118 #ifdef XK_dead_doubleacute
119 case XK_dead_doubleacute:
124 #ifdef XK_dead_cedilla
125 case XK_dead_cedilla:
127 #ifdef XK_dead_ogonek
133 #ifdef XK_dead_voiced_sound
134 case XK_dead_voiced_sound:
136 #ifdef XK_dead_semivoiced_sound
137 case XK_dead_semivoiced_sound:
139 #ifdef XK_dead_belowdot
140 case XK_dead_belowdot:
149 // This is called instead of XLookupString()
150 int LyXLookupString(XEvent * event,
151 char * buffer_return, int bytes_buffer,
152 KeySym * keysym_return)
156 if (isDeadEvent(event, buffer_return, bytes_buffer,
159 << "LyXLookupString: found DeadEvent" << endl;
162 if (XFilterEvent (event, None)) {
163 //lyxerr <<"XFilterEvent");
164 *keysym_return = NoSymbol;
167 if (event->type != KeyPress)
168 lyxerr << "LyXLookupString: wrong event type"
169 << event->type << endl;
170 Status status_return = 0;
172 result = XmbLookupString(xic, &event->xkey, buffer_return,
173 bytes_buffer, keysym_return,
175 switch(status_return) {
177 //lyxerr <<"XLookupBoth");
180 //lyxerr <<"XLookupChars");
181 *keysym_return = NoSymbol;
184 //lyxerr <<"XLookupKeySym");
188 //lyxerr <<"default");
189 *keysym_return = NoSymbol;
194 result = XLookupString(&event->xkey, buffer_return,
195 bytes_buffer, keysym_return,
201 // This is called after the main window has been destroyed
202 void CloseLyXLookup()
205 lyxerr[Debug::KEY] << "CloseLyXLookup: destroying input context"
214 #else // We do not have XOpenIM, so we stick with normal XLookupString
216 #include <X11/Xlib.h>
217 #include <X11/Xutil.h>
219 XComposeStatus compose_status= {0, 0};
221 // This is called after the main LyX window has been created
222 void InitLyXLookup(Display *, Window )
227 // This is called instead of XLookupString(). I this particular case,
228 // this *is* XLookupString...
229 int LyXLookupString(XEvent * event,
230 char * buffer_return, int bytes_buffer,
231 KeySym * keysym_return)
233 return XLookupString(&event->xkey, buffer_return,
234 bytes_buffer, keysym_return,
238 // This is called after the main window has been destroyed
239 void CloseLyXLookup()
244 #endif // HAVE_XOPENIM