1 /* # skkinput (Simple Kana-Kanji Input)
2  *
3  * This file is part of skkinput.
4  * Copyright (C) 2002
5  * Takashi SAKAMOTO (PXG01715@nifty.ne.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 /*
22  *	on-demand-synchronous-mode ��ư��뤳�Ȥ��ꤷ�Ƥ��롣
23  */
24 #include "AfxWin.h"
25 #include "local.h"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <sys/types.h>
29 #include <X11/X.h>
30 #include <X11/Xlib.h>
31 #if defined (__SVR4) && defined (__sun)
32 #include <X11/Xlibint.h>
33 #endif
34 #include <X11/Xatom.h>
35 #include <X11/IntrinsicP.h>
36 #include <X11/StringDefs.h>
37 #include <X11/Shell.h>
38 #include <X11/keysym.h>
39 //#include "skkinput.h"
40 #include "XIMClientP.h"
41 #include "XIMServer.h"
42 #include "XIMInputContext.h"
43 #include "XIMInputMethod.h"
44 #include "XIMData.h"
45 #include "dispatch.h"
46 #include "kanji.h"
47 
48 #define	SKKIME_SEE_ENCODING_NEGOTIATION_DETAIL	(1)
49 
50 typedef struct tagXIMAttribute {
51 	const char*		m_pName ;
52 	unsigned int	m_uValueType ;
53 	Boolean			m_fEnableCreate ;
54 	Boolean			m_fEnableNormal ;
55 	Boolean			(*m_pSetter)(Widget, XIMInputMethod*, XIMInputContext*, XIMData*, int, int) ;
56 	Boolean			(*m_pGetter)(Widget, XIMInputMethod*, XIMInputContext*, XIMData*, int*, int, XIMPacket*) ;
57 }	XIMAttribute ;
58 
59 typedef struct tagXIMCodingSystem {
60 	const char*		m_pEncodingName ;
61 	int				m_nCodingSystem ;
62 }	XIMCodingSystem ;
63 
64 /* ///////////////////////////////////////////////////////////////////////
65  */
66 
67 #define	DEFGETTER(name)	static Boolean name(Widget, XIMInputMethod*, XIMInputContext*, XIMData*, int*, int, XIMPacket*)
68 #define	DEFSETTER(name)	static Boolean name(Widget, XIMInputMethod*, XIMInputContext*, XIMData*, int, int)
69 DEFGETTER (ximClient_getImValueQueryInputStyle) ;
70 DEFGETTER (ximClient_getIcValueInputStyle) ;
71 DEFGETTER (ximClient_getIcValueClientWindow) ;
72 DEFGETTER (ximClient_getIcValueFocusWindow) ;
73 DEFGETTER (ximClient_getIcValueResetState) ;
74 DEFGETTER (ximClient_getIcValueFilterEvents) ;
75 DEFGETTER (ximClient_getIcValuePreeditState) ;
76 DEFGETTER (ximClient_getIcValuePreeditAttributes) ;
77 DEFGETTER (ximClient_getIcValueStatusAttributes) ;
78 DEFGETTER (ximClient_getIcValueArea) ;
79 DEFGETTER (ximClient_getIcValueAreaNeeded) ;
80 DEFGETTER (ximClient_getIcValueSpotLocation) ;
81 DEFGETTER (ximClient_getIcValueColormap) ;
82 DEFGETTER (ximClient_getIcValueStdColormap) ;
83 DEFGETTER (ximClient_getIcValueForeground) ;
84 DEFGETTER (ximClient_getIcValueBackground) ;
85 DEFGETTER (ximClient_getIcValueBackgroundPixmap) ;
86 DEFGETTER (ximClient_getIcValueLineSpacing) ;
87 DEFGETTER (ximClient_getIcValueCursor) ;
88 DEFGETTER (ximClient_getIcValueFontSet) ;
89 #if defined (not_yet)
90 DEFGETTER (ximClient_getIcValueHotKey) ;
91 DEFGETTER (ximClient_getIcValueHotKeyState) ;
92 #endif
93 
94 DEFSETTER (ximClient_setIcValueInputStyle) ;
95 DEFSETTER (ximClient_setIcValueClientWindow) ;
96 DEFSETTER (ximClient_setIcValueFocusWindow) ;
97 DEFSETTER (ximClient_setIcValueResetState) ;
98 DEFSETTER (ximClient_setIcValuePreeditState) ;
99 DEFSETTER (ximClient_setIcValuePreeditAttributes) ;
100 DEFSETTER (ximClient_setIcValueStatusAttributes) ;
101 DEFSETTER (ximClient_setIcValueArea) ;
102 DEFSETTER (ximClient_setIcValueAreaNeeded) ;
103 DEFSETTER (ximClient_setIcValueSpotLocation) ;
104 DEFSETTER (ximClient_setIcValueColormap) ;
105 DEFSETTER (ximClient_setIcValueStdColormap) ;
106 DEFSETTER (ximClient_setIcValueForeground) ;
107 DEFSETTER (ximClient_setIcValueBackground) ;
108 DEFSETTER (ximClient_setIcValueBackgroundPixmap) ;
109 DEFSETTER (ximClient_setIcValueFontSet) ;
110 DEFSETTER (ximClient_setIcValueLineSpacing) ;
111 DEFSETTER (ximClient_setIcValueCursor) ;
112 #if defined (not_yet)
113 DEFSETTER (ximClient_setIcValueHotKey) ;
114 DEFSETTER (ximClient_setIcValueHotKeyState) ;
115 #endif
116 #undef	DEFGETTER
117 #undef	DEFSETTER
118 
119 static	XIMAttribute	srSupportedInputMethodAttributes []	= {
120 	{	XNQueryInputStyle,		XIM_VALUE_TYPE_XIMSTYLES,	 False,	False,
121 		NULL,					ximClient_getImValueQueryInputStyle, },
122 } ;
123 
124 enum {
125 	XIM_ATTRIBUTEID_QUERYINPUTSTYLE	= 0,
126 	MAX_NUMBER_OF_XIM_ATTRIBUTEID,
127 } ;
128 
129 static	XIMAttribute	srSupportedInputContextAttributes []	= {
130 	{	XNInputStyle,			XIM_VALUE_TYPE_LONG,
131 		True,					False,
132 		ximClient_setIcValueInputStyle,
133 		ximClient_getIcValueInputStyle,	},
134 	{	XNClientWindow, 		XIM_VALUE_TYPE_WINDOW,
135 		True,					True,
136 		ximClient_setIcValueClientWindow,
137 		ximClient_getIcValueClientWindow, },
138 	{	XNFocusWindow, 			XIM_VALUE_TYPE_WINDOW,
139 		True,					True,
140 		ximClient_setIcValueFocusWindow,
141 		ximClient_getIcValueFocusWindow, },
142 	{	XNFilterEvents, 		XIM_VALUE_TYPE_LONG,
143 		False,					False,
144 		0,
145 		ximClient_getIcValueFilterEvents, },
146 	{	XNResetState,			XIM_VALUE_TYPE_XIMRESETSTATE,
147 		True,					True,
148 		ximClient_setIcValueResetState,
149 		ximClient_getIcValueResetState, },
150 	{	XNPreeditState,			XIM_VALUE_TYPE_XIMPREEDITSTATE,
151 		True,					True,
152 		ximClient_setIcValuePreeditState,
153 		ximClient_getIcValuePreeditState, },
154 	{	XNPreeditAttributes, 	XIM_VALUE_TYPE_NESTEDLIST,
155 		True,					True,
156 		ximClient_setIcValuePreeditAttributes,
157 		ximClient_getIcValuePreeditAttributes, },
158 	{	XNStatusAttributes,		XIM_VALUE_TYPE_NESTEDLIST,
159 		True,					True,
160 		ximClient_setIcValueStatusAttributes,
161 		ximClient_getIcValueStatusAttributes, },
162 	{	XNArea,					XIM_VALUE_TYPE_XRECTANGLE,
163 		True,					True,
164 		ximClient_setIcValueArea,
165 		ximClient_getIcValueArea, },
166 	{	XNAreaNeeded,			XIM_VALUE_TYPE_XRECTANGLE,
167 		True,					True,
168 		ximClient_setIcValueAreaNeeded,
169 		ximClient_getIcValueAreaNeeded, },
170 	{	XNSpotLocation,			XIM_VALUE_TYPE_XPOINT,
171 		True,					True,
172 		ximClient_setIcValueSpotLocation,
173 		ximClient_getIcValueSpotLocation, },
174 	{	XNColormap,				XIM_VALUE_TYPE_LONG,
175 		True,					True,
176 		ximClient_setIcValueColormap,
177 		ximClient_getIcValueColormap, },
178 	{	XNStdColormap,			XIM_VALUE_TYPE_LONG,
179 		True,					True,
180 		ximClient_setIcValueStdColormap,
181 		ximClient_getIcValueStdColormap, },
182 	{	XNForeground,			XIM_VALUE_TYPE_LONG,
183 		True,					True,
184 		ximClient_setIcValueForeground,
185 		ximClient_getIcValueForeground, },
186 	{	XNBackground,			XIM_VALUE_TYPE_LONG,
187 		True,					True,
188 		ximClient_setIcValueBackground,
189 		ximClient_getIcValueBackground, },
190 	{	XNBackgroundPixmap,		XIM_VALUE_TYPE_LONG,
191 		True,					True,
192 		ximClient_setIcValueBackgroundPixmap,
193 		ximClient_getIcValueBackgroundPixmap, },
194 	{	XNFontSet,			XIM_VALUE_TYPE_XFONTSET,
195 		True,					True,
196 		ximClient_setIcValueFontSet,
197 		ximClient_getIcValueFontSet, },
198 	{	XNLineSpace,			XIM_VALUE_TYPE_LONG,
199 		True,					True,
200 		ximClient_setIcValueLineSpacing,
201 		ximClient_getIcValueLineSpacing, },
202 	{	XNCursor,				XIM_VALUE_TYPE_LONG,
203 		True,					True,
204 		ximClient_setIcValueCursor,
205 		ximClient_getIcValueCursor, },
206 	{	XNSeparatorofNestedList,	XIM_VALUE_TYPE_SEPARATOR,
207 		False,					False,
208 		NULL,					NULL, },
209 #if defined (not_yet)
210 	/*
211 	 *	dynamic flow model ���� HOT_KEY ���ڤ��ؤ��Ϻ���ġ�
212 	 *	static flow model ���ä��顢�¹Բ�ǽ�����ɡġ�
213 	 *	X Input Method Protocol Specification ��ư���ǥ�Ǥ�
214 	 *	filter-event-mask ���ڤ��ؤ��Ƥ���褦�����ɡ�
215 	 *	filter-event-mask �����ꤷ�Ƥ��ޤä��顢Server �� Event ����ʤ���
216 	 *	Client ����������褦�˸������Ǥ�����
217 	 *	Focus Window �˺ٹ�����Ȥ������ȡ�
218 	 */
219 	{	XNHotKey,				XIM_VALUE_TYPE_HOTKEYTRIGGERS,
220 		True,					True,
221 		ximClient_setIcValueHotKey,
222 		ximClient_getIcValueHotKey, },
223 	{	XNHotKeyState,			XIM_VALUE_TYPE_HOTKEYSTATE,
224 		True,					True,
225 		ximClient_setIcValueHotKeyState,
226 		ximClient_getIcValueHotKeyState, },
227 #endif
228 } ;
229 
230 enum {
231 	XIC_ATTRIBUTEID_INPUTSTYLE	= 0,
232 	XIC_ATTRIBUTEID_CLIENTWINDOW,
233 	XIC_ATTRIBUTEID_FOCUSWINDOW,
234 	XIC_ATTRIBUTEID_FILTEREVENTS,
235 	XIC_ATTRIBUTEID_RESETSTATE,
236 	XIC_ATTRIBUTEID_PREEDITSTATE,
237 	XIC_ATTRIBUTEID_PREEDITATTRIBUTES,
238 	XIC_ATTRIBUTEID_STATUSATTRIBUTES,
239 	XIC_ATTRIBUTEID_AREA,
240 	XIC_ATTRIBUTEID_AREANEEDED,
241 	XIC_ATTRIBUTEID_SPOTLOCATION,
242 	XIC_ATTRIBUTEID_COLORMAP,
243 	XIC_ATTRIBUTEID_STDCOLORMAP,
244 	XIC_ATTRIBUTEID_FOREGROUND,
245 	XIC_ATTRIBUTEID_BACKGROUND,
246 	XIC_ATTRIBUTEID_BACKGROUNDPIXMAP,
247 	XIC_ATTRIBUTEID_FONTSET,
248 	XIC_ATTRIBUTEID_LINESPACE,
249 	XIC_ATTRIBUTEID_CURSOR,
250 	XIC_ATTRIBUTEID_SEPARATOR,
251 	MAX_NUMBER_OF_XIC_ATTRIBUTEID,
252 } ;
253 
254 #define	PREEDITATTRIBUTES_MASK			(1L << 0)
255 #define	STATUSATTRIBUTES_MASK			(1L << 1)
256 #define	XIC_CREATE_MASK					(1L << 2)
257 
258 #define	FORWARDEVENT_SYNC_MASK			(1L << 0)
259 #define	FORWARDEVENT_FILTER_MASK		(1L << 1)
260 #define	FORWARDEVENT_LOOKUPSTRING_MASK	(1L << 2)
261 
262 #define offset(field)  XtOffsetOf(XIMClientRec, ximClient.field)
263 #define goffset(field) XtOffsetOf(WidgetRec, core.field)
264 
265 static XtResource	srXIMClientResources [] = {
266 	{	XtNwidth,				XtCWidth,
267 		XtRDimension,			sizeof (Dimension),
268 		goffset (width),		XtRImmediate,	(XtPointer) 1, },
269 	{	XtNheight,				XtCHeight,
270 		XtRDimension,			sizeof (Dimension),
271 		goffset (height),		XtRImmediate,	(XtPointer) 1, },
272 	{	XtNmappedWhenManaged,	XtCMappedWhenManaged,
273 		XtRBoolean,				sizeof (Boolean),
274 		goffset (mapped_when_managed),	XtRImmediate,	(XtPointer)False, },
275 	{	XtNclientWindow,		XtCClientWindow,
276 		XtRWindow,				sizeof (Window),
277 		offset (m_wndClient),	XtRImmediate,	(XtPointer) None, },
278 	{	XtNdestroyCallback,			XtCCallback,
279 		XtRCallback,				sizeof (XtCallbackList),
280 		offset (m_lstCbkDestroy),	XtRCallback,		(XtPointer) NULL, },
281 	{	XtNprotocolWidget,		XtCProtocolWidget,
282 		XtRWidget,				sizeof (Widget),
283 		offset (m_wgProtocol),	XtRImmediate,	(XtPointer) NULL, },
284 } ;
285 
286 #undef offset
287 #undef goffset
288 
289 static	void		ximClient_onInitialize	(Widget, Widget, ArgList, Cardinal*) ;
290 static	void		ximClient_onRealize		(Widget, XtValueMask*, XSetWindowAttributes*) ;
291 static	Boolean		ximClient_onSetValues	(Widget, Widget, Widget, ArgList, Cardinal*) ;
292 static	void		ximClient_onDestroy		(Widget) ;
293 
294 static	void		ximClient_onClientMessage	(Widget, XEvent*, String*, Cardinal*) ;
295 static	int			ximClient_onClientDestroy	(void*, XEvent*) ;
296 
297 static	Boolean		ximClient_getMessage8				(Widget, const CARD8*, int) ;
298 static	Boolean		ximClient_getMessage32				(Widget, Atom) ;
299 static	void		ximClient_dispatchMessage			(Widget) ;
300 static	Boolean		ximClient_writeMessage				(Widget, XIMPacket*) ;
301 static	Boolean		ximClient_writeMessageWithEvent		(Widget, const BYTE*, int) ;
302 static	Boolean		ximClient_writeMessageWithProperty	(Widget, const BYTE*, int) ;
303 static	Boolean		ximClient_initialState			(Widget) ;
304 static	Boolean		ximClient_authorizationOk		(Widget) ;
305 static	Boolean		ximClient_authorizationNg		(Widget) ;
306 static	Boolean		ximClient_authorizationState	(Widget) ;
307 static	Boolean		ximClient_connectedState		(Widget) ;
308 
309 static	Boolean		ximClient_setIcValues	(Widget, XIMInputMethod*, XIMInputContext*, XIMData*, int, int) ;
310 static	Boolean		ximClient_getIcValues	(Widget, XIMInputMethod*, XIMInputContext*, XIMData*, int*, int, XIMPacket*) ;
311 static	void		ximClient_writeSyncReply		(Widget, int, XIMInputContext*) ;
312 static	void		ximClient_makePacketSync		(XIMPacket*) ;
313 static	void		ximClient_flushSpooledPacket	(Widget, XIMInputContext*) ;
314 #if defined (DEBUG) || 0
315 static	void		dumpBuf (const BYTE*, int) ;
316 #endif
317 
318 #define	DEFONXIMFUNC(funcname)	static Boolean	funcname (Widget, int, int, int, XIMData*)
319 DEFONXIMFUNC (ximClient_onXimOpen) ;
320 DEFONXIMFUNC (ximClient_onXimTriggerNotify) ;
321 DEFONXIMFUNC (ximClient_onXimEncodingNegotiation) ;
322 DEFONXIMFUNC (ximClient_onXimQueryExtension) ;
323 DEFONXIMFUNC (ximClient_onXimSetImValues) ;
324 DEFONXIMFUNC (ximClient_onXimGetImValues) ;
325 DEFONXIMFUNC (ximClient_onXimCreateIc) ;
326 DEFONXIMFUNC (ximClient_onXimSetIcValues) ;
327 DEFONXIMFUNC (ximClient_onXimGetIcValues) ;
328 DEFONXIMFUNC (ximClient_onXimSetIcFocus) ;
329 DEFONXIMFUNC (ximClient_onXimUnsetIcFocus) ;
330 DEFONXIMFUNC (ximClient_onXimDestroyIc) ;
331 DEFONXIMFUNC (ximClient_onXimResetIc) ;
332 DEFONXIMFUNC (ximClient_onXimForwardEvent) ;
333 DEFONXIMFUNC (ximClient_onXimSync) ;
334 DEFONXIMFUNC (ximClient_onXimSyncReply) ;
335 DEFONXIMFUNC (ximClient_onXimStrConversionReply) ;
336 DEFONXIMFUNC (ximClient_onXimPreeditStartReply) ;
337 DEFONXIMFUNC (ximClient_onXimPreeditCaretReply) ;
338 DEFONXIMFUNC (ximClient_onXimClose) ;
339 DEFONXIMFUNC (ximClient_onXimDisconnect) ;
340 DEFONXIMFUNC (ximClient_onXimError) ;
341 DEFONXIMFUNC (ximClient_onXimExtForwardKeyEvent) ;
342 DEFONXIMFUNC (ximClient_onXimExtMove) ;
343 #undef DEFONXIMFUNC
344 
345 static	Boolean		ximClient_putInputMethodAttribute	(XIMPacket*, int) ;
346 static	Boolean		ximClient_putInputContextAttribute	(XIMPacket*, int) ;
347 static	Boolean		ximClient_putAttributeCommon(XIMPacket*, int, XIMAttribute*) ;
348 static	Boolean		ximClient_putTriggerKey		(Widget, XIMPacket*, const XIMHotKeyTrigger*) ;
349 static	Boolean		ximClient_writeErrorMessage (Widget, int, int, int, const char*) ;
350 static	Boolean		ximClient_badProtocol		(Widget, const char*) ;
351 static	Boolean		ximClient_setForwardEvent	(Widget, XIMInputMethod*, XIMInputContext*, Boolean) ;
352 static	Boolean			ximClient_registerInputMethod	(Widget, XIMInputMethod*) ;
353 static	Boolean			ximClient_unregisterInputMethod	(Widget, XIMInputMethod*) ;
354 static	XIMInputMethod*		ximClient_findInputMethod	(Widget, CARD16) ;
355 static	XIMInputContext*	ximClient_findInputContext	(Widget, XIMInputMethod*, CARD16) ;
356 static	void			ximClient_destroyAllInputMethods	(Widget) ;
357 static	Boolean			ximClient_createXEvent		(Widget, unsigned long, const xEvent*, XEvent*) ;
358 static	int				ximClient_supportedEncodingp	(const char*, int) ;
359 
360 
361 static XtActionsRec		srXIMClientActionsTable [] = {
362 	{	"on-client-message",			ximClient_onClientMessage, },
363 } ;
364 
365 static char	sstrXIMClientTranslations []	=
366 "<Message>:                              on-client-message()" ;
367 
368 XIMClientClassRec	ximClientClassRec = {
369     {	/* core fields 			*/
370 		/* superclass			*/	&widgetClassRec,
371 		/* class_name			*/	"XIMClient",
372 		/* size					*/	sizeof (XIMClientRec),
373 		/* class_initialize		*/	NULL,
374 		/* class_part_initialize*/	NULL,
375 		/* class_inited			*/	FALSE,
376 		/* initialize			*/	ximClient_onInitialize,
377 		/* initialize_hook		*/	NULL,
378 		/* realize				*/	ximClient_onRealize,
379 		/* actions				*/	srXIMClientActionsTable,
380 		/* num_actions			*/	XtNumber (srXIMClientActionsTable),
381 		/* resources			*/	srXIMClientResources,
382 		/* num_resources		*/	XtNumber (srXIMClientResources),
383 		/* xrm_class			*/	NULLQUARK,
384 		/* compress_motion		*/	TRUE,
385 		/* compress_exposure	*/	TRUE,
386 		/* compress_enterleave	*/	TRUE,
387 		/* visible_interest		*/	FALSE,
388 		/* destroy				*/	ximClient_onDestroy,
389 		/* resize				*/	NULL,
390 		/* expose				*/	NULL,
391 		/* set_values			*/	ximClient_onSetValues,
392 		/* set_values_hook		*/	NULL,
393 		/* set_values_almost	*/	XtInheritSetValuesAlmost,
394 		/* get_values_hook		*/	NULL,
395 		/* accept_focus			*/	NULL,
396 		/* version				*/	XtVersion,
397 		/* callback_private		*/	NULL,
398 		/* tm_table				*/	sstrXIMClientTranslations,
399 		/* query_geometry		*/	XtInheritQueryGeometry,
400     }, {
401 		/* dummy				*/	0,
402 	}
403 } ;
404 
405 WidgetClass ximClientWidgetClass = (WidgetClass)&ximClientClassRec ;
406 
407 void
ximClient_onInitialize(register Widget greq,register Widget gnew,register ArgList args,register Cardinal * num_args)408 ximClient_onInitialize (
409 	register Widget		greq,
410 	register Widget		gnew,
411 	register ArgList	args,
412 	register Cardinal*	num_args)
413 {
414 	register XIMClientWidget	wgThis		= (XIMClientWidget) gnew ;
415 	register Display*			pDisplay	= XtDisplay (gnew) ;
416 
417 	TVarbuffer_Initialize (&wgThis->ximClient.m_vbufAuthProtocolNameList, sizeof (char)) ;
418 	TQueue_Initialize (&wgThis->ximClient.m_queInputMessage, sizeof (CARD8)) ;
419 	wgThis->ximClient.m_fBigEndian		= False ;
420 	wgThis->ximClient.m_pDispatcher		= NULL ;
421 	wgThis->ximClient.m_nAuthProtocol	= 0 ;
422 	wgThis->ximClient.m_uInputMethodID	= 1 ;
423 	wgThis->ximClient.m_lstInputMethod	= NULL ;
424 
425 #define MakeAtom(s)	XInternAtom(pDisplay,s,False)
426 	wgThis->ximClient.m_atProtocol	= MakeAtom ("_XIM_PROTOCOL") ;
427 	wgThis->ximClient.m_atMoreData	= MakeAtom ("_XIM_MOREDATA") ;
428 	wgThis->ximClient.m_atReadWrite	= MakeAtom ("_XIM_SKKCOMM") ;
429 #undef MakeAtom
430 	return ;
431 }
432 
433 Boolean
ximClient_onSetValues(register Widget gwCurrent,register Widget gwRequest,register Widget gwNeww,register ArgList args,register Cardinal * num_args)434 ximClient_onSetValues (
435 	register Widget		gwCurrent,
436 	register Widget		gwRequest,
437 	register Widget		gwNeww,
438 	register ArgList	args,
439 	register Cardinal*	num_args)
440 {
441 /*
442 	register XIMClientWidget	curw	= (XIMClientWidget) gwCurrent ;
443 	register XIMClientWidget	reqw	= (XIMClientWidget) gwRequest ;
444 	register XIMClientWidget	neww	= (XIMClientWidget) gwNeww ;
445 */
446 	return	False ;
447 }
448 
449 void
ximClient_onRealize(register Widget gw,register XtValueMask * pValueMask,register XSetWindowAttributes * pXSWA)450 ximClient_onRealize (
451 	register Widget					gw,
452 	register XtValueMask*			pValueMask,
453 	register XSetWindowAttributes*	pXSWA)
454 {
455 	register Display*			pDisplay	= XtDisplay (gw) ;
456 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
457 	register CoreWidgetClass	super	= (CoreWidgetClass) XtClass (gw)->core_class.superclass ;
458 
459 	(*super->core_class.realize)(gw, pValueMask, pXSWA) ;
460 
461 	if (wgThis->ximClient.m_wndClient == None) {
462 		XtDestroyWidget (gw) ;
463 		return ;
464 	}
465 	AfxRegisterWindow (pDisplay, wgThis->ximClient.m_wndClient, DestroyNotify, StructureNotifyMask, gw, ximClient_onClientDestroy) ;
466 	wgThis->ximClient.m_pDispatcher	= ximClient_initialState ;
467 #if defined (DEBUG_MEMORY)
468 	debug_touch () ;
469 #endif
470 	return ;
471 }
472 
473 void
ximClient_onDestroy(register Widget gw)474 ximClient_onDestroy (
475 	register Widget		gw)
476 {
477 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
478 
479 	XtCallCallbacks (gw, XtNdestroyCallback, gw) ;
480 
481 	AfxUnregisterWindow (wgThis->ximClient.m_wndClient, DestroyNotify, StructureNotifyMask, gw, ximClient_onClientDestroy) ;
482 
483 	/*	���Ƥ� InputMethod ���˴����롣*/
484 	ximClient_destroyAllInputMethods (gw) ;
485 
486 	TQueue_Uninitialize (&wgThis->ximClient.m_queInputMessage) ;
487 	TVarbuffer_Uninitialize (&wgThis->ximClient.m_vbufAuthProtocolNameList) ;
488 #if defined (DEBUG_MEMORY)
489 	debug_dumpmemory (1) ;
490 #endif
491 	return ;
492 }
493 
494 void
ximClient_onClientMessage(register Widget gw,register XEvent * pXEvent,register String * params,register Cardinal * num_params)495 ximClient_onClientMessage (
496 	register Widget		gw,
497 	register XEvent*	pXEvent,
498 	register String*	params,
499 	register Cardinal*	num_params)
500 {
501 	register XIMClientWidget		wgThis	= (XIMClientWidget) gw ;
502 	register XClientMessageEvent*	pEvent	= (XClientMessageEvent*)&pXEvent->xclient ;
503 	register Boolean	fResult ;
504 
505 	if (XtWindow (gw) != pEvent->window)
506 		return ;
507 
508 	switch (pEvent->format) {
509 	case	8:
510 		if (pEvent->message_type != wgThis->ximClient.m_atProtocol &&
511 			pEvent->message_type != wgThis->ximClient.m_atMoreData)
512 			return ;
513 		fResult	= ximClient_getMessage8 (gw, (CARD8 *)pEvent->data.b, XTRANSPORT_UNIT_SIZE) ;
514 #if defined (DEBUG)
515 		fprintf (stderr, "ximClient_getMessage8 (): %d\n", fResult) ;
516 #endif
517 		break ;
518 	case	32:
519 		if (pEvent->message_type != wgThis->ximClient.m_atProtocol)
520 			return ;
521 		fResult	= ximClient_getMessage32 (gw, (Atom)pEvent->data.l [1]) ;
522 #if defined (DEBUG)
523 		fprintf (stderr, "ximClient_getMessage32 (): %d\n", fResult) ;
524 #endif
525 		break ;
526 	default:
527 		return ;
528 	}
529 	if (fResult)
530 		ximClient_dispatchMessage (gw) ;
531 	return ;
532 }
533 
534 int
ximClient_onClientDestroy(register void * pClosure,register XEvent * pEvent)535 ximClient_onClientDestroy (
536 	register void*		pClosure,
537 	register XEvent*	pEvent)
538 {
539 	register XIMClientWidget	wgThis	= (XIMClientWidget) pClosure ;
540 #if defined (DEBUG)
541 	fprintf (stderr, "ximClient_onClientDestroy (%p, %p)\n", pClosure, pEvent) ;
542 #endif
543 	XtDestroyWidget ((Widget)wgThis) ;
544 	return	0 ;
545 }
546 
547 void
ximClient_dispatchMessage(register Widget gw)548 ximClient_dispatchMessage (
549 	register Widget		gw)
550 {
551 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
552 
553 	assert (wgThis->ximClient.m_pDispatcher != NULL) ;
554 
555 #if defined (DEBUG) || 0
556 	{
557 		register TQueue*		pQueue	= &wgThis->ximClient.m_queInputMessage ;
558 		register const BYTE*	pBuffer	= TQueue_GetData  (pQueue) ;
559 		register int			nUsage	= TQueue_GetUsage (pQueue) ;
560 		fprintf (stderr, "** input (%d) **\n", nUsage) ;
561 		dumpBuf (pBuffer, nUsage) ;
562 	}
563 #endif
564 
565 	while ((wgThis->ximClient.m_pDispatcher)(gw))
566 		;
567 	return ;
568 }
569 
570 Boolean
ximClient_getMessage8(register Widget gw,register const CARD8 * pData,register int nData)571 ximClient_getMessage8 (
572 	register Widget			gw,
573 	register const CARD8*	pData,
574 	register int			nData)
575 {
576 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
577 
578 	return	TQueue_In (&wgThis->ximClient.m_queInputMessage, pData, nData) ;
579 }
580 
581 Boolean
ximClient_getMessage32(register Widget gw,register Atom atProperty)582 ximClient_getMessage32 (
583 	register Widget		gw,
584 	register Atom		atProperty)
585 {
586 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
587 	register Display*			pDisplay	= XtDisplay (gw) ;
588 	register Window				window		= XtWindow (gw) ;
589 	register TQueue*			pQueue ;
590 	Atom				atActualType ;
591 	int					iActualFormat ;
592 	long				lOffset ;
593 	unsigned long		ulRemain ;
594 	unsigned long		ulItems ;
595 	char* 				pData ;
596 	Boolean				fRetvalue ;
597 
598 	lOffset		= 0 ;
599 	fRetvalue	= True ;
600 	pQueue		= &wgThis->ximClient.m_queInputMessage ;
601 
602 	do {
603 		XGetWindowProperty (pDisplay, window, atProperty, lOffset, 1000, True, AnyPropertyType, &atActualType, &iActualFormat, &ulItems, &ulRemain, (unsigned char **)&pData) ;
604 		if (!pData)
605 			break ;
606 		if (iActualFormat != 8){
607 			fRetvalue	= False ;
608 		} else {
609 			fRetvalue	= TQueue_In (pQueue, pData, ulItems) ;
610 			lOffset		+= ulItems ;
611 		}
612 		XFree (pData) ;
613 		pData	= 0 ;
614 	} while (fRetvalue && ulRemain > 0) ;
615 
616 	return	fRetvalue ;
617 }
618 
619 /*
620  *
621  */
622 Boolean
ximClient_writeMessage(register Widget gw,register XIMPacket * pPacket)623 ximClient_writeMessage (
624 	register Widget		gw,
625 	register XIMPacket*	pPacket)
626 {
627 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
628 	register XIMInputContext*	pInputContext ;
629 	register const BYTE*		pPacketData ;
630 	register int				nPacketSize ;
631 
632 	pInputContext	= XIMPacket_GetInputContext (pPacket) ;
633 #if defined (DEBUG) || 0
634 	{
635 		register XIMPacketSyncMode	uMode	= XIMPacket_GetSyncMode (pPacket) ;
636 		fprintf (stderr, "IC(%p), Mode(%x), ", pInputContext, uMode) ;
637 		XIMPacket_Show (pPacket) ;
638 	}
639 #endif
640 	if (pInputContext != NULL) {
641 		register XIMPacketSyncMode	uMode	= XIMPacket_GetSyncMode (pPacket) ;
642 
643 		switch (uMode) {
644 			register unsigned		uSyncMode ;
645 
646 			/*	�������ס���ѥ��åȤν�����*/
647 		case	XIMPS_SPOOL_PREEDIT_START:
648 		case	XIMPS_SPOOL_PREEDIT_CARET:
649 		case	XIMPS_SPOOL_PREEDIT:
650 		case	XIMPS_SPOOL:
651 #if defined (DEBUG) || 0
652 			fprintf (stderr, " ---> spool\n") ;
653 #endif
654 			return	XIMInputContext_SpoolPacket (pInputContext, pPacket) ;
655 
656 			/*	Ʊ���Ԥ����׵᤹��ѥ��åȤ�����Ȥä����ν�����*/
657 		case	XIMPS_SYNC_NORMAL:
658 		case	XIMPS_SYNC_PREEDIT_CARET:
659 		case	XIMPS_SYNC_PREEDIT_START:
660 			uSyncMode	= XIMInputContext_GetSyncMode (pInputContext) ;
661 			if ((uSyncMode & XIMSyncAny) != 0) {
662 #if defined (DEBUG) || 0
663 				fprintf (stderr, " ---> spool\n") ;
664 #endif
665 				return	XIMInputContext_SpoolPacket (pInputContext, pPacket) ;
666 			}
667 			XIMInputContext_SetSyncMode (pInputContext, 1 << (uMode - XIMPS_SPOOL)) ;
668 			break ;
669 
670 		case	XIMPS_NO:
671 		default:
672 			break ;
673 		}
674 	}
675 
676 #if defined (DEBUG) || 0
677 	fprintf (stderr, " ---> write\n") ;
678 #endif
679 
680 	pPacketData	= XIMPacket_GetData (pPacket) ;
681 	nPacketSize	= XIMPacket_GetDataSize (pPacket) ;
682 #if defined (DEBUG) || 0
683 	fprintf (stderr, "** output (%d) **\n", nPacketSize) ;
684 	dumpBuf (pPacketData, nPacketSize) ;
685 #endif
686 	if (nPacketSize < XTRANSPORT_DIVIDING_SIZE) {
687 		return	ximClient_writeMessageWithEvent (gw, pPacketData, nPacketSize) ;
688 	} else {
689 		return	ximClient_writeMessageWithProperty (gw, pPacketData, nPacketSize) ;
690 	}
691 }
692 
693 Boolean
ximClient_writeMessageWithEvent(register Widget gw,register const BYTE * pPacketData,register int nPacketSize)694 ximClient_writeMessageWithEvent (
695 	register Widget			gw,
696 	register const BYTE*	pPacketData,
697 	register int			nPacketSize)
698 {
699 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
700 	register Display*		pDisplay ;
701 	register Window			wndClient ;
702 	XEvent					xev ;
703 
704 	pDisplay	= XtDisplay (gw) ;
705 	wndClient	= wgThis->ximClient.m_wndClient ;
706 	while (nPacketSize > XTRANSPORT_UNIT_SIZE) {
707 		xev.type					= ClientMessage ;
708 		xev.xclient.display			= pDisplay ;
709 		xev.xclient.window			= wndClient ;
710 		xev.xclient.format			= 8 ;
711 		xev.xclient.message_type	= wgThis->ximClient.m_atMoreData ;
712 		memcpy (xev.xclient.data.b, pPacketData, XTRANSPORT_UNIT_SIZE) ;
713 		XSendEvent (pDisplay, wndClient, False, NoEventMask, &xev) ;
714 		pPacketData	+= XTRANSPORT_UNIT_SIZE ;
715 		nPacketSize	-= XTRANSPORT_UNIT_SIZE ;
716 	}
717 	if (0 < nPacketSize && nPacketSize <= XTRANSPORT_UNIT_SIZE) {
718 		xev.type					= ClientMessage ;
719 		xev.xclient.message_type	= wgThis->ximClient.m_atProtocol ;
720 		xev.xclient.display			= pDisplay ;
721 		xev.xclient.window			= wndClient ;
722 		xev.xclient.format			= 8 ;
723 		memset (xev.xclient.data.b, 0, XTRANSPORT_UNIT_SIZE) ;
724 		memcpy (xev.xclient.data.b, pPacketData, nPacketSize) ;
725 		XSendEvent (pDisplay, wndClient, False, NoEventMask, &xev) ;
726 	}
727 	XFlush (pDisplay) ;
728 	return	True ;
729 }
730 
731 Boolean
ximClient_writeMessageWithProperty(register Widget gw,register const BYTE * pPacketData,register int nPacketSize)732 ximClient_writeMessageWithProperty (
733 	register Widget			gw,
734 	register const BYTE*	pPacketData,
735 	register int			nPacketSize)
736 {
737 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
738 	register Display*	pDisplay ;
739 	register Window		wndClient ;
740 	XEvent		xev ;
741 
742 	pDisplay	= XtDisplay (gw) ;
743 	wndClient	= wgThis->ximClient.m_wndClient ;
744 	XChangeProperty (pDisplay, wndClient, wgThis->ximClient.m_atReadWrite, XA_STRING, 8, PropModeAppend, pPacketData, nPacketSize) ;
745 	xev.type					= ClientMessage ;
746 	xev.xclient.display			= pDisplay ;
747 	xev.xclient.window			= wndClient ;
748 	xev.xclient.message_type	= wgThis->ximClient.m_atProtocol ;
749 	xev.xclient.format			= 32 ;
750 	xev.xclient.data.l [0]		= nPacketSize ;
751 	xev.xclient.data.l [1]		= wgThis->ximClient.m_atReadWrite ;
752 	XSendEvent (pDisplay, wndClient, False, NoEventMask, &xev) ;
753 	XFlush (pDisplay) ;
754 	return	True ;
755 }
756 
757 /*
758  *(�ؿ�)
759  *	virtual bool	CXIMClient::initialState () ;
760  *(��ǽ)
761  *	X Input Method Protocol Server �� Client ����³����ޤǤΥ�å������ν���
762  *	��Ԥ����������������褿��å������� XIM_CONNECT �ʳ����ä����ˤ�
763  *	�����Фˤϲ���ޤǤΥǡ�����ΤƤ����ɤ��Τ����äѤ�ʬ����ʤ����Ȥˤʤ롣
764  *	��Endian �ξ�����������פġ�ȯ�ۤ�����ˡ֤��ν��֤�����롪�פȤ���
765  *	htons �ߤ����ʼ�ˡ���Ѱդ��������ɤ����ޤȤ⤫�Ȥ������Ȥ�ʬ�����֤Ǥ��롣
766  *	X lib �� patch �����Ƥ������⡣
767  *(������)
768  *	XIM �� ��äѤꥴ�ߤ���
769  *(�֤���)
770  *	True		�����η�³
771  *	false		�ǡ�����­�ˤ�����������
772  *	���顼���̤� XIM_ERROR ��å��������ꤲ��Τǡ�����פ��Ȼפ���
773  */
774 Boolean
ximClient_initialState(register Widget gw)775 ximClient_initialState (
776 	register Widget			gw)
777 {
778 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
779 	register TQueue*			pQueue ;
780 	XIMData		imData ;
781 	register int		nMajorOpCode, nMinorOpCode, nLength, nUsage ;
782 	register CARD8		byByteOrder ;
783 	register CARD16		woClientMajorProtocolVersion ;
784 	register CARD16		woClientMinorProtocolVersion ;
785 	register CARD16		woClientAuthProtocolNameLen ;
786 
787 	/*init-status*/
788 	/*	Wait XIM_CONNECT*/
789 	pQueue	= &wgThis->ximClient.m_queInputMessage ;
790 	XIMData_Initialize (&imData, TQueue_GetData (pQueue), False) ;
791 	nUsage	= TQueue_GetUsage (pQueue) ;
792 
793 	/*
794 	 *	�إå����� + Endian ��������Ǥ�̵���Ȥޤ�����
795 	 *	�ºݤˤɤ����٤Υǡ�����1�ѥ��åȤ������Ƥ���Τ��ϥ���ǥ�����ʬ�����
796 	 *	����ФȤ�ʤ���
797 	 *��	CARD16 �ʤΤǡ�
798 	 */
799 	if (nUsage < (int)(XIM_HEADER_SIZE + 8))
800 		return	False ;
801 	nMajorOpCode	= XIMData_GetCard8  (&imData) ;
802 	nMinorOpCode	= XIMData_GetCard8  (&imData) ;
803 	nLength			= XIMData_GetCard16 (&imData) ;
804 #if defined (DEBUG)
805 	fprintf (stderr, "InitialState1 (Major: %d, Minor: %d, Length: %d) / Usage: %d\n", nMajorOpCode, nMinorOpCode, nLength, nUsage) ;
806 #endif
807 
808 	if (nMajorOpCode != XIM_CONNECT){
809 		int	nTmpLength ;
810 		/*
811 		 *	�����ʳ��Ǥ� Client �� Endian �������ʤΤǡ�������ä��ѥ��åȤΥ���������������
812 		 *	����������̿�᤬�褿�Ȥ������Ȥ���ʬ����ʤ���
813 		 *	�������ʤ����饭�塼��ե�å��夹�뤬���ä��᤮���ǽ��������Ǥ��ʤ���
814 		 *	�Ϥä�����äơ�X INPUT METHOD PROTOCOL �μ�������Ȼפ���
815 		 */
816 		nTmpLength		= ((nLength & 0x00FF) << 8) | ((nLength >> 8) & 0x00FF) ;
817 		if (nTmpLength < nLength)
818 			nLength		= nTmpLength ;
819 		if ((int)(nLength * 4 + XIM_HEADER_SIZE) <= nUsage){
820 			TQueue_Out (pQueue, NULL, XIM_HEADER_SIZE + nLength * 4) ;
821 			//this->authorizationNg () ;
822 			return	True ;
823 		} else {
824 			return	False ;
825 		}
826 	}
827 	//	Recieve XIM_CONNECT
828 	byByteOrder	= XIMData_GetCard8 (&imData) ;
829 	if (byByteOrder == XIM_BIGENDIAN){
830 		wgThis->ximClient.m_fBigEndian	= True ;
831 		nLength		= ((nLength & 0x00FF) << 8) | ((nLength >> 8) & 0x00FF) ;
832 	} else {
833 		wgThis->ximClient.m_fBigEndian	= False ;
834 	}
835 	XIMData_SetEndian (&imData, wgThis->ximClient.m_fBigEndian) ;
836 #if defined (DEBUG)
837 	fprintf (stderr, "InitialState2 (Major: %d, Minor: %d, Length: %d)\n", nMajorOpCode, nMinorOpCode, nLength) ;
838 #endif
839 
840 	/*
841 	 *	��������ƤϤ���� nLength ��ʬ���ä��Τǡ��ǡ���������äƤ��뤫
842 	 *	�����å��Ǥ��롣
843 	 */
844 	if (nUsage < (int)(nLength * 4 + XIM_HEADER_SIZE))
845 		return	False ;
846 
847 	XIMData_Forward8 (&imData, 1) ;
848 	woClientMajorProtocolVersion	= XIMData_GetCard16 (&imData) ;
849 	woClientMinorProtocolVersion	= XIMData_GetCard16 (&imData) ;
850 	woClientAuthProtocolNameLen		= XIMData_GetCard16 (&imData) ;
851 
852 	if (woClientMajorProtocolVersion > XIM_PROTOCOL_MAJOR_VERSION ||
853 		(woClientMajorProtocolVersion == XIM_PROTOCOL_MAJOR_VERSION &&
854 		 woClientMinorProtocolVersion >  XIM_PROTOCOL_MINOR_VERSION)){
855 		//	Server NG
856 		TQueue_Out (pQueue, NULL, XIM_HEADER_SIZE + nLength * 4) ;
857 		return	ximClient_authorizationNg (gw) ;
858 	}
859 	//	Client �� Authorization ���׵ᤷ�Ƥ��롣
860 	if (woClientAuthProtocolNameLen > 0){
861 		register TVarbuffer*	pvbuf ;
862 		register int			nLength ;
863 
864 		pvbuf	= &wgThis->ximClient.m_vbufAuthProtocolNameList ;
865 		TVarbuffer_Clear (pvbuf) ;
866 		while (woClientAuthProtocolNameLen > 0){
867 			nLength	= XIMData_GetCard16 (&imData) ;
868 			//	NUL Terminate ���� STRING ���Ѵ����Ƥ��뤬�Ĥ��줬�ޤ����褦�ʻ��֤�ȯ�����뤫��
869 			if (TFAILED (TVarbuffer_Add (pvbuf, (const char*)XIMData_GetHead (&imData), nLength)) ||
870 				TFAILED (TVarbuffer_Add (pvbuf, "\0", 1))) {
871 				return	False ;
872 			}
873 			XIMData_Forward8 (&imData, nLength) ;
874 			woClientAuthProtocolNameLen	-- ;
875 		}
876 		wgThis->ximClient.m_nAuthProtocol	= 0 ;
877 
878 		//	Send XIM_AUTH_REQUIRED
879 		wgThis->ximClient.m_pDispatcher	= ximClient_authorizationState ;
880 	} else {
881 		//	Send XIM_CONNECT_REPLY
882 		wgThis->ximClient.m_pDispatcher	= ximClient_connectedState ;
883 		ximClient_authorizationOk (gw) ;
884 	}
885 	TQueue_Out (pQueue, NULL, XIM_HEADER_SIZE + nLength * 4) ;
886 #if defined (DEBUG)
887 	fprintf (stderr, "InitialState / Queue = %d\n", TQueue_GetUsage (pQueue)) ;
888 #endif
889 	return	True ;
890 }
891 
892 /*
893  *(�ؿ�)
894  *	virtual bool	CXIMClient::authorizationState () ;
895  *(��ǽ)
896  *	Server �� Client ����³�ˤ�����ǧ�ڥ��ơ�����
897  *(����)
898  *	�����Ǥ� Endian �����ꤷ�Ƥ���Τdzڡ�
899  *	�������ʤ��顢���ǧ�ڤäƤɤ����Ρ�����ʬ�� X library ������
900  *	��������Ƥ��ʤ���� X Input Method Protocol version 1.0 ���ͽ�
901  *	�Ȥ��ˤɤ�����Τ�������Ƥ⤤�ʤ��Τǡ��������Բ�ǽ���Ȼפ���
902  *	�֤�Ȥ�Ȥβ����������Ρ��פ�ʬ����СIJ��Ȥ��Ǥ���Τ��⤷��
903  *	�ʤ�����ɤ⡣
904  *(�֤���)
905  *	True		�����η�³
906  *	false		�ǡ�����­�ˤ�����������
907  *	���顼���̤� XIM_ERROR ��å��������ꤲ��Τǡ�����פ��Ȼפ���
908  */
909 Boolean
ximClient_authorizationState(register Widget gw)910 ximClient_authorizationState (
911 	register Widget		gw)
912 {
913 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
914 	register TQueue*	pQueue ;
915 	XIMData				imData ;
916 	register int		nMajorOpCode, nMinorOpCode, nLength, nUsage ;
917 
918 	pQueue	= &wgThis->ximClient.m_queInputMessage ;
919 	nUsage	= TQueue_GetUsage (pQueue) ;
920 	if (nUsage < (int)(XIM_HEADER_SIZE))
921 		return	False ;
922 
923 	XIMData_Initialize (&imData, TQueue_GetData (pQueue), wgThis->ximClient.m_fBigEndian) ;
924 	nMajorOpCode	= XIMData_GetCard8  (&imData) ;
925 	nMinorOpCode	= XIMData_GetCard8  (&imData) ;
926 	nLength			= XIMData_GetCard16 (&imData) ;
927 	if (nUsage < (int)(XIM_HEADER_SIZE + nLength * 4))
928 		return	False ;
929 
930 	//	Wait XIM_AUTH_REPLY or XIM_AUTH_NEXT
931 	if (nMajorOpCode != XIM_AUTH_REPLY && nMajorOpCode != XIM_AUTH_NEXT){
932 		TQueue_Out (pQueue, NULL, XIM_HEADER_SIZE + nLength * 4) ;
933 		//	Server NG
934 		return	ximClient_authorizationNg (gw) ;
935 	}
936 	if (nMajorOpCode == XIM_AUTH_REPLY){
937 		//	server_check �ˤ���ˤ� AUTH �μ����Ϥɤ�����٤����Ļ�����̵����
938 		TQueue_Out (pQueue, NULL, XIM_HEADER_SIZE + nLength * 4) ;
939 		return	ximClient_authorizationNg (gw) ;
940 	} else {
941 		//	Send XIM_AUTH_REQUIRED
942 		TQueue_Out (pQueue, NULL, XIM_HEADER_SIZE + nLength * 4) ;
943 	}
944 	return	True ;
945 }
946 
947 Boolean
ximClient_authorizationOk(register Widget gw)948 ximClient_authorizationOk (
949 	register Widget		gw)
950 {
951 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
952 	register XIMPacket*	pPacket ;
953 
954 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
955 #if defined (DEBUG) || 0
956 	fprintf (stderr, "XIMClient_authorizationOk ()\n") ;
957 #endif
958 	XIMPacket_SetHeader (pPacket, XIM_CONNECT_REPLY, 0) ;
959 	XIMPacket_AddCard16 (pPacket, XIM_PROTOCOL_MAJOR_VERSION) ;
960 	XIMPacket_AddCard16 (pPacket, XIM_PROTOCOL_MINOR_VERSION) ;
961 	XIMPacket_SetLength (pPacket) ;
962 	ximClient_writeMessage (gw, pPacket) ;
963 	XIMPacket_Release (pPacket) ;
964 	return	True ;
965 }
966 
967 /*
968  *(�ؿ�)
969  *	virtual bool	CXIMClient::authorizationNg () ;
970  *(��ǽ)
971  *	ǧ�ڤ˼��Ԥ����ݤ� client �������롣
972  */
973 Boolean
ximClient_authorizationNg(register Widget gw)974 ximClient_authorizationNg (
975 	register Widget		gw)
976 {
977 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
978 	register XIMPacket*	pPacket ;
979 
980 #if defined (DEBUG) || 0
981 	fprintf (stderr, "XIMClient_authorizationNg ()\n") ;
982 #endif
983 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
984 	XIMPacket_SetHeader (pPacket, XIM_AUTH_NG, 0) ;
985 	ximClient_writeMessage (gw, pPacket) ;
986 	wgThis->ximClient.m_pDispatcher	= ximClient_initialState ;
987 	return	True ;
988 }
989 
990 /*
991  *
992  */
993 #define	DEFINE_IMVFUNCTION(functionname,string)	Boolean	functionname (Widget gw, int nMajorOpCode, int nMinorOpCode, int nLength, XIMData* pData) \
994 { \
995     return	ximClient_badProtocol (gw, (string)) ;	\
996 }	// End of definition
997 
998 DEFINE_IMVFUNCTION(ximClient_onXimConnect,			"Already connected") ;
999 DEFINE_IMVFUNCTION(ximClient_onXimConnectReply,			"XIM_CONNECT_REPLY must be sent by IM Server") ;
1000 DEFINE_IMVFUNCTION(ximClient_onXimDisconnectReply,		"XIM_DISCONNECT_REPLY must be sent by IM Server") ;
1001 DEFINE_IMVFUNCTION(ximClient_onXimAuthRequired,			"Not autheraization phase.") ;
1002 DEFINE_IMVFUNCTION(ximClient_onXimAuthReply,			"Not autheraization phase.") ;
1003 DEFINE_IMVFUNCTION(ximClient_onXimAuthNext,			"Not autheraization phase.") ;
1004 DEFINE_IMVFUNCTION(ximClient_onXimAuthSetup,			"Not autheraization phase.") ;
1005 DEFINE_IMVFUNCTION(ximClient_onXimAuthNg,				"Not autheraization phase.") ;
1006 DEFINE_IMVFUNCTION(ximClient_onXimOpenReply,			"XIM_OPEN_REPLY must be sent by IM Server.") ;
1007 DEFINE_IMVFUNCTION(ximClient_onXimCloseReply,			"XIM_CLOSE_REPLY must be sent by IM Server.") ;
1008 DEFINE_IMVFUNCTION(ximClient_onXimRegisterTriggerkeys,		"XIM_REGISTER_TGIGGERKEYS must be sent by IM Server.") ;
1009 DEFINE_IMVFUNCTION(ximClient_onXimTriggerNotifyReply,		"XIM_TRIGGER_NOTIFY must be sent by IM Server.") ;
1010 DEFINE_IMVFUNCTION(ximClient_onXimSetEventMask,			"XIM_SET_EVENT_MASK must be sent by IM Server.") ;
1011 DEFINE_IMVFUNCTION(ximClient_onXimEncodingNegotiationReply,	"XIM_ENCODING_NEGOTIATION_REPLY must be sent by IM Server.") ;
1012 DEFINE_IMVFUNCTION(ximClient_onXimQueryExtensionReply,		"XIM_QUERY_EXTENSION_REPLY must be sent by IM Server.") ;
1013 DEFINE_IMVFUNCTION(ximClient_onXimSetImValuesReply,		"XIM_SET_IM_VALUES_REPLY must be sent by IM Server.") ;
1014 DEFINE_IMVFUNCTION(ximClient_onXimGetImValuesReply,		"XIM_GET_IM_VALUES_REPLY must be sent by IM Server.") ;
1015 DEFINE_IMVFUNCTION(ximClient_onXimCreateIcReply,			"XIM_CREATE_IC_REPLY must be sent by IM Server.") ;
1016 DEFINE_IMVFUNCTION(ximClient_onXimDestroyIcReply,			"XIM_DESTORY_IC_REPLY must be sent by IM Server.") ;
1017 DEFINE_IMVFUNCTION(ximClient_onXimSetIcValuesReply,		"XIM_SET_IC_VALUES_REPLY must be sent by IM Server.") ;
1018 DEFINE_IMVFUNCTION(ximClient_onXimGetIcValuesReply,		"XIM_GET_IC_VALUES_REPLY must be sent by IM Server.") ;
1019 DEFINE_IMVFUNCTION(ximClient_onXimCommit,				"XIM_COMMIT must be sent by IM Server.") ;
1020 DEFINE_IMVFUNCTION(ximClient_onXimResetIcReply,			"XIM_RESET_IC_REPLY must be sent by IM Server.") ;
1021 DEFINE_IMVFUNCTION(ximClient_onXimGeometry,			"XIM_GEOMETRY must be sent by IM Server.") ;
1022 DEFINE_IMVFUNCTION(ximClient_onXimStrConversion,			"XIM_STR_CONVERSION must be sent by IM Server.") ;
1023 DEFINE_IMVFUNCTION(ximClient_onXimPreeditStart,			"XIM_PREEDIT_START must be sent by IM Server.") ;
1024 DEFINE_IMVFUNCTION(ximClient_onXimPreeditDraw,			"XIM_PREEDIT_DRAW must be sent by IM Server.") ;
1025 DEFINE_IMVFUNCTION(ximClient_onXimPreeditCaret,			"XIM_PREEDIT_CARET must be sent by IM Server.") ;
1026 DEFINE_IMVFUNCTION(ximClient_onXimPreeditDone,			"XIM_PREEDIT_DONE must be sent by IM Server.") ;
1027 DEFINE_IMVFUNCTION(ximClient_onXimStatusStart,			"XIM_STATUS_START must be sent by IM Server.") ;
1028 DEFINE_IMVFUNCTION(ximClient_onXimStatusDraw,			"XIM_STATUS_DRAW must be sent by IM Server.") ;
1029 DEFINE_IMVFUNCTION(ximClient_onXimStatusDone,			"XIM_STATUS_DONE must be sent by IM Server.") ;
1030 DEFINE_IMVFUNCTION(ximClient_onXimPreeditState,			"XIM_PREEDITSTATE must be sent by IM Server.") ;
1031 
1032 #undef	DEFINE_IMVFUNCTION
1033 
1034 /*
1035  *(�ؿ�)
1036  *	virtual bool	CXIMClient::connectedState () ;
1037  *(��ǽ?)
1038  *	ǧ�ڤ��������� Server �� Client �֤���³�����������������δؿ���
1039  *	Client �Υ�å�������������뤿��˸ƤӽФ���롣
1040  *(�֤���)
1041  *	True		�����η�³
1042  *	false		�ǡ�����­�ˤ�����������
1043  *	���顼���̤� XIM_ERROR ��å��������ꤲ��Τǡ�����פ��Ȼפ���
1044  */
1045 Boolean
ximClient_connectedState(register Widget gw)1046 ximClient_connectedState (
1047 	register Widget		gw)
1048 {
1049 	/*
1050 	 *	Major Operation Code ���б���������ؿ��Υơ��֥롣
1051 	 */
1052 	static Boolean	(*operation_table[])(Widget, int, int, int, XIMData*) = {
1053 		NULL,							ximClient_onXimConnect,
1054 		ximClient_onXimConnectReply,	ximClient_onXimDisconnect,
1055 		ximClient_onXimDisconnectReply,	NULL,
1056 		NULL,							NULL,
1057 		NULL,							NULL,
1058 		ximClient_onXimAuthRequired,	ximClient_onXimAuthReply,
1059 		ximClient_onXimAuthNext,		ximClient_onXimAuthSetup,
1060 		ximClient_onXimAuthNg,			NULL,
1061 		NULL,							NULL,
1062 		NULL,							NULL,
1063 		ximClient_onXimError,			NULL,
1064 		NULL,							NULL,
1065 		NULL,							NULL,
1066 		NULL,							NULL,
1067 		NULL,							NULL,
1068 		ximClient_onXimOpen,			ximClient_onXimOpenReply,
1069 		ximClient_onXimClose,			ximClient_onXimCloseReply,
1070 		ximClient_onXimRegisterTriggerkeys,	ximClient_onXimTriggerNotify,
1071 		ximClient_onXimTriggerNotifyReply,	ximClient_onXimSetEventMask,
1072 		ximClient_onXimEncodingNegotiation,	ximClient_onXimEncodingNegotiationReply,
1073 		ximClient_onXimQueryExtension,	ximClient_onXimQueryExtensionReply,
1074 		ximClient_onXimSetImValues,		ximClient_onXimSetImValuesReply,
1075 		ximClient_onXimGetImValues,		ximClient_onXimGetImValuesReply,
1076 		NULL,							NULL,
1077 		NULL,							NULL,
1078 		ximClient_onXimCreateIc,		ximClient_onXimCreateIcReply,
1079 		ximClient_onXimDestroyIc,		ximClient_onXimDestroyIcReply,
1080 		ximClient_onXimSetIcValues,		ximClient_onXimSetIcValuesReply,
1081 		ximClient_onXimGetIcValues,		ximClient_onXimGetIcValuesReply,
1082 		ximClient_onXimSetIcFocus,		ximClient_onXimUnsetIcFocus,
1083 		ximClient_onXimForwardEvent,	ximClient_onXimSync,
1084 		ximClient_onXimSyncReply,		ximClient_onXimCommit,
1085 		ximClient_onXimResetIc,			ximClient_onXimResetIcReply,
1086 		NULL,							NULL,
1087 		NULL,							NULL,
1088 		ximClient_onXimGeometry,		ximClient_onXimStrConversion,
1089 		ximClient_onXimStrConversionReply,	ximClient_onXimPreeditStart,
1090 		ximClient_onXimPreeditStartReply,	ximClient_onXimPreeditDraw,
1091 		ximClient_onXimPreeditCaret,		ximClient_onXimPreeditCaretReply,
1092 		ximClient_onXimPreeditDone,		ximClient_onXimStatusStart,
1093 		ximClient_onXimStatusDraw,		ximClient_onXimStatusDone,
1094 		ximClient_onXimPreeditState,
1095 	} ;
1096 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
1097 	register TQueue*			pQueue ;
1098 	XIMData			imData ;
1099 	register int	nMajorOpCode, nMinorOpCode, nLength, nUsage ;
1100 
1101 	/*	�إå��ǡ���������äƤ��뤫�ɤ����Υ����å���Ԥ���*/
1102 	pQueue	= &wgThis->ximClient.m_queInputMessage ;
1103 	nUsage	= TQueue_GetUsage (pQueue) ;
1104 	if (nUsage < (int)XIM_HEADER_SIZE)
1105 		return	False ;
1106 
1107 	XIMData_Initialize (&imData, TQueue_GetData (pQueue), wgThis->ximClient.m_fBigEndian) ;
1108 	nMajorOpCode	= XIMData_GetCard8 (&imData) ;
1109 	nMinorOpCode	= XIMData_GetCard8 (&imData) ;
1110 	nLength			= XIMData_GetCard16 (&imData) ;
1111 #if defined (DEBUG) || 0
1112 	if (nMajorOpCode > 0)
1113 		fprintf (stderr, "ConnectedState (Major: %d, Minor: %d, Length: %d, nRead: %d/%d\n",
1114 				 nMajorOpCode, nMinorOpCode, nLength, nUsage, XIM_HEADER_SIZE + nLength * 4) ;
1115 #endif
1116 	if (nUsage < (int)(XIM_HEADER_SIZE + nLength * 4))
1117 		return	False ;
1118 
1119 	if (nMajorOpCode == XIM_EXT_FORWARD_KEYEVENT){
1120 		ximClient_onXimExtForwardKeyEvent (gw, nMajorOpCode, nMinorOpCode, nLength, &imData) ;
1121 	} else if (nMajorOpCode == XIM_EXT_MOVE){
1122 		ximClient_onXimExtMove (gw, nMajorOpCode, nMinorOpCode, nLength, &imData) ;
1123 	} else if (nMajorOpCode < 0 || nMajorOpCode > XIM_PREEDITSTATE || !operation_table [nMajorOpCode]){
1124 		if (nMajorOpCode)
1125 			ximClient_badProtocol (gw, "Invalid MajorOpCode") ;
1126 	} else {
1127 		(operation_table [nMajorOpCode])(gw, nMajorOpCode, nMinorOpCode, nLength, &imData) ;
1128 	}
1129 	TQueue_Out (pQueue, NULL, XIM_HEADER_SIZE + nLength * 4) ;
1130 
1131 	/*	���Υ�å����������뤫�ɤ���ʬ����ʤ��Τǡ���³�¹Ԥ��׵᤹�롣
1132 	 *	���顼��ȯ���������˼��Υ�å������äƤɤ�����Ρ��Ȥ�����ʬ�ϡ��档
1133 	 */
1134 	return	True ;
1135 }
1136 
1137 /*
1138  *	XIM Packet ��������� member function
1139  */
1140 /*
1141  *	XIM_OPEN: XIM library --> XIM Server
1142  *(������)
1143  *	XIM_OPEN Packet ��������ơ�XIM_OPEN_REPLY Packet �� library (Client) �������֤���
1144  *	���λ��� Input Method ��������롣
1145  *	1 InputMethod per 1 Client �ĤȤ����櫓�ǤϤʤ��Ȼפ��Τǡ������� InputMethod
1146  *	���� Client ��¸�ߤ���Ȥϻפ����ɸ����Ǥ� 1 Client �ˤĤ� 1 InputMethod �Τ�
1147  *	���Ǥ��롣
1148  *	X Input Method Protocol version 1.0 �Ȥ����� I18N �ʲ��ˤ���ɥ�����Ȥˤ�
1149  *	Dynamic Flow Control �ξ��ˤϡ�XIM_REGISTER_TRIGGERKEYS �� XIM_OPEN_REPLY ����
1150  *	�����뤳�ȤȤ��뤬��Xlib �Ϥ��Τ褦�˼����Ǥ��Ƥ��ʤ���
1151  */
1152 Boolean
ximClient_onXimOpen(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)1153 ximClient_onXimOpen (
1154 	register Widget		gw,
1155 	register int		nMajorOpCode,
1156 	register int		nMinorOpCode,
1157 	register int		nLength,
1158 	register XIMData*	pData)
1159 {
1160 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
1161 	register XIMInputMethod*	pXimIm ;
1162 	register XIMPacket*			pPacket ;
1163 	register const char*		pLocaleString ;
1164 	register int				nID ;
1165 	register int				nKey ;
1166 	register int				nIndexOfByteLength, nValue ;
1167 	/*	�ǥե���Ȥ��Ѵ����ϥ�����*/
1168 	static const XIMHotKeyTrigger	triggerKey [] = {
1169 		{ XK_KP_Space,	ShiftMask,	ShiftMask },
1170 		{ XK_space,		ShiftMask,	ShiftMask },
1171 	} ;
1172 	register int				nHotKey ;
1173 	const XIMHotKeyTrigger*		pHotKey ;
1174 
1175 	/*
1176 	 *	(1) locale ̾����Ф���
1177 	 */
1178 	pLocaleString	= (const char*)XIMData_GetHead (pData) ;
1179 
1180 	/*
1181 	 *	(1.5) ���ݡ��Ȥ���Ƥ��� locale ���ɤ��������å����롣
1182 	 *	�����Ϥɤ�����٤�����
1183 	 */
1184 
1185 	/*
1186 	 *	(2) input-method-ID ���������ơ�IM ���롣
1187 	 */
1188 	pXimIm	= XIMInputMethod_Create (gw, wgThis->ximClient.m_uInputMethodID) ;
1189 	if (pXimIm == NULL) {
1190 		/*
1191 		 *	BadAlloc �ʤΤ��ʡ� ���꤬��­���Ƥ�����ˤϡġ�
1192 		 *	���λ��ͽ���ǤϤɤΥ��顼������Ū�˲���������٤��ʤΤ���Ƚ�Ǥ��Ǥ��ʤ��Τ���
1193 		 *	��ɤ��
1194 		 */
1195 		ximClient_writeErrorMessage (gw, -1, -1, XIM_ERROR_BadAlloc, "out of memory.") ;
1196 		return	True ;
1197 	}
1198 	ximClient_registerInputMethod (gw, pXimIm) ;
1199 
1200 	/*
1201 	 *	XIM_OPEN_REPLY Packet �� client �����롣
1202 	 *		XIM Protocol ���ͽ�Ȥ������ʤ����Ƥ����������ˤ��ȡ�
1203 	 *		��XIM_REGISTER_TRIGGERKEYS �� XIM_OPEN_REPLY ���������뤳�ȡ�
1204 	 *		�Ƚ���Ƥ��뤬��
1205 	 *		Xlib �� _XimOpen ����ȡ�_XimWrite �� XIM_OPEN �����ä����
1206 	 *		XIM_OPEN_REPLY �ʳ�����뤳�Ȥ�ͤ��Ƥ��ʤ��褦�Ǥ��롣
1207 	 *		(�ְ㤤�ʤ� Xlib �ΥХ�)
1208 	 *		�ǿ��ǤǤϤɤ��ʤäƤ���Τ�������
1209 	 */
1210 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
1211 	XIMPacket_SetHeader (pPacket, XIM_OPEN_REPLY, 0) ;
1212 	XIMPacket_AddCard16 (pPacket, wgThis->ximClient.m_uInputMethodID) ;
1213 
1214 	/*
1215 	 *	(3) ���ݡ��Ȥ��Ƥ��� IM Attribute ��ȴ���Ф���
1216 	 */
1217 	nIndexOfByteLength	= XIMPacket_GetDataSize (pPacket) ;
1218 	XIMPacket_AddCard16 (pPacket, 0 /* byte length of IM attributes supported */) ;
1219 	nID	= 0 ;
1220 	while (ximClient_putInputMethodAttribute (pPacket, nID))
1221 		nID	++ ;
1222 #if defined (DEBUG) || 0
1223 	fprintf (stderr, "InputMethod ... nID = %d\n", nID) ;
1224 #endif
1225 	nValue	= XIMPacket_GetDataSize (pPacket) - nIndexOfByteLength - 2 ;
1226 	XIMPacket_SetCard16 (pPacket, nIndexOfByteLength, nValue) ;
1227 
1228 	/*
1229 	 *	(4) ���ݡ��Ȥ��Ƥ��� IC Attribute ��ȴ���Ф���
1230 	 */
1231 	nIndexOfByteLength	= XIMPacket_GetDataSize (pPacket) ;
1232 	XIMPacket_AddCard16 (pPacket, 0 /* byte length of IC attributes supported */) ;
1233 	XIMPacket_AddCard16 (pPacket, 0 /* unused */) ;
1234 	nID	= 0 ;
1235 	while (ximClient_putInputContextAttribute (pPacket, nID))
1236 		nID	++ ;
1237 #if defined (DEBUG) || 0
1238 	fprintf (stderr, "InputContext ... nID = %d\n", nID) ;
1239 #endif
1240 	nValue	= XIMPacket_GetDataSize (pPacket) - nIndexOfByteLength - 2 - 2 ;
1241 	XIMPacket_SetCard16 (pPacket, nIndexOfByteLength, nValue) ;
1242 
1243 	/*
1244 	 *	(5) XIM_OPEN_REPLY �ѥ��åȤ��������ơ������֤���
1245 	 */
1246 	XIMPacket_SetLength (pPacket) ;
1247 	ximClient_writeMessage (gw, pPacket) ;
1248 	XIMPacket_Release (pPacket) ;
1249 
1250 	/*	XIM_REGISTER_TRIGGERKEYS �����롣
1251 	 *	�����ϲ������������� Trigger Key ���ѹ��ϤǤ��ʤ��ʤäƤ��롣
1252 	 */
1253 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
1254 	XIMPacket_SetHeader (pPacket, XIM_REGISTER_TRIGGERKEYS, 0) ;
1255 	XIMPacket_AddCard16 (pPacket, wgThis->ximClient.m_uInputMethodID) ;
1256 	XIMPacket_AddCard16 (pPacket, 0 /* unused */) ;
1257 
1258 	nHotKey	= XIMServer_GetConversionStartKey (wgThis->ximClient.m_wgProtocol, &pHotKey) ;
1259 	if (nHotKey <= 0) {
1260 		nHotKey	= NELEMENTS (triggerKey) ;
1261 		pHotKey	= triggerKey ;
1262 	}
1263 #if defined (DEBUG)
1264 	for (nKey = 0 ; nKey < nHotKey ; nKey ++) {
1265 		fprintf (stderr, "XIMHotKeyTrigger(%lx, %x)\n",
1266 				 pHotKey [nKey].keysym,
1267 				 pHotKey [nKey].modifier) ;
1268 	}
1269 #endif
1270 	/*	on-keys list */
1271 	XIMPacket_AddCard32 (pPacket, (CARD32)(sizeof (CARD32) * 3 * nHotKey)) ;
1272 	for (nKey = 0 ; nKey < nHotKey ; nKey ++)
1273 		ximClient_putTriggerKey (gw, pPacket, &pHotKey [nKey]) ;
1274 	/*
1275 	 *	off-keys list
1276 	 *	on-key �� off-key ��Ʊ�����ˤϡ�X library �ϥ���ư����ʤ�
1277 	 *	�ΤǵѲ��ġ�
1278 	 */
1279 	XIMPacket_AddCard32 (pPacket, (CARD32)0) ;
1280 	XIMPacket_SetLength (pPacket) ;
1281 	ximClient_writeMessage (gw, pPacket) ;
1282 	XIMPacket_Release (pPacket) ;
1283 
1284 	/*
1285 	 *	Input Method ID �� 1 ���䤹��
1286 	 */
1287 	wgThis->ximClient.m_uInputMethodID	++ ;
1288 	return	True ;
1289 }
1290 
1291 /*
1292  *(�ؿ�)
1293  *	virtual bool	OnXimTriggerNotify (int nMajorOpCode, int nMinorOpCode, int nLength, CXIMData* pData) ;
1294  *(������)
1295  *	�ȥꥬ�������������줿�����Ѵ����饤����Ȥ��������Ƥ����å�����
1296  *	(XIM_TRIGGER_NOTIFY)�ν����ؿ���
1297  *	���ξ�硢ON TRIGGER �� OFF TRIGGER ��������ˤʤ뤬�����ΤȤ���
1298  *	OnTrigger �������ꤨ�ʤ���
1299  *	OnTrigger ���褿���ˡ�UserInterface Window ��ɽ���������Ϥ����Ϥ���
1300  *	�롣
1301  */
1302 Boolean
ximClient_onXimTriggerNotify(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)1303 ximClient_onXimTriggerNotify (
1304 	register Widget		gw,
1305 	register int		nMajorOpCode,
1306 	register int		nMinorOpCode,
1307 	register int		nLength,
1308 	register XIMData*	pData)
1309 {
1310 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
1311 	register CARD16				wInputMethodID ;
1312 	register CARD16				wInputContextID ;
1313 	register XIMInputMethod*	pInputMethod ;
1314 	register XIMInputContext*	pInputContext ;
1315 	register CARD32				dwFlag ;
1316 	register CARD32				dwIndexOfKeyList ;
1317 	register CARD32				dwEventMask ;
1318 	register Boolean			fRetvalue ;
1319 	register Boolean			fStartForward ;
1320 
1321 	wInputMethodID	= XIMData_GetCard16 (pData) ;
1322 	wInputContextID	= XIMData_GetCard16 (pData) ;
1323 	pInputMethod	= ximClient_findInputMethod (gw, wInputMethodID) ;
1324 	if (pInputMethod == NULL)
1325 		return	True ;
1326 
1327 	pInputContext	= ximClient_findInputContext (gw, pInputMethod, wInputContextID) ;
1328 	if (pInputContext == NULL)
1329 		return	True ;
1330 
1331 	/*
1332 	 *	dwFlag
1333 	 *		#0	on-keys list
1334 	 *		#1	off-keys list
1335 	 *	dwIndexOfKeyList
1336 	 *		�����ꥹ�Ȥ���ΤɤΥ����������줿�Τ���
1337 	 *	dwEventMask
1338 	 *		Client �� XSelectInput ����Ƥ��� Event �����ꤹ��Ĥ��Ȥ�
1339 	 *		��ǽ�ǤϤ��뤬�����ˤɤ��Ȥ��Τ�������
1340 	 */
1341 	dwFlag				= XIMData_GetCard32 (pData) ;
1342 	dwIndexOfKeyList	= XIMData_GetCard32 (pData) ;
1343 	dwEventMask			= XIMData_GetCard32 (pData) ;
1344 
1345 	if (!dwFlag){
1346 		//	�ɤΥ����������ꤷ�ʤ����� on-key �ʤ���Ѵ�ư����Ϥ��롣
1347 		fRetvalue		= XIMInputContext_StartConversion (pInputContext) ;
1348 		fStartForward	= True ;
1349 	} else {
1350 		//	off-key �ʤ���Ѵ���ư�����ߤ��롣
1351 		fRetvalue		= XIMInputContext_EndConversion (pInputContext) ;
1352 		fStartForward	= False ;
1353 	}
1354 	if (!fRetvalue){
1355 		/*
1356 		 *	�Ѵ�ư�����or��ߤǤ��ʤ���С����顼���֤���
1357 		 */
1358 		ximClient_writeErrorMessage (gw, wInputMethodID, wInputContextID, XIM_ERROR_BadProtocol, "Conversion error") ;
1359 	} else {
1360 		register XIMPacket*	pPacket ;
1361 
1362 		pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
1363 
1364 		/*
1365 		 *	������ set-forward-event �äƤ����Τϡ�
1366 		 *	˺��Ƥ���ʤ��ġ�
1367 		 */
1368 		ximClient_setForwardEvent (gw, pInputMethod, pInputContext, fStartForward) ;
1369 
1370 		/*
1371 		 *	XIM_TRIGGER_NOTIFY_REPLY ��å��������饤����Ȥ��ꤲ�롣
1372 		 */
1373 		XIMPacket_SetHeader (pPacket, XIM_TRIGGER_NOTIFY_REPLY, 0) ;
1374 		XIMPacket_AddCard16 (pPacket, wInputMethodID) ;
1375 		XIMPacket_AddCard16 (pPacket, wInputContextID) ;
1376 		XIMPacket_SetLength (pPacket) ;
1377 		ximClient_writeMessage (gw, pPacket) ;
1378 		XIMPacket_Release (pPacket) ;
1379 	}
1380 	return	True ;
1381 }
1382 
1383 /*
1384  *(�ؿ�)
1385  */
1386 Boolean
ximClient_onXimEncodingNegotiation(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)1387 ximClient_onXimEncodingNegotiation (
1388 	register Widget		gw,
1389 	register int		nMajorOpCode,
1390 	register int		nMinorOpCode,
1391 	register int		nLength,
1392 	register XIMData*	pData)
1393 {
1394 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
1395 	register CARD16				wInputMethodID ;
1396 	register XIMInputMethod*	pInputMethod ;
1397 	register XIMPacket*			pPacket ;
1398 	register int				nByteLengthOfEncoding ;
1399 	register int				nLenEncoding ;
1400 	register const char*		pStrEncoding ;
1401 	register int				nEncodingIndex ;
1402 	register int				nCodingSystem ;
1403 
1404 	/*
1405 	 *	������ input-method id ���ɤ���������å����롣
1406 	 *	������ input-method id �������ͳ�� input-method ��� encoding ��ˡ�����٤�
1407 	 *	�褦�ˤ������ä�����ʤ�Ǥ��礦�ͤ��ġ�
1408 	 *	ï�⤽��ʤ��Ȥ��Ƥ�����ä��ߤ��������ɡ�(^^;;
1409 	 *	1 Application 1 InputMethod �Ǥ����ʤ��ä��äƤΤϡ��ޤ��˳����������ߤ��ä���
1410 	 *	�Ƥ��ȤʤΤ��ʡ�
1411 	 *	�Ȥ⤢�� COMPOUND_TEXT ���������Фϼ������Ƥ��ʤ��Τǡ�input-method ¦��
1412 	 *	encoding �������äƤ���ɬ�פʤ���
1413 	 */
1414 	wInputMethodID	= XIMData_GetCard16 (pData) ;
1415 	pInputMethod	= ximClient_findInputMethod (gw, wInputMethodID) ;
1416 	if (pInputMethod == NULL)
1417 		return	True ;
1418 
1419 	nByteLengthOfEncoding	= (int)XIMData_GetCard16 (pData) ;
1420 	nEncodingIndex	= -1 ;
1421 	nCodingSystem	= -1 ;
1422 	if (nByteLengthOfEncoding > 0){
1423 		register int	nEncoding ;
1424 		nEncoding	= 0 ;
1425 		while (nByteLengthOfEncoding > 0){
1426 			nLenEncoding	= XIMData_GetCard8 (pData) ;
1427 			nByteLengthOfEncoding	-- ;
1428 			if (nByteLengthOfEncoding < nLenEncoding){
1429 				ximClient_writeErrorMessage (gw, wInputMethodID, -1, XIM_ERROR_BadProtocol, "Lack of data.") ;
1430 				return	True ;
1431 			}
1432 			pStrEncoding	= (const char*)XIMData_GetHead (pData) ;
1433 #if defined (DEBUG)
1434 			{
1435 				TVarbuffer	vbufMsg ;
1436 				TVarbuffer_Initialize (&vbufMsg, sizeof (char)) ;
1437 				TVarbuffer_Add (&vbufMsg, pStrEncoding, nLenEncoding) ;
1438 				TVarbuffer_Add (&vbufMsg, "", 1) ;	/* NUL ��ɬ�ס�*/
1439 				fprintf (stderr, "OnXimEncodingNegotitation: \"%s\".\n",
1440 						 (const char*)TVarbuffer_GetBuffer (&vbufMsg)) ;
1441 				TVarbuffer_Uninitialize (&vbufMsg) ;
1442 			}
1443 #endif
1444 			/*
1445 			 *	��괺�������ݡ��Ȥ��Ƥ�����沽��ˡ�� COMPOUND_TEXT �Τߡ�Xlib �⤽�Τ褦����
1446 			 *	���ȡ�STR �� STRING �� NUL Terminate ����Ƥ��ʤ��Ȼפ���
1447 			 */
1448 			nCodingSystem	= ximClient_supportedEncodingp (pStrEncoding, nLenEncoding) ;
1449 			if (nCodingSystem >= 0 &&
1450 				XIMInputMethod_SetCodingSystem (pInputMethod, nCodingSystem)) {
1451 				nEncodingIndex	= nEncoding ;
1452 				if (nCodingSystem == KCODING_SYSTEM_COMPOUND_TEXT)
1453 					break ;
1454 			}
1455 			XIMData_Forward8 (pData, nLenEncoding) ;
1456 			nByteLengthOfEncoding	-= nLenEncoding ;
1457 			nEncoding	++ ;
1458 		}
1459 	}
1460 
1461 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
1462 	XIMPacket_SetHeader (pPacket, XIM_ENCODING_NEGOTIATION_REPLY, 0) ;
1463 	XIMPacket_AddCard16 (pPacket, wInputMethodID) ;
1464 	/* ���ߤμ����Ǥ� detailed information ��¸�ߤ��ʤ��Τǡ�ɬ�� #0 �Ȥʤ롣*/
1465 	XIMPacket_AddCard16 (pPacket, 0) ;
1466 	XIMPacket_AddCard16 (pPacket, nEncodingIndex) ;
1467 	XIMPacket_AddCard16 (pPacket, 0) ;		/* unused */
1468 	XIMPacket_SetLength (pPacket) ;
1469 	ximClient_writeMessage (gw, pPacket) ;
1470 	XIMPacket_Release (pPacket) ;
1471 	return	True ;
1472 }
1473 
1474 /*
1475  *(������)
1476  *	EXTENSION �Ȥ��Ƽ��������٤���Τ� X library ����¤�ˤ����ơ�
1477  *		"XIM_EXT_SET_EVENT_MASK",
1478  *		"XIM_EXT_FORWARD_KEYEVENT",
1479  *		"XIM_EXT_MOVE"
1480  *	��3����Τ褦����
1481  */
1482 Boolean
ximClient_onXimQueryExtension(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)1483 ximClient_onXimQueryExtension (
1484 	register Widget		gw,
1485 	register int		nMajorOpCode,
1486 	register int		nMinorOpCode,
1487 	register int		nLength,
1488 	register XIMData*	pData)
1489 {
1490 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
1491 	register CARD16				wInputMethodID ;
1492 	register XIMInputMethod*	pInputMethod ;
1493 	register XIMPacket*			pPacket ;
1494 	static const char*			pExtensions [] = {
1495 		"XIM_EXT_SET_EVENT_MASK", "XIM_EXT_FORWARD_KEYEVENT", "XIM_EXT_MOVE", 0,
1496 	} ;
1497 	register int				nByteLengthIndex ;
1498 	register int				nExtensions ;
1499 	register int				nByteLengthOfExt ;
1500 	register const char*		pExtString ;
1501 	register int				nExtStrLength ;
1502 	register unsigned int		uMask ;
1503 	register int				nExtPktSize ;
1504 
1505 	/*
1506 	 *	������ input-method id ���ɤ���������å����롣
1507 	 */
1508 	wInputMethodID	= XIMData_GetCard16 (pData) ;
1509 	pInputMethod	= ximClient_findInputMethod (gw, wInputMethodID) ;
1510 	if (pInputMethod == NULL)
1511 		return	True ;
1512 
1513 	nByteLengthOfExt	= XIMData_GetCard16 (pData) ;
1514 
1515 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
1516 	XIMPacket_SetHeader (pPacket, XIM_QUERY_EXTENSION_REPLY, 0) ;
1517 	XIMPacket_AddCard16 (pPacket, wInputMethodID) ;
1518 	nByteLengthIndex	= XIMPacket_GetDataSize (pPacket) ;
1519 	XIMPacket_AddCard16 (pPacket, 0 /* dummy */) ;
1520 
1521 	/*
1522 	 *	�Ҥͤ�٤� EXTENSION �������ä����ˤϥ����Ф����ݡ��Ȥ��Ƥ����
1523 	 *	���������֤��ʤ���Фʤ�ʤ���
1524 	 *	�����Ǥʤ���С����饤����Ȥ����ä��褿��Τ���Ӥ��Ƽ�ʬ�ȥ���
1525 	 *	������Ȥ�ξ�������ݡ��Ȥ��Ƥ����Τ��֤���
1526 	 */
1527 	if (!nByteLengthOfExt){
1528 		for (nExtensions = 0 ; pExtensions [nExtensions] ; nExtensions ++){
1529 			XIMPacket_AddCard8   (pPacket, XIM_EXT_SET_EVENT_MASK + nExtensions) ;
1530 			XIMPacket_AddCard8   (pPacket, 0) ;
1531 			nExtStrLength	= strlen (pExtensions [nExtensions]) ;
1532 			XIMPacket_AddCard16  (pPacket, nExtStrLength) ;
1533 			XIMPacket_AddString8 (pPacket, pExtensions [nExtensions], nExtStrLength) ;
1534 			XIMPacket_AddPad     (pPacket, nExtStrLength) ;
1535 		}
1536 		/*	���Ѳ�ǽ�� Extension �������Ƥ�����*/
1537 		uMask	= XIM_EXT_SET_EVENT_MASK_MASK | XIM_EXT_FORWARD_KEYEVENT_MASK | XIM_EXT_MOVE_MASK ;
1538 		XIMInputMethod_SetExtMask (pInputMethod, uMask) ;
1539 	} else {
1540 		uMask	= XIMInputMethod_GetExtMask (pInputMethod) ;
1541 		while (nByteLengthOfExt > 0){
1542 			nExtStrLength	= XIMData_GetCard8 (pData) ;
1543 			pExtString		= (const char*)XIMData_GetHead (pData) ;
1544 			for (nExtensions = 0 ; pExtensions [nExtensions] ; nExtensions ++){
1545 				if (!strncmp (pExtString, pExtensions [nExtensions], nExtStrLength)){
1546 #if defined (DEBUG) || 0
1547 					fprintf (stderr, "Extension: \"%s\"/(%d)\n", pExtensions [nExtensions], nExtStrLength) ;
1548 #endif
1549 					XIMPacket_AddCard8   (pPacket, XIM_EXT_SET_EVENT_MASK + nExtensions) ;
1550 					XIMPacket_AddCard8   (pPacket, 0) ;
1551 					XIMPacket_AddCard16  (pPacket, nExtStrLength) ;
1552 					XIMPacket_AddString8 (pPacket, pExtString, nExtStrLength) ;
1553 					XIMPacket_AddPad     (pPacket, nExtStrLength) ;
1554 					//	���Ѳ�ǽ�� Extension �������Ƥ�����
1555 					uMask	|= (unsigned int)1 << nExtensions ;
1556 				}
1557 			}
1558 			XIMData_Forward8 (pData, nExtStrLength) ;
1559 			nByteLengthOfExt	-= (nExtStrLength + 1) ;
1560 		}
1561 		XIMInputMethod_SetExtMask (pInputMethod, uMask) ;
1562 	}
1563 
1564 	nExtPktSize	= XIMPacket_GetDataSize (pPacket) - nByteLengthIndex - 2 ;
1565 	XIMPacket_SetCard16 (pPacket, nByteLengthIndex, nExtPktSize) ;
1566 	XIMPacket_SetLength (pPacket) ;
1567 	ximClient_writeMessage (gw, pPacket) ;
1568 	XIMPacket_Release (pPacket) ;
1569 	return	True ;
1570 }
1571 
1572 /*
1573  *
1574  */
1575 Boolean
ximClient_onXimSetImValues(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)1576 ximClient_onXimSetImValues (
1577 	register Widget		gw,
1578 	register int		nMajorOpCode,
1579 	register int		nMinorOpCode,
1580 	register int		nLength,
1581 	register XIMData*	pData)
1582 {
1583 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
1584 	register CARD16				wInputMethodID ;
1585 	register XIMInputMethod*	pInputMethod ;
1586 	register XIMPacket*			pPacket ;
1587 	register XIMAttribute*		pAttribute ;
1588 	register int			nByteLengthOfImAttribute ;
1589 	register int			wAttributeID ;
1590 	register int			nValueLength ;
1591 
1592 	/*
1593 	 *	������ input-method id ���ɤ���������å����롣
1594 	 */
1595 	wInputMethodID	= XIMData_GetCard16 (pData) ;
1596 	pInputMethod	= ximClient_findInputMethod (gw,wInputMethodID) ;
1597 	if (pInputMethod == NULL)
1598 		return	True ;
1599 
1600 	nByteLengthOfImAttribute	= XIMData_GetCard16 (pData) ;
1601 	if (nByteLengthOfImAttribute > 0){
1602 		while (nByteLengthOfImAttribute > 0){
1603 			if (nByteLengthOfImAttribute < (int)((sizeof (CARD16) + sizeof (CARD16)) / sizeof (CARD8))){
1604 				ximClient_writeErrorMessage (gw, wInputMethodID, -1, XIM_ERROR_BadProtocol, "Lack of im-value.") ;
1605 				return	True ;
1606 			}
1607 			wAttributeID		= XIMData_GetCard16 (pData) ;
1608 			nValueLength		= XIMData_GetCard16 (pData) ;
1609 			nByteLengthOfImAttribute	-= (sizeof (CARD16) + sizeof (CARD16)) / sizeof (CARD8) ;
1610 			if (nValueLength <= 0){
1611 				XIMData_Forward8 (pData, IMPAD (nValueLength)) ;
1612 				continue ;
1613 			}
1614 			if (nByteLengthOfImAttribute < nValueLength){
1615 				ximClient_writeErrorMessage (gw, wInputMethodID, -1, XIM_ERROR_BadProtocol, "Lack of im-value.") ;
1616 				return	True ;
1617 			}
1618 			/*	wAttributeID �� nValueLength��pData ���� value ����Фäƥǥ�����
1619 			 *	���Ʋ�������(�羸)
1620 			 */
1621 			if (wAttributeID < 0 || wAttributeID >= MAX_NUMBER_OF_XIM_ATTRIBUTEID){
1622 				ximClient_writeErrorMessage (gw, wInputMethodID, -1, XIM_ERROR_BadProtocol, "Invalid Attribute-ID.") ;
1623 				return	True ;
1624 			}
1625 
1626 			pAttribute		= &srSupportedInputMethodAttributes [wAttributeID] ;
1627 			if (pAttribute->m_pSetter == NULL){
1628 				/*
1629 				 *	����Ǥ��ʤ��ͤ����ꤷ�褦�Ȥ������ˤ��������顼�Ȥʤ�ĤΤ���
1630 				 *	�ɤ��ͤ�����Ǥ��뤫�⤷��ʤ���������Ǥ��ʤ����⤷��ʤ���
1631 				 *	����� IM Server ���������¦�������˷����ɤ��ĤȻפ������ʤ��褦����
1632 				 */
1633 				ximClient_writeErrorMessage (gw, wInputMethodID, -1, XIM_ERROR_BadProtocol, "Operation: SetImValue is not permitted.") ;
1634 				return	True ;
1635 			}
1636 			if (!(pAttribute->m_pSetter)(gw, pInputMethod, 0, pData, nValueLength, 0))
1637 				return	True ;
1638 			XIMData_Forward8 (pData, IMPAD (nValueLength)) ;
1639 		}
1640 	}
1641 
1642 	/*
1643 	 *	XIM_ERROR �������Ƥ�����ˤ� XIM_SET_IM_VALUES_REPLY ������ɬ�פ�̵�������ġ�
1644 	 */
1645 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
1646 	XIMPacket_SetHeader (pPacket, XIM_SET_IM_VALUES_REPLY, 0) ;
1647 	XIMPacket_AddCard16 (pPacket, wInputMethodID) ;
1648 	XIMPacket_AddCard16 (pPacket, 0 /* unused */) ;
1649 	XIMPacket_SetLength (pPacket) ;
1650 	ximClient_writeMessage (gw, pPacket) ;
1651 	XIMPacket_Release (pPacket) ;
1652 	return	True ;
1653 }
1654 
1655 Boolean
ximClient_onXimGetImValues(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)1656 ximClient_onXimGetImValues (
1657 	register Widget		gw,
1658 	register int		nMajorOpCode,
1659 	register int		nMinorOpCode,
1660 	register int		nLength,
1661 	register XIMData*	pData)
1662 {
1663 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
1664 	register CARD16				wInputMethodID ;
1665 	register XIMInputMethod*	pInputMethod ;
1666 	register XIMPacket*			pPacket ;
1667 	register XIMAttribute*		pAttribute ;
1668 	register int				nIndexByteLengthOfImAttributeList ;
1669 	register int				wAttributeID ;
1670 	int							nByteLengthOfImAttribute ;
1671 	register int				nByteLength ;
1672 
1673 	/*
1674 	 *	������ input-method id ���ɤ���������å����롣
1675 	 */
1676 	wInputMethodID	= XIMData_GetCard16 (pData) ;
1677 	pInputMethod	= ximClient_findInputMethod (gw, wInputMethodID) ;
1678 	if (pInputMethod == NULL)
1679 		return	True ;
1680 
1681 	nByteLengthOfImAttribute	= XIMData_GetCard16 (pData) ;
1682 
1683 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
1684 	XIMPacket_SetHeader (pPacket, XIM_GET_IM_VALUES_REPLY, 0) ;
1685 	XIMPacket_AddCard16 (pPacket, wInputMethodID) ;
1686 	nIndexByteLengthOfImAttributeList	= XIMPacket_GetDataSize (pPacket) ;
1687 	XIMPacket_AddCard16 (pPacket, 0 /* Dummy */) ;
1688 
1689 	if (nByteLengthOfImAttribute > 0){
1690 		while (nByteLengthOfImAttribute > 0){
1691 			if (nByteLengthOfImAttribute < (int)(sizeof (CARD16) / sizeof (CARD8))){
1692 				ximClient_writeErrorMessage (gw, wInputMethodID, -1, XIM_ERROR_BadProtocol, "Lack of im-attribute.") ;
1693 				goto	exit_func ;
1694 			}
1695 			wAttributeID		= XIMData_GetCard16 (pData) ;
1696 			nByteLengthOfImAttribute	-= sizeof (CARD16) / sizeof (CARD8) ;
1697 			if (wAttributeID < 0 || wAttributeID >= MAX_NUMBER_OF_XIM_ATTRIBUTEID){
1698 				ximClient_writeErrorMessage (gw, wInputMethodID, -1, XIM_ERROR_BadProtocol, "Invalid attribute-ID.") ;
1699 				goto	exit_func ;
1700 			}
1701 			pAttribute	= &srSupportedInputMethodAttributes [wAttributeID] ;
1702 			if (pAttribute->m_pGetter == NULL){
1703 				/*
1704 				 *	�����Ǥ��ʤ��ͤ����褦�Ȥ������ˤ��������顼�Ȥʤ�ĤΤ���
1705 				 */
1706 				ximClient_writeErrorMessage (gw, wInputMethodID, -1, XIM_ERROR_BadProtocol, "Operation: GetImValue is not permitted.") ;
1707 				goto	exit_func ;
1708 			}
1709 			if (!(pAttribute->m_pGetter)(gw, pInputMethod, 0, pData, &nByteLengthOfImAttribute, 0, pPacket))
1710 				goto	exit_func ;
1711 		}
1712 	}
1713 	nByteLength	= XIMPacket_GetDataSize (pPacket) - (nIndexByteLengthOfImAttributeList + sizeof (CARD16)) ;
1714 	XIMPacket_SetCard16 (pPacket, nIndexByteLengthOfImAttributeList, nByteLength) ;
1715 	XIMPacket_SetLength (pPacket) ;
1716 	ximClient_writeMessage (gw, pPacket) ;
1717   exit_func:
1718 	XIMPacket_Release (pPacket) ;
1719 	return	True ;
1720 }
1721 
1722 Boolean
ximClient_onXimCreateIc(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)1723 ximClient_onXimCreateIc (
1724 	register Widget		gw,
1725 	register int		nMajorOpCode,
1726 	register int		nMinorOpCode,
1727 	register int		nLength,
1728 	register XIMData*	pData)
1729 {
1730 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
1731 	register CARD16				wInputMethodID ;
1732 	register XIMInputMethod*	pInputMethod ;
1733 	register XIMInputContext*	pInputContext ;
1734 	register XIMPacket*			pPacket ;
1735 	register int				nByteLengthOfIcAttribute ;
1736 
1737 	/*
1738 	 *	������ input-method id ���ɤ���������å����롣
1739 	 */
1740 	wInputMethodID	= XIMData_GetCard16 (pData) ;
1741 	pInputMethod	= ximClient_findInputMethod (gw,wInputMethodID) ;
1742 	if (pInputMethod == NULL)
1743 		return	True ;
1744 
1745 	/*	input-context ��������롣*/
1746 	pInputContext				= XIMInputMethod_CreateInputContext (pInputMethod) ;
1747 	nByteLengthOfIcAttribute	= XIMData_GetCard16 (pData) ;
1748 	/*	XIM_CREATE_IC ���Ϥ���Ƥ��� ic-attribute �����ꤹ�롣*/
1749 	if (nByteLengthOfIcAttribute > 0 &&
1750 		!ximClient_setIcValues (gw, pInputMethod, pInputContext, pData, nByteLengthOfIcAttribute, XIC_CREATE_MASK)){
1751 		/*	�Թ��ˤ��ƥ��顼��ȯ���������ˤ� input-context ���˴����롣*/
1752 		XIMInputMethod_DestroyInputContext (pInputMethod, pInputContext) ;
1753 		return	True ;
1754 	}
1755 
1756 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
1757 	XIMPacket_SetHeader (pPacket, XIM_CREATE_IC_REPLY, 0) ;
1758 	XIMPacket_AddCard16 (pPacket, wInputMethodID) ;
1759 	XIMPacket_AddCard16 (pPacket, XIMInputContext_GetID (pInputContext)) ;
1760 	XIMPacket_SetLength (pPacket) ;
1761 	ximClient_writeMessage (gw, pPacket) ;
1762 	XIMPacket_Release (pPacket) ;
1763 	return	True ;
1764 }
1765 
1766 Boolean
ximClient_onXimSetIcValues(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)1767 ximClient_onXimSetIcValues (
1768 	register Widget		gw,
1769 	register int		nMajorOpCode,
1770 	register int		nMinorOpCode,
1771 	register int		nLength,
1772 	register XIMData*	pData)
1773 {
1774 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
1775 	register CARD16				wInputMethodID ;
1776 	register CARD16				wInputContextID ;
1777 	register XIMInputMethod*	pInputMethod ;
1778 	register XIMInputContext*	pInputContext ;
1779 	register XIMPacket*			pPacket ;
1780 	register int				nByteLengthOfIcAttribute ;
1781 
1782 	/*
1783 	 *	������ input-method id ���ɤ���������å����롣
1784 	 */
1785 	wInputMethodID	= XIMData_GetCard16 (pData) ;
1786 	pInputMethod	= ximClient_findInputMethod (gw, wInputMethodID) ;
1787 	if (pInputMethod == NULL)
1788 		return	True ;
1789 
1790 	/*	������ input-context id ���ɤ���������å����롣*/
1791 	wInputContextID	= XIMData_GetCard16 (pData) ;
1792 	pInputContext	= ximClient_findInputContext (gw, pInputMethod, wInputContextID) ;
1793 	if (pInputContext == NULL)
1794 		return	True ;
1795 
1796 	/*	byte length of ic-attribute ���ɤ߼�롣*/
1797 	nByteLengthOfIcAttribute	= XIMData_GetCard16 (pData) ;
1798 	/*	unused ���ɤ����Ф���*/
1799 	XIMData_Forward8 (pData, 2) ;
1800 	/*	XIM_CREATE_IC ���Ϥ���Ƥ��� ic-attribute �����ꤹ�롣*/
1801 	if (nByteLengthOfIcAttribute > 0 &&
1802 		!ximClient_setIcValues (gw, pInputMethod, pInputContext, pData, nByteLengthOfIcAttribute, 0)) {
1803 		return	True ;
1804 	}
1805 
1806 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
1807 	XIMPacket_SetHeader (pPacket, XIM_SET_IC_VALUES_REPLY, 0) ;
1808 	XIMPacket_AddCard16 (pPacket, wInputMethodID) ;
1809 	XIMPacket_AddCard16 (pPacket, XIMInputContext_GetID (pInputContext)) ;
1810 	XIMPacket_SetLength (pPacket) ;
1811 	ximClient_writeMessage (gw, pPacket) ;
1812 	XIMPacket_Release (pPacket) ;
1813 	return	True ;
1814 }
1815 
1816 Boolean
ximClient_onXimGetIcValues(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)1817 ximClient_onXimGetIcValues (
1818 	register Widget		gw,
1819 	register int		nMajorOpCode,
1820 	register int		nMinorOpCode,
1821 	register int		nLength,
1822 	register XIMData*	pData)
1823 {
1824 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
1825 	register CARD16				wInputMethodID ;
1826 	register CARD16				wInputContextID ;
1827 	register XIMInputMethod*	pInputMethod ;
1828 	register XIMInputContext*	pInputContext ;
1829 	register XIMPacket*			pPacket ;
1830 	int							nByteLengthOfIcAttribute ;
1831 	register int				nIndexOfByteLength ;
1832 	register int				nBodySize ;
1833 
1834 	/*
1835 	 *	������ input-method id ���ɤ���������å����롣
1836 	 */
1837 	wInputMethodID	= XIMData_GetCard16 (pData) ;
1838 	pInputMethod	= ximClient_findInputMethod (gw, wInputMethodID) ;
1839 	if (pInputMethod == NULL)
1840 		return	True ;
1841 
1842 	/*	������ input-context id ���ɤ���������å����롣*/
1843 	wInputContextID	= XIMData_GetCard16 (pData) ;
1844 	pInputContext	= ximClient_findInputContext (gw, pInputMethod, wInputContextID) ;
1845 	if (pInputContext == NULL)
1846 		return	True ;
1847 
1848 	nByteLengthOfIcAttribute	= XIMData_GetCard16 (pData) ;
1849 
1850 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
1851 	XIMPacket_SetHeader (pPacket, XIM_GET_IC_VALUES_REPLY, 0) ;
1852 	XIMPacket_AddCard16 (pPacket, wInputMethodID) ;
1853 	XIMPacket_AddCard16 (pPacket, wInputContextID) ;
1854 	nIndexOfByteLength	= XIMPacket_GetDataSize (pPacket) ;
1855 	XIMPacket_AddCard16 (pPacket, 0 /* Byte length of ic-attributes */) ;
1856 	XIMPacket_AddCard16 (pPacket, 0 /* unused */) ;
1857 	/*	XIM_CREATE_IC ���Ϥ���Ƥ��� ic-attribute �����ꤹ�롣*/
1858 	if (nByteLengthOfIcAttribute > 0 &&
1859 		!ximClient_getIcValues (gw, pInputMethod, pInputContext, pData, &nByteLengthOfIcAttribute, 0, pPacket))
1860 		goto	exit_func ;
1861 	nBodySize	= XIMPacket_GetDataSize (pPacket) - nIndexOfByteLength - (sizeof (CARD16) + sizeof (CARD16)) / sizeof (CARD8) ;
1862 	XIMPacket_SetCard16 (pPacket, nIndexOfByteLength, nBodySize) ;
1863 	XIMPacket_SetLength (pPacket) ;
1864 	ximClient_writeMessage (gw, pPacket) ;
1865   exit_func:
1866 	XIMPacket_Release (pPacket) ;
1867 	return	True ;
1868 }
1869 
1870 Boolean
ximClient_onXimSetIcFocus(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)1871 ximClient_onXimSetIcFocus (
1872 	register Widget		gw,
1873 	register int		nMajorOpCode,
1874 	register int		nMinorOpCode,
1875 	register int		nLength,
1876 	register XIMData*	pData)
1877 {
1878 	register CARD16				wInputMethodID ;
1879 	register CARD16				wInputContextID ;
1880 	register XIMInputMethod*	pInputMethod ;
1881 	register XIMInputContext*	pInputContext ;
1882 
1883 	/*
1884 	 *	������ input-method id ���ɤ���������å����롣
1885 	 */
1886 	wInputMethodID	= XIMData_GetCard16 (pData) ;
1887 	pInputMethod	= ximClient_findInputMethod (gw, wInputMethodID) ;
1888 	if (pInputMethod == NULL)
1889 		return	True ;
1890 
1891 	/*	������ input-context id ���ɤ���������å����롣*/
1892 	wInputContextID	= XIMData_GetCard16 (pData) ;
1893 	pInputContext	= ximClient_findInputContext (gw, pInputMethod, wInputContextID) ;
1894 	if (pInputContext == NULL)
1895 		return	True ;
1896 
1897 	XIMInputContext_SetFocus (pInputContext) ;
1898 	/*	Asyncronous request �ʤΤ� Reply Message �Ϥʤ���*/
1899 	return	True ;
1900 }
1901 
1902 Boolean
ximClient_onXimUnsetIcFocus(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)1903 ximClient_onXimUnsetIcFocus (
1904 	register Widget		gw,
1905 	register int		nMajorOpCode,
1906 	register int		nMinorOpCode,
1907 	register int		nLength,
1908 	register XIMData*	pData)
1909 {
1910 	register CARD16				wInputMethodID ;
1911 	register CARD16				wInputContextID ;
1912 	register XIMInputMethod*	pInputMethod ;
1913 	register XIMInputContext*	pInputContext ;
1914 
1915 	/*
1916 	 *	������ input-method id ���ɤ���������å����롣
1917 	 */
1918 	wInputMethodID	= XIMData_GetCard16 (pData) ;
1919 	pInputMethod	= ximClient_findInputMethod (gw, wInputMethodID) ;
1920 	if (pInputMethod == NULL)
1921 		return	True ;
1922 
1923 	/*	������ input-context id ���ɤ���������å����롣*/
1924 	wInputContextID	= XIMData_GetCard16 (pData) ;
1925 	pInputContext	= ximClient_findInputContext (gw, pInputMethod, wInputContextID) ;
1926 	if (pInputContext == NULL)
1927 		return	True ;
1928 
1929 	XIMInputContext_UnsetFocus (pInputContext) ;
1930 	/*	Asyncronous request �ʤΤ� Reply Message �Ϥʤ���*/
1931 	return	True ;
1932 }
1933 
1934 Boolean
ximClient_onXimDestroyIc(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)1935 ximClient_onXimDestroyIc (
1936 	register Widget		gw,
1937 	register int		nMajorOpCode,
1938 	register int		nMinorOpCode,
1939 	register int		nLength,
1940 	register XIMData*	pData)
1941 {
1942 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
1943 	register CARD16				wInputMethodID ;
1944 	register CARD16				wInputContextID ;
1945 	register XIMInputMethod*	pInputMethod ;
1946 	register XIMInputContext*	pInputContext ;
1947 	register XIMPacket*			pPacket ;
1948 
1949 	/*
1950 	 *	������ input-method id ���ɤ���������å����롣
1951 	 */
1952 	wInputMethodID	= XIMData_GetCard16 (pData) ;
1953 	pInputMethod	= ximClient_findInputMethod (gw, wInputMethodID) ;
1954 	if (pInputMethod == NULL)
1955 		return	True ;
1956 
1957 	/*
1958 	 *	������ input-context id ���ɤ���������å����롣
1959 	 */
1960 	wInputContextID	= XIMData_GetCard16 (pData) ;
1961 	pInputContext	= ximClient_findInputContext (gw, pInputMethod, wInputContextID) ;
1962 	if (pInputContext == NULL)
1963 		return	True ;
1964 
1965 	/*	ľ�� XIMInputContext_Destroy ��ƤӽФ��ƤϤ����ʤ���*/
1966 	XIMInputMethod_DestroyInputContext (pInputMethod, pInputContext) ;
1967 
1968 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
1969 	XIMPacket_SetHeader (pPacket, XIM_DESTROY_IC_REPLY, 0) ;
1970 	XIMPacket_AddCard16 (pPacket, wInputMethodID) ;
1971 	XIMPacket_AddCard16 (pPacket, wInputContextID) ;
1972 	XIMPacket_SetLength (pPacket) ;
1973 	ximClient_writeMessage (gw, pPacket) ;
1974 	XIMPacket_Release (pPacket) ;
1975 	return	True ;
1976 }
1977 
1978 Boolean
ximClient_onXimResetIc(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)1979 ximClient_onXimResetIc (
1980 	register Widget		gw,
1981 	register int		nMajorOpCode,
1982 	register int		nMinorOpCode,
1983 	register int		nLength,
1984 	register XIMData*	pData)
1985 {
1986 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
1987 	register CARD16				wInputMethodID ;
1988 	register CARD16				wInputContextID ;
1989 	register XIMInputMethod*	pInputMethod ;
1990 	register XIMInputContext*	pInputContext ;
1991 	register XIMPacket*			pPacket ;
1992 	register int				nTextLength	= 0 ;
1993 
1994 	/*
1995 	 *	������ input-method id ���ɤ���������å����롣
1996 	 */
1997 	wInputMethodID	= XIMData_GetCard16 (pData) ;
1998 	pInputMethod	= ximClient_findInputMethod (gw,wInputMethodID) ;
1999 	if (pInputMethod == NULL)
2000 		return	True ;
2001 
2002 	/*	������ input-context id ���ɤ���������å����롣*/
2003 	wInputContextID	= XIMData_GetCard16 (pData) ;
2004 	pInputContext	= ximClient_findInputContext (gw, pInputMethod, wInputContextID) ;
2005 	if (pInputContext == NULL)
2006 		return	True ;
2007 
2008 	/*
2009 	 *	���ߤޤ����Ϥ���Ƥ���ʸ��������륤�����ե�����������Τ�����
2010 	 *	����ɬ�פϤ���Τ��� ���μ������ȡ�������������ʸ��������
2011 	 *	��ΤϿɤ���(���ä��ˤϤ��ä����Թ礬����Ȥ�����ĤǤ���)
2012 	 */
2013 	XIMInputContext_ResetConversion (pInputContext) ;
2014 
2015 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
2016 	XIMPacket_SetHeader (pPacket, XIM_RESET_IC_REPLY, 0) ;
2017 	XIMPacket_AddCard16 (pPacket, wInputMethodID) ;
2018 	XIMPacket_AddCard16 (pPacket, wInputContextID) ;
2019 	XIMPacket_AddCard16 (pPacket, nTextLength) ;
2020 	XIMPacket_AddPad (pPacket, 2 + nTextLength) ;
2021 	XIMPacket_SetLength (pPacket) ;
2022 	ximClient_writeMessage (gw, pPacket) ;
2023 	XIMPacket_Release (pPacket) ;
2024 	return	True ;
2025 }
2026 
2027 Boolean
ximClient_onXimForwardEvent(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)2028 ximClient_onXimForwardEvent (
2029 	register Widget		gw,
2030 	register int		nMajorOpCode,
2031 	register int		nMinorOpCode,
2032 	register int		nLength,
2033 	register XIMData*	pData)
2034 {
2035 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
2036 	register CARD16				wInputMethodID ;
2037 	register CARD16				wInputContextID ;
2038 	register CARD16				wFlag ;
2039 	register CARD16				wSerialNumber ;
2040 	register XIMInputMethod*	pInputMethod ;
2041 	register XIMInputContext*	pInputContext ;
2042 	XEvent		xev ;
2043 
2044 	/*
2045 	 *	������ input-method id ���ɤ���������å����롣
2046 	 */
2047 	wInputMethodID	= XIMData_GetCard16 (pData) ;
2048 	pInputMethod	= ximClient_findInputMethod (gw,wInputMethodID) ;
2049 	if (pInputMethod == NULL)
2050 		return	True ;
2051 
2052 	/*	������ input-context id ���ɤ���������å����롣*/
2053 	wInputContextID	= XIMData_GetCard16 (pData) ;
2054 	pInputContext	= ximClient_findInputContext (gw, pInputMethod, wInputContextID) ;
2055 	if (pInputContext == NULL)
2056 		return	True ;
2057 
2058 	wFlag			= XIMData_GetCard16 (pData) ;
2059 	wSerialNumber	= XIMData_GetCard16 (pData) ;
2060 
2061 	if (wFlag & FORWARDEVENT_SYNC_MASK) {
2062 #if defined (DEBUG) || 0
2063 		fprintf (stderr, "[Begin] Client-Sync-Mode\n") ;
2064 #endif
2065 		XIMInputContext_SetSyncMode (pInputContext, XIMClientSync) ;
2066 	}
2067 
2068 	/*	xEvent ��¤�Τ��� XEvent ��¤�Τ˥ǡ�����ͤ�ľ����*/
2069 	if (ximClient_createXEvent (gw, wSerialNumber, (const xEvent*)XIMData_GetHead (pData), &xev)) {
2070 #if defined (DEBUG) || 0
2071 		fprintf (stderr, "Forwarded Event: type(%d)\n", xev.type) ;
2072 #endif
2073 		if (!XIMInputContext_ForwardEvent (pInputContext, &xev))
2074 			XIMClient_ForwardEvent (gw, pInputMethod, pInputContext, &xev) ;
2075 	}
2076 
2077 	/*	Sync �ե饰�����äƤ����顢XIM_SYNC_REPLY ��ȯ�Ԥ���ɬ�פ����롣*/
2078 	if (wFlag & FORWARDEVENT_SYNC_MASK) {
2079 		ximClient_writeSyncReply (gw, wInputMethodID, pInputContext) ;
2080 		XIMInputContext_UnsetSyncMode (pInputContext, XIMClientSync) ;
2081 #if defined (DEBUG) || 0
2082 		fprintf (stderr, "[End] Client-Sync-Mode\n") ;
2083 #endif
2084 	}
2085 	return	True ;
2086 }
2087 
2088 Boolean
ximClient_onXimSync(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)2089 ximClient_onXimSync (
2090 	register Widget		gw,
2091 	register int		nMajorOpCode,
2092 	register int		nMinorOpCode,
2093 	register int		nLength,
2094 	register XIMData*	pData)
2095 {
2096 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
2097 	register CARD16				wInputMethodID ;
2098 	register CARD16				wInputContextID ;
2099 	register XIMInputMethod*	pInputMethod ;
2100 	register XIMInputContext*	pInputContext ;
2101 	register XIMPacket*			pPacket ;
2102 
2103 	/*
2104 	 *	������ input-method id ���ɤ���������å����롣
2105 	 */
2106 	wInputMethodID	= XIMData_GetCard16 (pData) ;
2107 	pInputMethod	= ximClient_findInputMethod (gw, wInputMethodID) ;
2108 	if (pInputMethod == NULL)
2109 		return	True ;
2110 
2111 	/*	������ input-context id ���ɤ���������å����롣*/
2112 	wInputContextID	= XIMData_GetCard16 (pData) ;
2113 	pInputContext	= ximClient_findInputContext (gw, pInputMethod, wInputContextID) ;
2114 	if (pInputContext == NULL)
2115 		return	True ;
2116 
2117 #if defined (DEBUG)
2118 	fprintf (stderr, "XIM_SYNC : MethodID (%d), ContextID (%d)\n",
2119 			 wInputMethodID,
2120 			 wInputContextID) ;
2121 #endif
2122 	/*	SYNC ���׵ᤵ��Ƥ⡢���饤����Ȥ���� SYNC REPLY ����ʤ��¤�
2123 	 *	�ˤ����ƥ��塼�����äƤ���ѥ��åȤ��Ф����ȤϤǤ��ʤ���
2124 	 */
2125 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
2126 	XIMPacket_SetHeader (pPacket, XIM_SYNC_REPLY, 0) ;
2127 	XIMPacket_AddCard16 (pPacket, wInputMethodID) ;
2128 	XIMPacket_AddCard16 (pPacket, wInputContextID) ;
2129 	XIMPacket_SetLength (pPacket) ;
2130 	ximClient_writeMessage (gw, pPacket) ;
2131 	XIMPacket_Release (pPacket) ;
2132 	return	True ;
2133 }
2134 
2135 Boolean
ximClient_onXimSyncReply(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)2136 ximClient_onXimSyncReply (
2137 	register Widget		gw,
2138 	register int		nMajorOpCode,
2139 	register int		nMinorOpCode,
2140 	register int		nLength,
2141 	register XIMData*	pData)
2142 {
2143 	register CARD16				wInputMethodID ;
2144 	register CARD16				wInputContextID ;
2145 	register XIMInputMethod*	pInputMethod ;
2146 	register XIMInputContext*	pInputContext ;
2147 
2148 	/*
2149 	 *	������ input-method id ���ɤ���������å����롣
2150 	 */
2151 	wInputMethodID	= XIMData_GetCard16 (pData) ;
2152 	pInputMethod	= ximClient_findInputMethod (gw, wInputMethodID) ;
2153 	if (pInputMethod == NULL)
2154 		return	True ;
2155 
2156 	/*	������ input-context id ���ɤ���������å����롣*/
2157 	wInputContextID	= XIMData_GetCard16 (pData) ;
2158 	pInputContext	= ximClient_findInputContext (gw, pInputMethod, wInputContextID) ;
2159 	if (pInputContext == NULL)
2160 		return	True ;
2161 
2162 #if defined (DEBUG)
2163 	fprintf (stderr, "XIM_SYNC_REPLY : MethodID (%d), ContextID (%d)\n",
2164 			 wInputMethodID,
2165 			 wInputContextID) ;
2166 #endif
2167 
2168 	/*	ľ���Υ֥�å��ϲ������롣*/
2169 	XIMInputContext_UnsetSyncMode (pInputContext, XIMSyncNormal) ;
2170 
2171 	/*	�֥�å�����ˤ�ä� spool ����Ƥ���ѥ��åȤ� flush ����롣*/
2172 	ximClient_flushSpooledPacket (gw, pInputContext) ;
2173 	return	True ;
2174 }
2175 
2176 Boolean
ximClient_onXimStrConversionReply(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)2177 ximClient_onXimStrConversionReply (
2178 	register Widget		gw,
2179 	register int		nMajorOpCode,
2180 	register int		nMinorOpCode,
2181 	register int		nLength,
2182 	register XIMData*	pData)
2183 {
2184 	return	True ;
2185 }
2186 
2187 Boolean
ximClient_onXimPreeditStartReply(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)2188 ximClient_onXimPreeditStartReply (
2189 	register Widget		gw,
2190 	register int		nMajorOpCode,
2191 	register int		nMinorOpCode,
2192 	register int		nLength,
2193 	register XIMData*	pData)
2194 {
2195 	register CARD16				wInputMethodID ;
2196 	register CARD16				wInputContextID ;
2197 	register XIMInputMethod*	pInputMethod ;
2198 	register XIMInputContext*	pInputContext ;
2199 
2200 	/*
2201 	 *	������ input-method id ���ɤ���������å����롣
2202 	 */
2203 	wInputMethodID	= XIMData_GetCard16 (pData) ;
2204 	pInputMethod	= ximClient_findInputMethod (gw, wInputMethodID) ;
2205 	if (pInputMethod == NULL)
2206 		return	True ;
2207 
2208 	/*	������ input-context id ���ɤ���������å����롣*/
2209 	wInputContextID	= XIMData_GetCard16 (pData) ;
2210 	pInputContext	= ximClient_findInputContext (gw, pInputMethod, wInputContextID) ;
2211 	if (pInputContext == NULL)
2212 		return	True ;
2213 
2214 #if defined (DEBUG)
2215 	fprintf (stderr, "XIM_PREEDIT_START_REPLY : MethodID (%d), ContextID (%d), Return (%lx)\n",
2216 			 wInputMethodID,
2217 			 wInputContextID,
2218 			 XIMData_GetCard32 (pData)) ;
2219 #endif
2220 
2221 	/*	ľ���Υ֥�å��ϲ������롣*/
2222 	XIMInputContext_UnsetSyncMode (pInputContext, XIMSyncPreeditStart) ;
2223 
2224 	/*	�֥�å�����ˤ�ä� spool ����Ƥ���ѥ��åȤ� flush ����롣*/
2225 	ximClient_flushSpooledPacket (gw, pInputContext) ;
2226 	return	True ;
2227 }
2228 
2229 Boolean
ximClient_onXimPreeditCaretReply(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)2230 ximClient_onXimPreeditCaretReply (
2231 	register Widget		gw,
2232 	register int		nMajorOpCode,
2233 	register int		nMinorOpCode,
2234 	register int		nLength,
2235 	register XIMData*	pData)
2236 {
2237 	register CARD16				wInputMethodID ;
2238 	register CARD16				wInputContextID ;
2239 	register XIMInputMethod*	pInputMethod ;
2240 	register XIMInputContext*	pInputContext ;
2241 
2242 	/*
2243 	 *	������ input-method id ���ɤ���������å����롣
2244 	 */
2245 	wInputMethodID	= XIMData_GetCard16 (pData) ;
2246 	pInputMethod	= ximClient_findInputMethod (gw, wInputMethodID) ;
2247 	if (pInputMethod == NULL)
2248 		return	True ;
2249 
2250 	/*	������ input-context id ���ɤ���������å����롣*/
2251 	wInputContextID	= XIMData_GetCard16 (pData) ;
2252 	pInputContext	= ximClient_findInputContext (gw, pInputMethod, wInputContextID) ;
2253 	if (pInputContext == NULL)
2254 		return	True ;
2255 
2256 	/*	�֤���� Position ���ͤ�¿ʬ�Ȥ�ʤ��Τǡ�̵�뤹�롣*/
2257 #if defined (DEBUG)
2258 	fprintf (stderr, "XIM_PREEDIT_CARET_REPLY : MethodID (%d), ContextID (%d), Position (%ld)\n",
2259 			 wInputMethodID,
2260 			 wInputContextID,
2261 			 XIMData_GetCard32 (pData)) ;
2262 #endif
2263 
2264 	/*	ľ���Υ֥�å��ϲ������롣*/
2265 	XIMInputContext_UnsetSyncMode (pInputContext, XIMSyncPreeditCaret) ;
2266 
2267 	/*	�֥�å�����ˤ�ä� spool ����Ƥ���ѥ��åȤ� flush ����롣*/
2268 	ximClient_flushSpooledPacket (gw, pInputContext) ;
2269 	return	True ;
2270 }
2271 
2272 Boolean
ximClient_onXimClose(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)2273 ximClient_onXimClose (
2274 	register Widget		gw,
2275 	register int		nMajorOpCode,
2276 	register int		nMinorOpCode,
2277 	register int		nLength,
2278 	register XIMData*	pData)
2279 {
2280 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
2281 	register CARD16				wInputMethodID ;
2282 	register XIMInputMethod*	pInputMethod ;
2283 	register XIMPacket*			pPacket ;
2284 
2285 	/*	input-method id ���� input-method �����롣*/
2286 	wInputMethodID	= XIMData_GetCard16 (pData) ;
2287 	pInputMethod	= ximClient_findInputMethod (gw, wInputMethodID) ;
2288 	if (pInputMethod == NULL)
2289 		return	True ;
2290 
2291 	ximClient_unregisterInputMethod (gw, pInputMethod) ;
2292 	XIMInputMethod_Destroy (pInputMethod) ;
2293 
2294 	/*	XIM_CLOSE_REPLY �� Library �����롣*/
2295 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
2296 	XIMPacket_SetHeader (pPacket, XIM_CLOSE_REPLY, 0) ;
2297 	XIMPacket_AddCard16 (pPacket, wInputMethodID) ;
2298 	XIMPacket_AddCard16 (pPacket, 0) ;
2299 	XIMPacket_SetLength (pPacket) ;
2300 	ximClient_writeMessage (gw, pPacket) ;
2301 	XIMPacket_Release (pPacket) ;
2302 	return	True ;
2303 }
2304 
2305 Boolean
ximClient_onXimDisconnect(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)2306 ximClient_onXimDisconnect (
2307 	register Widget		gw,
2308 	register int		nMajorOpCode,
2309 	register int		nMinorOpCode,
2310 	register int		nLength,
2311 	register XIMData*	pData)
2312 {
2313 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
2314 	register XIMPacket*			pPacket ;
2315 
2316 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
2317 	XIMPacket_SetHeader (pPacket, XIM_DISCONNECT_REPLY, 0) ;
2318 	XIMPacket_SetLength (pPacket) ;
2319 	ximClient_writeMessage (gw, pPacket) ;
2320 	XIMPacket_Release (pPacket) ;
2321 
2322 	/*	���Ƥ� InputMethod ���˴����롣*/
2323 	ximClient_destroyAllInputMethods (gw) ;
2324 
2325 	/*	��³���ξ��� (xInitialState) ���᤹��*/
2326 	wgThis->ximClient.m_pDispatcher	= ximClient_initialState ;
2327 	return	True ;
2328 }
2329 
2330 Boolean
ximClient_onXimError(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)2331 ximClient_onXimError (
2332 	register Widget		gw,
2333 	register int		nMajorOpCode,
2334 	register int		nMinorOpCode,
2335 	register int		nLength,
2336 	register XIMData*	pData)
2337 {
2338 	return	True ;
2339 }
2340 
2341 Boolean
ximClient_onXimExtForwardKeyEvent(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)2342 ximClient_onXimExtForwardKeyEvent (
2343 	register Widget		gw,
2344 	register int		nMajorOpCode,
2345 	register int		nMinorOpCode,
2346 	register int		nLength,
2347 	register XIMData*	pData)
2348 {
2349 	/*register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;*/
2350 	register CARD16				wInputMethodID ;
2351 	register CARD16				wInputContextID ;
2352 	register XIMInputMethod*	pInputMethod ;
2353 	register XIMInputContext*	pInputContext ;
2354 	XEvent						xev ;
2355 	register CARD16				wFlag ;
2356 
2357 	/*
2358 	 *	������ input-method id ���ɤ���������å����롣
2359 	 */
2360 	wInputMethodID	= XIMData_GetCard16 (pData) ;
2361 	pInputMethod	= ximClient_findInputMethod (gw, wInputMethodID) ;
2362 	if (pInputMethod == NULL)
2363 		return	True ;
2364 
2365 	/*	������ input-context id ���ɤ���������å����롣*/
2366 	wInputContextID	= XIMData_GetCard16 (pData) ;
2367 	pInputContext	= ximClient_findInputContext (gw, pInputMethod, wInputContextID) ;
2368 	if (pInputContext == NULL)
2369 		return	True ;
2370 
2371 	wFlag				= XIMData_GetCard16 (pData) ;
2372 	/*	�ʲ��� xlib �ˤ���������ͤˤ��Ƥ��롣*/
2373 	memset (&xev, 0, sizeof (XEvent)) ;
2374 	xev.xkey.display	= XtDisplay (gw) ;
2375 	xev.xkey.serial		= XIMData_GetCard16 (pData) ;
2376 	xev.xkey.type		= XIMData_GetCard8 (pData) & 0x7F ;
2377 	xev.xkey.keycode	= XIMData_GetCard8 (pData) ;
2378 	xev.xkey.state		= XIMData_GetCard16 (pData) ;
2379 	xev.xkey.time		= (Time) XIMData_GetCard32 (pData) ;
2380 	xev.xkey.window		= (Window) XIMData_GetCard32 (pData) ;
2381 
2382 	if (wFlag & 1)
2383 		XIMInputContext_SetSyncMode (pInputContext, XIMClientSync) ;
2384 
2385 	/*	X Event �� Forward ���롣
2386 	 *	Forward �Ǥ��ʤ���礬����ΤǤϤʤ�������(�ޤ����ΤǤϡ�)
2387 	 */
2388 	if (!XIMInputContext_ForwardEvent (pInputContext, &xev))
2389 		XIMClient_ForwardEvent (gw, pInputMethod, pInputContext, &xev) ;
2390 
2391 	/*	Synchronous �ʤ�� XIM_SYNC_REPLY ������Τϡ�ɬ�פ�
2392 	 *	�ѥ��åȤ����Ф����ä��塣
2393 	 *	�����顢��˽�����¹Ԥ��롣*/
2394 	if (wFlag & 1) {
2395 		ximClient_writeSyncReply (gw, wInputMethodID, pInputContext) ;
2396 		XIMInputContext_UnsetSyncMode (pInputContext, XIMClientSync) ;
2397 	}
2398 	return	True ;
2399 }
2400 
2401 Boolean
ximClient_onXimExtMove(register Widget gw,register int nMajorOpCode,register int nMinorOpCode,register int nLength,register XIMData * pData)2402 ximClient_onXimExtMove (
2403 	register Widget		gw,
2404 	register int		nMajorOpCode,
2405 	register int		nMinorOpCode,
2406 	register int		nLength,
2407 	register XIMData*	pData)
2408 {
2409 	register CARD16				wInputMethodID ;
2410 	register CARD16				wInputContextID ;
2411 	register XIMInputMethod*	pInputMethod ;
2412 	register XIMInputContext*	pInputContext ;
2413 	XPoint		pos ;
2414 
2415 	/*
2416 	 *	������ input-method id ���ɤ���������å����롣
2417 	 */
2418 	wInputMethodID	= XIMData_GetCard16 (pData) ;
2419 	pInputMethod	= ximClient_findInputMethod (gw, wInputMethodID) ;
2420 	if (pInputMethod == NULL)
2421 		return	True ;
2422 
2423 	/*	������ input-context id ���ɤ���������å����롣*/
2424 	wInputContextID	= XIMData_GetCard16 (pData) ;
2425 	pInputContext	= ximClient_findInputContext (gw, pInputMethod, wInputContextID) ;
2426 	if (pInputContext == NULL)
2427 		return	True ;
2428 
2429 	pos.x	= XIMData_GetCard16 (pData) ;
2430 	pos.y	= XIMData_GetCard16 (pData) ;
2431 	XIMInputContext_SetSpotLocation (pInputContext, &pos) ;
2432 	return	True ;
2433 }
2434 
2435 /* ////////////////////////////////////////////////////////////////////////
2436  */
2437 
2438 /*
2439  *(�ؿ�)
2440  *	virtual bool	putInputMethodAttribute (XIMPacket* pPacket, int nID) ;
2441  *(��ǽ)
2442  *	nID �� attributeID ����ꤵ�줿 attribute �� XIMATTR �η���ľ���ƥѥ��åȤ�ή�����ࡣ
2443  *(�֤���)
2444  *	true or falase
2445  *(����)
2446  *	�����ʤ�ή�����ߤޤ�������ʳ������ѤϹͤ��Ƥ��ʤ��ä��ꤷ�ơ�
2447  *	char* ������������Ȥ��Ĥäơ��ѥ��åȤˤ���ʳ��ˤ���ʻȤ��ˤ��������ˤ��뤳��
2448  *	����Ρ�
2449  */
2450 Boolean
ximClient_putInputMethodAttribute(register XIMPacket * pPacket,register int nID)2451 ximClient_putInputMethodAttribute (
2452 	register XIMPacket*		pPacket,
2453 	register int			nID)
2454 {
2455 	assert (pPacket != NULL) ;
2456 	if (nID < 0 || nID >= NELEMENTS (srSupportedInputMethodAttributes))
2457 		return	False ;
2458 
2459 	return	ximClient_putAttributeCommon (pPacket, nID, &srSupportedInputMethodAttributes [nID]) ;
2460 }
2461 
2462 Boolean
ximClient_putInputContextAttribute(register XIMPacket * pPacket,register int nID)2463 ximClient_putInputContextAttribute (
2464 	register XIMPacket*		pPacket,
2465 	register int			nID)
2466 {
2467 	assert (pPacket != NULL) ;
2468 	if (nID < 0 || nID >= NELEMENTS (srSupportedInputContextAttributes))
2469 		return	False ;
2470 
2471 	return	ximClient_putAttributeCommon (pPacket, nID, &srSupportedInputContextAttributes [nID]) ;
2472 }
2473 
2474 Boolean
ximClient_putAttributeCommon(register XIMPacket * pPacket,register int nID,register XIMAttribute * pAttribute)2475 ximClient_putAttributeCommon (
2476 	register XIMPacket*		pPacket,
2477 	register int			nID,
2478 	register XIMAttribute*	pAttribute)
2479 {
2480 	register int	nLength ;
2481 
2482 	assert (pPacket != NULL) ;
2483 	assert (pAttribute != NULL) ;
2484 
2485 	nLength	= strlen (pAttribute->m_pName) ;
2486 	XIMPacket_AddCard16  (pPacket, (CARD16)nID);
2487 	XIMPacket_AddCard16  (pPacket, (CARD16)pAttribute->m_uValueType) ;
2488 	XIMPacket_AddCard16  (pPacket, (CARD16)nLength) ;
2489 	XIMPacket_AddString8 (pPacket, pAttribute->m_pName, nLength) ;
2490 	XIMPacket_AddPad     (pPacket, 2 + nLength) ;
2491 	return	True ;
2492 }
2493 
2494 Boolean
ximClient_putTriggerKey(register Widget gw,register XIMPacket * pPacket,register const XIMHotKeyTrigger * pTriggerkey)2495 ximClient_putTriggerKey (
2496 	register Widget			gw,
2497 	register XIMPacket*		pPacket,
2498 	register const XIMHotKeyTrigger*	pTriggerkey)
2499 {
2500 	assert (pPacket != NULL) ;
2501 	assert (pTriggerkey != NULL) ;
2502 
2503 	XIMPacket_AddCard32 (pPacket, (CARD32)pTriggerkey->keysym) ;
2504 	XIMPacket_AddCard32 (pPacket, (CARD32)pTriggerkey->modifier) ;
2505 	XIMPacket_AddCard32 (pPacket, (CARD32)pTriggerkey->modifier_mask) ;
2506 	return	True ;
2507 }
2508 
2509 Boolean
ximClient_writeErrorMessage(register Widget gw,register int nInputMethodID,register int nInputContextID,register int nErrorCode,register const char * pString)2510 ximClient_writeErrorMessage (
2511 	register Widget			gw,
2512 	register int			nInputMethodID,
2513 	register int			nInputContextID,
2514 	register int			nErrorCode,
2515 	register const char*	pString)
2516 {
2517 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
2518 	register XIMPacket*			pPacket ;
2519 	register int				nLength ;
2520 
2521 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
2522 	nLength	= (pString)? strlen (pString) : 0 ;
2523 
2524 	XIMPacket_SetHeader (pPacket, XIM_ERROR, 0) ;
2525 	XIMPacket_AddCard16 (pPacket, nInputMethodID) ;
2526 	XIMPacket_AddCard16 (pPacket, nInputContextID) ;
2527 	XIMPacket_AddBitmask16 (pPacket, ((nInputMethodID >= 0)? 1 : 0) | ((nInputContextID >= 0)? 2 : 0)) ;
2528 	XIMPacket_AddCard16 (pPacket, nErrorCode) ;
2529 	XIMPacket_AddCard16 (pPacket, nLength) ;
2530 	XIMPacket_AddCard16 (pPacket, 0) ;
2531 	XIMPacket_AddString8 (pPacket, pString, nLength) ;
2532 	XIMPacket_AddPad (pPacket, nLength) ;
2533 	XIMPacket_SetLength (pPacket) ;
2534 	ximClient_writeMessage (gw, pPacket) ;
2535 	XIMPacket_Release (pPacket) ;
2536 	return	True ;
2537 }
2538 
2539 /*
2540  *(��ǽ)
2541  *	XIM_ERROR ���⡢#13 Bad Protocol �� library (client) �ؤ����롣
2542  *	Bad Protocol �����ֽ����ʡ� ���顼�����˻Ȥ��Τʤ�ľ������ʤ��Ȼפ����ɡġ�
2543  */
2544 Boolean
ximClient_badProtocol(register Widget gw,register const char * pString)2545 ximClient_badProtocol (
2546 	register Widget			gw,
2547 	register const char*	pString)
2548 {
2549 	return	ximClient_writeErrorMessage (gw, -1, -1, XIM_ERROR_BadProtocol, pString) ;
2550 }
2551 
2552 /*
2553  *(�ؿ�)
2554  *	virtual bool	CXIMClient::setForwardEvent (XIMInputMethod* pInputMethod, CXIMInputContext* pInputContext, bool fEnable) ;
2555  *(��ǽ)
2556  *	Client ���餳������ꤲ���ߤ��� X EVENT �����ꤹ����Ѥ���ؿ���
2557  *	Extension �������äƤ��뤫�ɤ����ǡ�XIM_EXT_SET_EVENT_MASK ��Ȥ��� XIM_SET_EVENT_MASK ��
2558  *	�Ȥ��������ꤵ��롣
2559  */
2560 Boolean
ximClient_setForwardEvent(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register Boolean fEnable)2561 ximClient_setForwardEvent (
2562 	register Widget				gw,
2563 	register XIMInputMethod*	pInputMethod,
2564 	register XIMInputContext*	pInputContext,
2565 	register Boolean			fEnable)
2566 {
2567 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
2568 	register XIMPacket*			pPacket ;
2569 
2570 #if defined (DEBUG) || 0
2571 	fprintf (stderr, "ximClient_setForwardEvent (%p, %d, %d)\n",
2572 			 gw,
2573 			 XIMInputMethod_GetID (pInputMethod),
2574 			 XIMInputContext_GetID (pInputContext)) ;
2575 #endif
2576 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
2577 
2578 	/*	������ forward �γ���/��λ���������롣*/
2579 	if (XIMInputMethod_GetExtMask (pInputMethod) & XIM_EXT_SET_EVENT_MASK_MASK){
2580 		XIMPacket_SetHeader (pPacket, XIM_EXT_SET_EVENT_MASK, 0) ;
2581 		XIMPacket_AddCard16 (pPacket, XIMInputMethod_GetID (pInputMethod)) ;
2582 		XIMPacket_AddCard16 (pPacket, XIMInputContext_GetID (pInputContext)) ;
2583 
2584 		/*
2585 		 *	filter-event-mask �������äƤ��� Event �� Client ¦����� Server �˽���
2586 		 *	���줿�褦�ˡ�Server �����̵���ä��褦�˸����롣
2587 		 */
2588 		XIMPacket_AddCard32 (pPacket, NoEventMask) ;
2589 		/*
2590 		 *	intercept-event-mask, select-event-mask ��Ȥ����Ȥ� X Input Method Protocol
2591 		 *	Client �� XSelectInput ���� X EVENT ����ȥ��뤹�뤳�Ȥ��Ǥ��롣
2592 		 *
2593 		 *	current-event-mask := �����ߤ� Client �� event-mask
2594 		 *	next-event-mask    := current-event-mask & ~intercept-event-mask | select-event-mask
2595 		 *
2596 		 *	�Ȥʤ롣
2597 		 */
2598 
2599 		/* intercept-event-mask */
2600 		XIMPacket_AddCard32 (pPacket, NoEventMask) ;
2601 		/* select-event-mask */
2602 		XIMPacket_AddCard32 (pPacket, NoEventMask) ;
2603 		/* forward-event-mask */
2604 		XIMPacket_AddCard32 (pPacket, fEnable? (KeyPressMask | KeyReleaseMask) : NoEventMask) ;
2605 		/* synchronous-event-mask */
2606 #if defined (USE_ASYNC_XIM)
2607 		XIMPacket_AddCard32 (pPacket, NoEventMask) ;
2608 #else
2609 		XIMPacket_AddCard32 (pPacket, fEnable? (KeyPressMask | KeyReleaseMask) : NoEventMask) ;
2610 #endif
2611 	} else {
2612 		XIMPacket_SetHeader (pPacket, XIM_SET_EVENT_MASK, 0) ;
2613 		XIMPacket_AddCard16 (pPacket, XIMInputMethod_GetID (pInputMethod)) ;
2614 		XIMPacket_AddCard16 (pPacket, XIMInputContext_GetID (pInputContext)) ;
2615 		/* forward-event-mask */
2616 		XIMPacket_AddCard32 (pPacket, fEnable? (KeyPressMask | KeyReleaseMask) : NoEventMask) ;
2617 		/* synchronous-event-mask */
2618 #if defined (USE_ASYNC_XIM)
2619 		XIMPacket_AddCard32 (pPacket, NoEventMask) ;
2620 #else
2621 		XIMPacket_AddCard32 (pPacket, fEnable? (KeyPressMask | KeyReleaseMask) : NoEventMask) ;
2622 #endif
2623 	}
2624 	XIMPacket_SetLength (pPacket) ;
2625 	ximClient_writeMessage (gw, pPacket) ;
2626 	XIMPacket_Release (pPacket) ;
2627 	return	True ;
2628 }
2629 
2630 Boolean
ximClient_registerInputMethod(register Widget gw,register XIMInputMethod * pInputMethod)2631 ximClient_registerInputMethod (
2632 	register Widget				gw,
2633 	register XIMInputMethod*	pInputMethod)
2634 {
2635 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
2636 
2637 	assert (gw != NULL) ;
2638 	assert (pInputMethod != NULL) ;
2639 
2640 	XIMInputMethod_SetNext (pInputMethod, wgThis->ximClient.m_lstInputMethod) ;
2641 	wgThis->ximClient.m_lstInputMethod	= pInputMethod ;
2642 	return	True ;
2643 }
2644 
2645 Boolean
ximClient_unregisterInputMethod(register Widget gw,register XIMInputMethod * pInputMethod)2646 ximClient_unregisterInputMethod (
2647 	register Widget				gw,
2648 	register XIMInputMethod*	pInputMethod)
2649 {
2650 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
2651 	register XIMInputMethod*	pPrevNode ;
2652 	register XIMInputMethod*	pNode ;
2653 	register XIMInputMethod*	pNextNode ;
2654 
2655 	pPrevNode	= NULL ;
2656 	pNode		= wgThis->ximClient.m_lstInputMethod ;
2657 	while (pNode != NULL) {
2658 		pNextNode	= XIMInputMethod_GetNext (pNode) ;
2659 		if (pNode == pInputMethod) {
2660 			if (pPrevNode != NULL) {
2661 				XIMInputMethod_SetNext (pPrevNode, pNextNode) ;
2662 			} else {
2663 				wgThis->ximClient.m_lstInputMethod	= pNextNode ;
2664 			}
2665 			return	True ;
2666 		}
2667 		pPrevNode	= pNode ;
2668 		pNode		= pNextNode ;
2669 	}
2670 	return	False ;
2671 }
2672 
2673 XIMInputMethod*
ximClient_findInputMethod(register Widget gw,register CARD16 wID)2674 ximClient_findInputMethod (
2675 	register Widget		gw,
2676 	register CARD16		wID)
2677 {
2678 	register XIMClientWidget		wgThis	= (XIMClientWidget) gw ;
2679 	register XIMInputMethod*		pInputMethod ;
2680 
2681 	pInputMethod	= wgThis->ximClient.m_lstInputMethod ;
2682 	while (pInputMethod != NULL) {
2683 		if (XIMInputMethod_GetID (pInputMethod) == wID)
2684 			return	pInputMethod ;
2685 		pInputMethod	= XIMInputMethod_GetNext (pInputMethod) ;
2686 	}
2687 	ximClient_badProtocol (gw, "Invalid input-method-ID") ;
2688 	return	NULL ;
2689 }
2690 
2691 XIMInputContext*
ximClient_findInputContext(register Widget gw,register XIMInputMethod * pIM,register CARD16 wICID)2692 ximClient_findInputContext (
2693 	register Widget				gw,
2694 	register XIMInputMethod*	pIM,
2695 	register CARD16				wICID)
2696 {
2697 	register XIMInputContext*	pIC ;
2698 
2699 	assert (gw  != NULL) ;
2700 	assert (pIM != NULL) ;
2701 
2702 	pIC	= XIMInputMethod_FindInputContext (pIM, wICID) ;
2703 	if (pIC == NULL || !XIMInputContext_Alivep (pIC))
2704 		ximClient_writeErrorMessage (gw, XIMInputMethod_GetID (pIM), -1, XIM_ERROR_BadProtocol, "Invalid inputcontext-id") ;
2705 	return	pIC ;
2706 }
2707 
2708 void
ximClient_destroyAllInputMethods(register Widget gw)2709 ximClient_destroyAllInputMethods (
2710 	register Widget		gw)
2711 {
2712 	register XIMClientWidget		wgThis	= (XIMClientWidget) gw ;
2713 	register XIMInputMethod*		pInputMethod ;
2714 	register XIMInputMethod*		pNextInputMethod ;
2715 
2716 	pInputMethod	= wgThis->ximClient.m_lstInputMethod ;
2717 	while (pInputMethod != NULL) {
2718 		pNextInputMethod	= XIMInputMethod_GetNext (pInputMethod) ;
2719 		XIMInputMethod_Destroy (pInputMethod) ;
2720 		pInputMethod		= pNextInputMethod ;
2721 	}
2722 	wgThis->ximClient.m_lstInputMethod	= NULL ;
2723 	return ;
2724 }
2725 
2726 Boolean
ximClient_createXEvent(register Widget gw,register unsigned long ulSerialNumber,register const xEvent * pSrc,register XEvent * pDest)2727 ximClient_createXEvent (
2728 	register Widget			gw,
2729 	register unsigned long	ulSerialNumber,
2730 	register const xEvent*	pSrc,
2731 	register XEvent*		pDest)
2732 {
2733 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
2734 	register int				nType ;
2735 
2736 	nType	= pSrc->u.u.type & 0x7f ;
2737 	if (nType != KeyPress && nType != KeyRelease)
2738 		return	False ;
2739 
2740 	pDest->type				= nType ;
2741 	pDest->xany.send_event	= ((pSrc->u.u.type & 0x80) != 0) ;
2742 	pDest->xany.display		= XtDisplay (gw) ;
2743 	pDest->xkey.display		= XtDisplay (gw) ;
2744 
2745 	if (wgThis->ximClient.m_fBigEndian) {
2746 #define	GET_BIGCARD32(ptr)	(((CARD32)*((CARD8*)(ptr)) << 24) | ((CARD32)*((CARD8*)(ptr) + 1) << 16) | ((CARD32)*((CARD8*)(ptr) + 2) << 8) | ((CARD32)*((CARD8*)(ptr) + 3) << 0))
2747 #define	GET_BIGCARD16(ptr)	(((CARD16)*((CARD8*)(ptr)) << 8) | ((CARD16)*((CARD8*)(ptr) + 1) << 0))
2748 		pDest->xany.serial		= (ulSerialNumber << 16) | GET_BIGCARD16 (&pSrc->u.u.sequenceNumber) ;
2749 		pDest->xkey.root		= GET_BIGCARD32 (&pSrc->u.keyButtonPointer.root) ;
2750 		pDest->xkey.window 		= GET_BIGCARD32 (&pSrc->u.keyButtonPointer.event) ;
2751 		pDest->xkey.subwindow 	= GET_BIGCARD32 (&pSrc->u.keyButtonPointer.child) ;
2752 		pDest->xkey.time 		= GET_BIGCARD32 (&pSrc->u.keyButtonPointer.time) ;
2753 		pDest->xkey.x 			= GET_BIGCARD16 (&pSrc->u.keyButtonPointer.eventX) ;
2754 		pDest->xkey.y 			= GET_BIGCARD16 (&pSrc->u.keyButtonPointer.eventY) ;
2755 		pDest->xkey.x_root 		= GET_BIGCARD16 (&pSrc->u.keyButtonPointer.rootX) ;
2756 		pDest->xkey.y_root 		= GET_BIGCARD16 (&pSrc->u.keyButtonPointer.rootY) ;
2757 		pDest->xkey.state		= GET_BIGCARD16 (&pSrc->u.keyButtonPointer.state) ;
2758 #undef	GET_BIGCARD32
2759 #undef	GET_BIGCARD16
2760 	} else {
2761 #define	GET_LITTLECARD32(ptr)	(((CARD32)*((CARD8*)(ptr)) << 0) | ((CARD32)*((CARD8*)(ptr) + 1) << 8) | ((CARD32)*((CARD8*)(ptr) + 2) << 16) | ((CARD32)*((CARD8*)(ptr) + 3) << 24))
2762 #define	GET_LITTLECARD16(ptr)	(((CARD16)*((CARD8*)(ptr)) << 0) | ((CARD16)*((CARD8*)(ptr) + 1) << 8))
2763 		pDest->xany.serial		= (ulSerialNumber << 16) | GET_LITTLECARD16 (&pSrc->u.u.sequenceNumber) ;
2764 		pDest->xkey.root		= GET_LITTLECARD32 (&pSrc->u.keyButtonPointer.root) ;
2765 		pDest->xkey.window 		= GET_LITTLECARD32 (&pSrc->u.keyButtonPointer.event) ;
2766 		pDest->xkey.subwindow 	= GET_LITTLECARD32 (&pSrc->u.keyButtonPointer.child) ;
2767 		pDest->xkey.time 		= GET_LITTLECARD32 (&pSrc->u.keyButtonPointer.time) ;
2768 		pDest->xkey.x 			= GET_LITTLECARD16 (&pSrc->u.keyButtonPointer.eventX) ;
2769 		pDest->xkey.y 			= GET_LITTLECARD16 (&pSrc->u.keyButtonPointer.eventY) ;
2770 		pDest->xkey.x_root 		= GET_LITTLECARD16 (&pSrc->u.keyButtonPointer.rootX) ;
2771 		pDest->xkey.y_root 		= GET_LITTLECARD16 (&pSrc->u.keyButtonPointer.rootY) ;
2772 		pDest->xkey.state		= GET_LITTLECARD16 (&pSrc->u.keyButtonPointer.state) ;
2773 #undef	GET_LITTLECARD32
2774 #undef	GET_LITTLECARD16
2775 	}
2776 	pDest->xkey.same_screen	= pSrc->u.keyButtonPointer.sameScreen ;
2777 	pDest->xkey.keycode 	= pSrc->u.u.detail ;
2778 	return	True ;
2779 }
2780 
2781 /* //////////////////////////////////////////////////////////////////////
2782  */
2783 /*
2784  *(�ؿ�)
2785  *	virtual bool	getImValueQueryInputStyle (
2786  *		XIMInputMethod* pInputMethod,
2787  *		CXIMInputContext* pInputContext,
2788  *		int nAttributeID,
2789  *		XIMPacket* pPacket
2790  *	) ;
2791  *(��ǽ)
2792  *	InputMethod �����ݡ��Ȥ��Ƥ��� XIMStyle �������ѥ��åȤ˵ͤ��
2793  *	�֤���
2794  *(�֤���)
2795  *	true	̵�����ͤ��Ȥ줿���
2796  *	false	���顼��ȯ���������
2797  *(����)
2798  *	���餯���顼���֤����ȤϤʤ�����
2799  */
2800 Boolean
ximClient_getImValueQueryInputStyle(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int nMode,register XIMPacket * pPacket)2801 ximClient_getImValueQueryInputStyle (
2802 	register Widget				gw,
2803 	register XIMInputMethod*	pInputMethod,
2804 	register XIMInputContext* 	pInputContext,
2805 	register XIMData*			pData,
2806 	register int*				pnItems,
2807 	register int				nMode,
2808 	register XIMPacket*			pPacket)
2809 {
2810 	const XIMInputStyle*		pQueryInputStyle ;
2811 	register int				nInputStyle ;
2812 	register int				nValueLength ;
2813 
2814 	/*	InputMethod ���饵�ݡ��Ȥ��Ƥ��� Style �����롣*/
2815 	nInputStyle		= XIMInputMethod_GetQueryInputStyle (pInputMethod, &pQueryInputStyle) ;
2816 	/*	Attribute-ID ��ѥ��åȤ˵ͤ�롣*/
2817 	XIMPacket_AddCard16 (pPacket, (CARD16)XIM_ATTRIBUTEID_QUERYINPUTSTYLE) ;
2818 	if (pQueryInputStyle != NULL && nInputStyle > 0){
2819 		//	XIMStyles ��ѥ��åȤ˵ͤ�롣
2820 		nValueLength	= (nInputStyle * sizeof (CARD32) + sizeof (CARD16) * 2) / sizeof (CARD8) ;
2821 		XIMPacket_AddCard16 (pPacket, nValueLength) ;
2822 		XIMPacket_AddCard16 (pPacket, nInputStyle) ;
2823 		XIMPacket_AddCard16 (pPacket, 0 /* unused */) ;
2824 		while (nInputStyle > 0){
2825 			XIMPacket_AddCard32 (pPacket, pQueryInputStyle->m_uXIMStyle) ;
2826 			pQueryInputStyle	++ ;
2827 			nInputStyle			-- ;
2828 		}
2829 	} else {
2830 		nValueLength	= 0 ;
2831 	}
2832 	XIMPacket_AddPad (pPacket, nValueLength) ;
2833 	return	True ;
2834 }
2835 
2836 /* ///////////////////////////////////////////////////////////////////////
2837  */
2838 
2839 /*
2840  *
2841  */
2842 Boolean
ximClient_getIcValues(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnLength,register int iMode,register XIMPacket * pPacket)2843 ximClient_getIcValues (
2844 	register Widget				gw,
2845 	register XIMInputMethod*	pInputMethod,
2846 	register XIMInputContext*	pInputContext,
2847 	register XIMData*			pData,
2848 	register int*				pnLength,
2849 	register int				iMode,
2850 	register XIMPacket*			pPacket)
2851 {
2852 	register XIMAttribute*		pAttribute ;
2853 	register int				nMethodID, nContextID ;
2854 	register int				nAttributeID ;
2855 	int							nLength ;
2856 
2857 	nLength		= *pnLength ;
2858 	nMethodID	= XIMInputMethod_GetID (pInputMethod) ;
2859 	nContextID	= XIMInputContext_GetID (pInputContext) ;
2860 	while (nLength > 0){
2861 		if (nLength < (int)(sizeof (CARD16) / sizeof (CARD8))){
2862 			ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "Lack of data.") ;
2863 			return	False ;
2864 		}
2865 		nAttributeID	= XIMData_GetCard16 (pData) ;
2866 		nLength			-= sizeof (CARD16) / sizeof (CARD8) ;
2867 		if (nAttributeID < 0 || nAttributeID >= MAX_NUMBER_OF_XIC_ATTRIBUTEID){
2868 			ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "Invalid attribute-ID.") ;
2869 			return	False ;
2870 		}
2871 
2872 		/*(���)
2873 		 *	Separator ��ȯ���������ˤϿƤΥꥹ�Ȥؤ���롣
2874 		 */
2875 		if (nAttributeID == XIC_ATTRIBUTEID_SEPARATOR){
2876 			if (iMode & (PREEDITATTRIBUTES_MASK | STATUSATTRIBUTES_MASK))
2877 				break ;
2878 			ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "Unexpected separator of nested list.") ;
2879 			return	False ;
2880 		}
2881 		pAttribute		= &srSupportedInputContextAttributes [nAttributeID] ;
2882 		if (pAttribute->m_pGetter == NULL){
2883 			ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "Operation: GetIcValue is not permitted.") ;
2884 			return	False ;
2885 		}
2886 
2887 		/*(���)
2888 		 *	NestedList ��Ĺ�������ꤵ��ʤ���������ߤ�Ĺ���� ListOfXICATTR �Ȥ���
2889 		 *	Ϳ�����Ƥ��롣
2890 		 */
2891 		if (!(pAttribute->m_pGetter)(gw, pInputMethod, pInputContext, pData, &nLength, iMode, pPacket))
2892 			return	False ;
2893 	}
2894 	*pnLength	= nLength ;
2895 	return	True ;
2896 }
2897 
2898 /*
2899  *(�ؿ�)
2900  *	virtual bool	getIcValueInputStyle (
2901  *		XIMInputMethod* pInputMethod,
2902  *		CXIMInputContext* pInputContext,
2903  *		int nAttributeID,
2904  *		XIMPacket* pPacket
2905  *	) ;
2906  *(��ǽ)
2907  *	InputContext �� InputStyle ��ѥ��åȤ˵ͤ���֤���
2908  *(�֤���)
2909  *	true	̵�����ͤ��Ȥ줿���
2910  *	false	���顼��ȯ���������
2911  *(����)
2912  *	���餯���顼���֤����ȤϤʤ�����
2913  *	SetValue �ʤ� BadValue �Ȥ��ͤ�����Τ�����ɤ⡣
2914  */
2915 Boolean
ximClient_getIcValueInputStyle(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)2916 ximClient_getIcValueInputStyle (
2917 	register Widget				gw,
2918 	register XIMInputMethod*	pInputMethod,
2919 	register XIMInputContext*	pInputContext,
2920 	register XIMData*			pData,
2921 	register int*				pnItems,
2922 	register int				iMode,
2923 	register XIMPacket*			pPacket)
2924 {
2925 	register XIMStyle	imstyle ;
2926 	register int		nValueLength ;
2927 
2928 	imstyle	= XIMInputContext_GetInputStyle (pInputContext) ;
2929 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_INPUTSTYLE) ;
2930 	nValueLength	= (int)(sizeof (CARD32) / sizeof (CARD8)) ;
2931 	XIMPacket_AddCard16 (pPacket, nValueLength) ;
2932 	XIMPacket_AddCard32 (pPacket, (CARD32)imstyle) ;
2933 	XIMPacket_AddPad (pPacket, nValueLength) ;
2934 	return	True ;
2935 }
2936 
2937 /*
2938  *(�ؿ�)
2939  *	virtual bool	getIcValueClientWindow (
2940  *		XIMInputMethod* pInputMethod,
2941  *		CXIMInputContext* pInputContext,
2942  *		int nAttributeID,
2943  *		XIMPacket* pPacket
2944  *	) ;
2945  *(��ǽ)
2946  *	InputContext ��������Ƥ��Ƥ��� Client Window �� Window ID (?)
2947  *	��ѥ��åȤ˵ͤ���֤���
2948  *(�֤���)
2949  *	true	̵�����ͤ��Ȥ줿���
2950  *	false	���顼��ȯ���������
2951  *(����)
2952  *	���餯���顼���֤����ȤϤʤ�����
2953  *	SetValue �ʤ� BadValue �Ȥ��ͤ�����Τ�����ɤ⡣
2954  */
2955 Boolean
ximClient_getIcValueClientWindow(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)2956 ximClient_getIcValueClientWindow (
2957 	register Widget				gw,
2958 	register XIMInputMethod*	pInputMethod,
2959 	register XIMInputContext*	pInputContext,
2960 	register XIMData*			pData,
2961 	register int*				pnItems,
2962 	register int				iMode,
2963 	register XIMPacket*			pPacket)
2964 {
2965 	register Window		winClient ;
2966 	register int		nValueLength ;
2967 
2968 	/*	Attribute-ID ��ѥ��åȤ˵ͤ�롣*/
2969 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_CLIENTWINDOW) ;
2970 	winClient	= XIMInputContext_GetClientWindow (pInputContext) ;
2971 	nValueLength	= (int)(sizeof (CARD32) / sizeof (CARD8)) ;
2972 	XIMPacket_AddCard16 (pPacket, nValueLength) ;
2973 	XIMPacket_AddCard32 (pPacket, (CARD32)winClient) ;
2974 	XIMPacket_AddPad (pPacket, nValueLength) ;
2975 	return	True ;
2976 }
2977 
2978 /*
2979  *(�ؿ�)
2980  *	virtual bool	getIcValueFocusWindow (
2981  *		XIMInputMethod* pInputMethod,
2982  *		CXIMInputContext* pInputContext,
2983  *		int nAttributeID,
2984  *		XIMPacket* pPacket
2985  *	) ;
2986  *(��ǽ)
2987  *	InputContext ��������Ƥ��Ƥ��� Focus Window �� Window ID (?)
2988  *	��ѥ��åȤ˵ͤ���֤���
2989  *(�֤���)
2990  *	true	̵�����ͤ��Ȥ줿���
2991  *	false	���顼��ȯ���������
2992  *(����)
2993  *	���餯���顼���֤����ȤϤʤ�����
2994  *	SetValue �ʤ� BadValue �Ȥ��ͤ�����Τ�����ɤ⡣
2995  */
2996 Boolean
ximClient_getIcValueFocusWindow(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)2997 ximClient_getIcValueFocusWindow (
2998 	register Widget				gw,
2999 	register XIMInputMethod*	pInputMethod,
3000 	register XIMInputContext*	pInputContext,
3001 	register XIMData*			pData,
3002 	register int*				pnItems,
3003 	register int				iMode,
3004 	register XIMPacket*			pPacket)
3005 {
3006 	register Window		winFocus ;
3007 	register int		nValueLength ;
3008 	/*	Attribute-ID ��ѥ��åȤ˵ͤ�롣*/
3009 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_FOCUSWINDOW) ;
3010 	winFocus		= XIMInputContext_GetFocusWindow (pInputContext) ;
3011 	nValueLength	= (int)(sizeof (CARD32) / sizeof (CARD8)) ;
3012 	XIMPacket_AddCard16 (pPacket, nValueLength) ;
3013 	XIMPacket_AddCard32 (pPacket, (CARD32)winFocus) ;
3014 	XIMPacket_AddPad (pPacket, nValueLength) ;
3015 	return	True ;
3016 }
3017 
3018 /*
3019  *(�ؿ�)
3020  *	virtual bool	getIcValueFilterEvents (
3021  *		XIMInputMethod* pInputMethod,
3022  *		CXIMInputContext* pInputContext,
3023  *		CXIMData* pData,
3024  *		int& nItems,
3025  *		int iMode,
3026  *		XIMPacket* pPacket
3027  *	) ;
3028  *(��ǽ)
3029  *	InputContext �� filter_events ���֤��ġ�filter_events �Ȥϲ�����
3030  *	��Τǽ���ͤϤɤ�����٤��ʤΤ�������
3031  *(�֤���)
3032  *	true	̵�����ͤ��Ȥ줿���
3033  *	false	���顼��ȯ���������
3034  *(����)
3035  *	���餯���顼���֤����ȤϤʤ�����
3036  *	SetValue �ʤ� BadValue �Ȥ��ͤ�����Τ�����ɤ⡣
3037  */
3038 Boolean
ximClient_getIcValueFilterEvents(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)3039 ximClient_getIcValueFilterEvents (
3040 	register Widget				gw,
3041 	register XIMInputMethod*	pInputMethod,
3042 	register XIMInputContext*	pInputContext,
3043 	register XIMData*			pData,
3044 	register int*				pnItems,
3045 	register int				iMode,
3046 	register XIMPacket*			pPacket)
3047 {
3048 	register CARD32		dwFilterEvents ;
3049 	register int		nValueLength ;
3050 
3051 	/*	Attribute-ID ��ѥ��åȤ˵ͤ�롣*/
3052 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_FILTEREVENTS) ;
3053 	dwFilterEvents	= XIMInputContext_GetFilterEvents (pInputContext) ;
3054 	nValueLength		= (int)(sizeof (CARD32) / sizeof (CARD8)) ;
3055 	XIMPacket_AddCard16 (pPacket, nValueLength) ;
3056 	XIMPacket_AddCard32 (pPacket, (CARD32)dwFilterEvents) ;
3057 	XIMPacket_AddPad (pPacket, nValueLength) ;
3058 	return	True ;
3059 }
3060 
3061 Boolean
ximClient_getIcValueResetState(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)3062 ximClient_getIcValueResetState (
3063 	register Widget				gw,
3064 	register XIMInputMethod*	pInputMethod,
3065 	register XIMInputContext*	pInputContext,
3066 	register XIMData*			pData,
3067 	register int*				pnItems,
3068 	register int				iMode,
3069 	register XIMPacket*			pPacket)
3070 {
3071 	register XIMResetState	ulState ;
3072 	register int			nValueLength ;
3073 
3074 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_RESETSTATE) ;
3075 	ulState			= XIMInputContext_GetResetState (pInputContext) ;
3076 	nValueLength	= (int)(sizeof (CARD32) / sizeof (CARD8)) ;
3077 	XIMPacket_AddCard16 (pPacket, nValueLength) ;
3078 	XIMPacket_AddCard32 (pPacket, (CARD32)ulState) ;
3079 	XIMPacket_AddPad (pPacket, nValueLength) ;
3080 	return	True ;
3081 }
3082 
3083 /*
3084  *
3085  */
3086 Boolean
ximClient_getIcValuePreeditState(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)3087 ximClient_getIcValuePreeditState (
3088 	register Widget				gw,
3089 	register XIMInputMethod*	pInputMethod,
3090 	register XIMInputContext*	pInputContext,
3091 	register XIMData*			pData,
3092 	register int*				pnItems,
3093 	register int				iMode,
3094 	register XIMPacket*			pPacket)
3095 {
3096 	register XIMResetState	ulState ;
3097 	register int		nValueLength ;
3098 
3099 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_PREEDITSTATE) ;
3100 	ulState				= XIMInputContext_GetPreeditState (pInputContext) ;
3101 	nValueLength		= (int)(sizeof (CARD32) / sizeof (CARD8)) ;
3102 	XIMPacket_AddCard16 (pPacket, nValueLength) ;
3103 	XIMPacket_AddCard32 (pPacket, (CARD32)ulState) ;
3104 	XIMPacket_AddPad (pPacket, nValueLength) ;
3105 	return	True ;
3106 }
3107 
3108 /*
3109  *
3110  */
3111 Boolean
ximClient_getIcValuePreeditAttributes(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)3112 ximClient_getIcValuePreeditAttributes (
3113 	register Widget				gw,
3114 	register XIMInputMethod*	pInputMethod,
3115 	register XIMInputContext*	pInputContext,
3116 	register XIMData*			pData,
3117 	register int*				pnItems,
3118 	register int				iMode,
3119 	register XIMPacket*			pPacket)
3120 {
3121 	register int	nMethodID, nContextID ;
3122 	register int	nIndexAttributeLength ;
3123 	register int	nValueLength ;
3124 	int				nItems ;
3125 
3126 	nItems		= *pnItems ;
3127 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3128 	nContextID	= XIMInputContext_GetID (pInputContext) ;
3129 
3130 	/*	Nested list ������ Nest ����Ƥ���褦�ʤ��ȤϤ��ꤨ�ʤ���
3131 	 *	�ĸ����Ǥϡ����դ��ä��Ƥ����ޤ��礦��(^^;;
3132 	 */
3133 	if (iMode & (PREEDITATTRIBUTES_MASK | STATUSATTRIBUTES_MASK)){
3134 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "Cannot nest nested list") ;
3135 		return	False ;
3136 	}
3137 	/*	Attribute-ID ��ѥ��åȤ˵ͤ�롣*/
3138 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_PREEDITATTRIBUTES);
3139 	nIndexAttributeLength	= XIMPacket_GetDataSize (pPacket) ;
3140 	XIMPacket_AddCard16 (pPacket, 0 /* dummy */) ;
3141 	/*	XNPreeditAttributes ��°���� Attribute ���Ȥ������꤬���ä���*/
3142 	if (!ximClient_getIcValues (gw, pInputMethod, pInputContext, pData, &nItems, iMode | PREEDITATTRIBUTES_MASK, pPacket)) {
3143 		*pnItems	= nItems ;
3144 		return	False ;
3145 	}
3146 	/*	XNPreeditAttributes �� XNSeparatorofNestedList ���Ĥ��롣*/
3147 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_SEPARATOR) ;
3148 	XIMPacket_AddCard16 (pPacket, strlen (XNSeparatorofNestedList)) ;
3149 	XIMPacket_AddString8 (pPacket, XNSeparatorofNestedList, strlen (XNSeparatorofNestedList)) ;
3150 	/*	���ΤҤȤޤȤޤ�� XNPreeditAttributes �� Value �Ȥʤ롣*/
3151 	nValueLength	= XIMPacket_GetDataSize (pPacket) - nIndexAttributeLength - 2 ;
3152 	XIMPacket_SetCard16 (pPacket, nIndexAttributeLength, (CARD16)nValueLength) ;
3153 	XIMPacket_AddPad (pPacket, nValueLength) ;
3154 	*pnItems		= nItems ;
3155 	return	True ;
3156 }
3157 
3158 /*
3159  *
3160  */
3161 Boolean
ximClient_getIcValueStatusAttributes(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)3162 ximClient_getIcValueStatusAttributes (
3163 	register Widget				gw,
3164 	register XIMInputMethod*	pInputMethod,
3165 	register XIMInputContext*	pInputContext,
3166 	register XIMData*			pData,
3167 	register int*				pnItems,
3168 	register int				iMode,
3169 	register XIMPacket*			pPacket)
3170 {
3171 	register int	nMethodID, nContextID ;
3172 	register int	nIndexAttributeLength ;
3173 	register int	nValueLength ;
3174 	int				nItems ;
3175 
3176 	nItems		= *pnItems ;
3177 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3178 	nContextID	= XIMInputContext_GetID (pInputContext) ;
3179 
3180 	/*	Nested list ������ Nest ����Ƥ���褦�ʤ��ȤϤ��ꤨ�ʤ���
3181 	 *	�ĸ����Ǥϡ����դ��ä��Ƥ����ޤ��礦��(^^;;
3182 	 */
3183 	if (iMode & (PREEDITATTRIBUTES_MASK | STATUSATTRIBUTES_MASK)){
3184 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "Cannot nest nested list") ;
3185 		return	False ;
3186 	}
3187 	/*	Attribute-ID ��ѥ��åȤ˵ͤ�롣*/
3188 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_STATUSATTRIBUTES);
3189 	nIndexAttributeLength	= XIMPacket_GetDataSize (pPacket) ;
3190 	XIMPacket_AddCard16 (pPacket, 0 /* dummy */) ;
3191 	/*	XNPreeditAttributes ��°���� Attribute ���Ȥ������꤬���ä���*/
3192 	if (!ximClient_getIcValues (gw, pInputMethod, pInputContext, pData, &nItems, iMode | STATUSATTRIBUTES_MASK, pPacket)) {
3193 		*pnItems	= nItems ;
3194 		return	False ;
3195 	}
3196 	/*	XNPreeditAttributes �� XNSeparatorofNestedList ���Ĥ��롣*/
3197 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_SEPARATOR) ;
3198 	XIMPacket_AddCard16 (pPacket, strlen (XNSeparatorofNestedList)) ;
3199 	XIMPacket_AddString8 (pPacket, XNSeparatorofNestedList, strlen (XNSeparatorofNestedList)) ;
3200 	/*	���ΤҤȤޤȤޤ�� XNPreeditAttributes �� Value �Ȥʤ롣*/
3201 	nValueLength	= XIMPacket_GetDataSize (pPacket) - nIndexAttributeLength - 2 ;
3202 	XIMPacket_SetCard16 (pPacket, nIndexAttributeLength, (CARD16)nValueLength) ;
3203 	XIMPacket_AddPad (pPacket, nValueLength) ;
3204 	*pnItems	= nItems ;
3205 	return	True ;
3206 }
3207 
3208 Boolean
ximClient_getIcValueArea(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)3209 ximClient_getIcValueArea (
3210 	register Widget				gw,
3211 	register XIMInputMethod*	pInputMethod,
3212 	register XIMInputContext*	pInputContext,
3213 	register XIMData*			pData,
3214 	register int*				pnItems,
3215 	register int				iMode,
3216 	register XIMPacket*			pPacket)
3217 {
3218 	register int	nMethodID, nContextID ;
3219 	register int	nValueLength ;
3220 	XRectangle		area ;
3221 
3222 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3223 	nContextID	= XIMInputContext_GetID (pInputContext) ;
3224 	if (iMode & PREEDITATTRIBUTES_MASK){
3225 		if (!XIMInputContext_GetPreeditArea (pInputContext, &area)){
3226 			ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "No PreeditArea.") ;
3227 			return	False ;
3228 		}
3229 	} else if (iMode & STATUSATTRIBUTES_MASK){
3230 		if (!XIMInputContext_GetStatusArea (pInputContext, &area)){
3231 			ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "No StatusArea.") ;
3232 			return	False ;
3233 		}
3234 	} else {
3235 		/*	PreeditAttribute �ʤΤ� StatusAttribute �ʤΤ���Ƚ�̤��Ǥ��ʤ���*/
3236 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
3237 		return	False ;
3238 	}
3239 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_AREA) ;
3240 	nValueLength	= (sizeof (INT16) + sizeof (INT16) + sizeof (CARD16) + sizeof (CARD16)) / sizeof (CARD8) ;
3241 	XIMPacket_AddCard16 (pPacket, nValueLength) ;
3242 	XIMPacket_AddCard16 (pPacket, area.x) ;
3243 	XIMPacket_AddCard16 (pPacket, area.y) ;
3244 	XIMPacket_AddCard16 (pPacket, area.width) ;
3245 	XIMPacket_AddCard16 (pPacket, area.height) ;
3246 	XIMPacket_AddPad (pPacket, nValueLength) ;
3247 	return	True ;
3248 }
3249 
3250 Boolean
ximClient_getIcValueAreaNeeded(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)3251 ximClient_getIcValueAreaNeeded (
3252 	register Widget				gw,
3253 	register XIMInputMethod*	pInputMethod,
3254 	register XIMInputContext*	pInputContext,
3255 	register XIMData*			pData,
3256 	register int*				pnItems,
3257 	register int				iMode,
3258 	register XIMPacket*			pPacket)
3259 {
3260 	register int	nMethodID, nContextID ;
3261 	register int	nValueLength ;
3262 	XRectangle		area ;
3263 
3264 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3265 	nContextID	= XIMInputContext_GetID (pInputContext) ;
3266 	if (iMode & PREEDITATTRIBUTES_MASK){
3267 		if (!XIMInputContext_GetPreeditAreaNeeded (pInputContext, &area)){
3268 			ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "No need for PreeditArea.") ;
3269 			return	False ;
3270 		}
3271 	} else if (iMode & STATUSATTRIBUTES_MASK){
3272 		if (!XIMInputContext_GetStatusAreaNeeded (pInputContext, &area)){
3273 			ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "No need for StatusArea.") ;
3274 			return	False ;
3275 		}
3276 	} else {
3277 		/*	PreeditAttribute �ʤΤ� StatusAttribute �ʤΤ���Ƚ�̤��Ǥ��ʤ���*/
3278 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
3279 		return	False ;
3280 	}
3281 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_AREANEEDED) ;
3282 	nValueLength	= (sizeof (INT16) + sizeof (INT16) + sizeof (CARD16) + sizeof (CARD16)) / sizeof (CARD8) ;
3283 	XIMPacket_AddCard16 (pPacket, nValueLength) ;
3284 	XIMPacket_AddCard16 (pPacket, area.x) ;
3285 	XIMPacket_AddCard16 (pPacket, area.y) ;
3286 	XIMPacket_AddCard16 (pPacket, area.width) ;
3287 	XIMPacket_AddCard16 (pPacket, area.height) ;
3288 	XIMPacket_AddPad (pPacket, nValueLength) ;
3289 	return	True ;
3290 }
3291 
3292 Boolean
ximClient_getIcValueSpotLocation(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)3293 ximClient_getIcValueSpotLocation (
3294 	register Widget				gw,
3295 	register XIMInputMethod*	pInputMethod,
3296 	register XIMInputContext*	pInputContext,
3297 	register XIMData*			pData,
3298 	register int*				pnItems,
3299 	register int				iMode,
3300 	register XIMPacket*			pPacket)
3301 {
3302 	register int	nMethodID, nContextID ;
3303 	register int	nValueLength ;
3304 	XPoint			pos ;
3305 
3306 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3307 	nContextID	= XIMInputContext_GetID (pInputContext) ;
3308 
3309 	if (iMode & PREEDITATTRIBUTES_MASK){
3310 		XIMInputContext_GetSpotLocation (pInputContext, &pos) ;
3311 	} else if (iMode & STATUSATTRIBUTES_MASK){
3312 		/*	Status Attribute �ˤ� SpotLocation �Ϥʤ���*/
3313 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "No need for StatusArea.") ;
3314 		return	False ;
3315 	} else {
3316 		/*	PreeditAttribute �ʤΤ� StatusAttribute �ʤΤ���Ƚ�̤��Ǥ��ʤ���*/
3317 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
3318 		return	False ;
3319   }
3320 
3321 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_SPOTLOCATION) ;
3322 	nValueLength	= (sizeof (INT16) + sizeof (INT16)) / sizeof (CARD8) ;
3323 	XIMPacket_AddCard16 (pPacket, nValueLength) ;
3324 	XIMPacket_AddCard16 (pPacket, pos.x) ;
3325 	XIMPacket_AddCard16 (pPacket, pos.y) ;
3326 	XIMPacket_AddPad (pPacket, nValueLength) ;
3327 	return	True ;
3328 }
3329 
3330 Boolean
ximClient_getIcValueColormap(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)3331 ximClient_getIcValueColormap (
3332 	register Widget				gw,
3333 	register XIMInputMethod*	pInputMethod,
3334 	register XIMInputContext*	pInputContext,
3335 	register XIMData*			pData,
3336 	register int*				pnItems,
3337 	register int				iMode,
3338 	register XIMPacket*			pPacket)
3339 {
3340 	register Colormap	colormap ;
3341 	register int		nValueLength ;
3342 
3343 	if (iMode & PREEDITATTRIBUTES_MASK){
3344 		colormap	= XIMInputContext_GetPreeditColormap (pInputContext) ;
3345 	} else if (iMode & STATUSATTRIBUTES_MASK){
3346 		colormap	= XIMInputContext_GetStatusColormap (pInputContext) ;
3347 	} else {
3348 		register int	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3349 		register int	nContextID	= XIMInputContext_GetID (pInputContext) ;
3350 
3351 		/*	PreeditAttribute �ʤΤ� StatusAttribute �ʤΤ���Ƚ�̤��Ǥ��ʤ���*/
3352 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
3353 		return	False ;
3354 	}
3355 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_COLORMAP) ;
3356 	nValueLength	= (sizeof (CARD32)) / sizeof (CARD8) ;
3357 	XIMPacket_AddCard16 (pPacket, nValueLength) ;
3358 	XIMPacket_AddCard32 (pPacket, (CARD32)colormap) ;
3359 	XIMPacket_AddPad (pPacket, nValueLength) ;
3360 	return	True ;
3361 }
3362 
3363 Boolean
ximClient_getIcValueStdColormap(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)3364 ximClient_getIcValueStdColormap (
3365 	register Widget				gw,
3366 	register XIMInputMethod*	pInputMethod,
3367 	register XIMInputContext*	pInputContext,
3368 	register XIMData*			pData,
3369 	register int*				pnItems,
3370 	register int				iMode,
3371 	register XIMPacket*			pPacket)
3372 {
3373 	register Atom		colormap ;
3374 	register int		nValueLength ;
3375 
3376 	if (iMode & PREEDITATTRIBUTES_MASK){
3377 		colormap	= XIMInputContext_GetPreeditStdColormap (pInputContext) ;
3378 	} else if (iMode & STATUSATTRIBUTES_MASK){
3379 		colormap	= XIMInputContext_GetStatusStdColormap (pInputContext) ;
3380 	} else {
3381 		register int	nMethodID, nContextID ;
3382 
3383 		nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3384 		nContextID	= XIMInputContext_GetID (pInputContext) ;
3385 
3386 		/*	PreeditAttribute �ʤΤ� StatusAttribute �ʤΤ���Ƚ�̤��Ǥ��ʤ���*/
3387 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
3388 		return	False ;
3389 	}
3390 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_STDCOLORMAP) ;
3391 	nValueLength	= (sizeof (CARD32)) / sizeof (CARD8) ;
3392 	XIMPacket_AddCard16 (pPacket, nValueLength) ;
3393 	XIMPacket_AddCard32 (pPacket, (CARD32)colormap) ;
3394 	XIMPacket_AddPad (pPacket, nValueLength) ;
3395 	return	True ;
3396 }
3397 
3398 Boolean
ximClient_getIcValueForeground(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)3399 ximClient_getIcValueForeground (
3400 	register Widget				gw,
3401 	register XIMInputMethod*	pInputMethod,
3402 	register XIMInputContext*	pInputContext,
3403 	register XIMData*			pData,
3404 	register int*				pnItems,
3405 	register int				iMode,
3406 	register XIMPacket*			pPacket)
3407 {
3408 	register unsigned long	foreground ;
3409 	register int			nValueLength ;
3410 
3411 	if (iMode & PREEDITATTRIBUTES_MASK){
3412 		foreground	= XIMInputContext_GetPreeditForeground (pInputContext) ;
3413 	} else if (iMode & STATUSATTRIBUTES_MASK){
3414 		foreground	= XIMInputContext_GetStatusForeground (pInputContext) ;
3415 	} else {
3416 		register int	nMethodID, nContextID ;
3417 
3418 		nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3419 		nContextID	= XIMInputContext_GetID (pInputContext) ;
3420 
3421 		/*	PreeditAttribute �ʤΤ� StatusAttribute �ʤΤ���Ƚ�̤��Ǥ��ʤ���*/
3422 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
3423 		return	False ;
3424 	}
3425 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_FOREGROUND) ;
3426 	nValueLength	= (sizeof (CARD32)) / sizeof (CARD8) ;
3427 	XIMPacket_AddCard16 (pPacket, nValueLength) ;
3428 	XIMPacket_AddCard32 (pPacket, (CARD32)foreground) ;
3429 	XIMPacket_AddPad (pPacket, nValueLength) ;
3430 	return	True ;
3431 }
3432 
3433 Boolean
ximClient_getIcValueBackground(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)3434 ximClient_getIcValueBackground (
3435 	register Widget				gw,
3436 	register XIMInputMethod*	pInputMethod,
3437 	register XIMInputContext*	pInputContext,
3438 	register XIMData*			pData,
3439 	register int*				pnItems,
3440 	register int				iMode,
3441 	register XIMPacket*			pPacket)
3442 {
3443 	register unsigned long	background ;
3444 	register int			nValueLength ;
3445 
3446 	if (iMode & PREEDITATTRIBUTES_MASK){
3447 		background	= XIMInputContext_GetPreeditBackground (pInputContext) ;
3448 	} else if (iMode & STATUSATTRIBUTES_MASK){
3449 		background	= XIMInputContext_GetStatusBackground (pInputContext) ;
3450 	} else {
3451 		register int	nMethodID, nContextID ;
3452 
3453 		nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3454 		nContextID	= XIMInputContext_GetID (pInputContext) ;
3455 
3456 		/*	PreeditAttribute �ʤΤ� StatusAttribute �ʤΤ���Ƚ�̤��Ǥ��ʤ���*/
3457 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
3458 		return	False ;
3459 	}
3460 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_BACKGROUND) ;
3461 	nValueLength	= (sizeof (CARD32)) / sizeof (CARD8) ;
3462 	XIMPacket_AddCard16 (pPacket, nValueLength) ;
3463 	XIMPacket_AddCard32 (pPacket, (CARD32)background) ;
3464 	XIMPacket_AddPad (pPacket, nValueLength) ;
3465 	return	True ;
3466 }
3467 
3468 Boolean
ximClient_getIcValueBackgroundPixmap(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)3469 ximClient_getIcValueBackgroundPixmap (
3470 	register Widget				gw,
3471 	register XIMInputMethod*	pInputMethod,
3472 	register XIMInputContext*	pInputContext,
3473 	register XIMData*			pData,
3474 	register int*				pnItems,
3475 	register int				iMode,
3476 	register XIMPacket*			pPacket)
3477 {
3478 	register Pixmap	pixmap ;
3479 	register int	nValueLength ;
3480 
3481 	if (iMode & PREEDITATTRIBUTES_MASK){
3482 		pixmap	= XIMInputContext_GetPreeditBackgroundPixmap (pInputContext) ;
3483 	} else if (iMode & STATUSATTRIBUTES_MASK){
3484 		pixmap	= XIMInputContext_GetStatusBackgroundPixmap (pInputContext) ;
3485 	} else {
3486 		register int	nMethodID, nContextID ;
3487 
3488 		nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3489 		nContextID	= XIMInputContext_GetID (pInputContext) ;
3490 
3491 		/*	PreeditAttribute �ʤΤ� StatusAttribute �ʤΤ���Ƚ�̤��Ǥ��ʤ���*/
3492 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
3493 		return	False ;
3494 	}
3495 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_BACKGROUNDPIXMAP) ;
3496 	nValueLength	= (sizeof (CARD32)) / sizeof (CARD8) ;
3497 	XIMPacket_AddCard16 (pPacket, nValueLength) ;
3498 	XIMPacket_AddCard32 (pPacket, (CARD32)pixmap) ;
3499 	XIMPacket_AddPad (pPacket, nValueLength) ;
3500 	return	True ;
3501 }
3502 
3503 Boolean
ximClient_getIcValueFontSet(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)3504 ximClient_getIcValueFontSet (
3505 	register Widget				gw,
3506 	register XIMInputMethod*	pInputMethod,
3507 	register XIMInputContext*	pInputContext,
3508 	register XIMData*			pData,
3509 	register int*				pnItems,
3510 	register int				iMode,
3511 	register XIMPacket*			pPacket)
3512 {
3513 	register const char*	pFontSet ;
3514 	register int			nBaseNameLength ;
3515 	register int			nIndexValueLength ;
3516 	register int			nValueLength ;
3517 
3518 	if (iMode & PREEDITATTRIBUTES_MASK){
3519 		/*	�����ࡣ���������դ��ġ�Font ̾�� Fake ����ɬ�פ����Ȥ��Ƥ��뤫�⡣*/
3520 		pFontSet	= XIMInputContext_GetPreeditFontSet (pInputContext) ;
3521 	} else if (iMode & STATUSATTRIBUTES_MASK){
3522 		pFontSet	= XIMInputContext_GetStatusFontSet (pInputContext) ;
3523 	} else {
3524 		register int	nMethodID, nContextID ;
3525 
3526 		nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3527 		nContextID	= XIMInputContext_GetID (pInputContext) ;
3528 
3529 		/*	PreeditAttribute �ʤΤ� StatusAttribute �ʤΤ���Ƚ�̤��Ǥ��ʤ���*/
3530 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
3531 		return	False ;
3532 	}
3533 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_FONTSET) ;
3534 	nIndexValueLength	= XIMPacket_GetDataSize (pPacket) ;
3535 	XIMPacket_AddCard16 (pPacket, 0 /* dummy */) ;
3536 	/*	�ͤϡ�TYPE_XFONTSET */
3537 	nBaseNameLength	= strlen (pFontSet) ;
3538 	XIMPacket_AddCard16 (pPacket, nBaseNameLength) ;
3539 	XIMPacket_AddString8 (pPacket, pFontSet, nBaseNameLength) ;
3540 	XIMPacket_AddPad (pPacket, nBaseNameLength) ;
3541 	nValueLength		= XIMPacket_GetDataSize (pPacket) - nIndexValueLength - 2 ;
3542 	XIMPacket_SetCard16 (pPacket, nIndexValueLength, nValueLength) ;
3543 	XIMPacket_AddPad (pPacket, nValueLength) ;
3544 	return	True ;
3545 }
3546 
3547 Boolean
ximClient_getIcValueLineSpacing(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)3548 ximClient_getIcValueLineSpacing (
3549 	register Widget				gw,
3550 	register XIMInputMethod*	pInputMethod,
3551 	register XIMInputContext*	pInputContext,
3552 	register XIMData*			pData,
3553 	register int*				pnItems,
3554 	register int				iMode,
3555 	register XIMPacket*			pPacket)
3556 {
3557 	register int	nLineSpacing ;
3558 	register int	nValueLength ;
3559 
3560 	if (iMode & PREEDITATTRIBUTES_MASK){
3561 		nLineSpacing	= XIMInputContext_GetPreeditLineSpacing (pInputContext) ;
3562 	} else if (iMode & STATUSATTRIBUTES_MASK){
3563 		nLineSpacing	= XIMInputContext_GetStatusLineSpacing (pInputContext) ;
3564 	} else {
3565 		register int	nMethodID, nContextID ;
3566 
3567 		nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3568 		nContextID	= XIMInputContext_GetID (pInputContext) ;
3569 
3570 		/*	PreeditAttribute �ʤΤ� StatusAttribute �ʤΤ���Ƚ�̤��Ǥ��ʤ���*/
3571 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
3572 		return	False ;
3573 	}
3574 
3575 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_LINESPACE) ;
3576 	nValueLength	= sizeof (CARD16) / sizeof (CARD8) ;
3577 	XIMPacket_AddCard16 (pPacket, nValueLength) ;
3578 	XIMPacket_AddCard32 (pPacket, (CARD32)nLineSpacing) ;
3579 	XIMPacket_AddPad (pPacket, nValueLength) ;
3580 	return	True ;
3581 }
3582 
3583 Boolean
ximClient_getIcValueCursor(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int * pnItems,register int iMode,register XIMPacket * pPacket)3584 ximClient_getIcValueCursor (
3585 	register Widget				gw,
3586 	register XIMInputMethod*	pInputMethod,
3587 	register XIMInputContext*	pInputContext,
3588 	register XIMData*			pData,
3589 	register int*				pnItems,
3590 	register int				iMode,
3591 	register XIMPacket*			pPacket)
3592 {
3593 	register Cursor	cursor ;
3594 	register int	nValueLength ;
3595 
3596 	if (iMode & PREEDITATTRIBUTES_MASK){
3597 		cursor	= XIMInputContext_GetPreeditCursor (pInputContext) ;
3598 	} else if (iMode & STATUSATTRIBUTES_MASK){
3599 		cursor	= XIMInputContext_GetStatusCursor (pInputContext) ;
3600 	} else {
3601 		register int	nMethodID, nContextID ;
3602 
3603 		nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3604 		nContextID	= XIMInputContext_GetID (pInputContext) ;
3605 
3606 		/*	PreeditAttribute �ʤΤ� StatusAttribute �ʤΤ���Ƚ�̤��Ǥ��ʤ���*/
3607 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
3608 		return	False ;
3609 	}
3610 	XIMPacket_AddCard16 (pPacket, (CARD16)XIC_ATTRIBUTEID_CURSOR) ;
3611 	nValueLength	= sizeof (CARD32) / sizeof (CARD8) ;
3612 	XIMPacket_AddCard16 (pPacket, nValueLength) ;
3613 	XIMPacket_AddCard32 (pPacket, (CARD32)cursor) ;
3614 	XIMPacket_AddPad (pPacket, nValueLength) ;
3615 	return	True ;
3616 }
3617 
3618 Boolean
ximClient_setIcValues(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)3619 ximClient_setIcValues (
3620 	register Widget				gw,
3621 	register XIMInputMethod*	pInputMethod,
3622 	register XIMInputContext*	pInputContext,
3623 	register XIMData*			pData,
3624 	register int				nDataLength,
3625 	register int				iMode)
3626 {
3627 	register XIMClientWidget	wgThis		= (XIMClientWidget) gw ;
3628 	register XIMAttribute*	pAttribute ;
3629 	register int			nAttributeID ;
3630 	register int			nValueLength ;
3631 	register int			nMethodID, nContextID ;
3632 	register const CARD8*	pHead ;
3633 	register Boolean		fBigEndian ;
3634 
3635 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3636 	nContextID	= XIMInputContext_GetID (pInputContext) ;
3637 	fBigEndian	= wgThis->ximClient.m_fBigEndian ;
3638 
3639 	while (nDataLength >= (int)((sizeof (CARD16) + sizeof (CARD16)) / sizeof (CARD8))){
3640 		nAttributeID	= XIMData_GetCard16 (pData) ;
3641 		nValueLength	= XIMData_GetCard16 (pData) ;
3642 		nDataLength		-= (sizeof (CARD16) + sizeof (CARD16)) / sizeof (CARD8) ;
3643 		/*	IC-attribute �Ȥ��������� ID �������Ƥ��뤫�ɤ���������å����롣*/
3644 		if (nAttributeID < 0 || nAttributeID >= MAX_NUMBER_OF_XIC_ATTRIBUTEID){
3645 			ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "Invalid attribute-ID.") ;
3646 			return	False ;
3647 		}
3648 		pHead		= XIMData_GetHead (pData) ;
3649 		/*	���ꤹ�٤��ǡ�������­���Ƥ����������å����롣*/
3650 		if (nDataLength < nValueLength){
3651 			ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "Lack of value.") ;
3652 			return	False ;
3653 		}
3654 		pAttribute		= &srSupportedInputContextAttributes [nAttributeID] ;
3655 
3656 		/*
3657 		 *	�������������ǽ�Ǥ��뤫��Ƚ�ꤹ��ġ�
3658 		 *	���������ǽ���Ȥ����Τ��Ƚ�Ǥ˺���Ȥ���Ϥ��뤬��
3659 		 */
3660 		if (( (iMode & XIC_CREATE_MASK) && !pAttribute->m_fEnableCreate) ||
3661 			(!(iMode & XIC_CREATE_MASK) && !pAttribute->m_fEnableNormal) ||
3662 			pAttribute->m_pSetter == NULL){
3663 			ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "Operation not permitted.") ;
3664 			return	False ;
3665 		}
3666 #if defined (DEBUG) || 0
3667 		fprintf (stderr, "set-ic-values: attribute = %d\n", nAttributeID) ;
3668 #endif
3669 		/*	�ͤ������*/
3670 		if (!((pAttribute->m_pSetter)(gw, pInputMethod, pInputContext, pData, nValueLength, iMode)))
3671 			return	False ;
3672 		XIMData_Initialize (pData, pHead + nValueLength + IMPAD (nValueLength), fBigEndian) ;
3673 		nDataLength		-= (nValueLength + IMPAD (nValueLength)) ;
3674 	}
3675 	return	True ;
3676 }
3677 
3678 Boolean
ximClient_setIcValueInputStyle(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)3679 ximClient_setIcValueInputStyle (
3680 	register Widget				gw,
3681 	register XIMInputMethod*	pInputMethod,
3682 	register XIMInputContext*	pInputContext,
3683 	register XIMData*			pData,
3684 	register int				nDataLength,
3685 	register int				iMode)
3686 {
3687 	register int		nMethodID, nContextID ;
3688 	register XIMStyle	imstyle ;
3689 
3690 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3691 	nContextID	= XIMInputContext_GetID (pInputContext) ;
3692 
3693 	if (nDataLength < GET_VALUE_LENGTH (CARD32)){
3694 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadStyle, "Bad input style") ;
3695 		return	False ;
3696 	}
3697 	imstyle	= (XIMStyle) XIMData_GetCard32 (pData) ;
3698 	if (!XIMInputContext_SetInputStyle (pInputContext, imstyle)){
3699 		/*	���ԡ��� ¿ʬ�������ˤ���ʤ��Ȼפ����ɡġ�*/
3700 	}
3701 
3702 	if ((imstyle & XIMPreeditMask) == XIMPreeditArea ||
3703 		(imstyle & XIMStatusMask)  == XIMStatusArea) {
3704 		/*	Geometry �� Query ���롣Focus Window ���ʤ���ǽ���⤢��Τ�
3705 		 *	�������륿���ߥ��� InputStyle �������ľ�������*/
3706 		XIMClient_WriteXimGeometry (gw, nMethodID, nContextID) ;
3707 	}
3708 #if defined (DEBUG)
3709 	fprintf (stderr, "InputStyle <- 0x%lx\n", imstyle) ;
3710 #endif
3711 	return	True ;
3712 }
3713 
3714 Boolean
ximClient_setIcValueClientWindow(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)3715 ximClient_setIcValueClientWindow (
3716 	register Widget				gw,
3717 	register XIMInputMethod*	pInputMethod,
3718 	register XIMInputContext*	pInputContext,
3719 	register XIMData*			pData,
3720 	register int				nDataLength,
3721 	register int				iMode)
3722 {
3723 	register int			nMethodID, nContextID ;
3724 	register Window			winClient ;
3725 
3726 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3727 	nContextID	= XIMInputContext_GetID (pInputContext) ;
3728 
3729 	if (nDataLength < GET_VALUE_LENGTH (CARD32)){
3730 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadClientWindow, "Bad client window") ;
3731 		return	False ;
3732 	}
3733 
3734 	winClient	= (Window) XIMData_GetCard32 (pData) ;
3735 	if (!XIMInputContext_SetClientWindow (pInputContext, winClient)){
3736 		//	���٤�������Ǥ��ʤ�°���ʤΤǣ��٣������ꤷ�褦�Ȥ���ȥ��顼�ˤʤ롣
3737 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "Client window only once") ;
3738 		return	False ;
3739 	}
3740 	return	True ;
3741 }
3742 
3743 Boolean
ximClient_setIcValueFocusWindow(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)3744 ximClient_setIcValueFocusWindow (
3745 	register Widget				gw,
3746 	register XIMInputMethod*	pInputMethod,
3747 	register XIMInputContext*	pInputContext,
3748 	register XIMData*			pData,
3749 	register int				nDataLength,
3750 	register int				iMode)
3751 {
3752 	register Window	winFocus ;
3753 
3754 	if (nDataLength < GET_VALUE_LENGTH (CARD32)){
3755 		register int			nMethodID, nContextID ;
3756 
3757 		nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3758 		nContextID	= XIMInputContext_GetID (pInputContext) ;
3759 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadFocusWindow, "Bad focus window") ;
3760 		return	False ;
3761 	}
3762 	winFocus	= (Window) XIMData_GetCard32 (pData) ;
3763 	if (!XIMInputContext_SetFocusWindow (pInputContext, winFocus)){
3764 		//	���ԡ���
3765 	}
3766 	return	True ;
3767 }
3768 
3769 Boolean
ximClient_setIcValueResetState(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)3770 ximClient_setIcValueResetState (
3771 	register Widget				gw,
3772 	register XIMInputMethod*	pInputMethod,
3773 	register XIMInputContext*	pInputContext,
3774 	register XIMData*			pData,
3775 	register int				nDataLength,
3776 	register int				iMode)
3777 {
3778 	register XIMResetState	ulState ;
3779 	register Boolean		fSuccess ;
3780 
3781 	fSuccess	= False ;
3782 	if (nDataLength >= GET_VALUE_LENGTH (XIMResetState)){
3783 		ulState		= (XIMResetState) XIMData_GetCard32 (pData) ;
3784 		fSuccess	= XIMInputContext_SetResetState (pInputContext, ulState) ;
3785 	}
3786 	if (!fSuccess) {
3787 		register int	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3788 		register int	nContextID	= XIMInputContext_GetID (pInputContext) ;
3789 
3790 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "Bad reset state") ;
3791 	}
3792 	return	fSuccess ;
3793 }
3794 
3795 Boolean
ximClient_setIcValuePreeditState(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)3796 ximClient_setIcValuePreeditState (
3797 	register Widget				gw,
3798 	register XIMInputMethod*	pInputMethod,
3799 	register XIMInputContext*	pInputContext,
3800 	register XIMData*			pData,
3801 	register int				nDataLength,
3802 	register int				iMode)
3803 {
3804 	register XIMPreeditState	ulState ;
3805 	register Boolean			fSuccess ;
3806 
3807 	fSuccess	= False ;
3808 	if (nDataLength >= GET_VALUE_LENGTH (XIMPreeditState)){
3809 		ulState		= (XIMResetState) XIMData_GetCard32 (pData) ;
3810 		fSuccess	= XIMInputContext_SetPreeditState (pInputContext, ulState) ;
3811 	}
3812 	if (!fSuccess) {
3813 		register int	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3814 		register int	nContextID	= XIMInputContext_GetID (pInputContext) ;
3815 
3816 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "Bad preedit state") ;
3817 	}
3818 	return	fSuccess ;
3819 }
3820 
3821 Boolean
ximClient_setIcValuePreeditAttributes(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)3822 ximClient_setIcValuePreeditAttributes (
3823 	register Widget				gw,
3824 	register XIMInputMethod*	pInputMethod,
3825 	register XIMInputContext*	pInputContext,
3826 	register XIMData*			pData,
3827 	register int				nDataLength,
3828 	register int				iMode)
3829 {
3830 	/*
3831 	 *	XNPreeditAttributes �ξ��ˤϡ����� XICATTRIBUTE �� value ��
3832 	 *	XICATTRIBUTE �� List �ˤʤäƤ��롣
3833 	 *	List ���礭���� XNPreeditAttributes �� value length ��Ϳ�����롣
3834 	 */
3835 	return	ximClient_setIcValues (gw, pInputMethod, pInputContext, pData, nDataLength, iMode | PREEDITATTRIBUTES_MASK) ;
3836 }
3837 
3838 Boolean
ximClient_setIcValueStatusAttributes(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)3839 ximClient_setIcValueStatusAttributes (
3840 	register Widget				gw,
3841 	register XIMInputMethod*	pInputMethod,
3842 	register XIMInputContext*	pInputContext,
3843 	register XIMData*			pData,
3844 	register int				nDataLength,
3845 	register int				iMode)
3846 {
3847 	/*
3848 	 *	XNStatusAttributes �ξ��ˤϡ����� XICATTRIBUTE �� value ��
3849 	 *	XICATTRIBUTE �� List �ˤʤäƤ��롣
3850 	 *	List ���礭���� XNStatusAttributes �� value length ��Ϳ�����롣
3851 	 */
3852 	return	ximClient_setIcValues (gw, pInputMethod, pInputContext, pData, nDataLength, iMode | STATUSATTRIBUTES_MASK) ;
3853 }
3854 
3855 Boolean
ximClient_setIcValueArea(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)3856 ximClient_setIcValueArea (
3857 	register Widget				gw,
3858 	register XIMInputMethod*	pInputMethod,
3859 	register XIMInputContext*	pInputContext,
3860 	register XIMData*			pData,
3861 	register int				nDataLength,
3862 	register int				iMode)
3863 {
3864 	register int			nMethodID, nContextID ;
3865 	XRectangle				rect ;
3866 
3867 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3868 	nContextID	= XIMInputContext_GetID (pInputContext) ;
3869 
3870 	if (nDataLength < (GET_VALUE_LENGTH (CARD16) * 4)){
3871 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadArea, "Bad area") ;
3872 		return	False ;
3873 	}
3874 
3875 	rect.x	= (INT16)XIMData_GetCard16 (pData) ;
3876 	rect.y	= (INT16)XIMData_GetCard16 (pData) ;
3877 	rect.width	= (CARD16)XIMData_GetCard16 (pData) ;
3878 	rect.height	= (CARD16)XIMData_GetCard16 (pData) ;
3879 	if (iMode & PREEDITATTRIBUTES_MASK){
3880 		if (!XIMInputContext_SetPreeditArea (pInputContext, &rect)){
3881 			ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadArea, "Bad area") ;
3882 			return	False ;
3883 		}
3884 	} else if (iMode & STATUSATTRIBUTES_MASK){
3885 		if (!XIMInputContext_SetStatusArea (pInputContext, &rect)){
3886 			ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadArea, "Bad area") ;
3887 			return	False ;
3888 		}
3889 	} else {
3890 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
3891 		return	False ;
3892 	}
3893 	return	True ;
3894 }
3895 
3896 Boolean
ximClient_setIcValueAreaNeeded(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)3897 ximClient_setIcValueAreaNeeded (
3898 	register Widget				gw,
3899 	register XIMInputMethod*	pInputMethod,
3900 	register XIMInputContext*	pInputContext,
3901 	register XIMData*			pData,
3902 	register int				nDataLength,
3903 	register int				iMode)
3904 {
3905 	register int		nMethodID, nContextID ;
3906 	XRectangle			rect ;
3907 
3908 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3909 	nContextID	= XIMInputContext_GetID (pInputContext) ;
3910 
3911 	if (nDataLength < (GET_VALUE_LENGTH (CARD16) * 4)){
3912 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadArea, "Bad area needed") ;
3913 		return	False ;
3914 	}
3915 
3916 	rect.x	= (INT16)XIMData_GetCard16 (pData) ;
3917 	rect.y	= (INT16)XIMData_GetCard16 (pData) ;
3918 	rect.width	= (CARD16)XIMData_GetCard16 (pData) ;
3919 	rect.height	= (CARD16)XIMData_GetCard16 (pData) ;
3920 	if (iMode & PREEDITATTRIBUTES_MASK){
3921 		if (!XIMInputContext_SetPreeditAreaNeeded (pInputContext, &rect)){
3922 			return	False ;
3923 		}
3924 	} else if (iMode & STATUSATTRIBUTES_MASK){
3925 		if (!XIMInputContext_SetStatusAreaNeeded (pInputContext, &rect)){
3926 			return	False ;
3927 		}
3928 	} else {
3929 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
3930 		return	False ;
3931 	}
3932 	return	True ;
3933 }
3934 
3935 Boolean
ximClient_setIcValueSpotLocation(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)3936 ximClient_setIcValueSpotLocation (
3937 	register Widget				gw,
3938 	register XIMInputMethod*	pInputMethod,
3939 	register XIMInputContext*	pInputContext,
3940 	register XIMData*			pData,
3941 	register int				nDataLength,
3942 	register int				iMode)
3943 {
3944 	register int		nMethodID, nContextID ;
3945 	XPoint				pos ;
3946 
3947 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3948 	nContextID	= XIMInputContext_GetID (pInputContext) ;
3949 
3950 	if (nDataLength < (GET_VALUE_LENGTH (CARD16) + GET_VALUE_LENGTH (CARD16))){
3951 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadSpotLocation, "Bad spot location") ;
3952 		return	False ;
3953 	}
3954 
3955 	pos.x	= (INT16)XIMData_GetCard16 (pData) ;
3956 	pos.y	= (INT16)XIMData_GetCard16 (pData) ;
3957 	if (iMode & PREEDITATTRIBUTES_MASK){
3958 		if (!XIMInputContext_SetSpotLocation (pInputContext, &pos)){
3959 			return	False ;
3960 		}
3961 	} else if (iMode & STATUSATTRIBUTES_MASK){
3962 		/*
3963 		 *	StatusAttribute �ˤ� SpotLocation �Ϥʤ���
3964 		 *	���ꤷ�褦�Ȥ���С�����ϥ��顼�Ȥʤ롣
3965 		 */
3966 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "StatusAttribute doesn't have attribute: SpotLocation") ;
3967 		return	False ;
3968 	} else {
3969 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
3970 		return	False ;
3971 	}
3972 	return	True ;
3973 }
3974 
3975 Boolean
ximClient_setIcValueColormap(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)3976 ximClient_setIcValueColormap (
3977 	register Widget				gw,
3978 	register XIMInputMethod*	pInputMethod,
3979 	register XIMInputContext*	pInputContext,
3980 	register XIMData*			pData,
3981 	register int				nDataLength,
3982 	register int				iMode)
3983 {
3984 	register int		nMethodID, nContextID ;
3985 	register Colormap	colormap ;
3986 
3987 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
3988 	nContextID	= XIMInputContext_GetID (pInputContext) ;
3989 
3990 	if (nDataLength < GET_VALUE_LENGTH (CARD32)){
3991 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadColormap, "Bad colormap") ;
3992 		return	False ;
3993 	}
3994 
3995 	colormap	= (Colormap) XIMData_GetCard32 (pData) ;
3996 	if (iMode & PREEDITATTRIBUTES_MASK){
3997 		if (!XIMInputContext_SetPreeditColormap (pInputContext, colormap)){
3998 			return	False ;
3999 		}
4000 	} else if (iMode & STATUSATTRIBUTES_MASK){
4001 		if (!XIMInputContext_SetStatusColormap (pInputContext, colormap)){
4002 			return	False ;
4003 		}
4004 	} else {
4005 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
4006 		return	False ;
4007 	}
4008 	return	True ;
4009 }
4010 
4011 Boolean
ximClient_setIcValueStdColormap(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)4012 ximClient_setIcValueStdColormap (
4013 	register Widget				gw,
4014 	register XIMInputMethod*	pInputMethod,
4015 	register XIMInputContext*	pInputContext,
4016 	register XIMData*			pData,
4017 	register int				nDataLength,
4018 	register int				iMode)
4019 {
4020 	register int			nMethodID, nContextID ;
4021 	register Colormap	colormap ;
4022 
4023 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
4024 	nContextID	= XIMInputContext_GetID (pInputContext) ;
4025 
4026 	if (nDataLength < GET_VALUE_LENGTH (CARD32)){
4027 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadColormap, "Bad standard colormap") ;
4028 		return	False ;
4029 	}
4030 
4031 	colormap	= (Colormap) XIMData_GetCard32 (pData) ;
4032 	if (iMode & PREEDITATTRIBUTES_MASK){
4033 		if (!XIMInputContext_SetPreeditStdColormap (pInputContext, colormap)){
4034 			return	False ;
4035 		}
4036 	} else if (iMode & STATUSATTRIBUTES_MASK){
4037 		if (!XIMInputContext_SetStatusStdColormap (pInputContext, colormap)){
4038 			return	False ;
4039 		}
4040 	} else {
4041 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
4042 		return	False ;
4043 	}
4044 	return	True ;
4045 }
4046 
4047 Boolean
ximClient_setIcValueForeground(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)4048 ximClient_setIcValueForeground (
4049 	register Widget				gw,
4050 	register XIMInputMethod*	pInputMethod,
4051 	register XIMInputContext*	pInputContext,
4052 	register XIMData*			pData,
4053 	register int				nDataLength,
4054 	register int				iMode)
4055 {
4056 	register int			nMethodID, nContextID ;
4057 	register unsigned long	ulForeground ;
4058 
4059 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
4060 	nContextID	= XIMInputContext_GetID (pInputContext) ;
4061 
4062 	if (nDataLength < GET_VALUE_LENGTH (CARD32)){
4063 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadPixel, "Bad pixel") ;
4064 		return	False ;
4065 	}
4066 	ulForeground	= (unsigned long) XIMData_GetCard32 (pData) ;
4067 	if (iMode & PREEDITATTRIBUTES_MASK){
4068 		if (!XIMInputContext_SetPreeditForeground (pInputContext, ulForeground)){
4069 			return	False ;
4070 		}
4071 	} else if (iMode & STATUSATTRIBUTES_MASK){
4072 		if (!XIMInputContext_SetStatusForeground (pInputContext, ulForeground)){
4073 			return	False ;
4074 		}
4075 	} else {
4076 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
4077 		return	False ;
4078 	}
4079 	return	True ;
4080 }
4081 
4082 Boolean
ximClient_setIcValueBackground(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)4083 ximClient_setIcValueBackground (
4084 	register Widget				gw,
4085 	register XIMInputMethod*	pInputMethod,
4086 	register XIMInputContext*	pInputContext,
4087 	register XIMData*			pData,
4088 	register int				nDataLength,
4089 	register int				iMode)
4090 {
4091 	register int			nMethodID, nContextID ;
4092 	register unsigned long	ulBackground ;
4093 
4094 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
4095 	nContextID	= XIMInputContext_GetID (pInputContext) ;
4096 
4097 	if (nDataLength < GET_VALUE_LENGTH (CARD32)){
4098 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadPixel, "Bad pixel") ;
4099 		return	False ;
4100 	}
4101 
4102 	ulBackground	= (unsigned long) XIMData_GetCard32 (pData) ;
4103 	if (iMode & PREEDITATTRIBUTES_MASK){
4104 		if (!XIMInputContext_SetPreeditBackground (pInputContext, ulBackground)){
4105 			return	False ;
4106 		}
4107 	} else if (iMode & STATUSATTRIBUTES_MASK){
4108 		if (!XIMInputContext_SetStatusBackground (pInputContext, ulBackground)){
4109 			return	False ;
4110 		}
4111 	} else {
4112 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
4113 		return	False ;
4114 	}
4115 	return	True ;
4116 }
4117 
4118 Boolean
ximClient_setIcValueBackgroundPixmap(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)4119 ximClient_setIcValueBackgroundPixmap (
4120 	register Widget				gw,
4121 	register XIMInputMethod*	pInputMethod,
4122 	register XIMInputContext*	pInputContext,
4123 	register XIMData*			pData,
4124 	register int				nDataLength,
4125 	register int				iMode)
4126 {
4127 	register int			nMethodID, nContextID ;
4128 	register Pixmap			pixmap ;
4129 
4130 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
4131 	nContextID	= XIMInputContext_GetID (pInputContext) ;
4132 
4133 	if (nDataLength < GET_VALUE_LENGTH (CARD32)){
4134 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadPixmap, "Bad pixmap") ;
4135 		return	False ;
4136 	}
4137 
4138 	pixmap	= (Pixmap)XIMData_GetCard32 (pData) ;
4139 	if (iMode & PREEDITATTRIBUTES_MASK){
4140 		if (!XIMInputContext_SetPreeditBackgroundPixmap (pInputContext, pixmap)){
4141 			return	False ;
4142 		}
4143 	} else if (iMode & STATUSATTRIBUTES_MASK){
4144 		if (!XIMInputContext_SetStatusBackgroundPixmap (pInputContext, pixmap)){
4145 			return	False ;
4146 		}
4147 	} else {
4148 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
4149 		return	False ;
4150 	}
4151 	return	True ;
4152 }
4153 
4154 Boolean
ximClient_setIcValueFontSet(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)4155 ximClient_setIcValueFontSet (
4156 	register Widget				gw,
4157 	register XIMInputMethod*	pInputMethod,
4158 	register XIMInputContext*	pInputContext,
4159 	register XIMData*			pData,
4160 	register int				nDataLength,
4161 	register int				iMode)
4162 {
4163 	register int			nMethodID, nContextID ;
4164 	register const char*	pFontSetBaseName ;
4165 	register int			nFontSetBaseNameLength ;
4166 
4167 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
4168 	nContextID	= XIMInputContext_GetID (pInputContext) ;
4169 
4170 	/*	�ե����̾��ȴ���Ф���*/
4171 	pFontSetBaseName		= 0 ;
4172 	nFontSetBaseNameLength	= -1 ;
4173 	if (nDataLength >= GET_VALUE_LENGTH (CARD16)){
4174 		nFontSetBaseNameLength	= (int)XIMData_GetCard16 (pData) ;
4175 		nDataLength			-= GET_VALUE_LENGTH (CARD16) ;
4176 		if (nDataLength >= nFontSetBaseNameLength)
4177 			pFontSetBaseName	= (const char*)XIMData_GetHead (pData) ;
4178 	}
4179 	/*	�ե����̾���������Ȥ줿���ɤ��������å����롣*/
4180 	if (nFontSetBaseNameLength <= 0){
4181 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadName, "Bad fontset") ;
4182 		return	False ;
4183 	}
4184 	if (iMode & PREEDITATTRIBUTES_MASK){
4185 		if (!XIMInputContext_SetPreeditFontSet (pInputContext, pFontSetBaseName, nFontSetBaseNameLength)){
4186 			return	False ;
4187 		}
4188 	} else if (iMode & STATUSATTRIBUTES_MASK){
4189 		if (!XIMInputContext_SetStatusFontSet (pInputContext, pFontSetBaseName, nFontSetBaseNameLength)){
4190 			return	False ;
4191 		}
4192 	} else {
4193 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
4194 		return	False ;
4195 	}
4196 	return	True ;
4197 }
4198 
4199 Boolean
ximClient_setIcValueLineSpacing(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)4200 ximClient_setIcValueLineSpacing (
4201 	register Widget				gw,
4202 	register XIMInputMethod*	pInputMethod,
4203 	register XIMInputContext*	pInputContext,
4204 	register XIMData*			pData,
4205 	register int				nDataLength,
4206 	register int				iMode)
4207 {
4208 	register int		nMethodID, nContextID ;
4209 	register long		lLineSpacing ;
4210 
4211 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
4212 	nContextID	= XIMInputContext_GetID (pInputContext) ;
4213 
4214 	if (nDataLength < GET_VALUE_LENGTH (CARD32)){
4215 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "Bad line spacing") ;
4216 		return	False ;
4217 	}
4218 
4219 	lLineSpacing	= (long) XIMData_GetCard32 (pData) ;
4220 	if (iMode & PREEDITATTRIBUTES_MASK){
4221 		if (!XIMInputContext_SetPreeditLineSpacing (pInputContext, lLineSpacing)){
4222 			ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "Bad line spacing") ;
4223 			return	False ;
4224 		}
4225 	} else if (iMode & STATUSATTRIBUTES_MASK){
4226 		if (!XIMInputContext_SetStatusLineSpacing (pInputContext, lLineSpacing)){
4227 			ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "Bad line spacing") ;
4228 			return	False ;
4229 		}
4230 	} else {
4231 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
4232 		return	False ;
4233 	}
4234 	return	True ;
4235 }
4236 
4237 Boolean
ximClient_setIcValueCursor(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XIMData * pData,register int nDataLength,register int iMode)4238 ximClient_setIcValueCursor (
4239 	register Widget				gw,
4240 	register XIMInputMethod*	pInputMethod,
4241 	register XIMInputContext*	pInputContext,
4242 	register XIMData*			pData,
4243 	register int				nDataLength,
4244 	register int				iMode)
4245 {
4246 	register int			nMethodID, nContextID ;
4247 	register Cursor			cursor ;
4248 
4249 	nMethodID	= XIMInputMethod_GetID  (pInputMethod) ;
4250 	nContextID	= XIMInputContext_GetID (pInputContext) ;
4251 
4252 	if (nDataLength < GET_VALUE_LENGTH (CARD32)){
4253 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadCursor, "Bad cursor") ;
4254 		return	False ;
4255 	}
4256 
4257 	cursor	= (Cursor) XIMData_GetCard32 (pData) ;
4258 	if (iMode & PREEDITATTRIBUTES_MASK){
4259 		if (!XIMInputContext_SetPreeditCursor (pInputContext, cursor)){
4260 			return	False ;
4261 		}
4262 	} else if (iMode & STATUSATTRIBUTES_MASK){
4263 		if (!XIMInputContext_SetStatusCursor (pInputContext, cursor)){
4264 			return	False ;
4265 		}
4266 	} else {
4267 		ximClient_writeErrorMessage (gw, nMethodID, nContextID, XIM_ERROR_BadProtocol, "PreeditAttribute or StatusAttribute?") ;
4268 		return	False ;
4269 	}
4270 	return	True ;
4271 }
4272 
4273 int
ximClient_supportedEncodingp(register const char * pStrEncoding,register int nStrEncoding)4274 ximClient_supportedEncodingp (
4275 	register const char*	pStrEncoding,
4276 	register int			nStrEncoding)
4277 {
4278 	static const XIMCodingSystem	srSupportedEncodings []	= {
4279 		{	"eucJP",			KCODING_SYSTEM_EUCJP, },
4280 		{	"SJIS",				KCODING_SYSTEM_SHIFTJIS, },
4281 		{	"COMPOUND_TEXT",	KCODING_SYSTEM_COMPOUND_TEXT, },
4282 	} ;
4283 	register const XIMCodingSystem*	pPtr ;
4284 	register int	i ;
4285 
4286 	pPtr	= srSupportedEncodings ;
4287 	for (i = 0 ; i < NELEMENTS (srSupportedEncodings) ; i ++) {
4288 		if (!strncmp (pPtr->m_pEncodingName, pStrEncoding, nStrEncoding) &&
4289 			*(pPtr->m_pEncodingName + nStrEncoding) == '\0')
4290 			return	pPtr->m_nCodingSystem ;
4291 		pPtr	++ ;
4292 	}
4293 	return	KCODING_SYSTEM_UNKNOWN ;
4294 }
4295 
4296 void
ximClient_writeSyncReply(register Widget gw,register int nInputMethodID,register XIMInputContext * pInputContext)4297 ximClient_writeSyncReply (
4298 	register Widget				gw,
4299 	register int				nInputMethodID,
4300 	register XIMInputContext*	pInputContext)
4301 {
4302 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
4303 	register XIMPacket*			pPacket	= NULL ;
4304 	register unsigned 			uSyncMode ;
4305 
4306 #if 1
4307 	while (uSyncMode = XIMInputContext_GetSyncMode (pInputContext),
4308 		   (uSyncMode & XIMSyncAny) == 0) {
4309 		register XIMPacketSyncMode	uPacketSync ;
4310 
4311 		pPacket		= XIMInputContext_GetSpooledPacket (pInputContext) ;
4312 		if (pPacket == NULL)
4313 			break ;
4314 
4315 		uPacketSync	= XIMPacket_GetSyncMode (pPacket) ;
4316 		/*	�ƶ��������Τϡ�SYNC_NORMAL �ʥѥ��åȤ���������ʳ���
4317 		 *	�ѥ��åȤϼ�ʬ�Υ֥�å��˽�����
4318 		 */
4319 		switch (uPacketSync) {
4320 			register int		nPacket ;
4321 		case	XIMPS_SPOOL:
4322 			/*	�֥�å��⡼�ɤǤ��뤫����³�Υѥ��åȤ�¸�ߤ�����ˤϡ�
4323 			 *	���ꤲ��ѥ��åȤ� SYNC �⡼�ɤǤʤ���Фʤ�ʤ���*/
4324 			nPacket		= XIMInputContext_GetNumberOfSpooledPacket (pInputContext) ;
4325 			if (nPacket > 0) {
4326 				/*	�ѥ��åȤ� SYNC �⡼�ɤ��ڤ��ؤ��ʤ���Фʤ�ʤ���*/
4327 				ximClient_makePacketSync (pPacket) ;
4328 				break ;
4329 			}
4330 			/*	fall down */
4331 
4332 		case	XIMPS_SPOOL_PREEDIT:
4333 			/*	�ѥ��åȤ� SYNC �Ǥʤ����ɤ���¿ʬ�����Τޤ��ꤲ��
4334 			 *	����ס�*/
4335 			XIMPacket_SetSyncMode (pPacket, XIMPS_NO) ;
4336 			break ;
4337 
4338 		case	XIMPS_SPOOL_PREEDIT_START:
4339 		case	XIMPS_SPOOL_PREEDIT_CARET:
4340 			/*	spool -> sync ���ѹ�����롣*/
4341 			XIMPacket_SetSyncMode (pPacket, uPacketSync + (XIMPS_SYNC_PREEDIT_START - XIMPS_SPOOL_PREEDIT_START)) ;
4342 			break ;
4343 
4344 		default:
4345 			break ;
4346 		}
4347 		ximClient_writeMessage (gw, pPacket) ;
4348 		XIMPacket_Release (pPacket) ;
4349 	}
4350 #else
4351 	uSyncMode	= XIMInputContext_GetSyncMode (pInputContext) ;
4352 	if (!(uSyncMode & (XIMSyncNormal | XIMSyncPreeditStart | XIMSyncPreeditCaret))) {
4353 		pPacket		= XIMInputContext_GetSpooledPacket (pInputContext) ;
4354 		if (pPacket != NULL) {
4355 			register XIMPacketSyncMode	uPacketSync	= XIMPacket_GetSyncMode (pPacket) ;
4356 
4357 			/*	�ƶ��������Τϡ�SYNC_NORMAL �ʥѥ��åȤ���������ʳ���
4358 			 *	�ѥ��åȤϼ�ʬ�Υ֥�å��˽�����
4359 			 */
4360 			if (uPacketSync == XIMPS_SPOOL) {
4361 				register int				nPacket ;
4362 
4363 				/*	�֥�å��⡼�ɤǤ��뤫����³�Υѥ��åȤ�¸�ߤ�����ˤϡ�
4364 				 *	���ꤲ��ѥ��åȤ� SYNC �⡼�ɤǤʤ���Фʤ�ʤ���*/
4365 				nPacket		= XIMInputContext_GetNumberOfSpooledPacket (pInputContext) ;
4366 				if (nPacket > 0) {
4367 					/*	�ѥ��åȤ� SYNC �⡼�ɤ��ڤ��ؤ��ʤ���Фʤ�ʤ���*/
4368 					ximClient_makePacketSync (pPacket) ;
4369 				} else {
4370 					/*	�ѥ��åȤ� SYNC �Ǥʤ����ɤ���¿ʬ�����Τޤ��ꤲ��
4371 					 *	����ס�*/
4372 					XIMPacket_SetSyncMode (pPacket, XIMPS_NO) ;
4373 				}
4374 			}
4375 			ximClient_writeMessage (gw, pPacket) ;
4376 			XIMPacket_Release (pPacket) ;
4377 		}
4378 	} else {
4379 		/*	�֥�å�����Ƥ���Τʤ顢SYNC_REPLY �ʳ��Υѥ��åȤ��ꤲ�ƤϤ�����
4380 		 *	����*/
4381 		pPacket		= NULL ;
4382 	}
4383 #endif
4384 
4385 	/*	SYNC REPLY �����Ф��롣
4386 	 */
4387 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
4388 	XIMPacket_SetHeader (pPacket, XIM_SYNC_REPLY, 0) ;
4389 	XIMPacket_AddCard16 (pPacket, nInputMethodID) ;
4390 	XIMPacket_AddCard16 (pPacket, XIMInputContext_GetID (pInputContext)) ;
4391 	XIMPacket_SetLength (pPacket) ;
4392 	ximClient_writeMessage (gw, pPacket) ;
4393 	XIMPacket_Release (pPacket) ;
4394 	return ;
4395 }
4396 
4397 void
ximClient_makePacketSync(register XIMPacket * pPacket)4398 ximClient_makePacketSync (
4399 	register XIMPacket*		pPacket)
4400 {
4401 	int				nMajor ;
4402 	CARD16			uMask ;
4403 
4404 	XIMPacket_GetHeader (pPacket, &nMajor, NULL) ;
4405 	assert (nMajor == XIM_COMMIT ||
4406 			nMajor == XIM_FORWARD_EVENT ||
4407 			nMajor == XIM_EXT_FORWARD_KEYEVENT) ;
4408 
4409 	XIMPacket_SetSyncMode (pPacket, XIMPS_SYNC_NORMAL) ;
4410 	XIMPacket_GetCard16   (pPacket, XIM_HEADER_SIZE + 2 + 2, &uMask) ;
4411 	XIMPacket_SetCard16   (pPacket, XIM_HEADER_SIZE + 2 + 2, uMask | 1) ;
4412 	return ;
4413 }
4414 
4415 void
ximClient_flushSpooledPacket(register Widget gw,register XIMInputContext * pInputContext)4416 ximClient_flushSpooledPacket (
4417 	register Widget				gw,
4418 	register XIMInputContext*	pInputContext)
4419 {
4420 	register XIMPacket*		pPacket ;
4421 	register unsigned int	uSyncMode ;
4422 
4423 	while (uSyncMode = XIMInputContext_GetSyncMode (pInputContext),
4424 		   (uSyncMode & XIMSyncAny) == 0) {
4425 		register XIMPacketSyncMode	uPacketSync ;
4426 
4427 		pPacket		= XIMInputContext_GetSpooledPacket (pInputContext) ;
4428 		if (pPacket == NULL)
4429 			break ;
4430 
4431 		uPacketSync	= XIMPacket_GetSyncMode (pPacket) ;
4432 		/*	�ƶ��������Τϡ�SYNC_NORMAL �ʥѥ��åȤ���������ʳ���
4433 		 *	�ѥ��åȤϼ�ʬ�Υ֥�å��˽�����
4434 		 */
4435 		switch (uPacketSync) {
4436 		case	XIMPS_SPOOL:
4437 			ximClient_makePacketSync (pPacket) ;
4438 			break ;
4439 
4440 		case	XIMPS_SPOOL_PREEDIT:
4441 			/*	�ѥ��åȤ� SYNC �Ǥʤ����ɤ���¿ʬ�����Τޤ��ꤲ��
4442 			 *	����ס�*/
4443 			XIMPacket_SetSyncMode (pPacket, XIMPS_NO) ;
4444 			break ;
4445 
4446 		case	XIMPS_SPOOL_PREEDIT_START:
4447 		case	XIMPS_SPOOL_PREEDIT_CARET:
4448 			/*	spool -> sync ���ѹ�����롣*/
4449 			XIMPacket_SetSyncMode (pPacket, uPacketSync + (XIMPS_SYNC_PREEDIT_START - XIMPS_SPOOL_PREEDIT_START)) ;
4450 			break ;
4451 
4452 		default:
4453 			break ;
4454 		}
4455 		ximClient_writeMessage (gw, pPacket) ;
4456 		XIMPacket_Release (pPacket) ;
4457 	}
4458 	return ;
4459 }
4460 
4461 /*
4462  */
4463 Boolean
XIMClient_CommitString(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register const Char * pText,register int nText)4464 XIMClient_CommitString (
4465 	register Widget				gw,
4466 	register XIMInputMethod*	pInputMethod,
4467 	register XIMInputContext*	pInputContext,
4468 	register const Char*		pText,
4469 	register int				nText)
4470 {
4471 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
4472 	register XIMPacket*			pPacket ;
4473 	KANJISTATEMACHINE			ksm ;
4474 	char						rchBuf [16] ;
4475 	register int				nCodingSystem ;
4476 	register int				nMethodID, nContextID ;
4477 	register int				nPacketSync ;
4478 	register unsigned int		uMask, uSyncMode ;
4479 
4480 	if (pInputMethod == NULL || pInputContext == NULL || nText <= 0)
4481 		return	False ;
4482 
4483 	nCodingSystem	= XIMInputMethod_GetCodingSystem (pInputMethod) ;
4484 	nMethodID		= XIMInputMethod_GetID  (pInputMethod) ;
4485 	nContextID		= XIMInputContext_GetID (pInputContext) ;
4486 
4487 #if defined (DEBUG)
4488 	fprintf (stderr, "XIMClient_CommitString (%p), IM(%d), IC(%d), Text(%p/%d)\n",
4489 			 gw,nMethodID, nContextID, pText, nText) ;
4490 #endif
4491 
4492 	/*	���饤����Ȥ��� SYNC_REPLY ���֤����Ȥ��׵ᤵ��Ƥʤ���or
4493 	 *	�֥�å��⡼�ɤˤ��롢
4494 	 *	���ξ��ˤϡ����Ф���ѥ��åȤ�Ʊ�������ǤȤ�ʤ��Ȥ�
4495 	 *	���ʤ��Τǡ�SYNC MASK �դ��ˤʤ롣
4496 	 */
4497 	uSyncMode	= XIMInputContext_GetSyncMode (pInputContext) ;
4498 	if (!(uSyncMode & XIMClientSync) ||
4499 		(uSyncMode & (XIMSyncNormal | XIMSyncPreeditStart | XIMSyncPreeditCaret))) {
4500 		nPacketSync	= XIMPS_SYNC_NORMAL ;
4501 		uMask		= 1 | 2 ;
4502 	} else {
4503 		/*	Client �� Sync-Reply ���֤����ʤ顢�ǽ�� 1 �Ĥ�
4504 		 *	�ѥ��åȤʤ�֥�å�����Ƥ��ʤ��Ƥ��ɤ����ǡ�
4505 		 *	�ǽ�� 1 �Ĥ��ɤ����ʤ�Ƥ�Ƚ��Ϥ����ǤϤǤ��ʤ�
4506 		 *	�Τǡ�SYNC ��̵��!�ˤ��Ƥ�����
4507 		 */
4508 		nPacketSync	= XIMPS_SPOOL ;
4509 		uMask		= 2 ;
4510 	}
4511 	while (nText > 0) {
4512 		if (*pText != '\n' && *pText != '\r' && *pText != ' ') {
4513 			register int	nctext, nptr, nIndex ;
4514 
4515 			pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
4516 			XIMPacket_SetHeader (pPacket, XIM_COMMIT, 0) ;
4517 			XIMPacket_AddCard16 (pPacket, nMethodID) ;
4518 			XIMPacket_AddCard16 (pPacket, nContextID) ;
4519 			XIMPacket_SetInputContext (pPacket, pInputContext) ;
4520 			XIMPacket_SetSyncMode  (pPacket, nPacketSync) ;
4521 			XIMPacket_AddBitmask16 (pPacket, uMask) ;
4522 			nIndex	= XIMPacket_GetDataSize (pPacket) ;
4523 			XIMPacket_AddCard16 (pPacket, 0 /* dummy */) ;
4524 
4525 			InitializeKanjiFiniteStateMachine (&ksm, nCodingSystem) ;
4526 			nctext	= 0 ;
4527 			while (nText > 0 && *pText != '\n' && *pText != '\r' && *pText != ' ') {
4528 				nptr	= RtransferKanjiFiniteStateMachine (&ksm, *pText ++, rchBuf) ;
4529 				nText	-- ;
4530 				nctext	+= nptr ;
4531 				if (nptr > 0)
4532 					XIMPacket_AddString8 (pPacket, (STRING8)rchBuf, nptr) ;
4533 			}
4534 			XIMPacket_AddPad (pPacket, nctext) ;
4535 			XIMPacket_SetCard16 (pPacket, nIndex, nctext) ;
4536 			XIMPacket_SetLength (pPacket) ;
4537 			/**/
4538 			ximClient_writeMessage (gw, pPacket) ;
4539 			XIMPacket_Release (pPacket) ;
4540 		}
4541 		if (nText > 0) {
4542 			register KeySym		keysym	= (*pText != ' ')? XK_Return : XK_space ;
4543 			register char		ch		= (*pText != ' ')? '\n' : ' ' ;
4544 
4545 #if defined (DEBUG)
4546 			fprintf (stderr, "Send NL packet\n") ;
4547 #endif
4548 			pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
4549 			XIMPacket_SetHeader (pPacket, XIM_COMMIT, 0) ;
4550 			XIMPacket_AddCard16 (pPacket, nMethodID) ;
4551 			XIMPacket_AddCard16 (pPacket, nContextID) ;
4552 			XIMPacket_SetInputContext (pPacket, pInputContext) ;
4553 			XIMPacket_SetSyncMode  (pPacket, nPacketSync) ;
4554 			XIMPacket_AddBitmask16 (pPacket, uMask | 2 | 4) ;
4555 			XIMPacket_AddCard16    (pPacket, 0 /* unused */) ;
4556 			XIMPacket_AddCard32    (pPacket, keysym) ;
4557 			XIMPacket_AddCard16    (pPacket, 1) ;
4558 			XIMPacket_AddCard8     (pPacket, ch) ;
4559 			XIMPacket_AddPad       (pPacket, 1 + 2) ;
4560 			XIMPacket_SetLength    (pPacket) ;
4561 			/**/
4562 			ximClient_writeMessage (gw, pPacket) ;
4563 			XIMPacket_Release (pPacket) ;
4564 			pText	++ ;
4565 			nText	-- ;
4566 		}
4567 	}
4568 	return	True ;
4569 }
4570 
4571 Boolean
XIMClient_PreeditStateChange(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext)4572 XIMClient_PreeditStateChange (
4573 	register Widget				gw,
4574 	register XIMInputMethod*	pInputMethod,
4575 	register XIMInputContext*	pInputContext)
4576 {
4577 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
4578 	register XIMPacket*			pPacket ;
4579 
4580 	if (pInputMethod == NULL || pInputContext == NULL)
4581 		return	False ;
4582 
4583 	/*	XIM_PREEDITSTATE �� Asynchronous �� Message ���Ȼפ��ġ�*/
4584 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
4585 	XIMPacket_SetHeader (pPacket, XIM_PREEDITSTATE, 0) ;
4586 	XIMPacket_AddCard16 (pPacket, XIMInputMethod_GetID (pInputMethod)) ;
4587 	XIMPacket_AddCard16 (pPacket, XIMInputContext_GetID (pInputContext)) ;
4588 	XIMPacket_AddBitmask32 (pPacket, XIMInputContext_GetPreeditState (pInputContext)) ;
4589 	XIMPacket_SetLength (pPacket) ;
4590 	ximClient_writeMessage (gw, pPacket) ;
4591 	XIMPacket_Release (pPacket) ;
4592 	return	True ;
4593 }
4594 
4595 Boolean
XIMClient_ControlEventFlow(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register Boolean fEnable)4596 XIMClient_ControlEventFlow (
4597 	register Widget				gw,
4598 	register XIMInputMethod*	pInputMethod,
4599 	register XIMInputContext*	pInputContext,
4600 	register Boolean			fEnable)
4601 {
4602 	if (pInputMethod == NULL || pInputContext == NULL)
4603 		return	False ;
4604 	ximClient_setForwardEvent (gw, pInputMethod, pInputContext, fEnable) ;
4605 	return	True ;
4606 }
4607 
4608 
4609 /*
4610  */
4611 Boolean
XIMClient_ForwardEvent(register Widget gw,register XIMInputMethod * pInputMethod,register XIMInputContext * pInputContext,register XEvent * pEvent)4612 XIMClient_ForwardEvent (
4613 	register Widget				gw,
4614 	register XIMInputMethod*	pInputMethod,
4615 	register XIMInputContext*	pInputContext,
4616 	register XEvent*			pEvent)
4617 {
4618 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
4619 	register XIMPacket*			pPacket ;
4620 	register int				nPacketSync ;
4621 	register unsigned int		uMask, uSyncMode ;
4622 
4623 	if (pInputMethod == NULL || pInputContext == NULL ||
4624 		pEvent == NULL || (pEvent->type != KeyPress && pEvent->type != KeyRelease))
4625 		return	False ;
4626 
4627 	/*	���饤����Ȥ��� SYNC_REPLY ���֤����Ȥ��׵ᤵ��Ƥʤ���or
4628 	 *	�֥�å��⡼�ɤˤ��롢
4629 	 *	���ξ��ˤϡ����Ф���ѥ��åȤ�Ʊ�������ǤȤ�ʤ��Ȥ�
4630 	 *	���ʤ��Τǡ�SYNC MASK �դ��ˤʤ롣
4631 	 */
4632 	uSyncMode	= XIMInputContext_GetSyncMode (pInputContext) ;
4633 #if defined (DEBUG)
4634 	fprintf (stderr, "XIMClient_ForwardEvent (%d, %d, %x)\n",
4635 			 XIMInputMethod_GetID (pInputMethod),
4636 			 XIMInputContext_GetID (pInputContext),
4637 			 uSyncMode) ;
4638 #endif
4639 	if (!(uSyncMode & XIMClientSync) ||
4640 		(uSyncMode & (XIMSyncNormal | XIMSyncPreeditStart | XIMSyncPreeditCaret))) {
4641 		nPacketSync	= XIMPS_SYNC_NORMAL ;
4642 		uMask		= FORWARDEVENT_SYNC_MASK ;
4643 	} else {
4644 		/*	Client �� Sync-Reply ���֤����ʤ顢�ǽ�� 1 �Ĥ�
4645 		 *	�ѥ��åȤʤ�֥�å�����Ƥ��ʤ��Ƥ��ɤ����ǡ�
4646 		 *	�ǽ�� 1 �Ĥ��ɤ����ʤ�Ƥ�Ƚ��Ϥ����ǤϤǤ��ʤ�
4647 		 *	�Τǡ�SYNC ��̵��!�ˤ��Ƥ�����
4648 		 */
4649 		nPacketSync	= XIMPS_SPOOL ;
4650 		uMask		= 0 ;
4651 	}
4652 
4653 	pPacket		= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
4654 	if (XIMInputMethod_GetExtMask (pInputMethod) & XIM_EXT_FORWARD_KEYEVENT_MASK) {
4655 		XIMPacket_SetHeader (pPacket, XIM_EXT_FORWARD_KEYEVENT, 0) ;
4656 		XIMPacket_AddCard16 (pPacket, XIMInputMethod_GetID (pInputMethod)) ;
4657 		XIMPacket_AddCard16 (pPacket, XIMInputContext_GetID (pInputContext)) ;
4658 		XIMPacket_SetInputContext (pPacket, pInputContext) ;
4659 		XIMPacket_SetSyncMode  (pPacket, nPacketSync) ;
4660 		XIMPacket_AddBitmask16 (pPacket, uMask) ;
4661 		XIMPacket_AddCard16 (pPacket, (CARD16)pEvent->xkey.serial) ;
4662 		XIMPacket_AddCard8  (pPacket, (CARD8)pEvent->xkey.type & 0x7F) ;
4663 		XIMPacket_AddCard8  (pPacket, (CARD8)pEvent->xkey.keycode) ;
4664 		XIMPacket_AddCard16 (pPacket, (CARD16)pEvent->xkey.state) ;
4665 		XIMPacket_AddCard32 (pPacket, (CARD32)pEvent->xkey.time) ;
4666 		XIMPacket_AddCard32 (pPacket, (CARD32)pEvent->xkey.window) ;
4667 	} else {
4668 		xEvent			xev ;
4669 		Boolean			fSwap ;
4670 		unsigned long	one		= 1 ;
4671 		char*			onep	= (char *)&one ;
4672 
4673 		if (*onep == 0) {
4674 			fSwap	= !wgThis->ximClient.m_fBigEndian ;
4675 		} else {
4676 			fSwap	= wgThis->ximClient.m_fBigEndian ;
4677 		}
4678 #define	BIGCARD16(wValue)	((!fSwap)? (wValue) : (((wValue) & 0x00FF) << 8) | (((wValue) & 0xFF00) >> 8))
4679 #define	BIGCARD32(dwValue)	((!fSwap)? (dwValue) : ((((dwValue) & 0x000000FFl) << 24) | (((dwValue) & 0x0000FF00l) <<  8) | (((dwValue) & 0x00FF0000l) >>  8) | (((dwValue) & 0xFF000000l) >> 24)))
4680 		xev.u.u.type					= pEvent->type ;
4681 		xev.u.keyButtonPointer.root		= BIGCARD32 (pEvent->xkey.root) ;
4682 		xev.u.keyButtonPointer.event	= BIGCARD32 (pEvent->xkey.window) ;
4683 		xev.u.keyButtonPointer.child	= BIGCARD32 (pEvent->xkey.subwindow) ;
4684 		xev.u.keyButtonPointer.time		= BIGCARD32 (pEvent->xkey.time) ;
4685 		xev.u.keyButtonPointer.eventX	= BIGCARD16 (pEvent->xkey.x) ;
4686 		xev.u.keyButtonPointer.eventY	= BIGCARD16 (pEvent->xkey.y) ;
4687 		xev.u.keyButtonPointer.rootX	= BIGCARD16 (pEvent->xkey.x_root) ;
4688 		xev.u.keyButtonPointer.rootY	= BIGCARD16 (pEvent->xkey.y_root) ;
4689 		xev.u.keyButtonPointer.state	= BIGCARD16 (pEvent->xkey.state) ;
4690 		xev.u.keyButtonPointer.sameScreen	= pEvent->xkey.same_screen ;
4691 		//xev.u.u.sequenceNumber			= BIGCARD16 ((pEvent->xany.serial & 0x0000FFFFl)) ;
4692 		xev.u.u.detail					= pEvent->xkey.keycode ;
4693 		if (((XAnyEvent *)pEvent)->send_event)
4694 			xev.u.u.type				|= 0x80 ;
4695 		xev.u.u.sequenceNumber	= ((XAnyEvent *)pEvent)->serial & ~((unsigned long)0xffff);
4696 		xev.u.u.sequenceNumber	= BIGCARD16 (xev.u.u.sequenceNumber);
4697 #undef	BIGCARD16
4698 #undef	BIGCARD32
4699 
4700 		XIMPacket_SetHeader (pPacket, XIM_FORWARD_EVENT, 0) ;
4701 		XIMPacket_AddCard16 (pPacket, XIMInputMethod_GetID (pInputMethod)) ;
4702 		XIMPacket_AddCard16 (pPacket, XIMInputContext_GetID (pInputContext)) ;
4703 		XIMPacket_SetInputContext (pPacket, pInputContext) ;
4704 		XIMPacket_SetSyncMode  (pPacket, nPacketSync) ;
4705 		XIMPacket_AddBitmask16 (pPacket, uMask) ;
4706 		XIMPacket_AddCard16 (pPacket, (CARD16)(pEvent->xany.serial >> 16)) ;
4707 		XIMPacket_AddString8 (pPacket, (STRING8)&xev, sizeof (xEvent)) ;
4708 	}
4709 	XIMPacket_SetLength (pPacket) ;
4710 	/**/
4711 	ximClient_writeMessage (gw, pPacket) ;
4712 	XIMPacket_Release (pPacket) ;
4713 	return	True ;
4714 }
4715 
4716 void
XIMClient_WriteXimGeometry(register Widget gw,register int nInputMethodID,register int nInputContextID)4717 XIMClient_WriteXimGeometry (
4718 	register Widget		gw,
4719 	register int		nInputMethodID,
4720 	register int		nInputContextID)
4721 {
4722 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
4723 	register XIMPacket*			pPacket ;
4724 
4725 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
4726 	XIMPacket_SetHeader (pPacket, XIM_GEOMETRY, 0) ;
4727 	XIMPacket_AddCard16 (pPacket, nInputMethodID) ;
4728 	XIMPacket_AddCard16 (pPacket, nInputContextID) ;
4729 	XIMPacket_SetLength (pPacket) ;
4730 	ximClient_writeMessage (gw, pPacket) ;
4731 	XIMPacket_Release (pPacket) ;
4732 	return ;
4733 }
4734 
4735 void
XIMClient_WritePreeditStart(register Widget gw,register int nInputMethodID,register XIMInputContext * pInputContext)4736 XIMClient_WritePreeditStart (
4737 	register Widget				gw,
4738 	register int				nInputMethodID,
4739 	register XIMInputContext*	pInputContext)
4740 {
4741 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
4742 	register XIMPacket*			pPacket ;
4743 	register unsigned int		uSyncMode ;
4744 	register int				nInputContextID, nPacketSync ;
4745 
4746 	assert (gw   != NULL) ;
4747 
4748 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
4749 	if (pPacket == NULL)
4750 		return ;
4751 
4752 	nInputContextID	= XIMInputContext_GetID (pInputContext) ;
4753 	XIMPacket_SetHeader   (pPacket, XIM_PREEDIT_START, 0) ;
4754 	XIMPacket_AddCard16   (pPacket, nInputMethodID) ;
4755 	XIMPacket_AddCard16   (pPacket, nInputContextID) ;
4756 
4757 	XIMPacket_SetInputContext (pPacket, pInputContext) ;
4758 	/*	���� SYNC �ϲ���ޤǤΥ�å�������֥�å�����Τ�
4759 	 *	������ ¿ʬ�������Ĥ� reply �ޤǤ� PREEDIT �Ϥ�
4760 	 *	��å���������ߤ���Τ������ɡ�*/
4761 	uSyncMode	= XIMInputContext_GetSyncMode (pInputContext) ;
4762 	if ((uSyncMode & (XIMClientSync | XIMSyncAny)) == 0) {
4763 		nPacketSync	= XIMPS_SYNC_PREEDIT_START ;
4764 	} else {
4765 		nPacketSync	= XIMPS_SPOOL_PREEDIT_START ;
4766 	}
4767 	XIMPacket_SetSyncMode (pPacket, nPacketSync) ;
4768 	XIMPacket_SetLength   (pPacket) ;
4769 	ximClient_writeMessage (gw, pPacket) ;
4770 	XIMPacket_Release (pPacket) ;
4771 	return ;
4772 }
4773 
4774 void
XIMClient_WritePreeditDraw(register Widget gw,register int nInputMethodID,register XIMInputContext * pInputContext,register const TOnTheSpotDrawArg * pArg)4775 XIMClient_WritePreeditDraw (
4776 	register Widget				gw,
4777 	register int				nInputMethodID,
4778 	register XIMInputContext*	pInputContext,
4779 	register const TOnTheSpotDrawArg*	pArg)
4780 {
4781 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
4782 	register XIMPacket*			pPacket ;
4783 	KANJISTATEMACHINE			ksm ;
4784 	char						rchBuf [16] ;
4785 	register const Char*		pText ;
4786 	register int				nctext, nText, nIndex, nptr ;
4787 	register unsigned int		uMask, uSyncMode ;
4788 	register int				nInputContextID, nPacketSync ;
4789 
4790 	assert (gw   != NULL) ;
4791 	assert (pArg != NULL) ;
4792 
4793 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
4794 	if (pPacket == NULL)
4795 		return ;
4796 
4797 	nInputContextID	= XIMInputContext_GetID (pInputContext) ;
4798 	XIMPacket_SetHeader   (pPacket, XIM_PREEDIT_DRAW, 0) ;
4799 	XIMPacket_AddCard16   (pPacket, nInputMethodID) ;
4800 	XIMPacket_AddCard16   (pPacket, nInputContextID) ;
4801 	XIMPacket_AddCard32	  (pPacket, pArg->m_nCaret) ;
4802 	XIMPacket_AddCard32   (pPacket, pArg->m_nChgFirst) ;
4803 
4804 	/*	2ʸ���ʾ夬 PreeditString �Ȥ���ɽ������Ƥ�����֤���
4805 	 *	ChgFirst, ChgLength �Ǿõ�褦�Ȥ���� KDE3.0 �ǤϾ�
4806 	 *	��˼��Ԥ��롣
4807 	 *	qt ��ʸ���ο������� im server ¦��ʸ���ο������������
4808 	 *	���롩 �ɤ�ʬ����ʤ���
4809 	 *	qt �� hack ������̡�-1 �� ChgLength �����äƤ���С�
4810 	 *	���õ���ˤʤäƤ���褦�ʤΤǡ���������Ѥ���(*)
4811 	 *
4812 	 *(*) ����ư��� qt ������ʻ��ͤʵ������롣����ư��ˤ���
4813 	 *	�ʤ��̤ʥ��饤����Ȥ��о줷�����ˡ��ɤ�������Τ���
4814 	 */
4815 #if !defined (QT_CANT_CLEAR_TEXT) && 0
4816 	/*
4817 	 *	Notepad.jar �ǥХ��ä���(;_;)
4818 	 */
4819 	if (pArg->m_nText <= 0 && pArg->m_nChgFirst <= 0) {
4820 		XIMPacket_AddCard32   (pPacket, -1) ;
4821 	} else {
4822 		XIMPacket_AddCard32   (pPacket, pArg->m_nChgLength) ;
4823 	}
4824 #else
4825 	XIMPacket_AddCard32   (pPacket, pArg->m_nChgLength) ;
4826 #endif
4827 
4828 	uMask	= 0 ;
4829 	if (pArg->m_nText <= 0)
4830 		uMask	|= 1 | 2 ;
4831 
4832 	XIMPacket_AddBitmask32(pPacket, uMask) ;
4833 	nIndex	= XIMPacket_GetDataSize (pPacket) ;
4834 	XIMPacket_AddCard16   (pPacket, 0 /* dummy */) ;
4835 
4836 	InitializeKanjiFiniteStateMachine (&ksm, KCODING_SYSTEM_COMPOUND_TEXT) ;
4837 	pText	= pArg->m_pText ;
4838 	nText	= pArg->m_nText ;
4839 	nctext	= 0 ;
4840 	while (nText > 0) {
4841 		if (*pText == '\n') {
4842 			rchBuf [0]	= '\r' ;
4843 			nptr		= 1 ;
4844 		} else {
4845 			nptr	= RtransferKanjiFiniteStateMachine (&ksm, *pText, rchBuf) ;
4846 		}
4847 		pText	++ ;
4848 		nText	-- ;
4849 		nctext	+= nptr ;
4850 		if (nptr > 0)
4851 			XIMPacket_AddString8 (pPacket, (STRING8)rchBuf, nptr) ;
4852 	}
4853 	XIMPacket_SetCard16   (pPacket, nIndex, nctext) ;
4854 #if defined (DEBUG) || 0
4855 	fprintf (stderr, "Caret(%d), ChgFirst(%d), ChgLength(%d), Text(%d), Attribute(%d), Length(%d)\n",
4856 			 pArg->m_nCaret,
4857 			 pArg->m_nChgFirst,
4858 			 pArg->m_nChgLength,
4859 			 pArg->m_nText,
4860 			 pArg->m_nAttribute,
4861 			 nctext) ;
4862 #endif
4863 	XIMPacket_AddPad      (pPacket, nctext + 2) ;
4864 	/*	FEEDBACK ���� */
4865 	if (uMask & 2) {
4866 		XIMPacket_AddCard16 (pPacket, 0) ;
4867 		XIMPacket_AddCard16 (pPacket, 0) ;
4868 	} else {
4869 		register const CARD32*	pAttribute ;
4870 		register int			nAttribute ;
4871 
4872 		XIMPacket_AddCard16 (pPacket, pArg->m_nAttribute * sizeof (CARD32)) ;
4873 		XIMPacket_AddCard16 (pPacket, 0) ;
4874 		pAttribute	= pArg->m_pAttribute ;
4875 		nAttribute	= pArg->m_nAttribute ;
4876 		while (nAttribute -- > 0)
4877 			XIMPacket_AddCard32 (pPacket, *pAttribute ++) ;
4878 	}
4879 
4880 	XIMPacket_SetInputContext (pPacket, pInputContext) ;
4881 	uSyncMode	= XIMInputContext_GetSyncMode (pInputContext) ;
4882 	if ((uSyncMode & (XIMClientSync | XIMSyncAny)) == 0) {
4883 		nPacketSync	= XIMPS_NO ;
4884 	} else {
4885 		nPacketSync	= XIMPS_SPOOL_PREEDIT ;
4886 	}
4887 	XIMPacket_SetSyncMode (pPacket, nPacketSync) ;
4888 	XIMPacket_SetLength   (pPacket) ;
4889 	ximClient_writeMessage (gw, pPacket) ;
4890 	XIMPacket_Release (pPacket) ;
4891 	return ;
4892 }
4893 
4894 void
XIMClient_WritePreeditCaret(register Widget gw,register int nInputMethodID,register XIMInputContext * pInputContext,register const TOnTheSpotDrawArg * pArg)4895 XIMClient_WritePreeditCaret (
4896 	register Widget				gw,
4897 	register int				nInputMethodID,
4898 	register XIMInputContext*	pInputContext,
4899 	register const TOnTheSpotDrawArg*	pArg)
4900 {
4901 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
4902 	register XIMPacket*			pPacket ;
4903 	register unsigned int		uSyncMode ;
4904 	register int				nInputContextID, nPacketSync ;
4905 
4906 	assert (gw   != NULL) ;
4907 
4908 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
4909 	if (pPacket == NULL)
4910 		return ;
4911 
4912 	nInputContextID	= XIMInputContext_GetID (pInputContext) ;
4913 	XIMPacket_SetHeader   (pPacket, XIM_PREEDIT_CARET, 0) ;
4914 	XIMPacket_AddCard16   (pPacket, nInputMethodID) ;
4915 	XIMPacket_AddCard16   (pPacket, nInputContextID) ;
4916 	XIMPacket_AddCard32	  (pPacket, pArg->m_nCaret) ;
4917 	XIMPacket_AddCard32	  (pPacket, 10) ;
4918 	XIMPacket_AddCard32	  (pPacket, 1) ;
4919 	XIMPacket_SetInputContext (pPacket, pInputContext) ;
4920 	uSyncMode	= XIMInputContext_GetSyncMode (pInputContext) ;
4921 	if ((uSyncMode & (XIMClientSync | XIMSyncAny)) == 0) {
4922 		nPacketSync	= XIMPS_SYNC_PREEDIT_CARET ;
4923 	} else {
4924 		nPacketSync	= XIMPS_SPOOL_PREEDIT_CARET ;
4925 	}
4926 	XIMPacket_SetSyncMode (pPacket, nPacketSync) ;
4927 	XIMPacket_SetLength   (pPacket) ;
4928 	ximClient_writeMessage (gw, pPacket) ;
4929 	XIMPacket_Release (pPacket) ;
4930 	return ;
4931 }
4932 
4933 void
XIMClient_WritePreeditDone(register Widget gw,register int nInputMethodID,register XIMInputContext * pInputContext)4934 XIMClient_WritePreeditDone (
4935 	register Widget				gw,
4936 	register int				nInputMethodID,
4937 	register XIMInputContext*	pInputContext)
4938 {
4939 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
4940 	register XIMPacket*			pPacket ;
4941 	register unsigned int		uSyncMode ;
4942 	register int				nInputContextID, nPacketSync ;
4943 
4944 	assert (gw   != NULL) ;
4945 
4946 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
4947 	if (pPacket == NULL)
4948 		return ;
4949 
4950 	nInputContextID	= XIMInputContext_GetID (pInputContext) ;
4951 	XIMPacket_SetHeader   (pPacket, XIM_PREEDIT_DONE, 0) ;
4952 	XIMPacket_AddCard16   (pPacket, nInputMethodID) ;
4953 	XIMPacket_AddCard16   (pPacket, nInputContextID) ;
4954 
4955 	XIMPacket_SetInputContext (pPacket, pInputContext) ;
4956 	/*	���� SYNC �ϲ���ޤǤΥ�å�������֥�å�����Τ�
4957 	 *	������ ¿ʬ�������Ĥ� reply �ޤǤ� PREEDIT �Ϥ�
4958 	 *	��å���������ߤ���Τ������ɡ�*/
4959 	uSyncMode	= XIMInputContext_GetSyncMode (pInputContext) ;
4960 	if ((uSyncMode & (XIMClientSync | XIMSyncAny)) == 0) {
4961 		nPacketSync	= XIMPS_NO ;
4962 	} else {
4963 		nPacketSync	= XIMPS_SPOOL_PREEDIT ;
4964 	}
4965 	XIMPacket_SetSyncMode (pPacket, nPacketSync) ;
4966 	XIMPacket_SetLength   (pPacket) ;
4967 	ximClient_writeMessage (gw, pPacket) ;
4968 	XIMPacket_Release (pPacket) ;
4969 	return ;
4970 }
4971 
4972 void
XIMClient_WriteStatusStart(register Widget gw,register int nInputMethodID,register XIMInputContext * pInputContext)4973 XIMClient_WriteStatusStart (
4974 	register Widget				gw,
4975 	register int				nInputMethodID,
4976 	register XIMInputContext*	pInputContext)
4977 {
4978 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
4979 	register XIMPacket*			pPacket ;
4980 	register unsigned int		uSyncMode ;
4981 	register int				nInputContextID, nPacketSync ;
4982 
4983 	assert (gw   != NULL) ;
4984 
4985 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
4986 	if (pPacket == NULL)
4987 		return ;
4988 
4989 	nInputContextID	= XIMInputContext_GetID (pInputContext) ;
4990 	XIMPacket_SetHeader   (pPacket, XIM_STATUS_START, 0) ;
4991 	XIMPacket_AddCard16   (pPacket, nInputMethodID) ;
4992 	XIMPacket_AddCard16   (pPacket, nInputContextID) ;
4993 #if defined (DEBUG) || 0
4994 	fprintf (stderr, "XIMClient_WriteStatusStart (%p, %d, %d)\n",
4995 			 gw, nInputMethodID, nInputContextID) ;
4996 #endif
4997 
4998 	XIMPacket_SetInputContext (pPacket, pInputContext) ;
4999 	/*	���� SYNC �ϲ���ޤǤΥ�å�������֥�å�����Τ�
5000 	 *	������ ¿ʬ�������Ĥ� reply �ޤǤ� PREEDIT �Ϥ�
5001 	 *	��å���������ߤ���Τ������ɡ�*/
5002 	uSyncMode	= XIMInputContext_GetSyncMode (pInputContext) ;
5003 	if ((uSyncMode & (XIMClientSync | XIMSyncAny)) == 0) {
5004 		nPacketSync	= XIMPS_NO ;
5005 	} else {
5006 		nPacketSync	= XIMPS_SPOOL_PREEDIT ;
5007 	}
5008 	XIMPacket_SetSyncMode (pPacket, nPacketSync) ;
5009 	XIMPacket_SetLength   (pPacket) ;
5010 	ximClient_writeMessage (gw, pPacket) ;
5011 	XIMPacket_Release (pPacket) ;
5012 	return ;
5013 }
5014 
5015 void
XIMClient_WriteStatusDraw(register Widget gw,register int nInputMethodID,register XIMInputContext * pInputContext,register const TOnTheSpotDrawArg * pArg)5016 XIMClient_WriteStatusDraw (
5017 	register Widget				gw,
5018 	register int				nInputMethodID,
5019 	register XIMInputContext*	pInputContext,
5020 	register const TOnTheSpotDrawArg*	pArg)
5021 {
5022 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
5023 	register XIMPacket*			pPacket ;
5024 	KANJISTATEMACHINE			ksm ;
5025 	char						rchBuf [16] ;
5026 	register const Char*		pText ;
5027 	register int				nctext, nText, nIndex, nptr ;
5028 	register unsigned int		uSyncMode ;
5029 	register int				nPacketSync, nInputContextID ;
5030 
5031 	assert (gw   != NULL) ;
5032 	assert (pArg != NULL) ;
5033 
5034 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
5035 	if (pPacket == NULL)
5036 		return ;
5037 
5038 	nInputContextID	= XIMInputContext_GetID (pInputContext) ;
5039 #if defined (DEBUG) || 0
5040 	fprintf (stderr, "XIMClient_WriteStatusDraw (%p, %d, %d, len(%d))\n",
5041 			 gw, nInputMethodID, nInputContextID, pArg->m_nText) ;
5042 #endif
5043 	XIMPacket_SetHeader   (pPacket, XIM_STATUS_DRAW, 0) ;
5044 	XIMPacket_AddCard16   (pPacket, nInputMethodID) ;
5045 	XIMPacket_AddCard16   (pPacket, nInputContextID) ;
5046 	XIMPacket_AddCard32   (pPacket, 0) ;
5047 	if (pArg->m_nText <= 0) {
5048 		XIMPacket_AddCard32   (pPacket, 1 | 2) ;
5049 	} else {
5050 		XIMPacket_AddCard32   (pPacket, 2) ;
5051 	}
5052 	nIndex	= XIMPacket_GetDataSize (pPacket) ;
5053 	XIMPacket_AddCard16   (pPacket, 0 /* dummy */) ;
5054 
5055 	InitializeKanjiFiniteStateMachine (&ksm, KCODING_SYSTEM_COMPOUND_TEXT) ;
5056 	pText	= pArg->m_pText ;
5057 	nText	= pArg->m_nText ;
5058 	nctext	= 0 ;
5059 	while (nText > 0) {
5060 		if (*pText == '\n') {
5061 			rchBuf [0]	= '\r' ;
5062 			nptr		= 1 ;
5063 		} else {
5064 			nptr	= RtransferKanjiFiniteStateMachine (&ksm, *pText, rchBuf) ;
5065 		}
5066 		pText	++ ;
5067 		nText	-- ;
5068 		nctext	+= nptr ;
5069 		if (nptr > 0)
5070 			XIMPacket_AddString8 (pPacket, (STRING8)rchBuf, nptr) ;
5071 	}
5072 	XIMPacket_SetCard16   (pPacket, nIndex, nctext) ;
5073 	XIMPacket_AddPad      (pPacket, nctext + 2) ;
5074 
5075 	XIMPacket_SetInputContext (pPacket, pInputContext) ;
5076 	uSyncMode	= XIMInputContext_GetSyncMode (pInputContext) ;
5077 	if ((uSyncMode & (XIMClientSync | XIMSyncAny)) == 0) {
5078 		nPacketSync	= XIMPS_NO ;
5079 	} else {
5080 		nPacketSync	= XIMPS_SPOOL_PREEDIT ;
5081 	}
5082 	XIMPacket_SetSyncMode (pPacket, nPacketSync) ;
5083 	XIMPacket_SetLength   (pPacket) ;
5084 	ximClient_writeMessage (gw, pPacket) ;
5085 	XIMPacket_Release (pPacket) ;
5086 	return ;
5087 }
5088 
5089 void
XIMClient_WriteStatusDone(register Widget gw,register int nInputMethodID,register XIMInputContext * pInputContext)5090 XIMClient_WriteStatusDone (
5091 	register Widget				gw,
5092 	register int				nInputMethodID,
5093 	register XIMInputContext*	pInputContext)
5094 {
5095 	register XIMClientWidget	wgThis	= (XIMClientWidget) gw ;
5096 	register XIMPacket*			pPacket ;
5097 	register unsigned int		uSyncMode ;
5098 	register int				nPacketSync, nInputContextID ;
5099 
5100 	assert (gw   != NULL) ;
5101 
5102 	pPacket	= XIMPacket_Create (wgThis->ximClient.m_fBigEndian) ;
5103 	if (pPacket == NULL)
5104 		return ;
5105 
5106 	nInputContextID	= XIMInputContext_GetID (pInputContext) ;
5107 	XIMPacket_SetHeader   (pPacket, XIM_STATUS_DONE, 0) ;
5108 	XIMPacket_AddCard16   (pPacket, nInputMethodID) ;
5109 	XIMPacket_AddCard16   (pPacket, nInputContextID) ;
5110 #if defined (DEBUG) || 0
5111 	fprintf (stderr, "XIMClient_WriteStatusDone (%p, %d, %d)\n",
5112 			 gw, nInputMethodID, nInputContextID) ;
5113 #endif
5114 
5115 	XIMPacket_SetInputContext (pPacket, pInputContext) ;
5116 	/*	���� SYNC �ϲ���ޤǤΥ�å�������֥�å�����Τ�
5117 	 *	������ ¿ʬ�������Ĥ� reply �ޤǤ� PREEDIT �Ϥ�
5118 	 *	��å���������ߤ���Τ������ɡ�*/
5119 	uSyncMode	= XIMInputContext_GetSyncMode (pInputContext) ;
5120 	if ((uSyncMode & (XIMClientSync | XIMSyncAny)) == 0) {
5121 		nPacketSync	= XIMPS_NO ;
5122 	} else {
5123 		nPacketSync	= XIMPS_SPOOL_PREEDIT ;
5124 	}
5125 	XIMPacket_SetSyncMode (pPacket, nPacketSync) ;
5126 	XIMPacket_SetLength   (pPacket) ;
5127 	ximClient_writeMessage (gw, pPacket) ;
5128 	XIMPacket_Release (pPacket) ;
5129 	return ;
5130 }
5131 
5132 #if defined (DEBUG) || 0
5133 void
dumpBuf(register const BYTE * pData,register int nData)5134 dumpBuf (
5135 	register const BYTE*	pData,
5136 	register int			nData)
5137 {
5138 	register int	i ;
5139 
5140 	for (i = 0 ; i < nData ; i ++) {
5141 		if ((i % 16) == 0)
5142 			fprintf (stderr, "\t") ;
5143 		fprintf (stderr, "%02x ", *pData) ;
5144 		pData	++ ;
5145 		if ((i % 16) == 15)
5146 			fprintf (stderr, "\n") ;
5147 	}
5148 	if ((nData % 16) != 0)
5149 		fprintf (stderr, "\n") ;
5150 	return ;
5151 }
5152 #endif
5153