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