/*
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 *                                  chinput.h
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 */
#define MAX_COLS	200
#define MAX_ROWS	128

typedef struct _status_button {
        int x, y;
        Boolean status;
        char *str1, *str2;
} status_button;

typedef struct {
/* These parameters apply to both windows */
	Window		window1;	/* window ID			*/
	Window		window2;	/* window ID			*/
	Window		window3;	/* window ID			*/
#if 0
	Window		window4;	/* window ID			*/
	Window		window5;	/* window ID			*/
	Window		window6;	/* window ID			*/
#endif
	Display		*display;	/* X display for screen		*/

	Window		lockw;		/* window being locked by chinput */
	Bool		focus;		/* if the window being focused  */
	Bool		plugin;

	GC		normalGC;	    /* normal painting		*/
	GC		normalgbGC;    	/* normal painting		*/
	GC		normalbig5GC;	/* normal painting		*/
	GC		dimGC;	    	/* gc for dim border 		*/
	GC		lightGC;    	/* gc for light border		*/
	GC		panelGC;    	/* gc for panel			*/
	GC		barGC;	    	/* gc for title bar of VK	*/
	GC		ledGC;	    	/* gc for switch led		*/

	int		width;	    	/* width of columns		*/
	int		height;	    	/* height of rows		*/
	int		lspacing;    	/* space in pixel between lines	*/

	int		encoding;	    /* encoding the same as misc	*/

	/* Hanzi input area stuff					*/
	struct {
		int	rows;	    	/* number of rows in input area	*/
		int	cols;
		int	x, y;	    	/* upperleft of the input area	*/
		int	width, height;	/* width, height of input area  */
	} hzIwin;

	//button window area
	struct {
		Bool flag;          /* flag marking the led on/off state */
		int	rows;
		int	cols;
		int	x, y;
		int width, height;
		int q_x1, q_y1, q_x2, q_y2;
		int p_x1, p_y1, p_x2, p_y2;
		int ledx1, ledy1, ledx2, ledy2;
		int offset;
		/* Led position */
		int btnx1, btny1, btnx2, btny2, btnx3, btny3;
	} hzBwin;

	//keyboard window area
	struct {
		Bool onflag;
		int	offx1, offy1;
		int	offx2, offy2;
		int	rows;
		int	cols;
		int	x, y;
		int	width, height;
		int	prevx1, prevy1, prevx2, prevy2, prevx3, prevy3;
		int	nextx1, nexty1, nextx2, nexty2, nextx3, nexty3;
		/* triangle buttons' position */
		int cur;                            /* current section     */
		int first_start, first_end;         /* range of first byte */
		int second_start, second_end;       /* rang of second byte */
		int second_start2, second_end2;     /* for big5 encode     */
	} hzKwin;

	//virtual keyboard
	struct {
		Bool	onflag;
		int	x, y;		/* up-left corner position */
		int	w, h;		/* size of window          */
	} hzVKwin;

	//handwriting recognition pad
	struct {
		int	x, y;		/* up-left corner position */
		int	w, h;		/* size of window          */
	} hzHWwin;

	//key window and choice window
	struct {
		int	x1, y1, w1, h1;
		int	x2, y2, w2, h2;
		//two triangle buttons
		int	b1_x1, b1_y1, b1_x2, b1_y2, b1_x3, b1_y3;
		int	b2_x1, b2_y1, b2_x2, b2_y2, b2_x3, b2_y3;
		//selection area by button
		int	s_x1, s_y1, s_x2, s_y2;
	} hzCwin;

	int	f_width;	    /* font width of text  */
	int	f_height;	    /* font height of text */

} HZinputmod;

typedef struct _chinput_ime {
	char name[20];      /* section name */
	char namegb[20];    /* input method name in GB */
	char namebig5[20];	/* input method name in Big5 */
	char namebig5hkscs[20];	/* input method name in Big5 */
	char encoding[20];  /* encoding: GB or BIG5 */
	char fname[80];     /* file name relative to dict path */
	char module[128];   /* module name */
	int	 favorite;
} chinput_ime;

typedef struct _chinput_rc {
	char gblocale[20];		//Locale Name
	char big5locale[20];
	int	dmode;		        //ROOT,OVERSPOT,ONSPOT,OFFSPOT
	int	hmode;			    //autohide inputbar in overspot style
	int	cmode;			    //choice window mode in onspot style
	int	areamode;		    //areamode in offspot style
	int	showime;			//show im name in inputbar in overspot style
	char dictionary[256];	//path of dictionary
	char ime_gb[20];		//default GB ime
	char ime_big5[20];		//default big5 ime
	//char	association[30];
	char font[128];		    // latin font name
	char gbfont[128];
	char big5font[128];

	int	width;			//inputbar width in chars

	char dimcolor[8];
	char lightcolor[8];
	char panelcolor[8];
	char hzcolor[8];
	char ledcolor[8];
	char barcolor[8];

	int	hwtimeout;		//timeout for handwriting
} chinput_rc;

/*
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 *                                  config.h
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 */
// This macro is defined by configure script
#define RESOURCEFILE    "/usr/lib/Chinput/Chinput.ad"
#define IMDIR           "/usr/lib/Chinput/im"

/*
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 *                                  defs.h
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 */
#define ZWIN_FLAG_DISPLAY       2
#define ZWIN_FLAG_FONT          3
#define ZWIN_FLAG_INPUT         4
#define ZWIN_FLAG_CURSOR        5
#define ZWIN_FLAG_DMODE         6
#define ZWIN_FLAG_IMODE         7
#define ZWIN_FLAG_DICT          8
#define ZWIN_FLAG_GRAB          9
#define ZWIN_FLAG_PASTE         10
#define ZWIN_FLAG_REFRESH       11
#define ZWIN_FLAG_CORNER		12
#define ZWIN_FLAG_PUNCT			13
#define ZWIN_FLAG_ENC			14
#define ZWIN_FLAG_HIDE          15
#define ZWIN_FLAG_MANAGE        16
#define ZWIN_FLAG_END           17


