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