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