#define EC_CHINESE              0
#define EC_WESTERN              1

#define CORNER_HALF             0
#define CORNER_FULL             1

#define PUNCT_CHINESE           0
#define PUNCT_WESTERN           1

#define ENC_GB                  0
#define ENC_BIG5                1

#define LOCK_NONE				0
#define LOCK_GB					1
#define LOCK_BIG5				2

#define BAR_HIDE				0
#define BAR_POP					1

#define MAX_IMES				60

#define FONT_ASCENT     		14
#define FONT_DESCENT     		2
#define FONT_WIDTH				16
#define FONT_HEIGHT				16
#define AREA_CHARS				19

/*
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 *                                  globals.h
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 */
//X Server
WHERE Display 		*display;
WHERE int 			screen_num;
WHERE Screen 		*screen_ptr;

//Input Server
WHERE Window  		window1;			//input window
WHERE Window  		window2;			//choice window
WHERE Window  		window3;			//virtual keyboard window
#if 0
WHERE Window  		window4;			//handwriting window(parent)
WHERE Window  		window5;			//handwriting window(left)
WHERE Window  		window6;			//handwriting window(right)
#endif
WHERE Window 		parent;				//parent window
WHERE Window		movingwin;			//moving window
WHERE int 			map_mode;			//mapped? altered by Control-Space
WHERE int 			dmode,saved_dmode;	//input mode
WHERE int 			hmode;				//auto-hide mode for overthespot
WHERE int			cmode;				//choice window mode for onthespot
WHERE char			input_method_gb[20];//input method name in rcfile
WHERE char			input_method_big5[20];
WHERE char			input_method_big5hkscs[20];
WHERE char			dict_path[256];		//dictionary path
WHERE int			cur_inputmethod;	//current input method by ID
WHERE int			boxdrawn;			//used for moving window
WHERE int			left, right, top, bottom, press_x, press_y, move_x, move_y;
WHERE int			butx, buty;
WHERE int			index_ime;
WHERE chinput_ime	chinputime[MAX_IMES];//input method from config file
WHERE HZinputmod	HZServer;			//all in one :)
WHERE int			selection_count;
WHERE char			selection_list[10][20];	//selections
WHERE int			csock;				// Half duplex sockets (Local)
WHERE int			dsock;				// Connecting docking application
WHERE int			docking_live;		// 1 for docking is live, 0 for off

//
WHERE Boolean		flag_corner;		//half/full cornered chars
WHERE Boolean		flag_punct;			//punctuation
WHERE int			flag_lock;			//encoding output locking
WHERE Boolean		flag_ec;			//output mode
WHERE Boolean		flag_refresh;		//switch input method
WHERE Boolean		flag_automode;		//automatic display mode?
WHERE Boolean		flag_up, flag_down;	//choice list page up/dow flag
WHERE Boolean		flag_english;		//english input leading by 'v'
WHERE int    		flag_single;		//single input by '[' or ']'
WHERE char			input_buf[80];		//input buf leading by 'v'
WHERE int			flag_encoding;		//encoding for client
WHERE int			flag_found;			//require selection?
WHERE int			flag_showime;		//show the ime in input window
WHERE int			flag_client;		//preedit/status area decided by client?
WHERE int			width_input_win;	//global var for input win width(caret)
WHERE int			width_inputbar;		//inputbar width in chars
WHERE int			prev_dmode;			//saved dmode
WHERE int			flag_tip;

//Font
WHERE GC			boxgc;
WHERE Cursor		arrow_cursor;
WHERE GC			offspot_gc, offspot_bggc;
WHERE GC			offspot_gbgc, offspot_big5gc, offspot_big5hkscsgc;
WHERE unsigned long	foreground_pixel, background_pixel, border_pixel;
WHERE char			font_latin[128], font_gb[128],
					font_big5[128], font_big5hkscs[128];
WHERE char			color_dim[10], color_light[10], color_panel[10];
WHERE char			color_hz[10], color_led[10], color_bar[10];
WHERE XFontStruct	*font_info, *hzgbfont_info;
WHERE XFontStruct	*hzbig5font_info, *hzbig5hkscsfont_info;
WHERE XFontSet		fontset_gb, fontset_big5, fontset_big5hkscs;

//XIM
WHERE char			gblocale[20];
WHERE char			big5locale[20];
WHERE char			big5hkscslocale[20];
WHERE char			deflocale[20];
WHERE char			imlocale[256];
WHERE int			last_icid;
WHERE int			last_connectid;
WHERE IC			*current_focus_ic;
WHERE XIMS			this_xims;
WHERE char			xim_connect[MAX_CONNECT];


//IME Server
WHERE ImmServer_T	chinput_imserver;
WHERE IMM			*chinput_imm;

//virtual keyboard
WHERE int			keytype;
WHERE vk_keys		vkkeys[N_KEYS];		//keys on keyboard

//handwriting recognition
WHERE Boolean		flag_checked;		//need a handwriting checking
WHERE int		    hw_activekeys;		//how many keys 
WHERE int     		flag_side;
WHERE int     		hw_timeout;			//timeout of hw recognition(milisecond)
//WHERE hw_keys hwkeys[N_HWKEYS];
WHERE Boolean 		flag_sent;
WHERE Boolean 		hwmode;

