comparison src/input-method-motif.c @ 428:3ecd8885ac67 r21-2-22

Import from CVS: tag r21-2-22
author cvs
date Mon, 13 Aug 2007 11:28:15 +0200
parents
children 84b14dcb0985
comparison
equal deleted inserted replaced
427:0a0253eac470 428:3ecd8885ac67
1 /* Various functions for X11R5+ input methods, using the Motif XmIm* functions.
2 input-method-xlib.c provides a lower-level implementation.
3 Copyright (C) 1996 Sun Microsystems.
4
5 This file is part of XEmacs.
6
7 XEmacs is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
10 later version.
11
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with XEmacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 /* Synched up with: Not in FSF. */
23
24 /* Written by Martin Buchholz. */
25
26 #include <config.h>
27 #include <X11/Xlocale.h> /* More portable than <locale.h> ? */
28 #include "lisp.h"
29 #include "console-x.h"
30 #include "device.h"
31 #include "frame.h"
32 #include "EmacsFrame.h"
33 #include <Xm/Xm.h>
34
35 #ifndef XIM_MOTIF
36 #error XIM_MOTIF is not defined??
37 #endif
38
39 void
40 Initialize_Locale (void)
41 {
42 char *locale;
43
44 /* dverna - Nov. 98: ### DON'T DO THIS !!! The default XtLanguageProc
45 routine calls setlocale(LC_ALL, lang) which fucks up our lower-level
46 locale management, and especially the value of LC_NUMERIC. Anyway, since
47 at this point, we don't know yet whether we're gonna need an X11 frame,
48 we should really do it manually and not use Xlib's dumb default routine */
49 /*XtSetLanguageProc (NULL, (XtLanguageProc) NULL, NULL);*/
50 if ((locale = setlocale (LC_ALL, "")) == NULL)
51 {
52 stderr_out ("Can't set locale.\n");
53 stderr_out ("Using C locale instead.\n");
54 putenv ("LANG=C");
55 putenv ("LC_ALL=C");
56 if ((locale = setlocale (LC_ALL, "C")) == NULL)
57 {
58 stderr_out ("Can't even set locale to `C'!\n");
59 return;
60 }
61 }
62
63 if (!XSupportsLocale ())
64 {
65 stderr_out ("X Windows does not support locale `%s'\n", locale);
66 stderr_out ("Using C Locale instead\n");
67 putenv ("LANG=C");
68 putenv ("LC_ALL=C");
69 if ((locale = setlocale (LC_ALL, "C")) == NULL)
70 {
71 stderr_out ("Can't even set locale to `C'!\n");
72 return;
73 }
74 if (!XSupportsLocale ())
75 {
76 stderr_out ("X Windows does not even support locale `C'!\n");
77 return;
78 }
79 }
80
81 setlocale(LC_NUMERIC, "C");
82
83 if (XSetLocaleModifiers ("") == NULL)
84 {
85 stderr_out ("XSetLocaleModifiers(\"\") failed\n");
86 stderr_out ("Check the value of the XMODIFIERS environment variable.\n");
87 }
88 }
89
90 /* Create X input method for device */
91 void
92 XIM_init_device (struct device *d)
93 {
94 /* Nothing to do */
95 }
96
97 void
98 XIM_init_frame (struct frame *f)
99 {
100 Widget w = FRAME_X_TEXT_WIDGET (f);
101 XPoint spot = {0,0};
102 XmFontList fontlist;
103 XmFontListEntry fontlistEntry;
104
105 typedef struct
106 {
107 XFontSet fontset;
108 Pixel fg;
109 Pixel bg;
110 } xim_resources_t;
111
112 xim_resources_t xim_resources;
113
114 /* mrb: #### Fix so that background and foreground is set from
115 default face, rather than foreground and background resources, or
116 that the user can use set-frame-parameters to set xic attributes */
117
118 #define res(name, class, representation, field, default_value) \
119 { name, class, representation, sizeof(xim_resources.field), \
120 XtOffsetOf(xim_resources_t, field), XtRString, default_value }
121
122 static XtResource resources[] =
123 {
124 /* name class represent'n field default value */
125 res(XtNfontSet, XtCFontSet, XtRFontSet, fontset, XtDefaultFontSet),
126 res(XtNximForeground, XtCForeground, XtRPixel, fg, XtDefaultForeground),
127 res(XtNximBackground, XtCBackground, XtRPixel, bg, XtDefaultBackground)
128 };
129
130 XtGetApplicationResources (w, &xim_resources,
131 resources, XtNumber (resources),
132 NULL, 0);
133
134 if (! xim_resources.fontset)
135 {
136 stderr_out ("Can't get fontset resource for Input Method\n");
137 return;
138 }
139
140 fontlistEntry = XmFontListEntryCreate(XmFONTLIST_DEFAULT_TAG,
141 XmFONT_IS_FONTSET,
142 (XtPointer) xim_resources.fontset);
143 fontlist = XmFontListAppendEntry (NULL, fontlistEntry);
144 XmImRegister (w, 0);
145 XmImVaSetValues (w,
146 XmNfontList, fontlist,
147 XmNforeground, xim_resources.fg,
148 XmNbackground, xim_resources.bg,
149 XmNspotLocation, &spot,
150 /* XmNlineSpace, 0, */
151 NULL);
152
153 XmFontListEntryFree (&fontlistEntry);
154 }
155
156 void
157 XIM_SetGeometry (struct frame *f)
158 {
159 }
160
161 void
162 XIM_SetSpotLocation (struct frame *f, int x, int y)
163 {
164 /* ### FIX: Must make sure spot fits within Preedit Area */
165 XPoint *spot = &(FRAME_X_XIC_SPOT (f));
166 if (spot->x == (short) x &&
167 spot->y == (short) y)
168 return;
169
170 spot->x = (short) x;
171 spot->y = (short) y;
172
173 XmImVaSetValues (FRAME_X_TEXT_WIDGET (f), XmNspotLocation, spot, NULL);
174 }
175
176 void
177 XIM_focus_event (struct frame *f, int in_p)
178 {
179 if (in_p)
180 XmImVaSetFocusValues (FRAME_X_TEXT_WIDGET (f), NULL);
181 else
182 XmImUnsetFocus (FRAME_X_TEXT_WIDGET (f));
183 }
184
185 void
186 vars_of_input_method_motif (void)
187 {
188 Fprovide (intern ("xim"));
189 }