17a84e134Smrg/*
27a84e134Smrg * Copyright 1991 by OMRON Corporation
37a84e134Smrg *
47a84e134Smrg * Permission to use, copy, modify, distribute, and sell this software and its
57a84e134Smrg * documentation for any purpose is hereby granted without fee, provided that
67a84e134Smrg * the above copyright notice appear in all copies and that both that
77a84e134Smrg * copyright notice and this permission notice appear in supporting
87a84e134Smrg * documentation, and that the name of OMRON not be used in advertising or
97a84e134Smrg * publicity pertaining to distribution of the software without specific,
107a84e134Smrg * written prior permission.  OMRON makes no representations about the
117a84e134Smrg * suitability of this software for any purpose.  It is provided "as is"
127a84e134Smrg * without express or implied warranty.
137a84e134Smrg *
147a84e134Smrg * OMRON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
157a84e134Smrg * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
167a84e134Smrg * OMRON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
177a84e134Smrg * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
187a84e134Smrg * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,
197a84e134Smrg * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
20421c997bSmrg * SOFTWARE.
217a84e134Smrg *
227a84e134Smrg *	Author:	Seiji Kuwari	OMRON Corporation
237a84e134Smrg *				kuwa@omron.co.jp
247a84e134Smrg *				kuwa%omron.co.jp@uunet.uu.net
25421c997bSmrg */
267a84e134Smrg
277a84e134Smrg
287a84e134Smrg/*
297a84e134Smrg
307a84e134SmrgCopyright 1994, 1998  The Open Group
317a84e134Smrg
327a84e134SmrgPermission to use, copy, modify, distribute, and sell this software and its
337a84e134Smrgdocumentation for any purpose is hereby granted without fee, provided that
347a84e134Smrgthe above copyright notice appear in all copies and that both that
357a84e134Smrgcopyright notice and this permission notice appear in supporting
367a84e134Smrgdocumentation.
377a84e134Smrg
387a84e134SmrgThe above copyright notice and this permission notice shall be included in
397a84e134Smrgall copies or substantial portions of the Software.
407a84e134Smrg
417a84e134SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
427a84e134SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
437a84e134SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
447a84e134SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
457a84e134SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
467a84e134SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
477a84e134Smrg
487a84e134SmrgExcept as contained in this notice, the name of The Open Group shall not be
497a84e134Smrgused in advertising or otherwise to promote the sale, use or other dealings
507a84e134Smrgin this Software without prior written authorization from The Open Group.
517a84e134Smrg
527a84e134Smrg*/
537a84e134Smrg
547a84e134Smrg#ifdef HAVE_CONFIG_H
557a84e134Smrg#include <config.h>
567a84e134Smrg#endif
577a84e134Smrg#include <X11/IntrinsicP.h>
587a84e134Smrg#include <X11/StringDefs.h>
597a84e134Smrg#include <X11/Xos.h>
607a84e134Smrg#include <X11/Xfuncs.h>
617a84e134Smrg#include <X11/ShellP.h>
627a84e134Smrg#include <X11/Xaw/TextP.h>
637a84e134Smrg#include <X11/Xaw/MultiSrc.h>
647a84e134Smrg#include <X11/Xaw/MultiSinkP.h>
657a84e134Smrg#include <X11/Xaw/XawImP.h>
667a84e134Smrg#include <X11/Xaw/VendorEP.h>
677a84e134Smrg#include "XawI18n.h"
687a84e134Smrg#include <ctype.h>
697a84e134Smrg
707a84e134Smrg#include <stdarg.h>
717a84e134Smrg
727a84e134Smrg#define maxAscentOfFontSet(fontset)     \
737a84e134Smrg        ( - (XExtentsOfFontSet((fontset)))->max_logical_extent.y)
747a84e134Smrg
757a84e134Smrg#define maxHeightOfFontSet(fontset) \
767a84e134Smrg        ((XExtentsOfFontSet((fontset)))->max_logical_extent.height)
777a84e134Smrg
787a84e134Smrg#define maxDescentOfFontSet(fontset) \
797a84e134Smrg        (maxHeightOfFontSet(fontset) - maxAscentOfFontSet(fontset))
807a84e134Smrg
817a84e134Smrg#define Offset(field) (XtOffsetOf(XawIcTablePart, field))
827a84e134Smrg
83efbcb2bfSmrg#define ADD_IC(value) ic_a[ic_cnt] = (XPointer) value; ic_cnt++
84efbcb2bfSmrg#define USE_IC(count) (ic_cnt > count) ? ic_a[count] : NULL
85efbcb2bfSmrg#define END_IC()      ic_a[ic_cnt] = (XPointer) NULL
86efbcb2bfSmrg
87efbcb2bfSmrg#define ADD_PE(value) pe_a[pe_cnt] = (XPointer) value; pe_cnt++
88efbcb2bfSmrg#define USE_PE(count) (pe_cnt > count) ? pe_a[count] : NULL
89efbcb2bfSmrg#define END_PE()      pe_a[pe_cnt] = (XPointer) NULL
90efbcb2bfSmrg
91efbcb2bfSmrg#define ADD_ST(value) st_a[st_cnt] = (XPointer) value; st_cnt++
92efbcb2bfSmrg#define USE_ST(count) (st_cnt > count) ? st_a[count] : NULL
93efbcb2bfSmrg#define END_ST()      st_a[st_cnt] = (XPointer) NULL
94efbcb2bfSmrg
957a84e134Smrg/*****************************************************
967a84e134Smrg *
977a84e134Smrg * Forward reference prototypes
987a84e134Smrg *
997a84e134Smrg *****************************************************/
100421c997bSmrg
1017a84e134Smrg/*
1027a84e134Smrg * Prototypes
1037a84e134Smrg */
1047a84e134Smrgstatic void AllCreateIC(XawVendorShellExtPart*);
1057a84e134Smrgstatic void CloseIM(XawVendorShellExtPart*);
1067a84e134Smrgstatic void CompileResourceList(XtResourceList, unsigned int);
1077a84e134Smrgstatic void ConfigureCB(Widget, XtPointer, XEvent*, Boolean*);
1087a84e134Smrgstatic void CreateIC(Widget, XawVendorShellExtPart*);
1097a84e134Smrgstatic XawIcTableList CreateIcTable(Widget, XawVendorShellExtPart*);
1107a84e134Smrgstatic XawIcTableList CurrentSharedIcTable(XawVendorShellExtPart*);
1117a84e134Smrgstatic void Destroy(Widget, XawVendorShellExtPart*);
1127a84e134Smrgstatic void DestroyAllIM(XawVendorShellExtPart*);
1137a84e134Smrgstatic void DestroyIC(Widget, XawVendorShellExtPart*);
1147a84e134Smrgstatic void FreeAllDataOfVendorShell(XawVendorShellExtPart*,
1157a84e134Smrg				     VendorShellWidget);
1167a84e134Smrgstatic XawVendorShellExtPart *GetExtPart(VendorShellWidget);
1177a84e134Smrgstatic XawIcTableList GetIcTable(Widget, XawVendorShellExtPart*);
1187a84e134Smrgstatic XawIcTableList GetIcTableShared(Widget, XawVendorShellExtPart*);
1197a84e134Smrgstatic XIMStyle GetInputStyleOfIC(XawVendorShellExtPart*);
1207a84e134Smrgstatic Bool Initialize(VendorShellWidget, XawVendorShellExtPart*);
1217a84e134Smrgstatic Bool IsCreatedIC(Widget, XawVendorShellExtPart*);
1227a84e134Smrgstatic Bool IsRegistered(Widget, XawVendorShellExtPart*);
1237a84e134Smrgstatic Bool IsSharedIC(XawVendorShellExtPart*);
1247a84e134Smrgstatic Bool NoRegistered(XawVendorShellExtPart*);
1257a84e134Smrgstatic void OpenIM(XawVendorShellExtPart*);
1267a84e134Smrgstatic void Reconnect(XawVendorShellExtPart*);
1277a84e134Smrgstatic void Register(Widget, XawVendorShellExtPart*);
1287a84e134Smrgstatic Bool RegisterToVendorShell(Widget, XawVendorShellExtPart*);
1297a84e134Smrgstatic void ResizeVendorShell(VendorShellWidget, XawVendorShellExtPart*);
1307a84e134Smrgstatic Bool ResizeVendorShell_Core(VendorShellWidget, XawVendorShellExtPart*,
1317a84e134Smrg				   XawIcTableList);
1327a84e134Smrgstatic VendorShellWidget SearchVendorShell(Widget);
1337a84e134Smrgstatic Widget SetErrCnxt(Widget, XIM);
1347a84e134Smrgstatic XawVendorShellExtPart *SetExtPart(VendorShellWidget,
1357a84e134Smrg					 XawVendorShellExtWidget);
1367a84e134Smrgstatic void SetFocus(Widget, XawVendorShellExtPart*);
1377a84e134Smrgstatic void SetFocusValues(Widget, ArgList, Cardinal, Bool);
1387a84e134Smrgstatic void SetICFocus(Widget, XawVendorShellExtPart*);
1397a84e134Smrgstatic void SetICValues(Widget, XawVendorShellExtPart*, Bool);
1407a84e134Smrgstatic void SetICValuesShared(Widget, XawVendorShellExtPart*, XawIcTableList,
1417a84e134Smrg			      Bool);
1427a84e134Smrgstatic void SetValues(Widget, XawVendorShellExtPart*, ArgList, Cardinal);
1437a84e134Smrgstatic unsigned int SetVendorShellHeight(XawVendorShellExtPart*,
1447a84e134Smrg					 unsigned int);
1457a84e134Smrgstatic void SharedICChangeFocusWindow(Widget, XawVendorShellExtPart*,
1467a84e134Smrg				      XawIcTableList);
1477a84e134Smrgstatic void SizeNegotiation(XawIcTableList, unsigned int, unsigned int);
1487a84e134Smrgstatic void Unregister(Widget, XawVendorShellExtPart*);
1497a84e134Smrgstatic void UnregisterFromVendorShell(Widget, XawVendorShellExtPart*);
1507a84e134Smrgstatic void UnsetFocus(Widget);
1517a84e134Smrgstatic void UnsetICFocus(Widget, XawVendorShellExtPart*);
1527a84e134Smrgstatic void VendorShellDestroyed(Widget, XtPointer, XtPointer);
1537a84e134Smrg
1547a84e134Smrg/*
1557a84e134Smrg * From Vendor.c
1567a84e134Smrg */
1577a84e134Smrgvoid XawVendorShellExtResize(Widget);
1587a84e134Smrgvoid XawVendorStructureNotifyHandler(Widget, XtPointer, XEvent*, Boolean*);
1597a84e134Smrg
1607a84e134Smrg
1617a84e134Smrg/*
1627a84e134Smrg * From Xt/Resources.c
1637a84e134Smrg */
1647a84e134Smrgvoid _XtCopyFromArg(XtArgVal src, char*, unsigned int);
1657a84e134Smrg
1667a84e134Smrgstatic XtResource resources[] =
1677a84e134Smrg{
1687a84e134Smrg    {
1697a84e134Smrg	XtNfontSet, XtCFontSet, XtRFontSet, sizeof(XFontSet),
1705ec34c4cSmrg	Offset (font_set), XtRString, (XtPointer)XtDefaultFontSet
1717a84e134Smrg    },
1727a84e134Smrg    {
1737a84e134Smrg	XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
1747a84e134Smrg	Offset (foreground), XtRString, (XtPointer)"XtDefaultForeground"
1757a84e134Smrg    },
1767a84e134Smrg    {
1777a84e134Smrg	XtNbackground, XtCBackground, XtRPixel, sizeof(Pixel),
1787a84e134Smrg	Offset (background), XtRString, (XtPointer)"XtDefaultBackground"
1797a84e134Smrg    },
1807a84e134Smrg    {
1817a84e134Smrg	XtNbackgroundPixmap, XtCPixmap, XtRPixmap, sizeof(Pixmap),
1827a84e134Smrg	Offset (bg_pixmap), XtRImmediate, (XtPointer) XtUnspecifiedPixmap
1837a84e134Smrg    },
1847a84e134Smrg    {
1857a84e134Smrg	XtNinsertPosition, XtCTextPosition, XtRInt, sizeof (XawTextPosition),
1867a84e134Smrg	Offset (cursor_position), XtRImmediate, (XtPointer) 0
1877a84e134Smrg    }
1887a84e134Smrg};
1897a84e134Smrg#undef Offset
1907a84e134Smrg
1917a84e134Smrg
192ab902922Smrgstatic VendorShellWidget SearchVendorShell(Widget w)
1937a84e134Smrg{
1947a84e134Smrg    while(w && !XtIsShell(w)) w = XtParent(w);
1957a84e134Smrg    if (w && XtIsVendorShell(w)) return((VendorShellWidget)w);
1967a84e134Smrg    return(NULL);
1977a84e134Smrg}
1987a84e134Smrg
199421c997bSmrgstatic XContext extContext = (XContext)0;
2007a84e134Smrg
2017a84e134Smrgstatic XawVendorShellExtPart *
2027a84e134SmrgSetExtPart(VendorShellWidget w, XawVendorShellExtWidget vew)
2037a84e134Smrg{
2047a84e134Smrg    contextDataRec *contextData;
2057a84e134Smrg
206421c997bSmrg    if (extContext == (XContext)0) extContext = XUniqueContext();
2077a84e134Smrg
2087a84e134Smrg    contextData = XtNew(contextDataRec);
2097a84e134Smrg    contextData->parent = (Widget)w;
2107a84e134Smrg    contextData->ve = (Widget)vew;
2117a84e134Smrg    if (XSaveContext(XtDisplay(w), (Window)w, extContext, (char *)contextData)) {
2127a84e134Smrg	return(NULL);
2137a84e134Smrg    }
2147a84e134Smrg    return(&(vew->vendor_ext));
2157a84e134Smrg}
2167a84e134Smrg
2177a84e134Smrgstatic XawVendorShellExtPart *
2187a84e134SmrgGetExtPart(VendorShellWidget w)
2197a84e134Smrg{
2207a84e134Smrg    contextDataRec *contextData;
2217a84e134Smrg    XawVendorShellExtWidget vew;
2227a84e134Smrg
2237a84e134Smrg    if (XFindContext(XtDisplay(w), (Window)w, extContext,
2247a84e134Smrg		      (XPointer*)&contextData)) {
2257a84e134Smrg	return(NULL);
2267a84e134Smrg    }
2277a84e134Smrg    vew = (XawVendorShellExtWidget)contextData->ve;
2287a84e134Smrg    return(&(vew->vendor_ext));
2297a84e134Smrg}
2307a84e134Smrg
2317a84e134Smrgstatic Bool
2327a84e134SmrgIsSharedIC(XawVendorShellExtPart * ve)
2337a84e134Smrg{
2347a84e134Smrg    return( ve->ic.shared_ic );
2357a84e134Smrg}
2367a84e134Smrg
2377a84e134Smrgstatic XawIcTableList
2387a84e134SmrgGetIcTableShared(Widget w, XawVendorShellExtPart *ve)
2397a84e134Smrg{
2407a84e134Smrg    XawIcTableList	p;
2417a84e134Smrg
2427a84e134Smrg    for (p = ve->ic.ic_table; p; p = p->next) {
2437a84e134Smrg	if (p->widget == w) {
2447a84e134Smrg	    if (IsSharedIC(ve)) {
2457a84e134Smrg		return(ve->ic.shared_ic_table);
2467a84e134Smrg	    } else {
2477a84e134Smrg		return(p);
2487a84e134Smrg	    }
2497a84e134Smrg	}
2507a84e134Smrg    }
2517a84e134Smrg    return(NULL);
2527a84e134Smrg}
2537a84e134Smrg
2547a84e134Smrgstatic XawIcTableList
2557a84e134SmrgGetIcTable(Widget w, XawVendorShellExtPart *ve)
2567a84e134Smrg{
2577a84e134Smrg    XawIcTableList	p;
2587a84e134Smrg
2597a84e134Smrg    for (p = ve->ic.ic_table; p; p = p->next) {
2607a84e134Smrg	if (p->widget == w) {
2617a84e134Smrg	    return(p);
2627a84e134Smrg	}
2637a84e134Smrg    }
2647a84e134Smrg    return(NULL);
2657a84e134Smrg}
2667a84e134Smrg
2677a84e134Smrgstatic XIMStyle
2687a84e134SmrgGetInputStyleOfIC(XawVendorShellExtPart *ve)
2697a84e134Smrg{
2707a84e134Smrg
2717a84e134Smrg    if (!ve) return((XIMStyle)0);
2727a84e134Smrg    return(ve->ic.input_style);
2737a84e134Smrg}
2747a84e134Smrg
2757a84e134Smrg/*ARGSUSED*/
2767a84e134Smrgstatic void
2775ec34c4cSmrgConfigureCB(Widget w, XtPointer closure _X_UNUSED, XEvent *event, Boolean *unused _X_UNUSED)
2787a84e134Smrg{
2797a84e134Smrg    XawVendorShellExtPart	*ve;
2807a84e134Smrg    VendorShellWidget		vw;
2817a84e134Smrg
2827a84e134Smrg    if (event->type != ConfigureNotify) return;
2837a84e134Smrg
2847a84e134Smrg    if ((vw = SearchVendorShell(w)) == NULL) return;
2857a84e134Smrg
2867a84e134Smrg    if ((ve = GetExtPart(vw)) != NULL) {
287efbcb2bfSmrg	XawIcTableList		p;
288efbcb2bfSmrg	XVaNestedList		pe_attr;
289efbcb2bfSmrg	XRectangle		pe_area;
290efbcb2bfSmrg	XawTextMargin		*margin;
291efbcb2bfSmrg
2927a84e134Smrg        if (IsSharedIC(ve)) return;
2937a84e134Smrg	if ((ve->im.xim == NULL) ||
2947a84e134Smrg	    ((p = GetIcTableShared(w, ve)) == NULL) ||
2957a84e134Smrg	    (p->xic == NULL) || !(p->input_style & XIMPreeditPosition)) return;
2967a84e134Smrg	pe_area.x = 0;
2977a84e134Smrg        pe_area.y = 0;
2987a84e134Smrg        pe_area.width = w->core.width;
2997a84e134Smrg        pe_area.height = w->core.height;
3007a84e134Smrg	margin = &(((TextWidget)w)->text.margin);
3015ec34c4cSmrg	pe_area.x = (short)(pe_area.x + margin->left);
3025ec34c4cSmrg	pe_area.y = (short)(pe_area.y + margin->top);
3035ec34c4cSmrg	pe_area.width = (unsigned short)(pe_area.width - (margin->left + margin->right - 1));
3045ec34c4cSmrg	pe_area.height = (unsigned short)(pe_area.height - (margin->top + margin->bottom - 1));
3057a84e134Smrg
3067a84e134Smrg	pe_attr = XVaCreateNestedList(0, XNArea, &pe_area, NULL);
3077a84e134Smrg	XSetICValues(p->xic, XNPreeditAttributes, pe_attr, NULL);
3087a84e134Smrg	XtFree(pe_attr);
3097a84e134Smrg    }
3107a84e134Smrg}
3117a84e134Smrg
312421c997bSmrgstatic XContext errContext = (XContext)0;
3137a84e134Smrg
3147a84e134Smrgstatic Widget SetErrCnxt(Widget w, XIM xim)
3157a84e134Smrg{
3167a84e134Smrg    contextErrDataRec *contextErrData;
3177a84e134Smrg
318421c997bSmrg    if (errContext == (XContext)0) errContext = XUniqueContext();
3197a84e134Smrg
3207a84e134Smrg    contextErrData = XtNew(contextErrDataRec);
3217a84e134Smrg    contextErrData->widget = w;
3227a84e134Smrg    contextErrData->xim = xim;
3237a84e134Smrg    if (XSaveContext(XtDisplay(w), (Window)xim, errContext,
3247a84e134Smrg	(char *)contextErrData)) {
3257a84e134Smrg	return(NULL);
3267a84e134Smrg    }
3277a84e134Smrg    return(contextErrData->widget);
3287a84e134Smrg}
3297a84e134Smrg
3307a84e134Smrgstatic void
3317a84e134SmrgCloseIM(XawVendorShellExtPart *ve)
3327a84e134Smrg{
3337a84e134Smrg    if (ve->im.xim)
3347a84e134Smrg	XCloseIM(ve->im.xim);
3357a84e134Smrg}
3367a84e134Smrg
3377a84e134Smrgstatic unsigned int
3387a84e134SmrgSetVendorShellHeight(XawVendorShellExtPart* ve, unsigned int height)
3397a84e134Smrg{
3407a84e134Smrg    Arg			args[2];
3417a84e134Smrg    Cardinal		i = 0;
3427a84e134Smrg
3437a84e134Smrg   if (ve->im.area_height < height || height == 0) {
3447a84e134Smrg       XtSetArg(args[i], XtNheight,
3457a84e134Smrg		(ve->parent->core.height + height - ve->im.area_height));
3465ec34c4cSmrg       ve->im.area_height = (Dimension)height;
3477a84e134Smrg       XtSetValues(ve->parent, args, 1);
3487a84e134Smrg   }
3497a84e134Smrg   return(ve->im.area_height);
3507a84e134Smrg}
3517a84e134Smrg
3527a84e134Smrgstatic void
3537a84e134SmrgDestroyAllIM(XawVendorShellExtPart *ve)
3547a84e134Smrg{
3557a84e134Smrg    XawIcTableList	p;
3567a84e134Smrg    contextErrDataRec *contextErrData;
3577a84e134Smrg
3587a84e134Smrg    /*
3595b16253fSmrg     * Destroy all ICs
3607a84e134Smrg     */
3617a84e134Smrg    if (IsSharedIC(ve)) {
3627a84e134Smrg        if ((p = ve->ic.shared_ic_table) && p->xic) {
3637a84e134Smrg            DestroyIC(p->widget, ve);
3647a84e134Smrg            p->xic = NULL;
3657a84e134Smrg            p->ic_focused = FALSE;
3667a84e134Smrg        }
3677a84e134Smrg    } else {
3687a84e134Smrg	for (p = ve->ic.ic_table; p; p = p->next) {
3697a84e134Smrg	    if (p->xic == NULL) continue;
3707a84e134Smrg	    DestroyIC(p->widget, ve);
3717a84e134Smrg	    p->xic = NULL;
3727a84e134Smrg	    p->ic_focused = FALSE;
3737a84e134Smrg	}
3747a84e134Smrg    }
3757a84e134Smrg    if (!ve->im.xim) return;
3767a84e134Smrg    /*
3777a84e134Smrg     * Close Input Method
3787a84e134Smrg     */
3797a84e134Smrg    if (!XFindContext(XDisplayOfIM(ve->im.xim), (Window)ve->im.xim, errContext,
3807a84e134Smrg		      (XPointer*)&contextErrData)) {
3817a84e134Smrg	if (contextErrData) XtFree((char *)contextErrData);
3827a84e134Smrg    }
3837a84e134Smrg    XDeleteContext(XDisplayOfIM(ve->im.xim), (Window)ve->im.xim, errContext);
3847a84e134Smrg    CloseIM(ve);
3857a84e134Smrg    ve->im.xim = NULL;
3867a84e134Smrg
3877a84e134Smrg    /*
3887a84e134Smrg     * resize vendor shell to core size
3897a84e134Smrg     */
3907a84e134Smrg    (void) SetVendorShellHeight(ve, 0);
3917a84e134Smrg    /*
3927a84e134Smrg    XawVendorShellExtResize(vw);
3937a84e134Smrg    */
3947a84e134Smrg    return;
3957a84e134Smrg}
3967a84e134Smrg
3977a84e134Smrgstatic void
3987a84e134SmrgFreeAllDataOfVendorShell(XawVendorShellExtPart *ve, VendorShellWidget vw)
3997a84e134Smrg{
4007a84e134Smrg    XawIcTableList       p, next;
4017a84e134Smrg    contextErrDataRec *contextErrData;
4027a84e134Smrg
4037a84e134Smrg    if (!XFindContext(XtDisplay(vw), (Window)vw, extContext,
4047a84e134Smrg		      (XPointer*)&contextErrData)) {
4057a84e134Smrg	if (contextErrData) XtFree((char *)contextErrData);
4067a84e134Smrg    }
4077a84e134Smrg    XDeleteContext(XtDisplay(vw), (Window)vw, extContext);
4087a84e134Smrg    if (ve->ic.shared_ic_table)
4097a84e134Smrg        XtFree((char *)ve->ic.shared_ic_table);
4107a84e134Smrg    if (ve->im.resources) XtFree((char *)ve->im.resources);
4117a84e134Smrg    for (p = ve->ic.ic_table; p; p = next) {
4127a84e134Smrg        next = p->next;
4137a84e134Smrg        XtFree((char *)p);
4147a84e134Smrg    }
4157a84e134Smrg}
4167a84e134Smrg
4177a84e134Smrgstatic void
4185ec34c4cSmrgVendorShellDestroyed(Widget w, XtPointer cl_data _X_UNUSED, XtPointer ca_data _X_UNUSED)
4197a84e134Smrg{
4207a84e134Smrg    XawVendorShellExtPart	*ve;
4217a84e134Smrg
4227a84e134Smrg    if ( ( ve = GetExtPart( (VendorShellWidget) w ) ) == NULL ) return;
4237a84e134Smrg    DestroyAllIM( ve );
4247a84e134Smrg    FreeAllDataOfVendorShell( ve, (VendorShellWidget) w );
4257a84e134Smrg    return;
4267a84e134Smrg}
4277a84e134Smrg
4287a84e134Smrg/*
4297a84e134Smrg * Attempt to open an input method
4307a84e134Smrg */
4317a84e134Smrgstatic void
4327a84e134SmrgOpenIM(XawVendorShellExtPart *ve)
4337a84e134Smrg{
4347a84e134Smrg    int		i;
4355ec34c4cSmrg    _Xconst char *s, *ns, *end;
436efbcb2bfSmrg    char	*p, buf[32];
4377a84e134Smrg    XIM		xim = NULL;
4387a84e134Smrg    XIMStyles	*xim_styles;
4397a84e134Smrg    XIMStyle	input_style = 0;
4407a84e134Smrg    Boolean	found;
4417a84e134Smrg
4427a84e134Smrg    if (ve->im.open_im == False) return;
4437a84e134Smrg    ve->im.xim = NULL;
4447a84e134Smrg    if (ve->im.input_method == NULL) {
4457a84e134Smrg	if ((p = XSetLocaleModifiers("@im=none")) != NULL && *p)
4467a84e134Smrg	    xim = XOpenIM(XtDisplay(ve->parent), NULL, NULL, NULL);
4477a84e134Smrg    } else {
448efbcb2bfSmrg	char	*pbuf;
449efbcb2bfSmrg
4507a84e134Smrg	/* no fragment can be longer than the whole string */
4515ec34c4cSmrg	Cardinal len = (Cardinal)strlen (ve->im.input_method) + 5;
4527a84e134Smrg
4537a84e134Smrg	if (len < sizeof buf) pbuf = buf;
4547a84e134Smrg	else pbuf = XtMalloc (len);
4557a84e134Smrg
4567a84e134Smrg	if (pbuf == NULL) return;
4577a84e134Smrg
4587a84e134Smrg	for(ns=s=ve->im.input_method; ns && *s;) {
4597a84e134Smrg	    /* skip any leading blanks */
4605b16253fSmrg	    while (*s && isspace((unsigned char)*s)) s++;
4617a84e134Smrg	    if (!*s) break;
4627a84e134Smrg	    if ((ns = end = strchr(s, ',')) == NULL)
4637a84e134Smrg		end = s + strlen(s);
4647a84e134Smrg	    /* If there is a spurious comma end can be the same as s */
4657a84e134Smrg	    if (end > s) {
4667a84e134Smrg		/* strip any trailing blanks */
4675b16253fSmrg		while (isspace((unsigned char)*(end - 1))) end--;
4687a84e134Smrg
4697a84e134Smrg		strcpy (pbuf, "@im=");
4705ec34c4cSmrg		strncat (pbuf, s, (size_t)(end - s));
4717a84e134Smrg		pbuf[end - s + 4] = '\0';
4727a84e134Smrg	    }
4737a84e134Smrg
4747a84e134Smrg	    if ((p = XSetLocaleModifiers(pbuf)) != NULL && *p
4757a84e134Smrg		&& (xim = XOpenIM(XtDisplay(ve->parent), NULL, NULL, NULL)) != NULL)
4767a84e134Smrg		break;
4777a84e134Smrg
4787a84e134Smrg	    s = ns + 1;
4797a84e134Smrg	}
4807a84e134Smrg
4817a84e134Smrg	if (pbuf != buf) XtFree (pbuf);
4827a84e134Smrg    }
4837a84e134Smrg    if (xim == NULL) {
484efbcb2bfSmrg	if (XSetLocaleModifiers("") != NULL) {
4857a84e134Smrg	    xim = XOpenIM(XtDisplay(ve->parent), NULL, NULL, NULL);
4867a84e134Smrg	}
4877a84e134Smrg    }
4887a84e134Smrg    if (xim == NULL) {
4897a84e134Smrg	XtAppWarning(XtWidgetToApplicationContext(ve->parent),
4907a84e134Smrg	    "Input Method Open Failed");
4917a84e134Smrg	return;
4927a84e134Smrg    }
4937a84e134Smrg    if (XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL)
4947a84e134Smrg	|| !xim_styles) {
495421c997bSmrg	XtAppWarning(XtWidgetToApplicationContext(ve->parent),
4967a84e134Smrg	    "input method doesn't support any style");
4977a84e134Smrg	XCloseIM(xim);
4987a84e134Smrg	return;
4997a84e134Smrg    }
5007a84e134Smrg    found = False;
501efbcb2bfSmrg    for (s = ve->im.preedit_type; s && !found;) {
5025b16253fSmrg	while (*s && isspace((unsigned char)*s)) s++;
5037a84e134Smrg	if (!*s) break;
5047a84e134Smrg	if ((ns = end = strchr(s, ',')) == NULL)
5057a84e134Smrg	    end = s + strlen(s);
5067a84e134Smrg	else
5077a84e134Smrg	    ns++;
5087a84e134Smrg	if (end > s)
5095b16253fSmrg	    while (isspace((unsigned char)*(end - 1))) end--;
5107a84e134Smrg
5115ec34c4cSmrg	if (!strncmp(s, "OverTheSpot", (size_t)(end - s))) {
5127a84e134Smrg	    input_style = (XIMPreeditPosition | XIMStatusArea);
5135ec34c4cSmrg	} else if (!strncmp(s, "OffTheSpot", (size_t)(end - s))) {
5147a84e134Smrg	    input_style = (XIMPreeditArea | XIMStatusArea);
5155ec34c4cSmrg	} else if (!strncmp(s, "Root", (size_t)(end - s))) {
5167a84e134Smrg	    input_style = (XIMPreeditNothing | XIMStatusNothing);
5177a84e134Smrg	}
5187a84e134Smrg	for (i = 0; (unsigned short)i < xim_styles->count_styles; i++)
5197a84e134Smrg	    if (input_style == xim_styles->supported_styles[i]) {
5207a84e134Smrg		ve->ic.input_style = input_style;
5217a84e134Smrg		SetErrCnxt(ve->parent, xim);
5227a84e134Smrg		ve->im.xim = xim;
5237a84e134Smrg		found = True;
5247a84e134Smrg		break;
5257a84e134Smrg	    }
5267a84e134Smrg
5277a84e134Smrg	s = ns;
5287a84e134Smrg    }
5297a84e134Smrg    XFree(xim_styles);
5307a84e134Smrg
5317a84e134Smrg    if (!found) {
5327a84e134Smrg	XCloseIM(xim);
5337a84e134Smrg	XtAppWarning(XtWidgetToApplicationContext(ve->parent),
5347a84e134Smrg		     "input method doesn't support my input style");
5357a84e134Smrg    }
5367a84e134Smrg}
5377a84e134Smrg
5387a84e134Smrgstatic Bool
5397a84e134SmrgResizeVendorShell_Core(VendorShellWidget vw, XawVendorShellExtPart *ve,
5407a84e134Smrg		       XawIcTableList p)
5417a84e134Smrg{
5427a84e134Smrg    XVaNestedList		pe_attr, st_attr;
5437a84e134Smrg    XRectangle			pe_area, st_area;
5447a84e134Smrg    XRectangle			*get_pe_area = NULL, *get_st_area = NULL;
5457a84e134Smrg
5467a84e134Smrg    st_area.width = 0;
5477a84e134Smrg    if (p->input_style & XIMStatusArea) {
5487a84e134Smrg	st_attr = XVaCreateNestedList(0, XNArea, &get_st_area, NULL);
5497a84e134Smrg	XGetICValues(p->xic, XNStatusAttributes, st_attr, NULL);
5507a84e134Smrg	XFree(st_attr);
5517a84e134Smrg	if (p->xic == NULL) {
5527a84e134Smrg	    return(FALSE);
5537a84e134Smrg	}
5547a84e134Smrg	st_area.x = 0;
5555ec34c4cSmrg	st_area.y = (short)(vw->core.height - ve->im.area_height);
5567a84e134Smrg	st_area.width = get_st_area->width;
5577a84e134Smrg	st_area.height = get_st_area->height;
5587a84e134Smrg	XFree(get_st_area);
5597a84e134Smrg	st_attr = XVaCreateNestedList(0, XNArea, &st_area, NULL);
5607a84e134Smrg	XSetICValues(p->xic, XNStatusAttributes, st_attr, NULL);
5617a84e134Smrg	XFree(st_attr);
5627a84e134Smrg	if (p->xic == NULL) {
5637a84e134Smrg	    return(FALSE);
5647a84e134Smrg	}
5657a84e134Smrg    }
5667a84e134Smrg    if (p->input_style & XIMPreeditArea) {
5677a84e134Smrg	pe_attr = XVaCreateNestedList(0, XNArea, &get_pe_area, NULL);
5687a84e134Smrg	XGetICValues(p->xic, XNPreeditAttributes, pe_attr, NULL);
5697a84e134Smrg	XFree(pe_attr);
5707a84e134Smrg	if (p->xic == NULL) {
5717a84e134Smrg	    return(FALSE);
5727a84e134Smrg	}
5735ec34c4cSmrg	pe_area.x = (short)st_area.width;
5745ec34c4cSmrg	pe_area.y = (short)(vw->core.height - ve->im.area_height);
5757a84e134Smrg	pe_area.width = vw->core.width;
5767a84e134Smrg	pe_area.height = get_pe_area->height;
5777a84e134Smrg	if (p->input_style & XIMStatusArea) {
5785ec34c4cSmrg	    pe_area.width = (unsigned short)(pe_area.width - st_area.width);
5797a84e134Smrg	}
5807a84e134Smrg	XFree(get_pe_area);
5817a84e134Smrg	pe_attr = XVaCreateNestedList(0, XNArea, &pe_area, NULL);
5827a84e134Smrg	XSetICValues(p->xic, XNPreeditAttributes, pe_attr, NULL);
5837a84e134Smrg	XFree(pe_attr);
5847a84e134Smrg    }
5857a84e134Smrg    return(TRUE);
5867a84e134Smrg}
5877a84e134Smrg
5887a84e134Smrgstatic void
5897a84e134SmrgResizeVendorShell(VendorShellWidget vw, XawVendorShellExtPart *ve)
5907a84e134Smrg{
5917a84e134Smrg    XawIcTableList               p;
5927a84e134Smrg
5937a84e134Smrg    if (IsSharedIC(ve)) {
5947a84e134Smrg	p = ve->ic.shared_ic_table;
5957a84e134Smrg	if (p->xic == NULL) return;
5967a84e134Smrg	ResizeVendorShell_Core(vw, ve, p);
5977a84e134Smrg	return;
5987a84e134Smrg    }
5997a84e134Smrg    for (p = ve->ic.ic_table; p; p = p->next) {
6007a84e134Smrg	if (p->xic == NULL) continue;
6017a84e134Smrg	if (ResizeVendorShell_Core(vw, ve, p) == FALSE) return;
6027a84e134Smrg    }
6037a84e134Smrg}
6047a84e134Smrg
6057a84e134Smrgstatic XawIcTableList
6065ec34c4cSmrgCreateIcTable(Widget w, XawVendorShellExtPart *ve _X_UNUSED)
6077a84e134Smrg{
6087a84e134Smrg    XawIcTableList	table;
6097a84e134Smrg
6107a84e134Smrg    table = (XawIcTableList) XtMalloc(sizeof(XawIcTablePart));
6117a84e134Smrg    if (table == NULL) return(NULL);
6127a84e134Smrg    table->widget = w;
6137a84e134Smrg    table->xic = NULL;
6147a84e134Smrg    table->flg = table->prev_flg = 0;
6157a84e134Smrg    table->font_set = NULL;
6167a84e134Smrg    table->foreground = table->background = 0xffffffff;
6177a84e134Smrg    table->bg_pixmap = 0;
6187a84e134Smrg    table->cursor_position = 0xffff;
6197a84e134Smrg    table->line_spacing = 0;
6207a84e134Smrg    table->ic_focused = FALSE;
6217a84e134Smrg    table->openic_error = FALSE;
6227a84e134Smrg    return(table);
6237a84e134Smrg}
6247a84e134Smrg
6257a84e134Smrgstatic Bool
6267a84e134SmrgRegisterToVendorShell(Widget w, XawVendorShellExtPart *ve)
6277a84e134Smrg{
6287a84e134Smrg    XawIcTableList	table;
6297a84e134Smrg
6307a84e134Smrg    if ((table = CreateIcTable(w, ve)) == NULL) return(FALSE);
6317a84e134Smrg    table->next = ve->ic.ic_table;
6327a84e134Smrg    ve->ic.ic_table = table;
6337a84e134Smrg    return(TRUE);
6347a84e134Smrg}
6357a84e134Smrg
6367a84e134Smrgstatic void
6377a84e134SmrgUnregisterFromVendorShell(Widget w, XawVendorShellExtPart *ve)
6387a84e134Smrg{
6397a84e134Smrg    XawIcTableList	*prev, p;
6407a84e134Smrg
6417a84e134Smrg    for (prev = &ve->ic.ic_table; (p = *prev) != NULL; prev = &p->next) {
6427a84e134Smrg	if (p->widget == w) {
6437a84e134Smrg	    *prev = p->next;
6447a84e134Smrg	    XtFree((char *)p);
6457a84e134Smrg	    break;
6467a84e134Smrg	}
6477a84e134Smrg    }
6487a84e134Smrg    return;
6497a84e134Smrg}
6507a84e134Smrg
6517a84e134Smrgstatic void
6527a84e134SmrgSetICValuesShared(Widget w, XawVendorShellExtPart *ve,
6537a84e134Smrg		  XawIcTableList p, Bool check)
6547a84e134Smrg{
6557a84e134Smrg    XawIcTableList	pp;
6567a84e134Smrg
6577a84e134Smrg    if ((pp = GetIcTable(w, ve)) == NULL) return;
6587a84e134Smrg    if (check == TRUE && CurrentSharedIcTable(ve) != pp) return;
6597a84e134Smrg
6607a84e134Smrg    if (pp->prev_flg & CICursorP && p->cursor_position != pp->cursor_position) {
6617a84e134Smrg	p->cursor_position = pp->cursor_position;
6627a84e134Smrg	p->flg |= CICursorP;
6637a84e134Smrg    }
6647a84e134Smrg    if (pp->prev_flg & CIFontSet && p->font_set != pp->font_set) {
6657a84e134Smrg	p->font_set = pp->font_set;
6667a84e134Smrg	p->flg |= (CIFontSet|CICursorP);
6677a84e134Smrg    }
6687a84e134Smrg    if (pp->prev_flg & CIFg && p->foreground != pp->foreground) {
6697a84e134Smrg	p->foreground = pp->foreground;
6707a84e134Smrg	p->flg |= CIFg;
6717a84e134Smrg    }
6727a84e134Smrg    if (pp->prev_flg & CIBg && p->background != pp->background) {
6737a84e134Smrg	p->background = pp->background;
6747a84e134Smrg	p->flg |= CIBg;
6757a84e134Smrg    }
6767a84e134Smrg    if (pp->prev_flg & CIBgPixmap && p->bg_pixmap != pp->bg_pixmap) {
6777a84e134Smrg	p->bg_pixmap = pp->bg_pixmap;
6787a84e134Smrg	p->flg |= CIBgPixmap;
6797a84e134Smrg    }
6807a84e134Smrg    if (pp->prev_flg & CILineS && p->line_spacing != pp->line_spacing) {
6817a84e134Smrg	p->line_spacing = pp->line_spacing;
6827a84e134Smrg	p->flg |= CILineS;
6837a84e134Smrg    }
6847a84e134Smrg}
6857a84e134Smrg
6867a84e134Smrgstatic Bool
6877a84e134SmrgIsCreatedIC(Widget w, XawVendorShellExtPart *ve)
6887a84e134Smrg{
6897a84e134Smrg    XawIcTableList	p;
6907a84e134Smrg
6917a84e134Smrg    if (ve->im.xim == NULL) return(FALSE);
6927a84e134Smrg    if ((p = GetIcTableShared(w, ve)) == NULL) return(FALSE);
6937a84e134Smrg    if (p->xic == NULL) return(FALSE);
6947a84e134Smrg    return(TRUE);
6957a84e134Smrg}
6967a84e134Smrg
6977a84e134Smrgstatic void
6987a84e134SmrgSizeNegotiation(XawIcTableList p, unsigned int width, unsigned int height)
6997a84e134Smrg{
7007a84e134Smrg    XRectangle		pe_area, st_area;
7017a84e134Smrg    XVaNestedList	pe_attr = NULL, st_attr = NULL;
7027a84e134Smrg    int			ic_cnt = 0;
7037a84e134Smrg    XRectangle		*pe_area_needed = NULL, *st_area_needed = NULL;
7047a84e134Smrg    XPointer		ic_a[5];
7057a84e134Smrg
7067a84e134Smrg    if (p->input_style & XIMPreeditArea) {
7077a84e134Smrg	pe_attr = XVaCreateNestedList(0, XNAreaNeeded, &pe_area_needed, NULL);
708efbcb2bfSmrg	ADD_IC(XNPreeditAttributes);
709efbcb2bfSmrg	ADD_IC(pe_attr);
7107a84e134Smrg    }
7117a84e134Smrg    if (p->input_style & XIMStatusArea) {
7127a84e134Smrg	st_attr = XVaCreateNestedList(0, XNAreaNeeded, &st_area_needed, NULL);
713efbcb2bfSmrg	ADD_IC(XNStatusAttributes);
714efbcb2bfSmrg	ADD_IC(st_attr);
7157a84e134Smrg    }
716efbcb2bfSmrg    END_IC();
7177a84e134Smrg
7187a84e134Smrg    if (ic_cnt > 0) {
719efbcb2bfSmrg	XGetICValues(p->xic, USE_IC(0), USE_IC(1), USE_IC(2), USE_IC(3), NULL);
7207a84e134Smrg	if (pe_attr) XFree(pe_attr);
7217a84e134Smrg	if (st_attr) XFree(st_attr);
7227a84e134Smrg	if (p->xic == NULL) {
7237a84e134Smrg	    p->openic_error = True;
7247a84e134Smrg	    return;
7257a84e134Smrg	}
7267a84e134Smrg	pe_attr = st_attr = NULL;
7277a84e134Smrg	ic_cnt = 0;
7287a84e134Smrg	if (p->input_style & XIMStatusArea) {
7297a84e134Smrg	    st_area.height = st_area_needed->height;
7307a84e134Smrg	    st_area.x = 0;
7315ec34c4cSmrg	    st_area.y = (short)(height - st_area.height);
7327a84e134Smrg	    if (p->input_style & XIMPreeditArea) {
7337a84e134Smrg		st_area.width = st_area_needed->width;
7347a84e134Smrg	    } else {
7355ec34c4cSmrg		st_area.width = (unsigned short)width;
7367a84e134Smrg	    }
7377a84e134Smrg
7387a84e134Smrg	    XFree(st_area_needed);
7397a84e134Smrg	    st_attr = XVaCreateNestedList(0, XNArea, &st_area, NULL);
740efbcb2bfSmrg	    ADD_IC(XNStatusAttributes);
741efbcb2bfSmrg	    ADD_IC(st_attr);
7427a84e134Smrg	}
7437a84e134Smrg	if (p->input_style & XIMPreeditArea) {
7447a84e134Smrg	    if (p->input_style & XIMStatusArea) {
7455ec34c4cSmrg		pe_area.x = (short)st_area.width;
7465ec34c4cSmrg		pe_area.width = (unsigned short)(width - st_area.width);
7477a84e134Smrg	    } else {
7487a84e134Smrg		pe_area.x = 0;
7495ec34c4cSmrg		pe_area.width = (unsigned short)width;
7507a84e134Smrg	    }
7517a84e134Smrg	    pe_area.height = pe_area_needed->height;
7527a84e134Smrg	    XFree(pe_area_needed);
7535ec34c4cSmrg	    pe_area.y = (short)(height - pe_area.height);
7547a84e134Smrg	    pe_attr = XVaCreateNestedList(0, XNArea, &pe_area, NULL);
755efbcb2bfSmrg	    ADD_IC(XNPreeditAttributes);
756efbcb2bfSmrg	    ADD_IC(pe_attr);
7577a84e134Smrg	}
758efbcb2bfSmrg	END_IC();
759efbcb2bfSmrg	XSetICValues(p->xic, USE_IC(0), USE_IC(1), USE_IC(2), USE_IC(3), NULL);
7607a84e134Smrg	if (pe_attr) XFree(pe_attr);
7617a84e134Smrg	if (st_attr) XFree(st_attr);
7627a84e134Smrg	if (p->xic == NULL) {
7637a84e134Smrg	    p->openic_error = True;
7647a84e134Smrg	    return;
7657a84e134Smrg	}
7667a84e134Smrg    }
7677a84e134Smrg}
7687a84e134Smrg
7697a84e134Smrgstatic void
7707a84e134SmrgCreateIC(Widget w, XawVendorShellExtPart *ve)
7717a84e134Smrg{
7727a84e134Smrg    XawIcTableList	p;
7737a84e134Smrg    XPoint		position;
7747a84e134Smrg    XRectangle		pe_area, st_area;
7757a84e134Smrg    XVaNestedList	pe_attr = NULL, st_attr = NULL;
7767a84e134Smrg    XPointer		ic_a[20], pe_a[20], st_a[20];
7777a84e134Smrg    Dimension		height = 0;
7787a84e134Smrg    int			ic_cnt = 0, pe_cnt = 0, st_cnt = 0;
7797a84e134Smrg
7807a84e134Smrg    if (!XtIsRealized(w)) return;
7817a84e134Smrg    if (((ve->im.xim == NULL) || (p = GetIcTableShared(w, ve)) == NULL) ||
7827a84e134Smrg	p->xic || (p->openic_error != FALSE)) return;
7837a84e134Smrg
7847a84e134Smrg    p->input_style = GetInputStyleOfIC(ve);
7857a84e134Smrg
7867a84e134Smrg    if (IsSharedIC(ve)) SetICValuesShared(w, ve, p, FALSE);
7877a84e134Smrg    XFlush(XtDisplay(w));
788421c997bSmrg
7897a84e134Smrg    if (p->input_style & (XIMPreeditArea|XIMPreeditPosition|XIMStatusArea)) {
7907a84e134Smrg	if (p->flg & CIFontSet) {
791efbcb2bfSmrg	    ADD_PE(XNFontSet);
792efbcb2bfSmrg	    ADD_PE(p->font_set);
793efbcb2bfSmrg	    ADD_ST(XNFontSet);
794efbcb2bfSmrg	    ADD_ST(p->font_set);
7957a84e134Smrg	    if (p->font_set) {
7965ec34c4cSmrg		height = (Dimension)(maxAscentOfFontSet(p->font_set)
7975ec34c4cSmrg				     + maxDescentOfFontSet(p->font_set));
7987a84e134Smrg	    }
7995ec34c4cSmrg	    height = (Dimension)SetVendorShellHeight(ve, height);
8007a84e134Smrg	}
8017a84e134Smrg	if (p->flg & CIFg) {
802efbcb2bfSmrg	    ADD_PE(XNForeground);
803efbcb2bfSmrg	    ADD_PE(p->foreground);
804efbcb2bfSmrg	    ADD_ST(XNForeground);
805efbcb2bfSmrg	    ADD_ST(p->foreground);
8067a84e134Smrg	}
8077a84e134Smrg	if (p->flg & CIBg) {
808efbcb2bfSmrg	    ADD_PE(XNBackground);
809efbcb2bfSmrg	    ADD_PE(p->background);
810efbcb2bfSmrg	    ADD_ST(XNBackground);
811efbcb2bfSmrg	    ADD_ST(p->background);
8127a84e134Smrg	}
8137a84e134Smrg	if (p->flg & CIBgPixmap) {
814efbcb2bfSmrg	    ADD_PE(XNBackgroundPixmap);
815efbcb2bfSmrg	    ADD_PE(p->bg_pixmap);
816efbcb2bfSmrg	    ADD_ST(XNBackgroundPixmap);
817efbcb2bfSmrg	    ADD_ST(p->bg_pixmap);
8187a84e134Smrg	}
8197a84e134Smrg	if (p->flg & CILineS) {
820efbcb2bfSmrg	    ADD_PE(XNLineSpace);
821efbcb2bfSmrg	    ADD_PE(p->line_spacing);
822efbcb2bfSmrg	    ADD_ST(XNLineSpace);
823efbcb2bfSmrg	    ADD_ST(p->line_spacing);
8247a84e134Smrg	}
8257a84e134Smrg    }
826efbcb2bfSmrg
8277a84e134Smrg    if (p->input_style & XIMPreeditArea) {
8287a84e134Smrg	pe_area.x = 0;
8295ec34c4cSmrg	pe_area.y = (short)(ve->parent->core.height - height);
8307a84e134Smrg	pe_area.width = ve->parent->core.width;
8317a84e134Smrg	pe_area.height = height;
832efbcb2bfSmrg	ADD_PE(XNArea);
833efbcb2bfSmrg	ADD_PE(&pe_area);
8347a84e134Smrg    }
835efbcb2bfSmrg
8367a84e134Smrg    if (p->input_style & XIMPreeditPosition) {
837efbcb2bfSmrg	XawTextMargin	*margin;
838efbcb2bfSmrg
8397a84e134Smrg	pe_area.x = 0;
8407a84e134Smrg	pe_area.y = 0;
8417a84e134Smrg	pe_area.width = w->core.width;
8427a84e134Smrg	pe_area.height = w->core.height;
8437a84e134Smrg	margin = &(((TextWidget)w)->text.margin);
8445ec34c4cSmrg	pe_area.x = (short)(pe_area.x + margin->left);
8455ec34c4cSmrg	pe_area.y = (short)(pe_area.y + margin->top);
8465ec34c4cSmrg	pe_area.width = (unsigned short)(pe_area.width - (margin->left + margin->right - 1));
8475ec34c4cSmrg	pe_area.height = (unsigned short)(pe_area.height - (margin->top + margin->bottom - 1));
848efbcb2bfSmrg	ADD_PE(XNArea);
849efbcb2bfSmrg	ADD_PE(&pe_area);
8507a84e134Smrg	if (p->flg & CICursorP) {
8517a84e134Smrg	    _XawMultiSinkPosToXY(w, p->cursor_position, &position.x, &position.y);
8527a84e134Smrg	} else {
8537a84e134Smrg	    position.x = position.y = 0;
8547a84e134Smrg	}
855efbcb2bfSmrg	ADD_PE(XNSpotLocation);
856efbcb2bfSmrg	ADD_PE(&position);
8577a84e134Smrg    }
8587a84e134Smrg    if (p->input_style & XIMStatusArea) {
8597a84e134Smrg	st_area.x = 0;
8605ec34c4cSmrg	st_area.y = (short)(ve->parent->core.height - height);
8617a84e134Smrg	st_area.width = ve->parent->core.width;
8627a84e134Smrg	st_area.height = height;
863efbcb2bfSmrg	ADD_ST(XNArea);
864efbcb2bfSmrg	ADD_ST(&st_area);
8657a84e134Smrg    }
8667a84e134Smrg
867efbcb2bfSmrg    ADD_IC(XNInputStyle);
868efbcb2bfSmrg    ADD_IC(p->input_style);
869efbcb2bfSmrg    ADD_IC(XNClientWindow);
870efbcb2bfSmrg    ADD_IC(XtWindow(ve->parent));
871efbcb2bfSmrg    ADD_IC(XNFocusWindow);
872efbcb2bfSmrg    ADD_IC(XtWindow(w));
8737a84e134Smrg
8747a84e134Smrg    if (pe_cnt > 0) {
875efbcb2bfSmrg	END_PE();
876efbcb2bfSmrg	pe_attr = XVaCreateNestedList(0, USE_PE(0), USE_PE(1), USE_PE(2),
877efbcb2bfSmrg				      USE_PE(3), USE_PE(4), USE_PE(5),
878efbcb2bfSmrg				      USE_PE(6), USE_PE(7), USE_PE(8),
879efbcb2bfSmrg				      USE_PE(9), USE_PE(10), USE_PE(11),
880efbcb2bfSmrg				      USE_PE(12), USE_PE(13), USE_PE(14),
881efbcb2bfSmrg				      USE_PE(15), NULL);
882efbcb2bfSmrg	ADD_IC(XNPreeditAttributes);
883efbcb2bfSmrg	ADD_IC(pe_attr);
8847a84e134Smrg    }
8857a84e134Smrg
8867a84e134Smrg    if (st_cnt > 0) {
887efbcb2bfSmrg	END_ST();
888efbcb2bfSmrg	st_attr = XVaCreateNestedList(0, USE_ST(0), USE_ST(1), USE_ST(2),
889efbcb2bfSmrg				      USE_ST(3), USE_ST(4), USE_ST(5),
890efbcb2bfSmrg				      USE_ST(6), USE_ST(7), USE_ST(8),
891efbcb2bfSmrg				      USE_ST(9), USE_ST(10), USE_ST(11), NULL);
892efbcb2bfSmrg	ADD_IC(XNStatusAttributes);
893efbcb2bfSmrg	ADD_IC(st_attr);
894efbcb2bfSmrg    }
895efbcb2bfSmrg    END_IC();
896efbcb2bfSmrg
897efbcb2bfSmrg    p->xic = XCreateIC(ve->im.xim, USE_IC(0), USE_IC(1), USE_IC(2), USE_IC(3),
898efbcb2bfSmrg		       USE_IC(4), USE_IC(5), USE_IC(6), USE_IC(7), USE_IC(8),
899efbcb2bfSmrg		       USE_IC(9), NULL);
9007a84e134Smrg    if (pe_attr) XtFree(pe_attr);
9017a84e134Smrg    if (st_attr) XtFree(st_attr);
9027a84e134Smrg
9037a84e134Smrg    if (p->xic == NULL) {
9047a84e134Smrg	p->openic_error = True;
9057a84e134Smrg	return;
9067a84e134Smrg    }
9077a84e134Smrg
9087a84e134Smrg    SizeNegotiation(p, ve->parent->core.width, ve->parent->core.height);
9097a84e134Smrg
9105ec34c4cSmrg    p->flg &= (unsigned long)(~(CIFontSet | CIFg | CIBg | CIBgPixmap | CICursorP | CILineS));
9117a84e134Smrg
9127a84e134Smrg    if (!IsSharedIC(ve)) {
9137a84e134Smrg	if (p->input_style & XIMPreeditPosition) {
9147a84e134Smrg	    XtAddEventHandler(w, (EventMask)StructureNotifyMask, FALSE,
9157a84e134Smrg			      (XtEventHandler)ConfigureCB, (Opaque)NULL);
9167a84e134Smrg	}
9177a84e134Smrg    }
9187a84e134Smrg}
9197a84e134Smrg
9207a84e134Smrgstatic void
9217a84e134SmrgSetICValues(Widget w, XawVendorShellExtPart *ve, Bool focus)
9227a84e134Smrg{
9237a84e134Smrg    XawIcTableList	p;
9247a84e134Smrg    XPoint		position;
9257a84e134Smrg    XRectangle		pe_area;
9267a84e134Smrg    XVaNestedList	pe_attr = NULL, st_attr = NULL;
9277a84e134Smrg    XPointer		ic_a[20], pe_a[20], st_a[20];
9287a84e134Smrg    int			ic_cnt = 0, pe_cnt = 0, st_cnt = 0;
9297a84e134Smrg    XawTextMargin	*margin;
9307a84e134Smrg    int			height = 0;
9317a84e134Smrg
9327a84e134Smrg    if ((ve->im.xim == NULL) || ((p = GetIcTableShared(w, ve)) == NULL) ||
9337a84e134Smrg	(p->xic == NULL)) return;
9347a84e134Smrg
9357a84e134Smrg    if (IsSharedIC(ve)) SetICValuesShared(w, ve, p, TRUE);
9367a84e134Smrg    XFlush(XtDisplay(w));
9377a84e134Smrg    if (focus == FALSE &&
9387a84e134Smrg	!(p->flg & (CIFontSet | CIFg | CIBg |
9397a84e134Smrg		    CIBgPixmap | CICursorP | CILineS))) return;
9407a84e134Smrg#ifdef SPOT
9417a84e134Smrg    if ((p->input_style & XIMPreeditPosition)
9427a84e134Smrg	&& ((!IsSharedIC(ve) && ((p->flg & ~CIICFocus) == CICursorP))
9437a84e134Smrg	    || (IsSharedIC(ve) && p->flg == CICursorP))) {
9447a84e134Smrg	_XawMultiSinkPosToXY(w, p->cursor_position, &position.x, &position.y);
9457a84e134Smrg	_XipChangeSpot(p->xic, position.x, position.y);
9467a84e134Smrg	p->flg &= ~CICursorP;
9477a84e134Smrg	return;
9487a84e134Smrg    }
9497a84e134Smrg#endif
9507a84e134Smrg
9517a84e134Smrg    if (p->input_style & (XIMPreeditArea|XIMPreeditPosition|XIMStatusArea)) {
9527a84e134Smrg	if (p->flg & CIFontSet) {
953efbcb2bfSmrg	    ADD_PE(XNFontSet);
954efbcb2bfSmrg	    ADD_PE(p->font_set);
955efbcb2bfSmrg	    ADD_ST(XNFontSet);
956efbcb2bfSmrg	    ADD_ST(p->font_set);
9577a84e134Smrg	    if (p->font_set) {
9587a84e134Smrg		height = maxAscentOfFontSet(p->font_set)
959efbcb2bfSmrg		       + maxDescentOfFontSet(p->font_set);
9607a84e134Smrg	    }
961efbcb2bfSmrg	    SetVendorShellHeight(ve, (unsigned)height);
9627a84e134Smrg	}
9637a84e134Smrg	if (p->flg & CIFg) {
964efbcb2bfSmrg	    ADD_PE(XNForeground);
965efbcb2bfSmrg	    ADD_PE(p->foreground);
966efbcb2bfSmrg	    ADD_ST(XNForeground);
967efbcb2bfSmrg	    ADD_ST(p->foreground);
9687a84e134Smrg	}
9697a84e134Smrg	if (p->flg & CIBg) {
970efbcb2bfSmrg	    ADD_PE(XNBackground);
971efbcb2bfSmrg	    ADD_PE(p->background);
972efbcb2bfSmrg	    ADD_ST(XNBackground);
973efbcb2bfSmrg	    ADD_ST(p->background);
9747a84e134Smrg	}
9757a84e134Smrg	if (p->flg & CIBgPixmap) {
976efbcb2bfSmrg	    ADD_PE(XNBackgroundPixmap);
977efbcb2bfSmrg	    ADD_PE(p->bg_pixmap);
978efbcb2bfSmrg	    ADD_ST(XNBackgroundPixmap);
979efbcb2bfSmrg	    ADD_ST(p->bg_pixmap);
9807a84e134Smrg	}
9817a84e134Smrg	if (p->flg & CILineS) {
982efbcb2bfSmrg	    ADD_PE(XNLineSpace);
983efbcb2bfSmrg	    ADD_PE(p->line_spacing);
984efbcb2bfSmrg	    ADD_ST(XNLineSpace);
985efbcb2bfSmrg	    ADD_ST(p->line_spacing);
9867a84e134Smrg	}
9877a84e134Smrg    }
9887a84e134Smrg    if (p->input_style & XIMPreeditPosition) {
9897a84e134Smrg	if (p->flg & CICursorP) {
9907a84e134Smrg	    _XawMultiSinkPosToXY(w, p->cursor_position, &position.x, &position.y);
991efbcb2bfSmrg	    ADD_PE(XNSpotLocation);
992efbcb2bfSmrg	    ADD_PE(&position);
9937a84e134Smrg	}
9947a84e134Smrg    }
9957a84e134Smrg    if (IsSharedIC(ve)) {
9967a84e134Smrg	if (p->input_style & XIMPreeditPosition) {
9977a84e134Smrg	    pe_area.x = 0;
9987a84e134Smrg	    pe_area.y = 0;
9997a84e134Smrg	    pe_area.width = w->core.width;
10007a84e134Smrg	    pe_area.height = w->core.height;
10017a84e134Smrg	    margin = &(((TextWidget)w)->text.margin);
10025ec34c4cSmrg	    pe_area.x = (short)(pe_area.x + margin->left);
10035ec34c4cSmrg	    pe_area.y = (short)(pe_area.y + margin->top);
10045ec34c4cSmrg	    pe_area.width = (unsigned short)(pe_area.width - (margin->left + margin->right - 1));
10055ec34c4cSmrg	    pe_area.height = (unsigned short)(pe_area.height - (margin->top + margin->bottom - 1));
1006efbcb2bfSmrg	    ADD_PE(XNArea);
1007efbcb2bfSmrg	    ADD_PE(&pe_area);
10087a84e134Smrg	}
10097a84e134Smrg    }
10107a84e134Smrg
10117a84e134Smrg    if (pe_cnt > 0) {
1012efbcb2bfSmrg	END_PE();
1013efbcb2bfSmrg	pe_attr = XVaCreateNestedList(0, USE_PE(0), USE_PE(1), USE_PE(2),
1014efbcb2bfSmrg				      USE_PE(3), USE_PE(4), USE_PE(5),
1015efbcb2bfSmrg				      USE_PE(6), USE_PE(7), USE_PE(8),
1016efbcb2bfSmrg				      USE_PE(9), USE_PE(10), USE_PE(11),
1017efbcb2bfSmrg				      USE_PE(12), USE_PE(13), NULL);
1018efbcb2bfSmrg	ADD_IC(XNPreeditAttributes);
1019efbcb2bfSmrg	ADD_IC(pe_attr);
10207a84e134Smrg    }
10217a84e134Smrg    if (st_cnt > 0) {
1022efbcb2bfSmrg	END_ST();
1023efbcb2bfSmrg	st_attr = XVaCreateNestedList(0, USE_ST(0), USE_ST(1), USE_ST(2),
1024efbcb2bfSmrg				      USE_ST(3), USE_ST(4), USE_ST(5),
1025efbcb2bfSmrg				      USE_ST(6), USE_ST(7), USE_ST(8),
1026efbcb2bfSmrg				      USE_ST(9), NULL);
1027efbcb2bfSmrg	ADD_IC(XNStatusAttributes);
1028efbcb2bfSmrg	ADD_IC(st_attr);
10297a84e134Smrg    }
10307a84e134Smrg    if (focus == TRUE) {
1031efbcb2bfSmrg	ADD_IC(XNFocusWindow);
1032efbcb2bfSmrg	ADD_IC(XtWindow(w));
10337a84e134Smrg    }
10347a84e134Smrg    if (ic_cnt > 0) {
1035efbcb2bfSmrg	END_IC();
1036efbcb2bfSmrg	XSetICValues(p->xic, USE_IC(0), USE_IC(1), USE_IC(2), USE_IC(3),
1037efbcb2bfSmrg		     USE_IC(4), USE_IC(5), NULL);
10387a84e134Smrg	if (pe_attr) XtFree(pe_attr);
10397a84e134Smrg	if (st_attr) XtFree(st_attr);
10407a84e134Smrg    }
10417a84e134Smrg
10427a84e134Smrg    if (IsSharedIC(ve) && p->flg & CIFontSet)
10437a84e134Smrg	SizeNegotiation(p, ve->parent->core.width, ve->parent->core.height);
10447a84e134Smrg
10455ec34c4cSmrg    p->flg &= (unsigned long)(~(CIFontSet | CIFg | CIBg | CIBgPixmap | CICursorP | CILineS));
10467a84e134Smrg}
10477a84e134Smrg
10487a84e134Smrgstatic void
10497a84e134SmrgSharedICChangeFocusWindow(Widget w, XawVendorShellExtPart *ve,
10505ec34c4cSmrg			  XawIcTableList p _X_UNUSED)
10517a84e134Smrg{
10527a84e134Smrg    XawIcTableList	pp;
10537a84e134Smrg
10547a84e134Smrg    if (w == NULL) {
10557a84e134Smrg	ve->ic.current_ic_table = NULL;
10567a84e134Smrg	return;
10577a84e134Smrg    }
10587a84e134Smrg    if ((pp = GetIcTable(w, ve)) == NULL) return;
10597a84e134Smrg    ve->ic.current_ic_table = pp;
10607a84e134Smrg    SetICValues(w, ve, TRUE);
10617a84e134Smrg}
10627a84e134Smrg
10637a84e134Smrgstatic XawIcTableList
10647a84e134SmrgCurrentSharedIcTable(XawVendorShellExtPart *ve)
10657a84e134Smrg{
10667a84e134Smrg    return(ve->ic.current_ic_table);
10677a84e134Smrg}
10687a84e134Smrg
10697a84e134Smrgstatic void
10707a84e134SmrgSetICFocus(Widget w, XawVendorShellExtPart *ve)
10717a84e134Smrg{
1072efbcb2bfSmrg    XawIcTableList	p;
10737a84e134Smrg
10747a84e134Smrg    if ((ve->im.xim == NULL) || ((p = GetIcTableShared(w, ve)) == NULL) ||
10757a84e134Smrg	(p->xic == NULL)) return;
10767a84e134Smrg
10777a84e134Smrg    if (IsSharedIC(ve)) {
1078efbcb2bfSmrg	XawIcTableList pp = CurrentSharedIcTable(ve);
10797a84e134Smrg	if (pp == NULL || pp->widget != w) {
10807a84e134Smrg	    SharedICChangeFocusWindow(w, ve, p);
10817a84e134Smrg	}
10827a84e134Smrg    }
10837a84e134Smrg    if (p->flg & CIICFocus && p->ic_focused == FALSE) {
10847a84e134Smrg	p->ic_focused = TRUE;
10857a84e134Smrg	XSetICFocus(p->xic);
10867a84e134Smrg    }
10875ec34c4cSmrg    p->flg &= (unsigned long)(~CIICFocus);
10887a84e134Smrg}
10897a84e134Smrg
10907a84e134Smrgstatic void
10917a84e134SmrgUnsetICFocus(Widget w, XawVendorShellExtPart *ve)
10927a84e134Smrg{
10937a84e134Smrg    XawIcTableList	p, pp;
10947a84e134Smrg
10957a84e134Smrg    if ((ve->im.xim == NULL) || ((p = GetIcTableShared(w, ve)) == NULL) ||
10967a84e134Smrg	(p->xic == NULL)) return;
10977a84e134Smrg
10987a84e134Smrg    if (IsSharedIC(ve) && (pp = CurrentSharedIcTable(ve))) {
10997a84e134Smrg	if (pp->widget != w) {
11007a84e134Smrg	    return;
11017a84e134Smrg	}
11027a84e134Smrg	SharedICChangeFocusWindow(NULL, ve, p);
11037a84e134Smrg    }
11047a84e134Smrg    if (p->ic_focused == TRUE) {
11057a84e134Smrg	XUnsetICFocus(p->xic);
11067a84e134Smrg	p->ic_focused = FALSE;
11077a84e134Smrg    }
11087a84e134Smrg}
11097a84e134Smrg
11107a84e134Smrgstatic void
11117a84e134SmrgSetValues(Widget w, XawVendorShellExtPart *ve,
11127a84e134Smrg	  ArgList args, Cardinal num_args)
11137a84e134Smrg{
11147a84e134Smrg    ArgList	arg;
11157a84e134Smrg
11167a84e134Smrg    XrmName	argName;
11177a84e134Smrg    XrmResourceList	xrmres;
11187a84e134Smrg    Cardinal	i;
11197a84e134Smrg    XawIcTablePart	*p, save_tbl;
11207a84e134Smrg
11217a84e134Smrg    if ((p = GetIcTable(w, ve)) == NULL) return;
11227a84e134Smrg
11237a84e134Smrg    memcpy(&save_tbl, p, sizeof(XawIcTablePart));
11247a84e134Smrg
11257a84e134Smrg    for (arg = args ; num_args != 0; num_args--, arg++) {
11267a84e134Smrg	argName = XrmStringToName(arg->name);
11277a84e134Smrg	for (xrmres = (XrmResourceList)ve->im.resources, i = 0;
11287a84e134Smrg	     i < ve->im.num_resources; i++, xrmres++) {
11297a84e134Smrg            if (argName == xrmres->xrm_name) {
11307a84e134Smrg                _XtCopyFromArg(arg->value,
11317a84e134Smrg			       (char *)p - xrmres->xrm_offset - 1,
11327a84e134Smrg			       xrmres->xrm_size);
11337a84e134Smrg                break;
11347a84e134Smrg            }
11357a84e134Smrg        }
11367a84e134Smrg    }
11377a84e134Smrg    if (p->font_set != save_tbl.font_set) {
11387a84e134Smrg	p->flg |= CIFontSet;
11397a84e134Smrg    }
11407a84e134Smrg    if (p->foreground != save_tbl.foreground) {
11417a84e134Smrg	p->flg |= CIFg;
11427a84e134Smrg    }
11437a84e134Smrg    if (p->background !=save_tbl.background) {
11447a84e134Smrg	p->flg |= CIBg;
11457a84e134Smrg    }
11467a84e134Smrg    if (p->bg_pixmap != save_tbl.bg_pixmap) {
11477a84e134Smrg	p->flg |= CIBgPixmap;
11487a84e134Smrg    }
11497a84e134Smrg    if (p->cursor_position != save_tbl.cursor_position) {
11507a84e134Smrg	p->flg |= CICursorP;
11517a84e134Smrg    }
11527a84e134Smrg    if (p->line_spacing != save_tbl.line_spacing) {
11537a84e134Smrg	p->flg |= CILineS;
11547a84e134Smrg    }
11557a84e134Smrg    p->prev_flg |= p->flg;
11567a84e134Smrg}
11577a84e134Smrg
11587a84e134Smrgstatic void
11597a84e134SmrgSetFocus(Widget w, XawVendorShellExtPart *ve)
11607a84e134Smrg{
11617a84e134Smrg    XawIcTableList	p;
11627a84e134Smrg    if ((p = GetIcTableShared(w, ve)) == NULL) return;
11637a84e134Smrg
11647a84e134Smrg    if ( p->ic_focused == FALSE || IsSharedIC(ve)) {
11657a84e134Smrg	p->flg |= CIICFocus;
11667a84e134Smrg    }
11677a84e134Smrg    p->prev_flg |= p->flg;
11687a84e134Smrg}
11697a84e134Smrg
11707a84e134Smrgstatic void
11717a84e134SmrgDestroyIC(Widget w, XawVendorShellExtPart *ve)
11727a84e134Smrg{
11737a84e134Smrg    XawIcTableList	p;
11747a84e134Smrg
11757a84e134Smrg    if ((ve->im.xim == NULL) || ((p = GetIcTableShared(w, ve)) == NULL) ||
11767a84e134Smrg	(p->xic == NULL)) return;
11777a84e134Smrg    if (IsSharedIC(ve)) {
11787a84e134Smrg	if (GetIcTable(w, ve) == ve->ic.current_ic_table) {
11797a84e134Smrg	    UnsetICFocus(w, ve);
11807a84e134Smrg	}
11817a84e134Smrg        return;
11827a84e134Smrg    }
11837a84e134Smrg    XDestroyIC(p->xic);
11847a84e134Smrg    if (!IsSharedIC(ve)) {
11857a84e134Smrg	if (p->input_style & XIMPreeditPosition) {
11867a84e134Smrg	    XtRemoveEventHandler(w, (EventMask)StructureNotifyMask, FALSE,
11877a84e134Smrg				 (XtEventHandler)ConfigureCB, (Opaque)NULL);
11887a84e134Smrg	}
11897a84e134Smrg    }
11907a84e134Smrg}
11917a84e134Smrg
11927a84e134Smrgstatic void
11937a84e134SmrgSetFocusValues(Widget inwidg, ArgList args, Cardinal num_args, Bool focus)
11947a84e134Smrg{
11957a84e134Smrg    XawVendorShellExtPart	*ve;
11967a84e134Smrg    VendorShellWidget		vw;
11977a84e134Smrg
11987a84e134Smrg    if ((vw = SearchVendorShell(inwidg)) == NULL) return;
11997a84e134Smrg    if ((ve = GetExtPart(vw)) != NULL) {
12007a84e134Smrg	if (num_args > 0) SetValues(inwidg, ve, args, num_args);
12017a84e134Smrg	if (focus) SetFocus(inwidg, ve);
12027a84e134Smrg	if (XtIsRealized((Widget)vw) && ve->im.xim) {
12037a84e134Smrg	    if (IsCreatedIC(inwidg, ve)) {
12047a84e134Smrg		SetICValues(inwidg, ve, FALSE);
12057a84e134Smrg		if (focus) SetICFocus(inwidg, ve);
12067a84e134Smrg	    } else {
12077a84e134Smrg		CreateIC(inwidg, ve);
1208421c997bSmrg		SetICFocus(inwidg, ve);
12097a84e134Smrg	    }
12107a84e134Smrg	}
12117a84e134Smrg    }
12127a84e134Smrg}
12137a84e134Smrg
12147a84e134Smrgstatic void
12157a84e134SmrgUnsetFocus(Widget inwidg)
12167a84e134Smrg{
12177a84e134Smrg    XawVendorShellExtPart	*ve;
12187a84e134Smrg    VendorShellWidget		vw;
12197a84e134Smrg
12207a84e134Smrg    if ((vw = SearchVendorShell(inwidg)) == NULL) return;
1221efbcb2bfSmrg
12227a84e134Smrg    if ((ve = GetExtPart(vw)) != NULL) {
1223efbcb2bfSmrg	XawIcTableList p;
1224efbcb2bfSmrg
12257a84e134Smrg	if ((p = GetIcTableShared(inwidg, ve)) == NULL) return;
12267a84e134Smrg	if (p->flg & CIICFocus) {
12275ec34c4cSmrg	    p->flg &= (unsigned long)(~CIICFocus);
12287a84e134Smrg	}
12295ec34c4cSmrg	p->prev_flg &= (unsigned long)(~CIICFocus);
12307a84e134Smrg	if (ve->im.xim && XtIsRealized((Widget)vw) && p->xic) {
12317a84e134Smrg	    UnsetICFocus(inwidg, ve);
12327a84e134Smrg	}
12337a84e134Smrg    }
12347a84e134Smrg}
12357a84e134Smrg
12367a84e134Smrgstatic Bool
12377a84e134SmrgIsRegistered(Widget w, XawVendorShellExtPart* ve)
12387a84e134Smrg{
12397a84e134Smrg    XawIcTableList	p;
12407a84e134Smrg
12417a84e134Smrg    for (p = ve->ic.ic_table; p; p = p->next)
12427a84e134Smrg	{
12437a84e134Smrg	    if (p->widget == w) return(TRUE);
12447a84e134Smrg	}
12457a84e134Smrg    return(FALSE);
12467a84e134Smrg}
12477a84e134Smrg
12487a84e134Smrgstatic void
12497a84e134SmrgRegister(Widget inwidg, XawVendorShellExtPart* ve)
12507a84e134Smrg{
12517a84e134Smrg    if (ve->im.xim == NULL)
12527a84e134Smrg	{
12537a84e134Smrg	    OpenIM(ve);
12547a84e134Smrg	}
12557a84e134Smrg
12567a84e134Smrg    if (IsRegistered(inwidg, ve)) return;
12577a84e134Smrg
12587a84e134Smrg    if (RegisterToVendorShell(inwidg, ve) == FALSE) return;
12597a84e134Smrg
12607a84e134Smrg    if (ve->im.xim == NULL) return;
12617a84e134Smrg
12627a84e134Smrg    if (XtIsRealized(ve->parent))
12637a84e134Smrg	{
12647a84e134Smrg	    CreateIC(inwidg, ve);
12657a84e134Smrg	    SetICFocus(inwidg, ve);
12667a84e134Smrg	}
12677a84e134Smrg}
12687a84e134Smrg
12697a84e134Smrgstatic Bool
12707a84e134SmrgNoRegistered(XawVendorShellExtPart* ve)
12717a84e134Smrg{
12727a84e134Smrg    if (ve->ic.ic_table == NULL) return(TRUE);
12737a84e134Smrg    return(FALSE);
12747a84e134Smrg}
12757a84e134Smrg
12767a84e134Smrgstatic void
12777a84e134SmrgUnregister(Widget inwidg, XawVendorShellExtPart *ve)
12787a84e134Smrg{
12797a84e134Smrg    if (!IsRegistered(inwidg, ve)) return;
12807a84e134Smrg
12817a84e134Smrg    DestroyIC(inwidg, ve);
12827a84e134Smrg
12837a84e134Smrg    UnregisterFromVendorShell(inwidg, ve);
12847a84e134Smrg
12857a84e134Smrg    if (NoRegistered(ve))
12867a84e134Smrg	{
12877a84e134Smrg	    CloseIM(ve);
12887a84e134Smrg	    ve->im.xim = NULL;
12897a84e134Smrg	    /*
12907a84e134Smrg	     * resize vendor shell to core size
12917a84e134Smrg	    */
12927a84e134Smrg	    (void) SetVendorShellHeight(ve, 0);
12937a84e134Smrg	}
12947a84e134Smrg}
12957a84e134Smrg
12967a84e134Smrgstatic void
12977a84e134SmrgAllCreateIC(XawVendorShellExtPart *ve)
12987a84e134Smrg{
12997a84e134Smrg    XawIcTableList p;
13007a84e134Smrg
13017a84e134Smrg    if (ve->im.xim == NULL) return;
13027a84e134Smrg    if (IsSharedIC(ve) && ve->ic.ic_table[0].widget) {
13037a84e134Smrg	p = ve->ic.shared_ic_table;
13047a84e134Smrg	if (p->xic == NULL)
13057a84e134Smrg	    CreateIC(ve->ic.ic_table[0].widget, ve);
13067a84e134Smrg	SetICFocus(ve->ic.ic_table[0].widget, ve);
13077a84e134Smrg	return;
13087a84e134Smrg    }
13097a84e134Smrg    for (p = ve->ic.ic_table; p; p = p->next) {
13107a84e134Smrg	if (p->xic == NULL)
13117a84e134Smrg	    CreateIC(p->widget, ve);
13127a84e134Smrg    }
13137a84e134Smrg    for (p = ve->ic.ic_table; p; p = p->next) {
13147a84e134Smrg	SetICFocus(p->widget, ve);
13157a84e134Smrg    }
13167a84e134Smrg}
13177a84e134Smrg
13187a84e134Smrg
13197a84e134Smrgstatic void
13207a84e134SmrgReconnect(XawVendorShellExtPart *ve)
13217a84e134Smrg{
13227a84e134Smrg    XawIcTableList	p;
13237a84e134Smrg
13247a84e134Smrg    ve->im.open_im = True;
13257a84e134Smrg    if (ve->im.xim == NULL) {
13267a84e134Smrg	OpenIM(ve);
13277a84e134Smrg    }
13287a84e134Smrg    if (ve->im.xim == NULL) return;
13297a84e134Smrg
13307a84e134Smrg    if (IsSharedIC(ve)) {
13317a84e134Smrg	p = ve->ic.shared_ic_table;
13327a84e134Smrg	p->flg = p->prev_flg;
13337a84e134Smrg	p->openic_error = FALSE;
13347a84e134Smrg    } else {
13357a84e134Smrg	for (p = ve->ic.ic_table; p; p = p->next) {
13367a84e134Smrg	    p->flg = p->prev_flg;
13377a84e134Smrg	    p->openic_error = FALSE;
13387a84e134Smrg	}
13397a84e134Smrg    }
13407a84e134Smrg    AllCreateIC(ve);
13417a84e134Smrg}
13427a84e134Smrg
13437a84e134Smrg
13447a84e134Smrgstatic void
13457a84e134SmrgCompileResourceList(XtResourceList res, unsigned int num_res)
13467a84e134Smrg{
13477a84e134Smrg    unsigned int count;
13487a84e134Smrg
13497a84e134Smrg#define xrmres	((XrmResourceList) res)
13507a84e134Smrg    for (count = 0; count < num_res; res++, count++) {
13517a84e134Smrg	xrmres->xrm_name         = XrmPermStringToQuark(res->resource_name);
13527a84e134Smrg	xrmres->xrm_class        = XrmPermStringToQuark(res->resource_class);
13537a84e134Smrg	xrmres->xrm_type         = XrmPermStringToQuark(res->resource_type);
13545ec34c4cSmrg	xrmres->xrm_offset	 = (int)(-res->resource_offset - 1);
13557a84e134Smrg	xrmres->xrm_default_type = XrmPermStringToQuark(res->default_type);
13567a84e134Smrg    }
13577a84e134Smrg#undef xrmres
13587a84e134Smrg}
13597a84e134Smrg
13607a84e134Smrgstatic Bool
13617a84e134SmrgInitialize(VendorShellWidget vw, XawVendorShellExtPart *ve)
13627a84e134Smrg{
13637a84e134Smrg    if (!XtIsVendorShell((Widget)vw)) return(FALSE);
13647a84e134Smrg    ve->parent = (Widget)vw;
13657a84e134Smrg    ve->im.xim = NULL;
13667a84e134Smrg    ve->im.area_height = 0;
13677a84e134Smrg    ve->im.resources = (XrmResourceList)XtMalloc(sizeof(resources));
13687a84e134Smrg    if (ve->im.resources == NULL) return(FALSE);
13697a84e134Smrg    memcpy((char *)ve->im.resources, (char *)resources, sizeof(resources));
13707a84e134Smrg    ve->im.num_resources = XtNumber(resources);
13717a84e134Smrg    CompileResourceList( (XtResourceList) ve->im.resources,
13727a84e134Smrg			   ve->im.num_resources );
13737a84e134Smrg    if ((ve->ic.shared_ic_table = CreateIcTable( (Widget)vw, ve)) == NULL)
13747a84e134Smrg	return(FALSE);
13757a84e134Smrg    ve->ic.current_ic_table = NULL;
13767a84e134Smrg    ve->ic.ic_table = NULL;
13777a84e134Smrg    return(TRUE);
13787a84e134Smrg}
13797a84e134Smrg
13807a84e134Smrg
13817a84e134Smrg/* Destroy()
13827a84e134Smrg *
13837a84e134Smrg * This frees all (most?) of the resources malloced by XawIm.
13847a84e134Smrg * It is called by _XawImDestroy, which is called by Vendor.c's
13857a84e134Smrg * VendorExt's Destroy method.           Sheeran, Omron KK, 93/08/05 */
13867a84e134Smrg
13877a84e134Smrgstatic void
13887a84e134SmrgDestroy(Widget w, XawVendorShellExtPart *ve)
13897a84e134Smrg{
13907a84e134Smrg    contextDataRec *contextData;
13917a84e134Smrg    contextErrDataRec *contextErrData;
13927a84e134Smrg
13937a84e134Smrg    if (!XtIsVendorShell( w ) )
13947a84e134Smrg	return;
13957a84e134Smrg    XtFree( (char*) ve->im.resources );
13967a84e134Smrg
1397421c997bSmrg    if (extContext != (XContext)0 &&
1398421c997bSmrg	!XFindContext (XtDisplay (w), (Window)w,
13997a84e134Smrg		       extContext, (XPointer*)&contextData))
14007a84e134Smrg        XtFree( (char*) contextData );
14017a84e134Smrg
1402421c997bSmrg    if (errContext != (XContext)0 &&
1403421c997bSmrg	!XFindContext (XDisplayOfIM( ve->im.xim ), (Window) ve->im.xim,
14047a84e134Smrg		       errContext, (XPointer*) &contextErrData))
14057a84e134Smrg        XtFree( (char*) contextErrData );
14067a84e134Smrg}
14077a84e134Smrg
14087a84e134Smrg/*********************************************
14097a84e134Smrg *
14107a84e134Smrg * SEMI-PRIVATE FUNCTIONS
14117a84e134Smrg * For use by other Xaw modules
14127a84e134Smrg *
14137a84e134Smrg ********************************************/
14147a84e134Smrg
14157a84e134Smrgvoid
14167a84e134Smrg_XawImResizeVendorShell(Widget w)
14177a84e134Smrg{
14187a84e134Smrg    XawVendorShellExtPart *ve;
14197a84e134Smrg
14207a84e134Smrg    if ( ( ve = GetExtPart( (VendorShellWidget) w ) ) && ve->im.xim ) {
14217a84e134Smrg	ResizeVendorShell( (VendorShellWidget) w, ve );
14227a84e134Smrg    }
14237a84e134Smrg}
14247a84e134Smrg
14257a84e134Smrg
14267a84e134SmrgDimension
14277a84e134Smrg_XawImGetShellHeight(Widget w)
14287a84e134Smrg{
14297a84e134Smrg    XawVendorShellExtPart *ve;
14307a84e134Smrg
14317a84e134Smrg    if (!XtIsVendorShell( w ) ) return( w->core.height );
14327a84e134Smrg    if ( (ve = GetExtPart( (VendorShellWidget) w )) != NULL ) {
14335ec34c4cSmrg	return (Dimension)( w->core.height - ve->im.area_height );
14347a84e134Smrg    }
14357a84e134Smrg    return( w->core.height );
14367a84e134Smrg}
14377a84e134Smrg
14387a84e134Smrgvoid
14397a84e134Smrg_XawImRealize(Widget w)
14407a84e134Smrg{
14417a84e134Smrg    XawVendorShellExtPart	*ve;
14427a84e134Smrg
14437a84e134Smrg    if ( !XtIsRealized( w ) || !XtIsVendorShell( w ) ) return;
14447a84e134Smrg    if ( (ve = GetExtPart( (VendorShellWidget) w )) != NULL ) {
14457a84e134Smrg	XtAddEventHandler( w, (EventMask)StructureNotifyMask, FALSE,
14467a84e134Smrg			  XawVendorStructureNotifyHandler, (XtPointer)NULL );
14477a84e134Smrg	AllCreateIC(ve);
14487a84e134Smrg    }
14497a84e134Smrg}
14507a84e134Smrg
14517a84e134Smrgvoid
14527a84e134Smrg_XawImInitialize(Widget w, Widget ext)
14537a84e134Smrg{
14547a84e134Smrg    XawVendorShellExtPart	*ve;
14557a84e134Smrg
14567a84e134Smrg    if ( !XtIsVendorShell( w ) ) return;
14577a84e134Smrg    if ( (ve = SetExtPart( (VendorShellWidget) w, (XawVendorShellExtWidget)ext )) != NULL ) {
14587a84e134Smrg	if ( Initialize( (VendorShellWidget) w, ve ) == FALSE ) return;
14597a84e134Smrg	XtAddCallback( w, XtNdestroyCallback, VendorShellDestroyed,
14607a84e134Smrg		      (XtPointer) NULL );
14617a84e134Smrg    }
14627a84e134Smrg}
14637a84e134Smrg
14647a84e134Smrgvoid
14657a84e134Smrg_XawImReconnect(Widget inwidg)
14667a84e134Smrg{
14677a84e134Smrg    XawVendorShellExtPart	*ve;
14687a84e134Smrg    VendorShellWidget		vw;
14697a84e134Smrg
14707a84e134Smrg    if ((vw = SearchVendorShell(inwidg)) == NULL) return;
14717a84e134Smrg    if ((ve = GetExtPart(vw)) != NULL) {
14727a84e134Smrg	Reconnect(ve);
14737a84e134Smrg    }
14747a84e134Smrg}
14757a84e134Smrg
14767a84e134Smrgvoid
14777a84e134Smrg_XawImRegister(Widget inwidg)
14787a84e134Smrg{
14797a84e134Smrg    XawVendorShellExtPart	*ve;
14807a84e134Smrg    VendorShellWidget		vw;
14817a84e134Smrg
14827a84e134Smrg    if ((vw = SearchVendorShell(inwidg)) == NULL) return;
14837a84e134Smrg    if ((ve = GetExtPart(vw)) != NULL) {
14847a84e134Smrg	Register(inwidg, ve);
14857a84e134Smrg    }
14867a84e134Smrg}
14877a84e134Smrg
14887a84e134Smrgvoid
14897a84e134Smrg_XawImUnregister(Widget inwidg)
14907a84e134Smrg{
14917a84e134Smrg    XawVendorShellExtPart	*ve;
14927a84e134Smrg    VendorShellWidget		vw;
14937a84e134Smrg
14947a84e134Smrg    if ((vw = SearchVendorShell(inwidg)) == NULL) return;
14957a84e134Smrg    if ((ve = GetExtPart(vw)) != NULL) {
14967a84e134Smrg	Unregister(inwidg, ve);
14977a84e134Smrg    }
14987a84e134Smrg}
14997a84e134Smrg
15007a84e134Smrgvoid
15017a84e134Smrg_XawImSetValues(Widget inwidg, ArgList args, Cardinal num_args)
15027a84e134Smrg{
15037a84e134Smrg    SetFocusValues( inwidg, args, num_args, FALSE );
15047a84e134Smrg}
15057a84e134Smrg
15067a84e134Smrgvoid
15077a84e134Smrg_XawImSetFocusValues(Widget inwidg, ArgList args, Cardinal num_args)
15087a84e134Smrg{
15097a84e134Smrg    SetFocusValues(inwidg, args, num_args, TRUE);
15107a84e134Smrg}
15117a84e134Smrg
15127a84e134Smrgvoid
15137a84e134Smrg_XawImUnsetFocus(Widget inwidg)
15147a84e134Smrg{
15157a84e134Smrg    UnsetFocus(inwidg);
15167a84e134Smrg}
15177a84e134Smrg
15187a84e134Smrgint
15197a84e134Smrg_XawImWcLookupString(Widget inwidg, XKeyPressedEvent *event,
15207a84e134Smrg		     wchar_t* buffer_return, int bytes_buffer,
15217a84e134Smrg		     KeySym *keysym_return)
15227a84e134Smrg{
15237a84e134Smrg    XawVendorShellExtPart*	ve;
15247a84e134Smrg    VendorShellWidget		vw;
15257a84e134Smrg    XawIcTableList		p;
15267a84e134Smrg    int				i, ret;
15277a84e134Smrg    char			tmp_buf[64], *tmp_p;
15287a84e134Smrg    wchar_t*			buf_p;
15297a84e134Smrg
15307a84e134Smrg    if ((vw = SearchVendorShell(inwidg)) && (ve = GetExtPart(vw)) &&
15317a84e134Smrg	ve->im.xim && (p = GetIcTableShared(inwidg, ve)) && p->xic) {
15325ec34c4cSmrg	  return(XwcLookupString(p->xic, event, buffer_return,
15335ec34c4cSmrg				 (int)((size_t)bytes_buffer/sizeof(wchar_t)),
15347a84e134Smrg				 keysym_return, NULL));
15357a84e134Smrg    }
15367a84e134Smrg    ret = XLookupString( event, tmp_buf, sizeof(tmp_buf), keysym_return,
15377a84e134Smrg		         NULL );
15387a84e134Smrg    for ( i = 0, tmp_p = tmp_buf, buf_p = buffer_return; i < ret; i++ ) {
15395ec34c4cSmrg	*buf_p++ = _Xaw_atowc((unsigned char)*tmp_p++);
15407a84e134Smrg    }
15417a84e134Smrg    return( ret );
15427a84e134Smrg}
15437a84e134Smrg
15447a84e134Smrgint
15457a84e134Smrg_XawLookupString(Widget w, XKeyEvent *event, char *buffer_return, int buffer_size,
15467a84e134Smrg		 KeySym *keysym_return)
15477a84e134Smrg{
15487a84e134Smrg    XawVendorShellExtPart *ve;
15497a84e134Smrg    VendorShellWidget vw;
15507a84e134Smrg    XawIcTableList p;
15517a84e134Smrg
15527a84e134Smrg    if ((vw = SearchVendorShell(w)) && (ve = GetExtPart(vw))
15537a84e134Smrg	&& ve->im.xim && (p = GetIcTableShared(w, ve)) && p->xic)
15547a84e134Smrg	return (XmbLookupString(p->xic, event, buffer_return, buffer_size,
15557a84e134Smrg				keysym_return, NULL));
15567a84e134Smrg
15577a84e134Smrg    return (XLookupString(event, buffer_return, buffer_size,
15587a84e134Smrg			  keysym_return, NULL));
15597a84e134Smrg}
15607a84e134Smrg
15617a84e134Smrgint
15627a84e134Smrg_XawImGetImAreaHeight(Widget w)
15637a84e134Smrg{
15647a84e134Smrg    XawVendorShellExtPart	*ve;
15657a84e134Smrg    VendorShellWidget		vw;
15667a84e134Smrg
15677a84e134Smrg    if ((vw = SearchVendorShell(w)) && (ve = GetExtPart(vw))) {
15687a84e134Smrg	return(ve->im.area_height);
15697a84e134Smrg    }
15707a84e134Smrg    return(0);
15717a84e134Smrg}
15727a84e134Smrg
15737a84e134Smrgvoid
15747a84e134Smrg_XawImCallVendorShellExtResize(Widget w)
15757a84e134Smrg{
15767a84e134Smrg    VendorShellWidget		vw;
15777a84e134Smrg
15787a84e134Smrg    if ((vw = SearchVendorShell(w)) && GetExtPart(vw)) {
15797a84e134Smrg	XawVendorShellExtResize((Widget)vw);
15807a84e134Smrg    }
15817a84e134Smrg}
15827a84e134Smrg
15837a84e134Smrg
15847a84e134Smrg/* _XawImDestroy()
15857a84e134Smrg *
15867a84e134Smrg * This should be called by the VendorExt from its
15877a84e134Smrg * core Destroy method.  Sheeran, Omron KK 93/08/05 */
15887a84e134Smrg
15897a84e134Smrgvoid
15905ec34c4cSmrg_XawImDestroy(Widget w, Widget ext _X_UNUSED)
15917a84e134Smrg{
15927a84e134Smrg    XawVendorShellExtPart        *ve;
15937a84e134Smrg
15947a84e134Smrg    if ( !XtIsVendorShell( w ) ) return;
15957a84e134Smrg    if ( (ve = GetExtPart( (VendorShellWidget) w )) != NULL )
15967a84e134Smrg        Destroy( w, ve );
15977a84e134Smrg}
1598