//images
#ifdef IMLIB
WHERE ImlibData 	*icon_id;
WHERE ImlibImage 	*im_chinput;
WHERE ImlibImage 	*im_123;
#endif

/*
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 *                                  hzclient.h
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 */
#define HZINPUT_CLIENT_VERSION				"3.0.1"
#define HZINPUT_SERVER_VERSION  			"3.0.1"
#define HZINPUT_SERVER_PROTOCOL				"CHINESE_CONVERSION"

#define	HZSERVER_ENCODING_DEFAULT			1	
#define HZSERVER_ENCODING_GB				0
#define HZSERVER_ENCODING_BIG5				1
#define HZSERVER_ENCODING_JIS				2
#define HZSERVER_ENCODING_KS				3
#define HZSERVER_ENCODING_LATIN1			4
#define HZSERVER_ENCODING_LATIN2			5
#define HZSERVER_ENCODING_LATIN3			6
#define HZSERVER_ENCODING_LATIN4			7
#define HZSERVER_ENCODING_CYRILLIC			8
#define HZSERVER_ENCODING_ARABIC			9
#define HZSERVER_ENCODING_GREEK				10
#define HZSERVER_ENCODING_HEBREW			11
#define HZSERVER_ENCODING_LATIN5			12
#define HZSERVER_ENCODING_LATIN6			13
#define HZSERVER_ENCODING_BIG5HKSCS			14
#define HZSERVER_ENCODING_UNKNOWN			(-1)

#define HZCLIENT_QUERY_PROTOCOL				0
#define HZCLIENT_QUERY_VERSION				1
#define HZCLIENT_QUERY_ENCODING				2
#define HZCLIENT_QUERY_INPUTMETHOD			3
#define HZCLIENT_QUERY_STATUS				4
#define HZCLIENT_QUERY_UNKNOWN				(-1)

#define HZCLIENT_CONFIG_DEFAULTCOLOR		0
#define HZCLIENT_CONFIG_DIMCOLOR			1
#define HZCLIENT_CONFIG_LIGHTCOLOR			2
#define HZCLIENT_CONFIG_PANELCOLOR			3
#define HZCLIENT_CONFIG_TEXTCOLOR			4
#define HZCLIENT_CONFIG_HZFONT				5
#define HZCLIENT_CONFIG_FONT				6
#define HZCLIENT_CONFIG_INMETHOD			7
#define HZCLIENT_CONFIG_ENCODING			8
#define HZCLIENT_CONFIG_DICTIONARY			9
#define HZCLIENT_CONFIG_ASSOCIATION			10
#define HZCLIENT_CONFIG_LOCKWINDOW			11
#define HZCLIENT_CONFIG_RELEASEWINDOW		12
#define HZCLIENT_CONFIG_PLUGIN				13
#define HZCLIENT_CONFIG_FREEWIN				14
#define HZCLIENT_CONFIG_HIDE				15
#define HZCLIENT_CONFIG_SHOW				16
#define HZCLIENT_CONFIG_ROOTDRAW			17
#define HZCLIENT_CONFIG_WINDRAW				18
#define HZCLIENT_CONFIG_POSITION			19
#define HZCLIENT_CONFIG_QJ					20
#define HZCLIENT_CONFIG_PUNCT				21
#define HZCLIENT_CONFIG_LOCK				22
#define HZCLIENT_CONFIG_SWITCH				23
#define HZCLIENT_CONFIG_KEYBOARD			24
#define HZCLIENT_CONFIG_HANDWRITING			25
#define HZCLIENT_CONFIG_VOICE				26
#define HZCLIENT_CONFIG_CLOSE				27

#define HZSERVER_STATUS_DISABLED	        0
#define HZSERVER_STATUS_ENABLED    			1

#define HZSERVER_KEYBOARD_NULL				0
#define HZSERVER_KEYBOARD_SYMBOL_NUMERIC	1
#define HZSERVER_KEYBOARD_QJ_PY				2
#define HZSERVER_KEYBOARD_JAPANESE			3
#define HZSERVER_KEYBOARD_GREEK_RUSSIAN		4
#define HZSERVER_KEYBOARD_TABLE				5

#define HZSERVER_OUTPUT_NORMAL_KEY			0
#define HZSERVER_OUTPUT_FUNCTION_KEY		1
#define HZSERVER_OUTPUT_HANZI				2
#define HZSERVER_OUTPUT_BAD					-1

#define HZSERVER_INPUT_METHOD_DISABLE		-1
#define HZSERVER_INPUT_METHOD_ENABLE		-2

// These macro haven't been used!
// We might think about the use of these macro!
#define HZSERVER_INPUT_METHOD_GB_ASCII		001
#define HZSERVER_INPUT_METHOD_GB_IC			002
#define HZSERVER_INPUT_METHOD_GB_QW			003
#define HZSERVER_INPUT_METHOD_GB_TONEPY		004
#define HZSERVER_INPUT_METHOD_GB_QJ			005
#define HZSERVER_INPUT_METHOD_GB_PUNCT		006
#define HZSERVER_INPUT_METHOD_GB_PY			007
#define HZSERVER_INPUT_METHOD_GB_CCDOSPY	008
#define HZSERVER_INPUT_METHOD_GB_WUBI		009
#define HZSERVER_INPUT_METHOD_GB_CANGJIE	010
#define HZSERVER_INPUT_METHOD_GB_ENGLISH	011
#define HZSERVER_INPUT_METHOD_GB_CTLAU		012
#define HZSERVER_INPUT_METHOD_GB_SW			013
#define HZSERVER_INPUT_METHOD_GB_QIANMA		014
#define HZSERVER_INPUT_METHOD_GB_TELECODE   015
#define HZSERVER_INPUT_METHOD_GB_HIRAGANA   016
#define HZSERVER_INPUT_METHOD_GB_KATAKANA   017
#define HZSERVER_INPUT_METHOD_GB_ZNPY		018
#define HZSERVER_INPUT_METHOD_GB_MGM		019
#define HZSERVER_INPUT_METHOD_GB_TABLE		020

