⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sampleim.c

📁 手写识别Chinput3.0.2源代码,可以在linux下开发手写板程序
💻 C
字号:
/******************************************************************          Copyright 1994, 1995 by Sun Microsystems, Inc.         Copyright 1993, 1994 by Hewlett-Packard Company Permission to use, copy, modify, distribute, and sell this softwareand its documentation for any purpose is hereby granted without fee,provided that the above copyright notice appear in all copies andthat both that copyright notice and this permission notice appearin supporting documentation, and that the name of Sun Microsystems, Inc.and Hewlett-Packard not be used in advertising or publicity pertaining todistribution of the software without specific, written prior permission.Sun Microsystems, Inc. and Hewlett-Packard make no representations aboutthe suitability of this software for any purpose.  It is provided "as is"without express or implied warranty. SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALLWARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALLSUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANYSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVERRESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OFCONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF ORIN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.   Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. ******************************************************************/#include <stdio.h>#include <X11/Xlocale.h>#include <X11/Xlib.h>#include <X11/Xutil.h>#include <X11/keysym.h>#include "IMdkit.h"#include "Xi18n.h"#define DEFAULT_IMNAME "sampleIM"#define DEFAULT_LOCALE "zh_CN"/* flags for debugging */Bool use_trigger = True;	/* Dynamic Event Flow is default */Bool use_offkey = False;	/* Register OFF Key for Dynamic Event Flow */Bool use_tcp = False;		/* Using TCP/IP Transport or not */Bool use_local = False;		/* Using Unix domain Tranport or not */long filter_mask = KeyPressMask;CARD16 last_icid = 0;CARD16 last_connectid = 0;/* Supported Inputstyles */static XIMStyle Styles[] = {    XIMPreeditPosition|XIMStatusNothing,    XIMPreeditPosition|XIMStatusArea,    XIMPreeditArea|XIMStatusArea,    XIMPreeditNothing|XIMStatusNothing,    XIMPreeditCallbacks|XIMStatusCallbacks,    0};/* Trigger Keys List */static XIMTriggerKey Trigger_Keys[] = {    {XK_space, ShiftMask, ShiftMask},    {0L, 0L, 0L}};/* Conversion Keys List */static XIMTriggerKey Conversion_Keys[] = {    {XK_k, ControlMask, ControlMask},    {0L, 0L, 0L}};/* Forward Keys List */static XIMTriggerKey Forward_Keys[] = {    {XK_Return, 0, 0},    {XK_Tab, 0, 0},    {0L, 0L, 0L}};/* Supported Taiwanese Encodings */static XIMEncoding zhEncodings[] = {    "COMPOUND_TEXT",    NULL};MyGetICValuesHandler(ims, call_data)XIMS ims;IMChangeICStruct *call_data;{    GetIC(call_data);    return True;}MySetICValuesHandler(ims, call_data)XIMS ims;IMChangeICStruct *call_data;{    SetIC(call_data);    return True;}MyOpenHandler(ims, call_data)XIMS ims;IMOpenStruct *call_data;{#ifdef DEBUG    printf("new_client lang = %s\n", call_data->lang.name);    printf("     connect_id = 0x%x\n", (int)call_data->connect_id);#endif    return True;}MyCloseHandler(ims, call_data)XIMS ims;IMOpenStruct *call_data;{#ifdef DEBUG    printf("closing connect_id 0x%x\n", (int)call_data->connect_id);#endif    return True;}MyCreateICHandler(ims, call_data)XIMS ims;IMChangeICStruct *call_data;{    CreateIC(call_data);    return True;}MyDestroyICHandler(ims, call_data)XIMS ims;IMChangeICStruct *call_data;{    DestroyIC(call_data);    return True;}#define STRBUFLEN 64IsKey(ims, call_data, trigger)XIMS ims;IMForwardEventStruct *call_data;XIMTriggerKey *trigger;		       /* Searching for these keys */{    char strbuf[STRBUFLEN];    KeySym keysym;    int i;    int modifier;    int modifier_mask;    XKeyEvent *kev;    memset(strbuf, 0, STRBUFLEN);    kev = (XKeyEvent*)&call_data->event;    XLookupString(kev, strbuf, STRBUFLEN, &keysym, NULL);    for (i = 0; trigger[i].keysym != 0; i++) {	modifier      = trigger[i].modifier;	modifier_mask = trigger[i].modifier_mask;	if (((KeySym)trigger[i].keysym == keysym)	    && ((kev->state & modifier_mask) == modifier))	  return True;    }    return False;}ProcessKey(ims, call_data)XIMS ims;IMForwardEventStruct *call_data;{    char strbuf[STRBUFLEN];    KeySym keysym;    XKeyEvent *kev;    int count;    fprintf(stderr, "Processing \n");    memset(strbuf, 0, STRBUFLEN);    kev = (XKeyEvent*)&call_data->event;    count = XLookupString(kev, strbuf, STRBUFLEN, &keysym, NULL);    if (count > 0) {	fprintf(stdout, "[%s] ", strbuf);    }}MyForwardEventHandler(ims, call_data)XIMS ims;IMForwardEventStruct *call_data;{    /* Lookup KeyPress Events only */    fprintf(stderr, "ForwardEventHandler\n");    if (call_data->event.type != KeyPress) {        fprintf(stderr, "bogus event type, ignored\n");    	return True;    }    /* In case of Static Event Flow */    if (!use_trigger) {	static Bool preedit_state_flag = False;	if (IsKey(ims, call_data, Trigger_Keys)) {	    preedit_state_flag = !preedit_state_flag;	    return True;	}    }    /* In case of Dynamic Event Flow without registering OFF keys,       the end of preediting must be notified from IMserver to       IMlibrary. */    if (use_trigger && !use_offkey) {	if (IsKey(ims, call_data, Trigger_Keys)) {	    return IMPreeditEnd(ims, (XPointer)call_data);	}    }    last_connectid = (int)call_data->connect_id;    last_icid = (int)call_data->icid;printf("last id:%x %x\n", last_icid, last_connectid);    if (IsKey(ims, call_data, Conversion_Keys)) {	XTextProperty tp;	Display *display = ims->core.display;	/* char *text = "硂琌

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -