* $XConsortium: XCrIC.c,v 1.34 92/07/29 13:54:58 rws Exp $
* Copyright 1990, 1991 by OMRON Corporation
* Copyright 1991 by the Massachusetts Institute of Technology
* 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 OMRON and MIT not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. OMRON and MIT make no representations
* about the suitability of this software for any purpose. It is provided
* "as is" without express or implied warranty.
* OMRON AND MIT DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OMRON OR MIT 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
* TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
* Author: Seiji Kuwari OMRON Corporation
* kuwa%omron.co.jp@uunet.uu.net
#if NeedVarargsPrototypes
# define Va_start(a,b) va_start(a,b)
# define Va_start(a,b) va_start(a)
#if __STDC__ && !defined(NORCONST)
* Free the input context.
XipIM im
= (XipIM
)ic
->core
.im
;
req
.reqType
= XIM_DestroyIC
;
req
.length
= sz_ximDestroyICReq
;
if ((_XipWriteToIM(im
, (char *)&req
, sz_ximDestroyICReq
) >= 0) &&
(_XipFlushToIM(im
) >= 0)) {
if ((_XipReadFromIM(im
, (char *)&reply
, sz_ximEventReply
) < 0)
|| (reply
.state
== 0xffff)) {
if (reply
.detail
== XIM_CALLBACK
) {
* Call the callback routines.
if (_XipCallCallbacks(ic
) < 0) {
_XUnregisterFilter(im
->core
.display
, ic
->core
.focus_window
,
ic
->prototype_filter
, (XPointer
)ic
);
if (ic
->mb
) _XlcFreeLocale(ic
->mb
);
if (ic
->wc
) _XlcFreeLocale(ic
->wc
);
for (i
= 0; i
< ic
->xlc_num
; i
++) {
_XlcFreeLocale(ic
->mb_temp
[i
]);
_XlcFreeLocale(ic
->wc_temp
[i
]);
if (ic
->mb_temp
) Xfree(ic
->mb_temp
);
if (ic
->wc_temp
) Xfree(ic
->wc_temp
);
if (ic
->values
.using_language
) Xfree(ic
->values
.using_language
);
if (ic
->values
.current_language
) Xfree(ic
->values
.current_language
);
if (ic
->ct_buf
) Xfree(ic
->ct_buf
);
if (ic
->wc_buf
) Xfree(ic
->wc_buf
);
(void) _XipFreeAllICQueue(ic
);
static RConst XICMethodsRec ic_methods
= {
_StringToPixel(display
, colormap
, name
, pixel
)
status
= XParseColor(display
, colormap
, name
, &c
);
status
= XAllocColor(display
, colormap
, &c
);
status
= XAllocNamedColor(display
, colormap
, name
, &c
, &e_c
);
_XipReadRdb(display
, ic
, mask
, rdb
, res_name
, res_class
)
unsigned long ret_mask
= 0;
char name_prefix
[256], class_prefix
[256];
char res_name_buf
[256], res_class_buf
[256];
char def_fg_name
[256], def_bg_name
[256];
unsigned long def_fg
, def_bg
;
XIMArg args
[8], pre_args
[4], st_args
[4];
int count
= 0, pre_count
= 0, st_count
= 0;
Colormap colormap
, def_colormap
;
XWindowAttributes win_info
;
if (ic
->core
.client_window
) {
XGetWindowAttributes(display
, ic
->core
.client_window
, &win_info
);
XGetWindowAttributes(display
,
RootWindow(display
, DefaultScreen(display
)),
def_colormap
= win_info
.colormap
;
if (res_name
== NULL
|| *res_name
== '\0'
|| res_class
== NULL
|| *res_class
== '\0') {
strcpy(name_prefix
, "*.");
strcpy(class_prefix
, "*.");
strcpy(name_prefix
, res_name
);
strcpy(class_prefix
, res_class
);
strcat(name_prefix
, ".");
strcat(class_prefix
, ".");
if (!(mask
& ((1 << ICForeground
) | (1 << (ICForeground
+ StatusOffset
))))){
strcpy(res_name_buf
, name_prefix
);
strcpy(res_class_buf
, class_prefix
);
strcat(res_name_buf
, "foreground");
strcat(res_class_buf
, "Foreground");
if (XrmGetResource(rdb
, res_name_buf
, res_class_buf
,
str_type
, &value
) == True
) {
strncpy(def_fg_name
, value
.addr
, (int)value
.size
);
if (ic
->core
.preedit_attr
.colormap
) {
colormap
= ic
->core
.preedit_attr
.colormap
;
if (_StringToPixel(display
, colormap
, def_fg_name
, &def_fg
) == 0) {
if (!(mask
& (1 << ICForeground
))) {
pre_args
[pre_count
].name
= (char *)XNForeground
;
pre_args
[pre_count
].value
= (XPointer
)def_fg
;
if (!(mask
& (1 << (ICForeground
+ StatusOffset
)))) {
st_args
[st_count
].name
= (char *)XNForeground
;
st_args
[st_count
].value
= (XPointer
)def_fg
;
fprintf(stderr
, "XIM: Could not Alloc color \"%s\".",
if (!(mask
& ((1 << ICBackground
) | (1 << (ICBackground
+ StatusOffset
))))){
strcpy(res_name_buf
, name_prefix
);
strcpy(res_class_buf
, class_prefix
);
strcat(res_name_buf
, "background");
strcat(res_class_buf
, "Background");
if (XrmGetResource(rdb
, res_name_buf
, res_class_buf
,
str_type
, &value
) == True
) {
strncpy(def_bg_name
, value
.addr
, (int)value
.size
);
if (ic
->core
.preedit_attr
.colormap
) {
colormap
= ic
->core
.preedit_attr
.colormap
;
if (_StringToPixel(display
, colormap
, def_bg_name
, &def_bg
) == 0) {
if (!(mask
& (1 << ICBackground
))) {
pre_args
[pre_count
].name
= (char *)XNBackground
;
pre_args
[pre_count
].value
= (XPointer
)def_bg
;
if (!(mask
& (1 << (ICBackground
+ StatusOffset
)))) {
st_args
[st_count
].name
= (char *)XNBackground
;
st_args
[st_count
].value
= (XPointer
)def_bg
;
fprintf(stderr
, "XIM: Could not Alloc color \"%s\".",
if (!(mask & ((1 << ICFontSet) | (1 << (ICFontSet + StatusOffset))))) {
strcpy(res_name_buf, name_prefix);
strcpy(res_class_buf, class_prefix);
strcat(res_name_buf, "fontSet");
strcat(res_class_buf, "FontSet");
if (XrmGetResource(rdb, res_name_buf, res_class_buf,
str_type, &value) == True) {
strncpy(def_fontset, value.addr, value.size);
if (!(mask & (1 << ICFontSet))) {
pre_args[pre_count].name = (char *)XNFontSet;
pre_args[pre_count].value = (XPointer)def_fontset;
if (!(mask & (1 << (ICFontSet + StatusOffset)))) {
st_args[st_count].name = (char *)XNForeground;
st_args[st_count].value = (XPointer)def_fg;
if (!(mask
& (1 << ICUsingLanguage
))) {
strcpy(res_name_buf
, name_prefix
);
strcpy(res_class_buf
, class_prefix
);
strcat(res_name_buf
, "usingLanguage");
strcat(res_class_buf
, "usingLanguage");
if (XrmGetResource(rdb
, res_name_buf
, res_class_buf
,
str_type
, &value
) == True
) {
strncpy(def_language
, value
.addr
, (int)value
.size
);
args
[count
].name
= (char *)XNUsingLanguage
;
args
[count
].value
= (XPointer
)def_language
;
pre_args
[pre_count
].name
= (char *)NULL
;
(void)_XipICSetAttrValues(im
, pre_args
, &ic
->core
.preedit_attr
,
st_args
[st_count
].name
= (char *)NULL
;
(void)_XipICSetAttrValues(im
, st_args
, &ic
->core
.status_attr
,
&ret_mask
, StatusOffset
);
args
[count
].name
= (char *)NULL
;
(void)_XipICSetValues(ic
, args
, &ret_mask
);
im
->default_ic
= (XipIC
)Xcalloc(1, sizeof(XipICRec
));
if (im
->default_ic
== NULL
) {
im
->default_ic
->core
.im
= (XIM
)im
;
im
->default_mask
= _XipReadRdb(im
->core
.display
, im
->default_ic
,
im
->core
.rdb
, im
->core
.res_name
,
* Create an input context within the input method,
* and return a pointer the input context ti the caller.
_XipCreateIC(supim
, args
)
extern Bool
_XipBackEndFilter();
char *p
, **nls_list
, **l
;
* If im is not specified or the file descripter is not available,
if ((ic
= (XipIC
)Xcalloc(1, sizeof(XipICRec
))) == NULL
) {
bcopy((char *)&im
->default_ic
->values
, (char *)&ic
->values
,
sizeof(struct _ICValues
));
ic
->methods
= (XICMethods
) &ic_methods
;
ic
->prototype_filter
= _XipBackEndFilter
;
(void)_XipICSetValues(ic
, args
, &mask
);
req
.reqType
= XIM_CreateIC
;
req
.length
= sz_ximCreateICReq
+ strlen(im
->client_data
);
if ((_XipWriteToIM(im
, (char *)&req
, sz_ximCreateICReq
) < 0) ||
(_XipWriteToIM(im
, im
->client_data
, strlen(im
->client_data
)) < 0) ||
(_XipFlushToIM(im
) < 0)) {
if (im
->core
.rdb
&& ic
->values
.res_name
&& ic
->values
.res_class
) {
mask
|= _XipReadRdb(im
->core
.display
, ic
, mask
, im
->core
.rdb
,
ic
->values
.res_name
, ic
->values
.res_class
);
ic
->mb
= _XlcDupLocale(im
->xlc
);
ic
->wc
= _XlcDupLocale(im
->xlc
);
n
= strlen(im
->xlc
->xlc_db
->lc_name
) + 1;
if ((p
= Xmalloc(n
)) == NULL
) return(NULL
);
strcpy(p
, im
->xlc
->xlc_db
->lc_name
);
ic
->values
.using_language
= p
;
mask
|= (1 << ICUsingLanguage
);
if ((ic
->mb_temp
= (XLocale
*)Xmalloc(sizeof(XLocale
) * 32)) == NULL
) {
if ((ic
->wc_temp
= (XLocale
*)Xmalloc(sizeof(XLocale
) * 32)) == NULL
) {
_XlcListLocale(&nls_list
);
for (l
= nls_list
; *l
; l
++) {
xlc
= _XlcMakeLocale(*l
);
ic
->mb_temp
[ic
->xlc_num
] = xlc
;
ic
->wc_temp
[ic
->xlc_num
] = _XlcDupLocale(xlc
);
n
+= strlen(ic
->mb_temp
[ic
->xlc_num
]->xlc_db
->lc_name
) + 1;
if ((p
= Xmalloc(n
)) == NULL
) return(NULL
);
for (i
= 0; i
< ic
->xlc_num
; i
++) {
strcat(p
, ic
->mb_temp
[i
]->xlc_db
->lc_name
);
ic
->values
.using_language
= p
;
mask
|= (1 << ICUsingLanguage
);
* Attempt to send IC data to the input manager. If sending failed,
* free IC structure and return NULL.
_XipSendICValues(ic
, mask
);
ic
->max_of_ct
= ic
->max_of_wc
= 0;
if ((_XipReadFromIM(im
, (char *)&reply1
, sz_ximEventReply
) < 0) ||
(reply1
.state
== 0xffff)) {
if (reply1
.detail
== XIM_CALLBACK
) {
* Call the callback routines.
if (_XipCallCallbacks(ic
) < 0) {
} else if (reply1
.detail
== XIM_IC
) {
if (_XipReadFromIM(im
, (char *)&reply
, sz_ximCreateICReply
) < 0) {
* Attempt to get current IC data from the input manager.
_XipReceiveICValues(ic
, (unsigned long)ICAllMask
);
for (i
= 0; i
< ic
->xlc_num
; i
++) {
if (!strcmp(ic
->values
.current_language
,
ic
->mb_temp
[i
]->xlc_db
->lc_name
)) {
if (ic
->mb
) _XlcFreeLocale(ic
->mb
);
if (ic
->wc
) _XlcFreeLocale(ic
->wc
);
for (i
= 0; i
< ic
->xlc_num
; i
++) {
_XlcFreeLocale(ic
->mb_temp
[i
]);
_XlcFreeLocale(ic
->wc_temp
[i
]);
if (ic
->mb_temp
) Xfree(ic
->mb_temp
);
if (ic
->wc_temp
) Xfree(ic
->wc_temp
);
if (ic
->values
.using_language
) Xfree(ic
->values
.using_language
);
* Reset the input context.
XIC ic
; /* specified the input context to reset*/
XipIM im
= ipIMofIC((XipIC
)ic
);
* If im is not specified or the file descripter is not available,
req
.reqType
= XIM_ResetIC
;
req
.length
= sz_ximResetICReq
;
req
.xic
= ((XipIC
)ic
)->icid
;
if ((_XipWriteToIM(im
, (char *)&req
, sz_ximResetICReq
) >= 0) &&
(_XipFlushToIM(im
) >= 0)) {
if ((_XipReadFromIM(im
, (char *)&reply
, sz_ximEventReply
) < 0) ||
(reply
.state
== 0xffff)) {
if (reply
.detail
== XIM_CALLBACK
) {
* Call the callback routines.
if (_XipCallCallbacks(ic
) < 0) {
XIC ic
; /* specified the input context to reset*/
XipIM im
= ipIMofIC((XipIC
)ic
);
* If im is not specified or the file descripter is not available,
req
.reqType
= XIM_ResetIC
;
req
.length
= sz_ximResetICReq
;
req
.xic
= ((XipIC
)ic
)->icid
;
if ((_XipWriteToIM(im
, (char *)&req
, sz_ximResetICReq
) >= 0) &&
(_XipFlushToIM(im
) >= 0)) {
if ((_XipReadFromIM(im
, (char *)&reply
, sz_ximEventReply
) < 0) ||
(reply
.state
== 0xffff)) {
if (reply
.detail
== XIM_CALLBACK
) {
* Call the callback routines.
if (_XipCallCallbacks(ic
) < 0) {
_XipChangeLocale(ic
, lc_name
)
for (i
= 0; i
< ic
->xlc_num
; i
++) {
if ((!strcmp(lc_name
, ic
->mb_temp
[i
]->lc_lang
)) ||
(!strcmp(lc_name
, ic
->mb_temp
[i
]->xlc_db
->lc_name
))) {
xlc
= _XlcMakeLocale(lc_name
);
ic
->mb
= ic
->mb_temp
[ic
->xlc_num
] = xlc
;
ic
->wc
= ic
->wc_temp
[ic
->xlc_num
] = _XlcDupLocale(xlc
);