#define HZSERVER_INPUT_METHOD_BIG5_ASCII    101
#define HZSERVER_INPUT_METHOD_BIG5_IC       102
#define HZSERVER_INPUT_METHOD_BIG5_PY       103
#define HZSERVER_INPUT_METHOD_BIG5_QJ       104
#define HZSERVER_INPUT_METHOD_BIG5_PUNCT    105
#define HZSERVER_INPUT_METHOD_BIG5_ETZY     106
#define HZSERVER_INPUT_METHOD_BIG5_ZOZY     107
#define HZSERVER_INPUT_METHOD_BIG5_SIMPLEX  108
#define HZSERVER_INPUT_METHOD_BIG5_CANGJIE  109
#define HZSERVER_INPUT_METHOD_BIG5_ENGLISH  110
#define HZSERVER_INPUT_METHOD_BIG5_4CORNER  111
#define HZSERVER_INPUT_METHOD_BIG5_HSU      112
#define HZSERVER_INPUT_METHOD_BIG5_ARRAY30  113
#define HZSERVER_INPUT_METHOD_BIG5_BOSHIAMY 114
#define HZSERVER_INPUT_METHOD_BIG5_ZNPY     115

#define HZSERVER_INPUT_METHOD_BIG5HKSCS_CANGJIE	201 
#define HZSERVER_INPUT_METHOD_BIG5HKSCS_SIMPLEX	202

#define HZ_PROTOCOL_ATOM 	"_CHINESE_CONVERSION"
#define HZ_HPROTOCOL_ATOM	"_CHINESE_HANDWRITING"
#define HZ_VPROTOCOL_ATOM	"_CHINESE_VOICERECOGNITION"
#define HZ_TOOLBAR_ATOM		"_CHINESE_CONTROLBAR"

#define HZ_OUTPUT_ATOM      "_HZ_OUTPUT_ATOM"
#define HZ_HANDWRITING_ATOM "_HZ_HANDWRITING_ATOM"
#define HZ_VOICE_ATOM       "_HZ_VOICE_ATOM"

#define HZ_INPUT_ATOM           "_HZ_INPUT_ATOM"
#define HZ_CONFIG_ATOM		"_HZ_CONFIG_ATOM"
#define HZ_QUERY_ATOM		"_HZ_QUERY_ATOM"
#define HZ_REPLY_ATOM		"_HZ_REPLY_ATOM"
#define HZ_GRASP_ATOM		"_HZ_GRASP_ATOM"
#define HZ_GRASP2_ATOM		"_HZ_GRASP2_ATOM"

Atom hz_protocol_atom;		/* protocol atom marking the server	*/
Atom hz_hprotocol_atom;		/* protocol of handwriting */
Atom hz_vprotocol_atom;		/* from voice recognitio */
Atom hz_toolbar_atom;		/* protocol atom for toolbar */

Atom hz_output_atom;		/* atom for output from the server */
Atom hz_handwriting_atom;
Atom hz_voice_atom;

Atom hz_input_atom;			/* atom for key press */
Atom hz_query_atom;			/* query server */
Atom hz_reply_atom;			/* reply client query */
Atom hz_config_atom;		/* config server attributes and state */
Atom hz_grasp_atom;			/* grasp word from screen */
Atom hz_grasp2_atom;		/* grasp word, with small edict */

/*
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 *                                  hzserver.h
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 */
#define 	MAX_STROKES             	32
#define 	BUFLEN                  	1024
#define		HZSERVER_BUFFER_SIZE		20
#define		HZSERVER_SYS_ERR_FP			stderr
#define		HZSERVER_SYS_MSG_FP			stderr
#define		HZSERVER_DEBUG_MSG_FP		stderr
#define		DEBUG				1
#define		HZSERVER_DEFAULT_LOCALE		"zh_TW"
#define		HZSERVER_DEFAULT_BIG5_IME	"CangJie"
#define		HZSERVER_DEFAULT_BIG5HKSCS_IME	"CangJie"
#define		HZSERVER_DEFAULT_GB_IME		"ZNPY"

#define		HZSERVER_BIG5_LOCALE		"zh_TW.Big5"
#define		HZSERVER_GB_LOCALE			"zh_CN.GB2312"
#define		HZSERVER_BIG5HKSCS_LOCALE	"zh_HK.big5hkscs"

#define     HZSERVER_FONT           	"-*-medium-r-normal-*-p-*-iso8859-1"
#define     HZSERVER_GB_FONT        	"-*-medium-r-normal-*-*-*-gb2312.1980-0"
#define     HZSERVER_BIG5_FONT      	"-*-medium-r-normal-*-*-*-big5-0"
#define     HZSERVER_BIG5HKSCS_FONT    	"-*-medium-r-normal-*-*-*-big5hkscs-0"

#define     HZSERVER_MODE_ONE			1
#define		HZSERVER_MODE_TWO			2

#define		HZSERVER_DMODE_AUTO			0
#define		HZSERVER_DMODE_ROOT			1
#define		HZSERVER_DMODE_OVERSPOT		2
#define		HZSERVER_DMODE_ONSPOT		3
#define		HZSERVER_DMODE_OFFSPOT		4
#define		HZSERVER_DMODE_HW			5	//handwriting recognition
#define		HZSERVER_DMODE_VR			6	//voice recognition
#define		HZSERVER_HMODE_AUTO			1
#define		HZSERVER_HMODE_NO			2
#define		HZSERVER_CMODE_AUTO			1
#define		HZSERVER_CMODE_NO			2
#define		HZSERVER_AREAMODE_CLIENT	1
#define		HZSERVER_AREAMODE_SERVER	2
#define 	HZSERVER_DIM_COLOR			"#666666"
#define 	HZSERVER_LIGHT_COLOR		"#f5f5f5"
#define 	HZSERVER_PANEL_COLOR		"#c0c0c0"
#define 	HZSERVER_LED_COLOR			"#00ff00"
#define 	HZSERVER_RED_COLOR			"#ff0000"
#define		HZSERVER_HZ_COLOR			"#000000"
#define		HZSERVER_TEXT_COLOR			"#000000"
#define		HZSERVER_BAR_COLOR			"#000080"
#define		HZSERVER_ROWS				2
#define		HZSERVER_COLS				70
#define		HZSERVER_ENTRY_CHARS		10
#define		HZSERVER_MAXCOLS			80
#define		HZSERVER_MINCOLS			30
#define		HZSERVER_STARTX				100
#define     HZSERVER_STARTY				100

#define     HZSERVER_16_WIDTH2      	(HZSERVER_COLS * 8 + 20)
#define     HZSERVER_16_HEIGHT2     	50
#define     HZSERVER_16_WIDTH1     		\
					((HZSERVER_COLS + HZSERVER_ENTRY_CHARS)*8 + 20) 
#define     HZSERVER_16_HEIGHT1     	20
#define     HZSERVER_BWIN16_WIDTH   	60
#define     HZSERVER_BWIN16_HEIGHT  	48
#define		HZSERVER_KWIN16_WIDTH		\
					(HZSERVER_16_WIDTH + HZSERVER_BWIN16_WIDTH)
#define		HZSERVER_KWIN16_HEIGHT		260
#define		HZSERVER_KWIN16_XOFFSET1	5
#define		HZSERVER_KWIN16_YOFFSET1	5
#define     HZSERVER_KWIN16_XOFFSET2  	220
#define     HZSERVER_KWIN16_YOFFSET2  	5
#define		HZSERVER_VK_WIDTH			460
#define		HZSERVER_VK_HEIGHT			226
#define		HZSERVER_HW_TIMEOUT			1500 //mili-second
#define		HZSERVER_HW_LEFT			1
#define		HZSERVER_HW_RIGHT			2
#define		HZSERVER_HW_WIDTH			450
#define		HZSERVER_HW_HEIGHT			260
#define  	HZSERVER_HW_XOFF			5
#define  	HZSERVER_HW_YOFF			70
#define		HZSERVER_HW_CHILD_WIDTH		\
					(HZSERVER_HW_WIDTH - 42)/2
#define		HZSERVER_HW_CHILD_HEIGHT	\
					(HZSERVER_HW_HEIGHT - HZSERVER_HW_YOFF - 10)

#define		HZSERVER_INPUT_CHARS		12
#define		HZSERVER_CHOICE_CHARS		10
#define		HZSERVER_INPUT_WIN16_WIDTH	(HZSERVER_INPUT_CHARS*8+8)
#define		HZSERVER_INPUT_WIN16_HEIGHT	(16 + 12)
#define		HZSERVER_WIN16_XOFFSET		(HZSERVER_INPUT_WIN16_WIDTH + 4)
#define		HZSERVER_CHOICE_WIN16_WIDTH	(HZSERVER_CHOICE_CHARS*16+8)
#define		HZSERVER_CHOICE_WIN16_HEIGHT	\
					((HZSERVER_CHOICE_CHARS+2) * 18 + 12)
#define		HZSERVER_POS_XOFFSET		0
#define 	HZSERVER_POS_YOFFSET		16

/*
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 *                                  IC.h
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 */
#define MAX_CONNECT 20000

typedef struct {
    XRectangle	area;			/* area */
    XRectangle	area_needed;	/* area needed */
    XPoint		spot_location;	/* spot location */
    Colormap	cmap;			/* colormap */
    CARD32		foreground;		/* foreground */
    CARD32		background;		/* background */
    Pixmap		bg_pixmap;		/* background pixmap */
    char		*base_font;		/* base font of fontset */
    XFontSet    fs;				/* fontset */
    GC			gc;				/* graphics context */
    CARD32		line_space;		/* line spacing */
    Cursor		cursor;			/* cursor */
} PreeditAttributes;

typedef struct {
    XRectangle	area;			/* area */
    XRectangle	area_needed;	/* area needed */
    Colormap	cmap;			/* colormap */
    CARD32		foreground;		/* foreground */
    CARD32		background;		/* background */
    Pixmap		bg_pixmap;		/* background pixmap */
    char		*base_font;		/* base font of fontset */
    XFontSet	fs;				/* fontset */
    GC			gc;				/* graphics context */
    CARD32		line_space;		/* line spacing */
    Cursor		cursor;			/* cursor */
} StatusAttributes;

typedef struct _IC {
    CARD16		id;				/* ic id */
    CARD16		connect_id;		/* connect id */
    INT32		input_style;	/* input style */
    Window		client_win;		/* client window */
    Window		focus_win;		/* focus window */
    Window		status_win;		/* status window(offthespot) */
    Window		preedit_win;	/* preedit window(offthespot) */
    int			reparented;		/* reparented to the client window */
    char		encoding;		/* connection encoding */
    char		*resource_name;	/* resource name */
    char		*resource_class;/* resource class */
    int			len;			/* preedit area string length(onthespot) */
    PreeditAttributes	 pre_attr;	/* preedit attributes */
    StatusAttributes	 sts_attr;	/* status attributes */
    struct _IC	*next;
} IC;

