imRm.c revision 07fb9b8f
1/****************************************************************** 2 3 Copyright 1990, 1991, 1992,1993, 1994 by FUJITSU LIMITED 4 Copyright 1994 by Sony Corporation 5 6Permission to use, copy, modify, distribute, and sell this software 7and its documentation for any purpose is hereby granted without fee, 8provided that the above copyright notice appear in all copies and 9that both that copyright notice and this permission notice appear 10in supporting documentation, and that the name of FUJITSU LIMITED 11and Sony Corporation not be used in advertising or publicity 12pertaining to distribution of the software without specific, 13written prior permission. FUJITSU LIMITED and Sony Corporation make 14no representations about the suitability of this software for any 15purpose. It is provided "as is" without express or implied warranty. 16 17FUJITSU LIMITED AND SONY CORPORATION DISCLAIM ALL WARRANTIES WITH 18REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF 19MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJITSU LIMITED AND 20SONY CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 21DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 22PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 23TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 24PERFORMANCE OF THIS SOFTWARE. 25 26 Author: Takashi Fujiwara FUJITSU LIMITED 27 fujiwara@a80.tech.yk.fujitsu.co.jp 28 Modifier: Makoto Wakamatsu Sony Corporation 29 makoto@sm.sony.co.jp 30 31******************************************************************/ 32 33#ifdef HAVE_CONFIG_H 34#include <config.h> 35#endif 36#include <stdio.h> 37#include <X11/Xlib.h> 38#include "Xlibint.h" 39#include "Xlcint.h" 40#include "Ximint.h" 41#include "Xresource.h" 42 43#define GET_NAME(x) name_table + x.name_offset 44 45typedef struct _XimValueOffsetInfo { 46 unsigned short name_offset; 47 XrmQuark quark; 48 unsigned int offset; 49 Bool (*defaults)( 50 struct _XimValueOffsetInfo *, XPointer, XPointer, unsigned long 51 ); 52 Bool (*encode)( 53 struct _XimValueOffsetInfo *, XPointer, XPointer 54 ); 55 Bool (*decode)( 56 struct _XimValueOffsetInfo *, XPointer, XPointer 57 ); 58} XimValueOffsetInfoRec, *XimValueOffsetInfo; 59 60#ifdef XIM_CONNECTABLE 61static Bool 62_XimCheckBool(str) 63 char *str; 64{ 65 if(!strcmp(str, "True") || !strcmp(str, "true") || 66 !strcmp(str, "Yes") || !strcmp(str, "yes") || 67 !strcmp(str, "ON") || !strcmp(str, "on")) 68 return True; 69 return False; 70} 71 72void 73_XimSetProtoResource(im) 74 Xim im; 75{ 76 char res_name_buf[256]; 77 char* res_name; 78 size_t res_name_len; 79 char res_class_buf[256]; 80 char* res_class; 81 size_t res_class_len; 82 char* str_type; 83 XrmValue value; 84 XIMStyle preedit_style = 0; 85 XIMStyle status_style = 0; 86 XIMStyles* imstyles; 87 char* dotximdot = ".xim."; 88 char* ximdot = "xim."; 89 char* dotXimdot = ".Xim."; 90 char* Ximdot = "Xim."; 91 92 if (!im->core.rdb) 93 return; 94 95 res_name_len = strlen (im->core.res_name); 96 if (res_name_len < 200) { 97 res_name = res_name_buf; 98 res_name_len = sizeof(res_name_buf); 99 } 100 else { 101 res_name_len += 50; 102 res_name = Xmalloc (res_name_len); 103 } 104 res_class_len = strlen (im->core.res_class); 105 if (res_class_len < 200) { 106 res_class = res_class_buf; 107 res_class_len = sizeof(res_class_buf); 108 } 109 else { 110 res_class_len += 50; 111 res_class = Xmalloc (res_class_len); 112 } 113 /* pretend malloc always works */ 114 115 (void) snprintf (res_name, res_name_len, "%s%s%s", 116 im->core.res_name != NULL ? im->core.res_name : "*", 117 im->core.res_name != NULL ? dotximdot : ximdot, 118 "useAuth"); 119 (void) snprintf (res_class, res_class_len, "%s%s%s", 120 im->core.res_class != NULL ? im->core.res_class : "*", 121 im->core.res_class != NULL ? dotXimdot : Ximdot, 122 "UseAuth"); 123 bzero(&value, sizeof(XrmValue)); 124 if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) { 125 if(_XimCheckBool(value.addr)) { 126 MARK_USE_AUTHORIZATION_FUNC(im); 127 } 128 } 129 130 (void) snprintf (res_name, res_name_len, "%s%s%s", 131 im->core.res_name != NULL ? im->core.res_name : "*", 132 im->core.res_name != NULL ? dotximdot : ximdot, 133 "delaybinding"); 134 (void) snprintf (res_class, res_class_len, "%s%s%s", 135 im->core.res_class != NULL ? im->core.res_class : "*", 136 im->core.res_class != NULL ? dotXimdot : Ximdot, 137 "Delaybinding"); 138 bzero(&value, sizeof(XrmValue)); 139 if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) { 140 if(_XimCheckBool(value.addr)) { 141 MARK_DELAYBINDABLE(im); 142 } 143 } 144 145 (void) snprintf (res_name, res_name_len, "%s%s%s", 146 im->core.res_name != NULL ? im->core.res_name : "*", 147 im->core.res_name != NULL ? dotximdot : ximdot, 148 "reconnect"); 149 (void) snprintf (res_class, res_class_len, "%s%s%s", 150 im->core.res_class != NULL ? im->core.res_class : "*", 151 im->core.res_class != NULL ? dotXimdot : Ximdot, 152 "Reconnect"); 153 bzero(&value, sizeof(XrmValue)); 154 if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) { 155 if(_XimCheckBool(value.addr)) { 156 MARK_RECONNECTABLE(im); 157 } 158 } 159 160 if(!IS_CONNECTABLE(im)) { 161 if (res_name != res_name_buf) Xfree (res_name); 162 if (res_class != res_class_buf) Xfree (res_class); 163 return; 164 } 165 166 (void) snprintf (res_name, res_name_len, "%s%s%s", 167 im->core.res_name != NULL ? im->core.res_name : "*", 168 im->core.res_name != NULL ? dotximdot : ximdot, 169 "preeditDefaultStyle"); 170 (void) snprintf (res_class, res_class_len, "%s%s%s", 171 im->core.res_class != NULL ? im->core.res_class : "*", 172 im->core.res_class != NULL ? dotXimdot : Ximdot, 173 "PreeditDefaultStyle"); 174 if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) { 175 if(!strcmp(value.addr, "XIMPreeditArea")) 176 preedit_style = XIMPreeditArea; 177 else if(!strcmp(value.addr, "XIMPreeditCallbacks")) 178 preedit_style = XIMPreeditCallbacks; 179 else if(!strcmp(value.addr, "XIMPreeditPosition")) 180 preedit_style = XIMPreeditPosition; 181 else if(!strcmp(value.addr, "XIMPreeditNothing")) 182 preedit_style = XIMPreeditNothing; 183 else if(!strcmp(value.addr, "XIMPreeditNone")) 184 preedit_style = XIMPreeditNone; 185 } 186 if(!preedit_style) 187 preedit_style = XIMPreeditNothing; 188 189 (void) snprintf (res_name, res_name_len, "%s%s%s", 190 im->core.res_name != NULL ? im->core.res_name : "*", 191 im->core.res_name != NULL ? dotximdot : ximdot, 192 "statusDefaultStyle"); 193 (void) snprintf (res_class, res_class_len, "%s%s%s", 194 im->core.res_class != NULL ? im->core.res_class : "*", 195 im->core.res_class != NULL ? dotXimdot : Ximdot, 196 "StatusDefaultStyle"); 197 if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) { 198 if(!strcmp(value.addr, "XIMStatusArea")) 199 status_style = XIMStatusArea; 200 else if(!strcmp(value.addr, "XIMStatusCallbacks")) 201 status_style = XIMStatusCallbacks; 202 else if(!strcmp(value.addr, "XIMStatusNothing")) 203 status_style = XIMStatusNothing; 204 else if(!strcmp(value.addr, "XIMStatusNone")) 205 status_style = XIMStatusNone; 206 } 207 if(!status_style) 208 status_style = XIMStatusNothing; 209 210 if(!(imstyles = Xmalloc(sizeof(XIMStyles) + sizeof(XIMStyle)))){ 211 if (res_name != res_name_buf) Xfree (res_name); 212 if (res_class != res_class_buf) Xfree (res_class); 213 return; 214 } 215 imstyles->count_styles = 1; 216 imstyles->supported_styles = 217 (XIMStyle *)((char *)imstyles + sizeof(XIMStyles)); 218 imstyles->supported_styles[0] = preedit_style | status_style; 219 im->private.proto.default_styles = imstyles; 220 if (res_name != res_name_buf) Xfree (res_name); 221 if (res_class != res_class_buf) Xfree (res_class); 222} 223#endif /* XIM_CONNECTABLE */ 224 225static const char name_table[] = 226 /* 0 */ XNQueryInputStyle"\0" 227 /* 16 */ XNClientWindow"\0" 228 /* 29 */ XNInputStyle"\0" 229 /* 40 */ XNFocusWindow"\0" 230 /* 52 */ XNResourceName"\0" 231 /* 65 */ XNResourceClass"\0" 232 /* 79 */ XNGeometryCallback"\0" 233 /* 96 */ XNDestroyCallback"\0" 234 /* 112 */ XNFilterEvents"\0" 235 /* 125 */ XNPreeditStartCallback"\0" 236 /* 146 */ XNPreeditDoneCallback"\0" 237 /* 166 */ XNPreeditDrawCallback"\0" 238 /* 186 */ XNPreeditCaretCallback"\0" 239 /* 207 */ XNPreeditStateNotifyCallback"\0" 240 /* 234 */ XNPreeditAttributes"\0" 241 /* 252 */ XNStatusStartCallback"\0" 242 /* 272 */ XNStatusDoneCallback"\0" 243 /* 291 */ XNStatusDrawCallback"\0" 244 /* 310 */ XNStatusAttributes"\0" 245 /* 327 */ XNArea"\0" 246 /* 332 */ XNAreaNeeded"\0" 247 /* 343 */ XNSpotLocation"\0" 248 /* 356 */ XNColormap"\0" 249 /* 365 */ XNStdColormap"\0" 250 /* 377 */ XNForeground"\0" 251 /* 388 */ XNBackground"\0" 252 /* 399 */ XNBackgroundPixmap"\0" 253 /* 416 */ XNFontSet"\0" 254 /* 424 */ XNLineSpace"\0" 255 /* 434 */ XNCursor"\0" 256 /* 441 */ XNQueryIMValuesList"\0" 257 /* 459 */ XNQueryICValuesList"\0" 258 /* 477 */ XNVisiblePosition"\0" 259 /* 493 */ XNStringConversionCallback"\0" 260 /* 518 */ XNStringConversion"\0" 261 /* 535 */ XNResetState"\0" 262 /* 546 */ XNHotKey"\0" 263 /* 553 */ XNHotKeyState"\0" 264 /* 565 */ XNPreeditState 265; 266 267#define OFFSET_XNQUERYINPUTSTYLE 0 268#define OFFSET_XNCLIENTWINDOW 16 269#define OFFSET_XNINPUTSTYLE 29 270#define OFFSET_XNFOCUSWINDOW 40 271#define OFFSET_XNRESOURCENAME 52 272#define OFFSET_XNRESOURCECLASS 65 273#define OFFSET_XNGEOMETRYCALLBACK 79 274#define OFFSET_XNDESTROYCALLBACK 96 275#define OFFSET_XNFILTEREVENTS 112 276#define OFFSET_XNPREEDITSTARTCALLBACK 125 277#define OFFSET_XNPREEDITDONECALLBACK 146 278#define OFFSET_XNPREEDITDRAWCALLBACK 166 279#define OFFSET_XNPREEDITCARETCALLBACK 186 280#define OFFSET_XNPREEDITSTATENOTIFYCALLBACK 207 281#define OFFSET_XNPREEDITATTRIBUTES 234 282#define OFFSET_XNSTATUSSTARTCALLBACK 252 283#define OFFSET_XNSTATUSDONECALLBACK 272 284#define OFFSET_XNSTATUSDRAWCALLBACK 291 285#define OFFSET_XNSTATUSATTRIBUTES 310 286#define OFFSET_XNAREA 327 287#define OFFSET_XNAREANEEDED 332 288#define OFFSET_XNSPOTLOCATION 343 289#define OFFSET_XNCOLORMAP 356 290#define OFFSET_XNSTDCOLORMAP 365 291#define OFFSET_XNFOREGROUND 377 292#define OFFSET_XNBACKGROUND 388 293#define OFFSET_XNBACKGROUNDPIXMAP 399 294#define OFFSET_XNFONTSET 416 295#define OFFSET_XNLINESPACE 424 296#define OFFSET_XNCURSOR 434 297#define OFFSET_XNQUERYIMVALUESLIST 441 298#define OFFSET_XNQUERYICVALUESLIST 459 299#define OFFSET_XNVISIBLEPOSITION 477 300#define OFFSET_XNSTRINGCONVERSIONCALLBACK 493 301#define OFFSET_XNSTRINGCONVERSION 518 302#define OFFSET_XNRESETSTATE 535 303#define OFFSET_XNHOTKEY 546 304#define OFFSET_XNHOTKEYSTATE 553 305#define OFFSET_XNPREEDITSTATE 565 306 307/* offsets into name_table */ 308static const unsigned short supported_local_im_values_list[] = { 309 OFFSET_XNQUERYINPUTSTYLE, 310 OFFSET_XNRESOURCENAME, 311 OFFSET_XNRESOURCECLASS, 312 OFFSET_XNDESTROYCALLBACK, 313 OFFSET_XNQUERYIMVALUESLIST, 314 OFFSET_XNQUERYICVALUESLIST, 315 OFFSET_XNVISIBLEPOSITION 316}; 317 318/* offsets into name_table */ 319static const unsigned short supported_local_ic_values_list[] = { 320 OFFSET_XNINPUTSTYLE, 321 OFFSET_XNCLIENTWINDOW, 322 OFFSET_XNFOCUSWINDOW, 323 OFFSET_XNRESOURCENAME, 324 OFFSET_XNRESOURCECLASS, 325 OFFSET_XNGEOMETRYCALLBACK, 326 OFFSET_XNFILTEREVENTS, 327 OFFSET_XNDESTROYCALLBACK, 328 OFFSET_XNSTRINGCONVERSIONCALLBACK, 329 OFFSET_XNSTRINGCONVERSIONCALLBACK, 330 OFFSET_XNRESETSTATE, 331 OFFSET_XNHOTKEY, 332 OFFSET_XNHOTKEYSTATE, 333 OFFSET_XNPREEDITATTRIBUTES, 334 OFFSET_XNSTATUSATTRIBUTES, 335 OFFSET_XNAREA, 336 OFFSET_XNAREANEEDED, 337 OFFSET_XNSPOTLOCATION, 338 OFFSET_XNCOLORMAP, 339 OFFSET_XNSTDCOLORMAP, 340 OFFSET_XNFOREGROUND, 341 OFFSET_XNBACKGROUND, 342 OFFSET_XNBACKGROUNDPIXMAP, 343 OFFSET_XNFONTSET, 344 OFFSET_XNLINESPACE, 345 OFFSET_XNCURSOR, 346 OFFSET_XNPREEDITSTARTCALLBACK, 347 OFFSET_XNPREEDITDONECALLBACK, 348 OFFSET_XNPREEDITDRAWCALLBACK, 349 OFFSET_XNPREEDITCARETCALLBACK, 350 OFFSET_XNSTATUSSTARTCALLBACK, 351 OFFSET_XNSTATUSDONECALLBACK, 352 OFFSET_XNSTATUSDRAWCALLBACK, 353 OFFSET_XNPREEDITSTATE, 354 OFFSET_XNPREEDITSTATENOTIFYCALLBACK 355}; 356 357static XIMStyle const supported_local_styles[] = { 358 XIMPreeditNone | XIMStatusNone, 359 XIMPreeditNothing | XIMStatusNothing, 360 0 /* dummy */ 361}; 362 363static Bool 364_XimDefaultStyles( 365 XimValueOffsetInfo info, 366 XPointer top, 367 XPointer parm, /* unused */ 368 unsigned long mode) /* unused */ 369{ 370 XIMStyles *styles; 371 XIMStyles **out; 372 register int i; 373 unsigned int n; 374 int len; 375 XPointer tmp; 376 377 n = XIMNumber(supported_local_styles) - 1; 378 len = sizeof(XIMStyles) + sizeof(XIMStyle) * n; 379 if(!(tmp = Xcalloc(1, len))) { 380 return False; 381 } 382 383 styles = (XIMStyles *)tmp; 384 if (n > 0) { 385 styles->count_styles = (unsigned short)n; 386 styles->supported_styles = 387 (XIMStyle *)((char *)tmp + sizeof(XIMStyles)); 388 for(i = 0; i < n; i++) { 389 styles->supported_styles[i] = supported_local_styles[i]; 390 } 391 } 392 393 out = (XIMStyles **)((char *)top + info->offset); 394 *out = styles; 395 return True; 396} 397 398static Bool 399_XimDefaultIMValues( 400 XimValueOffsetInfo info, 401 XPointer top, 402 XPointer parm, /* unused */ 403 unsigned long mode) /* unused */ 404{ 405 XIMValuesList *values_list; 406 XIMValuesList **out; 407 register int i; 408 unsigned int n; 409 int len; 410 XPointer tmp; 411 412 n = XIMNumber(supported_local_im_values_list); 413 len = sizeof(XIMValuesList) + sizeof(char **) * n; 414 if(!(tmp = Xcalloc(1, len))) { 415 return False; 416 } 417 418 values_list = (XIMValuesList *)tmp; 419 if (n > 0) { 420 values_list->count_values = (unsigned short)n; 421 values_list->supported_values 422 = (char **)((char *)tmp + sizeof(XIMValuesList)); 423 for(i = 0; i < n; i++) { 424 values_list->supported_values[i] = 425 (char *)name_table + supported_local_im_values_list[i]; 426 } 427 } 428 429 out = (XIMValuesList **)((char *)top + info->offset); 430 *out = values_list; 431 return True; 432} 433 434static Bool 435_XimDefaultICValues( 436 XimValueOffsetInfo info, 437 XPointer top, 438 XPointer parm, /* unused */ 439 unsigned long mode) /* unused */ 440{ 441 XIMValuesList *values_list; 442 XIMValuesList **out; 443 register int i; 444 unsigned int n; 445 int len; 446 XPointer tmp; 447 448 n = XIMNumber(supported_local_ic_values_list); 449 len = sizeof(XIMValuesList) + sizeof(char **) * n; 450 if(!(tmp = Xcalloc(1, len))) { 451 return False; 452 } 453 454 values_list = (XIMValuesList *)tmp; 455 if (n > 0) { 456 values_list->count_values = (unsigned short)n; 457 values_list->supported_values 458 = (char **)((char *)tmp + sizeof(XIMValuesList)); 459 for(i = 0; i < n; i++) { 460 values_list->supported_values[i] = 461 (char *)name_table + supported_local_ic_values_list[i]; 462 } 463 } 464 465 out = (XIMValuesList **)((char *)top + info->offset); 466 *out = values_list; 467 return True; 468} 469 470static Bool 471_XimDefaultVisiblePos( 472 XimValueOffsetInfo info, 473 XPointer top, 474 XPointer parm, /* unused */ 475 unsigned long mode) /* unused */ 476{ 477 Bool *out; 478 479 out = (Bool *)((char *)top + info->offset); 480 *out = False; 481 return True; 482} 483 484static Bool 485_XimDefaultFocusWindow( 486 XimValueOffsetInfo info, 487 XPointer top, 488 XPointer parm, 489 unsigned long mode) 490{ 491 Xic ic = (Xic)parm; 492 Window *out; 493 494 if(ic->core.client_window == (Window)NULL) { 495 return True; 496 } 497 498 out = (Window *)((char *)top + info->offset); 499 *out = ic->core.client_window; 500 return True; 501} 502 503static Bool 504_XimDefaultResName( 505 XimValueOffsetInfo info, 506 XPointer top, 507 XPointer parm, 508 unsigned long mode) 509{ 510 Xic ic = (Xic)parm; 511 Xim im = (Xim)ic->core.im; 512 char **out; 513 char *string; 514 515 if(im->core.res_name == (char *)NULL) { 516 return True; 517 } 518 519 string=strdup(im->core.res_name); 520 if ( string == NULL) 521 return False; 522 523 out = (char **)((char *)top + info->offset); 524 525 Xfree(*out); /* free old im->core.res_name */ 526 *out =string; 527 528 return True; 529} 530 531static Bool 532_XimDefaultResClass( 533 XimValueOffsetInfo info, 534 XPointer top, 535 XPointer parm, 536 unsigned long mode) 537{ 538 Xic ic = (Xic)parm; 539 Xim im = (Xim)ic->core.im; 540 char *string; 541 char **out; 542 543 if(im->core.res_class == (char *)NULL) { 544 return True; 545 } 546 547 string=strdup(im->core.res_class); 548 if (string == NULL) 549 return False; 550 551 out = (char **)((char *)top + info->offset); 552 553 Xfree(*out); /* free old im->core.res_class */ 554 *out = string; 555 556 return True; 557} 558 559static Bool 560_XimDefaultDestroyCB( 561 XimValueOffsetInfo info, 562 XPointer top, 563 XPointer parm, 564 unsigned long mode) 565{ 566 Xic ic = (Xic)parm; 567 Xim im = (Xim)ic->core.im; 568 XIMCallback *out; 569 570 out = (XIMCallback *)((char *)top + info->offset); 571 *out = im->core.destroy_callback; 572 return True; 573} 574 575static Bool 576_XimDefaultResetState( 577 XimValueOffsetInfo info, 578 XPointer top, 579 XPointer parm, 580 unsigned long mode) 581{ 582 XIMResetState *out; 583 584 out = (XIMResetState *)((char *)top + info->offset); 585 *out = XIMInitialState; 586 return True; 587} 588 589static Bool 590_XimDefaultHotKeyState( 591 XimValueOffsetInfo info, 592 XPointer top, 593 XPointer parm, 594 unsigned long mode) 595{ 596 XIMHotKeyState *out; 597 598 out = (XIMHotKeyState *)((char *)top + info->offset); 599 *out = XIMHotKeyStateOFF; 600 return True; 601} 602 603static Bool 604_XimDefaultArea( 605 XimValueOffsetInfo info, 606 XPointer top, 607 XPointer parm, 608 unsigned long mode) 609{ 610 Xic ic = (Xic)parm; 611 Xim im = (Xim)ic->core.im; 612 Window root_return; 613 int x_return, y_return; 614 unsigned int width_return, height_return; 615 unsigned int border_width_return; 616 unsigned int depth_return; 617 XRectangle area; 618 XRectangle *out; 619 620 if(ic->core.focus_window == (Window)NULL) { 621 return True; 622 } 623 if(XGetGeometry(im->core.display, (Drawable)ic->core.focus_window, 624 &root_return, &x_return, &y_return, &width_return, 625 &height_return, &border_width_return, &depth_return) 626 == (Status)Success) { 627 return True; 628 } 629 area.x = 0; 630 area.y = 0; 631 area.width = width_return; 632 area.height = height_return; 633 634 out = (XRectangle *)((char *)top + info->offset); 635 *out = area; 636 return True; 637} 638 639static Bool 640_XimDefaultColormap( 641 XimValueOffsetInfo info, 642 XPointer top, 643 XPointer parm, 644 unsigned long mode) 645{ 646 Xic ic = (Xic)parm; 647 Xim im = (Xim)ic->core.im; 648 XWindowAttributes win_attr; 649 Colormap *out; 650 651 if(ic->core.client_window == (Window)NULL) { 652 return True; 653 } 654 if(XGetWindowAttributes(im->core.display, ic->core.client_window, 655 &win_attr) == (Status)Success) { 656 return True; 657 } 658 659 out = (Colormap *)((char *)top + info->offset); 660 *out = win_attr.colormap; 661 return True; 662} 663 664static Bool 665_XimDefaultStdColormap( 666 XimValueOffsetInfo info, 667 XPointer top, 668 XPointer parm, 669 unsigned long mode) 670{ 671 Atom *out; 672 673 out = (Atom *)((char *)top + info->offset); 674 *out = (Atom)0; 675 return True; 676} 677 678static Bool 679_XimDefaultFg( 680 XimValueOffsetInfo info, 681 XPointer top, 682 XPointer parm, 683 unsigned long mode) 684{ 685 Xic ic = (Xic)parm; 686 Xim im = (Xim)ic->core.im; 687 unsigned long fg; 688 unsigned long *out; 689 690 fg = WhitePixel(im->core.display, DefaultScreen(im->core.display)); 691 out = (unsigned long *)((char *)top + info->offset); 692 *out = fg; 693 return True; 694} 695 696static Bool 697_XimDefaultBg( 698 XimValueOffsetInfo info, 699 XPointer top, 700 XPointer parm, 701 unsigned long mode) 702{ 703 Xic ic = (Xic)parm; 704 Xim im = (Xim)ic->core.im; 705 unsigned long bg; 706 unsigned long *out; 707 708 bg = BlackPixel(im->core.display, DefaultScreen(im->core.display)); 709 out = (unsigned long *)((char *)top + info->offset); 710 *out = bg; 711 return True; 712} 713 714static Bool 715_XimDefaultBgPixmap( 716 XimValueOffsetInfo info, 717 XPointer top, 718 XPointer parm, 719 unsigned long mode) 720{ 721 Pixmap *out; 722 723 out = (Pixmap *)((char *)top + info->offset); 724 *out = (Pixmap)0; 725 return True; 726} 727 728static Bool 729_XimDefaultFontSet( 730 XimValueOffsetInfo info, 731 XPointer top, 732 XPointer parm, 733 unsigned long mode) 734{ 735 XFontSet *out; 736 737 out = (XFontSet *)((char *)top + info->offset); 738 *out = 0; 739 return True; 740} 741 742static Bool 743_XimDefaultLineSpace( 744 XimValueOffsetInfo info, 745 XPointer top, 746 XPointer parm, 747 unsigned long mode) 748{ 749 Xic ic = (Xic)parm; 750 XFontSet fontset; 751 XFontSetExtents *fset_extents; 752 int line_space = 0; 753 int *out; 754 755 if(mode & XIM_PREEDIT_ATTR) { 756 fontset = ic->core.preedit_attr.fontset; 757 } else if(mode & XIM_STATUS_ATTR) { 758 fontset = ic->core.status_attr.fontset; 759 } else { 760 return True; 761 } 762 if (fontset) { 763 fset_extents = XExtentsOfFontSet(fontset); 764 line_space = fset_extents->max_logical_extent.height; 765 } 766 out = (int *)((char *)top + info->offset); 767 *out = line_space; 768 return True; 769} 770 771static Bool 772_XimDefaultCursor( 773 XimValueOffsetInfo info, 774 XPointer top, 775 XPointer parm, 776 unsigned long mode) 777{ 778 Cursor *out; 779 780 out = (Cursor *)((char *)top + info->offset); 781 *out = (Cursor)0; 782 return True; 783} 784 785static Bool 786_XimDefaultPreeditState( 787 XimValueOffsetInfo info, 788 XPointer top, 789 XPointer parm, 790 unsigned long mode) 791{ 792 XIMPreeditState *out; 793 794 out = (XIMPreeditState *)((char *)top + info->offset); 795 *out = XIMPreeditDisable; 796 return True; 797} 798 799static Bool 800_XimDefaultNest( 801 XimValueOffsetInfo info, 802 XPointer top, 803 XPointer parm, 804 unsigned long mode) 805{ 806 return True; 807} 808 809static Bool 810_XimEncodeCallback( 811 XimValueOffsetInfo info, 812 XPointer top, 813 XPointer val) 814{ 815 XIMCallback *out; 816 817 out = (XIMCallback *)((char *)top + info->offset); 818 *out = *((XIMCallback *)val); 819 return True; 820} 821 822static Bool 823_XimEncodeString( 824 XimValueOffsetInfo info, 825 XPointer top, 826 XPointer val) 827{ 828 char *string; 829 char **out; 830 831 if(val == (XPointer)NULL) { 832 return False; 833 } 834 if (!(string = strdup((char *)val))) { 835 return False; 836 } 837 838 out = (char **)((char *)top + info->offset); 839 840 Xfree(*out); 841 *out = string; 842 return True; 843} 844 845static Bool 846_XimEncodeStyle( 847 XimValueOffsetInfo info, 848 XPointer top, 849 XPointer val) 850{ 851 XIMStyle *out; 852 853 out = (XIMStyle *)((char *)top + info->offset); 854 *out = (XIMStyle)val; 855 return True; 856} 857 858static Bool 859_XimEncodeWindow( 860 XimValueOffsetInfo info, 861 XPointer top, 862 XPointer val) 863{ 864 Window *out; 865 866 out = (Window *)((char *)top + info->offset); 867 *out = (Window)val; 868 return True; 869} 870 871static Bool 872_XimEncodeStringConv( 873 XimValueOffsetInfo info, 874 XPointer top, 875 XPointer val) 876{ 877 /* 878 * Not yet 879 */ 880 return True; 881} 882 883static Bool 884_XimEncodeResetState( 885 XimValueOffsetInfo info, 886 XPointer top, 887 XPointer val) 888{ 889 XIMResetState *out; 890 891 out = (XIMResetState *)((char *)top + info->offset); 892 *out = (XIMResetState)val; 893 return True; 894} 895 896static Bool 897_XimEncodeHotKey( 898 XimValueOffsetInfo info, 899 XPointer top, 900 XPointer val) 901{ 902 XIMHotKeyTriggers *hotkey = (XIMHotKeyTriggers *)val; 903 XIMHotKeyTriggers **out; 904 XIMHotKeyTriggers *key_list; 905 XIMHotKeyTrigger *key; 906 XPointer tmp; 907 int num; 908 int len; 909 register int i; 910 911 if(hotkey == (XIMHotKeyTriggers *)NULL) { 912 return True; 913 } 914 915 if((num = hotkey->num_hot_key) == 0) { 916 return True; 917 } 918 919 len = sizeof(XIMHotKeyTriggers) + sizeof(XIMHotKeyTrigger) * num; 920 if(!(tmp = Xmalloc(len))) { 921 return False; 922 } 923 924 key_list = (XIMHotKeyTriggers *)tmp; 925 key = (XIMHotKeyTrigger *)((char *)tmp + sizeof(XIMHotKeyTriggers)); 926 927 for(i = 0; i < num; i++) { 928 key[i] = hotkey->key[i]; 929 } 930 931 key_list->num_hot_key = num; 932 key_list->key = key; 933 934 out = (XIMHotKeyTriggers **)((char *)top + info->offset); 935 *out = key_list; 936 return True; 937} 938 939static Bool 940_XimEncodeHotKetState( 941 XimValueOffsetInfo info, 942 XPointer top, 943 XPointer val) 944{ 945 XIMHotKeyState *out; 946 947 out = (XIMHotKeyState *)((char *)top + info->offset); 948 *out = (XIMHotKeyState)val; 949 return True; 950} 951 952static Bool 953_XimEncodeRectangle( 954 XimValueOffsetInfo info, 955 XPointer top, 956 XPointer val) 957{ 958 XRectangle *out; 959 960 out = (XRectangle *)((char *)top + info->offset); 961 *out = *((XRectangle *)val); 962 return True; 963} 964 965static Bool 966_XimEncodeSpot( 967 XimValueOffsetInfo info, 968 XPointer top, 969 XPointer val) 970{ 971 XPoint *out; 972 973 out = (XPoint *)((char *)top + info->offset); 974 *out = *((XPoint *)val); 975 return True; 976} 977 978static Bool 979_XimEncodeColormap( 980 XimValueOffsetInfo info, 981 XPointer top, 982 XPointer val) 983{ 984 Colormap *out; 985 986 out = (Colormap *)((char *)top + info->offset); 987 *out = (Colormap)val; 988 return True; 989} 990 991static Bool 992_XimEncodeStdColormap( 993 XimValueOffsetInfo info, 994 XPointer top, 995 XPointer val) 996{ 997 Atom *out; 998 999 out = (Atom *)((char *)top + info->offset); 1000 *out = (Atom)val; 1001 return True; 1002} 1003 1004static Bool 1005_XimEncodeLong( 1006 XimValueOffsetInfo info, 1007 XPointer top, 1008 XPointer val) 1009{ 1010 unsigned long *out; 1011 1012 out = (unsigned long *)((char *)top + info->offset); 1013 *out = (unsigned long)val; 1014 return True; 1015} 1016 1017static Bool 1018_XimEncodeBgPixmap( 1019 XimValueOffsetInfo info, 1020 XPointer top, 1021 XPointer val) 1022{ 1023 Pixmap *out; 1024 1025 out = (Pixmap *)((char *)top + info->offset); 1026 *out = (Pixmap)val; 1027 return True; 1028} 1029 1030static Bool 1031_XimEncodeFontSet( 1032 XimValueOffsetInfo info, 1033 XPointer top, 1034 XPointer val) 1035{ 1036 XFontSet *out; 1037 1038 out = (XFontSet *)((char *)top + info->offset); 1039 *out = (XFontSet)val; 1040 return True; 1041} 1042 1043static Bool 1044_XimEncodeLineSpace( 1045 XimValueOffsetInfo info, 1046 XPointer top, 1047 XPointer val) 1048{ 1049 int *out; 1050 1051 out = (int *)((char *)top + info->offset); 1052 *out = (long)val; 1053 return True; 1054} 1055 1056static Bool 1057_XimEncodeCursor( 1058 XimValueOffsetInfo info, 1059 XPointer top, 1060 XPointer val) 1061{ 1062 Cursor *out; 1063 1064 out = (Cursor *)((char *)top + info->offset); 1065 *out = (Cursor)val; 1066 return True; 1067} 1068 1069static Bool 1070_XimEncodePreeditState( 1071 XimValueOffsetInfo info, 1072 XPointer top, 1073 XPointer val) 1074{ 1075 XIMPreeditState *out; 1076 1077 out = (XIMPreeditState *)((char *)top + info->offset); 1078 *out = (XIMPreeditState)val; 1079 return True; 1080} 1081 1082static Bool 1083_XimEncodeNest( 1084 XimValueOffsetInfo info, 1085 XPointer top, 1086 XPointer val) 1087{ 1088 return True; 1089} 1090 1091static Bool 1092_XimDecodeStyles( 1093 XimValueOffsetInfo info, 1094 XPointer top, 1095 XPointer val) 1096{ 1097 XIMStyles *styles; 1098 XIMStyles *out; 1099 register int i; 1100 unsigned int num; 1101 int len; 1102 XPointer tmp; 1103 1104 if(val == (XPointer)NULL) { 1105 return False; 1106 } 1107 1108 styles = *((XIMStyles **)((char *)top + info->offset)); 1109 num = styles->count_styles; 1110 1111 len = sizeof(XIMStyles) + sizeof(XIMStyle) * num; 1112 if(!(tmp = Xcalloc(1, len))) { 1113 return False; 1114 } 1115 1116 out = (XIMStyles *)tmp; 1117 if(num >0) { 1118 out->count_styles = (unsigned short)num; 1119 out->supported_styles = (XIMStyle *)((char *)tmp + sizeof(XIMStyles)); 1120 1121 for(i = 0; i < num; i++) { 1122 out->supported_styles[i] = styles->supported_styles[i]; 1123 } 1124 } 1125 *((XIMStyles **)val) = out; 1126 return True; 1127} 1128 1129static Bool 1130_XimDecodeValues( 1131 XimValueOffsetInfo info, 1132 XPointer top, 1133 XPointer val) 1134{ 1135 XIMValuesList *values_list; 1136 XIMValuesList *out; 1137 register int i; 1138 unsigned int num; 1139 int len; 1140 XPointer tmp; 1141 1142 if(val == (XPointer)NULL) { 1143 return False; 1144 } 1145 1146 values_list = *((XIMValuesList **)((char *)top + info->offset)); 1147 num = values_list->count_values; 1148 1149 len = sizeof(XIMValuesList) + sizeof(char **) * num; 1150 if(!(tmp = Xcalloc(1, len))) { 1151 return False; 1152 } 1153 1154 out = (XIMValuesList *)tmp; 1155 if(num) { 1156 out->count_values = (unsigned short)num; 1157 out->supported_values = (char **)((char *)tmp + sizeof(XIMValuesList)); 1158 1159 for(i = 0; i < num; i++) { 1160 out->supported_values[i] = values_list->supported_values[i]; 1161 } 1162 } 1163 *((XIMValuesList **)val) = out; 1164 return True; 1165} 1166 1167static Bool 1168_XimDecodeCallback( 1169 XimValueOffsetInfo info, 1170 XPointer top, 1171 XPointer val) 1172{ 1173 XIMCallback *in; 1174 XIMCallback *callback; 1175 1176 in = (XIMCallback *)((char *)top + info->offset); 1177 if(!(callback = Xmalloc(sizeof(XIMCallback)))) { 1178 return False; 1179 } 1180 callback->client_data = in->client_data; 1181 callback->callback = in->callback; 1182 1183 *((XIMCallback **)val) = callback; 1184 return True; 1185} 1186 1187static Bool 1188_XimDecodeString( 1189 XimValueOffsetInfo info, 1190 XPointer top, 1191 XPointer val) 1192{ 1193 char *in; 1194 char *string; 1195 1196 in = *((char **)((char *)top + info->offset)); 1197 if (in != NULL) { 1198 string = strdup(in); 1199 } else { 1200 string = Xcalloc(1, 1); /* strdup("") */ 1201 } 1202 if (string == NULL) { 1203 return False; 1204 } 1205 *((char **)val) = string; 1206 return True; 1207} 1208 1209static Bool 1210_XimDecodeBool( 1211 XimValueOffsetInfo info, 1212 XPointer top, 1213 XPointer val) 1214{ 1215 Bool *in; 1216 1217 in = (Bool *)((char *)top + info->offset); 1218 *((Bool *)val) = *in; 1219 return True; 1220} 1221 1222static Bool 1223_XimDecodeStyle( 1224 XimValueOffsetInfo info, 1225 XPointer top, 1226 XPointer val) 1227{ 1228 XIMStyle *in; 1229 1230 in = (XIMStyle *)((char *)top + info->offset); 1231 *((XIMStyle *)val) = *in; 1232 return True; 1233} 1234 1235static Bool 1236_XimDecodeWindow( 1237 XimValueOffsetInfo info, 1238 XPointer top, 1239 XPointer val) 1240{ 1241 Window *in; 1242 1243 in = (Window *)((char *)top + info->offset); 1244 *((Window *)val) = *in; 1245 return True; 1246} 1247 1248static Bool 1249_XimDecodeStringConv( 1250 XimValueOffsetInfo info, 1251 XPointer top, 1252 XPointer val) 1253{ 1254 /* 1255 * Not yet 1256 */ 1257 return True; 1258} 1259 1260static Bool 1261_XimDecodeResetState( 1262 XimValueOffsetInfo info, 1263 XPointer top, 1264 XPointer val) 1265{ 1266 XIMResetState *in; 1267 1268 in = (XIMResetState *)((char *)top + info->offset); 1269 *((XIMResetState *)val) = *in; 1270 return True; 1271} 1272 1273static Bool 1274_XimDecodeHotKey( 1275 XimValueOffsetInfo info, 1276 XPointer top, 1277 XPointer val) 1278{ 1279 XIMHotKeyTriggers *in; 1280 XIMHotKeyTriggers *hotkey; 1281 XIMHotKeyTrigger *key; 1282 XPointer tmp; 1283 int num; 1284 int len; 1285 register int i; 1286 1287 in = *((XIMHotKeyTriggers **)((char *)top + info->offset)); 1288 num = in->num_hot_key; 1289 len = sizeof(XIMHotKeyTriggers) + sizeof(XIMHotKeyTrigger) * num; 1290 if(!(tmp = Xmalloc(len))) { 1291 return False; 1292 } 1293 1294 hotkey = (XIMHotKeyTriggers *)tmp; 1295 key = (XIMHotKeyTrigger *)((char *)tmp + sizeof(XIMHotKeyTriggers)); 1296 1297 for(i = 0; i < num; i++) { 1298 key[i] = in->key[i]; 1299 } 1300 hotkey->num_hot_key = num; 1301 hotkey->key = key; 1302 1303 *((XIMHotKeyTriggers **)val) = hotkey; 1304 return True; 1305} 1306 1307static Bool 1308_XimDecodeHotKetState( 1309 XimValueOffsetInfo info, 1310 XPointer top, 1311 XPointer val) 1312{ 1313 XIMHotKeyState *in; 1314 1315 in = (XIMHotKeyState *)((char *)top + info->offset); 1316 *((XIMHotKeyState *)val) = *in; 1317 return True; 1318} 1319 1320static Bool 1321_XimDecodeRectangle( 1322 XimValueOffsetInfo info, 1323 XPointer top, 1324 XPointer val) 1325{ 1326 XRectangle *in; 1327 XRectangle *rect; 1328 1329 in = (XRectangle *)((char *)top + info->offset); 1330 if(!(rect = Xmalloc(sizeof(XRectangle)))) { 1331 return False; 1332 } 1333 *rect = *in; 1334 *((XRectangle **)val) = rect; 1335 return True; 1336} 1337 1338static Bool 1339_XimDecodeSpot( 1340 XimValueOffsetInfo info, 1341 XPointer top, 1342 XPointer val) 1343{ 1344 XPoint *in; 1345 XPoint *spot; 1346 1347 in = (XPoint *)((char *)top + info->offset); 1348 if(!(spot = Xmalloc(sizeof(XPoint)))) { 1349 return False; 1350 } 1351 *spot = *in; 1352 *((XPoint **)val) = spot; 1353 return True; 1354} 1355 1356static Bool 1357_XimDecodeColormap( 1358 XimValueOffsetInfo info, 1359 XPointer top, 1360 XPointer val) 1361{ 1362 Colormap *in; 1363 1364 in = (Colormap *)((char *)top + info->offset); 1365 *((Colormap *)val) = *in; 1366 return True; 1367} 1368 1369static Bool 1370_XimDecodeStdColormap( 1371 XimValueOffsetInfo info, 1372 XPointer top, 1373 XPointer val) 1374{ 1375 Atom *in; 1376 1377 in = (Atom *)((char *)top + info->offset); 1378 *((Atom *)val) = *in; 1379 return True; 1380} 1381 1382static Bool 1383_XimDecodeLong( 1384 XimValueOffsetInfo info, 1385 XPointer top, 1386 XPointer val) 1387{ 1388 unsigned long *in; 1389 1390 in = (unsigned long *)((char *)top + info->offset); 1391 *((unsigned long *)val) = *in; 1392 return True; 1393} 1394 1395static Bool 1396_XimDecodeBgPixmap( 1397 XimValueOffsetInfo info, 1398 XPointer top, 1399 XPointer val) 1400{ 1401 Pixmap *in; 1402 1403 in = (Pixmap *)((char *)top + info->offset); 1404 *((Pixmap *)val) = *in; 1405 return True; 1406} 1407 1408static Bool 1409_XimDecodeFontSet( 1410 XimValueOffsetInfo info, 1411 XPointer top, 1412 XPointer val) 1413{ 1414 XFontSet *in; 1415 1416 in = (XFontSet *)((char *)top + info->offset); 1417 *((XFontSet *)val) = *in; 1418 return True; 1419} 1420 1421static Bool 1422_XimDecodeLineSpace( 1423 XimValueOffsetInfo info, 1424 XPointer top, 1425 XPointer val) 1426{ 1427 int *in; 1428 1429 in = (int *)((char *)top + info->offset); 1430 *((int *)val) = *in; 1431 return True; 1432} 1433 1434static Bool 1435_XimDecodeCursor( 1436 XimValueOffsetInfo info, 1437 XPointer top, 1438 XPointer val) 1439{ 1440 Cursor *in; 1441 1442 in = (Cursor *)((char *)top + info->offset); 1443 *((Cursor *)val) = *in; 1444 return True; 1445} 1446 1447static Bool 1448_XimDecodePreeditState( 1449 XimValueOffsetInfo info, 1450 XPointer top, 1451 XPointer val) 1452{ 1453 XIMPreeditState *in; 1454 1455 in = (XIMPreeditState *)((char *)top + info->offset); 1456 *((XIMPreeditState *)val) = *in; 1457 return True; 1458} 1459 1460static Bool 1461_XimDecodeNest( 1462 XimValueOffsetInfo info, 1463 XPointer top, 1464 XPointer val) 1465{ 1466 return True; 1467} 1468 1469static XIMResource im_resources[] = { 1470 {XNQueryInputStyle, 0, XimType_XIMStyles, 0, 0, 0}, 1471 {XNDestroyCallback, 0, 0, 0, 0, 0}, 1472 {XNResourceName, 0, XimType_STRING8, 0, 0, 0}, 1473 {XNResourceClass, 0, XimType_STRING8, 0, 0, 0}, 1474 {XNQueryIMValuesList, 0, 0, 0, 0, 0}, 1475 {XNQueryICValuesList, 0, 0, 0, 0, 0}, 1476 {XNVisiblePosition, 0, 0, 0, 0, 0} 1477}; 1478 1479static XIMResource im_inner_resources[] = { 1480 {XNDestroyCallback, 0, 0, 0, 0, 0}, 1481 {XNResourceName, 0, XimType_STRING8, 0, 0, 0}, 1482 {XNResourceClass, 0, XimType_STRING8, 0, 0, 0}, 1483 {XNQueryIMValuesList, 0, 0, 0, 0, 0}, 1484 {XNQueryICValuesList, 0, 0, 0, 0, 0}, 1485 {XNVisiblePosition, 0, 0, 0, 0, 0} 1486}; 1487 1488static XIMResource ic_resources[] = { 1489 {XNInputStyle, 0, XimType_CARD32, 0, 0, 0}, 1490 {XNClientWindow, 0, XimType_Window, 0, 0, 0}, 1491 {XNFocusWindow, 0, XimType_Window, 0, 0, 0}, 1492 {XNResourceName, 0, XimType_STRING8, 0, 0, 0}, 1493 {XNResourceClass, 0, XimType_STRING8, 0, 0, 0}, 1494 {XNGeometryCallback, 0, 0, 0, 0, 0}, 1495 {XNFilterEvents, 0, XimType_CARD32, 0, 0, 0}, 1496 {XNDestroyCallback, 0, 0, 0, 0, 0}, 1497 {XNStringConversionCallback, 0, 0, 0, 0, 0}, 1498 {XNStringConversion, 0, XimType_XIMStringConversion,0, 0, 0}, 1499 {XNResetState, 0, 0, 0, 0, 0}, 1500 {XNHotKey, 0, XimType_XIMHotKeyTriggers,0, 0, 0}, 1501 {XNHotKeyState, 0, XimType_XIMHotKeyState, 0, 0, 0}, 1502 {XNPreeditAttributes, 0, XimType_NEST, 0, 0, 0}, 1503 {XNStatusAttributes, 0, XimType_NEST, 0, 0, 0}, 1504 {XNArea, 0, XimType_XRectangle, 0, 0, 0}, 1505 {XNAreaNeeded, 0, XimType_XRectangle, 0, 0, 0}, 1506 {XNSpotLocation, 0, XimType_XPoint, 0, 0, 0}, 1507 {XNColormap, 0, XimType_CARD32, 0, 0, 0}, 1508 {XNStdColormap, 0, XimType_CARD32, 0, 0, 0}, 1509 {XNForeground, 0, XimType_CARD32, 0, 0, 0}, 1510 {XNBackground, 0, XimType_CARD32, 0, 0, 0}, 1511 {XNBackgroundPixmap, 0, XimType_CARD32, 0, 0, 0}, 1512 {XNFontSet, 0, XimType_XFontSet, 0, 0, 0}, 1513 {XNLineSpace, 0, XimType_CARD32, 0, 0, 0}, 1514 {XNCursor, 0, XimType_CARD32, 0, 0, 0}, 1515 {XNPreeditStartCallback, 0, 0, 0, 0, 0}, 1516 {XNPreeditDoneCallback, 0, 0, 0, 0, 0}, 1517 {XNPreeditDrawCallback, 0, 0, 0, 0, 0}, 1518 {XNPreeditCaretCallback, 0, 0, 0, 0, 0}, 1519 {XNStatusStartCallback, 0, 0, 0, 0, 0}, 1520 {XNStatusDoneCallback, 0, 0, 0, 0, 0}, 1521 {XNStatusDrawCallback, 0, 0, 0, 0, 0}, 1522 {XNPreeditState, 0, 0, 0, 0, 0}, 1523 {XNPreeditStateNotifyCallback, 0, 0, 0, 0, 0}, 1524}; 1525 1526static XIMResource ic_inner_resources[] = { 1527 {XNResourceName, 0, XimType_STRING8, 0, 0, 0}, 1528 {XNResourceClass, 0, XimType_STRING8, 0, 0, 0}, 1529 {XNGeometryCallback, 0, 0, 0, 0, 0}, 1530 {XNDestroyCallback, 0, 0, 0, 0, 0}, 1531 {XNStringConversionCallback, 0, 0, 0, 0, 0}, 1532 {XNPreeditStartCallback, 0, 0, 0, 0, 0}, 1533 {XNPreeditDoneCallback, 0, 0, 0, 0, 0}, 1534 {XNPreeditDrawCallback, 0, 0, 0, 0, 0}, 1535 {XNPreeditCaretCallback, 0, 0, 0, 0, 0}, 1536 {XNStatusStartCallback, 0, 0, 0, 0, 0}, 1537 {XNStatusDoneCallback, 0, 0, 0, 0, 0}, 1538 {XNStatusDrawCallback, 0, 0, 0, 0, 0}, 1539 {XNPreeditStateNotifyCallback, 0, 0, 0, 0, 0}, 1540}; 1541 1542static XimValueOffsetInfoRec im_attr_info[] = { 1543 {OFFSET_XNQUERYINPUTSTYLE, 0, 1544 XOffsetOf(XimDefIMValues, styles), 1545 _XimDefaultStyles, NULL, _XimDecodeStyles}, 1546 1547 {OFFSET_XNDESTROYCALLBACK, 0, 1548 XOffsetOf(XimDefIMValues, destroy_callback), 1549 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1550 1551 {OFFSET_XNRESOURCENAME, 0, 1552 XOffsetOf(XimDefIMValues, res_name), 1553 NULL, _XimEncodeString, _XimDecodeString}, 1554 1555 {OFFSET_XNRESOURCECLASS, 0, 1556 XOffsetOf(XimDefIMValues, res_class), 1557 NULL, _XimEncodeString, _XimDecodeString}, 1558 1559 {OFFSET_XNQUERYIMVALUESLIST, 0, 1560 XOffsetOf(XimDefIMValues, im_values_list), 1561 _XimDefaultIMValues, NULL, _XimDecodeValues}, 1562 1563 {OFFSET_XNQUERYICVALUESLIST, 0, 1564 XOffsetOf(XimDefIMValues, ic_values_list), 1565 _XimDefaultICValues, NULL, _XimDecodeValues}, 1566 1567 {OFFSET_XNVISIBLEPOSITION, 0, 1568 XOffsetOf(XimDefIMValues, visible_position), 1569 _XimDefaultVisiblePos, NULL, _XimDecodeBool} 1570}; 1571 1572static XimValueOffsetInfoRec ic_attr_info[] = { 1573 {OFFSET_XNINPUTSTYLE, 0, 1574 XOffsetOf(XimDefICValues, input_style), 1575 NULL, _XimEncodeStyle, _XimDecodeStyle}, 1576 1577 {OFFSET_XNCLIENTWINDOW, 0, 1578 XOffsetOf(XimDefICValues, client_window), 1579 NULL, _XimEncodeWindow, _XimDecodeWindow}, 1580 1581 {OFFSET_XNFOCUSWINDOW, 0, 1582 XOffsetOf(XimDefICValues, focus_window), 1583 _XimDefaultFocusWindow, _XimEncodeWindow, _XimDecodeWindow}, 1584 1585 {OFFSET_XNRESOURCENAME, 0, 1586 XOffsetOf(XimDefICValues, res_name), 1587 _XimDefaultResName, _XimEncodeString, _XimDecodeString}, 1588 1589 {OFFSET_XNRESOURCECLASS, 0, 1590 XOffsetOf(XimDefICValues, res_class), 1591 _XimDefaultResClass, _XimEncodeString, _XimDecodeString}, 1592 1593 {OFFSET_XNGEOMETRYCALLBACK, 0, 1594 XOffsetOf(XimDefICValues, geometry_callback), 1595 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1596 1597 {OFFSET_XNFILTEREVENTS, 0, 1598 XOffsetOf(XimDefICValues, filter_events), 1599 NULL, NULL, _XimDecodeLong}, 1600 1601 {OFFSET_XNDESTROYCALLBACK, 0, 1602 XOffsetOf(XimDefICValues, destroy_callback), 1603 _XimDefaultDestroyCB, _XimEncodeCallback, _XimDecodeCallback}, 1604 1605 {OFFSET_XNSTRINGCONVERSIONCALLBACK, 0, 1606 XOffsetOf(XimDefICValues, string_conversion_callback), 1607 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1608 1609 {OFFSET_XNSTRINGCONVERSION, 0, 1610 XOffsetOf(XimDefICValues, string_conversion), 1611 NULL, _XimEncodeStringConv, _XimDecodeStringConv}, 1612 1613 {OFFSET_XNRESETSTATE, 0, 1614 XOffsetOf(XimDefICValues, reset_state), 1615 _XimDefaultResetState, _XimEncodeResetState, _XimDecodeResetState}, 1616 1617 {OFFSET_XNHOTKEY, 0, 1618 XOffsetOf(XimDefICValues, hotkey), 1619 NULL, _XimEncodeHotKey, _XimDecodeHotKey}, 1620 1621 {OFFSET_XNHOTKEYSTATE, 0, 1622 XOffsetOf(XimDefICValues, hotkey_state), 1623 _XimDefaultHotKeyState, _XimEncodeHotKetState, _XimDecodeHotKetState}, 1624 1625 {OFFSET_XNPREEDITATTRIBUTES, 0, 1626 XOffsetOf(XimDefICValues, preedit_attr), 1627 _XimDefaultNest, _XimEncodeNest, _XimDecodeNest}, 1628 1629 {OFFSET_XNSTATUSATTRIBUTES, 0, 1630 XOffsetOf(XimDefICValues, status_attr), 1631 _XimDefaultNest, _XimEncodeNest, _XimDecodeNest}, 1632}; 1633 1634static XimValueOffsetInfoRec ic_pre_attr_info[] = { 1635 {OFFSET_XNAREA, 0, 1636 XOffsetOf(ICPreeditAttributes, area), 1637 _XimDefaultArea, _XimEncodeRectangle, _XimDecodeRectangle}, 1638 1639 {OFFSET_XNAREANEEDED, 0, 1640 XOffsetOf(ICPreeditAttributes, area_needed), 1641 NULL, _XimEncodeRectangle, _XimDecodeRectangle}, 1642 1643 {OFFSET_XNSPOTLOCATION, 0, 1644 XOffsetOf(ICPreeditAttributes, spot_location), 1645 NULL, _XimEncodeSpot, _XimDecodeSpot}, 1646 1647 {OFFSET_XNCOLORMAP, 0, 1648 XOffsetOf(ICPreeditAttributes, colormap), 1649 _XimDefaultColormap, _XimEncodeColormap, _XimDecodeColormap}, 1650 1651 {OFFSET_XNSTDCOLORMAP, 0, 1652 XOffsetOf(ICPreeditAttributes, std_colormap), 1653 _XimDefaultStdColormap, _XimEncodeStdColormap, _XimDecodeStdColormap}, 1654 1655 {OFFSET_XNFOREGROUND, 0, 1656 XOffsetOf(ICPreeditAttributes, foreground), 1657 _XimDefaultFg, _XimEncodeLong, _XimDecodeLong}, 1658 1659 {OFFSET_XNBACKGROUND, 0, 1660 XOffsetOf(ICPreeditAttributes, background), 1661 _XimDefaultBg, _XimEncodeLong, _XimDecodeLong}, 1662 1663 {OFFSET_XNBACKGROUNDPIXMAP, 0, 1664 XOffsetOf(ICPreeditAttributes, background_pixmap), 1665 _XimDefaultBgPixmap, _XimEncodeBgPixmap, _XimDecodeBgPixmap}, 1666 1667 {OFFSET_XNFONTSET, 0, 1668 XOffsetOf(ICPreeditAttributes, fontset), 1669 _XimDefaultFontSet, _XimEncodeFontSet, _XimDecodeFontSet}, 1670 1671 {OFFSET_XNLINESPACE, 0, 1672 XOffsetOf(ICPreeditAttributes, line_spacing), 1673 _XimDefaultLineSpace, _XimEncodeLineSpace, _XimDecodeLineSpace}, 1674 1675 {OFFSET_XNCURSOR, 0, 1676 XOffsetOf(ICPreeditAttributes, cursor), 1677 _XimDefaultCursor, _XimEncodeCursor, _XimDecodeCursor}, 1678 1679 {OFFSET_XNPREEDITSTARTCALLBACK, 0, 1680 XOffsetOf(ICPreeditAttributes, start_callback), 1681 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1682 1683 {OFFSET_XNPREEDITDONECALLBACK, 0, 1684 XOffsetOf(ICPreeditAttributes, done_callback), 1685 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1686 1687 {OFFSET_XNPREEDITDRAWCALLBACK, 0, 1688 XOffsetOf(ICPreeditAttributes, draw_callback), 1689 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1690 1691 {OFFSET_XNPREEDITCARETCALLBACK, 0, 1692 XOffsetOf(ICPreeditAttributes, caret_callback), 1693 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1694 1695 {OFFSET_XNPREEDITSTATE, 0, 1696 XOffsetOf(ICPreeditAttributes, preedit_state), 1697 _XimDefaultPreeditState, _XimEncodePreeditState,_XimDecodePreeditState}, 1698 1699 {OFFSET_XNPREEDITSTATENOTIFYCALLBACK, 0, 1700 XOffsetOf(ICPreeditAttributes, state_notify_callback), 1701 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1702}; 1703 1704static XimValueOffsetInfoRec ic_sts_attr_info[] = { 1705 {OFFSET_XNAREA, 0, 1706 XOffsetOf(ICStatusAttributes, area), 1707 _XimDefaultArea, _XimEncodeRectangle, _XimDecodeRectangle}, 1708 1709 {OFFSET_XNAREANEEDED, 0, 1710 XOffsetOf(ICStatusAttributes, area_needed), 1711 NULL, _XimEncodeRectangle, _XimDecodeRectangle}, 1712 1713 {OFFSET_XNCOLORMAP, 0, 1714 XOffsetOf(ICStatusAttributes, colormap), 1715 _XimDefaultColormap, _XimEncodeColormap, _XimDecodeColormap}, 1716 1717 {OFFSET_XNSTDCOLORMAP, 0, 1718 XOffsetOf(ICStatusAttributes, std_colormap), 1719 _XimDefaultStdColormap, _XimEncodeStdColormap, _XimDecodeStdColormap}, 1720 1721 {OFFSET_XNFOREGROUND, 0, 1722 XOffsetOf(ICStatusAttributes, foreground), 1723 _XimDefaultFg, _XimEncodeLong, _XimDecodeLong}, 1724 1725 {OFFSET_XNBACKGROUND, 0, 1726 XOffsetOf(ICStatusAttributes, background), 1727 _XimDefaultBg, _XimEncodeLong, _XimDecodeLong}, 1728 1729 {OFFSET_XNBACKGROUNDPIXMAP, 0, 1730 XOffsetOf(ICStatusAttributes, background_pixmap), 1731 _XimDefaultBgPixmap, _XimEncodeBgPixmap, _XimDecodeBgPixmap}, 1732 1733 {OFFSET_XNFONTSET, 0, 1734 XOffsetOf(ICStatusAttributes, fontset), 1735 _XimDefaultFontSet, _XimEncodeFontSet, _XimDecodeFontSet}, 1736 1737 {OFFSET_XNLINESPACE, 0, 1738 XOffsetOf(ICStatusAttributes, line_spacing), 1739 _XimDefaultLineSpace, _XimEncodeLineSpace, _XimDecodeLineSpace}, 1740 1741 {OFFSET_XNCURSOR, 0, 1742 XOffsetOf(ICStatusAttributes, cursor), 1743 _XimDefaultCursor, _XimEncodeCursor, _XimDecodeCursor}, 1744 1745 {OFFSET_XNSTATUSSTARTCALLBACK, 0, 1746 XOffsetOf(ICStatusAttributes, start_callback), 1747 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1748 1749 {OFFSET_XNSTATUSDONECALLBACK, 0, 1750 XOffsetOf(ICStatusAttributes, done_callback), 1751 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1752 1753 {OFFSET_XNSTATUSDRAWCALLBACK, 0, 1754 XOffsetOf(ICStatusAttributes, draw_callback), 1755 NULL, _XimEncodeCallback, _XimDecodeCallback} 1756}; 1757 1758typedef struct _XimIMMode { 1759 unsigned short name_offset; 1760 unsigned short mode; 1761} XimIMMode; 1762 1763static const XimIMMode im_mode[] = { 1764 {OFFSET_XNQUERYINPUTSTYLE, 1765 (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)}, 1766 {OFFSET_XNDESTROYCALLBACK, 1767 (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)}, 1768 {OFFSET_XNRESOURCENAME, 1769 (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)}, 1770 {OFFSET_XNRESOURCECLASS, 1771 (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)}, 1772 {OFFSET_XNQUERYIMVALUESLIST, 1773 (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)}, 1774 {OFFSET_XNQUERYICVALUESLIST, 1775 (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)}, 1776 {OFFSET_XNVISIBLEPOSITION, 1777 (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)} 1778}; 1779 1780typedef struct _XimICMode { 1781 unsigned short name_offset; 1782 unsigned short preedit_callback_mode; 1783 unsigned short preedit_position_mode; 1784 unsigned short preedit_area_mode; 1785 unsigned short preedit_nothing_mode; 1786 unsigned short preedit_none_mode; 1787 unsigned short status_callback_mode; 1788 unsigned short status_area_mode; 1789 unsigned short status_nothing_mode; 1790 unsigned short status_none_mode; 1791} XimICMode; 1792 1793static const XimICMode ic_mode[] = { 1794 {OFFSET_XNINPUTSTYLE, 1795 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET), 1796 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET), 1797 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET), 1798 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET), 1799 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET), 1800 (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET), 1801 (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET), 1802 (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET), 1803 (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET)}, 1804 {OFFSET_XNCLIENTWINDOW, 1805 (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET), 1806 (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET), 1807 (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET), 1808 (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET), 1809 0, 1810 (XIM_MODE_STS_ONCE | XIM_MODE_STS_GET), 1811 (XIM_MODE_STS_ONCE | XIM_MODE_STS_GET), 1812 (XIM_MODE_STS_ONCE | XIM_MODE_STS_GET), 1813 0}, 1814 {OFFSET_XNFOCUSWINDOW, 1815 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1816 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1817 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1818 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1819 0, 1820 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1821 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1822 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1823 0}, 1824 {OFFSET_XNRESOURCENAME, 1825 0, 1826 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1827 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1828 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1829 0, 1830 0, 1831 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1832 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1833 0}, 1834 {OFFSET_XNRESOURCECLASS, 1835 0, 1836 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1837 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1838 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1839 0, 1840 0, 1841 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1842 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1843 0}, 1844 {OFFSET_XNGEOMETRYCALLBACK, 1845 0, 1846 0, 1847 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1848 0, 1849 0, 1850 0, 1851 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1852 0, 1853 0}, 1854 {OFFSET_XNFILTEREVENTS, 1855 XIM_MODE_PRE_GET, 1856 XIM_MODE_PRE_GET, 1857 XIM_MODE_PRE_GET, 1858 XIM_MODE_PRE_GET, 1859 0, 1860 XIM_MODE_STS_GET, 1861 XIM_MODE_STS_GET, 1862 XIM_MODE_STS_GET, 1863 XIM_MODE_STS_GET}, 1864 {OFFSET_XNDESTROYCALLBACK, 1865 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1866 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1867 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1868 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1869 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1870 0, 1871 0, 1872 0, 1873 0}, 1874 {OFFSET_XNSTRINGCONVERSIONCALLBACK, 1875 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1876 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1877 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1878 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1879 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1880 0, 1881 0, 1882 0, 1883 0}, 1884 {OFFSET_XNSTRINGCONVERSION, 1885 XIM_MODE_PRE_SET, 1886 XIM_MODE_PRE_SET, 1887 XIM_MODE_PRE_SET, 1888 XIM_MODE_PRE_SET, 1889 XIM_MODE_PRE_SET, 1890 0, 1891 0, 1892 0, 1893 0}, 1894 {OFFSET_XNRESETSTATE, 1895 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1896 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1897 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1898 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1899 0, 1900 0, 1901 0, 1902 0, 1903 0}, 1904 {OFFSET_XNHOTKEY, 1905 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1906 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1907 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1908 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1909 0, 1910 0, 1911 0, 1912 0, 1913 0}, 1914 {OFFSET_XNHOTKEYSTATE, 1915 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1916 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1917 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1918 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1919 0, 1920 0, 1921 0, 1922 0, 1923 0}, 1924 {OFFSET_XNPREEDITATTRIBUTES, 1925 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1926 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1927 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1928 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1929 0, 1930 0, 1931 0, 1932 0, 1933 0}, 1934 {OFFSET_XNSTATUSATTRIBUTES, 1935 0, 1936 0, 1937 0, 1938 0, 1939 0, 1940 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1941 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1942 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1943 0}, 1944 {OFFSET_XNAREA, 1945 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1946 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1947 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1948 0, 1949 0, 1950 0, 1951 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1952 0, 1953 0}, 1954 {OFFSET_XNAREANEEDED, 1955 0, 1956 0, 1957 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1958 0, 1959 0, 1960 0, 1961 (XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1962 0, 1963 0}, 1964 {OFFSET_XNSPOTLOCATION, 1965 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1966 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1967 0, 1968 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1969 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1970 0, 1971 0, 1972 0, 1973 0}, 1974 {OFFSET_XNCOLORMAP, 1975 0, 1976 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1977 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1978 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1979 0, 1980 0, 1981 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1982 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1983 0}, 1984 {OFFSET_XNSTDCOLORMAP, 1985 0, 1986 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1987 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1988 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1989 0, 1990 0, 1991 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1992 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1993 0}, 1994 {OFFSET_XNFOREGROUND, 1995 0, 1996 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1997 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1998 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1999 0, 2000 0, 2001 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2002 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2003 0}, 2004 {OFFSET_XNBACKGROUND, 2005 0, 2006 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2007 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2008 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2009 0, 2010 0, 2011 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2012 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2013 0}, 2014 {OFFSET_XNBACKGROUNDPIXMAP, 2015 0, 2016 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2017 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2018 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2019 0, 2020 0, 2021 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2022 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2023 0}, 2024 {OFFSET_XNFONTSET, 2025 0, 2026 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2027 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2028 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2029 0, 2030 0, 2031 (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2032 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2033 0}, 2034 {OFFSET_XNLINESPACE, 2035 0, 2036 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2037 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2038 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2039 0, 2040 0, 2041 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2042 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2043 0}, 2044 {OFFSET_XNCURSOR, 2045 0, 2046 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2047 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2048 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2049 0, 2050 0, 2051 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2052 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2053 0}, 2054 {OFFSET_XNPREEDITSTARTCALLBACK, 2055 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2056 0, 2057 0, 2058 0, 2059 0, 2060 0, 2061 0, 2062 0, 2063 0}, 2064 {OFFSET_XNPREEDITDONECALLBACK, 2065 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2066 0, 2067 0, 2068 0, 2069 0, 2070 0, 2071 0, 2072 0, 2073 0}, 2074 {OFFSET_XNPREEDITDRAWCALLBACK, 2075 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2076 0, 2077 0, 2078 0, 2079 0, 2080 0, 2081 0, 2082 0, 2083 0}, 2084 {OFFSET_XNPREEDITCARETCALLBACK, 2085 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2086 0, 2087 0, 2088 0, 2089 0, 2090 0, 2091 0, 2092 0, 2093 0}, 2094 {OFFSET_XNPREEDITSTATE, 2095 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2096 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2097 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2098 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2099 0, 2100 0, 2101 0, 2102 0, 2103 0}, 2104 {OFFSET_XNPREEDITSTATENOTIFYCALLBACK, 2105 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2106 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2107 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2108 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2109 0, 2110 0, 2111 0, 2112 0, 2113 0}, 2114 {OFFSET_XNSTATUSSTARTCALLBACK, 2115 0, 2116 0, 2117 0, 2118 0, 2119 0, 2120 (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2121 0, 2122 0, 2123 0}, 2124 {OFFSET_XNSTATUSDONECALLBACK, 2125 0, 2126 0, 2127 0, 2128 0, 2129 0, 2130 (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2131 0, 2132 0, 2133 0}, 2134 {OFFSET_XNSTATUSDRAWCALLBACK, 2135 0, 2136 0, 2137 0, 2138 0, 2139 0, 2140 (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2141 0, 2142 0, 2143 0} 2144}; 2145 2146/* the quarks are separated from im_mode/ic_mode so those arrays 2147 * can be const. 2148 */ 2149static XrmQuark im_mode_quark[sizeof(im_mode) / sizeof(im_mode[0])]; 2150static XrmQuark ic_mode_quark[sizeof(ic_mode) / sizeof(ic_mode[0])]; 2151 2152static Bool 2153_XimSetResourceList( 2154 XIMResourceList *res_list, 2155 unsigned int *list_num, 2156 XIMResourceList resource, 2157 unsigned int num_resource, 2158 unsigned short id) 2159{ 2160 register int i; 2161 int len; 2162 XIMResourceList res; 2163 2164 len = sizeof(XIMResource) * num_resource; 2165 if(!(res = Xcalloc(1, len))) { 2166 return False; 2167 } 2168 2169 for(i = 0; i < num_resource; i++, id++) { 2170 res[i] = resource[i]; 2171 res[i].id = id; 2172 } 2173 2174 _XIMCompileResourceList(res, num_resource); 2175 *res_list = res; 2176 *list_num = num_resource; 2177 return True; 2178} 2179 2180Bool 2181_XimSetIMResourceList( 2182 XIMResourceList *res_list, 2183 unsigned int *list_num) 2184{ 2185 return _XimSetResourceList(res_list, list_num, 2186 im_resources, XIMNumber(im_resources), 100); 2187} 2188 2189Bool 2190_XimSetICResourceList( 2191 XIMResourceList *res_list, 2192 unsigned int *list_num) 2193{ 2194 return _XimSetResourceList(res_list, list_num, 2195 ic_resources, XIMNumber(ic_resources), 200); 2196} 2197 2198Bool 2199_XimSetInnerIMResourceList( 2200 XIMResourceList *res_list, 2201 unsigned int *list_num) 2202{ 2203 return _XimSetResourceList(res_list, list_num, 2204 im_inner_resources, XIMNumber(im_inner_resources), 100); 2205} 2206 2207Bool 2208_XimSetInnerICResourceList( 2209 XIMResourceList *res_list, 2210 unsigned int *list_num) 2211{ 2212 return _XimSetResourceList(res_list, list_num, 2213 ic_inner_resources, XIMNumber(ic_inner_resources), 200); 2214} 2215 2216static XIMResourceList 2217_XimGetResourceListRecByMode( 2218 XIMResourceList res_list, 2219 unsigned int list_num, 2220 unsigned short mode) 2221{ 2222 register int i; 2223 2224 for(i = 0; i < list_num; i++) { 2225 if (res_list[i].mode & mode) { 2226 return (XIMResourceList)&res_list[i]; 2227 } 2228 } 2229 return (XIMResourceList)NULL; 2230} 2231 2232Bool 2233_XimCheckCreateICValues( 2234 XIMResourceList res_list, 2235 unsigned int list_num) 2236{ 2237 if (!_XimGetResourceListRecByMode(res_list, list_num, XIM_MODE_IC_CREATE)) { 2238 return True; 2239 } 2240 return False; 2241} 2242 2243XIMResourceList 2244_XimGetResourceListRecByQuark( 2245 XIMResourceList res_list, 2246 unsigned int list_num, 2247 XrmQuark quark) 2248{ 2249 register int i; 2250 2251 for(i = 0; i < list_num; i++) { 2252 if (res_list[i].xrm_name == quark) { 2253 return (XIMResourceList)&res_list[i]; 2254 } 2255 } 2256 return (XIMResourceList)NULL; 2257} 2258 2259XIMResourceList 2260_XimGetResourceListRec( 2261 XIMResourceList res_list, 2262 unsigned int list_num, 2263 const char *name) 2264{ 2265 XrmQuark quark = XrmStringToQuark(name); 2266 2267 return _XimGetResourceListRecByQuark(res_list, list_num, quark); 2268} 2269 2270char * 2271_XimSetIMValueData( 2272 Xim im, 2273 XPointer top, 2274 XIMArg *values, 2275 XIMResourceList res_list, 2276 unsigned int list_num) 2277{ 2278 register XIMArg *p; 2279 XIMResourceList res; 2280 int check; 2281 2282 for(p = values; p->name != NULL; p++) { 2283 if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) { 2284 return p->name; 2285 } 2286 check = _XimCheckIMMode(res, XIM_SETIMVALUES); 2287 if(check == XIM_CHECK_INVALID) { 2288 continue; 2289 } else if (check == XIM_CHECK_ERROR) { 2290 return p->name; 2291 } 2292 2293 if(!_XimEncodeLocalIMAttr(res, top, p->value)) { 2294 return p->name; 2295 } 2296 } 2297 return NULL; 2298} 2299 2300char * 2301_XimGetIMValueData( 2302 Xim im, 2303 XPointer top, 2304 XIMArg *values, 2305 XIMResourceList res_list, 2306 unsigned int list_num) 2307{ 2308 register XIMArg *p; 2309 XIMResourceList res; 2310 int check; 2311 2312 for(p = values; p->name != NULL; p++) { 2313 if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) { 2314 return p->name; 2315 } 2316 check = _XimCheckIMMode(res, XIM_GETIMVALUES); 2317 if(check == XIM_CHECK_INVALID) { 2318 continue; 2319 } else if (check == XIM_CHECK_ERROR) { 2320 return p->name; 2321 } 2322 2323 if(!_XimDecodeLocalIMAttr(res, top, p->value)) { 2324 return p->name; 2325 } 2326 } 2327 return NULL; 2328} 2329 2330void 2331_XimSetIMMode( 2332 XIMResourceList res_list, 2333 unsigned int list_num) 2334{ 2335 XIMResourceList res; 2336 unsigned int n = XIMNumber(im_mode); 2337 register int i; 2338 2339 for(i = 0; i < n; i++) { 2340 if(!(res = _XimGetResourceListRecByQuark(res_list, 2341 list_num, im_mode_quark[i]))) { 2342 continue; 2343 } 2344 res->mode = im_mode[i].mode; 2345 } 2346 return; 2347} 2348 2349static int 2350_XimCheckSetIMDefaultsMode( 2351 XIMResourceList res) 2352{ 2353 if(res->mode & XIM_MODE_IM_DEFAULT) { 2354 return XIM_CHECK_VALID; 2355 } 2356 return XIM_CHECK_INVALID; 2357} 2358 2359static int 2360_XimCheckSetIMValuesMode( 2361 XIMResourceList res) 2362{ 2363 if(res->mode & XIM_MODE_IM_SET) { 2364 return XIM_CHECK_VALID; 2365 } 2366 return XIM_CHECK_INVALID; 2367} 2368 2369static int 2370 _XimCheckGetIMValuesMode( 2371 XIMResourceList res) 2372{ 2373 if(res->mode & XIM_MODE_IM_GET) { 2374 return XIM_CHECK_VALID; 2375 } 2376 return XIM_CHECK_INVALID; 2377} 2378 2379int 2380 _XimCheckIMMode( 2381 XIMResourceList res, 2382 unsigned long mode) 2383{ 2384 if(res->mode == 0) { 2385 return XIM_CHECK_INVALID; 2386 } 2387 if(mode & XIM_SETIMDEFAULTS) { 2388 return _XimCheckSetIMDefaultsMode(res); 2389 } else if (mode & XIM_SETIMVALUES) { 2390 return _XimCheckSetIMValuesMode(res); 2391 } else if (mode & XIM_GETIMVALUES) { 2392 return _XimCheckGetIMValuesMode(res); 2393 } else { 2394 return XIM_CHECK_ERROR; 2395 } 2396} 2397 2398void 2399_XimSetICMode(XIMResourceList res_list, unsigned int list_num, XIMStyle style) 2400{ 2401 XIMResourceList res; 2402 unsigned int n = XIMNumber(ic_mode); 2403 register int i; 2404 unsigned int pre_offset; 2405 unsigned int sts_offset; 2406 2407 if(style & XIMPreeditArea) { 2408 pre_offset = XOffsetOf(XimICMode, preedit_area_mode); 2409 } else if(style & XIMPreeditCallbacks) { 2410 pre_offset = XOffsetOf(XimICMode, preedit_callback_mode); 2411 } else if(style & XIMPreeditPosition) { 2412 pre_offset = XOffsetOf(XimICMode, preedit_position_mode); 2413 } else if(style & XIMPreeditNothing) { 2414 pre_offset = XOffsetOf(XimICMode, preedit_nothing_mode); 2415 } else { 2416 pre_offset = XOffsetOf(XimICMode, preedit_none_mode); 2417 } 2418 2419 if(style & XIMStatusArea) { 2420 sts_offset = XOffsetOf(XimICMode, status_area_mode); 2421 } else if(style & XIMStatusCallbacks) { 2422 sts_offset = XOffsetOf(XimICMode, status_callback_mode); 2423 } else if(style & XIMStatusNothing) { 2424 sts_offset = XOffsetOf(XimICMode, status_nothing_mode); 2425 } else { 2426 sts_offset = XOffsetOf(XimICMode, status_none_mode); 2427 } 2428 2429 for(i = 0; i < n; i++) { 2430 if(!(res = _XimGetResourceListRecByQuark(res_list, 2431 list_num, ic_mode_quark[i]))) { 2432 continue; 2433 } 2434 res->mode = ( (*(const unsigned short *)((const char *)&ic_mode[i] + pre_offset)) 2435 | (*(const unsigned short *)((const char *)&ic_mode[i] + sts_offset))); 2436 } 2437 return; 2438} 2439 2440static int 2441_XimCheckSetICDefaultsMode( 2442 XIMResourceList res, 2443 unsigned long mode) 2444{ 2445 if(mode & XIM_PREEDIT_ATTR) { 2446 if(!(res->mode & XIM_MODE_PRE_MASK)) { 2447 return XIM_CHECK_INVALID; 2448 } 2449 2450 if(res->mode & XIM_MODE_PRE_CREATE) { 2451 return XIM_CHECK_ERROR; 2452 } else if (!(res->mode & XIM_MODE_PRE_DEFAULT)) { 2453 return XIM_CHECK_INVALID; 2454 } 2455 2456 } else if(mode & XIM_STATUS_ATTR) { 2457 if(!(res->mode & XIM_MODE_STS_MASK)) { 2458 return XIM_CHECK_INVALID; 2459 } 2460 2461 if(res->mode & XIM_MODE_STS_CREATE) { 2462 return XIM_CHECK_ERROR; 2463 } 2464 if(!(res->mode & XIM_MODE_STS_DEFAULT)) { 2465 return XIM_CHECK_INVALID; 2466 } 2467 2468 } else { 2469 if(!res->mode) { 2470 return XIM_CHECK_INVALID; 2471 } 2472 2473 if(res->mode & XIM_MODE_IC_CREATE) { 2474 return XIM_CHECK_ERROR; 2475 } 2476 if(!(res->mode & XIM_MODE_IC_DEFAULT)) { 2477 return XIM_CHECK_INVALID; 2478 } 2479 } 2480 return XIM_CHECK_VALID; 2481} 2482 2483static int 2484_XimCheckCreateICMode( 2485 XIMResourceList res, 2486 unsigned long mode) 2487{ 2488 if(mode & XIM_PREEDIT_ATTR) { 2489 if(!(res->mode & XIM_MODE_PRE_MASK)) { 2490 return XIM_CHECK_INVALID; 2491 } 2492 2493 if(res->mode & XIM_MODE_PRE_CREATE) { 2494 res->mode &= ~XIM_MODE_PRE_CREATE; 2495 } else if(res->mode & XIM_MODE_PRE_ONCE) { 2496 res->mode &= ~XIM_MODE_PRE_ONCE; 2497 } else if(res->mode & XIM_MODE_PRE_DEFAULT) { 2498 res->mode &= ~XIM_MODE_PRE_DEFAULT; 2499 } else if (!(res->mode & XIM_MODE_PRE_SET)) { 2500 return XIM_CHECK_ERROR; 2501 } 2502 2503 } else if(mode & XIM_STATUS_ATTR) { 2504 if(!(res->mode & XIM_MODE_STS_MASK)) { 2505 return XIM_CHECK_INVALID; 2506 } 2507 2508 if(res->mode & XIM_MODE_STS_CREATE) { 2509 res->mode &= ~XIM_MODE_STS_CREATE; 2510 } else if(res->mode & XIM_MODE_STS_ONCE) { 2511 res->mode &= ~XIM_MODE_STS_ONCE; 2512 } else if(res->mode & XIM_MODE_STS_DEFAULT) { 2513 res->mode &= ~XIM_MODE_STS_DEFAULT; 2514 } else if (!(res->mode & XIM_MODE_STS_SET)) { 2515 return XIM_CHECK_ERROR; 2516 } 2517 2518 } else { 2519 if(!res->mode) { 2520 return XIM_CHECK_INVALID; 2521 } 2522 2523 if(res->mode & XIM_MODE_IC_CREATE) { 2524 res->mode &= ~XIM_MODE_IC_CREATE; 2525 } else if(res->mode & XIM_MODE_IC_ONCE) { 2526 res->mode &= ~XIM_MODE_IC_ONCE; 2527 } else if(res->mode & XIM_MODE_IC_DEFAULT) { 2528 res->mode &= ~XIM_MODE_IC_DEFAULT; 2529 } else if (!(res->mode & XIM_MODE_IC_SET)) { 2530 return XIM_CHECK_ERROR; 2531 } 2532 } 2533 return XIM_CHECK_VALID; 2534} 2535 2536static int 2537_XimCheckSetICValuesMode( 2538 XIMResourceList res, 2539 unsigned long mode) 2540{ 2541 if(mode & XIM_PREEDIT_ATTR) { 2542 if(!(res->mode & XIM_MODE_PRE_MASK)) { 2543 return XIM_CHECK_INVALID; 2544 } 2545 2546 if(res->mode & XIM_MODE_PRE_ONCE) { 2547 res->mode &= ~XIM_MODE_PRE_ONCE; 2548 } else if(!(res->mode & XIM_MODE_PRE_SET)) { 2549 return XIM_CHECK_ERROR; 2550 } 2551 2552 } else if(mode & XIM_STATUS_ATTR) { 2553 if(!(res->mode & XIM_MODE_STS_MASK)) { 2554 return XIM_CHECK_INVALID; 2555 } 2556 2557 if(res->mode & XIM_MODE_STS_ONCE) { 2558 res->mode &= ~XIM_MODE_STS_ONCE; 2559 } else if(!(res->mode & XIM_MODE_STS_SET)) { 2560 return XIM_CHECK_ERROR; 2561 } 2562 2563 } else { 2564 if(!res->mode) { 2565 return XIM_CHECK_INVALID; 2566 } 2567 2568 if(res->mode & XIM_MODE_IC_ONCE) { 2569 res->mode &= ~XIM_MODE_IC_ONCE; 2570 } else if(!(res->mode & XIM_MODE_IC_SET)) { 2571 return XIM_CHECK_ERROR; 2572 } 2573 } 2574 return XIM_CHECK_VALID; 2575} 2576 2577static int 2578_XimCheckGetICValuesMode( 2579 XIMResourceList res, 2580 unsigned long mode) 2581{ 2582 if(mode & XIM_PREEDIT_ATTR) { 2583 if(!(res->mode & XIM_MODE_PRE_MASK)) { 2584 return XIM_CHECK_INVALID; 2585 } 2586 2587 if(!(res->mode & XIM_MODE_PRE_GET)) { 2588 return XIM_CHECK_ERROR; 2589 } 2590 2591 } else if(mode & XIM_STATUS_ATTR) { 2592 if(!(res->mode & XIM_MODE_STS_MASK)) { 2593 return XIM_CHECK_INVALID; 2594 } 2595 2596 if(!(res->mode & XIM_MODE_STS_GET)) { 2597 return XIM_CHECK_ERROR; 2598 } 2599 2600 } else { 2601 if(!res->mode) { 2602 return XIM_CHECK_INVALID; 2603 } 2604 2605 if(!(res->mode & XIM_MODE_IC_GET)) { 2606 return XIM_CHECK_ERROR; 2607 } 2608 } 2609 return XIM_CHECK_VALID; 2610} 2611 2612int 2613 _XimCheckICMode( 2614 XIMResourceList res, 2615 unsigned long mode) 2616{ 2617 if(mode &XIM_SETICDEFAULTS) { 2618 return _XimCheckSetICDefaultsMode(res, mode); 2619 } else if (mode & XIM_CREATEIC) { 2620 return _XimCheckCreateICMode(res, mode); 2621 } else if (mode & XIM_SETICVALUES) { 2622 return _XimCheckSetICValuesMode(res, mode); 2623 } else if (mode & XIM_GETICVALUES) { 2624 return _XimCheckGetICValuesMode(res, mode); 2625 } else { 2626 return XIM_CHECK_ERROR; 2627 } 2628} 2629 2630Bool 2631_XimSetLocalIMDefaults( 2632 Xim im, 2633 XPointer top, 2634 XIMResourceList res_list, 2635 unsigned int list_num) 2636{ 2637 XimValueOffsetInfo info; 2638 unsigned int num; 2639 register int i; 2640 XIMResourceList res; 2641 int check; 2642 2643 info = im_attr_info; 2644 num = XIMNumber(im_attr_info); 2645 2646 for(i = 0; i < num; i++) { 2647 if((res = _XimGetResourceListRecByQuark( res_list, list_num, 2648 info[i].quark)) == (XIMResourceList)NULL) { 2649 return False; 2650 } 2651 2652 check = _XimCheckIMMode(res, XIM_SETIMDEFAULTS); 2653 if(check == XIM_CHECK_INVALID) { 2654 continue; 2655 } else if (check == XIM_CHECK_ERROR) { 2656 return False; 2657 } 2658 2659 if(!info[i].defaults) { 2660 continue; 2661 } 2662 if(!(info[i].defaults(&info[i], top, (XPointer)NULL, 0))) { 2663 return False; 2664 } 2665 } 2666 return True; 2667} 2668 2669Bool 2670_XimSetICDefaults( 2671 Xic ic, 2672 XPointer top, 2673 unsigned long mode, 2674 XIMResourceList res_list, 2675 unsigned int list_num) 2676{ 2677 unsigned int num; 2678 XimValueOffsetInfo info; 2679 register int i; 2680 XIMResourceList res; 2681 int check; 2682 XrmQuark pre_quark; 2683 XrmQuark sts_quark; 2684 2685 pre_quark = XrmStringToQuark(XNPreeditAttributes); 2686 sts_quark = XrmStringToQuark(XNStatusAttributes); 2687 2688 if(mode & XIM_PREEDIT_ATTR) { 2689 info = ic_pre_attr_info; 2690 num = XIMNumber(ic_pre_attr_info); 2691 } else if(mode & XIM_STATUS_ATTR) { 2692 info = ic_sts_attr_info; 2693 num = XIMNumber(ic_sts_attr_info); 2694 } else { 2695 info = ic_attr_info; 2696 num = XIMNumber(ic_attr_info); 2697 } 2698 2699 for(i = 0; i < num; i++) { 2700 if(info[i].quark == pre_quark) { 2701 if(!_XimSetICDefaults(ic, (XPointer)((char *)top + info[i].offset), 2702 (mode | XIM_PREEDIT_ATTR), res_list, list_num)) { 2703 return False; 2704 } 2705 } else if (info[i].quark == sts_quark) { 2706 if(!_XimSetICDefaults(ic, (XPointer)((char *)top + info[i].offset), 2707 (mode | XIM_STATUS_ATTR), res_list, list_num)) { 2708 return False; 2709 } 2710 } else { 2711 if(!(res = _XimGetResourceListRecByQuark(res_list, list_num, 2712 info[i].quark))) { 2713 return False; 2714 } 2715 2716 check = _XimCheckICMode(res, mode); 2717 if (check == XIM_CHECK_INVALID) { 2718 continue; 2719 } else if (check == XIM_CHECK_ERROR) { 2720 return False; 2721 } 2722 2723 if (!info[i].defaults) { 2724 continue; 2725 } 2726 if (!(info[i].defaults(&info[i], top, (XPointer)ic, mode))) { 2727 return False; 2728 } 2729 } 2730 } 2731 return True; 2732} 2733 2734static Bool 2735_XimEncodeAttr( 2736 XimValueOffsetInfo info, 2737 unsigned int num, 2738 XIMResourceList res, 2739 XPointer top, 2740 XPointer val) 2741{ 2742 register int i; 2743 2744 for(i = 0; i < num; i++ ) { 2745 if(info[i].quark == res->xrm_name) { 2746 if(!info[i].encode) { 2747 return False; 2748 } 2749 return (*info[i].encode)(&info[i], top, val); 2750 } 2751 } 2752 return False; 2753} 2754 2755Bool 2756_XimEncodeLocalIMAttr( 2757 XIMResourceList res, 2758 XPointer top, 2759 XPointer val) 2760{ 2761 return _XimEncodeAttr(im_attr_info, XIMNumber(im_attr_info), 2762 res, top, val); 2763} 2764 2765Bool 2766_XimEncodeLocalICAttr( 2767 Xic ic, 2768 XIMResourceList res, 2769 XPointer top, 2770 XIMArg *arg, 2771 unsigned long mode) 2772{ 2773 unsigned int num; 2774 XimValueOffsetInfo info; 2775 2776 if(mode & XIM_PREEDIT_ATTR) { 2777 info = ic_pre_attr_info; 2778 num = XIMNumber(ic_pre_attr_info); 2779 } else if(mode & XIM_STATUS_ATTR) { 2780 info = ic_sts_attr_info; 2781 num = XIMNumber(ic_sts_attr_info); 2782 } else { 2783 info = ic_attr_info; 2784 num = XIMNumber(ic_attr_info); 2785 } 2786 2787 return _XimEncodeAttr(info, num, res, top, arg->value); 2788} 2789 2790static Bool 2791_XimEncodeLocalTopValue( 2792 Xic ic, 2793 XIMResourceList res, 2794 XPointer val, 2795 Bool flag) 2796{ 2797 XIMArg *p = (XIMArg *)val; 2798 2799 if (res->xrm_name == XrmStringToQuark(XNClientWindow)) { 2800 ic->core.client_window = (Window)p->value; 2801 if (ic->core.focus_window == (Window)0) 2802 ic->core.focus_window = ic->core.client_window; 2803 if (flag) { 2804 _XRegisterFilterByType(ic->core.im->core.display, 2805 ic->core.focus_window, 2806 KeyPress, KeyRelease, _XimLocalFilter, (XPointer)ic); 2807 } 2808 } else if (res->xrm_name == XrmStringToQuark(XNFocusWindow)) { 2809 if (ic->core.client_window) { 2810 if (flag) { 2811 _XUnregisterFilter(ic->core.im->core.display, 2812 ic->core.focus_window, _XimLocalFilter, (XPointer)ic); 2813 } 2814 ic->core.focus_window = (Window)p->value; 2815 if (flag) { 2816 _XRegisterFilterByType(ic->core.im->core.display, 2817 ic->core.focus_window, KeyPress, KeyRelease, 2818 _XimLocalFilter, (XPointer)ic); 2819 } 2820 } else 2821 ic->core.focus_window = (Window)p->value; 2822 } 2823 return True; 2824} 2825 2826static Bool 2827_XimEncodeLocalPreeditValue( 2828 Xic ic, 2829 XIMResourceList res, 2830 XPointer val) 2831{ 2832 XIMArg *p = (XIMArg *)val; 2833 2834 if (res->xrm_name == XrmStringToQuark(XNStdColormap)) { 2835 XStandardColormap *colormap_ret; 2836 int count; 2837 2838 if (!(XGetRGBColormaps(ic->core.im->core.display, 2839 ic->core.focus_window, &colormap_ret, 2840 &count, (Atom)p->value))) 2841 return False; 2842 2843 Xfree(colormap_ret); 2844 } 2845 return True; 2846} 2847 2848static Bool 2849_XimEncodeLocalStatusValue( 2850 Xic ic, 2851 XIMResourceList res, 2852 XPointer val) 2853{ 2854 XIMArg *p = (XIMArg *)val; 2855 2856 if (res->xrm_name == XrmStringToQuark(XNStdColormap)) { 2857 XStandardColormap *colormap_ret; 2858 int count; 2859 2860 if (!(XGetRGBColormaps(ic->core.im->core.display, 2861 ic->core.focus_window, &colormap_ret, 2862 &count, (Atom)p->value))) 2863 return False; 2864 2865 Xfree(colormap_ret); 2866 } 2867 return True; 2868} 2869 2870char * 2871_XimSetICValueData( 2872 Xic ic, 2873 XPointer top, 2874 XIMResourceList res_list, 2875 unsigned int list_num, 2876 XIMArg *values, 2877 unsigned long mode, 2878 Bool flag) 2879{ 2880 register XIMArg *p; 2881 XIMResourceList res; 2882 char *name; 2883 int check; 2884 XrmQuark pre_quark; 2885 XrmQuark sts_quark; 2886 2887 pre_quark = XrmStringToQuark(XNPreeditAttributes); 2888 sts_quark = XrmStringToQuark(XNStatusAttributes); 2889 2890 for(p = values; p->name != NULL; p++) { 2891 if((res = _XimGetResourceListRec(res_list, list_num, 2892 p->name)) == (XIMResourceList)NULL) { 2893 return p->name; 2894 } 2895 if(res->xrm_name == pre_quark) { 2896 if(((name = _XimSetICValueData(ic, 2897 (XPointer)(&((XimDefICValues *)top)->preedit_attr), 2898 res_list, list_num, (XIMArg *)p->value, 2899 (mode | XIM_PREEDIT_ATTR), flag)))) { 2900 return name; 2901 } 2902 } else if(res->xrm_name == sts_quark) { 2903 if(((name = _XimSetICValueData(ic, 2904 (XPointer)(&((XimDefICValues *)top)->status_attr), 2905 res_list, list_num, (XIMArg *)p->value, 2906 (mode | XIM_STATUS_ATTR), flag)))) { 2907 return name; 2908 } 2909 } else { 2910 check = _XimCheckICMode(res, mode); 2911 if(check == XIM_CHECK_INVALID) { 2912 continue; 2913 } else if(check == XIM_CHECK_ERROR) { 2914 return p->name; 2915 } 2916 2917 if(mode & XIM_PREEDIT_ATTR) { 2918 if (!_XimEncodeLocalPreeditValue(ic, res, (XPointer)p)) 2919 return p->name; 2920 } else if(mode & XIM_STATUS_ATTR) { 2921 if (!_XimEncodeLocalStatusValue(ic, res, (XPointer)p)) 2922 return p->name; 2923 } else { 2924 if (!_XimEncodeLocalTopValue(ic, res, (XPointer)p, flag)) 2925 return p->name; 2926 } 2927 if(_XimEncodeLocalICAttr(ic, res, top, p, mode) == False) { 2928 return p->name; 2929 } 2930 } 2931 } 2932 return NULL; 2933} 2934 2935static Bool 2936_XimCheckInputStyle( 2937 XIMStyles *styles, 2938 XIMStyle style) 2939{ 2940 int num = styles->count_styles; 2941 register int i; 2942 2943 for(i = 0; i < num; i++) { 2944 if(styles->supported_styles[i] == style) { 2945 return True; 2946 } 2947 } 2948 return False; 2949} 2950 2951Bool 2952_XimCheckLocalInputStyle( 2953 Xic ic, 2954 XPointer top, 2955 XIMArg *values, 2956 XIMStyles *styles, 2957 XIMResourceList res_list, 2958 unsigned int list_num) 2959{ 2960 XrmQuark quark = XrmStringToQuark(XNInputStyle); 2961 register XIMArg *p; 2962 XIMResourceList res; 2963 2964 for(p = values; p && p->name != NULL; p++) { 2965 if(quark == XrmStringToQuark(p->name)) { 2966 if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) { 2967 return False; 2968 } 2969 if(!_XimEncodeLocalICAttr(ic, res, top, p, 0)) { 2970 return False; 2971 } 2972 if (_XimCheckInputStyle(styles, 2973 ((XimDefICValues *)top)->input_style)) { 2974 return True; 2975 } 2976 return False; 2977 } 2978 } 2979 return False; 2980} 2981 2982static Bool 2983_XimDecodeAttr( 2984 XimValueOffsetInfo info, 2985 unsigned int num, 2986 XIMResourceList res, 2987 XPointer top, 2988 XPointer val) 2989{ 2990 register int i; 2991 2992 for(i = 0; i < num; i++ ) { 2993 if(info[i].quark == res->xrm_name) { 2994 if(!info[i].decode) { 2995 return False; 2996 } 2997 return (*info[i].decode)(&info[i], top, val); 2998 } 2999 } 3000 return False; 3001} 3002 3003Bool 3004_XimDecodeLocalIMAttr( 3005 XIMResourceList res, 3006 XPointer top, 3007 XPointer val) 3008{ 3009 return _XimDecodeAttr(im_attr_info, XIMNumber(im_attr_info), 3010 res, top, val); 3011} 3012 3013Bool 3014_XimDecodeLocalICAttr( 3015 XIMResourceList res, 3016 XPointer top, 3017 XPointer val, 3018 unsigned long mode) 3019{ 3020 unsigned int num; 3021 XimValueOffsetInfo info; 3022 3023 if(mode & XIM_PREEDIT_ATTR) { 3024 info = ic_pre_attr_info; 3025 num = XIMNumber(ic_pre_attr_info); 3026 } else if(mode & XIM_STATUS_ATTR) { 3027 info = ic_sts_attr_info; 3028 num = XIMNumber(ic_sts_attr_info); 3029 } else { 3030 info = ic_attr_info; 3031 num = XIMNumber(ic_attr_info); 3032 } 3033 3034 return _XimDecodeAttr(info, num, res, top, val); 3035} 3036 3037char * 3038_XimGetICValueData(Xic ic, XPointer top, XIMResourceList res_list, 3039 unsigned int list_num, XIMArg *values, unsigned long mode) 3040{ 3041 register XIMArg *p; 3042 XIMResourceList res; 3043 char *name; 3044 int check; 3045 XrmQuark pre_quark; 3046 XrmQuark sts_quark; 3047 3048 pre_quark = XrmStringToQuark(XNPreeditAttributes); 3049 sts_quark = XrmStringToQuark(XNStatusAttributes); 3050 3051 for(p = values; p->name != NULL; p++) { 3052 if((res = _XimGetResourceListRec(res_list, list_num, 3053 p->name)) == (XIMResourceList)NULL) { 3054 return p->name; 3055 } 3056 if(res->xrm_name == pre_quark) { 3057 if((name = _XimGetICValueData(ic, 3058 (XPointer)(&((XimDefICValues *)top)->preedit_attr), 3059 res_list, list_num, (XIMArg *)p->value, 3060 (mode | XIM_PREEDIT_ATTR)))) { 3061 return name; 3062 } 3063 } else if(res->xrm_name == sts_quark) { 3064 if((name = _XimGetICValueData(ic, 3065 (XPointer)(&((XimDefICValues *)top)->status_attr), 3066 res_list, list_num, (XIMArg *)p->value, 3067 (mode | XIM_STATUS_ATTR)))) { 3068 return name; 3069 } 3070 } else { 3071 check = _XimCheckICMode(res, mode); 3072 if(check == XIM_CHECK_INVALID) { 3073 continue; 3074 } else if(check == XIM_CHECK_ERROR) { 3075 return p->name; 3076 } 3077 3078 if(_XimDecodeLocalICAttr(res, top, p->value, mode) == False) { 3079 return p->name; 3080 } 3081 } 3082 } 3083 return NULL; 3084} 3085 3086void 3087_XimGetCurrentIMValues(Xim im, XimDefIMValues *im_values) 3088{ 3089 bzero((char *)im_values, sizeof(XimDefIMValues)); 3090 3091 im_values->styles = im->core.styles; 3092 im_values->im_values_list = im->core.im_values_list; 3093 im_values->ic_values_list = im->core.ic_values_list; 3094 im_values->destroy_callback = im->core.destroy_callback; 3095 im_values->res_name = im->core.res_name; 3096 im_values->res_class = im->core.res_class; 3097 im_values->visible_position = im->core.visible_position; 3098} 3099 3100void 3101_XimSetCurrentIMValues(Xim im, XimDefIMValues *im_values) 3102{ 3103 im->core.styles = im_values->styles; 3104 im->core.im_values_list = im_values->im_values_list; 3105 im->core.ic_values_list = im_values->ic_values_list; 3106 im->core.destroy_callback = im_values->destroy_callback; 3107 im->core.res_name = im_values->res_name; 3108 im->core.res_class = im_values->res_class; 3109 im->core.visible_position = im_values->visible_position; 3110} 3111 3112void 3113_XimGetCurrentICValues(Xic ic, XimDefICValues *ic_values) 3114{ 3115 bzero((char *)ic_values, sizeof(XimDefICValues)); 3116 3117 ic_values->input_style = ic->core.input_style; 3118 ic_values->client_window = ic->core.client_window; 3119 ic_values->focus_window = ic->core.focus_window; 3120 ic_values->filter_events = ic->core.filter_events; 3121 ic_values->geometry_callback = ic->core.geometry_callback; 3122 ic_values->res_name = ic->core.res_name; 3123 ic_values->res_class = ic->core.res_class; 3124 ic_values->destroy_callback = ic->core.destroy_callback; 3125 ic_values->string_conversion_callback 3126 = ic->core.string_conversion_callback; 3127 ic_values->string_conversion = ic->core.string_conversion; 3128 ic_values->reset_state = ic->core.reset_state; 3129 ic_values->hotkey = ic->core.hotkey; 3130 ic_values->hotkey_state = ic->core.hotkey_state; 3131 ic_values->preedit_attr = ic->core.preedit_attr; 3132 ic_values->status_attr = ic->core.status_attr; 3133} 3134 3135void 3136_XimSetCurrentICValues( 3137 Xic ic, 3138 XimDefICValues *ic_values) 3139{ 3140 ic->core.input_style = ic_values->input_style; 3141 ic->core.client_window = ic_values->client_window; 3142 if (ic_values->focus_window) 3143 ic->core.focus_window = ic_values->focus_window; 3144 ic->core.filter_events = ic_values->filter_events; 3145 ic->core.geometry_callback = ic_values->geometry_callback; 3146 ic->core.res_name = ic_values->res_name; 3147 ic->core.res_class = ic_values->res_class; 3148 ic->core.destroy_callback = ic_values->destroy_callback; 3149 ic->core.string_conversion_callback 3150 = ic_values->string_conversion_callback; 3151 ic->core.string_conversion = ic_values->string_conversion; 3152 ic->core.reset_state = ic_values->reset_state; 3153 ic->core.hotkey = ic_values->hotkey; 3154 ic->core.hotkey_state = ic_values->hotkey_state; 3155 ic->core.preedit_attr = ic_values->preedit_attr; 3156 ic->core.status_attr = ic_values->status_attr; 3157} 3158 3159static void 3160_XimInitialIMOffsetInfo(void) 3161{ 3162 unsigned int n = XIMNumber(im_attr_info); 3163 register int i; 3164 3165 for(i = 0; i < n; i++) { 3166 im_attr_info[i].quark = XrmStringToQuark(GET_NAME(im_attr_info[i])); 3167 } 3168} 3169 3170static void 3171_XimInitialICOffsetInfo(void) 3172{ 3173 unsigned int n; 3174 register int i; 3175 3176 n = XIMNumber(ic_attr_info); 3177 for(i = 0; i < n; i++) { 3178 ic_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_attr_info[i])); 3179 } 3180 3181 n = XIMNumber(ic_pre_attr_info); 3182 for(i = 0; i < n; i++) { 3183 ic_pre_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_pre_attr_info[i])); 3184 } 3185 3186 n = XIMNumber(ic_sts_attr_info); 3187 for(i = 0; i < n; i++) { 3188 ic_sts_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_sts_attr_info[i])); 3189 } 3190} 3191 3192static void 3193_XimInitialIMMode(void) 3194{ 3195 unsigned int n = XIMNumber(im_mode); 3196 register int i; 3197 3198 for(i = 0; i < n; i++) { 3199 im_mode_quark[i] = XrmStringToQuark(GET_NAME(im_mode[i])); 3200 } 3201} 3202 3203static void 3204_XimInitialICMode(void) 3205{ 3206 unsigned int n = XIMNumber(ic_mode); 3207 register int i; 3208 3209 for(i = 0; i < n; i++) { 3210 ic_mode_quark[i] = XrmStringToQuark(GET_NAME(ic_mode[i])); 3211 } 3212} 3213 3214void 3215_XimInitialResourceInfo(void) 3216{ 3217 static Bool init_flag = False; 3218 3219 if(init_flag == True) { 3220 return; 3221 } 3222 _XimInitialIMOffsetInfo(); 3223 _XimInitialICOffsetInfo(); 3224 _XimInitialIMMode(); 3225 _XimInitialICMode(); 3226 init_flag = True; 3227} 3228