1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 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>
28 XComposeStatus compose_status= {0, 0};
30 // This is called after the main LyX window has been created
31 void InitLyXLookup(Display * display, Window window)
35 // This part could be done before opening display
36 setlocale(LC_CTYPE, "");
37 if (!XSupportsLocale()) {
39 << "InitLyXLookup: X does not support this locale."
43 if (!XSetLocaleModifiers("")) {
44 lyxerr.debug() << "InitLyXLookup: Could not set modifiers "
45 "for this locale." << endl;
49 // This part will have to be done for each frame
50 xim = XOpenIM (display, 0, 0, 0);
52 xic = XCreateIC(xim, XNInputStyle,
53 XIMPreeditNothing | XIMStatusNothing,
54 XNClientWindow, window,
55 XNFocusWindow, window,
59 lyxerr.debug() << "InitLyXLookup: could not create "
60 "an input context" << endl;
66 lyxerr.debug() << "InitLyXLookup: could not open "
67 "an input method." << endl;
72 bool isDeadEvent(XEvent * event,
73 char * buffer_return, int bytes_buffer,
74 KeySym * keysym_return)
76 XLookupString(&event->xkey, buffer_return,
77 bytes_buffer, keysym_return,
79 // Can this be done safely in any other way?
80 // This is all the dead keys I know of in X11R6.1
83 || *keysym_return == XK_dead_grave
86 || *keysym_return == XK_dead_acute
88 #ifdef XK_dead_circumflex
89 || *keysym_return == XK_dead_circumflex
92 || *keysym_return == XK_dead_tilde
95 || *keysym_return == XK_dead_macron
98 || *keysym_return == XK_dead_breve
100 #ifdef XK_dead_abovedot
101 || *keysym_return == XK_dead_abovedot
103 #ifdef XK_dead_diaeresis
104 || *keysym_return == XK_dead_diaeresis
106 #ifdef XK_dead_abovering
107 || *keysym_return == XK_dead_abovering
109 #ifdef XK_dead_doubleacute
110 || *keysym_return == XK_dead_doubleacute
113 || *keysym_return == XK_dead_caron
115 #ifdef XK_dead_cedilla
116 || *keysym_return == XK_dead_cedilla
118 #ifdef XK_dead_ogonek
119 || *keysym_return == XK_dead_ogonek
122 || *keysym_return == XK_dead_iota
124 #ifdef XK_dead_voiced_sound
125 || *keysym_return == XK_dead_voiced_sound
127 #ifdef XK_dead_semivoiced_sound
128 || *keysym_return == XK_dead_semivoiced_sound
130 #ifdef XK_dead_belowdot
131 || *keysym_return == XK_dead_belowdot
139 // This is called instead of XLookupString()
140 int LyXLookupString(XEvent * event,
141 char * buffer_return, int bytes_buffer,
142 KeySym * keysym_return)
146 if (isDeadEvent(event, buffer_return, bytes_buffer,
150 if (XFilterEvent (event, None)) {
151 //lyxerr <<"XFilterEvent");
152 *keysym_return = NoSymbol;
155 if (event->type != KeyPress)
156 lyxerr << "LyXLookupString: wrong event type"
157 << event->type << endl;
158 Status status_return;
160 result = XmbLookupString(xic, &event->xkey, buffer_return,
161 bytes_buffer, keysym_return,
163 switch(status_return) {
165 //lyxerr <<"XLookupBoth");
168 //lyxerr <<"XLookupChars");
169 *keysym_return = NoSymbol;
172 //lyxerr <<"XLookupKeySym");
176 //lyxerr <<"default");
177 *keysym_return = NoSymbol;
182 result = XLookupString(&event->xkey, buffer_return,
183 bytes_buffer, keysym_return,
189 // This is called after the main window has been destroyed
190 void CloseLyXLookup()
193 lyxerr.debug() << "CloseLyXLookup: destroying input context"
201 #else // We do not have XOpenIM, so we stick with normal XLookupString
203 #include <X11/Xlib.h>
204 #include <X11/Xutil.h>
206 XComposeStatus compose_status= {0, 0};
208 // This is called after the main LyX window has been created
209 void InitLyXLookup(Display *, Window )
214 // This is called instead of XLookupString(). I this particular case,
215 // this *is* XLookupString...
216 int LyXLookupString(XEvent * event,
217 char * buffer_return, int bytes_buffer,
218 KeySym * keysym_return)
220 return XLookupString(&event->xkey, buffer_return,
221 bytes_buffer, keysym_return,
225 // This is called after the main window has been destroyed
226 void CloseLyXLookup()
231 #endif // HAVE_XOPENIM