/*
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 *                                  keyboard.h
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 */
#define N_KEYS				71

#define KEY_WIDTH			30
#define KEY_HEIGHT			30
#define KEY_XOFF			5
#define KEY_YOFF			5

#define KEYBOARD_ENGLISH	0
#define KEYBOARD_GERMAN		1

#define KEYBOARD_DEFAULT	KEYBOARD_ENGLISH


typedef struct _vk_keyboard {
	unsigned char	*language;		//language name
	unsigned char	*locale;		//locale name for the encoding
	unsigned char	*normal_keys;	//keys 58
	unsigned char	*shift_keys;	//shift 58
	unsigned char	*alt_keys;		//alt-ed keys
	unsigned char	*font_name;		//xfont name
	Bool 			flag_capslock;	//CapsLock on?
	Bool			flag_shift;		//shift pressed?
	Bool			flag_control;	//control pressed?
	Bool			flag_alt;		//alt pressed?
} vk_keyboard;

typedef struct _vk_keys {
	unsigned		char c;		//character
	unsigned		char f;		//shift char
	unsigned		char a;		//alted char
	unsigned		long s;		//X key symbol
	int				x;			//position and size
	int				y;
	int				w;
	int				h;
} vk_keys;

/*
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 *                                  layout.h
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 */
//init English virtual keyboard
vk_keyboard vkkeyboard[2] = {
	{
	//English Keyboard Layout
       	"English",              //language name
       	"en",                   //locale name for the encoding
       	"`1234567890-=\\\0\0qwertyuiop[]\0\0asdfghjkl;'\0zxcvbnm,./"
	"\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
       	"~!@#$%^&*()_+|\0\0QWERTYUIOP{}\0\0ASDFGHJKL:\"\0ZXCVBNM<>?"
	"\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
       	"",                     //alt-ed keys 58
       	"",                     //xfont name
       	0,                      //CapsLock on?
       	0,                      //shift pressed?
       	0,                      //control pressed?
       	0                       //alt pressed?
	},
	{
	//German Keyboard Layout
	"German",               //language name
	"de",                   //locale name for the encoding
	"^1234567890\337\264#\0\0qwertzuiop\374+\0\0asdfghjkl\366\344\0yxcvbnm,.-"
	"\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
	"\260!\"\247$%&/()=?`'\0\0QWERTZUIOP\334*\0\0ASDFGHJKL\326\304\0YXCVBNM;:_"
	"\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
	"",                     //alt-ed keys 58
	"",                     //xfont name
	0,                      //CapsLock on?
	0,                      //shift pressed?
	0,                      //control pressed?
	0                       //alt pressed?
	}
};

/*
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 *                                  symbol.h
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 */
typedef struct _chinput_symbol{
	char	c;
	int		num;
	int 	cur;
	char    *s;
} chinput_symbol;

// A table convert signle char to double byte char in GB2312 charset.
chinput_symbol chinput_corner_gb[] = {
	{' ',		1,	0,	"¡¡"},
	{'!',		1,	0,	"£¡"},
};

// A table convert signle char to double byte char in Big5 charset.
chinput_symbol chinput_corner_big5[] = {
	{' ',		1,	0,	"¡@"},
	{'!',		1,	0,	"¡I"},
};

#define N_SYMBOL  (sizeof(chinput_corner_gb)/sizeof(chinput_corner_gb[0]))

/*
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 *                                  table.h
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 */
typedef struct _GB2BIG5 {
	char *gb;
	char *big5;
} GB2BIG5;

#define TABLENUM sizeof(hc_g2b)/sizeof(hc_g2b[0])

// A table convert GB2312 char to Big5 equivalent.
gb2big5 hc_g2b[] = {
	{"¡¡", "¡@"},
	{"¡¢", "¡B"},
	{"¡£", "¡C"}
};

/*
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 *                                  tips.h
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 */
#define NUM_TIPS    8
#define MAX_TIP_LEN 242
// "Textual tips for user, oringally, the tips are in GB.
char* tip[] = {
	""
};

/*
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 *                                  XIM.h
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 */
#define DEFAULT_IMNAME  "Chinput"
#define IMLOCALE	"zh_HK.big5hkscs,zh_CN,zh_TW,ja_JP,ko_KR"

/*
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 *                                  Xi18n.h
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 */
#include "XimProto.h"

/*
 * Minor Protocol Number for Extension Protocol 
 */
#define XIM_EXTENSION				128
#define XIM_EXT_SET_EVENT_MASK		(0x30)
#define	XIM_EXT_FORWARD_KEYEVENT	(0x32)
#define	XIM_EXT_MOVE				(0x33)
#define COMMON_EXTENSIONS_NUM   	3

#include <stdlib.h>
#include "IMdkit.h"

/* XI18N Valid Attribute Name Definition */
#define ExtForwardKeyEvent			"extForwardKeyEvent"
#define ExtMove						"extMove"
#define ExtSetEventMask				"extSetEventMask"

/*
 * Padding macro
 */
#define	IMPAD(length)				((4 - ((length)%4))%4)

/*
 * Target Atom for Transport Connection
 */
#define LOCALES						"LOCALES"
#define TRANSPORT					"TRANSPORT"

#define I18N_OPEN					0
#define I18N_SET					1
#define I18N_GET					2

typedef struct
{
    char        *transportname;
    int         namelen;
    Bool        (*checkAddr) ();
} TransportSW;

typedef struct _XIMPending
{
    unsigned char		*p;
    struct _XIMPending	*next;
} XIMPending;

typedef struct _XimProtoHdr
{
    CARD8		major_opcode;
    CARD8		minor_opcode;
    CARD16		length;
} XimProtoHdr;

typedef struct
{
    CARD16		attribute_id;
    CARD16		type;
    CARD16		length;
    char		*name;
} XIMAttr;

typedef struct
{
    CARD16		attribute_id;
    CARD16		type;
    CARD16		length;
    char		*name;
} XICAttr;

typedef struct
{
    int			attribute_id;
    CARD16		name_length; 
    char		*name;
    int			value_length;
    void		*value;
    int			type;
} XIMAttribute;

typedef struct
{
    int			attribute_id;
    CARD16		name_length;
    char		*name;
    int			value_length;
    void		*value;
    int			type;
} XICAttribute;

typedef struct
{
    int			length;
    char		*name;
} XIMStr;

typedef struct
{
    CARD16		major_opcode;
    CARD16		minor_opcode;
    CARD16		length;
    char		*name;
} XIMExt;

typedef struct _Xi18nClient
{
    int			connect_id;
    CARD8		byte_order;
    /*
       '?': initial value
       'B': for Big-Endian
       'l': for little-endian
     */
    int			sync;
    XIMPending  *pending;
    void		*trans_rec;		/* contains transport specific data  */
    struct _Xi18nClient	*next;
} Xi18nClient;

typedef struct _Xi18nCore *Xi18n;

/*
 * Callback Struct for XIM Protocol
 */
typedef struct
{
    int			major_code;
    in			minor_code;
    CARD16		connect_id;
} IMAnyStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD8		byte_order;
    CARD16		major_version;
    CARD16		minor_version;
} IMConnectStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
} IMDisConnectStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    XIMStr		lang;
} IMOpenStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
} IMCloseStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		number;
    XIMStr		*extension;
} IMQueryExtensionStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		number;
    char		**im_attr_list;
} IMGetIMValuesStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		icid;
    CARD16		preedit_attr_num;
    CARD16		status_attr_num;
    CARD16		ic_attr_num;
    XICAttribute *preedit_attr;
    XICAttribute *status_attr;
    XICAttribute *ic_attr;
} IMChangeICStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		icid;
} IMDestroyICStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		icid;
    CARD16		length;
    char		*commit_string;
} IMResetICStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		icid;
} IMChangeFocusStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		icid;
    BITMASK16	sync_bit;
    CARD16		serial_number;
    XEvent		event;
} IMForwardEventStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		icid;
    CARD16		flag;
    KeySym		keysym;
    char		*commit_string;
} IMCommitStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		icid;
    CARD32		flag;
    CARD32		key_index;
    CARD32		event_mask;
} IMTriggerNotifyStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		encoding_number;
    XIMStr		*encoding;	/* name information */
    CARD16		encoding_info_number;
    XIMStr		*encodinginfo;	/* detailed information */
    CARD16		category;	/* #0 for name, #1 for detail */
    INT16		enc_index;	/* index of the encoding determined */
} IMEncodingNegotiationStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		icid;
    CARD32		flag;
    CARD32		forward_event_mask;
    CARD32		sync_event_mask;
} IMSetEventMaskStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		icid;
    CARD32		flag;
    CARD32		intercept_event_mask;
    CARD32		select_event_mask;
    CARD32		forward_event_mask;
    CARD32		sync_event_mask;
} IMExtSetEventMaskStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		icid;
    CARD16		x;
    CARD16		y;
} IMMoveStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		icid;
    BITMASK16	flag;
    CARD16		error_code;
    CARD16		str_length;
    CARD16		error_type;
    char		*error_detail;
} IMErrorStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		icid;
} IMPreeditStateStruct;

/* Callbacks */
typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		icid;
} IMGeometryCBStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		icid;
    union
    {
		int 	return_value;					/* PreeditStart */
		XIMPreeditDrawCallbackStruct	draw;	/* PreeditDraw */
		XIMPreeditCaretCallbackStruct	caret; 	/* PreeditCaret */
    } todo;
} IMPreeditCBStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		icid;
    union
    {
		XIMStatusDrawCallbackStruct		draw;	/* StatusDraw */
    } todo;
} IMStatusCBStruct;

typedef struct
{
    int			major_code;
    int			minor_code;
    CARD16		connect_id;
    CARD16		icid;
    XIMStringConversionCallbackStruct	strconv;
} IMStrConvCBStruct;

typedef union _IMProtocol
{
    int							major_code;
    IMAnyStruct					any;
    IMConnectStruct 			imconnect;
    IMDisConnectStruct		 	imdisconnect;
    IMOpenStruct 				imopen;
    IMCloseStruct 				imclose;
    IMQueryExtensionStruct		queryext;
    IMGetIMValuesStruct			getim;
    IMEncodingNegotiationStruct	encodingnego;
    IMExtSetEventMaskStruct		extsetevent;
    IMMoveStruct				extmove;
    IMSetEventMaskStruct		setevent;
    IMChangeICStruct			changeic;
    IMDestroyICStruct			destroyic;
    IMResetICStruct				resetic;
    IMChangeFocusStruct			changefocus;
    IMCommitStruct				commitstring;
    IMForwardEventStruct		forwardevent;
    IMTriggerNotifyStruct		triggernotify;
    IMPreeditStateStruct		preedit_state;
    IMErrorStruct				imerror;
    IMGeometryCBStruct			geometry_callback;
    IMPreeditCBStruct			preedit_callback;
    IMStatusCBStruct			status_callback;
    IMStrConvCBStruct			strconv_callback;
    long						pad[32];
} IMProtocol;

typedef int (*IMProtoHandler) (XIMS, IMProtocol*);

#define DEFAULT_FILTER_MASK	(KeyPressMask)

