New upstream version 3.5.99.27
This commit is contained in:
1
nx-X11/lib/modules/Makefile.am
Normal file
1
nx-X11/lib/modules/Makefile.am
Normal file
@@ -0,0 +1 @@
|
||||
SUBDIRS = im lc om
|
||||
1
nx-X11/lib/modules/im/Makefile.am
Normal file
1
nx-X11/lib/modules/im/Makefile.am
Normal file
@@ -0,0 +1 @@
|
||||
SUBDIRS = ximcp
|
||||
56
nx-X11/lib/modules/im/ximcp/Makefile.am
Normal file
56
nx-X11/lib/modules/im/ximcp/Makefile.am
Normal file
@@ -0,0 +1,56 @@
|
||||
NULL =
|
||||
|
||||
noinst_LTLIBRARIES=libximcp.la
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/include/X11 \
|
||||
-I$(top_builddir)/include \
|
||||
-I$(top_builddir)/include/X11 \
|
||||
-I$(top_srcdir)/src/xcms \
|
||||
-I$(top_srcdir)/src/xkb \
|
||||
-I$(top_srcdir)/src/xlibi18n \
|
||||
-I$(top_srcdir)/src \
|
||||
-I$(top_srcdir)/../exports/include \
|
||||
-D_GNU_SOURCE \
|
||||
-DXIM_t \
|
||||
-DTRANS_CLIENT \
|
||||
$(NULL)
|
||||
|
||||
AM_CFLAGS = \
|
||||
$(X11_CFLAGS) \
|
||||
$(BIGFONT_CFLAGS) \
|
||||
$(MALLOC_ZERO_CFLAGS) \
|
||||
$(CWARNFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
ximcp_la_SOURCES = \
|
||||
imCallbk.c \
|
||||
imDefFlt.c \
|
||||
imDefIc.c \
|
||||
imDefIm.c \
|
||||
imDefLkup.c \
|
||||
imDispch.c \
|
||||
imEvToWire.c \
|
||||
imExten.c \
|
||||
imImSw.c \
|
||||
imInsClbk.c \
|
||||
imInt.c \
|
||||
imLcFlt.c \
|
||||
imLcGIc.c \
|
||||
imLcIc.c \
|
||||
imLcIm.c \
|
||||
imLcLkup.c \
|
||||
imLcPrs.c \
|
||||
imLcSIc.c \
|
||||
imRmAttr.c \
|
||||
imRm.c \
|
||||
imThaiFlt.c \
|
||||
imThaiIc.c \
|
||||
imThaiIm.c \
|
||||
imTrans.c \
|
||||
imTransR.c \
|
||||
imTrX.c \
|
||||
$(NULL)
|
||||
|
||||
libximcp_la_SOURCES = $(ximcp_la_SOURCES)
|
||||
747
nx-X11/lib/modules/im/ximcp/imCallbk.c
Normal file
747
nx-X11/lib/modules/im/ximcp/imCallbk.c
Normal file
@@ -0,0 +1,747 @@
|
||||
/***********************************************************************
|
||||
Copyright 1993 by Digital Equipment Corporation, Maynard, Massachusetts,
|
||||
Copyright 1994 by FUJITSU LIMITED
|
||||
Copyright 1994 by Sony Corporation
|
||||
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee is hereby granted,
|
||||
provided that the above copyright notice appear in all copies and that
|
||||
both that copyright notice and this permission notice appear in
|
||||
supporting documentation, and that the names of Digital, FUJITSU
|
||||
LIMITED and Sony Corporation not be used in advertising or publicity
|
||||
pertaining to distribution of the software without specific, written
|
||||
prior permission.
|
||||
|
||||
DIGITAL, FUJITSU LIMITED AND SONY CORPORATION DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DIGITAL, FUJITSU LIMITED
|
||||
AND SONY CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Author: Hiroyuki Miyamoto Digital Equipment Corporation
|
||||
miyamoto@jrd.dec.com
|
||||
Modifier: Takashi Fujiwara FUJITSU LIMITED
|
||||
fujiwara@a80.tech.yk.fujitsu.co.jp
|
||||
Makoto Wakamatsu Sony Corporation
|
||||
makoto@sm.sony.co.jp
|
||||
|
||||
***********************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include "Xlibint.h"
|
||||
#include "Xlcint.h"
|
||||
#include "Ximint.h"
|
||||
#include "XlcPubI.h"
|
||||
|
||||
#define sz_CARD8 1
|
||||
#define sz_INT8 1
|
||||
#define sz_CARD16 2
|
||||
#define sz_INT16 2
|
||||
#define sz_BITMASK16 sz_CARD16
|
||||
#define sz_CARD32 4
|
||||
#define sz_INT32 4
|
||||
#define sz_BITMASK32 sz_CARD32
|
||||
#define sz_XIMID sizeof(XIMID)
|
||||
#define sz_XICID sizeof(XICID)
|
||||
#define sz_XIMATTRID sizeof(XIMATTRID)
|
||||
#define sz_XICATTRID sizeof(XICATTRID)
|
||||
#define sz_ximPacketHeader (XIM_HEADER_SIZE + sz_XIMID + sz_XICID)
|
||||
#define sz_ximGeometry 0
|
||||
#define sz_ximStrConversion (sz_CARD32 + sz_CARD32 + sz_CARD32 + sz_CARD32)
|
||||
#define sz_ximPreeditStart 0
|
||||
#define sz_ximPreeditStartReply sz_INT32
|
||||
#define sz_ximPreeditCaret (sz_INT32 + sz_CARD32 + sz_CARD32)
|
||||
#define sz_ximPreeditCaretReply sz_CARD32
|
||||
#define sz_ximPreeditDone 0
|
||||
#define sz_ximStatusStart 0
|
||||
#define sz_ximStatusDone 0
|
||||
|
||||
typedef enum {
|
||||
XimCbSuccess,
|
||||
XimCbNoCallback,
|
||||
XimCbError,
|
||||
XimCbQueued,
|
||||
XimCbBadContextID,
|
||||
XimCbBadOpcode
|
||||
} XimCbStatus;
|
||||
|
||||
typedef XimCbStatus (*XimCb)(
|
||||
Xim, Xic, char*, int
|
||||
);
|
||||
|
||||
#define PACKET_TO_MAJOROPCODE(p) (*(CARD8*)((CARD8*)(p)))
|
||||
#define PACKET_TO_MINOROPCODE(p) (*(CARD8*)((CARD8*)(p) + sz_CARD8))
|
||||
#define PACKET_TO_LENGTH(p) (*(CARD16*)((CARD8*)(p) + sz_CARD8 + sz_CARD8))
|
||||
#define PACKET_TO_IMID(p) (*(XIMID*)((CARD8*)(p) + XIM_HEADER_SIZE))
|
||||
#define PACKET_TO_ICID(p) (*(XICID*)((CARD8*)(p) + XIM_HEADER_SIZE + sz_XIMID))
|
||||
|
||||
#define _XimWriteData(im,len,data) \
|
||||
(im->private.proto.write((im),(len),(XPointer)(data)))
|
||||
#define _XimReadData(im,buf,buf_len,len) \
|
||||
(im->private.proto.read((im),(XPointer)(buf),(buf_len),&(len)))
|
||||
#define _XimFlushData(im) im->private.proto.flush((im))
|
||||
|
||||
static XimCbStatus _XimGeometryCallback(Xim, Xic, char*, int);
|
||||
static XimCbStatus _XimStrConversionCallback(Xim, Xic, char*, int);
|
||||
static XimCbStatus _XimPreeditStartCallback(Xim, Xic, char*, int);
|
||||
static XimCbStatus _XimPreeditDoneCallback(Xim, Xic, char*, int);
|
||||
static void _free_memory_for_text(XIMText*);
|
||||
static XimCbStatus _XimPreeditDrawCallback(Xim, Xic, char*, int);
|
||||
static XimCbStatus _XimPreeditCaretCallback(Xim, Xic, char*, int);
|
||||
static XimCbStatus _XimStatusStartCallback(Xim, Xic, char*, int);
|
||||
static XimCbStatus _XimStatusDoneCallback(Xim, Xic, char*, int);
|
||||
static XimCbStatus _XimStatusDrawCallback(Xim, Xic, char*, int);
|
||||
static XimCbStatus _XimPreeditStateNotifyCallback(Xim, Xic, char *, int);
|
||||
|
||||
#if defined(__STDC__) && ((defined(sun) && defined(SVR4)) || defined(WIN32))
|
||||
#define RConst /**/
|
||||
#else
|
||||
#define RConst const
|
||||
#endif
|
||||
|
||||
/* NOTE:
|
||||
* the table below depends on the protocol number
|
||||
* defined in the IM Protocol document.
|
||||
*/
|
||||
static RConst XimCb callback_table[] = {
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #000-009 */
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #010-019 */
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #020-029 */
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #030-039 */
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #040-049 */
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #050-059 */
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* #060-069 */
|
||||
_XimGeometryCallback, /* #070 */
|
||||
_XimStrConversionCallback, /* #071 */
|
||||
NULL, /* #072 */
|
||||
_XimPreeditStartCallback, /* #073 */
|
||||
NULL, /* #074 */
|
||||
_XimPreeditDrawCallback, /* #075 */
|
||||
_XimPreeditCaretCallback, /* #076 */
|
||||
NULL, /* #077 */
|
||||
_XimPreeditDoneCallback, /* #078 */
|
||||
_XimStatusStartCallback, /* #079 */
|
||||
_XimStatusDrawCallback, /* #080 */
|
||||
_XimStatusDoneCallback, /* #081 */
|
||||
_XimPreeditStateNotifyCallback /* #082 */
|
||||
};
|
||||
|
||||
|
||||
static Bool
|
||||
_XimIsReadyForProcess(Xic ic)
|
||||
{
|
||||
return(!ic->private.proto.waitCallback); /* check HM */
|
||||
}
|
||||
|
||||
static void
|
||||
_XimProcessPendingCallbacks(Xic ic)
|
||||
{
|
||||
XimPendingCallback pcbq;
|
||||
|
||||
while (((pcbq = ic->private.proto.pend_cb_que) != (XimPendingCallback)NULL)
|
||||
&& _XimIsReadyForProcess(ic)) {
|
||||
(void) (*callback_table[pcbq->major_opcode])(pcbq->im,
|
||||
pcbq->ic,
|
||||
pcbq->proto,
|
||||
pcbq->proto_len);
|
||||
ic->private.proto.pend_cb_que = pcbq->next;
|
||||
Xfree(pcbq->proto); /* free memory of XimPendingCallback */
|
||||
Xfree(pcbq);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_XimPutCbIntoQueue(Xic ic, XimPendingCallback call_data)
|
||||
{
|
||||
XimPendingCallback pcbq = ic->private.proto.pend_cb_que;
|
||||
|
||||
/* Queuing is FIFO
|
||||
*/
|
||||
while (pcbq != (XimPendingCallback)NULL) {
|
||||
if (pcbq->next == (XimPendingCallback)NULL) {
|
||||
break;
|
||||
}
|
||||
pcbq = pcbq->next;
|
||||
}
|
||||
if (pcbq == (XimPendingCallback)NULL) {
|
||||
ic->private.proto.pend_cb_que = call_data;
|
||||
}
|
||||
else {
|
||||
pcbq->next = call_data;
|
||||
}
|
||||
}
|
||||
|
||||
Bool
|
||||
_XimCbDispatch(Xim xim,
|
||||
INT16 len,
|
||||
XPointer data,
|
||||
XPointer call_data)
|
||||
{
|
||||
/* `data' points to the beginning of the packet defined in IM Protocol doc.
|
||||
*/
|
||||
int major_opcode = PACKET_TO_MAJOROPCODE(data);
|
||||
XIMID imid = PACKET_TO_IMID(data);
|
||||
XICID icid = PACKET_TO_ICID(data);
|
||||
Xim im = (Xim)call_data; /* check HM */
|
||||
Xic ic = _XimICOfXICID(im, icid);
|
||||
char* proto;
|
||||
int proto_len;
|
||||
|
||||
/* check validity of im/ic
|
||||
*/
|
||||
if ((imid != im->private.proto.imid) || !ic) {
|
||||
return False; /* status = XimCbBadContextID; */
|
||||
}
|
||||
|
||||
/* process pending callbacks
|
||||
*/
|
||||
_XimProcessPendingCallbacks(ic);
|
||||
|
||||
/* check if the protocol should be processed here
|
||||
*/
|
||||
if (major_opcode > 82) {
|
||||
return False; /* status = XimCbBadOpcode; */
|
||||
}
|
||||
if (!callback_table[major_opcode]) {
|
||||
return False; /* status = XimCbBadOpcode; */
|
||||
}
|
||||
|
||||
/* move the pointer ahead by the IM Protocol packet header size
|
||||
*/
|
||||
proto = (char*)data + sz_ximPacketHeader;
|
||||
proto_len = (int)len - sz_ximPacketHeader;
|
||||
|
||||
/* check if it can be processed right away
|
||||
* and if no, queue the protocol, otherwise invoke a callback
|
||||
*/
|
||||
if (!_XimIsReadyForProcess(ic)) {
|
||||
|
||||
/* queue the protocol
|
||||
*/
|
||||
XimPendingCallback pcb;
|
||||
char *proto_buf = (proto_len > 0) ? Xmalloc(proto_len) : NULL;
|
||||
|
||||
pcb = Xmalloc(sizeof(XimPendingCallbackRec));
|
||||
if (pcb && (proto_len <= 0 || proto_buf)) {
|
||||
if (proto_len > 0)
|
||||
memcpy(proto_buf, proto, proto_len);
|
||||
|
||||
pcb->major_opcode = major_opcode;
|
||||
pcb->im = im;
|
||||
pcb->ic = ic;
|
||||
pcb->proto = proto_buf;
|
||||
pcb->proto_len = proto_len;
|
||||
pcb->next = (XimPendingCallback)NULL; /* queue is FIFO */
|
||||
_XimPutCbIntoQueue(ic, pcb);
|
||||
/* status = XimCbQueued; */
|
||||
} else {
|
||||
/* status = XimCbError; */
|
||||
Xfree(pcb);
|
||||
Xfree(proto_buf);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* invoke each callback according to the major opcode.
|
||||
* `proto' points to the next address of IM-ID and IC-ID.
|
||||
* `proto_len' specifies the packet length.
|
||||
*/
|
||||
(void) (*callback_table[major_opcode])(im, ic, proto, proto_len);
|
||||
}
|
||||
return True;
|
||||
}
|
||||
|
||||
static XimCbStatus
|
||||
_XimGeometryCallback(Xim im,
|
||||
Xic ic,
|
||||
char* proto,
|
||||
int len)
|
||||
{
|
||||
XICCallback* cb = &ic->core.geometry_callback;
|
||||
|
||||
/* invoke the callback
|
||||
*/
|
||||
if (cb && cb->callback) {
|
||||
(*cb->callback)((XIC)ic, cb->client_data, (XPointer)NULL);
|
||||
}
|
||||
else {
|
||||
|
||||
/* no callback registered
|
||||
*/
|
||||
return XimCbNoCallback;
|
||||
}
|
||||
|
||||
return XimCbSuccess;
|
||||
}
|
||||
|
||||
static XimCbStatus
|
||||
_XimStrConversionCallback(Xim im,
|
||||
Xic ic,
|
||||
char* proto,
|
||||
int len)
|
||||
{
|
||||
XICCallback* cb = &ic->core.string_conversion_callback; /* check HM */
|
||||
XIMStringConversionCallbackStruct cbrec;
|
||||
|
||||
/* invoke the callback
|
||||
*/
|
||||
if (cb && cb->callback) {
|
||||
int p = XIM_HEADER_SIZE;
|
||||
cbrec.position = (XIMStringConversionPosition)
|
||||
*(CARD32*)&proto[p]; p += sz_CARD32;
|
||||
cbrec.direction = (XIMCaretDirection)
|
||||
*(CARD32*)&proto[p]; p += sz_CARD32;
|
||||
cbrec.operation = (XIMStringConversionOperation)
|
||||
*(CARD32*)&proto[p]; p += sz_CARD32;
|
||||
cbrec.factor = (unsigned short)
|
||||
*(CARD32*)&proto[p];
|
||||
|
||||
(*cb->callback)((XIC)ic, cb->client_data, (XPointer)&cbrec);
|
||||
}
|
||||
else {
|
||||
|
||||
/* no callback registered
|
||||
*/
|
||||
_XimError(im, ic,
|
||||
(CARD16)XIM_BadSomething,
|
||||
(INT16)len,
|
||||
(CARD16)XIM_STR_CONVERSION,
|
||||
(char*)proto); /* send XIM_ERROR */
|
||||
return XimCbNoCallback;
|
||||
}
|
||||
|
||||
/* send a reply
|
||||
*/
|
||||
{
|
||||
CARD8 *buf;
|
||||
INT16 buf_len;
|
||||
int p, length_in_bytes, i;
|
||||
|
||||
/* Assumption:
|
||||
* `cbrec.text->length' means the string length in characters
|
||||
*/
|
||||
{
|
||||
length_in_bytes = (cbrec.text->encoding_is_wchar)?
|
||||
sizeof(wchar_t) * cbrec.text->length: /* wchar */
|
||||
strlen(cbrec.text->string.mbs); /* mb */
|
||||
buf_len = XIM_HEADER_SIZE +
|
||||
sz_CARD16 +
|
||||
2 + length_in_bytes +
|
||||
XIM_PAD(2 + length_in_bytes) +
|
||||
2 + 2 + sz_CARD32 * cbrec.text->length;
|
||||
buf = Xmalloc(buf_len);
|
||||
}
|
||||
_XimSetHeader((XPointer)buf, XIM_STR_CONVERSION_REPLY, 0, &buf_len);
|
||||
buf_len -= XIM_HEADER_SIZE; /* added by _XimSetHeader (HACK) */
|
||||
p = XIM_HEADER_SIZE;
|
||||
*(CARD16*)&buf[p] = (CARD16)im->private.proto.imid; p += sz_CARD16;
|
||||
*(CARD16*)&buf[p] = (CARD16)ic->private.proto.icid; p += sz_CARD16;
|
||||
*(CARD16*)&buf[p] = (CARD16)cbrec.text->length; p += sz_CARD16;
|
||||
memcpy(&buf[p],&cbrec.text->string.mbs,length_in_bytes);
|
||||
p += length_in_bytes;
|
||||
*(CARD16*)&buf[p] = (CARD16)(sz_CARD32*cbrec.text->length);
|
||||
p += XIM_PAD(2);
|
||||
for (i = 0; i < (int)cbrec.text->length; i++) {
|
||||
*(CARD32*)&buf[p] = (CARD32)cbrec.text->feedback[i];
|
||||
p += sz_CARD32;
|
||||
}
|
||||
|
||||
if (!(_XimWriteData(im, buf_len, buf))) {
|
||||
return XimCbError;
|
||||
}
|
||||
_XimFlushData(im);
|
||||
|
||||
Xfree(buf);
|
||||
}
|
||||
|
||||
return XimCbSuccess;
|
||||
}
|
||||
|
||||
static XimCbStatus
|
||||
_XimPreeditStartCallback(Xim im,
|
||||
Xic ic,
|
||||
char* proto,
|
||||
int len)
|
||||
{
|
||||
XICCallback* cb = &ic->core.preedit_attr.start_callback;
|
||||
int ret;
|
||||
|
||||
/* invoke the callback
|
||||
*/
|
||||
if (cb && cb->callback){
|
||||
ret = (*(cb->callback))((XIC)ic, cb->client_data, (XPointer)NULL);
|
||||
}
|
||||
else {
|
||||
|
||||
/* no callback registered
|
||||
*/
|
||||
_XimError(im, ic,
|
||||
(CARD16)XIM_BadSomething,
|
||||
(INT16)len,
|
||||
(CARD16)XIM_PREEDIT_START,
|
||||
(char*)proto); /* send XIM_ERROR */
|
||||
return XimCbNoCallback;
|
||||
}
|
||||
|
||||
/* send a reply
|
||||
*/
|
||||
{
|
||||
CARD32 buf32[(sz_ximPacketHeader + sz_ximPreeditStartReply) / 4];
|
||||
CARD8 *buf = (CARD8 *)buf32;
|
||||
INT16 buf_len = sz_XIMID + sz_XICID + sz_ximPreeditStartReply;
|
||||
int p;
|
||||
|
||||
_XimSetHeader((XPointer)buf, XIM_PREEDIT_START_REPLY, 0, &buf_len);
|
||||
p = XIM_HEADER_SIZE;
|
||||
*(CARD16*)&buf[p] = (CARD16)im->private.proto.imid; p += sz_CARD16;
|
||||
*(CARD16*)&buf[p] = (CARD16)ic->private.proto.icid; p += sz_CARD16;
|
||||
*(INT32*)&buf[p] = (INT32)ret;
|
||||
|
||||
if (!(_XimWriteData(im, buf_len, buf))) {
|
||||
return XimCbError;
|
||||
}
|
||||
_XimFlushData(im);
|
||||
}
|
||||
|
||||
return XimCbSuccess;
|
||||
}
|
||||
|
||||
static XimCbStatus
|
||||
_XimPreeditDoneCallback(Xim im,
|
||||
Xic ic,
|
||||
char* proto,
|
||||
int len)
|
||||
{
|
||||
XICCallback* cb = &ic->core.preedit_attr.done_callback;
|
||||
|
||||
/* invoke the callback
|
||||
*/
|
||||
if (cb && cb->callback) {
|
||||
(*cb->callback)((XIC)ic, cb->client_data, (XPointer)NULL);
|
||||
}
|
||||
else {
|
||||
|
||||
/* no callback registered
|
||||
*/
|
||||
return XimCbNoCallback;
|
||||
}
|
||||
|
||||
return XimCbSuccess;
|
||||
}
|
||||
|
||||
static void
|
||||
_read_text_from_packet(Xim im,
|
||||
char* buf,
|
||||
XIMText** text_ptr)
|
||||
{
|
||||
int status;
|
||||
XIMText* text;
|
||||
int tmp_len;
|
||||
char* tmp_buf;
|
||||
Status s = 0;
|
||||
|
||||
status = (int)*(BITMASK32*)buf; buf += sz_BITMASK32;
|
||||
|
||||
/* string part
|
||||
*/
|
||||
if (status & 0x00000001) /* "no string" bit on */ {
|
||||
buf += sz_CARD16; /* skip "length of preedit string" */
|
||||
buf += 2; /* pad */
|
||||
*text_ptr = (XIMText*)NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
*text_ptr = text = Xmalloc(sizeof(XIMText));
|
||||
if (text == (XIMText*)NULL) return;
|
||||
|
||||
tmp_len = (int)*(CARD16*)buf;
|
||||
buf += sz_CARD16;
|
||||
if ((tmp_buf = Xmalloc(tmp_len + 1))) {
|
||||
memcpy(tmp_buf, buf, tmp_len);
|
||||
tmp_buf[tmp_len] = '\0';
|
||||
|
||||
text->encoding_is_wchar = False;
|
||||
text->length = im->methods->ctstombs((XIM)im,
|
||||
tmp_buf, tmp_len,
|
||||
NULL, 0, &s); /* CT? HM */
|
||||
if (s != XLookupNone) {
|
||||
#ifndef NO_DEC_I18N_FIX
|
||||
/* Allow for NULL-terminated */
|
||||
if ((text->string.multi_byte = Xmalloc(text->length *
|
||||
XLC_PUBLIC(im->core.lcd,mb_cur_max) + 1))) {
|
||||
#else
|
||||
if (text->string.multi_byte = Xmalloc(text->length+1)) {
|
||||
#endif
|
||||
int tmp;
|
||||
#ifndef NO_DEC_I18N_FIX
|
||||
char *char_tmp;
|
||||
int char_len;
|
||||
#endif
|
||||
tmp = im->methods->ctstombs((XIM)im,
|
||||
tmp_buf, tmp_len,
|
||||
#ifndef NO_DEC_I18N_FIX
|
||||
text->string.multi_byte,
|
||||
text->length * XLC_PUBLIC(im->core.lcd,mb_cur_max) + 1,
|
||||
#else
|
||||
text->string.multi_byte, text->length,
|
||||
#endif
|
||||
&s);
|
||||
text->string.multi_byte[tmp] = '\0';
|
||||
#ifndef NO_DEC_I18N_FIX
|
||||
text->length = 0;
|
||||
char_tmp = text->string.multi_byte;
|
||||
while (*char_tmp != '\0') {
|
||||
char_len = mblen(char_tmp, strlen(char_tmp));
|
||||
char_tmp = char_tmp + char_len;
|
||||
(text->length)++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else {
|
||||
text->length = 0;
|
||||
text->string.multi_byte = NULL;
|
||||
}
|
||||
|
||||
Xfree(tmp_buf);
|
||||
}
|
||||
buf += tmp_len;
|
||||
|
||||
buf += XIM_PAD(sz_CARD16 + tmp_len); /* pad */
|
||||
|
||||
/* feedback part
|
||||
*/
|
||||
if (status & 0x00000002) /* "no feedback" bit on */ {
|
||||
text->feedback = (XIMFeedback*)NULL;
|
||||
}
|
||||
else {
|
||||
int i, j;
|
||||
|
||||
i = (int)*(CARD16*)buf; buf += sz_CARD16;
|
||||
buf += sz_CARD16; /* skip `unused' */
|
||||
text->feedback = Xmalloc(i*(sizeof(XIMFeedback)/sizeof(CARD32)));
|
||||
j = 0;
|
||||
while (i > 0) {
|
||||
text->feedback[j] = (XIMFeedback)*(CARD32*)buf;
|
||||
buf += sz_CARD32;
|
||||
i -= sz_CARD32;
|
||||
j++;
|
||||
}
|
||||
/*
|
||||
* text->length tells how long both the status string and
|
||||
* the feedback array are. If there's "no string" the
|
||||
* text->length was set to zero previously. See above.
|
||||
* But if there is feedback (i.e. not "no feedback") then
|
||||
* we need to convey the length of the feedback array.
|
||||
* It might have been better if the protocol sent two
|
||||
* different values, one for the length of the status
|
||||
* string and one for the length of the feedback array.
|
||||
*/
|
||||
if (status & 0x00000001) /* "no string" bit on */ {
|
||||
text->length = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_free_memory_for_text(XIMText* text)
|
||||
{
|
||||
if (text) {
|
||||
Xfree(text->string.multi_byte);
|
||||
Xfree(text->feedback);
|
||||
Xfree(text);
|
||||
}
|
||||
}
|
||||
|
||||
static XimCbStatus
|
||||
_XimPreeditDrawCallback(Xim im,
|
||||
Xic ic,
|
||||
char* proto,
|
||||
int len)
|
||||
{
|
||||
XICCallback* cb = &ic->core.preedit_attr.draw_callback;
|
||||
XIMPreeditDrawCallbackStruct cbs;
|
||||
|
||||
/* invoke the callback
|
||||
*/
|
||||
if (cb && cb->callback) {
|
||||
cbs.caret = (int)*(INT32*)proto; proto += sz_INT32;
|
||||
cbs.chg_first = (int)*(INT32*)proto; proto += sz_INT32;
|
||||
cbs.chg_length = (int)*(INT32*)proto; proto += sz_INT32;
|
||||
_read_text_from_packet(im, proto, &cbs.text);
|
||||
|
||||
(*cb->callback)((XIC)ic, cb->client_data, (XPointer)&cbs);
|
||||
|
||||
_free_memory_for_text((XIMText*)cbs.text);
|
||||
}
|
||||
else {
|
||||
|
||||
/* no callback registered
|
||||
*/
|
||||
return XimCbNoCallback;
|
||||
}
|
||||
|
||||
return XimCbSuccess;
|
||||
}
|
||||
|
||||
static XimCbStatus
|
||||
_XimPreeditCaretCallback(Xim im,
|
||||
Xic ic,
|
||||
char* proto,
|
||||
int len)
|
||||
{
|
||||
XICCallback* cb = &ic->core.preedit_attr.caret_callback;
|
||||
XIMPreeditCaretCallbackStruct cbs;
|
||||
|
||||
/* invoke the callback
|
||||
*/
|
||||
if (cb && cb->callback) {
|
||||
cbs.position = (int)*(INT32*)proto; proto += sz_INT32;
|
||||
cbs.direction = (XIMCaretDirection)*(CARD32*)proto; proto += sz_CARD32;
|
||||
cbs.style = (XIMCaretStyle)*(CARD32*)proto; proto += sz_CARD32;
|
||||
|
||||
(*cb->callback)((XIC)ic, cb->client_data, (XPointer)&cbs);
|
||||
}
|
||||
else {
|
||||
|
||||
/* no callback registered
|
||||
*/
|
||||
_XimError(im, ic,
|
||||
(CARD16)XIM_BadSomething,
|
||||
(INT16)len,
|
||||
(CARD16)XIM_PREEDIT_CARET,
|
||||
(char*)proto); /* send XIM_ERROR */
|
||||
return XimCbNoCallback;
|
||||
}
|
||||
|
||||
/* Send a reply
|
||||
*/
|
||||
{
|
||||
CARD8 buf[sz_ximPacketHeader + sz_ximPreeditCaretReply];
|
||||
INT16 rlen = sz_XIMID + sz_XICID + sz_ximPreeditCaretReply;
|
||||
int p;
|
||||
|
||||
_XimSetHeader((XPointer)buf, XIM_PREEDIT_CARET_REPLY, 0, &rlen);
|
||||
p = XIM_HEADER_SIZE;
|
||||
*(CARD16*)&buf[p] = (CARD16)im->private.proto.imid; p += sz_CARD16;
|
||||
*(CARD16*)&buf[p] = (CARD16)ic->private.proto.icid; p += sz_CARD16;
|
||||
*(CARD32*)&buf[p] = (CARD32)cbs.position;
|
||||
|
||||
if (!(_XimWriteData(im, rlen, buf))) {
|
||||
return XimCbError;
|
||||
}
|
||||
_XimFlushData(im);
|
||||
}
|
||||
|
||||
return XimCbSuccess;
|
||||
}
|
||||
|
||||
static XimCbStatus
|
||||
_XimStatusStartCallback(Xim im,
|
||||
Xic ic,
|
||||
char* proto,
|
||||
int len)
|
||||
{
|
||||
XICCallback* cb = &ic->core.status_attr.start_callback;
|
||||
|
||||
/* invoke the callback
|
||||
*/
|
||||
if (cb && cb->callback) {
|
||||
(*cb->callback)((XIC)ic, cb->client_data, (XPointer)NULL);
|
||||
}
|
||||
else {
|
||||
|
||||
/* no callback registered
|
||||
*/
|
||||
return XimCbNoCallback;
|
||||
}
|
||||
|
||||
return XimCbSuccess;
|
||||
}
|
||||
|
||||
static XimCbStatus
|
||||
_XimStatusDoneCallback(Xim im,
|
||||
Xic ic,
|
||||
char* proto,
|
||||
int len)
|
||||
{
|
||||
XICCallback* cb = &ic->core.status_attr.done_callback;
|
||||
|
||||
/* invoke the callback
|
||||
*/
|
||||
if (cb && cb->callback) {
|
||||
(*cb->callback)((XIC)ic, cb->client_data, (XPointer)NULL);
|
||||
}
|
||||
else {
|
||||
|
||||
/* no callback registered
|
||||
*/
|
||||
return XimCbNoCallback;
|
||||
}
|
||||
|
||||
return XimCbSuccess;
|
||||
}
|
||||
|
||||
static XimCbStatus
|
||||
_XimStatusDrawCallback(Xim im,
|
||||
Xic ic,
|
||||
char* proto,
|
||||
int len)
|
||||
{
|
||||
XICCallback* cb = &ic->core.status_attr.draw_callback;
|
||||
XIMStatusDrawCallbackStruct cbs;
|
||||
|
||||
/* invoke the callback
|
||||
*/
|
||||
if (cb && cb->callback) {
|
||||
cbs.type = (XIMStatusDataType)*(CARD32*)proto; proto += sz_CARD32;
|
||||
if (cbs.type == XIMTextType) {
|
||||
_read_text_from_packet(im, proto, &cbs.data.text);
|
||||
}
|
||||
else if (cbs.type == XIMBitmapType) {
|
||||
cbs.data.bitmap = (Pixmap)*(CARD32*)proto;
|
||||
}
|
||||
|
||||
(*cb->callback)((XIC)ic, cb->client_data, (XPointer)&cbs);
|
||||
|
||||
if (cbs.type == XIMTextType)
|
||||
_free_memory_for_text((XIMText *)cbs.data.text);
|
||||
}
|
||||
else {
|
||||
|
||||
/* no callback registered
|
||||
*/
|
||||
return XimCbNoCallback;
|
||||
}
|
||||
|
||||
return XimCbSuccess;
|
||||
}
|
||||
|
||||
static XimCbStatus
|
||||
_XimPreeditStateNotifyCallback( Xim im, Xic ic, char* proto, int len )
|
||||
{
|
||||
XICCallback *cb = &ic->core.preedit_attr.state_notify_callback;
|
||||
|
||||
/* invoke the callback
|
||||
*/
|
||||
if( cb && cb->callback ) {
|
||||
XIMPreeditStateNotifyCallbackStruct cbrec;
|
||||
|
||||
cbrec.state = *(BITMASK32 *)proto;
|
||||
(*cb->callback)( (XIC)ic, cb->client_data, (XPointer)&cbrec );
|
||||
}
|
||||
else {
|
||||
/* no callback registered
|
||||
*/
|
||||
return XimCbNoCallback;
|
||||
}
|
||||
|
||||
return XimCbSuccess;
|
||||
}
|
||||
|
||||
413
nx-X11/lib/modules/im/ximcp/imDefFlt.c
Normal file
413
nx-X11/lib/modules/im/ximcp/imDefFlt.c
Normal file
@@ -0,0 +1,413 @@
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1992, 1993, 1994 by FUJITSU LIMITED
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and
|
||||
that both that copyright notice and this permission notice appear
|
||||
in supporting documentation, and that the name of FUJITSU LIMITED
|
||||
not be used in advertising or publicity pertaining to distribution
|
||||
of the software without specific, written prior permission.
|
||||
FUJITSU LIMITED makes no representations about the suitability of
|
||||
this software for any purpose.
|
||||
It is provided "as is" without express or implied warranty.
|
||||
|
||||
FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Author: Takashi Fujiwara FUJITSU LIMITED
|
||||
fujiwara@a80.tech.yk.fujitsu.co.jp
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <nx-X11/Xatom.h>
|
||||
#include "Xlibint.h"
|
||||
#include "Xutil.h"
|
||||
#include "Xlcint.h"
|
||||
#include "Ximint.h"
|
||||
|
||||
static long
|
||||
_XimTriggerCheck(
|
||||
Xim im,
|
||||
XKeyEvent *ev,
|
||||
INT32 len,
|
||||
CARD32 *keylist)
|
||||
{
|
||||
register long i;
|
||||
KeySym keysym;
|
||||
CARD32 buf32[BUFSIZE/4];
|
||||
char *buf = (char *)buf32;
|
||||
int modifier;
|
||||
int modifier_mask;
|
||||
CARD32 min_len = sizeof(CARD32) /* sizeof keysym */
|
||||
+ sizeof(CARD32) /* sizeof modifier */
|
||||
+ sizeof(CARD32); /* sizeof modifier mask */
|
||||
|
||||
XLookupString(ev, buf, BUFSIZE, &keysym, NULL);
|
||||
if (!keysym)
|
||||
return -1;
|
||||
|
||||
for (i = 0; len >= min_len; i += 3, len -= min_len) {
|
||||
modifier = keylist[i + 1];
|
||||
modifier_mask = keylist[i + 2];
|
||||
if (((KeySym)keylist[i] == keysym)
|
||||
&& ((ev->state & modifier_mask) == modifier))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static long
|
||||
_XimTriggerOnCheck(
|
||||
Xim im,
|
||||
XKeyEvent *ev)
|
||||
{
|
||||
return _XimTriggerCheck(im, ev, (INT32)im->private.proto.im_onkeylist[0],
|
||||
&im->private.proto.im_onkeylist[1]);
|
||||
}
|
||||
|
||||
static long
|
||||
_XimTriggerOffCheck(
|
||||
Xim im,
|
||||
XKeyEvent *ev)
|
||||
{
|
||||
return _XimTriggerCheck(im, ev, (INT32)im->private.proto.im_offkeylist[0],
|
||||
&im->private.proto.im_offkeylist[1]);
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimOnKeysCheck(
|
||||
Xic ic,
|
||||
XKeyEvent *ev)
|
||||
{
|
||||
Xim im = (Xim)ic->core.im;
|
||||
long idx;
|
||||
|
||||
if (IS_DYNAMIC_EVENT_FLOW(ic->core.im) &&
|
||||
im->private.proto.im_onkeylist &&
|
||||
im->private.proto.im_onkeylist[0]) {
|
||||
if ((idx = _XimTriggerOnCheck(im, ev)) >= 0) {
|
||||
(void)_XimTriggerNotify(im, ic, 0, (CARD32)idx); /* Trigger on */
|
||||
return True;
|
||||
}
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimOffKeysCheck(
|
||||
Xic ic,
|
||||
XKeyEvent *ev)
|
||||
{
|
||||
Xim im = (Xim)ic->core.im;
|
||||
long idx;
|
||||
|
||||
if (IS_DYNAMIC_EVENT_FLOW(ic->core.im) &&
|
||||
im->private.proto.im_offkeylist &&
|
||||
im->private.proto.im_offkeylist[0]) {
|
||||
if ((idx = _XimTriggerOffCheck(im, ev)) >= 0) {
|
||||
_XimTriggerNotify(im, ic, 1, (CARD32)idx); /* Trigger off */
|
||||
return True;
|
||||
}
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
||||
static void
|
||||
_XimPendingFilter(
|
||||
Xic ic)
|
||||
{
|
||||
Xim im = (Xim)ic->core.im;
|
||||
|
||||
if (IS_NEED_SYNC_REPLY(im)) {
|
||||
(void)_XimProcSyncReply(im, ic);
|
||||
UNMARK_NEED_SYNC_REPLY(im);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimProtoKeypressFilter(
|
||||
Xic ic,
|
||||
XKeyEvent *ev)
|
||||
{
|
||||
Xim im = (Xim)ic->core.im;
|
||||
|
||||
if (IS_FABRICATED(im)) {
|
||||
_XimPendingFilter(ic);
|
||||
UNMARK_FABRICATED(im);
|
||||
return NOTFILTERD;
|
||||
}
|
||||
|
||||
if (IS_NEGLECT_EVENT(ic, KeyPressMask))
|
||||
return FILTERD;
|
||||
|
||||
#ifdef XIM_CONNECTABLE
|
||||
if (!IS_IC_CONNECTED(ic)) {
|
||||
if (IS_CONNECTABLE(im)) {
|
||||
if (_XimConnectServer(im)) {
|
||||
if (!_XimReCreateIC(ic)) {
|
||||
_XimDelayModeSetAttr(im);
|
||||
return NOTFILTERD;
|
||||
}
|
||||
} else {
|
||||
return NOTFILTERD;
|
||||
}
|
||||
} else {
|
||||
return NOTFILTERD;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (!IS_IC_CONNECTED(ic))
|
||||
return NOTFILTERD;
|
||||
#endif /* XIM_CONNECTABLE */
|
||||
|
||||
if (!IS_FORWARD_EVENT(ic, KeyPressMask)) {
|
||||
if (_XimOnKeysCheck(ic, ev))
|
||||
return FILTERD;
|
||||
return NOTFILTERD;
|
||||
}
|
||||
if (_XimOffKeysCheck(ic, ev))
|
||||
return FILTERD;
|
||||
|
||||
if (_XimForwardEvent(ic, (XEvent *)ev,
|
||||
IS_SYNCHRONOUS_EVENT(ic, KeyPressMask)))
|
||||
return FILTERD;
|
||||
|
||||
return NOTFILTERD;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimFilterKeypress(
|
||||
Display *d,
|
||||
Window w,
|
||||
XEvent *ev,
|
||||
XPointer client_data)
|
||||
{
|
||||
return _XimProtoKeypressFilter((Xic)client_data, (XKeyEvent *)ev );
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimProtoKeyreleaseFilter(
|
||||
Xic ic,
|
||||
XKeyEvent *ev)
|
||||
{
|
||||
Xim im = (Xim)ic->core.im;
|
||||
|
||||
if (IS_FABRICATED(im)) {
|
||||
_XimPendingFilter(ic);
|
||||
UNMARK_FABRICATED(im);
|
||||
return NOTFILTERD;
|
||||
}
|
||||
|
||||
if (IS_NEGLECT_EVENT(ic, KeyReleaseMask))
|
||||
return FILTERD;
|
||||
|
||||
#ifdef XIM_CONNECTABLE
|
||||
if (!IS_IC_CONNECTED(ic)) {
|
||||
if (IS_CONNECTABLE(im)) {
|
||||
if (_XimConnectServer(im)) {
|
||||
if (!_XimReCreateIC(ic)) {
|
||||
_XimDelayModeSetAttr(im);
|
||||
return NOTFILTERD;
|
||||
}
|
||||
} else {
|
||||
return NOTFILTERD;
|
||||
}
|
||||
} else {
|
||||
return NOTFILTERD;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (!IS_IC_CONNECTED(ic))
|
||||
return NOTFILTERD;
|
||||
#endif /* XIM_CONNECTABLE */
|
||||
|
||||
if (!IS_FORWARD_EVENT(ic, KeyReleaseMask)) {
|
||||
if (_XimOnKeysCheck(ic, ev))
|
||||
return FILTERD;
|
||||
return NOTFILTERD;
|
||||
}
|
||||
if (_XimOffKeysCheck(ic, ev))
|
||||
return FILTERD;
|
||||
|
||||
if (_XimForwardEvent(ic, (XEvent *)ev,
|
||||
IS_SYNCHRONOUS_EVENT(ic, KeyPressMask)))
|
||||
return FILTERD;
|
||||
|
||||
return NOTFILTERD;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimFilterKeyrelease(
|
||||
Display *d,
|
||||
Window w,
|
||||
XEvent *ev,
|
||||
XPointer client_data)
|
||||
{
|
||||
return _XimProtoKeyreleaseFilter((Xic)client_data, (XKeyEvent *)ev);
|
||||
}
|
||||
|
||||
static void
|
||||
_XimRegisterKeyPressFilter(
|
||||
Xic ic)
|
||||
{
|
||||
if (ic->core.focus_window) {
|
||||
if (!(ic->private.proto.registed_filter_event & KEYPRESS_MASK)) {
|
||||
_XRegisterFilterByType (ic->core.im->core.display,
|
||||
ic->core.focus_window,
|
||||
KeyPress, KeyPress,
|
||||
_XimFilterKeypress,
|
||||
(XPointer)ic);
|
||||
ic->private.proto.registed_filter_event |= KEYPRESS_MASK;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
_XimRegisterKeyReleaseFilter(
|
||||
Xic ic)
|
||||
{
|
||||
if (ic->core.focus_window) {
|
||||
if (!(ic->private.proto.registed_filter_event & KEYRELEASE_MASK)) {
|
||||
_XRegisterFilterByType (ic->core.im->core.display,
|
||||
ic->core.focus_window,
|
||||
KeyRelease, KeyRelease,
|
||||
_XimFilterKeyrelease,
|
||||
(XPointer)ic);
|
||||
ic->private.proto.registed_filter_event |= KEYRELEASE_MASK;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
_XimUnregisterKeyPressFilter(
|
||||
Xic ic)
|
||||
{
|
||||
if (ic->core.focus_window) {
|
||||
if (ic->private.proto.registed_filter_event & KEYPRESS_MASK) {
|
||||
_XUnregisterFilter (ic->core.im->core.display,
|
||||
ic->core.focus_window,
|
||||
_XimFilterKeypress,
|
||||
(XPointer)ic);
|
||||
ic->private.proto.registed_filter_event &= ~KEYPRESS_MASK;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
_XimUnregisterKeyReleaseFilter(
|
||||
Xic ic)
|
||||
{
|
||||
if (ic->core.focus_window) {
|
||||
if (ic->private.proto.registed_filter_event & KEYRELEASE_MASK) {
|
||||
_XUnregisterFilter (ic->core.im->core.display,
|
||||
ic->core.focus_window,
|
||||
_XimFilterKeyrelease,
|
||||
(XPointer)ic);
|
||||
ic->private.proto.registed_filter_event &= ~KEYRELEASE_MASK;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
_XimRegisterFilter(
|
||||
Xic ic)
|
||||
{
|
||||
_XimRegisterKeyPressFilter(ic);
|
||||
if (IS_FORWARD_EVENT(ic, KeyReleaseMask))
|
||||
_XimRegisterKeyReleaseFilter(ic);
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
_XimUnregisterFilter(
|
||||
Xic ic)
|
||||
{
|
||||
_XimUnregisterKeyPressFilter(ic);
|
||||
_XimUnregisterKeyReleaseFilter(ic);
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
_XimReregisterFilter(
|
||||
Xic ic)
|
||||
{
|
||||
if (IS_FORWARD_EVENT(ic, KeyReleaseMask))
|
||||
_XimRegisterKeyReleaseFilter(ic);
|
||||
else
|
||||
_XimUnregisterKeyReleaseFilter(ic);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimFilterServerDestroy(
|
||||
Display *d,
|
||||
Window w,
|
||||
XEvent *ev,
|
||||
XPointer client_data)
|
||||
{
|
||||
Xim im = (Xim)client_data;
|
||||
|
||||
if (ev->type == DestroyNotify) {
|
||||
UNMARK_SERVER_CONNECTED(im);
|
||||
#ifdef XIM_CONNECTABLE
|
||||
if (!IS_SERVER_CONNECTED(im) && IS_RECONNECTABLE(im)) {
|
||||
_XimServerReconectableDestroy();
|
||||
return True;
|
||||
}
|
||||
#endif /* XIM_CONNECTABLE */
|
||||
_XimServerDestroy(im);
|
||||
}
|
||||
return True;
|
||||
}
|
||||
|
||||
void
|
||||
_XimRegisterServerFilter(
|
||||
Xim im)
|
||||
{
|
||||
if (im->private.proto.im_window) {
|
||||
if (!(im->private.proto.registed_filter_event & DESTROYNOTIFY_MASK)) {
|
||||
_XRegisterFilterByMask(im->core.display,
|
||||
im->private.proto.im_window,
|
||||
StructureNotifyMask,
|
||||
_XimFilterServerDestroy,
|
||||
(XPointer)im);
|
||||
XSelectInput(im->core.display, im->private.proto.im_window,
|
||||
StructureNotifyMask);
|
||||
im->private.proto.registed_filter_event |= DESTROYNOTIFY_MASK;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
_XimUnregisterServerFilter(
|
||||
Xim im)
|
||||
{
|
||||
if (im->private.proto.im_window) {
|
||||
if (im->private.proto.registed_filter_event & DESTROYNOTIFY_MASK) {
|
||||
_XUnregisterFilter(im->core.display,
|
||||
im->private.proto.im_window,
|
||||
_XimFilterServerDestroy,
|
||||
(XPointer)im);
|
||||
im->private.proto.registed_filter_event &= ~DESTROYNOTIFY_MASK;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
1604
nx-X11/lib/modules/im/ximcp/imDefIc.c
Normal file
1604
nx-X11/lib/modules/im/ximcp/imDefIc.c
Normal file
File diff suppressed because it is too large
Load Diff
2047
nx-X11/lib/modules/im/ximcp/imDefIm.c
Normal file
2047
nx-X11/lib/modules/im/ximcp/imDefIm.c
Normal file
File diff suppressed because it is too large
Load Diff
1178
nx-X11/lib/modules/im/ximcp/imDefLkup.c
Normal file
1178
nx-X11/lib/modules/im/ximcp/imDefLkup.c
Normal file
File diff suppressed because it is too large
Load Diff
104
nx-X11/lib/modules/im/ximcp/imDispch.c
Normal file
104
nx-X11/lib/modules/im/ximcp/imDispch.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1993, 1994 by FUJITSU LIMITED
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and
|
||||
that both that copyright notice and this permission notice appear
|
||||
in supporting documentation, and that the name of FUJITSU LIMITED
|
||||
not be used in advertising or publicity pertaining to distribution
|
||||
of the software without specific, written prior permission.
|
||||
FUJITSU LIMITED makes no representations about the suitability of
|
||||
this software for any purpose.
|
||||
It is provided "as is" without express or implied warranty.
|
||||
|
||||
FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Author: Takashi Fujiwara FUJITSU LIMITED
|
||||
fujiwara@a80.tech.yk.fujitsu.co.jp
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <nx-X11/Xlib.h>
|
||||
#include "Xlibint.h"
|
||||
#include "Xutil.h"
|
||||
#include "Xlcint.h"
|
||||
#include "Ximint.h"
|
||||
|
||||
|
||||
Bool
|
||||
_XimRegProtoIntrCallback(
|
||||
Xim im,
|
||||
CARD16 major_code,
|
||||
CARD16 minor_code,
|
||||
Bool (*proc)(
|
||||
Xim, INT16, XPointer, XPointer
|
||||
),
|
||||
|
||||
XPointer call_data)
|
||||
{
|
||||
XimProtoIntrRec *rec;
|
||||
|
||||
if (!(rec = Xmalloc(sizeof(XimProtoIntrRec))))
|
||||
return False;
|
||||
rec->func = proc;
|
||||
rec->major_code = major_code;
|
||||
rec->minor_code = minor_code;
|
||||
rec->call_data = call_data;
|
||||
rec->next = im->private.proto.intrproto;
|
||||
im->private.proto.intrproto = rec;
|
||||
return True;
|
||||
}
|
||||
|
||||
void
|
||||
_XimFreeProtoIntrCallback(Xim im)
|
||||
{
|
||||
register XimProtoIntrRec *rec, *next;
|
||||
|
||||
for (rec = im->private.proto.intrproto; rec;) {
|
||||
next = rec->next;
|
||||
Xfree(rec);
|
||||
rec = next;
|
||||
}
|
||||
im->private.proto.intrproto = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimTransportIntr(
|
||||
Xim im,
|
||||
INT16 len,
|
||||
XPointer data,
|
||||
XPointer call_data)
|
||||
{
|
||||
Xim call_im = (Xim)call_data;
|
||||
XimProtoIntrRec *rec = call_im->private.proto.intrproto;
|
||||
CARD8 major_opcode = *((CARD8 *)data);
|
||||
CARD8 minor_opcode = *((CARD8 *)data + 1);
|
||||
|
||||
for (; rec; rec = rec->next) {
|
||||
if ((major_opcode == (CARD8)rec->major_code)
|
||||
&& (minor_opcode == (CARD8)rec->minor_code))
|
||||
if ((*rec->func)(call_im, len, data, rec->call_data))
|
||||
return True;
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
||||
Bool
|
||||
_XimDispatchInit(Xim im)
|
||||
{
|
||||
if (_XimRegisterDispatcher(im, _XimTransportIntr, (XPointer)im))
|
||||
return True;
|
||||
return False;
|
||||
}
|
||||
788
nx-X11/lib/modules/im/ximcp/imEvToWire.c
Normal file
788
nx-X11/lib/modules/im/ximcp/imEvToWire.c
Normal file
@@ -0,0 +1,788 @@
|
||||
/***********************************************************
|
||||
Copyright 1993 by Digital Equipment Corporation, Maynard, Massachusetts,
|
||||
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee is hereby granted,
|
||||
provided that the above copyright notice appear in all copies and that
|
||||
both that copyright notice and this permission notice appear in
|
||||
supporting documentation, and that the name of Digital not be
|
||||
used in advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
||||
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
SOFTWARE.
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <nx-X11/Xlibint.h>
|
||||
#include <nx-X11/Xlib.h>
|
||||
#include "Ximint.h"
|
||||
|
||||
|
||||
#define sw16(n, s) ((s) ? \
|
||||
(((n) << 8 & 0xff00) | \
|
||||
((n) >> 8 & 0xff) \
|
||||
) : n)
|
||||
|
||||
#define sw32(n, s) ((s) ? \
|
||||
(((n) << 24 & 0xff000000) | \
|
||||
((n) << 8 & 0xff0000) | \
|
||||
((n) >> 8 & 0xff00) | \
|
||||
((n) >> 24 & 0xff) \
|
||||
) : n)
|
||||
|
||||
Status
|
||||
_XimProtoEventToWire(
|
||||
register XEvent *re, /* pointer to where event should be reformatted */
|
||||
register xEvent *event, /* wire protocol event */
|
||||
Bool sw) /* swap byte? */
|
||||
{
|
||||
switch (event->u.u.type = re->type) {
|
||||
case KeyPress:
|
||||
case KeyRelease:
|
||||
{
|
||||
register XKeyEvent *ev = (XKeyEvent*) re;
|
||||
event->u.keyButtonPointer.root = sw32(ev->root, sw);
|
||||
event->u.keyButtonPointer.event =
|
||||
sw32(ev->window, sw);
|
||||
event->u.keyButtonPointer.child =
|
||||
sw32(ev->subwindow, sw);
|
||||
event->u.keyButtonPointer.time = sw32(ev->time, sw);
|
||||
event->u.keyButtonPointer.eventX = sw16(ev->x, sw) ;
|
||||
event->u.keyButtonPointer.eventY = sw16(ev->y, sw) ;
|
||||
event->u.keyButtonPointer.rootX =
|
||||
sw16(ev->x_root, sw);
|
||||
event->u.keyButtonPointer.rootY =
|
||||
sw16(ev->y_root, sw);
|
||||
event->u.keyButtonPointer.state = sw16(ev->state, sw);
|
||||
event->u.keyButtonPointer.sameScreen = ev->same_screen;
|
||||
event->u.u.detail = ev->keycode;
|
||||
}
|
||||
break;
|
||||
case ButtonPress:
|
||||
case ButtonRelease:
|
||||
{
|
||||
register XButtonEvent *ev = (XButtonEvent *) re;
|
||||
event->u.keyButtonPointer.root = sw32(ev->root, sw);
|
||||
event->u.keyButtonPointer.event = sw32(ev->window, sw);
|
||||
event->u.keyButtonPointer.child = sw32(ev->subwindow, sw);
|
||||
event->u.keyButtonPointer.time = sw32(ev->time, sw);
|
||||
event->u.keyButtonPointer.eventX = sw16(ev->x, sw);
|
||||
event->u.keyButtonPointer.eventY = sw16(ev->y, sw);
|
||||
event->u.keyButtonPointer.rootX = sw16(ev->x_root, sw);
|
||||
event->u.keyButtonPointer.rootY = sw16(ev->y_root, sw);
|
||||
event->u.keyButtonPointer.state = sw16(ev->state, sw);
|
||||
event->u.keyButtonPointer.sameScreen = ev->same_screen;
|
||||
event->u.u.detail = ev->button;
|
||||
}
|
||||
break;
|
||||
case MotionNotify:
|
||||
{
|
||||
register XMotionEvent *ev = (XMotionEvent *)re;
|
||||
event->u.keyButtonPointer.root = sw32(ev->root, sw);
|
||||
event->u.keyButtonPointer.event = sw32(ev->window, sw);
|
||||
event->u.keyButtonPointer.child = sw32(ev->subwindow, sw);
|
||||
event->u.keyButtonPointer.time = sw32(ev->time, sw);
|
||||
event->u.keyButtonPointer.eventX= sw16(ev->x, sw);
|
||||
event->u.keyButtonPointer.eventY= sw16(ev->y, sw);
|
||||
event->u.keyButtonPointer.rootX = sw16(ev->x_root, sw);
|
||||
event->u.keyButtonPointer.rootY = sw16(ev->y_root, sw);
|
||||
event->u.keyButtonPointer.state = sw16(ev->state, sw);
|
||||
event->u.keyButtonPointer.sameScreen= ev->same_screen;
|
||||
event->u.u.detail = ev->is_hint;
|
||||
}
|
||||
break;
|
||||
case EnterNotify:
|
||||
case LeaveNotify:
|
||||
{
|
||||
register XCrossingEvent *ev = (XCrossingEvent *) re;
|
||||
event->u.enterLeave.root = sw32(ev->root, sw);
|
||||
event->u.enterLeave.event = sw32(ev->window, sw);
|
||||
event->u.enterLeave.child = sw32(ev->subwindow, sw);
|
||||
event->u.enterLeave.time = sw32(ev->time, sw);
|
||||
event->u.enterLeave.eventX = sw16(ev->x, sw);
|
||||
event->u.enterLeave.eventY = sw16(ev->y, sw);
|
||||
event->u.enterLeave.rootX = sw16(ev->x_root, sw);
|
||||
event->u.enterLeave.rootY = sw16(ev->y_root, sw);
|
||||
event->u.enterLeave.state = sw16(ev->state, sw);
|
||||
event->u.enterLeave.mode = ev->mode;
|
||||
event->u.enterLeave.flags = 0;
|
||||
if (ev->same_screen) {
|
||||
event->u.enterLeave.flags |= ELFlagSameScreen;
|
||||
}
|
||||
if (ev->focus) {
|
||||
event->u.enterLeave.flags |= ELFlagFocus;
|
||||
}
|
||||
event->u.u.detail = ev->detail;
|
||||
}
|
||||
break;
|
||||
case FocusIn:
|
||||
case FocusOut:
|
||||
{
|
||||
register XFocusChangeEvent *ev = (XFocusChangeEvent *) re;
|
||||
event->u.focus.window = sw32(ev->window, sw);
|
||||
event->u.focus.mode = ev->mode;
|
||||
event->u.u.detail = ev->detail;
|
||||
}
|
||||
break;
|
||||
case KeymapNotify:
|
||||
{
|
||||
register XKeymapEvent *ev = (XKeymapEvent *) re;
|
||||
memcpy((char *)(((xKeymapEvent *) event)->map),
|
||||
&ev->key_vector[1],
|
||||
sizeof (((xKeymapEvent *) event)->map));
|
||||
}
|
||||
break;
|
||||
case Expose:
|
||||
{
|
||||
register XExposeEvent *ev = (XExposeEvent *) re;
|
||||
event->u.expose.window = sw32(ev->window, sw);
|
||||
event->u.expose.x = sw16(ev->x, sw);
|
||||
event->u.expose.y = sw16(ev->y, sw);
|
||||
event->u.expose.width = sw16(ev->width, sw);
|
||||
event->u.expose.height = sw16(ev->height, sw);
|
||||
event->u.expose.count = sw16(ev->count, sw);
|
||||
}
|
||||
break;
|
||||
case GraphicsExpose:
|
||||
{
|
||||
register XGraphicsExposeEvent *ev =
|
||||
(XGraphicsExposeEvent *) re;
|
||||
event->u.graphicsExposure.drawable = sw32(ev->drawable, sw);
|
||||
event->u.graphicsExposure.x = sw16(ev->x, sw);
|
||||
event->u.graphicsExposure.y = sw16(ev->y, sw);
|
||||
event->u.graphicsExposure.width = sw16(ev->width, sw);
|
||||
event->u.graphicsExposure.height = sw16(ev->height, sw);
|
||||
event->u.graphicsExposure.count = sw16(ev->count, sw);
|
||||
event->u.graphicsExposure.majorEvent= ev->major_code;
|
||||
event->u.graphicsExposure.minorEvent= sw16(ev->minor_code, sw);
|
||||
}
|
||||
break;
|
||||
case NoExpose:
|
||||
{
|
||||
register XNoExposeEvent *ev = (XNoExposeEvent *) re;
|
||||
event->u.noExposure.drawable = sw32(ev->drawable, sw);
|
||||
event->u.noExposure.majorEvent = ev->major_code;
|
||||
event->u.noExposure.minorEvent = sw16(ev->minor_code, sw);
|
||||
}
|
||||
break;
|
||||
case VisibilityNotify:
|
||||
{
|
||||
register XVisibilityEvent *ev = (XVisibilityEvent *) re;
|
||||
event->u.visibility.window = sw32(ev->window, sw);
|
||||
event->u.visibility.state = ev->state;
|
||||
}
|
||||
break;
|
||||
case CreateNotify:
|
||||
{
|
||||
register XCreateWindowEvent *ev =
|
||||
(XCreateWindowEvent *) re;
|
||||
event->u.createNotify.window = sw32(ev->window, sw);
|
||||
event->u.createNotify.parent = sw32(ev->parent, sw);
|
||||
event->u.createNotify.x = sw16(ev->x, sw);
|
||||
event->u.createNotify.y = sw16(ev->y, sw);
|
||||
event->u.createNotify.width = sw16(ev->width, sw);
|
||||
event->u.createNotify.height = sw16(ev->height, sw);
|
||||
event->u.createNotify.borderWidth = sw16(ev->border_width, sw);
|
||||
event->u.createNotify.override = ev->override_redirect;
|
||||
}
|
||||
break;
|
||||
case DestroyNotify:
|
||||
{
|
||||
register XDestroyWindowEvent *ev =
|
||||
(XDestroyWindowEvent *) re;
|
||||
event->u.destroyNotify.window = sw32(ev->window, sw);
|
||||
event->u.destroyNotify.event = sw32(ev->event, sw);
|
||||
}
|
||||
break;
|
||||
case UnmapNotify:
|
||||
{
|
||||
register XUnmapEvent *ev = (XUnmapEvent *) re;
|
||||
event->u.unmapNotify.window = sw32(ev->window, sw);
|
||||
event->u.unmapNotify.event = sw32(ev->event, sw);
|
||||
event->u.unmapNotify.fromConfigure = ev->from_configure;
|
||||
}
|
||||
break;
|
||||
case MapNotify:
|
||||
{
|
||||
register XMapEvent *ev = (XMapEvent *) re;
|
||||
event->u.mapNotify.window = sw32(ev->window, sw);
|
||||
event->u.mapNotify.event = sw32(ev->event, sw);
|
||||
event->u.mapNotify.override = ev->override_redirect;
|
||||
}
|
||||
break;
|
||||
case MapRequest:
|
||||
{
|
||||
register XMapRequestEvent *ev = (XMapRequestEvent *) re;
|
||||
event->u.mapRequest.window = sw32(ev->window, sw);
|
||||
event->u.mapRequest.parent = sw32(ev->parent, sw);
|
||||
}
|
||||
break;
|
||||
case ReparentNotify:
|
||||
{
|
||||
register XReparentEvent *ev = (XReparentEvent *) re;
|
||||
event->u.reparent.window = sw32(ev->window, sw);
|
||||
event->u.reparent.event = sw32(ev->event, sw);
|
||||
event->u.reparent.parent = sw32(ev->parent, sw);
|
||||
event->u.reparent.x = sw16(ev->x, sw);
|
||||
event->u.reparent.y = sw16(ev->y, sw);
|
||||
event->u.reparent.override = ev->override_redirect;
|
||||
}
|
||||
break;
|
||||
case ConfigureNotify:
|
||||
{
|
||||
register XConfigureEvent *ev = (XConfigureEvent *) re;
|
||||
event->u.configureNotify.window = sw32(ev->window, sw);
|
||||
event->u.configureNotify.event = sw32(ev->event, sw);
|
||||
event->u.configureNotify.aboveSibling = sw32(ev->above, sw);
|
||||
event->u.configureNotify.x = sw16(ev->x, sw);
|
||||
event->u.configureNotify.y = sw16(ev->y, sw);
|
||||
event->u.configureNotify.width = sw16(ev->width, sw);
|
||||
event->u.configureNotify.height = sw16(ev->height, sw);
|
||||
event->u.configureNotify.borderWidth= sw16(ev->border_width, sw);
|
||||
event->u.configureNotify.override = ev->override_redirect;
|
||||
}
|
||||
break;
|
||||
case ConfigureRequest:
|
||||
{
|
||||
register XConfigureRequestEvent *ev =
|
||||
(XConfigureRequestEvent *) re;
|
||||
event->u.configureRequest.window = sw32(ev->window, sw);
|
||||
event->u.configureRequest.parent = sw32(ev->parent, sw);
|
||||
event->u.configureRequest.sibling = sw32(ev->above, sw);
|
||||
event->u.configureRequest.x = sw16(ev->x, sw);
|
||||
event->u.configureRequest.y = sw16(ev->y, sw);
|
||||
event->u.configureRequest.width = sw16(ev->width, sw);
|
||||
event->u.configureRequest.height = sw16(ev->height, sw);
|
||||
event->u.configureRequest.borderWidth= sw16(ev->border_width, sw);
|
||||
event->u.configureRequest.valueMask= sw16(ev->value_mask, sw);
|
||||
event->u.u.detail = ev->detail;
|
||||
}
|
||||
break;
|
||||
case GravityNotify:
|
||||
{
|
||||
register XGravityEvent *ev = (XGravityEvent *) re;
|
||||
event->u.gravity.window = sw32(ev->window, sw);
|
||||
event->u.gravity.event = sw32(ev->event, sw);
|
||||
event->u.gravity.x = sw16(ev->x, sw);
|
||||
event->u.gravity.y = sw16(ev->y, sw);
|
||||
}
|
||||
break;
|
||||
case ResizeRequest:
|
||||
{
|
||||
register XResizeRequestEvent *ev =
|
||||
(XResizeRequestEvent *) re;
|
||||
event->u.resizeRequest.window = sw32(ev->window, sw);
|
||||
event->u.resizeRequest.width = sw16(ev->width, sw);
|
||||
event->u.resizeRequest.height = sw16(ev->height, sw);
|
||||
}
|
||||
break;
|
||||
case CirculateNotify:
|
||||
{
|
||||
register XCirculateEvent *ev = (XCirculateEvent *) re;
|
||||
event->u.circulate.window = sw32(ev->window, sw);
|
||||
event->u.circulate.event = sw32(ev->event, sw);
|
||||
event->u.circulate.place = ev->place;
|
||||
}
|
||||
break;
|
||||
case CirculateRequest:
|
||||
{
|
||||
register XCirculateRequestEvent *ev =
|
||||
(XCirculateRequestEvent *) re;
|
||||
event->u.circulate.window = sw32(ev->window, sw);
|
||||
event->u.circulate.event = sw32(ev->parent, sw);
|
||||
event->u.circulate.place = ev->place;
|
||||
}
|
||||
break;
|
||||
case PropertyNotify:
|
||||
{
|
||||
register XPropertyEvent *ev = (XPropertyEvent *) re;
|
||||
event->u.property.window = sw32(ev->window, sw);
|
||||
event->u.property.atom = sw32(ev->atom, sw);
|
||||
event->u.property.time = sw32(ev->time, sw);
|
||||
event->u.property.state = ev->state;
|
||||
}
|
||||
break;
|
||||
case SelectionClear:
|
||||
{
|
||||
register XSelectionClearEvent *ev =
|
||||
(XSelectionClearEvent *) re;
|
||||
event->u.selectionClear.window = sw32(ev->window, sw);
|
||||
event->u.selectionClear.atom = sw32(ev->selection, sw);
|
||||
event->u.selectionClear.time = sw32(ev->time, sw);
|
||||
}
|
||||
break;
|
||||
case SelectionRequest:
|
||||
{
|
||||
register XSelectionRequestEvent *ev =
|
||||
(XSelectionRequestEvent *) re;
|
||||
event->u.selectionRequest.owner = sw32(ev->owner, sw);
|
||||
event->u.selectionRequest.requestor = sw32(ev->requestor, sw);
|
||||
event->u.selectionRequest.selection = sw32(ev->selection, sw);
|
||||
event->u.selectionRequest.target = sw32(ev->target, sw);
|
||||
event->u.selectionRequest.property = sw32(ev->property, sw);
|
||||
event->u.selectionRequest.time = sw32(ev->time, sw);
|
||||
}
|
||||
break;
|
||||
case SelectionNotify:
|
||||
{
|
||||
register XSelectionEvent *ev = (XSelectionEvent *) re;
|
||||
event->u.selectionNotify.requestor = sw32(ev->requestor, sw);
|
||||
event->u.selectionNotify.selection = sw32(ev->selection, sw);
|
||||
event->u.selectionNotify.target = sw32(ev->target, sw);
|
||||
event->u.selectionNotify.property = sw32(ev->property, sw);
|
||||
event->u.selectionNotify.time = sw32(ev->time, sw);
|
||||
}
|
||||
break;
|
||||
case ColormapNotify:
|
||||
{
|
||||
register XColormapEvent *ev = (XColormapEvent *) re;
|
||||
event->u.colormap.window = sw32(ev->window, sw);
|
||||
event->u.colormap.colormap = sw32(ev->colormap, sw);
|
||||
event->u.colormap.new = ev->new;
|
||||
event->u.colormap.state = ev->state;
|
||||
}
|
||||
break;
|
||||
case ClientMessage:
|
||||
{
|
||||
register int i;
|
||||
register XClientMessageEvent *ev
|
||||
= (XClientMessageEvent *) re;
|
||||
event->u.clientMessage.window = sw32(ev->window, sw);
|
||||
event->u.u.detail = ev->format;
|
||||
switch (ev->format) {
|
||||
case 8:
|
||||
event->u.clientMessage.u.b.type = sw32(ev->message_type, sw);
|
||||
for (i = 0; i < 20; i++)
|
||||
event->u.clientMessage.u.b.bytes[i] = ev->data.b[i];
|
||||
break;
|
||||
case 16:
|
||||
event->u.clientMessage.u.s.type = sw32(ev->message_type, sw);
|
||||
event->u.clientMessage.u.s.shorts0 = sw16(ev->data.s[0], sw);
|
||||
event->u.clientMessage.u.s.shorts1 = sw16(ev->data.s[1], sw);
|
||||
event->u.clientMessage.u.s.shorts2 = sw16(ev->data.s[2], sw);
|
||||
event->u.clientMessage.u.s.shorts3 = sw16(ev->data.s[3], sw);
|
||||
event->u.clientMessage.u.s.shorts4 = sw16(ev->data.s[4], sw);
|
||||
event->u.clientMessage.u.s.shorts5 = sw16(ev->data.s[5], sw);
|
||||
event->u.clientMessage.u.s.shorts6 = sw16(ev->data.s[6], sw);
|
||||
event->u.clientMessage.u.s.shorts7 = sw16(ev->data.s[7], sw);
|
||||
event->u.clientMessage.u.s.shorts8 = sw16(ev->data.s[8], sw);
|
||||
event->u.clientMessage.u.s.shorts9 = sw16(ev->data.s[9], sw);
|
||||
break;
|
||||
case 32:
|
||||
event->u.clientMessage.u.l.type = sw32(ev->message_type, sw);
|
||||
event->u.clientMessage.u.l.longs0 = sw32(ev->data.l[0], sw);
|
||||
event->u.clientMessage.u.l.longs1 = sw32(ev->data.l[1], sw);
|
||||
event->u.clientMessage.u.l.longs2 = sw32(ev->data.l[2], sw);
|
||||
event->u.clientMessage.u.l.longs3 = sw32(ev->data.l[3], sw);
|
||||
event->u.clientMessage.u.l.longs4 = sw32(ev->data.l[4], sw);
|
||||
break;
|
||||
default:
|
||||
/* client passing bogus data, let server complain */
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MappingNotify:
|
||||
{
|
||||
register XMappingEvent *ev = (XMappingEvent *) re;
|
||||
event->u.mappingNotify.firstKeyCode = ev->first_keycode;
|
||||
event->u.mappingNotify.request = ev->request;
|
||||
event->u.mappingNotify.count = ev->count;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return(0);
|
||||
}
|
||||
/* Common process */
|
||||
if (((XAnyEvent *)re)->send_event)
|
||||
event->u.u.type |= 0x80;
|
||||
event->u.u.sequenceNumber =
|
||||
((XAnyEvent *)re)->serial & ~((unsigned long)0xffff);
|
||||
event->u.u.sequenceNumber = sw16(event->u.u.sequenceNumber, sw);
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* reformat a wire event into an XEvent structure of the right type.
|
||||
*/
|
||||
Bool
|
||||
_XimProtoWireToEvent(
|
||||
register XEvent *re, /* pointer to where event should be reformatted */
|
||||
register xEvent *event, /* wire protocol event */
|
||||
Bool sw) /* swap byte? */
|
||||
{
|
||||
|
||||
re->type = event->u.u.type & 0x7f;
|
||||
((XAnyEvent *)re)->serial = sw16(event->u.u.sequenceNumber, sw);
|
||||
((XAnyEvent *)re)->send_event = ((event->u.u.type & 0x80) != 0);
|
||||
((XAnyEvent *)re)->display = NULL;
|
||||
|
||||
/* Ignore the leading bit of the event type since it is set when a
|
||||
client sends an event rather than the server. */
|
||||
|
||||
switch (event-> u.u.type & 0177) {
|
||||
case KeyPress:
|
||||
case KeyRelease:
|
||||
{
|
||||
register XKeyEvent *ev = (XKeyEvent*) re;
|
||||
ev->root = sw32(event->u.keyButtonPointer.root, sw);
|
||||
ev->window = sw32(event->u.keyButtonPointer.event, sw);
|
||||
ev->subwindow = sw32(event->u.keyButtonPointer.child, sw);
|
||||
ev->time = sw32(event->u.keyButtonPointer.time, sw);
|
||||
ev->x = cvtINT16toInt(sw16(event->u.keyButtonPointer.eventX, sw));
|
||||
ev->y = cvtINT16toInt(sw16(event->u.keyButtonPointer.eventY, sw));
|
||||
ev->x_root = cvtINT16toInt(sw16(event->u.keyButtonPointer.rootX, sw));
|
||||
ev->y_root = cvtINT16toInt(sw16(event->u.keyButtonPointer.rootY, sw));
|
||||
ev->state = sw16(event->u.keyButtonPointer.state, sw);
|
||||
ev->same_screen = event->u.keyButtonPointer.sameScreen;
|
||||
ev->keycode = event->u.u.detail;
|
||||
}
|
||||
break;
|
||||
case ButtonPress:
|
||||
case ButtonRelease:
|
||||
{
|
||||
register XButtonEvent *ev = (XButtonEvent *) re;
|
||||
ev->root = sw32(event->u.keyButtonPointer.root, sw);
|
||||
ev->window = sw32(event->u.keyButtonPointer.event, sw);
|
||||
ev->subwindow = sw32(event->u.keyButtonPointer.child, sw);
|
||||
ev->time = sw32(event->u.keyButtonPointer.time, sw);
|
||||
ev->x = cvtINT16toInt(sw16(event->u.keyButtonPointer.eventX, sw));
|
||||
ev->y = cvtINT16toInt(sw16(event->u.keyButtonPointer.eventY, sw));
|
||||
ev->x_root = cvtINT16toInt(sw16(event->u.keyButtonPointer.rootX, sw));
|
||||
ev->y_root = cvtINT16toInt(sw16(event->u.keyButtonPointer.rootY, sw));
|
||||
ev->state = sw16(event->u.keyButtonPointer.state, sw);
|
||||
ev->same_screen = event->u.keyButtonPointer.sameScreen;
|
||||
ev->button = event->u.u.detail;
|
||||
}
|
||||
break;
|
||||
case MotionNotify:
|
||||
{
|
||||
register XMotionEvent *ev = (XMotionEvent *)re;
|
||||
ev->root = sw32(event->u.keyButtonPointer.root, sw);
|
||||
ev->window = sw32(event->u.keyButtonPointer.event, sw);
|
||||
ev->subwindow = sw32(event->u.keyButtonPointer.child, sw);
|
||||
ev->time = sw32(event->u.keyButtonPointer.time, sw);
|
||||
ev->x = cvtINT16toInt(sw16(event->u.keyButtonPointer.eventX, sw));
|
||||
ev->y = cvtINT16toInt(sw16(event->u.keyButtonPointer.eventY, sw));
|
||||
ev->x_root = cvtINT16toInt(sw16(event->u.keyButtonPointer.rootX, sw));
|
||||
ev->y_root = cvtINT16toInt(sw16(event->u.keyButtonPointer.rootY, sw));
|
||||
ev->state = sw16(event->u.keyButtonPointer.state, sw);
|
||||
ev->same_screen = event->u.keyButtonPointer.sameScreen;
|
||||
ev->is_hint = event->u.u.detail;
|
||||
}
|
||||
break;
|
||||
case EnterNotify:
|
||||
case LeaveNotify:
|
||||
{
|
||||
register XCrossingEvent *ev = (XCrossingEvent *) re;
|
||||
ev->root = sw32(event->u.enterLeave.root, sw);
|
||||
ev->window = sw32(event->u.enterLeave.event, sw);
|
||||
ev->subwindow = sw32(event->u.enterLeave.child, sw);
|
||||
ev->time = sw32(event->u.enterLeave.time, sw);
|
||||
ev->x = cvtINT16toInt(sw16(event->u.enterLeave.eventX, sw));
|
||||
ev->y = cvtINT16toInt(sw16(event->u.enterLeave.eventY, sw));
|
||||
ev->x_root = cvtINT16toInt(sw16(event->u.enterLeave.rootX, sw));
|
||||
ev->y_root = cvtINT16toInt(sw16(event->u.enterLeave.rootY, sw));
|
||||
ev->state = sw16(event->u.enterLeave.state, sw);
|
||||
ev->mode = event->u.enterLeave.mode;
|
||||
ev->same_screen = (event->u.enterLeave.flags &
|
||||
ELFlagSameScreen) && True;
|
||||
ev->focus = (event->u.enterLeave.flags &
|
||||
ELFlagFocus) && True;
|
||||
ev->detail = event->u.u.detail;
|
||||
}
|
||||
break;
|
||||
case FocusIn:
|
||||
case FocusOut:
|
||||
{
|
||||
register XFocusChangeEvent *ev = (XFocusChangeEvent *) re;
|
||||
ev->window = sw32(event->u.focus.window, sw);
|
||||
ev->mode = event->u.focus.mode;
|
||||
ev->detail = event->u.u.detail;
|
||||
}
|
||||
break;
|
||||
case KeymapNotify:
|
||||
{
|
||||
register XKeymapEvent *ev = (XKeymapEvent *) re;
|
||||
ev->window = None;
|
||||
memcpy(&ev->key_vector[1],
|
||||
(char *)((xKeymapEvent *) event)->map,
|
||||
sizeof (((xKeymapEvent *) event)->map));
|
||||
}
|
||||
break;
|
||||
case Expose:
|
||||
{
|
||||
register XExposeEvent *ev = (XExposeEvent *) re;
|
||||
ev->window = sw32(event->u.expose.window, sw);
|
||||
ev->x = sw16(event->u.expose.x, sw);
|
||||
ev->y = sw16(event->u.expose.y, sw);
|
||||
ev->width = sw16(event->u.expose.width, sw);
|
||||
ev->height = sw16(event->u.expose.height, sw);
|
||||
ev->count = sw16(event->u.expose.count, sw);
|
||||
}
|
||||
break;
|
||||
case GraphicsExpose:
|
||||
{
|
||||
register XGraphicsExposeEvent *ev =
|
||||
(XGraphicsExposeEvent *) re;
|
||||
ev->drawable = sw32(event->u.graphicsExposure.drawable, sw);
|
||||
ev->x = sw16(event->u.graphicsExposure.x, sw);
|
||||
ev->y = sw16(event->u.graphicsExposure.y, sw);
|
||||
ev->width = sw16(event->u.graphicsExposure.width, sw);
|
||||
ev->height = sw16(event->u.graphicsExposure.height, sw);
|
||||
ev->count = sw16(event->u.graphicsExposure.count, sw);
|
||||
ev->major_code = event->u.graphicsExposure.majorEvent;
|
||||
ev->minor_code = sw16(event->u.graphicsExposure.minorEvent, sw);
|
||||
}
|
||||
break;
|
||||
case NoExpose:
|
||||
{
|
||||
register XNoExposeEvent *ev = (XNoExposeEvent *) re;
|
||||
ev->drawable = sw32(event->u.noExposure.drawable, sw);
|
||||
ev->major_code = event->u.noExposure.majorEvent;
|
||||
ev->minor_code = sw16(event->u.noExposure.minorEvent, sw);
|
||||
}
|
||||
break;
|
||||
case VisibilityNotify:
|
||||
{
|
||||
register XVisibilityEvent *ev = (XVisibilityEvent *) re;
|
||||
ev->window = sw32(event->u.visibility.window, sw);
|
||||
ev->state = event->u.visibility.state;
|
||||
}
|
||||
break;
|
||||
case CreateNotify:
|
||||
{
|
||||
register XCreateWindowEvent *ev =
|
||||
(XCreateWindowEvent *) re;
|
||||
ev->window = sw32(event->u.createNotify.window, sw);
|
||||
ev->parent = sw32(event->u.createNotify.parent, sw);
|
||||
ev->x = cvtINT16toInt(sw16(event->u.createNotify.x, sw));
|
||||
ev->y = cvtINT16toInt(sw16(event->u.createNotify.y, sw));
|
||||
ev->width = sw16(event->u.createNotify.width, sw);
|
||||
ev->height = sw16(event->u.createNotify.height, sw);
|
||||
ev->border_width = sw16(event->u.createNotify.borderWidth, sw);
|
||||
ev->override_redirect = event->u.createNotify.override;
|
||||
}
|
||||
break;
|
||||
case DestroyNotify:
|
||||
{
|
||||
register XDestroyWindowEvent *ev =
|
||||
(XDestroyWindowEvent *) re;
|
||||
ev->window = sw32(event->u.destroyNotify.window, sw);
|
||||
ev->event = sw32(event->u.destroyNotify.event, sw);
|
||||
}
|
||||
break;
|
||||
case UnmapNotify:
|
||||
{
|
||||
register XUnmapEvent *ev = (XUnmapEvent *) re;
|
||||
ev->window = sw32(event->u.unmapNotify.window, sw);
|
||||
ev->event = sw32(event->u.unmapNotify.event, sw);
|
||||
ev->from_configure = event->u.unmapNotify.fromConfigure;
|
||||
}
|
||||
break;
|
||||
case MapNotify:
|
||||
{
|
||||
register XMapEvent *ev = (XMapEvent *) re;
|
||||
ev->window = sw32(event->u.mapNotify.window, sw);
|
||||
ev->event = sw32(event->u.mapNotify.event, sw);
|
||||
ev->override_redirect = event->u.mapNotify.override;
|
||||
}
|
||||
break;
|
||||
case MapRequest:
|
||||
{
|
||||
register XMapRequestEvent *ev = (XMapRequestEvent *) re;
|
||||
ev->window = sw32(event->u.mapRequest.window, sw);
|
||||
ev->parent = sw32(event->u.mapRequest.parent, sw);
|
||||
}
|
||||
break;
|
||||
case ReparentNotify:
|
||||
{
|
||||
register XReparentEvent *ev = (XReparentEvent *) re;
|
||||
ev->event = sw32(event->u.reparent.event, sw);
|
||||
ev->window = sw32(event->u.reparent.window, sw);
|
||||
ev->parent = sw32(event->u.reparent.parent, sw);
|
||||
ev->x = cvtINT16toInt(sw16(event->u.reparent.x, sw));
|
||||
ev->y = cvtINT16toInt(sw16(event->u.reparent.y, sw));
|
||||
ev->override_redirect = event->u.reparent.override;
|
||||
}
|
||||
break;
|
||||
case ConfigureNotify:
|
||||
{
|
||||
register XConfigureEvent *ev = (XConfigureEvent *) re;
|
||||
ev->event = sw32(event->u.configureNotify.event, sw);
|
||||
ev->window = sw32(event->u.configureNotify.window, sw);
|
||||
ev->above = sw32(event->u.configureNotify.aboveSibling, sw);
|
||||
ev->x = cvtINT16toInt(sw16(event->u.configureNotify.x, sw));
|
||||
ev->y = cvtINT16toInt(sw16(event->u.configureNotify.y, sw));
|
||||
ev->width = sw16(event->u.configureNotify.width, sw);
|
||||
ev->height = sw16(event->u.configureNotify.height, sw);
|
||||
ev->border_width = sw16(event->u.configureNotify.borderWidth, sw);
|
||||
ev->override_redirect = event->u.configureNotify.override;
|
||||
}
|
||||
break;
|
||||
case ConfigureRequest:
|
||||
{
|
||||
register XConfigureRequestEvent *ev =
|
||||
(XConfigureRequestEvent *) re;
|
||||
ev->window = sw32(event->u.configureRequest.window, sw);
|
||||
ev->parent = sw32(event->u.configureRequest.parent, sw);
|
||||
ev->above = sw32(event->u.configureRequest.sibling, sw);
|
||||
ev->x = cvtINT16toInt(sw16(event->u.configureRequest.x, sw));
|
||||
ev->y = cvtINT16toInt(sw16(event->u.configureRequest.y, sw));
|
||||
ev->width = sw16(event->u.configureRequest.width, sw);
|
||||
ev->height = sw16(event->u.configureRequest.height, sw);
|
||||
ev->border_width = sw16(event->u.configureRequest.borderWidth, sw);
|
||||
ev->value_mask = sw16(event->u.configureRequest.valueMask, sw);
|
||||
ev->detail = event->u.u.detail;
|
||||
}
|
||||
break;
|
||||
case GravityNotify:
|
||||
{
|
||||
register XGravityEvent *ev = (XGravityEvent *) re;
|
||||
ev->window = sw32(event->u.gravity.window, sw);
|
||||
ev->event = sw32(event->u.gravity.event, sw);
|
||||
ev->x = cvtINT16toInt(sw16(event->u.gravity.x, sw));
|
||||
ev->y = cvtINT16toInt(sw16(event->u.gravity.y, sw));
|
||||
}
|
||||
break;
|
||||
case ResizeRequest:
|
||||
{
|
||||
register XResizeRequestEvent *ev =
|
||||
(XResizeRequestEvent *) re;
|
||||
ev->window = sw32(event->u.resizeRequest.window, sw);
|
||||
ev->width = sw16(event->u.resizeRequest.width, sw);
|
||||
ev->height = sw16(event->u.resizeRequest.height, sw);
|
||||
}
|
||||
break;
|
||||
case CirculateNotify:
|
||||
{
|
||||
register XCirculateEvent *ev = (XCirculateEvent *) re;
|
||||
ev->window = sw32(event->u.circulate.window, sw);
|
||||
ev->event = sw32(event->u.circulate.event, sw);
|
||||
ev->place = event->u.circulate.place;
|
||||
}
|
||||
break;
|
||||
case CirculateRequest:
|
||||
{
|
||||
register XCirculateRequestEvent *ev =
|
||||
(XCirculateRequestEvent *) re;
|
||||
ev->window = sw32(event->u.circulate.window, sw);
|
||||
ev->parent = sw32(event->u.circulate.event, sw);
|
||||
ev->place = event->u.circulate.place;
|
||||
}
|
||||
break;
|
||||
case PropertyNotify:
|
||||
{
|
||||
register XPropertyEvent *ev = (XPropertyEvent *) re;
|
||||
ev->window = sw32(event->u.property.window, sw);
|
||||
ev->atom = sw32(event->u.property.atom, sw);
|
||||
ev->time = sw32(event->u.property.time, sw);
|
||||
ev->state = event->u.property.state;
|
||||
}
|
||||
break;
|
||||
case SelectionClear:
|
||||
{
|
||||
register XSelectionClearEvent *ev =
|
||||
(XSelectionClearEvent *) re;
|
||||
ev->window = sw32(event->u.selectionClear.window, sw);
|
||||
ev->selection = sw32(event->u.selectionClear.atom, sw);
|
||||
ev->time = sw32(event->u.selectionClear.time, sw);
|
||||
}
|
||||
break;
|
||||
case SelectionRequest:
|
||||
{
|
||||
register XSelectionRequestEvent *ev =
|
||||
(XSelectionRequestEvent *) re;
|
||||
ev->owner = sw32(event->u.selectionRequest.owner, sw);
|
||||
ev->requestor = sw32(event->u.selectionRequest.requestor, sw);
|
||||
ev->selection = sw32(event->u.selectionRequest.selection, sw);
|
||||
ev->target = sw32(event->u.selectionRequest.target, sw);
|
||||
ev->property = sw32(event->u.selectionRequest.property, sw);
|
||||
ev->time = sw32(event->u.selectionRequest.time, sw);
|
||||
}
|
||||
break;
|
||||
case SelectionNotify:
|
||||
{
|
||||
register XSelectionEvent *ev = (XSelectionEvent *) re;
|
||||
ev->requestor = sw32(event->u.selectionNotify.requestor, sw);
|
||||
ev->selection = sw32(event->u.selectionNotify.selection, sw);
|
||||
ev->target = sw32(event->u.selectionNotify.target, sw);
|
||||
ev->property = sw32(event->u.selectionNotify.property, sw);
|
||||
ev->time = sw32(event->u.selectionNotify.time, sw);
|
||||
}
|
||||
break;
|
||||
case ColormapNotify:
|
||||
{
|
||||
register XColormapEvent *ev = (XColormapEvent *) re;
|
||||
ev->window = sw32(event->u.colormap.window, sw);
|
||||
ev->colormap = sw32(event->u.colormap.colormap, sw);
|
||||
ev->new = event->u.colormap.new;
|
||||
ev->state = event->u.colormap.state;
|
||||
}
|
||||
break;
|
||||
case ClientMessage:
|
||||
{
|
||||
register int i;
|
||||
register XClientMessageEvent *ev
|
||||
= (XClientMessageEvent *) re;
|
||||
ev->window = sw32(event->u.clientMessage.window, sw);
|
||||
ev->format = event->u.u.detail;
|
||||
switch (ev->format) {
|
||||
case 8:
|
||||
ev->message_type = sw32(event->u.clientMessage.u.b.type, sw);
|
||||
for (i = 0; i < 20; i++)
|
||||
ev->data.b[i] = event->u.clientMessage.u.b.bytes[i];
|
||||
break;
|
||||
case 16:
|
||||
ev->message_type = sw32(event->u.clientMessage.u.s.type, sw);
|
||||
ev->data.s[0] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts0, sw));
|
||||
ev->data.s[1] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts1, sw));
|
||||
ev->data.s[2] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts2, sw));
|
||||
ev->data.s[3] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts3, sw));
|
||||
ev->data.s[4] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts4, sw));
|
||||
ev->data.s[5] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts5, sw));
|
||||
ev->data.s[6] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts6, sw));
|
||||
ev->data.s[7] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts7, sw));
|
||||
ev->data.s[8] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts8, sw));
|
||||
ev->data.s[9] = cvtINT16toShort(sw16(event->u.clientMessage.u.s.shorts9, sw));
|
||||
break;
|
||||
case 32:
|
||||
ev->message_type = sw32(event->u.clientMessage.u.l.type, sw);
|
||||
ev->data.l[0] = cvtINT32toLong(sw32(event->u.clientMessage.u.l.longs0, sw));
|
||||
ev->data.l[1] = cvtINT32toLong(sw32(event->u.clientMessage.u.l.longs1, sw));
|
||||
ev->data.l[2] = cvtINT32toLong(sw32(event->u.clientMessage.u.l.longs2, sw));
|
||||
ev->data.l[3] = cvtINT32toLong(sw32(event->u.clientMessage.u.l.longs3, sw));
|
||||
ev->data.l[4] = cvtINT32toLong(sw32(event->u.clientMessage.u.l.longs4, sw));
|
||||
break;
|
||||
default: /* XXX should never occur */
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MappingNotify:
|
||||
{
|
||||
register XMappingEvent *ev = (XMappingEvent *)re;
|
||||
ev->window = 0;
|
||||
ev->first_keycode = event->u.mappingNotify.firstKeyCode;
|
||||
ev->request = event->u.mappingNotify.request;
|
||||
ev->count = event->u.mappingNotify.count;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return(False);
|
||||
}
|
||||
return(True);
|
||||
}
|
||||
576
nx-X11/lib/modules/im/ximcp/imExten.c
Normal file
576
nx-X11/lib/modules/im/ximcp/imExten.c
Normal file
@@ -0,0 +1,576 @@
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1992, 1993, 1994 by FUJITSU LIMITED
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and
|
||||
that both that copyright notice and this permission notice appear
|
||||
in supporting documentation, and that the name of FUJITSU LIMITED
|
||||
not be used in advertising or publicity pertaining to distribution
|
||||
of the software without specific, written prior permission.
|
||||
FUJITSU LIMITED makes no representations about the suitability of
|
||||
this software for any purpose.
|
||||
It is provided "as is" without express or implied warranty.
|
||||
|
||||
FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Author: Takashi Fujiwara FUJITSU LIMITED
|
||||
fujiwara@a80.tech.yk.fujitsu.co.jp
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <nx-X11/Xatom.h>
|
||||
#include "Xlibint.h"
|
||||
#include "Xlcint.h"
|
||||
#include "Ximint.h"
|
||||
|
||||
/*
|
||||
* index of extensions
|
||||
*/
|
||||
|
||||
#define XIM_EXT_SET_EVENT_MASK_IDX 0
|
||||
#ifdef EXT_FORWARD
|
||||
#define XIM_EXT_FORWARD_KEYEVENT_IDX 1
|
||||
#endif
|
||||
#ifdef EXT_MOVE
|
||||
#define XIM_EXT_MOVE_IDX 2
|
||||
#endif
|
||||
|
||||
typedef struct _XIM_QueryExtRec {
|
||||
Bool is_support;
|
||||
const char *name;
|
||||
int name_len;
|
||||
CARD16 major_opcode;
|
||||
CARD16 minor_opcode;
|
||||
int idx;
|
||||
} XIM_QueryExtRec;
|
||||
|
||||
static XIM_QueryExtRec extensions[] = {
|
||||
{False, "XIM_EXT_SET_EVENT_MASK", 0, 0, 0,
|
||||
XIM_EXT_SET_EVENT_MASK_IDX},
|
||||
#ifdef EXT_FORWARD
|
||||
{False, "XIM_EXT_FORWARD_KEYEVENT", 0, 0, 0,
|
||||
XIM_EXT_FORWARD_KEYEVENT_IDX},
|
||||
#endif
|
||||
#ifdef EXT_MOVE
|
||||
{False, "XIM_EXT_MOVE", 0, 0, 0, XIM_EXT_MOVE_IDX},
|
||||
#endif
|
||||
{False, NULL, 0, 0, 0, 0} /* dummy */
|
||||
};
|
||||
|
||||
static int
|
||||
_XimIsSupportExt(
|
||||
int idx)
|
||||
{
|
||||
register int i;
|
||||
int n = XIMNumber(extensions) - 1;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if (extensions[i].idx == idx) {
|
||||
if (extensions[i].is_support)
|
||||
return i;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimProcExtSetEventMask(
|
||||
Xim im,
|
||||
Xic ic,
|
||||
XPointer buf)
|
||||
{
|
||||
EVENTMASK *buf_l = (EVENTMASK *)buf;
|
||||
EVENTMASK select_mask = _XimGetWindowEventmask(ic);
|
||||
|
||||
ic->private.proto.filter_event_mask = buf_l[0];
|
||||
ic->private.proto.intercept_event_mask = buf_l[1];
|
||||
ic->private.proto.select_event_mask = buf_l[2];
|
||||
ic->private.proto.forward_event_mask = buf_l[3];
|
||||
ic->private.proto.synchronous_event_mask = buf_l[4];
|
||||
|
||||
select_mask &= ~ic->private.proto.intercept_event_mask;
|
||||
/* deselected event mask */
|
||||
select_mask |= ic->private.proto.select_event_mask;
|
||||
/* selected event mask */
|
||||
XSelectInput(im->core.display, ic->core.focus_window, select_mask);
|
||||
_XimReregisterFilter(ic);
|
||||
|
||||
if (!(_XimProcSyncReply(im, ic)))
|
||||
return False;
|
||||
return True;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimExtSetEventMaskCallback(
|
||||
Xim xim,
|
||||
INT16 len,
|
||||
XPointer data,
|
||||
XPointer call_data)
|
||||
{
|
||||
CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
|
||||
XIMID imid = buf_s[0];
|
||||
XICID icid = buf_s[1];
|
||||
Xim im = (Xim)call_data;
|
||||
Xic ic;
|
||||
|
||||
if ((imid == im->private.proto.imid)
|
||||
&& (ic = _XimICOfXICID(im, icid))) {
|
||||
(void)_XimProcExtSetEventMask(im, ic, (XPointer)&buf_s[2]);
|
||||
return True;
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
||||
#ifdef EXT_FORWARD
|
||||
static Bool
|
||||
_XimProcExtForwardKeyEvent(
|
||||
Xim im,
|
||||
Xic ic,
|
||||
XPointer buf)
|
||||
{
|
||||
CARD8 *buf_b = (CARD8 *)buf;
|
||||
CARD16 *buf_s = (CARD16 *)buf;
|
||||
CARD32 *buf_l = (CARD32 *)buf;
|
||||
XEvent ev;
|
||||
XKeyEvent *kev = (XKeyEvent *)&ev;
|
||||
|
||||
bzero(&ev, sizeof(XEvent));
|
||||
kev->send_event = False;
|
||||
kev->display = im->core.display;
|
||||
kev->serial = buf_s[1]; /* sequence number */
|
||||
kev->type = buf_b[4] & 0x7f; /* xEvent.u.u.type */
|
||||
kev->keycode = buf_b[5]; /* Keycode */
|
||||
kev->state = buf_s[3]; /* state */
|
||||
kev->time = buf_l[2]; /* time */
|
||||
|
||||
XPutBackEvent(im->core.display, &ev);
|
||||
|
||||
_XimRespSyncReply(ic, buf_s[0]);
|
||||
MARK_FABRICATED(im);
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimExtForwardKeyEventCallback(
|
||||
Xim xim,
|
||||
INT16 len,
|
||||
XPointer data,
|
||||
XPointer call_data)
|
||||
{
|
||||
CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
|
||||
XIMID imid = buf_s[0];
|
||||
XICID icid = buf_s[1];
|
||||
Xim im = (Xim)call_data;
|
||||
Xic ic;
|
||||
|
||||
if ((imid == im->private.proto.imid)
|
||||
&& (ic = _XimICOfXICID(im, icid))) {
|
||||
(void)_XimProcExtForwardKeyEvent(im, ic, (XPointer)&buf_s[2]);
|
||||
return True;
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimExtForwardKeyEventCheck(
|
||||
Xim im,
|
||||
INT16 len,
|
||||
XPointer data,
|
||||
XPointer arg)
|
||||
{
|
||||
Xic ic = (Xic)arg;
|
||||
CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
|
||||
CARD8 major_opcode = *((CARD8 *)data);
|
||||
CARD8 minor_opcode = *((CARD8 *)data + 1);
|
||||
XIMID imid = buf_s[0];
|
||||
XICID icid = buf_s[1];
|
||||
|
||||
if ((major_opcode == XIM_SYNC_REPLY)
|
||||
&& (minor_opcode == 0)
|
||||
&& (imid == im->private.proto.imid)
|
||||
&& (icid == ic->private.proto.icid))
|
||||
if ((major_opcode == XIM_ERROR)
|
||||
&& (minor_opcode == 0)
|
||||
&& (buf_s[2] & XIM_IMID_VALID)
|
||||
&& (imid == im->private.proto.imid)
|
||||
&& (buf_s[2] & XIM_ICID_VALID)
|
||||
&& (icid == ic->private.proto.icid))
|
||||
return True;
|
||||
return False;
|
||||
}
|
||||
|
||||
Bool
|
||||
_XimExtForwardKeyEvent(
|
||||
Xic ic,
|
||||
XKeyEvent *ev,
|
||||
Bool sync)
|
||||
{
|
||||
Xim im = (Xim) ic->core.im;
|
||||
CARD32 buf32[BUFSIZE/4];
|
||||
CARD8 *buf = (CARD8 *)buf32;
|
||||
CARD8 *buf_b = &buf[XIM_HEADER_SIZE];
|
||||
CARD16 *buf_s = (CARD16 *)buf_b;
|
||||
CARD32 *buf_l = (CARD32 *)buf_b;
|
||||
CARD32 reply32[BUFSIZE/4];
|
||||
char *reply = (char *)reply32;
|
||||
XPointer preply;
|
||||
int buf_size;
|
||||
int ret_code;
|
||||
INT16 len;
|
||||
int idx;
|
||||
|
||||
if ((idx = _XimIsSupportExt(XIM_EXT_FORWARD_KEYEVENT_IDX)) < 0)
|
||||
return False;
|
||||
|
||||
buf_s[0] = im->private.proto.imid; /* imid */
|
||||
buf_s[1] = ic->private.proto.icid; /* icid */
|
||||
buf_s[2] = sync ? XimSYNCHRONUS : 0; /* flag */
|
||||
buf_s[3] = (CARD16)(((XAnyEvent *)ev)->serial & ((unsigned long) 0xffff));
|
||||
/* sequence number */
|
||||
buf_b[8] = ev->type; /* xEvent.u.u.type */
|
||||
buf_b[9] = ev->keycode; /* keycode */
|
||||
buf_s[5] = ev->state; /* state */
|
||||
buf_l[3] = ev->time; /* time */
|
||||
len = sizeof(CARD16) /* sizeof imid */
|
||||
+ sizeof(CARD16) /* sizeof icid */
|
||||
+ sizeof(BITMASK16) /* sizeof flag */
|
||||
+ sizeof(CARD16) /* sizeof sequence number */
|
||||
+ sizeof(BYTE) /* sizeof xEvent.u.u.type */
|
||||
+ sizeof(BYTE) /* sizeof keycode */
|
||||
+ sizeof(CARD16) /* sizeof state */
|
||||
+ sizeof(CARD32); /* sizeof time */
|
||||
|
||||
_XimSetHeader((XPointer)buf,
|
||||
extensions[idx].major_opcode,
|
||||
extensions[idx].minor_opcode, &len);
|
||||
if (!(_XimWrite(im, len, (XPointer)buf)))
|
||||
return False;
|
||||
_XimFlush(im);
|
||||
if (sync) {
|
||||
buf_size = BUFSIZE;
|
||||
ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
|
||||
_XimExtForwardKeyEventCheck, (XPointer)ic);
|
||||
if(ret_code == XIM_TRUE) {
|
||||
preply = reply;
|
||||
} else if(ret_code == XIM_OVERFLOW) {
|
||||
if(len <= 0) {
|
||||
preply = reply;
|
||||
} else {
|
||||
buf_sizex = len;
|
||||
preply = Xmalloc(buf_size);
|
||||
ret_code = _XimRead(im, &len, preply, buf_size,
|
||||
_XimExtForwardKeyEventCheck, (XPointer)ic);
|
||||
if(ret_code != XIM_TRUE) {
|
||||
Xfree(preply);
|
||||
return False;
|
||||
}
|
||||
}
|
||||
} else
|
||||
return False;
|
||||
buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
|
||||
if (*((CARD8 *)preply) == XIM_ERROR) {
|
||||
_XimProcError(im, 0, (XPointer)&buf_s[3]);
|
||||
if(reply != preply)
|
||||
Xfree(preply);
|
||||
return False;
|
||||
}
|
||||
if(reply != preply)
|
||||
Xfree(preply);
|
||||
}
|
||||
return True;
|
||||
}
|
||||
#endif /* EXT_FORWARD */
|
||||
|
||||
static int
|
||||
_XimCheckExtensionListSize(void)
|
||||
{
|
||||
register int i;
|
||||
int len;
|
||||
int total = 0;
|
||||
int n = XIMNumber(extensions) - 1;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
len = strlen(extensions[i].name);
|
||||
extensions[i].name_len = len;
|
||||
len += sizeof(BYTE);
|
||||
total += len;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
static void
|
||||
_XimSetExtensionList(
|
||||
CARD8 *buf)
|
||||
{
|
||||
register int i;
|
||||
int len;
|
||||
int n = XIMNumber(extensions) - 1;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
len = extensions[i].name_len;
|
||||
buf[0] = (BYTE)len;
|
||||
(void)strcpy((char *)&buf[1], extensions[i].name);
|
||||
len += sizeof(BYTE);
|
||||
buf += len;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
_XimCountNumberOfExtension(
|
||||
INT16 total,
|
||||
CARD8 *ext)
|
||||
{
|
||||
unsigned int n;
|
||||
INT16 len;
|
||||
INT16 min_len = sizeof(CARD8)
|
||||
+ sizeof(CARD8)
|
||||
+ sizeof(INT16);
|
||||
|
||||
n = 0;
|
||||
while (total > min_len) {
|
||||
len = *((INT16 *)(&ext[2]));
|
||||
len += (min_len + XIM_PAD(len));
|
||||
total -= len;
|
||||
ext += len;
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimParseExtensionList(
|
||||
Xim im,
|
||||
CARD16 *data)
|
||||
{
|
||||
int num = XIMNumber(extensions) - 1;
|
||||
unsigned int n;
|
||||
CARD8 *buf;
|
||||
register int i;
|
||||
register int j;
|
||||
INT16 len;
|
||||
|
||||
if (!(n = _XimCountNumberOfExtension(data[0], (CARD8 *)&data[1])))
|
||||
return True;
|
||||
|
||||
buf = (CARD8 *)&data[1];
|
||||
for (i = 0; i < n; i++) {
|
||||
len = *((INT16 *)(&buf[2]));
|
||||
for (j = 0; j < num; j++) {
|
||||
if (!(strncmp(extensions[j].name, (char *)&buf[4], len))) {
|
||||
extensions[j].major_opcode = buf[0];
|
||||
extensions[j].minor_opcode = buf[1];
|
||||
extensions[j].is_support = True;
|
||||
break;
|
||||
}
|
||||
}
|
||||
len += sizeof(CARD8) /* sizeof major_opcode */
|
||||
+ sizeof(CARD8) /* sizeof minor_opcode */
|
||||
+ sizeof(INT16) /* sizeof length */
|
||||
+ XIM_PAD(len); /* sizeof pad */
|
||||
buf += len;
|
||||
}
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimQueryExtensionCheck(
|
||||
Xim im,
|
||||
INT16 len,
|
||||
XPointer data,
|
||||
XPointer arg)
|
||||
{
|
||||
CARD16 *buf_s = (CARD16 *)((CARD8 *)data + XIM_HEADER_SIZE);
|
||||
CARD8 major_opcode = *((CARD8 *)data);
|
||||
CARD8 minor_opcode = *((CARD8 *)data + 1);
|
||||
XIMID imid = buf_s[0];
|
||||
|
||||
if ((major_opcode == XIM_QUERY_EXTENSION_REPLY)
|
||||
&& (minor_opcode == 0)
|
||||
&& (imid == im->private.proto.imid))
|
||||
return True;
|
||||
if ((major_opcode == XIM_ERROR)
|
||||
&& (minor_opcode == 0)
|
||||
&& (buf_s[2] & XIM_IMID_VALID)
|
||||
&& (imid == im->private.proto.imid))
|
||||
return True;
|
||||
return False;
|
||||
}
|
||||
|
||||
Bool
|
||||
_XimExtension(
|
||||
Xim im)
|
||||
{
|
||||
CARD8 *buf;
|
||||
CARD16 *buf_s;
|
||||
int buf_len;
|
||||
INT16 len;
|
||||
CARD32 reply32[BUFSIZE/4];
|
||||
char *reply = (char *)reply32;
|
||||
XPointer preply;
|
||||
int buf_size;
|
||||
int ret_code;
|
||||
int idx;
|
||||
|
||||
if (!(len = _XimCheckExtensionListSize()))
|
||||
return True;
|
||||
|
||||
buf_len = XIM_HEADER_SIZE
|
||||
+ sizeof(CARD16)
|
||||
+ sizeof(INT16)
|
||||
+ len
|
||||
+ XIM_PAD(len);
|
||||
|
||||
if (!(buf = Xmalloc(buf_len)))
|
||||
return False;
|
||||
buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
|
||||
|
||||
buf_s[0] = im->private.proto.imid; /* imid */
|
||||
buf_s[1] = len; /* length of Extensions */
|
||||
_XimSetExtensionList((CARD8 *)&buf_s[2]);
|
||||
/* extensions supported */
|
||||
XIM_SET_PAD(&buf_s[2], len); /* pad */
|
||||
len += sizeof(CARD16) /* sizeof imid */
|
||||
+ sizeof(INT16); /* sizeof length of extensions */
|
||||
|
||||
_XimSetHeader((XPointer)buf, XIM_QUERY_EXTENSION, 0, &len);
|
||||
if (!(_XimWrite(im, len, (XPointer)buf))) {
|
||||
XFree(buf);
|
||||
return False;
|
||||
}
|
||||
XFree(buf);
|
||||
_XimFlush(im);
|
||||
buf_size = BUFSIZE;
|
||||
ret_code = _XimRead(im, &len, (XPointer)reply, buf_size,
|
||||
_XimQueryExtensionCheck, 0);
|
||||
if(ret_code == XIM_TRUE) {
|
||||
preply = reply;
|
||||
} else if(ret_code == XIM_OVERFLOW) {
|
||||
if(len <= 0) {
|
||||
preply = reply;
|
||||
} else {
|
||||
buf_size = len;
|
||||
preply = Xmalloc(buf_size);
|
||||
ret_code = _XimRead(im, &len, reply, buf_size,
|
||||
_XimQueryExtensionCheck, 0);
|
||||
if(ret_code != XIM_TRUE) {
|
||||
Xfree(preply);
|
||||
return False;
|
||||
}
|
||||
}
|
||||
} else
|
||||
return False;
|
||||
buf_s = (CARD16 *)((char *)preply + XIM_HEADER_SIZE);
|
||||
if (*((CARD8 *)preply) == XIM_ERROR) {
|
||||
_XimProcError(im, 0, (XPointer)&buf_s[3]);
|
||||
if(reply != preply)
|
||||
Xfree(preply);
|
||||
return False;
|
||||
}
|
||||
|
||||
if (!(_XimParseExtensionList(im, &buf_s[1]))) {
|
||||
if(reply != preply)
|
||||
Xfree(preply);
|
||||
return False;
|
||||
}
|
||||
if(reply != preply)
|
||||
Xfree(preply);
|
||||
|
||||
if ((idx = _XimIsSupportExt(XIM_EXT_SET_EVENT_MASK_IDX)) >= 0)
|
||||
_XimRegProtoIntrCallback(im,
|
||||
extensions[idx].major_opcode,
|
||||
extensions[idx].minor_opcode,
|
||||
_XimExtSetEventMaskCallback, (XPointer)im);
|
||||
#ifdef EXT_FORWARD
|
||||
if ((idx = _XimIsSupportExt(XIM_EXT_FORWARD_KEYEVENT_IDX)) >= 0)
|
||||
_XimRegProtoIntrCallback(im,
|
||||
extensions[idx].major_opcode,
|
||||
extensions[idx].minor_opcode,
|
||||
_XimExtForwardKeyEventCallback, (XPointer)im);
|
||||
#endif
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
#ifdef EXT_MOVE
|
||||
/* flag of ExtenArgCheck */
|
||||
#define EXT_XNSPOTLOCATION (1L<<0)
|
||||
|
||||
/* macro for ExtenArgCheck */
|
||||
#define SET_EXT_XNSPOTLOCATION(flag) (flag |= EXT_XNSPOTLOCATION)
|
||||
#define IS_EXT_XNSPOTLOCATION(flag) (flag & EXT_XNSPOTLOCATION)
|
||||
|
||||
/* length of XPoint attribute */
|
||||
#define XIM_Xpoint_length 12
|
||||
|
||||
static Bool
|
||||
_XimExtMove(
|
||||
Xim im,
|
||||
Xic ic,
|
||||
CARD16 x,
|
||||
CARD16 y)
|
||||
{
|
||||
CARD32 buf32[BUFSIZE/4];
|
||||
CARD8 *buf = (CARD8 *)buf32;
|
||||
CARD16 *buf_s = (CARD16 *)&buf[XIM_HEADER_SIZE];
|
||||
INT16 len;
|
||||
int idx;
|
||||
|
||||
if ((idx = _XimIsSupportExt(XIM_EXT_MOVE_IDX)) < 0)
|
||||
return False;
|
||||
|
||||
buf_s[0] = im->private.proto.imid; /* imid */
|
||||
buf_s[1] = ic->private.proto.icid; /* icid */
|
||||
buf_s[2] = x; /* X */
|
||||
buf_s[3] = y; /* Y */
|
||||
len = sizeof(CARD16) /* sizeof imid */
|
||||
+ sizeof(CARD16) /* sizeof icid */
|
||||
+ sizeof(INT16) /* sizeof X */
|
||||
+ sizeof(INT16); /* sizeof Y */
|
||||
|
||||
_XimSetHeader((XPointer)buf, extensions[idx].major_opcode,
|
||||
extensions[idx].minor_opcode, &len);
|
||||
if (!(_XimWrite(im, len, (XPointer)buf)))
|
||||
return False;
|
||||
_XimFlush(im);
|
||||
return True;
|
||||
}
|
||||
|
||||
BITMASK32
|
||||
_XimExtenArgCheck(
|
||||
XIMArg *arg)
|
||||
{
|
||||
CARD32 flag = 0L;
|
||||
if (!strcmp(arg->name, XNSpotLocation))
|
||||
SET_EXT_XNSPOTLOCATION(flag);
|
||||
return flag;
|
||||
}
|
||||
|
||||
Bool
|
||||
_XimExtenMove(
|
||||
Xim im,
|
||||
Xic ic,
|
||||
CARD32 flag,
|
||||
CARD16 *buf,
|
||||
INT16 length)
|
||||
{
|
||||
if ((IS_EXT_XNSPOTLOCATION(flag)) && (length == XIM_Xpoint_length))
|
||||
return _XimExtMove(im, ic, buf[4], buf[5]);
|
||||
return False;
|
||||
}
|
||||
#endif /* EXT_MOVE */
|
||||
55
nx-X11/lib/modules/im/ximcp/imImSw.c
Normal file
55
nx-X11/lib/modules/im/ximcp/imImSw.c
Normal file
@@ -0,0 +1,55 @@
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1992, 1993 by FUJITSU LIMITED
|
||||
Copyright 1993 by Digital Equipment Corporation
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and that
|
||||
both that copyright notice and this permission notice appear in
|
||||
supporting documentation, and that the name of FUJITSU LIMITED and
|
||||
Digital Equipment Corporation not be used in advertising or publicity
|
||||
pertaining to distribution of the software without specific, written
|
||||
prior permission. FUJITSU LIMITED and Digital Equipment Corporation
|
||||
makes no representations about the suitability of this software for
|
||||
any purpose. It is provided "as is" without express or implied
|
||||
warranty.
|
||||
|
||||
FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION DISCLAIM ALL
|
||||
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||
FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
|
||||
ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
|
||||
Author: Takashi Fujiwara FUJITSU LIMITED
|
||||
fujiwara@a80.tech.yk.fujitsu.co.jp
|
||||
Modifier: Franky Ling Digital Equipment Corporation
|
||||
frankyling@hgrd01.enet.dec.com
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include "Xlibint.h"
|
||||
#include "Xlcint.h"
|
||||
#include "Ximint.h"
|
||||
#include "XimImSw.h"
|
||||
|
||||
static Bool
|
||||
_XimCheckIfDefault(
|
||||
Xim im)
|
||||
{
|
||||
return(True);
|
||||
}
|
||||
|
||||
XimImsportSW _XimImSportRec[] = {
|
||||
{ _XimCheckIfLocalProcessing, _XimLocalOpenIM, _XimLocalIMFree },
|
||||
{ _XimCheckIfThaiProcessing, _XimThaiOpenIM, _XimThaiIMFree },
|
||||
{ _XimCheckIfDefault, _XimProtoOpenIM, _XimProtoIMFree },
|
||||
{ NULL, NULL, NULL },
|
||||
};
|
||||
297
nx-X11/lib/modules/im/ximcp/imInsClbk.c
Normal file
297
nx-X11/lib/modules/im/ximcp/imInsClbk.c
Normal file
@@ -0,0 +1,297 @@
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1993, 1994 by Sony Corporation
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and
|
||||
that both that copyright notice and this permission notice appear
|
||||
in supporting documentation, and that the name of Sony Corporation
|
||||
not be used in advertising or publicity pertaining to distribution
|
||||
of the software without specific, written prior permission.
|
||||
Sony Corporation makes no representations about the suitability of
|
||||
this software for any purpose. It is provided "as is" without
|
||||
express or implied warranty.
|
||||
|
||||
SONY CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Author: Makoto Wakamatsu Sony Corporation
|
||||
makoto@sm.sony.co.jp
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <nx-X11/Xatom.h>
|
||||
#include "Xlibint.h"
|
||||
#include "Xlcint.h"
|
||||
#include "XlcPublic.h"
|
||||
#include "Ximint.h"
|
||||
|
||||
|
||||
typedef struct _XimInstCallback {
|
||||
Bool call;
|
||||
Bool destroy;
|
||||
Display *display;
|
||||
XLCd lcd;
|
||||
char name[XIM_MAXLCNAMELEN];
|
||||
char *modifiers;
|
||||
XrmDatabase rdb;
|
||||
char *res_name;
|
||||
char *res_class;
|
||||
XIDProc callback;
|
||||
XPointer client_data;
|
||||
struct _XimInstCallback *next;
|
||||
} XimInstCallbackRec, *XimInstCallback;
|
||||
|
||||
|
||||
static XimInstCallback callback_list = NULL;
|
||||
static Bool lock = False;
|
||||
|
||||
|
||||
static void
|
||||
MakeLocale( XLCd lcd, char locale[] )
|
||||
{
|
||||
char *language, *territory, *codeset;
|
||||
|
||||
_XGetLCValues( lcd, XlcNLanguage, &language, XlcNTerritory, &territory,
|
||||
XlcNCodeset, &codeset, NULL );
|
||||
|
||||
strcpy( locale, language );
|
||||
if( territory && *territory ) {
|
||||
strcat( locale, "_" );
|
||||
strcat( locale, territory );
|
||||
}
|
||||
if( codeset && *codeset ) {
|
||||
strcat( locale, "." );
|
||||
strcat( locale, codeset );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static Bool
|
||||
_XimFilterPropertyNotify(
|
||||
Display *display,
|
||||
Window window,
|
||||
XEvent *event,
|
||||
XPointer client_data)
|
||||
{
|
||||
Atom ims, actual_type, *atoms;
|
||||
int actual_format;
|
||||
unsigned long nitems, bytes_after;
|
||||
int ii;
|
||||
XIM xim;
|
||||
Bool flag = False;
|
||||
XimInstCallback icb, picb, tmp;
|
||||
|
||||
if( (ims = XInternAtom( display, XIM_SERVERS, True )) == None ||
|
||||
event->xproperty.atom != ims ||
|
||||
event->xproperty.state == PropertyDelete )
|
||||
return( False );
|
||||
|
||||
if( XGetWindowProperty( display, RootWindow(display, 0), ims, 0L, 1000000L,
|
||||
False, XA_ATOM, &actual_type, &actual_format,
|
||||
&nitems, &bytes_after, (unsigned char **)&atoms )
|
||||
!= Success ) {
|
||||
return( False );
|
||||
}
|
||||
if( actual_type != XA_ATOM || actual_format != 32 ) {
|
||||
XFree( atoms );
|
||||
return( False );
|
||||
}
|
||||
|
||||
lock = True;
|
||||
for( ii = 0; ii < nitems; ii++ ) {
|
||||
if(XGetSelectionOwner (display, atoms[ii])) {
|
||||
for( icb = callback_list; icb; icb = icb->next ) {
|
||||
if( !icb->call && !icb->destroy ) {
|
||||
xim = (*icb->lcd->methods->open_im)( icb->lcd, display,
|
||||
icb->rdb,
|
||||
icb->res_name,
|
||||
icb->res_class );
|
||||
if( xim ) {
|
||||
xim->methods->close( (XIM)xim );
|
||||
flag = True;
|
||||
icb->call = True;
|
||||
icb->callback( icb->display, icb->client_data, NULL );
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
XFree( atoms );
|
||||
|
||||
for( icb = callback_list, picb = NULL; icb; ) {
|
||||
if( icb->destroy ) {
|
||||
if( picb )
|
||||
picb->next = icb->next;
|
||||
else
|
||||
callback_list = icb->next;
|
||||
tmp = icb;
|
||||
icb = icb->next;
|
||||
XFree( tmp );
|
||||
}
|
||||
else {
|
||||
picb = icb;
|
||||
icb = icb->next;
|
||||
}
|
||||
}
|
||||
lock = False;
|
||||
|
||||
return( flag );
|
||||
}
|
||||
|
||||
|
||||
Bool
|
||||
_XimRegisterIMInstantiateCallback(
|
||||
XLCd lcd,
|
||||
Display *display,
|
||||
XrmDatabase rdb,
|
||||
char *res_name,
|
||||
char *res_class,
|
||||
XIDProc callback,
|
||||
XPointer client_data)
|
||||
{
|
||||
XimInstCallback icb, tmp;
|
||||
XIM xim;
|
||||
char *modifiers = NULL;
|
||||
Window root;
|
||||
XWindowAttributes attr;
|
||||
|
||||
if( lock )
|
||||
return( False );
|
||||
|
||||
icb = Xmalloc(sizeof(XimInstCallbackRec));
|
||||
if( !icb )
|
||||
return( False );
|
||||
if (lcd->core->modifiers) {
|
||||
modifiers = strdup(lcd->core->modifiers);
|
||||
if (!modifiers) {
|
||||
Xfree(icb);
|
||||
return( False );
|
||||
}
|
||||
}
|
||||
icb->call = icb->destroy = False;
|
||||
icb->display = display;
|
||||
icb->lcd = lcd;
|
||||
MakeLocale( lcd, icb->name );
|
||||
icb->modifiers = modifiers;
|
||||
icb->rdb = rdb;
|
||||
icb->res_name = res_name;
|
||||
icb->res_class = res_class;
|
||||
icb->callback = callback;
|
||||
icb->client_data = client_data;
|
||||
icb->next = NULL;
|
||||
|
||||
if( !callback_list )
|
||||
callback_list = icb;
|
||||
else {
|
||||
for( tmp = callback_list; tmp->next; tmp = tmp->next );
|
||||
tmp->next = icb;
|
||||
}
|
||||
|
||||
xim = (*lcd->methods->open_im)( lcd, display, rdb, res_name, res_class );
|
||||
|
||||
if( icb == callback_list ) {
|
||||
root = RootWindow( display, 0 );
|
||||
XGetWindowAttributes( display, root, &attr );
|
||||
_XRegisterFilterByType( display, root, PropertyNotify, PropertyNotify,
|
||||
_XimFilterPropertyNotify, (XPointer)NULL );
|
||||
XSelectInput( display, root,
|
||||
attr.your_event_mask | PropertyChangeMask );
|
||||
}
|
||||
|
||||
if( xim ) {
|
||||
lock = True;
|
||||
xim->methods->close( (XIM)xim );
|
||||
lock = False;
|
||||
icb->call = True;
|
||||
callback( display, client_data, NULL );
|
||||
}
|
||||
|
||||
return( True );
|
||||
}
|
||||
|
||||
|
||||
Bool
|
||||
_XimUnRegisterIMInstantiateCallback(
|
||||
XLCd lcd,
|
||||
Display *display,
|
||||
XrmDatabase rdb,
|
||||
char *res_name,
|
||||
char *res_class,
|
||||
XIDProc callback,
|
||||
XPointer client_data)
|
||||
{
|
||||
char locale[XIM_MAXLCNAMELEN];
|
||||
XimInstCallback icb, picb;
|
||||
|
||||
if( !callback_list )
|
||||
return( False );
|
||||
|
||||
MakeLocale( lcd, locale );
|
||||
|
||||
for( icb = callback_list, picb = NULL; icb; picb = icb, icb = icb->next ) {
|
||||
if( !strcmp( locale, icb->name ) &&
|
||||
(lcd->core->modifiers == icb->modifiers || /* XXXXX */
|
||||
(lcd->core->modifiers && icb->modifiers &&
|
||||
!strcmp( lcd->core->modifiers, icb->modifiers ))) &&
|
||||
rdb == icb->rdb && /* XXXXX */
|
||||
((res_name == NULL && icb->res_name == NULL) ||
|
||||
(res_name != NULL && icb->res_name != NULL &&
|
||||
!strcmp( res_name, icb->res_name ))) &&
|
||||
((res_class == NULL && icb->res_class == NULL) ||
|
||||
(res_class != NULL && icb->res_class != NULL &&
|
||||
!strcmp( res_class, icb->res_class ))) &&
|
||||
(callback == icb->callback) &&
|
||||
(client_data == icb->client_data) && /* XXXXX */
|
||||
!icb->destroy ) {
|
||||
if( lock )
|
||||
icb->destroy = True;
|
||||
else {
|
||||
if( !picb ) {
|
||||
callback_list = icb->next;
|
||||
_XUnregisterFilter( display, RootWindow(display, 0),
|
||||
_XimFilterPropertyNotify,
|
||||
(XPointer)NULL );
|
||||
}
|
||||
else
|
||||
picb->next = icb->next;
|
||||
_XCloseLC( icb->lcd );
|
||||
XFree( icb->modifiers );
|
||||
XFree( icb );
|
||||
}
|
||||
return( True );
|
||||
}
|
||||
}
|
||||
return( False );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_XimResetIMInstantiateCallback(Xim xim)
|
||||
{
|
||||
char locale[XIM_MAXLCNAMELEN];
|
||||
XimInstCallback icb;
|
||||
XLCd lcd = xim->core.lcd;
|
||||
|
||||
if( !callback_list && lock )
|
||||
return;
|
||||
|
||||
MakeLocale( lcd, locale );
|
||||
|
||||
for( icb = callback_list; icb; icb = icb->next )
|
||||
if( !strcmp( locale, icb->name ) &&
|
||||
(lcd->core->modifiers == icb->modifiers ||
|
||||
(lcd->core->modifiers && icb->modifiers &&
|
||||
!strcmp( lcd->core->modifiers, icb->modifiers ))) )
|
||||
icb->call = False;
|
||||
}
|
||||
260
nx-X11/lib/modules/im/ximcp/imInt.c
Normal file
260
nx-X11/lib/modules/im/ximcp/imInt.c
Normal file
@@ -0,0 +1,260 @@
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1992, 1993, 1994 by FUJITSU LIMITED
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and
|
||||
that both that copyright notice and this permission notice appear
|
||||
in supporting documentation, and that the name of FUJITSU LIMITED
|
||||
not be used in advertising or publicity pertaining to distribution
|
||||
of the software without specific, written prior permission.
|
||||
FUJITSU LIMITED makes no representations about the suitability of
|
||||
this software for any purpose.
|
||||
It is provided "as is" without express or implied warranty.
|
||||
|
||||
FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Author: Takashi Fujiwara FUJITSU LIMITED
|
||||
fujiwara@a80.tech.yk.fujitsu.co.jp
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <nx-X11/Xatom.h>
|
||||
#include <nx-X11/Xlib.h>
|
||||
#include <nx-X11/Xmd.h>
|
||||
#include "Xlibint.h"
|
||||
#include "Xlcint.h"
|
||||
#include "Ximint.h"
|
||||
#include "XimImSw.h"
|
||||
|
||||
static Xim *_XimCurrentIMlist = (Xim *)NULL;
|
||||
static int _XimCurrentIMcount = 0;
|
||||
|
||||
static Bool
|
||||
_XimSetIMStructureList(
|
||||
Xim im)
|
||||
{
|
||||
register int i;
|
||||
Xim *xim;
|
||||
|
||||
if(!(_XimCurrentIMlist)) {
|
||||
if(!(_XimCurrentIMlist = Xmalloc(sizeof(Xim))))
|
||||
return False;
|
||||
_XimCurrentIMlist[0] = im;
|
||||
_XimCurrentIMcount = 1;
|
||||
}
|
||||
else {
|
||||
for(i = 0; i < _XimCurrentIMcount; i++) {
|
||||
if(!( _XimCurrentIMlist[i])) {
|
||||
_XimCurrentIMlist[i] = im;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(i >= _XimCurrentIMcount) {
|
||||
if(!(xim = Xrealloc(_XimCurrentIMlist,
|
||||
((i + 1) * sizeof(Xim)))))
|
||||
return False;
|
||||
_XimCurrentIMlist = xim;
|
||||
_XimCurrentIMlist[_XimCurrentIMcount] = im;
|
||||
_XimCurrentIMcount++;
|
||||
}
|
||||
}
|
||||
return True;
|
||||
}
|
||||
|
||||
void
|
||||
_XimDestroyIMStructureList(Xim im)
|
||||
{
|
||||
register int i;
|
||||
|
||||
for(i = 0; i < _XimCurrentIMcount; i++) {
|
||||
if(_XimCurrentIMlist[i] == im) {
|
||||
_XimCurrentIMlist[i] = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
_XimServerDestroy(Xim im_2_destroy)
|
||||
{
|
||||
register int i;
|
||||
Xim im;
|
||||
XIC ic;
|
||||
|
||||
for(i = 0; i < _XimCurrentIMcount; i++) {
|
||||
if(!(im = _XimCurrentIMlist[i]))
|
||||
continue;
|
||||
/*
|
||||
* Only continue if this im is the one to be destroyed.
|
||||
*/
|
||||
if (im != im_2_destroy)
|
||||
continue;
|
||||
|
||||
if (im->core.destroy_callback.callback)
|
||||
(*im->core.destroy_callback.callback)((XIM)im,
|
||||
im->core.destroy_callback.client_data, NULL);
|
||||
for (ic = im->core.ic_chain; ic; ic = ic->core.next) {
|
||||
if (ic->core.destroy_callback.callback) {
|
||||
(*ic->core.destroy_callback.callback)(ic,
|
||||
ic->core.destroy_callback.client_data, NULL);
|
||||
}
|
||||
}
|
||||
_XimResetIMInstantiateCallback( im );
|
||||
(void)im->methods->close((XIM)im);
|
||||
Xfree(im);
|
||||
_XimCurrentIMlist[i] = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef XIM_CONNECTABLE
|
||||
void
|
||||
_XimServerReconectableDestroy(void)
|
||||
{
|
||||
register int i;
|
||||
Xim im;
|
||||
XIC ic;
|
||||
|
||||
for(i = 0; i < _XimCurrentIMcount; i++) {
|
||||
if(!(im = _XimCurrentIMlist[i]))
|
||||
continue;
|
||||
|
||||
if (im->core.destroy_callback.callback)
|
||||
(*im->core.destroy_callback.callback)(im,
|
||||
im->core.destroy_callback.client_data, NULL);
|
||||
for (ic = im->core.ic_chain; ic; ic = ic->core.next) {
|
||||
if (ic->core.destroy_callback.callback) {
|
||||
(*ic->core.destroy_callback.callback)(ic,
|
||||
ic->core.destroy_callback.client_data, NULL);
|
||||
}
|
||||
}
|
||||
_XimResetIMInstantiateCallback( im );
|
||||
(void)im->methods->close((XIM)im);
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif /* XIM_CONNECTABLE */
|
||||
|
||||
static const char *
|
||||
_XimStrstr(
|
||||
register const char *src,
|
||||
register const char *dest)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = strlen(dest);
|
||||
while((src = strchr(src, *dest))) {
|
||||
if(!strncmp(src, dest, len))
|
||||
return src;
|
||||
src++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *
|
||||
_XimMakeImName(
|
||||
XLCd lcd)
|
||||
{
|
||||
const char* begin = NULL;
|
||||
const char* end = NULL;
|
||||
char* ret = NULL;
|
||||
const char* ximmodifier = XIMMODIFIER;
|
||||
|
||||
if(lcd->core->modifiers != NULL && *lcd->core->modifiers != '\0') {
|
||||
begin = _XimStrstr(lcd->core->modifiers, ximmodifier);
|
||||
if (begin != NULL) {
|
||||
end = begin += strlen(ximmodifier);
|
||||
while (*end && *end != '@')
|
||||
end++;
|
||||
}
|
||||
}
|
||||
ret = Xmalloc(end - begin + 1);
|
||||
if (ret != NULL) {
|
||||
if (begin != NULL && end != NULL) {
|
||||
(void)strncpy(ret, begin, end - begin);
|
||||
ret[end - begin] = '\0';
|
||||
} else {
|
||||
ret[0] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
XIM
|
||||
_XimOpenIM(
|
||||
XLCd lcd,
|
||||
Display *dpy,
|
||||
XrmDatabase rdb,
|
||||
char *res_name,
|
||||
char *res_class)
|
||||
{
|
||||
Xim im;
|
||||
register int i;
|
||||
|
||||
if (!(im = Xcalloc(1, sizeof(XimRec))))
|
||||
return (XIM)NULL;
|
||||
|
||||
im->core.lcd = lcd;
|
||||
im->core.ic_chain = (XIC)NULL;
|
||||
im->core.display = dpy;
|
||||
im->core.rdb = rdb;
|
||||
im->core.res_name = NULL;
|
||||
im->core.res_class = NULL;
|
||||
if((res_name != NULL) && (*res_name != '\0')){
|
||||
if(!(im->core.res_name = strdup(res_name)))
|
||||
goto Error1;
|
||||
}
|
||||
if((res_class != NULL) && (*res_class != '\0')){
|
||||
if(!(im->core.res_class = strdup(res_class)))
|
||||
goto Error2;
|
||||
}
|
||||
if(!(im->core.im_name = _XimMakeImName(lcd)))
|
||||
goto Error3;
|
||||
|
||||
for(i= 0; ; i++) {
|
||||
if(_XimImSportRec[i].checkprocessing(im)) {
|
||||
if(!(_XimImSportRec[i].im_open(im)))
|
||||
goto Error4;
|
||||
if(!_XimSetIMStructureList(im))
|
||||
goto Error4;
|
||||
return (XIM)im;
|
||||
}
|
||||
}
|
||||
|
||||
Error4 :
|
||||
_XimImSportRec[i].im_free(im);
|
||||
Xfree(im);
|
||||
return NULL;
|
||||
Error3 :
|
||||
Xfree(im->core.im_name);
|
||||
Error2:
|
||||
Xfree(im->core.res_class);
|
||||
Error1:
|
||||
Xfree(im->core.res_name);
|
||||
Xfree(im);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Bool
|
||||
_XInitIM(XLCd lcd)
|
||||
{
|
||||
if(lcd == (XLCd)NULL)
|
||||
return False;
|
||||
lcd->methods->open_im = _XimOpenIM;
|
||||
lcd->methods->register_callback = _XimRegisterIMInstantiateCallback;
|
||||
lcd->methods->unregister_callback = _XimUnRegisterIMInstantiateCallback;
|
||||
return True;
|
||||
}
|
||||
159
nx-X11/lib/modules/im/ximcp/imLcFlt.c
Normal file
159
nx-X11/lib/modules/im/ximcp/imLcFlt.c
Normal file
@@ -0,0 +1,159 @@
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1992 by Fuji Xerox Co., Ltd.
|
||||
Copyright 1992, 1994 by FUJITSU LIMITED
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and
|
||||
that both that copyright notice and this permission notice appear
|
||||
in supporting documentation, and that the name of Fuji Xerox,
|
||||
FUJITSU LIMITED not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission. Fuji Xerox, FUJITSU LIMITED make no representations
|
||||
about the suitability of this software for any purpose.
|
||||
It is provided "as is" without express or implied warranty.
|
||||
|
||||
FUJI XEROX, FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJI XEROX,
|
||||
FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
|
||||
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
|
||||
OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Author : Kazunori Nishihara Fuji Xerox
|
||||
Modifier : Takashi Fujiwara FUJITSU LIMITED
|
||||
fujiwara@a80.tech.yk.fujitsu.co.jp
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include "Xlibint.h"
|
||||
#include <nx-X11/keysym.h>
|
||||
#include "Xlcint.h"
|
||||
#include "Ximint.h"
|
||||
|
||||
Bool
|
||||
_XimLocalFilter(Display *d, Window w, XEvent *ev, XPointer client_data)
|
||||
{
|
||||
Xic ic = (Xic)client_data;
|
||||
KeySym keysym;
|
||||
static char buf[256];
|
||||
static unsigned prevcode = 0, prevstate = 0;
|
||||
unsigned currstate;
|
||||
DefTree *b = ic->private.local.base.tree;
|
||||
DTIndex t;
|
||||
Bool anymodifier = False;
|
||||
unsigned char braillePattern = 0;
|
||||
|
||||
if(ev->xkey.keycode == 0)
|
||||
return (False);
|
||||
|
||||
XLookupString((XKeyEvent *)ev, buf, sizeof(buf), &keysym, NULL);
|
||||
|
||||
if(keysym >= XK_braille_dot_1 && keysym <= XK_braille_dot_8) {
|
||||
if(ev->type == KeyPress) {
|
||||
ic->private.local.brl_pressed |=
|
||||
1<<(keysym-XK_braille_dot_1);
|
||||
return(True);
|
||||
} else {
|
||||
if(!ic->private.local.brl_committing
|
||||
|| ev->xkey.time - ic->private.local.brl_release_start > 300) {
|
||||
ic->private.local.brl_committing = ic->private.local.brl_pressed;
|
||||
ic->private.local.brl_release_start = ev->xkey.time;
|
||||
}
|
||||
ic->private.local.brl_pressed &= ~(1<<(keysym-XK_braille_dot_1));
|
||||
if(!ic->private.local.brl_pressed && ic->private.local.brl_committing) {
|
||||
/* Committed a braille pattern, let it go through compose tree */
|
||||
keysym = XK_braille_blank | ic->private.local.brl_committing;
|
||||
ev->type = KeyPress;
|
||||
braillePattern = ic->private.local.brl_committing;
|
||||
ic->private.local.brl_committing = 0;
|
||||
} else {
|
||||
return(True);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(((Xim)ic->core.im)->private.local.top == 0 )
|
||||
goto emit_braille;
|
||||
|
||||
currstate = ev->xkey.state;
|
||||
if(ev->type == KeyPress) {
|
||||
prevcode = ev->xkey.keycode;
|
||||
prevstate = currstate;
|
||||
|
||||
if(IsModifierKey(keysym))
|
||||
return(False);
|
||||
prevcode = 0;
|
||||
} else {
|
||||
if(prevcode != ev->xkey.keycode)
|
||||
return False;
|
||||
|
||||
/* For lookup, we use the state at the time when the key was pressed, */
|
||||
/* because this state was not affected by the modifier that is mapped */
|
||||
/* to the key. */
|
||||
ev->xkey.state = prevstate;
|
||||
XLookupString((XKeyEvent *)ev, buf, sizeof(buf), &keysym, NULL);
|
||||
}
|
||||
|
||||
for(t = ic->private.local.context; t; t = b[t].next) {
|
||||
if(IsModifierKey(b[t].keysym))
|
||||
anymodifier = True;
|
||||
if(((ev->xkey.state & b[t].modifier_mask) == b[t].modifier) &&
|
||||
(keysym == b[t].keysym))
|
||||
break;
|
||||
}
|
||||
|
||||
/* Restore the state */
|
||||
ev->xkey.state = currstate;
|
||||
|
||||
if(t) { /* Matched */
|
||||
if(b[t].succession) { /* Intermediate */
|
||||
ic->private.local.context = b[t].succession;
|
||||
return (ev->type == KeyPress);
|
||||
} else { /* Terminate (reached to leaf) */
|
||||
ic->private.local.composed = t;
|
||||
ic->private.local.brl_committed = 0;
|
||||
/* return back to client KeyPressEvent keycode == 0 */
|
||||
ev->xkey.keycode = 0;
|
||||
ev->xkey.type = KeyPress;
|
||||
XPutBackEvent(d, ev);
|
||||
if(prevcode){
|
||||
/* For modifier key releases, restore the event, as we do not */
|
||||
/* filter it. */
|
||||
ev->xkey.type = KeyRelease;
|
||||
ev->xkey.keycode = prevcode;
|
||||
}
|
||||
/* initialize internal state for next key sequence */
|
||||
ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
|
||||
return (ev->type == KeyPress);
|
||||
}
|
||||
} else { /* Unmatched */
|
||||
/* Unmatched modifier key releases abort matching only in the case that */
|
||||
/* there was any modifier that would have matched */
|
||||
if((ic->private.local.context == ((Xim)ic->core.im)->private.local.top) ||
|
||||
(ev->type == KeyRelease && !anymodifier)) {
|
||||
goto emit_braille;
|
||||
}
|
||||
/* Error (Sequence Unmatch occurred) */
|
||||
/* initialize internal state for next key sequence */
|
||||
ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
|
||||
return (ev->type == KeyPress);
|
||||
}
|
||||
|
||||
emit_braille:
|
||||
if(braillePattern) {
|
||||
/* Braille pattern is not in compose tree, emit alone */
|
||||
ic->private.local.brl_committed = braillePattern;
|
||||
ic->private.local.composed = 0;
|
||||
ev->xkey.keycode = 0;
|
||||
_XPutBackEvent(d, ev);
|
||||
return(True);
|
||||
}
|
||||
return(False);
|
||||
}
|
||||
47
nx-X11/lib/modules/im/ximcp/imLcGIc.c
Normal file
47
nx-X11/lib/modules/im/ximcp/imLcGIc.c
Normal file
@@ -0,0 +1,47 @@
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1992,1993, 1994 by FUJITSU LIMITED
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and
|
||||
that both that copyright notice and this permission notice appear
|
||||
in supporting documentation, and that the name of FUJITSU LIMITED
|
||||
not be used in advertising or publicity pertaining to distribution
|
||||
of the software without specific, written prior permission.
|
||||
FUJITSU LIMITED makes no representations about the suitability of
|
||||
this software for any purpose.
|
||||
It is provided "as is" without express or implied warranty.
|
||||
|
||||
FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Author: Takashi Fujiwara FUJITSU LIMITED
|
||||
fujiwara@a80.tech.yk.fujitsu.co.jp
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include "Xlibint.h"
|
||||
#include "Xlcint.h"
|
||||
#include "Ximint.h"
|
||||
|
||||
char *
|
||||
_XimLocalGetICValues(XIC xic, XIMArg *values)
|
||||
{
|
||||
Xic ic = (Xic)xic;
|
||||
XimDefICValues ic_values;
|
||||
|
||||
_XimGetCurrentICValues(ic, &ic_values);
|
||||
return(_XimGetICValueData(ic, (XPointer)&ic_values,
|
||||
ic->private.local.ic_resources,
|
||||
ic->private.local.ic_num_resources,
|
||||
values, XIM_GETICVALUES));
|
||||
}
|
||||
199
nx-X11/lib/modules/im/ximcp/imLcIc.c
Normal file
199
nx-X11/lib/modules/im/ximcp/imLcIc.c
Normal file
@@ -0,0 +1,199 @@
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1992,1993, 1994 by FUJITSU LIMITED
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and
|
||||
that both that copyright notice and this permission notice appear
|
||||
in supporting documentation, and that the name of FUJITSU LIMITED
|
||||
not be used in advertising or publicity pertaining to distribution
|
||||
of the software without specific, written prior permission.
|
||||
FUJITSU LIMITED makes no representations about the suitability of
|
||||
this software for any purpose.
|
||||
It is provided "as is" without express or implied warranty.
|
||||
|
||||
FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Author: Takashi Fujiwara FUJITSU LIMITED
|
||||
fujiwara@a80.tech.yk.fujitsu.co.jp
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <nx-X11/Xlib.h>
|
||||
#include <nx-X11/Xmd.h>
|
||||
#include "Xlibint.h"
|
||||
#include "Xlcint.h"
|
||||
#include "Ximint.h"
|
||||
|
||||
static void
|
||||
_XimLocalUnSetFocus(
|
||||
XIC xic)
|
||||
{
|
||||
Xic ic = (Xic)xic;
|
||||
((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL;
|
||||
|
||||
if (ic->core.focus_window)
|
||||
_XUnregisterFilter(ic->core.im->core.display,
|
||||
ic->core.focus_window, _XimLocalFilter, (XPointer)ic);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
_XimLocalDestroyIC(
|
||||
XIC xic)
|
||||
{
|
||||
Xic ic = (Xic)xic;
|
||||
|
||||
if(((Xim)ic->core.im)->private.local.current_ic == (XIC)ic) {
|
||||
((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL;
|
||||
}
|
||||
if (ic->core.focus_window)
|
||||
_XUnregisterFilter(ic->core.im->core.display,
|
||||
ic->core.focus_window, _XimLocalFilter, (XPointer)ic);
|
||||
if(ic->private.local.ic_resources) {
|
||||
Xfree(ic->private.local.ic_resources);
|
||||
ic->private.local.ic_resources = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
_XimLocalSetFocus(
|
||||
XIC xic)
|
||||
{
|
||||
Xic ic = (Xic)xic;
|
||||
XIC current_ic = ((Xim)ic->core.im)->private.local.current_ic;
|
||||
|
||||
if (current_ic == (XIC)ic)
|
||||
return;
|
||||
|
||||
if (current_ic != (XIC)NULL) {
|
||||
_XimLocalUnSetFocus(current_ic);
|
||||
}
|
||||
((Xim)ic->core.im)->private.local.current_ic = (XIC)ic;
|
||||
|
||||
if (ic->core.focus_window)
|
||||
_XRegisterFilterByType(ic->core.im->core.display,
|
||||
ic->core.focus_window, KeyPress, KeyRelease,
|
||||
_XimLocalFilter, (XPointer)ic);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
_XimLocalReset(
|
||||
XIC xic)
|
||||
{
|
||||
Xic ic = (Xic)xic;
|
||||
ic->private.local.composed = 0;
|
||||
ic->private.local.context = ((Xim)ic->core.im)->private.local.top;
|
||||
ic->private.local.brl_pressed = 0;
|
||||
ic->private.local.brl_committing = 0;
|
||||
ic->private.local.brl_committed = 0;
|
||||
}
|
||||
|
||||
static char *
|
||||
_XimLocalMbReset(
|
||||
XIC xic)
|
||||
{
|
||||
_XimLocalReset(xic);
|
||||
return (char *)NULL;
|
||||
}
|
||||
|
||||
static wchar_t *
|
||||
_XimLocalWcReset(
|
||||
XIC xic)
|
||||
{
|
||||
_XimLocalReset(xic);
|
||||
return (wchar_t *)NULL;
|
||||
}
|
||||
|
||||
static XICMethodsRec Local_ic_methods = {
|
||||
_XimLocalDestroyIC, /* destroy */
|
||||
_XimLocalSetFocus, /* set_focus */
|
||||
_XimLocalUnSetFocus, /* unset_focus */
|
||||
_XimLocalSetICValues, /* set_values */
|
||||
_XimLocalGetICValues, /* get_values */
|
||||
_XimLocalMbReset, /* mb_reset */
|
||||
_XimLocalWcReset, /* wc_reset */
|
||||
_XimLocalMbReset, /* utf8_reset */
|
||||
_XimLocalMbLookupString, /* mb_lookup_string */
|
||||
_XimLocalWcLookupString, /* wc_lookup_string */
|
||||
_XimLocalUtf8LookupString /* utf8_lookup_string */
|
||||
};
|
||||
|
||||
XIC
|
||||
_XimLocalCreateIC(
|
||||
XIM im,
|
||||
XIMArg *values)
|
||||
{
|
||||
Xic ic;
|
||||
XimDefICValues ic_values;
|
||||
XIMResourceList res;
|
||||
unsigned int num;
|
||||
int len;
|
||||
|
||||
if((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) {
|
||||
return ((XIC)NULL);
|
||||
}
|
||||
|
||||
ic->methods = &Local_ic_methods;
|
||||
ic->core.im = im;
|
||||
ic->private.local.base = ((Xim)im)->private.local.base;
|
||||
ic->private.local.context = ((Xim)im)->private.local.top;
|
||||
ic->private.local.composed = 0;
|
||||
ic->private.local.brl_pressed = 0;
|
||||
ic->private.local.brl_committing = 0;
|
||||
ic->private.local.brl_committed = 0;
|
||||
|
||||
num = im->core.ic_num_resources;
|
||||
len = sizeof(XIMResource) * num;
|
||||
if((res = Xmalloc(len)) == (XIMResourceList)NULL) {
|
||||
goto Set_Error;
|
||||
}
|
||||
(void)memcpy((char *)res, (char *)im->core.ic_resources, len);
|
||||
ic->private.local.ic_resources = res;
|
||||
ic->private.local.ic_num_resources = num;
|
||||
|
||||
bzero((char *)&ic_values, sizeof(XimDefICValues));
|
||||
if(_XimCheckLocalInputStyle(ic, (XPointer)&ic_values, values,
|
||||
im->core.styles, res, num) == False) {
|
||||
goto Set_Error;
|
||||
}
|
||||
|
||||
_XimSetICMode(res, num, ic_values.input_style);
|
||||
|
||||
if(_XimSetICValueData(ic, (XPointer)&ic_values,
|
||||
ic->private.local.ic_resources,
|
||||
ic->private.local.ic_num_resources,
|
||||
values, XIM_CREATEIC, True)) {
|
||||
goto Set_Error;
|
||||
}
|
||||
ic_values.filter_events = KeyPressMask | KeyReleaseMask;
|
||||
_XimSetCurrentICValues(ic, &ic_values);
|
||||
if(_XimSetICDefaults(ic, (XPointer)&ic_values,
|
||||
XIM_SETICDEFAULTS, res, num) == False) {
|
||||
goto Set_Error;
|
||||
}
|
||||
_XimSetCurrentICValues(ic, &ic_values);
|
||||
|
||||
return((XIC)ic);
|
||||
|
||||
Set_Error :
|
||||
if (ic->private.local.ic_resources) {
|
||||
Xfree(ic->private.local.ic_resources);
|
||||
ic->private.local.ic_resources = NULL;
|
||||
}
|
||||
Xfree(ic);
|
||||
return((XIC)NULL);
|
||||
}
|
||||
711
nx-X11/lib/modules/im/ximcp/imLcIm.c
Normal file
711
nx-X11/lib/modules/im/ximcp/imLcIm.c
Normal file
@@ -0,0 +1,711 @@
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1992, 1993, 1994 by FUJITSU LIMITED
|
||||
Copyright 1993 by Digital Equipment Corporation
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and that
|
||||
both that copyright notice and this permission notice appear in
|
||||
supporting documentation, and that the name of FUJITSU LIMITED and
|
||||
Digital Equipment Corporation not be used in advertising or publicity
|
||||
pertaining to distribution of the software without specific, written
|
||||
prior permission. FUJITSU LIMITED and Digital Equipment Corporation
|
||||
makes no representations about the suitability of this software for
|
||||
any purpose. It is provided "as is" without express or implied
|
||||
warranty.
|
||||
|
||||
FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION DISCLAIM ALL
|
||||
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||
FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
|
||||
ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
|
||||
Author: Takashi Fujiwara FUJITSU LIMITED
|
||||
fujiwara@a80.tech.yk.fujitsu.co.jp
|
||||
Modifier: Franky Ling Digital Equipment Corporation
|
||||
frankyling@hgrd01.enet.dec.com
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
#include <nx-X11/Xmd.h>
|
||||
#include <nx-X11/Xatom.h>
|
||||
#include <nx-X11/Xos.h>
|
||||
#include "Xlibint.h"
|
||||
#include "Xlcint.h"
|
||||
#include "XlcPublic.h"
|
||||
#include "XlcPubI.h"
|
||||
#include "Ximint.h"
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef COMPOSECACHE
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <sys/mman.h>
|
||||
# include <langinfo.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef COMPOSECACHE
|
||||
|
||||
/* include trailing '/' for cache directory, file prefix otherwise */
|
||||
#define XIM_GLOBAL_CACHE_DIR "/var/cache/libx11/compose/"
|
||||
#define XIM_HOME_CACHE_DIR "/.compose-cache/"
|
||||
#define XIM_CACHE_MAGIC ('X' | 'i'<<8 | 'm'<<16 | 'C'<<24)
|
||||
#define XIM_CACHE_VERSION 4
|
||||
#define XIM_CACHE_TREE_ALIGNMENT 4
|
||||
|
||||
#define XIM_HASH_PRIME_1 13
|
||||
#define XIM_HASH_PRIME_2 1234096939
|
||||
|
||||
typedef INT32 DTStructIndex;
|
||||
struct _XimCacheStruct {
|
||||
INT32 id;
|
||||
INT32 version;
|
||||
DTStructIndex tree;
|
||||
DTStructIndex mb;
|
||||
DTStructIndex wc;
|
||||
DTStructIndex utf8;
|
||||
DTStructIndex size;
|
||||
DTIndex top;
|
||||
DTIndex treeused;
|
||||
DTCharIndex mbused;
|
||||
DTCharIndex wcused;
|
||||
DTCharIndex utf8used;
|
||||
char fname[];
|
||||
/* char encoding[] */
|
||||
};
|
||||
|
||||
static struct _XimCacheStruct* _XimCache_mmap = NULL;
|
||||
static DefTreeBase _XimCachedDefaultTreeBase;
|
||||
static int _XimCachedDefaultTreeRefcount = 0;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Bool
|
||||
_XimCheckIfLocalProcessing(Xim im)
|
||||
{
|
||||
FILE *fp;
|
||||
char *name;
|
||||
|
||||
if(strcmp(im->core.im_name, "") == 0) {
|
||||
name = _XlcFileName(im->core.lcd, COMPOSE_FILE);
|
||||
if (name != (char *)NULL) {
|
||||
fp = _XFopenFile (name, "r");
|
||||
Xfree(name);
|
||||
if (fp != (FILE *)NULL) {
|
||||
fclose(fp);
|
||||
return(True);
|
||||
}
|
||||
}
|
||||
return(False);
|
||||
} else if(strcmp(im->core.im_name, "local") == 0 ||
|
||||
strcmp(im->core.im_name, "none" ) == 0 ) {
|
||||
return(True);
|
||||
}
|
||||
return(False);
|
||||
}
|
||||
|
||||
static void
|
||||
XimFreeDefaultTree(
|
||||
DefTreeBase *b)
|
||||
{
|
||||
if (!b) return;
|
||||
if (b->tree == NULL) return;
|
||||
#ifdef COMPOSECACHE
|
||||
if (b->tree == _XimCachedDefaultTreeBase.tree) {
|
||||
_XimCachedDefaultTreeRefcount--;
|
||||
/* No deleting, it's a cache after all. */
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
Xfree (b->tree);
|
||||
b->tree = NULL;
|
||||
Xfree (b->mb);
|
||||
b->mb = NULL;
|
||||
Xfree (b->wc);
|
||||
b->wc = NULL;
|
||||
Xfree (b->utf8);
|
||||
b->utf8 = NULL;
|
||||
|
||||
b->treeused = b->treesize = 0;
|
||||
b->mbused = b->mbsize = 0;
|
||||
b->wcused = b->wcsize = 0;
|
||||
b->utf8used = b->utf8size = 0;
|
||||
}
|
||||
|
||||
void
|
||||
_XimLocalIMFree(
|
||||
Xim im)
|
||||
{
|
||||
XimFreeDefaultTree(&im->private.local.base);
|
||||
im->private.local.top = 0;
|
||||
|
||||
Xfree(im->core.im_resources);
|
||||
im->core.im_resources = NULL;
|
||||
|
||||
Xfree(im->core.ic_resources);
|
||||
im->core.ic_resources = NULL;
|
||||
|
||||
Xfree(im->core.im_values_list);
|
||||
im->core.im_values_list = NULL;
|
||||
|
||||
Xfree(im->core.ic_values_list);
|
||||
im->core.ic_values_list = NULL;
|
||||
|
||||
Xfree(im->core.styles);
|
||||
im->core.styles = NULL;
|
||||
|
||||
Xfree(im->core.res_name);
|
||||
im->core.res_name = NULL;
|
||||
|
||||
Xfree(im->core.res_class);
|
||||
im->core.res_class = NULL;
|
||||
|
||||
Xfree(im->core.im_name);
|
||||
im->core.im_name = NULL;
|
||||
|
||||
if (im->private.local.ctom_conv) {
|
||||
_XlcCloseConverter(im->private.local.ctom_conv);
|
||||
im->private.local.ctom_conv = NULL;
|
||||
}
|
||||
if (im->private.local.ctow_conv) {
|
||||
_XlcCloseConverter(im->private.local.ctow_conv);
|
||||
im->private.local.ctow_conv = NULL;
|
||||
}
|
||||
if (im->private.local.ctoutf8_conv) {
|
||||
_XlcCloseConverter(im->private.local.ctoutf8_conv);
|
||||
im->private.local.ctoutf8_conv = NULL;
|
||||
}
|
||||
if (im->private.local.cstomb_conv) {
|
||||
_XlcCloseConverter(im->private.local.cstomb_conv);
|
||||
im->private.local.cstomb_conv = NULL;
|
||||
}
|
||||
if (im->private.local.cstowc_conv) {
|
||||
_XlcCloseConverter(im->private.local.cstowc_conv);
|
||||
im->private.local.cstowc_conv = NULL;
|
||||
}
|
||||
if (im->private.local.cstoutf8_conv) {
|
||||
_XlcCloseConverter(im->private.local.cstoutf8_conv);
|
||||
im->private.local.cstoutf8_conv = NULL;
|
||||
}
|
||||
if (im->private.local.ucstoc_conv) {
|
||||
_XlcCloseConverter(im->private.local.ucstoc_conv);
|
||||
im->private.local.ucstoc_conv = NULL;
|
||||
}
|
||||
if (im->private.local.ucstoutf8_conv) {
|
||||
_XlcCloseConverter(im->private.local.ucstoutf8_conv);
|
||||
im->private.local.ucstoutf8_conv = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static Status
|
||||
_XimLocalCloseIM(
|
||||
XIM xim)
|
||||
{
|
||||
Xim im = (Xim)xim;
|
||||
XIC ic;
|
||||
XIC next;
|
||||
|
||||
ic = im->core.ic_chain;
|
||||
im->core.ic_chain = NULL;
|
||||
while (ic) {
|
||||
(*ic->methods->destroy) (ic);
|
||||
next = ic->core.next;
|
||||
Xfree (ic);
|
||||
ic = next;
|
||||
}
|
||||
_XimLocalIMFree(im);
|
||||
_XimDestroyIMStructureList(im);
|
||||
return(True);
|
||||
}
|
||||
|
||||
char *
|
||||
_XimLocalGetIMValues(
|
||||
XIM xim,
|
||||
XIMArg *values)
|
||||
{
|
||||
Xim im = (Xim)xim;
|
||||
XimDefIMValues im_values;
|
||||
|
||||
_XimGetCurrentIMValues(im, &im_values);
|
||||
return(_XimGetIMValueData(im, (XPointer)&im_values, values,
|
||||
im->core.im_resources, im->core.im_num_resources));
|
||||
}
|
||||
|
||||
char *
|
||||
_XimLocalSetIMValues(
|
||||
XIM xim,
|
||||
XIMArg *values)
|
||||
{
|
||||
Xim im = (Xim)xim;
|
||||
XimDefIMValues im_values;
|
||||
char *name = (char *)NULL;
|
||||
|
||||
_XimGetCurrentIMValues(im, &im_values);
|
||||
name = _XimSetIMValueData(im, (XPointer)&im_values, values,
|
||||
im->core.im_resources, im->core.im_num_resources);
|
||||
_XimSetCurrentIMValues(im, &im_values);
|
||||
return(name);
|
||||
}
|
||||
|
||||
|
||||
#ifdef COMPOSECACHE
|
||||
|
||||
static Bool
|
||||
_XimReadCachedDefaultTree(
|
||||
int fd_cache,
|
||||
const char *name,
|
||||
const char *encoding,
|
||||
DTStructIndex size)
|
||||
{
|
||||
struct _XimCacheStruct* m;
|
||||
int namelen = strlen (name) + 1;
|
||||
int encodinglen = strlen (encoding) + 1;
|
||||
|
||||
m = mmap (NULL, size, PROT_READ, MAP_PRIVATE, fd_cache, 0);
|
||||
if (m == NULL || m == MAP_FAILED)
|
||||
return False;
|
||||
assert (m->id == XIM_CACHE_MAGIC);
|
||||
assert (m->version == XIM_CACHE_VERSION);
|
||||
if (size != m->size ||
|
||||
size < sizeof (struct _XimCacheStruct) + namelen + encodinglen) {
|
||||
fprintf (stderr, "Ignoring broken XimCache %s [%s]\n", name, encoding);
|
||||
munmap (m, size);
|
||||
return False;
|
||||
}
|
||||
if (strncmp (name, m->fname, namelen) != 0) {
|
||||
/* m->fname may *not* be terminated - but who cares here */
|
||||
fprintf (stderr, "Filename hash clash - expected %s, got %s\n",
|
||||
name, m->fname);
|
||||
munmap (m, size);
|
||||
return False;
|
||||
}
|
||||
if (strncmp (encoding, m->fname + namelen, encodinglen) != 0) {
|
||||
/* m->fname+namelen may *not* be terminated - but who cares here */
|
||||
fprintf (stderr, "Enoding hash clash - expected %s, got %s\n",
|
||||
encoding, m->fname + namelen);
|
||||
munmap (m, size);
|
||||
return False;
|
||||
}
|
||||
_XimCache_mmap = m;
|
||||
_XimCachedDefaultTreeBase.tree = (DefTree *) (((char *) m) + m->tree);
|
||||
_XimCachedDefaultTreeBase.mb = (((char *) m) + m->mb);
|
||||
_XimCachedDefaultTreeBase.wc = (wchar_t *) (((char *) m) + m->wc);
|
||||
_XimCachedDefaultTreeBase.utf8 = (((char *) m) + m->utf8);
|
||||
_XimCachedDefaultTreeBase.treeused = m->treeused;
|
||||
_XimCachedDefaultTreeBase.mbused = m->mbused;
|
||||
_XimCachedDefaultTreeBase.wcused = m->wcused;
|
||||
_XimCachedDefaultTreeBase.utf8used = m->utf8used;
|
||||
/* treesize etc. is ignored because only used during parsing */
|
||||
_XimCachedDefaultTreeRefcount = 0;
|
||||
/* fprintf (stderr, "read cached tree at %p: %s\n", (void *) m, name); */
|
||||
return True;
|
||||
}
|
||||
|
||||
static unsigned int strToHash (
|
||||
const char *name)
|
||||
{
|
||||
unsigned int hash = 0;
|
||||
while (*name)
|
||||
hash = hash * XIM_HASH_PRIME_1 + *(unsigned const char *)name++;
|
||||
return hash % XIM_HASH_PRIME_2;
|
||||
}
|
||||
|
||||
|
||||
/* Returns read-only fd of cache file, -1 if none.
|
||||
* Sets *res to cache filename if safe. Sets *size to file size of cache. */
|
||||
static int _XimCachedFileName (
|
||||
const char *dir, const char *name,
|
||||
const char *intname, const char *encoding,
|
||||
uid_t uid, int isglobal, char **res, off_t *size)
|
||||
{
|
||||
struct stat st_name, st;
|
||||
int fd;
|
||||
unsigned int len, hash, hash2;
|
||||
struct _XimCacheStruct *m;
|
||||
/* There are some races here with 'dir', but we are either in our own home
|
||||
* or the global cache dir, and not inside some public writable dir */
|
||||
/* fprintf (stderr, "XimCachedFileName for dir %s name %s intname %s encoding %s uid %d\n", dir, name, intname, encoding, uid); */
|
||||
if (stat (name, &st_name) == -1 || ! S_ISREG (st_name.st_mode)
|
||||
|| stat (dir, &st) == -1 || ! S_ISDIR (st.st_mode) || st.st_uid != uid
|
||||
|| (st.st_mode & 0022) != 0000) {
|
||||
*res = NULL;
|
||||
return -1;
|
||||
}
|
||||
len = strlen (dir);
|
||||
hash = strToHash (intname);
|
||||
hash2 = strToHash (encoding);
|
||||
*res = Xmalloc (len + 1 + 27 + 1); /* Max VERSION 9999 */
|
||||
|
||||
if (len == 0 || dir [len-1] != '/')
|
||||
sprintf (*res, "%s/%c%d_%03x_%08x_%08x", dir, _XimGetMyEndian(),
|
||||
XIM_CACHE_VERSION, (unsigned int)sizeof (DefTree), hash, hash2);
|
||||
else
|
||||
sprintf (*res, "%s%c%d_%03x_%08x_%08x", dir, _XimGetMyEndian(),
|
||||
XIM_CACHE_VERSION, (unsigned int)sizeof (DefTree), hash, hash2);
|
||||
|
||||
/* fprintf (stderr, "-> %s\n", *res); */
|
||||
if ( (fd = _XOpenFile (*res, O_RDONLY)) == -1)
|
||||
return -1;
|
||||
|
||||
if (fstat (fd, &st) == -1) {
|
||||
Xfree (*res);
|
||||
*res = NULL;
|
||||
close (fd);
|
||||
return -1;
|
||||
}
|
||||
*size = st.st_size;
|
||||
|
||||
if (! S_ISREG (st.st_mode) || st.st_uid != uid
|
||||
|| (st.st_mode & 0022) != 0000 || st.st_mtime <= st_name.st_mtime
|
||||
|| (st.st_mtime < time (NULL) - 24*60*60 && ! isglobal)) {
|
||||
|
||||
close (fd);
|
||||
if (unlink (*res) != 0) {
|
||||
Xfree (*res);
|
||||
*res = NULL; /* cache is not safe */
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
m = mmap (NULL, sizeof (struct _XimCacheStruct), PROT_READ, MAP_PRIVATE,
|
||||
fd, 0);
|
||||
if (m == NULL || m == MAP_FAILED) {
|
||||
close (fd);
|
||||
Xfree (*res);
|
||||
*res = NULL;
|
||||
return -1;
|
||||
}
|
||||
if (*size < sizeof (struct _XimCacheStruct) || m->id != XIM_CACHE_MAGIC) {
|
||||
munmap (m, sizeof (struct _XimCacheStruct));
|
||||
close (fd);
|
||||
fprintf (stderr, "Ignoring broken XimCache %s\n", *res);
|
||||
Xfree (*res);
|
||||
*res = NULL;
|
||||
return -1;
|
||||
}
|
||||
if (m->version != XIM_CACHE_VERSION) {
|
||||
munmap (m, sizeof (struct _XimCacheStruct));
|
||||
close (fd);
|
||||
if (unlink (*res) != 0) {
|
||||
Xfree (*res);
|
||||
*res = NULL; /* cache is not safe */
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
munmap (m, sizeof (struct _XimCacheStruct));
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
static Bool _XimLoadCache (
|
||||
int fd,
|
||||
const char *name,
|
||||
const char *encoding,
|
||||
off_t size,
|
||||
Xim im)
|
||||
{
|
||||
if (_XimCache_mmap ||
|
||||
_XimReadCachedDefaultTree (fd, name, encoding, size)) {
|
||||
_XimCachedDefaultTreeRefcount++;
|
||||
memcpy (&im->private.local.base, &_XimCachedDefaultTreeBase,
|
||||
sizeof (_XimCachedDefaultTreeBase));
|
||||
im->private.local.top = _XimCache_mmap->top;
|
||||
return True;
|
||||
}
|
||||
|
||||
return False;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
_XimWriteCachedDefaultTree(
|
||||
const char *name,
|
||||
const char *encoding,
|
||||
const char *cachename,
|
||||
Xim im)
|
||||
{
|
||||
int fd;
|
||||
FILE *fp;
|
||||
struct _XimCacheStruct *m;
|
||||
int msize = (sizeof(struct _XimCacheStruct)
|
||||
+ strlen(name) + strlen(encoding) + 2
|
||||
+ XIM_CACHE_TREE_ALIGNMENT-1) & -XIM_CACHE_TREE_ALIGNMENT;
|
||||
DefTreeBase *b = &im->private.local.base;
|
||||
|
||||
if (! b->tree && ! (b->tree = Xcalloc (1, sizeof(DefTree))) )
|
||||
return;
|
||||
if (! b->mb && ! (b->mb = Xmalloc (1)) )
|
||||
return;
|
||||
if (! b->wc && ! (b->wc = Xmalloc (sizeof(wchar_t))) )
|
||||
return;
|
||||
if (! b->utf8 && ! (b->utf8 = Xmalloc (1)) )
|
||||
return;
|
||||
|
||||
/* First entry is always unused */
|
||||
b->mb[0] = 0;
|
||||
b->wc[0] = 0;
|
||||
b->utf8[0] = 0;
|
||||
|
||||
m = Xcalloc (1, msize);
|
||||
m->id = XIM_CACHE_MAGIC;
|
||||
m->version = XIM_CACHE_VERSION;
|
||||
m->top = im->private.local.top;
|
||||
m->treeused = b->treeused;
|
||||
m->mbused = b->mbused;
|
||||
m->wcused = b->wcused;
|
||||
m->utf8used = b->utf8used;
|
||||
/* Tree first, then wide chars, then the rest due to alignment */
|
||||
m->tree = msize;
|
||||
m->wc = msize + sizeof (DefTree) * m->treeused;
|
||||
m->mb = m->wc + sizeof (wchar_t) * m->wcused;
|
||||
m->utf8 = m->mb + m->mbused;
|
||||
m->size = m->utf8 + m->utf8used;
|
||||
strcpy (m->fname, name);
|
||||
strcpy (m->fname+strlen(name)+1, encoding);
|
||||
|
||||
/* This STILL might be racy on NFS */
|
||||
if ( (fd = _XOpenFileMode (cachename, O_WRONLY | O_CREAT | O_EXCL,
|
||||
0600)) < 0) {
|
||||
Xfree(m);
|
||||
return;
|
||||
}
|
||||
if (! (fp = fdopen (fd, "wb")) ) {
|
||||
close (fd);
|
||||
Xfree(m);
|
||||
return;
|
||||
}
|
||||
fwrite (m, msize, 1, fp);
|
||||
fwrite (im->private.local.base.tree, sizeof(DefTree), m->treeused, fp);
|
||||
fwrite (im->private.local.base.wc, sizeof(wchar_t), m->wcused, fp);
|
||||
fwrite (im->private.local.base.mb, 1, m->mbused, fp);
|
||||
fwrite (im->private.local.base.utf8, 1, m->utf8used, fp);
|
||||
if (fclose (fp) != 0)
|
||||
unlink (cachename);
|
||||
_XimCache_mmap = m;
|
||||
memcpy (&_XimCachedDefaultTreeBase, &im->private.local.base,
|
||||
sizeof (_XimCachedDefaultTreeBase));
|
||||
/* fprintf (stderr, "wrote tree %s size %ld to %s\n", name, m->size, cachename); */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
_XimCreateDefaultTree(
|
||||
Xim im)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
char *name, *tmpname = NULL;
|
||||
char *cachename = NULL;
|
||||
/* Should use getpwent() instead of $HOME (cross-platform?) */
|
||||
char *home = getenv("HOME");
|
||||
char *tmpcachedir = NULL;
|
||||
int hl = home ? strlen (home) : 0;
|
||||
#ifdef COMPOSECACHE
|
||||
char *intname;
|
||||
char *cachedir = NULL;
|
||||
const char *encoding = nl_langinfo (CODESET);
|
||||
uid_t euid = geteuid ();
|
||||
gid_t egid = getegid ();
|
||||
int cachefd = -1;
|
||||
off_t size;
|
||||
#endif
|
||||
|
||||
name = getenv("XCOMPOSEFILE");
|
||||
if (name == (char *) NULL) {
|
||||
if (home != (char *) NULL) {
|
||||
tmpname = name = Xmalloc(hl + 10 + 1);
|
||||
if (name != (char *) NULL) {
|
||||
int fd;
|
||||
strcpy(name, home);
|
||||
strcpy(name + hl, "/.XCompose");
|
||||
if ( (fd = _XOpenFile (name, O_RDONLY)) < 0) {
|
||||
Xfree (name);
|
||||
name = tmpname = NULL;
|
||||
} else
|
||||
close (fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (name == (char *) NULL) {
|
||||
tmpname = name = _XlcFileName(im->core.lcd, COMPOSE_FILE);
|
||||
}
|
||||
#ifdef COMPOSECACHE
|
||||
intname = name;
|
||||
|
||||
if (getuid () == euid && getgid () == egid && euid != 0) {
|
||||
char *c;
|
||||
/* Usage: XCOMPOSECACHE=<cachedir>[=<filename>]
|
||||
* cachedir: directory of cache files
|
||||
* filename: internally used name for cache file */
|
||||
cachedir = getenv("XCOMPOSECACHE");
|
||||
if (cachedir && (c = strchr (cachedir, '='))) {
|
||||
tmpcachedir = strdup (cachedir);
|
||||
intname = tmpcachedir + (c-cachedir) + 1;
|
||||
tmpcachedir[c-cachedir] = '\0';
|
||||
cachedir = tmpcachedir;
|
||||
}
|
||||
}
|
||||
|
||||
if (! cachedir) {
|
||||
cachefd = _XimCachedFileName (XIM_GLOBAL_CACHE_DIR, name, intname,
|
||||
encoding, 0, 1, &cachename, &size);
|
||||
if (cachefd != -1) {
|
||||
if (_XimLoadCache (cachefd, intname, encoding, size, im)) {
|
||||
Xfree (tmpcachedir);
|
||||
Xfree (tmpname);
|
||||
Xfree (cachename);
|
||||
close (cachefd);
|
||||
return;
|
||||
}
|
||||
close (cachefd);
|
||||
}
|
||||
Xfree (cachename);
|
||||
cachename = NULL;
|
||||
}
|
||||
|
||||
if (getuid () == euid && getgid () == egid && euid != 0 && home) {
|
||||
|
||||
if (! cachedir) {
|
||||
tmpcachedir = cachedir = Xmalloc (hl+strlen(XIM_HOME_CACHE_DIR)+1);
|
||||
strcpy (cachedir, home);
|
||||
strcat (cachedir, XIM_HOME_CACHE_DIR);
|
||||
}
|
||||
cachefd = _XimCachedFileName (cachedir, name, intname, encoding,
|
||||
euid, 0, &cachename, &size);
|
||||
if (cachefd != -1) {
|
||||
if (_XimLoadCache (cachefd, intname, encoding, size, im)) {
|
||||
Xfree (tmpcachedir);
|
||||
Xfree (tmpname);
|
||||
Xfree (cachename);
|
||||
close (cachefd);
|
||||
return;
|
||||
}
|
||||
close (cachefd);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (! (fp = _XFopenFile (name, "r"))) {
|
||||
Xfree (tmpcachedir);
|
||||
Xfree (tmpname);
|
||||
Xfree (cachename);
|
||||
return;
|
||||
}
|
||||
_XimParseStringFile(fp, im);
|
||||
fclose(fp);
|
||||
|
||||
#ifdef COMPOSECACHE
|
||||
if (cachename) {
|
||||
assert (euid != 0);
|
||||
_XimWriteCachedDefaultTree (intname, encoding, cachename, im);
|
||||
}
|
||||
#endif
|
||||
|
||||
Xfree (tmpcachedir);
|
||||
Xfree (tmpname);
|
||||
Xfree (cachename);
|
||||
}
|
||||
|
||||
static XIMMethodsRec Xim_im_local_methods = {
|
||||
_XimLocalCloseIM, /* close */
|
||||
_XimLocalSetIMValues, /* set_values */
|
||||
_XimLocalGetIMValues, /* get_values */
|
||||
_XimLocalCreateIC, /* create_ic */
|
||||
_XimLcctstombs, /* ctstombs */
|
||||
_XimLcctstowcs, /* ctstowcs */
|
||||
_XimLcctstoutf8 /* ctstoutf8 */
|
||||
};
|
||||
|
||||
Bool
|
||||
_XimLocalOpenIM(
|
||||
Xim im)
|
||||
{
|
||||
XLCd lcd = im->core.lcd;
|
||||
XlcConv conv;
|
||||
XimDefIMValues im_values;
|
||||
XimLocalPrivateRec* private = &im->private.local;
|
||||
|
||||
_XimInitialResourceInfo();
|
||||
if(_XimSetIMResourceList(&im->core.im_resources,
|
||||
&im->core.im_num_resources) == False) {
|
||||
goto Open_Error;
|
||||
}
|
||||
if(_XimSetICResourceList(&im->core.ic_resources,
|
||||
&im->core.ic_num_resources) == False) {
|
||||
goto Open_Error;
|
||||
}
|
||||
|
||||
_XimSetIMMode(im->core.im_resources, im->core.im_num_resources);
|
||||
|
||||
_XimGetCurrentIMValues(im, &im_values);
|
||||
if(_XimSetLocalIMDefaults(im, (XPointer)&im_values,
|
||||
im->core.im_resources, im->core.im_num_resources) == False) {
|
||||
goto Open_Error;
|
||||
}
|
||||
_XimSetCurrentIMValues(im, &im_values);
|
||||
|
||||
if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte)))
|
||||
goto Open_Error;
|
||||
private->ctom_conv = conv;
|
||||
|
||||
if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar)))
|
||||
goto Open_Error;
|
||||
private->ctow_conv = conv;
|
||||
|
||||
if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNUtf8String)))
|
||||
goto Open_Error;
|
||||
private->ctoutf8_conv = conv;
|
||||
|
||||
if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte)))
|
||||
goto Open_Error;
|
||||
private->cstomb_conv = conv;
|
||||
|
||||
if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNWideChar)))
|
||||
goto Open_Error;
|
||||
private->cstowc_conv = conv;
|
||||
|
||||
if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNUtf8String)))
|
||||
goto Open_Error;
|
||||
private->cstoutf8_conv = conv;
|
||||
|
||||
if (!(conv = _XlcOpenConverter(lcd, XlcNUcsChar, lcd, XlcNChar)))
|
||||
goto Open_Error;
|
||||
private->ucstoc_conv = conv;
|
||||
|
||||
if (!(conv = _XlcOpenConverter(lcd, XlcNUcsChar, lcd, XlcNUtf8String)))
|
||||
goto Open_Error;
|
||||
private->ucstoutf8_conv = conv;
|
||||
|
||||
private->base.treeused = 1;
|
||||
private->base.mbused = 1;
|
||||
private->base.wcused = 1;
|
||||
private->base.utf8used = 1;
|
||||
|
||||
_XimCreateDefaultTree(im);
|
||||
|
||||
im->methods = &Xim_im_local_methods;
|
||||
private->current_ic = (XIC)NULL;
|
||||
|
||||
return(True);
|
||||
|
||||
Open_Error :
|
||||
_XimLocalIMFree(im);
|
||||
return(False);
|
||||
}
|
||||
417
nx-X11/lib/modules/im/ximcp/imLcLkup.c
Normal file
417
nx-X11/lib/modules/im/ximcp/imLcLkup.c
Normal file
@@ -0,0 +1,417 @@
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1992 by Fuji Xerox Co., Ltd.
|
||||
Copyright 1992, 1994 by FUJITSU LIMITED
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and
|
||||
that both that copyright notice and this permission notice appear
|
||||
in supporting documentation, and that the name of Fuji Xerox,
|
||||
FUJITSU LIMITED not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission. Fuji Xerox, FUJITSU LIMITED make no representations
|
||||
about the suitability of this software for any purpose.
|
||||
It is provided "as is" without express or implied warranty.
|
||||
|
||||
FUJI XEROX, FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJI XEROX,
|
||||
FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
|
||||
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
|
||||
OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Author: Kazunori Nishihara Fuji Xerox
|
||||
Takashi Fujiwara FUJITSU LIMITED
|
||||
fujiwara@a80.tech.yk.fujitsu.co.jp
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <nx-X11/Xatom.h>
|
||||
#include <nx-X11/Xos.h>
|
||||
#include <nx-X11/Xlib.h>
|
||||
#include <nx-X11/keysym.h>
|
||||
#include <nx-X11/Xutil.h>
|
||||
#include "Xlibint.h"
|
||||
#include "Xlcint.h"
|
||||
#include "XlcPubI.h"
|
||||
#include "Ximint.h"
|
||||
|
||||
int
|
||||
_XimLocalMbLookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes,
|
||||
KeySym *keysym, Status *status)
|
||||
{
|
||||
Xic ic = (Xic)xic;
|
||||
int ret;
|
||||
DefTree *b = ic->private.local.base.tree;
|
||||
char *mb = ic->private.local.base.mb;
|
||||
|
||||
if(ev->type != KeyPress) {
|
||||
if(status) *status = XLookupNone;
|
||||
return(0);
|
||||
}
|
||||
if(ev->keycode == 0 &&
|
||||
( (ic->private.local.composed != 0)
|
||||
||(ic->private.local.brl_committed != 0))) {
|
||||
if (ic->private.local.brl_committed != 0) { /* Braille Event */
|
||||
unsigned char pattern = ic->private.local.brl_committed;
|
||||
char mb2[XLC_PUBLIC(ic->core.im->core.lcd, mb_cur_max)];
|
||||
ret = _Xlcwctomb(ic->core.im->core.lcd, mb2, BRL_UC_ROW | pattern);
|
||||
if(ret > bytes) {
|
||||
if(status) *status = XBufferOverflow;
|
||||
return(ret);
|
||||
}
|
||||
if(keysym) *keysym = XK_braille_blank | pattern;
|
||||
if(ret > 0) {
|
||||
if (keysym) {
|
||||
if(status) *status = XLookupBoth;
|
||||
} else {
|
||||
if(status) *status = XLookupChars;
|
||||
}
|
||||
memcpy(buffer, mb2, ret);
|
||||
} else {
|
||||
if(keysym) {
|
||||
if(status) *status = XLookupKeySym;
|
||||
} else {
|
||||
if(status) *status = XLookupNone;
|
||||
}
|
||||
}
|
||||
} else { /* Composed Event */
|
||||
ret = strlen(&mb[b[ic->private.local.composed].mb]);
|
||||
if(ret > bytes) {
|
||||
if(status) *status = XBufferOverflow;
|
||||
return(ret);
|
||||
}
|
||||
memcpy(buffer, &mb[b[ic->private.local.composed].mb], ret);
|
||||
if(keysym) *keysym = b[ic->private.local.composed].ks;
|
||||
if (ret > 0) {
|
||||
if (keysym && *keysym != NoSymbol) {
|
||||
if(status) *status = XLookupBoth;
|
||||
} else {
|
||||
if(status) *status = XLookupChars;
|
||||
}
|
||||
} else {
|
||||
if(keysym && *keysym != NoSymbol) {
|
||||
if(status) *status = XLookupKeySym;
|
||||
} else {
|
||||
if(status) *status = XLookupNone;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (ret);
|
||||
} else { /* Throughed Event */
|
||||
ret = _XimLookupMBText(ic, ev, buffer, bytes, keysym, NULL);
|
||||
if(ret > 0) {
|
||||
if (ret > bytes) {
|
||||
if (status) *status = XBufferOverflow;
|
||||
} else if (keysym && *keysym != NoSymbol) {
|
||||
if(status) *status = XLookupBoth;
|
||||
} else {
|
||||
if(status) *status = XLookupChars;
|
||||
}
|
||||
} else {
|
||||
if(keysym && *keysym != NoSymbol) {
|
||||
if(status) *status = XLookupKeySym;
|
||||
} else {
|
||||
if(status) *status = XLookupNone;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
_XimLocalWcLookupString(XIC xic, XKeyEvent *ev, wchar_t *buffer, int wlen,
|
||||
KeySym *keysym, Status *status)
|
||||
{
|
||||
Xic ic = (Xic)xic;
|
||||
int ret;
|
||||
DefTree *b = ic->private.local.base.tree;
|
||||
wchar_t *wc = ic->private.local.base.wc;
|
||||
|
||||
if(ev->type != KeyPress) {
|
||||
if(status) *status = XLookupNone;
|
||||
return(0);
|
||||
}
|
||||
if(ev->keycode == 0) {
|
||||
if (ic->private.local.brl_committed != 0) { /* Braille Event */
|
||||
unsigned char pattern = ic->private.local.brl_committed;
|
||||
ret = 1;
|
||||
if (ret > wlen) {
|
||||
if(status) *status = XBufferOverflow;
|
||||
return (ret);
|
||||
}
|
||||
*buffer = BRL_UC_ROW | pattern;
|
||||
if(keysym) {
|
||||
*keysym = XK_braille_blank | pattern;
|
||||
if(status) *status = XLookupBoth;
|
||||
} else
|
||||
if(status) *status = XLookupChars;
|
||||
} else { /* Composed Event */
|
||||
ret = _Xwcslen(&wc[b[ic->private.local.composed].wc]);
|
||||
if(ret > wlen) {
|
||||
if(status) *status = XBufferOverflow;
|
||||
return (ret);
|
||||
}
|
||||
memcpy((char *)buffer, (char *)&wc[b[ic->private.local.composed].wc],
|
||||
ret * sizeof(wchar_t));
|
||||
if(keysym) *keysym = b[ic->private.local.composed].ks;
|
||||
if (ret > 0) {
|
||||
if (keysym && *keysym != NoSymbol) {
|
||||
if(status) *status = XLookupBoth;
|
||||
} else {
|
||||
if(status) *status = XLookupChars;
|
||||
}
|
||||
} else {
|
||||
if(keysym && *keysym != NoSymbol) {
|
||||
if(status) *status = XLookupKeySym;
|
||||
} else {
|
||||
if(status) *status = XLookupNone;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (ret);
|
||||
} else { /* Throughed Event */
|
||||
ret = _XimLookupWCText(ic, ev, buffer, wlen, keysym, NULL);
|
||||
if(ret > 0) {
|
||||
if (ret > wlen) {
|
||||
if (status) *status = XBufferOverflow;
|
||||
} else if (keysym && *keysym != NoSymbol) {
|
||||
if(status) *status = XLookupBoth;
|
||||
} else {
|
||||
if(status) *status = XLookupChars;
|
||||
}
|
||||
} else {
|
||||
if(keysym && *keysym != NoSymbol) {
|
||||
if(status) *status = XLookupKeySym;
|
||||
} else {
|
||||
if(status) *status = XLookupNone;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
_XimLocalUtf8LookupString(XIC xic, XKeyEvent *ev, char *buffer, int bytes,
|
||||
KeySym *keysym, Status *status)
|
||||
{
|
||||
Xic ic = (Xic)xic;
|
||||
int ret;
|
||||
DefTree *b = ic->private.local.base.tree;
|
||||
char *utf8 = ic->private.local.base.utf8;
|
||||
|
||||
if(ev->type != KeyPress) {
|
||||
if(status) *status = XLookupNone;
|
||||
return(0);
|
||||
}
|
||||
if(ev->keycode == 0) {
|
||||
if (ic->private.local.brl_committed != 0) { /* Braille Event */
|
||||
unsigned char pattern = ic->private.local.brl_committed;
|
||||
ret = 3;
|
||||
if (ret > bytes) {
|
||||
if(status) *status = XBufferOverflow;
|
||||
return (ret);
|
||||
}
|
||||
buffer[0] = 0xe0 | ((BRL_UC_ROW >> 12) & 0x0f);
|
||||
buffer[1] = 0x80 | ((BRL_UC_ROW >> 8) & 0x30) | (pattern >> 6);
|
||||
buffer[2] = 0x80 | (pattern & 0x3f);
|
||||
if(keysym) {
|
||||
*keysym = XK_braille_blank | pattern;
|
||||
if(status) *status = XLookupBoth;
|
||||
} else
|
||||
if(status) *status = XLookupChars;
|
||||
} else { /* Composed Event */
|
||||
ret = strlen(&utf8[b[ic->private.local.composed].utf8]);
|
||||
if(ret > bytes) {
|
||||
if(status) *status = XBufferOverflow;
|
||||
return (ret);
|
||||
}
|
||||
memcpy(buffer, &utf8[b[ic->private.local.composed].utf8], ret);
|
||||
if(keysym) *keysym = b[ic->private.local.composed].ks;
|
||||
if (ret > 0) {
|
||||
if (keysym && *keysym != NoSymbol) {
|
||||
if(status) *status = XLookupBoth;
|
||||
} else {
|
||||
if(status) *status = XLookupChars;
|
||||
}
|
||||
} else {
|
||||
if(keysym && *keysym != NoSymbol) {
|
||||
if(status) *status = XLookupKeySym;
|
||||
} else {
|
||||
if(status) *status = XLookupNone;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (ret);
|
||||
} else { /* Throughed Event */
|
||||
ret = _XimLookupUTF8Text(ic, ev, buffer, bytes, keysym, NULL);
|
||||
if(ret > 0) {
|
||||
if (ret > bytes) {
|
||||
if (status) *status = XBufferOverflow;
|
||||
} else if (keysym && *keysym != NoSymbol) {
|
||||
if(status) *status = XLookupBoth;
|
||||
} else {
|
||||
if(status) *status = XLookupChars;
|
||||
}
|
||||
} else {
|
||||
if(keysym && *keysym != NoSymbol) {
|
||||
if(status) *status = XLookupKeySym;
|
||||
} else {
|
||||
if(status) *status = XLookupNone;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
static int
|
||||
_XimLcctsconvert(
|
||||
XlcConv conv,
|
||||
char *from,
|
||||
int from_len,
|
||||
char *to,
|
||||
int to_len,
|
||||
Status *state)
|
||||
{
|
||||
int from_left;
|
||||
int to_left;
|
||||
int from_savelen;
|
||||
int to_savelen;
|
||||
int from_cnvlen;
|
||||
int to_cnvlen;
|
||||
char *from_buf;
|
||||
char *to_buf;
|
||||
char scratchbuf[BUFSIZ];
|
||||
Status tmp_state;
|
||||
|
||||
if (!state)
|
||||
state = &tmp_state;
|
||||
|
||||
if (!conv || !from || !from_len) {
|
||||
*state = XLookupNone;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Reset the converter. The CompoundText at 'from' starts in
|
||||
initial state. */
|
||||
_XlcResetConverter(conv);
|
||||
|
||||
from_left = from_len;
|
||||
to_left = BUFSIZ;
|
||||
from_cnvlen = 0;
|
||||
to_cnvlen = 0;
|
||||
for (;;) {
|
||||
from_buf = &from[from_cnvlen];
|
||||
from_savelen = from_left;
|
||||
to_buf = &scratchbuf[to_cnvlen];
|
||||
to_savelen = to_left;
|
||||
if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
|
||||
(XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
|
||||
*state = XLookupNone;
|
||||
return 0;
|
||||
}
|
||||
from_cnvlen += (from_savelen - from_left);
|
||||
to_cnvlen += (to_savelen - to_left);
|
||||
if (from_left == 0) {
|
||||
if (!to_cnvlen) {
|
||||
*state = XLookupNone;
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!to || !to_len || (to_len < to_cnvlen)) {
|
||||
*state = XBufferOverflow;
|
||||
} else {
|
||||
memcpy(to, scratchbuf, to_cnvlen);
|
||||
*state = XLookupChars;
|
||||
}
|
||||
return to_cnvlen;
|
||||
}
|
||||
|
||||
int
|
||||
_XimLcctstombs(XIM xim, char *from, int from_len,
|
||||
char *to, int to_len, Status *state)
|
||||
{
|
||||
return _XimLcctsconvert(((Xim)xim)->private.local.ctom_conv,
|
||||
from, from_len, to, to_len, state);
|
||||
}
|
||||
|
||||
int
|
||||
_XimLcctstowcs(XIM xim, char *from, int from_len,
|
||||
wchar_t *to, int to_len, Status *state)
|
||||
{
|
||||
Xim im = (Xim)xim;
|
||||
XlcConv conv = im->private.local.ctow_conv;
|
||||
int from_left;
|
||||
int to_left;
|
||||
int from_savelen;
|
||||
int to_savelen;
|
||||
int from_cnvlen;
|
||||
int to_cnvlen;
|
||||
char *from_buf;
|
||||
wchar_t *to_buf;
|
||||
wchar_t scratchbuf[BUFSIZ];
|
||||
Status tmp_state;
|
||||
|
||||
if (!state)
|
||||
state = &tmp_state;
|
||||
|
||||
if (!conv || !from || !from_len) {
|
||||
*state = XLookupNone;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Reset the converter. The CompoundText at 'from' starts in
|
||||
initial state. */
|
||||
_XlcResetConverter(conv);
|
||||
|
||||
from_left = from_len;
|
||||
to_left = BUFSIZ;
|
||||
from_cnvlen = 0;
|
||||
to_cnvlen = 0;
|
||||
for (;;) {
|
||||
from_buf = &from[from_cnvlen];
|
||||
from_savelen = from_left;
|
||||
to_buf = &scratchbuf[to_cnvlen];
|
||||
to_savelen = to_left;
|
||||
if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
|
||||
(XPointer *)&to_buf, &to_left, NULL, 0) < 0) {
|
||||
*state = XLookupNone;
|
||||
return 0;
|
||||
}
|
||||
from_cnvlen += (from_savelen - from_left);
|
||||
to_cnvlen += (to_savelen - to_left);
|
||||
if (from_left == 0) {
|
||||
if (!to_cnvlen){
|
||||
*state = XLookupNone;
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!to || !to_len || (to_len < to_cnvlen)) {
|
||||
*state = XBufferOverflow;
|
||||
} else {
|
||||
memcpy(to, scratchbuf, to_cnvlen * sizeof(wchar_t));
|
||||
*state = XLookupChars;
|
||||
}
|
||||
return to_cnvlen;
|
||||
}
|
||||
|
||||
int
|
||||
_XimLcctstoutf8(XIM xim, char *from, int from_len,
|
||||
char *to, int to_len, Status *state)
|
||||
{
|
||||
return _XimLcctsconvert(((Xim)xim)->private.local.ctoutf8_conv,
|
||||
from, from_len, to, to_len, state);
|
||||
}
|
||||
743
nx-X11/lib/modules/im/ximcp/imLcPrs.c
Normal file
743
nx-X11/lib/modules/im/ximcp/imLcPrs.c
Normal file
@@ -0,0 +1,743 @@
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1992 by Oki Technosystems Laboratory, Inc.
|
||||
Copyright 1992 by Fuji Xerox Co., Ltd.
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and
|
||||
that both that copyright notice and this permission notice appear
|
||||
in supporting documentation, and that the name of Oki Technosystems
|
||||
Laboratory and Fuji Xerox not be used in advertising or publicity
|
||||
pertaining to distribution of the software without specific, written
|
||||
prior permission.
|
||||
Oki Technosystems Laboratory and Fuji Xerox make no representations
|
||||
about the suitability of this software for any purpose. It is provided
|
||||
"as is" without express or implied warranty.
|
||||
|
||||
OKI TECHNOSYSTEMS LABORATORY AND FUJI XEROX DISCLAIM ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL OKI TECHNOSYSTEMS
|
||||
LABORATORY AND FUJI XEROX BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
||||
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
|
||||
OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Author: Yasuhiro Kawai Oki Technosystems Laboratory
|
||||
Author: Kazunori Nishihara Fuji Xerox
|
||||
|
||||
******************************************************************/
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <nx-X11/Xlib.h>
|
||||
#include <nx-X11/Xmd.h>
|
||||
#include <nx-X11/Xos.h>
|
||||
#include "Xlibint.h"
|
||||
#include "Xlcint.h"
|
||||
#include "Ximint.h"
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include "pathmax.h"
|
||||
|
||||
#define XLC_BUFSIZE 256
|
||||
|
||||
extern int _Xmbstowcs(
|
||||
wchar_t *wstr,
|
||||
char *str,
|
||||
int len
|
||||
);
|
||||
|
||||
extern int _Xmbstoutf8(
|
||||
char *ustr,
|
||||
const char *str,
|
||||
int len
|
||||
);
|
||||
|
||||
static void parsestringfile(FILE *fp, Xim im, int depth);
|
||||
|
||||
/*
|
||||
* Parsing File Format:
|
||||
*
|
||||
* FILE ::= { [PRODUCTION] [COMMENT] "\n"}
|
||||
* PRODUCTION ::= LHS ":" RHS [ COMMENT ]
|
||||
* COMMENT ::= "#" {<any character except null or newline>}
|
||||
* LHS ::= EVENT { EVENT }
|
||||
* EVENT ::= [MODIFIER_LIST] "<" keysym ">"
|
||||
* MODIFIER_LIST ::= (["!"] {MODIFIER} ) | "None"
|
||||
* MODIFIER ::= ["~"] MODIFIER_NAME
|
||||
* MODIFIER_NAME ::= ("Ctrl"|"Lock"|"Caps"|"Shift"|"Alt"|"Meta")
|
||||
* RHS ::= ( STRING | keysym | STRING keysym )
|
||||
* STRING ::= '"' { CHAR } '"'
|
||||
* CHAR ::= GRAPHIC_CHAR | ESCAPED_CHAR
|
||||
* GRAPHIC_CHAR ::= locale (codeset) dependent code
|
||||
* ESCAPED_CHAR ::= ('\\' | '\"' | OCTAL | HEX )
|
||||
* OCTAL ::= '\' OCTAL_CHAR [OCTAL_CHAR [OCTAL_CHAR]]
|
||||
* OCTAL_CHAR ::= (0|1|2|3|4|5|6|7)
|
||||
* HEX ::= '\' (x|X) HEX_CHAR [HEX_CHAR]]
|
||||
* HEX_CHAR ::= (0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|a|b|c|d|e|f)
|
||||
*
|
||||
*/
|
||||
|
||||
static int
|
||||
nextch(
|
||||
FILE *fp,
|
||||
int *lastch)
|
||||
{
|
||||
int c;
|
||||
|
||||
if (*lastch != 0) {
|
||||
c = *lastch;
|
||||
*lastch = 0;
|
||||
} else {
|
||||
c = getc(fp);
|
||||
if (c == '\\') {
|
||||
c = getc(fp);
|
||||
if (c == '\n') {
|
||||
c = getc(fp);
|
||||
} else {
|
||||
ungetc(c, fp);
|
||||
c = '\\';
|
||||
}
|
||||
}
|
||||
}
|
||||
return(c);
|
||||
}
|
||||
|
||||
static void
|
||||
putbackch(
|
||||
int c,
|
||||
int *lastch)
|
||||
{
|
||||
*lastch = c;
|
||||
}
|
||||
|
||||
#define ENDOFFILE 0
|
||||
#define ENDOFLINE 1
|
||||
#define COLON 2
|
||||
#define LESS 3
|
||||
#define GREATER 4
|
||||
#define EXCLAM 5
|
||||
#define TILDE 6
|
||||
#define STRING 7
|
||||
#define KEY 8
|
||||
#define ERROR 9
|
||||
|
||||
#ifndef isalnum
|
||||
#define isalnum(c) \
|
||||
(('0' <= (c) && (c) <= '9') || \
|
||||
('A' <= (c) && (c) <= 'Z') || \
|
||||
('a' <= (c) && (c) <= 'z'))
|
||||
#endif
|
||||
|
||||
static int
|
||||
nexttoken(
|
||||
FILE *fp,
|
||||
char *tokenbuf,
|
||||
int *lastch)
|
||||
{
|
||||
int c;
|
||||
int token;
|
||||
char *p;
|
||||
int i, j;
|
||||
|
||||
while ((c = nextch(fp, lastch)) == ' ' || c == '\t') {
|
||||
}
|
||||
switch (c) {
|
||||
case EOF:
|
||||
token = ENDOFFILE;
|
||||
break;
|
||||
case '\n':
|
||||
token = ENDOFLINE;
|
||||
break;
|
||||
case '<':
|
||||
token = LESS;
|
||||
break;
|
||||
case '>':
|
||||
token = GREATER;
|
||||
break;
|
||||
case ':':
|
||||
token = COLON;
|
||||
break;
|
||||
case '!':
|
||||
token = EXCLAM;
|
||||
break;
|
||||
case '~':
|
||||
token = TILDE;
|
||||
break;
|
||||
case '"':
|
||||
p = tokenbuf;
|
||||
while ((c = nextch(fp, lastch)) != '"') {
|
||||
if (c == '\n' || c == EOF) {
|
||||
putbackch(c, lastch);
|
||||
token = ERROR;
|
||||
goto string_error;
|
||||
} else if (c == '\\') {
|
||||
c = nextch(fp, lastch);
|
||||
switch (c) {
|
||||
case '\\':
|
||||
case '"':
|
||||
*p++ = c;
|
||||
break;
|
||||
case 'n':
|
||||
*p++ = '\n';
|
||||
break;
|
||||
case 'r':
|
||||
*p++ = '\r';
|
||||
break;
|
||||
case 't':
|
||||
*p++ = '\t';
|
||||
break;
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
i = c - '0';
|
||||
c = nextch(fp, lastch);
|
||||
for (j = 0; j < 2 && c >= '0' && c <= '7'; j++) {
|
||||
i <<= 3;
|
||||
i += c - '0';
|
||||
c = nextch(fp, lastch);
|
||||
}
|
||||
putbackch(c, lastch);
|
||||
*p++ = (char)i;
|
||||
break;
|
||||
case 'X':
|
||||
case 'x':
|
||||
i = 0;
|
||||
for (j = 0; j < 2; j++) {
|
||||
c = nextch(fp, lastch);
|
||||
i <<= 4;
|
||||
if (c >= '0' && c <= '9') {
|
||||
i += c - '0';
|
||||
} else if (c >= 'A' && c <= 'F') {
|
||||
i += c - 'A' + 10;
|
||||
} else if (c >= 'a' && c <= 'f') {
|
||||
i += c - 'a' + 10;
|
||||
} else {
|
||||
putbackch(c, lastch);
|
||||
i >>= 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j == 0) {
|
||||
token = ERROR;
|
||||
goto string_error;
|
||||
}
|
||||
*p++ = (char)i;
|
||||
break;
|
||||
case EOF:
|
||||
putbackch(c, lastch);
|
||||
token = ERROR;
|
||||
goto string_error;
|
||||
default:
|
||||
*p++ = c;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
*p++ = c;
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
token = STRING;
|
||||
break;
|
||||
case '#':
|
||||
while ((c = nextch(fp, lastch)) != '\n' && c != EOF) {
|
||||
}
|
||||
if (c == '\n') {
|
||||
token = ENDOFLINE;
|
||||
} else {
|
||||
token = ENDOFFILE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (isalnum(c) || c == '_' || c == '-') {
|
||||
p = tokenbuf;
|
||||
*p++ = c;
|
||||
c = nextch(fp, lastch);
|
||||
while (isalnum(c) || c == '_' || c == '-') {
|
||||
*p++ = c;
|
||||
c = nextch(fp, lastch);
|
||||
}
|
||||
*p = '\0';
|
||||
putbackch(c, lastch);
|
||||
token = KEY;
|
||||
} else {
|
||||
token = ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
string_error:
|
||||
return(token);
|
||||
}
|
||||
|
||||
static long
|
||||
modmask(
|
||||
char *name)
|
||||
{
|
||||
struct _modtbl {
|
||||
const char name[6];
|
||||
long mask;
|
||||
};
|
||||
|
||||
static const struct _modtbl tbl[] = {
|
||||
{ "Ctrl", ControlMask },
|
||||
{ "Lock", LockMask },
|
||||
{ "Caps", LockMask },
|
||||
{ "Shift", ShiftMask },
|
||||
{ "Alt", Mod1Mask },
|
||||
{ "Meta", Mod1Mask }};
|
||||
|
||||
int i, num_entries = sizeof (tbl) / sizeof (tbl[0]);
|
||||
|
||||
for (i = 0; i < num_entries; i++)
|
||||
if (!strcmp (name, tbl[i].name))
|
||||
return tbl[i].mask;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char*
|
||||
TransFileName(Xim im, char *name)
|
||||
{
|
||||
char *home = NULL, *lcCompose = NULL;
|
||||
char dir[XLC_BUFSIZE] = "";
|
||||
char *i = name, *ret = NULL, *j;
|
||||
size_t l = 0;
|
||||
|
||||
while (*i) {
|
||||
if (*i == '%') {
|
||||
i++;
|
||||
switch (*i) {
|
||||
case '%':
|
||||
l++;
|
||||
break;
|
||||
case 'H':
|
||||
if (home == NULL)
|
||||
home = getenv("HOME");
|
||||
if (home) {
|
||||
size_t Hsize = strlen(home);
|
||||
if (Hsize > PATH_MAX)
|
||||
/* your home directory length is ridiculous */
|
||||
goto end;
|
||||
l += Hsize;
|
||||
}
|
||||
break;
|
||||
case 'L':
|
||||
if (lcCompose == NULL)
|
||||
lcCompose = _XlcFileName(im->core.lcd, COMPOSE_FILE);
|
||||
if (lcCompose) {
|
||||
size_t Lsize = strlen(lcCompose);
|
||||
if (Lsize > PATH_MAX)
|
||||
/* your compose pathname length is ridiculous */
|
||||
goto end;
|
||||
l += Lsize;
|
||||
}
|
||||
break;
|
||||
case 'S':
|
||||
if (dir[0] == '\0')
|
||||
xlocaledir(dir, XLC_BUFSIZE);
|
||||
if (dir[0]) {
|
||||
size_t Ssize = strlen(dir);
|
||||
if (Ssize > PATH_MAX)
|
||||
/* your locale directory path length is ridiculous */
|
||||
goto end;
|
||||
l += Ssize;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
l++;
|
||||
}
|
||||
i++;
|
||||
if (l > PATH_MAX)
|
||||
/* your expanded path length is ridiculous */
|
||||
goto end;
|
||||
}
|
||||
|
||||
j = ret = Xmalloc(l+1);
|
||||
if (ret == NULL)
|
||||
goto end;
|
||||
i = name;
|
||||
while (*i) {
|
||||
if (*i == '%') {
|
||||
i++;
|
||||
switch (*i) {
|
||||
case '%':
|
||||
*j++ = '%';
|
||||
break;
|
||||
case 'H':
|
||||
if (home) {
|
||||
strcpy(j, home);
|
||||
j += strlen(home);
|
||||
}
|
||||
break;
|
||||
case 'L':
|
||||
if (lcCompose) {
|
||||
strcpy(j, lcCompose);
|
||||
j += strlen(lcCompose);
|
||||
}
|
||||
break;
|
||||
case 'S':
|
||||
strcpy(j, dir);
|
||||
j += strlen(dir);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
} else {
|
||||
*j++ = *i++;
|
||||
}
|
||||
}
|
||||
*j = '\0';
|
||||
end:
|
||||
Xfree(lcCompose);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef MB_LEN_MAX
|
||||
#define MB_LEN_MAX 6
|
||||
#endif
|
||||
|
||||
static int
|
||||
get_mb_string (Xim im, char *buf, KeySym ks)
|
||||
{
|
||||
XPointer from, to;
|
||||
int from_len, to_len, len;
|
||||
XPointer args[1];
|
||||
XlcCharSet charset;
|
||||
char local_buf[MB_LEN_MAX];
|
||||
unsigned int ucs;
|
||||
ucs = KeySymToUcs4(ks);
|
||||
|
||||
from = (XPointer) &ucs;
|
||||
to = (XPointer) local_buf;
|
||||
from_len = 1;
|
||||
to_len = MB_LEN_MAX;
|
||||
args[0] = (XPointer) &charset;
|
||||
if (_XlcConvert(im->private.local.ucstoc_conv,
|
||||
&from, &from_len, &to, &to_len, args, 1 ) != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
from = (XPointer) local_buf;
|
||||
to = (XPointer) buf;
|
||||
from_len = MB_LEN_MAX - to_len;
|
||||
to_len = MB_LEN_MAX + 1;
|
||||
args[0] = (XPointer) charset;
|
||||
if (_XlcConvert(im->private.local.cstomb_conv,
|
||||
&from, &from_len, &to, &to_len, args, 1 ) != 0) {
|
||||
return 0;
|
||||
}
|
||||
len = MB_LEN_MAX + 1 - to_len;
|
||||
buf[len] = '\0';
|
||||
return len;
|
||||
}
|
||||
|
||||
#define AllMask (ShiftMask | LockMask | ControlMask | Mod1Mask)
|
||||
#define LOCAL_WC_BUFSIZE 128
|
||||
#define LOCAL_UTF8_BUFSIZE 256
|
||||
#define SEQUENCE_MAX 10
|
||||
|
||||
static int
|
||||
parseline(
|
||||
FILE *fp,
|
||||
Xim im,
|
||||
char* tokenbuf,
|
||||
int depth)
|
||||
{
|
||||
int token;
|
||||
DTModifier modifier_mask;
|
||||
DTModifier modifier;
|
||||
DTModifier tmp;
|
||||
KeySym keysym = NoSymbol;
|
||||
DTIndex *top = &im->private.local.top;
|
||||
DefTreeBase *b = &im->private.local.base;
|
||||
DTIndex t;
|
||||
DefTree *p = NULL;
|
||||
Bool exclam, tilde;
|
||||
KeySym rhs_keysym = 0;
|
||||
char *rhs_string_mb;
|
||||
int l;
|
||||
int lastch = 0;
|
||||
char local_mb_buf[MB_LEN_MAX+1];
|
||||
wchar_t local_wc_buf[LOCAL_WC_BUFSIZE], *rhs_string_wc;
|
||||
char local_utf8_buf[LOCAL_UTF8_BUFSIZE], *rhs_string_utf8;
|
||||
|
||||
struct DefBuffer {
|
||||
DTModifier modifier_mask;
|
||||
DTModifier modifier;
|
||||
KeySym keysym;
|
||||
};
|
||||
|
||||
struct DefBuffer buf[SEQUENCE_MAX];
|
||||
int i, n;
|
||||
|
||||
do {
|
||||
token = nexttoken(fp, tokenbuf, &lastch);
|
||||
} while (token == ENDOFLINE);
|
||||
|
||||
if (token == ENDOFFILE) {
|
||||
return(-1);
|
||||
}
|
||||
|
||||
n = 0;
|
||||
do {
|
||||
if ((token == KEY) && (strcmp("include", tokenbuf) == 0)) {
|
||||
char *filename;
|
||||
FILE *infp;
|
||||
token = nexttoken(fp, tokenbuf, &lastch);
|
||||
if (token != KEY && token != STRING)
|
||||
goto error;
|
||||
if (++depth > 100)
|
||||
goto error;
|
||||
if ((filename = TransFileName(im, tokenbuf)) == NULL)
|
||||
goto error;
|
||||
infp = _XFopenFile(filename, "r");
|
||||
Xfree(filename);
|
||||
if (infp == NULL)
|
||||
goto error;
|
||||
parsestringfile(infp, im, depth);
|
||||
fclose(infp);
|
||||
return (0);
|
||||
} else if ((token == KEY) && (strcmp("None", tokenbuf) == 0)) {
|
||||
modifier = 0;
|
||||
modifier_mask = AllMask;
|
||||
token = nexttoken(fp, tokenbuf, &lastch);
|
||||
} else {
|
||||
modifier_mask = modifier = 0;
|
||||
exclam = False;
|
||||
if (token == EXCLAM) {
|
||||
exclam = True;
|
||||
token = nexttoken(fp, tokenbuf, &lastch);
|
||||
}
|
||||
while (token == TILDE || token == KEY) {
|
||||
tilde = False;
|
||||
if (token == TILDE) {
|
||||
tilde = True;
|
||||
token = nexttoken(fp, tokenbuf, &lastch);
|
||||
if (token != KEY)
|
||||
goto error;
|
||||
}
|
||||
tmp = modmask(tokenbuf);
|
||||
if (!tmp) {
|
||||
goto error;
|
||||
}
|
||||
modifier_mask |= tmp;
|
||||
if (tilde) {
|
||||
modifier &= ~tmp;
|
||||
} else {
|
||||
modifier |= tmp;
|
||||
}
|
||||
token = nexttoken(fp, tokenbuf, &lastch);
|
||||
}
|
||||
if (exclam) {
|
||||
modifier_mask = AllMask;
|
||||
}
|
||||
}
|
||||
|
||||
if (token != LESS) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
token = nexttoken(fp, tokenbuf, &lastch);
|
||||
if (token != KEY) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
token = nexttoken(fp, tokenbuf, &lastch);
|
||||
if (token != GREATER) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
keysym = XStringToKeysym(tokenbuf);
|
||||
if (keysym == NoSymbol) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
buf[n].keysym = keysym;
|
||||
buf[n].modifier = modifier;
|
||||
buf[n].modifier_mask = modifier_mask;
|
||||
n++;
|
||||
if( n >= SEQUENCE_MAX )
|
||||
goto error;
|
||||
token = nexttoken(fp, tokenbuf, &lastch);
|
||||
} while (token != COLON);
|
||||
|
||||
token = nexttoken(fp, tokenbuf, &lastch);
|
||||
if (token == STRING) {
|
||||
l = strlen(tokenbuf) + 1;
|
||||
while (b->mbused + l > b->mbsize) {
|
||||
DTCharIndex newsize = b->mbsize ? b->mbsize * 1.5 : 1024;
|
||||
char *newmb = Xrealloc (b->mb, newsize);
|
||||
if (newmb == NULL)
|
||||
goto error;
|
||||
b->mb = newmb;
|
||||
b->mbsize = newsize;
|
||||
}
|
||||
rhs_string_mb = &b->mb[b->mbused];
|
||||
b->mbused += l;
|
||||
strcpy(rhs_string_mb, tokenbuf);
|
||||
token = nexttoken(fp, tokenbuf, &lastch);
|
||||
if (token == KEY) {
|
||||
rhs_keysym = XStringToKeysym(tokenbuf);
|
||||
if (rhs_keysym == NoSymbol) {
|
||||
goto error;
|
||||
}
|
||||
token = nexttoken(fp, tokenbuf, &lastch);
|
||||
}
|
||||
if (token != ENDOFLINE && token != ENDOFFILE) {
|
||||
goto error;
|
||||
}
|
||||
} else if (token == KEY) {
|
||||
rhs_keysym = XStringToKeysym(tokenbuf);
|
||||
if (rhs_keysym == NoSymbol) {
|
||||
goto error;
|
||||
}
|
||||
token = nexttoken(fp, tokenbuf, &lastch);
|
||||
if (token != ENDOFLINE && token != ENDOFFILE) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
l = get_mb_string(im, local_mb_buf, rhs_keysym);
|
||||
while (b->mbused + l + 1 > b->mbsize) {
|
||||
DTCharIndex newsize = b->mbsize ? b->mbsize * 1.5 : 1024;
|
||||
char *newmb = Xrealloc (b->mb, newsize);
|
||||
if (newmb == NULL)
|
||||
goto error;
|
||||
b->mb = newmb;
|
||||
b->mbsize = newsize;
|
||||
}
|
||||
rhs_string_mb = &b->mb[b->mbused];
|
||||
b->mbused += l + 1;
|
||||
memcpy(rhs_string_mb, local_mb_buf, l);
|
||||
rhs_string_mb[l] = '\0';
|
||||
} else {
|
||||
goto error;
|
||||
}
|
||||
|
||||
l = _Xmbstowcs(local_wc_buf, rhs_string_mb, LOCAL_WC_BUFSIZE - 1);
|
||||
if (l == LOCAL_WC_BUFSIZE - 1) {
|
||||
local_wc_buf[l] = (wchar_t)'\0';
|
||||
}
|
||||
while (b->wcused + l + 1 > b->wcsize) {
|
||||
DTCharIndex newsize = b->wcsize ? b->wcsize * 1.5 : 512;
|
||||
wchar_t *newwc = Xrealloc (b->wc, sizeof(wchar_t) * newsize);
|
||||
if (newwc == NULL)
|
||||
goto error;
|
||||
b->wc = newwc;
|
||||
b->wcsize = newsize;
|
||||
}
|
||||
rhs_string_wc = &b->wc[b->wcused];
|
||||
b->wcused += l + 1;
|
||||
memcpy((char *)rhs_string_wc, (char *)local_wc_buf, (l + 1) * sizeof(wchar_t) );
|
||||
|
||||
l = _Xmbstoutf8(local_utf8_buf, rhs_string_mb, LOCAL_UTF8_BUFSIZE - 1);
|
||||
if (l == LOCAL_UTF8_BUFSIZE - 1) {
|
||||
local_utf8_buf[l] = '\0';
|
||||
}
|
||||
while (b->utf8used + l + 1 > b->utf8size) {
|
||||
DTCharIndex newsize = b->utf8size ? b->utf8size * 1.5 : 1024;
|
||||
char *newutf8 = Xrealloc (b->utf8, newsize);
|
||||
if (newutf8 == NULL)
|
||||
goto error;
|
||||
b->utf8 = newutf8;
|
||||
b->utf8size = newsize;
|
||||
}
|
||||
rhs_string_utf8 = &b->utf8[b->utf8used];
|
||||
b->utf8used += l + 1;
|
||||
memcpy(rhs_string_utf8, local_utf8_buf, l + 1);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (t = *top; t; t = b->tree[t].next) {
|
||||
if (buf[i].keysym == b->tree[t].keysym &&
|
||||
buf[i].modifier == b->tree[t].modifier &&
|
||||
buf[i].modifier_mask == b->tree[t].modifier_mask) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (t) {
|
||||
p = &b->tree[t];
|
||||
top = &p->succession;
|
||||
} else {
|
||||
while (b->treeused >= b->treesize) {
|
||||
DefTree *old = b->tree;
|
||||
int oldsize = b->treesize;
|
||||
int newsize = b->treesize ? b->treesize * 1.5 : 256;
|
||||
DefTree *new = Xrealloc (b->tree, sizeof(DefTree) * newsize);
|
||||
if (new == NULL)
|
||||
goto error;
|
||||
b->tree = new;
|
||||
b->treesize = newsize;
|
||||
/* Re-derive top after realloc() to avoid undefined behaviour
|
||||
(and crashes on architectures that track pointer bounds). */
|
||||
if (top >= (DTIndex *) old && top < (DTIndex *) &old[oldsize])
|
||||
top = (DTIndex *) (((char *)new) + (((char *)top)-(char *)old));
|
||||
}
|
||||
p = &b->tree[b->treeused];
|
||||
p->keysym = buf[i].keysym;
|
||||
p->modifier = buf[i].modifier;
|
||||
p->modifier_mask = buf[i].modifier_mask;
|
||||
p->succession = 0;
|
||||
p->next = *top;
|
||||
p->mb = 0;
|
||||
p->wc = 0;
|
||||
p->utf8 = 0;
|
||||
p->ks = NoSymbol;
|
||||
*top = b->treeused;
|
||||
top = &p->succession;
|
||||
b->treeused++;
|
||||
}
|
||||
}
|
||||
|
||||
/* old entries no longer freed... */
|
||||
p->mb = rhs_string_mb - b->mb;
|
||||
p->wc = rhs_string_wc - b->wc;
|
||||
p->utf8 = rhs_string_utf8 - b->utf8;
|
||||
p->ks = rhs_keysym;
|
||||
return(n);
|
||||
error:
|
||||
while (token != ENDOFLINE && token != ENDOFFILE) {
|
||||
token = nexttoken(fp, tokenbuf, &lastch);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
void
|
||||
_XimParseStringFile(
|
||||
FILE *fp,
|
||||
Xim im)
|
||||
{
|
||||
parsestringfile(fp, im, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
parsestringfile(
|
||||
FILE *fp,
|
||||
Xim im,
|
||||
int depth)
|
||||
{
|
||||
char tb[8192];
|
||||
char* tbp;
|
||||
struct stat st;
|
||||
|
||||
if (fstat (fileno (fp), &st) != -1) {
|
||||
unsigned long size = (unsigned long) st.st_size;
|
||||
if (st.st_size >= INT_MAX)
|
||||
return;
|
||||
if (size <= sizeof tb) tbp = tb;
|
||||
else tbp = malloc (size);
|
||||
|
||||
if (tbp != NULL) {
|
||||
while (parseline(fp, im, tbp, depth) >= 0) {}
|
||||
if (tbp != tb) free (tbp);
|
||||
}
|
||||
}
|
||||
}
|
||||
54
nx-X11/lib/modules/im/ximcp/imLcSIc.c
Normal file
54
nx-X11/lib/modules/im/ximcp/imLcSIc.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1990, 1991, 1992, 1993, 1994 by FUJITSU LIMITED
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and
|
||||
that both that copyright notice and this permission notice appear
|
||||
in supporting documentation, and that the name of FUJITSU LIMITED
|
||||
not be used in advertising or publicity pertaining to distribution
|
||||
of the software without specific, written prior permission.
|
||||
FUJITSU LIMITED makes no representations about the suitability of
|
||||
this software for any purpose.
|
||||
It is provided "as is" without express or implied warranty.
|
||||
|
||||
FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Author: Takashi Fujiwara FUJITSU LIMITED
|
||||
fujiwara@a80.tech.yk.fujitsu.co.jp
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <nx-X11/Xlib.h>
|
||||
#include <nx-X11/Xmd.h>
|
||||
#include <nx-X11/Xutil.h>
|
||||
#include "Xlibint.h"
|
||||
#include "Xlcint.h"
|
||||
#include "Ximint.h"
|
||||
|
||||
char *
|
||||
_XimLocalSetICValues(XIC xic, XIMArg *values)
|
||||
{
|
||||
XimDefICValues ic_values;
|
||||
Xic ic = (Xic)xic;
|
||||
char *name;
|
||||
|
||||
_XimGetCurrentICValues(ic, &ic_values);
|
||||
name = _XimSetICValueData(ic, (XPointer)&ic_values,
|
||||
ic->private.local.ic_resources,
|
||||
ic->private.local.ic_num_resources,
|
||||
values, XIM_SETICVALUES, True);
|
||||
_XimSetCurrentICValues(ic, &ic_values);
|
||||
return(name);
|
||||
}
|
||||
3212
nx-X11/lib/modules/im/ximcp/imRm.c
Normal file
3212
nx-X11/lib/modules/im/ximcp/imRm.c
Normal file
File diff suppressed because it is too large
Load Diff
1530
nx-X11/lib/modules/im/ximcp/imRmAttr.c
Normal file
1530
nx-X11/lib/modules/im/ximcp/imRmAttr.c
Normal file
File diff suppressed because it is too large
Load Diff
1421
nx-X11/lib/modules/im/ximcp/imThaiFlt.c
Normal file
1421
nx-X11/lib/modules/im/ximcp/imThaiFlt.c
Normal file
File diff suppressed because it is too large
Load Diff
229
nx-X11/lib/modules/im/ximcp/imThaiIc.c
Normal file
229
nx-X11/lib/modules/im/ximcp/imThaiIc.c
Normal file
@@ -0,0 +1,229 @@
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1992, 1993, 1994 by FUJITSU LIMITED
|
||||
Copyright 1993 by Digital Equipment Corporation
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and that
|
||||
both that copyright notice and this permission notice appear in
|
||||
supporting documentation, and that the name of FUJITSU LIMITED and
|
||||
Digital Equipment Corporation not be used in advertising or publicity
|
||||
pertaining to distribution of the software without specific, written
|
||||
prior permission. FUJITSU LIMITED and Digital Equipment Corporation
|
||||
makes no representations about the suitability of this software for
|
||||
any purpose. It is provided "as is" without express or implied
|
||||
warranty.
|
||||
|
||||
FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION DISCLAIM ALL
|
||||
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||
FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
|
||||
ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
|
||||
Author: Takashi Fujiwara FUJITSU LIMITED
|
||||
fujiwara@a80.tech.yk.fujitsu.co.jp
|
||||
Modifier: Franky Ling Digital Equipment Corporation
|
||||
frankyling@hgrd01.enet.dec.com
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <nx-X11/Xlib.h>
|
||||
#include <nx-X11/Xmd.h>
|
||||
#include "Xlibint.h"
|
||||
#include "Xlcint.h"
|
||||
#include "Ximint.h"
|
||||
|
||||
static void
|
||||
_XimThaiUnSetFocus(
|
||||
XIC xic)
|
||||
{
|
||||
Xic ic = (Xic)xic;
|
||||
((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL;
|
||||
|
||||
if (ic->core.focus_window)
|
||||
_XUnregisterFilter(ic->core.im->core.display, ic->core.focus_window,
|
||||
_XimThaiFilter, (XPointer)ic);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
_XimThaiDestroyIC(
|
||||
XIC xic)
|
||||
{
|
||||
Xic ic = (Xic)xic;
|
||||
DefTreeBase *b = &ic->private.local.base;
|
||||
|
||||
if(((Xim)ic->core.im)->private.local.current_ic == (XIC)ic) {
|
||||
_XimThaiUnSetFocus(xic);
|
||||
}
|
||||
|
||||
Xfree(ic->private.local.ic_resources);
|
||||
ic->private.local.ic_resources = NULL;
|
||||
|
||||
Xfree (b->tree);
|
||||
b->tree = NULL;
|
||||
|
||||
Xfree (b->mb);
|
||||
b->mb = NULL;
|
||||
|
||||
Xfree (b->wc);
|
||||
b->wc = NULL;
|
||||
|
||||
Xfree (b->utf8);
|
||||
b->utf8 = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
_XimThaiSetFocus(
|
||||
XIC xic)
|
||||
{
|
||||
Xic ic = (Xic)xic;
|
||||
XIC current_ic = ((Xim)ic->core.im)->private.local.current_ic;
|
||||
|
||||
if (current_ic == (XIC)ic)
|
||||
return;
|
||||
|
||||
if (current_ic != (XIC)NULL) {
|
||||
_XimThaiUnSetFocus(current_ic);
|
||||
}
|
||||
((Xim)ic->core.im)->private.local.current_ic = (XIC)ic;
|
||||
|
||||
if (ic->core.focus_window)
|
||||
_XRegisterFilterByType(ic->core.im->core.display, ic->core.focus_window,
|
||||
KeyPress, KeyPress, _XimThaiFilter, (XPointer)ic);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
_XimThaiReset(
|
||||
XIC xic)
|
||||
{
|
||||
Xic ic = (Xic)xic;
|
||||
DefTreeBase *b = &ic->private.local.base;
|
||||
ic->private.local.thai.comp_state = 0;
|
||||
ic->private.local.thai.keysym = 0;
|
||||
b->mb[b->tree[ic->private.local.composed].mb] = '\0';
|
||||
b->wc[b->tree[ic->private.local.composed].wc] = '\0';
|
||||
b->utf8[b->tree[ic->private.local.composed].utf8] = '\0';
|
||||
}
|
||||
|
||||
static char *
|
||||
_XimThaiMbReset(
|
||||
XIC xic)
|
||||
{
|
||||
_XimThaiReset(xic);
|
||||
return (char *)NULL;
|
||||
}
|
||||
|
||||
static wchar_t *
|
||||
_XimThaiWcReset(
|
||||
XIC xic)
|
||||
{
|
||||
_XimThaiReset(xic);
|
||||
return (wchar_t *)NULL;
|
||||
}
|
||||
|
||||
static XICMethodsRec Thai_ic_methods = {
|
||||
_XimThaiDestroyIC, /* destroy */
|
||||
_XimThaiSetFocus, /* set_focus */
|
||||
_XimThaiUnSetFocus, /* unset_focus */
|
||||
_XimLocalSetICValues, /* set_values */
|
||||
_XimLocalGetICValues, /* get_values */
|
||||
_XimThaiMbReset, /* mb_reset */
|
||||
_XimThaiWcReset, /* wc_reset */
|
||||
_XimThaiMbReset, /* utf8_reset */
|
||||
_XimLocalMbLookupString, /* mb_lookup_string */
|
||||
_XimLocalWcLookupString, /* wc_lookup_string */
|
||||
_XimLocalUtf8LookupString /* utf8_lookup_string */
|
||||
};
|
||||
|
||||
XIC
|
||||
_XimThaiCreateIC(
|
||||
XIM im,
|
||||
XIMArg *values)
|
||||
{
|
||||
Xic ic;
|
||||
XimDefICValues ic_values;
|
||||
XIMResourceList res;
|
||||
unsigned int num;
|
||||
int len;
|
||||
DefTree *tree;
|
||||
|
||||
if((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) {
|
||||
return ((XIC)NULL);
|
||||
}
|
||||
|
||||
ic->methods = &Thai_ic_methods;
|
||||
ic->core.im = im;
|
||||
ic->core.filter_events = KeyPressMask;
|
||||
|
||||
if (! (ic->private.local.base.tree = tree = Xmalloc(sizeof(DefTree)*3)) )
|
||||
goto Set_Error;
|
||||
if (! (ic->private.local.base.mb = Xmalloc(21)) )
|
||||
goto Set_Error;
|
||||
if (! (ic->private.local.base.wc = Xmalloc(sizeof(wchar_t)*21)) )
|
||||
goto Set_Error;
|
||||
if (! (ic->private.local.base.utf8 = Xmalloc(21)) )
|
||||
goto Set_Error;
|
||||
ic->private.local.context = 1;
|
||||
tree[1].mb = 1;
|
||||
tree[1].wc = 1;
|
||||
tree[1].utf8 = 1;
|
||||
ic->private.local.composed = 2;
|
||||
tree[2].mb = 11;
|
||||
tree[2].wc = 11;
|
||||
tree[2].utf8 = 11;
|
||||
|
||||
ic->private.local.thai.comp_state = 0;
|
||||
ic->private.local.thai.keysym = 0;
|
||||
ic->private.local.thai.input_mode = 0;
|
||||
|
||||
num = im->core.ic_num_resources;
|
||||
len = sizeof(XIMResource) * num;
|
||||
if((res = Xmalloc(len)) == (XIMResourceList)NULL) {
|
||||
goto Set_Error;
|
||||
}
|
||||
(void)memcpy((char *)res, (char *)im->core.ic_resources, len);
|
||||
ic->private.local.ic_resources = res;
|
||||
ic->private.local.ic_num_resources = num;
|
||||
|
||||
bzero((char *)&ic_values, sizeof(XimDefICValues));
|
||||
if(_XimCheckLocalInputStyle(ic, (XPointer)&ic_values, values,
|
||||
im->core.styles, res, num) == False) {
|
||||
goto Set_Error;
|
||||
}
|
||||
|
||||
_XimSetICMode(res, num, ic_values.input_style);
|
||||
|
||||
if(_XimSetICValueData(ic, (XPointer)&ic_values,
|
||||
ic->private.local.ic_resources,
|
||||
ic->private.local.ic_num_resources,
|
||||
values, XIM_CREATEIC, True)) {
|
||||
goto Set_Error;
|
||||
}
|
||||
if(_XimSetICDefaults(ic, (XPointer)&ic_values,
|
||||
XIM_SETICDEFAULTS, res, num) == False) {
|
||||
goto Set_Error;
|
||||
}
|
||||
ic_values.filter_events = KeyPressMask;
|
||||
_XimSetCurrentICValues(ic, &ic_values);
|
||||
|
||||
return ((XIC)ic);
|
||||
|
||||
Set_Error :
|
||||
if (ic->private.local.ic_resources) {
|
||||
Xfree(ic->private.local.ic_resources);
|
||||
}
|
||||
Xfree(ic);
|
||||
return((XIC)NULL);
|
||||
}
|
||||
235
nx-X11/lib/modules/im/ximcp/imThaiIm.c
Normal file
235
nx-X11/lib/modules/im/ximcp/imThaiIm.c
Normal file
@@ -0,0 +1,235 @@
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1992, 1993, 1994 by FUJITSU LIMITED
|
||||
Copyright 1993 by Digital Equipment Corporation
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and that
|
||||
both that copyright notice and this permission notice appear in
|
||||
supporting documentation, and that the name of FUJITSU LIMITED and
|
||||
Digital Equipment Corporation not be used in advertising or publicity
|
||||
pertaining to distribution of the software without specific, written
|
||||
prior permission. FUJITSU LIMITED and Digital Equipment Corporation
|
||||
makes no representations about the suitability of this software for
|
||||
any purpose. It is provided "as is" without express or implied
|
||||
warranty.
|
||||
|
||||
FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION DISCLAIM ALL
|
||||
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||
FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
|
||||
ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
|
||||
Author: Takashi Fujiwara FUJITSU LIMITED
|
||||
fujiwara@a80.tech.yk.fujitsu.co.jp
|
||||
Modifier: Franky Ling Digital Equipment Corporation
|
||||
frankyling@hgrd01.enet.dec.com
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <nx-X11/Xlib.h>
|
||||
#include <nx-X11/Xmd.h>
|
||||
#include <nx-X11/Xatom.h>
|
||||
#include <nx-X11/Xos.h>
|
||||
#include "Xlibint.h"
|
||||
#include "Xlcint.h"
|
||||
#include "XlcPublic.h"
|
||||
#include "XlcPubI.h"
|
||||
#include "Ximint.h"
|
||||
|
||||
static XIMMethodsRec Xim_im_thai_methods = {
|
||||
_XimThaiCloseIM, /* close */
|
||||
_XimLocalSetIMValues, /* set_values */
|
||||
_XimLocalGetIMValues, /* get_values */
|
||||
_XimThaiCreateIC, /* create_ic */
|
||||
_XimLcctstombs, /* ctstombs */
|
||||
_XimLcctstowcs, /* ctstowcs */
|
||||
_XimLcctstoutf8 /* ctstoutf8 */
|
||||
};
|
||||
|
||||
#define THAI_LANGUAGE_NAME "th"
|
||||
|
||||
Bool
|
||||
_XimCheckIfThaiProcessing(Xim im)
|
||||
{
|
||||
char *language;
|
||||
|
||||
_XGetLCValues(im->core.lcd, XlcNLanguage, &language, NULL);
|
||||
if(strcmp(language, THAI_LANGUAGE_NAME) == 0 &&
|
||||
(strcmp(im->core.im_name, "") == 0 ||
|
||||
strcmp(im->core.im_name, "BasicCheck") == 0 ||
|
||||
strcmp(im->core.im_name, "Strict") == 0 ||
|
||||
strcmp(im->core.im_name, "Thaicat") == 0 ||
|
||||
strcmp(im->core.im_name, "Passthrough") == 0))
|
||||
{
|
||||
return(True);
|
||||
}
|
||||
return(False);
|
||||
}
|
||||
|
||||
Bool
|
||||
_XimThaiOpenIM(Xim im)
|
||||
{
|
||||
XLCd lcd = im->core.lcd;
|
||||
XlcConv conv;
|
||||
XimDefIMValues im_values;
|
||||
XimLocalPrivateRec* private = &im->private.local;
|
||||
|
||||
_XimInitialResourceInfo();
|
||||
if(_XimSetIMResourceList(&im->core.im_resources,
|
||||
&im->core.im_num_resources) == False) {
|
||||
goto Open_Error;
|
||||
}
|
||||
if(_XimSetICResourceList(&im->core.ic_resources,
|
||||
&im->core.ic_num_resources) == False) {
|
||||
goto Open_Error;
|
||||
}
|
||||
|
||||
_XimSetIMMode(im->core.im_resources, im->core.im_num_resources);
|
||||
|
||||
_XimGetCurrentIMValues(im, &im_values);
|
||||
if(_XimSetLocalIMDefaults(im, (XPointer)&im_values,
|
||||
im->core.im_resources, im->core.im_num_resources) == False) {
|
||||
goto Open_Error;
|
||||
}
|
||||
_XimSetCurrentIMValues(im, &im_values);
|
||||
|
||||
if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte)))
|
||||
goto Open_Error;
|
||||
private->ctom_conv = conv;
|
||||
|
||||
if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar)))
|
||||
goto Open_Error;
|
||||
private->ctow_conv = conv;
|
||||
|
||||
if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNUtf8String)))
|
||||
goto Open_Error;
|
||||
private->ctoutf8_conv = conv;
|
||||
|
||||
if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte)))
|
||||
goto Open_Error;
|
||||
private->cstomb_conv = conv;
|
||||
|
||||
if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNWideChar)))
|
||||
goto Open_Error;
|
||||
private->cstowc_conv = conv;
|
||||
|
||||
if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNUtf8String)))
|
||||
goto Open_Error;
|
||||
private->cstoutf8_conv = conv;
|
||||
|
||||
if (!(conv = _XlcOpenConverter(lcd, XlcNUcsChar, lcd, XlcNChar)))
|
||||
goto Open_Error;
|
||||
private->ucstoc_conv = conv;
|
||||
|
||||
if (!(conv = _XlcOpenConverter(lcd, XlcNUcsChar, lcd, XlcNUtf8String)))
|
||||
goto Open_Error;
|
||||
private->ucstoutf8_conv = conv;
|
||||
|
||||
im->methods = &Xim_im_thai_methods;
|
||||
private->current_ic = (XIC)NULL;
|
||||
|
||||
return(True);
|
||||
|
||||
Open_Error :
|
||||
_XimThaiIMFree(im);
|
||||
return(False);
|
||||
}
|
||||
|
||||
void
|
||||
_XimThaiIMFree(Xim im)
|
||||
{
|
||||
if(im->core.im_resources) {
|
||||
Xfree(im->core.im_resources);
|
||||
im->core.im_resources = NULL;
|
||||
}
|
||||
if(im->core.ic_resources) {
|
||||
Xfree(im->core.ic_resources);
|
||||
im->core.ic_resources = NULL;
|
||||
}
|
||||
if(im->core.im_values_list) {
|
||||
Xfree(im->core.im_values_list);
|
||||
im->core.im_values_list = NULL;
|
||||
}
|
||||
if(im->core.ic_values_list) {
|
||||
Xfree(im->core.ic_values_list);
|
||||
im->core.ic_values_list = NULL;
|
||||
}
|
||||
if(im->core.styles) {
|
||||
Xfree(im->core.styles);
|
||||
im->core.styles = NULL;
|
||||
}
|
||||
if(im->core.res_name) {
|
||||
Xfree(im->core.res_name);
|
||||
im->core.res_name = NULL;
|
||||
}
|
||||
if(im->core.res_class) {
|
||||
Xfree(im->core.res_class);
|
||||
im->core.res_class = NULL;
|
||||
}
|
||||
if(im->core.im_name) {
|
||||
Xfree(im->core.im_name);
|
||||
im->core.im_name = NULL;
|
||||
}
|
||||
if (im->private.local.ctom_conv) {
|
||||
_XlcCloseConverter(im->private.local.ctom_conv);
|
||||
im->private.local.ctom_conv = NULL;
|
||||
}
|
||||
if (im->private.local.ctow_conv) {
|
||||
_XlcCloseConverter(im->private.local.ctow_conv);
|
||||
im->private.local.ctow_conv = NULL;
|
||||
}
|
||||
if (im->private.local.ctoutf8_conv) {
|
||||
_XlcCloseConverter(im->private.local.ctoutf8_conv);
|
||||
im->private.local.ctoutf8_conv = NULL;
|
||||
}
|
||||
if (im->private.local.cstomb_conv) {
|
||||
_XlcCloseConverter(im->private.local.cstomb_conv);
|
||||
im->private.local.cstomb_conv = NULL;
|
||||
}
|
||||
if (im->private.local.cstowc_conv) {
|
||||
_XlcCloseConverter(im->private.local.cstowc_conv);
|
||||
im->private.local.cstowc_conv = NULL;
|
||||
}
|
||||
if (im->private.local.cstoutf8_conv) {
|
||||
_XlcCloseConverter(im->private.local.cstoutf8_conv);
|
||||
im->private.local.cstoutf8_conv = NULL;
|
||||
}
|
||||
if (im->private.local.ucstoc_conv) {
|
||||
_XlcCloseConverter(im->private.local.ucstoc_conv);
|
||||
im->private.local.ucstoc_conv = NULL;
|
||||
}
|
||||
if (im->private.local.ucstoutf8_conv) {
|
||||
_XlcCloseConverter(im->private.local.ucstoutf8_conv);
|
||||
im->private.local.ucstoutf8_conv = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Status
|
||||
_XimThaiCloseIM(XIM xim)
|
||||
{
|
||||
Xim im = (Xim)xim;
|
||||
XIC ic;
|
||||
XIC next;
|
||||
|
||||
ic = im->core.ic_chain;
|
||||
im->core.ic_chain = NULL;
|
||||
while (ic) {
|
||||
(*ic->methods->destroy) (ic);
|
||||
next = ic->core.next;
|
||||
Xfree (ic);
|
||||
ic = next;
|
||||
}
|
||||
_XimThaiIMFree(im);
|
||||
return(True);
|
||||
}
|
||||
519
nx-X11/lib/modules/im/ximcp/imTrX.c
Normal file
519
nx-X11/lib/modules/im/ximcp/imTrX.c
Normal file
@@ -0,0 +1,519 @@
|
||||
/*
|
||||
* Copyright 1992 Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1992, 1993, 1994 by FUJITSU LIMITED
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and
|
||||
that both that copyright notice and this permission notice appear
|
||||
in supporting documentation, and that the name of FUJITSU LIMITED
|
||||
not be used in advertising or publicity pertaining to distribution
|
||||
of the software without specific, written prior permission.
|
||||
FUJITSU LIMITED makes no representations about the suitability of
|
||||
this software for any purpose.
|
||||
It is provided "as is" without express or implied warranty.
|
||||
|
||||
FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Author: Hideki Hiura (hhiura@Sun.COM) Sun Microsystems, Inc.
|
||||
Takashi Fujiwara FUJITSU LIMITED
|
||||
fujiwara@a80.tech.yk.fujitsu.co.jp
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <nx-X11/Xatom.h>
|
||||
#include "Xlibint.h"
|
||||
#include "Xlcint.h"
|
||||
#include "Ximint.h"
|
||||
#include "XimTrInt.h"
|
||||
#include "XimTrX.h"
|
||||
|
||||
static Bool
|
||||
_XimXRegisterDispatcher(
|
||||
Xim im,
|
||||
Bool (*callback)(
|
||||
Xim, INT16, XPointer, XPointer
|
||||
),
|
||||
XPointer call_data)
|
||||
{
|
||||
XIntrCallbackPtr rec;
|
||||
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
|
||||
|
||||
if (!(rec = Xmalloc(sizeof(XIntrCallbackRec))))
|
||||
return False;
|
||||
|
||||
rec->func = callback;
|
||||
rec->call_data = call_data;
|
||||
rec->next = spec->intr_cb;
|
||||
spec->intr_cb = rec;
|
||||
return True;
|
||||
}
|
||||
|
||||
static void
|
||||
_XimXFreeIntrCallback(
|
||||
Xim im)
|
||||
{
|
||||
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
|
||||
register XIntrCallbackPtr rec, next;
|
||||
|
||||
for (rec = spec->intr_cb; rec;) {
|
||||
next = rec->next;
|
||||
Xfree(rec);
|
||||
rec = next;
|
||||
}
|
||||
spec->intr_cb = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimXCallDispatcher(Xim im, INT16 len, XPointer data)
|
||||
{
|
||||
register XIntrCallbackRec *rec;
|
||||
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
|
||||
|
||||
for (rec = spec->intr_cb; rec; rec = rec->next) {
|
||||
if ((*rec->func)(im, len, data, rec->call_data))
|
||||
return True;
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimXFilterWaitEvent(
|
||||
Display *d,
|
||||
Window w,
|
||||
XEvent *ev,
|
||||
XPointer arg)
|
||||
{
|
||||
Xim im = (Xim)arg;
|
||||
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
|
||||
Bool ret;
|
||||
|
||||
spec->ev = (XPointer)ev;
|
||||
ret = _XimFilterWaitEvent(im);
|
||||
|
||||
/*
|
||||
* If ev is a pointer to a stack variable, there could be
|
||||
* a coredump later on if the pointer is dereferenced.
|
||||
* Therefore, reset to NULL to force reinitialization in
|
||||
* _XimXRead().
|
||||
*
|
||||
* Keep in mind _XimXRead may be called again when the stack
|
||||
* is very different.
|
||||
*/
|
||||
spec->ev = (XPointer)NULL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_CheckConnect(
|
||||
Display *display,
|
||||
XEvent *event,
|
||||
XPointer xim)
|
||||
{
|
||||
Xim im = (Xim)xim;
|
||||
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
|
||||
|
||||
if ((event->type == ClientMessage)
|
||||
&& (event->xclient.message_type == spec->imconnectid)) {
|
||||
return True;
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimXConnect(Xim im)
|
||||
{
|
||||
XEvent event;
|
||||
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
|
||||
CARD32 major_code;
|
||||
CARD32 minor_code;
|
||||
|
||||
if (!(spec->lib_connect_wid = XCreateSimpleWindow(im->core.display,
|
||||
DefaultRootWindow(im->core.display), 0, 0, 1, 1, 1, 0, 0))) {
|
||||
return False;
|
||||
}
|
||||
|
||||
event.xclient.type = ClientMessage;
|
||||
event.xclient.display = im->core.display;
|
||||
event.xclient.window = im->private.proto.im_window;
|
||||
event.xclient.message_type = spec->imconnectid;
|
||||
event.xclient.format = 32;
|
||||
event.xclient.data.l[0] = (CARD32)spec->lib_connect_wid;
|
||||
event.xclient.data.l[1] = spec->major_code;
|
||||
event.xclient.data.l[2] = spec->minor_code;
|
||||
event.xclient.data.l[3] = 0;
|
||||
event.xclient.data.l[4] = 0;
|
||||
|
||||
if(event.xclient.data.l[1] == 1 || event.xclient.data.l[1] == 2) {
|
||||
XWindowAttributes atr;
|
||||
long event_mask;
|
||||
|
||||
XGetWindowAttributes(im->core.display, spec->lib_connect_wid, &atr);
|
||||
event_mask = atr.your_event_mask | PropertyChangeMask;
|
||||
XSelectInput(im->core.display, spec->lib_connect_wid, event_mask);
|
||||
_XRegisterFilterByType(im->core.display, spec->lib_connect_wid,
|
||||
PropertyNotify, PropertyNotify,
|
||||
_XimXFilterWaitEvent, (XPointer)im);
|
||||
}
|
||||
|
||||
XSendEvent(im->core.display, im->private.proto.im_window,
|
||||
False, NoEventMask, &event);
|
||||
XFlush(im->core.display);
|
||||
|
||||
for (;;) {
|
||||
XIfEvent(im->core.display, &event, _CheckConnect, (XPointer)im);
|
||||
if (event.xclient.type != ClientMessage) {
|
||||
return False;
|
||||
}
|
||||
if (event.xclient.message_type == spec->imconnectid)
|
||||
break;
|
||||
}
|
||||
|
||||
spec->ims_connect_wid = (Window)event.xclient.data.l[0];
|
||||
major_code = (CARD32)event.xclient.data.l[1];
|
||||
minor_code = (CARD32)event.xclient.data.l[2];
|
||||
|
||||
if (((major_code == 0) && (minor_code <= 2)) ||
|
||||
((major_code == 1) && (minor_code == 0)) ||
|
||||
((major_code == 2) && (minor_code <= 1))) {
|
||||
spec->major_code = major_code;
|
||||
spec->minor_code = minor_code;
|
||||
}
|
||||
if (((major_code == 0) && (minor_code == 2)) ||
|
||||
((major_code == 2) && (minor_code == 1))) {
|
||||
spec->BoundarySize = (CARD32)event.xclient.data.l[3];
|
||||
}
|
||||
|
||||
/* ClientMessage Event Filter */
|
||||
_XRegisterFilterByType(im->core.display, spec->lib_connect_wid,
|
||||
ClientMessage, ClientMessage,
|
||||
_XimXFilterWaitEvent, (XPointer)im);
|
||||
return True;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimXShutdown(Xim im)
|
||||
{
|
||||
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
|
||||
|
||||
if (!spec)
|
||||
return True;
|
||||
|
||||
/* ClientMessage Event Filter */
|
||||
_XUnregisterFilter(im->core.display,
|
||||
((XSpecRec *)im->private.proto.spec)->lib_connect_wid,
|
||||
_XimXFilterWaitEvent, (XPointer)im);
|
||||
XDestroyWindow(im->core.display,
|
||||
((XSpecRec *)im->private.proto.spec)->lib_connect_wid);
|
||||
_XimXFreeIntrCallback(im);
|
||||
Xfree(spec);
|
||||
im->private.proto.spec = 0;
|
||||
return True;
|
||||
}
|
||||
|
||||
static char *
|
||||
_NewAtom(
|
||||
char *atomName)
|
||||
{
|
||||
static int sequence = 0;
|
||||
|
||||
(void)sprintf(atomName, "_client%d", sequence);
|
||||
sequence = ((sequence < 20) ? sequence + 1 : 0);
|
||||
return atomName;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimXWrite(Xim im, INT16 len, XPointer data)
|
||||
{
|
||||
Atom atom;
|
||||
char atomName[16];
|
||||
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
|
||||
XEvent event;
|
||||
CARD8 *p;
|
||||
CARD32 major_code = spec->major_code;
|
||||
CARD32 minor_code = spec->minor_code;
|
||||
int BoundSize;
|
||||
|
||||
bzero(&event,sizeof(XEvent));
|
||||
event.xclient.type = ClientMessage;
|
||||
event.xclient.display = im->core.display;
|
||||
event.xclient.window = spec->ims_connect_wid;
|
||||
if(major_code == 1 && minor_code == 0) {
|
||||
BoundSize = 0;
|
||||
} else if((major_code == 0 && minor_code == 2) ||
|
||||
(major_code == 2 && minor_code == 1)) {
|
||||
BoundSize = spec->BoundarySize;
|
||||
} else if(major_code == 0 && minor_code == 1) {
|
||||
BoundSize = len;
|
||||
} else {
|
||||
BoundSize = XIM_CM_DATA_SIZE;
|
||||
}
|
||||
if (len > BoundSize) {
|
||||
event.xclient.message_type = spec->improtocolid;
|
||||
atom = XInternAtom(im->core.display, _NewAtom(atomName), False);
|
||||
XChangeProperty(im->core.display, spec->ims_connect_wid,
|
||||
atom, XA_STRING, 8, PropModeAppend,
|
||||
(unsigned char *)data, len);
|
||||
if(major_code == 0) {
|
||||
event.xclient.format = 32;
|
||||
event.xclient.data.l[0] = (long)len;
|
||||
event.xclient.data.l[1] = (long)atom;
|
||||
XSendEvent(im->core.display, spec->ims_connect_wid,
|
||||
False, NoEventMask, &event);
|
||||
}
|
||||
} else {
|
||||
int length;
|
||||
|
||||
event.xclient.format = 8;
|
||||
for(length = 0 ; length < len ; length += XIM_CM_DATA_SIZE) {
|
||||
p = (CARD8 *)&event.xclient.data.b[0];
|
||||
if((length + XIM_CM_DATA_SIZE) >= len) {
|
||||
event.xclient.message_type = spec->improtocolid;
|
||||
bzero(p, XIM_CM_DATA_SIZE);
|
||||
memcpy((char *)p, (data + length), (len - length));
|
||||
} else {
|
||||
event.xclient.message_type = spec->immoredataid;
|
||||
memcpy((char *)p, (data + length), XIM_CM_DATA_SIZE);
|
||||
}
|
||||
XSendEvent(im->core.display, spec->ims_connect_wid,
|
||||
False, NoEventMask, &event);
|
||||
}
|
||||
}
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimXGetReadData(
|
||||
Xim im,
|
||||
char *buf,
|
||||
int buf_len,
|
||||
int *ret_len,
|
||||
XEvent *event)
|
||||
{
|
||||
char *data;
|
||||
int len;
|
||||
|
||||
char tmp_buf[XIM_CM_DATA_SIZE];
|
||||
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
|
||||
unsigned long length;
|
||||
Atom prop;
|
||||
int return_code;
|
||||
Atom type_ret;
|
||||
int format_ret;
|
||||
unsigned long nitems;
|
||||
unsigned long bytes_after_ret;
|
||||
unsigned char *prop_ret;
|
||||
|
||||
if ((event->type == ClientMessage) &&
|
||||
!((event->xclient.message_type == spec->improtocolid) ||
|
||||
(event->xclient.message_type == spec->immoredataid))) {
|
||||
/* This event has nothing to do with us,
|
||||
* FIXME should not have gotten here then...
|
||||
*/
|
||||
return False;
|
||||
} else if ((event->type == ClientMessage) && (event->xclient.format == 8)) {
|
||||
data = event->xclient.data.b;
|
||||
if (buf_len >= XIM_CM_DATA_SIZE) {
|
||||
(void)memcpy(buf, data, XIM_CM_DATA_SIZE);
|
||||
*ret_len = XIM_CM_DATA_SIZE;
|
||||
} else {
|
||||
(void)memcpy(buf, data, buf_len);
|
||||
len = XIM_CM_DATA_SIZE - buf_len;
|
||||
(void)memcpy(tmp_buf, &data[buf_len], len);
|
||||
bzero(data, XIM_CM_DATA_SIZE);
|
||||
(void)memcpy(data, tmp_buf, len);
|
||||
XPutBackEvent(im->core.display, event);
|
||||
*ret_len = buf_len;
|
||||
}
|
||||
} else if ((event->type == ClientMessage)
|
||||
&& (event->xclient.format == 32)) {
|
||||
length = (unsigned long)event->xclient.data.l[0];
|
||||
prop = (Atom)event->xclient.data.l[1];
|
||||
return_code = XGetWindowProperty(im->core.display,
|
||||
spec->lib_connect_wid, prop, 0L,
|
||||
(long)((length + 3)/ 4), True, AnyPropertyType,
|
||||
&type_ret, &format_ret, &nitems, &bytes_after_ret, &prop_ret);
|
||||
if (return_code != Success || format_ret == 0 || nitems == 0) {
|
||||
if (return_code == Success)
|
||||
XFree(prop_ret);
|
||||
return False;
|
||||
}
|
||||
if (buf_len >= (int)nitems) {
|
||||
(void)memcpy(buf, prop_ret, (int)nitems);
|
||||
*ret_len = (int)nitems;
|
||||
if (bytes_after_ret > 0) {
|
||||
XFree(prop_ret);
|
||||
if (XGetWindowProperty(im->core.display,
|
||||
spec->lib_connect_wid, prop, 0L,
|
||||
((length + bytes_after_ret + 3)/ 4),
|
||||
True, AnyPropertyType,
|
||||
&type_ret, &format_ret, &nitems,
|
||||
&bytes_after_ret,
|
||||
&prop_ret) == Success) {
|
||||
XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
|
||||
XA_STRING, 8, PropModePrepend, &prop_ret[length],
|
||||
(nitems - length));
|
||||
} else {
|
||||
return False;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
(void)memcpy(buf, prop_ret, buf_len);
|
||||
*ret_len = buf_len;
|
||||
len = nitems - buf_len;
|
||||
|
||||
if (bytes_after_ret > 0) {
|
||||
XFree(prop_ret);
|
||||
if (XGetWindowProperty(im->core.display,
|
||||
spec->lib_connect_wid, prop, 0L,
|
||||
((length + bytes_after_ret + 3)/ 4),
|
||||
True, AnyPropertyType,
|
||||
&type_ret, &format_ret, &nitems,
|
||||
&bytes_after_ret, &prop_ret) != Success) {
|
||||
return False;
|
||||
}
|
||||
}
|
||||
XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
|
||||
XA_STRING, 8, PropModePrepend, &prop_ret[buf_len], len);
|
||||
event->xclient.data.l[0] = (long)len;
|
||||
event->xclient.data.l[1] = (long)prop;
|
||||
XPutBackEvent(im->core.display, event);
|
||||
}
|
||||
XFree(prop_ret);
|
||||
} else if (event->type == PropertyNotify) {
|
||||
prop = event->xproperty.atom;
|
||||
return_code = XGetWindowProperty(im->core.display,
|
||||
spec->lib_connect_wid, prop, 0L,
|
||||
1000000L, True, AnyPropertyType,
|
||||
&type_ret, &format_ret, &nitems, &bytes_after_ret, &prop_ret);
|
||||
if (return_code != Success || format_ret == 0 || nitems == 0) {
|
||||
if (return_code == Success)
|
||||
XFree(prop_ret);
|
||||
return False;
|
||||
}
|
||||
if (buf_len >= nitems) {
|
||||
(void)memcpy(buf, prop_ret, (int)nitems);
|
||||
*ret_len = (int)nitems;
|
||||
} else {
|
||||
(void)memcpy(buf, prop_ret, buf_len);
|
||||
*ret_len = buf_len;
|
||||
len = nitems - buf_len;
|
||||
XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
|
||||
XA_STRING, 8, PropModePrepend, &prop_ret[buf_len], len);
|
||||
}
|
||||
XFree(prop_ret);
|
||||
}
|
||||
return True;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_CheckCMEvent(
|
||||
Display *display,
|
||||
XEvent *event,
|
||||
XPointer xim)
|
||||
{
|
||||
Xim im = (Xim)xim;
|
||||
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
|
||||
CARD32 major_code = spec->major_code;
|
||||
|
||||
if ((event->type == ClientMessage)
|
||||
&&((event->xclient.message_type == spec->improtocolid) ||
|
||||
(event->xclient.message_type == spec->immoredataid)))
|
||||
return True;
|
||||
if((major_code == 1 || major_code == 2) &&
|
||||
(event->type == PropertyNotify) &&
|
||||
(event->xproperty.state == PropertyNewValue))
|
||||
return True;
|
||||
return False;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimXRead(Xim im, XPointer recv_buf, int buf_len, int *ret_len)
|
||||
{
|
||||
XEvent *ev;
|
||||
XEvent event;
|
||||
int len = 0;
|
||||
XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
|
||||
XPointer arg = spec->ev;
|
||||
|
||||
if (!arg) {
|
||||
bzero(&event, sizeof(XEvent));
|
||||
ev = &event;
|
||||
XIfEvent(im->core.display, ev, _CheckCMEvent, (XPointer)im);
|
||||
} else {
|
||||
ev = (XEvent *)arg;
|
||||
spec->ev = (XPointer)NULL;
|
||||
}
|
||||
if (!(_XimXGetReadData(im, recv_buf, buf_len, &len, ev)))
|
||||
return False;
|
||||
*ret_len = len;
|
||||
return True;
|
||||
}
|
||||
|
||||
static void
|
||||
_XimXFlush(Xim im)
|
||||
{
|
||||
XFlush(im->core.display);
|
||||
return;
|
||||
}
|
||||
|
||||
Bool
|
||||
_XimXConf(Xim im, char *address)
|
||||
{
|
||||
XSpecRec *spec;
|
||||
|
||||
if (!(spec = Xcalloc(1, sizeof(XSpecRec))))
|
||||
return False;
|
||||
|
||||
spec->improtocolid = XInternAtom(im->core.display, _XIM_PROTOCOL, False);
|
||||
spec->imconnectid = XInternAtom(im->core.display, _XIM_XCONNECT, False);
|
||||
spec->immoredataid = XInternAtom(im->core.display, _XIM_MOREDATA, False);
|
||||
spec->major_code = MAJOR_TRANSPORT_VERSION;
|
||||
spec->minor_code = MINOR_TRANSPORT_VERSION;
|
||||
|
||||
im->private.proto.spec = (XPointer)spec;
|
||||
im->private.proto.connect = _XimXConnect;
|
||||
im->private.proto.shutdown = _XimXShutdown;
|
||||
im->private.proto.write = _XimXWrite;
|
||||
im->private.proto.read = _XimXRead;
|
||||
im->private.proto.flush = _XimXFlush;
|
||||
im->private.proto.register_dispatcher = _XimXRegisterDispatcher;
|
||||
im->private.proto.call_dispatcher = _XimXCallDispatcher;
|
||||
|
||||
return True;
|
||||
}
|
||||
322
nx-X11/lib/modules/im/ximcp/imTrans.c
Normal file
322
nx-X11/lib/modules/im/ximcp/imTrans.c
Normal file
@@ -0,0 +1,322 @@
|
||||
/*
|
||||
* Copyright 1992 Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1992, 1993, 1994 by FUJITSU LIMITED
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and
|
||||
that both that copyright notice and this permission notice appear
|
||||
in supporting documentation, and that the name of FUJITSU LIMITED
|
||||
not be used in advertising or publicity pertaining to distribution
|
||||
of the software without specific, written prior permission.
|
||||
FUJITSU LIMITED makes no representations about the suitability of
|
||||
this software for any purpose.
|
||||
It is provided "as is" without express or implied warranty.
|
||||
|
||||
FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Author: Hideki Hiura (hhiura@Sun.COM) Sun Microsystems, Inc.
|
||||
Takashi Fujiwara FUJITSU LIMITED
|
||||
fujiwara@a80.tech.yk.fujitsu.co.jp
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <nx-X11/Xatom.h>
|
||||
#include <nx-X11/Xmd.h>
|
||||
#include "Xlibint.h"
|
||||
#include <nx-X11/Xtrans/Xtrans.h>
|
||||
#include "Xlcint.h"
|
||||
#include "Ximint.h"
|
||||
#include "XimTrans.h"
|
||||
#include "XimTrInt.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <nx-X11/Xwindows.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef XIM_CONNECTION_RETRIES
|
||||
#define XIM_CONNECTION_RETRIES 5
|
||||
#endif
|
||||
|
||||
|
||||
static Bool
|
||||
_XimTransConnect(
|
||||
Xim im)
|
||||
{
|
||||
TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
|
||||
int connect_stat, retry;
|
||||
Window window;
|
||||
|
||||
for (retry = XIM_CONNECTION_RETRIES; retry >= 0; retry--)
|
||||
{
|
||||
if ((spec->trans_conn = _XimXTransOpenCOTSClient (
|
||||
spec->address)) == NULL)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if ((connect_stat = _XimXTransConnect (
|
||||
spec->trans_conn, spec->address)) < 0)
|
||||
{
|
||||
_XimXTransClose (spec->trans_conn);
|
||||
spec->trans_conn = NULL;
|
||||
|
||||
if (connect_stat == TRANS_TRY_CONNECT_AGAIN)
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (spec->trans_conn == NULL)
|
||||
return False;
|
||||
|
||||
spec->fd = _XimXTransGetConnectionNumber (spec->trans_conn);
|
||||
|
||||
if (!(window = XCreateSimpleWindow(im->core.display,
|
||||
DefaultRootWindow(im->core.display), 0, 0, 1, 1, 1, 0, 0)))
|
||||
return False;
|
||||
spec->window = window;
|
||||
|
||||
_XRegisterFilterByType(im->core.display, window, KeyPress, KeyPress,
|
||||
_XimTransFilterWaitEvent, (XPointer)im);
|
||||
|
||||
return _XRegisterInternalConnection(im->core.display, spec->fd,
|
||||
(_XInternalConnectionProc)_XimTransInternalConnection,
|
||||
(XPointer)im);
|
||||
}
|
||||
|
||||
|
||||
static Bool
|
||||
_XimTransShutdown(
|
||||
Xim im)
|
||||
{
|
||||
TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
|
||||
|
||||
_XimXTransDisconnect(spec->trans_conn);
|
||||
(void)_XimXTransClose(spec->trans_conn);
|
||||
_XimFreeTransIntrCallback(im);
|
||||
_XUnregisterInternalConnection(im->core.display, spec->fd);
|
||||
_XUnregisterFilter(im->core.display, spec->window,
|
||||
_XimTransFilterWaitEvent, (XPointer)im);
|
||||
XDestroyWindow(im->core.display, spec->window);
|
||||
Xfree(spec->address);
|
||||
Xfree(spec);
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Bool
|
||||
_XimTransRegisterDispatcher(
|
||||
Xim im,
|
||||
Bool (*callback)(
|
||||
Xim, INT16, XPointer, XPointer
|
||||
),
|
||||
XPointer call_data)
|
||||
{
|
||||
TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
|
||||
TransIntrCallbackPtr rec;
|
||||
|
||||
if (!(rec = Xmalloc(sizeof(TransIntrCallbackRec))))
|
||||
return False;
|
||||
|
||||
rec->func = callback;
|
||||
rec->call_data = call_data;
|
||||
rec->next = spec->intr_cb;
|
||||
spec->intr_cb = rec;
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_XimFreeTransIntrCallback(
|
||||
Xim im)
|
||||
{
|
||||
TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
|
||||
register TransIntrCallbackPtr rec, next;
|
||||
|
||||
for (rec = spec->intr_cb; rec;) {
|
||||
next = rec->next;
|
||||
Xfree(rec);
|
||||
rec = next;
|
||||
}
|
||||
spec->intr_cb = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Bool
|
||||
_XimTransCallDispatcher(Xim im, INT16 len, XPointer data)
|
||||
{
|
||||
TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
|
||||
TransIntrCallbackRec *rec;
|
||||
|
||||
for (rec = spec->intr_cb; rec; rec = rec->next) {
|
||||
if ((*rec->func)(im, len, data, rec->call_data))
|
||||
return True;
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
||||
|
||||
Bool
|
||||
_XimTransFilterWaitEvent(
|
||||
Display *d,
|
||||
Window w,
|
||||
XEvent *ev,
|
||||
XPointer arg)
|
||||
{
|
||||
Xim im = (Xim)arg;
|
||||
TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
|
||||
|
||||
spec->is_putback = False;
|
||||
return _XimFilterWaitEvent(im);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_XimTransInternalConnection(
|
||||
Display *d,
|
||||
int fd,
|
||||
XPointer arg)
|
||||
{
|
||||
Xim im = (Xim)arg;
|
||||
XEvent ev;
|
||||
XKeyEvent *kev;
|
||||
TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
|
||||
|
||||
if (spec->is_putback)
|
||||
return;
|
||||
|
||||
bzero(&ev, sizeof(ev)); /* FIXME: other fields may be accessed, too. */
|
||||
kev = (XKeyEvent *)&ev;
|
||||
kev->type = KeyPress;
|
||||
kev->send_event = False;
|
||||
kev->display = im->core.display;
|
||||
kev->window = spec->window;
|
||||
kev->keycode = 0;
|
||||
kev->time = 0L;
|
||||
kev->serial = LastKnownRequestProcessed(im->core.display);
|
||||
#if 0
|
||||
fprintf(stderr,"%s,%d: putback FIXED kev->time=0 kev->serial=%lu\n", __FILE__, __LINE__, kev->serial);
|
||||
#endif
|
||||
|
||||
XPutBackEvent(im->core.display, &ev);
|
||||
XFlush(im->core.display);
|
||||
spec->is_putback = True;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Bool
|
||||
_XimTransWrite(Xim im, INT16 len, XPointer data)
|
||||
{
|
||||
TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
|
||||
char *buf = (char *)data;
|
||||
register int nbyte;
|
||||
|
||||
while (len > 0) {
|
||||
if ((nbyte = _XimXTransWrite(spec->trans_conn, buf, len)) <= 0)
|
||||
return False;
|
||||
len -= nbyte;
|
||||
buf += nbyte;
|
||||
}
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
Bool
|
||||
_XimTransRead(
|
||||
Xim im,
|
||||
XPointer recv_buf,
|
||||
int buf_len,
|
||||
int *ret_len)
|
||||
{
|
||||
TransSpecRec *spec = (TransSpecRec *)im->private.proto.spec;
|
||||
int len;
|
||||
|
||||
if (buf_len == 0) {
|
||||
*ret_len = 0;
|
||||
return True;
|
||||
}
|
||||
if ((len = _XimXTransRead(spec->trans_conn, recv_buf, buf_len)) <= 0)
|
||||
return False;
|
||||
*ret_len = len;
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_XimTransFlush(
|
||||
Xim im)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Bool
|
||||
_XimTransConf(
|
||||
Xim im,
|
||||
char *address)
|
||||
{
|
||||
char *paddr;
|
||||
TransSpecRec *spec;
|
||||
|
||||
if (!(paddr = strdup(address)))
|
||||
return False;
|
||||
|
||||
if (!(spec = Xcalloc(1, sizeof(TransSpecRec)))) {
|
||||
Xfree(paddr);
|
||||
return False;
|
||||
}
|
||||
|
||||
spec->address = paddr;
|
||||
|
||||
im->private.proto.spec = (XPointer)spec;
|
||||
im->private.proto.connect = _XimTransConnect;
|
||||
im->private.proto.shutdown = _XimTransShutdown;
|
||||
im->private.proto.write = _XimTransWrite;
|
||||
im->private.proto.read = _XimTransRead;
|
||||
im->private.proto.flush = _XimTransFlush;
|
||||
im->private.proto.register_dispatcher = _XimTransRegisterDispatcher;
|
||||
im->private.proto.call_dispatcher = _XimTransCallDispatcher;
|
||||
|
||||
return True;
|
||||
}
|
||||
306
nx-X11/lib/modules/im/ximcp/imTransR.c
Normal file
306
nx-X11/lib/modules/im/ximcp/imTransR.c
Normal file
@@ -0,0 +1,306 @@
|
||||
/*
|
||||
* Copyright 1992 Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1992, 1993, 1994 by FUJITSU LIMITED
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and
|
||||
that both that copyright notice and this permission notice appear
|
||||
in supporting documentation, and that the name of FUJITSU LIMITED
|
||||
not be used in advertising or publicity pertaining to distribution
|
||||
of the software without specific, written prior permission.
|
||||
FUJITSU LIMITED makes no representations about the suitability of
|
||||
this software for any purpose.
|
||||
It is provided "as is" without express or implied warranty.
|
||||
|
||||
FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Author: Hideki Hiura (hhiura@Sun.COM) Sun Microsystems, Inc.
|
||||
Takashi Fujiwara FUJITSU LIMITED
|
||||
fujiwara@a80.tech.yk.fujitsu.co.jp
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include "Xlibint.h"
|
||||
#include "Xlcint.h"
|
||||
#include "XimTrInt.h"
|
||||
#include "Ximint.h"
|
||||
|
||||
TransportSW _XimTransportRec[] = {
|
||||
{ "X", _XimXConf }, /* 1st entry must be X.
|
||||
This will be a fallback */
|
||||
#ifdef TCPCONN
|
||||
{ "tcp", _XimTransConf }, /* use X transport lib */
|
||||
#endif /* TCPCONN */
|
||||
#if defined(UNIXCONN) || defined(LOCALCONN)
|
||||
{ "local", _XimTransConf }, /* use X transport lib */
|
||||
#endif /* UNIXCONN */
|
||||
{ (char *)NULL, (Bool (*)(Xim, char *))NULL },
|
||||
};
|
||||
|
||||
Bool
|
||||
_XimConnect(Xim im)
|
||||
{
|
||||
return im->private.proto.connect(im);
|
||||
}
|
||||
|
||||
Bool
|
||||
_XimShutdown(Xim im)
|
||||
{
|
||||
return im->private.proto.shutdown(im);
|
||||
}
|
||||
|
||||
Bool
|
||||
_XimWrite(Xim im, INT16 len, XPointer data)
|
||||
{
|
||||
return im->private.proto.write(im, len, data);
|
||||
}
|
||||
|
||||
static int
|
||||
_CheckProtocolData(
|
||||
Xim im,
|
||||
char *recv_buf)
|
||||
{
|
||||
int data_len;
|
||||
|
||||
data_len = (int)(((*((CARD16 *)recv_buf + 1)) * 4) + XIM_HEADER_SIZE);
|
||||
return data_len;
|
||||
}
|
||||
|
||||
static int
|
||||
_XimReadData(
|
||||
Xim im,
|
||||
INT16 *len,
|
||||
XPointer buf,
|
||||
int buf_size)
|
||||
{
|
||||
char *hold_buf;
|
||||
char *tmp;
|
||||
int data_len;
|
||||
int packet_size;
|
||||
int ret_len;
|
||||
register int i;
|
||||
|
||||
if (buf_size < XIM_HEADER_SIZE) {
|
||||
*len = (INT16)XIM_HEADER_SIZE;
|
||||
return XIM_OVERFLOW;
|
||||
}
|
||||
|
||||
bzero(buf, buf_size);
|
||||
packet_size = 0;
|
||||
data_len = 0;
|
||||
|
||||
if ((hold_buf = im->private.proto.hold_data)) {
|
||||
data_len = im->private.proto.hold_data_len;
|
||||
if (data_len >= XIM_HEADER_SIZE) {
|
||||
packet_size = _CheckProtocolData(im, hold_buf);
|
||||
if (packet_size > buf_size) {
|
||||
*len = (INT16)packet_size;
|
||||
return XIM_OVERFLOW;
|
||||
}
|
||||
if (packet_size <= data_len) {
|
||||
memcpy(buf, hold_buf, packet_size);
|
||||
for (i = packet_size; i < data_len; i++) {
|
||||
if (hold_buf[i])
|
||||
break;
|
||||
}
|
||||
data_len -= i;
|
||||
|
||||
if (data_len) {
|
||||
if (!(tmp = Xmalloc(data_len))) {
|
||||
return XIM_FALSE;
|
||||
}
|
||||
memcpy(tmp, &hold_buf[i], data_len);
|
||||
im->private.proto.hold_data = tmp;
|
||||
im->private.proto.hold_data_len = data_len;
|
||||
} else {
|
||||
im->private.proto.hold_data = 0;
|
||||
im->private.proto.hold_data_len = 0;
|
||||
}
|
||||
Xfree(hold_buf);
|
||||
*len = (INT16)packet_size;
|
||||
return XIM_TRUE;
|
||||
}
|
||||
}
|
||||
memcpy(buf, hold_buf, data_len);
|
||||
buf_size -= data_len;
|
||||
Xfree(hold_buf);
|
||||
im->private.proto.hold_data = 0;
|
||||
im->private.proto.hold_data_len = 0;
|
||||
}
|
||||
|
||||
if (!packet_size) {
|
||||
while (data_len < XIM_HEADER_SIZE) {
|
||||
if (!(im->private.proto.read(im,
|
||||
(XPointer)&buf[data_len], buf_size, &ret_len))) {
|
||||
return XIM_FALSE;
|
||||
}
|
||||
data_len += ret_len;
|
||||
buf_size -= ret_len;
|
||||
}
|
||||
packet_size = _CheckProtocolData(im, buf);
|
||||
}
|
||||
|
||||
if (packet_size > buf_size) {
|
||||
if (!(tmp = Xmalloc(data_len))) {
|
||||
return XIM_FALSE;
|
||||
}
|
||||
memcpy(tmp, buf, data_len);
|
||||
bzero(buf, data_len);
|
||||
im->private.proto.hold_data = tmp;
|
||||
im->private.proto.hold_data_len = data_len;
|
||||
*len = (INT16)packet_size;
|
||||
return XIM_OVERFLOW;
|
||||
}
|
||||
|
||||
while (data_len < packet_size) {
|
||||
if (!(im->private.proto.read(im,
|
||||
(XPointer)&buf[data_len], buf_size, &ret_len))) {
|
||||
return XIM_FALSE;
|
||||
}
|
||||
data_len += ret_len;
|
||||
buf_size -= ret_len;
|
||||
}
|
||||
|
||||
for (i = packet_size; i < data_len; i++) {
|
||||
if (buf[i])
|
||||
break;
|
||||
}
|
||||
data_len -= i;
|
||||
|
||||
if (data_len) {
|
||||
if (!(tmp = Xmalloc(data_len))) {
|
||||
return XIM_FALSE;
|
||||
}
|
||||
memcpy(tmp, &buf[i], data_len);
|
||||
bzero(&buf[i], data_len);
|
||||
im->private.proto.hold_data = tmp;
|
||||
im->private.proto.hold_data_len = data_len;
|
||||
} else {
|
||||
im->private.proto.hold_data = 0;
|
||||
im->private.proto.hold_data_len = 0;
|
||||
}
|
||||
*len = (INT16)packet_size;
|
||||
return XIM_TRUE;
|
||||
}
|
||||
|
||||
static Bool
|
||||
_XimCallDispatcher(
|
||||
Xim im,
|
||||
INT16 len,
|
||||
XPointer data)
|
||||
{
|
||||
return im->private.proto.call_dispatcher(im, len, data);
|
||||
}
|
||||
|
||||
int
|
||||
_XimRead(Xim im, INT16 *len, XPointer buf, int buf_size,
|
||||
Bool (*predicate)(Xim, INT16, XPointer, XPointer), XPointer arg)
|
||||
{
|
||||
INT16 read_len;
|
||||
int ret_code;
|
||||
|
||||
for (;;) {
|
||||
ret_code = _XimReadData(im, &read_len, buf, buf_size);
|
||||
if(ret_code != XIM_TRUE) {
|
||||
return ret_code;
|
||||
}
|
||||
if ((*predicate)(im, read_len, buf, arg))
|
||||
break;
|
||||
if (_XimCallDispatcher(im, read_len, buf))
|
||||
continue;
|
||||
_XimError(im, 0, XIM_BadProtocol, (INT16)0, (CARD16)0, (char *)NULL);
|
||||
}
|
||||
*len = read_len;
|
||||
return True;
|
||||
}
|
||||
|
||||
Bool
|
||||
_XimRegisterDispatcher(
|
||||
Xim im,
|
||||
Bool (*callback)(
|
||||
Xim, INT16, XPointer, XPointer
|
||||
),
|
||||
XPointer call_data)
|
||||
{
|
||||
return im->private.proto.register_dispatcher(im, callback, call_data);
|
||||
}
|
||||
|
||||
void
|
||||
_XimFlush(Xim im)
|
||||
{
|
||||
im->private.proto.flush(im);
|
||||
return;
|
||||
}
|
||||
|
||||
Bool
|
||||
_XimFilterWaitEvent(Xim im)
|
||||
{
|
||||
INT16 read_len;
|
||||
CARD32 reply32[BUFSIZE/4];
|
||||
char *reply = (char *)reply32;
|
||||
XPointer preply;
|
||||
int buf_size;
|
||||
int ret_code;
|
||||
|
||||
buf_size = BUFSIZE;
|
||||
ret_code = _XimReadData(im, &read_len, (XPointer)reply, buf_size);
|
||||
if(ret_code == XIM_TRUE) {
|
||||
preply = reply;
|
||||
} else if(ret_code == XIM_OVERFLOW) {
|
||||
if(read_len <= 0) {
|
||||
preply = reply;
|
||||
} else {
|
||||
buf_size = (int)read_len;
|
||||
preply = Xmalloc(buf_size);
|
||||
ret_code = _XimReadData(im, &read_len, preply, buf_size);
|
||||
if(ret_code != XIM_TRUE) {
|
||||
if (preply != reply)
|
||||
Xfree(preply);
|
||||
return False;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return False;
|
||||
}
|
||||
if (_XimCallDispatcher(im, read_len, preply)) {
|
||||
if(reply != preply)
|
||||
Xfree(preply);
|
||||
return True;
|
||||
}
|
||||
_XimError(im, 0, XIM_BadProtocol, (INT16)0, (CARD16)0, (char *)NULL);
|
||||
if(reply != preply)
|
||||
Xfree(preply);
|
||||
return True;
|
||||
}
|
||||
1
nx-X11/lib/modules/lc/Makefile.am
Normal file
1
nx-X11/lib/modules/lc/Makefile.am
Normal file
@@ -0,0 +1 @@
|
||||
SUBDIRS = Utf8 def gen
|
||||
28
nx-X11/lib/modules/lc/Utf8/Makefile.am
Normal file
28
nx-X11/lib/modules/lc/Utf8/Makefile.am
Normal file
@@ -0,0 +1,28 @@
|
||||
NULL =
|
||||
|
||||
noinst_LTLIBRARIES = libxlcUTF8Load.la
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/include/X11 \
|
||||
-I$(top_builddir)/include \
|
||||
-I$(top_builddir)/include/X11 \
|
||||
-I$(top_srcdir)/src/xcms \
|
||||
-I$(top_srcdir)/src/xkb \
|
||||
-I$(top_srcdir)/src/xlibi18n \
|
||||
-I$(top_srcdir)/../exports/include \
|
||||
-D_GNU_SOURCE \
|
||||
$(NULL)
|
||||
|
||||
AM_CFLAGS = \
|
||||
$(X11_CFLAGS) \
|
||||
$(BIGFONT_CFLAGS) \
|
||||
$(MALLOC_ZERO_CFLAGS) \
|
||||
$(CWARNFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
xlcUTF8Load_la_SOURCES = \
|
||||
lcUTF8Load.c \
|
||||
$(NULL)
|
||||
|
||||
libxlcUTF8Load_la_SOURCES = $(xlcUTF8Load_la_SOURCES)
|
||||
70
nx-X11/lib/modules/lc/Utf8/lcUTF8Load.c
Normal file
70
nx-X11/lib/modules/lc/Utf8/lcUTF8Load.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/******************************************************************
|
||||
|
||||
Copyright 1993 by SunSoft, Inc.
|
||||
Copyright 1999-2000 by Bruno Haible
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this software
|
||||
and its documentation for any purpose is hereby granted without fee,
|
||||
provided that the above copyright notice appear in all copies and
|
||||
that both that copyright notice and this permission notice appear
|
||||
in supporting documentation, and that the names of SunSoft, Inc. and
|
||||
Bruno Haible not be used in advertising or publicity pertaining to
|
||||
distribution of the software without specific, written prior
|
||||
permission. SunSoft, Inc. and Bruno Haible make no representations
|
||||
about the suitability of this software for any purpose. It is
|
||||
provided "as is" without express or implied warranty.
|
||||
|
||||
SunSoft Inc. AND Bruno Haible DISCLAIM ALL WARRANTIES WITH REGARD
|
||||
TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS, IN NO EVENT SHALL SunSoft, Inc. OR Bruno Haible BE LIABLE
|
||||
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
******************************************************************/
|
||||
|
||||
/*
|
||||
* This file contains the UTF-8 locale loader.
|
||||
* Supports: all locales with codeset UTF-8.
|
||||
* Platforms: all systems.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include "Xlibint.h"
|
||||
#include "XlcPubI.h"
|
||||
#include "XlcGeneric.h"
|
||||
|
||||
XLCd
|
||||
_XlcUtf8Loader(
|
||||
const char *name)
|
||||
{
|
||||
XLCd lcd;
|
||||
|
||||
lcd = _XlcCreateLC(name, _XlcGenericMethods);
|
||||
if (lcd == (XLCd) NULL)
|
||||
return lcd;
|
||||
|
||||
/* The official IANA name for UTF-8 is "UTF-8" in upper case with a dash. */
|
||||
if (!XLC_PUBLIC_PART(lcd)->codeset) {
|
||||
_XlcDestroyLC(lcd);
|
||||
return (XLCd) NULL;
|
||||
}
|
||||
else if (!_XlcCompareISOLatin1(XLC_PUBLIC_PART(lcd)->codeset, "UTF-8")) {
|
||||
_XlcAddUtf8LocaleConverters(lcd);
|
||||
}
|
||||
else if (!_XlcCompareISOLatin1(XLC_PUBLIC_PART(lcd)->codeset, "GB18030")) {
|
||||
_XlcAddGB18030LocaleConverters(lcd);
|
||||
}
|
||||
else {
|
||||
_XlcDestroyLC(lcd);
|
||||
return (XLCd) NULL;
|
||||
}
|
||||
|
||||
_XlcAddUtf8Converters(lcd);
|
||||
|
||||
return lcd;
|
||||
}
|
||||
27
nx-X11/lib/modules/lc/def/Makefile.am
Normal file
27
nx-X11/lib/modules/lc/def/Makefile.am
Normal file
@@ -0,0 +1,27 @@
|
||||
NULL =
|
||||
|
||||
noinst_LTLIBRARIES = libxlcDef.la
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/include/X11 \
|
||||
-I$(top_builddir)/include \
|
||||
-I$(top_builddir)/include/X11 \
|
||||
-I$(top_srcdir)/src/xcms \
|
||||
-I$(top_srcdir)/src/xkb \
|
||||
-I$(top_srcdir)/src/xlibi18n \
|
||||
-I$(top_srcdir)/../exports/include \
|
||||
-D_GNU_SOURCE \
|
||||
$(NULL)
|
||||
|
||||
AM_CFLAGS = \
|
||||
$(X11_CFLAGS) \
|
||||
$(BIGFONT_CFLAGS) \
|
||||
$(CWARNFLAG) \
|
||||
$(NULL)
|
||||
|
||||
xlcDef_la_SOURCES = \
|
||||
lcDefConv.c \
|
||||
$(NULL)
|
||||
|
||||
libxlcDef_la_SOURCES = $(xlcDef_la_SOURCES)
|
||||
806
nx-X11/lib/modules/lc/def/lcDefConv.c
Normal file
806
nx-X11/lib/modules/lc/def/lcDefConv.c
Normal file
@@ -0,0 +1,806 @@
|
||||
/*
|
||||
* Copyright 1992, 1993 by TOSHIBA Corp.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation for any purpose and without fee is hereby granted, provided
|
||||
* that the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of TOSHIBA not be used in advertising
|
||||
* or publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. TOSHIBA make no representations about the
|
||||
* suitability of this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*
|
||||
* TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||
* TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
||||
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Author: Katsuhisa Yano TOSHIBA Corp.
|
||||
* mopi@osa.ilab.toshiba.co.jp
|
||||
*/
|
||||
/*
|
||||
* 2000
|
||||
* Modifier: Ivan Pascal The XFree86 Project
|
||||
*/
|
||||
|
||||
/*
|
||||
* The default locale loader.
|
||||
* Supports: one byte per char (iso8859 like) locales.
|
||||
* How: converts bytes to wide characters in a 1:1 manner.
|
||||
* Platforms: all systems.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include "Xlibint.h"
|
||||
#include "XlcGeneric.h"
|
||||
|
||||
#ifndef MB_LEN_MAX
|
||||
#define MB_LEN_MAX 6
|
||||
#endif
|
||||
|
||||
#if !defined(X_LOCALE)
|
||||
#define STDCVT
|
||||
#endif
|
||||
|
||||
#define GR 0x80
|
||||
#define GL 0x7f
|
||||
|
||||
typedef struct _StateRec *State;
|
||||
typedef struct _StateRec {
|
||||
CodeSet GL_codeset;
|
||||
CodeSet GR_codeset;
|
||||
wchar_t wc_mask;
|
||||
wchar_t wc_encode_mask;
|
||||
Bool (*MBtoWC) (State state, const char *ch, wchar_t *wc);
|
||||
Bool (*WCtoMB) (State state, wchar_t wc, char *ch);
|
||||
} StateRec;
|
||||
|
||||
static
|
||||
Bool MBtoWCdef(
|
||||
State state,
|
||||
const char *ch,
|
||||
wchar_t *wc)
|
||||
{
|
||||
wchar_t wc_encoding;
|
||||
CodeSet codeset = (*ch & GR) ? state->GR_codeset : state->GL_codeset;
|
||||
if (!codeset)
|
||||
return False;
|
||||
wc_encoding = codeset->wc_encoding;
|
||||
*wc = ((wchar_t) *ch & state->wc_mask) | wc_encoding;
|
||||
return True;
|
||||
}
|
||||
|
||||
#ifdef STDCVT
|
||||
static
|
||||
Bool MBtoWCstd(
|
||||
State state,
|
||||
const char *ch,
|
||||
wchar_t *wc)
|
||||
{
|
||||
return (mbtowc(wc, ch, 1) == 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
static
|
||||
Bool WCtoMBdef(
|
||||
State state,
|
||||
wchar_t wc,
|
||||
char *ch)
|
||||
{
|
||||
wchar_t wc_encoding = wc & state->wc_encode_mask;
|
||||
CodeSet codeset;
|
||||
|
||||
codeset = state->GL_codeset;
|
||||
if (codeset && (wc_encoding == codeset->wc_encoding)) {
|
||||
*ch = wc & state->wc_mask;
|
||||
return True;
|
||||
}
|
||||
codeset = state->GR_codeset;
|
||||
if (codeset && (wc_encoding == codeset->wc_encoding)) {
|
||||
*ch = (wc & state->wc_mask) | GR;
|
||||
return True;
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
||||
#ifdef STDCVT
|
||||
static
|
||||
Bool WCtoMBstd(
|
||||
State state,
|
||||
wchar_t wc,
|
||||
char *ch)
|
||||
{
|
||||
return (wctomb(ch, wc) == 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
static
|
||||
XlcCharSet get_charset(
|
||||
State state,
|
||||
char side)
|
||||
{
|
||||
CodeSet codeset = side ? state->GR_codeset : state->GL_codeset;
|
||||
if (codeset) {
|
||||
int i;
|
||||
XlcCharSet charset;
|
||||
for (i = 0; i < codeset->num_charsets; i++) {
|
||||
charset = codeset->charset_list[i];
|
||||
if (*charset->ct_sequence != '\0')
|
||||
return charset;
|
||||
}
|
||||
return *(codeset->charset_list);
|
||||
}
|
||||
return (XlcCharSet) NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
def_mbstowcs(
|
||||
XlcConv conv,
|
||||
XPointer *from,
|
||||
int *from_left,
|
||||
XPointer *to,
|
||||
int *to_left,
|
||||
XPointer *args,
|
||||
int num_args)
|
||||
{
|
||||
const char *src;
|
||||
wchar_t *dst = (wchar_t *) *to;
|
||||
State state = (State) conv->state;
|
||||
int unconv = 0;
|
||||
|
||||
if (from == NULL || *from == NULL)
|
||||
return 0;
|
||||
|
||||
src = (const char *) *from;
|
||||
|
||||
while (*from_left && *to_left) {
|
||||
(*from_left)--;
|
||||
if (state->MBtoWC (state, src++, dst)) {
|
||||
dst++;
|
||||
(*to_left)--;
|
||||
} else {
|
||||
unconv++;
|
||||
}
|
||||
}
|
||||
*from = (XPointer) src;
|
||||
*to = (XPointer) dst;
|
||||
return unconv;
|
||||
}
|
||||
|
||||
static int
|
||||
def_wcstombs(
|
||||
XlcConv conv,
|
||||
XPointer *from,
|
||||
int *from_left,
|
||||
XPointer *to,
|
||||
int *to_left,
|
||||
XPointer *args,
|
||||
int num_args)
|
||||
{
|
||||
const wchar_t *src;
|
||||
char *dst = (char *) *to;
|
||||
State state = (State) conv->state;
|
||||
char ch[MB_LEN_MAX];
|
||||
int unconv = 0;
|
||||
|
||||
if (from == NULL || *from == NULL)
|
||||
return 0;
|
||||
|
||||
src = (const wchar_t *) *from;
|
||||
|
||||
while (*from_left && *to_left) {
|
||||
(*from_left)--;
|
||||
if (state->WCtoMB (state, *src++, ch)) {
|
||||
*dst++ = *ch;
|
||||
(*to_left)--;
|
||||
} else {
|
||||
unconv++;
|
||||
}
|
||||
}
|
||||
*from = (XPointer) src;
|
||||
*to = (XPointer) dst;
|
||||
return unconv;
|
||||
}
|
||||
|
||||
static int
|
||||
mbstostr(
|
||||
XlcConv conv,
|
||||
XPointer *from,
|
||||
int *from_left,
|
||||
XPointer *to,
|
||||
int *to_left,
|
||||
XPointer *args,
|
||||
int num_args)
|
||||
{
|
||||
const char *src;
|
||||
char *dst = (char *) *to;
|
||||
CodeSet codeset;
|
||||
State state = (State) conv->state;
|
||||
char ch;
|
||||
int unconv = 0;
|
||||
|
||||
if (from == NULL || *from == NULL)
|
||||
return 0;
|
||||
|
||||
src = (const char *) *from;
|
||||
|
||||
while (*from_left && *to_left) {
|
||||
ch = *src++;
|
||||
(*from_left)--;
|
||||
|
||||
codeset = (ch & GR) ? state->GR_codeset : state->GL_codeset;
|
||||
if (codeset && codeset->string_encoding) {
|
||||
*dst++ = ch;
|
||||
(*to_left)--;
|
||||
} else {
|
||||
unconv++;
|
||||
}
|
||||
}
|
||||
*from = (XPointer) src;
|
||||
*to = (XPointer) dst;
|
||||
return unconv;
|
||||
}
|
||||
|
||||
static int
|
||||
wcstostr(
|
||||
XlcConv conv,
|
||||
XPointer *from,
|
||||
int *from_left,
|
||||
XPointer *to,
|
||||
int *to_left,
|
||||
XPointer *args,
|
||||
int num_args)
|
||||
{
|
||||
const wchar_t *src;
|
||||
char *dst = (char *) *to;
|
||||
CodeSet codeset;
|
||||
State state = (State) conv->state;
|
||||
char ch[MB_LEN_MAX];
|
||||
int unconv = 0;
|
||||
|
||||
if (from == NULL || *from == NULL)
|
||||
return 0;
|
||||
|
||||
src = (const wchar_t *) *from;
|
||||
|
||||
while (*from_left && *to_left) {
|
||||
(*from_left)--;
|
||||
if (state->WCtoMB (state, *src++, ch)) {
|
||||
codeset = (*ch & GR) ? state->GR_codeset : state->GL_codeset;
|
||||
if (codeset && codeset->string_encoding) {
|
||||
*dst++ = *ch;
|
||||
(*to_left)--;
|
||||
} else {
|
||||
unconv++;
|
||||
}
|
||||
} else {
|
||||
unconv++;
|
||||
}
|
||||
}
|
||||
*from = (XPointer) src;
|
||||
*to = (XPointer) dst;
|
||||
return unconv;
|
||||
}
|
||||
|
||||
static int
|
||||
mbstocs(
|
||||
XlcConv conv,
|
||||
XPointer *from,
|
||||
int *from_left,
|
||||
XPointer *to,
|
||||
int *to_left,
|
||||
XPointer *args,
|
||||
int num_args)
|
||||
{
|
||||
const char *src;
|
||||
char *dst = (char *) *to;
|
||||
int length;
|
||||
State state = (State) conv->state;
|
||||
char cur_side;
|
||||
int unconv = 0;
|
||||
|
||||
if (from == NULL || *from == NULL)
|
||||
return 0;
|
||||
|
||||
src = (const char *) *from;
|
||||
length = min(*from_left, *to_left);
|
||||
|
||||
cur_side = *src & GR;
|
||||
while (length) {
|
||||
if ((char) (*src & GR) != cur_side)
|
||||
break;
|
||||
*dst++ = *src++;
|
||||
length--;
|
||||
}
|
||||
|
||||
if (num_args > 0) {
|
||||
XlcCharSet charset = get_charset(state, cur_side);
|
||||
if (charset) {
|
||||
*((XlcCharSet *) args[0]) = charset;
|
||||
} else {
|
||||
dst = *to;
|
||||
unconv = -1;
|
||||
}
|
||||
}
|
||||
*from_left -= src - (char *) *from;
|
||||
*to_left -= dst - (char *) *to;
|
||||
*from = (XPointer) src;
|
||||
*to = (XPointer) dst;
|
||||
return unconv;
|
||||
}
|
||||
|
||||
static int
|
||||
wcstocs(
|
||||
XlcConv conv,
|
||||
XPointer *from,
|
||||
int *from_left,
|
||||
XPointer *to,
|
||||
int *to_left,
|
||||
XPointer *args,
|
||||
int num_args)
|
||||
{
|
||||
const wchar_t *src;
|
||||
char *dst = (char *) *to;
|
||||
State state = (State) conv->state;
|
||||
char cur_side = 0, ch[MB_LEN_MAX];
|
||||
int unconv = 0;
|
||||
Bool found = False;
|
||||
|
||||
if (from == NULL || *from == NULL)
|
||||
return 0;
|
||||
|
||||
src = (const wchar_t *) *from;
|
||||
|
||||
while (*from_left) {
|
||||
if ((found = state->WCtoMB (state, *src, ch)))
|
||||
break;
|
||||
unconv++;
|
||||
src++;
|
||||
(*from_left)--;
|
||||
}
|
||||
|
||||
if (found) {
|
||||
cur_side = *ch & GR;
|
||||
while (*from_left && *to_left) {
|
||||
(*from_left)--;
|
||||
if (state->WCtoMB (state, *src++, ch)) {
|
||||
if ((char) (*ch & GR) != cur_side) {
|
||||
src--;
|
||||
(*from_left)++;
|
||||
break;
|
||||
} else {
|
||||
*dst++ = *ch;
|
||||
(*to_left)--;
|
||||
}
|
||||
} else {
|
||||
unconv++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unconv++;
|
||||
}
|
||||
|
||||
if (num_args > 0) {
|
||||
XlcCharSet charset = get_charset(state, cur_side);
|
||||
if (charset) {
|
||||
*((XlcCharSet *) args[0]) = charset;
|
||||
} else {
|
||||
unconv = -1;
|
||||
}
|
||||
}
|
||||
*from = (XPointer) src;
|
||||
*to = (XPointer) dst;
|
||||
return unconv;
|
||||
}
|
||||
|
||||
static int
|
||||
cstombs(
|
||||
XlcConv conv,
|
||||
XPointer *from,
|
||||
int *from_left,
|
||||
XPointer *to,
|
||||
int *to_left,
|
||||
XPointer *args,
|
||||
int num_args)
|
||||
{
|
||||
const char *src;
|
||||
char *dst = (char *) *to;
|
||||
CodeSet codeset;
|
||||
XlcCharSet charset;
|
||||
State state = (State) conv->state;
|
||||
unsigned char cur_side = 0;
|
||||
int i;
|
||||
Bool found = False;
|
||||
|
||||
if (from == NULL || *from == NULL)
|
||||
return 0;
|
||||
|
||||
src = (const char *) *from;
|
||||
|
||||
if (num_args > 0) {
|
||||
charset = (XlcCharSet) args[0];
|
||||
if (charset == NULL)
|
||||
return -1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((charset->side == XlcGL) || (charset->side == XlcGLGR)) {
|
||||
codeset = state->GL_codeset;
|
||||
if (codeset) {
|
||||
for (i = 0; i < codeset->num_charsets; i++)
|
||||
if (charset == codeset->charset_list[i]) {
|
||||
found = True;
|
||||
cur_side = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found && ((charset->side == XlcGR) || (charset->side == XlcGLGR))) {
|
||||
codeset = state->GR_codeset;
|
||||
if (codeset) {
|
||||
for (i = 0; i < codeset->num_charsets; i++)
|
||||
if (charset == codeset->charset_list[i]) {
|
||||
found = True;
|
||||
cur_side = GR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
int length = min(*from_left, *to_left);
|
||||
while (length) {
|
||||
*dst++ = *src++ | cur_side;
|
||||
length--;
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*from_left -= src - (char *) *from;
|
||||
*to_left -= dst - (char *) *to;
|
||||
*from = (XPointer) src;
|
||||
*to = (XPointer) dst;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
cstowcs(
|
||||
XlcConv conv,
|
||||
XPointer *from,
|
||||
int *from_left,
|
||||
XPointer *to,
|
||||
int *to_left,
|
||||
XPointer *args,
|
||||
int num_args)
|
||||
{
|
||||
const char *src;
|
||||
wchar_t *dst = (wchar_t *) *to;
|
||||
CodeSet codeset;
|
||||
XlcCharSet charset;
|
||||
State state = (State) conv->state;
|
||||
Bool found = False;
|
||||
int i, unconv = 0;
|
||||
unsigned char cur_side = 0;
|
||||
|
||||
if (from == NULL || *from == NULL)
|
||||
return 0;
|
||||
|
||||
src = (const char *) *from;
|
||||
|
||||
if (num_args > 0) {
|
||||
charset = (XlcCharSet) args[0];
|
||||
if (charset == NULL)
|
||||
return -1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((charset->side == XlcGL) || (charset->side == XlcGLGR)) {
|
||||
codeset = state->GL_codeset;
|
||||
if (codeset) {
|
||||
for (i = 0; i < codeset->num_charsets; i++)
|
||||
if (charset == codeset->charset_list[i]) {
|
||||
found = True;
|
||||
cur_side = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found && ((charset->side == XlcGR) || (charset->side == XlcGLGR))) {
|
||||
codeset = state->GR_codeset;
|
||||
if (codeset) {
|
||||
for (i = 0; i < codeset->num_charsets; i++)
|
||||
if (charset == codeset->charset_list[i]) {
|
||||
found = True;
|
||||
cur_side = GR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
char ch;
|
||||
while (*from_left && *to_left) {
|
||||
ch = *src++ | cur_side;
|
||||
(*from_left)--;
|
||||
if (state->MBtoWC (state, &ch, dst)) {
|
||||
dst++;
|
||||
(*to_left)--;
|
||||
} else {
|
||||
unconv++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
*from = (XPointer) src;
|
||||
*to = (XPointer) dst;
|
||||
return unconv;
|
||||
}
|
||||
|
||||
static int
|
||||
strtombs(
|
||||
XlcConv conv,
|
||||
XPointer *from,
|
||||
int *from_left,
|
||||
XPointer *to,
|
||||
int *to_left,
|
||||
XPointer *args,
|
||||
int num_args)
|
||||
{
|
||||
const char *src;
|
||||
char *dst = (char *) *to;
|
||||
int length;
|
||||
|
||||
if (from == NULL || *from == NULL)
|
||||
return 0;
|
||||
|
||||
src = (const char *) *from;
|
||||
length = min(*from_left, *to_left);
|
||||
while (length) {
|
||||
*dst++ = *src++;
|
||||
length--;
|
||||
}
|
||||
|
||||
*from_left -= src - (char *) *from;
|
||||
*to_left -= dst - (char *) *to;
|
||||
*from = (XPointer) src;
|
||||
*to = (XPointer) dst;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
close_converter(
|
||||
XlcConv conv)
|
||||
{
|
||||
|
||||
Xfree(conv->state);
|
||||
Xfree(conv);
|
||||
}
|
||||
|
||||
static XlcConv
|
||||
create_conv(
|
||||
XLCd lcd,
|
||||
XlcConvMethods methods)
|
||||
{
|
||||
XlcConv conv;
|
||||
State state;
|
||||
|
||||
conv = Xcalloc(1, sizeof(XlcConvRec));
|
||||
if (conv == NULL)
|
||||
return (XlcConv) NULL;
|
||||
|
||||
state = Xmalloc(sizeof(StateRec));
|
||||
if (state == NULL) {
|
||||
close_converter(conv);
|
||||
return (XlcConv) NULL;
|
||||
}
|
||||
state->GL_codeset = XLC_GENERIC(lcd, initial_state_GL);
|
||||
state->GR_codeset = XLC_GENERIC(lcd, initial_state_GR);
|
||||
state->wc_mask = (1 << XLC_GENERIC(lcd, wc_shift_bits)) - 1;
|
||||
state->wc_encode_mask = XLC_GENERIC(lcd, wc_encode_mask);
|
||||
|
||||
#ifdef STDCVT
|
||||
if (XLC_GENERIC(lcd, use_stdc_env) == True)
|
||||
state->MBtoWC = &MBtoWCstd;
|
||||
else
|
||||
#endif
|
||||
state->MBtoWC = &MBtoWCdef;
|
||||
|
||||
#ifdef STDCVT
|
||||
if (XLC_GENERIC(lcd, use_stdc_env) == True)
|
||||
state->WCtoMB = &WCtoMBstd;
|
||||
else
|
||||
#endif
|
||||
state->WCtoMB = &WCtoMBdef;
|
||||
|
||||
conv->methods = methods;
|
||||
conv->state = (XPointer) state;
|
||||
|
||||
return conv;
|
||||
}
|
||||
|
||||
static XlcConvMethodsRec mbstowcs_methods = {
|
||||
close_converter,
|
||||
def_mbstowcs,
|
||||
NULL
|
||||
};
|
||||
|
||||
static XlcConv
|
||||
open_mbstowcs(
|
||||
XLCd from_lcd,
|
||||
const char *from_type,
|
||||
XLCd to_lcd,
|
||||
const char *to_type)
|
||||
{
|
||||
return create_conv(from_lcd, &mbstowcs_methods);
|
||||
}
|
||||
|
||||
static XlcConvMethodsRec mbstostr_methods = {
|
||||
close_converter,
|
||||
mbstostr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static XlcConv
|
||||
open_mbstostr(
|
||||
XLCd from_lcd,
|
||||
const char *from_type,
|
||||
XLCd to_lcd,
|
||||
const char *to_type)
|
||||
{
|
||||
return create_conv(from_lcd, &mbstostr_methods);
|
||||
}
|
||||
|
||||
static XlcConvMethodsRec mbstocs_methods = {
|
||||
close_converter,
|
||||
mbstocs,
|
||||
NULL
|
||||
};
|
||||
|
||||
static XlcConv
|
||||
open_mbstocs(
|
||||
XLCd from_lcd,
|
||||
const char *from_type,
|
||||
XLCd to_lcd,
|
||||
const char *to_type)
|
||||
{
|
||||
return create_conv(from_lcd, &mbstocs_methods);
|
||||
}
|
||||
|
||||
static XlcConvMethodsRec wcstombs_methods = {
|
||||
close_converter,
|
||||
def_wcstombs,
|
||||
NULL
|
||||
};
|
||||
|
||||
static XlcConv
|
||||
open_wcstombs(
|
||||
XLCd from_lcd,
|
||||
const char *from_type,
|
||||
XLCd to_lcd,
|
||||
const char *to_type)
|
||||
{
|
||||
return create_conv(from_lcd, &wcstombs_methods);
|
||||
}
|
||||
|
||||
static XlcConvMethodsRec wcstostr_methods = {
|
||||
close_converter,
|
||||
wcstostr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static XlcConv
|
||||
open_wcstostr(
|
||||
XLCd from_lcd,
|
||||
const char *from_type,
|
||||
XLCd to_lcd,
|
||||
const char *to_type)
|
||||
{
|
||||
return create_conv(from_lcd, &wcstostr_methods);
|
||||
}
|
||||
|
||||
static XlcConvMethodsRec wcstocs_methods = {
|
||||
close_converter,
|
||||
wcstocs,
|
||||
NULL
|
||||
};
|
||||
|
||||
static XlcConv
|
||||
open_wcstocs(
|
||||
XLCd from_lcd,
|
||||
const char *from_type,
|
||||
XLCd to_lcd,
|
||||
const char *to_type)
|
||||
{
|
||||
return create_conv(from_lcd, &wcstocs_methods);
|
||||
}
|
||||
|
||||
static XlcConvMethodsRec strtombs_methods = {
|
||||
close_converter,
|
||||
strtombs,
|
||||
NULL
|
||||
};
|
||||
|
||||
static XlcConv
|
||||
open_strtombs(
|
||||
XLCd from_lcd,
|
||||
const char *from_type,
|
||||
XLCd to_lcd,
|
||||
const char *to_type)
|
||||
{
|
||||
return create_conv(from_lcd, &strtombs_methods);
|
||||
}
|
||||
|
||||
static XlcConvMethodsRec cstombs_methods = {
|
||||
close_converter,
|
||||
cstombs,
|
||||
NULL
|
||||
};
|
||||
|
||||
static XlcConv
|
||||
open_cstombs(
|
||||
XLCd from_lcd,
|
||||
const char *from_type,
|
||||
XLCd to_lcd,
|
||||
const char *to_type)
|
||||
{
|
||||
return create_conv(from_lcd, &cstombs_methods);
|
||||
}
|
||||
|
||||
static XlcConvMethodsRec cstowcs_methods = {
|
||||
close_converter,
|
||||
cstowcs,
|
||||
NULL
|
||||
};
|
||||
|
||||
static XlcConv
|
||||
open_cstowcs(
|
||||
XLCd from_lcd,
|
||||
const char *from_type,
|
||||
XLCd to_lcd,
|
||||
const char *to_type)
|
||||
{
|
||||
return create_conv(from_lcd, &cstowcs_methods);
|
||||
}
|
||||
|
||||
XLCd
|
||||
_XlcDefaultLoader(
|
||||
const char *name)
|
||||
{
|
||||
XLCd lcd;
|
||||
|
||||
lcd = _XlcCreateLC(name, _XlcGenericMethods);
|
||||
if (lcd == NULL)
|
||||
return lcd;
|
||||
|
||||
if (XLC_PUBLIC(lcd, mb_cur_max) != 1){
|
||||
_XlcDestroyLC(lcd);
|
||||
return (XLCd) NULL;
|
||||
}
|
||||
|
||||
_XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar, open_mbstowcs);
|
||||
_XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNString, open_mbstostr);
|
||||
_XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_mbstocs);
|
||||
_XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_mbstocs);
|
||||
|
||||
_XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte, open_wcstombs);
|
||||
_XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNString, open_wcstostr);
|
||||
_XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstocs);
|
||||
|
||||
_XlcSetConverter(lcd, XlcNString, lcd, XlcNMultiByte, open_strtombs);
|
||||
_XlcSetConverter(lcd, XlcNString, lcd, XlcNWideChar, open_mbstowcs);
|
||||
|
||||
_XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte, open_cstombs);
|
||||
_XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_cstowcs);
|
||||
|
||||
_XlcAddUtf8Converters(lcd);
|
||||
|
||||
return lcd;
|
||||
}
|
||||
27
nx-X11/lib/modules/lc/gen/Makefile.am
Normal file
27
nx-X11/lib/modules/lc/gen/Makefile.am
Normal file
@@ -0,0 +1,27 @@
|
||||
NULL =
|
||||
|
||||
noinst_LTLIBRARIES = libxlibi18n.la
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/include/X11 \
|
||||
-I$(top_builddir)/include \
|
||||
-I$(top_builddir)/include/X11 \
|
||||
-I$(top_srcdir)/src/xcms \
|
||||
-I$(top_srcdir)/src/xkb \
|
||||
-I$(top_srcdir)/src/xlibi18n \
|
||||
-I$(top_srcdir)/../exports/include \
|
||||
-D_GNU_SOURCE \
|
||||
$(NULL)
|
||||
|
||||
AM_CFLAGS = \
|
||||
$(X11_CFLAGS) \
|
||||
$(BIGFONT_CFLAGS) \
|
||||
$(CWARNFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
xlibi18n_la_SOURCES = \
|
||||
lcGenConv.c \
|
||||
$(NULL)
|
||||
|
||||
libxlibi18n_la_SOURCES = $(xlibi18n_la_SOURCES)
|
||||
3112
nx-X11/lib/modules/lc/gen/lcGenConv.c
Normal file
3112
nx-X11/lib/modules/lc/gen/lcGenConv.c
Normal file
File diff suppressed because it is too large
Load Diff
1
nx-X11/lib/modules/om/Makefile.am
Normal file
1
nx-X11/lib/modules/om/Makefile.am
Normal file
@@ -0,0 +1 @@
|
||||
SUBDIRS = generic
|
||||
36
nx-X11/lib/modules/om/generic/Makefile.am
Normal file
36
nx-X11/lib/modules/om/generic/Makefile.am
Normal file
@@ -0,0 +1,36 @@
|
||||
NULL =
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/include/X11 \
|
||||
-I$(top_builddir)/include \
|
||||
-I$(top_builddir)/include/X11 \
|
||||
-I$(top_srcdir)/src/xcms \
|
||||
-I$(top_srcdir)/src/xkb \
|
||||
-I$(top_srcdir)/src/xlibi18n \
|
||||
-I$(top_srcdir)/src \
|
||||
-I$(top_srcdir)/../exports/include \
|
||||
-D_GNU_SOURCE \
|
||||
$(NULL)
|
||||
|
||||
AM_CFLAGS = \
|
||||
$(X11_CFLAGS) \
|
||||
$(BIGFONT_CFLAGS) \
|
||||
$(MALLOC_ZERO_CFLAGS) \
|
||||
$(CWARNFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
noinst_LTLIBRARIES = libxomGeneric.la
|
||||
|
||||
xomGeneric_la_SOURCES = \
|
||||
omDefault.c \
|
||||
omGeneric.c \
|
||||
omImText.c \
|
||||
omText.c \
|
||||
omTextEsc.c \
|
||||
omTextExt.c \
|
||||
omTextPer.c \
|
||||
omXChar.c \
|
||||
$(NULL)
|
||||
|
||||
libxomGeneric_la_SOURCES = $(xomGeneric_la_SOURCES)
|
||||
449
nx-X11/lib/modules/om/generic/omDefault.c
Normal file
449
nx-X11/lib/modules/om/generic/omDefault.c
Normal file
@@ -0,0 +1,449 @@
|
||||
/*
|
||||
* Copyright 1992, 1993 by TOSHIBA Corp.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation for any purpose and without fee is hereby granted, provided
|
||||
* that the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of TOSHIBA not be used in advertising
|
||||
* or publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. TOSHIBA make no representations about the
|
||||
* suitability of this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*
|
||||
* TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||
* TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
||||
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Author: Katsuhisa Yano TOSHIBA Corp.
|
||||
* mopi@osa.ilab.toshiba.co.jp
|
||||
*/
|
||||
/*
|
||||
* (c) Copyright 1995 FUJITSU LIMITED
|
||||
* This is source code modified by FUJITSU LIMITED under the Joint
|
||||
* Development Agreement for the CDE/Motif PST.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include "Xlibint.h"
|
||||
#include "XomGeneric.h"
|
||||
#include <nx-X11/Xos.h>
|
||||
#include <nx-X11/Xatom.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define DefineLocalBuf char local_buf[BUFSIZ]
|
||||
#define AllocLocalBuf(length) (length > BUFSIZ ? (char *)Xmalloc(length) : local_buf)
|
||||
#define FreeLocalBuf(ptr) if (ptr != local_buf) Xfree(ptr)
|
||||
|
||||
static Bool
|
||||
wcs_to_mbs(
|
||||
XOC oc,
|
||||
char *to,
|
||||
_Xconst wchar_t *from,
|
||||
int length)
|
||||
{
|
||||
XlcConv conv;
|
||||
int to_left, ret;
|
||||
|
||||
conv = _XomInitConverter(oc, XOMWideChar);
|
||||
if (conv == NULL)
|
||||
return False;
|
||||
|
||||
to_left = length;
|
||||
ret = _XlcConvert(conv, (XPointer *) &from, &length, (XPointer *) &to,
|
||||
&to_left, NULL, 0);
|
||||
if (ret != 0 || length > 0)
|
||||
return False;
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
static Bool
|
||||
utf8_to_mbs(
|
||||
XOC oc,
|
||||
char *to,
|
||||
_Xconst char *from,
|
||||
int length)
|
||||
{
|
||||
XlcConv conv;
|
||||
int to_left, ret;
|
||||
|
||||
conv = _XomInitConverter(oc, XOMUtf8String);
|
||||
if (conv == NULL)
|
||||
return False;
|
||||
|
||||
to_left = length;
|
||||
ret = _XlcConvert(conv, (XPointer *) &from, &length, (XPointer *) &to,
|
||||
&to_left, NULL, 0);
|
||||
if (ret != 0 || length > 0)
|
||||
return False;
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
int
|
||||
_XmbDefaultTextEscapement(XOC oc, _Xconst char *text, int length)
|
||||
{
|
||||
return XTextWidth(*oc->core.font_info.font_struct_list, text, length);
|
||||
}
|
||||
|
||||
int
|
||||
_XwcDefaultTextEscapement(XOC oc, _Xconst wchar_t *text, int length)
|
||||
{
|
||||
DefineLocalBuf;
|
||||
char *buf = AllocLocalBuf(length);
|
||||
int ret;
|
||||
|
||||
if (buf == NULL)
|
||||
return 0;
|
||||
|
||||
if (wcs_to_mbs(oc, buf, text, length) == False) {
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = _XmbDefaultTextEscapement(oc, buf, length);
|
||||
|
||||
err:
|
||||
FreeLocalBuf(buf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
_Xutf8DefaultTextEscapement(XOC oc, _Xconst char *text, int length)
|
||||
{
|
||||
DefineLocalBuf;
|
||||
char *buf = AllocLocalBuf(length);
|
||||
int ret;
|
||||
|
||||
if (buf == NULL)
|
||||
return 0;
|
||||
|
||||
if (utf8_to_mbs(oc, buf, text, length) == False) {
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = _XmbDefaultTextEscapement(oc, buf, length);
|
||||
|
||||
err:
|
||||
FreeLocalBuf(buf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
_XmbDefaultTextExtents(XOC oc, _Xconst char *text, int length,
|
||||
XRectangle *overall_ink, XRectangle *overall_logical)
|
||||
{
|
||||
int direction, logical_ascent, logical_descent;
|
||||
XCharStruct overall;
|
||||
|
||||
XTextExtents(*oc->core.font_info.font_struct_list, text, length, &direction,
|
||||
&logical_ascent, &logical_descent, &overall);
|
||||
|
||||
if (overall_ink) {
|
||||
overall_ink->x = overall.lbearing;
|
||||
overall_ink->y = -(overall.ascent);
|
||||
overall_ink->width = overall.rbearing - overall.lbearing;
|
||||
overall_ink->height = overall.ascent + overall.descent;
|
||||
}
|
||||
|
||||
if (overall_logical) {
|
||||
overall_logical->x = 0;
|
||||
overall_logical->y = -(logical_ascent);
|
||||
overall_logical->width = overall.width;
|
||||
overall_logical->height = logical_ascent + logical_descent;
|
||||
}
|
||||
|
||||
return overall.width;
|
||||
}
|
||||
|
||||
int
|
||||
_XwcDefaultTextExtents(XOC oc, _Xconst wchar_t *text, int length,
|
||||
XRectangle *overall_ink, XRectangle *overall_logical)
|
||||
{
|
||||
DefineLocalBuf;
|
||||
char *buf = AllocLocalBuf(length);
|
||||
int ret;
|
||||
|
||||
if (buf == NULL)
|
||||
return 0;
|
||||
|
||||
if (wcs_to_mbs(oc, buf, text, length) == False) {
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = _XmbDefaultTextExtents(oc, buf, length, overall_ink, overall_logical);
|
||||
|
||||
err:
|
||||
FreeLocalBuf(buf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
_Xutf8DefaultTextExtents(XOC oc, _Xconst char *text, int length,
|
||||
XRectangle *overall_ink, XRectangle *overall_logical)
|
||||
{
|
||||
DefineLocalBuf;
|
||||
char *buf = AllocLocalBuf(length);
|
||||
int ret;
|
||||
|
||||
if (buf == NULL)
|
||||
return 0;
|
||||
|
||||
if (utf8_to_mbs(oc, buf, text, length) == False) {
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = _XmbDefaultTextExtents(oc, buf, length, overall_ink, overall_logical);
|
||||
|
||||
err:
|
||||
FreeLocalBuf(buf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Status
|
||||
_XmbDefaultTextPerCharExtents(XOC oc, _Xconst char *text, int length,
|
||||
XRectangle *ink_buf, XRectangle *logical_buf,
|
||||
int buf_size, int *num_chars,
|
||||
XRectangle *overall_ink,
|
||||
XRectangle *overall_logical)
|
||||
{
|
||||
XFontStruct *font = *oc->core.font_info.font_struct_list;
|
||||
XCharStruct *def, *cs, overall;
|
||||
Bool first = True;
|
||||
|
||||
if (buf_size < length)
|
||||
return 0;
|
||||
|
||||
bzero((char *) &overall, sizeof(XCharStruct));
|
||||
*num_chars = 0;
|
||||
|
||||
CI_GET_DEFAULT_INFO_1D(font, def)
|
||||
|
||||
while (length-- > 0) {
|
||||
CI_GET_CHAR_INFO_1D(font, *text, def, cs)
|
||||
text++;
|
||||
if (cs == NULL)
|
||||
continue;
|
||||
|
||||
ink_buf->x = overall.width + cs->lbearing;
|
||||
ink_buf->y = -(cs->ascent);
|
||||
ink_buf->width = cs->rbearing - cs->lbearing;
|
||||
ink_buf->height = cs->ascent + cs->descent;
|
||||
ink_buf++;
|
||||
|
||||
logical_buf->x = overall.width;
|
||||
logical_buf->y = -(font->ascent);
|
||||
logical_buf->width = cs->width;
|
||||
logical_buf->height = font->ascent + font->descent;
|
||||
logical_buf++;
|
||||
|
||||
if (first) {
|
||||
overall = *cs;
|
||||
first = False;
|
||||
} else {
|
||||
overall.ascent = max(overall.ascent, cs->ascent);
|
||||
overall.descent = max(overall.descent, cs->descent);
|
||||
overall.lbearing = min(overall.lbearing, overall.width +
|
||||
cs->lbearing);
|
||||
overall.rbearing = max(overall.rbearing, overall.width +
|
||||
cs->rbearing);
|
||||
overall.width += cs->width;
|
||||
}
|
||||
|
||||
(*num_chars)++;
|
||||
}
|
||||
|
||||
if (overall_ink) {
|
||||
overall_ink->x = overall.lbearing;
|
||||
overall_ink->y = -(overall.ascent);
|
||||
overall_ink->width = overall.rbearing - overall.lbearing;
|
||||
overall_ink->height = overall.ascent + overall.descent;
|
||||
}
|
||||
|
||||
if (overall_logical) {
|
||||
overall_logical->x = 0;
|
||||
overall_logical->y = -(font->ascent);
|
||||
overall_logical->width = overall.width;
|
||||
overall_logical->height = font->ascent + font->descent;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Status
|
||||
_XwcDefaultTextPerCharExtents(XOC oc, _Xconst wchar_t *text, int length,
|
||||
XRectangle *ink_buf, XRectangle *logical_buf,
|
||||
int buf_size, int *num_chars,
|
||||
XRectangle *overall_ink,
|
||||
XRectangle *overall_logical)
|
||||
{
|
||||
DefineLocalBuf;
|
||||
char *buf = AllocLocalBuf(length);
|
||||
Status ret;
|
||||
|
||||
if (buf == NULL)
|
||||
return 0;
|
||||
|
||||
if (wcs_to_mbs(oc, buf, text, length) == False) {
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = _XmbDefaultTextPerCharExtents(oc, buf, length, ink_buf, logical_buf,
|
||||
buf_size, num_chars, overall_ink,
|
||||
overall_logical);
|
||||
|
||||
err:
|
||||
FreeLocalBuf(buf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Status
|
||||
_Xutf8DefaultTextPerCharExtents(XOC oc, _Xconst char *text, int length,
|
||||
XRectangle *ink_buf, XRectangle *logical_buf,
|
||||
int buf_size, int *num_chars,
|
||||
XRectangle *overall_ink,
|
||||
XRectangle *overall_logical)
|
||||
{
|
||||
DefineLocalBuf;
|
||||
char *buf = AllocLocalBuf(length);
|
||||
Status ret;
|
||||
|
||||
if (buf == NULL)
|
||||
return 0;
|
||||
|
||||
if (utf8_to_mbs(oc, buf, text, length) == False) {
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = _XmbDefaultTextPerCharExtents(oc, buf, length, ink_buf, logical_buf,
|
||||
buf_size, num_chars, overall_ink,
|
||||
overall_logical);
|
||||
|
||||
err:
|
||||
FreeLocalBuf(buf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
_XmbDefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
|
||||
_Xconst char *text, int length)
|
||||
{
|
||||
XFontStruct *font = *oc->core.font_info.font_struct_list;
|
||||
|
||||
XSetFont(dpy, gc, font->fid);
|
||||
XDrawString(dpy, d, gc, x, y, text, length);
|
||||
|
||||
return XTextWidth(font, text, length);
|
||||
}
|
||||
|
||||
int
|
||||
_XwcDefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
|
||||
_Xconst wchar_t *text, int length)
|
||||
{
|
||||
DefineLocalBuf;
|
||||
char *buf = AllocLocalBuf(length);
|
||||
int ret;
|
||||
|
||||
if (buf == NULL)
|
||||
return 0;
|
||||
|
||||
if (wcs_to_mbs(oc, buf, text, length) == False) {
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = _XmbDefaultDrawString(dpy, d, oc, gc, x, y, buf, length);
|
||||
|
||||
err:
|
||||
FreeLocalBuf(buf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
_Xutf8DefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
|
||||
_Xconst char *text, int length)
|
||||
{
|
||||
DefineLocalBuf;
|
||||
char *buf = AllocLocalBuf(length);
|
||||
int ret;
|
||||
|
||||
if (buf == NULL)
|
||||
return 0;
|
||||
|
||||
if (utf8_to_mbs(oc, buf, text, length) == False) {
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = _XmbDefaultDrawString(dpy, d, oc, gc, x, y, buf, length);
|
||||
|
||||
err:
|
||||
FreeLocalBuf(buf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
_XmbDefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
|
||||
int y, _Xconst char *text, int length)
|
||||
{
|
||||
XSetFont(dpy, gc, (*oc->core.font_info.font_struct_list)->fid);
|
||||
XDrawImageString(dpy, d, gc, x, y, text, length);
|
||||
}
|
||||
|
||||
void
|
||||
_XwcDefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
|
||||
int y, _Xconst wchar_t *text, int length)
|
||||
{
|
||||
DefineLocalBuf;
|
||||
char *buf = AllocLocalBuf(length);
|
||||
|
||||
if (buf == NULL)
|
||||
return;
|
||||
|
||||
if (wcs_to_mbs(oc, buf, text, length) == False)
|
||||
goto err;
|
||||
|
||||
_XmbDefaultDrawImageString(dpy, d, oc, gc, x, y, buf, length);
|
||||
|
||||
err:
|
||||
FreeLocalBuf(buf);
|
||||
}
|
||||
|
||||
void
|
||||
_Xutf8DefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
|
||||
int y, _Xconst char *text, int length)
|
||||
{
|
||||
DefineLocalBuf;
|
||||
char *buf = AllocLocalBuf(length);
|
||||
|
||||
if (buf == NULL)
|
||||
return;
|
||||
|
||||
if (utf8_to_mbs(oc, buf, text, length) == False)
|
||||
goto err;
|
||||
|
||||
_XmbDefaultDrawImageString(dpy, d, oc, gc, x, y, buf, length);
|
||||
|
||||
err:
|
||||
FreeLocalBuf(buf);
|
||||
}
|
||||
2089
nx-X11/lib/modules/om/generic/omGeneric.c
Normal file
2089
nx-X11/lib/modules/om/generic/omGeneric.c
Normal file
File diff suppressed because it is too large
Load Diff
86
nx-X11/lib/modules/om/generic/omImText.c
Normal file
86
nx-X11/lib/modules/om/generic/omImText.c
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 1992, 1993 by TOSHIBA Corp.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation for any purpose and without fee is hereby granted, provided
|
||||
* that the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of TOSHIBA not be used in advertising
|
||||
* or publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. TOSHIBA make no representations about the
|
||||
* suitability of this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*
|
||||
* TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||
* TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
||||
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Author: Katsuhisa Yano TOSHIBA Corp.
|
||||
* mopi@osa.ilab.toshiba.co.jp
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include "Xlibint.h"
|
||||
#include "XomGeneric.h"
|
||||
|
||||
#define GET_VALUE_MASK (GCFunction | GCForeground | GCBackground | GCFillStyle)
|
||||
#define SET_VALUE_MASK (GCFunction | GCForeground | GCFillStyle)
|
||||
|
||||
static void
|
||||
_XomGenericDrawImageString(
|
||||
Display *dpy,
|
||||
Drawable d,
|
||||
XOC oc,
|
||||
GC gc,
|
||||
int x, int y,
|
||||
XOMTextType type,
|
||||
XPointer text,
|
||||
int length)
|
||||
{
|
||||
XGCValues values;
|
||||
XRectangle extent;
|
||||
|
||||
XGetGCValues(dpy, gc, GET_VALUE_MASK, &values);
|
||||
|
||||
XSetFunction(dpy, gc, GXcopy);
|
||||
XSetForeground(dpy, gc, values.background);
|
||||
XSetFillStyle(dpy, gc, FillSolid);
|
||||
|
||||
_XomGenericTextExtents(oc, type, text, length, 0, &extent);
|
||||
XFillRectangle(dpy, d, gc, x + extent.x, y + extent.y, extent.width,
|
||||
extent.height);
|
||||
|
||||
XChangeGC(dpy, gc, SET_VALUE_MASK, &values);
|
||||
|
||||
_XomGenericDrawString(dpy, d, oc, gc, x, y, type, text, length);
|
||||
}
|
||||
|
||||
void
|
||||
_XmbGenericDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
|
||||
int y, _Xconst char *text, int length)
|
||||
{
|
||||
_XomGenericDrawImageString(dpy, d, oc, gc, x, y, XOMMultiByte,
|
||||
(XPointer) text, length);
|
||||
}
|
||||
|
||||
void
|
||||
_XwcGenericDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
|
||||
int y, _Xconst wchar_t *text, int length)
|
||||
{
|
||||
_XomGenericDrawImageString(dpy, d, oc, gc, x, y, XOMWideChar,
|
||||
(XPointer) text, length);
|
||||
}
|
||||
|
||||
void
|
||||
_Xutf8GenericDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
|
||||
int y, _Xconst char *text, int length)
|
||||
{
|
||||
_XomGenericDrawImageString(dpy, d, oc, gc, x, y, XOMUtf8String,
|
||||
(XPointer) text, length);
|
||||
}
|
||||
370
nx-X11/lib/modules/om/generic/omText.c
Normal file
370
nx-X11/lib/modules/om/generic/omText.c
Normal file
@@ -0,0 +1,370 @@
|
||||
/*
|
||||
* Copyright 1992, 1993 by TOSHIBA Corp.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation for any purpose and without fee is hereby granted, provided
|
||||
* that the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of TOSHIBA not be used in advertising
|
||||
* or publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. TOSHIBA make no representations about the
|
||||
* suitability of this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*
|
||||
* TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||
* TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
||||
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Author: Katsuhisa Yano TOSHIBA Corp.
|
||||
* mopi@osa.ilab.toshiba.co.jp
|
||||
*/
|
||||
/*
|
||||
* Copyright 1995 by FUJITSU LIMITED
|
||||
* This is source code modified by FUJITSU LIMITED under the Joint
|
||||
* Development Agreement for the CDE/Motif PST.
|
||||
*/
|
||||
/*
|
||||
* Modifiers: Jeff Walls, Paul Anderson (HEWLETT-PACKARD)
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include "Xlibint.h"
|
||||
#include "XomGeneric.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/* For VW/UDC */
|
||||
|
||||
static int
|
||||
is_rotate(
|
||||
XOC oc,
|
||||
XFontStruct *font)
|
||||
{
|
||||
XOCGenericPart *gen = XOC_GENERIC(oc);
|
||||
FontSet font_set;
|
||||
VRotate vrotate;
|
||||
int font_set_count;
|
||||
int vrotate_num;
|
||||
|
||||
font_set = gen->font_set;
|
||||
font_set_count = gen->font_set_num;
|
||||
for( ; font_set_count-- ; font_set++) {
|
||||
if((font_set->vrotate_num > 0) && (font_set->vrotate)) {
|
||||
vrotate = font_set->vrotate;
|
||||
vrotate_num = font_set->vrotate_num;
|
||||
for( ; vrotate_num-- ; vrotate++)
|
||||
if(vrotate->font == font)
|
||||
return True;
|
||||
}
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
||||
static int
|
||||
is_codemap(
|
||||
XOC oc,
|
||||
XFontStruct *font)
|
||||
{
|
||||
XOCGenericPart *gen = XOC_GENERIC(oc);
|
||||
FontSet font_set;
|
||||
FontData vmap;
|
||||
int font_set_count;
|
||||
int vmap_num;
|
||||
|
||||
font_set = gen->font_set;
|
||||
font_set_count = gen->font_set_num;
|
||||
for( ; font_set_count-- ; font_set++) {
|
||||
if(font_set->vmap_num > 0) {
|
||||
vmap = font_set->vmap;
|
||||
vmap_num = font_set->vmap_num;
|
||||
for( ; vmap_num-- ; vmap++)
|
||||
if(vmap->font == font)
|
||||
return True;
|
||||
}
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
||||
static int
|
||||
draw_vertical(
|
||||
Display *dpy,
|
||||
Drawable d,
|
||||
XOC oc,
|
||||
GC gc,
|
||||
XFontStruct *font,
|
||||
Bool is_xchar2b,
|
||||
int x, int y,
|
||||
XPointer text,
|
||||
int length)
|
||||
{
|
||||
XChar2b *buf2b;
|
||||
char *buf;
|
||||
int wx = 0, wy = 0;
|
||||
int direction = 0;
|
||||
int font_ascent_return = 0, font_descent_return = 0;
|
||||
int i;
|
||||
XCharStruct overall;
|
||||
|
||||
wy = y;
|
||||
if (is_xchar2b) {
|
||||
for(i = 0, buf2b = (XChar2b *) text ; i < length ; i++, buf2b++) {
|
||||
if(is_rotate(oc, font) == True) {
|
||||
XTextExtents16(font, buf2b, 1,
|
||||
&direction, &font_ascent_return,
|
||||
&font_descent_return, &overall);
|
||||
wx = x - (int)((overall.rbearing - overall.lbearing) >> 1) -
|
||||
(int) overall.lbearing;
|
||||
wy += overall.ascent;
|
||||
XDrawString16(dpy, d, gc, wx, wy, buf2b, 1);
|
||||
wy += overall.descent;
|
||||
} else {
|
||||
wx = x - (int)((font->max_bounds.rbearing -
|
||||
font->min_bounds.lbearing) >> 1) -
|
||||
(int) font->min_bounds.lbearing;
|
||||
wy += font->max_bounds.ascent;
|
||||
XDrawString16(dpy, d, gc, wx, wy, buf2b, 1);
|
||||
wy += font->max_bounds.descent;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(i = 0, buf = (char *)text ; i < length && *buf ; i++, buf++) {
|
||||
if(is_rotate(oc, font) == True) {
|
||||
XTextExtents(font, buf, 1,
|
||||
&direction, &font_ascent_return,
|
||||
&font_descent_return, &overall);
|
||||
wx = x - (int)((overall.rbearing - overall.lbearing) >> 1) -
|
||||
(int) overall.lbearing;
|
||||
wy += overall.ascent;
|
||||
XDrawString(dpy, d, gc, wx, wy, buf, 1);
|
||||
wy += overall.descent;
|
||||
} else {
|
||||
wx = x - (int)((font->max_bounds.rbearing -
|
||||
font->min_bounds.lbearing) >> 1) -
|
||||
(int) font->min_bounds.lbearing;
|
||||
wy += font->max_bounds.ascent;
|
||||
XDrawString(dpy, d, gc, wx, wy, buf, 1);
|
||||
wy += font->max_bounds.descent;
|
||||
}
|
||||
}
|
||||
}
|
||||
return wy;
|
||||
}
|
||||
|
||||
#define VMAP 0
|
||||
#define VROTATE 1
|
||||
#define FONTSCOPE 2
|
||||
|
||||
static int
|
||||
DrawStringWithFontSet(
|
||||
Display *dpy,
|
||||
Drawable d,
|
||||
XOC oc,
|
||||
FontSet fs,
|
||||
GC gc,
|
||||
int x, int y,
|
||||
XPointer text,
|
||||
int length)
|
||||
{
|
||||
XFontStruct *font;
|
||||
Bool is_xchar2b;
|
||||
unsigned char *ptr;
|
||||
int ptr_len, char_len = 0;
|
||||
FontData fd;
|
||||
int ret = 0;
|
||||
|
||||
ptr = (unsigned char *)text;
|
||||
is_xchar2b = fs->is_xchar2b;
|
||||
|
||||
while (length > 0) {
|
||||
fd = _XomGetFontDataFromFontSet(fs,
|
||||
ptr,length,&ptr_len,is_xchar2b,FONTSCOPE);
|
||||
if(ptr_len <= 0)
|
||||
break;
|
||||
|
||||
/* First, see if the "Best Match" font for the FontSet was set.
|
||||
* If it was, use that font. If it was not set, then use the
|
||||
* font defined by font_set->font_data[0] (which is what
|
||||
* _XomGetFontDataFromFontSet() always seems to return for
|
||||
* non-VW text). Note that given the new algorithm in
|
||||
* parse_fontname() and parse_fontdata(), fs->font will
|
||||
* *always* contain good data. We should probably remove
|
||||
* the check for "fd->font", but we won't :-) -- jjw/pma (HP)
|
||||
*/
|
||||
if((font = fs->font) == (XFontStruct *) NULL){
|
||||
|
||||
if(fd == (FontData) NULL ||
|
||||
(font = fd->font) == (XFontStruct *) NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
switch(oc->core.orientation) {
|
||||
case XOMOrientation_LTR_TTB:
|
||||
case XOMOrientation_RTL_TTB:
|
||||
XSetFont(dpy, gc, font->fid);
|
||||
|
||||
if (is_xchar2b) {
|
||||
char_len = ptr_len / sizeof(XChar2b);
|
||||
XDrawString16(dpy, d, gc, x, y, (XChar2b *)ptr, char_len);
|
||||
x += XTextWidth16(font, (XChar2b *)ptr, char_len);
|
||||
} else {
|
||||
char_len = ptr_len;
|
||||
XDrawString(dpy, d, gc, x, y, (char *)ptr, char_len);
|
||||
x += XTextWidth(font, (char *)ptr, char_len);
|
||||
}
|
||||
break;
|
||||
case XOMOrientation_TTB_RTL:
|
||||
case XOMOrientation_TTB_LTR:
|
||||
if(fs->font == font) {
|
||||
fd = _XomGetFontDataFromFontSet(fs,
|
||||
ptr,length,&ptr_len,is_xchar2b,VMAP);
|
||||
if(ptr_len <= 0)
|
||||
break;
|
||||
if(fd == (FontData) NULL ||
|
||||
(font = fd->font) == (XFontStruct *) NULL)
|
||||
break;
|
||||
|
||||
if(is_codemap(oc, fd->font) == False) {
|
||||
fd = _XomGetFontDataFromFontSet(fs,
|
||||
ptr,length,&ptr_len,is_xchar2b,VROTATE);
|
||||
if(ptr_len <= 0)
|
||||
break;
|
||||
if(fd == (FontData) NULL ||
|
||||
(font = fd->font) == (XFontStruct *) NULL)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(is_xchar2b)
|
||||
char_len = ptr_len / sizeof(XChar2b);
|
||||
else
|
||||
char_len = ptr_len;
|
||||
XSetFont(dpy, gc, font->fid);
|
||||
y = draw_vertical(dpy, d, oc, gc, font, is_xchar2b, x, y,
|
||||
(char *)ptr, char_len);
|
||||
break;
|
||||
|
||||
case XOMOrientation_Context:
|
||||
/* never used? */
|
||||
break;
|
||||
}
|
||||
|
||||
if(char_len <= 0)
|
||||
break;
|
||||
|
||||
length -= char_len;
|
||||
ptr += ptr_len;
|
||||
}
|
||||
|
||||
switch(oc->core.orientation) {
|
||||
case XOMOrientation_LTR_TTB:
|
||||
case XOMOrientation_RTL_TTB:
|
||||
ret = x;
|
||||
break;
|
||||
case XOMOrientation_TTB_RTL:
|
||||
case XOMOrientation_TTB_LTR:
|
||||
ret = y;
|
||||
break;
|
||||
case XOMOrientation_Context:
|
||||
/* not used? */
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* For VW/UDC */
|
||||
|
||||
int
|
||||
_XomGenericDrawString(
|
||||
Display *dpy,
|
||||
Drawable d,
|
||||
XOC oc,
|
||||
GC gc,
|
||||
int x, int y,
|
||||
XOMTextType type,
|
||||
XPointer text,
|
||||
int length)
|
||||
{
|
||||
XlcConv conv;
|
||||
XFontStruct *font;
|
||||
Bool is_xchar2b;
|
||||
/* VW/UDC */
|
||||
XPointer args[3];
|
||||
FontSet fs;
|
||||
/* VW/UDC */
|
||||
XChar2b xchar2b_buf[BUFSIZ], *buf;
|
||||
int start_x = x;
|
||||
int start_y = y;
|
||||
int left = 0, buf_len = 0;
|
||||
int next = 0;
|
||||
|
||||
conv = _XomInitConverter(oc, type);
|
||||
if (conv == NULL)
|
||||
return -1;
|
||||
|
||||
args[0] = (XPointer) &font;
|
||||
args[1] = (XPointer) &is_xchar2b;
|
||||
args[2] = (XPointer) &fs;
|
||||
|
||||
while (length > 0) {
|
||||
buf = xchar2b_buf;
|
||||
left = buf_len = BUFSIZ;
|
||||
|
||||
if (_XomConvert(oc, conv, (XPointer *) &text, &length,
|
||||
(XPointer *) &buf, &left, args, 3) < 0)
|
||||
break;
|
||||
buf_len -= left;
|
||||
|
||||
/* For VW/UDC */
|
||||
next = DrawStringWithFontSet(dpy, d, oc, fs, gc, x, y,
|
||||
(XPointer)xchar2b_buf, buf_len);
|
||||
|
||||
switch(oc->core.orientation) {
|
||||
case XOMOrientation_LTR_TTB:
|
||||
case XOMOrientation_RTL_TTB:
|
||||
x = next;
|
||||
break;
|
||||
case XOMOrientation_TTB_RTL:
|
||||
case XOMOrientation_TTB_LTR:
|
||||
y = next;
|
||||
break;
|
||||
case XOMOrientation_Context:
|
||||
/* not used */
|
||||
break;
|
||||
}
|
||||
/* For VW/UDC */
|
||||
}
|
||||
|
||||
x -= start_x;
|
||||
y -= start_y;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
int
|
||||
_XmbGenericDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
|
||||
_Xconst char *text, int length)
|
||||
{
|
||||
return _XomGenericDrawString(dpy, d, oc, gc, x, y, XOMMultiByte,
|
||||
(XPointer) text, length);
|
||||
}
|
||||
|
||||
int
|
||||
_XwcGenericDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
|
||||
_Xconst wchar_t *text, int length)
|
||||
{
|
||||
return _XomGenericDrawString(dpy, d, oc, gc, x, y, XOMWideChar,
|
||||
(XPointer) text, length);
|
||||
}
|
||||
|
||||
int
|
||||
_Xutf8GenericDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
|
||||
_Xconst char *text, int length)
|
||||
{
|
||||
return _XomGenericDrawString(dpy, d, oc, gc, x, y, XOMUtf8String,
|
||||
(XPointer) text, length);
|
||||
}
|
||||
300
nx-X11/lib/modules/om/generic/omTextEsc.c
Normal file
300
nx-X11/lib/modules/om/generic/omTextEsc.c
Normal file
@@ -0,0 +1,300 @@
|
||||
/*
|
||||
* Copyright 1992, 1993 by TOSHIBA Corp.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation for any purpose and without fee is hereby granted, provided
|
||||
* that the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of TOSHIBA not be used in advertising
|
||||
* or publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. TOSHIBA make no representations about the
|
||||
* suitability of this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*
|
||||
* TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||
* TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
||||
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Author: Katsuhisa Yano TOSHIBA Corp.
|
||||
* mopi@osa.ilab.toshiba.co.jp
|
||||
*/
|
||||
/*
|
||||
* Copyright 1995 by FUJITSU LIMITED
|
||||
* This is source code modified by FUJITSU LIMITED under the Joint
|
||||
* Development Agreement for the CDE/Motif PST.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include "Xlibint.h"
|
||||
#include "XomGeneric.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/* For VW/UDC start */
|
||||
|
||||
#define VMAP 0
|
||||
#define VROTATE 1
|
||||
#define FONTSCOPE 2
|
||||
|
||||
static int
|
||||
is_rotate(
|
||||
XOC oc,
|
||||
XFontStruct *font)
|
||||
{
|
||||
XOCGenericPart *gen = XOC_GENERIC(oc);
|
||||
FontSet font_set;
|
||||
VRotate vrotate;
|
||||
int font_set_count;
|
||||
int vrotate_num;
|
||||
|
||||
font_set = gen->font_set;
|
||||
font_set_count = gen->font_set_num;
|
||||
for( ; font_set_count-- ; font_set++) {
|
||||
if((font_set->vrotate_num > 0) && (font_set->vrotate != NULL)) {
|
||||
vrotate = font_set->vrotate;
|
||||
vrotate_num = font_set->vrotate_num;
|
||||
for( ; vrotate_num-- ; vrotate++)
|
||||
if(vrotate->font == font)
|
||||
return True;
|
||||
}
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
||||
static int
|
||||
is_codemap(
|
||||
XOC oc,
|
||||
XFontStruct *font)
|
||||
{
|
||||
XOCGenericPart *gen = XOC_GENERIC(oc);
|
||||
FontSet font_set;
|
||||
FontData vmap;
|
||||
int font_set_count;
|
||||
int vmap_num;
|
||||
|
||||
font_set = gen->font_set;
|
||||
font_set_count = gen->font_set_num;
|
||||
for( ; font_set_count-- ; font_set++) {
|
||||
if(font_set->vmap_num > 0) {
|
||||
vmap = font_set->vmap;
|
||||
vmap_num = font_set->vmap_num;
|
||||
for( ; vmap_num-- ; vmap++)
|
||||
if(vmap->font == font)
|
||||
return True;
|
||||
}
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
||||
static int
|
||||
escapement_vertical(
|
||||
XOC oc,
|
||||
XFontStruct *font,
|
||||
Bool is_xchar2b,
|
||||
XPointer text,
|
||||
int length)
|
||||
{
|
||||
XChar2b *buf2b;
|
||||
char *buf;
|
||||
int escapement = 0, i;
|
||||
|
||||
if(is_xchar2b) {
|
||||
for(i = 0, buf2b = (XChar2b *) text ; i < length ; i++, buf2b++) {
|
||||
if(is_rotate(oc, font) == True) {
|
||||
escapement += _XTextHeight16(font, buf2b, 1);
|
||||
} else {
|
||||
escapement += (int) (font->max_bounds.ascent +
|
||||
font->max_bounds.descent);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(i = 0, buf = (char *)text ; i < length && *buf ; i++, buf++) {
|
||||
if(is_rotate(oc, font) == True) {
|
||||
escapement += _XTextHeight(font, buf, 1);
|
||||
} else {
|
||||
escapement += (int) (font->max_bounds.ascent +
|
||||
font->max_bounds.descent);
|
||||
}
|
||||
}
|
||||
}
|
||||
return escapement;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
TextWidthWithFontSet(
|
||||
FontSet font_set,
|
||||
XOC oc,
|
||||
XPointer text,
|
||||
int length)
|
||||
{
|
||||
FontData fd;
|
||||
XFontStruct *font;
|
||||
unsigned char *ptr = (unsigned char *)text;
|
||||
Bool is_xchar2b;
|
||||
int ptr_len = length;
|
||||
int escapement = 0, char_len = 0;
|
||||
|
||||
if(font_set == (FontSet) NULL)
|
||||
return escapement;
|
||||
|
||||
is_xchar2b = font_set->is_xchar2b;
|
||||
|
||||
while(length > 0) {
|
||||
fd = _XomGetFontDataFromFontSet(font_set, ptr, length, &ptr_len,
|
||||
is_xchar2b, FONTSCOPE);
|
||||
if(ptr_len <= 0)
|
||||
break;
|
||||
|
||||
/*
|
||||
* First, see if the "Best Match" font for the FontSet was set.
|
||||
* If it was, use that font. If it was not set, then use the
|
||||
* font defined by font_set->font_data[0] (which is what
|
||||
* _XomGetFontDataFromFontSet() always seems to return for
|
||||
* non-VW text). Note that given the new algorithm in
|
||||
* parse_fontname() and parse_fontdata(), fs->font will
|
||||
* *always* contain good data. We should probably remove
|
||||
* the check for "fd->font", but we won't :-) -- jjw/pma (HP)
|
||||
*
|
||||
* Above comment and way this is done propagated from omText.c
|
||||
* Note that fd->font is junk so using the result of the
|
||||
* above call /needs/ to be ignored.
|
||||
*
|
||||
* Owen Taylor <otaylor@redhat.com> 12 Jul 2000
|
||||
*
|
||||
*/
|
||||
|
||||
if((font = font_set->font) == (XFontStruct *) NULL) {
|
||||
|
||||
if(fd == (FontData) NULL ||
|
||||
(font = fd->font) == (XFontStruct *) NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
switch(oc->core.orientation) {
|
||||
case XOMOrientation_LTR_TTB:
|
||||
case XOMOrientation_RTL_TTB:
|
||||
if (is_xchar2b) {
|
||||
char_len = ptr_len / sizeof(XChar2b);
|
||||
escapement += XTextWidth16(font, (XChar2b *)ptr, char_len);
|
||||
} else {
|
||||
char_len = ptr_len;
|
||||
escapement += XTextWidth(font, (char *)ptr, char_len);
|
||||
}
|
||||
break;
|
||||
|
||||
case XOMOrientation_TTB_LTR:
|
||||
case XOMOrientation_TTB_RTL:
|
||||
if(font_set->font == font) {
|
||||
fd = _XomGetFontDataFromFontSet(font_set, ptr, length, &ptr_len,
|
||||
is_xchar2b, VMAP);
|
||||
if(ptr_len <= 0)
|
||||
break;
|
||||
if(fd == (FontData) NULL ||
|
||||
(font = fd->font) == (XFontStruct *) NULL)
|
||||
break;
|
||||
|
||||
if(is_codemap(oc, fd->font) == False) {
|
||||
fd = _XomGetFontDataFromFontSet(font_set, ptr, length,
|
||||
&ptr_len, is_xchar2b,
|
||||
VROTATE);
|
||||
if(ptr_len <= 0)
|
||||
break;
|
||||
if(fd == (FontData) NULL ||
|
||||
(font = fd->font) == (XFontStruct *) NULL)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(is_xchar2b)
|
||||
char_len = ptr_len / sizeof(XChar2b);
|
||||
else
|
||||
char_len = ptr_len;
|
||||
escapement += escapement_vertical(oc, font, is_xchar2b,
|
||||
(XPointer) ptr, char_len);
|
||||
break;
|
||||
|
||||
case XOMOrientation_Context:
|
||||
/* not used? */
|
||||
break;
|
||||
}
|
||||
|
||||
if(char_len <= 0)
|
||||
break;
|
||||
|
||||
length -= char_len;
|
||||
ptr += ptr_len;
|
||||
}
|
||||
|
||||
return escapement;
|
||||
}
|
||||
|
||||
/* For VW/UDC end */
|
||||
|
||||
static int
|
||||
_XomGenericTextEscapement(
|
||||
XOC oc,
|
||||
XOMTextType type,
|
||||
XPointer text,
|
||||
int length)
|
||||
{
|
||||
XlcConv conv;
|
||||
XFontStruct *font;
|
||||
Bool is_xchar2b;
|
||||
/* VW/UDC */
|
||||
XPointer args[3];
|
||||
FontSet font_set;
|
||||
/* VW/UDC */
|
||||
XChar2b xchar2b_buf[BUFSIZ], *buf;
|
||||
int escapement = 0;
|
||||
int buf_len = 0, left = 0;
|
||||
|
||||
conv = _XomInitConverter(oc, type);
|
||||
if (conv == NULL)
|
||||
return escapement;
|
||||
|
||||
args[0] = (XPointer) &font;
|
||||
args[1] = (XPointer) &is_xchar2b;
|
||||
args[2] = (XPointer) &font_set;
|
||||
|
||||
while (length > 0) {
|
||||
buf = xchar2b_buf;
|
||||
left = buf_len = BUFSIZ;
|
||||
|
||||
if (_XomConvert(oc, conv, (XPointer *) &text, &length,
|
||||
(XPointer *) &buf, &left, args, 3) < 0)
|
||||
break;
|
||||
buf_len -= left;
|
||||
|
||||
/* VW/UDC */
|
||||
escapement += TextWidthWithFontSet(font_set, oc,
|
||||
(XPointer) xchar2b_buf, buf_len);
|
||||
/* VW/UDC */
|
||||
}
|
||||
|
||||
return escapement;
|
||||
}
|
||||
|
||||
int
|
||||
_XmbGenericTextEscapement(XOC oc, _Xconst char *text, int length)
|
||||
{
|
||||
return _XomGenericTextEscapement(oc, XOMMultiByte, (XPointer) text, length);
|
||||
}
|
||||
|
||||
int
|
||||
_XwcGenericTextEscapement(XOC oc, _Xconst wchar_t *text, int length)
|
||||
{
|
||||
return _XomGenericTextEscapement(oc, XOMWideChar, (XPointer) text, length);
|
||||
}
|
||||
|
||||
int
|
||||
_Xutf8GenericTextEscapement(XOC oc, _Xconst char *text, int length)
|
||||
{
|
||||
return _XomGenericTextEscapement(oc, XOMUtf8String, (XPointer) text,
|
||||
length);
|
||||
}
|
||||
135
nx-X11/lib/modules/om/generic/omTextExt.c
Normal file
135
nx-X11/lib/modules/om/generic/omTextExt.c
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright 1992, 1993 by TOSHIBA Corp.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation for any purpose and without fee is hereby granted, provided
|
||||
* that the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of TOSHIBA not be used in advertising
|
||||
* or publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. TOSHIBA make no representations about the
|
||||
* suitability of this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*
|
||||
* TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||
* TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
||||
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Author: Katsuhisa Yano TOSHIBA Corp.
|
||||
* mopi@osa.ilab.toshiba.co.jp
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include "Xlibint.h"
|
||||
#include "XomGeneric.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
_XomGenericTextExtents(
|
||||
XOC oc,
|
||||
XOMTextType type,
|
||||
XPointer text,
|
||||
int length,
|
||||
XRectangle *overall_ink,
|
||||
XRectangle *overall_logical)
|
||||
{
|
||||
XlcConv conv;
|
||||
XFontStruct *font;
|
||||
Bool is_xchar2b;
|
||||
XPointer args[2];
|
||||
XChar2b xchar2b_buf[BUFSIZ], *buf;
|
||||
int direction, logical_ascent, logical_descent, tmp_ascent, tmp_descent;
|
||||
XCharStruct overall, tmp_overall;
|
||||
int buf_len, left;
|
||||
Bool first = True;
|
||||
|
||||
conv = _XomInitConverter(oc, type);
|
||||
if (conv == NULL)
|
||||
return 0;
|
||||
|
||||
bzero((char *) &overall, sizeof(XCharStruct));
|
||||
logical_ascent = logical_descent = 0;
|
||||
|
||||
args[0] = (XPointer) &font;
|
||||
args[1] = (XPointer) &is_xchar2b;
|
||||
|
||||
while (length > 0) {
|
||||
buf = xchar2b_buf;
|
||||
left = buf_len = BUFSIZ;
|
||||
|
||||
if (_XomConvert(oc, conv, (XPointer *) &text, &length,
|
||||
(XPointer *) &buf, &left, args, 2) < 0)
|
||||
break;
|
||||
buf_len -= left;
|
||||
|
||||
if (is_xchar2b)
|
||||
XTextExtents16(font, xchar2b_buf, buf_len, &direction,
|
||||
&tmp_ascent, &tmp_descent, &tmp_overall);
|
||||
else
|
||||
XTextExtents(font, (char *) xchar2b_buf, buf_len, &direction,
|
||||
&tmp_ascent, &tmp_descent, &tmp_overall);
|
||||
|
||||
if (first) { /* initialize overall */
|
||||
overall = tmp_overall;
|
||||
logical_ascent = tmp_ascent;
|
||||
logical_descent = tmp_descent;
|
||||
first = False;
|
||||
} else {
|
||||
overall.lbearing = min(overall.lbearing,
|
||||
overall.width + tmp_overall.lbearing);
|
||||
overall.rbearing = max(overall.rbearing,
|
||||
overall.width + tmp_overall.rbearing);
|
||||
overall.ascent = max(overall.ascent, tmp_overall.ascent);
|
||||
overall.descent = max(overall.descent, tmp_overall.descent);
|
||||
overall.width += tmp_overall.width;
|
||||
logical_ascent = max(logical_ascent, tmp_ascent);
|
||||
logical_descent = max(logical_descent, tmp_descent);
|
||||
}
|
||||
}
|
||||
|
||||
if (overall_ink) {
|
||||
overall_ink->x = overall.lbearing;
|
||||
overall_ink->y = -(overall.ascent);
|
||||
overall_ink->width = overall.rbearing - overall.lbearing;
|
||||
overall_ink->height = overall.ascent + overall.descent;
|
||||
}
|
||||
|
||||
if (overall_logical) {
|
||||
overall_logical->x = 0;
|
||||
overall_logical->y = -(logical_ascent);
|
||||
overall_logical->width = overall.width;
|
||||
overall_logical->height = logical_ascent + logical_descent;
|
||||
}
|
||||
|
||||
return overall.width;
|
||||
}
|
||||
|
||||
int
|
||||
_XmbGenericTextExtents(XOC oc, _Xconst char *text, int length,
|
||||
XRectangle *overall_ink, XRectangle *overall_logical)
|
||||
{
|
||||
return _XomGenericTextExtents(oc, XOMMultiByte, (XPointer) text, length,
|
||||
overall_ink, overall_logical);
|
||||
}
|
||||
|
||||
int
|
||||
_XwcGenericTextExtents(XOC oc, _Xconst wchar_t *text, int length,
|
||||
XRectangle *overall_ink, XRectangle *overall_logical)
|
||||
{
|
||||
return _XomGenericTextExtents(oc, XOMWideChar, (XPointer) text, length,
|
||||
overall_ink, overall_logical);
|
||||
}
|
||||
|
||||
int
|
||||
_Xutf8GenericTextExtents(XOC oc, _Xconst char *text, int length,
|
||||
XRectangle *overall_ink, XRectangle *overall_logical)
|
||||
{
|
||||
return _XomGenericTextExtents(oc, XOMUtf8String, (XPointer) text, length,
|
||||
overall_ink, overall_logical);
|
||||
}
|
||||
202
nx-X11/lib/modules/om/generic/omTextPer.c
Normal file
202
nx-X11/lib/modules/om/generic/omTextPer.c
Normal file
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* Copyright 1992, 1993 by TOSHIBA Corp.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation for any purpose and without fee is hereby granted, provided
|
||||
* that the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of TOSHIBA not be used in advertising
|
||||
* or publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. TOSHIBA make no representations about the
|
||||
* suitability of this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*
|
||||
* TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||
* TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
||||
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Author: Katsuhisa Yano TOSHIBA Corp.
|
||||
* mopi@osa.ilab.toshiba.co.jp
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include "Xlibint.h"
|
||||
#include "XomGeneric.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static Status
|
||||
_XomGenericTextPerCharExtents(
|
||||
XOC oc,
|
||||
XOMTextType type,
|
||||
XPointer text,
|
||||
int length,
|
||||
XRectangle *ink_buf,
|
||||
XRectangle *logical_buf,
|
||||
int buf_size,
|
||||
int *num_chars,
|
||||
XRectangle *overall_ink,
|
||||
XRectangle *overall_logical)
|
||||
{
|
||||
XlcConv conv;
|
||||
XFontStruct *font;
|
||||
Bool is_xchar2b;
|
||||
XPointer args[2];
|
||||
XChar2b xchar2b_buf[BUFSIZ], *xchar2b_ptr;
|
||||
char *xchar_ptr = NULL;
|
||||
XCharStruct *def, *cs, overall;
|
||||
int buf_len, left, require_num;
|
||||
int logical_ascent, logical_descent;
|
||||
Bool first = True;
|
||||
|
||||
conv = _XomInitConverter(oc, type);
|
||||
if (conv == NULL)
|
||||
return 0;
|
||||
|
||||
bzero((char *) &overall, sizeof(XCharStruct));
|
||||
logical_ascent = logical_descent = require_num = *num_chars = 0;
|
||||
|
||||
args[0] = (XPointer) &font;
|
||||
args[1] = (XPointer) &is_xchar2b;
|
||||
|
||||
while (length > 0) {
|
||||
xchar2b_ptr = xchar2b_buf;
|
||||
left = buf_len = BUFSIZ;
|
||||
|
||||
if (_XomConvert(oc, conv, (XPointer *) &text, &length,
|
||||
(XPointer *) &xchar2b_ptr, &left, args, 2) < 0)
|
||||
break;
|
||||
buf_len -= left;
|
||||
|
||||
if (require_num) {
|
||||
require_num += buf_len;
|
||||
continue;
|
||||
}
|
||||
if (buf_size < buf_len) {
|
||||
require_num = *num_chars + buf_len;
|
||||
continue;
|
||||
}
|
||||
buf_size -= buf_len;
|
||||
|
||||
if (first) {
|
||||
logical_ascent = font->ascent;
|
||||
logical_descent = font->descent;
|
||||
} else {
|
||||
logical_ascent = max(logical_ascent, font->ascent);
|
||||
logical_descent = max(logical_descent, font->descent);
|
||||
}
|
||||
|
||||
if (is_xchar2b) {
|
||||
CI_GET_DEFAULT_INFO_2D(font, def)
|
||||
xchar2b_ptr = xchar2b_buf;
|
||||
} else {
|
||||
CI_GET_DEFAULT_INFO_1D(font, def)
|
||||
xchar_ptr = (char *) xchar2b_buf;
|
||||
}
|
||||
|
||||
while (buf_len-- > 0) {
|
||||
if (is_xchar2b) {
|
||||
CI_GET_CHAR_INFO_2D(font, xchar2b_ptr->byte1,
|
||||
xchar2b_ptr->byte2, def, cs)
|
||||
xchar2b_ptr++;
|
||||
} else {
|
||||
CI_GET_CHAR_INFO_1D(font, *xchar_ptr, def, cs)
|
||||
xchar_ptr++;
|
||||
}
|
||||
if (cs == NULL)
|
||||
continue;
|
||||
|
||||
ink_buf->x = overall.width + cs->lbearing;
|
||||
ink_buf->y = -(cs->ascent);
|
||||
ink_buf->width = cs->rbearing - cs->lbearing;
|
||||
ink_buf->height = cs->ascent + cs->descent;
|
||||
ink_buf++;
|
||||
|
||||
logical_buf->x = overall.width;
|
||||
logical_buf->y = -(font->ascent);
|
||||
logical_buf->width = cs->width;
|
||||
logical_buf->height = font->ascent + font->descent;
|
||||
logical_buf++;
|
||||
|
||||
if (first) {
|
||||
overall = *cs;
|
||||
first = False;
|
||||
} else {
|
||||
overall.ascent = max(overall.ascent, cs->ascent);
|
||||
overall.descent = max(overall.descent, cs->descent);
|
||||
overall.lbearing = min(overall.lbearing,
|
||||
overall.width + cs->lbearing);
|
||||
overall.rbearing = max(overall.rbearing,
|
||||
overall.width + cs->rbearing);
|
||||
overall.width += cs->width;
|
||||
}
|
||||
|
||||
(*num_chars)++;
|
||||
}
|
||||
}
|
||||
|
||||
if (require_num) {
|
||||
*num_chars = require_num;
|
||||
return 0;
|
||||
} else {
|
||||
if (overall_ink) {
|
||||
overall_ink->x = overall.lbearing;
|
||||
overall_ink->y = -(overall.ascent);
|
||||
overall_ink->width = overall.rbearing - overall.lbearing;
|
||||
overall_ink->height = overall.ascent + overall.descent;
|
||||
}
|
||||
|
||||
if (overall_logical) {
|
||||
overall_logical->x = 0;
|
||||
overall_logical->y = -(logical_ascent);
|
||||
overall_logical->width = overall.width;
|
||||
overall_logical->height = logical_ascent + logical_descent;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Status
|
||||
_XmbGenericTextPerCharExtents(XOC oc, _Xconst char *text, int length,
|
||||
XRectangle *ink_buf, XRectangle *logical_buf,
|
||||
int buf_size, int *num_chars,
|
||||
XRectangle *overall_ink,
|
||||
XRectangle *overall_logical)
|
||||
{
|
||||
return _XomGenericTextPerCharExtents(oc, XOMMultiByte, (XPointer) text,
|
||||
length, ink_buf, logical_buf, buf_size,
|
||||
num_chars, overall_ink,
|
||||
overall_logical);
|
||||
}
|
||||
|
||||
Status
|
||||
_XwcGenericTextPerCharExtents(XOC oc, _Xconst wchar_t *text, int length,
|
||||
XRectangle *ink_buf, XRectangle *logical_buf,
|
||||
int buf_size, int *num_chars,
|
||||
XRectangle *overall_ink,
|
||||
XRectangle *overall_logical)
|
||||
{
|
||||
return _XomGenericTextPerCharExtents(oc, XOMWideChar, (XPointer) text,
|
||||
length, ink_buf, logical_buf, buf_size,
|
||||
num_chars, overall_ink,
|
||||
overall_logical);
|
||||
}
|
||||
|
||||
Status
|
||||
_Xutf8GenericTextPerCharExtents(XOC oc, _Xconst char *text, int length,
|
||||
XRectangle *ink_buf, XRectangle *logical_buf,
|
||||
int buf_size, int *num_chars,
|
||||
XRectangle *overall_ink,
|
||||
XRectangle *overall_logical)
|
||||
{
|
||||
return _XomGenericTextPerCharExtents(oc, XOMUtf8String, (XPointer) text,
|
||||
length, ink_buf, logical_buf, buf_size,
|
||||
num_chars, overall_ink,
|
||||
overall_logical);
|
||||
}
|
||||
404
nx-X11/lib/modules/om/generic/omXChar.c
Normal file
404
nx-X11/lib/modules/om/generic/omXChar.c
Normal file
@@ -0,0 +1,404 @@
|
||||
/*
|
||||
* Copyright 1992, 1993 by TOSHIBA Corp.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation for any purpose and without fee is hereby granted, provided
|
||||
* that the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of TOSHIBA not be used in advertising
|
||||
* or publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. TOSHIBA make no representations about the
|
||||
* suitability of this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*
|
||||
* TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||
* TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
||||
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Author: Katsuhisa Yano TOSHIBA Corp.
|
||||
* mopi@osa.ilab.toshiba.co.jp
|
||||
*/
|
||||
/*
|
||||
* Copyright 1995 by FUJITSU LIMITED
|
||||
* This is source code modified by FUJITSU LIMITED under the Joint
|
||||
* Development Agreement for the CDE/Motif PST.
|
||||
*
|
||||
* Modifier: Takanori Tateno FUJITSU LIMITED
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Modifiers: Jeff Walls, Paul Anderson (HEWLETT-PACKARD)
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include "Xlibint.h"
|
||||
#include "XlcPublic.h"
|
||||
#include "XomGeneric.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/* for VW/UDC start */
|
||||
static Bool
|
||||
ismatch_scopes(
|
||||
FontData fontdata,
|
||||
unsigned long *value,
|
||||
Bool is_shift)
|
||||
{
|
||||
register int scopes_num = fontdata->scopes_num;
|
||||
FontScope scopes = fontdata->scopes;
|
||||
if (!scopes_num)
|
||||
return False;
|
||||
|
||||
if(fontdata->font == NULL)
|
||||
return False;
|
||||
|
||||
for(;scopes_num--;scopes++)
|
||||
if ((scopes->start <= (*value & 0x7f7f)) &&
|
||||
((scopes->end) >= (*value & 0x7f7f))){
|
||||
if(is_shift == True) {
|
||||
if(scopes->shift){
|
||||
if(scopes->shift_direction == '+'){
|
||||
*value += scopes->shift ;
|
||||
} else if( scopes->shift_direction == '-'){
|
||||
*value -= scopes->shift ;
|
||||
}
|
||||
}
|
||||
}
|
||||
return True;
|
||||
}
|
||||
|
||||
return False;
|
||||
}
|
||||
|
||||
static int
|
||||
check_vertical_fonttype(
|
||||
char *name)
|
||||
{
|
||||
char *ptr;
|
||||
int type = 0;
|
||||
|
||||
if(name == (char *)NULL || (int) strlen(name) <= 0)
|
||||
return False;
|
||||
|
||||
/* Obtains the pointer of CHARSET_ENCODING_FIELD. */
|
||||
if((ptr = strchr(name, '-')) == (char *) NULL)
|
||||
return False;
|
||||
ptr++;
|
||||
|
||||
/* Obtains the pointer of vertical_map font type. */
|
||||
if((ptr = strchr(ptr, '.')) == (char *) NULL)
|
||||
return False;
|
||||
ptr++;
|
||||
|
||||
switch(*ptr) {
|
||||
case '1':
|
||||
type = 1; break;
|
||||
case '2':
|
||||
type = 2; break;
|
||||
case '3':
|
||||
type = 3; break;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/*
|
||||
*/
|
||||
#define VMAP 0
|
||||
#define VROTATE 1
|
||||
#define FONTSCOPE 2
|
||||
|
||||
FontData
|
||||
_XomGetFontDataFromFontSet(
|
||||
FontSet fs,
|
||||
unsigned char *str,
|
||||
int len,
|
||||
int *len_ret,
|
||||
int is2b,
|
||||
int type) /* VMAP , VROTATE , else */
|
||||
{
|
||||
unsigned long value;
|
||||
int num,i,hit,csize;
|
||||
FontData fontdata;
|
||||
unsigned char *c;
|
||||
int vfont_type;
|
||||
|
||||
c = str;
|
||||
hit = -1;
|
||||
if(type == VMAP){
|
||||
fontdata = fs->vmap;
|
||||
num = fs->vmap_num;
|
||||
} else if(type == VROTATE){
|
||||
fontdata = (FontData)fs->vrotate;
|
||||
num = fs->vrotate_num;
|
||||
} else {
|
||||
if(fs->font_data_count <= 0 || fs->font_data == (FontData)NULL) {
|
||||
fontdata = fs->substitute;
|
||||
num = fs->substitute_num;
|
||||
}else {
|
||||
fontdata = fs->font_data;
|
||||
num = fs->font_data_count;
|
||||
}
|
||||
/* CDExc20229 fix */
|
||||
if(fontdata == NULL || num == 0){
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(is2b){
|
||||
csize = 2;
|
||||
} else {
|
||||
csize = 1;
|
||||
}
|
||||
|
||||
for(;len;len--){
|
||||
if(is2b){
|
||||
value = (((unsigned long)*c) << 8)|(unsigned long)*(c + 1);
|
||||
} else {
|
||||
value = (unsigned long)*c;
|
||||
}
|
||||
|
||||
/* ### NOTE: This routine DOES NOT WORK!
|
||||
* ### We can work around the problem in the calling routine,
|
||||
* ### but we really need to understand this better. As it
|
||||
* ### stands, the algorithm ALWAYS returns "fontdata[0]"
|
||||
* ### for non-VW text! This is clearly wrong. In fact,
|
||||
* ### given the new parse_font[name|data]() algorithms,
|
||||
* ### we may not even need this routine to do anything
|
||||
* ### for non-VW text (since font_set->font always contains
|
||||
* ### the best font for this fontset). -- jjw/pma (HP)
|
||||
*/
|
||||
for (i=0;i<num;i++) {
|
||||
if(type == VROTATE) {
|
||||
if(fontdata[i].font) {
|
||||
/* If the num_cr equal zero, all character is rotated. */
|
||||
if(fontdata[i].scopes_num == 0) {
|
||||
break;
|
||||
} else {
|
||||
/* The vertical rotate glyph is not have code shift. */
|
||||
if (ismatch_scopes(&(fontdata[i]),&value,False)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(type == VMAP) {
|
||||
if(fontdata[i].font) {
|
||||
vfont_type = check_vertical_fonttype(fontdata[i].name);
|
||||
if(vfont_type == 0 || vfont_type == 1) {
|
||||
break;
|
||||
} else if(vfont_type == 2 || vfont_type == 3) {
|
||||
if(fontdata[i].scopes_num <= 0)
|
||||
break;
|
||||
|
||||
if (ismatch_scopes(&(fontdata[i]),&value,True)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { /* FONTSCOPE */
|
||||
if(fontdata[i].font) {
|
||||
if(fontdata[i].scopes_num <= 0)
|
||||
break;
|
||||
if (ismatch_scopes(&(fontdata[i]),&value,True)){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if((hit != -1) && (i != hit)){
|
||||
break;
|
||||
}
|
||||
if(i == num){
|
||||
if( type == VROTATE || type == VMAP){
|
||||
/* Change 1996.01.23 start */
|
||||
if(fs->font_data_count <= 0 ||
|
||||
fs->font_data == (FontData)NULL)
|
||||
fontdata = fs->substitute;
|
||||
else
|
||||
fontdata = fs->font_data;
|
||||
/* Change 1996.01.23 end */
|
||||
}
|
||||
hit = 0;
|
||||
c += csize;
|
||||
break;
|
||||
}
|
||||
if( hit == -1 ) hit = i;
|
||||
if(is2b){
|
||||
*c = (unsigned char)(value >> 8);
|
||||
*(c + 1) = (unsigned char)(value);
|
||||
} else {
|
||||
*c = (unsigned char)value;
|
||||
}
|
||||
c += csize;
|
||||
}
|
||||
*len_ret = (c - str);
|
||||
return(&(fontdata[hit]));
|
||||
}
|
||||
/* for VW/UDC end */
|
||||
|
||||
static FontSet
|
||||
_XomGetFontSetFromCharSet(
|
||||
XOC oc,
|
||||
XlcCharSet charset)
|
||||
{
|
||||
register FontSet font_set = XOC_GENERIC(oc)->font_set;
|
||||
register int num = XOC_GENERIC(oc)->font_set_num;
|
||||
XlcCharSet *charset_list;
|
||||
int charset_count;
|
||||
|
||||
for ( ; num-- > 0; font_set++) {
|
||||
charset_count = font_set->charset_count;
|
||||
charset_list = font_set->charset_list;
|
||||
for ( ; charset_count-- > 0; charset_list++)
|
||||
if (*charset_list == charset)
|
||||
return font_set;
|
||||
}
|
||||
|
||||
return (FontSet) NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
shift_to_gl(
|
||||
register char *text,
|
||||
register int length)
|
||||
{
|
||||
while (length-- > 0)
|
||||
*text++ &= 0x7f;
|
||||
}
|
||||
|
||||
static void
|
||||
shift_to_gr(
|
||||
register char *text,
|
||||
register int length)
|
||||
{
|
||||
while (length-- > 0)
|
||||
*text++ |= 0x80;
|
||||
}
|
||||
|
||||
static Bool
|
||||
load_font(
|
||||
XOC oc,
|
||||
FontSet font_set)
|
||||
{
|
||||
font_set->font = XLoadQueryFont(oc->core.om->core.display,
|
||||
oc->core.font_info.font_name_list[font_set->id]);
|
||||
if (font_set->font == NULL)
|
||||
return False;
|
||||
|
||||
oc->core.font_info.font_struct_list[font_set->id] = font_set->font;
|
||||
XFreeFontInfo(NULL, font_set->info, 1);
|
||||
font_set->info = NULL;
|
||||
|
||||
if (font_set->font->min_byte1 || font_set->font->max_byte1)
|
||||
font_set->is_xchar2b = True;
|
||||
else
|
||||
font_set->is_xchar2b = False;
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
int
|
||||
_XomConvert(
|
||||
XOC oc,
|
||||
XlcConv conv,
|
||||
XPointer *from,
|
||||
int *from_left,
|
||||
XPointer *to,
|
||||
int *to_left,
|
||||
XPointer *args,
|
||||
int num_args)
|
||||
{
|
||||
XPointer cs, lc_args[1];
|
||||
XlcCharSet charset;
|
||||
int length, cs_left, ret;
|
||||
FontSet font_set;
|
||||
|
||||
cs = *to;
|
||||
cs_left = *to_left;
|
||||
lc_args[0] = (XPointer) &charset;
|
||||
|
||||
ret = _XlcConvert(conv, from, from_left, &cs, &cs_left, lc_args, 1);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
font_set = _XomGetFontSetFromCharSet(oc, charset);
|
||||
if (font_set == NULL)
|
||||
return -1;
|
||||
|
||||
if (font_set->font == NULL && load_font(oc, font_set) == False)
|
||||
return -1;
|
||||
|
||||
length = *to_left - cs_left;
|
||||
|
||||
if (font_set->side != charset->side) {
|
||||
if (font_set->side == XlcGL)
|
||||
shift_to_gl(*to, length);
|
||||
else if (font_set->side == XlcGR)
|
||||
shift_to_gr(*to, length);
|
||||
}
|
||||
|
||||
if (font_set->is_xchar2b)
|
||||
length >>= 1;
|
||||
*to = cs;
|
||||
*to_left -= length;
|
||||
|
||||
*((XFontStruct **) args[0]) = font_set->font;
|
||||
*((Bool *) args[1]) = font_set->is_xchar2b;
|
||||
if(num_args >= 3){
|
||||
*((FontSet *) args[2]) = font_set;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
XlcConv
|
||||
_XomInitConverter(
|
||||
XOC oc,
|
||||
XOMTextType type)
|
||||
{
|
||||
XOCGenericPart *gen = XOC_GENERIC(oc);
|
||||
XlcConv *convp;
|
||||
const char *conv_type;
|
||||
XlcConv conv;
|
||||
XLCd lcd;
|
||||
|
||||
switch (type) {
|
||||
case XOMWideChar:
|
||||
convp = &gen->wcs_to_cs;
|
||||
conv_type = XlcNWideChar;
|
||||
break;
|
||||
case XOMMultiByte:
|
||||
convp = &gen->mbs_to_cs;
|
||||
conv_type = XlcNMultiByte;
|
||||
break;
|
||||
case XOMUtf8String:
|
||||
convp = &gen->utf8_to_cs;
|
||||
conv_type = XlcNUtf8String;
|
||||
break;
|
||||
default:
|
||||
return (XlcConv) NULL;
|
||||
}
|
||||
|
||||
conv = *convp;
|
||||
if (conv) {
|
||||
_XlcResetConverter(conv);
|
||||
return conv;
|
||||
}
|
||||
|
||||
lcd = oc->core.om->core.lcd;
|
||||
|
||||
conv = _XlcOpenConverter(lcd, conv_type, lcd, XlcNFontCharSet);
|
||||
if (conv == (XlcConv) NULL) {
|
||||
conv = _XlcOpenConverter(lcd, conv_type, lcd, XlcNCharSet);
|
||||
if (conv == (XlcConv) NULL)
|
||||
return (XlcConv) NULL;
|
||||
}
|
||||
|
||||
*convp = conv;
|
||||
return conv;
|
||||
}
|
||||
Reference in New Issue
Block a user