00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #include <X11/IntrinsicP.h>
00058 #include <X11/StringDefs.h>
00059 #include <X11/Xos.h>
00060 #include <X11/Xfuncs.h>
00061 #include <X11/ShellP.h>
00062 #include <X11/Xaw3d/TextP.h>
00063 #include <X11/Xaw3d/MultiSrc.h>
00064 #include <X11/Xaw3d/MultiSinkP.h>
00065 #include <X11/Xaw3d/XawImP.h>
00066 #include <X11/Xaw3d/VendorEP.h>
00067 #include "XawI18n.h"
00068 #include <ctype.h>
00069
00070 #if NeedVarargsPrototypes
00071 # include <stdarg.h>
00072 # define Va_start(a,b) va_start(a,b)
00073 #else
00074 # include <varargs.h>
00075 # define Va_start(a,b) va_start(a)
00076 #endif
00077
00078 #define maxAscentOfFontSet(fontset) \
00079 ( - (XExtentsOfFontSet((fontset)))->max_logical_extent.y)
00080
00081 #define maxHeightOfFontSet(fontset) \
00082 ((XExtentsOfFontSet((fontset)))->max_logical_extent.height)
00083
00084 #define maxDescentOfFontSet(fontset) \
00085 (maxHeightOfFontSet(fontset) - maxAscentOfFontSet(fontset))
00086
00087 #define Offset(field) (XtOffsetOf(XawIcTablePart, field))
00088
00089
00090
00091
00092
00093
00094
00095 static XawIcTableList CurrentSharedIcTable(
00096 #if NeedFunctionPrototypes
00097 XawVendorShellExtPart*
00098 #endif
00099 );
00100
00101 static void DestroyIC(
00102 #if NeedFunctionPrototypes
00103 Widget ,
00104 XawVendorShellExtPart*
00105 #endif
00106 );
00107
00108 static XtResource resources[] =
00109 {
00110 {
00111 XtNfontSet, XtCFontSet, XtRFontSet, sizeof(XFontSet),
00112 Offset (font_set), XtRString, XtDefaultFontSet
00113 },
00114 {
00115 XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
00116 Offset (foreground), XtRString, (XtPointer)"XtDefaultForeground"
00117 },
00118 {
00119 XtNbackground, XtCBackground, XtRPixel, sizeof(Pixel),
00120 Offset (background), XtRString, (XtPointer)"XtDefaultBackground"
00121 },
00122 {
00123 XtNbackgroundPixmap, XtCPixmap, XtRPixmap, sizeof(Pixmap),
00124 Offset (bg_pixmap), XtRImmediate, (XtPointer) XtUnspecifiedPixmap
00125 },
00126 {
00127 XtNinsertPosition, XtCTextPosition, XtRInt, sizeof (XawTextPosition),
00128 Offset (cursor_position), XtRImmediate, (XtPointer) 0
00129 }
00130 };
00131 #undef Offset
00132
00133
00134 static void SetVaArg( arg, value )
00135 XPointer *arg, value;
00136 {
00137 *arg = value;
00138 }
00139
00140 static VendorShellWidget SearchVendorShell( w )
00141 Widget w;
00142 {
00143 while(w && !XtIsShell(w)) w = XtParent(w);
00144 if (w && XtIsVendorShell(w)) return((VendorShellWidget)w);
00145 return(NULL);
00146 }
00147
00148 static XContext extContext = (XContext)NULL;
00149
00150 static XawVendorShellExtPart *SetExtPart( w, vew )
00151 VendorShellWidget w;
00152 XawVendorShellExtWidget vew;
00153 {
00154 contextDataRec *contextData;
00155
00156 if (extContext == (XContext)NULL) extContext = XUniqueContext();
00157
00158 contextData = XtNew(contextDataRec);
00159 contextData->parent = (Widget)w;
00160 contextData->ve = (Widget)vew;
00161 if (XSaveContext(XtDisplay(w), (Window)w, extContext, (char *)contextData)) {
00162 return(NULL);
00163 }
00164 return(&(vew->vendor_ext));
00165 }
00166
00167 static XawVendorShellExtPart *GetExtPart( w )
00168 VendorShellWidget w;
00169 {
00170 contextDataRec *contextData;
00171 XawVendorShellExtWidget vew;
00172
00173 if (XFindContext(XtDisplay(w), (Window)w, extContext,
00174 (XPointer*)&contextData)) {
00175 return(NULL);
00176 }
00177 vew = (XawVendorShellExtWidget)contextData->ve;
00178 return(&(vew->vendor_ext));
00179 }
00180
00181 static Boolean IsSharedIC( ve )
00182 XawVendorShellExtPart * ve;
00183 {
00184 return( ve->ic.shared_ic );
00185 }
00186
00187 static XawIcTableList GetIcTableShared( w, ve )
00188 Widget w;
00189 XawVendorShellExtPart * ve;
00190 {
00191 XawIcTableList p;
00192
00193 for (p = ve->ic.ic_table; p; p = p->next) {
00194 if (p->widget == w) {
00195 if (IsSharedIC(ve)) {
00196 return(ve->ic.shared_ic_table);
00197 } else {
00198 return(p);
00199 }
00200 }
00201 }
00202 return(NULL);
00203 }
00204
00205 static XawIcTableList GetIcTable( w, ve )
00206 Widget w;
00207 XawVendorShellExtPart * ve;
00208 {
00209 XawIcTableList p;
00210
00211 for (p = ve->ic.ic_table; p; p = p->next) {
00212 if (p->widget == w) {
00213 return(p);
00214 }
00215 }
00216 return(NULL);
00217 }
00218
00219 static XIMStyle GetInputStyleOfIC( ve )
00220 XawVendorShellExtPart * ve;
00221 {
00222
00223 if (!ve) return((XIMStyle)0);
00224 return(ve->ic.input_style);
00225 }
00226
00227 static void ConfigureCB( w, closure, event )
00228 Widget w;
00229 XtPointer closure;
00230 XEvent * event;
00231 {
00232 XawIcTableList p;
00233 XawVendorShellExtPart *ve;
00234 VendorShellWidget vw;
00235 XVaNestedList pe_attr;
00236 XRectangle pe_area;
00237 XawTextMargin *margin;
00238
00239 if (event->type != ConfigureNotify) return;
00240
00241 if ((vw = SearchVendorShell(w)) == NULL) return;
00242
00243 if ((ve = GetExtPart(vw))) {
00244 if (IsSharedIC(ve)) return;
00245 if ((ve->im.xim == NULL) ||
00246 ((p = GetIcTableShared(w, ve)) == NULL) ||
00247 (p->xic == NULL) || !(p->input_style & XIMPreeditPosition)) return;
00248 pe_area.x = 0;
00249 pe_area.y = 0;
00250 pe_area.width = w->core.width;
00251 pe_area.height = w->core.height;
00252 margin = &(((TextWidget)w)->text.margin);
00253 pe_area.x += margin->left;
00254 pe_area.y += margin->top;
00255 pe_area.width -= (margin->left + margin->right - 1);
00256 pe_area.height -= (margin->top + margin->bottom - 1);
00257
00258 pe_attr = XVaCreateNestedList(0, XNArea, &pe_area, NULL);
00259 XSetICValues(p->xic, XNPreeditAttributes, pe_attr, NULL);
00260 XtFree(pe_attr);
00261 }
00262 }
00263
00264 static XContext errContext = (XContext)NULL;
00265
00266 static Widget SetErrCnxt( w, xim )
00267 Widget w;
00268 XIM xim;
00269 {
00270 contextErrDataRec *contextErrData;
00271
00272 if (errContext == (XContext)NULL) errContext = XUniqueContext();
00273
00274 contextErrData = XtNew(contextErrDataRec);
00275 contextErrData->widget = w;
00276 contextErrData->xim = xim;
00277 if (XSaveContext(XtDisplay(w), (Window)xim, errContext,
00278 (char *)contextErrData)) {
00279 return(NULL);
00280 }
00281 return(contextErrData->widget);
00282 }
00283
00284 static void CloseIM( ve )
00285 XawVendorShellExtPart * ve;
00286 {
00287 if (ve->im.xim)
00288 XCloseIM(ve->im.xim);
00289 }
00290
00291 static Dimension SetVendorShellHeight( ve, height )
00292 XawVendorShellExtPart* ve;
00293 Dimension height;
00294 {
00295 Arg args[2];
00296 Cardinal i = 0;
00297
00298 if (ve->im.area_height < height || height == 0) {
00299 XtSetArg(args[i], XtNheight,
00300 (ve->parent->core.height + height - ve->im.area_height));
00301 ve->im.area_height = height;
00302 XtSetValues(ve->parent, args, 1);
00303 }
00304 return(ve->im.area_height);
00305 }
00306
00307 static void DestroyAllIM( ve )
00308 XawVendorShellExtPart * ve;
00309 {
00310 XawIcTableList p;
00311 contextErrDataRec *contextErrData;
00312
00313
00314
00315
00316 if (IsSharedIC(ve)) {
00317 if ((p = ve->ic.shared_ic_table) && p->xic) {
00318 DestroyIC(p->widget, ve);
00319 p->xic = NULL;
00320 p->ic_focused = FALSE;
00321 }
00322 } else {
00323 for (p = ve->ic.ic_table; p; p = p->next) {
00324 if (p->xic == NULL) continue;
00325 DestroyIC(p->widget, ve);
00326 p->xic = NULL;
00327 p->ic_focused = FALSE;
00328 }
00329 }
00330 if (!ve->im.xim) return;
00331
00332
00333
00334 CloseIM(ve);
00335 if (!XFindContext(XDisplayOfIM(ve->im.xim), (Window)ve->im.xim, errContext,
00336 (XPointer*)&contextErrData)) {
00337 if (contextErrData) XtFree((char *)contextErrData);
00338 }
00339 XDeleteContext(XDisplayOfIM(ve->im.xim), (Window)ve->im.xim, errContext);
00340 ve->im.xim = NULL;
00341
00342
00343
00344
00345 (void) SetVendorShellHeight(ve, 0);
00346
00347
00348
00349 return;
00350 }
00351
00352 static void FreeAllDataOfVendorShell(ve, vw)
00353 XawVendorShellExtPart * ve;
00354 VendorShellWidget vw;
00355 {
00356 XawIcTableList p, next;
00357 contextErrDataRec *contextErrData;
00358
00359 if (!XFindContext(XtDisplay(vw), (Window)vw, extContext,
00360 (XPointer*)&contextErrData)) {
00361 if (contextErrData) XtFree((char *)contextErrData);
00362 }
00363 XDeleteContext(XtDisplay(vw), (Window)vw, extContext);
00364 if (ve->ic.shared_ic_table)
00365 XtFree((char *)ve->ic.shared_ic_table);
00366 if (ve->im.resources) XtFree((char *)ve->im.resources);
00367 for (p = ve->ic.ic_table; p; p = next) {
00368 next = p->next;
00369 XtFree((char *)p);
00370 }
00371 }
00372
00373 static void VendorShellDestroyed( w, cl_data, ca_data )
00374 Widget w;
00375 XtPointer cl_data, ca_data;
00376 {
00377 XawVendorShellExtPart *ve;
00378
00379 if ( ( ve = GetExtPart( (VendorShellWidget) w ) ) == NULL ) return;
00380 DestroyAllIM( ve );
00381 FreeAllDataOfVendorShell( ve, (VendorShellWidget) w );
00382 return;
00383 }
00384
00385
00386
00387
00388
00389 static void OpenIM(ve)
00390 XawVendorShellExtPart * ve;
00391 {
00392 int i;
00393 char *p, *s, *ns, *end, *pbuf, buf[32];
00394 XIM xim = NULL;
00395 XIMStyles *xim_styles;
00396 XIMStyle input_style = 0;
00397 Boolean found;
00398
00399 if (ve->im.open_im == False) return;
00400 ve->im.xim = NULL;
00401 if (ve->im.input_method == NULL) {
00402 if ((p = XSetLocaleModifiers("@im=none")) != NULL && *p)
00403 xim = XOpenIM(XtDisplay(ve->parent), NULL, NULL, NULL);
00404 } else {
00405
00406 int len = strlen (ve->im.input_method) + 5;
00407
00408 if (len < sizeof buf) pbuf = buf;
00409 else pbuf = XtMalloc (len);
00410
00411 if (pbuf == NULL) return;
00412
00413 for(ns=s=ve->im.input_method; ns && *s;) {
00414
00415 while (*s && isspace(*s)) s++;
00416 if (!*s) break;
00417 if ((ns = end = strchr(s, ',')) == NULL)
00418 end = s + strlen(s);
00419
00420 while (isspace(*end)) end--;
00421
00422 strcpy (pbuf, "@im=");
00423 strncat (pbuf, s, end - s);
00424 pbuf[end - s + 4] = '\0';
00425
00426 if ((p = XSetLocaleModifiers(pbuf)) != NULL && *p
00427 && (xim = XOpenIM(XtDisplay(ve->parent), NULL, NULL, NULL)) != NULL)
00428 break;
00429
00430 s = ns + 1;
00431 }
00432
00433 if (pbuf != buf) XtFree (pbuf);
00434 }
00435 if (xim == NULL) {
00436 if ((p = XSetLocaleModifiers("")) != NULL) {
00437 xim = XOpenIM(XtDisplay(ve->parent), NULL, NULL, NULL);
00438 }
00439 }
00440 if (xim == NULL) {
00441 XtAppWarning(XtWidgetToApplicationContext(ve->parent),
00442 "Input Method Open Failed");
00443 return;
00444 }
00445 if (XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL)
00446 || !xim_styles) {
00447 XtAppWarning(XtWidgetToApplicationContext(ve->parent),
00448 "input method doesn't support any style");
00449 XCloseIM(xim);
00450 return;
00451 }
00452 found = False;
00453 for(ns = s = ve->im.preedit_type; s && !found;) {
00454 while (*s && isspace(*s)) s++;
00455 if (!*s) break;
00456 if ((ns = end = strchr(s, ',')) == NULL)
00457 end = s + strlen(s);
00458 while (isspace(*end)) end--;
00459
00460 if (!strncmp(s, "OverTheSpot", end - s)) {
00461 input_style = (XIMPreeditPosition | XIMStatusArea);
00462 } else if (!strncmp(s, "OffTheSpot", end - s)) {
00463 input_style = (XIMPreeditArea | XIMStatusArea);
00464 } else if (!strncmp(s, "Root", end - s)) {
00465 input_style = (XIMPreeditNothing | XIMStatusNothing);
00466 }
00467 for (i = 0; (unsigned short)i < xim_styles->count_styles; i++)
00468 if (input_style == xim_styles->supported_styles[i]) {
00469 ve->ic.input_style = input_style;
00470 SetErrCnxt(ve->parent, xim);
00471 ve->im.xim = xim;
00472 found = True;
00473 break;
00474 }
00475
00476 s = ns + 1;
00477 }
00478 XFree(xim_styles);
00479
00480 if (!found) {
00481 XCloseIM(xim);
00482 XtAppWarning(XtWidgetToApplicationContext(ve->parent),
00483 "input method doesn't support my input style");
00484 }
00485 }
00486
00487 static Boolean ResizeVendorShell_Core(vw, ve, p)
00488 VendorShellWidget vw;
00489 XawVendorShellExtPart * ve;
00490 XawIcTableList p;
00491 {
00492 XVaNestedList pe_attr, st_attr;
00493 XRectangle pe_area, st_area;
00494 XRectangle *get_pe_area = NULL, *get_st_area = NULL;
00495
00496 st_area.width = 0;
00497 if (p->input_style & XIMStatusArea) {
00498 st_attr = XVaCreateNestedList(0, XNArea, &get_st_area, NULL);
00499 XGetICValues(p->xic, XNStatusAttributes, st_attr, NULL);
00500 XFree(st_attr);
00501 if (p->xic == NULL) {
00502 return(FALSE);
00503 }
00504 st_area.x = 0;
00505 st_area.y = vw->core.height - ve->im.area_height;
00506 st_area.width = get_st_area->width;
00507 st_area.height = get_st_area->height;
00508 XFree(get_st_area);
00509 st_attr = XVaCreateNestedList(0, XNArea, &st_area, NULL);
00510 XSetICValues(p->xic, XNStatusAttributes, st_attr, NULL);
00511 XFree(st_attr);
00512 if (p->xic == NULL) {
00513 return(FALSE);
00514 }
00515 }
00516 if (p->input_style & XIMPreeditArea) {
00517 pe_attr = XVaCreateNestedList(0, XNArea, &get_pe_area, NULL);
00518 XGetICValues(p->xic, XNPreeditAttributes, pe_attr, NULL);
00519 XFree(pe_attr);
00520 if (p->xic == NULL) {
00521 return(FALSE);
00522 }
00523 pe_area.x = st_area.width;
00524 pe_area.y = vw->core.height - ve->im.area_height;
00525 pe_area.width = vw->core.width;
00526 pe_area.height = get_pe_area->height;
00527 if (p->input_style & XIMStatusArea) {
00528 pe_area.width -= st_area.width;
00529 }
00530 XFree(get_pe_area);
00531 pe_attr = XVaCreateNestedList(0, XNArea, &pe_area, NULL);
00532 XSetICValues(p->xic, XNPreeditAttributes, pe_attr, NULL);
00533 XFree(pe_attr);
00534 }
00535 return(TRUE);
00536 }
00537
00538 static void ResizeVendorShell(vw, ve)
00539 VendorShellWidget vw;
00540 XawVendorShellExtPart * ve;
00541 {
00542 XawIcTableList p;
00543
00544 if (IsSharedIC(ve)) {
00545 p = ve->ic.shared_ic_table;
00546 if (p->xic == NULL) return;
00547 ResizeVendorShell_Core(vw, ve, p);
00548 return;
00549 }
00550 for (p = ve->ic.ic_table; p; p = p->next) {
00551 if (p->xic == NULL) continue;
00552 if (ResizeVendorShell_Core(vw, ve, p) == FALSE) return;
00553 }
00554 }
00555
00556 static XawIcTableList CreateIcTable( w, ve )
00557 Widget w;
00558 XawVendorShellExtPart * ve;
00559 {
00560 XawIcTableList table;
00561
00562 table = (XawIcTableList) XtMalloc(sizeof(XawIcTablePart));
00563 if (table == NULL) return(NULL);
00564 table->widget = w;
00565 table->xic = NULL;
00566 table->flg = table->prev_flg = 0;
00567 table->font_set = NULL;
00568 table->foreground = table->background = 0xffffffff;
00569 table->bg_pixmap = 0;
00570 table->cursor_position = 0xffff;
00571 table->line_spacing = 0;
00572 table->ic_focused = FALSE;
00573 table->openic_error = FALSE;
00574 return(table);
00575 }
00576
00577 static Boolean RegisterToVendorShell( w, ve )
00578 Widget w;
00579 XawVendorShellExtPart * ve;
00580 {
00581 XawIcTableList table;
00582
00583 if ((table = CreateIcTable(w, ve)) == NULL) return(FALSE);
00584 table->next = ve->ic.ic_table;
00585 ve->ic.ic_table = table;
00586 return(TRUE);
00587 }
00588
00589 static void UnregisterFromVendorShell(w, ve)
00590 Widget w;
00591 XawVendorShellExtPart * ve;
00592 {
00593 XawIcTableList *prev, p;
00594
00595 for (prev = &ve->ic.ic_table; (p = *prev); prev = &p->next) {
00596 if (p->widget == w) {
00597 *prev = p->next;
00598 XtFree((char *)p);
00599 break;
00600 }
00601 }
00602 return;
00603 }
00604
00605 static void SetICValuesShared(w, ve, p, check)
00606 Widget w;
00607 XawVendorShellExtPart * ve;
00608 XawIcTableList p;
00609 Boolean check;
00610 {
00611 XawIcTableList pp;
00612
00613 if ((pp = GetIcTable(w, ve)) == NULL) return;
00614 if (check == TRUE && CurrentSharedIcTable(ve) != pp) return;
00615
00616 if (pp->prev_flg & CICursorP && p->cursor_position != pp->cursor_position) {
00617 p->cursor_position = pp->cursor_position;
00618 p->flg |= CICursorP;
00619 }
00620 if (pp->prev_flg & CIFontSet && p->font_set != pp->font_set) {
00621 p->font_set = pp->font_set;
00622 p->flg |= (CIFontSet|CICursorP);
00623 }
00624 if (pp->prev_flg & CIFg && p->foreground != pp->foreground) {
00625 p->foreground = pp->foreground;
00626 p->flg |= CIFg;
00627 }
00628 if (pp->prev_flg & CIBg && p->background != pp->background) {
00629 p->background = pp->background;
00630 p->flg |= CIBg;
00631 }
00632 if (pp->prev_flg & CIBgPixmap && p->bg_pixmap != pp->bg_pixmap) {
00633 p->bg_pixmap = pp->bg_pixmap;
00634 p->flg |= CIBgPixmap;
00635 }
00636 if (pp->prev_flg & CILineS && p->line_spacing != pp->line_spacing) {
00637 p->line_spacing = pp->line_spacing;
00638 p->flg |= CILineS;
00639 }
00640 }
00641
00642 static Boolean IsCreatedIC(w, ve)
00643 Widget w;
00644 XawVendorShellExtPart * ve;
00645 {
00646 XawIcTableList p;
00647
00648 if (ve->im.xim == NULL) return(FALSE);
00649 if ((p = GetIcTableShared(w, ve)) == NULL) return(FALSE);
00650 if (p->xic == NULL) return(FALSE);
00651 return(TRUE);
00652 }
00653
00654 static void SizeNegotiation(p, width, height)
00655 XawIcTableList p;
00656 Dimension width, height;
00657 {
00658 XRectangle pe_area, st_area;
00659 XVaNestedList pe_attr = NULL, st_attr = NULL;
00660 int ic_cnt = 0, pe_cnt = 0, st_cnt = 0;
00661 XRectangle *pe_area_needed = NULL, *st_area_needed = NULL;
00662 XPointer ic_a[5];
00663
00664 if (p->input_style & XIMPreeditArea) {
00665 pe_attr = XVaCreateNestedList(0, XNAreaNeeded, &pe_area_needed, NULL);
00666 SetVaArg( &ic_a[ic_cnt], (XPointer) XNPreeditAttributes); ic_cnt++;
00667 SetVaArg( &ic_a[ic_cnt], (XPointer) pe_attr); ic_cnt++;
00668 }
00669 if (p->input_style & XIMStatusArea) {
00670 st_attr = XVaCreateNestedList(0, XNAreaNeeded, &st_area_needed, NULL);
00671 SetVaArg( &ic_a[ic_cnt], (XPointer) XNStatusAttributes); ic_cnt++;
00672 SetVaArg( &ic_a[ic_cnt], (XPointer) st_attr); ic_cnt++;
00673 }
00674 SetVaArg( &ic_a[ic_cnt], (XPointer) NULL);
00675
00676 if (ic_cnt > 0) {
00677 XGetICValues(p->xic, ic_a[0], ic_a[1], ic_a[2], ic_a[3], ic_a[4]);
00678 if (pe_attr) XFree(pe_attr);
00679 if (st_attr) XFree(st_attr);
00680 if (p->xic == NULL) {
00681 p->openic_error = True;
00682 return;
00683 }
00684 pe_attr = st_attr = NULL;
00685 ic_cnt = pe_cnt = st_cnt = 0;
00686 if (p->input_style & XIMStatusArea) {
00687 st_area.height = st_area_needed->height;
00688 st_area.x = 0;
00689 st_area.y = height - st_area.height;
00690 if (p->input_style & XIMPreeditArea) {
00691 st_area.width = st_area_needed->width;
00692 } else {
00693 st_area.width = width;
00694 }
00695
00696 XFree(st_area_needed);
00697 st_attr = XVaCreateNestedList(0, XNArea, &st_area, NULL);
00698 SetVaArg( &ic_a[ic_cnt], (XPointer) XNStatusAttributes); ic_cnt++;
00699 SetVaArg( &ic_a[ic_cnt], (XPointer) st_attr); ic_cnt++;
00700 }
00701 if (p->input_style & XIMPreeditArea) {
00702 if (p->input_style & XIMStatusArea) {
00703 pe_area.x = st_area.width;
00704 pe_area.width = width - st_area.width;
00705 } else {
00706 pe_area.x = 0;
00707 pe_area.width = width;
00708 }
00709 pe_area.height = pe_area_needed->height;
00710 XFree(pe_area_needed);
00711 pe_area.y = height - pe_area.height;
00712 pe_attr = XVaCreateNestedList(0, XNArea, &pe_area, NULL);
00713 SetVaArg( &ic_a[ic_cnt], (XPointer) XNPreeditAttributes); ic_cnt++;
00714 SetVaArg( &ic_a[ic_cnt], (XPointer) pe_attr); ic_cnt++;
00715 }
00716 SetVaArg( &ic_a[ic_cnt], (XPointer) NULL);
00717 XSetICValues(p->xic, ic_a[0], ic_a[1], ic_a[2], ic_a[3], ic_a[4]);
00718 if (pe_attr) XFree(pe_attr);
00719 if (st_attr) XFree(st_attr);
00720 if (p->xic == NULL) {
00721 p->openic_error = True;
00722 return;
00723 }
00724 }
00725 }
00726
00727 static void CreateIC( w, ve )
00728 Widget w;
00729 XawVendorShellExtPart* ve;
00730 {
00731 XawIcTableList p;
00732 XPoint position;
00733 XRectangle pe_area, st_area;
00734 XVaNestedList pe_attr = NULL, st_attr = NULL;
00735 XPointer ic_a[20], pe_a[20], st_a[20];
00736 Dimension height = 0;
00737 int ic_cnt = 0, pe_cnt = 0, st_cnt = 0;
00738 XawTextMargin *margin;
00739
00740 if (!XtIsRealized(w)) return;
00741 if (((ve->im.xim == NULL) || (p = GetIcTableShared(w, ve)) == NULL) ||
00742 p->xic || (p->openic_error != FALSE)) return;
00743
00744 p->input_style = GetInputStyleOfIC(ve);
00745
00746 if (IsSharedIC(ve)) SetICValuesShared(w, ve, p, FALSE);
00747 XFlush(XtDisplay(w));
00748
00749 if (p->input_style & (XIMPreeditArea|XIMPreeditPosition|XIMStatusArea)) {
00750 if (p->flg & CIFontSet) {
00751 SetVaArg( &pe_a[pe_cnt], (XPointer) XNFontSet); pe_cnt++;
00752 SetVaArg( &pe_a[pe_cnt], (XPointer) p->font_set); pe_cnt++;
00753 SetVaArg( &st_a[st_cnt], (XPointer) XNFontSet); st_cnt++;
00754 SetVaArg( &st_a[st_cnt], (XPointer) p->font_set); st_cnt++;
00755 height = maxAscentOfFontSet(p->font_set)
00756 + maxDescentOfFontSet(p->font_set);
00757 height = SetVendorShellHeight(ve, height);
00758 }
00759 if (p->flg & CIFg) {
00760 SetVaArg( &pe_a[pe_cnt], (XPointer) XNForeground); pe_cnt++;
00761 SetVaArg( &pe_a[pe_cnt], (XPointer) p->foreground); pe_cnt++;
00762 SetVaArg( &st_a[st_cnt], (XPointer) XNForeground); st_cnt++;
00763 SetVaArg( &st_a[st_cnt], (XPointer) p->foreground); st_cnt++;
00764 }
00765 if (p->flg & CIBg) {
00766 SetVaArg( &pe_a[pe_cnt], (XPointer) XNBackground); pe_cnt++;
00767 SetVaArg( &pe_a[pe_cnt], (XPointer) p->background); pe_cnt++;
00768 SetVaArg( &st_a[st_cnt], (XPointer) XNBackground); st_cnt++;
00769 SetVaArg( &st_a[st_cnt], (XPointer) p->background); st_cnt++;
00770 }
00771 if (p->flg & CIBgPixmap) {
00772 SetVaArg( &pe_a[pe_cnt], (XPointer) XNBackgroundPixmap); pe_cnt++;
00773 SetVaArg( &pe_a[pe_cnt], (XPointer) p->bg_pixmap); pe_cnt++;
00774 SetVaArg( &st_a[st_cnt], (XPointer) XNBackgroundPixmap); st_cnt++;
00775 SetVaArg( &st_a[st_cnt], (XPointer) p->bg_pixmap); st_cnt++;
00776 }
00777 if (p->flg & CILineS) {
00778 SetVaArg( &pe_a[pe_cnt], (XPointer) XNLineSpace); pe_cnt++;
00779 SetVaArg( &pe_a[pe_cnt], (XPointer) p->line_spacing); pe_cnt++;
00780 SetVaArg( &st_a[st_cnt], (XPointer) XNLineSpace); st_cnt++;
00781 SetVaArg( &st_a[st_cnt], (XPointer) p->line_spacing); st_cnt++;
00782 }
00783 }
00784 if (p->input_style & XIMPreeditArea) {
00785 pe_area.x = 0;
00786 pe_area.y = ve->parent->core.height - height;
00787 pe_area.width = ve->parent->core.width;
00788 pe_area.height = height;
00789 SetVaArg( &pe_a[pe_cnt], (XPointer) XNArea); pe_cnt++;
00790 SetVaArg( &pe_a[pe_cnt], (XPointer) &pe_area); pe_cnt++;
00791 }
00792 if (p->input_style & XIMPreeditPosition) {
00793 pe_area.x = 0;
00794 pe_area.y = 0;
00795 pe_area.width = w->core.width;
00796 pe_area.height = w->core.height;
00797 margin = &(((TextWidget)w)->text.margin);
00798 pe_area.x += margin->left;
00799 pe_area.y += margin->top;
00800 pe_area.width -= (margin->left + margin->right - 1);
00801 pe_area.height -= (margin->top + margin->bottom - 1);
00802 SetVaArg( &pe_a[pe_cnt], (XPointer) XNArea); pe_cnt++;
00803 SetVaArg( &pe_a[pe_cnt], (XPointer) &pe_area); pe_cnt++;
00804 if (p->flg & CICursorP) {
00805 _XawMultiSinkPosToXY(w, p->cursor_position, &position.x, &position.y);
00806 } else {
00807 position.x = position.y = 0;
00808 }
00809 SetVaArg( &pe_a[pe_cnt], (XPointer) XNSpotLocation); pe_cnt++;
00810 SetVaArg( &pe_a[pe_cnt], (XPointer) &position); pe_cnt++;
00811 }
00812 if (p->input_style & XIMStatusArea) {
00813 st_area.x = 0;
00814 st_area.y = ve->parent->core.height - height;
00815 st_area.width = ve->parent->core.width;
00816 st_area.height = height;
00817 SetVaArg( &st_a[st_cnt], (XPointer) XNArea); st_cnt++;
00818 SetVaArg( &st_a[st_cnt], (XPointer) &st_area); st_cnt++;
00819 }
00820
00821 SetVaArg( &ic_a[ic_cnt], (XPointer) XNInputStyle); ic_cnt++;
00822 SetVaArg( &ic_a[ic_cnt], (XPointer) p->input_style); ic_cnt++;
00823 SetVaArg( &ic_a[ic_cnt], (XPointer) XNClientWindow); ic_cnt++;
00824 SetVaArg( &ic_a[ic_cnt], (XPointer) XtWindow(ve->parent)); ic_cnt++;
00825 SetVaArg( &ic_a[ic_cnt], (XPointer) XNFocusWindow); ic_cnt++;
00826 SetVaArg( &ic_a[ic_cnt], (XPointer) XtWindow(w)); ic_cnt++;
00827
00828 if (pe_cnt > 0) {
00829 SetVaArg( &pe_a[pe_cnt], (XPointer) NULL);
00830 pe_attr = XVaCreateNestedList(0, pe_a[0], pe_a[1], pe_a[2], pe_a[3],
00831 pe_a[4], pe_a[5], pe_a[6], pe_a[7], pe_a[8],
00832 pe_a[9], pe_a[10], pe_a[11], pe_a[12],
00833 pe_a[13], pe_a[14], pe_a[15], pe_a[16],
00834 pe_a[17], pe_a[18], pe_a[19]);
00835 SetVaArg( &ic_a[ic_cnt], (XPointer) XNPreeditAttributes); ic_cnt++;
00836 SetVaArg( &ic_a[ic_cnt], (XPointer) pe_attr); ic_cnt++;
00837 }
00838
00839 if (st_cnt > 0) {
00840 SetVaArg( &st_a[st_cnt], (XPointer) NULL);
00841 st_attr = XVaCreateNestedList(0, st_a[0], st_a[1], st_a[2], st_a[3],
00842 st_a[4], st_a[5], st_a[6], st_a[7], st_a[8],
00843 st_a[9], st_a[10], st_a[11], st_a[12],
00844 st_a[13], st_a[14], st_a[15], st_a[16],
00845 st_a[17], st_a[18], st_a[19]);
00846 SetVaArg( &ic_a[ic_cnt], (XPointer) XNStatusAttributes); ic_cnt++;
00847 SetVaArg( &ic_a[ic_cnt], (XPointer) st_attr); ic_cnt++;
00848 }
00849 SetVaArg( &ic_a[ic_cnt], (XPointer) NULL);
00850
00851 p->xic = XCreateIC(ve->im.xim, ic_a[0], ic_a[1], ic_a[2], ic_a[3],
00852 ic_a[4], ic_a[5], ic_a[6], ic_a[7], ic_a[8], ic_a[9],
00853 ic_a[10], ic_a[11], ic_a[12], ic_a[13], ic_a[14],
00854 ic_a[15], ic_a[16], ic_a[17], ic_a[18], ic_a[19]);
00855 if (pe_attr) XtFree(pe_attr);
00856 if (st_attr) XtFree(st_attr);
00857
00858 if (p->xic == NULL) {
00859 p->openic_error = True;
00860 return;
00861 }
00862
00863 SizeNegotiation(p, ve->parent->core.width, ve->parent->core.height);
00864
00865 p->flg &= ~(CIFontSet | CIFg | CIBg | CIBgPixmap | CICursorP | CILineS);
00866
00867 if (!IsSharedIC(ve)) {
00868 if (p->input_style & XIMPreeditPosition) {
00869 XtAddEventHandler(w, (EventMask)StructureNotifyMask, FALSE,
00870 (XtEventHandler)ConfigureCB, (Opaque)NULL);
00871 }
00872 }
00873 }
00874
00875 static void SetICValues( w, ve, focus )
00876 Widget w;
00877 XawVendorShellExtPart *ve;
00878 Boolean focus;
00879 {
00880 XawIcTableList p;
00881 XPoint position;
00882 XRectangle pe_area;
00883 XVaNestedList pe_attr = NULL, st_attr = NULL;
00884 XPointer ic_a[20], pe_a[20], st_a[20];
00885 int ic_cnt = 0, pe_cnt = 0, st_cnt = 0;
00886 XawTextMargin *margin;
00887 int height;
00888
00889 if ((ve->im.xim == NULL) || ((p = GetIcTableShared(w, ve)) == NULL) ||
00890 (p->xic == NULL)) return;
00891
00892 if (IsSharedIC(ve)) SetICValuesShared(w, ve, p, TRUE);
00893 XFlush(XtDisplay(w));
00894 if (focus == FALSE &&
00895 !(p->flg & (CIFontSet | CIFg | CIBg |
00896 CIBgPixmap | CICursorP | CILineS))) return;
00897 #ifdef SPOT
00898 if ((p->input_style & XIMPreeditPosition)
00899 && ((!IsSharedIC(ve) && ((p->flg & ~CIICFocus) == CICursorP))
00900 || (IsSharedIC(ve) && p->flg == CICursorP))) {
00901 _XawMultiSinkPosToXY(w, p->cursor_position, &position.x, &position.y);
00902 _XipChangeSpot(p->xic, position.x, position.y);
00903 p->flg &= ~CICursorP;
00904 return;
00905 }
00906 #endif
00907
00908 if (p->input_style & (XIMPreeditArea|XIMPreeditPosition|XIMStatusArea)) {
00909 if (p->flg & CIFontSet) {
00910 SetVaArg( &pe_a[pe_cnt], (XPointer) XNFontSet); pe_cnt++;
00911 SetVaArg( &pe_a[pe_cnt], (XPointer) p->font_set); pe_cnt++;
00912 SetVaArg( &st_a[st_cnt], (XPointer) XNFontSet); st_cnt++;
00913 SetVaArg( &st_a[st_cnt], (XPointer) p->font_set); st_cnt++;
00914 height = maxAscentOfFontSet(p->font_set)
00915 + maxDescentOfFontSet(p->font_set);
00916 height = SetVendorShellHeight(ve, height);
00917 }
00918 if (p->flg & CIFg) {
00919 SetVaArg( &pe_a[pe_cnt], (XPointer) XNForeground); pe_cnt++;
00920 SetVaArg( &pe_a[pe_cnt], (XPointer) p->foreground); pe_cnt++;
00921 SetVaArg( &st_a[st_cnt], (XPointer) XNForeground); st_cnt++;
00922 SetVaArg( &st_a[st_cnt], (XPointer) p->foreground); st_cnt++;
00923 }
00924 if (p->flg & CIBg) {
00925 SetVaArg( &pe_a[pe_cnt], (XPointer) XNBackground); pe_cnt++;
00926 SetVaArg( &pe_a[pe_cnt], (XPointer) p->background); pe_cnt++;
00927 SetVaArg( &st_a[st_cnt], (XPointer) XNBackground); st_cnt++;
00928 SetVaArg( &st_a[st_cnt], (XPointer) p->background); st_cnt++;
00929 }
00930 if (p->flg & CIBgPixmap) {
00931 SetVaArg( &pe_a[pe_cnt], (XPointer) XNBackgroundPixmap); pe_cnt++;
00932 SetVaArg( &pe_a[pe_cnt], (XPointer) p->bg_pixmap); pe_cnt++;
00933 SetVaArg( &st_a[st_cnt], (XPointer) XNBackgroundPixmap); st_cnt++;
00934 SetVaArg( &st_a[st_cnt], (XPointer) p->bg_pixmap); st_cnt++;
00935 }
00936 if (p->flg & CILineS) {
00937 SetVaArg( &pe_a[pe_cnt], (XPointer) XNLineSpace); pe_cnt++;
00938 SetVaArg( &pe_a[pe_cnt], (XPointer) p->line_spacing); pe_cnt++;
00939 SetVaArg( &st_a[st_cnt], (XPointer) XNLineSpace); st_cnt++;
00940 SetVaArg( &st_a[st_cnt], (XPointer) p->line_spacing); st_cnt++;
00941 }
00942 }
00943 if (p->input_style & XIMPreeditPosition) {
00944 if (p->flg & CICursorP) {
00945 _XawMultiSinkPosToXY(w, p->cursor_position, &position.x, &position.y);
00946 SetVaArg( &pe_a[pe_cnt], (XPointer) XNSpotLocation); pe_cnt++;
00947 SetVaArg( &pe_a[pe_cnt], (XPointer) &position); pe_cnt++;
00948 }
00949 }
00950 if (IsSharedIC(ve)) {
00951 if (p->input_style & XIMPreeditPosition) {
00952 pe_area.x = 0;
00953 pe_area.y = 0;
00954 pe_area.width = w->core.width;
00955 pe_area.height = w->core.height;
00956 margin = &(((TextWidget)w)->text.margin);
00957 pe_area.x += margin->left;
00958 pe_area.y += margin->top;
00959 pe_area.width -= (margin->left + margin->right - 1);
00960 pe_area.height -= (margin->top + margin->bottom - 1);
00961 SetVaArg( &pe_a[pe_cnt], (XPointer) XNArea); pe_cnt++;
00962 SetVaArg( &pe_a[pe_cnt], (XPointer) &pe_area); pe_cnt++;
00963 }
00964 }
00965
00966 if (pe_cnt > 0) {
00967 SetVaArg( &pe_a[pe_cnt], (XPointer) NULL);
00968 pe_attr = XVaCreateNestedList(0, pe_a[0], pe_a[1], pe_a[2], pe_a[3],
00969 pe_a[4], pe_a[5], pe_a[6], pe_a[7],
00970 pe_a[8], pe_a[9], pe_a[10], pe_a[11],
00971 pe_a[12], pe_a[13], pe_a[14], pe_a[15],
00972 pe_a[16], pe_a[17], pe_a[18], pe_a[19]);
00973 SetVaArg( &ic_a[ic_cnt], (XPointer) XNPreeditAttributes); ic_cnt++;
00974 SetVaArg( &ic_a[ic_cnt], (XPointer) pe_attr); ic_cnt++;
00975 }
00976 if (st_cnt > 0) {
00977 SetVaArg( &st_a[st_cnt], (XPointer) NULL);
00978 st_attr = XVaCreateNestedList(0, st_a[0], st_a[1], st_a[2], st_a[3],
00979 st_a[4], st_a[5], st_a[6], st_a[7],
00980 st_a[8], st_a[9], st_a[10], st_a[11],
00981 st_a[12], st_a[13], st_a[14], st_a[15],
00982 st_a[16], st_a[17], st_a[18], st_a[19]);
00983 SetVaArg( &ic_a[ic_cnt], (XPointer) XNStatusAttributes); ic_cnt++;
00984 SetVaArg( &ic_a[ic_cnt], (XPointer) st_attr); ic_cnt++;
00985 }
00986 if (focus == TRUE) {
00987 SetVaArg( &ic_a[ic_cnt], (XPointer) XNFocusWindow); ic_cnt++;
00988 SetVaArg( &ic_a[ic_cnt], (XPointer) XtWindow(w)); ic_cnt++;
00989 }
00990 if (ic_cnt > 0) {
00991 SetVaArg( &ic_a[ic_cnt], (XPointer) NULL);
00992 XSetICValues(p->xic, ic_a[0], ic_a[1], ic_a[2], ic_a[3], ic_a[4],
00993 ic_a[5], ic_a[6], ic_a[7], ic_a[8], ic_a[9], ic_a[10],
00994 ic_a[11], ic_a[12], ic_a[13], ic_a[14], ic_a[15],
00995 ic_a[16], ic_a[17], ic_a[18], ic_a[19]);
00996 if (pe_attr) XtFree(pe_attr);
00997 if (st_attr) XtFree(st_attr);
00998 }
00999
01000 if (IsSharedIC(ve) && p->flg & CIFontSet)
01001 SizeNegotiation(p, ve->parent->core.width, ve->parent->core.height);
01002
01003 p->flg &= ~(CIFontSet | CIFg | CIBg | CIBgPixmap | CICursorP | CILineS);
01004 }
01005
01006 static void SharedICChangeFocusWindow(w, ve, p)
01007 Widget w;
01008 XawVendorShellExtPart *ve;
01009 XawIcTableList p;
01010 {
01011 XawIcTableList pp;
01012
01013 if (w == NULL) {
01014 ve->ic.current_ic_table = NULL;
01015 return;
01016 }
01017 if ((pp = GetIcTable(w, ve)) == NULL) return;
01018 ve->ic.current_ic_table = pp;
01019 SetICValues(w, ve, TRUE);
01020 }
01021
01022 static XawIcTableList CurrentSharedIcTable( ve )
01023 XawVendorShellExtPart * ve;
01024 {
01025 return(ve->ic.current_ic_table);
01026 }
01027
01028 static void SetICFocus(w, ve)
01029 Widget w;
01030 XawVendorShellExtPart * ve;
01031 {
01032 XawIcTableList p, pp;
01033
01034 if ((ve->im.xim == NULL) || ((p = GetIcTableShared(w, ve)) == NULL) ||
01035 (p->xic == NULL)) return;
01036
01037 if (IsSharedIC(ve)) {
01038 pp = CurrentSharedIcTable(ve);
01039 if (pp == NULL || pp->widget != w) {
01040 SharedICChangeFocusWindow(w, ve, p);
01041 }
01042 }
01043 if (p->flg & CIICFocus && p->ic_focused == FALSE) {
01044 p->ic_focused = TRUE;
01045 XSetICFocus(p->xic);
01046 }
01047 p->flg &= ~CIICFocus;
01048 }
01049
01050 static void UnsetICFocus(w, ve)
01051 Widget w;
01052 XawVendorShellExtPart * ve;
01053 {
01054 XawIcTableList p, pp;
01055
01056 if ((ve->im.xim == NULL) || ((p = GetIcTableShared(w, ve)) == NULL) ||
01057 (p->xic == NULL)) return;
01058
01059 if (IsSharedIC(ve) && (pp = CurrentSharedIcTable(ve))) {
01060 if (pp->widget != w) {
01061 return;
01062 }
01063 SharedICChangeFocusWindow(NULL, ve, p);
01064 }
01065 if (p->ic_focused == TRUE) {
01066 XUnsetICFocus(p->xic);
01067 p->ic_focused = FALSE;
01068 }
01069 }
01070
01071 static void SetValues( w, ve, args, num_args )
01072 Widget w;
01073 XawVendorShellExtPart * ve;
01074 ArgList args;
01075 Cardinal num_args;
01076 {
01077 ArgList arg;
01078
01079 XrmName argName;
01080 XrmResourceList xrmres;
01081 int i;
01082 XawIcTablePart *p, save_tbl;
01083
01084 if ((p = GetIcTable(w, ve)) == NULL) return;
01085
01086 memcpy(&save_tbl, p, sizeof(XawIcTablePart));
01087
01088 for (arg = args ; num_args != 0; num_args--, arg++) {
01089 argName = XrmStringToName(arg->name);
01090 for (xrmres = (XrmResourceList)ve->im.resources, i = 0;
01091 i < ve->im.num_resources; i++, xrmres++) {
01092 if (argName == xrmres->xrm_name) {
01093 _XtCopyFromArg(arg->value,
01094 (char *)p - xrmres->xrm_offset - 1,
01095 xrmres->xrm_size);
01096 break;
01097 }
01098 }
01099 }
01100 if (p->font_set != save_tbl.font_set) {
01101 p->flg |= CIFontSet;
01102 }
01103 if (p->foreground != save_tbl.foreground) {
01104 p->flg |= CIFg;
01105 }
01106 if (p->background !=save_tbl.background) {
01107 p->flg |= CIBg;
01108 }
01109 if (p->bg_pixmap != save_tbl.bg_pixmap) {
01110 p->flg |= CIBgPixmap;
01111 }
01112 if (p->cursor_position != save_tbl.cursor_position) {
01113 p->flg |= CICursorP;
01114 }
01115 if (p->line_spacing != save_tbl.line_spacing) {
01116 p->flg |= CILineS;
01117 }
01118 p->prev_flg |= p->flg;
01119 }
01120
01121 static void SetFocus( w, ve )
01122 Widget w;
01123 XawVendorShellExtPart *ve;
01124 {
01125 XawIcTableList p;
01126 if ((p = GetIcTableShared(w, ve)) == NULL) return;
01127
01128 if ( p->ic_focused == FALSE || IsSharedIC(ve)) {
01129 p->flg |= CIICFocus;
01130 }
01131 p->prev_flg |= p->flg;
01132 }
01133
01134 static void DestroyIC(w, ve)
01135 Widget w;
01136 XawVendorShellExtPart *ve;
01137 {
01138 XawIcTableList p;
01139
01140 if ((ve->im.xim == NULL) || ((p = GetIcTableShared(w, ve)) == NULL) ||
01141 (p->xic == NULL)) return;
01142 if (IsSharedIC(ve)) {
01143 if (GetIcTable(w, ve) == ve->ic.current_ic_table) {
01144 UnsetICFocus(w, ve);
01145 }
01146 return;
01147 }
01148 XDestroyIC(p->xic);
01149 if (!IsSharedIC(ve)) {
01150 if (p->input_style & XIMPreeditPosition) {
01151 XtRemoveEventHandler(w, (EventMask)StructureNotifyMask, FALSE,
01152 (XtEventHandler)ConfigureCB, (Opaque)NULL);
01153 }
01154 }
01155 }
01156
01157 static void SetFocusValues( inwidg, args, num_args, focus )
01158 Widget inwidg;
01159 ArgList args;
01160 Cardinal num_args;
01161 Boolean focus;
01162 {
01163 XawVendorShellExtPart *ve;
01164 VendorShellWidget vw;
01165
01166 if ((vw = SearchVendorShell(inwidg)) == NULL) return;
01167 if ((ve = GetExtPart(vw))) {
01168 if (num_args > 0) SetValues(inwidg, ve, args, num_args);
01169 if (focus) SetFocus(inwidg, ve);
01170 if (XtIsRealized((Widget)vw) && ve->im.xim) {
01171 if (IsCreatedIC(inwidg, ve)) {
01172 SetICValues(inwidg, ve, FALSE);
01173 if (focus) SetICFocus(inwidg, ve);
01174 } else {
01175 CreateIC(inwidg, ve);
01176 SetICFocus(inwidg, ve);
01177 }
01178 }
01179 }
01180 }
01181
01182 static void UnsetFocus( inwidg )
01183 Widget inwidg;
01184 {
01185 XawVendorShellExtPart *ve;
01186 VendorShellWidget vw;
01187 XawIcTableList p;
01188
01189 if ((vw = SearchVendorShell(inwidg)) == NULL) return;
01190 if ((ve = GetExtPart(vw))) {
01191 if ((p = GetIcTableShared(inwidg, ve)) == NULL) return;
01192 if (p->flg & CIICFocus) {
01193 p->flg &= ~CIICFocus;
01194 }
01195 p->prev_flg &= ~CIICFocus;
01196 if (ve->im.xim && XtIsRealized((Widget)vw) && p->xic) {
01197 UnsetICFocus(inwidg, ve);
01198 }
01199 }
01200 }
01201
01202 static Boolean IsRegistered( w, ve )
01203 Widget w;
01204 XawVendorShellExtPart* ve;
01205 {
01206 XawIcTableList p;
01207
01208 for (p = ve->ic.ic_table; p; p = p->next)
01209 {
01210 if (p->widget == w) return(TRUE);
01211 }
01212 return(FALSE);
01213 }
01214
01215 static void Register(inwidg, ve)
01216 Widget inwidg;
01217 XawVendorShellExtPart* ve;
01218 {
01219 if (ve->im.xim == NULL)
01220 {
01221 OpenIM(ve);
01222 }
01223
01224 if (IsRegistered(inwidg, ve)) return;
01225
01226 if (RegisterToVendorShell(inwidg, ve) == FALSE) return;
01227
01228 if (ve->im.xim == NULL) return;
01229
01230 if (XtIsRealized(ve->parent))
01231 {
01232 CreateIC(inwidg, ve);
01233 SetICFocus(inwidg, ve);
01234 }
01235 }
01236
01237 static Boolean NoRegistered(ve)
01238 XawVendorShellExtPart* ve;
01239 {
01240 if (ve->ic.ic_table == NULL) return(TRUE);
01241 return(FALSE);
01242 }
01243
01244 static void Unregister(inwidg, ve)
01245 Widget inwidg;
01246 XawVendorShellExtPart* ve;
01247 {
01248 if (!IsRegistered(inwidg, ve)) return;
01249
01250 DestroyIC(inwidg, ve);
01251
01252 UnregisterFromVendorShell(inwidg, ve);
01253
01254 if (NoRegistered(ve))
01255 {
01256 CloseIM(ve);
01257 ve->im.xim = NULL;
01258
01259
01260
01261 (void) SetVendorShellHeight(ve, 0);
01262 }
01263 }
01264
01265 static void AllCreateIC( ve )
01266 XawVendorShellExtPart* ve;
01267 {
01268 XawIcTableList p;
01269
01270 if (ve->im.xim == NULL) return;
01271 if (IsSharedIC(ve) && ve->ic.ic_table[0].widget) {
01272 p = ve->ic.shared_ic_table;
01273 if (p->xic == NULL)
01274 CreateIC(ve->ic.ic_table[0].widget, ve);
01275 SetICFocus(ve->ic.ic_table[0].widget, ve);
01276 return;
01277 }
01278 for (p = ve->ic.ic_table; p; p = p->next) {
01279 if (p->xic == NULL)
01280 CreateIC(p->widget, ve);
01281 }
01282 for (p = ve->ic.ic_table; p; p = p->next) {
01283 SetICFocus(p->widget, ve);
01284 }
01285 }
01286
01287
01288 static void Reconnect(ve)
01289 XawVendorShellExtPart* ve;
01290 {
01291 XawIcTableList p;
01292
01293 ve->im.open_im = True;
01294 if (ve->im.xim == NULL) {
01295 OpenIM(ve);
01296 }
01297 if (ve->im.xim == NULL) return;
01298
01299 if (IsSharedIC(ve)) {
01300 p = ve->ic.shared_ic_table;
01301 p->flg = p->prev_flg;
01302 p->openic_error = FALSE;
01303 } else {
01304 for (p = ve->ic.ic_table; p; p = p->next) {
01305 p->flg = p->prev_flg;
01306 p->openic_error = FALSE;
01307 }
01308 }
01309 AllCreateIC(ve);
01310 }
01311
01312
01313 static void CompileResourceList( res, num_res )
01314 XtResourceList res;
01315 unsigned int num_res;
01316 {
01317 unsigned int count;
01318
01319 #define xrmres ((XrmResourceList) res)
01320 for (count = 0; count < num_res; res++, count++) {
01321 xrmres->xrm_name = XrmPermStringToQuark(res->resource_name);
01322 xrmres->xrm_class = XrmPermStringToQuark(res->resource_class);
01323 xrmres->xrm_type = XrmPermStringToQuark(res->resource_type);
01324 xrmres->xrm_offset = -res->resource_offset - 1;
01325 xrmres->xrm_default_type = XrmPermStringToQuark(res->default_type);
01326 }
01327 #undef xrmres
01328 }
01329
01330 static Boolean Initialize( vw, ve )
01331 VendorShellWidget vw;
01332 XawVendorShellExtPart* ve;
01333 {
01334 int i;
01335
01336 if (!XtIsVendorShell((Widget)vw)) return(FALSE);
01337 ve->parent = (Widget)vw;
01338 ve->im.xim = NULL;
01339 ve->im.area_height = 0;
01340 ve->im.resources = (XrmResourceList)XtMalloc(sizeof(resources));
01341 if (ve->im.resources == NULL) return(FALSE);
01342 memcpy((char *)ve->im.resources, (char *)resources, sizeof(resources));
01343 ve->im.num_resources = XtNumber(resources);
01344 CompileResourceList( (XtResourceList) ve->im.resources,
01345 ve->im.num_resources );
01346 if ((ve->ic.shared_ic_table = CreateIcTable( (Widget)vw, ve)) == NULL)
01347 return(FALSE);
01348 ve->ic.current_ic_table = NULL;
01349 ve->ic.ic_table = NULL;
01350 return(TRUE);
01351 }
01352
01353
01354
01355
01356
01357
01358
01359
01360 static void Destroy( w, ve )
01361 Widget w;
01362 XawVendorShellExtPart* ve;
01363 {
01364 contextDataRec *contextData;
01365 contextErrDataRec *contextErrData;
01366
01367 if (!XtIsVendorShell( w ) )
01368 return;
01369 XtFree( (char*) ve->im.resources );
01370
01371 if (extContext != (XContext)NULL &&
01372 !XFindContext (XtDisplay (w), (Window)w,
01373 extContext, (XPointer*)&contextData))
01374 XtFree( (char*) contextData );
01375
01376 if (errContext != (XContext)NULL &&
01377 !XFindContext (XDisplayOfIM( ve->im.xim ), (Window) ve->im.xim,
01378 errContext, (XPointer*) &contextErrData))
01379 XtFree( (char*) contextErrData );
01380 }
01381
01382
01383
01384
01385
01386
01387
01388
01389 void
01390 #if NeedFunctionPrototypes
01391 _XawImResizeVendorShell(
01392 Widget w )
01393 #else
01394 _XawImResizeVendorShell( w )
01395 Widget w;
01396 #endif
01397 {
01398 XawVendorShellExtPart *ve;
01399
01400 if ( ( ve = GetExtPart( (VendorShellWidget) w ) ) && ve->im.xim ) {
01401 ResizeVendorShell( (VendorShellWidget) w, ve );
01402 }
01403 }
01404
01405
01406 Dimension
01407 #if NeedFunctionPrototypes
01408 _XawImGetShellHeight(
01409 Widget w )
01410 #else
01411 _XawImGetShellHeight( w )
01412 Widget w;
01413 #endif
01414 {
01415 XawVendorShellExtPart *ve;
01416
01417 if (!XtIsVendorShell( w ) ) return( w->core.height );
01418 if ((ve = GetExtPart( (VendorShellWidget) w ))) {
01419 return( w->core.height - ve->im.area_height );
01420 }
01421 return( w->core.height );
01422 }
01423
01424 void
01425 #if NeedFunctionPrototypes
01426 _XawImRealize(
01427 Widget w )
01428 #else
01429 _XawImRealize( w )
01430 Widget w;
01431 #endif
01432 {
01433 XawVendorShellExtPart *ve;
01434 extern void XawVendorShellExtResize();
01435
01436 if ( !XtIsRealized( w ) || !XtIsVendorShell( w ) ) return;
01437 if ((ve = GetExtPart( (VendorShellWidget) w ))) {
01438 XtAddEventHandler( w, (EventMask)StructureNotifyMask, FALSE,
01439 XawVendorShellExtResize, (XtPointer)NULL );
01440 AllCreateIC(ve);
01441 }
01442 }
01443
01444 void
01445 #if NeedFunctionPrototypes
01446 _XawImInitialize(
01447 Widget w,
01448 Widget ext )
01449 #else
01450 _XawImInitialize( w, ext )
01451 Widget w, ext;
01452 #endif
01453 {
01454 XawVendorShellExtPart *ve;
01455
01456 if ( !XtIsVendorShell( w ) ) return;
01457 if ((ve = SetExtPart( (VendorShellWidget) w, (XawVendorShellExtWidget)ext)) ) {
01458 if ( Initialize( (VendorShellWidget) w, ve ) == FALSE ) return;
01459 XtAddCallback( w, XtNdestroyCallback, VendorShellDestroyed,
01460 (XtPointer) NULL );
01461 }
01462 }
01463
01464 void
01465 #if NeedFunctionPrototypes
01466 _XawImReconnect(
01467 Widget inwidg )
01468 #else
01469 _XawImReconnect( inwidg )
01470 Widget inwidg;
01471 #endif
01472 {
01473 XawVendorShellExtPart *ve;
01474 VendorShellWidget vw;
01475
01476 if ((vw = SearchVendorShell(inwidg)) == NULL) return;
01477 if ((ve = GetExtPart(vw))) {
01478 Reconnect(ve);
01479 }
01480 }
01481
01482 void
01483 #if NeedFunctionPrototypes
01484 _XawImRegister(
01485 Widget inwidg)
01486 #else
01487 _XawImRegister(inwidg)
01488 Widget inwidg;
01489 #endif
01490 {
01491 XawVendorShellExtPart *ve;
01492 VendorShellWidget vw;
01493
01494 if ((vw = SearchVendorShell(inwidg)) == NULL) return;
01495 if ((ve = GetExtPart(vw))) {
01496 Register(inwidg, ve);
01497 }
01498 }
01499
01500 void
01501 #if NeedFunctionPrototypes
01502 _XawImUnregister(
01503 Widget inwidg)
01504 #else
01505 _XawImUnregister(inwidg)
01506 Widget inwidg;
01507 #endif
01508 {
01509 XawVendorShellExtPart *ve;
01510 VendorShellWidget vw;
01511
01512 if ((vw = SearchVendorShell(inwidg)) == NULL) return;
01513 if ((ve = GetExtPart(vw))) {
01514 Unregister(inwidg, ve);
01515 }
01516 }
01517
01518 void
01519 #if NeedFunctionPrototypes
01520 _XawImSetValues(
01521 Widget inwidg,
01522 ArgList args,
01523 Cardinal num_args )
01524 #else
01525 _XawImSetValues( inwidg, args, num_args )
01526 Widget inwidg;
01527 ArgList args;
01528 Cardinal num_args;
01529 #endif
01530 {
01531 SetFocusValues( inwidg, args, num_args, FALSE );
01532 }
01533
01534 void
01535 #if NeedVarargsPrototypes
01536 _XawImVASetValues( Widget inwidg, ... )
01537 #else
01538 _XawImVASetValues( inwidg, va_alist )
01539 Widget inwidg;
01540 va_dcl
01541 #endif
01542 {
01543 va_list var;
01544 ArgList args = NULL;
01545 Cardinal num_args;
01546 int total_count, typed_count;
01547
01548 Va_start( var, inwidg );
01549 _XtCountVaList( var, &total_count, &typed_count );
01550 va_end( var );
01551
01552 Va_start( var, inwidg );
01553
01554 _XtVaToArgList( inwidg, var, total_count, &args, &num_args );
01555 _XawImSetValues( inwidg, args, num_args );
01556 if ( args != NULL ) {
01557 XtFree( (XtPointer) args );
01558 }
01559 va_end( var );
01560 }
01561
01562 void
01563 #if NeedFunctionPrototypes
01564 _XawImSetFocusValues(
01565 Widget inwidg,
01566 ArgList args,
01567 Cardinal num_args)
01568 #else
01569 _XawImSetFocusValues(inwidg, args, num_args)
01570 Widget inwidg;
01571 ArgList args;
01572 Cardinal num_args;
01573 #endif
01574 {
01575 SetFocusValues(inwidg, args, num_args, TRUE);
01576 }
01577
01578 void
01579 #if NeedVarargsPrototypes
01580 _XawImVASetFocusValues(Widget inwidg, ...)
01581 #else
01582 _XawImVASetFocusValues(inwidg, va_alist)
01583 Widget inwidg;
01584 va_dcl
01585 #endif
01586 {
01587 va_list var;
01588 ArgList args = NULL;
01589 Cardinal num_args;
01590 int total_count, typed_count;
01591
01592 Va_start(var, inwidg);
01593 _XtCountVaList(var, &total_count, &typed_count);
01594 va_end(var);
01595
01596 Va_start(var,inwidg);
01597
01598 _XtVaToArgList(inwidg, var, total_count, &args, &num_args);
01599 _XawImSetFocusValues(inwidg, args, num_args);
01600 if (args != NULL) {
01601 XtFree((XtPointer)args);
01602 }
01603 va_end(var);
01604 }
01605
01606 void
01607 #if NeedFunctionPrototypes
01608 _XawImUnsetFocus(
01609 Widget inwidg)
01610 #else
01611 _XawImUnsetFocus(inwidg)
01612 Widget inwidg;
01613 #endif
01614 {
01615 UnsetFocus(inwidg);
01616 }
01617
01618 int
01619 #if NeedFunctionPrototypes
01620 _XawImWcLookupString(
01621 Widget inwidg,
01622 XKeyPressedEvent *event,
01623 wchar_t* buffer_return,
01624 int bytes_buffer,
01625 KeySym *keysym_return,
01626 Status *status_return)
01627 #else
01628 _XawImWcLookupString( inwidg, event, buffer_return, bytes_buffer,
01629 keysym_return, status_return)
01630 Widget inwidg;
01631 XKeyPressedEvent* event;
01632 wchar_t* buffer_return;
01633 int bytes_buffer;
01634 KeySym* keysym_return;
01635 Status* status_return;
01636 #endif
01637 {
01638 XawVendorShellExtPart* ve;
01639 VendorShellWidget vw;
01640 XawIcTableList p;
01641 int i, ret;
01642 char tmp_buf[64], *tmp_p;
01643 wchar_t* buf_p;
01644
01645 if ((vw = SearchVendorShell(inwidg)) && (ve = GetExtPart(vw)) &&
01646 ve->im.xim && (p = GetIcTableShared(inwidg, ve)) && p->xic) {
01647 return(XwcLookupString(p->xic, event, buffer_return, bytes_buffer,
01648 keysym_return, status_return));
01649 }
01650 ret = XLookupString( event, tmp_buf, 64, keysym_return,
01651 (XComposeStatus*) status_return );
01652 for ( i = 0, tmp_p = tmp_buf, buf_p = buffer_return; i < ret; i++ ) {
01653 *buf_p++ = _Xaw_atowc(*tmp_p++);
01654 }
01655 return( ret );
01656 }
01657
01658 int
01659 #if NeedFunctionPrototypes
01660 _XawImGetImAreaHeight(
01661 Widget w)
01662 #else
01663 _XawImGetImAreaHeight( w )
01664 Widget w;
01665 #endif
01666 {
01667 XawVendorShellExtPart *ve;
01668 VendorShellWidget vw;
01669
01670 if ((vw = SearchVendorShell(w)) && (ve = GetExtPart(vw))) {
01671 return(ve->im.area_height);
01672 }
01673 return(0);
01674 }
01675
01676 void
01677 #if NeedFunctionPrototypes
01678 _XawImCallVendorShellExtResize(
01679 Widget w)
01680 #else
01681 _XawImCallVendorShellExtResize( w )
01682 Widget w;
01683 #endif
01684 {
01685 XawVendorShellExtPart *ve;
01686 VendorShellWidget vw;
01687 extern void XawVendorShellExtResize();
01688
01689 if ((vw = SearchVendorShell(w)) && (ve = GetExtPart(vw))) {
01690 XawVendorShellExtResize(vw);
01691 }
01692 }
01693
01694
01695
01696
01697
01698
01699
01700 void
01701 #if NeedFunctionPrototypes
01702 _XawImDestroy(
01703 Widget w,
01704 Widget ext )
01705 #else
01706 _XawImDestroy( w, ext )
01707 Widget w;
01708 Widget ext;
01709 #endif
01710 {
01711 XawVendorShellExtPart *ve;
01712
01713 if ( !XtIsVendorShell( w ) ) return;
01714 if ((ve = GetExtPart( (VendorShellWidget) w )))
01715 Destroy( w, ve );
01716 }