/* Xi18nAddressRec structure */
typedef struct _Xi18nAddressRec
{
    Display			*dpy;
    CARD8			im_byteOrder;	/* byte order 'B' or 'l' */
    /* IM Values */
    long			imvalue_mask;
    Window			im_window;	/* IMServerWindow */
    char			*im_name;	/* IMServerName */
    char			*im_locale;	/* IMLocale */
    char			*im_addr;	/* IMServerTransport */
    XIMStyles		input_styles;	/* IMInputStyles */
    XIMTriggerKeys	on_keys;	/* IMOnKeysList */
    XIMTriggerKeys	off_keys;	/* IMOffKeysList */
    XIMEncodings	encoding_list; /* IMEncodingList */
    IMProtoHandler	improto;	/* IMProtocolHander */
    long			filterevent_mask; /* IMFilterEventMask */
    /* XIM_SERVERS target Atoms */
    Atom			selection;
    Atom			Localename;
    Atom			Transportname;
    /* XIM/XIC Attr */
    int				im_attr_num;
    XIMAttr			*xim_attr;
    int				ic_attr_num;
    XICAttr			*xic_attr;
    CARD16			preeditAttr_id;
    CARD16			statusAttr_id;
    CARD16			separatorAttr_id;
    /* XIMExtension List */
    int				ext_num;
    XIMExt			extension[COMMON_EXTENSIONS_NUM];
    /* transport specific connection address */
    void			*connect_addr;
    /* actual data is defined:
       XSpecRec in Xi18nX.h for X-based connection.
       TransSpecRec in Xi18nTr.h for Socket-based connection.
     */
    /* clients table */
    Xi18nClient		*clients;
    Xi18nClient		*free_clients;
} Xi18nAddressRec;

typedef struct _Xi18nMethodsRec
{
    Bool (*begin)	(XIMS);
    Bool (*end)		(XIMS);
    Bool (*send)	(XIMS, CARD16, unsigned char*, long);
    Bool (*wait)	(XIMS, CARD16, CARD8, CARD8);
    Bool (*disconnect) (XIMS, CARD16);
} Xi18nMethodsRec;

typedef struct _Xi18nCore
{
    Xi18nAddressRec address;
    Xi18nMethodsRec methods;
} Xi18nCore;

/*
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 *                                  IMdkit.h
 *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
 */
/* IM Attributes Name */
#define IMModifiers			"modifiers"
#define IMServerWindow		"serverWindow"
#define IMServerName		"serverName"
#define IMServerTransport	"serverTransport"
#define IMLocale			"locale"
#define IMInputStyles		"inputStyles"
#define IMProtocolHandler	"protocolHandler"
#define IMOnKeysList		"onKeysList"
#define IMOffKeysList		"offKeysList"
#define IMEncodingList		"encodingList"
#define IMFilterEventMask	"filterEventMask"
#define IMProtocolDepend	"protocolDepend"

/* Masks for IM Attributes Name */
#define I18N_IMSERVER_WIN	0x0001 /* IMServerWindow */
#define I18N_IM_NAME		0x0002 /* IMServerName */
#define I18N_IM_LOCALE		0x0004 /* IMLocale */
#define I18N_IM_ADDRESS		0x0008 /* IMServerTransport */
#define I18N_INPUT_STYLES	0x0010 /* IMInputStyles */
#define I18N_ON_KEYS		0x0020 /* IMOnKeysList */
#define I18N_OFF_KEYS		0x0040 /* IMOffKeysList */
#define I18N_IM_HANDLER		0x0080 /* IMProtocolHander */
#define I18N_ENCODINGS		0x0100 /* IMEncodingList */
#define I18N_FILTERMASK		0x0200 /* IMFilterEventMask */
#define I18N_PROTO_DEPEND	0x0400 /* IMProtoDepend */

typedef struct
{
    char			*name;
    XPointer		value;
} XIMArg;

typedef struct
{
    CARD32			keysym;
    CARD32			modifier;
    CARD32			modifier_mask;
} XIMTriggerKey;

typedef struct
{
    unsigned short	count_keys;
    XIMTriggerKey	*keylist;
} XIMTriggerKeys;

typedef char *XIMEncoding;

typedef struct
{
    unsigned short	count_encodings;
    XIMEncoding		*supported_encodings;
} XIMEncodings;

typedef struct _XIMS *XIMS;

typedef struct
{
    void*	(*setup)	(Display *, XIMArg *);
    Status	(*openIM)	(XIMS);
    Status	(*closeIM)	(XIMS);
    char*	(*setIMValues)	(XIMS, XIMArg *);
    char*	(*getIMValues)	(XIMS, XIMArg *);
    Status	(*forwardEvent)	(XIMS, ...);
    Status	(*commitString)	(XIMS, ...);
    int		(*callCallback)	(XIMS, ...);
    int		(*preeditStart)	(XIMS, ...);
    int		(*preeditEnd)	(XIMS, ...);
} IMMethodsRec, *IMMethods;

typedef struct
{
    Display	*display;
    int		screen;
} IMCoreRec, *IMCore;

typedef struct _XIMS
{
    IMMethods	methods;
    IMCoreRec	core;
    void	*protocol;
} XIMProtocolRec;

/* 
 * X function declarations.
 */
extern XIMS IMOpenIM (Display *, ...);
extern Status IMCloseIM (XIMS);
extern char *IMSetIMValues (XIMS, ...);
extern char *IMGetIMValues (XIMS, ...);
void IMForwardEvent (XIMS, XPointer);
void IMCommitString (XIMS, XPointer);
int IMCallCallback (XIMS, XPointer);
int IMPreeditStart (XIMS, XPointer);
int IMPreeditEnd (XIMS, XPointer);

