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