1 /* # skkinput (Simple Kana-Kanji Input)
2 * Ximp.c --- Ximp Protocol
3 * This file is part of skkinput.
4 * Copyright (C) 1997
5 * Takashi SAKAMOTO (sakamoto@yajima.kuis.kyoto-u.ac.jp)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with skkinput; see the file COPYING. If not, write to
19 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <sys/types.h>
24 #include <X11/X.h>
25 #include <X11/Xlib.h>
26 #include <X11/Xatom.h>
27 #include <X11/IntrinsicP.h>
28 #include <X11/StringDefs.h>
29 #include <X11/Shell.h>
30
31 #include "commondef.h"
32 #include "XimpP.h"
33 #include "SeparateWin.h"
34 #include "OverWin.h"
35 #include "OffWin.h"
36 #include "MyDispatch.h"
37 #include "MyError.h"
38 #include "resrcs.h"
39 #include "HistMgr.h"
40 #include "skkkey.h"
41 #include "FontMgr.h"
42
43 #define PROTOCOL_VERSION_STRING "XIMP.3.5"
44 #define SERVER_NAME "skkinput"
45 #define SERVER_VERSION "1"
46 #define VENDOR_NAME "KUIS"
47
48 #define MIN_LINE_SPACING (2)
49 #define MIN_AREA_WIDTH (16)
50 #define MIN_AREA_HEIGHT (10)
51
52 /*
53 * �ץ�ȥ����������
54 */
55 static void Ximp_Initialize
56 ( Widget greq, Widget gnew, ArgList args, Cardinal *num_args ) ;
57 static void Ximp_Realize
58 ( Widget gw, XtValueMask *valueMask, XSetWindowAttributes *attrs ) ;
59 static Boolean Ximp_SetValues
60 ( Widget current, Widget request, Widget new,
61 ArgList args, Cardinal *num_args ) ;
62 static void Ximp_Destroy( Widget gw ) ;
63
64 static void Ximp_getAtoms( Widget gw ) ;
65
66 static void Ximp_setServerProperty( Widget gw ) ;
67 static int Ximp_ownSelection( Widget gw ) ;
68 static int Ximp_setKeyProperty( Widget gw ) ;
69
70 static int Ximp_isCorrectConversionMessage
71 ( Widget gw, XEvent *xevent ) ;
72
73 static void Ximp_conversionMessageEventHandler
74 ( Widget gw, XEvent *xevent, String *args, Cardinal *num_of_args ) ;
75 static void Ximp_createMessageHandler
76 ( Widget gw, XClientMessageEvent *xclme ) ;
77 static void Ximp_beginMessageHandler
78 ( Widget gw, XClientMessageEvent *xclme ) ;
79 static void Ximp_endMessageHandler
80 ( Widget gw, XClientMessageEvent *xclme ) ;
81 static void Ximp_setFocusMessageHandler
82 ( Widget gw, XClientMessageEvent *xclme ) ;
83 static void Ximp_unsetFocusMessageHandler
84 ( Widget gw, XClientMessageEvent *xclme ) ;
85 static void Ximp_moveMessageHandler
86 ( Widget gw, XClientMessageEvent *xclme ) ;
87 static void Ximp_resetMessageHandler
88 ( Widget gw, XClientMessageEvent *xclme ) ;
89 static void Ximp_changeMessageHandler
90 ( Widget gw, XClientMessageEvent *xclme ) ;
91 static void Ximp_getValueMessageHandler
92 ( Widget gw, XClientMessageEvent *xclme ) ;
93 static void Ximp_extensionMessageHandler
94 ( Widget gw, XClientMessageEvent *xclme ) ;
95 static void Ximp_keypressMessageHandler
96 ( Widget gw, XClientMessageEvent *xclme ) ;
97 static void Ximp_setvalueMessageHandler
98 ( Widget gw, XClientMessageEvent *xclme ) ;
99 static void Ximp_SelectionRequestEventHandler
100 ( Widget gw, XEvent *xevent, String *params, Cardinal *num_params ) ;
101 static void Ximp_SelectionClearEventHandler
102 ( Widget gw, XEvent *xevent, String *params, Cardinal *num_params ) ;
103
104 static void Ximp_rejectCreateMessage( Widget gw, Window win ) ;
105 static void Ximp_sendErrorEvent
106 ( struct XimpClient *ximpClient, int errorno ) ;
107 #if 0
108 static int Ximp_sendClientMessage8
109 ( struct XimpClient *ximpClient, unsigned char *string, int length ) ;
110 #endif
111 static int Ximp_sendClientMessage32
112 ( struct XimpClient *ximpClient, int type,
113 unsigned long l1, unsigned long l2,
114 unsigned long l3, unsigned long l4 ) ;
115
116 static void Ximp_getAttributes
117 ( struct XimpClient *ximpClient, unsigned long mask ) ;
118 static int Ximp_getClientVersionProperty
119 ( struct XimpClient *ximpClient ) ;
120
121 static struct XimpClient *Ximp_createClient
122 ( Widget gw, Window requestor, XimpInputStyle *xis ) ;
123 static struct XimpClient *Ximp_findClient
124 ( Widget gw, unsigned long id ) ;
125 #if 0
126 static struct XimpClient *Ximp_findClientWithWindowID
127 ( Widget gw, Window win ) ;
128 #endif
129 static void Ximp_destroyClient( struct XimpClient *ximpClient ) ;
130
131 static void Ximp_getFonts
132 ( struct XimpClient *ximpClient, unsigned char *fontnamelist ) ;
133
134 static void Ximp_fillInDefaultAttributes
135 ( struct XimpClient *ximpClient ) ;
136 static unsigned long Ximp_makeConvAttributes
137 ( struct XimpClient *ximpClient, struct ConvAttrs *attr ) ;
138
139 static void Ximp_SendMessageToRequestorCallback
140 ( Widget gw, caddr_t client, caddr_t caller ) ;
141 static void Ximp_EndMessageToRequestorCallback
142 ( Widget gw, caddr_t client, caddr_t caller ) ;
143 static void Ximp_KeyEventToRequestorCallback
144 ( Widget gw, caddr_t client, caddr_t caller ) ;
145
146 static int Ximp_getProperty
147 ( struct XimpClient *ximpClient, Atom property, Atom type, int format,
148 unsigned char **rprop, unsigned long *rnitems ) ;
149 static void Ximp_getFocusProperty
150 ( struct XimpClient *ximpClient ) ;
151 static void Ximp_getPreeditFontProperty
152 ( struct XimpClient *ximpClient ) ;
153 static void Ximp_getStatusFontProperty
154 ( struct XimpClient *ximpClient ) ;
155 static void Ximp_getPreeditProperty
156 ( struct XimpClient *ximpClient, unsigned long mask ) ;
157 static void Ximp_getStatusProperty
158 ( struct XimpClient *ximpClient, unsigned long mask ) ;
159
160 static void Ximp_setAttributes
161 ( struct XimpClient *ximpClient, unsigned long mask ) ;
162 static void Ximp_setFocusProperty
163 ( struct XimpClient *ximpClient ) ;
164 static void Ximp_setPreeditFontProperty
165 ( struct XimpClient *ximpClient ) ;
166 static void Ximp_setStatusFontProperty
167 ( struct XimpClient *ximpClient ) ;
168 static void Ximp_setPreeditProperty
169 ( struct XimpClient *ximpClient, unsigned long mask ) ;
170 static void Ximp_setStatusProperty
171 ( struct XimpClient *ximpClient, unsigned long mask ) ;
172 static void Ximp_setProperty
173 ( struct XimpClient *ximpClient, Atom property, Atom type, int format,
174 unsigned char *data, int nelements ) ;
175 static void Ximp_unlinkClient( struct XimpClient *ximpClient ) ;
176 static void Ximp_freeClient( struct XimpClient *ximpClient ) ;
177
178 static void Ximp_ChangeFocusWindow
179 ( struct XimpClient *ximpClient, Window focus_window ) ;
180
181 /*
182 * �������Ȥ��Ƥ���ؿ��Υץ�ȥ����������
183 */
184 /* ctext.c */
185 extern int string2ctext( struct myChar *string, unsigned char *cstr ) ;
186
187 /* parseStr.c */
188 extern int parseXrLikeKeyStrings
189 ( unsigned char *string, struct XrLikeKey *keytbl ) ;
190
191 /*
192 * �����Х��ѿ��������
193 */
194 #define offset(field) XtOffsetOf(XimpRec, ximp.field)
195 #define goffset(field) XtOffsetOf(WidgetRec, core.field)
196
197 /* �����������*/
198 static XtResource ximp_resources[] = {
199 /* ����� kinput protocol ���̤����ɤ�����*/
200 { XtNdefaultXimpServer, XtCDefaultXimpServer, XtRBoolean,
201 sizeof( Boolean ), offset(ximp_defaultServer),
202 XtRImmediate, (XtPointer)FALSE },
203 /* SeparateWindow, Over-The-Spot-Window �Ĥ��������륳����Хå���*
204 * ����� XimpWidget ���ɤ�������������ɤ��Τ��Τ�ʤ����ȤʤΤǡ� *
205 * ������Хå��η��ǿƤ˽�����ꤤ���Ƥ��롣*/
206 { XtNsetupInputWindowNotify, XtCCallback, XtRCallback,
207 sizeof( caddr_t ), offset( setupInputWindowCallback ), XtRCallback,
208 ( caddr_t )NULL },
209 /* Ximp Protocol Widget ���Ĥ������θƽФ�������Хå���*/
210 { XtNserverCloseNotify, XtCCallback, XtRCallback, sizeof( caddr_t ),
211 offset( serverCloseCallback ), XtRCallback, ( caddr_t )NULL },
212 /* ���饤����Ȥ�ï����Ȥ���褦�Ȥ��Ƥ��롩 */
213 { XtNdestroyWindowEvent, XtCDestroyWindowEvent, XtRImmediate,
214 sizeof( XDestroyWindowEvent * ),
215 offset( destroyWindowEvent ), XtRImmediate, ( XtPointer )NULL },
216 /* ������������*/
217 { XtNjisyoDirty, XtCJisyoDirty, XtRImmediate, sizeof (int),
218 offset(jisyo_dirty), XtRImmediate, (XtPointer) FALSE },
219 /* �Ѵ��Ϥ��륭������Ͽ���롣*/
220 { XtNconversionStartKey, XtCConversionStartKey, XtRString,
221 sizeof( String ), offset( conversionStartKey ), XtRImmediate,
222 ( XtPointer )"Shift<Key>space,Cntrl<Key>Kanji,Cntrl<Key>Henkan_Mode" },
223 } ;
224 #undef offset
225 #undef goffset
226
227 static XimpInputStyle ximpInputStyles[] = {
228 { XIMPreeditPosition | XIMStatusArea,
229 WINDOW_TYPE_OVERTHESPOT, False },
230 { XIMPreeditPosition | XIMStatusNothing,
231 WINDOW_TYPE_OVERTHESPOT, False },
232 { XIMPreeditArea | XIMStatusArea,
233 WINDOW_TYPE_OFFTHESPOT, False },
234 { XIMPreeditNothing | XIMStatusNothing,
235 WINDOW_TYPE_SEPARATE, True },
236 { 0, 0, False },
237 } ;
238 #define XIMP_INPUT_STYLES_NUM (5)
239
240 /* ���٥�Ȥ��Ф��륢�������Υơ��֥롣*/
241 static XtActionsRec ximp_actions_table[] = {
242 /* �Ѵ����Ͻ�λ����¾°�����ѹ����������롣*/
243 { "ximp-message",
244 Ximp_conversionMessageEventHandler },
245 /* _JAPANESE_CONVERSION ���ߤ����ȸ���줿���ν�����Ԥ���*/
246 { "ximp-selection-request",
247 Ximp_SelectionRequestEventHandler },
248 /* _JAPANESE_CONVERSION �ä����ν�����Ԥ���*/
249 { "ximp-selection-clear",
250 Ximp_SelectionClearEventHandler },
251 };
252
253 static char default_ximp_translations[] =
254 "<Message>_XIMP_PROTOCOL: ximp-message()\n\
255 <SelReq>: ximp-selection-request()\n\
256 <SelClr>: ximp-selection-clear()";
257
258 XimpClassRec ximpClassRec = {
259 { /* core fields */
260 /* superclass */ &widgetClassRec,
261 /* class_name */ "Ximp",
262 /* size */ sizeof( XimpRec ),
263 /* class_initialize */ NULL,
264 /* class_part_initialize */ NULL,
265 /* class_inited */ FALSE,
266 /* initialize */ Ximp_Initialize,
267 /* initialize_hook */ NULL,
268 /* realize */ Ximp_Realize,
269 /* actions */ ximp_actions_table,
270 /* num_actions */ XtNumber( ximp_actions_table ),
271 /* resources */ ximp_resources,
272 /* num_resources */ XtNumber( ximp_resources ),
273 /* xrm_class */ NULLQUARK,
274 /* compress_motion */ TRUE,
275 /* compress_exposure */ TRUE,
276 /* compress_enterleave */ TRUE,
277 /* visible_interest */ FALSE,
278 /* destroy */ Ximp_Destroy,
279 /* resize */ NULL,
280 /* expose */ NULL,
281 /* set_values */ Ximp_SetValues,
282 /* set_values_hook */ NULL,
283 /* set_values_almost */ XtInheritSetValuesAlmost,
284 /* get_values_hook */ NULL,
285 /* accept_focus */ NULL,
286 /* version */ XtVersion,
287 /* callback_private */ NULL,
288 /* tm_table */ default_ximp_translations,
289 /* query_geometry */ XtInheritQueryGeometry,
290 }
291 } ;
292
293 WidgetClass ximpWidgetClass = ( WidgetClass )&ximpClassRec ;
294
295 /*
296 * KinputWidgetClass �ν�����ؿ���
297 */
Ximp_Initialize(Widget greq,Widget gnew,ArgList args,Cardinal * num_args)298 static void Ximp_Initialize
299 ( Widget greq, Widget gnew, ArgList args, Cardinal *num_args )
300 {
301 XimpWidget w = ( XimpWidget )gnew ;
302
303 w->ximp.localename = "ja_JP" ;
304 w->ximp.servername = SERVER_NAME ;
305 w->ximp.icid = 1L ;
306 w->ximp.property_id = 0L ;
307 /* ��������Ƥ��륯�饤����Ȥϲ���ʤ���*/
308 w->ximp.client_list = NULL ;
309 w->ximp.status_width = 0 ;
310 /* �Ѵ������Ѥ��륢�ȥ��������Ƥ�����*/
311 Ximp_getAtoms( gnew ) ;
312 return ;
313 }
314
Ximp_getAtoms(Widget gw)315 static void Ximp_getAtoms( Widget gw )
316 {
317 XimpWidget w = ( XimpWidget )gw ;
318 Display *disp = XtDisplay( gw ) ;
319 unsigned char buffer[ BUFSIZE ] ;
320
321 #define MAKE_ATOM(str) XInternAtom(disp,(str),False)
322
323 sprintf( buffer, "_XIMP_%s", w->ximp.localename ) ;
324 w->ximp.ximp_selection1 = MAKE_ATOM( buffer ) ;
325 sprintf
326 ( buffer, "_XIMP_%s@%s.%d",
327 w->ximp.localename, w->ximp.servername,
328 DefaultScreen( XtDisplay( gw ) ) ) ;
329 w->ximp.ximp_selection2 = MAKE_ATOM( buffer ) ;
330 w->ximp.compound_text = MAKE_ATOM( "COMPOUND_TEXT" ) ;
331 w->ximp.ximp_version = MAKE_ATOM( "_XIMP_VERSION" ) ;
332 w->ximp.ximp_inputstyle = MAKE_ATOM( "_XIMP_STYLE" ) ;
333 w->ximp.ximp_keys = MAKE_ATOM( "_XIMP_KEYS" ) ;
334 w->ximp.ximp_servername = MAKE_ATOM( "_XIMP_SERVERNAME" ) ;
335 w->ximp.ximp_serverversion = MAKE_ATOM( "_XIMP_SERVERVERSION" ) ;
336 w->ximp.ximp_vendorname = MAKE_ATOM( "_XIMP_VENDORNAME" ) ;
337 w->ximp.ximp_extensions = MAKE_ATOM( "_XIMP_EXTENSIONS" ) ;
338 w->ximp.ximp_protocol = MAKE_ATOM( "_XIMP_PROTOCOL" ) ;
339 w->ximp.ximp_focus = MAKE_ATOM( "_XIMP_FOCUS" ) ;
340 w->ximp.ximp_preedit = MAKE_ATOM( "_XIMP_PREEDIT" ) ;
341 w->ximp.ximp_status = MAKE_ATOM( "_XIMP_STATUS" ) ;
342 w->ximp.ximp_preeditfont = MAKE_ATOM( "_XIMP_PREEDITFONT" ) ;
343 w->ximp.ximp_statusfont = MAKE_ATOM( "_XIMP_STATUSFONT" ) ;
344 w->ximp.ximp_extbackfront = MAKE_ATOM( "_XIMP_EXT_XIMP_BACK_FRONT" ) ;
345 #undef MAKE_ATOM
346 return ;
347 }
348
Ximp_Realize(Widget gw,XtValueMask * valueMask,XSetWindowAttributes * attrs)349 static void Ximp_Realize
350 ( Widget gw, XtValueMask *valueMask, XSetWindowAttributes *attrs )
351 {
352 CoreWidgetClass super =
353 ( CoreWidgetClass )XtClass( gw )->core_class.superclass ;
354
355 /* ���Ŭ�ڤʥ�����ɥ����Ѱդ����Ƥ����ʤ���С���� *
356 * XChangeProperty ��ư��ʤ����Ȥˤʤ롣*/
357 ( *super->core_class.realize )( gw, valueMask, attrs ) ;
358
359 /* �����ФȤ��Ƥ������åȤ��Ƥ�����*/
360 Ximp_setServerProperty( gw ) ;
361 /* �����ФȤʤ�٤����쥯�����Υ����ʤˤʤ��Ȥ��롣*/
362 if( !Ximp_ownSelection( gw ) ){
363 XtDestroyWidget( gw ) ;
364 return ;
365 }
366 #ifdef DEBUG
367 printf( "Ximp Server Window(%ld)\n", XtWindow( gw ) ) ;
368 #endif
369 return ;
370 }
371
Ximp_setServerPropertySub(Widget gw,Atom property,Atom type,int format,unsigned char * data,int nelements)372 static void Ximp_setServerPropertySub
373 ( Widget gw, Atom property, Atom type, int format,
374 unsigned char *data, int nelements )
375 {
376 XChangeProperty
377 ( XtDisplay( gw ), XtWindow( gw ), property, type, format,
378 PropModeReplace, data, nelements ) ;
379 return ;
380 }
381
382 /*
383 * �����ФȤ��Ʋ�����ǽ�����ɤΤ褦�ʥ����ФǤ��뤫����Ͽ����ؿ���
384 *-----
385 * �ޤ���XIMP �����ФǤ���Ȥ������Ȥ���Ͽ���롣
386 * ���˥����ФΥС������Ȥ��ɤΤ褦�����ϥ�������ݡ��Ȥ��Ƥ���
387 * ���Ȥ�����Ͽ����櫓�Ǥ��롣
388 */
Ximp_setServerProperty(Widget gw)389 static void Ximp_setServerProperty( Widget gw )
390 {
391 XimpWidget w = ( XimpWidget )gw ;
392 XimpInputStyle *xinps = ximpInputStyles ;
393 unsigned long styles[ XIMP_INPUT_STYLES_NUM ] ;
394 unsigned long extensions[ 5 ] ;
395 int number_of_styles, number_of_extensions ;
396
397 Ximp_setServerPropertySub
398 ( gw, w->ximp.ximp_version, XA_STRING, 8,
399 PROTOCOL_VERSION_STRING, strlen( PROTOCOL_VERSION_STRING ) ) ;
400 Ximp_setServerPropertySub
401 ( gw, w->ximp.ximp_servername, XA_STRING, 8,
402 SERVER_NAME, strlen( SERVER_NAME ) ) ;
403 Ximp_setServerPropertySub
404 ( gw, w->ximp.ximp_serverversion, XA_STRING, 8,
405 SERVER_VERSION, strlen( SERVER_VERSION ) ) ;
406 Ximp_setServerPropertySub
407 ( gw, w->ximp.ximp_vendorname, XA_STRING, 8,
408 VENDOR_NAME, strlen( VENDOR_NAME ) ) ;
409 number_of_styles = 0 ;
410 while( xinps->style != 0 ){
411 styles[ number_of_styles ++ ] = xinps->style ;
412 xinps ++ ;
413 }
414 Ximp_setServerPropertySub
415 ( gw, w->ximp.ximp_inputstyle, w->ximp.ximp_inputstyle, 32,
416 ( unsigned char *)styles, number_of_styles ) ;
417
418 number_of_extensions = 0 ;
419 extensions[ number_of_extensions ++ ] = w->ximp.ximp_extbackfront ;
420 Ximp_setServerPropertySub
421 ( gw, w->ximp.ximp_extensions, w->ximp.ximp_extensions, 32,
422 ( unsigned char *)extensions, number_of_extensions ) ;
423 Ximp_setKeyProperty( gw ) ;
424 return ;
425 }
426
427 /*
428 * �Ѵ����ϥ�������Ͽ��Ԥ��ؿ���
429 *-----
430 * ���ϼ��ȴ���Ƥ���Τǡ��Ѵ����ϤΥ����ϥ��եȥ��ڡ����θ���Ǥ��롣
431 */
Ximp_setKeyProperty(Widget gw)432 static int Ximp_setKeyProperty( Widget gw )
433 {
434 XimpWidget w = ( XimpWidget )gw ;
435 unsigned long *keydata ;
436 int num, i ;
437 struct XrLikeKey *startkeys ;
438
439 /* �ޤ��������Ѱդ��ʤ��Ȥ����ʤ��Τ�������롣*/
440 num = parseXrLikeKeyStrings( w->ximp.conversionStartKey, NULL ) ;
441 if( num <= 0 )
442 return False ;
443 /* �������ݤ��롣*/
444 if( ( startkeys = malloc( sizeof( struct XrLikeKey ) * num ) ) == NULL )
445 return False ;
446 if( ( keydata = malloc( sizeof( unsigned long ) * 3 * num ) ) == NULL ){
447 free( startkeys ) ;
448 return False ;
449 }
450 /* ���٤ϼºݤ˥������ɤߡ����ݤ��롣*/
451 num = parseXrLikeKeyStrings( w->ximp.conversionStartKey, startkeys ) ;
452 /* �����ǡ�������Ͽ���Ƥ����ġ�*/
453 for( i = 0 ; i < num ; i ++ ){
454 keydata[ i * 3 + 0 ] = startkeys[ i ].checkModifiers ;
455 keydata[ i * 3 + 1 ] = startkeys[ i ].modifiers ;
456 keydata[ i * 3 + 2 ] = startkeys[ i ].keysym ;
457 }
458 /* property ����Ͽ���롣*/
459 XChangeProperty
460 ( XtDisplay( gw ), XtWindow( gw ),
461 w->ximp.ximp_keys, w->ximp.ximp_keys, 32,
462 PropModeReplace, ( unsigned char *)keydata, num * 3 ) ;
463 /* ���Ū�����Ѥ��Ƥ��������������롣*/
464 free( startkeys ) ;
465 free( keydata ) ;
466 return True ;
467 }
468
469 /*
470 * �Ѵ������Ф���̾����夲��ؿ���
471 *-----
472 * ���̤� X Window System �Υ����Фϡ�
473 *
474 * �֤��륢�ȥ������������λ�����ˤʤ�פȤ������Ȥ���Ϥ�롣
475 *
476 * ���饤����ȤϤ��Υ��ȥ�λ����礬ï����Ĵ�٤뤳�Ȥˤ�äƥ����Ф�
477 * ¸�ߤ��Τ뤳�Ȥ��Ǥ���ΤǤ��롣
478 */
Ximp_ownSelection(Widget gw)479 static int Ximp_ownSelection( Widget gw )
480 {
481 XimpWidget w = ( XimpWidget )gw ;
482 Display *disp = XtDisplay( gw ) ;
483
484 if( w->ximp.ximp_defaultServer ||
485 XGetSelectionOwner
486 ( disp, w->ximp.ximp_selection1 ) == None ){
487 XSetSelectionOwner
488 ( disp, w->ximp.ximp_selection1, XtWindow( gw ), CurrentTime ) ;
489 }
490 /* Selection2 �� owner �ˤʤ롣������ϸ�����˻��ꤵ��� Server ��
491 ���롣*/
492 XSetSelectionOwner
493 ( disp, w->ximp.ximp_selection2, XtWindow( gw ), CurrentTime ) ;
494 /* ̵�� selection �� owner �ˤʤ줿���ɤ������֤���*/
495 return
496 ( XGetSelectionOwner
497 ( disp, w->ximp.ximp_selection2 ) == XtWindow( gw ) ) ;
498 }
499
500 /*
501 * ���� KinputWidget �λ����ѿ����ͤ��ѹ������Ȥ������˸ƤФ���
502 * ����
503 * ------
504 * ����ϡ�Widget �س��������å����������ä����ˤɤΤ褦�ʽ�����
505 * �Τ��Ȥ������ȤȤߤʤ����Ȥ��Ǥ��롣���������졹��������ꤹ�����
506 * �ݤ��ȻפäƤ��ޤ��������Х��ѿ����Ϥ������ʤäƤ��ޤ��Τ����Ĥ�
507 * ��Ǥϰܿ������㤯�ʤ롣
508 */
Ximp_SetValues(Widget current,Widget request,Widget new,ArgList args,Cardinal * num_args)509 static Boolean Ximp_SetValues
510 ( Widget current, Widget request, Widget new,
511 ArgList args, Cardinal *num_args )
512 {
513 XimpWidget curw = ( XimpWidget )current ;
514 XimpWidget reqw = ( XimpWidget )request ;
515 XimpWidget neww = ( XimpWidget )new ;
516 struct XimpClient *ximpClient ;
517
518 /* �ޤ���ï�����饤����Ȥ���Ȥ���褦�Ȥ��Ƥ��롩�� */
519 if( reqw->ximp.destroyWindowEvent != NULL ){
520 XDestroyWindowEvent *xdwe = reqw->ximp.destroyWindowEvent ;
521 ximpClient = reqw->ximp.client_list ;
522 while( ximpClient != NULL ){
523 if( xdwe->window == ximpClient->request_window ||
524 xdwe->window == ximpClient->focus_window ){
525 remove_allmyeventhandler
526 ( XtDisplay( new ), ximpClient->request_window ) ;
527 XSafeSelectInput
528 ( XtDisplay( new ), ximpClient->request_window, NoEventMask ) ;
529 remove_allmyeventhandler
530 ( XtDisplay( new ), ximpClient->focus_window ) ;
531 XSafeSelectInput
532 ( XtDisplay( new ), ximpClient->focus_window, NoEventMask ) ;
533 ximpClient->request_window =
534 ximpClient->focus_window = None ;
535 /* ���㤢���Ĥ��ޤ��礦��*/
536 if( ximpClient->skkinput != NULL ){
537 Ximp_unlinkClient( ximpClient ) ;
538 ximpClient->to_destroy = True ;
539 XtDestroyWidget( ximpClient->skkinput ) ;
540 } else {
541 Ximp_destroyClient( ximpClient ) ;
542 }
543 break ;
544 }
545 ximpClient = ximpClient->next ;
546 }
547 curw->ximp.destroyWindowEvent =
548 neww->ximp.destroyWindowEvent =
549 reqw->ximp.destroyWindowEvent = NULL ;
550 return( FALSE ) ;
551 }
552 if( reqw->ximp.jisyo_dirty != curw->ximp.jisyo_dirty ){
553 ximpClient = neww->ximp.client_list ;
554 while( ximpClient != NULL ){
555 if( ximpClient->skkinput != NULL )
556 XtVaSetValues
557 ( ximpClient->skkinput,
558 XtNjisyoDirty, reqw->ximp.jisyo_dirty, NULL ) ;
559 ximpClient = ximpClient->next ;
560 }
561 curw->ximp.jisyo_dirty = neww->ximp.jisyo_dirty =
562 reqw->ximp.jisyo_dirty ;
563 return ( FALSE ) ;
564 }
565 /* �����Ǥϲ��⤹�뤳�Ȥ��ʤ���*/
566 return( FALSE ) ;
567 }
568
569 /*
570 * Ximp Widget ���˴�����Ȥ��˸ƤФ��ؿ���
571 */
Ximp_Destroy(Widget gw)572 static void Ximp_Destroy( Widget gw )
573 {
574 /* �֤��Ρ������Ϥɤ��ʤ��ä���Ǥ��礦���� */
575 /* �֤����������Ϥޤ������ɤ��Τ������ɤ����Τ��������Ƥ��ʤ���
576 ��͡����ϲ��⤷�ʤ�������� */
577 /* (�ԤĤ��ȿ����֡�) */
578 XimpWidget w = ( XimpWidget )gw ;
579 struct XimpClient *node, *nextNode ;
580
581 node = w->ximp.client_list ;
582 while( node != NULL ){
583 nextNode = node->next ;
584 /* ���Υ��饤����ȤϽ�������ߤ��롣*/
585 if( node->skkinput != NULL ){
586 Ximp_unlinkClient( node ) ;
587 node->to_destroy = True ;
588 XtDestroyWidget( node->skkinput ) ;
589 } else {
590 /* ���饤����Ȥ���Ϥ�Ϥ䲿�Υ��٥�Ȥ�������ʤ���*/
591 remove_allmyeventhandler
592 ( XtDisplay( gw ), node->request_window ) ;
593 /* Ximp �ǽ�������Ƥ����ҥ��ȥ���������פˤʤä���*/
594 history_destroy( node->request_window ) ;
595 Ximp_destroyClient( node ) ;
596 }
597 /* ���Υ����ߥǥΡ��ɤ��ե����Ƥ��ޤäƤ����ǽ��������� */
598 /* �ǡ�nextNode ���Ƥ����ΤǤ��롣*/
599 node = nextNode ;
600 }
601 /* ��Ǥ������ˤʤ�ޤ�����*/
602 w->ximp.client_list = NULL ;
603 /* ��ʬ���Ȥ��˴����٤����ƥ��������åȤ˽������᤹�롣*/
604 XtCallCallbacks( gw, XtNserverCloseNotify, NULL ) ;
605 /* Ximp Protocol �Υ����ФȤ��Ƥ����ܤ���ߤ��롣*/
606 return ;
607 }
608
609 /*
610 * �Ѵ����饤����Ȥ��������Ƥ������饤����ȥ�å����������������
611 * �������Ǥ��뤫�ɤ�����Ƚ�Ǥ���ؿ���
612 *----
613 * �����ʥ�å������Ǥ���Τϡ�
614 * �����饤����ȥ�å��������٥�ȤǤʤ���
615 * ���ե����ޥåȤ����äƤ��롣
616 * ������Υ�����ɥ��������Ф���ʤ���
617 * ���ץ�ȥ��뤬�㤦��(�ץ�ȥ���ϥ�å��������ǻ��ꤷ�Ƥ��롣)
618 */
Ximp_isCorrectConversionMessage(Widget gw,XEvent * xevent)619 static int Ximp_isCorrectConversionMessage
620 ( Widget gw, XEvent *xevent )
621 {
622 XimpWidget w = ( XimpWidget )gw ;
623 /* ClientMessageEvent ��̵�����̵�뤹��Ĥ�������ʤ����ȤäƤ���Ρ�*/
624 if( xevent->type != ClientMessage )
625 return False ;
626 /* ������ ClientMessageEvent �Ǥ��뤫��Ƚ�Ǥ��롣�����å�������ܤ�
627 ��å������μ���������衢���Ȥϥե����ޥåȡ�*/
628 if( xevent->xclient.window != XtWindow( gw ) ||
629 xevent->xclient.message_type != w->ximp.ximp_protocol ||
630 xevent->xclient.format != 32 )
631 return False ;
632 return True ;
633 }
634
635 /*
636 * �Ѵ����饤����Ȥ��¤�¸�ߤ��ʤ�������ɥ����ä��ꤷ�ʤ�����Ƚ�ꤹ
637 * ��ؿ���
638 */
Ximp_isCorrectWindowP(Widget gw,Window win,unsigned int * width,unsigned int * height)639 static int Ximp_isCorrectWindowP
640 ( Widget gw, Window win, unsigned int *width, unsigned int *height )
641 {
642 XWindowAttributes xwa ;
643 /* ������֤����ϡ�SubWindow Mapping �Ǥ��뤫�ɤ�����Ƚ�̤���ɬ�פ� *
644 * ����ΤǤ��Υ����ɤǤϤޤ������� *
645 * ���� �֤����ʤΤǤ����� �䡢����Ǥ⤫�ޤ�ʤ��ȻפäƤޤ�����*
646 * ������֤��䡢Netscape ��������Ȥ��Ƥ����Ф��������������ϡ�*/
647 if( !isWindowExistIfExistsGetXWA( XtDisplay( gw ), win, &xwa ) )
648 return False ;
649 if( width != NULL && height != NULL ){
650 *width = xwa.width ;
651 *height = xwa.height ;
652 }
653 return True ;
654 }
655
Ximp_SetNeededSize(XimpAttributes * attr,unsigned int width,unsigned int height,unsigned int max_width,unsigned int max_height)656 static void Ximp_SetNeededSize
657 ( XimpAttributes *attr,
658 unsigned int width, unsigned int height,
659 unsigned int max_width, unsigned int max_height )
660 {
661 if( max_width > 0 && width > max_width )
662 width = max_width ;
663 if( max_height > 0 && height > max_height )
664 height = max_height ;
665 if( width < MIN_AREA_WIDTH )
666 width = MIN_AREA_WIDTH ;
667 if( height < MIN_AREA_HEIGHT )
668 height = MIN_AREA_HEIGHT ;
669
670 attr->needed_width = width ;
671 attr->needed_height = height ;
672 return ;
673 }
674
Ximp_ComputeAreaForQuery(struct XimpClient * ximpClient)675 static void Ximp_ComputeAreaForQuery
676 ( struct XimpClient *ximpClient )
677 {
678 XimpWidget xw = ( XimpWidget )ximpClient->protocol_widget ;
679 unsigned int fontheight, width, height, max_width, max_height ;
680
681 if( ximpClient->style->inputStyle != WINDOW_TYPE_SEPARATE ){
682 /* Root Window Style �Ǥʤ���С����饤����ȤΥ�����ɥ���������
683 * ����ɬ�פ����롣*/
684 Ximp_isCorrectWindowP
685 ( ( Widget )xw,
686 ximpClient->request_window,
687 &ximpClient->request_width,
688 &ximpClient->request_height ) ;
689 }
690 if( ximpClient->style->inputStyle != WINDOW_TYPE_SEPARATE ){
691 /* OverTheSpot/OffTheSpot �Ȥ�˥��ơ��������ꥢ�����Ѥ���Τǡ���
692 * ���礭�������Ƥ�����*/
693 fontheight = ximpClient->status_attributes.line_spacing + 2 ;
694 max_width = max_height = 0 ;
695 if( ximpClient->attribute_mask & XIMP_STS_AREANEED_MASK ){
696 max_width = ximpClient->status_attributes.needed_width ;
697 max_height = ximpClient->status_attributes.needed_height ;
698 }
699 if( xw->ximp.status_width > 0 ){
700 width = xw->ximp.status_width ;
701 } else {
702 /* ���β���40ʸ������ɽ�������н�ʬ�Ѥ���������Ǥ��и�����
703 * Ƚ�Ǥ��ޤ���*/
704 width = fontheight * 40 ;
705 /* �ᤵ�줿�������⤺�ä��礭����ΤǤ����顢���ä��ˤ��ޤ�
706 * ����*/
707 if( width > ximpClient->request_width ){
708 width = ximpClient->request_width ;
709 }
710 }
711 height = fontheight ;
712
713 Ximp_SetNeededSize
714 ( &ximpClient->status_attributes,
715 width, height, max_width, max_height ) ;
716
717 if( !( ximpClient->attribute_mask & XIMP_STS_AREA_MASK ) ){
718 ximpClient->status_attributes.area_x = 0;
719 ximpClient->status_attributes.area_y =
720 ximpClient->request_height -
721 ximpClient->status_attributes.needed_height ;
722 ximpClient->status_attributes.area_width =
723 ximpClient->status_attributes.needed_width ;
724 ximpClient->status_attributes.area_height =
725 ximpClient->status_attributes.needed_height ;
726 }
727 #ifdef DEBUG
728 printf( "Status area : (x,y,w,h)=(%d,%d,%d,%d)\n",
729 ximpClient->status_attributes.area_x,
730 ximpClient->status_attributes.area_y,
731 ximpClient->status_attributes.area_width,
732 ximpClient->status_attributes.area_height ) ;
733 #endif
734 }
735 if( ximpClient->style->inputStyle == WINDOW_TYPE_OFFTHESPOT ){
736
737 fontheight = ximpClient->preedit_attributes.line_spacing + 2 ;
738 max_width = max_height = 0 ;
739 if( ximpClient->attribute_mask & XIMP_PRE_AREANEED_MASK ){
740 max_width = ximpClient->preedit_attributes.needed_width ;
741 max_height = ximpClient->preedit_attributes.needed_height ;
742 }
743 width = ximpClient->request_width -
744 ximpClient->status_attributes.needed_width ;
745 height = fontheight ;
746
747 Ximp_SetNeededSize
748 ( &ximpClient->preedit_attributes,
749 width, height, max_width, max_height ) ;
750
751 if( !( ximpClient->attribute_mask & XIMP_PRE_AREA_MASK ) ){
752 ximpClient->preedit_attributes.area_x =
753 ximpClient->status_attributes.needed_width ;
754 ximpClient->preedit_attributes.area_y =
755 ximpClient->request_height -
756 ximpClient->preedit_attributes.needed_height ;
757 ximpClient->preedit_attributes.area_width =
758 ximpClient->preedit_attributes.needed_width ;
759 ximpClient->preedit_attributes.area_height =
760 ximpClient->preedit_attributes.needed_height ;
761 }
762 } else if( ximpClient->style->inputStyle == WINDOW_TYPE_OVERTHESPOT ){
763 if( !( ximpClient->attribute_mask & XIMP_PRE_AREA_MASK ) ){
764 ximpClient->preedit_attributes.area_x = 0 ;
765 ximpClient->preedit_attributes.area_y = 0 ;
766 ximpClient->preedit_attributes.area_width =
767 ximpClient->focus_width ;
768 ximpClient->preedit_attributes.area_height =
769 ximpClient->focus_height ;
770 }
771 }
772 return ;
773 }
774
Ximp_ComputeAreaForStartUp(struct XimpClient * ximpClient)775 static void Ximp_ComputeAreaForStartUp
776 ( struct XimpClient *ximpClient )
777 {
778 if( ximpClient->style->inputStyle == WINDOW_TYPE_SEPARATE ||
779 ximpClient->style->inputStyle == WINDOW_TYPE_OVERTHESPOT )
780 return ;
781 if( ( ximpClient->attribute_mask & XIMP_STS_AREA_MASK ) &&
782 ( ximpClient->attribute_mask & XIMP_PRE_AREA_MASK ) )
783 return ;
784 Ximp_ComputeAreaForQuery( ximpClient ) ;
785 if( !( ximpClient->attribute_mask & XIMP_STS_AREA_MASK ) ){
786 ximpClient->status_attributes.area_x = 0 ;
787 ximpClient->status_attributes.area_y = ximpClient->request_height -
788 ximpClient->status_attributes.needed_height ;
789 ximpClient->status_attributes.area_width =
790 ximpClient->status_attributes.needed_width ;
791 ximpClient->status_attributes.area_height =
792 ximpClient->status_attributes.needed_height ;
793 }
794 if( !( ximpClient->attribute_mask & XIMP_PRE_AREA_MASK ) ){
795 ximpClient->preedit_attributes.area_x =
796 ximpClient->status_attributes.area_x +
797 ximpClient->status_attributes.area_width ;
798 ximpClient->preedit_attributes.area_y =
799 ximpClient->request_height -
800 ximpClient->preedit_attributes.needed_height ;
801 ximpClient->preedit_attributes.area_width =
802 ximpClient->preedit_attributes.needed_width ;
803 ximpClient->preedit_attributes.area_height =
804 ximpClient->preedit_attributes.needed_height ;
805 }
806 return ;
807 }
808
809 /*
810 * �Ѵ����饤����Ȥ����Ѵ������Ф���³��褿���ν�����
811 */
Ximp_createMessageHandler(Widget gw,XClientMessageEvent * xclme)812 static void Ximp_createMessageHandler
813 ( Widget gw, XClientMessageEvent *xclme )
814 {
815 Window requestor ;
816 XIMStyle inputStyle ;
817 XimpInputStyle *xis ;
818 struct XimpClient *ximpClient ;
819 unsigned long attributemask ;
820 unsigned int width, height ;
821
822 /* �Ѵ����饤����ȤΥ�����ɥ��ɣĤ�ȴ���Ф��Ƥ�����*/
823 requestor = ( Window )xclme->data.l[ 1 ] ;
824 if( !Ximp_isCorrectWindowP( gw, requestor, &width, &height ) ){
825 return ;
826 }
827 #if 0
828 /* ���˽�������Ƥ����Ѵ����饤����ȤǤ���Τ��� */
829 if( Ximp_findClientWithWindowID( gw, requestor ) != NULL ){
830 /* ���˽�������Ƥ���Τʤ���ٺ�������ɬ�פ�̵���Τ��Ĥ��롣*/
831 return ;
832 }
833 #endif
834 /* ���ϥ���������ɤߤ��ࡣ*/
835 inputStyle = ( XIMStyle )xclme->data.l[ 2 ] ;
836
837 /* ���ݡ��Ȥ���Ƥ������ϥ�������Ǥ��뤫�ɤ����롣*/
838 for( xis = ximpInputStyles ; xis->style != inputStyle ; xis ++ ){
839 if( xis->style == 0 ){
840 Ximp_rejectCreateMessage( gw, requestor ) ;
841 return ;
842 }
843 }
844 #if defined(DEBUG)
845 fprintf( stderr, "Ximp input style is \"%d\".\n", xis->inputStyle ) ;
846 #endif
847 /* ���饤����Ȥ�������뤿��Υǡ�������ݤ��롣*/
848 ximpClient = Ximp_createClient( gw, requestor, xis ) ;
849 ximpClient->request_width = width ;
850 ximpClient->request_height = height ;
851 ximpClient->xevent = *xclme ;
852 ximpClient->style = xis ;
853
854 attributemask = xclme->data.l[ 3 ] ;
855 /* ���饤����ȤΥС�������������Ƥ������ɤ����ΰ�̣������Τ���
856 �档*/
857 Ximp_getClientVersionProperty( ximpClient ) ;
858 /* ���饤����Ȥξ����������롣*/
859 Ximp_getAttributes( ximpClient, attributemask ) ;
860 /* �Ѵ����饤����Ȥ��˴�����Ƥ��ޤ��褦�ʤ��Ȥ����ä��鸡�ΤǤ���
861 �褦�ˤ��롣
862 �����Ϥ���Ȫ�μ���Ψ���ɤΰ̤��Ȥ����ѤϤɤ����Ȥ����������Τ�
863 Ĵ�٤뤳�ȤǤϤʤ����ޤ������ս��ȤȤϲ��δط���ʤ��ΤǤ������*/
864 add_myeventhandler
865 ( XtDisplay( gw ), requestor, XtWindow( gw ),
866 NO_EVENT_HANDLE, StructureNotifyMask) ;
867
868 /* ̵���˺�뤳�Ȥ�����ޤ�����ȡ��ֻ����*/
869 Ximp_sendClientMessage32
870 ( ximpClient, XIMP_CREATE_RETURN, ximpClient->id, 0L, 0L, 0L ) ;
871 return ;
872 }
873
874 /*
875 * �Ѵ����饤����Ȥ����Ѵ������Ф���³��λ���褿���ν�����
876 */
Ximp_destroyMessageHandler(Widget gw,XClientMessageEvent * xclme)877 static void Ximp_destroyMessageHandler
878 ( Widget gw, XClientMessageEvent *xclme )
879 {
880 struct XimpClient *ximpClient ;
881 unsigned long id ;
882
883 /* ��Τ��ä����饤����Ȥ�¸�ߤ��뤫�ɤ�����Ĵ�٤롣*/
884 id = xclme->data.l[ 1 ] ;
885 if( ( ximpClient = Ximp_findClient( gw, id ) ) == NULL ){
886 return ;
887 }
888 ximpClient->xevent = *xclme ;
889 /* ���饤����Ȥ��˴����롣*/
890 if( ximpClient->skkinput != NULL ){
891 Ximp_unlinkClient( ximpClient ) ;
892 ximpClient->to_destroy = True ;
893 XtDestroyWidget( ximpClient->skkinput ) ;
894 } else {
895 Ximp_destroyClient( ximpClient ) ;
896 }
897 return ;
898 }
899
900 /*
901 * �Ѵ����������������ν�����Ԥ��ؿ���
902 */
Ximp_beginMessageHandler(Widget gw,XClientMessageEvent * xclme)903 static void Ximp_beginMessageHandler
904 ( Widget gw, XClientMessageEvent *xclme )
905 {
906 struct XimpClient *ximpClient ;
907 unsigned long id ;
908 Window probe ;
909 unsigned char *class_name ;
910 WidgetClass class ;
911 HistoryListNode *history ;
912
913 /* ���� create message �������Ƥ��ʤ���Фʤ�ʤ����������� */
914 id = xclme->data.l[ 1 ] ;
915 if( ( ximpClient = Ximp_findClient( gw, id ) ) == NULL ){
916 return ;
917 }
918 ximpClient->xevent = *xclme ;
919 /* ���˲����Ѵ���ȤϤ���Ƥ���Τ��� */
920 if( ximpClient->skkinput != NULL ){
921 return ;
922 }
923 if( !Ximp_isCorrectWindowP
924 ( gw, ximpClient->focus_window, NULL, NULL ) ||
925 ( ximpClient->style->inputStyle == WINDOW_TYPE_OFFTHESPOT &&
926 !( ximpClient->attribute_mask & XIMP_STS_AREA_MASK ) ) ){
927 /* ���饤����Ȥ˽�λ���Τ����롣*/
928 Ximp_sendClientMessage32
929 ( ximpClient, XIMP_PROCESS_END, ximpClient->id, 0L, 0L, 0L ) ;
930 Ximp_destroyClient( ximpClient ) ;
931 return ;
932 }
933 /* �ҥ��ȥ�ν�����������˺���ȡ� �ɤ��ʤ�Τ�������*/
934 history = history_setup
935 ( ximpClient->skkinput, ximpClient->request_window ) ;
936 /* �Ѵ��Τ���Υ�����ɥ���������뤾��*/
937 switch( ximpClient->style->inputStyle ){
938 case WINDOW_TYPE_OVERTHESPOT :
939 class_name = "overthespot" ;
940 class = overthespotWinWidgetClass ;
941 break ;
942 case WINDOW_TYPE_OFFTHESPOT :
943 class_name = "offthespot" ;
944 class = offthespotWinWidgetClass ;
945 break ;
946 case WINDOW_TYPE_SEPARATE :
947 default :
948 class_name = "separate" ;
949 class = separateWinWidgetClass ;
950 break ;
951 }
952 ximpClient->skkinput = XtVaCreateWidget
953 ( class_name, class, gw,
954 XtNmappedWhenManaged, False,
955 XtNclientWindow, ximpClient->request_window,
956 XtNconversionHistory, history, NULL ) ;
957
958 /* �Ƥ����Τ�ʤ����åȥ��å�����Ԥ���*/
959 XtCallCallbacks
960 ( gw, XtNsetupInputWindowNotify, ximpClient->skkinput ) ;
961 /* ������Хå������ꡣrealize ���Ƥ���Ǥ�����Ǥ��ʤ��Τǡ������� *
962 * ���뤳�Ȥˤʤ롣*/
963 XtAddCallback
964 ( ximpClient->skkinput, XtNfixNotify,
965 ( XtCallbackProc )Ximp_SendMessageToRequestorCallback,
966 ( XtPointer )ximpClient ) ;
967 XtAddCallback
968 ( ximpClient->skkinput, XtNendNotify,
969 ( XtCallbackProc )Ximp_EndMessageToRequestorCallback,
970 ( XtPointer )ximpClient ) ;
971 XtAddCallback
972 ( ximpClient->skkinput, XtNkeybackNotify,
973 ( XtCallbackProc )Ximp_KeyEventToRequestorCallback,
974 ( XtPointer )ximpClient ) ;
975
976 Ximp_fillInDefaultAttributes( ximpClient ) ;
977 Ximp_ComputeAreaForStartUp( ximpClient ) ;
978 ximpClient->camsg.mask = Ximp_makeConvAttributes
979 ( ximpClient, &ximpClient->camsg.value ) ;
980 XtVaSetValues
981 ( ximpClient->skkinput, XtNconversionAttribute,
982 &ximpClient->camsg, NULL ) ;
983
984 /* Event Capture Method �ν�����Ԥ���*/
985 if( ximpClient->event_capture_method == EVENT_HA_INPUTONLY ){
986 /* �Ѵ����饤����Ȥξ��Ʃ���Υ�����ɥ���Ž���դ��ƥ��٥�Ȥ�å *
987 * ����褦�ˤ��뤾��*/
988 probe = XCreateWindow
989 ( XtDisplay( gw ), ximpClient->focus_window, 0, 0, 9999, 9999, 0, 0,
990 InputOnly, (Visual *)CopyFromParent,
991 0L, (XSetWindowAttributes *)NULL ) ;
992 ximpClient->probe_window = probe ;
993 XMapWindow( XtDisplay( gw ), probe ) ;
994 } else {
995 ximpClient->probe_window = None ;
996 probe = ximpClient->focus_window ;
997 }
998 XtVaSetValues( ximpClient->skkinput, XtNprobeWindow, probe, NULL ) ;
999
1000 /* Window �� Pop Up ���롣Exclusive �ˤ���ȡ�¾�� Popup �������� *
1001 * ������˥������٥�Ȥ��Ȥ�ʤ��ʤäƤ��ޤ��Τǡ�Nonexclusive �� *
1002 * ���뤳�ȡ�*/
1003 XtRealizeWidget( ximpClient->skkinput ) ;
1004
1005 /*
1006 * focus �⤷����Ʃ��������ɥ����饭�����٥�Ȥ��롣
1007 */
1008 if( ximpClient->event_capture_method == EVENT_HA_FOCUS_KARA ||
1009 ximpClient->event_capture_method == EVENT_HA_INPUTONLY ){
1010 add_myeventhandler
1011 ( XtDisplay( gw ), probe,
1012 XtWindow( ximpClient->skkinput ), KeyPress, KeyPressMask ) ;
1013 add_myeventhandler
1014 ( XtDisplay( gw ), probe,
1015 XtWindow( ximpClient->skkinput ), KeyRelease, KeyReleaseMask ) ;
1016 }
1017 /* �Ѵ����饤����Ȥ��˴�����Ƥ��ޤä����ˤ�����ΤǤ���褦 *
1018 * �ˤ��뤾��*/
1019 add_myeventhandler
1020 ( XtDisplay( gw ), ximpClient->request_window, XtWindow( gw ),
1021 NO_EVENT_HANDLE, StructureNotifyMask ) ;
1022 Ximp_sendClientMessage32
1023 ( ximpClient, XIMP_PROCESS_BEGIN, ximpClient->id, 0L, 0L, 0L ) ;
1024 return ;
1025 }
1026
Ximp_endMessageHandler(Widget gw,XClientMessageEvent * xclme)1027 static void Ximp_endMessageHandler
1028 ( Widget gw, XClientMessageEvent *xclme )
1029 {
1030 unsigned long id = xclme->data.l[ 1 ] ;
1031 struct XimpClient *ximpClient ;
1032
1033 /* �ޤ��Ѵ���λ���褦�Ȥ��Ƥ��륯�饤����Ȥ��ºݤ˽�������Ƥ� *
1034 * ��Τ��ɤ����롣*/
1035 if( ( ximpClient = Ximp_findClient( gw, id ) ) == NULL ){
1036 return ;
1037 }
1038 ximpClient->xevent = *xclme ;
1039 if( ximpClient->skkinput == NULL )
1040 return ;
1041 /* �Ѵ�����ߤ��롣*/
1042 ximpClient->to_destroy = False ;
1043 XtDestroyWidget( ximpClient->skkinput ) ;
1044 return ;
1045 }
1046
Ximp_setFocusMessageHandler(Widget gw,XClientMessageEvent * xclme)1047 static void Ximp_setFocusMessageHandler
1048 ( Widget gw, XClientMessageEvent *xclme )
1049 {
1050 unsigned long id = xclme->data.l[ 1 ] ;
1051 struct XimpClient *ximpClient ;
1052
1053 /* �ޤ��Ѵ���λ���褦�Ȥ��Ƥ��륯�饤����Ȥ��ºݤ˽�������Ƥ� *
1054 * ��Τ��ɤ����롣*/
1055 if( ( ximpClient = Ximp_findClient( gw, id ) ) == NULL ){
1056 return ;
1057 }
1058 ximpClient->xevent = *xclme ;
1059 if( ximpClient->skkinput != NULL )
1060 XtVaSetValues
1061 ( ximpClient->skkinput, XtNsetFocus, True, NULL ) ;
1062 return ;
1063 }
1064
Ximp_unsetFocusMessageHandler(Widget gw,XClientMessageEvent * xclme)1065 static void Ximp_unsetFocusMessageHandler
1066 ( Widget gw, XClientMessageEvent *xclme )
1067 {
1068 unsigned long id = xclme->data.l[ 1 ] ;
1069 struct XimpClient *ximpClient ;
1070
1071 /* �ޤ��Ѵ���λ���褦�Ȥ��Ƥ��륯�饤����Ȥ��ºݤ˽�������Ƥ� *
1072 * ��Τ��ɤ����롣*/
1073 if( ( ximpClient = Ximp_findClient( gw, id ) ) == NULL ){
1074 return ;
1075 }
1076 ximpClient->xevent = *xclme ;
1077 if( ximpClient->skkinput != NULL )
1078 XtVaSetValues
1079 ( ximpClient->skkinput, XtNunsetFocus, True, NULL ) ;
1080 return ;
1081 }
1082
Ximp_moveMessageHandler(Widget gw,XClientMessageEvent * xclme)1083 static void Ximp_moveMessageHandler
1084 ( Widget gw, XClientMessageEvent *xclme )
1085 {
1086 unsigned long id = xclme->data.l[ 1 ] ;
1087 struct XimpClient *ximpClient ;
1088
1089 /* �ޤ��Ѵ���λ���褦�Ȥ��Ƥ��륯�饤����Ȥ��ºݤ˽�������Ƥ� *
1090 * ��Τ��ɤ����롣*/
1091 if( ( ximpClient = Ximp_findClient( gw, id ) ) == NULL ){
1092 return ;
1093 }
1094 ximpClient->xevent = *xclme ;
1095
1096 ximpClient->preedit_attributes.spot_x = xclme->data.l[ 2 ] ;
1097 ximpClient->preedit_attributes.spot_y = xclme->data.l[ 3 ] ;
1098 /* �Ѵ��������˾��������ͳ����뤫�⤷��ʤ��Τǡ���ա�*/
1099 ximpClient->attribute_mask |= XIMP_PRE_SPOTL_MASK ;
1100
1101 /* �����顢������ NULL ���ɤ������Ƥ��롣*/
1102 if( ximpClient->skkinput != NULL ){
1103 ximpClient->camsg.mask = CASpotLocation ;
1104 ximpClient->camsg.value.spot_x = ximpClient->preedit_attributes.spot_x ;
1105 ximpClient->camsg.value.spot_y = ximpClient->preedit_attributes.spot_y ;
1106 XtVaSetValues
1107 ( ximpClient->skkinput, XtNconversionAttribute,
1108 &ximpClient->camsg, NULL ) ;
1109 }
1110 return ;
1111 }
1112
Ximp_resetMessageHandler(Widget gw,XClientMessageEvent * xclme)1113 static void Ximp_resetMessageHandler
1114 ( Widget gw, XClientMessageEvent *xclme )
1115 {
1116 XimpWidget w = ( XimpWidget )gw ;
1117 unsigned long id = xclme->data.l[ 1 ] ;
1118 struct XimpClient *ximpClient ;
1119
1120 /* �ޤ��Ѵ���λ���褦�Ȥ��Ƥ��륯�饤����Ȥ��ºݤ˽�������Ƥ� *
1121 * ��Τ��ɤ����롣*/
1122 if( ( ximpClient = Ximp_findClient( gw, id ) ) == NULL ){
1123 return ;
1124 }
1125 ximpClient->xevent = *xclme ;
1126 ximpClient->resetting = True ;
1127 /* ����ʸ��������롣(?)*/
1128 XChangeProperty
1129 ( XtDisplay( gw ), XtWindow( gw ),
1130 ximpClient->property, w->ximp.compound_text, 8,
1131 PropModeAppend, (unsigned char *)"", 0 ) ;
1132 /* �ꥻ�åȤ����ݤ������롣*/
1133 Ximp_sendClientMessage32
1134 ( ximpClient, XIMP_RESET_RETURN, ximpClient->id,
1135 ximpClient->property, 0L, 0L ) ;
1136 return ;
1137 }
1138
Ximp_setvalueMessageHandler(Widget gw,XClientMessageEvent * xclme)1139 static void Ximp_setvalueMessageHandler
1140 ( Widget gw, XClientMessageEvent *xclme )
1141 {
1142 unsigned long id = xclme->data.l[ 1 ] ;
1143 struct XimpClient *ximpClient ;
1144 unsigned long mask ;
1145
1146 /* �ޤ��Ѵ���λ���褦�Ȥ��Ƥ��륯�饤����Ȥ��ºݤ˽�������Ƥ���
1147 * �Τ��ɤ����롣�ɤ���顢Netscape �ϥե�����ξ��Ȥ��˴ط���
1148 * ���ˡ�Ʊ��� Netscape �ʤ�Ʊ��� ID ���Ѥ��褦�Ȥ���餷���ġ���
1149 * ��Ϻ��ä����Ȥ��Ȼפ��ġ�*/
1150 if( ( ximpClient = Ximp_findClient( gw, id ) ) == NULL ){
1151 return ;
1152 }
1153 mask = xclme->data.l[ 2 ] ;
1154 ximpClient->xevent = *xclme ;
1155 #ifdef DEBUG
1156 printf( "[Ximp] SetValueMessage( mask = %lx )\n", mask ) ;
1157 #endif
1158 Ximp_getAttributes( ximpClient, mask ) ;
1159 /* �����Ѵ����Ϥ���Ƥ���Τʤ�ġ�*/
1160 if( ximpClient->skkinput != NULL ){
1161 ximpClient->camsg.mask = Ximp_makeConvAttributes
1162 ( ximpClient, &ximpClient->camsg.value ) ;
1163 if( ximpClient->camsg.mask )
1164 XtVaSetValues
1165 ( ximpClient->skkinput, XtNconversionAttribute,
1166 &ximpClient->camsg, NULL ) ;
1167 }
1168 return ;
1169 }
1170
Ximp_changeMessageHandler(Widget gw,XClientMessageEvent * xclme)1171 static void Ximp_changeMessageHandler
1172 ( Widget gw, XClientMessageEvent *xclme )
1173 {
1174 XimpWidget w = ( XimpWidget )gw ;
1175 unsigned long id = xclme->data.l[ 1 ] ;
1176 struct XimpClient *ximpClient ;
1177 Atom atom ;
1178 unsigned long mask ;
1179
1180 /* �ޤ��Ѵ���λ���褦�Ȥ��Ƥ��륯�饤����Ȥ��ºݤ˽�������Ƥ� *
1181 * ��Τ��ɤ����롣*/
1182 if( ( ximpClient = Ximp_findClient( gw, id ) ) == NULL ){
1183 return ;
1184 }
1185 /* �Ѳ�����°���� ATOM �η����Ϥ���롣*/
1186 atom = xclme->data.l[ 2 ] ;
1187 ximpClient->xevent = *xclme ;
1188 /* �ɤ�°�����Ѳ������ΤǤ����� */
1189 if( atom == w->ximp.ximp_focus ){
1190 /* ���������ե����������Ƥ��륦����ɥ����Ѳ����������Ȼפ��� *
1191 * �����������ä����ʡ� �����ɤ�Ȥ����ʤ�Τ����� */
1192 mask = XIMP_FOCUS_WIN_MASK ;
1193 } else if( atom == w->ximp.ximp_preedit ){
1194 mask = PREEDIT_MASK ;
1195 } else if( atom == w->ximp.ximp_status ){
1196 mask = STATUS_MASK ;
1197 } else if( atom == w->ximp.ximp_preeditfont ){
1198 mask = XIMP_PRE_FONT_MASK ;
1199 } else if( atom == w->ximp.ximp_statusfont ){
1200 mask = XIMP_STS_FONT_MASK ;
1201 } else {
1202 Ximp_sendErrorEvent( ximpClient, XIMP_BadProperty ) ;
1203 return ;
1204 }
1205 /* �Ѳ�����°������ټ��ľ����*/
1206 Ximp_getAttributes( ximpClient, mask ) ;
1207 if( ximpClient->skkinput != NULL ){
1208 ximpClient->camsg.mask =
1209 Ximp_makeConvAttributes( ximpClient, &ximpClient->camsg.value ) ;
1210 XtVaSetValues
1211 ( ximpClient->skkinput, XtNconversionAttribute,
1212 &ximpClient->camsg, NULL ) ;
1213 }
1214 return ;
1215 }
1216
Ximp_getValueMessageHandler(Widget gw,XClientMessageEvent * xclme)1217 static void Ximp_getValueMessageHandler
1218 ( Widget gw, XClientMessageEvent *xclme )
1219 {
1220 unsigned long id = xclme->data.l[ 1 ] ;
1221 struct XimpClient *ximpClient ;
1222 unsigned long mask ;
1223
1224 /* �ޤ��Ѵ���λ���褦�Ȥ��Ƥ��륯�饤����Ȥ��ºݤ˽�������Ƥ� *
1225 * ��Τ��ɤ����롣*/
1226 if( ( ximpClient = Ximp_findClient( gw, id ) ) == NULL ){
1227 return ;
1228 }
1229 ximpClient->xevent = *xclme ;
1230 mask = xclme->data.l[ 2 ] ;
1231 #ifdef DEBUG
1232 printf( "[Ximp] GetValueMessage( mask = %lx )\n", mask ) ;
1233 #endif
1234 Ximp_fillInDefaultAttributes( ximpClient ) ;
1235 Ximp_ComputeAreaForQuery( ximpClient ) ;
1236 Ximp_setAttributes( ximpClient, mask ) ;
1237 Ximp_sendClientMessage32
1238 ( ximpClient, XIMP_GETVALUE_RETURN, ximpClient->id, 0L, 0L, 0L ) ;
1239 return ;
1240 }
1241
Ximp_keypressMessageHandler(Widget gw,XClientMessageEvent * xclme)1242 static void Ximp_keypressMessageHandler
1243 ( Widget gw, XClientMessageEvent *xclme )
1244 {
1245 unsigned long id = xclme->data.l[ 1 ] ;
1246 struct XimpClient *ximpClient ;
1247 XKeyEvent xkey ;
1248
1249 /* �ޤ��Ѵ���λ���褦�Ȥ��Ƥ��륯�饤����Ȥ��ºݤ˽�������Ƥ� *
1250 * ��Τ��ɤ����롣*/
1251 if( ( ximpClient = Ximp_findClient( gw, id ) ) == NULL ){
1252 return ;
1253 }
1254 ximpClient->xevent = *xclme ;
1255
1256 if( ximpClient->skkinput == NULL )
1257 return ;
1258
1259 /* �������٥�Ȥ� fake ���롣*/
1260 xkey.type = KeyPress ;
1261 xkey.serial = xclme->serial ;
1262 xkey.send_event = True ;
1263 xkey.display = xclme->display ;
1264 xkey.window = ximpClient->focus_window ;
1265 xkey.root = DefaultRootWindow( xclme->display ) ;
1266 xkey.subwindow = None ;
1267 xkey.time = 0 ;
1268 xkey.x = 0 ;
1269 xkey.y = 0 ;
1270 xkey.x_root = 0 ;
1271 xkey.y_root = 0 ;
1272 xkey.state = xclme->data.l[ 3 ] ;
1273 xkey.keycode = xclme->data.l[ 2 ] ;
1274 xkey.same_screen = True ;
1275
1276 /* ����Ĥ��롣*/
1277 XtCallActionProc
1278 ( ximpClient->skkinput, "KeyDownEventHandler",
1279 ( XEvent * )&xkey, ( String * )NULL, ( Cardinal )0 ) ;
1280 return ;
1281 }
1282
Ximp_extensionMessageHandler(Widget gw,XClientMessageEvent * xclme)1283 static void Ximp_extensionMessageHandler
1284 ( Widget gw, XClientMessageEvent *xclme )
1285 {
1286 XimpWidget w = ( XimpWidget )gw ;
1287 unsigned long id = xclme->data.l[ 1 ] ;
1288 struct XimpClient *ximpClient ;
1289 Atom extension_atom ;
1290
1291 /* �ޤ��Ѵ���λ���褦�Ȥ��Ƥ��륯�饤����Ȥ��ºݤ˽�������Ƥ� *
1292 * ��Τ��ɤ����롣*/
1293 if( ( ximpClient = Ximp_findClient( gw, id ) ) == NULL ){
1294 return ;
1295 }
1296 ximpClient->xevent = *xclme ;
1297 extension_atom = xclme->data.l[ 2 ] ;
1298
1299 if( extension_atom == w->ximp.ximp_extbackfront ){
1300 if( ximpClient->skkinput != NULL ){
1301 return ;
1302 }
1303 if( xclme->data.l[ 3 ] != 0 ){
1304 ximpClient->event_capture_method = EVENT_NO_SHORINASHI ;
1305 } else {
1306 ximpClient->event_capture_method = EVENT_HA_FOCUS_KARA ;
1307 }
1308 } else {
1309 Ximp_sendErrorEvent( ximpClient, XIMP_BadAtom ) ;
1310 }
1311 return ;
1312 }
1313
1314 /*
1315 * ��³���Ф��Ƥ������饤����ȤΥС��������������ؿ���
1316 *----
1317 * �̤˼��ʤ��Ƥ�����ʤ��褦�����ɡġ�
1318 */
Ximp_getClientVersionProperty(struct XimpClient * ximpClient)1319 static int Ximp_getClientVersionProperty
1320 ( struct XimpClient *ximpClient )
1321 {
1322 XimpWidget w = ( XimpWidget )ximpClient->protocol_widget ;
1323 unsigned char *version_string ;
1324 unsigned long length ;
1325
1326 if( !Ximp_getProperty
1327 ( ximpClient, w->ximp.ximp_version, XA_STRING, 8,
1328 &version_string, &length ) ){
1329 ximpClient->client_version = NULL ;
1330 return False ;
1331 }
1332 ximpClient->client_version = version_string ;
1333 return True ;
1334 }
1335
1336 /*
1337 * �Ѵ����饤����Ȥξ����ȴ���Ф��ؿ�������
1338 */
Ximp_getAttributes(struct XimpClient * ximpClient,unsigned long mask)1339 static void Ximp_getAttributes
1340 ( struct XimpClient *ximpClient, unsigned long mask )
1341 {
1342 if( mask & XIMP_FOCUS_WIN_MASK ){
1343 Ximp_getFocusProperty( ximpClient ) ;
1344 }
1345 if( mask & XIMP_PRE_FONT_MASK ){
1346 Ximp_getPreeditFontProperty( ximpClient ) ;
1347 }
1348 if( mask & XIMP_STS_FONT_MASK ){
1349 Ximp_getStatusFontProperty( ximpClient ) ;
1350 }
1351 if( mask & PREEDIT_MASK ){
1352 Ximp_getPreeditProperty( ximpClient, mask & PREEDIT_MASK ) ;
1353 }
1354 if( mask & STATUS_MASK ){
1355 Ximp_getStatusProperty( ximpClient, mask & STATUS_MASK ) ;
1356 }
1357 return ;
1358 }
1359
1360 /*
1361 * �Ѵ����饤����Ȥ��᤹��°���Ȥ�������ħ�Ȥ����������Ȥ������ؼ�
1362 * �Τ褦�ʤ�Τ���Ф��ؿ���
1363 */
Ximp_getProperty(struct XimpClient * ximpClient,Atom property,Atom type,int format,unsigned char ** rprop,unsigned long * rnitems)1364 static int Ximp_getProperty
1365 ( struct XimpClient *ximpClient, Atom property, Atom type, int format,
1366 unsigned char **rprop, unsigned long *rnitems )
1367 {
1368 Atom actualtype ;
1369 int actualformat ;
1370 unsigned long rbytes_after ;
1371
1372 *rprop = NULL ;
1373 /* �Ѵ����饤����ȤΥ�����ɥ��ɣĤ����Ѥ��ơ����Υץ�ѥƥ����ɤࡣ*/
1374 XGetWindowProperty
1375 ( XtDisplay( ximpClient->protocol_widget ),
1376 ximpClient->request_window,
1377 property, 0L, 1000L, True, type,
1378 &actualtype, &actualformat, rnitems,
1379 &rbytes_after, rprop ) ;
1380 /* �ؼ������ץ�ѥƥ����ɤ�ʤ���Х��顼�����Τ��롣*/
1381 if( actualtype == None ){
1382 Ximp_sendErrorEvent( ximpClient, XIMP_BadProperty ) ;
1383 return False ;
1384 } else if( actualtype != type ){
1385 Ximp_sendErrorEvent( ximpClient, XIMP_BadPropertyType ) ;
1386 return False;
1387 } else if( actualformat != format ){
1388 if( *rprop != NULL )
1389 XFree( (char *)*rprop ) ;
1390 *rprop = NULL ;
1391 Ximp_sendErrorEvent( ximpClient, XIMP_BadPropertyType ) ;
1392 return False ;
1393 }
1394 /* ̵�����ɤ��УϣˤʤΤǤ��롣*/
1395 return True ;
1396 }
1397
Ximp_getFocusProperty(struct XimpClient * ximpClient)1398 static void Ximp_getFocusProperty( struct XimpClient *ximpClient )
1399 {
1400 XimpWidget w = ( XimpWidget )ximpClient->protocol_widget ;
1401 unsigned char *data ;
1402 unsigned long len ;
1403 Window focus_window ;
1404 unsigned int width, height ;
1405
1406 if( !Ximp_getProperty
1407 ( ximpClient, w->ximp.ximp_focus, XA_WINDOW, 32,
1408 &data, &len ) ){
1409 return ;
1410 } else if( len != 1 ){
1411 XFree( ( char * )data ) ;
1412 return ;
1413 }
1414
1415 focus_window = *( Window * )data ;
1416 XFree( ( char * )data ) ;
1417
1418 if( !Ximp_isCorrectWindowP( ( Widget )w, focus_window, &width, &height ) ){
1419 Ximp_sendErrorEvent( ximpClient, XIMP_BadFocusWindow ) ;
1420 return ;
1421 }
1422 /* �ե�������������ɥ���������롣*/
1423 #ifdef DEBUG
1424 fprintf
1425 ( stderr, "(Ximp) FocusWindow:(%lu) %u x %u, RequestWindow:(%lu)\n",
1426 focus_window, width, height, ximpClient->request_window ) ;
1427 #endif
1428 if( ximpClient->skkinput != NULL )
1429 Ximp_ChangeFocusWindow( ximpClient, focus_window ) ;
1430
1431 ximpClient->focus_window = focus_window ;
1432 ximpClient->attribute_mask |= XIMP_FOCUS_WIN_MASK ;
1433 ximpClient->focus_width = width ;
1434 ximpClient->focus_height = height ;
1435 return ;
1436 }
1437
Ximp_getPreeditFontProperty(struct XimpClient * ximpClient)1438 static void Ximp_getPreeditFontProperty
1439 ( struct XimpClient *ximpClient )
1440 {
1441 XimpWidget w = ( XimpWidget )ximpClient->protocol_widget ;
1442 unsigned char *fontlistname ;
1443 unsigned long length_of_fontlistname ;
1444
1445 #ifdef DEBUG
1446 printf( "(Ximp) GetPreeditFontProperty()\n" ) ;
1447 #endif
1448 /* �ե���Ȥ�̾����ȴ���Ф���*/
1449 if( !Ximp_getProperty
1450 ( ximpClient, w->ximp.ximp_preeditfont, XA_STRING, 8,
1451 &fontlistname, &length_of_fontlistname ) ){
1452 return ;
1453 }
1454
1455 /* ���˲��餫�Υե���Ȥ������Ƥ��Ƥ���Τʤ�С������������� *
1456 * �����ե���Ȥ�̾������Ͽ���롣*/
1457 if( ximpClient->preedit_attributes.fontlist != NULL ){
1458 if( !strcmp( fontlistname, ximpClient->preedit_attributes.fontlist ) ){
1459 XFree( fontlistname ) ;
1460 return;
1461 }
1462 XFree( ximpClient->preedit_attributes.fontlist ) ;
1463 }
1464 ximpClient->preedit_attributes.fontlist = fontlistname ;
1465 ximpClient->attribute_mask |= XIMP_PRE_FONT_MASK ;
1466 Ximp_getFonts( ximpClient, fontlistname ) ;
1467 return ;
1468 }
1469
Ximp_getFonts(struct XimpClient * ximpClient,unsigned char * fontnamelist)1470 static void Ximp_getFonts
1471 ( struct XimpClient *ximpClient, unsigned char *fontnamelist )
1472 {
1473 #ifdef DEBUG
1474 fprintf( stdout, "(Ximp) fontset = \"%s\"\n", fontnamelist ) ;
1475 fflush( stdout ) ;
1476 #endif
1477 /* �ե���Ȥ���ݤ��롣*/
1478 fontMgr_PrepareFontByName
1479 ( XtDisplay( ximpClient->protocol_widget ),
1480 ximpClient->fontset, fontnamelist ) ;
1481 return ;
1482 }
1483
Ximp_getStatusFontProperty(struct XimpClient * ximpClient)1484 static void Ximp_getStatusFontProperty
1485 ( struct XimpClient *ximpClient )
1486 {
1487 XimpWidget w = ( XimpWidget )ximpClient->protocol_widget ;
1488 unsigned char *fontlistname ;
1489 unsigned long length_of_fontlistname ;
1490
1491 #ifdef DEBUG
1492 printf( "(Ximp) GetStatusFontProperty()\n" ) ;
1493 #endif
1494 if( !Ximp_getProperty
1495 ( ximpClient, w->ximp.ximp_statusfont, XA_STRING, 8,
1496 &fontlistname, &length_of_fontlistname ) ){
1497 return ;
1498 }
1499
1500 if( ximpClient->status_attributes.fontlist != NULL ){
1501 XFree( ximpClient->status_attributes.fontlist ) ;
1502 }
1503 ximpClient->status_attributes.fontlist = fontlistname ;
1504 ximpClient->attribute_mask |= XIMP_STS_FONT_MASK ;
1505 return ;
1506 }
1507
Ximp_getPreeditProperty(struct XimpClient * ximpClient,unsigned long mask)1508 static void Ximp_getPreeditProperty
1509 ( struct XimpClient *ximpClient, unsigned long mask )
1510 {
1511 XimpWidget w = ( XimpWidget )ximpClient->protocol_widget ;
1512 unsigned long *data ;
1513 unsigned long len ;
1514
1515 if( !Ximp_getProperty
1516 ( ximpClient, w->ximp.ximp_preedit,
1517 w->ximp.ximp_preedit, 32,
1518 ( unsigned char ** )&data, &len ) ){
1519 return ;
1520 } else if ( len < 14 ){
1521 XFree( ( char * )data ) ;
1522 return ;
1523 }
1524
1525 ximpClient->attribute_mask |= mask ;
1526 #ifdef DEBUG
1527 printf( "(Ximp) GetPreeditProperty()\n" ) ;
1528 #endif
1529 /* �Ѵ����饤����Ȥ�ɽ�����ꥢ�ΰ��ֵڤ��礭���������롣*/
1530 if( mask & XIMP_PRE_AREA_MASK ){
1531 ximpClient->preedit_attributes.area_x = data[ 0 ] ;
1532 ximpClient->preedit_attributes.area_y = data[ 1 ] ;
1533 ximpClient->preedit_attributes.area_width = data[ 2 ] ;
1534 ximpClient->preedit_attributes.area_height = data[ 3 ] ;
1535 if( data[ 2 ] == 0 || data[ 3 ] == 0 ){
1536 ximpClient->attribute_mask &= ~( XIMP_PRE_AREA_MASK ) ;
1537 }
1538 #ifdef DEBUG
1539 printf( "\t\"PRE_AREA_MASK\" (x,y,w,h)=(%ld,%ld,%ld,%ld)\n",
1540 data[0],data[1],data[2],data[3] ) ;
1541 #endif
1542 }
1543 /* �Ѵ����饤����Ȥ����ʿ��������롣*/
1544 if( mask & XIMP_PRE_FG_MASK ){
1545 ximpClient->preedit_attributes.foreground = data[ 4 ] ;
1546 #ifdef DEBUG
1547 printf( "\t\"XIMP_PRE_FG_MASK\" foreground = %lx\n", data[4] ) ;
1548 #endif
1549 }
1550 /* �Ѵ����饤����Ȥ��طʿ��������롣*/
1551 if( mask & XIMP_PRE_BG_MASK ){
1552 ximpClient->preedit_attributes.background = data[ 5 ] ;
1553 #ifdef DEBUG
1554 printf( "\t\"XIMP_PRE_BG_MASK\" background = %lx\n", data[5] ) ;
1555 #endif
1556 }
1557 /* �Ѵ����饤����Ȥ��طʤΥԥå����ޥåפ������������롩 */
1558 if( mask & XIMP_PRE_COLORMAP_MASK ){
1559 ximpClient->preedit_attributes.colormap = data[ 6 ] ;
1560 #ifdef DEBUG
1561 printf( "\t\"XIMP_PRE_COLORMAP_MASK\" colormap = %ld\n",data[6] ) ;
1562 #endif
1563 }
1564 if( mask & XIMP_PRE_BGPIXMAP_MASK ){
1565 ximpClient->preedit_attributes.background_pixmap = data[ 7 ] ;
1566 #ifdef DEBUG
1567 printf( "\t\"XIMP_PRE_BGPIXMAP_MASK\" bg_pixmap = %ld\n", data[7] ) ;
1568 #endif
1569 }
1570 if( mask & XIMP_PRE_LINESP_MASK ){
1571 if( data[8] < MIN_LINE_SPACING ){
1572 ximpClient->attribute_mask &= ~XIMP_PRE_LINESP_MASK ;
1573 } else {
1574 ximpClient->preedit_attributes.line_spacing = data[ 8 ] ;
1575 }
1576 #ifdef DEBUG
1577 printf( "\t\"XIMP_PRE_LINESP_MASK\" linespacing = %ld\n",data[ 8 ] ) ;
1578 #endif
1579 }
1580 /* data[9]: Cursor */
1581 if( mask & XIMP_PRE_CURSOR_MASK ){
1582 ximpClient->preedit_attributes.cursor = data[ 9 ] ;
1583 #ifdef DEBUG
1584 printf( "\t\"XIMP_PRE_CURSOR_MASK\" cursor = %lx\n", data[9] ) ;
1585 #endif
1586 }
1587 if( mask & XIMP_PRE_AREANEED_MASK ){
1588 ximpClient->preedit_attributes.needed_width = data[ 10 ] ;
1589 ximpClient->preedit_attributes.needed_height = data[ 11 ] ;
1590 #ifdef DEBUG
1591 printf( "\t\"XIMP_PRE_AREANEED_MASK\" (w,h) = (%ld,%ld)\n",
1592 data[10],data[11] ) ;
1593 #endif
1594 }
1595 if( mask & XIMP_PRE_SPOTL_MASK ){
1596 ximpClient->preedit_attributes.spot_x = data[ 12 ] ;
1597 ximpClient->preedit_attributes.spot_y = data[ 13 ] ;
1598 #ifdef DEBUG
1599 printf( "\t\"XIMP_PRE_SPOTL_MASK\" (x,y) = (%ld,%ld)\n",
1600 data[12],data[13] ) ;
1601 #endif
1602 }
1603 XFree( ( char * )data ) ;
1604 return ;
1605 }
1606
Ximp_getStatusProperty(struct XimpClient * ximpClient,unsigned long mask)1607 static void Ximp_getStatusProperty
1608 ( struct XimpClient *ximpClient, unsigned long mask )
1609 {
1610 XimpWidget w = ( XimpWidget )ximpClient->protocol_widget ;
1611 unsigned long *data ;
1612 unsigned long len ;
1613
1614 if( !Ximp_getProperty
1615 ( ximpClient, w->ximp.ximp_status,
1616 w->ximp.ximp_status, 32,
1617 ( unsigned char ** )&data, &len ) ){
1618 return ;
1619 } else if( len < 12 ){
1620 XFree( ( char * )data ) ;
1621 return ;
1622 }
1623
1624 ximpClient->attribute_mask |= mask ;
1625 #ifdef DEBUG
1626 printf( "(Ximp) GetStatusProperty( mask = %lx )\n", mask ) ;
1627 #endif
1628 if( mask & XIMP_STS_AREA_MASK ){
1629 if( data[ 2 ] > 0 && data[ 3 ] > 0 ){
1630 ximpClient->status_attributes.area_x = data[ 0 ] ;
1631 ximpClient->status_attributes.area_y = data[ 1 ] ;
1632 ximpClient->status_attributes.area_width = data[ 2 ] ;
1633 ximpClient->status_attributes.area_height = data[ 3 ] ;
1634 } else {
1635 ximpClient->attribute_mask &= ~( XIMP_STS_AREA_MASK ) ;
1636 }
1637 #ifdef DEBUG
1638 printf( "\t\"XIMP_STS_AREA_MASK\" (x,y,w,h) = (%ld,%ld,%ld,%ld)\n",
1639 data[ 0 ], data[ 1 ],data[ 2 ], data[ 3 ] ) ;
1640 #endif
1641 }
1642 if( mask & XIMP_STS_FG_MASK ){
1643 ximpClient->status_attributes.foreground = data[ 4 ] ;
1644 #ifdef DEBUG
1645 printf( "\t\"XIMP_STS_FG_MASK\" foreground = %ld\n", data[4] ) ;
1646 #endif
1647 }
1648 if( mask & XIMP_STS_BG_MASK ){
1649 ximpClient->status_attributes.background = data[ 5 ] ;
1650 #ifdef DEBUG
1651 printf( "\t\"XIMP_STS_BG_MASK\" background = %ld\n", data[5] ) ;
1652 #endif
1653 }
1654 if( mask & XIMP_STS_COLORMAP_MASK ){
1655 ximpClient->status_attributes.colormap = data[ 6 ] ;
1656 #ifdef DEBUG
1657 printf( "\t\"XIMP_STS_COLORMAP_MASK\" colormap = %ld\n", data[6] ) ;
1658 #endif
1659 }
1660 if( mask & XIMP_STS_BGPIXMAP_MASK ){
1661 ximpClient->status_attributes.background_pixmap = data[ 7 ] ;
1662 #ifdef DEBUG
1663 printf( "\t\"XIMP_STS_BGPIXMAP_MASK\" bgpixmap = %ld\n", data[7] ) ;
1664 #endif
1665 }
1666 if( mask & XIMP_STS_LINESP_MASK ){
1667 if( data[ 8 ] < MIN_LINE_SPACING ){
1668 ximpClient->attribute_mask &= ~( XIMP_STS_LINESP_MASK ) ;
1669 } else {
1670 ximpClient->status_attributes.line_spacing = data[ 8 ] ;
1671 }
1672 #ifdef DEBUG
1673 printf( "\t\"XIMP_STS_LINESP_MASK\" linespacing = %ld\n", data[8] ) ;
1674 #endif
1675 }
1676 if( mask & XIMP_STS_CURSOR_MASK ){
1677 ximpClient->status_attributes.cursor = data[ 9 ] ;
1678 #ifdef DEBUG
1679 printf( "\t\"XIMP_STS_CURSOR_MASK\" cursor = %lx\n", data[9] ) ;
1680 #endif
1681 }
1682 if( mask & XIMP_STS_AREANEED_MASK ){
1683 ximpClient->status_attributes.needed_width = data[ 10 ] ;
1684 ximpClient->status_attributes.needed_height = data[ 11 ] ;
1685 #ifdef DEBUG
1686 printf( "\t\"XIMP_STS_AREANEED_MASK\" (w,h) = (%ld,%ld)\n",
1687 data[10],data[11] ) ;
1688 #endif
1689 }
1690 if( len > 12 && ( mask & XIMP_STS_WINDOW_MASK ) ){
1691 ximpClient->status_window = None ;
1692 #ifdef DEBUG
1693 printf( "\t\"XIMP_STS_WINDOW_MASK\" window = None\n" ) ;
1694 #endif
1695 }
1696 XFree( ( char *)data ) ;
1697 return ;
1698 }
1699
1700 /*
1701 * �ݡݡ� �������鲼���Ѵ�°�����Ѵ����饤����Ȥ��������Ϣ �ݡݡ�
1702 */
1703
Ximp_setAttributes(struct XimpClient * ximpClient,unsigned long mask)1704 static void Ximp_setAttributes
1705 ( struct XimpClient *ximpClient, unsigned long mask )
1706 {
1707 if( mask & XIMP_FOCUS_WIN_MASK ){
1708 Ximp_setFocusProperty( ximpClient ) ;
1709 }
1710 if( mask & XIMP_PRE_FONT_MASK ){
1711 Ximp_setPreeditFontProperty( ximpClient ) ;
1712 }
1713 if( mask & XIMP_STS_FONT_MASK ){
1714 Ximp_setStatusFontProperty( ximpClient ) ;
1715 }
1716 if( mask & PREEDIT_MASK ){
1717 Ximp_setPreeditProperty( ximpClient, mask ) ;
1718 }
1719 if( mask & STATUS_MASK ){
1720 Ximp_setStatusProperty( ximpClient, mask ) ;
1721 }
1722 return ;
1723 }
1724
Ximp_setFocusProperty(struct XimpClient * ximpClient)1725 static void Ximp_setFocusProperty
1726 ( struct XimpClient *ximpClient )
1727 {
1728 XimpWidget w = ( XimpWidget )ximpClient->protocol_widget ;
1729
1730 #ifdef DEBUG
1731 printf( "(Ximp) setFocusProperty() focus = %ld\n",
1732 ximpClient->focus_window ) ;
1733 #endif
1734 Ximp_setProperty
1735 ( ximpClient, w->ximp.ximp_focus, XA_WINDOW, 32,
1736 ( unsigned char * )&ximpClient->focus_window, 1 ) ;
1737 return ;
1738 }
1739
Ximp_setPreeditFontProperty(struct XimpClient * ximpClient)1740 static void Ximp_setPreeditFontProperty
1741 ( struct XimpClient *ximpClient )
1742 {
1743 XimpWidget w = ( XimpWidget )ximpClient->protocol_widget ;
1744
1745 #ifdef DEBUG
1746 printf( "(Ximp) setPreeditFont()\n" ) ;
1747 #endif
1748 /* �ե���Ȥޤ��ϥǥե���Ȥ� Overthespot �Ȥ�����Ǥ�äƤ���� *
1749 * �ǡ��Ѵ����饤�����¦�����ꤷ�ʤ���� NULL �Τޤޡ�*/
1750 if( ximpClient->preedit_attributes.fontlist != NULL ){
1751 Ximp_setProperty
1752 ( ximpClient, w->ximp.ximp_preeditfont, XA_STRING, 8,
1753 ( unsigned char * )ximpClient->preedit_attributes.fontlist,
1754 strlen( ximpClient->preedit_attributes.fontlist ) ) ;
1755 } else {
1756 Ximp_setProperty
1757 ( ximpClient, w->ximp.ximp_preeditfont, XA_STRING, 8,
1758 ( unsigned char * )"", 0 ) ;
1759 }
1760 return ;
1761 }
1762
Ximp_setStatusFontProperty(struct XimpClient * ximpClient)1763 static void Ximp_setStatusFontProperty
1764 ( struct XimpClient *ximpClient )
1765 {
1766 XimpWidget w = ( XimpWidget )ximpClient->protocol_widget ;
1767
1768 #ifdef DEBUG
1769 printf( "(Ximp) setStatusFont()\n" ) ;
1770 #endif
1771 /* �ե���Ȥޤ��ϥǥե���Ȥ� Overthespot �Ȥ�����Ǥ�äƤ���� *
1772 * �ǡ��Ѵ����饤�����¦�����ꤷ�ʤ���� NULL �Τޤޡ�*/
1773 if( ximpClient->status_attributes.fontlist != NULL ){
1774 Ximp_setProperty
1775 ( ximpClient, w->ximp.ximp_statusfont, XA_STRING, 8,
1776 ( unsigned char * )ximpClient->status_attributes.fontlist,
1777 strlen( ximpClient->status_attributes.fontlist ) ) ;
1778 } else {
1779 Ximp_setProperty
1780 ( ximpClient, w->ximp.ximp_statusfont, XA_STRING, 8,
1781 ( unsigned char * )"", 0 ) ;
1782 }
1783 return ;
1784 }
1785
Ximp_setPreeditProperty(struct XimpClient * ximpClient,unsigned long mask)1786 static void Ximp_setPreeditProperty
1787 ( struct XimpClient *ximpClient, unsigned long mask )
1788 {
1789 XimpWidget w = ( XimpWidget )ximpClient->protocol_widget ;
1790 long data[ 14 ] ;
1791
1792 #ifdef DEBUG
1793 printf( "(Ximp) setPreeditProperty( mask = %lx )\n", mask ) ;
1794 #endif
1795 /* data[0]-data[3]: Area.{x,y,width,height} */
1796 if( mask & XIMP_PRE_AREA_MASK ){
1797 data[ 0 ] = ximpClient->preedit_attributes.area_x ;
1798 data[ 1 ] = ximpClient->preedit_attributes.area_y ;
1799 data[ 2 ] = ximpClient->preedit_attributes.area_width ;
1800 data[ 3 ] = ximpClient->preedit_attributes.area_height ;
1801 #ifdef DEBUG
1802 printf( "\t\"XIMP_PRE_AREA_MASK\" (x,y,w,h)=(%ld,%ld,%ld,%ld)\n",
1803 data[0],data[1],data[2],data[3] ) ;
1804 #endif
1805 }
1806 /* data[4]: Foreground */
1807 if( mask & XIMP_PRE_FG_MASK ){
1808 data[ 4 ] = ximpClient->preedit_attributes.foreground ;
1809 #ifdef DEBUG
1810 printf( "\t\"XIMP_PRE_FG_MASK\" foreground = %lx\n", data[4] ) ;
1811 #endif
1812 }
1813 /* data[5]: Background */
1814 if( mask & XIMP_PRE_BG_MASK ){
1815 data[ 5 ] = ximpClient->preedit_attributes.background ;
1816 #ifdef DEBUG
1817 printf( "\t\"XIMP_PRE_BG_MASK\" background = %lx\n", data[5] ) ;
1818 #endif
1819 }
1820 /* data[6]: Colormap */
1821 if( mask & XIMP_PRE_COLORMAP_MASK ){
1822 data[ 6 ] = ximpClient->preedit_attributes.colormap ;
1823 #ifdef DEBUG
1824 printf( "\t\"XIMP_PRE_COLORMAP_MASK\" colormap = %ld\n",data[6] ) ;
1825 #endif
1826 }
1827 /* data[7]: BackgroundPixmap */
1828 if( mask & XIMP_PRE_BGPIXMAP_MASK ){
1829 data[ 7 ] = ximpClient->preedit_attributes.background_pixmap ;
1830 #ifdef DEBUG
1831 printf( "\t\"XIMP_PRE_BGPIXMAP_MASK\" bg_pixmap = %ld\n", data[7] ) ;
1832 #endif
1833 }
1834 /* data[8]: Line_Spacing */
1835 if( mask & XIMP_PRE_LINESP_MASK ){
1836 data[ 8 ] = ximpClient->preedit_attributes.line_spacing ;
1837 #ifdef DEBUG
1838 printf( "\t\"XIMP_PRE_LINESP_MASK\" linespacing = %ld\n",data[ 8 ] ) ;
1839 #endif
1840 }
1841 /* data[9]: Cursor */
1842 if (mask & XIMP_PRE_CURSOR_MASK) {
1843 data[ 9 ] = ximpClient->preedit_attributes.cursor ;
1844 #ifdef DEBUG
1845 printf( "\t\"XIMP_PRE_CURSOR_MASK\" cursor = %lx\n", data[9] ) ;
1846 #endif
1847 }
1848 /* data[10]-data[11]: AreaNeeded.{width,height} */
1849 if( mask & XIMP_PRE_AREANEED_MASK ){
1850 data[ 10 ] = ximpClient->preedit_attributes.needed_width ;
1851 data[ 11 ] = ximpClient->preedit_attributes.needed_height ;
1852 #ifdef DEBUG
1853 printf( "\t\"XIMP_PRE_AREANEED_MASK\" (w,h) = (%ld,%ld)\n",
1854 data[10],data[11] ) ;
1855 #endif
1856 }
1857 /* data[12]-data[13]: SpotLocation.{x,y} */
1858 if( mask & XIMP_PRE_SPOTL_MASK ){
1859 data[ 12 ] = ximpClient->preedit_attributes.spot_x ;
1860 data[ 13 ] = ximpClient->preedit_attributes.spot_y ;
1861 #ifdef DEBUG
1862 printf( "\t\"XIMP_PRE_SPOTL_MASK\" (x,y) = (%ld,%ld)\n",
1863 data[12],data[13] ) ;
1864 #endif
1865 }
1866 Ximp_setProperty
1867 ( ximpClient, w->ximp.ximp_preedit, w->ximp.ximp_preedit, 32,
1868 ( unsigned char * )data, 14 ) ;
1869 return ;
1870 }
1871
Ximp_setStatusProperty(struct XimpClient * ximpClient,unsigned long mask)1872 static void Ximp_setStatusProperty
1873 ( struct XimpClient *ximpClient, unsigned long mask )
1874 {
1875 XimpWidget w = ( XimpWidget )ximpClient->protocol_widget ;
1876 long data[ 13 ] ;
1877 #ifdef DEBUG
1878 printf( "(Ximp) SetStatusProperty( mask = %lx )\n", mask ) ;
1879 #endif
1880 /* data[0]-data[3]: Area.{x,y,width,height} */
1881 if( mask & XIMP_STS_AREA_MASK ){
1882 data[ 0 ] = ximpClient->status_attributes.area_x ;
1883 data[ 1 ] = ximpClient->status_attributes.area_y ;
1884 data[ 2 ] = ximpClient->status_attributes.area_width ;
1885 data[ 3 ] = ximpClient->status_attributes.area_height ;
1886 #ifdef DEBUG
1887 printf( "\t\"XIMP_STS_AREA_MASK\" (x,y,w,h) = (%ld,%ld,%ld,%ld)\n",
1888 data[ 0 ], data[ 1 ],data[ 2 ], data[ 3 ] ) ;
1889 #endif
1890 }
1891 /* data[4]: Foreground */
1892 if( mask & XIMP_STS_FG_MASK ){
1893 data[ 4 ] = ximpClient->status_attributes.foreground ;
1894 #ifdef DEBUG
1895 printf( "\t\"XIMP_STS_FG_MASK\" foreground = %ld\n", data[4] ) ;
1896 #endif
1897 }
1898 /* data[5]: Background */
1899 if( mask & XIMP_STS_BG_MASK ){
1900 data[ 5 ] = ximpClient->status_attributes.background ;
1901 #ifdef DEBUG
1902 printf( "\t\"XIMP_STS_BG_MASK\" background = %ld\n", data[5] ) ;
1903 #endif
1904 }
1905 /* data[6]: Colormap */
1906 if( mask & XIMP_STS_COLORMAP_MASK ){
1907 data[ 6 ] = ximpClient->status_attributes.colormap ;
1908 #ifdef DEBUG
1909 printf( "\t\"XIMP_STS_COLORMAP_MASK\" colormap = %ld\n", data[6] ) ;
1910 #endif
1911 }
1912 /* data[7]: BackgroundPixmap */
1913 if( mask & XIMP_STS_BGPIXMAP_MASK ){
1914 data[ 7 ] = ximpClient->status_attributes.background_pixmap ;
1915 #ifdef DEBUG
1916 printf( "\t\"XIMP_STS_BGPIXMAP_MASK\" bgpixmap = %ld\n", data[7] ) ;
1917 #endif
1918 }
1919 /* data[8]: Line_Spacing */
1920 if( mask & XIMP_STS_LINESP_MASK ){
1921 data[ 8 ] = ximpClient->status_attributes.line_spacing ;
1922 #ifdef DEBUG
1923 printf( "\t\"XIMP_STS_LINESP_MASK\" linespacing = %ld\n", data[8] ) ;
1924 #endif
1925 }
1926 /* data[9]: Cursor */
1927 if( mask & XIMP_STS_CURSOR_MASK ){
1928 data[ 9 ] = ximpClient->status_attributes.cursor ;
1929 }
1930 /* data[10]-data[11]: AreaNeeded.{width,height} */
1931 if( mask & XIMP_STS_AREANEED_MASK ){
1932 data[ 10 ] = ximpClient->status_attributes.needed_width ;
1933 data[ 11 ] = ximpClient->status_attributes.needed_height ;
1934 #ifdef DEBUG
1935 printf( "\t\"XIMP_STS_AREANEED_MASK\" (w,h)=(%ld,%ld)\n",
1936 data[10],data[11]) ;
1937 #endif
1938 }
1939 /* data[12]: StatusWindowID -- not suppoted by kinput2 */
1940 if( mask & XIMP_STS_WINDOW_MASK ){
1941 data[ 12 ] = ximpClient->status_window ;
1942 #ifdef DEBUG
1943 printf( "\t\"XIMP_STS_WINDOW_MASK\" window = %lx\n", data[12] ) ;
1944 #endif
1945 }
1946 Ximp_setProperty
1947 ( ximpClient, w->ximp.ximp_status,
1948 w->ximp.ximp_status, 32, ( unsigned char * )data, 13 ) ;
1949 return ;
1950 }
1951
Ximp_setProperty(struct XimpClient * ximpClient,Atom property,Atom type,int format,unsigned char * data,int nelements)1952 static void Ximp_setProperty
1953 ( struct XimpClient *ximpClient, Atom property, Atom type, int format,
1954 unsigned char *data, int nelements )
1955 {
1956 XChangeProperty
1957 ( XtDisplay( ximpClient->protocol_widget ),
1958 ximpClient->request_window, property, type, format,
1959 PropModeReplace, data, nelements ) ;
1960 return ;
1961 }
1962
1963 /*
1964 * �ݡݡݡ� �������鲼�� skkinput ��ɬ�פȤ����Ѵ�°�����Ѱդ����ꡢ
1965 * Ximp ���Ѵ�°���� skkinput ��ʬ�����Ѵ�°�����Ѵ�������
1966 * ����ؿ����¤֡��ݡݡݡ�
1967 */
1968
1969
Ximp_fillInDefaultAttributes(struct XimpClient * ximpClient)1970 static void Ximp_fillInDefaultAttributes
1971 ( struct XimpClient *ximpClient )
1972 {
1973 if( ximpClient->already_initial_setup )
1974 return ;
1975
1976 if( !( ximpClient->attribute_mask & XIMP_FOCUS_WIN_MASK ) ){
1977 ximpClient->focus_window = ximpClient->request_window ;
1978 ximpClient->focus_width = ximpClient->request_width ;
1979 ximpClient->focus_height = ximpClient->request_height ;
1980 }
1981
1982 if( !( ximpClient->attribute_mask & XIMP_PRE_FONT_MASK ) ){
1983 fontMgr_copyDefaultFontSet
1984 ( XtDisplay( ximpClient->protocol_widget ), ximpClient->fontset ) ;
1985 ximpClient->attribute_mask |= XIMP_PRE_FONT_MASK ;
1986 }
1987 if( !( ximpClient->attribute_mask & XIMP_PRE_LINESP_MASK ) ){
1988 Cardinal i ;
1989 XFontStruct *font ;
1990 int maxascent = 0, maxdescent = 0 ;
1991
1992 for( i = 0 ; i < NUMBER_OF_CHARSET ; i++ ){
1993 if( ximpClient->fontset[ i ] == NULL )
1994 continue ;
1995 if( ( font = ( ( ximpClient->fontset[ i ] )->font ) ) != NULL ){
1996 if( maxascent < font->ascent )
1997 maxascent = font->ascent ;
1998 if( maxdescent < font->descent )
1999 maxdescent = font->descent ;
2000 }
2001 }
2002 ximpClient->preedit_attributes.line_spacing =
2003 maxascent + maxdescent ;
2004 if( ximpClient->preedit_attributes.line_spacing <= 0 ){
2005 ximpClient->preedit_attributes.line_spacing = MIN_LINE_SPACING ;
2006 }
2007 }
2008 if( !( ximpClient->attribute_mask & XIMP_PRE_SPOTL_MASK ) ){
2009 ximpClient->preedit_attributes.spot_x = 0 ;
2010 ximpClient->preedit_attributes.spot_y = 0 ;
2011 }
2012 if( !( ximpClient->attribute_mask & XIMP_STS_LINESP_MASK ) ){
2013 ximpClient->status_attributes.line_spacing =
2014 ximpClient->preedit_attributes.line_spacing ;
2015 }
2016 if( !( ximpClient->attribute_mask & XIMP_STS_WINDOW_MASK ) ){
2017 ximpClient->status_window = None ;
2018 }
2019 ximpClient->already_initial_setup = True ;
2020 return ;
2021 }
2022
2023 /*
2024 * �Ѵ����饤����Ȥξ���� skkinput �� widget ���Ϥ���褦���Ѵ�����
2025 * �Τ˻Ȥ���ؿ�������
2026 */
Ximp_makeConvAttributes(struct XimpClient * ximpClient,struct ConvAttrs * attr)2027 static unsigned long Ximp_makeConvAttributes
2028 ( struct XimpClient *ximpClient, struct ConvAttrs *attr )
2029 {
2030 unsigned long mask ;
2031
2032 mask = 0L ;
2033 attr->focus_window = ximpClient->focus_window ;
2034 mask |= CAFocusWindow ;
2035
2036 if( ximpClient->style->inputStyle == WINDOW_TYPE_SEPARATE )
2037 return mask ;
2038
2039 /* ɽ���ΰ�����ꡣ*/
2040 if( ximpClient->attribute_mask & XIMP_PRE_AREA_MASK ){
2041 attr->client_area.x = ximpClient->preedit_attributes.area_x ;
2042 attr->client_area.y = ximpClient->preedit_attributes.area_y ;
2043 attr->client_area.width = ximpClient->preedit_attributes.area_width ;
2044 attr->client_area.height = ximpClient->preedit_attributes.area_height ;
2045 mask |= CAClientArea ;
2046 }
2047 /* ���ʿ����طʿ������ꤹ�롣*/
2048 if( ximpClient->attribute_mask &
2049 ( XIMP_PRE_FG_MASK | XIMP_PRE_BG_MASK ) ){
2050 attr->foreground = ximpClient->preedit_attributes.foreground ;
2051 attr->background = ximpClient->preedit_attributes.background ;
2052 mask |= CAForegroundPixel | CABackgroundPixel ;
2053 }
2054 if( ximpClient->attribute_mask & XIMP_PRE_COLORMAP_MASK ){
2055 attr->colormap = ximpClient->preedit_attributes.colormap ;
2056 mask |= CAColormap ;
2057 }
2058 #if 0
2059 /* ���Τ�Τϻפ��ä���̤�����Ǥ��롣
2060 * ��background pixmap
2061 * ��line spacing
2062 * ��cursor
2063 */
2064 #endif
2065 /* ���ơ������ΰ�����ꡣoff-the-spot �Ѵ��ξ��ˤ�ɬ�����ơ��� *
2066 * ���ΰ褬���ꤵ��Ƥ��ʤ���Фʤ�ʤ���*/
2067 if( ximpClient->attribute_mask & XIMP_STS_AREA_MASK ){
2068 attr->status_area.x = ximpClient->status_attributes.area_x ;
2069 attr->status_area.y = ximpClient->status_attributes.area_y ;
2070 attr->status_area.width = ximpClient->status_attributes.area_width ;
2071 attr->status_area.height = ximpClient->status_attributes.area_height ;
2072 mask |= CAStatusArea ;
2073 #if defined(DEBUG)
2074 } else {
2075 if( ximpClient->style->inputStyle == WINDOW_TYPE_OFFTHESPOT ){
2076 fprintf( stderr, "off-the-spot window style needs status area.\n" ) ;
2077 }
2078 #endif
2079 }
2080 /* �ե���Ȥ����ꤵ��Ƥ������ν�����ɬ���ǤϤʤ���̵����С�����*
2081 * ���Ǿ���˥ǥե���ȤΥե���Ȥ����Ѥ��Ƥ��ޤ���*/
2082 if( ximpClient->attribute_mask & XIMP_PRE_FONT_MASK ){
2083 attr->fontset = ximpClient->fontset ;
2084 mask |= CAFonts ;
2085 }
2086 /* over-the-spot �Ѵ��ʤ�С��ɤΰ��֤˸��ߥ������뤬���뤫�λ��� *
2087 * �뤳�Ȥ�Ǥ���Ĥ���ʤ��Ƥ����ߤ������ɡġ�*/
2088 if( ximpClient->style->inputStyle == WINDOW_TYPE_OVERTHESPOT &&
2089 ximpClient->attribute_mask & XIMP_PRE_SPOTL_MASK ){
2090 attr->spot_x = ximpClient->preedit_attributes.spot_x ;
2091 attr->spot_y = ximpClient->preedit_attributes.spot_y ;
2092 mask |= CASpotLocation ;
2093 }
2094 return mask ;
2095 }
2096
2097 /*
2098 *�ݡݡݡ� �������鲼�� X �Υ�å�����(���٥��)������(send)�ط� �ݡݡݡ�
2099 */
2100
2101 #if 0
2102 /*
2103 *
2104 */
2105 static int Ximp_sendClientMessage8
2106 ( struct XimpClient *ximpClient, unsigned char *string, int length )
2107 {
2108 XimpWidget w = ( XimpWidget )ximpClient->protocol_widget ;
2109 XEvent xevent ;
2110
2111 xevent.xclient.type = ClientMessage;
2112 xevent.xclient.window = ximpClient->focus_window ;
2113 xevent.xclient.message_type = w->ximp.ximp_protocol ;
2114 xevent.xclient.format = 8 ;
2115
2116 /* �ɤ���� ID ������ä��Ϥ��Ƥ���ߤ�����*/
2117 xevent.xclient.data.b[ 0 ] = ( ximpClient->id >> 24 ) & 0xff ;
2118 xevent.xclient.data.b[ 1 ] = ( ximpClient->id >> 16 ) & 0xff ;
2119 xevent.xclient.data.b[ 2 ] = ( ximpClient->id >> 8 ) & 0xff ;
2120 xevent.xclient.data.b[ 3 ] = ( ximpClient->id ) & 0xff ;
2121 xevent.xclient.data.b[ 4 ] = length ;
2122
2123 /* �ۤ��� ����Ϥɤ��������ȡ� */
2124 strncpy( &xevent.xclient.data.b[ 5 ], string, 20 - 5 ) ;
2125
2126 return XSendEvent
2127 ( XtDisplay( ( Widget )w ), ximpClient->focus_window,
2128 False, NoEventMask, &xevent ) ;
2129 }
2130 #endif
2131
2132 /*
2133 * �Ѵ����饤����Ȥ˥�å�����������Τ����Ѥ����ؿ���
2134 */
Ximp_sendClientMessage32(struct XimpClient * ximpClient,int type,unsigned long l1,unsigned long l2,unsigned long l3,unsigned long l4)2135 static int Ximp_sendClientMessage32
2136 ( struct XimpClient *ximpClient, int type,
2137 unsigned long l1, unsigned long l2,
2138 unsigned long l3, unsigned long l4 )
2139 {
2140 XimpWidget w = ( XimpWidget )ximpClient->protocol_widget ;
2141 XEvent event ;
2142
2143 event.xclient.type = ClientMessage ;
2144 event.xclient.window = ximpClient->focus_window ;
2145 event.xclient.message_type = w->ximp.ximp_protocol ;
2146 event.xclient.format = 32 ;
2147 event.xclient.data.l[ 0 ] = type ;
2148 event.xclient.data.l[ 1 ] = l1 ;
2149 event.xclient.data.l[ 2 ] = l2 ;
2150 event.xclient.data.l[ 3 ] = l3 ;
2151 event.xclient.data.l[ 4 ] = l4 ;
2152
2153 return ( int )XSendEvent
2154 ( XtDisplay( ( Widget )w ), ximpClient->focus_window,
2155 False, NoEventMask, &event ) ;
2156 }
2157
2158 /*
2159 * ���顼��ȯ���������Ȥ��Ѵ����饤����Ȥ�������ؿ���
2160 */
Ximp_sendErrorEvent(struct XimpClient * ximpClient,int errorno)2161 static void Ximp_sendErrorEvent
2162 ( struct XimpClient *ximpClient, int errorno )
2163 {
2164 Ximp_sendClientMessage32
2165 ( ximpClient, XIMP_ERROR, ximpClient->id,
2166 ximpClient->xevent.serial, ( unsigned long )errorno, 0L ) ;
2167 return ;
2168 }
2169
2170 /*
2171 * �Ѵ����饤����Ȥ˽����Ǥ��ʤ��Ȥ������Ȥ��֤��ؿ���
2172 */
Ximp_rejectCreateMessage(Widget gw,Window win)2173 static void Ximp_rejectCreateMessage( Widget gw, Window win )
2174 {
2175 XimpWidget w = ( XimpWidget )gw ;
2176 XEvent xevent ;
2177
2178 xevent.xclient.type = ClientMessage ;
2179 xevent.xclient.window = win ;
2180 xevent.xclient.message_type = w->ximp.ximp_protocol ;
2181 xevent.xclient.format = 32 ;
2182 xevent.xclient.data.l[0] = XIMP_CREATE_RETURN ;
2183 xevent.xclient.data.l[1] = 0L ;
2184 xevent.xclient.data.l[2] = 0L ;
2185 xevent.xclient.data.l[3] = 0L ;
2186 xevent.xclient.data.l[4] = 0L ;
2187
2188 XSendEvent
2189 ( XtDisplay( gw ), win, False, NoEventMask, &xevent ) ;
2190 return ;
2191 }
2192
2193
2194 /*
2195 * �ݡݡݡ� �������鲼�ϣإ��٥�Ȥν����ؿ����ݡݡݡݡݡ�
2196 */
2197
2198
2199 /*
2200 * �Ѵ����饤����Ȥ��������Ƥ�����å��������������ؿ���
2201 *----
2202 * ����˥�å������Ȥ����������Υ�å������ˤϡ�
2203 * ���Ѵ����ϤΤ����ͽ��
2204 * ���Ѵ������ᡣ
2205 * ���Ѵ���λ�ᡣ
2206 * �ʤɤ��ޤޤ�Ƥ��롣kinput2 protocol �Ǹ�����
2207 * CONVERSION_REQUEST, CONVERSION_CLOSE �ʤ����äƤ���ΤǤ��롣
2208 */
Ximp_conversionMessageEventHandler(Widget gw,XEvent * xevent,String * args,Cardinal * num_of_args)2209 static void Ximp_conversionMessageEventHandler
2210 ( Widget gw, XEvent *xevent, String *args, Cardinal *num_of_args )
2211 {
2212 XClientMessageEvent *xclme = &( xevent->xclient ) ;
2213 struct XimpClient *ximpClient = NULL ;
2214
2215 #ifdef DEBUG
2216 printf( "[Ximp] Conversion message recieved :" ) ;
2217 #endif
2218 /*
2219 * �ޤ���������å������Ǥ��뤫�ɤ�����Ĵ�٤롣
2220 */
2221 if( !Ximp_isCorrectConversionMessage( gw, xevent ) ){
2222 return ;
2223 }
2224 /*
2225 * �ɤΤ褦�ʥ�å������Ǥ��뤫�ơ����ν����ؿ��ذ����Ϥ���
2226 */
2227 #ifdef DEBUG
2228 printf( "(%ld).\n", xclme->data.l[ 0 ] ) ;
2229 {
2230 ximpClient = Ximp_findClient
2231 ( gw, ( unsigned long )xclme->data.l[ 1 ] ) ;
2232 if( ximpClient != NULL ){
2233 printf( "[%ld] -----> xmask = %lx\n",
2234 xclme->data.l[1], ximpClient->attribute_mask ) ;
2235 }
2236 }
2237 #endif
2238 switch( ( unsigned long )xclme->data.l[ 0 ] ){
2239 case XIMP_CREATE :
2240 Ximp_createMessageHandler( gw, xclme ) ;
2241 break ;
2242 case XIMP_DESTROY :
2243 Ximp_destroyMessageHandler( gw, xclme ) ;
2244 break ;
2245 case XIMP_BEGIN :
2246 Ximp_beginMessageHandler( gw, xclme ) ;
2247 break ;
2248 case XIMP_END :
2249 Ximp_endMessageHandler( gw, xclme ) ;
2250 break ;
2251 case XIMP_SETFOCUS :
2252 Ximp_setFocusMessageHandler( gw, xclme ) ;
2253 break ;
2254 case XIMP_UNSETFOCUS :
2255 Ximp_unsetFocusMessageHandler( gw, xclme ) ;
2256 break ;
2257 case XIMP_KEYPRESS :
2258 Ximp_keypressMessageHandler( gw, xclme ) ;
2259 break ;
2260 case XIMP_SETVALUE :
2261 Ximp_setvalueMessageHandler( gw, xclme ) ;
2262 break ;
2263 case XIMP_CHANGE :
2264 Ximp_changeMessageHandler( gw, xclme ) ;
2265 break ;
2266 case XIMP_GETVALUE :
2267 Ximp_getValueMessageHandler( gw, xclme ) ;
2268 break ;
2269 case XIMP_MOVE :
2270 Ximp_moveMessageHandler( gw, xclme ) ;
2271 break ;
2272 case XIMP_RESET :
2273 Ximp_resetMessageHandler( gw, xclme ) ;
2274 break ;
2275 case XIMP_EXTENSION :
2276 Ximp_extensionMessageHandler( gw, xclme ) ;
2277 break ;
2278 default :
2279 /* �⤷����ʳ��Υ�å���������Ƥ����顢���顼�ˤʤäƤ��ޤ���*/
2280 ximpClient = Ximp_findClient
2281 ( gw, ( unsigned long )xclme->data.l[ 1 ] ) ;
2282 if( ximpClient != NULL ){
2283 ximpClient->xevent = *xclme ;
2284 Ximp_sendErrorEvent( ximpClient, XIMP_BadProtocol ) ;
2285 }
2286 break ;
2287 }
2288 #ifdef DEBUG
2289 if( ximpClient != NULL ){
2290 printf( "<-------- xmask = %lx\n",
2291 ximpClient->attribute_mask ) ;
2292 }
2293 #endif
2294 return ;
2295 }
2296
Ximp_SelectionRequestEventHandler(Widget gw,XEvent * xevent,String * params,Cardinal * num_params)2297 static void Ximp_SelectionRequestEventHandler
2298 ( Widget gw, XEvent *xevent, String *params, Cardinal *num_params )
2299 {
2300 XSelectionRequestEvent *xsrev = &( xevent->xselectionrequest ) ;
2301 XEvent xev ;
2302
2303 xev.xselection.type = SelectionNotify ;
2304 xev.xselection.requestor = xsrev->requestor ;
2305 xev.xselection.selection = xsrev->selection ;
2306 xev.xselection.target = xsrev->target ;
2307 xev.xselection.property = None ;
2308 xev.xselection.time = xsrev->time ;
2309
2310 XSendEvent
2311 ( xsrev->display, xsrev->requestor, False, NoEventMask, &xev ) ;
2312 return ;
2313 }
2314
2315 /*
2316 * �Ѵ������Ф��븢�¤ä����ν�����Ԥ��ؿ���
2317 */
Ximp_SelectionClearEventHandler(Widget gw,XEvent * xevent,String * params,Cardinal * num_params)2318 static void Ximp_SelectionClearEventHandler
2319 ( Widget gw, XEvent *xevent, String *params, Cardinal *num_params )
2320 {
2321 /* ��ʬ���Ȥ��˲����ƽ�λ���롣���λ�����ʬ���Ȥ����äƤ��������� *
2322 * �Хå��������˴����ʤ���Фʤ�ʤ����ɡġ� */
2323 #ifdef DEBUG
2324 fprintf( stderr, "(Ximp)Selection Lost....\n" ) ;
2325 #endif
2326 XtDestroyWidget( gw ) ;
2327 return ;
2328 }
2329
2330 /*
2331 * �ݡݡ� �������鲼�ϥ�����Хå��ؿ����ݡݡݡ�
2332 */
Ximp_SendMessageToRequestorCallback(Widget gw,caddr_t client,caddr_t caller)2333 static void Ximp_SendMessageToRequestorCallback
2334 ( Widget gw, caddr_t client, caddr_t caller )
2335 {
2336 struct XimpClient *ximpClient = ( struct XimpClient * )client ;
2337 XimpWidget w = ( XimpWidget )ximpClient->protocol_widget ;
2338 struct myChar *text = ( struct myChar * )caller ;
2339 Atom proptype ;
2340 int propsize ;
2341 int propformat ;
2342 caddr_t propvalue ;
2343 struct myChar *wptr ;
2344
2345 /*
2346 * ���������ɤǻ��äƤ���ƥ����Ȥ� Compound Text �ؤ��Ѵ����롣
2347 */
2348 for( wptr = text ; !IS_END_OF_STRING( *wptr ) ; wptr ++ )
2349 if( IS_ASCII_EQUAL( *wptr, '\r' ) )
2350 wptr->chara = '\n' ;
2351 proptype = w->ximp.compound_text ;
2352 propformat = 8 ;
2353 propsize = string2ctext( text, NULL ) ;
2354 if ( propsize <= 0 )
2355 return ;
2356 propvalue =
2357 ( caddr_t )malloc( propsize * sizeof( unsigned char ) * 4 ) ;
2358 string2ctext( text, ( unsigned char * )propvalue ) ;
2359
2360 XChangeProperty
2361 ( XtDisplay( ( Widget )w ), XtWindow( ( Widget )w ),
2362 ximpClient->property, proptype, propformat,
2363 PropModeAppend, propvalue, propsize ) ;
2364 if( !ximpClient->resetting ){
2365 Ximp_sendClientMessage32
2366 ( ximpClient, XIMP_READPROP,
2367 ximpClient->id, ximpClient->property, 0L, 0L ) ;
2368 }
2369 free( propvalue ) ;
2370 return ;
2371 }
2372
Ximp_EndOfConversionMain(struct XimpClient * ximpClient)2373 static int Ximp_EndOfConversionMain( struct XimpClient *ximpClient )
2374 {
2375 /* ��λ���Τ����롣���������Ƥ� DestroyNotify �ˤ�ä��˲�����Ƥ� *
2376 * ����ˤ����ƤϤ��θ¤�ǤϤʤ������ξ��ˤ� req_window == *
2377 * None �ȤʤäƤ��롣*/
2378 if( ximpClient->focus_window != None ){
2379 /* ���饤����Ȥ˽�λ���Τ����롣*/
2380 Ximp_sendClientMessage32
2381 ( ximpClient, XIMP_PROCESS_END, ximpClient->id, 0L, 0L, 0L ) ;
2382 remove_myeventhandler
2383 ( XtDisplay( ximpClient->protocol_widget ),
2384 ximpClient->focus_window,
2385 KeyPress, KeyPressMask ) ;
2386 remove_myeventhandler
2387 ( XtDisplay( ximpClient->protocol_widget ),
2388 ximpClient->focus_window,
2389 KeyRelease, KeyReleaseMask ) ;
2390 } else {
2391 if( ( ximpClient->focus_window = ximpClient->request_window ) != None )
2392 Ximp_sendClientMessage32
2393 ( ximpClient, XIMP_END, ximpClient->id, 0L, 0L, 0L ) ;
2394 }
2395 /* InputOnly ���ä����ˤϡ�Ʃ�����뤬����Ƥ���Ȧ�ʤΤǡ������ */
2396 /* �ä��Ƥ�����*/
2397 if( ximpClient->probe_window != None ){
2398 remove_allmyeventhandler
2399 ( XtDisplay( ximpClient->protocol_widget ),
2400 ximpClient->probe_window ) ;
2401 XSafeDestroyWindow
2402 ( XtDisplay( ximpClient->protocol_widget ), ximpClient->probe_window ) ;
2403 ximpClient->probe_window = None ;
2404 }
2405 /* ʸ������Ѵ���Ԥ�����Ĥ������callback���˴���*/
2406 XtRemoveAllCallbacks( ximpClient->skkinput, XtNfixNotify ) ;
2407 /* �Ѵ���Ԥ��Ѵ��ν�λ�����Τ������callback���˴���*/
2408 XtRemoveAllCallbacks( ximpClient->skkinput, XtNendNotify ) ;
2409 /* �������Ϥ饤����ȥ�����ɥ��ؤ����� callback ���˴���*/
2410 XtRemoveAllCallbacks( ximpClient->skkinput, XtNkeybackNotify ) ;
2411
2412 /* �Ĥ������˥��٥�ȥ��塼��ե�å��夷�Ƥ�����*/
2413 XSafeFlush( XtDisplay( ximpClient->protocol_widget ) ) ;
2414 ximpClient->skkinput = NULL ;
2415 return 0 ;
2416 }
2417
2418 /*
2419 * skkinput �뤬�Ĥ�����˥�����¦�˽�λ�����Τ��뤿��˸ƤӽФ����ؿ���
2420 *(������Хå�)
2421 */
Ximp_EndMessageToRequestorCallback(Widget gw,caddr_t client,caddr_t caller)2422 static void Ximp_EndMessageToRequestorCallback
2423 ( Widget gw, caddr_t client, caddr_t caller )
2424 {
2425 struct XimpClient *ximpClient = ( struct XimpClient * )client ;
2426 /* history ���������٤����ݤ���*/
2427 if( caller != NULL )
2428 history_close( XtDisplay( ximpClient->protocol_widget ), caller ) ;
2429 /* ��λ���롣*/
2430 Ximp_EndOfConversionMain( ximpClient ) ;
2431 /* �Ѵ����饤����ȥꥹ�Ȥ��������ƤϤʤ�ʤ������Τʤ� END ���Ƥ� *
2432 * BEGIN ���뤫��Ǥ��롣���� CREATE ����뤳�ȤϤʤ��� */
2433 if( ximpClient->to_destroy ){
2434 Ximp_freeClient( ximpClient ) ;
2435 }
2436 return ;
2437 }
2438
Ximp_KeyEventToRequestorCallback(Widget gw,caddr_t client,caddr_t caller)2439 static void Ximp_KeyEventToRequestorCallback
2440 ( Widget gw, caddr_t client, caddr_t caller )
2441 {
2442 struct XimpClient *ximpClient = ( struct XimpClient * )client ;
2443 XKeyEvent *xkey = ( XKeyEvent * )caller ;
2444
2445 Ximp_sendClientMessage32
2446 ( ximpClient, XIMP_KEYPRESS, ximpClient->id,
2447 ( unsigned long )xkey->keycode, ( unsigned long )xkey->state, 0L ) ;
2448 return ;
2449 }
2450
2451 /*
2452 * ����¾���Ѵ����饤����Ȥ����ˤĤ��ơ�
2453 */
2454
Ximp_createClient(Widget gw,Window requestor,XimpInputStyle * xis)2455 static struct XimpClient *Ximp_createClient
2456 ( Widget gw, Window requestor, XimpInputStyle *xis )
2457 {
2458 XimpWidget w = ( XimpWidget )gw ;
2459 struct XimpClient *ximpClient ;
2460 unsigned char buffer[ 25 ] ;
2461 int i ;
2462
2463 if( ( ximpClient = malloc( sizeof( struct XimpClient ) ) ) == NULL )
2464 return NULL ;
2465
2466 sprintf( buffer, "_XIMP_STRING_%ld", w->ximp.property_id ++ ) ;
2467 ximpClient->property = XInternAtom( XtDisplay( gw ), buffer, False ) ;
2468
2469 ximpClient->id = w->ximp.icid ++ ;
2470 ximpClient->request_window = requestor ;
2471 ximpClient->focus_window = requestor ;
2472 ximpClient->probe_window = None ;
2473 ximpClient->style = xis ;
2474 ximpClient->protocol_widget = gw ;
2475 ximpClient->skkinput = NULL ;
2476 ximpClient->event_capture_method = EVENT_HA_FOCUS_KARA ;
2477 ximpClient->resetting = False ;
2478 ximpClient->to_destroy = False ;
2479 ximpClient->already_initial_setup = False ;
2480 ximpClient->attribute_mask = 0L ;
2481 ximpClient->client_version = NULL ;
2482 ximpClient->xevent.window = None ;
2483 ximpClient->resetting = False ;
2484
2485 ximpClient->preedit_attributes.fontlist = NULL ;
2486 ximpClient->status_attributes.fontlist = NULL ;
2487
2488 /* fontset �ν������Ԥ���*/
2489 for( i = 0 ; i < NUMBER_OF_CHARSET ; i ++ ){
2490 ximpClient->fontset[ i ] = NULL ;
2491 }
2492 ximpClient->next = w->ximp.client_list ;
2493 w->ximp.client_list = ximpClient ;
2494 return ximpClient ;
2495 }
2496
2497 /*
2498 * �Ѵ����饤����Ȥλ��ģɣĤ��饯�饤����Ȥ��ܤ��ؿ���
2499 */
Ximp_findClient(Widget gw,unsigned long id)2500 static struct XimpClient *Ximp_findClient
2501 ( Widget gw, unsigned long id )
2502 {
2503 XimpWidget w = ( XimpWidget )gw ;
2504 struct XimpClient *ximpClient ;
2505
2506 ximpClient = w->ximp.client_list ;
2507 while( ximpClient != NULL ){
2508 if( ximpClient->id == id )
2509 break ;
2510 ximpClient = ximpClient->next ;
2511 }
2512 return ximpClient ;
2513 }
2514
2515 #if 0
2516 /*
2517 * ������ɥ��ɣĤ����Ѵ����饤����Ȥ��ܤ��ؿ���
2518 */
2519 static struct XimpClient *Ximp_findClientWithWindowID
2520 ( Widget gw, Window win )
2521 {
2522 XimpWidget w = ( XimpWidget )gw ;
2523 struct XimpClient *ximpClient ;
2524
2525 ximpClient = w->ximp.client_list ;
2526 while( ximpClient != NULL ){
2527 if( ximpClient->request_window == win ||
2528 ximpClient->focus_window == win )
2529 break ;
2530 ximpClient = ximpClient->next ;
2531 }
2532 return ximpClient ;
2533 }
2534 #endif
2535
2536 /*
2537 * �Ѵ����饤����Ȥ�������Ƥ���ǡ����ΰ���˴�����ؿ���
2538 */
Ximp_destroyClient(struct XimpClient * ximpClient)2539 static void Ximp_destroyClient( struct XimpClient *ximpClient )
2540 {
2541 Ximp_unlinkClient( ximpClient ) ;
2542 Ximp_freeClient( ximpClient ) ;
2543 return ;
2544 }
2545
Ximp_unlinkClient(struct XimpClient * ximpClient)2546 static void Ximp_unlinkClient( struct XimpClient *ximpClient )
2547 {
2548 XimpWidget w = ( XimpWidget )ximpClient->protocol_widget ;
2549 struct XimpClient *node = w->ximp.client_list ;
2550
2551 /* ������������Ƥ��ޤä��Τʤ顢�ꥹ�Ȥ��餳�ä��Ǿʤ��ʤ���Фʤ�ʤ���*/
2552 if( node == ximpClient ){
2553 w->ximp.client_list = ximpClient->next ;
2554 } else {
2555 while( node->next != ximpClient )
2556 node = node->next ;
2557 node->next = ximpClient->next ;
2558 }
2559 ximpClient->next = NULL ;
2560
2561 return ;
2562 }
2563
Ximp_freeClient(struct XimpClient * ximpClient)2564 static void Ximp_freeClient( struct XimpClient *ximpClient )
2565 {
2566 XimpWidget w = ( XimpWidget )ximpClient->protocol_widget ;
2567 int i ;
2568
2569 /* �ե���Ȥ�������롣*/
2570 for( i = 0 ; i < NUMBER_OF_CHARSET ; i ++ ){
2571 fontMgr_FreeFont
2572 ( XtDisplay( ( Widget )w ), ximpClient->fontset[ i ] ) ;
2573 ximpClient->fontset[ i ] = NULL ;
2574 }
2575 /* �ե����̾��������롣*/
2576 if( ximpClient->preedit_attributes.fontlist != NULL )
2577 XFree( ximpClient->preedit_attributes.fontlist ) ;
2578 if( ximpClient->status_attributes.fontlist != NULL )
2579 XFree( ximpClient->status_attributes.fontlist ) ;
2580 /* ���饤����ȤΥС����������������롣*/
2581 if( ximpClient->client_version != NULL )
2582 XFree( ximpClient->client_version ) ;
2583 free( ximpClient ) ;
2584 return ;
2585 }
2586
Ximp_ChangeFocusWindow(struct XimpClient * ximpClient,Window focus_window)2587 static void Ximp_ChangeFocusWindow
2588 ( struct XimpClient *ximpClient, Window focus_window )
2589 {
2590 Window probe ;
2591
2592 if( ( ximpClient->event_capture_method != EVENT_HA_INPUTONLY &&
2593 ximpClient->event_capture_method != EVENT_HA_FOCUS_KARA ) ||
2594 focus_window == None ||
2595 focus_window == ximpClient->focus_window )
2596 return ;
2597
2598 if( ximpClient->event_capture_method == EVENT_HA_INPUTONLY ){
2599 if( ximpClient->probe_window != None ){
2600 remove_myeventhandler
2601 ( XtDisplay( ximpClient->protocol_widget ),
2602 ximpClient->probe_window,
2603 KeyPress, KeyPressMask ) ;
2604 remove_myeventhandler
2605 ( XtDisplay( ximpClient->protocol_widget ),
2606 ximpClient->probe_window,
2607 KeyRelease, KeyReleaseMask ) ;
2608 XSafeDestroyWindow
2609 ( XtDisplay( ximpClient->protocol_widget ),
2610 ximpClient->probe_window ) ;
2611 ximpClient->probe_window = None ;
2612 }
2613 probe = XCreateWindow
2614 ( XtDisplay( ximpClient->protocol_widget ),
2615 focus_window, 0, 0, 9999, 9999, 0, 0,
2616 InputOnly, (Visual *)CopyFromParent,
2617 0L, (XSetWindowAttributes *)NULL ) ;
2618 ximpClient->probe_window = probe ;
2619 XMapWindow( XtDisplay( ximpClient->protocol_widget ), probe ) ;
2620 } else {
2621 if( ximpClient->focus_window != None ){
2622 remove_myeventhandler
2623 ( XtDisplay( ximpClient->protocol_widget ),
2624 ximpClient->focus_window,
2625 KeyPress, KeyPressMask ) ;
2626 remove_myeventhandler
2627 ( XtDisplay( ximpClient->protocol_widget ),
2628 ximpClient->focus_window,
2629 KeyRelease, KeyReleaseMask ) ;
2630 }
2631 probe = focus_window ;
2632 }
2633 add_myeventhandler
2634 ( XtDisplay( ximpClient->protocol_widget ), probe,
2635 XtWindow( ximpClient->skkinput ), KeyPress, KeyPressMask ) ;
2636 add_myeventhandler
2637 ( XtDisplay( ximpClient->protocol_widget ), probe,
2638 XtWindow( ximpClient->skkinput ), KeyRelease, KeyReleaseMask ) ;
2639 return ;
2640 }
2641