/******************************************************************
Copyright 1990, 1991, 1992,1993, 1994 by FUJITSU LIMITED
Copyright 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 FUJITSU LIMITED
and Sony Corporation not be used in advertising or publicity
pertaining to distribution of the software without specific,
written prior permission. FUJITSU LIMITED and Sony Corporation make
no representations about the suitability of this software for any
purpose. It is provided "as is" without express or implied warranty.
FUJITSU LIMITED AND SONY CORPORATION DISCLAIM ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 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: Takashi Fujiwara FUJITSU LIMITED
fujiwara@a80.tech.yk.fujitsu.co.jp
Modifier: Makoto Wakamatsu Sony Corporation
makoto@sm.sony.co.jp
******************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <X11/Xlib.h>
#include "Xlibint.h"
#include "Xlcint.h"
#include "Ximint.h"
#include "Xresource.h"
#define GET_NAME(x) name_table + x.name_offset
typedef struct _XimValueOffsetInfo {
unsigned short name_offset;
XrmQuark quark;
unsigned int offset;
Bool (*defaults)(
struct _XimValueOffsetInfo *, XPointer, XPointer, unsigned long
);
Bool (*encode)(
struct _XimValueOffsetInfo *, XPointer, XPointer
);
Bool (*decode)(
struct _XimValueOffsetInfo *, XPointer, XPointer
);
} XimValueOffsetInfoRec, *XimValueOffsetInfo;
#ifdef XIM_CONNECTABLE
static Bool
_XimCheckBool(str)
char *str;
{
if(!strcmp(str, "True") || !strcmp(str, "true") ||
!strcmp(str, "Yes") || !strcmp(str, "yes") ||
!strcmp(str, "ON") || !strcmp(str, "on"))
return True;
return False;
}
void
_XimSetProtoResource(im)
Xim im;
{
char res_name_buf[256];
char* res_name;
size_t res_name_len;
char res_class_buf[256];
char* res_class;
size_t res_class_len;
char* str_type;
XrmValue value;
XIMStyle preedit_style = 0;
XIMStyle status_style = 0;
XIMStyles* imstyles;
char* dotximdot = ".xim.";
char* ximdot = "xim.";
char* dotXimdot = ".Xim.";
char* Ximdot = "Xim.";
if (!im->core.rdb)
return;
res_name_len = strlen (im->core.res_name);
if (res_name_len < 200) {
res_name = res_name_buf;
res_name_len = sizeof(res_name_buf);
}
else {
res_name_len += 50;
res_name = Xmalloc (res_name_len);
}
res_class_len = strlen (im->core.res_class);
if (res_class_len < 200) {
res_class = res_class_buf;
res_class_len = sizeof(res_class_buf);
}
else {
res_class_len += 50;
res_class = Xmalloc (res_class_len);
}
/* pretend malloc always works */
(void) snprintf (res_name, res_name_len, "%s%s%s",
im->core.res_name != NULL ? im->core.res_name : "*",
im->core.res_name != NULL ? dotximdot : ximdot,
"useAuth");
(void) snprintf (res_class, res_class_len, "%s%s%s",
im->core.res_class != NULL ? im->core.res_class : "*",
im->core.res_class != NULL ? dotXimdot : Ximdot,
"UseAuth");
bzero(&value, sizeof(XrmValue));
if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
if(_XimCheckBool(value.addr)) {
MARK_USE_AUTHORIZATION_FUNC(im);
}
}
(void) snprintf (res_name, res_name_len, "%s%s%s",
im->core.res_name != NULL ? im->core.res_name : "*",
im->core.res_name != NULL ? dotximdot : ximdot,
"delaybinding");
(void) snprintf (res_class, res_class_len, "%s%s%s",
im->core.res_class != NULL ? im->core.res_class : "*",
im->core.res_class != NULL ? dotXimdot : Ximdot,
"Delaybinding");
bzero(&value, sizeof(XrmValue));
if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
if(_XimCheckBool(value.addr)) {
MARK_DELAYBINDABLE(im);
}
}
(void) snprintf (res_name, res_name_len, "%s%s%s",
im->core.res_name != NULL ? im->core.res_name : "*",
im->core.res_name != NULL ? dotximdot : ximdot,
"reconnect");
(void) snprintf (res_class, res_class_len, "%s%s%s",
im->core.res_class != NULL ? im->core.res_class : "*",
im->core.res_class != NULL ? dotXimdot : Ximdot,
"Reconnect");
bzero(&value, sizeof(XrmValue));
if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
if(_XimCheckBool(value.addr)) {
MARK_RECONNECTABLE(im);
}
}
if(!IS_CONNECTABLE(im)) {
if (res_name != res_name_buf) Xfree (res_name);
if (res_class != res_class_buf) Xfree (res_class);
return;
}
(void) snprintf (res_name, res_name_len, "%s%s%s",
im->core.res_name != NULL ? im->core.res_name : "*",
im->core.res_name != NULL ? dotximdot : ximdot,
"preeditDefaultStyle");
(void) snprintf (res_class, res_class_len, "%s%s%s",
im->core.res_class != NULL ? im->core.res_class : "*",
im->core.res_class != NULL ? dotXimdot : Ximdot,
"PreeditDefaultStyle");
if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
if(!strcmp(value.addr, "XIMPreeditArea"))
preedit_style = XIMPreeditArea;
else if(!strcmp(value.addr, "XIMPreeditCallbacks"))
preedit_style = XIMPreeditCallbacks;
else if(!strcmp(value.addr, "XIMPreeditPosition"))
preedit_style = XIMPreeditPosition;
else if(!strcmp(value.addr, "XIMPreeditNothing"))
preedit_style = XIMPreeditNothing;
else if(!strcmp(value.addr, "XIMPreeditNone"))
preedit_style = XIMPreeditNone;
}
if(!preedit_style)
preedit_style = XIMPreeditNothing;
(void) snprintf (res_name, res_name_len, "%s%s%s",
im->core.res_name != NULL ? im->core.res_name : "*",
im->core.res_name != NULL ? dotximdot : ximdot,
"statusDefaultStyle");
(void) snprintf (res_class, res_class_len, "%s%s%s",
im->core.res_class != NULL ? im->core.res_class : "*",
im->core.res_class != NULL ? dotXimdot : Ximdot,
"StatusDefaultStyle");
if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
if(!strcmp(value.addr, "XIMStatusArea"))
status_style = XIMStatusArea;
else if(!strcmp(value.addr, "XIMStatusCallbacks"))
status_style = XIMStatusCallbacks;
else if(!strcmp(value.addr, "XIMStatusNothing"))
status_style = XIMStatusNothing;
else if(!strcmp(value.addr, "XIMStatusNone"))
status_style = XIMStatusNone;
}
if(!status_style)
status_style = XIMStatusNothing;
if(!(imstyles = Xmalloc(sizeof(XIMStyles) + sizeof(XIMStyle)))){
if (res_name != res_name_buf) Xfree (res_name);
if (res_class != res_class_buf) Xfree (res_class);
return;
}
imstyles->count_styles = 1;
imstyles->supported_styles =
(XIMStyle *)((char *)imstyles + sizeof(XIMStyles));
imstyles->supported_styles[0] = preedit_style | status_style;
im->private.proto.default_styles = imstyles;
if (res_name != res_name_buf) Xfree (res_name);
if (res_class != res_class_buf) Xfree (res_class);
}
#endif /* XIM_CONNECTABLE */
static const char name_table[] =
/* 0 */ XNQueryInputStyle"\0"
/* 16 */ XNClientWindow"\0"
/* 29 */ XNInputStyle"\0"
/* 40 */ XNFocusWindow"\0"
/* 52 */ XNResourceName"\0"
/* 65 */ XNResourceClass"\0"
/* 79 */ XNGeometryCallback"\0"
/* 96 */ XNDestroyCallback"\0"
/* 112 */ XNFilterEvents"\0"
/* 125 */ XNPreeditStartCallback"\0"
/* 146 */ XNPreed